//File sdcsdr.cpp #include "bstree.h" #include "document.h" #include #include #include #include class indexDriver { public: indexDriver(char *fName, char *cwfName); void makePhrase(char aWord[80], char* aPhrase, char* predecessor); }; indexDriver::indexDriver(char *fName, char *cwfName) { document cwfDoc(cwfName), aDoc(fName); binstree aCwList, ignoreWList, userWList, phraseList, anIndexWriter; while (!cwfDoc.endofdocument) { char cWord[80]; int aPage; cwfDoc.getwordandpage(cWord, aPage); information item(cWord, aPage); aCwList.insert(item); } // end of while loop. char predecessor[80]; for (int k = 0; k < 80; k++) { predecessor[k] = '\0'; } cout << "\t **********************************************\n" << "\t * Welcome to BHJ's Index Writer *\n" << "\t **********************************************\n\n"; while (!aDoc.endofdocument) { char aWord[80], phrase[80]; int page; aDoc.getwordandpage(aWord, page); // Create ignore word list, user word list, and index word list: if (!aCwList.search(aWord) && !ignoreWList.search(aWord) && !userWList.search(aWord)) { makePhrase(aWord, phrase, predecessor); information anItem(aWord, page); information phraseItem(phrase, page); if (anIndexWriter.search(aWord)) { anIndexWriter.insert(anItem); if (anIndexWriter.search(phrase)) anIndexWriter.insert(phraseItem); } else { char choice; cout << "\t******************************************************\n" << "\t Choice Menu for word \"" << aWord << "\" \n" << "\ti) Ignore this word \n" << "\tu) Place word \"" << aWord << "\" in user word list \n" << "\tp) Add phrase \"" << phrase << "\" into the index list \n" << "\to) Other choices place word \"" << aWord << "\" into index list\n" << "\t******************************************************\n" << "\n\tYour Choice => "; //<< "\t* *Any other entry will place the " << aWord // << " into the index list \n"; cin >> choice; char upperChoice = toupper(choice); if ((upperChoice == 'I') || (upperChoice == 'U') || (upperChoice == 'P') ) { switch (choice) { case 'i': case 'I': ignoreWList.insert(anItem); break; case 'u': case 'U': userWList.insert(anItem); break; case 'p': case 'P': anIndexWriter.insert(phraseItem); anIndexWriter.insert(anItem); phraseList.insert(phraseItem); break; default: cout << "You should not get at all !!\n"; break; } } else { anIndexWriter.insert(anItem); } } // end of else. } } // end of while loop. cout << "\n\n"; cout << "==================\n"; cout << "The Index list is:\n"; cout << "==================\n"; anIndexWriter.traverse(INORDER); cout << "\n\n"; cout << "========================\n"; cout << "The common word list is:\n"; cout << "========================\n"; aCwList.traverse(INORDER); cout << "\n\n"; cout << "========================\n"; cout << "The ignore word list is:\n"; cout << "========================\n"; ignoreWList.traverse(INORDER); cout << "\n\n"; cout << "======================\n"; cout << "The user word list is:\n"; cout << "======================\n"; userWList.traverse(INORDER); cout << "\n\n"; cout << "===================\n"; cout << "The phrase list is:\n"; cout << "===================\n"; phraseList.traverse(INORDER); } void indexDriver::makePhrase(char aWord[80], char* phrase, char* predecessor) { //char phrase[80]; int i = 0; for (i = 0; i < 80; i++) { phrase[i] = '\0'; } i = 0; while (predecessor[i] != '\0') { phrase[i] = predecessor[i]; i++; } phrase[i] = ' '; i++; int j = 0; while (aWord[j] != '\0') { phrase[i] = aWord[j]; predecessor[j] = aWord[j]; j++; i++; } for (int m = j; m < 80; m++) { // clear the rest of the array. predecessor[m] = '\0'; } } int main(int argc, char *argv[]) { char* fileName = ""; if (argc != 3) { cout << "Incorrect number of command line arguments" << endl; cout << "Usage: sdcsdr \n"; exit(1); } else { fileName = new char[strlen(argv[1]) + 1]; strcpy(fileName, argv[1]); } indexDriver anIndexDriver(fileName, argv[2]); return 0; }