From: Dale Weiler Date: Tue, 10 Apr 2012 08:29:06 +0000 (-0400) Subject: digraph and trigraph tests X-Git-Tag: 0.1-rc1~692 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d5dcb3aff72f4411c83ce97eb13006931fc186f6;p=xonotic%2Fgmqcc.git digraph and trigraph tests --- diff --git a/gmqcc.h b/gmqcc.h index 50fd856..8219d9d 100644 --- 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 7b55dff..ae73dc1 100644 --- 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 52413ca..29695c0 100644 --- 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 index 0000000..6467638 --- /dev/null +++ b/test/digraph.qc @@ -0,0 +1,5 @@ +<% + <% + <% %> + %> +%> diff --git a/test/trigraph.qc b/test/trigraph.qc new file mode 100644 index 0000000..770272c --- /dev/null +++ b/test/trigraph.qc @@ -0,0 +1,5 @@ +??< + ??< + ??< ??> + ??> +??>