#include "canvas.h" #include "figures.h" #include "lexer.h" #include "parser.h" #include "drawing.h" #include // THE MAIN PROGRAM // COMMAND LINE ARGUMENTS: [ bin|ascii ] int main(int argc, char* argv[]) { parser P; drawable_list L; if (argc<3) { cerr << argv[0] << " [ bin|ascii ]" << endl; return 1; } bool ascii = true; // by default if (argc==4) { if (strcmp(argv[3],"bin") ==0) { ascii = false; } else if (strcmp(argv[3],"ascii")!=0) { cerr << "bin or ascii expected instead of \"" << argv[3] << "\"" << endl; return 1; } } ifstream ifs(argv[1]); if (!ifs) { cerr << "could not open \"" << argv[1] << "\" for reading" << endl; return 1; } try { // parse file P.parse(L,ifs); } catch (lexer_error& le) { cerr << "error: " << le.error << " near line: " << le.line_number << endl; return 1; } catch (parse_error& pe) { cerr << "error: " << pe.error << " near line: " << pe.line_number << endl; return 1; } ifs.close(); // create a canvas canvas C(P.x_resolution(),P.y_resolution()); // render the figures drawing::render(L,C); ofstream ofs(argv[2]); if (!ofs) { cerr << "could not open \"" << argv[2] << "\" for writing" << endl; return 1; } // create PPM file if (ascii) C.dump_text_PPM(ofs); else C.dump_binary_PPM(ofs); ofs.close(); // done return 0; }