Remove global argument/arglist pointers, and pass them properly as
[smatch.git] / test-parsing.c
blobd4fc7a4ab75b6ebfcad96af8769243b18f33fb9b
1 /*
2 * Example trivial client program that uses the sparse library
3 * to tokenize, pre-process and parse a C file, and prints out
4 * the results.
6 * Copyright (C) 2003 Linus Torvalds, all rights reserved.
7 */
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <ctype.h>
13 #include <unistd.h>
14 #include <fcntl.h>
16 #include "lib.h"
17 #include "token.h"
18 #include "parse.h"
19 #include "symbol.h"
21 char *includepath[] = {
22 "/usr/lib/gcc-lib/i386-redhat-linux/3.2.1/include/",
23 #if 1
24 "/home/torvalds/v2.5/linux/include/",
25 #else
26 "/usr/include/",
27 "/usr/local/include/",
28 #endif
29 "",
30 NULL
33 static void handle_switch(char *arg)
37 int main(int argc, char **argv)
39 int i, fd;
40 char *filename = NULL;
41 struct token *token;
42 struct symbol_list *list = NULL;
44 // Initialize symbol stream first, so that we can add defines etc
45 init_symbols();
47 for (i = 1; i < argc; i++) {
48 char *arg = argv[i];
49 if (arg[0] == '-') {
50 handle_switch(arg+1);
51 continue;
53 filename = arg;
57 fd = open(filename, O_RDONLY);
58 if (fd < 0)
59 die("No such file: %s", argv[1]);
61 // Tokenize the input stream
62 token = tokenize(filename, fd, NULL);
63 close(fd);
65 // Pre-process the stream
66 token = preprocess(token);
68 // Parse the resulting C code
69 translation_unit(token, &list);
71 // Show the end result.
72 show_symbol_list(list, "\n\n");
73 printf("\n\n");
75 // And show the allocation statistics
76 show_ident_alloc();
77 show_token_alloc();
78 show_symbol_alloc();
79 show_expression_alloc();
80 show_statement_alloc();
81 show_string_alloc();
82 show_bytes_alloc();
83 return 0;