diff options
author | 2003-09-07 01:11:26 -0700 | |
---|---|---|
committer | 2005-04-07 21:01:03 -0700 | |
commit | 795df34616b799a0a651359c577fe6cd0973274d (patch) | |
tree | ec291d4a7441374f741a2ae96d3001e25034f281 /test-parsing.c | |
parent | [PATCH] Make sparse understand complex initializers inside expressions (diff) | |
download | sparse-795df34616b799a0a651359c577fe6cd0973274d.tar.gz sparse-795df34616b799a0a651359c577fe6cd0973274d.tar.bz2 sparse-795df34616b799a0a651359c577fe6cd0973274d.zip |
o move add_pre_buffer, handle_switch and friends to lib.c
This way we can reuse this thing on the utilities, this time check and
test-parsing are the ones using it.
Diffstat (limited to 'test-parsing.c')
-rw-r--r-- | test-parsing.c | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/test-parsing.c b/test-parsing.c index 7d5b5ec..1983d1a 100644 --- a/test-parsing.c +++ b/test-parsing.c @@ -22,52 +22,6 @@ #include "symbol.h" #include "expression.h" -static unsigned int pre_buffer_size = 0; -static unsigned char pre_buffer[8192]; - -static void add_pre_buffer(const char *fmt, ...) -{ - va_list args; - unsigned int size; - - va_start(args, fmt); - size = pre_buffer_size; - size += vsnprintf(pre_buffer + size, - sizeof(pre_buffer) - size, - fmt, args); - pre_buffer_size = size; - va_end(args); -} - -static void handle_switch(char *arg) -{ - 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; - } - } - add_pre_buffer("#define %s %s\n", name, value); - return; - } - - case 'I': - add_pre_buffer("#add_include \"%s/\"\n", arg+1); - return; - default: - fprintf(stderr, "unknown switch '%s'\n", arg); - } -} - static void clean_up_symbol(struct symbol *sym, void *_parent, int flags) { evaluate_symbol(sym); @@ -76,8 +30,8 @@ static void clean_up_symbol(struct symbol *sym, void *_parent, int flags) int main(int argc, char **argv) { - int i, fd; - char *filename = NULL; + int fd; + char *filename = NULL, **args;; struct token *token; // Initialize symbol stream first, so that we can add defines etc @@ -87,15 +41,17 @@ int main(int argc, char **argv) add_pre_buffer("#define __GNUC__ 2\n"); add_pre_buffer("#define __GNUC_MINOR__ 95\n"); - for (i = 1; i < argc; i++) { - char *arg = argv[i]; + args = argv; + for (;;) { + char *arg = *++args; + if (!arg) + break; if (arg[0] == '-') { - handle_switch(arg+1); + args = handle_switch(arg + 1, args); continue; } filename = arg; } - fd = open(filename, O_RDONLY); if (fd < 0) |