X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=main.c;h=06e036d280e64d0c6a6aca45727e5e4e8acbe491;hb=d96fd2d9b881fc7d9339cddbdd7cf8fbd4acf05f;hp=a8832864e9b12a8d564b92d628df142e208c5c49;hpb=488859a218f03f4ca6427128e84aa30d8d8bbfba;p=xonotic%2Fgmqcc.git diff --git a/main.c b/main.c index a883286..06e036d 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 + * Copyright (C) 2012 * Dale Weiler * * Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -21,157 +21,373 @@ * SOFTWARE. */ #include "gmqcc.h" -// todo CLEANUP this argitem thing -typedef struct { char *name, type; } argitem; + +uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; +uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)]; + +uint32_t opts_O = 1; +const char *opts_output = "progs.dat"; +int opts_standard = COMPILER_GMQCC; +bool opts_debug = false; +bool opts_memchk = false; + +typedef struct { char *filename; int type; } argitem; VECTOR_MAKE(argitem, items); -/* global options */ -bool opts_debug = false; -bool opts_memchk = false; -bool opts_darkplaces_stringtablebug = false; -bool opts_omit_nullcode = false; -int opts_compiler = COMPILER_GMQCC; - -static const int usage(const char *const app) { - printf("usage:\n" - " %s -c -oprog.dat -- compile file\n" - " %s -a -oprog.dat -- assemble file\n" - " %s -c -i -oprog.dat -- compile together (allowed multiple -i)\n" - " %s -a -i -oprog.dat -- assemble together(allowed multiple -i)\n" - " example:\n" - " %s -cfoo.qc -ibar.qc -oqc.dat -afoo.qs -ibar.qs -oqs.dat\n" - " additional flags:\n" - " -debug -- turns on compiler debug messages\n" - " -memchk -- turns on compiler memory leak check\n" - " -help -- prints this help/usage text\n" - " -std -- select the QuakeC compile type (types below):\n" - " -std=qcc -- original QuakeC\n" - " -std=ftqecc -- fteqcc QuakeC\n" - " -std=qccx -- qccx QuakeC\n" - " -std=gmqcc -- this compiler QuakeC (default selection)\n" - " codegen flags:\n" - " -fdarkplaces-string-table-bug -- patches the string table to work with bugged versions of darkplaces\n" - " -fomit-nullcode -- omits the generation of null code (will break everywhere see propsal.txt)\n", - app,app,app,app,app - ); +#define TYPE_QC 0 +#define TYPE_ASM 1 +#define TYPE_SRC 2 + +static const char *app_name; + +static int usage() { + printf("usage: %s [options] [files...]", app_name); + printf("options:\n" + " -h, --help show this help message\n" + " -debug turns on compiler debug messages\n" + " -memchk turns on compiler memory leak check\n"); + printf(" -o, --output=file output file, defaults to progs.dat\n" + " -a filename add an asm file to be assembled\n" + " -s filename add a progs.src file to be used\n"); + printf(" -f enable a flag\n" + " -fno- disable a flag\n" + " -std standard select one of the following standards\n" + " -std=qcc original QuakeC\n" + " -std=fteqcc fteqcc QuakeC\n" + " -std=gmqcc this compiler (default)\n"); + printf(" -W enable a warning\n" + " -Wno- disable a warning\n" + " -Wall enable all warnings\n"); + printf("\n"); + printf("flags:\n" + " -fdarkplaces-string-table-bug\n" + " patch the string table to work with some bugged darkplaces versions\n" + " -fomit-nullbytes\n" + " omits certain null-bytes for a smaller output - requires a patched engine\n" + ); return -1; } -int main(int argc, char **argv) { - size_t itr = 0; - char *app = &argv[0][0]; - FILE *fpp = NULL; - lex_file *lex = NULL; - - /* - * Parse all command line arguments. This is rather annoying to do - * because of all tiny corner cases. - */ - if (argc <= 1 || (argv[1][0] != '-')) - return usage(app); - - while ((argc > 1) && argv[1][0] == '-') { - switch (argv[1][1]) { - case 'v': { - printf("GMQCC:\n" - " version: %d.%d.%d (0x%08X)\n" - " build date: %s\n" - " build time: %s\n", - (GMQCC_VERSION >> 16) & 0xFF, - (GMQCC_VERSION >> 8) & 0xFF, - (GMQCC_VERSION >> 0) & 0xFF, - (GMQCC_VERSION), - __DATE__, - __TIME__ - ); - return 0; +static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { + size_t i; + + for (i = 0; i < listsize; ++i) { + if (!strcmp(name, list[i].name)) { + longbit lb = list[i].bit; +#if 0 + if (on) + flags[lb.idx] |= (1<<(lb.bit)); + else + flags[lb.idx] &= ~(1<<(lb.bit)); +#else + if (on) + flags[0] |= (1<