xref: /freebsd/contrib/pkgconf/cli/getopt_long.h (revision a3cefe7f2b4df0f70ff92d4570ce18e517af43ec)
1*a3cefe7fSPierre Pronchery /*	$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $	*/
2*a3cefe7fSPierre Pronchery /*	$FreeBSD$ */
3*a3cefe7fSPierre Pronchery 
4*a3cefe7fSPierre Pronchery /*-
5*a3cefe7fSPierre Pronchery  * Copyright (c) 2000 The NetBSD Foundation, Inc.
6*a3cefe7fSPierre Pronchery  * All rights reserved.
7*a3cefe7fSPierre Pronchery  *
8*a3cefe7fSPierre Pronchery  * This code is derived from software contributed to The NetBSD Foundation
9*a3cefe7fSPierre Pronchery  * by Dieter Baron and Thomas Klausner.
10*a3cefe7fSPierre Pronchery  *
11*a3cefe7fSPierre Pronchery  * Redistribution and use in source and binary forms, with or without
12*a3cefe7fSPierre Pronchery  * modification, are permitted provided that the following conditions
13*a3cefe7fSPierre Pronchery  * are met:
14*a3cefe7fSPierre Pronchery  * 1. Redistributions of source code must retain the above copyright
15*a3cefe7fSPierre Pronchery  *    notice, this list of conditions and the following disclaimer.
16*a3cefe7fSPierre Pronchery  * 2. Redistributions in binary form must reproduce the above copyright
17*a3cefe7fSPierre Pronchery  *    notice, this list of conditions and the following disclaimer in the
18*a3cefe7fSPierre Pronchery  *    documentation and/or other materials provided with the distribution.
19*a3cefe7fSPierre Pronchery  *
20*a3cefe7fSPierre Pronchery  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21*a3cefe7fSPierre Pronchery  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22*a3cefe7fSPierre Pronchery  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23*a3cefe7fSPierre Pronchery  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24*a3cefe7fSPierre Pronchery  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*a3cefe7fSPierre Pronchery  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*a3cefe7fSPierre Pronchery  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*a3cefe7fSPierre Pronchery  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*a3cefe7fSPierre Pronchery  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*a3cefe7fSPierre Pronchery  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*a3cefe7fSPierre Pronchery  * POSSIBILITY OF SUCH DAMAGE.
31*a3cefe7fSPierre Pronchery  */
32*a3cefe7fSPierre Pronchery 
33*a3cefe7fSPierre Pronchery #ifndef _GETOPT_LONG_H_
34*a3cefe7fSPierre Pronchery #define _GETOPT_LONG_H_
35*a3cefe7fSPierre Pronchery 
36*a3cefe7fSPierre Pronchery #include <stdint.h>
37*a3cefe7fSPierre Pronchery 
38*a3cefe7fSPierre Pronchery /*
39*a3cefe7fSPierre Pronchery  * GNU-like getopt_long()/getopt_long_only() with 4.4BSD optreset extension.
40*a3cefe7fSPierre Pronchery  * getopt() is declared here too for GNU programs.
41*a3cefe7fSPierre Pronchery  */
42*a3cefe7fSPierre Pronchery #define no_argument        0
43*a3cefe7fSPierre Pronchery #define required_argument  1
44*a3cefe7fSPierre Pronchery #define optional_argument  2
45*a3cefe7fSPierre Pronchery 
46*a3cefe7fSPierre Pronchery struct pkg_option {
47*a3cefe7fSPierre Pronchery 	/* name of long option */
48*a3cefe7fSPierre Pronchery 	const char *name;
49*a3cefe7fSPierre Pronchery 	/*
50*a3cefe7fSPierre Pronchery 	 * one of no_argument, required_argument, and optional_argument:
51*a3cefe7fSPierre Pronchery 	 * whether option takes an argument
52*a3cefe7fSPierre Pronchery 	 */
53*a3cefe7fSPierre Pronchery 	int has_arg;
54*a3cefe7fSPierre Pronchery 	/* if not NULL, set *flag to val when option found */
55*a3cefe7fSPierre Pronchery 	uint64_t *flag;
56*a3cefe7fSPierre Pronchery 	/* if flag not NULL, value to set *flag to; else return value */
57*a3cefe7fSPierre Pronchery 	uint64_t val;
58*a3cefe7fSPierre Pronchery };
59*a3cefe7fSPierre Pronchery 
60*a3cefe7fSPierre Pronchery int	pkg_getopt_long(int, char * const *, const char *,
61*a3cefe7fSPierre Pronchery 	const struct pkg_option *, int *);
62*a3cefe7fSPierre Pronchery int	pkg_getopt_long_only(int, char * const *, const char *,
63*a3cefe7fSPierre Pronchery 	const struct pkg_option *, int *);
64*a3cefe7fSPierre Pronchery int	pkg_getopt(int, char * const [], const char *);
65*a3cefe7fSPierre Pronchery 
66*a3cefe7fSPierre Pronchery extern char *pkg_optarg;			/* getopt(3) external variables */
67*a3cefe7fSPierre Pronchery extern int pkg_optind, pkg_opterr, pkg_optopt;
68*a3cefe7fSPierre Pronchery extern int pkg_optreset;			/* getopt(3) external variable */
69*a3cefe7fSPierre Pronchery 
70*a3cefe7fSPierre Pronchery #endif
71