Add strings option.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2821 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-08-08 22:40:17 +00:00
parent 62ee52a000
commit 96529dcd8d
2 changed files with 26 additions and 1 deletions

View File

@@ -91,12 +91,16 @@ arg_printusage (struct getargs *args,
len += 2 + strlen(args[i].long_name); len += 2 + strlen(args[i].long_name);
len += print_arg (1, &args[i]); len += print_arg (1, &args[i]);
putc (']', stderr); putc (']', stderr);
if(args[i].type == arg_strings)
fprintf (stderr, "...");
} }
if (args[i].short_name) { if (args[i].short_name) {
len += 2; len += 2;
fprintf (stderr, " [-%c", args[i].short_name); fprintf (stderr, " [-%c", args[i].short_name);
len += print_arg (0, &args[i]); len += print_arg (0, &args[i]);
putc (']', stderr); putc (']', stderr);
if(args[i].type == arg_strings)
fprintf (stderr, "...");
} }
if (args[i].long_name && args[i].short_name) if (args[i].long_name && args[i].short_name)
len += 4; len += 4;
@@ -136,6 +140,14 @@ arg_printusage (struct getargs *args,
} }
} }
static void
add_string(getarg_strings *s, char *value)
{
s->strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings));
s->strings[s->num_strings] = value;
s->num_strings++;
}
static int static int
arg_match_long(struct getargs *args, size_t num_args, arg_match_long(struct getargs *args, size_t num_args,
char *argv) char *argv)
@@ -206,6 +218,11 @@ arg_match_long(struct getargs *args, size_t num_args,
*(char**)current->value = optarg + 1; *(char**)current->value = optarg + 1;
return 0; return 0;
} }
case arg_strings:
{
add_string((getarg_strings*)current->value, optarg + 1);
return 0;
}
case arg_flag: case arg_flag:
{ {
int *flag = current->value; int *flag = current->value;
@@ -279,6 +296,9 @@ getarg(struct getargs *args, size_t num_args,
}else if(args[k].type == arg_string){ }else if(args[k].type == arg_string){
*(char**)args[k].value = optarg; *(char**)args[k].value = optarg;
goto out; goto out;
}else if(args[k].type == arg_strings){
add_string((getarg_strings*)args[k].value, optarg);
goto out;
} }
return ARG_ERR_BAD_ARG; return ARG_ERR_BAD_ARG;
} }

View File

@@ -46,7 +46,7 @@
struct getargs{ struct getargs{
const char *long_name; const char *long_name;
char short_name; char short_name;
enum { arg_integer, arg_string, arg_flag, arg_negative_flag } type; enum { arg_integer, arg_string, arg_flag, arg_negative_flag, arg_strings } type;
void *value; void *value;
const char *help; const char *help;
const char *arg_help; const char *arg_help;
@@ -58,6 +58,11 @@ enum {
ARG_ERR_NO_ARG ARG_ERR_NO_ARG
}; };
typedef struct getarg_strings {
int num_strings;
char **strings;
} getarg_strings;
int getarg(struct getargs *args, size_t num_args, int getarg(struct getargs *args, size_t num_args,
int argc, char **argv, int *optind); int argc, char **argv, int *optind);