aboutsummaryrefslogtreecommitdiff
path: root/src/survive.c
diff options
context:
space:
mode:
authorJustin Berger <j.david.berger@gmail.com>2018-03-24 10:26:53 -0600
committerJustin Berger <j.david.berger@gmail.com>2018-03-24 10:34:27 -0600
commitc17ac29dcdb617f5d9d960e432a628747e0e63df (patch)
tree7bbb6219887b8b104ffbd214d73f2dac16684d4d /src/survive.c
parentd5c42c4951261c401c5f9148ce2d6bb1402ce75b (diff)
downloadlibsurvive-c17ac29dcdb617f5d9d960e432a628747e0e63df.tar.gz
libsurvive-c17ac29dcdb617f5d9d960e432a628747e0e63df.tar.bz2
Added support for flags on command-line
Diffstat (limited to 'src/survive.c')
-rw-r--r--src/survive.c19
1 files changed, 14 insertions, 5 deletions
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;