";
marker2 = "";
} else marker1 = marker2 = "";
n = s.find('\n');
while (n != string::npos) {
m = s.rfind('\n',n-1);
if (m == string::npos) s.insert(0,marker1);
else s.insert(m+1,marker1);
n = s.find('\n',m+1);
s.insert(n,marker2);
n = s.find('\n',n);
n = s.find('\n',n+1);
}
allflag = "";
}
}
// open input file as-is or as file.txt
// if npair = 0, don't open output file (is just initial pass thru input)
// if npair = 1, open output file as stdout
// if npair > 1, open output file with .html suffix
// either replace .txt in input file, or append .html
void file_open(int npair, string &infile, FILE **in, FILE **out)
{
*in = fopen(infile.c_str(),"r");
if (*in == NULL) {
string root = infile;
infile = infile + ".txt";
*in = fopen(infile.c_str(),"r");
if (*in == NULL) {
fprintf(stderr,"ERROR: Could not open %s or %s\n",
root.c_str(),infile.c_str());
exit(1);
}
}
if (npair == 0) return;
else if (npair == 1) *out = stdout;
else {
string outfile;
size_t pos = infile.rfind(".txt");
if (pos == infile.length()-4) outfile = infile.substr(0,pos) + ".html";
else outfile = infile + ".html";
*out = fopen(outfile.c_str(),"w");
if (*out == NULL) {
fprintf(stderr,"ERROR: Could not open %s\n",outfile.c_str());
exit(1);
}
}
}
// for tables:
// build | string (DT) based on current column
string td_tag(int currentc) {
// eacolumn gives the alignment printout of a specific column
string eacolumn;
// va gives vertical alignment to a specific column
string va;
// DT is the complete | tag, with width and align
string DT;
// dw is the width for tables. It is also the tag beginning
string dw;
// set up alignment for particular columns
for (int counter=0; counter < ncalign; counter++){
if (ncalign != 0 && acolnum[counter] == currentc){
string align;
if (colalign[counter] == "l") align= "left";
else if (colalign[counter] == "r") align= "right";
else if (colalign[counter] == "c") align= "center";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for caM=X\n",
colalign[counter].c_str());
exit(1);
}
eacolumn= " ALIGN =\"" + align +"\"";
}else eacolumn= "";
}
// set up vertical alignment for particular columns
for (int counter=0; counter < ncvalign; counter++){
if (ncvalign != 0 && vacolnum[counter] == currentc){
string valign;
if (colvalign[counter] == "t") valign= "top";
else if (colvalign[counter] == "m") valign= "middle";
else if (colvalign[counter] == "ba") valign= "baseline";
else if (colvalign[counter] == "bo") valign= "bottom";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for cvaM=X\n",
colvalign[counter].c_str());
exit(1);
}
va = " VALIGN =\"" + valign + "\"";
} else va = " ";
}
// put in special width if specified
// new code
// if dwidth has not been set, dw is blank
// if dwidth has been set, dw has that... unless
if (dwidth=="0") dw = " ";
else dw =" WIDTH=\""+ dwidth + "\"";
for (int counter = 0; counter < ncnum; counter++){
// if it is the right column, dw = cwidth property
if (cnum[counter] == currentc) dw= " WIDTH=\"" + cwidth[counter] + "\"";
}
// DT is set for all of this particular separator : reset next separator
DT = "| ";
return DT;
}
// for tables:
// find the next separator starting at nend(the end of the last .insert)
// if there is either a delim or newline
// decide which is first
// set n = to that position
// nsep is position of the next separator. changes in here.
long find_n(string &s, int nend, int &nsep)
// nsep is position of the next separator. changes in here.
{
long n;
nsep = s.find(tabledelim,nend);
long n2 = s.find('\n',nend);
long m = s.length() - 1;
if (nsep >= 0 && n2 >= 0) {
if (nsep <= n2) n = nsep;
else n = n2;
} else {
if (nsep >= 0) n = nsep;
else{
if (n2 < m) n = n2;
else n = string::npos;
}
}
return n;
}
| |