]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - opts.c
Initial platform / compiler specific code refactoring.
[xonotic/gmqcc.git] / opts.c
diff --git a/opts.c b/opts.c
index 4cfa79c9eb13fd900e2cf5935db8fb253169a42c..570b5789116f68cc9b435e5e0d30d5b9c809e880 100644 (file)
--- a/opts.c
+++ b/opts.c
  */
 #include <string.h>
 #include <stdlib.h>
-#include <ctype.h>
 
 #include "gmqcc.h"
 
+const unsigned int opts_opt_oflag[COUNT_OPTIMIZATIONS+1] = {
+# define GMQCC_TYPE_OPTIMIZATIONS
+# define GMQCC_DEFINE_FLAG(NAME, MIN_O) MIN_O,
+#  include "opts.def"
+    0
+};
+
+const opts_flag_def_t opts_opt_list[COUNT_OPTIMIZATIONS+1] = {
+# define GMQCC_TYPE_OPTIMIZATIONS
+# define GMQCC_DEFINE_FLAG(NAME, MIN_O) { #NAME, LONGBIT(OPTIM_##NAME) },
+#  include "opts.def"
+    { NULL, LONGBIT(0) }
+};
+
+const opts_flag_def_t opts_warn_list[COUNT_WARNINGS+1] = {
+# define GMQCC_TYPE_WARNS
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(WARN_##X) },
+#  include "opts.def"
+    { NULL, LONGBIT(0) }
+};
+
+const opts_flag_def_t opts_flag_list[COUNT_FLAGS+1] = {
+# define GMQCC_TYPE_FLAGS
+# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
+#  include "opts.def"
+    { NULL, LONGBIT(0) }
+};
+
 unsigned int opts_optimizationcount[COUNT_OPTIMIZATIONS];
-opts_cmd_t   opts; /* command lien options */
+opts_cmd_t   opts; /* command line options */
 
-static void opts_setdefault() {
+static void opts_setdefault(void) {
     memset(&opts, 0, sizeof(opts_cmd_t));
     OPTS_OPTION_BOOL(OPTION_CORRECTION) = true;
+    OPTS_OPTION_STR(OPTION_PROGSRC) = "progs.src";
 
     /* warnings */
     opts_set(opts.warn,  WARN_UNUSED_VARIABLE,           true);
@@ -62,6 +90,8 @@ static void opts_setdefault() {
     opts_set(opts.warn,  WARN_UNINITIALIZED_CONSTANT,    true);
     opts_set(opts.warn,  WARN_DEPRECATED,                true);
     opts_set(opts.warn,  WARN_PARENTHESIS,               true);
+    opts_set(opts.warn,  WARN_CONST_OVERWRITE,           true);
+    opts_set(opts.warn,  WARN_DIRECTIVE_INMACRO,         true);
 
     /* flags */
     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
@@ -105,7 +135,7 @@ void opts_init(const char *output, int standard, size_t arraysize) {
     OPTS_OPTION_U16(OPTION_MEMDUMPCOLS)    = 16;
 }
 
-static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) {
+static bool opts_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def_t *list, size_t listsize) {
     size_t i;
 
     for (i = 0; i < listsize; ++i) {
@@ -163,13 +193,13 @@ void opts_setoptimlevel(unsigned int level) {
  */
 static char *opts_ini_rstrip(char *s) {
     char *p = s + strlen(s);
-    while(p > s && isspace(*--p))
+    while(p > s && util_isspace(*--p))
         *p = '\0';
     return s;
 }
 
 static char *opts_ini_lskip(const char *s) {
-    while (*s && isspace(*s))
+    while (*s && util_isspace(*s))
         s++;
     return (char*)s;
 }
@@ -177,7 +207,7 @@ static char *opts_ini_lskip(const char *s) {
 static char *opts_ini_next(const char *s, char c) {
     bool last = false;
     while (*s && *s != c && !(last && *s == ';'))
-        last = !!isspace(*s), s++;
+        last = !!util_isspace(*s), s++;
 
     return (char*)s;
 }
@@ -221,7 +251,7 @@ static size_t opts_ini_parse (
             /* section found */
             if (*(parse_end = opts_ini_next(parse_beg + 1, ']')) == ']') {
                 * parse_end = '\0'; /* terminate bro */
-                util_strncpy(section_data, parse_beg + 1, sizeof(section_data));
+                platform_strncpy(section_data, parse_beg + 1, sizeof(section_data));
                 section_data[sizeof(section_data) - 1] = '\0';
                 *oldname_data                          = '\0';
             } else if (!error) {
@@ -242,7 +272,7 @@ static size_t opts_ini_parse (
                 opts_ini_rstrip(read_value);
 
                 /* valid name value pair, lets call down to handler */
-                util_strncpy(oldname_data, read_name, sizeof(oldname_data));
+                platform_strncpy(oldname_data, read_name, sizeof(oldname_data));
                 oldname_data[sizeof(oldname_data) - 1] ='\0';
 
                 if ((*errorhandle = loadhandle(section_data, read_name, read_value)) && !error)
@@ -321,16 +351,16 @@ static char *opts_ini_load(const char *section, const char *name, const char *va
             strcmp(section, "warnings")      &&
             strcmp(section, "optimizations"))
         {
-            vec_upload(error, "invalid section `", 17);
-            vec_upload(error, section, strlen(section));
+            vec_append(error, 17,             "invalid section `");
+            vec_append(error, strlen(section), section);
             vec_push  (error, '`');
             vec_push  (error, '\0');
         } else {
-            vec_upload(error, "invalid variable `", 18);
-            vec_upload(error, name, strlen(name));
+            vec_append(error, 18,             "invalid variable `");
+            vec_append(error, strlen(name), name);
             vec_push  (error, '`');
-            vec_upload(error, " in section: `", 14);
-            vec_upload(error, section, strlen(section));
+            vec_append(error, 14,              " in section: `");
+            vec_append(error, strlen(section), section);
             vec_push  (error, '`');
             vec_push  (error, '\0');
         }
@@ -348,11 +378,10 @@ void opts_ini_init(const char *file) {
      *  gmqcc.ini
      *  gmqcc.cfg
      */
-    char       *error;
+    char       *error = NULL;
     size_t     line;
     FILE       *ini;
 
-
     if (!file) {
         /* try ini */
         if (!(ini = fs_file_open((file = "gmqcc.ini"), "r")))