]> 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 bfa7443f3eb09fa13e1b104e33f67562a84f7b88..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;
@@ -523,13 +527,20 @@ int lex_do(lex_file *lex)
                        case '^':
                        case '~':
                        case ',':
-                               return ch;
+                   case '.':
+                   case '!':
+                   if (!lex_tokench(lex, ch) ||
+                       !lex_endtoken(lex))
+                   {
+                       return (lex->tok->ttype = TOKEN_FATAL);
+                   }
+                               return (lex->tok->ttype = ch);
                        default:
                                break;
                }
        }
 
-       if (ch == ',') {
+       if (ch == ',' || ch == '.') {
            if (!lex_tokench(lex, ch) ||
                !lex_endtoken(lex))
            {
@@ -540,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))
@@ -561,6 +572,7 @@ int lex_do(lex_file *lex)
                return (lex->tok->ttype = TOKEN_OPERATOR);
        }
 
+    /*
        if (ch == '^' || ch == '~' || ch == '!')
        {
                if (!lex_tokench(lex, ch) ||
@@ -570,6 +582,7 @@ int lex_do(lex_file *lex)
                }
                return (lex->tok->ttype = TOKEN_OPERATOR);
        }
+       */
 
        if (ch == '*' || ch == '/') /* *=, /= */
        {
@@ -623,7 +636,9 @@ int lex_do(lex_file *lex)
                } else if (!strcmp(v, "for")  ||
                         !strcmp(v, "while")  ||
                         !strcmp(v, "do")     ||
-                        !strcmp(v, "var")    ||
+                        !strcmp(v, "if")     ||
+                        !strcmp(v, "else")   ||
+                        !strcmp(v, "local")  ||
                         !strcmp(v, "return") ||
                         !strcmp(v, "const"))
                        lex->tok->ttype = TOKEN_KEYWORD;
@@ -662,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;
                 }