]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
Added command line parsing to test-suite
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index 0b9d726744a4169220e92916c96899835ad3716f..b483db9880d1dd4b4de6a19f2515e5aee3c6f4af 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,7 +46,7 @@ const oper_info *operators      = NULL;
 size_t           operator_count = 0;
 
 typedef struct { char *filename; int type; } argitem;
-VECTOR_MAKE(argitem, items);
+static argitem *items = NULL;
 
 #define TYPE_QC  0
 #define TYPE_ASM 1
@@ -181,7 +181,10 @@ static void options_set(uint32_t *flags, size_t idx, bool on)
 static bool options_parse(int argc, char **argv) {
     bool argend = false;
     size_t itr;
-    char buffer[1024];
+    char  buffer[1024];
+    char *redirout = (char*)stdout;
+    char *redirerr = (char*)stderr;
+
     while (!argend && argc > 1) {
         char *argarg;
         argitem item;
@@ -215,6 +218,15 @@ static bool options_parse(int argc, char **argv) {
                 opts_forced_crc = strtol(argarg, NULL, 0);
                 continue;
             }
+            if (options_long_gcc("redirout", &argc, &argv, &redirout)) {
+                continue;
+            }
+            if (options_long_gcc("redirerr", &argc, &argv, &redirerr)) {
+                continue;
+            }
+            
+            con_change(redirout, redirerr);
+
             if (!strcmp(argv[0]+1, "debug")) {
                 opts_debug = true;
                 continue;
@@ -227,6 +239,10 @@ static bool options_parse(int argc, char **argv) {
                 opts_memchk = true;
                 continue;
             }
+            if (!strcmp(argv[0]+1, "nocolor")) {
+                con_color(0);
+                continue;
+            }
 
             switch (argv[0][1]) {
                 /* -h, show usage but exit with 0 */
@@ -327,7 +343,7 @@ static bool options_parse(int argc, char **argv) {
                         return false;
                     }
                     item.filename = argarg;
-                    items_add(item);
+                    vec_push(items, item);
                     break;
 
                 case '-':
@@ -364,15 +380,14 @@ static bool options_parse(int argc, char **argv) {
             argitem item;
             item.filename = argv[0];
             item.type     = TYPE_QC;
-            items_add(item);
+            vec_push(items, item);
         }
     }
     return true;
 }
 
 /* returns the line number, or -1 on error */
-static bool progs_nextline(char **out, size_t *alen,FILE *src)
-{
+static bool progs_nextline(char **out, size_t *alen,FILE *src) {
     int    len;
     char  *line;
     char  *start;
@@ -457,21 +472,21 @@ int main(int argc, char **argv) {
 
     util_debug("COM", "starting ...\n");
 
-    if (items_elements) {
+    if (vec_size(items)) {
         con_out("Mode: manual\n");
-        con_out("There are %lu items to compile:\n", (unsigned long)items_elements);
-        for (itr = 0; itr < items_elements; ++itr) {
+        con_out("There are %lu items to compile:\n", (unsigned long)vec_size(items));
+        for (itr = 0; itr < vec_size(items); ++itr) {
             con_out("  item: %s (%s)\n",
-                   items_data[itr].filename,
-                   ( (items_data[itr].type == TYPE_QC ? "qc" :
-                     (items_data[itr].type == TYPE_ASM ? "asm" :
-                     (items_data[itr].type == TYPE_SRC ? "progs.src" :
+                   items[itr].filename,
+                   ( (items[itr].type == TYPE_QC ? "qc" :
+                     (items[itr].type == TYPE_ASM ? "asm" :
+                     (items[itr].type == TYPE_SRC ? "progs.src" :
                      ("unknown"))))));
 
-        if (!parser_compile_file(items_data[itr].filename))
-        {
-                retval = 1;
-                goto cleanup;
+            if (!parser_compile_file(items[itr].filename))
+            {
+                    retval = 1;
+                    goto cleanup;
             }
         }
 
@@ -526,8 +541,8 @@ srcdone:
 
 cleanup:
     util_debug("COM", "cleaning ...\n");
-
-    mem_d(items_data);
+    con_close();
+    vec_free(items);
 
     parser_cleanup();
     if (opts_output_free)