From 8aa5ec317af49d811b1c4b65c905cca81f845321 Mon Sep 17 00:00:00 2001 From: Thomas Guyot-Sionnest Date: Sun, 30 Mar 2008 14:02:13 +0000 Subject: - Remove the last argument of np_extra_opts - Code cleanups and comments git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1967 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 3a0ce04..2aeb77a 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c @@ -44,23 +44,18 @@ is_option (char *str) } /* this is the externally visible function used by plugins */ -/* Shouldn't se modify directly **argv (passed as a char ***) and argc - * (as int *) ? - */ -char **np_extra_opts(int argc, char **argv, const char *plugin_name, int *argc_new){ - np_arg_list *extra_args=NULL, *ea_tmp1=NULL, *ea_tmp2=NULL; +char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ + np_arg_list *extra_args=NULL, *ea1=NULL, *ea_tmp=NULL; char **argv_new=NULL; char *argptr=NULL; - int i, j, optfound, ea_num=argc; + int i, j, optfound, argc_new, ea_num=*argc; - if(argc<2) { + if(*argc<2) { /* No arguments provided */ - *argc_new=argc; - argv_new=argv; - return argv_new; + return argv; } - for(i=1; inext) { - ea_tmp2=ea_tmp2->next; - ea_num++; - } + extra_args=ea1; + while(ea1=ea1->next) ea_num++; }else{ - ea_tmp2=extra_args; - while(ea_tmp2->next) { - ea_tmp2=ea_tmp2->next; - ea_num++; - } - ea_tmp2->next=ea_tmp1; + ea_tmp=extra_args; + while(ea_tmp=ea_tmp->next) ea_num++; + ea_tmp->next=ea1; } - ea_tmp1=ea_tmp2=NULL; + ea1=ea_tmp=NULL; } /* lather, rince, repeat */ } - if(ea_num==argc && extra_args==NULL){ + if(ea_num==*argc && extra_args==NULL){ /* No extra-opts */ - *argc_new=argc; - argv_new=argv; - return argv_new; + return argv; } - /* done processing arguments. now create a new argc/argv set... */ + /* done processing arguments. now create a new argv array... */ argv_new=(char**)malloc((ea_num+1)*sizeof(char**)); if(argv_new==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n")); - /* starting with program name (Should we strdup or just use the poiter?) */ + /* starting with program name */ argv_new[0]=strdup(argv[0]); - *argc_new=1; + argc_new=1; /* then parsed ini opts (frying them up in the same run) */ while(extra_args){ - argv_new[*argc_new]=strdup(extra_args->arg); - *argc_new+=1; - ea_tmp1=extra_args; + argv_new[argc_new++]=extra_args->arg; + ea1=extra_args; extra_args=extra_args->next; - free(ea_tmp1); - } - /* finally the rest of the argv array (Should we strdup or just use the poiter?) */ - for (i=1; i