290 #define csnip_clopts_Addvar(opts, \ 
  296     csnip_clopts__Addvar((opts), (short_name), (long_name), \ 
  297                     (description), (ptr_target), (err), \ 
  298             csnip__parser, csnip__O, csnip__errval) 
  301 #define csnip_clopts__Addvar(opts_, \ 
  312         csnip_clopts_parser parser_ = csnip_clopts__Getparser(ptr_target_); \ 
  313         csnip_clopts_optinfo O = { \ 
  314             .short_name = short_name_, \ 
  315             .long_name = long_name_, \ 
  316             .description = description_, \ 
  319             .usr = (void*)ptr_target_, \ 
  321         int errval = csnip_clopts_add(opts_, 1, &O); \ 
  323             csnip_err_Raise(errval, err); \ 
  356 #define csnip_clopts_Addflag(opts, \ 
  362     csnip_clopts__Addflag((opts), (short_name), (long_name), \ 
  363                     (description), (ptr_target), (err), \ 
  364             csnip__O, csnip__errval) 
  367 #define csnip_clopts__Addflag(opts_, \ 
  376         csnip_clopts_optinfo O = { \ 
  377             .short_name = short_name_, \ 
  378             .long_name = long_name_, \ 
  379             .description = description_, \ 
  380             .takes_val = false, \ 
  381             .parser = csnip_clopts_flagparser_bool, \ 
  382             .usr = (void*)ptr_target_ \ 
  384         int errval = csnip_clopts_add(opts_, 1, &O); \ 
  386             csnip_err_Raise(errval, err); \ 
  395 #define csnip_clopts__Getparser(ptr_target_) \ 
  396           _Generic(*ptr_target_, \ 
  397             char: csnip_clopts_parser_uchar, \ 
  398             unsigned char: csnip_clopts_parser_uchar, \ 
  399             int: csnip_clopts_parser_uint, \ 
  400             unsigned int: csnip_clopts_parser_uint, \ 
  401             long: csnip_clopts_parser_ulong, \ 
  402             unsigned long: csnip_clopts_parser_ulong, \ 
  403             long long: csnip_clopts_parser_ullong, \ 
  404             unsigned long long: csnip_clopts_parser_ullong, \ 
  405             float: csnip_clopts_parser_float, \ 
  406             double: csnip_clopts_parser_double, \ 
  407             long double: csnip_clopts_parser_ldouble, \ 
  408             char*: csnip_clopts_parser_pchar, \ 
  409             char const*: csnip_clopts_parser_pchar) 
  416 #define csnip_clopts__tspec(type, suffix) \ 
  417     template<> csnip_clopts_parser csnip_clopts__getparser<type>(type*) \ 
  419         return csnip_clopts_parser_ ## suffix; \ 
  421 csnip_clopts__tspec(
char, uchar)
 
  422 csnip_clopts__tspec(
unsigned char, uchar)
 
  423 csnip_clopts__tspec(
int, uint)
 
  424 csnip_clopts__tspec(
unsigned int, uint)
 
  425 csnip_clopts__tspec(
long, ulong)
 
  426 csnip_clopts__tspec(
unsigned long, ulong)
 
  427 csnip_clopts__tspec(
long long, ullong)
 
  428 csnip_clopts__tspec(
unsigned long long, ullong)
 
  429 csnip_clopts__tspec(
float, 
float)
 
  430 csnip_clopts__tspec(
double, 
double)
 
  431 csnip_clopts__tspec(
long double, ldouble)
 
  432 csnip_clopts__tspec(
char*, pchar)
 
  433 csnip_clopts__tspec(
char const*, pchar)
 
  434 #undef csnip_clopts__tspec 
  435 #define csnip_clopts__Getparser(ptr_target_) csnip_clopts__getparser(ptr_target_) 
  444 #if defined(CSNIP_SHORT_NAMES) && !defined(CSNIP_CLOPTS_HAVE_SHORT_NAMES) 
  445 #define clopts          csnip_clopts 
  446 #define clopts_optinfo      csnip_clopts_optinfo 
  447 #define clopts_parser       csnip_clopts_parser 
  448 #define clopts_init     csnip_clopts_init 
  449 #define clopts_clear        csnip_clopts_clear 
  450 #define clopts_add_defaults csnip_clopts_add_defaults 
  451 #define clopts_add      csnip_clopts_add 
  452 #define clopts_process      csnip_clopts_process 
  453 #define clopts_clear        csnip_clopts_clear 
  454 #define clopts_parser_uchar csnip_clopts_parser_uchar 
  455 #define clopts_parser_uint  csnip_clopts_parser_uint 
  456 #define clopts_parser_ulong csnip_clopts_parser_ulong 
  457 #define clopts_parser_ullong    csnip_clopts_parser_ullong 
  458 #define clopts_parser_float csnip_clopts_parser_float 
  459 #define clopts_parser_double    csnip_clopts_parser_double 
  460 #define clopts_parser_ldouble   csnip_clopts_parser_ldouble 
  461 #define clopts_parser_pchar csnip_clopts_parser_pchar 
  462 #define clopts_Addvar       csnip_clopts_Addvar 
  463 #define clopts_Addflag      csnip_clopts_Addflag 
  464 #define CSNIP_CLOPTS_HAVE_SHORT_NAMES 
int csnip_clopts_parser_ullong(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as long long int.
 
int csnip_clopts_parser_uchar(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as integer of type char.
Definition: clopts.c:229
 
int csnip_clopts_parser_pchar(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Assign a char* to point to the argument.
Definition: clopts.c:331
 
int csnip_clopts_flagparser_bool(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parser for flags, bool target.
Definition: clopts.c:342
 
int csnip_clopts_parser_ulong(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as a long int.
 
int csnip_clopts_parser_double(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as double.
 
int csnip_clopts_parser_float(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as float.
 
int csnip_clopts_parser_ldouble(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as long double.
 
int csnip_clopts_parser_uint(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Parse argument as an int.
 
int(* csnip_clopts_parser)(const csnip_clopts *opts, const csnip_clopts_optinfo *optinfo, const char *argval)
Argument parser function pointer type.
Definition: clopts.h:86
 
int csnip_clopts_add(csnip_clopts *opts, int n_optinfo, const csnip_clopts_optinfo *optinfo)
Add processable options.
Definition: clopts.c:49
 
void csnip_clopts_clear(csnip_clopts *opts)
Clear clopts assignments, freeing memory.
Definition: clopts.c:224
 
int csnip_clopts_add_defaults(csnip_clopts *opts)
Add handlers for default options.
Definition: clopts.c:37
 
int csnip_clopts_process(csnip_clopts *opts, int argc, char **argv, int *ret_pos_args, bool do_clear)
Process command line arguments.
Definition: clopts.c:212
 
Descriptor for a single command line option.
Definition: clopts.h:91
 
csnip_clopts_parser parser
The parser function callback.
Definition: clopts.h:98
 
char short_name
Short (single character) form.
Definition: clopts.h:92
 
void * usr
User data pointer for the callback.
Definition: clopts.h:100
 
const char * long_name
Long option form.
Definition: clopts.h:93
 
bool takes_val
True if option takes a value, false if it's a flag.
Definition: clopts.h:96
 
const char * description
Option description.
Definition: clopts.h:94
 
Set of descriptors for all command line options.
Definition: clopts.h:105
 
const char * description
General program description.
Definition: clopts.h:112
 
csnip_clopts_optinfo * optinfo
The options array.
Definition: clopts.h:117
 
int n_optinfo_cap
Capacity of the option array.
Definition: clopts.h:116
 
int n_optinfo
Number of command line options.
Definition: clopts.h:115