]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Fixes, but still crashes because ... I have no clue, there is no reason for this...
authorDale Weiler <killfieldengine@gmail.com>
Mon, 17 Dec 2012 15:38:32 +0000 (15:38 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Mon, 17 Dec 2012 15:39:22 +0000 (15:39 +0000)
ftepp.c
main.c

diff --git a/ftepp.c b/ftepp.c
index 6fff6e09be19b8db25064aea5fa88cb243d31c9e..d3e58df083fe64a2fa82787de96befc945b4943b 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -1369,6 +1369,13 @@ bool ftepp_preprocess_string(const char *name, const char *str)
 
 void ftepp_add_macro(const char *name, const char *value) {
     char *create = NULL;
+
+    /* use saner path for empty macros */
+    if (!value) {
+        ftepp_add_define("__builtin__", name);
+        return;
+    }
+
     vec_upload(create, "#define ", 8);
     vec_upload(create, name,  strlen(name));
     vec_push  (create, ' ');
diff --git a/main.c b/main.c
index ca8ff42da2e928f4f1e7488dc1ec45368135f9dc..1bb988324aa8ecb837bce5542c536be3711bd334 100644 (file)
--- a/main.c
+++ b/main.c
@@ -312,13 +312,19 @@ static bool options_parse(int argc, char **argv) {
                     break;
 
                 case 'D':
-                    if (!(argarg = strchr(argv[0] + 2, '='))) {
-                        con_out("missing = in -D\n");
+                    if (!strlen(argv[0]+2)) {
+                        con_err("expected name after -D\n");
                         exit(0);
                     }
-                    *argarg='\0'; /* terminate for name */
-                    macro.name  = util_strdup(argarg);
-                    macro.value = util_strdup(argv[0]+2);
+
+                    if (!(argarg = strchr(argv[0] + 2, '='))) {
+                        macro.name  = util_strdup(argv[0]+2);
+                        macro.value = NULL;
+                    } else {
+                        *argarg='\0'; /* terminate for name */
+                        macro.name  = util_strdup(argv[0]+2);
+                        macro.value = util_strdup(argarg+1);
+                    }
                     vec_push(ppems, macro);
                     break;
 
@@ -625,18 +631,21 @@ int main(int argc, char **argv) {
             con_err("failed to initialize parser\n");
             retval = 1;
             goto cleanup;
-        } else {
-            size_t i;
-            for (i = 0; i < vec_size(ppems); ++i) {
-                ftepp_add_macro(ppems[i].name, ppems[i].value);
-                mem_d(ppems[i].name);
-                mem_d(ppems[i].value);
-            }
         }
     }
 
     util_debug("COM", "starting ...\n");
 
+    /* add macros */
+    for (itr = 0; itr < vec_size(ppems); itr++) {
+        ftepp_add_macro(ppems[itr].name, ppems[itr].value);
+        mem_d(ppems[itr].name);
+
+        /* can be null */
+        if (ppems[itr].value)
+            mem_d(ppems[itr].value);
+    }
+
     if (!vec_size(items)) {
         FILE *src;
         char *line;