remove unused merge_pools() function.
[smatch.git] / smatch.c
blobb4e69a940e1e5b1d7e17cc45153e1fb48821dd47
1 /*
2 * sparse/smatch.c
4 * Copyright (C) 2006 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <libgen.h>
13 #include "smatch.h"
15 char *data_dir;
16 int option_no_data = 0;
18 typedef void (*reg_func) (int id);
19 void register_smatch_extra(int id);
20 void register_smatch_ignore(int id);
21 void register_implications(int id);
22 void register_function_hooks(int id);
23 void check_debug(int id);
24 void check_null_deref(int id);
25 void check_overflow(int id);
26 void check_locking(int id);
27 void check_memory(int id);
28 void check_frees_argument(int id);
29 void check_puts_argument(int id);
30 void check_leaks(int id);
31 void check_type(int id);
32 void check_allocation_funcs(int id);
33 void check_err_ptr(int id);
34 void check_err_ptr_deref(int id);
35 /* <- your test goes here */
36 /* void register_template(int id); */
38 static const reg_func reg_funcs[] = {
39 &register_smatch_extra, /* smatch_extra always has to be first */
40 &register_smatch_ignore,
41 &check_debug,
42 &check_null_deref,
43 &check_overflow,
44 &check_locking,
45 &check_memory,
46 // &check_type,
47 // &check_allocation_funcs,
48 // &check_leaks,
49 // &check_frees_argument,
50 // &check_puts_argument,
51 // &check_err_ptr,
52 &check_err_ptr_deref,
54 /* <- your test goes here */
55 /* &register_template, */
57 &register_implications, /* implications always has to be last */
58 NULL
61 static void help(void)
63 printf("Usage: smatch [smatch arguments][sparse arguments] file.c\n");
64 printf("--debug: print lots of debug output.\n");
65 printf("--debug-implied: print debug output about implications.\n");
66 printf("--oom <num>: number of mB memory to use before giving up.\n");
67 printf("--no-implied: ignore implications.\n");
68 printf("--assume-loops: assume loops always go through at least once.\n");
69 printf("--known-conditions: don't branch for known conditions.\n");
70 printf("--no-data: do not use the /smatch_data/ directory.\n");
71 printf("--help: print this helpfull message.\n");
72 exit(1);
75 void parse_args(int *argcp, char ***argvp)
77 while(*argcp >= 2) {
78 if (!strcmp((*argvp)[1], "--debug")) {
79 debug_states = 1;
80 (*argvp)[1] = (*argvp)[0];
81 } else if (!strcmp((*argvp)[1], "--debug-implied")) {
82 debug_implied_states = 1;
83 (*argvp)[1] = (*argvp)[0];
84 } else if (!strcmp((*argvp)[1], "--oom")) {
85 option_oom_kb = atoi((*argvp)[2]) * 1000;
86 (*argvp)[2] = (*argvp)[0];
87 (*argcp)--;
88 (*argvp)++;
89 } else if (!strcmp((*argvp)[1], "--no-implied")) {
90 option_no_implied = 1;
91 (*argvp)[1] = (*argvp)[0];
92 } else if (!strcmp((*argvp)[1], "--assume-loops")) {
93 option_assume_loops = 1;
94 (*argvp)[1] = (*argvp)[0];
95 } else if (!strcmp((*argvp)[1], "--known-conditions")) {
96 option_known_conditions = 1;
97 (*argvp)[1] = (*argvp)[0];
98 } else if (!strcmp((*argvp)[1], "--no-data")) {
99 option_no_data = 1;
100 (*argvp)[1] = (*argvp)[0];
101 } else if (!strcmp((*argvp)[1], "--help")) {
102 help();
103 } else {
104 break;
106 (*argcp)--;
107 (*argvp)++;
111 static char *get_data_dir(char *arg0)
113 char *bin_dir;
114 char buf[256];
115 char *dir;
117 if (option_no_data) {
118 return NULL;
120 bin_dir = dirname(alloc_string(arg0));
121 strncpy(buf, bin_dir, 254);
122 buf[255] = '\0';
123 strncat(buf, "/smatch_data/", 254 - strlen(buf));
124 dir = alloc_string(buf);
125 if (!access(dir, R_OK))
126 return dir;
127 printf("Warning: %s is not accessible.\n", dir);
128 printf("Use --no-data to suppress this message.\n");
129 return NULL;
132 int main(int argc, char **argv)
134 int i;
135 reg_func func;
137 parse_args(&argc, &argv);
139 data_dir = get_data_dir(argv[0]);
141 /* The script IDs start at 1.
142 0 is used for internal stuff. */
143 create_function_hash();
144 for(i = 0; (func = reg_funcs[i]); i++){
145 func(i + 1);
147 register_function_hooks(-1);
149 smatch(argc, argv);
150 free_string(data_dir);
151 return 0;