diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-13 11:50:54 +0000 |
commit | 9e009c4b1128352c6039d25b39213fd480e9b055 (patch) | |
tree | e1495ef4ada6f8e092e20bc474195719f1b2b4aa /plugins/check_hpjd.c | |
parent | 9728dcad931d1c442a6d8e3e6765e2d9870600d1 (diff) | |
download | monitoring-plugins-9e009c4b1128352c6039d25b39213fd480e9b055.tar.gz |
remove call_getopt and asprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_hpjd.c')
-rw-r--r-- | plugins/check_hpjd.c | 96 |
1 files changed, 34 insertions, 62 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 6d42cd38..42b4bb54 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -66,6 +66,8 @@ #include "utils.h" #define PROGNAME "check_hpjd" +#define REVISION "$Revision$" +#define COPYRIGHT "2000-2002" #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" @@ -84,13 +86,13 @@ #define OFFLINE 1 int process_arguments (int, char **); -int call_getopt (int, char **); int validate_arguments (void); void print_help (void); void print_usage (void); char *community = NULL; -char *address = NULL; +char *address = "127.0.0.1"; + int main (int argc, char **argv) @@ -386,55 +388,6 @@ process_arguments (int argc, char **argv) { int c; - if (argc < 2) - return ERROR; - - for (c = 1; c < argc; c++) { - if (strcmp ("-to", argv[c]) == 0) - strcpy (argv[c], "-t"); - else if (strcmp ("-wt", argv[c]) == 0) - strcpy (argv[c], "-w"); - else if (strcmp ("-ct", argv[c]) == 0) - strcpy (argv[c], "-c"); - } - - - - c = 0; - while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { - - if (is_option (argv[c])) - continue; - - if (address == NULL) { - if (is_host (argv[c])) { - address = argv[c]; - } - else { - usage ("Invalid host name"); - } - } - else if (community == NULL) { - community = argv[c]; - } - } - - if (address == NULL) - address = strscpy (NULL, "127.0.0.1"); - - return validate_arguments (); -} - - - - - - -int -call_getopt (int argc, char **argv) -{ - int c, i = 0; - #ifdef HAVE_GETOPT_H int option_index = 0; static struct option long_options[] = { @@ -450,6 +403,18 @@ call_getopt (int argc, char **argv) }; #endif + if (argc < 2) + return ERROR; + + for (c = 1; c < argc; c++) { + if (strcmp ("-to", argv[c]) == 0) + strcpy (argv[c], "-t"); + else if (strcmp ("-wt", argv[c]) == 0) + strcpy (argv[c], "-w"); + else if (strcmp ("-ct", argv[c]) == 0) + strcpy (argv[c], "-c"); + } + while (1) { #ifdef HAVE_GETOPT_H c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); @@ -457,18 +422,10 @@ call_getopt (int argc, char **argv) c = getopt (argc, argv, "+?hVH:C:"); #endif - i++; - if (c == -1 || c == EOF || c == 1) break; switch (c) { - case 'H': - case 'C': - i++; - } - - switch (c) { case 'H': /* hostname */ if (is_host (optarg)) { address = optarg; @@ -481,7 +438,7 @@ call_getopt (int argc, char **argv) community = optarg; break; case 'V': /* version */ - print_revision (PROGNAME, "$Revision$"); + print_revision (PROGNAME, REVISION); exit (STATE_OK); case 'h': /* help */ print_help (); @@ -490,7 +447,22 @@ call_getopt (int argc, char **argv) usage ("Invalid argument\n"); } } - return i; + + c = optind; + if (address == NULL) { + if (is_host (argv[c])) { + address = argv[c++]; + } + else { + usage ("Invalid host name"); + } + } + + if (community == NULL) { + community = argv[c++]; + } + + return validate_arguments (); } @@ -510,7 +482,7 @@ validate_arguments (void) void print_help (void) { - print_revision (PROGNAME, "$Revision$"); + print_revision (PROGNAME, REVISION); printf ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" "This plugin tests the STATUS of an HP printer with a JetDirect card.\n" |