Fix pointer addition
[smatch.git] / test-lexing.c
blobb9af6df70576baf004bff5e2691e82a42a684ca7
1 /*
2 * Example test program that just uses the tokenization and
3 * preprocessing phases, and prints out the results.
5 * Copyright (C) 2003 Transmeta Corp.
6 * 2003 Linus Torvalds
8 * Licensed under the Open Software License version 1.1
9 */
10 #include <stdarg.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <ctype.h>
15 #include <unistd.h>
16 #include <fcntl.h>
18 #include "token.h"
19 #include "symbol.h"
21 int main(int argc, char **argv)
23 int fd = open(argv[1], O_RDONLY);
24 struct token *token;
26 if (fd < 0)
27 die("No such file: %s", argv[1]);
29 init_symbols();
30 token = tokenize(argv[1], fd, NULL);
31 close(fd);
32 token = preprocess(token);
34 while (!eof_token(token)) {
35 int prec = 1;
36 struct token *next = token->next;
37 char * separator = "";
38 if (next->pos.whitespace)
39 separator = " ";
40 if (next->pos.newline) {
41 separator = "\n\t\t\t\t\t";
42 prec = next->pos.pos;
43 if (prec > 4)
44 prec = 4;
46 printf("%s%.*s", show_token(token), prec, separator);
47 token = next;
49 putchar('\n');
50 show_identifier_stats();
51 return 0;