// Oldham, Jeffrey D. // 2000Mar13 // CS1321 // Brain-Dead String Editor // based on Eric Roberts's \emph{Programming Abstractions in C}, chapter~9. #include #include // has EXIT_SUCCESS #include // has tolower() #include "buffer.h" #include #define STRLNG 1000 // can't use string class; mtrace problem #include // has C-string functions int main() { mtrace(); buffer b; char command[STRLNG]; cerr << "prompt> "; while (cin.getline(command, STRLNG)) { if (strlen(command) > 0) { char c = tolower(command[0]); if (c == 'b') b.backCursor(); else if (c == 'f') b.forwardCursor(); else if (c == 'd') b.deleteChar(); else if (c == 'i') b.insertChars(command+1); // extract all but the first character else if (c == '^') b.front(); else if (c == '$') b.back(); else if (c == '#') ; // ignore comments else if (c == 'q') return EXIT_SUCCESS; // quit else cerr << "Illegal command\n"; } cout << b << endl; printCursor(cout, b) << endl; cerr << "prompt> "; } return EXIT_SUCCESS; }