]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
handling TOKEN_CHARCONST - -Wmultibyte-character
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index 3f00888532878df211f5928f28ed86359ee3c765..6ee7d8e4611968eb843023d3c6ac8ace965fc64b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2012
  *     Dale Weiler
+ *     Wolfgang Bumiller
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  * this software and associated documentation files (the "Software"), to deal in
@@ -31,6 +32,7 @@ const char *opts_output   = "progs.dat";
 int         opts_standard = COMPILER_GMQCC;
 bool        opts_debug    = false;
 bool        opts_memchk   = false;
+bool        opts_dumpfin  = false;
 bool        opts_dump     = false;
 bool        opts_werror   = false;
 bool        opts_forcecrc = false;
@@ -203,6 +205,7 @@ static bool options_parse(int argc, char **argv) {
                     opts_standard = COMPILER_QCC;
                 } else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) {
                     options_set(opts_flags, FTEPP,                true);
+                    options_set(opts_flags, TRANSLATABLE_STRINGS, true);
                     options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
                     opts_standard = COMPILER_FTEQCC;
                 } else if (!strcmp(argarg, "qccx")) {
@@ -220,11 +223,38 @@ static bool options_parse(int argc, char **argv) {
                 continue;
             }
             if (options_long_gcc("redirout", &argc, &argv, &redirout)) {
+                con_change(redirout, redirerr);
                 continue;
             }
             if (options_long_gcc("redirerr", &argc, &argv, &redirerr)) {
+                con_change(redirout, redirerr);
                 continue;
             }
+            
+            /* show defaults (like pathscale) */
+            if (!strcmp(argv[0]+1, "show-defaults")) {
+                size_t itr;
+                char   buffer[1024];
+                for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+                    if (!OPTS_FLAG(itr))
+                        continue;
+                        
+                    memset(buffer, 0, sizeof(buffer));
+                    util_strtononcmd(opts_flag_list[itr].name, buffer, strlen(opts_flag_list[itr].name) + 1);
+    
+                    con_out("-f%s ", buffer);
+                }
+                for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+                    if (!OPTS_WARN(itr))
+                        continue;
+                    
+                    memset(buffer, 0, sizeof(buffer));
+                    util_strtononcmd(opts_warn_list[itr].name, buffer, strlen(opts_warn_list[itr].name) + 1);
+                    con_out("-W%s ", buffer);
+                }
+                con_out("\n");
+                exit(0);
+            }
 
             if (!strcmp(argv[0]+1, "debug")) {
                 opts_debug = true;
@@ -234,6 +264,10 @@ static bool options_parse(int argc, char **argv) {
                 opts_dump = true;
                 continue;
             }
+            if (!strcmp(argv[0]+1, "dumpfin")) {
+                opts_dumpfin = true;
+                continue;
+            }
             if (!strcmp(argv[0]+1, "memchk")) {
                 opts_memchk = true;
                 continue;
@@ -248,7 +282,7 @@ static bool options_parse(int argc, char **argv) {
                 case 'h':
                     usage();
                     exit(0);
-                    break;
+                    /* break; never reached because of exit(0) */
 
                 case 'E':
                     opts_pp_only = true;
@@ -257,7 +291,7 @@ static bool options_parse(int argc, char **argv) {
                 /* handle all -fflags */
                 case 'f':
                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
-                    if (!strcmp(argv[0]+2, "HELP")) {
+                    if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
                         con_out("Possible flags:\n");
                         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
                             util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
@@ -278,7 +312,7 @@ static bool options_parse(int argc, char **argv) {
                     break;
                 case 'W':
                     util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
-                    if (!strcmp(argv[0]+2, "HELP")) {
+                    if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
                         con_out("Possible warnings:\n");
                         for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
                             util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
@@ -376,13 +410,11 @@ static bool options_parse(int argc, char **argv) {
         else
         {
             /* it's a QC filename */
-            argitem item;
             item.filename = argv[0];
             item.type     = TYPE_QC;
             vec_push(items, item);
         }
     }
-    con_change(redirout, redirerr);
     return true;
 }
 
@@ -440,6 +472,9 @@ int main(int argc, char **argv) {
     options_set(opts_warn, WARN_ASSIGN_FUNCTION_TYPES, true);
     options_set(opts_warn, WARN_PREPROCESSOR, true);
     options_set(opts_warn, WARN_MULTIFILE_IF, true);
+    options_set(opts_warn, WARN_DOUBLE_DECLARATION, true);
+    options_set(opts_warn, WARN_CONST_VAR, true);
+    options_set(opts_warn, WARN_MULTIBYTE_CHARACTER, true);
 
     options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
     options_set(opts_flags, FTEPP, false);
@@ -452,6 +487,9 @@ int main(int argc, char **argv) {
     if (opts_standard == COMPILER_GMQCC) {
         operators = c_operators;
         operator_count = c_operator_count;
+    } else if (opts_standard == COMPILER_FTEQCC) {
+        operators = fte_operators;
+        operator_count = fte_operator_count;
     } else {
         operators = qcc_operators;
         operator_count = qcc_operator_count;
@@ -558,11 +596,14 @@ srcdone:
             }
 
             if (opts_pp_only) {
+                const char *out;
                 if (!ftepp_preprocess_file(items[itr].filename)) {
                     retval = 1;
                     goto cleanup;
                 }
-                fprintf(outfile, "%s", ftepp_get());
+                out = ftepp_get();
+                if (out)
+                    fprintf(outfile, "%s", out);
                 ftepp_flush();
             }
             else {
@@ -610,7 +651,8 @@ cleanup:
     con_close();
     vec_free(items);
 
-    parser_cleanup();
+    if (!opts_pp_only)
+        parser_cleanup();
     if (opts_output_free)
         mem_d((char*)opts_output);