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 #include "common.h"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate int
parse_option(int * pargc,char *** pargv,struct flags * flag)30*7c478bd9Sstevel@tonic-gate parse_option(int *pargc, char ***pargv, struct flags *flag)
31*7c478bd9Sstevel@tonic-gate {
32*7c478bd9Sstevel@tonic-gate char c;
33*7c478bd9Sstevel@tonic-gate char *arg;
34*7c478bd9Sstevel@tonic-gate int argc = *pargc;
35*7c478bd9Sstevel@tonic-gate char **argv = *pargv;
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate argv++;
38*7c478bd9Sstevel@tonic-gate while (--argc > 1) {
39*7c478bd9Sstevel@tonic-gate arg = *argv;
40*7c478bd9Sstevel@tonic-gate if (*arg == '-') {
41*7c478bd9Sstevel@tonic-gate if (!*(arg + 1)) {
42*7c478bd9Sstevel@tonic-gate /* not an option */
43*7c478bd9Sstevel@tonic-gate break;
44*7c478bd9Sstevel@tonic-gate }
45*7c478bd9Sstevel@tonic-gate loop:
46*7c478bd9Sstevel@tonic-gate if ((c = *++arg) == '\0') {
47*7c478bd9Sstevel@tonic-gate /* next argument */
48*7c478bd9Sstevel@tonic-gate argv++;
49*7c478bd9Sstevel@tonic-gate continue;
50*7c478bd9Sstevel@tonic-gate } else if (c != '-') {
51*7c478bd9Sstevel@tonic-gate /* Sun option */
52*7c478bd9Sstevel@tonic-gate switch (c) {
53*7c478bd9Sstevel@tonic-gate case 'D':
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate * add directory to list for input
56*7c478bd9Sstevel@tonic-gate * files search.
57*7c478bd9Sstevel@tonic-gate */
58*7c478bd9Sstevel@tonic-gate if (*(arg + 1)) {
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate * no spaces between -D and
61*7c478bd9Sstevel@tonic-gate * optarg
62*7c478bd9Sstevel@tonic-gate */
63*7c478bd9Sstevel@tonic-gate flag->idir = ++arg;
64*7c478bd9Sstevel@tonic-gate argv++;
65*7c478bd9Sstevel@tonic-gate continue;
66*7c478bd9Sstevel@tonic-gate }
67*7c478bd9Sstevel@tonic-gate if (--argc > 1) {
68*7c478bd9Sstevel@tonic-gate if (!flag->idir)
69*7c478bd9Sstevel@tonic-gate flag->idir = *++argv;
70*7c478bd9Sstevel@tonic-gate else
71*7c478bd9Sstevel@tonic-gate ++argv;
72*7c478bd9Sstevel@tonic-gate argv++;
73*7c478bd9Sstevel@tonic-gate continue;
74*7c478bd9Sstevel@tonic-gate }
75*7c478bd9Sstevel@tonic-gate /* not enough args */
76*7c478bd9Sstevel@tonic-gate return (-1);
77*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
78*7c478bd9Sstevel@tonic-gate case 'f':
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate * Use fuzzy entry
81*7c478bd9Sstevel@tonic-gate */
82*7c478bd9Sstevel@tonic-gate flag->fuzzy = 1;
83*7c478bd9Sstevel@tonic-gate goto loop;
84*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
85*7c478bd9Sstevel@tonic-gate case 'o':
86*7c478bd9Sstevel@tonic-gate /*
87*7c478bd9Sstevel@tonic-gate * Specify output file name
88*7c478bd9Sstevel@tonic-gate */
89*7c478bd9Sstevel@tonic-gate if (*(arg + 1)) {
90*7c478bd9Sstevel@tonic-gate /*
91*7c478bd9Sstevel@tonic-gate * no spaces between -o and
92*7c478bd9Sstevel@tonic-gate * optarg
93*7c478bd9Sstevel@tonic-gate */
94*7c478bd9Sstevel@tonic-gate flag->ofile = ++arg;
95*7c478bd9Sstevel@tonic-gate argv++;
96*7c478bd9Sstevel@tonic-gate continue;
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate if (--argc > 1) {
99*7c478bd9Sstevel@tonic-gate flag->ofile = *++argv;
100*7c478bd9Sstevel@tonic-gate argv++;
101*7c478bd9Sstevel@tonic-gate continue;
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate /* not enough args */
104*7c478bd9Sstevel@tonic-gate return (-1);
105*7c478bd9Sstevel@tonic-gate case 'g':
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate * GNU mode
108*7c478bd9Sstevel@tonic-gate */
109*7c478bd9Sstevel@tonic-gate flag->gnu_p = 1;
110*7c478bd9Sstevel@tonic-gate goto loop;
111*7c478bd9Sstevel@tonic-gate case 's':
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate * Sun mode
114*7c478bd9Sstevel@tonic-gate */
115*7c478bd9Sstevel@tonic-gate flag->sun_p = 1;
116*7c478bd9Sstevel@tonic-gate goto loop;
117*7c478bd9Sstevel@tonic-gate case 'v':
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate * verbose mode
120*7c478bd9Sstevel@tonic-gate */
121*7c478bd9Sstevel@tonic-gate flag->verbose = 1;
122*7c478bd9Sstevel@tonic-gate goto loop;
123*7c478bd9Sstevel@tonic-gate default:
124*7c478bd9Sstevel@tonic-gate /* illegal option */
125*7c478bd9Sstevel@tonic-gate return (-1);
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate /* NOTREACHED */
128*7c478bd9Sstevel@tonic-gate }
129*7c478bd9Sstevel@tonic-gate
130*7c478bd9Sstevel@tonic-gate if (*(arg + 1) == '\0') {
131*7c478bd9Sstevel@tonic-gate /* option end */
132*7c478bd9Sstevel@tonic-gate argv++;
133*7c478bd9Sstevel@tonic-gate argc--;
134*7c478bd9Sstevel@tonic-gate break;
135*7c478bd9Sstevel@tonic-gate }
136*7c478bd9Sstevel@tonic-gate
137*7c478bd9Sstevel@tonic-gate /* GNU options */
138*7c478bd9Sstevel@tonic-gate arg++;
139*7c478bd9Sstevel@tonic-gate if (strncmp(arg, "directory=", 10) == 0) {
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate * add directory to list for input
142*7c478bd9Sstevel@tonic-gate * files search.
143*7c478bd9Sstevel@tonic-gate */
144*7c478bd9Sstevel@tonic-gate if (flag->idir) {
145*7c478bd9Sstevel@tonic-gate /*
146*7c478bd9Sstevel@tonic-gate * inputdir has already been specified
147*7c478bd9Sstevel@tonic-gate */
148*7c478bd9Sstevel@tonic-gate argv++;
149*7c478bd9Sstevel@tonic-gate continue;
150*7c478bd9Sstevel@tonic-gate }
151*7c478bd9Sstevel@tonic-gate arg += 10;
152*7c478bd9Sstevel@tonic-gate if (*arg == '\0') {
153*7c478bd9Sstevel@tonic-gate /* illegal option */
154*7c478bd9Sstevel@tonic-gate return (-1);
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate flag->idir = arg;
157*7c478bd9Sstevel@tonic-gate argv++;
158*7c478bd9Sstevel@tonic-gate continue;
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "use-fuzzy") == 0) {
161*7c478bd9Sstevel@tonic-gate /*
162*7c478bd9Sstevel@tonic-gate * Use fuzzy entry
163*7c478bd9Sstevel@tonic-gate */
164*7c478bd9Sstevel@tonic-gate flag->fuzzy = 1;
165*7c478bd9Sstevel@tonic-gate argv++;
166*7c478bd9Sstevel@tonic-gate continue;
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate if (strncmp(arg, "output-file=", 12) == 0) {
169*7c478bd9Sstevel@tonic-gate /*
170*7c478bd9Sstevel@tonic-gate * Specify output file name
171*7c478bd9Sstevel@tonic-gate */
172*7c478bd9Sstevel@tonic-gate arg += 12;
173*7c478bd9Sstevel@tonic-gate if (*arg == '\0') {
174*7c478bd9Sstevel@tonic-gate /* illegal option */
175*7c478bd9Sstevel@tonic-gate return (-1);
176*7c478bd9Sstevel@tonic-gate }
177*7c478bd9Sstevel@tonic-gate flag->ofile = arg;
178*7c478bd9Sstevel@tonic-gate argv++;
179*7c478bd9Sstevel@tonic-gate continue;
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "strict") == 0) {
182*7c478bd9Sstevel@tonic-gate /*
183*7c478bd9Sstevel@tonic-gate * strict mode
184*7c478bd9Sstevel@tonic-gate */
185*7c478bd9Sstevel@tonic-gate flag->strict = 1;
186*7c478bd9Sstevel@tonic-gate argv++;
187*7c478bd9Sstevel@tonic-gate continue;
188*7c478bd9Sstevel@tonic-gate }
189*7c478bd9Sstevel@tonic-gate if (strcmp(arg, "verbose") == 0) {
190*7c478bd9Sstevel@tonic-gate /*
191*7c478bd9Sstevel@tonic-gate * verbose mode
192*7c478bd9Sstevel@tonic-gate */
193*7c478bd9Sstevel@tonic-gate flag->verbose = 1;
194*7c478bd9Sstevel@tonic-gate argv++;
195*7c478bd9Sstevel@tonic-gate continue;
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate /* illegal option */
198*7c478bd9Sstevel@tonic-gate return (-1);
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate break;
201*7c478bd9Sstevel@tonic-gate }
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gate if (argc == 0)
204*7c478bd9Sstevel@tonic-gate return (-1);
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate *pargc = argc;
207*7c478bd9Sstevel@tonic-gate *pargv = argv;
208*7c478bd9Sstevel@tonic-gate return (0);
209*7c478bd9Sstevel@tonic-gate }
210