2 * A judge comparing two sequences of tokens
4 * (c) 2007 Martin Krulis <bobrik@matfyz.cz>
5 * (c) 2007 Martin Mares <mj@ucw.cz>
15 static int ignore_nl, ignore_trailing_nl;
17 static int trailing_nl(struct tokenizer *t)
19 // Ignore empty lines at the end of file
20 if (t->token[0] || !ignore_trailing_nl)
22 t->flags &= ~TF_REPORT_LINES;
26 static void usage(void)
28 fprintf(stderr, "Usage: judge-tok [<options>] <file1> <file2>\n\
31 -n\t\tIgnore newlines\n\
32 -t\t\tIgnore newlines at the end of file\n\
37 int main(int argc, char **argv)
39 struct tokenizer t1, t2;
42 while ((opt = getopt(argc, argv, "nt")) >= 0)
54 if (optind + 2 != argc)
57 tok_init(&t1, sopen_read(argv[optind]));
58 tok_init(&t2, sopen_read(argv[optind+1]));
60 t1.flags = t2.flags = TF_REPORT_LINES;
64 char *a = get_token(&t1), *b = get_token(&t2);
67 if (b && !trailing_nl(&t2))
68 tok_err(&t1, "Ends too early");
73 if (a && !trailing_nl(&t1))
74 tok_err(&t2, "Garbage at the end");
77 else if (strcmp(a, b))
78 tok_err(&t1, "Found <%s>, expected <%s>", a, b);