1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1996-2001 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include "common.h"
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate int
parse_option(int * pargc,char *** pargv,struct flags * flag)32*7c478bd9Sstevel@tonic-gate parse_option(int *pargc, char ***pargv, struct flags *flag)
33*7c478bd9Sstevel@tonic-gate {
34*7c478bd9Sstevel@tonic-gate char c;
35*7c478bd9Sstevel@tonic-gate char *arg;
36*7c478bd9Sstevel@tonic-gate int argc = *pargc;
37*7c478bd9Sstevel@tonic-gate char **argv = *pargv;
38*7c478bd9Sstevel@tonic-gate
39*7c478bd9Sstevel@tonic-gate argv++;
40*7c478bd9Sstevel@tonic-gate while (--argc > 1) {
41*7c478bd9Sstevel@tonic-gate arg = *argv;
42*7c478bd9Sstevel@tonic-gate if (*arg == '-') {
43*7c478bd9Sstevel@tonic-gate if (!*(arg + 1)) {
44*7c478bd9Sstevel@tonic-gate /* not an option */
45*7c478bd9Sstevel@tonic-gate break;
46*7c478bd9Sstevel@tonic-gate }
47*7c478bd9Sstevel@tonic-gate loop:
48*7c478bd9Sstevel@tonic-gate if ((c = *++arg) == '\0') {
49*7c478bd9Sstevel@tonic-gate /* next argument */
50*7c478bd9Sstevel@tonic-gate argv++;
51*7c478bd9Sstevel@tonic-gate continue;
52*7c478bd9Sstevel@tonic-gate } else if (c != '-') {
53*7c478bd9Sstevel@tonic-gate /* Sun option */
54*7c478bd9Sstevel@tonic-gate switch (c) {
55*7c478bd9Sstevel@tonic-gate case 'D':
56*7c478bd9Sstevel@tonic-gate /*
57*7c478bd9Sstevel@tonic-gate * add directory to list for input
58*7c478bd9Sstevel@tonic-gate * files search.
59*7c478bd9Sstevel@tonic-gate */
60*7c478bd9Sstevel@tonic-gate if (*(arg + 1)) {
61*7c478bd9Sstevel@tonic-gate /*
62*7c478bd9Sstevel@tonic-gate * no spaces between -D and
63*7c478bd9Sstevel@tonic-gate * optarg
64*7c478bd9Sstevel@tonic-gate */
65*7c478bd9Sstevel@tonic-gate flag->idir = ++arg;
66*7c478bd9Sstevel@tonic-gate argv++;
67*7c478bd9Sstevel@tonic-gate continue;
68*7c478bd9Sstevel@tonic-gate }
69*7c478bd9Sstevel@tonic-gate if (--argc > 1) {
70*7c478bd9Sstevel@tonic-gate if (!flag->idir)
71*7c478bd9Sstevel@tonic-gate flag->idir = *++argv;
72*7c478bd9Sstevel@tonic-gate else
73*7c478bd9Sstevel@tonic-gate ++argv;
74*7c478bd9Sstevel@tonic-gate argv++;
75*7c478bd9Sstevel@tonic-gate continue;
76*7c478bd9Sstevel@tonic-gate }
77*7c478bd9Sstevel@tonic-gate /* not enough args */
78*7c478bd9Sstevel@tonic-gate return (-1);
79*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
80*7c478bd9Sstevel@tonic-gate case 'f':
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate * Use fuzzy entry
83*7c478bd9Sstevel@tonic-gate */
84*7c478bd9Sstevel@tonic-gate flag->fuzzy = 1;
85*7c478bd9Sstevel@tonic-gate goto loop;
86*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
87*7c478bd9Sstevel@tonic-gate case 'o':
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * Specify output file name
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate if (*(arg + 1)) {
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate * no spaces between -o and
94*7c478bd9Sstevel@tonic-gate * optarg
95*7c478bd9Sstevel@tonic-gate */
96*7c478bd9Sstevel@tonic-gate flag->ofile = ++arg;
97*7c478bd9Sstevel@tonic-gate argv++;
98*7c478bd9Sstevel@tonic-gate continue;
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate if (--argc > 1) {
101*7c478bd9Sstevel@tonic-gate flag->ofile = *++argv;
102*7c478bd9Sstevel@tonic-gate argv++;
103*7c478bd9Sstevel@tonic-gate continue;
104*7c478bd9Sstevel@tonic-gate }
105*7c478bd9Sstevel@tonic-gate /* not enough args */
106*7c478bd9Sstevel@tonic-gate return (-1);
107*7c478bd9Sstevel@tonic-gate case 'g':
108*7c478bd9Sstevel@tonic-gate /*
109*7c478bd9Sstevel@tonic-gate * GNU mode
110*7c478bd9Sstevel@tonic-gate */
111*7c478bd9Sstevel@tonic-gate flag->gnu_p = 1;
112*7c478bd9Sstevel@tonic-gate goto loop;
113*7c478bd9Sstevel@tonic-gate case 's':
114*7c478bd9Sstevel@tonic-gate /*
115*7c478bd9Sstevel@tonic-gate * Sun mode
116*7c478bd9Sstevel@tonic-gate */
117*7c478bd9Sstevel@tonic-gate flag->sun_p = 1;
118*7c478bd9Sstevel@tonic-gate goto loop;
119*7c478bd9Sstevel@tonic-gate case 'v':
120*7c478bd9Sstevel@tonic-gate /*
121*7c478bd9Sstevel@tonic-gate * verbose mode
122*7c478bd9Sstevel@tonic-gate */
123*7c478bd9Sstevel@tonic-gate flag->verbose = 1;
124*7c478bd9Sstevel@tonic-gate goto loop;
125*7c478bd9Sstevel@tonic-gate default:
126*7c478bd9Sstevel@tonic-gate /* illegal option */
127*7c478bd9Sstevel@tonic-gate return (-1);
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate if (*(arg + 1) == '\0') {
133*7c478bd9Sstevel@tonic-gate /* option end */
134*7c478bd9Sstevel@tonic-gate argv++;
135*7c478bd9Sstevel@tonic-gate argc--;
136*7c478bd9Sstevel@tonic-gate break;
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate /* GNU options */
140*7c478bd9Sstevel@tonic-gate arg++;
141*7c478bd9Sstevel@tonic-gate if (strncmp(arg, "directory=", 10) == 0) {
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate * add directory to list for input
144*7c478bd9Sstevel@tonic-gate * files search.
145*7c478bd9Sstevel@tonic-gate */
146*7c478bd9Sstevel@tonic-gate if (flag->idir) {
147*7c478bd9Sstevel@tonic-gate /*
148*7c478bd9Sstevel@tonic-gate * inputdir has already been specified
149*7c478bd9Sstevel@tonic-gate */
150*7c478bd9Sstevel@tonic-gate argv++;
151*7c478bd9Sstevel@tonic-gate continue;
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate arg += 10;
154*7c478bd9Sstevel@tonic-gate if (*arg == '\0') {
155*7c478bd9Sstevel@tonic-gate /* illegal option */
156*7c478bd9Sstevel@tonic-gate return (-1);
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate flag->idir = arg;
159*7c478bd9Sstevel@tonic-gate argv++;
160*7c478bd9Sstevel@tonic-gate continue;
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "use-fuzzy") == 0) {
163*7c478bd9Sstevel@tonic-gate /*
164*7c478bd9Sstevel@tonic-gate * Use fuzzy entry
165*7c478bd9Sstevel@tonic-gate */
166*7c478bd9Sstevel@tonic-gate flag->fuzzy = 1;
167*7c478bd9Sstevel@tonic-gate argv++;
168*7c478bd9Sstevel@tonic-gate continue;
169*7c478bd9Sstevel@tonic-gate }
170*7c478bd9Sstevel@tonic-gate if (strncmp(arg, "output-file=", 12) == 0) {
171*7c478bd9Sstevel@tonic-gate /*
172*7c478bd9Sstevel@tonic-gate * Specify output file name
173*7c478bd9Sstevel@tonic-gate */
174*7c478bd9Sstevel@tonic-gate arg += 12;
175*7c478bd9Sstevel@tonic-gate if (*arg == '\0') {
176*7c478bd9Sstevel@tonic-gate /* illegal option */
177*7c478bd9Sstevel@tonic-gate return (-1);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate flag->ofile = arg;
180*7c478bd9Sstevel@tonic-gate argv++;
181*7c478bd9Sstevel@tonic-gate continue;
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "strict") == 0) {
184*7c478bd9Sstevel@tonic-gate /*
185*7c478bd9Sstevel@tonic-gate * strict mode
186*7c478bd9Sstevel@tonic-gate */
187*7c478bd9Sstevel@tonic-gate flag->strict = 1;
188*7c478bd9Sstevel@tonic-gate argv++;
189*7c478bd9Sstevel@tonic-gate continue;
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "verbose") == 0) {
192*7c478bd9Sstevel@tonic-gate /*
193*7c478bd9Sstevel@tonic-gate * verbose mode
194*7c478bd9Sstevel@tonic-gate */
195*7c478bd9Sstevel@tonic-gate flag->verbose = 1;
196*7c478bd9Sstevel@tonic-gate argv++;
197*7c478bd9Sstevel@tonic-gate continue;
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate /* illegal option */
200*7c478bd9Sstevel@tonic-gate return (-1);
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate break;
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate
205*7c478bd9Sstevel@tonic-gate if (argc == 0)
206*7c478bd9Sstevel@tonic-gate return (-1);
207*7c478bd9Sstevel@tonic-gate
208*7c478bd9Sstevel@tonic-gate *pargc = argc;
209*7c478bd9Sstevel@tonic-gate *pargv = argv;
210*7c478bd9Sstevel@tonic-gate return (0);
211*7c478bd9Sstevel@tonic-gate }
212