Motr  M0
getopts.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_LIB_USER_SPACE_GETOPTS_H__
26 #define __MOTR_LIB_USER_SPACE_GETOPTS_H__
27 
28 #include "lib/types.h"
29 
105 };
106 
123  char go_opt;
125  const char *go_desc;
129  void (*got_void)(void);
131  void (*got_number)(int64_t num);
135  void (*got_string)(const char *string);
136  struct {
138  const char *f_string;
141  void *f_out;
142  } got_fmt;
144  bool *got_flag;
145  } go_u;
146 };
147 
163 int m0_getopts(const char *progname, int argc, char *const *argv,
164  const struct m0_getopts_opt *opts, unsigned nr);
165 
169 #define M0_GETOPTS(progname, argc, argv, ...) \
170  m0_getopts((progname), (argc), (argv), \
171  (const struct m0_getopts_opt []){ __VA_ARGS__ }, \
172  ARRAY_SIZE(((const struct m0_getopts_opt []){ __VA_ARGS__ })))
173 
177 #define M0_VOIDARG(ch, desc, func) { \
178  .go_type = GOT_VOID, \
179  .go_opt = (ch), \
180  .go_desc = (desc), \
181  .go_u = { .got_void = (func) } \
182 }
183 
187 #define M0_NUMBERARG(ch, desc, func) { \
188  .go_type = GOT_NUMBER, \
189  .go_opt = (ch), \
190  .go_desc = (desc), \
191  .go_u = { .got_number = (func) } \
192 }
193 
197 #define M0_SCALEDARG(ch, desc, func) { \
198  .go_type = GOT_SCALED, \
199  .go_opt = (ch), \
200  .go_desc = (desc), \
201  .go_u = { .got_scaled = (func) } \
202 }
203 
207 #define M0_STRINGARG(ch, desc, func) { \
208  .go_type = GOT_STRING, \
209  .go_opt = (ch), \
210  .go_desc = (desc), \
211  .go_u = { .got_string = (func) } \
212 }
213 
218 #define M0_FORMATARG(ch, desc, fmt, ptr) { \
219  .go_type = GOT_FORMAT, \
220  .go_opt = (ch), \
221  .go_desc = (desc), \
222  .go_u = { \
223  .got_fmt = { \
224  .f_string = (fmt), .f_out = (ptr) \
225  } \
226  } \
227 }
228 
232 #define M0_FLAGARG(ch, desc, ptr) { \
233  .go_type = GOT_FLAG, \
234  .go_opt = (ch), \
235  .go_desc = (desc), \
236  .go_u = { .got_flag = (ptr) } \
237 }
238 
242 #define M0_HELPARG(ch) { \
243  .go_type = GOT_HELP, \
244  .go_opt = (ch), \
245  .go_desc = "display this help and exit",\
246  .go_u = { .got_void = NULL } \
247 }
248 
250 #endif /* __MOTR_LIB_USER_SPACE_GETOPTS_H__ */
251 
252 /*
253  * Local variables:
254  * c-indentation-style: "K&R"
255  * c-basic-offset: 8
256  * tab-width: 8
257  * fill-column: 80
258  * scroll-step: 1
259  * End:
260  */
static size_t nr
Definition: dump.c:1505
uint64_t m0_bcount_t
Definition: types.h:77
void(* got_number)(int64_t num)
Definition: getopts.h:131
m0_getopts_opt_type
Definition: getopts.h:54
enum m0_getopts_opt_type go_type
Definition: getopts.h:121
void(* got_string)(const char *string)
Definition: getopts.h:135
struct m0_getopts_opt::m0_getopts_union::@271 got_fmt
union m0_getopts_opt::m0_getopts_union go_u
static const char * progname
Definition: traced.c:65
const char * go_desc
Definition: getopts.h:125
void(* got_scaled)(m0_bcount_t num)
Definition: getopts.h:133
int num
Definition: bulk_if.c:54
int m0_getopts(const char *progname, int argc, char *const *argv, const struct m0_getopts_opt *opts, unsigned nr)
Definition: ugetopts.c:98