Handling optparse long option

pull/323/head
German Service Network 7 months ago committed by Erik Auerswald
parent 2f2ff0bd2c
commit 652d319803

@ -561,6 +561,16 @@ int main(int argc, char **argv)
float opt_value_float;
while ((c = optparse_long(&optparse_state, longopts, NULL)) != EOF) {
switch (c) {
case '0':
/*
* Use long-option example
* Define "struct optparse_long longopts": { "long-option-name", '0', OPTPARSE_NONE }
*
* if(strstr(optparse_state.optlongname, "long-option-name") != NULL) {
* long_option_flag = 1;
* }
*/
break;
case '4':
#ifdef IPV6
if (hints_ai_family != AF_UNSPEC && hints_ai_family != AF_INET) {

@ -238,12 +238,14 @@ optparse_long(struct optparse *options,
/* Parse as long option. */
options->errmsg[0] = '\0';
options->optopt = 0;
options->optlongname = 0;
options->optarg = 0;
option += 2; /* skip "--" */
options->optind++;
for (int i = 0; !longopts_end(longopts, i); i++) {
const char *name = longopts[i].longname;
if (longopts_match(name, option)) {
options->optlongname = option;
if (longindex)
*longindex = i;
options->optopt = longopts[i].shortname;

@ -48,6 +48,7 @@ struct optparse {
int permute;
int optind;
int optopt;
char *optlongname;
char *optarg;
char errmsg[64];
int subopt;

Loading…
Cancel
Save