main.cc
Go to the documentation of this file.
1 
27 #include <getopt.h>
28 
29 #include "stage.hh"
30 #include "config.h"
31 using namespace Stg;
32 
33 const char* USAGE =
34  "USAGE: stage [options] <worldfile1> [worldfile2 ... worldfileN]\n"
35  "Available [options] are:\n"
36  " --clock : print simulation time peridically on standard output\n"
37  " -c : equivalent to --clock\n"
38  " --gui : run without a GUI\n"
39  " -g : equivalent to --gui\n"
40  " --help : print this message\n"
41  " --args \"str\" : define an argument string to be passed to all controllers\n"
42  " -a \"str\" : equivalent to --args \"str\"\n"
43  " -h : equivalent to --help\n"
44  " -? : equivalent to --help";
45 
46 /* options descriptor */
47 static struct option longopts[] = {
48  { "gui", optional_argument, NULL, 'g' },
49  { "clock", optional_argument, NULL, 'c' },
50  { "help", optional_argument, NULL, 'h' },
51  { "args", required_argument, NULL, 'a' },
52  { NULL, 0, NULL, 0 }
53 };
54 
55 int main( int argc, char* argv[] )
56 {
57  // initialize libstage - call this first
58  Stg::Init( &argc, &argv );
59 
60  printf( "%s %s ", PROJECT, VERSION );
61 
62  int ch=0, optindex=0;
63  bool usegui = true;
64  bool showclock = false;
65 
66  while ((ch = getopt_long(argc, argv, "cgh?", longopts, &optindex)) != -1)
67  {
68  switch( ch )
69  {
70  case 0: // long option given
71  printf( "option %s given\n", longopts[optindex].name );
72  break;
73  case 'a':
74  World::ctrlargs = std::string(optarg);
75  break;
76  case 'c':
77  showclock = true;
78  printf( "[Clock enabled]" );
79  break;
80  case 'g':
81  usegui = false;
82  printf( "[GUI disabled]" );
83  break;
84  case 'h':
85  case '?':
86  puts( USAGE );
87  // exit(0);
88  break;
89  default:
90  printf("unhandled option %c\n", ch );
91  puts( USAGE );
92  //exit(0);
93  }
94  }
95 
96  puts("");// end the first start-up line
97 
98  // arguments at index [optindex] and later are not options, so they
99  // must be world file names
100 
101  optindex = optind; //points to first non-option
102  while( optindex < argc )
103  {
104  if( optindex > 0 )
105  {
106  const char* worldfilename = argv[optindex];
107  World* world = ( usegui ?
108  new WorldGui( 400, 300, worldfilename ) :
109  new World( worldfilename ) );
110  world->Load( worldfilename );
111  world->ShowClock( showclock );
112 
113  if( ! world->paused )
114  world->Start();
115  }
116  optindex++;
117  }
118 
119  World::Run();
120 
121  puts( "\n[Stage: done]" );
122 
123  return EXIT_SUCCESS;
124 }
virtual void Start()
Definition: stage.hh:923
const char * USAGE
Definition: main.cc:33
World class
Definition: stage.hh:814
The Stage library uses its own namespace.
Definition: canvas.hh:8
void Init(int *argc, char **argv[])
Definition: stage.cc:18
static struct option longopts[]
Definition: main.cc:47
static int argc
int main(int argc, char *argv[])
Definition: main.cc:55
static char * argv
bool paused
if true, the simulation is stopped
Definition: stage.hh:921
static void Run()
Definition: world.cc:207
void ShowClock(bool enable)
Control printing time to stdout.
Definition: stage.hh:1190
static std::string ctrlargs
Definition: stage.hh:827
virtual void Load(const std::string &worldfile_path)
Definition: world.cc:388


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 Mon Jun 10 2019 15:06:09