diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/getopt.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/openbsd-compat/getopt.c b/openbsd-compat/getopt.c index 9e13504a0..f4fbc9bac 100644 --- a/openbsd-compat/getopt.c +++ b/openbsd-compat/getopt.c | |||
@@ -42,11 +42,11 @@ static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; | |||
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | #include <string.h> | 43 | #include <string.h> |
44 | 44 | ||
45 | int opterr = 1, /* if error message should be printed */ | 45 | int BSDopterr = 1, /* if error message should be printed */ |
46 | optind = 1, /* index into parent argv vector */ | 46 | BSDoptind = 1, /* index into parent argv vector */ |
47 | optopt, /* character checked for validity */ | 47 | BSDoptopt, /* character checked for validity */ |
48 | optreset; /* reset getopt */ | 48 | BSDoptreset; /* reset getopt */ |
49 | char *optarg; /* argument associated with option */ | 49 | char *BSDoptarg; /* argument associated with option */ |
50 | 50 | ||
51 | #define BADCH (int)'?' | 51 | #define BADCH (int)'?' |
52 | #define BADARG (int)':' | 52 | #define BADARG (int)':' |
@@ -66,57 +66,57 @@ BSDgetopt(nargc, nargv, ostr) | |||
66 | static char *place = EMSG; /* option letter processing */ | 66 | static char *place = EMSG; /* option letter processing */ |
67 | char *oli; /* option letter list index */ | 67 | char *oli; /* option letter list index */ |
68 | 68 | ||
69 | if (optreset || !*place) { /* update scanning pointer */ | 69 | if (BSDoptreset || !*place) { /* update scanning pointer */ |
70 | optreset = 0; | 70 | BSDoptreset = 0; |
71 | if (optind >= nargc || *(place = nargv[optind]) != '-') { | 71 | if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') { |
72 | place = EMSG; | 72 | place = EMSG; |
73 | return (-1); | 73 | return (-1); |
74 | } | 74 | } |
75 | if (place[1] && *++place == '-') { /* found "--" */ | 75 | if (place[1] && *++place == '-') { /* found "--" */ |
76 | ++optind; | 76 | ++BSDoptind; |
77 | place = EMSG; | 77 | place = EMSG; |
78 | return (-1); | 78 | return (-1); |
79 | } | 79 | } |
80 | } /* option letter okay? */ | 80 | } /* option letter okay? */ |
81 | if ((optopt = (int)*place++) == (int)':' || | 81 | if ((BSDoptopt = (int)*place++) == (int)':' || |
82 | !(oli = strchr(ostr, optopt))) { | 82 | !(oli = strchr(ostr, BSDoptopt))) { |
83 | /* | 83 | /* |
84 | * if the user didn't specify '-' as an option, | 84 | * if the user didn't specify '-' as an option, |
85 | * assume it means -1. | 85 | * assume it means -1. |
86 | */ | 86 | */ |
87 | if (optopt == (int)'-') | 87 | if (BSDoptopt == (int)'-') |
88 | return (-1); | 88 | return (-1); |
89 | if (!*place) | 89 | if (!*place) |
90 | ++optind; | 90 | ++BSDoptind; |
91 | if (opterr && *ostr != ':') | 91 | if (BSDopterr && *ostr != ':') |
92 | (void)fprintf(stderr, | 92 | (void)fprintf(stderr, |
93 | "%s: illegal option -- %c\n", __progname, optopt); | 93 | "%s: illegal option -- %c\n", __progname, BSDoptopt); |
94 | return (BADCH); | 94 | return (BADCH); |
95 | } | 95 | } |
96 | if (*++oli != ':') { /* don't need argument */ | 96 | if (*++oli != ':') { /* don't need argument */ |
97 | optarg = NULL; | 97 | BSDoptarg = NULL; |
98 | if (!*place) | 98 | if (!*place) |
99 | ++optind; | 99 | ++BSDoptind; |
100 | } | 100 | } |
101 | else { /* need an argument */ | 101 | else { /* need an argument */ |
102 | if (*place) /* no white space */ | 102 | if (*place) /* no white space */ |
103 | optarg = place; | 103 | BSDoptarg = place; |
104 | else if (nargc <= ++optind) { /* no arg */ | 104 | else if (nargc <= ++BSDoptind) { /* no arg */ |
105 | place = EMSG; | 105 | place = EMSG; |
106 | if (*ostr == ':') | 106 | if (*ostr == ':') |
107 | return (BADARG); | 107 | return (BADARG); |
108 | if (opterr) | 108 | if (BSDopterr) |
109 | (void)fprintf(stderr, | 109 | (void)fprintf(stderr, |
110 | "%s: option requires an argument -- %c\n", | 110 | "%s: option requires an argument -- %c\n", |
111 | __progname, optopt); | 111 | __progname, BSDoptopt); |
112 | return (BADCH); | 112 | return (BADCH); |
113 | } | 113 | } |
114 | else /* white space */ | 114 | else /* white space */ |
115 | optarg = nargv[optind]; | 115 | BSDoptarg = nargv[BSDoptind]; |
116 | place = EMSG; | 116 | place = EMSG; |
117 | ++optind; | 117 | ++BSDoptind; |
118 | } | 118 | } |
119 | return (optopt); /* dump back option letter */ | 119 | return (BSDoptopt); /* dump back option letter */ |
120 | } | 120 | } |
121 | 121 | ||
122 | #endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */ | 122 | #endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */ |