X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=lex.c;h=556f485536934d6a860ddc40197bb5aa6327cb0f;hp=669d13d7afd89201c20d7dd47ae6e666d6d6a5cd;hb=9493da4f8b373ba2266d411f6ec50f1920b9255c;hpb=32d7728b2f9be72cfa364bb84ec7c570975af7ac diff --git a/lex.c b/lex.c index 669d13d..556f485 100644 --- a/lex.c +++ b/lex.c @@ -48,7 +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 = 1; + lex->line = 0; memset(lex->peek, 0, sizeof(lex->peek)); return lex; @@ -139,15 +139,20 @@ static int lex_digraph(struct lex_file *file, int first) { static int lex_getch(struct lex_file *file) { int ch = lex_inget(file); - + + static int str = 0; switch (ch) { case '?' : return lex_trigraph(file); case '<' : case ':' : case '%' : - return lex_digraph (file, ch); - case '\n': file->line ++; + case '"' : str = !str; if (str) { file->line ++; } + return lex_digraph(file, ch); + + case '\n': + if (!str) + file->line++; } return ch; @@ -277,7 +282,14 @@ int lex_token(struct lex_file *file) { /* valid identifier */ if (ch > 0 && (ch == '_' || isalpha(ch))) { lex_clear(file); - while (ch > 0 && ch != ' ' && ch != '(' && ch != '\n' && 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); }