src/main.cpp

changeset 137
73d057b030d0
parent 135
8b9132fea327
child 138
a426c1039655
equal deleted inserted replaced
136:1c40bb4f8221 137:73d057b030d0
42 // Intepret command-line parameters: 42 // Intepret command-line parameters:
43 // -l: list commands 43 // -l: list commands
44 // I guess there should be a better way to do this. 44 // I guess there should be a better way to do this.
45 if (argc == 2 and String (argv[1]) == "-l") 45 if (argc == 2 and String (argv[1]) == "-l")
46 { 46 {
47 print ("Begin list of commands:\n");
48 print ("------------------------------------------------------\n");
49
50 BotscriptParser parser; 47 BotscriptParser parser;
51 parser.setReadOnly (true); 48 parser.setReadOnly (true);
52 parser.parseBotscript ("botc_defs.bts"); 49 parser.parseBotscript ("botc_defs.bts");
53 50
54 for (CommandInfo* comm : getCommands()) 51 for (CommandInfo* comm : getCommands())
55 print ("%1\n", comm->signature()); 52 print ("%1\n", comm->signature());
56 53
57 print ("------------------------------------------------------\n"); 54 exit (0);
58 print ("End of command list\n"); 55 }
56
57 if (argc == 2 and String (argv[1]) == "-v")
58 {
59 // Print header
60 String header;
61 header = format (APPNAME " %1", versionString (true));
62
63 #ifdef DEBUG
64 header += " (debug build)";
65 #endif
66
67 print ("%1\n", header);
59 exit (0); 68 exit (0);
60 } 69 }
61 70
62 if (argc < 2) 71 if (argc < 2)
63 { 72 {
73 fprintf (stderr, APPNAME " %s\n", versionString (false).c_str());
64 fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]); 74 fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]);
65 fprintf (stderr, " %s -l # lists commands\n", argv[0]); 75 fprintf (stderr, " %s -l # lists commands\n", argv[0]);
76 fprintf (stderr, " %s -v # displays version info\n", argv[0]);
66 exit (1); 77 exit (1);
67 } 78 }
68
69 // Print header
70 String header;
71 String headerline;
72 header = format (APPNAME " version %1", versionString (true));
73
74 #ifdef DEBUG
75 if (header.firstIndexOf ("(") != -1)
76 header += ", ";
77 else
78 header += " (";
79
80 header += "debug build";
81 #endif
82
83 if (header.firstIndexOf ("(") != -1)
84 header += ")";
85
86 for (int i = 0; i < header.length() / 2; ++i)
87 headerline += "-=";
88
89 headerline += '-';
90 print ("%2\n\n%1\n\n%2\n\n", header, headerline);
91 79
92 String outfile; 80 String outfile;
93 81
94 if (argc < 3) 82 if (argc < 3)
95 outfile = makeObjectFileName (argv[1]); 83 outfile = makeObjectFileName (argv[1]);
144 // ============================================================================ 132 // ============================================================================
145 // 133 //
146 DataType getTypeByName (String token) 134 DataType getTypeByName (String token)
147 { 135 {
148 token = token.toLowercase(); 136 token = token.toLowercase();
149 return (token == "int") ? TYPE_Int : 137 return (token == "int") ? TYPE_Int
150 (token == "str") ? TYPE_String : 138 : (token == "str") ? TYPE_String
151 (token == "void") ? TYPE_Void : 139 : (token == "void") ? TYPE_Void
152 (token == "bool") ? TYPE_Bool : 140 : (token == "bool") ? TYPE_Bool
153 TYPE_Unknown; 141 : TYPE_Unknown;
154 } 142 }
155 143
156 144
157 // ============================================================================ 145 // ============================================================================
158 // 146 //
174 162
175 // ============================================================================= 163 // =============================================================================
176 // 164 //
177 String makeVersionString (int major, int minor, int patch) 165 String makeVersionString (int major, int minor, int patch)
178 { 166 {
179 String ver = format ("%1.%2", major, minor); 167 String ver = String::fromNumber (major);
168 ver += "." + String::fromNumber (minor);
180 169
181 if (patch != 0) 170 if (patch != 0)
182 { 171 ver += "." + patch;
183 ver += ".";
184 ver += patch;
185 }
186 172
187 return ver; 173 return ver;
188 } 174 }
189 175
190 // ============================================================================= 176 // =============================================================================
191 // 177 //
192 String versionString (bool) 178 String versionString (bool longform)
193 { 179 {
194 #if defined(GIT_DESCRIPTION) and defined (DEBUG) 180 String result = makeVersionString (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
195 String tag (GIT_DESCRIPTION);
196 String version = tag;
197 181
198 if (longform and tag.endsWith ("-pre")) 182 #ifdef SVN_REVISION_STRING
199 version += "-" + String (GIT_HASH).mid (0, 8); 183 if (longform)
184 result += "-" SVN_REVISION_STRING;
185 #else
186 (void) longform; // shuts up GCC
187 #endif
200 188
201 return version; 189 return result;
202 #elif VERSION_PATCH != 0
203 return format ("%1.%2.%3", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
204 #else
205 return format ("%1.%2", VERSION_MAJOR, VERSION_MINOR);
206 #endif
207 } 190 }

mercurial