//: C01:ReprocessHTML.cpp
// From Thinking in C++, 2nd Edition
// Available at http://www.BruceEckel.com
// (c) Bruce Eckel 2000
// Copyright notice in Copyright.txt
// Take Word's html output and fix up
// the code listings and html tags
#include "../require.h"
#include ")) != string::npos)
s.erase(br, strlen(" "));
while((br = s.find("
" // Means "preformatted" in html
<< stripPBreaks(line.substr(tag)) << endl;
string s;
while(getline(in, s)) {
int endtag = s.find("/""/""/"":~");
if(endtag != string::npos) {
endtag += strlen("/""/""/"":~");
string before = s.substr(0, endtag);
string after = s.substr(endtag);
out << stripPBreaks(before) << ""
<< after << endl;
return;
}
out << stripPBreaks(s) << endl;
}
}
string removals[] = {
"",
"",
"",
"",
"",
"SIZE=1", // Eliminate all other '1' & '2' size
"SIZE=2",
};
const int rmsz =
sizeof(removals)/sizeof(*removals);
int main(int argc, char* argv[]) {
requireArgs(argc, 2);
ifstream in(argv[1]);
assure(in, argv[1]);
ofstream out(argv[2]);
string line;
while(getline(in, line)) {
// The "Body" tag only appears once:
if(line.find("" << endl;
continue; // Get next line
}
// Eliminate each of the removals strings:
for(int i = 0; i < rmsz; i++) {
int find = line.find(removals[i]);
if(find != string::npos)
line.erase(find, removals[i].size());
}
int tag1 = line.find("/""/"":");
int tag2 = line.find("/""*"":");
if(tag1 != string::npos)
fixupCodeListing(in, out, line, tag1);
else if(tag2 != string::npos)
fixupCodeListing(in, out, line, tag2);
else
out << line << endl;
}
} ///:~