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