]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
NOT for entity, function and string - we're not constant-folding it for functions...
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index 29b3018916b4f93f3f74b5235b7cf108beb05695..382512de20cf71c4955802080cdceef53e7e76aa 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -122,7 +122,7 @@ token* token_copy_all(const token *cp)
 lex_file* lex_open(const char *file)
 {
        lex_file *lex;
-       FILE *in = fopen(file, "rb");
+       FILE *in = util_fopen(file, "rb");
 
        if (!in) {
                lexerror(NULL, "open failed: '%s'\n", file);
@@ -498,7 +498,11 @@ int lex_do(lex_file *lex)
                case ']':
 
                case '#':
-
+               if (!lex_tokench(lex, ch) ||
+                   !lex_endtoken(lex))
+               {
+                   return (lex->tok->ttype = TOKEN_FATAL);
+               }
                        return (lex->tok->ttype = ch);
                default:
                        break;
@@ -524,6 +528,12 @@ int lex_do(lex_file *lex)
                        case '~':
                        case ',':
                    case '.':
+                   case '!':
+                   if (!lex_tokench(lex, ch) ||
+                       !lex_endtoken(lex))
+                   {
+                       return (lex->tok->ttype = TOKEN_FATAL);
+                   }
                                return (lex->tok->ttype = ch);
                        default:
                                break;
@@ -541,7 +551,7 @@ int lex_do(lex_file *lex)
 
        if (ch == '+' || ch == '-' || /* ++, --, +=, -=  and -> as well! */
            ch == '>' || ch == '<' || /* <<, >>, <=, >= */
-           ch == '=' ||              /* == */
+           ch == '=' || ch == '!' || /* ==, != */
            ch == '&' || ch == '|')   /* &&, ||, &=, |= */
        {
                if (!lex_tokench(lex, ch))
@@ -562,6 +572,7 @@ int lex_do(lex_file *lex)
                return (lex->tok->ttype = TOKEN_OPERATOR);
        }
 
+    /*
        if (ch == '^' || ch == '~' || ch == '!')
        {
                if (!lex_tokench(lex, ch) ||
@@ -571,6 +582,7 @@ int lex_do(lex_file *lex)
                }
                return (lex->tok->ttype = TOKEN_OPERATOR);
        }
+       */
 
        if (ch == '*' || ch == '/') /* *=, /= */
        {
@@ -626,7 +638,7 @@ int lex_do(lex_file *lex)
                         !strcmp(v, "do")     ||
                         !strcmp(v, "if")     ||
                         !strcmp(v, "else")   ||
-                        !strcmp(v, "var")    ||
+                        !strcmp(v, "local")  ||
                         !strcmp(v, "return") ||
                         !strcmp(v, "const"))
                        lex->tok->ttype = TOKEN_KEYWORD;
@@ -665,7 +677,13 @@ int lex_do(lex_file *lex)
                         return (lex->tok->ttype = TOKEN_FATAL);
 
                 /* It's a vector if we can successfully scan 3 floats */
-                if (sscanf(lex->tok->value, " %f %f %f ", &lex->tok->constval.v.x, &lex->tok->constval.v.y, &lex->tok->constval.v.z) == 3)
+#ifdef WIN32
+                if (sscanf_s(lex->tok->value, " %f %f %f ",
+                           &lex->tok->constval.v.x, &lex->tok->constval.v.y, &lex->tok->constval.v.z) == 3)
+#else
+                if (sscanf(lex->tok->value, " %f %f %f ",
+                           &lex->tok->constval.v.x, &lex->tok->constval.v.y, &lex->tok->constval.v.z) == 3)
+#endif
                 {
                         lex->tok->ttype = TOKEN_VECTORCONST;
                 }