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


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 Feb 28 2022 23:48:55