home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / Options.C < prev    next >
C/C++ Source or Header  |  1993-03-10  |  5KB  |  206 lines

  1. /*
  2.  * Options.C
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #include <stdlib.h>
  20. #include "Options.h"
  21. #include "Expression.h"
  22. #include "Hull.h"
  23.  
  24. //___________________________________________________________ Options
  25.  
  26. static void usage(const rcString&);
  27. Options theOptions;
  28.  
  29. Options::Options()
  30. : iname("cin"), oname("cout"), optionsForCPP(" "),
  31.   resX(400), resY(400),
  32.   eye(0,1,0), lookat(0,0,0), up(0,0,1), fov(45.0)
  33. {
  34. #ifdef SUPPORT_X11
  35.   drivername = "x11simple";
  36. #else
  37. #ifdef SUPPORT_AMIGA
  38.   drivername = "amigasimple";
  39. #else
  40.   drivername = "example";
  41. #endif
  42. #endif
  43.  
  44.   verbose        = 0;
  45.   quiet          = 0;
  46.   printlsys      = 0;
  47.   printModules   = 0;
  48.   deleteModules  = 0;
  49.   autoscale      = 1;
  50.   coneSpheres    = 0;
  51.   showHulls      = 0;
  52.  
  53.   coneResolution   = -1; // use default resolutions
  54.   sphereResolution = -1;
  55.  
  56.   defaultForward = 10;
  57.   defaultPitch   = dtor(45);
  58.   defaultTurn    = dtor(45);
  59.   defaultRoll    = dtor(45);
  60.  
  61.   tropismX = NULL;
  62.   tropismY = NULL;
  63.   tropismZ = NULL;
  64.   weight   = NULL;
  65.   hulls    = NULL;
  66. }
  67.  
  68. void parseOptions(int argc, char** argv)
  69. {
  70.   rcString progname = argv[0];
  71.  
  72.   while (--argc) {
  73.     argv++;  
  74.  
  75.     if (argv[0][0] != '-')
  76.       break;
  77.  
  78.     switch(argv[0][1]) {
  79.     case 'O':
  80.       if (argc < 2) usage(progname);
  81.       theOptions.oname = argv[1];
  82.       argv++;
  83.       argc--;
  84.       break;
  85.     case 'D':
  86.       theOptions.optionsForCPP = theOptions.optionsForCPP 
  87.                                  + " " + argv[0];
  88.       break;
  89.     case 'd':
  90.       if (argc < 2) usage(progname);
  91.       theOptions.drivername = argv[1];
  92.       argv++;
  93.       argc--;
  94.       break;
  95.     case 'v':
  96.       theOptions.verbose = 1;
  97.       break;
  98.     case 'q':
  99.       theOptions.quiet = 1;
  100.       theOptions.verbose = 0;
  101.       theOptions.printlsys = 0;
  102.       theOptions.printModules = 0;
  103.       break;
  104.     case 'l':
  105.       theOptions.printlsys = 1;
  106.       break;
  107.     case 'p':
  108.       theOptions.printModules = 1;
  109.       break;
  110.     case 'e':
  111.       theOptions.deleteModules = 1;
  112.       break;
  113.     case 'R':
  114.       if (argc < 3) usage(progname);
  115.       theOptions.resX = atoi(argv[1]);
  116.       theOptions.resY = atoi(argv[2]);
  117.       argv += 2;
  118.       argc -= 2;
  119.       break;
  120.     case 'E':
  121.       if (argc < 4) usage(progname);
  122.       theOptions.eye = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  123.       argv += 3;
  124.       argc -= 3;
  125.       theOptions.autoscale = 0;
  126.       break;
  127.     case 'L':
  128.       if (argc < 4) usage(progname);
  129.       theOptions.lookat = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  130.       argv += 3;
  131.       argc -= 3;
  132.       theOptions.autoscale = 0;
  133.       break;
  134.     case 'U':
  135.       if (argc < 4) usage(progname);
  136.       theOptions.up = Vector(atof(argv[1]), atof(argv[2]), atof(argv[3]));
  137.       argv += 3;
  138.       argc -= 3;
  139.       break;
  140.     case 'f':
  141.       if (argc < 2) usage(progname);
  142.       theOptions.fov = atoi(argv[1]);
  143.       argv += 1;
  144.       argc -= 1;
  145.       break;
  146.     case 'c':
  147.       theOptions.coneSpheres = 1;
  148.       break;
  149.     case 's':
  150.       theOptions.showHulls = 1;
  151.       break;
  152.     case 'h':
  153.       usage(progname);
  154.       break;
  155.     default:
  156.       cerr << "Unrecognized option " << argv[0] << "\n";
  157.       usage(progname);
  158.     }
  159.   }  
  160.   
  161.   if (argc == 1)
  162.     theOptions.iname = argv[0];
  163.   else if (argc < 0 || argc > 1)
  164.     usage(progname);
  165. }
  166.  
  167. static void usage(const rcString& progname)
  168. {
  169.   cerr << "usage: " << progname << " [options] [filename]\n"
  170.        << "Where options include:\n"
  171.        << "\t-O outfile\t(Set output file name.)\n"
  172.        << "\t-R xres yres\t(Render at given resolution.)\n"
  173.        << "\t-E x y z\t(Set eyepoint vector.)\n"
  174.        << "\t-L x y z\t(Set lookat vector.)\n"
  175.        << "\t-U x y z\t(Set up vector.)\n"
  176.        << "\t-Dname\t\t(Define name as 1 (cpp option).)\n"
  177.        << "\t-Dname=def\t(Define name as \"def\" (cpp option).)\n"
  178.        << "\t-f angle\t(Set field of view.)\n"
  179.        << "\t-d drivername\n"
  180.        << "\t   no\t\t(No turtle interpretation.)\n"
  181.        << "\t   example\t(Example driver.)\n"
  182.        << "\t   bbox\t\t(Calculate bounding box and view parameter.)\n"
  183.        << "\t   rayshade\t(Rayshade driver.)\n"
  184. #ifdef SUPPORT_X11
  185.        << "\t   x11simple\t(Simple line drawing driver for X11.)\n"
  186.        << "\t   x11wire\t(Wire frame driver for X11.)\n"
  187. #endif
  188. #ifdef SUPPORT_AMIGA
  189.        << "\t   amigasimple\t(Simple line drawing driver for AMIGA.)\n"
  190.        << "\t   amigawire\t(Wire frame driver for AMIGA.)\n"
  191. #endif
  192.        << "\t   flat\t\t(Simple z-buffering.)\n"
  193.        << "\t-c\t\t(Toggle cone spheres generation.)\n "
  194.        << "\t-s\t\t(Show defined hulls.)\n "
  195.        << "\t-v\t\t(Verbose output.)\n"
  196.        << "\t-q\t\t(Run quietly.)\n"
  197.        << "\t-l\t\t(Print l-system definition.)\n"
  198.        << "\t-p\t\t(Print resulting module string.)\n"
  199.        << "\t-e\t\t(Erase module after turtle interpretation.)\n"
  200.        << "\t-h\t\t(Print this message.)\n";
  201.         
  202.   exit(1);
  203. }
  204.  
  205.  
  206.