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