xref: /onnv-gate/usr/src/cmd/lvm/metassist/controller/getopt_ext.h (revision 0:68f95e015346)
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 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _GETOPTEXT_H
28*0Sstevel@tonic-gate #define	_GETOPTEXT_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #ifdef __cplusplus
33*0Sstevel@tonic-gate extern "C" {
34*0Sstevel@tonic-gate #endif
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate  * Returned chars for getopt_ext
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate /* A non-option argument was found */
41*0Sstevel@tonic-gate #define	GETOPT_NON_OPTION_ARG		1
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate /* All arguments have been parsed */
44*0Sstevel@tonic-gate #define	GETOPT_DONE_PARSING		-1
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /* An invalid option was found */
47*0Sstevel@tonic-gate #define	GETOPT_ERR_INVALID_OPT		-2
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /* An invalid non-option argument was found */
50*0Sstevel@tonic-gate #define	GETOPT_ERR_INVALID_ARG		-3
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate /* No argument for valid option expecting an argument */
53*0Sstevel@tonic-gate #define	GETOPT_ERR_MISSING_ARG		-4
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /*
56*0Sstevel@tonic-gate  * Function prototypes
57*0Sstevel@tonic-gate  */
58*0Sstevel@tonic-gate 
59*0Sstevel@tonic-gate /*
60*0Sstevel@tonic-gate  * Identical to getopt(3), except that
61*0Sstevel@tonic-gate  *
62*0Sstevel@tonic-gate  * 1. If "-" is the first character of optstring, each non-option argv
63*0Sstevel@tonic-gate  *    element is handled as if it were the argument of an option with
64*0Sstevel@tonic-gate  *    character code GETOPT_NON_OPTION_ARG.  The result is that
65*0Sstevel@tonic-gate  *    GETOPT_DONE_PARSING will not be returned until the end of the
66*0Sstevel@tonic-gate  *    argument list has been reached.
67*0Sstevel@tonic-gate  *
68*0Sstevel@tonic-gate  *    This mirrors the functionality provided by GNU getopt.
69*0Sstevel@tonic-gate  *
70*0Sstevel@tonic-gate  * 2. GETOPT_ERR_INVALID_OPT or GETOPT_ERR_MISSING_ARG is returned
71*0Sstevel@tonic-gate  *    instead of '?'.  Subsequently "-?" can be used as a valid
72*0Sstevel@tonic-gate  *    option.
73*0Sstevel@tonic-gate  *
74*0Sstevel@tonic-gate  * 3. GETOPT_DONE_PARSING, GETOPT_ERR_INVALID_ARG, or
75*0Sstevel@tonic-gate  *    GETOPT_NON_OPTION_ARG is returned instead of -1.
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  * @param       argc
78*0Sstevel@tonic-gate  *              The number of arguments in the array
79*0Sstevel@tonic-gate  *
80*0Sstevel@tonic-gate  * @param       argv
81*0Sstevel@tonic-gate  *              The argument array
82*0Sstevel@tonic-gate  *
83*0Sstevel@tonic-gate  * @param       optstring
84*0Sstevel@tonic-gate  *              The option letters, with ':' following options with
85*0Sstevel@tonic-gate  *              required arguments.  See note about "-" as the first
86*0Sstevel@tonic-gate  *              character.
87*0Sstevel@tonic-gate  *
88*0Sstevel@tonic-gate  * @return      GETOPT_ERR_INVALID_OPT
89*0Sstevel@tonic-gate  *              if the option is not found in optstring
90*0Sstevel@tonic-gate  *
91*0Sstevel@tonic-gate  *              GETOPT_ERR_MISSING_ARG
92*0Sstevel@tonic-gate  *              if the option requires an argument which is missing
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  *              GETOPT_ERR_INVALID_ARG
95*0Sstevel@tonic-gate  *              if "-" is not the first character in optstring and a
96*0Sstevel@tonic-gate  *              non-option argument is encountered
97*0Sstevel@tonic-gate  *
98*0Sstevel@tonic-gate  *              GETOPT_NON_OPTION_ARG
99*0Sstevel@tonic-gate  *              if "-" is the first character in optstring and a
100*0Sstevel@tonic-gate  *              non-option argument is encountered
101*0Sstevel@tonic-gate  *
102*0Sstevel@tonic-gate  *              GETOPT_DONE_PARSING
103*0Sstevel@tonic-gate  *              if the end of the argument list is reached
104*0Sstevel@tonic-gate  *
105*0Sstevel@tonic-gate  *              <optopt>
106*0Sstevel@tonic-gate  *              the option character itself, if none of the above
107*0Sstevel@tonic-gate  *              scenarios applies.
108*0Sstevel@tonic-gate  */
109*0Sstevel@tonic-gate extern int getopt_ext(int argc, char * const argv[], const char *optstring);
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #ifdef __cplusplus
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate #endif
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate #endif /* _GETOPTEXT_H */
116