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 ++++++++++++++----- src/survive_playback.c | 4 +--- 2 files changed, 15 insertions(+), 8 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; diff --git a/src/survive_playback.c b/src/survive_playback.c index e4321bc..dc9a330 100644 --- a/src/survive_playback.c +++ b/src/survive_playback.c @@ -350,7 +350,7 @@ void survive_install_recording(SurviveContext *ctx) { ctx->recptr->output_file = fopen(dataout_file, "w"); if (ctx->recptr->output_file == 0 && !record_to_stdout) { - SV_INFO("Could not open %s for writing\n", dataout_file); + SV_INFO("Could not open %s for writing", dataout_file); free(ctx->recptr); ctx->recptr = 0; return; @@ -377,8 +377,6 @@ int DriverRegPlayback(SurviveContext *ctx) { sp->playback_dir = playback_file; sp->time_factor = survive_configf(ctx, "playback-factor", SC_GET, 1.f); - printf("%s\n", playback_file); - sp->playback_file = fopen(playback_file, "r"); if (sp->playback_file == 0) { fprintf(stderr, "Could not open playback events file %s", -- cgit v1.2.3