1 /*-
2  * Copyright (c) 2000 The NetBSD Foundation, Inc.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to The NetBSD Foundation
6  * by Dieter Baron and Thomas Klausner.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /** @file
31  *  @brief Interfaces for getopt() and getopt_long() work-alike functions.
32  *
33  *  This code was taken from FreeBSD and slightly modified, mostly to rename
34  *  symbols with external linkage to avoid naming conflicts in systems where
35  *  there are real getopt()/getopt_long() implementations.  Changed to use
36  *  fixed-width types to allow code using these interfaces to be consistent
37  *  with the rest of the product.
38  */
39 #ifndef REDGETOPT_H
40 #define REDGETOPT_H
41 
42 
43 #define red_no_argument          0
44 #define red_required_argument    1
45 #define red_optional_argument    2
46 
47 
48 /** @brief Specifies a long option.
49  */
50 typedef struct
51 {
52     /* name of long option */
53     const char * name;
54 
55     /*
56      * one of red_no_argument, red_required_argument, and red_optional_argument:
57      * whether option takes an argument
58      */
59     int32_t has_arg;
60     /* if not NULL, set *flag to val when option found */
61     int32_t * flag;
62     /* if flag not NULL, value to set *flag to; else return value */
63     int32_t val;
64 } REDOPTION;
65 
66 
67 int32_t RedGetopt( int32_t nargc,
68                    char * const * nargv,
69                    const char * options );
70 int32_t RedGetoptLong( int32_t nargc,
71                        char * const * nargv,
72                        const char * options,
73                        const REDOPTION * long_options,
74                        int32_t * idx );
75 
76 
77 extern const char * red_optarg;
78 extern int32_t red_optind;
79 extern int32_t red_opterr;
80 extern int32_t red_optopt;
81 extern int32_t red_optreset;
82 
83 
84 #endif /* ifndef REDGETOPT_H */
85