The C type part and the preprocessor part of a symbol are supposed
[smatch.git] / test-lexing.c
blobfe2abfb21c6399d0d62639228f3989413ca32828
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, all rights reserved.
6 */
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <unistd.h>
13 #include <fcntl.h>
15 #include "token.h"
16 #include "symbol.h"
18 int main(int argc, char **argv)
20 int fd = open(argv[1], O_RDONLY);
21 struct token *token;
23 if (fd < 0)
24 die("No such file: %s", argv[1]);
26 init_symbols();
27 token = tokenize(argv[1], fd, NULL);
28 close(fd);
29 token = preprocess(token);
31 while (!eof_token(token)) {
32 int prec = 1;
33 struct token *next = token->next;
34 char * separator = "";
35 if (next->pos.whitespace)
36 separator = " ";
37 if (next->pos.newline) {
38 separator = "\n\t\t\t\t\t";
39 prec = next->pos.pos;
40 if (prec > 4)
41 prec = 4;
43 printf("%s%.*s", show_token(token), prec, separator);
44 token = next;
46 putchar('\n');
47 show_identifier_stats();
48 return 0;