Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
mxq
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
3
Code
Issues
20
Pull requests
3
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
3732792
helper
manpages
mysql
web
.gitignore
.vimrc
Doxyfile
LICENSE
Makefile
README.md
keywordset.c
keywordset.h
mx_flock.c
mx_flock.h
mx_getopt.c
mx_getopt.h
mx_log.c
mx_log.h
mx_mysql.c
mx_mysql.h
mx_proc.c
mx_proc.h
mx_util.c
mx_util.h
mxq.h
mxq_daemon.c
mxq_daemon.h
mxq_group.c
mxq_group.h
mxq_job.c
mxq_job.h
mxq_log.c
mxq_reaper.c
mxqadmin.c
mxqd.c
mxqd.h
mxqd_control.c
mxqd_control.h
mxqdctl-hostconfig.sh
mxqdump.c
mxqkill.c
mxqps.c
mxqset.c
mxqsub.c
os-release
parser.y
ppidcache.c
ppidcache.h
test_keywordset.c
test_mx_log.c
test_mx_mysql.c
test_mx_util.c
test_mxqd_control.c
test_parser.c
xmalloc.h
Breadcrumbs
mxq
/
mx_getopt.h
Blame
Blame
Latest commit
History
History
183 lines (148 loc) · 5.49 KB
Breadcrumbs
mxq
/
mx_getopt.h
Top
File metadata and controls
Code
Blame
183 lines (148 loc) · 5.49 KB
Raw
/* ** beegetopt - parse options ** ** Copyright (C) 2009-2012 ** Marius Tolzmann <tolzmann@molgen.mpg.de> ** and other bee developers ** ** This file is part of bee. ** ** bee is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, see <http://www.gnu.org/licenses/>. */ #ifndef MX_GETOPT_H #define MX_GETOPT_H 1 #define MX_TYPE_STRING 1 #define MX_TYPE_INTEGER 2 #define MX_TYPE_FLOAT 3 #define MX_TYPE_FLAG 4 #define MX_TYPE_NO 5 #define MX_TYPE_ENABLE 6 #define MX_TYPE_WITH 7 #define MX_TYPE_TOGGLE 8 #define MX_TYPE_COUNT 9 #define MX_FLAG_SKIPUNKNOWN (1<<0) #define MX_FLAG_STOPONNOOPT (1<<1) #define MX_FLAG_STOPONUNKNOWN (1<<2) #define MX_FLAG_KEEPOPTIONEND (1<<3) #define MX_OPT_LONG(name) .long_opt = (name) #define MX_OPT_SHORT(short) .short_opt = (short) #define MX_OPT_VALUE(v) .value = (v) #define MX_OPT_FLAG(f) .flag = (f) #define MX_OPT_TYPE(t) .type = (t) #define MX_OPT_OPTIONAL(args) .optional_args = (args) #define MX_OPT_REQUIRED(args) .required_args = (args) #define _MX_OPT_LEN(l) ._long_len = (l) #define MX_GETOPT_END -1 #define MX_GETOPT_ERROR -2 #define MX_GETOPT_NOVALUE -3 #define MX_GETOPT_NOOPT -4 #define MX_GETOPT_AMBIGUOUS -5 #define MX_GETOPT_OPTUNKNOWN -6 #define MX_GETOPT_NOARG -7 #define MX_GETOPT_NOARGS -8 #define MX_OPTION_DEFAULTS \ MX_OPT_LONG(NULL), \ MX_OPT_SHORT(0), \ MX_OPT_VALUE(MX_GETOPT_NOVALUE), \ MX_OPT_FLAG(NULL), \ MX_OPT_TYPE(MX_TYPE_FLAG), \ MX_OPT_OPTIONAL(0), \ MX_OPT_REQUIRED(0), \ _MX_OPT_LEN(0) #define MX_INIT_OPTION_DEFAULTS(opt) \ (opt)->long_opt = NULL; \ (opt)->short_opt = 0; \ (opt)->value = MX_GETOPT_NOVALUE; \ (opt)->flag = NULL; \ (opt)->type = MX_TYPE_FLAG; \ (opt)->optional_args = 0; \ (opt)->required_args = 0; \ (opt)->_long_len = 0 #define MX_INIT_OPTION_END(opt) MX_INIT_OPTION_DEFAULTS((opt)) #define MX_OPTION_END { MX_OPT_LONG(NULL), MX_OPT_SHORT(0) } #define MX_OPTION(...) { MX_OPTION_DEFAULTS, ## __VA_ARGS__ } #define MX_OPTION_NO_ARG(name, short, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ ## __VA_ARGS__) #define MX_OPTION_REQUIRED_ARG(name, short, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ MX_OPT_TYPE(MX_TYPE_STRING), \ MX_OPT_REQUIRED(1), \ ## __VA_ARGS__ ) #define MX_OPTION_REQUIRED_ARGS(name, short, n, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ MX_OPT_TYPE(MX_TYPE_STRING), \ MX_OPT_REQUIRED(n), \ ## __VA_ARGS__ ) #define MX_OPTION_OPTIONAL_ARG(name, short, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ MX_OPT_TYPE(MX_TYPE_STRING), \ MX_OPT_OPTIONAL(1), \ ## __VA_ARGS__ ) #define MX_OPTION_OPTIONAL_ARGS(name, short, n, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ MX_OPT_TYPE(MX_TYPE_STRING), \ MX_OPT_OPTIONAL(n), \ ## __VA_ARGS__ ) #define MX_OPTION_ARGS(name, short, opt, req, ...) \ MX_OPTION(MX_OPT_LONG(name), \ MX_OPT_SHORT(short), \ MX_OPT_VALUE(short), \ MX_OPT_TYPE(MX_TYPE_STRING), \ MX_OPT_OPTIONAL(opt), \ MX_OPT_REQUIRED(req), \ ## __VA_ARGS__ ) #define MX_GETOPT_FINISH(optctl, argc, argv) \ do { \ (argv) = &(optctl).argv[(optctl).optind]; \ (argc) = (optctl).argc - (optctl).optind; \ } while(0) struct mx_option { char *long_opt; char short_opt; int value; int *flag; int type; int optional_args; int required_args; int _long_len; }; struct mx_getopt_ctl { int optind; char *program; char *optarg; int optargc; char **optargv; int argc; char **argv; struct mx_option *options; int _argc; int _optcnt; char *_unhandled_shortopts; int flags; }; void mx_getopt_pop_current_argument(struct mx_getopt_ctl *optctl); int mx_getopt_init(struct mx_getopt_ctl *ctl, int argc, char **argv, struct mx_option *optv); int mx_getopt(struct mx_getopt_ctl *optctl, int *optindex); #endif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
You can’t perform that action at this time.