Debian Codegraph @

ext/argparse/argparse.h

raw symbols SCIP
1 /**
2 * Copyright (C) 2012-2015 Yecheng Fu <cofyc.jackson at gmail dot com>
3 * All rights reserved.
4 *
5 * Use of this source code is governed by a MIT-style license that can be found
6 * in the LICENSE file.
7 */
8 #ifndef ARGPARSE_H
9 #define ARGPARSE_Hcxx . . $ `ext/argparse/argparse.h:9:9`!
10
11 /* For c++ compatibility */
12 #ifdef __cpluspluscxx . . $ `<built-in>:454:9`!
13 extern "C" {
14 #endif
15
16 #include <stdint.h>
17
18 struct argparse;
19 struct argparse_option;
20
21 typedef int argparse_callback (struct argparse *self,
22 const struct argparse_option *option);
23
24 enum argparse_flag {
25 ARGPARSE_STOP_AT_NON_OPTION = 1 << 0,
26 ARGPARSE_IGNORE_UNKNOWN_ARGS = 1 << 1,
27 };
28
29 enum argparse_option_type {
30 /* special */
31 ARGPARSE_OPT_END,
32 ARGPARSE_OPT_GROUP,
33 /* options with no arguments */
34 ARGPARSE_OPT_BOOLEAN,
35 ARGPARSE_OPT_BIT,
36 /* options with arguments (optional or required) */
37 ARGPARSE_OPT_INTEGER,
38 #ifdef ARGPARSE_HAVE_FLOAT
39 ARGPARSE_OPT_FLOAT,
40 #endif
41 ARGPARSE_OPT_STRING,
42 };
43
44 enum argparse_option_flags {
45 OPT_NONEG = 1, /* disable negation */
46 };
47
48 /**
49 * argparse option
50 *
51 * `type`:
52 * holds the type of the option, you must have an ARGPARSE_OPT_END last in your
53 * array.
54 *
55 * `short_name`:
56 * the character to use as a short option name, '\0' if none.
57 *
58 * `long_name`:
59 * the long option name, without the leading dash, NULL if none.
60 *
61 * `value`:
62 * stores pointer to the value to be filled.
63 *
64 * `help`:
65 * the short help message associated to what the option does.
66 * Must never be NULL (except for ARGPARSE_OPT_END).
67 *
68 * `callback`:
69 * function is called when corresponding argument is parsed.
70 *
71 * `data`:
72 * associated data. Callbacks can use it like they want.
73 *
74 * `flags`:
75 * option flags.
76 */
77 struct argparse_option {
78 enum argparse_option_type type;
79 const char short_name;
80 const char *long_name;
81 void *value;
82 const char *help;
83 argparse_callback *callback;
84 intptr_tcxx . . $ intptr_t# data;
85 int flags;
86 };
87
88 /**
89 * argpparse
90 */
91 struct argparse {
92 // user supplied
93 const struct argparse_option *options;
94 const char *const *usages;
95 int flags;
96 const char *description; // a description after usage
97 const char *epilog; // a description at the end
98 // internal context
99 int argc;
100 char **argv;
101 char **out;
102 int cpidx;
103 const char *optvalue; // current option value
104 };
105
106 // built-in callbacks
107 int argparse_help_cb(struct argparse *self,
108 const struct argparse_option *option);
109
110 // built-in option macros
111 #define OPT_ENDcxx . . $ `ext/argparse/argparse.h:111:9`!() { ARGPARSE_OPT_END, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0 }
112 #define OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!(...) { ARGPARSE_OPT_BOOLEAN, __VA_ARGS__ }
113 #define OPT_BITcxx . . $ `ext/argparse/argparse.h:113:9`!(...) { ARGPARSE_OPT_BIT, __VA_ARGS__ }
114 #define OPT_INTEGERcxx . . $ `ext/argparse/argparse.h:114:9`!(...) { ARGPARSE_OPT_INTEGER, __VA_ARGS__ }
115 #ifdef ARGPARSE_HAVE_FLOAT
116 #define OPT_FLOAT(...) { ARGPARSE_OPT_FLOAT, __VA_ARGS__ }
117 #endif
118 #define OPT_STRINGcxx . . $ `ext/argparse/argparse.h:118:9`!(...) { ARGPARSE_OPT_STRING, __VA_ARGS__ }
119 #define OPT_GROUPcxx . . $ `ext/argparse/argparse.h:119:9`!(h) { ARGPARSE_OPT_GROUP, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, h, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0, 0 }
120 #define OPT_HELPcxx . . $ `ext/argparse/argparse.h:120:9`!() OPT_BOOLEANcxx . . $ `ext/argparse/argparse.h:112:9`!('h', "help", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, \
121 "show this help message and exit", \
122 argparse_help_cb, 0, OPT_NONEG)
123
124 int argparse_init(struct argparse *self, struct argparse_option *options,
125 const char *const *usages, int flags);
126 void argparse_describe(struct argparse *self, const char *description,
127 const char *epilog);
128 int argparse_parse(struct argparse *self, int argc, char **argv);
129 void argparse_usage(struct argparse *self);
130
131 #ifdef __cpluspluscxx . . $ `<built-in>:455:9`!
132 }
133 #endif
134
135 #endif