]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
keep the filenames of all lexed files in a global lex_filenames vector because we...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:47:33 +0000 (16:47 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sat, 18 Aug 2012 14:47:33 +0000 (16:47 +0200)
lexer.c
lexer.h
main.c

diff --git a/lexer.c b/lexer.c
index 9956e0f7ff13927b1570147c759d764314884db7..d9483d806e9f2afe1538a9916a77881fc393d4ec 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -9,6 +9,8 @@
 MEM_VEC_FUNCTIONS(token, char, value)
 MEM_VEC_FUNCTIONS(lex_file, frame_macro, frames)
 
+VECTOR_MAKE(char*, lex_filenames);
+
 void lexerror(lex_file *lex, const char *fmt, ...)
 {
     va_list ap;
@@ -145,9 +147,19 @@ lex_file* lex_open(const char *file)
 
     lex->peekpos = 0;
 
+    lex_filenames_add(lex->name);
+
     return lex;
 }
 
+void lex_cleanup(void)
+{
+    size_t i;
+    for (i = 0; i < lex_filenames_elements; ++i)
+        mem_d(lex_filenames_data[i]);
+    mem_d(lex_filenames_data);
+}
+
 void lex_close(lex_file *lex)
 {
     size_t i;
@@ -162,7 +174,7 @@ void lex_close(lex_file *lex)
         fclose(lex->file);
     if (lex->tok)
         token_delete(lex->tok);
-    mem_d(lex->name);
+    /* mem_d(lex->name); collected in lex_filenames */
     mem_d(lex);
 }
 
diff --git a/lexer.h b/lexer.h
index 5e0d18cd40ffc29e61b2d3e8be89f4939d58a683..b3114ec8b0969dd6407d471ff1348a5a88b5c145 100644 (file)
--- a/lexer.h
+++ b/lexer.h
@@ -111,6 +111,7 @@ MEM_VECTOR_PROTO(lex_file, char, token);
 lex_file* lex_open (const char *file);
 void      lex_close(lex_file   *lex);
 int       lex_do   (lex_file   *lex);
+void      lex_cleanup(void);
 
 /* Parser
  *
diff --git a/main.c b/main.c
index d354e3d46b6283b40261675ee8730fdab1476fc6..7369a9ca7d06987be0a7863becc8fe0583b42cb4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@
  * SOFTWARE.
  */
 #include "gmqcc.h"
+#include "lexer.h"
 
 uint32_t    opts_flags[1 + (COUNT_FLAGS / 32)];
 uint32_t    opts_warn [1 + (COUNT_WARNINGS / 32)];
@@ -475,6 +476,7 @@ cleanup:
     if (opts_output_free)
         mem_d((char*)opts_output);
 
+    lex_cleanup();
     util_meminfo();
     return retval;
 }