xref: /freebsd/contrib/file/src/mygetopt.h (revision 48c779cdecb5f803e5fe5d761987e976ca9609db)
1*b6cee71dSXin LI /*	$NetBSD: getopt.h,v 1.8 2007/11/06 19:21:18 christos Exp $	*/
2*b6cee71dSXin LI 
3*b6cee71dSXin LI /*-
4*b6cee71dSXin LI  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5*b6cee71dSXin LI  * All rights reserved.
6*b6cee71dSXin LI  *
7*b6cee71dSXin LI  * This code is derived from software contributed to The NetBSD Foundation
8*b6cee71dSXin LI  * by Dieter Baron and Thomas Klausner.
9*b6cee71dSXin LI  *
10*b6cee71dSXin LI  * Redistribution and use in source and binary forms, with or without
11*b6cee71dSXin LI  * modification, are permitted provided that the following conditions
12*b6cee71dSXin LI  * are met:
13*b6cee71dSXin LI  * 1. Redistributions of source code must retain the above copyright
14*b6cee71dSXin LI  *    notice, this list of conditions and the following disclaimer.
15*b6cee71dSXin LI  * 2. Redistributions in binary form must reproduce the above copyright
16*b6cee71dSXin LI  *    notice, this list of conditions and the following disclaimer in the
17*b6cee71dSXin LI  *    documentation and/or other materials provided with the distribution.
18*b6cee71dSXin LI  * 3. All advertising materials mentioning features or use of this software
19*b6cee71dSXin LI  *    must display the following acknowledgement:
20*b6cee71dSXin LI  *        This product includes software developed by the NetBSD
21*b6cee71dSXin LI  *        Foundation, Inc. and its contributors.
22*b6cee71dSXin LI  * 4. Neither the name of The NetBSD Foundation nor the names of its
23*b6cee71dSXin LI  *    contributors may be used to endorse or promote products derived
24*b6cee71dSXin LI  *    from this software without specific prior written permission.
25*b6cee71dSXin LI  *
26*b6cee71dSXin LI  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27*b6cee71dSXin LI  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28*b6cee71dSXin LI  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29*b6cee71dSXin LI  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30*b6cee71dSXin LI  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31*b6cee71dSXin LI  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32*b6cee71dSXin LI  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33*b6cee71dSXin LI  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34*b6cee71dSXin LI  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35*b6cee71dSXin LI  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36*b6cee71dSXin LI  * POSSIBILITY OF SUCH DAMAGE.
37*b6cee71dSXin LI  */
38*b6cee71dSXin LI 
39*b6cee71dSXin LI #ifndef _GETOPT_H_
40*b6cee71dSXin LI #define _GETOPT_H_
41*b6cee71dSXin LI 
42*b6cee71dSXin LI #include <unistd.h>
43*b6cee71dSXin LI 
44*b6cee71dSXin LI /*
45*b6cee71dSXin LI  * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
46*b6cee71dSXin LI  */
47*b6cee71dSXin LI #define no_argument        0
48*b6cee71dSXin LI #define required_argument  1
49*b6cee71dSXin LI #define optional_argument  2
50*b6cee71dSXin LI 
51*b6cee71dSXin LI struct option {
52*b6cee71dSXin LI 	/* name of long option */
53*b6cee71dSXin LI 	const char *name;
54*b6cee71dSXin LI 	/*
55*b6cee71dSXin LI 	 * one of no_argument, required_argument, and optional_argument:
56*b6cee71dSXin LI 	 * whether option takes an argument
57*b6cee71dSXin LI 	 */
58*b6cee71dSXin LI 	int has_arg;
59*b6cee71dSXin LI 	/* if not NULL, set *flag to val when option found */
60*b6cee71dSXin LI 	int *flag;
61*b6cee71dSXin LI 	/* if flag not NULL, value to set *flag to; else return value */
62*b6cee71dSXin LI 	int val;
63*b6cee71dSXin LI };
64*b6cee71dSXin LI 
65*b6cee71dSXin LI int getopt_long(int, char * const *, const char *,
66*b6cee71dSXin LI     const struct option *, int *);
67*b6cee71dSXin LI 
68*b6cee71dSXin LI #endif /* !_GETOPT_H_ */
69