/* * simple main program to illustrate the facilities */ #include "config.h" #ifdef HAVE_GETOPT_H #include #else #include "getopt.h" #endif #include #include #include #include #include #include "lsys.h" #include "interp.h" #include "interface.h" #include "tokens.h" // antlr has problems without! #include "Parser.h" #include "ps_int.h" #include "gl_int.h" #include "rad_int.h" #include "ray_int.h" using namespace std; static struct option options[] = { { "interface" , required_argument , 0, 'f' }, { "interpreter" , required_argument , 0, 'i' }, { "output" , required_argument , 0, 'o' }, { "show-depth" , required_argument , 0, 'd' }, { "module" , required_argument , 0, 'm' }, { "help" , no_argument , 0, 'h' }, { 0 , 0 , 0, 0 }, }; void usage(int ret) { cerr << "\n" PACKAGE " version " VERSION ", a l-system exploration system\n" "written by Marc Lehmann You can find more info at\n" "http://www.plan9.de/ or http://www.goof.com/pcg/marc/lsys.html\n" "\n" "USAGE: lsys [options] sourcefile [min [max [step]]]\n" " where options are:\n" " [ -h | --help ] this help\n" " [ -m | --module string ] use a specific module as seed\n" " [ -i | --interpreter int ] select an interpreter [turtle2d, turtle3d]\n" " [ -f | --interface iface ] select an interface [ps, gl, rad, ray]\n" " [ -d | --show-depth depth ] show evaluated system\n" " [ -o | --output dest ] select an output destination\n" " [ -I | --include path ] search includes also in path\n" "\n"; exit (ret); } int verbose = 0; int main(int argc, char *argv[]) try { char c; int option_index = 0; gfx_int *iface = 0; interpreter *inter = 0; ostream *ofile = 0; char *outfile_str = 0; const char *interpreter_str = "turtle"; const char *interface_str = "gl"; char *module_str = 0; double min, max, step; int show_depth = 0; lsys root_lsys; while ((c = getopt_long (argc, argv, "hm:o:I:f:i:d:v", options, &option_index)) != -1) switch (c) { case 'm': module_str = optarg; break; case 'i': interpreter_str = optarg; break; case 'f': interface_str = optarg; break; case 'o': outfile_str = optarg; break; case 'I': include_dirs.push_back (string (optarg)); break; case 'd': show_depth = atoi (optarg); break; case 'v': verbose++; break; case ':': fprintf (stderr, "required argument missing, try -h for help.\n"); exit (1); case '?': fprintf (stderr, "unknown option, try -h for help.\n"); exit (1); case 'h': default: usage (1); } if (outfile_str) ofile = new ofstream (outfile_str); if (!interface_str) throw error ("you _must_ specify an interface"); else if (strcmp (interface_str, "ps") == 0 || strcmp (interface_str, "postscript") == 0) ofile ? (void) (iface = new ps_int (*ofile)) : throw error ("output file required for postscript interface"); else if (strcmp (interface_str, "rad") == 0 || strcmp (interface_str, "radiance") == 0) ofile ? (void) (iface = new rad_int (*ofile)) : throw error ("output file required for radiance interface"); else if (strcmp (interface_str, "ray") == 0 || strcmp (interface_str, "rayshade") == 0) ofile ? (void) (iface = new ray_int (*ofile)) : throw error ("output file required for rayshade interface"); else if (strcmp (interface_str, "gl") == 0 || strcmp (interface_str, "opengl") == 0) #if HAVE_OPENGL iface = new gl_int (); #else throw error ("this binary was compiled without opengl support"); #endif else throw error ("unknown interface"); if (!interpreter_str) throw error ("you _must_ specify an interpreter"); else if (strcmp (interpreter_str, "turtle2d") == 0) inter = new turtle_interpreter (*iface, true); else if (strcmp (interpreter_str, "turtle3d") == 0 || strcmp (interpreter_str, "turtle") == 0) inter = new turtle_interpreter (*iface, false); else throw error ("unknown interface\n"); if (optind >= argc) throw error ("you have to specify at least a source file"); if (optind < argc) parse_file (argv [optind++], root_lsys); if (optind < argc) min = atof (argv [optind++]); else min = 1; if (optind < argc) max = atof (argv [optind++]); else max = 1000; if (optind < argc) step = atof (argv [optind++]); else step = 1; if (verbose) cout << endl << root_lsys << endl << "evaluating from " << min << " to " << max << " stepsize " << step << endl; simple_interpreter s_int(show_depth); while (min <= max) { module seed(module_str ? module_str : root_lsys.str, min); module_vec v(root_lsys (seed.wrap ())); if (verbose) cout << "STEP " << min << ": " << v << endl; s_int (v, root_lsys); (*inter) (v, root_lsys); min += step; } if (inter) delete inter; if (iface) delete iface; if (ofile) delete ofile; return 0; } catch (const error &e) { cerr << e; return 1; }