From 8d44c3a83a4ab3b7911aa8a6c50308f3e56c63e0 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Sun, 1 Oct 2000 19:04:33 +0000 Subject: [PATCH] handle -opt-value style options as well for files --- lib/myopt.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/myopt.c b/lib/myopt.c index a28e7538..d625436c 100644 --- a/lib/myopt.c +++ b/lib/myopt.c @@ -47,19 +47,29 @@ void myoptfile(const char* fn, const struct cmdinfo* cmdinfos) { while (isspace(*opt)) opt++; } - for (cip=cmdinfos; cip->olong || cip->oshort; cip++) - if (!strcmp(cip->olong,linebuf)) { - if (cip->takesvalue) { - if (!opt) ohshite(_("configuration error: %s needs a value"), linebuf); - if (cip->call) cip->call(cip,opt); - else *cip->sassignto= opt; - } else { - if (opt) ohshite(_("configuration error: %s does not take a value"), linebuf); - if (cip->call) cip->call(cip,0); - else *cip->iassignto= cip->arg; - } + for (cip=cmdinfos; cip->olong || cip->oshort; cip++) { + int l; + if (!cip->olong) continue; + if (!strcmp(cip->olong,linebuf)) break; + l=strlen(cip->olong); + if ((cip->takesvalue==2) && (linebuf[l]=='-') && + !opt && !strncmp(linebuf,cip->olong,l)) { + opt=linebuf+l+1; + break; } + } + if (!cip->olong) ohshite(_("configuration error: unknown option %s"), linebuf); + + if (cip->takesvalue) { + if (!opt) ohshite(_("configuration error: %s needs a value"), linebuf); + if (cip->call) cip->call(cip,opt); + else *cip->sassignto= opt; + } else { + if (opt) ohshite(_("configuration error: %s does not take a value"), linebuf); + if (cip->call) cip->call(cip,0); + else *cip->iassignto= cip->arg; + } } if (ferror(file)) ohshite(_("read error in configuration file `%.255s'"), fn); if (fclose(file)) ohshite(_("error closing configuration file `%.255s'"), fn); -- 2.39.5