]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - lexer.c
string-literals now do not treat digraphs as digraphs
[xonotic/gmqcc.git] / lexer.c
diff --git a/lexer.c b/lexer.c
index 373009394e811a47f0c31ccc944d92b8867c3ad9..634f90ca348da3584998bd94f3e83425820f61c9 100644 (file)
--- a/lexer.c
+++ b/lexer.c
@@ -225,6 +225,24 @@ static int lex_try_trigraph(lex_file *lex, int old)
     }
 }
 
+static int lex_try_digraph(lex_file *lex, int ch)
+{
+    int c2;
+    c2 = fgetc(lex->file);
+    if      (ch == '<' && c2 == ':')
+        return '[';
+    else if (ch == ':' && c2 == '>')
+        return ']';
+    else if (ch == '<' && c2 == '%')
+        return '{';
+    else if (ch == '%' && c2 == '>')
+        return '}';
+    else if (ch == '%' && c2 == ':')
+        return '#';
+    lex_ungetch(lex, c2);
+    return ch;
+}
+
 static int lex_getch(lex_file *lex)
 {
     int ch;
@@ -241,6 +259,8 @@ static int lex_getch(lex_file *lex)
         lex->line++;
     else if (ch == '?')
         return lex_try_trigraph(lex, ch);
+    else if (!lex->flags.nodigraphs && (ch == '<' || ch == ':' || ch == '%'))
+        return lex_try_digraph(lex, ch);
     return ch;
 }
 
@@ -978,6 +998,7 @@ int lex_do(lex_file *lex)
 
     if (ch == '"')
     {
+        lex->flags.nodigraphs = true;
         lex->tok.ttype = lex_finish_string(lex, '"');
         while (lex->tok.ttype == TOKEN_STRINGCONST)
         {
@@ -990,6 +1011,7 @@ int lex_do(lex_file *lex)
 
             lex->tok.ttype = lex_finish_string(lex, '"');
         }
+        lex->flags.nodigraphs = false;
         if (!lex_endtoken(lex))
             return (lex->tok.ttype = TOKEN_FATAL);
         return lex->tok.ttype;