1 /* -*- indent-tabs-mode: nil -*-
3 * ya_getopt - Yet another getopt
4 * https://github.com/kubo/ya_getopt
6 * Copyright 2015 Kubo Takehiro <kubo@jiubao.org>
8 * Redistribution and use in source and binary forms, with or without modification, are
9 * permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright notice, this list of
12 * conditions and the following disclaimer.
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.
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.
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.
36 #if defined(__cplusplus)
40 #define ya_no_argument 0
41 #define ya_required_argument 1
42 #define ya_optional_argument 2
51 int ya_getopt(int argc, char * const argv[], const char *optstring);
52 int ya_getopt_long(int argc, char * const argv[], const char *optstring,
53 const struct option *longopts, int *longindex);
54 int ya_getopt_long_only(int argc, char * const argv[], const char *optstring,
55 const struct option *longopts, int *longindex);
57 extern char *ya_optarg;
58 extern int ya_optind, ya_opterr, ya_optopt;
60 #ifndef YA_GETOPT_NO_COMPAT_MACRO
61 #define getopt ya_getopt
62 #define getopt_long ya_getopt_long
63 #define getopt_long_only ya_getopt_long_only
64 #define optarg ya_optarg
65 #define optind ya_optind
66 #define opterr ya_opterr
67 #define optopt ya_optopt
68 #define no_argument ya_no_argument
69 #define required_argument ya_required_argument
70 #define optional_argument ya_optional_argument
73 #if defined(__cplusplus)