From 60e847c330420ac5029ac5ed6580776c26a52282 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Sat, 6 Dec 2008 20:30:01 +0100 Subject: More improvements to eurephia_getopt(...) Sending the argument incrementer as reference instead of as value. This way eurephia_getopt(...) can directly increase the incrementer on arguments with extra options. --- eurephiadm/argparser.c | 9 +++++---- eurephiadm/argparser.h | 2 +- eurephiadm/commands/edit_config.c | 2 +- eurephiadm/commands/users.c | 8 ++++---- eurephiadm/eurephiadm.c | 4 +--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/eurephiadm/argparser.c b/eurephiadm/argparser.c index bc635e8..cbfdc67 100644 --- a/eurephiadm/argparser.c +++ b/eurephiadm/argparser.c @@ -27,9 +27,9 @@ char *optargs[MAX_ARGUMENTS]; -int _eurephia_getopt(const char *module, int curarg, int argc, char **argv, e_options *argopts) { +int _eurephia_getopt(const char *module, int *curarg, int argc, char **argv, e_options *argopts) { int i = 0; - char *arg = argv[curarg]; + char *arg = argv[*curarg]; if( arg == NULL ) { return -1; @@ -39,10 +39,11 @@ int _eurephia_getopt(const char *module, int curarg, int argc, char **argv, e_op if( (strcmp(argopts[i].longarg, arg) == 0) || (strcmp(argopts[i].shortarg, arg) == 0) ) { - if( (argopts[i].param > 0) && (argc > curarg+argopts[i].param) ) { + if( (argopts[i].param > 0) && (argc > (*curarg)+argopts[i].param) ) { int j = 0; for( j = 0; j < argopts[i].param; j++ ) { - optargs[j] = argv[curarg+j+1]; + optargs[j] = argv[(*curarg)+j+1]; + (*curarg)++; } } else if( (argopts[i].param > 0) ) { fprintf(stderr, "%s: ERROR :: Missing argument(s) to '%s'\n", module, arg); diff --git a/eurephiadm/argparser.h b/eurephiadm/argparser.h index 842e14a..2b6b26d 100644 --- a/eurephiadm/argparser.h +++ b/eurephiadm/argparser.h @@ -37,7 +37,7 @@ typedef struct { extern char *optargs[MAX_ARGUMENTS]; -int _eurephia_getopt(const char *module, int curarg, int argc, char **argv, e_options *argopts); +int _eurephia_getopt(const char *module, int *curarg, int argc, char **argv, e_options *argopts); #define eurephia_getopt(ca, ac, av, opts) _eurephia_getopt(MODULE, ca, ac, av, opts) size_t eurephia_arraycp(int stidx, int inargc, char **inargv, char **outargv, size_t outsize); diff --git a/eurephiadm/commands/edit_config.c b/eurephiadm/commands/edit_config.c index 0bf7d4d..eae957b 100644 --- a/eurephiadm/commands/edit_config.c +++ b/eurephiadm/commands/edit_config.c @@ -73,7 +73,7 @@ int cmd_EditConfig(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, if( *argv[i] != '-' ) { break; } - switch( eurephia_getopt(i, argc, argv, editargs) ) { + switch( eurephia_getopt(&i, argc, argv, editargs) ) { case 's': fprintf(stderr, "Setting config parameter '%s' to '%s'\n", optargs[0], optargs[1]); rc = eDBadminConfigSet(ctx, optargs[0], optargs[1]); diff --git a/eurephiadm/commands/users.c b/eurephiadm/commands/users.c index 1b25458..4c1a449 100644 --- a/eurephiadm/commands/users.c +++ b/eurephiadm/commands/users.c @@ -96,7 +96,8 @@ int help_Users2(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, in {NULL, NULL, 0} }; - display_users_help(eurephia_getopt(1, argc, argv, helpargs)); + int i = 1; + display_users_help(eurephia_getopt(&i, argc, argv, helpargs)); return 0; } @@ -118,10 +119,9 @@ int list_users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int assert((ctx != NULL) && (ctx->dbc != NULL) && (ctx->dbc->config != NULL)); for( i = 1; i < argc; i++ ) { - switch( eurephia_getopt(i, argc, argv, listargs) ) { + switch( eurephia_getopt(&i, argc, argv, listargs) ) { case 'S': sortkeys = optargs[0]; - i++; break; default: @@ -182,7 +182,7 @@ int cmd_Users(eurephiaCTX *ctx, eurephiaSESSION *sess, eurephiaVALUES *cfg, int assert((ctx != NULL) && (ctx->dbc != NULL) && (ctx->dbc->config != NULL)); mode_fnc = NULL; for( i = 1; i < argc; i++ ) { - switch( eurephia_getopt(i, argc, argv, modeargs) ) { + switch( eurephia_getopt(&i, argc, argv, modeargs) ) { case 'l': mode_fnc = list_users; break; diff --git a/eurephiadm/eurephiadm.c b/eurephiadm/eurephiadm.c index 7062a81..43ae999 100644 --- a/eurephiadm/eurephiadm.c +++ b/eurephiadm/eurephiadm.c @@ -257,7 +257,7 @@ int main(int argc, char **argv) { if( *argv[argi] != '-' ) { break; } - switch( eurephia_getopt(argi, argc, argv, argopts) ) { + switch( eurephia_getopt(&argi, argc, argv, argopts) ) { case 'V': print_version(argv[0]); return 0; @@ -272,12 +272,10 @@ int main(int argc, char **argv) { basename(argv[0]), optargs[0]); return 0; } - argi++; break; case 'L': loglevel = atoi_nullsafe(optargs[0]); - argi++; break; default: -- cgit