]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Implemented platform[safe, neutral], compiler[safe, neutral] and C version[safe,...
authorDale Weiler <killfieldengine@gmail.com>
Wed, 25 Apr 2012 21:03:56 +0000 (17:03 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Wed, 25 Apr 2012 21:03:56 +0000 (17:03 -0400)
gmqcc.h
main.c

diff --git a/gmqcc.h b/gmqcc.h
index 24d34cda71217f9f3027598ea9f994340ba92529..d40314f841cfbd754e695813f74839ee90a7618f 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
+
+/*
+ * We cannoy rely on C99 at all, since compilers like MSVC
+ * simply don't support it.  We define our own boolean type
+ * as a result (since we cannot include <stdbool.h>). For
+ * compilers that are in 1999 mode (C99 compliant) we can use
+ * the language keyword _Bool which can allow for better code
+ * on GCC and GCC-like compilers, opposed to `int`.
+ */
+#ifndef __cplusplus
+#   ifdef  false
+#       undef  false
+#   endif /* !false */
+#   ifdef  true
+#       undef true
+#   endif /* !true  */
+#   define false (0)
+#   define true  (1)
+#   define bool _Bool
+#   if __STDC_VERSION__ < 199901L && __GNUC__ < 3
+        typedef int  _Bool
+#   endif
+#   endif /* !__cplusplus */
+
 /*
  * stdint.h and inttypes.h -less subset
  * for systems that don't have it, which we must
@@ -508,8 +532,9 @@ enum {
     COMPILER_QCCX,    /* qccx   QuakeC */
     COMPILER_GMQCC    /* this   QuakeC */
 };
-extern int opts_debug;
-extern int opts_memchk;
-extern int opts_darkplaces_stringtablebug;
-extern int opts_omit_nullcode;
+extern bool opts_debug;
+extern bool opts_memchk;
+extern bool opts_darkplaces_stringtablebug;
+extern bool opts_omit_nullcode;
+extern int  opts_compiler;
 #endif
diff --git a/main.c b/main.c
index 88481e388d2c0fa004f678c27c4bcd70fdc6287a..89090ba22246f6e00292e3c1e4089c8b49b5a93f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,11 +26,11 @@ typedef struct { char *name, type; } argitem;
 VECTOR_MAKE(argitem, items);
 
 /* global options */
-int opts_debug                     = 0;
-int opts_memchk                    = 0;
-int opts_compiler                  = COMPILER_GMQCC;
-int opts_darkplaces_stringtablebug = 0;
-int opts_omit_nullcode             = 0;
+bool opts_debug                     = false;
+bool opts_memchk                    = false;
+bool opts_darkplaces_stringtablebug = false;
+bool opts_omit_nullcode             = false;
+int  opts_compiler                  = COMPILER_GMQCC;
 
 static const int usage(const char *const app) {
     printf("usage:\n");
@@ -73,8 +73,8 @@ int main(int argc, char **argv) {
             case 'a': items_add((argitem){util_strdup(&argv[1][2]), 1}); break; /* assemble */
             case 'i': items_add((argitem){util_strdup(&argv[1][2]), 2}); break; /* includes */
             default:
-                if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug  = 1; break; }
-                if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = 1; break; }
+                if (!strncmp(&argv[1][1], "debug" , 5)) { opts_debug  = true; break; }
+                if (!strncmp(&argv[1][1], "memchk", 6)) { opts_memchk = true; break; }
                 if (!strncmp(&argv[1][1], "help",   4)) {
                     return usage(app);
                     break;
@@ -95,11 +95,11 @@ int main(int argc, char **argv) {
 
                 /* code specific switches */
                 if (!strcmp(&argv[1][1], "fdarkplaces-stringtablebug")) {
-                    opts_darkplaces_stringtablebug = 1;
+                    opts_darkplaces_stringtablebug = true;
                     break;
                 }
                 if (!strcmp(&argv[1][1], "fomit-nullcode")) {
-                    opts_omit_nullcode = 1;
+                    opts_omit_nullcode = true;
                     break;
                 }
                 return usage(app);