main.cc
Go to the documentation of this file.
00001 
00027 #include <getopt.h>
00028 
00029 #include "stage.hh"
00030 #include "config.h"
00031 using namespace Stg;
00032 
00033 const char* USAGE = 
00034   "USAGE:  stage [options] <worldfile1> [worldfile2 ... worldfileN]\n"
00035   "Available [options] are:\n"
00036   "  --clock        : print simulation time peridically on standard output\n"
00037   "  -c             : equivalent to --clock\n"
00038   "  --gui          : run without a GUI\n"
00039   "  -g             : equivalent to --gui\n"
00040   "  --help         : print this message\n"
00041   "  --args \"str\"   : define an argument string to be passed to all controllers\n"
00042   "  -a \"str\"       : equivalent to --args \"str\"\n"
00043   "  -h             : equivalent to --help\n"
00044   "  -?             : equivalent to --help";
00045 
00046 /* options descriptor */
00047 static struct option longopts[] = {
00048         { "gui",  optional_argument,   NULL,  'g' },
00049         { "clock",  optional_argument,   NULL,  'c' },
00050         { "help",  optional_argument,   NULL,  'h' },
00051         { "args",  required_argument,   NULL,  'a' },
00052         { NULL, 0, NULL, 0 }
00053 };
00054 
00055 int main( int argc, char* argv[] )
00056 {
00057   // initialize libstage - call this first
00058   Stg::Init( &argc, &argv );
00059 
00060   printf( "%s %s ", PROJECT, VERSION );
00061   
00062   int ch=0, optindex=0;
00063   bool usegui = true;
00064   bool showclock = false;
00065   
00066   while ((ch = getopt_long(argc, argv, "cgh?", longopts, &optindex)) != -1)
00067          {
00068                 switch( ch )
00069                   {
00070                   case 0: // long option given
00071                          printf( "option %s given\n", longopts[optindex].name );
00072                          break;
00073                   case 'a':
00074                          World::ctrlargs = std::string(optarg);
00075                          break;
00076                   case 'c': 
00077                          showclock = true;
00078                          printf( "[Clock enabled]" );
00079                          break;
00080                   case 'g': 
00081                          usegui = false;
00082                          printf( "[GUI disabled]" );
00083                          break;
00084                   case 'h':  
00085                   case '?':  
00086                          puts( USAGE );
00087                          //                      exit(0);
00088                          break;
00089                   default:
00090                          printf("unhandled option %c\n", ch );
00091                          puts( USAGE );
00092                          //exit(0);
00093                   }
00094          }
00095   
00096   puts("");// end the first start-up line
00097 
00098   // arguments at index [optindex] and later are not options, so they
00099   // must be world file names
00100   
00101   optindex = optind; //points to first non-option
00102   while( optindex < argc )
00103          {
00104                 if( optindex > 0 )
00105                   {      
00106                          const char* worldfilename = argv[optindex];
00107                          World* world = ( usegui ? 
00108                                                                                 new WorldGui( 400, 300, worldfilename ) : 
00109                                                                         new World( worldfilename ) );
00110                          world->Load( worldfilename );
00111                          world->ShowClock( showclock );
00112 
00113                          if( ! world->paused ) 
00114                                 world->Start();
00115                   }
00116                 optindex++;
00117          }
00118 
00119   World::Run();  
00120   
00121   puts( "\n[Stage: done]" );
00122 
00123         return EXIT_SUCCESS;
00124 }


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57