Deleted Added
full compact
egetopt.c (1591) egetopt.c (98552)
1/*-
2 * Copyright (c) 1991 Keith Muller.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
1/*-
2 * Copyright (c) 1991 Keith Muller.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 21 unchanged lines hidden (view full) ---

30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38#if 0
38#ifndef lint
39static char sccsid[] = "@(#)egetopt.c 8.1 (Berkeley) 6/6/93";
40#endif /* not lint */
39#ifndef lint
40static char sccsid[] = "@(#)egetopt.c 8.1 (Berkeley) 6/6/93";
41#endif /* not lint */
42#endif
41
43
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/usr.bin/pr/egetopt.c 98552 2002-06-21 10:14:57Z markm $");
46
42#include <ctype.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46
47#include "extern.h"
48
49/*

--- 9 unchanged lines hidden (view full) ---

59 */
60
61int eopterr = 1; /* if error message should be printed */
62int eoptind = 1; /* index into parent argv vector */
63int eoptopt; /* character checked for validity */
64char *eoptarg; /* argument associated with option */
65
66#define BADCH (int)'?'
47#include <ctype.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <string.h>
51
52#include "extern.h"
53
54/*

--- 9 unchanged lines hidden (view full) ---

64 */
65
66int eopterr = 1; /* if error message should be printed */
67int eoptind = 1; /* index into parent argv vector */
68int eoptopt; /* character checked for validity */
69char *eoptarg; /* argument associated with option */
70
71#define BADCH (int)'?'
67#define EMSG ""
68
72
73static char emsg[] = "";
74
69int
75int
70egetopt(nargc, nargv, ostr)
71 int nargc;
72 char * const *nargv;
73 const char *ostr;
76egetopt(int nargc, char * const *nargv, const char *ostr)
74{
77{
75 static char *place = EMSG; /* option letter processing */
76 register char *oli; /* option letter list index */
78 static char *place = emsg; /* option letter processing */
79 char *oli; /* option letter list index */
77 static int delim; /* which option delimeter */
80 static int delim; /* which option delimeter */
78 register char *p;
81 char *p;
79 static char savec = '\0';
80
81 if (savec != '\0') {
82 *place = savec;
83 savec = '\0';
84 }
85
86 if (!*place) {
87 /*
88 * update scanning pointer
89 */
90 if ((eoptind >= nargc) ||
91 ((*(place = nargv[eoptind]) != '-') && (*place != '+'))) {
82 static char savec = '\0';
83
84 if (savec != '\0') {
85 *place = savec;
86 savec = '\0';
87 }
88
89 if (!*place) {
90 /*
91 * update scanning pointer
92 */
93 if ((eoptind >= nargc) ||
94 ((*(place = nargv[eoptind]) != '-') && (*place != '+'))) {
92 place = EMSG;
95 place = emsg;
93 return (EOF);
94 }
95
96 delim = (int)*place;
97 if (place[1] && *++place == '-' && !place[1]) {
98 /*
99 * found "--"
100 */
101 ++eoptind;
96 return (EOF);
97 }
98
99 delim = (int)*place;
100 if (place[1] && *++place == '-' && !place[1]) {
101 /*
102 * found "--"
103 */
104 ++eoptind;
102 place = EMSG;
105 place = emsg;
103 return (EOF);
104 }
105 }
106
107 /*
108 * check option letter
109 */
110 if ((eoptopt = (int)*place++) == (int)':' || (eoptopt == (int)'?') ||

--- 12 unchanged lines hidden (view full) ---

123 */
124 for (p = place; *p != '\0'; ++p) {
125 if (!isdigit(*p))
126 break;
127 }
128 eoptarg = place-1;
129
130 if (*p == '\0') {
106 return (EOF);
107 }
108 }
109
110 /*
111 * check option letter
112 */
113 if ((eoptopt = (int)*place++) == (int)':' || (eoptopt == (int)'?') ||

--- 12 unchanged lines hidden (view full) ---

126 */
127 for (p = place; *p != '\0'; ++p) {
128 if (!isdigit(*p))
129 break;
130 }
131 eoptarg = place-1;
132
133 if (*p == '\0') {
131 place = EMSG;
134 place = emsg;
132 ++eoptind;
133 } else {
134 place = p;
135 savec = *p;
136 *place = '\0';
137 }
138 return (delim);
139 }

--- 47 unchanged lines hidden (view full) ---

187 /*
188 * no arg, but NOT required
189 */
190 eoptarg = NULL;
191 } else if (nargc <= ++eoptind) {
192 /*
193 * no arg, but IS required
194 */
135 ++eoptind;
136 } else {
137 place = p;
138 savec = *p;
139 *place = '\0';
140 }
141 return (delim);
142 }

--- 47 unchanged lines hidden (view full) ---

190 /*
191 * no arg, but NOT required
192 */
193 eoptarg = NULL;
194 } else if (nargc <= ++eoptind) {
195 /*
196 * no arg, but IS required
197 */
195 place = EMSG;
198 place = emsg;
196 if (eopterr) {
197 if (!(p = strrchr(*nargv, '/')))
198 p = *nargv;
199 else
200 ++p;
201 (void)fprintf(stderr,
202 "%s: option requires an argument -- %c\n", p,
203 eoptopt);
204 }
205 return (BADCH);
206 } else {
207 /*
208 * arg has white space
209 */
210 eoptarg = nargv[eoptind];
211 }
199 if (eopterr) {
200 if (!(p = strrchr(*nargv, '/')))
201 p = *nargv;
202 else
203 ++p;
204 (void)fprintf(stderr,
205 "%s: option requires an argument -- %c\n", p,
206 eoptopt);
207 }
208 return (BADCH);
209 } else {
210 /*
211 * arg has white space
212 */
213 eoptarg = nargv[eoptind];
214 }
212 place = EMSG;
215 place = emsg;
213 ++eoptind;
214 return (eoptopt);
215}
216 ++eoptind;
217 return (eoptopt);
218}