]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lex.c
Indentation
[xonotic/gmqcc.git] / lex.c
diff --git a/lex.c b/lex.c
index ae73dc1f97ac26b527b8de9bed40455f7a5620f3..556f485536934d6a860ddc40197bb5aa6327cb0f 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -48,6 +48,7 @@ struct lex_file *lex_open(FILE *fp) {
        lex->size   = lex->length; /* copy, this is never changed */
        fseek(lex->file, 0, SEEK_SET);
        lex->last = 0;
+       lex->line = 0;
        
        memset(lex->peek, 0, sizeof(lex->peek));
        return lex;
@@ -138,10 +139,21 @@ static int lex_digraph(struct lex_file *file, int first) {
 
 static int lex_getch(struct lex_file *file) {
        int ch = lex_inget(file);
-       if (ch == '?')
-               return lex_trigraph(file);
-       if (ch == '<' || ch == ':' || ch == '%')
-               return lex_digraph (file, ch);
+
+       static int str = 0;
+       switch (ch) {
+               case '?' :
+                       return lex_trigraph(file);
+               case '<' :
+               case ':' :
+               case '%' :
+               case '"' : str = !str; if (str) { file->line ++; }
+                       return lex_digraph(file, ch);
+                       
+               case '\n':
+                       if (!str)
+                               file->line++;
+       }
                
        return ch;
 }
@@ -150,7 +162,7 @@ static int lex_get(struct lex_file *file) {
        int ch;
        if (!isspace(ch = lex_getch(file)))
                return ch;
-       
+               
        /* skip over all spaces */
        while (isspace(ch) && ch != '\n')
                ch = lex_getch(file);
@@ -258,7 +270,8 @@ static int lex_getsource(struct lex_file *file) {
                case '\'': return lex_skipchr(file);
                case '"':  return lex_skipstr(file);
                case '/':  return lex_skipcmt(file);
-               default:   return ch;
+               default:
+                       return ch;
        }
 }
 
@@ -269,7 +282,14 @@ int lex_token(struct lex_file *file) {
        /* valid identifier */
        if (ch > 0 && (ch == '_' || isalpha(ch))) {
                lex_clear(file);
-               while (ch > 0 && (isalpha(ch) || ch == '_')) {
+               
+               /*
+                * Yes this is dirty, but there is no other _sane_ easy
+                * way to do it, this is what I call defensive programming
+                * if something breaks, add more defense :-)
+                */
+               while (ch >   0   && ch != ' ' && ch != '(' &&
+                      ch != '\n' && ch != ';' && ch != ')') {
                        lex_addch(ch, file);
                        ch = lex_getsource(file);
                }
@@ -293,7 +313,7 @@ int lex_token(struct lex_file *file) {
                        if (!strncmp(X, "entity", sizeof("entity"))) \
                            return TOKEN_ENTITY;                     \
                        if (!strncmp(X, "void"  , sizeof("void")))   \
-                               return TOKEN_VOID;                       \
+                           return TOKEN_VOID;                       \
                    } while(0)
                
                TEST_TYPE(file->lastok);
@@ -302,6 +322,7 @@ int lex_token(struct lex_file *file) {
                if (typedef_find(file->lastok))
                        TEST_TYPE(typedef_find(file->lastok)->name);
                        
+               #undef TEST_TYPE
                return LEX_IDENT;
        }
        return ch;