small refactor
This commit is contained in:
parent
3b30447bca
commit
cd8144aec7
1 changed files with 16 additions and 11 deletions
27
args.h
27
args.h
|
@ -97,6 +97,20 @@ void args_print_help()
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void args_check_bounds()
|
||||||
|
{
|
||||||
|
if (args_current >= args_argc) {
|
||||||
|
if (args_current - 1 == args_previous)
|
||||||
|
fprintf(stderr, "%s requires an argument.\n",
|
||||||
|
args_previous_name);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "%s requires another argument.\n",
|
||||||
|
args_previous_name);
|
||||||
|
args_print_usage();
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int args_get_index(char* name)
|
static int args_get_index(char* name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
@ -114,20 +128,11 @@ static int args_get_index(char* name)
|
||||||
|
|
||||||
static char* args__poll(char wants_switch)
|
static char* args__poll(char wants_switch)
|
||||||
{
|
{
|
||||||
static char short_[3] = "-\0";
|
static char short_[3] = "--";
|
||||||
static int pos = 0;
|
static int pos = 0;
|
||||||
char* arg = NULL;
|
char* arg = NULL;
|
||||||
|
|
||||||
if (args_current >= args_argc) {
|
args_check_bounds();
|
||||||
if (args_current - 1 == args_previous)
|
|
||||||
fprintf(stderr, "%s requires an argument.\n",
|
|
||||||
args_previous_name);
|
|
||||||
else
|
|
||||||
fprintf(stderr, "%s requires another argument.\n",
|
|
||||||
args_previous_name);
|
|
||||||
args_print_usage();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
arg = args_argv[args_current];
|
arg = args_argv[args_current];
|
||||||
if (!wants_switch) {
|
if (!wants_switch) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue