summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-03-04 12:13:22 -0500
committermidipix <writeonce@midipix.org>2016-03-04 13:07:23 -0500
commit4e499f0f5fdec0167304927959f7a259490e67db (patch)
treef84eca59ebadbcdc097a960ef99dc0ce8343db36 /src
parente775c9e7f1bfc93a26cc9373f6bea6a378dbc07e (diff)
downloadapimagic-4e499f0f5fdec0167304927959f7a259490e67db.tar.bz2
apimagic-4e499f0f5fdec0167304927959f7a259490e67db.tar.xz
argv.h: argv_scan(): report argv index of first unit and first error (if any).
Diffstat (limited to 'src')
-rw-r--r--src/internal/argv/argv.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h
index c1c16b0..c8554f9 100644
--- a/src/internal/argv/argv.h
+++ b/src/internal/argv/argv.h
@@ -128,6 +128,8 @@ struct argv_ctx {
int flags;
int mode;
int nentries;
+ int unitidx;
+ int erridx;
enum argv_error errcode;
const char * errch;
const struct argv_option * erropt;
@@ -292,8 +294,7 @@ static void argv_scan(
bool fhybrid;
bool fnoscan;
- argv++;
- parg = argv;
+ parg = &argv[1];
ch = *parg;
ferr = ARGV_ERROR_OK;
fshort = false;
@@ -301,6 +302,9 @@ static void argv_scan(
fval = false;
mentry = meta ? meta->entries : 0;
+ ctx->unitidx = 0;
+ ctx->erridx = 0;
+
while (ch && (ferr == ARGV_ERROR_OK)) {
option = 0;
fhybrid = false;
@@ -424,10 +428,15 @@ static void argv_scan(
if (!is_arg_in_paradigm(ch,option->paradigm))
ferr = ARGV_ERROR_OPTARG_PARADIGM;
+ if (ferr == ARGV_ERROR_OK)
+ if (!option && !ctx->unitidx)
+ ctx->unitidx = parg - argv;
+
if (ferr != ARGV_ERROR_OK) {
ctx->errcode = ferr;
ctx->errch = ctx->errch ? ctx->errch : ch;
ctx->erropt = option;
+ ctx->erridx = parg - argv;
return;
} else if (ctx->mode == ARGV_MODE_SCAN) {
if (!fnoscan)
@@ -670,7 +679,7 @@ static struct argv_meta * argv_get(
int flags)
{
struct argv_meta * meta;
- struct argv_ctx ctx = {flags,ARGV_MODE_SCAN,0,0,0,0,0};
+ struct argv_ctx ctx = {flags,ARGV_MODE_SCAN,0,0,0,0,0,0,0};
argv_scan(argv,options,&ctx,0);