X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=lib%2Fextra_opts.c;h=2939c7a14e1ad80364c8a822664f4ae41b8b4ee3;hb=4611e41bc50d15275b316c6f21b688997a9c78c4;hp=2aeb77ac2ab0b618025358bdb2e072cdffb95ea5;hpb=8aa5ec317af49d811b1c4b65c905cca81f845321;p=nagiosplug.git diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 2aeb77a..2939c7a 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c @@ -5,9 +5,6 @@ * License: GPL * Copyright (c) 2007 Nagios Plugins Development Team * -* Last Modified: $Date: 2008-03-15 18:42:01 -0400 (Sat, 15 Mar 2008) $ -* -* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -21,26 +18,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * -* $Id: parse_ini.c 1950 2008-03-15 22:42:01Z dermoth $ -* *****************************************************************************/ #include "common.h" -#include "extra_opts.h" -#include "parse_ini.h" #include "utils_base.h" -#include +#include "parse_ini.h" +#include "extra_opts.h" /* FIXME: copied from utils.h; we should move a bunch of libs! */ int -is_option (char *str) +is_option2 (char *str) { if (!str) - return 0; + return FALSE; else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) - return 1; + return TRUE; else - return 0; + return FALSE; } /* this is the externally visible function used by plugins */ @@ -66,9 +60,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ /* Delete the extra opts argument */ for(j=i;j<*argc;j++) argv[j]=argv[j+1]; i--; - *argc--; + *argc-=1; }else if(strcmp(argv[i], "--extra-opts")==0){ - if(!is_option(argv[i+1])){ + if((i+1<*argc)&&!is_option2(argv[i+1])){ /* It is a argument with separate value */ argptr=argv[i+1]; /* Delete the extra-opts argument/value */ @@ -82,7 +76,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ /* Delete the extra opts argument */ for(j=i;j<*argc;j++) argv[j]=argv[j+1]; i--; - *argc--; + *argc-=1; } } @@ -102,13 +96,15 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ while(ea1=ea1->next) ea_num++; }else{ ea_tmp=extra_args; - while(ea_tmp=ea_tmp->next) ea_num++; + while(ea_tmp->next) { + ea_tmp=ea_tmp->next; + } ea_tmp->next=ea1; + while(ea1=ea1->next) ea_num++; } ea1=ea_tmp=NULL; } - /* lather, rince, repeat */ - } + } /* lather, rince, repeat */ if(ea_num==*argc && extra_args==NULL){ /* No extra-opts */ @@ -120,7 +116,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ if(argv_new==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n")); /* starting with program name */ - argv_new[0]=strdup(argv[0]); + argv_new[0]=argv[0]; argc_new=1; /* then parsed ini opts (frying them up in the same run) */ while(extra_args){ @@ -130,7 +126,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name){ free(ea1); } /* finally the rest of the argv array */ - for (i=1; i<*argc; i++) argv_new[argc_new++]=strdup(argv[i]); + for (i=1; i<*argc; i++) argv_new[argc_new++]=argv[i]; *argc=argc_new; /* and terminate. */ argv_new[argc_new]=NULL;