]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
util_strncmpexact
authorDale Weiler <killfieldengine@gmail.com>
Sat, 5 May 2012 02:01:02 +0000 (22:01 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 5 May 2012 02:01:02 +0000 (22:01 -0400)
asm.c
data/test.qs
gmqcc.h
main.c
util.c

diff --git a/asm.c b/asm.c
index 59572ed0d76adf2b62877c7eeb5b045d1e824c0c..1c001990f63227592d530dd956ed8770ece26317 100644 (file)
--- a/asm.c
+++ b/asm.c
@@ -576,7 +576,7 @@ static GMQCC_INLINE bool asm_parse_stmt(const char *skip, size_t line, asm_state
                                 *strchr(Y, ' ')='\0';                                              \
                             }                                                                      \
                             for (; f<asm_symbols_elements; f++) {                                  \
-                                if (!strcnmp(asm_symbols_data[f].name, (Y), strlen(Y)) &&          \
+                                if (!strncmp(asm_symbols_data[f].name, (Y), strlen(Y)) &&          \
                                             asm_symbols_data[f].type == TYPE_FUNCTION) {           \
                                     (X)=asm_symbols_data[f].offset;                                \
                                     goto OPCCAT(foundf, __LINE__);                                 \
index f3f0506310fe6fd95a7889c51f550ce607ba3940..6ebdf2a32a24360f98c68b7b82130e93e285570e 100644 (file)
@@ -82,29 +82,22 @@ FUNCTION: pow,            $97
 FUNCTION: findfloat,      $98
 FUNCTION: checkextension, $99
 
+FUNCTION: test     #0
+       FLOAT: x, 100
+       FLOAT: y, 200
 
-;code_chars_put("m_init",        0x6);
-;code_chars_put("m_keydown",     0x9);
-;code_chars_put("m_draw",        0x6);
-;code_chars_put("m_toggle",      0x8);
-;code_chars_put("m_shutdown",    0xA);
+       FLOAT: r_mul
+       FLOAT: r_div
+       FLOAT: r_add
+       FLOAT: r_sub
 
-FUNCTION: m_init     #0
-       CALL0 dprint
-END
-
-FUNCTION: m_keydown  #0
-       CALL0 dprint 
-END
+       MUL_V x,y,r_mul
+       DIV_V x,y,r_div
+       ADD_V x,y,r_add
+       SUV_V x,y,r_sub
 
-FUNCTION: m_draw     #3VVV
-       CALL0 dprint 
-END
-
-FUNCTION: m_toggle   #1S
-       CALL0 dprint 
-END
+       STORE_V r_mul
+       CALL0   dprint
 
-FUNCTION: m_shutdown #1S
-       CALL0 dprint 
+       STORE_V
 END
diff --git a/gmqcc.h b/gmqcc.h
index f8bb93e2cee725a86ee204e5af6a201474f6f73b..ec28a30e7fa72e609f5d6e87700f2b77fd2956d9 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -256,6 +256,7 @@ void  util_meminfo       ();
 
 bool  util_strupper      (const char *);
 bool  util_strdigit      (const char *);
+bool  util_strncmpexact  (const char *, const char *, size_t);
 char *util_strdup        (const char *);
 char *util_strrq         (const char *);
 char *util_strrnl        (const char *);
diff --git a/main.c b/main.c
index 2256dc444ff70179f5c7191e1bd93b1c0fe41c9e..bd53048cc28e282b690d0be52f766badfc6666a6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -101,18 +101,18 @@ int main(int argc, char **argv) {
             case 'i': { param_argument(2); break; } /* includes */
             #undef parm_argument
             default:
-                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)) {
+                if (util_strncmpexact(&argv[1][1], "debug" , 5)) { opts_debug  = true; break; }
+                if (util_strncmpexact(&argv[1][1], "memchk", 6)) { opts_memchk = true; break; }
+                if (util_strncmpexact(&argv[1][1], "help",   4)) {
                     return usage(app);
                     break;
                 }
                 /* compiler type selection */
-                if (!strncmp(&argv[1][1], "std=qcc"   , 7 )) { opts_compiler = COMPILER_QCC;    break; }
-                if (!strncmp(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
-                if (!strncmp(&argv[1][1], "std=qccx",   8 )) { opts_compiler = COMPILER_QCCX;   break; }
-                if (!strncmp(&argv[1][1], "std=gmqcc",  9 )) { opts_compiler = COMPILER_GMQCC;  break; }
-                if (!strncmp(&argv[1][1], "std=",       4 )) {
+                if (util_strncmpexact(&argv[1][1], "std=qcc"   , 7 )) { opts_compiler = COMPILER_QCC;    break; }
+                if (util_strncmpexact(&argv[1][1], "std=fteqcc", 10)) { opts_compiler = COMPILER_FTEQCC; break; }
+                if (util_strncmpexact(&argv[1][1], "std=qccx",   8 )) { opts_compiler = COMPILER_QCCX;   break; }
+                if (util_strncmpexact(&argv[1][1], "std=gmqcc",  9 )) { opts_compiler = COMPILER_GMQCC;  break; }
+                if (util_strncmpexact(&argv[1][1], "std=",       4 )) {
                     printf("invalid std selection, supported types:\n"
                            "    -std=qcc     -- original QuakeC\n"
                            "    -std=ftqecc  -- fteqcc QuakeC\n"
@@ -122,28 +122,27 @@ int main(int argc, char **argv) {
                 }
 
                 /* code specific switches */
-                if (!strcmp(&argv[1][1], "fdarkplaces-stringtablebug")) {
+                if (util_strncmpexact(&argv[1][1], "fdarkplaces-stringtablebug", 26)) {
                     opts_darkplaces_stringtablebug = true;
                     break;
                 }
-                if (!strcmp(&argv[1][1], "fomit-nullcode")) {
+                if (util_strncmpexact(&argv[1][1], "fomit-nullcode", 14)) {
                     opts_omit_nullcode = true;
                     break;
                 }
-                return usage(app);
+                return printf("invalid command line argument: %s\n", argv[1]);
 
         }
         ++argv;
         --argc;
     }
-
     /*
      * options could depend on another option, this is where option
      * validity checking like that would take place.
      */
     if (opts_memchk && !opts_debug)
         printf("Warning: cannot enable -memchk, without -debug.\n");
-
+    
     util_debug("COM", "starting ...\n");
     /* multi file multi path compilation system */
     for (; itr < items_elements; itr++) {
diff --git a/util.c b/util.c
index 123974cdf2aacea9824e5da7af8d45d3e76b8835..9b8fb5c9115c5ffbe25b72f2e11dfd3e8ed48b02 100644 (file)
--- a/util.c
+++ b/util.c
@@ -163,6 +163,14 @@ bool util_strdigit(const char *str) {
     return true;
 }
 
+bool util_strncmpexact(const char *src, const char *ned, size_t len) {
+    if (!strncmp(src, ned, len)) {
+        if (!src[len])
+            return true;
+    }
+    return false;
+}
+
 void util_debug(const char *area, const char *ms, ...) {
     va_list  va;
     if (!opts_debug)