diff options
author | Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 2003-09-11 23:10:43 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-07 21:01:14 -0700 |
commit | 659513c0418d16cc9b5be9f5293b9a43f618c9ca (patch) | |
tree | 09fc71e8e0b2e29cb77cc5bc4ca38abb4e380798 /lib.c | |
parent | [be] properly emit "regular preops" (diff) | |
download | sparse-659513c0418d16cc9b5be9f5293b9a43f618c9ca.tar.gz sparse-659513c0418d16cc9b5be9f5293b9a43f618c9ca.tar.bz2 sparse-659513c0418d16cc9b5be9f5293b9a43f618c9ca.zip |
o split handle_switch, to make it more lib friendly
I.e. a more complex tool will need a different handle_switch,
so make the handling of each switch a function that can be
used by such specialized handle_switch while keeping handle_switch
for simpler tools.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 100 |
1 files changed, 61 insertions, 39 deletions
@@ -326,52 +326,74 @@ void add_pre_buffer(const char *fmt, ...) va_end(args); } -char **handle_switch(char *arg, char **next) +char **handle_switch_D(char *arg, char **next) { - switch (*arg) { - case 'D': { - const char *name = arg+1; - const char *value = ""; - for (;;) { - char c; - c = *++arg; - if (!c) - break; - if (isspace(c) || c == '=') { - *arg = '\0'; - value = arg+1; - break; - } + const char *name = arg + 1; + const char *value = ""; + for (;;) { + char c; + c = *++arg; + if (!c) + break; + if (isspace(c) || c == '=') { + *arg = '\0'; + value = arg + 1; + break; } - add_pre_buffer("#define %s %s\n", name, value); - return next; } + add_pre_buffer("#define %s %s\n", name, value); + return next; +} - case 'E': - preprocess_only = 1; - return next; - case 'v': - verbose = 1; - return next; - case 'I': - add_pre_buffer("#add_include \"%s/\"\n", arg+1); - return next; - case 'i': - if (*next && !strcmp(arg, "include")) { - char *name = *++next; - int fd = open(name, O_RDONLY); - include_fd = fd; - include = name; - if (fd < 0) - perror(name); - return next; - } - /* Fallthrough */ +char **handle_switch_E(char *arg, char **next) +{ + preprocess_only = 1; + return next; +} + +char **handle_switch_v(char *arg, char **next) +{ + verbose = 1; + return next; +} +char **handle_switch_I(char *arg, char **next) +{ + add_pre_buffer("#add_include \"%s/\"\n", arg + 1); + return next; +} + +char **handle_switch_i(char *arg, char **next) +{ + if (*next && !strcmp(arg, "include")) { + char *name = *++next; + int fd = open(name, O_RDONLY); + + include_fd = fd; + include = name; + if (fd < 0) + perror(name); + } + return next; +} + +char **handle_switch(char *arg, char **next) +{ + char **rc = next; + + switch (*arg) { + case 'D': rc = handle_switch_D(arg, next); break; + case 'E': rc = handle_switch_E(arg, next); break; + case 'v': rc = handle_switch_v(arg, next); break; + case 'I': rc = handle_switch_I(arg, next); break; + case 'i': rc = handle_switch_i(arg, next); break; default: - /* Ignore unknown command line options - they're probably gcc switches */ + /* + * Ignore unknown command line options: + * they're probably gcc switches + */ break; } - return next; + return rc; } void create_builtin_stream(void) |