From a2f55eeab8d75e1813a75d0a9f331a60e84d4fa1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 24 Apr 2020 16:39:51 -0700 Subject: [PATCH] construct: Add STRINGS program options type support. --- construct/lgetopt.cc | 13 +++++++++++++ construct/lgetopt.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/construct/lgetopt.cc b/construct/lgetopt.cc index a1954d684..90fbb74b4 100644 --- a/construct/lgetopt.cc +++ b/construct/lgetopt.cc @@ -99,6 +99,19 @@ parseargs(int *argc, char * const **argv, struct lgetopt *opts) (*argc)--; (*argv)++; break; + case argtype::STRINGS: + if(*argc < 2) + { + fprintf(stderr, + "error: option '%c%s' requires an argument\n", + OPTCHAR, opts[i].opt); + usage(progname, opts); + } + + ((std::vector *)opts[i].argloc)->emplace_back((*argv)[1]); + (*argc)--; + (*argv)++; + break; case argtype::USAGE: usage(progname, opts); diff --git a/construct/lgetopt.h b/construct/lgetopt.h index f71af0595..cdefecc65 100644 --- a/construct/lgetopt.h +++ b/construct/lgetopt.h @@ -27,7 +27,7 @@ struct lgetopt const char *opt; /* name of the argument */ void *argloc; /* where we store the argument to it (-option argument) */ enum - { INTEGER, YESNO, STRING, USAGE, ENDEBUG, BOOL } + { INTEGER, YESNO, STRING, STRINGS, USAGE, ENDEBUG, BOOL } argtype; const char *desc; /* description of the argument, usage for printing help */ };