Add current directory to search path.
[smatch.git] / test-lexing.c
blob3ad9aef6d746209227b75c7a6e1ca42643df7ae2
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.
7 * Licensed under the Open Software License version 1.1
8 */
9 #include <stdarg.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <unistd.h>
15 #include <fcntl.h>
17 #include "token.h"
18 #include "symbol.h"
20 int main(int argc, char **argv)
22 int fd = open(argv[1], O_RDONLY);
23 struct token *token;
25 if (fd < 0)
26 die("No such file: %s", argv[1]);
28 init_symbols();
29 token = tokenize(argv[1], fd, NULL);
30 close(fd);
31 token = preprocess(token);
33 while (!eof_token(token)) {
34 int prec = 1;
35 struct token *next = token->next;
36 char * separator = "";
37 if (next->pos.whitespace)
38 separator = " ";
39 if (next->pos.newline) {
40 separator = "\n\t\t\t\t\t";
41 prec = next->pos.pos;
42 if (prec > 4)
43 prec = 4;
45 printf("%s%.*s", show_token(token), prec, separator);
46 token = next;
48 putchar('\n');
49 show_identifier_stats();
50 return 0;