5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is furnished to do
10 * so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 typedef struct { char *name, type; } argitem;
25 VECTOR_MAKE(argitem, items);
27 static const int usage(const char *const app) {
29 " %s -c<file> -oprog.dat -- compile file\n"
30 " %s -a<file> -oprog.dat -- assemble file\n"
31 " %s -c<file> -i<file> -oprog.dat -- compile together (allowed multiple -i<file>)\n"
32 " %s -a<file> -i<file> -oprog.dat -- assemble together(allowed multiple -i<file>)\n"
34 " %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n", app, app, app, app, app);
36 printf(" additional flags:\n"
37 " -debug -- turns on compiler debug messages\n"
38 " -memchk -- turns on compiler memory leak check\n"
39 " -help -- prints this help/usage text\n"
40 " -std -- select the QuakeC compile type (types below):\n");
42 printf(" -std=qcc -- original QuakeC\n"
43 " -std=ftqecc -- fteqcc QuakeC\n"
44 " -std=qccx -- qccx QuakeC\n"
45 " -std=gmqcc -- this compiler QuakeC (default selection)\n");
47 printf(" codegen flags:\n"
48 " -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n"
49 " -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n");
53 int main(int argc, char **argv) {
55 char *app = &argv[0][0];
60 * Parse all command line arguments. This is rather annoying to do
61 * because of all tiny corner cases.
63 if (argc <= 1 || (argv[1][0] != '-'))
66 while ((argc > 1) && argv[1][0] == '-') {
70 " version: %d.%d.%d (0x%08X)\n"
73 (GMQCC_VERSION >> 16) & 0xFF,
74 (GMQCC_VERSION >> 8) & 0xFF,
75 (GMQCC_VERSION >> 0) & 0xFF,
82 #define param_argument(argtype) do { \
85 item.name = util_strdup(&argv[1][2]); \
86 item.type = argtype; \
92 goto clean_params_usage; \
93 item.name = util_strdup(argv[1]); \
94 item.type = argtype; \
99 case 'c': { param_argument(0); break; } /* compile */
100 case 'a': { param_argument(1); break; } /* assemble */
101 case 'i': { param_argument(2); break; } /* includes */
104 if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug = true; break; }
105 if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = true; break; }
106 if (!strncmp(&argv[1][1], "help", 4)) {
110 /* compiler type selection */
111 if (!strncmp(&argv[1][1], "std=qcc" , 7 )) { opts_compiler = COMPILER_QCC; break; }
112 if (!strncmp(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
113 if (!strncmp(&argv[1][1], "std=qccx", 8 )) { opts_compiler = COMPILER_QCCX; break; }
114 if (!strncmp(&argv[1][1], "std=gmqcc", 9 )) { opts_compiler = COMPILER_GMQCC; break; }
115 if (!strncmp(&argv[1][1], "std=", 4 )) {
116 printf("invalid std selection, supported types:\n"
117 " -std=qcc -- original QuakeC\n"
118 " -std=ftqecc -- fteqcc QuakeC\n"
119 " -std=qccx -- qccx QuakeC\n"
120 " -std=gmqcc -- this compiler QuakeC (default selection)\n");
124 /* code specific switches */
125 if (!strcmp(&argv[1][1], "fdarkplaces-stringtablebug")) {
126 opts_darkplaces_stringtablebug = true;
129 if (!strcmp(&argv[1][1], "fomit-nullcode")) {
130 opts_omit_nullcode = true;
141 * options could depend on another option, this is where option
142 * validity checking like that would take place.
144 if (opts_memchk && !opts_debug)
145 printf("Warning: cannot enable -memchk, without -debug.\n");
147 util_debug("COM", "starting ...\n");
148 /* multi file multi path compilation system */
149 for (; itr < items_elements; itr++) {
150 switch (items_data[itr].type) {
152 lex_init (items_data[itr].name, &lex);
159 asm_init (items_data[itr].name, &fpp);
168 util_debug("COM", "cleaning ...\n");
170 for (itr = 0; itr < items_elements; itr++)
171 mem_d(items_data[itr].name);
178 for (itr = 0; itr < items_elements; itr++)
179 mem_d(items_data[itr].name);