From: Dale Weiler Date: Tue, 18 Dec 2012 05:22:23 +0000 (+0000) Subject: Allow setting configuration file via commandline X-Git-Tag: 0.1.9~71 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2587aed697c20791b6c63240343a1902f3b5743e;p=xonotic%2Fgmqcc.git Allow setting configuration file via commandline --- diff --git a/gmqcc.h b/gmqcc.h index 5f39634..b95bac4 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -882,6 +882,7 @@ bool opts_setoptim(const char *, bool); void opts_init (const char *, int, size_t); void opts_set (uint32_t *, size_t, bool); void opts_setoptimlevel(unsigned int); +void opts_ini_init (const char *); enum { # define GMQCC_TYPE_FLAGS diff --git a/main.c b/main.c index 6ae0091..80f242c 100644 --- a/main.c +++ b/main.c @@ -138,6 +138,7 @@ static bool options_parse(int argc, char **argv) { char buffer[1024]; char *redirout = (char*)stdout; char *redirerr = (char*)stderr; + char *config = NULL; while (!argend && argc > 1) { char *argarg; @@ -195,6 +196,10 @@ static bool options_parse(int argc, char **argv) { con_change(redirout, redirerr); continue; } + if (options_long_gcc("config", &argc, &argv, &argarg)) { + config = argarg; + continue; + } /* show defaults (like pathscale) */ if (!strcmp(argv[0]+1, "show-defaults")) { @@ -437,6 +442,7 @@ static bool options_parse(int argc, char **argv) { vec_push(items, item); } } + opts_ini_init(config); return true; } diff --git a/opts.c b/opts.c index 93433b6..6a6af17 100644 --- a/opts.c +++ b/opts.c @@ -25,7 +25,6 @@ unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS]; opts_cmd_t opts; /* command lien options */ -static void opts_ini_init(); static void opts_setdefault() { memset(&opts, 0, sizeof(opts_cmd_t)); @@ -63,8 +62,6 @@ void opts_init(const char *output, int standard, size_t arraysize) { opts.output = output; opts.standard = standard; opts.max_array_size = arraysize; - - opts_ini_init(); } static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { @@ -299,23 +296,25 @@ static char *opts_ini_load(const char *section, const char *name, const char *va * Actual loading subsystem, this finds the ini or cfg file, and properly * loads it and executes it to set compiler options. */ -static void opts_ini_init() { +void opts_ini_init(const char *file) { /* * Possible matches are: * gmqcc.ini * gmqcc.cfg */ + char *error; + size_t line; + FILE *ini; - char *file; - char *error; - size_t line; - FILE *ini; - - /* try ini */ - if (!(ini = fopen((file = "gmqcc.ini"), "r"))) - /* try cfg */ - if (!(ini = fopen((file = "gmqcc.cfg"), "r"))) - return; + + if (!file) { + /* try ini */ + if (!(ini = fopen((file = "gmqcc.ini"), "r"))) + /* try cfg */ + if (!(ini = fopen((file = "gmqcc.cfg"), "r"))) + return; + } else if (!(ini = fopen(file, "r"))) + return; con_out("found ini file `%s`\n", file);