19 rc = sscanf(size_str,
" %lld %c ", (
long long*) & size, &range);
60 pos += printf(
"=STRING");
64 pos += printf(
"=%.14f ", *(
double*) o->
variable);
68 pos += printf(
"=%.6f ", (
double) *(
float*) o->
variable);
72 pos += printf(
"=%d ", *(
int*) o->
variable);
78 pos += printf(
"=%s", *(
char**) o->
variable);
80 pos += printf(
"=STRING");
85 pos += printf(
"=%c", *(
char*) o->
variable);
89 pos += printf(
"=%lld", *(
long long*) o->
variable);
95 pos += printf(
" (%d)", (*(
int*)o->
variable));
109 printf(
"%s\n", o->
help);
113 printf(
"\n%s\n", name);
123 pos += printf(
"--%s", o->
longVar);
128 for(
int i = 0 ; i < (30 - pos); i++){
131 printf(
"%s", o->
help);
152 pos += printf(
"=%.14f ", *(
double*) o->
variable);
156 pos += printf(
"=%.6f ", (
double) *(
float*) o->
variable);
160 pos += printf(
"=%d ", *(
int*) o->
variable);
164 pos += printf(
"=HIDDEN");
169 pos += printf(
"=%s", *(
char**) o->
variable);
176 pos += printf(
"=%c", *(
char*) o->
variable);
180 pos += printf(
"=%lld", *(
long long*) o->
variable);
203 pos += printf(
"%s", o->
longVar);
207 pos += printf(
"%s", o->
longVar);
225 int requiredArgsSeen = 0;
226 int requiredArgsNeeded = 0;
232 if(args ==
NULL)
continue;
233 for(
option_help *
o = args;
o->shortVar != 0 ||
o->longVar != 0 ;
o++ ){
235 requiredArgsNeeded++;
240 for(i=1; i < argc; i++){
241 char * txt = argv[i];
243 char * arg = strstr(txt,
"=");
244 int replaced_equal = 0;
253 if(args ==
NULL)
continue;
256 if(
o->shortVar == 0 &&
o->longVar == 0 ){
260 if ( (txt[0] ==
'-' &&
o->shortVar == txt[1]) || (strlen(txt) > 2 && txt[0] ==
'-' && txt[1] ==
'-' &&
o->longVar !=
NULL && strcmp(txt + 2,
o->longVar) == 0)){
266 assert(
o->type ==
'd');
267 (*(
int*)
o->variable)++;
274 if(
o->shortVar == txt[1] && txt[2] != 0){
284 const char str[] = {
o->shortVar, 0};
285 printf(
"Error, argument missing for option %s\n", (
o->longVar !=
NULL) ?
o->longVar : str);
292 void(*fp)() =
o->variable;
297 *(
double*)
o->variable = atof(arg);
301 *(
float*)
o->variable = atof(arg);
306 if (val > INT_MAX || val < INT_MIN){
307 printf(
"WARNING: parsing the number %s to integer, this produced an overflow!\n", arg);
309 *(
int*)
o->variable = val;
314 (*(
char **)
o->variable) = strdup(arg);
318 (*(
char *)
o->variable) = arg[0];
320 printf(
"Error, ignoring remainder of string for option %c (%s).\n",
o->shortVar,
o->longVar);
329 printf(
"ERROR: Unknown option type %c\n",
o->type);
346 if(strcmp(txt,
"-h") == 0 || strcmp(txt,
"--help") == 0){
349 printf(
"Error invalid argument: %s\n", txt);
355 if( requiredArgsSeen != requiredArgsNeeded ){
356 printf(
"Error: Missing some required arguments\n\n");
361 printf(
"Invalid options\n");
366 printf(
"Synopsis %s\n", argv[0]);
369 if(args ==
NULL)
continue;
372 printf(
"\n\nModule %s\n", prefix);
void option_print_help(option_help *args)
int option_parse(int argc, char **argv, options_all *opt_all)
static void print_current_option_section(option_help *args, option_value_type type)
void option_print_current(option_help *args)
static int print_option_value(option_help *o)
static int print_value(option_help *o)
int64_t string_to_bytes(char *size_str)
static void print_help_section(option_help *args, option_value_type type, char *name)
static struct dummy_options o