-/* Licensed under GPLv3+ - see LICENSE file for details */
+/* Licensed under GPLv2+ - see LICENSE file for details */
/* Actual code to parse commandline. */
#include <ccan/opt/opt.h>
#include <string.h>
/* Returns 1 if argument consumed, 0 if all done, -1 on error. */
int parse_one(int *argc, char *argv[], enum opt_type is_early, unsigned *offset,
- void (*errlog)(const char *fmt, ...))
+ void (*errlog)(const char *fmt, ...), bool unknown_ok)
{
unsigned i, arg, len;
const char *o, *optarg = NULL;
continue;
break;
}
- if (!o)
+ if (!o) {
+ if (unknown_ok)
+ goto ok;
return parse_err(errlog, argv[0],
argv[arg], strlen(argv[arg]),
"unrecognized option");
+ }
/* For error messages, we include the leading '--' */
o -= 2;
len += 2;
(*offset)++;
break;
}
- if (!o)
+ if (!o) {
+ if (unknown_ok) {
+ (*offset)++;
+ goto ok;
+ }
return parse_err(errlog, argv[0],
argv[arg], strlen(argv[arg]),
"unrecognized option");
+ }
/* For error messages, we include the leading '-' */
o--;
len = 2;
if (problem) {
parse_err(errlog, argv[0], o, len, problem);
- free(problem);
+ opt_alloc.free(problem);
return -1;
}
+ok:
/* If no more letters in that short opt, reset offset. */
if (*offset && !argv[arg][*offset + 1])
*offset = 0;