1 /* -*- indent-tabs-mode: nil -*-
2  *
3  * ya_getopt  - Yet another getopt
4  * https://github.com/kubo/ya_getopt
5  *
6  * Copyright 2015 Kubo Takehiro <kubo@jiubao.org>
7  *
8  * Redistribution and use in source and binary forms, with or without modification, are
9  * permitted provided that the following conditions are met:
10  *
11  *    1. Redistributions of source code must retain the above copyright notice, this list of
12  *       conditions and the following disclaimer.
13  *
14  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
15  *       of conditions and the following disclaimer in the documentation and/or other materials
16  *       provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS OR IMPLIED
19  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * The views and conclusions contained in the software and documentation are those of the
29  * authors and should not be interpreted as representing official policies, either expressed
30  * or implied, of the authors.
31  *
32  */
33 #ifndef YA_GETOPT_H
34 #define YA_GETOPT_H 1
35 
36 #define ya_no_argument        0
37 #define ya_required_argument  1
38 #define ya_optional_argument  2
39 
40 struct option {
41     const char *name;
42     int has_arg;
43     int *flag;
44     int val;
45 };
46 
47 int ya_getopt(int argc, char * const argv[], const char *optstring);
48 int ya_getopt_long(int argc, char * const argv[], const char *optstring,
49                    const struct option *longopts, int *longindex);
50 int ya_getopt_long_only(int argc, char * const argv[], const char *optstring,
51                         const struct option *longopts, int *longindex);
52 
53 extern char *ya_optarg;
54 extern int ya_optind, ya_opterr, ya_optopt;
55 
56 #ifndef YA_GETOPT_NO_COMPAT_MACRO
57 #define getopt ya_getopt
58 #define getopt_long ya_getopt_long
59 #define getopt_long_only ya_getopt_long_only
60 #define optarg ya_optarg
61 #define optind ya_optind
62 #define opterr ya_opterr
63 #define optopt ya_optopt
64 #define no_argument ya_no_argument
65 #define required_argument ya_required_argument
66 #define optional_argument ya_optional_argument
67 #endif
68 
69 #endif
70