aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-03-20 22:17:45 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-03-20 22:17:45 +0000
commit7447e206a366114a3b3cf96e692d0712fbe2f5bc (patch)
treeb101824209bfe964f10e0686891c4cc8ce6e982f /src/main.c
parent175b09fd5daffdca63dd9f07009dc5c689b6d1b7 (diff)
downloadcflow-7447e206a366114a3b3cf96e692d0712fbe2f5bc.tar.gz
cflow-7447e206a366114a3b3cf96e692d0712fbe2f5bc.tar.bz2
Reordered functions
(find_option_type): Take third argument. (symbol_override,number,parse_level_string) (set_level_indent): Operate on read-only strings (options): New option --number (-n)
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c509
1 files changed, 265 insertions, 244 deletions
diff --git a/src/main.c b/src/main.c
index d312718..08ab6cc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,12 +20,6 @@
20#include <stdarg.h> 20#include <stdarg.h>
21#include <parser.h> 21#include <parser.h>
22 22
23void symbol_override();
24void init();
25void set_print_option(char*);
26static void set_level_indent(char*);
27static void parse_level_string(char*, char**);
28
29const char *argp_program_version = "cflow (" PACKAGE_NAME ") " VERSION; 23const char *argp_program_version = "cflow (" PACKAGE_NAME ") " VERSION;
30const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">"; 24const char *argp_program_bug_address = "<" PACKAGE_BUGREPORT ">";
31static char doc[] = ""; 25static char doc[] = "";
@@ -61,15 +55,17 @@ static struct argp_option options[] = {
61 "record defines (not implemented yet)", 11 }, 55 "record defines (not implemented yet)", 11 },
62 { "ansi", 'a', NULL, 0, 56 { "ansi", 'a', NULL, 0,
63 "Assume input to be written in ANSI C", 11 }, 57 "Assume input to be written in ANSI C", 11 },
64 { "pushdown", 'p', "VALUE", 0, 58 { "pushdown", 'p', "NUMBER", 0,
65 "set initial token stack size to VALUE", 11 }, 59 "set initial token stack size to NUMBER", 11 },
66 { "symbol", 's', "SYM:TYPE", 0, 60 { "symbol", 's', "SYM:TYPE", 0,
67 "make cflow believe the symbol SYM is of type TYPE. Valid types are: keyword (or kw), modifier, identifier, type, wrapper. Any unambiguous abbreviation of the above is also accepted", 11 }, 61 "make cflow believe the symbol SYM is of type TYPE. Valid types are: keyword (or kw), modifier, identifier, type, wrapper. Any unambiguous abbreviation of the above is also accepted", 11 },
68 { "main", 'm', "NAME", 0, 62 { "main", 'm', "NAME", 0,
69 "Assume main function to be called NAME", 11 }, 63 "Assume main function to be called NAME", 11 },
70 64
71 { NULL, 0, NULL, 0, 65 { NULL, 0, NULL, 0,
72 "Output control:", 20}, 66 "Output control:", 20 },
67 { "number", 'n', "BOOL", OPTION_ARG_OPTIONAL,
68 "Print line numbers", 21 },
73 { "print-level", 'l', NULL, 0, 69 { "print-level", 'l', NULL, 0,
74 "Print nesting level along with the call tree", 21 }, 70 "Print nesting level along with the call tree", 21 },
75 { "level-indent", OPT_LEVEL_INDENT, "STRING", 0, 71 { "level-indent", OPT_LEVEL_INDENT, "STRING", 0,
@@ -112,26 +108,6 @@ struct option_type {
112 int type; /* data associated with the arg */ 108 int type; /* data associated with the arg */
113}; 109};
114 110
115static int find_option_type(struct option_type *, char *);
116
117/* Args for --print option */
118struct option_type print_optype[] = {
119 { "xref", 1, PRINT_XREF },
120 { "cross-ref", 1, PRINT_XREF },
121 { "tree", 1, PRINT_TREE },
122 { 0 },
123};
124/* Args for --symbol option */
125struct option_type symbol_optype[] = {
126 { "keyword", 2, WORD },
127 { "kw", 2, WORD },
128 { "modifier", 1, MODIFIER },
129 { "identifier", 1, IDENTIFIER },
130 { "type", 1, TYPE },
131 { "wrapper", 1, PARM_WRAPPER },
132 { 0 },
133};
134
135int debug; /* debug level */ 111int debug; /* debug level */
136char *outname = "-"; /* default output file name */ 112char *outname = "-"; /* default output file name */
137int print_option = 0; /* what to print. */ 113int print_option = 0; /* what to print. */
@@ -143,6 +119,7 @@ int ignore_indentation; /* Don't rely on indentation,
143 */ 119 */
144int record_defines; /* Record macro definitions */ 120int record_defines; /* Record macro definitions */
145int strict_ansi; /* Assume sources to be written in ANSI C */ 121int strict_ansi; /* Assume sources to be written in ANSI C */
122int print_line_numbers; /* Print line numbers */
146int print_levels; /* Print level number near every branch */ 123int print_levels; /* Print level number near every branch */
147int print_as_tree; /* Print as tree */ 124int print_as_tree; /* Print as tree */
148int brief_listing; /* Produce short listing */ 125int brief_listing; /* Produce short listing */
@@ -164,207 +141,62 @@ char *level_begin = "";
164 141
165char *start_name = "main"; /* Name of start symbol */ 142char *start_name = "main"; /* Name of start symbol */
166 143
167static error_t 144#define boolean_value(arg) ((arg) ? ((arg)[0] == 'y' || (arg)[0] == 'Y') : 1)
168parse_opt (int key, char *arg, struct argp_state *state)
169{
170 int num;
171
172 switch (key) {
173 case 'a':
174 strict_ansi = 1;
175 break;
176 case OPT_DEBUG:
177 debug = arg ? atoi(arg) : 1;
178 break;
179 case 'L':
180 printf("License for %s:\n\n", argp_program_version);
181 printf("%s", cflow_license_text);
182 exit(0);
183 case 'P':
184 set_print_option(arg);
185 break;
186 case 'S':
187 ignore_indentation = 1;
188 break;
189 case 'T':
190 print_as_tree = 1;
191 level_indent[0] = " "; /* two spaces */
192 level_indent[1] = "| ";
193 level_end[0] = "+-";
194 level_end[1] = "\\-";
195 break;
196 case 'b':
197 brief_listing = arg ? (arg[0] == 'y' || arg[0] == 'Y') : 1;
198 break;
199 case 'd':
200 max_depth = atoi(arg);
201 if (max_depth < 0)
202 max_depth = 0;
203 break;
204 case OPT_DEFINES:
205 record_defines = 1;
206 break;
207 case 'f':
208 if (select_output_driver(arg))
209 argp_error(state, "%s: No such output driver", optarg);
210 else if (strcmp(arg, "posix") == 0)
211 brief_listing = 1;
212 break;
213 case OPT_LEVEL_INDENT:
214 set_level_indent(arg);
215 break;
216 case 'i':
217 if (arg[0] == '^') {
218 excluded_symbols = xrealloc(excluded_symbols,
219 strlen(excluded_symbols) +
220 strlen(arg+1) + 1);
221 strcat(excluded_symbols, arg+1);
222 } else {
223 included_symbols = xrealloc(included_symbols,
224 strlen(included_symbols) +
225 strlen(arg) + 1);
226 strcat(included_symbols, arg);
227 }
228 break;
229 case 'l':
230 print_levels = 1;
231 break;
232 case 'm':
233 start_name = strdup(arg);
234 break;
235 case 'o':
236 outname = strdup(arg);
237 break;
238 case 'p':
239 num = atoi(arg);
240 if (num > 0)
241 token_stack_length = num;
242 break;
243 case 'r':
244 reverse_tree = 1;
245 break;
246 case 's':
247 symbol_override(arg);
248 break;
249 case 'v':
250 verbose = 1;
251 break;
252 case 'x':
253 print_option = PRINT_XREF;
254 break;
255 default:
256 return ARGP_ERR_UNKNOWN;
257 }
258 return 0;
259}
260
261static struct argp argp = {
262 options,
263 parse_opt,
264 "[FILE]...",
265 doc,
266 NULL,
267 NULL,
268 NULL
269};
270
271int
272included_char(int c)
273{
274 return strchr (included_symbols, c)
275 && !strchr (excluded_symbols, c);
276}
277
278int
279globals_only()
280{
281 return !included_char('s');
282}
283
284int
285include_symbol(Symbol *sym)
286{
287 int type = 0;
288
289 if (sym->name[0] == '_' && !included_char('_'))
290 return 0;
291
292 if (sym->type == SymIdentifier) {
293 if (sym->arity == -1)
294 type = 'x';
295 else if (sym->storage == StaticStorage)
296 type = 's';
297 } else if (sym->type == SymToken
298 && sym->token_type == TYPE
299 && sym->source)
300 type = 't';
301
302 if (type == 0)
303 return 1;
304 return included_char(type);
305}
306
307void
308xalloc_die(void)
309{
310 error(1, ENOMEM, "");
311}
312
313void
314init()
315{
316 if (level_indent[0] == NULL) {
317 level_indent[0] = level_indent[1] = " "; /* 4 spaces */
318 level_end[0] = level_end[1] = "";
319 }