From: Karl DeBisschop Date: Fri, 8 Nov 2002 08:06:55 +0000 (+0000) Subject: remove call_getopt X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b39ae71c60f0039cda60590715fc17f92107ac35;p=nagiosplug.git remove call_getopt git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@175 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/plugins/check_vsz.c b/plugins/check_vsz.c index f53eeae..2ec8775 100644 --- a/plugins/check_vsz.c +++ b/plugins/check_vsz.c @@ -33,12 +33,18 @@ * *****************************************************************************/ +#define PROGNAME "check_vsz" +#define REVISION "$Revision$" +#define COPYRIGHT "1999-2002" +#define AUTHOR "Karl DeBisschop" +#define EMAIL "karl@debisschop.net" +#define SUMMARY "Check the image size of a running program.\n" + #include "common.h" #include "popen.h" #include "utils.h" int process_arguments (int argc, char **argv); -int call_getopt (int argc, char **argv); void print_help (char *cmd); void print_usage (char *cmd); @@ -146,47 +152,6 @@ process_arguments (int argc, char **argv) { int c; - if (argc < 2) - return ERROR; - - c = 0; - while (c += (call_getopt (argc - c, &argv[c]))) { - if (argc <= c) - break; - if (warn == -1) { - if (!is_intnonneg (argv[c])) { - printf ("%s: critical threshold must be an integer: %s\n", - my_basename (argv[0]), argv[c]); - print_usage (my_basename (argv[0])); - exit (STATE_UNKNOWN); - } - warn = atoi (argv[c]); - } - else if (crit == -1) { - if (!is_intnonneg (argv[c])) { - printf ("%s: critical threshold must be an integer: %s\n", - my_basename (argv[0]), argv[c]); - print_usage (my_basename (argv[0])); - exit (STATE_UNKNOWN); - } - crit = atoi (argv[c]); - } - else if (proc == NULL) { - proc = malloc (strlen (argv[c]) + 1); - if (proc == NULL) - terminate (STATE_UNKNOWN, - "check_vsz: failed malloc of proc in process_arguments"); - strcpy (proc, argv[c]); - } - } - return c; -} - -int -call_getopt (int argc, char **argv) -{ - int c, i = 1; - #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { @@ -199,6 +164,9 @@ call_getopt (int argc, char **argv) }; #endif + if (argc < 2) + return ERROR; + while (1) { #ifdef HAVE_GETOPT_H c = getopt_long (argc, argv, "+hVc:w:C:", long_options, &option_index); @@ -208,14 +176,6 @@ call_getopt (int argc, char **argv) if (c == EOF) break; - i++; - switch (c) { - case 'c': - case 'w': - case 'C': - i++; - } - switch (c) { case '?': /* help */ printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); @@ -254,7 +214,37 @@ call_getopt (int argc, char **argv) break; } } - return i; + + c = optind; + if (warn == -1) { + if (!is_intnonneg (argv[c])) { + printf ("%s: critical threshold must be an integer: %s\n", + PROGNAME, argv[c]); + print_usage (PROGNAME); + exit (STATE_UNKNOWN); + } + warn = atoi (argv[c++]); + } + + if (crit == -1) { + if (!is_intnonneg (argv[c])) { + printf ("%s: critical threshold must be an integer: %s\n", + PROGNAME, argv[c]); + print_usage (PROGNAME); + exit (STATE_UNKNOWN); + } + crit = atoi (argv[c++]); + } + + if (proc == NULL) { + proc = malloc (strlen (argv[c]) + 1); + if (proc == NULL) + terminate (STATE_UNKNOWN, + "check_vsz: failed malloc of proc in process_arguments"); + strcpy (proc, argv[c]); + } + + return c; } void