// Programmer: Gregory A. Perkins // Class: CS 66 // Due: 2 May 1997 // Basic line editor program with the ability to IN - Insert new lines, // DL - delete current line, MV n - move n lines in current list, // LA - list all from current line to the end, && XT - exit #include#include #include "LineList.h" #define NUM_CMDS 5 // Number of commands global for future probable money-making updates :) //=================================> Function Prototypes <================================== void Welcome(); // POST: cout << Cheesy message void DisplayCommands(); // POST: cout << Confusing list of commands displayed int GetCommands(int& arg); // PRE: arg is assigned && // USER MUST HAVE INTEREST IN OPERATING A LINE EDITOR // POST: 0 <= FCTVAL <= 4 && // if move command executed, arg assigned number of lines to move //=================================> Function Definitions <================================= //=================================> main <================================= int main() { char newLine[81]; int choice; int moveArg = 0; // Variable used to hold the argument for the move command Welcome(); // "Cheese!!!" LineList info; // An instance of LineList has been created while ((choice = GetCommands(moveArg)) < NUM_CMDS - 1) // numCmds - 1 represents exit cmd { switch (choice) { case 0: while (cin.getline(newLine, 81) && (strcmp(newLine, "//"))) { //if (!strcmp(newLine, "//")) // break; info.insert(newLine); } break; case 1: info.remove(); info.display_current(); break; case 2: if (moveArg >= 0) { info.advance(moveArg); info.display_current(); } else { info.backup(moveArg); info.display_current(); } break; case 3: info.display(); break; } } return (0); } //=================================> Welcome <================================= void Welcome() { cout << "Welcome to the Line Editor Version 3.14157 !!!" << endl << "*** Commands must be entered in ALL CAPS ***" << endl << "For a listing of all commands, you MUST purchase :" << endl << "Data Abstraction and Structures Using C++, by Headington && Riley." << endl << "Cost: $55.35 Page: 384" << endl << endl << endl; return; } //=================================> DisplayCommands <================================= void DisplayCommands() { cout << endl << "C:\\> "; return; } //=================================> GetCommands <================================= int GetCommands(int& arg) { char cmdStr[2]; char* cmds[NUM_CMDS] = {"IN", "DL", "MV", "LA", "XT"}; while (1) { DisplayCommands(); cin >> cmdStr; if(!strcmp(cmdStr, "MV")) cin >> arg; // get 'move' command argument out of the stream cin.ignore(50, '\n'); // clear the stream for future operations for (int i = 0; i < 5; i++) if (!strcmp(cmdStr, cmds[i])) return i; } }