getopt.h revision 126142
1230557Sjimharris/*	$NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $	*/
2230557Sjimharris/*	$FreeBSD: head/include/getopt.h 126142 2004-02-23 04:51:07Z ache $ */
3230557Sjimharris
4230557Sjimharris/*-
5230557Sjimharris * Copyright (c) 2000 The NetBSD Foundation, Inc.
6230557Sjimharris * All rights reserved.
7230557Sjimharris *
8230557Sjimharris * This code is derived from software contributed to The NetBSD Foundation
9230557Sjimharris * by Dieter Baron and Thomas Klausner.
10230557Sjimharris *
11230557Sjimharris * Redistribution and use in source and binary forms, with or without
12230557Sjimharris * modification, are permitted provided that the following conditions
13230557Sjimharris * are met:
14230557Sjimharris * 1. Redistributions of source code must retain the above copyright
15230557Sjimharris *    notice, this list of conditions and the following disclaimer.
16230557Sjimharris * 2. Redistributions in binary form must reproduce the above copyright
17230557Sjimharris *    notice, this list of conditions and the following disclaimer in the
18230557Sjimharris *    documentation and/or other materials provided with the distribution.
19230557Sjimharris * 3. All advertising materials mentioning features or use of this software
20230557Sjimharris *    must display the following acknowledgement:
21230557Sjimharris *        This product includes software developed by the NetBSD
22230557Sjimharris *        Foundation, Inc. and its contributors.
23230557Sjimharris * 4. Neither the name of The NetBSD Foundation nor the names of its
24230557Sjimharris *    contributors may be used to endorse or promote products derived
25230557Sjimharris *    from this software without specific prior written permission.
26230557Sjimharris *
27230557Sjimharris * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28230557Sjimharris * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29230557Sjimharris * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30230557Sjimharris * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31230557Sjimharris * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32230557Sjimharris * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33230557Sjimharris * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34230557Sjimharris * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35230557Sjimharris * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36230557Sjimharris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37230557Sjimharris * POSSIBILITY OF SUCH DAMAGE.
38230557Sjimharris */
39230557Sjimharris
40230557Sjimharris#ifndef _GETOPT_H_
41230557Sjimharris#define _GETOPT_H_
42230557Sjimharris
43230557Sjimharris#include <sys/cdefs.h>
44230557Sjimharris
45230557Sjimharris/*
46230557Sjimharris * GNU-like getopt_long() & getopt() for GNU programs.
47230557Sjimharris */
48230557Sjimharris#define no_argument        0
49230557Sjimharris#define required_argument  1
50230557Sjimharris#define optional_argument  2
51230557Sjimharris
52230557Sjimharrisstruct option {
53230557Sjimharris	/* name of long option */
54230557Sjimharris	const char *name;
55230557Sjimharris	/*
56230557Sjimharris	 * one of no_argument, required_argument, and optional_argument:
57230557Sjimharris	 * whether option takes an argument
58230557Sjimharris	 */
59230557Sjimharris	int has_arg;
60230557Sjimharris	/* if not NULL, set *flag to val when option found */
61230557Sjimharris	int *flag;
62230557Sjimharris	/* if flag not NULL, value to set *flag to; else return value */
63230557Sjimharris	int val;
64230557Sjimharris};
65230557Sjimharris
66230557Sjimharris__BEGIN_DECLS
67230557Sjimharrisint	getopt_long(int, char * const *, const char *,
68230557Sjimharris	const struct option *, int *);
69230557Sjimharris#ifndef _GETOPT_DECLARED
70230557Sjimharris#define	_GETOPT_DECLARED
71230557Sjimharrisint	 getopt(int, char * const [], const char *);
72230557Sjimharris
73230557Sjimharrisextern char *optarg;			/* getopt(3) external variables */
74230557Sjimharrisextern int optind, opterr, optopt;
75230557Sjimharris#endif
76230557Sjimharris#ifndef _OPTRESET_DECLARED
77230557Sjimharris#define	_OPTRESET_DECLARED
78230557Sjimharrisextern int optreset;			/* getopt(3) external variable */
79230557Sjimharris#endif
80230557Sjimharris__END_DECLS
81230557Sjimharris
82230557Sjimharris#endif /* !_GETOPT_H_ */
83230557Sjimharris