version 1.4, 2004/06/08 16:49:00 |
version 1.5, 2005/10/16 18:56:35 |
|
|
|
|
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
#include <config.h> |
#include <config.h> |
RCSID("$KTH: getarg.c,v 1.46 2002/08/20 16:23:07 joda Exp $"); |
RCSID("$KTH: getarg.c,v 1.48 2005/04/12 11:28:43 lha Exp $"); |
#endif |
#endif |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <err.h> |
#include <errno.h> |
#include "getarg.h" |
#include "getarg.h" |
|
|
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag) |
#define ISFLAG(X) ((X).type == arg_flag || (X).type == arg_negative_flag) |
|
|
return col; |
return col; |
} |
} |
|
|
void |
void ROKEN_LIB_FUNCTION |
arg_printusage (struct getargs *args, |
arg_printusage (struct getargs *args, |
size_t num_args, |
size_t num_args, |
const char *progname, |
const char *progname, |
|
|
} |
} |
} |
} |
|
|
static void |
static int |
add_string(getarg_strings *s, char *value) |
add_string(getarg_strings *s, char *value) |
{ |
{ |
if ((s->strings = realloc(s->strings, (s->num_strings + 1) * |
char **strings; |
sizeof(*s->strings))) == NULL) |
|
err(1, "realloc"); |
strings = realloc(s->strings, (s->num_strings + 1) * sizeof(*s->strings)); |
|
if (strings == NULL) { |
|
free(s->strings); |
|
s->strings = NULL; |
|
s->num_strings = 0; |
|
return ENOMEM; |
|
} |
|
s->strings = strings; |
s->strings[s->num_strings] = value; |
s->strings[s->num_strings] = value; |
s->num_strings++; |
s->num_strings++; |
|
return 0; |
} |
} |
|
|
static int |
static int |
|
|
} |
} |
case arg_strings: |
case arg_strings: |
{ |
{ |
add_string((getarg_strings*)current->value, goptarg + 1); |
return add_string((getarg_strings*)current->value, goptarg + 1); |
return 0; |
|
} |
} |
case arg_flag: |
case arg_flag: |
case arg_negative_flag: |
case arg_negative_flag: |
|
|
*(char**)args[k].value = goptarg; |
*(char**)args[k].value = goptarg; |
return 0; |
return 0; |
} else if(args[k].type == arg_strings) { |
} else if(args[k].type == arg_strings) { |
add_string((getarg_strings*)args[k].value, goptarg); |
return add_string((getarg_strings*)args[k].value, goptarg); |
return 0; |
|
} else if(args[k].type == arg_double) { |
} else if(args[k].type == arg_double) { |
double tmp; |
double tmp; |
if(sscanf(goptarg, "%lf", &tmp) != 1) |
if(sscanf(goptarg, "%lf", &tmp) != 1) |
|
|
return 0; |
return 0; |
} |
} |
|
|
int |
int ROKEN_LIB_FUNCTION |
getarg(struct getargs *args, size_t num_args, |
getarg(struct getargs *args, size_t num_args, |
int argc, char **argv, int *goptind) |
int argc, char **argv, int *goptind) |
{ |
{ |
|
|
return ret; |
return ret; |
} |
} |
|
|
void |
void ROKEN_LIB_FUNCTION |
free_getarg_strings (getarg_strings *s) |
free_getarg_strings (getarg_strings *s) |
{ |
{ |
free (s->strings); |
free (s->strings); |