[PATCH] Update get_number_value()
[smatch.git] / test-lexing.c
blob0e971e67f67ae3835065be26e1f54e1f42d0293b
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();
31 // Initialize type system
32 init_ctype();
34 token = tokenize(argv[1], fd, NULL);
35 close(fd);
36 token = preprocess(token);
38 while (!eof_token(token)) {
39 int prec = 1;
40 struct token *next = token->next;
41 char * separator = "";
42 if (next->pos.whitespace)
43 separator = " ";
44 if (next->pos.newline) {
45 separator = "\n\t\t\t\t\t";
46 prec = next->pos.pos;
47 if (prec > 4)
48 prec = 4;
50 printf("%s%.*s", show_token(token), prec, separator);
51 token = next;
53 putchar('\n');
54 show_identifier_stats();
55 return 0;