Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ int main(int argc, char **argv)
}
}

/* Print remaining arguments. */
printf("amend : %s\n", amend ? "true" : "false");
printf("brief : %s\n", brief ? "true" : "false");
printf("color : %s\n", color);
printf("delay : %d\n", delay);

printf("Print remaining arguments:\n");
while ((arg = optparse_arg(&options)))
printf("%s\n", arg);

Expand Down
7 changes: 7 additions & 0 deletions optparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ optparse_long(struct optparse *options,
int *longindex)
{
int i;
char *next;
char *option = options->argv[options->optind];
if (option == 0) {
return -1;
Expand All @@ -373,6 +374,7 @@ optparse_long(struct optparse *options,
options->optopt = 0;
options->optarg = 0;
option += 2; /* skip "--" */
next = options->argv[options->optind + 1];
options->optind++;
for (i = 0; !optparse_longopts_end(longopts, i); i++) {
const char *name = longopts[i].longname;
Expand All @@ -392,6 +394,11 @@ optparse_long(struct optparse *options,
return optparse_error(options, OPTPARSE_MSG_MISSING, name);
else
options->optind++;
#ifdef IMPROVED_OPTPARSE_OPTIONAL
} else if (longopts[i].argtype == OPTPARSE_OPTIONAL) {
if (next && next[0] != '-')
options->optarg = options->argv[options->optind++];
#endif
}
return options->optopt;
}
Expand Down