// bytemark - version 1.00.web1, Rupert Scammell fib@lumiere.net // The latest version of this code may be found at http://lumiere.net/~fib/code.html // This code is public domain. #include #include #include #include // uncomment this for most compilers: //using namespace std; int main(void) { string wordstring; string currentfirst; string currentsecond; string backrefstr; long byteoffset; int repeated = 0; ofstream bookmarkFile("bytemarkMoby"); ifstream MobyPOS("mobyposi"); ofstream BackRefOut("mobyrepdata"); cout << "Bytemark Moby POS bookmark generator. Standby.." << endl; if (BackRefOut.fail()) { cerr << "Repetition data file could not be written. Halted." << endl; return 1; } BackRefOut << "#" << endl; // so we append. BackRefOut.close(); if (MobyPOS.fail()) { cerr << "Moby POS Database not found. Halted." << endl; return 1; } if (bookmarkFile.fail()) { cerr << "Bookmark file could not be written. Halted" << endl; return 1; } cout << "I/O files opened successfully... beginning bookmark process." << endl; byteoffset = 0; while (!MobyPOS.eof()) { getline(MobyPOS, wordstring); byteoffset = byteoffset+ wordstring.length(); if (wordstring.substr(0, 1) == currentfirst && wordstring.substr(1, 1) != currentsecond) { ifstream BackRef("mobyrepdata"); repeated = 0; //make sure the loop starts off assuming a repeat ! occurred. while (!BackRef.eof() && repeated != 1) { getline(BackRef, backrefstr); if (backrefstr == wordstring.substr(0, 2)) { repeated = 1; BackRef.close(); } } if (repeated == 0) { BackRef.close(); ofstream BackRefOut("mobyrepdata", ios::out | ios::ate); if (BackRefOut.fail()) { cerr << "Moby Rep Data file could not be appended. Halted." << endl; return 1; } BackRefOut << wordstring.substr(0, 1) << wordstring.substr(1, 1) << endl; BackRefOut.close(); bookmarkFile << wordstring.substr(0, 1) << wordstring.substr(1, 1) << "*" << byteoffset <