/********************************************************************** VUtils.cpp - utilities for Logical Developments in Verish version 0.95 ------------------- begin : circa August 1997 release date : 31 January 2013 copyright : (C) 1997 - 2013 by Chris Austin email : chris@chrisaustin.info **********************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include "Verish.h" using namespace std; void dispusg(); void rdfile(const char* flnm, string& infile); void wrtfile(const string infile); void testss(); void wrnprbs(const string infile); void bigrnum(string& infile); void addPr(string& infile); void insrtApps(string& infile, const string requestTit); void getMthReas(string& Sent, size_t& getpos, const string infile, size_t& Mthpos); void insrtblnks(string& Sent); void prpRpApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs); int isRp(const string Sent); void prpSaApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs); bool isSa(const string Sent); void prpScApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs); bool isSc(const string Sent); void addAo(string& infile); void addhtmkup(string& infile); void mvback(const string infile, size_t& pos); void bscPar(string& infile, size_t& Spos); void strtSent(const string infile, size_t& pos); // argc is total number of words in command line // argv[] is array of pointers to the command line words void VUtilsMain(const int argc, const char* argv[]) { string infile = "", notQnt = "", buf; char c; int n; if (argc < 2) dispusg(); else if (argc == 3) { buf = ""; n = 0; do { c = argv[2][n++]; if ( ( c >= '!' ) && ( c < 0x7f ) ) buf += c; } while (c); if ( buf == "-rf" ) { rdfile(argv[1], infile); wrtfile(infile); } else if ( buf == "-warnofprobs" ) { rdfile(argv[1], infile); wrnprbs(infile); } else if ( buf == "-bigrenum" ) { rdfile(argv[1], infile); bigrnum(infile); wrtfile(infile); } else if ( buf == "-addPr" ) { rdfile(argv[1], infile); addPr(infile); wrtfile(infile); } else if ( buf == "-addAo" ) { rdfile(argv[1], infile); addAo(infile); wrtfile(infile); } else if ( buf == "-addMthApps" ) { rdfile(argv[1], infile); try { insrtApps(infile, ""); } catch (int e) { if ( e == 0 ) cout << endl << endl; if ( e == 1 ) cout << endl; } catch (exception& e) { cout << "Standard exception: " << e.what() << endl; } wrtfile(infile); } else throw 3; } else if ( argc == 4 ) throw 3; else if ( argc == 5 ) { buf = argv[2]; if ( buf == "-addhtmlmkup" ) { rdfile(argv[1], infile); addhtmkup(infile); rdfile(argv[3], buf); infile.insert(0, buf); rdfile(argv[4], buf); infile += buf; wrtfile(infile); } } else if ( argc > 5 ) throw 3; } // display usage information void dispusg() { cout << "\nVerish 0.95. Copyright (c) Chris Austin, 1997 - 2013"; cout << "\nReasoning checker and utilities for files written in Verish"; cout << "\nUsage for reasoning checking:\n./Verish filespec"; cout << "\n Displays the Sentences in filespec, followed by appropriate messages,"; cout << "\n (such as Title, Abbreviation, Definition, Method, Reason, or Fact),\n"; cout << " until an error is detected, at which point an appropriate diagnostic is"; cout << "\n displayed, and the program terminates. All possible errors of"; cout << "\n reasoning are checked for.\n./Verish filespec Tit"; cout << "\n Checks the reasoning from the last occurrence of Tit as a Title onwards,"; cout << "\n on the assumption that there are no errors before that."; cout << "\nFor further usage information, please see http://verish.info"; cout << "\nLicensed under the Free Software Foundation General Public License.\n\n"; } // read a file void rdfile(const char* flnm, string& infile) { char c; ifstream sourcefile; bool openflag = false; infile = ""; sourcefile.open(flnm, ios::binary); if ( sourcefile ) openflag = true; else throw 2; while ( sourcefile.get(c) != 0 ) infile += c; cerr << endl << "infile.length() = " << infile.length() << endl; if ( openflag ) sourcefile.close(); } // write a file to cout void wrtfile(const string infile) { char c; size_t getpos = 0; while ( getpos < infile.length() ) { c = infile[getpos++]; cout << c; } } void wrnprbs(const string infile) { size_t pos1 = 0, pos2 = 0, pos3, pos4; string wrkTit, starTit, skTit; getSent(starTit, pos2, infile); getSent(wrkTit, pos1, infile); do { getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); while ( ( starTit.substr(0, 3) != "+**" ) && ( starTit != "" ) ) { getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); } if ( starTit != "" ) { cout << starTit << " " << pos2 << endl; pos4 = pos2; getSent(skTit, pos4, infile); getSent(skTit, pos4, infile); getSent(skTit, pos4, infile); while ( pos1 < pos2 ) { skTit = wrkTit + " "; pos3 = infile.find(skTit, pos4); if ( pos3 != string::npos ) { cout << endl << endl << "Title " << wrkTit << " precedes " << starTit; cout << " at pos2 around " << pos2; cout << ", but is found at pos3 = " << pos3; throw 0; } getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); } } } while ( starTit != "" ); } void bigrnum(string& infile) { size_t pos1 = 0, pos2 = 0, pos3, pos4, svpos1, posTit, pos5; string wrkTit, starTit, skTit, nwTit; stringstream tss; int numTit; getSent(starTit, pos2, infile); getSent(wrkTit, pos1, infile); while ( starTit != "" ) { svpos1 = pos1; getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); while ( ( starTit.substr(0, 3) != "+**" ) && ( starTit != "" ) ) { getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); getSent(starTit, pos2, infile); } if ( starTit != "" ) { pos5 = pos2; getSent(skTit, pos5, infile); numTit = 1; while ( pos1 < pos2 ) { skTit = wrkTit + " "; tss.str(""); tss << "+"; tss << numTit++; nwTit = tss.str() + " "; posTit = infile.find(skTit, svpos1); infile.replace(posTit, skTit.length(), nwTit); pos1 += (nwTit.length() - skTit.length()); pos2 += (nwTit.length() - skTit.length()); pos3 = pos1; while ( pos3 < pos5 ) { pos4 = infile.find(skTit, pos3); pos3 = pos4; if ( pos3 != string::npos ) { if ( pos3 >= pos5 ) { cout << endl << endl << "Title " << wrkTit << " precedes " << starTit; cout << " at pos5 around " << pos5; cout << ", but is found at pos3 = " << pos3; throw 0; } infile.replace(pos3, skTit.length(), nwTit); if ( pos3 < pos2 ) pos2 += (nwTit.length() - skTit.length()); } else pos3 = pos5; } getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); getSent(wrkTit, pos1, infile); } } } } void addPr(string& infile) { size_t pos = 0; string starTit; int numOpTit = 0; do { if ( numOpTit != 0 ) { cerr << endl << endl << "numOpTit should be 0 but = " << numOpTit; throw 0; } getSent(starTit, pos, infile); while ( ( starTit.substr(0, 3) != "+**" ) && ( starTit != "" ) ) { if ( isOpnTit(starTit) ) numOpTit++; getSent(starTit, pos, infile); getSent(starTit, pos, infile); getSent(starTit, pos, infile); } if ( ( numOpTit < 0 ) || ( numOpTit > 1 ) ) { cerr << endl << endl << "numOpTit should be 0 or 1 but = " << numOpTit; throw 0; } if ( numOpTit == 1 ) { infile.insert(pos, "+Pr "); pos += 4; numOpTit--; } getSent(starTit, pos, infile); getSent(starTit, pos, infile); } while ( starTit != "" ); } // insert the Applications of the automatic Methods, starting at the last occurrence of // requestTit if requestTit is not the null string, and otherwise at the start of infile void insrtApps(string& infile, const string requestTit) { size_t pos = 0, auxpos = 0, strts[STSSZ], Mthpos, lpos; int n; string Sent, auxfile = infile, Ap, Rs; initstrts(strts); bool failAp = false; if ( requestTit != "" ) { sklstTit(infile, requestTit, pos); if ( pos == string::npos ) { cout << endl << "Error seeking Title"; throw 0; } prpflsts(infile, strts, pos); pos = strts[nxtstrt(strts) - 1]; } do { lpos = auxpos = strts[nxtstrt(strts) - 1]; getSent(Sent, auxpos, auxfile); if ( Sent == "" ) break; if ( ( Sent != "+Df" ) && ( Sent != "+1Df" ) ) { auxpos = lpos; getMthReas(Sent, auxpos, auxfile, Mthpos); if ( ( Sent == "+Ao" ) && ( !failAp ) ) { getSent(Sent, Mthpos, auxfile); // work through the list of automatic Methods, looking for a match if ( isRp(Sent) >= 0 ) prpRpApp(auxfile, strts, Ap, Rs); else if ( isSa(Sent) ) prpSaApp(auxfile, strts, Ap, Rs); else if ( isSc(Sent) ) prpScApp(auxfile, strts, Ap, Rs); else { failAp = true; continue; } // the +Ao Reason has to be replaced, and the Method Application inserted, both // in auxfile and in infile if ( Ap != "" ) auxfile.replace(Mthpos, auxpos - Mthpos, Rs); auxpos = lpos; lpos = pos; getMthReas(Sent, pos, infile, Mthpos); getSent(Sent, Mthpos, infile); if ( Ap != "" ) infile.replace(Mthpos, pos - Mthpos, Rs); else { Ap = " \n(* Cannot form Method Application *) \n \n(* " + Rs + " *) \n \n"; failAp = true; } pos = lpos; auxfile.insert(auxpos, Ap); infile.insert(pos, Ap); continue; } } lpos = auxpos = strts[nxtstrt(strts) - 1]; getSent(Sent, auxpos, auxfile); auxpos = lpos; if ( ( Sent != "+Df" ) && ( Sent != "+1Df" ) ) { n = (nxtstrt(strts) - 1) - cntMthnfbAo(auxfile, auxpos); lpos = strts[n]; auxfile.erase(lpos, auxpos - lpos); n++; while ( n < STSSZ ) { if ( strts[n] == string::npos ) break; strts[n++] = string::npos; } getSent(Sent, lpos, auxfile); auxpos = lpos; getSent(Sent, auxpos, auxfile); while ( !isReason(Sent) ) { auxfile.erase(lpos, auxpos - lpos); auxpos = lpos; getSent(Sent, auxpos, auxfile); } } n = nxtstrt(strts) - 1; lpos = auxpos = strts[n]; nxtPar(auxfile, auxpos); getSent(Sent, lpos, auxfile); if ( isOpnTit(Sent) ) strts[n + 1] = auxpos; else strts[n] = auxpos; nxtPar(infile, pos); failAp = false; } while ( true ); } // if getpos is start of a Statement Paragraph, get the Reason into Sent and set getpos to // start of the Statement, and Mthpos to the start of the Sentence before the Reason void getMthReas(string& Sent, size_t& getpos, const string infile, size_t& Mthpos) { size_t savepos = getpos; string Tit; getSent(Tit, getpos, infile); do { Mthpos = savepos; savepos = getpos; getSent(Sent, getpos, infile); if ( ( nmSbjBrf(Sent) < 0 ) || ( Sent == "" ) ) { cout << "No Reason found after Title\n\n" << Tit; throw 0; } } while ( !isReason(Sent) ); } // put a blank space after each Word in Sent void insrtblnks(string& Sent) { size_t pos = 1; while ( pos < Sent.length() ) { pos = Sent.find_first_of("=-()+[]", pos); if ( pos != string::npos ) { Sent.insert(pos, " "); pos += 2; } else pos = Sent.length(); } Sent += " "; } // prepare the Application of +Rp/, and the new Reason, for a Statement Paragraph that // starts at strts[nxtstrt(strts) - 1], and has a +Rp/ Method followed by +Ao void prpRpApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs) { const size_t stpos = strts[nxtstrt(strts) - 1]; size_t pos = stpos, Mthpos, savepos; bool flag = true; string Sent, Tits[2], Sbjs[MXSBJ], Fcts[MXSBJ], buf1, buf2; getMthReas(Sent, pos, infile, Mthpos); getSent(Sent, Mthpos, infile); getSbjs(Sent, Sbjs); if ( Sbjs[0] != "+1" ) Tits[0] = "+1 "; else Tits[0] = "+1a "; if ( Sbjs[0] != "+2" ) Tits[1] = "+2 "; else Tits[1] = "+2a "; getSbjs(Sent, Fcts); TittoFact(infile, Fcts, strts); getSent(Sent, pos, infile); Ap = Tits[0] + "+Ex ) - "; pos = Mthpos = 0; while ( flag && ( pos < Sent.length() ) && ( Mthpos < Fcts[0].length() ) ) { savepos = pos; putWord(Sent, pos, buf1); putWord(Fcts[0], Mthpos, buf2); if ( buf1 != buf2 ) flag = false; } if ( flag ) { Ap = ""; Rs = "No substitution found"; } else { insrtblnks(Fcts[0]); insrtblnks(Sent); buf2.replace(0, 1, "["); Ap += buf2; Ap += " "; Ap += Fcts[0]; Ap += Sent; Ap += "\n"; Ap += Tits[1]; Ap += "+Gn/ "; Ap += Sbjs[0]; Ap += " "; Ap += buf2; Ap += " "; Ap += Fcts[0]; Ap += "\n"; Rs = "+Tb// " + Tits[0] + Tits[1]; } } // return -1 if the Sentence is not a +Rp/ Method, and 1 otherwise int isRp(const string Sent) { int count = nmSbjBrf(Sent); if (count != 1) count = -1; if ( Sent.length() < 4 ) count = -1; else if ( Sent.substr(0, 4) != "+Rp/" ) count = -1; return count; } // prepare the Application of +Sa/, and the new Reason, for a Statement Paragraph that // starts at strts[nxtstrt(strts) - 1], and has a +Sa/ Method followed by +Ao void prpSaApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs) { const size_t stpos = strts[nxtstrt(strts) - 1]; size_t pos = stpos, Mthpos; string Sent, Tits[3], Sbjs[MXSBJ], Wrd, SntA, SntB; getMthReas(Sent, pos, infile, Mthpos); getSent(Sent, Mthpos, infile); getSbjs(Sent, Sbjs); if ( Sbjs[0] != "+1" ) Tits[0] = "+1 "; else Tits[0] = "+1a "; if ( Sbjs[0] != "+2" ) Tits[1] = "+2 "; else Tits[1] = "+2a "; if ( Sbjs[0] != "+3" ) Tits[2] = "+3 "; else Tits[2] = "+3a "; getSent(Sent, pos, infile); Ap = ""; pos = 0; putWord(Sent, pos, Wrd); if ( Wrd != ")" ) Rs = "Statement does not begin with )"; else { getSent(SntB, pos, Sent); putWord(Sent, pos, Wrd); if ( Wrd != "-" ) Rs = "Second Subject of ) does not begin with -"; else { putWord(Sent, pos, Wrd); if ( Wrd[0] != ']' ) Rs = "Second Word of second Subject of ) does not begin with ]"; else { getSent(SntA, pos, Sent); insrtblnks(SntA); insrtblnks(SntB); Wrd.replace(0, 1, "["); Wrd += " "; Ap = Tits[0] + "+Gn/ " + Sbjs[0] + " " + Wrd + ") " + SntB + "- " + SntA + "\n"; Ap += (Tits[1] + "+Fc/ " + Tits[0] + ") " + SntB + Wrd + "- " + SntA + "\n"); Ap += (Tits[2] + "+Tb/ " + Tits[1] + ") " + SntB + "- - " + Wrd + "- " + SntA + "\n"); Rs = "+Sm/ " + Tits[2]; } } } } // return true if Sent is a +Sa/ Method, and false otherwise bool isSa(const string Sent) { bool flag = true; int count = nmSbjBrf(Sent); if (count != 1) flag = false; if ( Sent.length() < 4 ) flag = false; else if ( Sent.substr(0, 4) != "+Sa/" ) flag = false; return flag; } // prepare the Application of +Sc/, and the new Reason, for a Statement Paragraph that // starts at strts[nxtstrt(strts) - 1], and has a +Sc/ Method followed by +Ao void prpScApp(const string infile, const size_t strts[STSSZ], string& Ap, string& Rs) { const size_t stpos = strts[nxtstrt(strts) - 1]; size_t pos = stpos, Mthpos; bool flag = true; string Sent, Tits[2], Sbjs[MXSBJ], Fcts[MXSBJ], Wrd, SntA, SntB, SntD; getMthReas(Sent, pos, infile, Mthpos); getSent(Sent, Mthpos, infile); getSbjs(Sent, Sbjs); if ( Sbjs[0] != "+1" ) Tits[0] = "+1 "; else Tits[0] = "+1a "; if ( Sbjs[0] != "+2" ) Tits[1] = "+2 "; else Tits[1] = "+2a "; getSbjs(Sent, Fcts); TittoFact(infile, Fcts, strts); getSent(Sent, pos, infile); Ap = ""; pos = 0; putWord(Fcts[0], pos, Wrd); if ( Wrd != ")" ) { Rs = "Earlier Statement does not begin with )"; flag = false; } if ( flag ) { putWord(Fcts[0], pos, Wrd); if ( Wrd != "-" ) { Rs = "Second Word of earlier Statement is not -"; flag = false; } } if ( flag ) { getSent(SntA, pos, Fcts[0]); getSent(SntB, pos, Fcts[0]); pos = 0; putWord(Sent, pos, Wrd); if ( Wrd != ")" ) { Rs = "Statement does not begin with )"; flag = false; } } if ( flag ) { putWord(Sent, pos, Wrd); if ( Wrd != "-" ) { Rs = "Second Word of Statement is not -"; flag = false; } } if ( flag ) { getSent(SntA, pos, Sent); putWord(Sent, pos, Wrd); if ( Wrd[0] != ']' ) { Rs = "Second Subject of ) does not begin with ]"; flag = false; } } if ( flag ) { getSent(SntD, pos, Sent); insrtblnks(SntA); insrtblnks(SntB); insrtblnks(SntD); Wrd.replace(0, 1, "["); Wrd += " "; Ap = Tits[0] + "+Ex ) - " + Wrd + "- " + SntD + "- " + SntB + "\n"; Ap += (Tits[1] + "+Tb// " + Sbjs[0] + " " + Tits[0]); Ap += (") - " + SntA + "- " + Wrd + "- " + SntD + "\n"); Rs = "+Sm/ " + Tits[1]; } } // return true if Sent is a +Sc/ Method, and false otherwise bool isSc(const string Sent) { bool flag = true; int count = nmSbjBrf(Sent); if (count != 1) flag = false; if ( Sent.length() < 4 ) flag = false; else if ( Sent.substr(0, 4) != "+Sc/" ) flag = false; return flag; } void addAo(string& infile) { size_t pos = 0; string Sent; do { getSent(Sent, pos, infile); if ( !isNoun(Sent) && ( Sent != "" ) ) { cerr << "\n\nNot a Title\n\n"; cerr << "pos = " << pos << "\n\n"; throw 0; } getSent(Sent, pos, infile); if ( Sent == "+Pr" ) getSent(Sent, pos, infile); if ( isRp(Sent) == 1 ) { infile.insert(pos, "+Ao "); pos += 4; } getSent(Sent, pos, infile); } while ( Sent != "" ); } void addhtmkup(string& infile) { size_t Parpos = 0, pos, savepos, Spos, nxtPpos, varpos, prsts[STSSZ]; int n1, n2 = 0, numvar = 1; stringstream tss; string Sent, Apvars = "", elmnt, revApv, numbuf1, numbuf2, numtl, saveSent; bool frstMth; while ( n2 < STSSZ ) prsts[n2++] = string::npos; do { pos = Parpos; getSent(Sent, pos, infile); saveSent = Sent; if ( Sent == "" ) break; Spos = Parpos; // set Spos to the actual start position of the Sentence strtSent(infile, Spos); // markup any Comments between Parpos and Spos pos = Parpos; while ( pos < Spos ) { pos = infile.find_first_of("=-()+[]", pos); if ( pos == Spos ) break; if ( infile.substr(pos, 2) == "(^" ) { infile.insert(pos, "

"); pos = infile.find("^)", pos + 20); infile.insert(pos + 2, "

"); pos += 6; Spos += 22; continue; } else if ( infile.substr(pos, 2) == "(_" ) { infile.insert(pos, "

"); pos = infile.find("_)", pos + 20); infile.insert(pos + 2, "

"); pos += 6; Spos += 22; continue; } else if ( infile.substr(pos, 2) == "({" ) { infile.insert(pos, "

"); pos = infile.find("})", pos + 5); infile.insert(pos + 2, "

"); pos += 6; Spos += 7; continue; } else if ( infile.substr(pos, 2) == "[[" ) { infile.insert(pos, "

"); pos = infile.find("]]", pos + 21); infile.insert(pos + 2, "

"); pos += 7; Spos += 24; continue; } else if ( infile.substr(pos, 2) == "[(" ) { infile.insert(pos, "

"); pos = infile.find(")]", pos + 21); infile.insert(pos + 2, "

"); pos += 7; Spos += 24; continue; } else if ( infile.substr(pos, 2) == "[-" ) { infile.insert(pos, "

"); pos = infile.find("-]", pos + 21); infile.insert(pos + 2, "

"); pos += 7; Spos += 24; continue; } else { infile.resize(pos + 2); cout << infile << endl << endl; cout << "Unrecognized Comment type"; throw 0; } } nxtPpos = pos; nxtPar(infile, nxtPpos); while ( pos < nxtPpos ) { pos = infile.find('&', pos); if ( pos == string::npos ) pos = infile.length(); if ( pos < nxtPpos ) { infile.replace(pos, 1, "&"); pos += 5; nxtPpos += 4; } } pos = Spos; while ( pos < nxtPpos ) { pos = infile.find('<', pos); if ( pos == string::npos ) pos = infile.length(); if ( pos < nxtPpos ) { infile.replace(pos, 1, "<"); pos += 4; nxtPpos += 3; } } pos = Spos; while ( pos < nxtPpos ) { pos = infile.find('>', pos); if ( pos == string::npos ) pos = infile.length(); if ( pos < nxtPpos ) { infile.replace(pos, 1, ">"); pos += 4; nxtPpos += 3; } } pos = Spos; n1 = 0; if ( ( Sent != "+Df" ) && ( Sent != "+1Df" ) ) { n1 = cntMthnfbAo(infile, pos); if ( n1 == 0 ) bscPar(infile, Spos); else { elmnt = "\n"; infile.insert(Spos, elmnt); Spos += elmnt.length(); n2 = 0; while ( n2 < n1 ) { infile.insert(Spos, ""); Spos += 6; n2++; } elmnt = "\n 0 ) { varpos = revApv.rfind("+"); if ( varpos == string::npos ) { infile.resize(nxtPpos); cout << infile << endl << endl; cout << "The number of Methods not followed by +Ao has effectively exceeded the"; cout << "number\nof Opening Titles"; throw 0; } revApv.resize(varpos); n2--; } putWord(Apvars, varpos, numbuf1); numbuf1.erase(0, 1); numtl = numbuf1; elmnt += numbuf1; elmnt += ">\n"); Spos = savepos + 5; frstMth = true; do { elmnt = ""); Spos = savepos + 5; if ( numbuf2 != "" ) numbuf1 = numbuf2; } while ( numbuf2 != "" ); elmnt = ""); Spos = savepos + 5; elmnt = "\n\n
"; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); if ( !isReason(Sent) ) getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); elmnt = "
"; infile.insert(Spos, elmnt); Spos = savepos + elmnt.length(); Apvars = revApv; } } else bscPar(infile, Spos); n2 = nxtstrt(prsts) - n1; // if this returns, then n2 < STSSZ - n1 if ( n2 < 0 ) { cout << "\nThe number of Methods not followed by +Ao is greater than the number"; cout << "\nof Opening Titles"; throw 0; } if ( isOpnTit(saveSent) ) { elmnt = "
\n"; if ( n1 == 0 ) { infile.insert(pos, elmnt); prsts[n2] = pos; } else { infile.insert(prsts[n2++], elmnt); while ( prsts[n2] != string::npos ) prsts[n2++] = string::npos; } Spos += elmnt.length(); } else while ( prsts[n2] != string::npos ) prsts[n2++] = string::npos; Parpos = Spos; } while ( true ); } // decrease pos until the character that precedes it in infile is a Letter void mvback(const string infile, size_t& pos) { char c; do { c = infile[pos - 1]; if ( ( c < '!' ) || ( c > 0x7e ) ) pos--; } while ( ( c < '!' ) || ( c > 0x7e ) ); } // insert the html markup for a basic 3-effective-Sentence Paragraph whose actual start // position is Spos, and set Spos to an effective start position for the next Paragraph void bscPar(string& infile, size_t& Spos) { size_t savepos; bool Aoflag = false; string Sent, elmnt; elmnt = "\n"); Spos = savepos + 5; elmnt = "\n"); Spos = savepos + 5; elmnt = "\n"); Spos = savepos + 5; elmnt = "\n\n
"; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); if ( ( Sent != "+Df" ) && ( Sent != "+1Df" ) ) Aoflag = true; savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); getSent(Sent, Spos, infile); if ( Aoflag ) if ( isReason(Sent) ) Aoflag = false; savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); if ( Aoflag ) { getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); infile.insert(Spos, ""; infile.insert(Spos, elmnt); Spos += elmnt.length(); } getSent(Sent, Spos, infile); savepos = Spos; mvback(infile, Spos); elmnt = "
"; infile.insert(Spos, elmnt); Spos = savepos + elmnt.length(); } // if pos is an effective start position of a non-null Sentence, set pos to the actual start // position, assuming that the last two Letters in a Comment are consecutive void strtSent(const string infile, size_t& pos) { size_t savepos; char c1, c2; string endCmnt; while ( true ) { pos = infile.find_first_of("=-()+[]", pos); savepos = pos; c1 = infile[pos++]; c2 = ' '; while ( ( c2 < '!' ) || ( c2 > 0x7e ) ) c2 = infile[pos++]; if ( ( c1 != '+' ) && ( c1 != '[' ) && ( c1 != ']' ) ) { if ( isInitial(c2) ) break; } else if ( !isCapital(c2) ) break; endCmnt = ""; endCmnt += possreverse(c2); endCmnt += possreverse(c1); pos = infile.find(endCmnt, pos) + 2; } pos = savepos; }