fixed argument parsing
This commit is contained in:
parent
d37daec957
commit
b4ed7b4372
2 changed files with 11 additions and 7 deletions
11
args.h
11
args.h
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
extern char args_info[];
|
extern char args_info[];
|
||||||
extern char args_usage[];
|
extern char args_usage[];
|
||||||
extern char args_help_suffix[];
|
extern void args_print_help_suffix();
|
||||||
|
|
||||||
extern const int args_switch_count;
|
extern const int args_switch_count;
|
||||||
extern char* args_switches[];
|
extern char* args_switches[];
|
||||||
|
@ -87,7 +87,7 @@ static void args_print_switches()
|
||||||
args_switches[i + 1],
|
args_switches[i + 1],
|
||||||
args_switches[i + 2]);
|
args_switches[i + 2]);
|
||||||
}
|
}
|
||||||
printf(args_help_suffix);
|
args_print_help_suffix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void args_print_help()
|
void args_print_help()
|
||||||
|
@ -120,10 +120,9 @@ static int args_get_index(char* name)
|
||||||
continue; /* skip checking the description column */
|
continue; /* skip checking the description column */
|
||||||
if (args_is_blank(args_switches[i]))
|
if (args_is_blank(args_switches[i]))
|
||||||
continue;
|
continue;
|
||||||
if (!strcmp(args_switches[i], name)) {
|
if (!strcmp(args_switches[i], name))
|
||||||
return i / args_columns;
|
return i / args_columns;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +137,9 @@ static char* args__poll(char wants_switch)
|
||||||
arg = args_argv[args_current];
|
arg = args_argv[args_current];
|
||||||
if (!wants_switch) {
|
if (!wants_switch) {
|
||||||
args_current++;
|
args_current++;
|
||||||
return arg + pos * sizeof(char);
|
arg += pos * sizeof(char);
|
||||||
|
pos = 0;
|
||||||
|
return arg;
|
||||||
}
|
}
|
||||||
if (args_is_short(arg)) {
|
if (args_is_short(arg)) {
|
||||||
if (pos == 0)
|
if (pos == 0)
|
||||||
|
|
7
main.c
7
main.c
|
@ -37,8 +37,11 @@ static char reflect_output = 0;
|
||||||
|
|
||||||
char args_info[] = "crc32 - 32-bit cyclic redundancy check calculator\n";
|
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_usage[] = "Usage: %s [-i f] [-s n] [-p n] [-e] [-x] [-r] [-b]\n";
|
||||||
char args_help_suffix[] = "\n\
|
void args_print_help_suffix()
|
||||||
numbers (n) can be entered as hexadecimal or octal with prefixes\n";
|
{
|
||||||
|
puts("\n\
|
||||||
|
numbers (n) can be entered as hexadecimal or octal with prefixes");
|
||||||
|
}
|
||||||
|
|
||||||
const int args_switch_count = 9;
|
const int args_switch_count = 9;
|
||||||
char* args_switches[] = {
|
char* args_switches[] = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue