X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=judge%2Ftoken.c;h=85f5069420e96755f2f98e7299f3fa4469055f12;hb=14a86595bbff1ef0b0e504480fb36d097e5cf17c;hp=3c8ce38cd71c68e642ca9a767bd4eef9b6f20388;hpb=3a3647ada32a29ae781e8474387da14f7577abab;p=moe.git diff --git a/judge/token.c b/judge/token.c index 3c8ce38..85f5069 100644 --- a/judge/token.c +++ b/judge/token.c @@ -34,9 +34,9 @@ void tok_err(struct tokenizer *t, char *msg, ...) { va_list args; va_start(args, msg); - printf("%s:%d: ", t->stream->name, t->line); - vprintf(msg, args); - putchar('\n'); + fprintf(stderr, "Error at %s line %d:\n", t->stream->name, t->line); + vfprintf(stderr, msg, args); + fputc('\n', stderr); va_end(args); exit(1); } @@ -101,6 +101,8 @@ char *get_token(struct tokenizer *t) #define PARSE(f, ...) \ char *end; \ errno = 0; \ + if (!t->toksize) \ + return 0; \ *x = f(t->token, &end, ##__VA_ARGS__); \ return !(errno || (unsigned char *) end != t->token + t->toksize) @@ -161,3 +163,10 @@ GET(long, long int) GET(ulong, unsigned long int) GET(double, double) GET(long_double, long double) + +void get_nl(struct tokenizer *t) +{ + char *tok = get_token(t); + if (tok && *tok) + tok_err(t, "Expected end of line"); +}