Language type selection at command line.

This commit is contained in:
Dale Weiler 2012-04-21 22:55:30 -04:00
parent 7849f8c597
commit 4d001da04e
3 changed files with 40 additions and 13 deletions

View file

@ -476,6 +476,12 @@ void asm_parse(FILE *);
//======================================================================
//============================= main.c =================================
//======================================================================
enum {
COMPILER_QCC, /* circa QuakeC */
COMPILER_FTEQCC, /* fteqcc QuakeC */
COMPILER_QCCX, /* qccx QuakeC */
COMPILER_GMQCC /* this QuakeC */
};
extern int opts_debug;
extern int opts_memchk;
#endif

31
main.c
View file

@ -26,8 +26,9 @@ typedef struct { char *name, type; } argitem;
VECTOR_MAKE(argitem, items);
/* global options */
int opts_debug = 0;
int opts_memchk = 0;
int opts_debug = 0;
int opts_memchk = 0;
int opts_compiler = COMPILER_GMQCC;
static const int usage(const char *const app) {
printf("usage:\n");
@ -40,7 +41,12 @@ static const int usage(const char *const app) {
printf(" additional flags:\n");
printf(" -debug -- turns on compiler debug messages\n");
printf(" -memchk -- turns on compiler memory leak check\n");
printf(" -help -- prints this help/usage text\n");
printf(" -std -- select the QuakeC compile type (types below):\n");
printf(" -std=qcc -- original QuakeC\n");
printf(" -std=ftqecc -- fteqcc QuakeC\n");
printf(" -std=qccx -- qccx QuakeC\n");
printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n");
return -1;
}
@ -64,6 +70,23 @@ int main(int argc, char **argv) {
default:
if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug = 1; break; }
if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = 1; break; }
if (!strncmp(&argv[1][1], "help", 4)) {
return usage(app);
break;
}
/* compiler type selection */
if (!strncmp(&argv[1][1], "std=qcc" , 7 )) { opts_compiler = COMPILER_QCC; break; }
if (!strncmp(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
if (!strncmp(&argv[1][1], "std=qccx", 8 )) { opts_compiler = COMPILER_QCCX; break; }
if (!strncmp(&argv[1][1], "std=gmqcc", 9 )) { opts_compiler = COMPILER_GMQCC; break; }
if (!strncmp(&argv[1][1], "std=", 4 )) {
printf("invalid std selection, supported types:\n");
printf(" -std=qcc -- original QuakeC\n");
printf(" -std=ftqecc -- fteqcc QuakeC\n");
printf(" -std=qccx -- qccx QuakeC\n");
printf(" -std=gmqcc -- this compiler QuakeC (default selection)\n");
return 0;
}
return usage(app);
}
@ -78,6 +101,7 @@ int main(int argc, char **argv) {
if (opts_memchk && !opts_debug)
printf("Warning: cannot enable -memchk, without -debug.\n");
util_debug("COM", "starting ...\n");
/* multi file multi path compilation system */
for (; itr < items_elements; itr++) {
switch (items_data[itr].type) {
@ -95,6 +119,7 @@ int main(int argc, char **argv) {
}
}
util_debug("COM", "cleaning ...\n");
/* clean list */
for (itr = 0; itr < items_elements; itr++)
mem_d(items_data[itr].name);

14
util.c
View file

@ -68,19 +68,15 @@ void util_meminfo() {
Total allocations: %llu\n\
Total deallocations: %llu\n\
Total allocated: %llu (bytes)\n\
Total deallocated: %llu (bytes)\n",
Total deallocated: %llu (bytes)\n\
Leaks found: lost %llu (bytes) in %d allocations\n",
mem_at, mem_dt,
mem_ab, mem_db
mem_ab, mem_db,
(mem_ab - mem_db),
(mem_at - mem_dt)
);
}
//#ifndef mem_d
//#define mem_d(x) util_memory_d((x), __LINE__, __FILE__)
//#endif
//#ifndef mem_a
//#define mem_a(x) util_memory_a((x), __LINE__, __FILE__)
//#endif
/*
* Some string utility functions, because strdup uses malloc, and we want
* to track all memory (without replacing malloc).