src/main.cpp

changeset 141
68d60e2cfa76
parent 140
04a6eb68f226
child 142
1f5518dd8146
equal deleted inserted replaced
140:04a6eb68f226 141:68d60e2cfa76
45 45
46 int main (int argc, char** argv) 46 int main (int argc, char** argv)
47 { 47 {
48 try 48 try
49 { 49 {
50 Verbosity verboselevel = Verbosity::None; 50 Verbosity verboselevel (Verbosity::None);
51 bool listcommands = false; 51 bool listcommands (false);
52 bool sendhelp (false);
53 bool test (true);
52 54
53 CommandLine cmdline; 55 CommandLine cmdline;
54 cmdline.addOption (listcommands, 'l', "listfunctions", 56 cmdline.addOption (listcommands, 'l', "listfunctions", "List available functions");
55 "List available function signatures and exit"); 57 cmdline.addOption (sendhelp, 'h', "help", "Print help text");
56 cmdline.addEnumeratedOption (verboselevel, 'V', "verbose", 58 cmdline.addOption (test, 'x', "test", "testy test");
57 "Output more verbose information (0 through 2)"); 59 cmdline.addEnumeratedOption (verboselevel, 'V', "verbose", "Output more information");
58 StringList args = cmdline.process (argc, argv); 60 StringList args = cmdline.process (argc, argv);
61
62 if (sendhelp)
63 {
64 // Print header
65 String header = APPNAME " " FULL_VERSION_STRING;
66 #ifdef DEBUG
67 header += " (debug build)";
68 #endif
69 printTo (stderr, "%1\n", header);
70 printTo (stderr, "usage: %1 [OPTIONS] SOURCE [OUTPUT]\n\n", argv[0]);
71 printTo (stderr, "Options:\n" + cmdline.describeOptions());
72 return EXIT_SUCCESS;
73 }
59 74
60 if (listcommands) 75 if (listcommands)
61 { 76 {
62 BotscriptParser parser; 77 BotscriptParser parser;
63 parser.setReadOnly (true); 78 parser.setReadOnly (true);
64 parser.parseBotscript ("botc_defs.bts"); 79 parser.parseBotscript ("botc_defs.bts");
65 80
66 for (CommandInfo* comm : getCommands()) 81 for (CommandInfo* comm : getCommands())
67 print ("%1\n", comm->signature()); 82 print ("%1\n", comm->signature());
68 83
69 exit (0); 84 return EXIT_SUCCESS;
70 } 85 }
71 86
72 if (not within (args.size(), 1, 2)) 87 if (not within (args.size(), 1, 2))
73 { 88 {
74 // Print header 89 printTo (stderr, "%1: need an input file.\nUse `%1 --help` for more information\n",
75 String header = APPNAME " " FULL_VERSION_STRING; 90 argv[0]);
76 #ifdef DEBUG 91 return EXIT_FAILURE;
77 header += " (debug build)";
78 #endif
79
80 printTo (stderr, "%1\n", header);
81 printTo (stderr, "usage: %1 <infile> [outfile] # compiles botscript\n", argv[0]);
82 printTo (stderr, " %1 -l # lists commands\n", argv[0]);
83 printTo (stderr, " %1 -v # displays version info\n", argv[0]);
84 exit (1);
85 } 92 }
86 93
87 String outfile; 94 String outfile;
88 95
89 if (args.size() == 1) 96 if (args.size() == 1)
109 print ("%1 / %2 events\n", parser->numEvents(), Limits::MaxEvents); 116 print ("%1 / %2 events\n", parser->numEvents(), Limits::MaxEvents);
110 print ("%1 state%s1\n", parser->numStates()); 117 print ("%1 state%s1\n", parser->numStates());
111 118
112 parser->writeToFile (outfile); 119 parser->writeToFile (outfile);
113 delete parser; 120 delete parser;
114 return 0; 121 return EXIT_SUCCESS;
115 } 122 }
116 catch (std::exception& e) 123 catch (std::exception& e)
117 { 124 {
118 fprintf (stderr, "error: %s\n", e.what()); 125 fprintf (stderr, "error: %s\n", e.what());
119 return 1; 126 return EXIT_FAILURE;
120 } 127 }
121 } 128 }
122 129
123 // _________________________________________________________________________________________________ 130 // _________________________________________________________________________________________________
124 // 131 //
173 { 180 {
174 String ver = String::fromNumber (major); 181 String ver = String::fromNumber (major);
175 ver += "." + String::fromNumber (minor); 182 ver += "." + String::fromNumber (minor);
176 183
177 if (patch != 0) 184 if (patch != 0)
178 ver += "." + patch; 185 ver += String (".") + patch;
179 186
180 return ver; 187 return ver;
181 } 188 }
182 189
183 // _________________________________________________________________________________________________ 190 // _________________________________________________________________________________________________

mercurial