src/main.cc

changeset 82
841562f5a32f
parent 79
2425fa6a4f21
child 85
264a61e9eba0
equal deleted inserted replaced
81:071715c17296 82:841562f5a32f
37 #include "variables.h" 37 #include "variables.h"
38 #include "data_buffer.h" 38 #include "data_buffer.h"
39 #include "object_writer.h" 39 #include "object_writer.h"
40 #include "parser.h" 40 #include "parser.h"
41 #include "lexer.h" 41 #include "lexer.h"
42 #include "gitinfo.h"
42 43
43 // List of keywords 44 // List of keywords
44 const string_list g_Keywords = 45 const string_list g_Keywords =
45 { 46 {
46 "bool", 47 "bool",
82 // Intepret command-line parameters: 83 // Intepret command-line parameters:
83 // -l: list commands 84 // -l: list commands
84 // I guess there should be a better way to do this. 85 // I guess there should be a better way to do this.
85 if (argc == 2 && !strcmp (argv[1], "-l")) 86 if (argc == 2 && !strcmp (argv[1], "-l"))
86 { 87 {
87 init_commands();
88 printf ("Begin list of commands:\n"); 88 printf ("Begin list of commands:\n");
89 printf ("------------------------------------------------------\n"); 89 printf ("------------------------------------------------------\n");
90 90
91 for (command_info* comm : get_commands()) 91 for (command_info* comm : get_commands())
92 print ("%1\n", get_command_signature (comm)); 92 print ("%1\n", get_command_signature (comm));
97 } 97 }
98 98
99 // Print header 99 // Print header
100 string header; 100 string header;
101 string headerline; 101 string headerline;
102 header = format ("%1 version %2.%3", APPNAME, VERSION_MAJOR, VERSION_MINOR); 102 header = format (APPNAME " version %1", get_version_string (e_long_form));
103 103
104 for (int i = 0; i < (header.len() / 2) - 1; ++i) 104 #ifdef DEBUG
105 header += " (debug build)";
106 #endif
107
108 for (int i = 0; i < header.len() / 2; ++i)
105 headerline += "-="; 109 headerline += "-=";
106 110
107 headerline += '-'; 111 headerline += '-';
108 print ("%1\n%2\n", header, headerline); 112 print ("%2\n\n%1\n\n%2\n\n", header, headerline);
109 113
110 if (argc < 2) 114 if (argc < 2)
111 { 115 {
112 fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]); 116 fprintf (stderr, "usage: %s <infile> [outfile] # compiles botscript\n", argv[0]);
113 fprintf (stderr, " %s -l # lists commands\n", argv[0]); 117 fprintf (stderr, " %s -l # lists commands\n", argv[0]);
148 { 152 {
149 printf ("abort\n"); 153 printf ("abort\n");
150 exit (1); 154 exit (1);
151 } 155 }
152 } 156 }
153
154 // Read definitions
155 printf ("Reading definitions...\n");
156 init_events();
157 init_commands();
158 157
159 // Prepare reader and writer 158 // Prepare reader and writer
160 botscript_parser* r = new botscript_parser; 159 botscript_parser* r = new botscript_parser;
161 object_writer* w = new object_writer; 160 object_writer* w = new object_writer;
162 161
254 // Inverse operation - type name by value 253 // Inverse operation - type name by value
255 string GetTypeName (type_e type) 254 string GetTypeName (type_e type)
256 { 255 {
257 switch (type) 256 switch (type)
258 { 257 {
259 case TYPE_INT: return "int"; break; 258 case TYPE_INT: return "int"; break;
260 259 case TYPE_STRING: return "str"; break;
261 case TYPE_STRING: return "str"; break; 260 case TYPE_VOID: return "void"; break;
262 261 case TYPE_BOOL: return "bool"; break;
263 case TYPE_VOID: return "void"; break; 262 case TYPE_UNKNOWN: return "???"; break;
264
265 case TYPE_BOOL: return "bool"; break;
266
267 case TYPE_UNKNOWN: return "???"; break;
268 } 263 }
269 264
270 return ""; 265 return "";
271 } 266 }
267 // =============================================================================
268 //
269
270 string make_version_string (int major, int minor, int patch)
271 {
272 string ver = format ("%1.%2", major, minor);
273
274 if (patch != 0)
275 {
276 ver += ".";
277 ver += patch;
278 }
279
280 return ver;
281 }
282
283 // =============================================================================
284 //
285 string get_version_string (form_length_e len)
286 {
287 string tag (GIT_DESCRIPTION);
288 string version = tag;
289
290 if (tag.ends_with ("-pre") && len == e_long_form)
291 version += "-" + string (GIT_HASH).mid (0, 8);
292
293 return version;
294 }

mercurial