/* options.C
 */


#include <string.h>
#include <stdlib.h>
#include "main.h"

#define BOOL_TO_STRING(b) (b ? "yes" : "no")


/* Print the list of options and their current values.  Then stop the
 * program.
 */


void
printHelpAndQuit( char *programName )

{
  cerr << "usage: " << programName << " {options}\n";
  cerr << "          -n filename   network file (" << configFileName << ")\n";
  cerr << "          -r #          report interval (" << reportInterval << ")\n";
  cerr << "          -s #          stopping time (" << stoppingTime << ")\n";
  cerr << "          -a #          train advance interval (" << trainAdvanceInterval << ")\n";
  cerr << "          -T            tutor test mode (" << BOOL_TO_STRING(testing) << ")\n";
  cerr << "          -t            text report output (" << BOOL_TO_STRING(textOutput) << ")\n";
  cerr << "          -e            event description output (" << BOOL_TO_STRING(outputEvents) << ")\n";
  cerr << "          -g            graphics output (" << BOOL_TO_STRING(outputGraphics) << ")\n";
  cerr << "          -p            output passenger appearance events (" << BOOL_TO_STRING(outputPassengerAppearances) << ")\n";
  cerr << "          -S            show section directions for debuggin (" << BOOL_TO_STRING(showSectionDirections) << ")\n";
  cerr << "          -w            update window upon report (" << BOOL_TO_STRING(redrawUponReport) << ")\n";
  cerr << "          -A            allow accidents to occur (" << BOOL_TO_STRING(allowAccidents) << ")\n";
  cerr << endl;
  cerr << "       To see different parts of the subway system, hold down the left mouse\n";
  cerr << "         button while dragging the mouse in the window.\n";
  cerr << "       To zoom in or out, hold down the right mouse button while dragging\n";
  cerr << "         the mouse up or down in the window.\n";
  abort();
}

extern bool outputPassengerAppearances;
extern bool showSectionDirections;

/* Read and parse options from the command line.
 */


void
getOptions( int argc, char **argv )

{
  char *programName = argv[0];

  while (argc > 1) {

    argv++;
    argc--;

    if (argv[0][0] != '-') {

      cerr << programName << ": unrecognized argument, " << argv[0] << endl;
      printHelpAndQuit( programName );

    } else
      switch( argv[0][1] ) {

      case 'n':			/* set vertical_scale */
	configFileName = strdup( argv[1] );
	argv++;
	argc--;
	break;

      case 'r':
	reportInterval = atof( argv[1] );
	argv++;
	argc--;
	break;

      case 'a':
	trainAdvanceInterval = atof( argv[1] );
	argv++;
	argc--;
	break;

      case 's':
	stoppingTime = atof( argv[1] );
	argv++;
	argc--;
	break;

      case 'T':
	testing = !testing;
	break;

      case 't':
	textOutput = !textOutput;
	break;

      case 'e':
	outputEvents = !outputEvents;
	break;

      case 'w':
	redrawUponReport = !redrawUponReport;
	break;

      case 'p':
	outputPassengerAppearances = !outputPassengerAppearances;
	break;

      case 'S':
	showSectionDirections = !showSectionDirections;
	break;

      case 'g':
	outputGraphics = !outputGraphics;
	break;

      case 'A':
	allowAccidents = !allowAccidents;
	break;

      default:
        cerr << programName << ": unrecognized option, -" << argv[0][1] << endl;
	printHelpAndQuit( programName );
        break;
      }
  }
}


