//*********************************************** // Simple Message Filer (Version1) // This implementation introduces the message and messageFolder objects // Uses Message Class Objects (message.h) // Each Message is stored in a separate file // Each Message Folder contains a file which contains Message Header for each Message in the folder // The Message Folder is also encapsulated in a class. (messageFolder.h) // FILE IO: // terminal input and output uses c++'s cin and cout operators // However for file I/O we use win32 file routines // even though c++ or c's file I/O may be more preferable because of // its portability. We are here to learn windowsNT not c++ // USER INTERFACE: // It's single character command driven with integer message numbers as appropriate. // Accepts both upper and lower case commands. // L: List the messages currently available // A: Adds a new message to the end of the list // D #: Deletes message # from list (actually just marks it for deletion) // S #: shows message # // I folderName: inputs message list in folderName // O [folderName]: outputs message to folderName(default is input folderName) // H: prints commands (also ?) will work // Q: quit program // There can be only one blank between I or O and the folderName ( pretty ugly huh?) // Messages are arbitrarily numbered from 1 to the last message // Messages consist of a topic( up to 50 characters) and text (up to 300) // Editing of existing messages is not supported in this version. // AUTHOR: chris wild // DATE: July 29. 1997 //************************************************* #include "Message.h" #include "MsgFolder.h" #include "worker.h" // access to the worker functions #include void main() { char folderName[50] = ""; // file name as string char command; int messageNum; CMsgFolder folder; char helpMsg[] = "\nO(pen Message Folder) folder , L(ist messages), A(dd message)\n\ D(elete) #, S(how) #, C(lose Folder) [folder], H(elp)\n"; cout << " Welcome to the Message Filer (version 1):\n\n"; cout << helpMsg; do { cout << "% " ; // prompt cin >> command; switch (command) { case 'L': case 'l': listMsgs(folder); break; case 'A': case 'a': cin.ignore(); addMsg(folder); break; case 'D': case 'd': cin >> messageNum; cin.ignore(); // newline deleteMsg(messageNum, folder); break; case 'S': case 's': cin >> messageNum; cin.ignore(); // newline showMsg(messageNum, folder); break; case 'O': case 'o': cin.ignore(); // blank after command cin.getline(folderName,50); if (!folder.OpenMsgFolder((const char*)folderName)) cerr << folderName << " could not be opened\n"; break; case 'C': case 'c': cin.ignore(); folder.CloseMsgFolder(); break; case 'H': case 'h': case'?': cin.ignore(); cout << helpMsg; break; case 'Q': case 'q': command = 'Q'; // make it upper case for ease of testing break; default: cout << "\nbad command: " << command << "; skipping rest of line\n"; do cin.get(command); while (command != '\n'); break; } } while (command != 'Q'); }