xref: /illumos-gate/usr/src/lib/libdwarf/common/dwgetopt.h (revision 09fbbb7d1b5a956a9b81304070dcff318a4a158e)
1 /* $NetBSD: getopt.c,v 1.1 2009/03/22 22:33:13 joerg Exp $*/
2 /*  Modified by David Anderson to work with GNU/Linux and freebsd.
3     Added {} for clarity.
4     Switched to standard dwarfdump formatting.
5     Treatment of : modified so that :: gets dwoptarg NULL
6     if space follows the letter
7     (the dwoptarg is set to null).
8 */
9 /*
10 * Copyright (c) 1987, 1993, 1994
11 * The Regents of the University of California.  All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 *    may be used to endorse or promote products derived from this software
23 *    without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif /* __cplusplus */
41 extern int  dwopterr;
42 extern int  dwoptind;
43 extern int  dwoptopt;
44 extern int  dwoptreset;
45 extern char *dwoptarg;
46 
47 int dwgetopt(int nargc, char * const nargv[], const char *ostr);
48 
49 /*  As of October 2017 it seems adviseable to allow
50     long option names.  So based on a reading of
51     'man 3 getopt' we reimplement a portion of GNU getopt_long().
52     It's a wonderfully sensible design and all the credit
53     should go to the original designers.
54     We are not implementing all the features of GNU/Linux
55     getopt_long(), just the features we wish to use.
56     Specifically, we require val be 0 and flag
57     be NULL and ignore those fields.
58     We do not implement GNU digit_optind at all.
59     Within these restrictions the interface behaves the same
60     as GNU getopt_long() (or so it appears from the
61     getopt documentation:
62     release 4.04 of the Linux man-pages project,
63     GETOPT(3),
64     http://www.kernel.org/doc/man-pages/).
65     */
66 
67 struct dwoption {
68     const char *name;
69     int has_arg;
70     int *flag;
71     int val;
72 };
73 #define dwno_argument 0
74 #define dwrequired_argument 1
75 #define dwoptional_argument 2
76 
77 int dwgetopt_long(int nargc, char *const nargv[],
78     const char *ostr,
79     const struct dwoption* longopts,
80     int *longindex);
81 
82 
83 #ifdef __cplusplus
84 }
85 #endif /* __cplusplus */
86