home *** CD-ROM | disk | FTP | other *** search
- /*
- * main.C
- *
- * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
- * University of Berne, Switzerland
- * All rights reserved.
- *
- * This software may be freely copied, modified, and redistributed
- * provided that this copyright notice is preserved on all copies.
- *
- * You may not distribute this software, in whole or in part, as part of
- * any commercial product without the express consent of the authors.
- *
- * There is no warranty or other guarantee of fitness of this software
- * for any purpose. It is provided solely "as is".
- *
- */
-
- #include <stdio.h>
- #include <stream.h>
- #include <stdlib.h>
- #include <new.h>
-
- #include "globals.h"
- #include "Options.h"
- #include "LSystem.h"
- #include "Interpreter.h"
- #include "Color.h"
- #include "BBoxDevice.h"
- #include "ExampleDevice.h"
- #include "RayshadeDevice.h"
- #include "FlatDevice.h"
-
- #ifdef SUPPORT_X11
- # include "LineDevice.h"
- # include "WireDevice.h"
- # include "X11_Window.h"
- #endif
-
- #ifdef SUPPORT_AMIGA
- # include "LineDevice.h"
- # include "WireDevice.h"
- # include "AMIGA_Window.h"
- #endif
-
- extern int yyparse(void);
- extern LSystem* lsystem;
- extern FILE* yyin;
-
- void memory_error_handler();
-
- int main(int argc, char** argv)
- {
- #if !defined(__GNUC__) && !defined (_AIX) && !defined(__DECCXX)
- mallopt(M_MXFAST, 32);
- #endif
-
- set_new_handler(memory_error_handler);
-
- /*
- * Parse the command line options to get name of input file.
- */
- parseOptions(argc, argv);
- Color::setupColors();
-
- rcString cmd(CPP_NAME);
-
- if (theOptions.iname != "cin")
- cmd = cmd + " " + theOptions.iname + theOptions.optionsForCPP;
- else
- cmd = cmd + " " + theOptions.optionsForCPP;
-
- if ((yyin = popen(cmd.chars(), "r")) == NULL)
- Error(ERR_PANIC, theOptions.iname + ": no such file");
-
- if (!yyparse()) {
- /*
- * Parse a second time, because command line options overrides
- * the settings in lsys-file.
- */
- parseOptions(argc, argv);
-
- if (theOptions.printlsys)
- cerr << *lsystem << "\n";
-
- ModuleList* result = lsystem->execute();
- if (theOptions.printModules) {
- cerr << '\n';
- for (register long i=0; i<result->count(); i++)
- cerr << *result->item(i) << "\n";
- }
-
- /*
- * Select output driver and start turtle interpretation.
- */
- DeviceDriver* d;
- if (theOptions.drivername == "no")
- return 1;
- else if (theOptions.drivername == "example")
- d = new ExampleDevice;
- else if (theOptions.drivername == "bbox")
- d = new BBoxDevice(&theOptions);
- else if (theOptions.drivername == "rayshade")
- d = new RayshadeDevice(&theOptions);
- else if (theOptions.drivername == "flat")
- d = new FlatDevice(&theOptions);
- #ifdef SUPPORT_X11
- else if (theOptions.drivername == "x11simple")
- d = new LineDevice(new X11_Window, &theOptions);
- else if (theOptions.drivername == "x11wire")
- d = new WireDevice(new X11_Window, &theOptions);
- #endif
- #ifdef SUPPORT_AMIGA
- else if (theOptions.drivername == "amigasimple")
- d = new LineDevice(new AMIGA_Window, &theOptions);
- else if (theOptions.drivername == "amigawire")
- d = new WireDevice(new AMIGA_Window, &theOptions);
- #endif
- else {
- if (!theOptions.quiet)
- #ifdef SUPPORT_X11
- cerr << "\nUnknown driver specified, using simple X11.\n\n";
- d = new LineDevice(new X11_Window, &theOptions);
- #else
- #ifdef SUPPORT_AMIGA
- cerr << "\nUnknown driver specified, using simple AMIGA.\n\n";
- d = new LineDevice(new AMIGA_Window, &theOptions);
- #else
- cerr << "\nUnknown driver specified, using ExampleDevice.\n\n";
- d = new ExampleDevice;
- #endif
- #endif
- }
-
- d->setName(lsystem->getName());
- Interpreter interp(d, &theOptions);
- interp.interpret(result);
- // delete d; let the system do the clean up.
- }
-
- return 1;
- }
-
- void memory_error_handler()
- {
- cerr << "Fatal error: out of memory\n";
- exit(1);
- }
-