]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Allow setting configuration file via commandline
authorDale Weiler <killfieldengine@gmail.com>
Tue, 18 Dec 2012 05:22:23 +0000 (05:22 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 18 Dec 2012 05:22:23 +0000 (05:22 +0000)
gmqcc.h
main.c
opts.c

diff --git a/gmqcc.h b/gmqcc.h
index 5f39634528e375f1b01ddcbc07c643bfb007281e..b95bac4fc2268b2ca3f9db035831b2c0f204702a 100644 (file)
--- 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 6ae009145479850cca3c0f3dc5aaaf3db6eab007..80f242c52ea08cbc26b0143d0e617cf50d7e2d68 100644 (file)
--- 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 93433b6b0cfe82098ec3ad2bdf1a5daf501dc5d2..6a6af173682a507530173c8d9795e43d434eecb3 100644 (file)
--- 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);