From b4ed7b437220d265ce32e79a6c012987d67c876d Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Sat, 21 Apr 2012 10:08:48 -0700 Subject: [PATCH] fixed argument parsing --- args.h | 11 ++++++----- main.c | 7 +++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/args.h b/args.h index e7dcaab..62c5d90 100644 --- a/args.h +++ b/args.h @@ -26,7 +26,7 @@ extern char args_info[]; extern char args_usage[]; -extern char args_help_suffix[]; +extern void args_print_help_suffix(); extern const int args_switch_count; extern char* args_switches[]; @@ -87,7 +87,7 @@ static void args_print_switches() args_switches[i + 1], args_switches[i + 2]); } - printf(args_help_suffix); + args_print_help_suffix(); } void args_print_help() @@ -120,9 +120,8 @@ static int args_get_index(char* name) continue; /* skip checking the description column */ if (args_is_blank(args_switches[i])) continue; - if (!strcmp(args_switches[i], name)) { + if (!strcmp(args_switches[i], name)) return i / args_columns; - } } return -1; } @@ -138,7 +137,9 @@ static char* args__poll(char wants_switch) arg = args_argv[args_current]; if (!wants_switch) { args_current++; - return arg + pos * sizeof(char); + arg += pos * sizeof(char); + pos = 0; + return arg; } if (args_is_short(arg)) { if (pos == 0) diff --git a/main.c b/main.c index 4179c00..ae51a54 100644 --- a/main.c +++ b/main.c @@ -37,8 +37,11 @@ static char reflect_output = 0; char args_info[] = "crc32 - 32-bit cyclic redundancy check calculator\n"; char args_usage[] = "Usage: %s [-i f] [-s n] [-p n] [-e] [-x] [-r] [-b]\n"; -char args_help_suffix[] = "\n\ -numbers (n) can be entered as hexadecimal or octal with prefixes\n"; +void args_print_help_suffix() +{ + puts("\n\ +numbers (n) can be entered as hexadecimal or octal with prefixes"); +} const int args_switch_count = 9; char* args_switches[] = {