]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Cleanups
authorDale Weiler <killfieldengine@gmail.com>
Sun, 15 Apr 2012 21:47:14 +0000 (17:47 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 15 Apr 2012 21:47:14 +0000 (17:47 -0400)
gmqcc.h
lex.c
parse.c
util.c

diff --git a/gmqcc.h b/gmqcc.h
index d201c7885da237327aa51c87449acf9703d150cd..665d8c98ecdfcf450517221ddacd3b0b0414a7fa 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -116,6 +116,8 @@ int           typedef_add (const char *, const char *);
 void *util_memory_a(unsigned int, unsigned int, const char *);
 void  util_memory_d(void       *, unsigned int, const char *);
 char *util_strdup  (const char *);
+char *util_strrq   (char *);
+void  util_debug   (const char *, const char *, ...);
 
 #ifdef NOTRACK
 #      define mem_a(x) malloc(x)
diff --git a/lex.c b/lex.c
index bedaaa9db5e2c839e77a124fddc288fc88528398..560a1eaa84957df2b5269725e8710e2384919c29 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -344,22 +344,7 @@ void lex_reset(struct lex_file *file) {
  * recrusion.
  */
 struct lex_file *lex_include(struct lex_file *lex, char *file) {
-       char *find = (char*)file;
-       /* 
-        * strip for "" (quotes) .. they might be part of the current
-        * thing.  Or possibly not.
-        */
-       if (*find == '"') {
-               find++;
-               file++;
-               while (*find != '"' && *find != '\0')
-                       find++;
-       
-               /* strip end "" (quotes) .. if they're actually there */
-               if (*find != '\0')
-                       *find  = '\0';
-       }
-       
+       char *find = util_strrq(file);
        /*
         * Dissallow recrusive include: this could easily cause some breakage
         * and instant OOM.
@@ -375,9 +360,5 @@ struct lex_file *lex_include(struct lex_file *lex, char *file) {
                exit (-1);
        }
        
-       /* must free strdup */
-       file --;
-       mem_d (file);
-       
        return lex_open(fp);
 }
diff --git a/parse.c b/parse.c
index cc228ed1b9c268970de55f072a89d8c9e0352a5a..3cbde9ef5009df31a33d2a76d2e539d38963ee39 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -35,6 +35,19 @@ typedef struct {
 } constant;
 VECTOR_MAKE(constant, compile_constants);
 
+void compile_constant_debug() {
+       int iter = 0;
+       for(; iter < compile_constants_elements; iter++) {
+               constant *c = &compile_constants_data[iter];
+               switch(c->type) {
+                       case TYPE_FLOAT:  printf("constant: %s FLOAT   %f\n",       c->name, c->value[0]);                           break;
+                       case TYPE_VECTOR: printf("constant: %s VECTOR {%f,%f,%f}\n",c->name, c->value[0], c->value[1], c->value[2]); break;
+                       case TYPE_STRING: printf("constant: %s STRING  %s\n",       c->name, c->string); break;
+                       case TYPE_VOID:   printf("constant: %s VOID    %s\n",       c->name, c->string); break;
+               }
+       }
+}
+
 /*
  * Generates a parse tree out of the lexees generated by the lexer.  This
  * is where the tree is built.  This is where valid check is performed.
@@ -264,6 +277,12 @@ int parse_gen(struct lex_file *file) {
                                                error(ERROR_INTERNAL, "Include subsystem failure\n");
                                                exit (-1);
                                        }
+                                       compile_constants_add((constant) {
+                                                       .name   = "#include",
+                                                       .type   = TYPE_VOID,
+                                                       .value  = {0,0,0},
+                                                       .string = copy
+                                       });
                                        parse_gen(next);
                                        mem_d    (copy);
                                        lex_close(next);
@@ -278,6 +297,7 @@ int parse_gen(struct lex_file *file) {
                                break;
                }
        }
+       compile_constant_debug();
        lex_reset(file);
        return 1;
 }      
diff --git a/util.c b/util.c
index 76bd44865c8164c1592c8c370dac252e02789b7a..b6264cca7df3346dec5c6e7fad27207635043762 100644 (file)
--- a/util.c
+++ b/util.c
@@ -81,6 +81,28 @@ char *util_strdup(const char *s) {
        return ptr;
 }
 
+/*
+ * Removed quotes from a string, escapes from \ in string
+ * as well.  This function shouldn't be used to create a
+ * char array that is later freed (it uses pointer arith)
+ */
+char *util_strrq(char *s) {
+       char *dst = s;
+       char *src = s;
+       char  chr;
+       while ((chr = *src++) != '\0') {
+               if (chr == '\\') {
+                       *dst++ = chr;
+                       if ((chr = *src++) == '\0')
+                               break;
+                       *dst++ = chr;
+               } else if (chr != '"')
+                       *dst++ = chr;
+       }
+       *dst = '\0';
+       return dst;
+}
+
 void util_debug(const char *area, const char *ms, ...) {
        va_list  va;
        va_start(va, ms);