From c17ac29dcdb617f5d9d960e432a628747e0e63df Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sat, 24 Mar 2018 10:26:53 -0600 Subject: Added support for flags on command-line --- src/survive.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/survive.c') diff --git a/src/survive.c b/src/survive.c index 807e82f..73d6474 100644 --- a/src/survive.c +++ b/src/survive.c @@ -159,11 +159,18 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) { } if (vartoupdate) { - if (av + 1 == argvend) { - fprintf(stderr, "Error: expected parameter after %s\n", *av); - showhelp = 1; + const char *name = *av + 2; // Skip the '--'; + bool flagArgument = (av + 1 == argvend) || av[1][0] == '-'; + + if (flagArgument) { + bool value = strncmp("no-", name, 3) != 0; + if (value == 0) { + name += 3; // Skip "no-" + } + survive_configi(ctx, name, SC_OVERRIDE | SC_SET, value); } else { - survive_configs(ctx, *av + 2, SC_OVERRIDE | SC_SET, *(av + 1)); + const char *value = *(av + 1); + survive_configs(ctx, name, SC_OVERRIDE | SC_SET, value); av++; } } @@ -273,7 +280,7 @@ int survive_startup(SurviveContext *ctx) { ctx->state = SURVIVE_RUNNING; int calibrateMandatory = survive_configi(ctx, "calibrate", SC_GET, 0); - int calibrateForbidden = survive_configi(ctx, "no-calibrate", SC_GET, 0); + int calibrateForbidden = survive_configi(ctx, "calibrate", SC_GET, 1) == 0; if (calibrateMandatory && calibrateForbidden) { SV_INFO("Contradictory settings --calibrate and --no-calibrate specified. Switching to normal behavior."); calibrateMandatory = calibrateForbidden = 0; @@ -288,6 +295,8 @@ int survive_startup(SurviveContext *ctx) { if (!isCalibrated) { SV_INFO("Uncalibrated configuration detected. Attaching calibration. Please don't move tracked objects for " "the duration of calibration. Pass '--no-calibrate' to skip calibration"); + } else { + SV_INFO("Calibration requested. Previous calibration will be overwritten."); } bool doCalibrate = isCalibrated == false || calibrateMandatory; -- cgit v1.2.3