// Oldham, Jeffrey D. // 2000Mar13 // CS1321 // Modified by: // Massingill, Berna L. // 2000 March // Brain-Dead String Editor // Based on Eric Roberts's \emph{Programming Abstractions in C}, chapter~9. #include #include // has EXIT_SUCCESS #include #include // has tolower() #include "buffer-2.h" using namespace std; int main() { buffer b; string command; char prompt[] = "command? (? for help)> "; char help[] = " to display line\n" "b to move cursor left\n" "f to move cursor right\n" "d to delete character\n" "iXYZQ to insert XYZQ\n" "q to quit\n"; cout << prompt; while (getline(cin, command)) { if (command.size() > 0) { char c = tolower(command[0]); if (c == '?') cout << help; else if (c == 'b') b.backCursor(); else if (c == 'f') b.forwardCursor(); else if (c == 'd') b.deleteChar(); else if (c == 'i') b.insertChars(command.substr(1)); // extract all but the first character else if (c == 'q') break; // exit loop else cerr << "Illegal command\n"; } cout << b << endl; printCursor(cout, b) << endl; cout << prompt; } return EXIT_SUCCESS; }