#include "screen.h" #include #include #include const int BUFLENGTH = 80; const int CMDLENGTH = 10; void fatalError( char msg[] ) { cerr << msg << endl; exit( -1 ); } /* readChar expects to read in something of the form 'c' where c is some * arbitrary character. it ignores all characters before the first ' */ char readChar( istream& is ) { char ch; char ret; while( is.get( ch ) && (ch != '\'') ); if( !is ) { fatalError( "Bad char" ); } is.get( ret ); is.get( ch ); if( ch != '\'' ) { fatalError( "Bad char" ); } return ret; } /* readText reads in text of the form "text" where text is some arbitrary * character string */ bool readText( istream& is, char buf[] ) { char ch; int idx = 0; while( is.get( ch ) && (ch != '"') ); while( is.get( ch ) ) { if( ch == '"' ) { buf[idx] = '\0'; return true; } else { buf[ idx++ ] = ch; } } return false; } int main( void ) { char cmd[ CMDLENGTH ]; int col, row, width, height; char fill; char ch; Screen screen; while( cin >> cmd ) { if( strcmp( cmd, "fill" ) == 0 ) { fill = readChar( cin ); screen.fill( fill ); } else if( strcmp( cmd, "hline" ) == 0 ) { cin >> col >> row >> width; fill = readChar( cin ); if( !screen.horizontalLine( col, row, width, fill ) ) { cerr << "Error." << endl; } } else if( strcmp( cmd, "vline" ) == 0 ) { // insert implementation here // should be implemented using readChar } else if( strcmp( cmd, "rectangle" ) == 0 ) { // insert implementation here // should be implemented using readChar } else if( strcmp( cmd, "text" ) == 0 ) { // insert implementation here // should be implemented using readText } else if( strcmp( cmd, "ctext" ) == 0 ) { // insert implementation here // should be implemented using readText } else if( strcmp( cmd, "load" ) == 0 ) { // insert implementation here } else if( strcmp( cmd, "save" ) == 0 ) { // insert implementation here } else if( strcmp( cmd, "print" ) == 0 ) { // insert implementation here } else if( strcmp( cmd, "quit" ) == 0 ) { // insert implementation here } else { // insert implementation here } } return 0; }