]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
digraph and trigraph tests
authorDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 08:29:06 +0000 (04:29 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 10 Apr 2012 08:29:06 +0000 (04:29 -0400)
gmqcc.h
lex.c
main.c
test/digraph.qc [new file with mode: 0644]
test/trigraph.qc [new file with mode: 0644]

diff --git a/gmqcc.h b/gmqcc.h
index 50fd8568e9e3f19fe356138151bdcc534d4d7150..8219d9d1054046c007381b5dbc8ce5694229f077 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -137,7 +137,6 @@ struct lex_file {
        int   current;
        int   length;
        int   size;
-       long  line;         /* Line the lexer is on                     */
        char  lastok[8192]; /* No token shall ever be bigger than this! */
 };
 
diff --git a/lex.c b/lex.c
index 7b55dff5033269203a3893804f7a61c89e64b468..ae73dc1f97ac26b527b8de9bed40455f7a5620f3 100644 (file)
--- a/lex.c
+++ b/lex.c
@@ -39,16 +39,17 @@ static const char *const lex_keywords[] = {
 
 struct lex_file *lex_open(FILE *fp) {
        struct lex_file *lex = mem_a(sizeof(struct lex_file));
-       if (lex) {
-               lex->file = fp;
-               fseek(lex->file, 0, SEEK_END);
-               lex->length = ftell(lex->file);
-               lex->size   = lex->length; /* copy, this is never changed */
-               fseek(lex->file, 0, SEEK_SET);
-               lex->last = 0;
+       if (!lex || !fp)
+               return NULL;
                
-               memset(lex->peek, 0, sizeof(lex->peek));
-       }
+       lex->file = fp;
+       fseek(lex->file, 0, SEEK_END);
+       lex->length = ftell(lex->file);
+       lex->size   = lex->length; /* copy, this is never changed */
+       fseek(lex->file, 0, SEEK_SET);
+       lex->last = 0;
+       
+       memset(lex->peek, 0, sizeof(lex->peek));
        return lex;
 }
 
@@ -236,7 +237,7 @@ static int lex_skipcmt(struct lex_file *file) {
                lex_addch(ch, file);
                while ((ch = lex_getch(file)) != '*') {
                        if (ch == EOF)
-                               return error(ERROR_LEX, "malformatted comment at line %d", file->line);
+                               return error(ERROR_LEX, "malformatted comment at line", "");
                        else
                                lex_addch(ch, file);
                }
diff --git a/main.c b/main.c
index 52413ca084608d2b64a7eb1bb4f8d6f7b047c579..29695c01c64ce75dc5d70c87e3317f260eac2397 100644 (file)
--- a/main.c
+++ b/main.c
@@ -65,6 +65,10 @@ int main(int argc, char **argv) {
                return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
        } else {
                struct lex_file *lex = lex_open(fp);
+               if (!lex) {
+                       fclose(fp);
+                       return 0;
+               }
                parse_tree(lex); /* generate parse tree */
                lex_close (lex); /* cleanup  lexer      */
        }
diff --git a/test/digraph.qc b/test/digraph.qc
new file mode 100644 (file)
index 0000000..6467638
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+       <%
+               <% %>
+       %>
+%>
diff --git a/test/trigraph.qc b/test/trigraph.qc
new file mode 100644 (file)
index 0000000..770272c
--- /dev/null
@@ -0,0 +1,5 @@
+??<
+       ??<
+               ??< ??>
+       ??>
+??>