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);
28 bool opts_debug = false;
29 bool opts_memchk = false;
30 bool opts_darkplaces_stringtablebug = false;
31 bool opts_omit_nullcode = false;
32 int opts_compiler = COMPILER_GMQCC;
34 static const int usage(const char *const app) {
36 " %s -c<file> -oprog.dat -- compile file\n"
37 " %s -a<file> -oprog.dat -- assemble file\n"
38 " %s -c<file> -i<file> -oprog.dat -- compile together (allowed multiple -i<file>)\n"
39 " %s -a<file> -i<file> -oprog.dat -- assemble together(allowed multiple -i<file>)\n"
41 " %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n", app, app, app, app, app);
43 printf(" additional flags:\n"
44 " -debug -- turns on compiler debug messages\n"
45 " -memchk -- turns on compiler memory leak check\n"
46 " -help -- prints this help/usage text\n"
47 " -std -- select the QuakeC compile type (types below):\n");
49 printf(" -std=qcc -- original QuakeC\n"
50 " -std=ftqecc -- fteqcc QuakeC\n"
51 " -std=qccx -- qccx QuakeC\n"
52 " -std=gmqcc -- this compiler QuakeC (default selection)\n");
54 printf(" codegen flags:\n"
55 " -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n"
56 " -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n");
60 int main(int argc, char **argv) {
62 char *app = &argv[0][0];
67 * Parse all command line arguments. This is rather annoying to do
68 * because of all tiny corner cases.
70 if (argc <= 1 || (argv[1][0] != '-'))
73 while ((argc > 1) && argv[1][0] == '-') {
77 " version: %d.%d.%d (0x%08X)\n"
80 (GMQCC_VERSION >> 16) & 0xFF,
81 (GMQCC_VERSION >> 8) & 0xFF,
82 (GMQCC_VERSION >> 0) & 0xFF,
89 #define param_argument(argtype) do { \
92 item.name = util_strdup(&argv[1][2]); \
93 item.type = argtype; \
99 goto clean_params_usage; \
100 item.name = util_strdup(argv[1]); \
101 item.type = argtype; \
106 case 'c': { param_argument(0); break; } /* compile */
107 case 'a': { param_argument(1); break; } /* assemble */
108 case 'i': { param_argument(2); break; } /* includes */
111 if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug = true; break; }
112 if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = true; break; }
113 if (!strncmp(&argv[1][1], "help", 4)) {
117 /* compiler type selection */
118 if (!strncmp(&argv[1][1], "std=qcc" , 7 )) { opts_compiler = COMPILER_QCC; break; }
119 if (!strncmp(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
120 if (!strncmp(&argv[1][1], "std=qccx", 8 )) { opts_compiler = COMPILER_QCCX; break; }
121 if (!strncmp(&argv[1][1], "std=gmqcc", 9 )) { opts_compiler = COMPILER_GMQCC; break; }
122 if (!strncmp(&argv[1][1], "std=", 4 )) {
123 printf("invalid std selection, supported types:\n"
124 " -std=qcc -- original QuakeC\n"
125 " -std=ftqecc -- fteqcc QuakeC\n"
126 " -std=qccx -- qccx QuakeC\n"
127 " -std=gmqcc -- this compiler QuakeC (default selection)\n");
131 /* code specific switches */
132 if (!strcmp(&argv[1][1], "fdarkplaces-stringtablebug")) {
133 opts_darkplaces_stringtablebug = true;
136 if (!strcmp(&argv[1][1], "fomit-nullcode")) {
137 opts_omit_nullcode = true;
148 * options could depend on another option, this is where option
149 * validity checking like that would take place.
151 if (opts_memchk && !opts_debug)
152 printf("Warning: cannot enable -memchk, without -debug.\n");
154 util_debug("COM", "starting ...\n");
155 /* multi file multi path compilation system */
156 for (; itr < items_elements; itr++) {
157 switch (items_data[itr].type) {
159 lex_init (items_data[itr].name, &lex);
166 asm_init (items_data[itr].name, &fpp);
175 util_debug("COM", "cleaning ...\n");
177 for (itr = 0; itr < items_elements; itr++)
178 mem_d(items_data[itr].name);
185 for (itr = 0; itr < items_elements; itr++)
186 mem_d(items_data[itr].name);