diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-09-21 15:11:37 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2005-09-21 15:11:37 +0000 |
commit | 153040933c1b97eda6707cd0316eed8fa73f1c16 (patch) | |
tree | 80c3c867a04bad4613d02261320e0f97fec79f37 /src/main.c | |
parent | bf88dc72ee5824bdbf80b40da2bb2ee77d5a5f4e (diff) | |
download | cflow-153040933c1b97eda6707cd0316eed8fa73f1c16.tar.gz cflow-153040933c1b97eda6707cd0316eed8fa73f1c16.tar.bz2 |
(excluded_symbols,included_symbols): Removed
(symbol_map): New variable, instead of the previous two. All
references updated.
(symbol_override): Minor fix.
(parse_opt): Allow to use +,- and ^ in any part of the argument
string.
(included_char): Removed
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 115 |
1 files changed, 64 insertions, 51 deletions
@@ -35,13 +35,13 @@ static struct argp_option options[] = { #define GROUP_ID 0 { NULL, 0, NULL, 0, N_("General options:"), GROUP_ID }, { "depth", 'd', N_("NUMBER"), 0, N_("Set the depth at which the flowgraph is cut off"), GROUP_ID+1 }, { "include", 'i', N_("SPEC"), 0, - N_("Control the number of included symbols. SPEC is a string consisting of characters, specifying what class of symbols to include in the output (see below). If SPEC starts with ^, its meaning is reversed."), GROUP_ID+1 }, + N_("Control the number of included symbols. SPEC is a string consisting of characters, specifying what class of symbols to include in the output (see below)."), GROUP_ID+1 }, { "format", 'f', N_("NAME"), 0, N_("Use given output format NAME. Valid names are gnu (default) and posix"), GROUP_ID+1 }, { "reverse", 'r', NULL, 0, @@ -54,12 +54,18 @@ static struct argp_option options[] = { { "output", 'o', N_("FILE"), 0, N_("Set output file name (default -, meaning stdout)"), GROUP_ID+1 }, { NULL, 0, NULL, 0, N_("Valid SPEC symbols for --include option:"), GROUP_ID+2 }, + {" +", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, + N_("Include symbols denoted by the following letters (default)"), + GROUP_ID+3 }, + {" - or ^", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, + N_("Exclude symbols denoted by the following letters (default)"), + GROUP_ID+3 }, {" x", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, N_("all data symbols, both external and static"), GROUP_ID+3 }, {" _", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, N_("symbols whose names begin with an underscore"), GROUP_ID+3 }, {" s", 0, NULL, OPTION_DOC|OPTION_NO_TRANS, N_("static symbols"), GROUP_ID+3 }, @@ -159,21 +165,26 @@ int strict_ansi; /* Assume sources to be written in ANSI C */ int print_line_numbers; /* Print line numbers */ int print_levels; /* Print level number near every branch */ int print_as_tree; /* Print as tree */ int brief_listing; /* Produce short listing */ int reverse_tree; /* Generate reverse tree */ int max_depth; /* The depth at which the flowgraph is cut off */ -char *included_symbols; /* A list of symbols included in the graph. - Consists of the following letters: - x Include (external and static) data symbols; - _ Include names that begin with an underscore; - s Include static functions; - t Include typedefs (for cross-references only); - */ -char *excluded_symbols; /* A list of symbols *not* included in the graph. - Overrides included_symbols */ + +#define SM_FUNCTIONS 0x0001 +#define SM_DATA 0x0002 +#define SM_STATIC 0x0004 +#define SM_UNDERSCORE 0x0008 +#define SM_TYPEDEF 0x0010 + +#define CHAR_TO_SM(c) ((c)=='x' ? SM_DATA : \ + (c)=='_' ? SM_UNDERSCORE : \ + (c)=='s' ? SM_STATIC : \ + (c)=='t' ? SM_TYPEDEF : 0) +#define SYMBOL_INCLUDE(c) (symbol_map |= CHAR_TO_SM(c)) +#define SYMBOL_EXCLUDE(c) (symbol_map &= ~CHAR_TO_SM(c)) +int symbol_map; /* A bitmap of symbols included in the graph. */ char *level_indent[] = { NULL, NULL }; char *level_end[] = { "", "" }; char *level_begin = ""; int preprocess_option = 0; /* Do they want to preprocess sources? */ @@ -222,15 +233,13 @@ symbol_override(const char *str) { int type; const char *ptr; char *name; Symbol *sp; - ptr = str; - while (*ptr && *ptr != ':') - ptr++; + ptr = strchr(str, ':'); if (*ptr == ':') { type = find_option_type(symbol_optype, ptr+1, 0); if (type == 0) { error(0, 0, _("unknown symbol type: %s"), ptr+1); return; } @@ -508,23 +517,34 @@ parse_opt (int key, char *arg, struct argp_state *state) output_init(); break; case OPT_LEVEL_INDENT: set_level_indent(arg); break; case 'i': - if (arg[0] == '^') { - excluded_symbols = xrealloc(excluded_symbols, - strlen(excluded_symbols) + - strlen(arg+1) + 1); - strcat(excluded_symbols, arg+1); - } else { - included_symbols = xrealloc(included_symbols, - strlen(included_symbols) + - strlen(arg) + 1); - strcat(included_symbols, arg); - } + num = 1; + for (; *arg; arg++) + switch (*arg) { + case '-': + case '^': + num = 0; + break; + case '+': + num = 1; + break; + case 'x': + case '_': + case 's': + case 't': + if (num) + SYMBOL_INCLUDE(*arg); + else + SYMBOL_EXCLUDE(*arg); + break; + default: + argp_error(state, _("Unknown symbol class: %c"), *arg); + } break; case 'l': print_levels = 1; break; case 'm': start_name = strdup(arg); @@ -581,48 +601,42 @@ static struct argp argp = { NULL, NULL, NULL }; int -included_char(int c) -{ - return strchr (included_symbols, c) - && !strchr (excluded_symbols, c); -} - -int globals_only() { - return !included_char('s'); + return !(symbol_map & SM_STATIC); } int include_symbol(Symbol *sym) { int type = 0; - - if (!sym || sym->type == SymToken) - return 0; - if (sym->name[0] == '_' && !included_char('_')) + if (!sym) return 0; - - if (sym->type == SymIdentifier) { - if (sym->arity == -1) - type = 'x'; - else if (sym->storage == StaticStorage) - type = 's'; - } else if (sym->type == SymToken - && sym->token_type == TYPE - && sym->source) - type = 't'; - if (type == 0) - return 1; - return included_char(type); + if (sym->type == SymIdentifier) { + if (sym->name[0] == '_' && !(symbol_map & SM_UNDERSCORE)) + return 0; + + if (sym->storage == StaticStorage) + type |= SM_STATIC; + if (sym->arity == -1 && sym->storage != AutoStorage) + type |= SM_DATA; + else if (sym->arity >= 0) + type |= SM_FUNCTIONS; + } else if (sym->type == SymToken) { + if (sym->token_type == TYPE && sym->source) + type |= SM_TYPEDEF; + else + return 0; + } + return (symbol_map & type) == type; } void xalloc_die(void) { error(1, ENOMEM, _("Exiting")); @@ -653,14 +667,13 @@ main(int argc, char **argv) bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); register_output("gnu", gnu_output_handler, NULL); register_output("posix", posix_output_handler, NULL); - included_symbols = xstrdup("s"); - excluded_symbols = xstrdup(""); + symbol_map = SM_FUNCTIONS|SM_STATIC; if (getenv ("POSIXLY_CORRECT")) { if (select_output_driver("posix")) error(0, _("%s: No such output driver"), "posix"); output_init(); } |