diff --git a/build.py b/build.py index 71f5274d..9e61d692 100644 --- a/build.py +++ b/build.py @@ -28,7 +28,7 @@ else: ("acorndfs", "", "--200"), ("agat", "", ""), ("amiga", "", ""), - ("apple2", "", "--140 40track_drive"), + ("apple2", "", "--140 -c 40track_drive"), ("atarist", "", "--360"), ("atarist", "", "--370"), ("atarist", "", "--400"), @@ -38,17 +38,17 @@ else: ("atarist", "", "--800"), ("atarist", "", "--820"), ("bk", "", ""), - ("brother", "", "--120 40track_drive"), + ("brother", "", "--120 -c 40track_drive"), ("brother", "", "--240"), ( "commodore", "scripts/commodore1541_test.textpb", - "--171 40track_drive", + "--171 -c 40track_drive", ), ( "commodore", "scripts/commodore1541_test.textpb", - "--192 40track_drive", + "--192 -c 40track_drive", ), ("commodore", "", "--800"), ("commodore", "", "--1620"), @@ -60,17 +60,17 @@ else: ("ibm", "", "--1232"), ("ibm", "", "--1440"), ("ibm", "", "--1680"), - ("ibm", "", "--180 40track_drive"), - ("ibm", "", "--160 40track_drive"), - ("ibm", "", "--320 40track_drive"), - ("ibm", "", "--360 40track_drive"), + ("ibm", "", "--180 -c 40track_drive"), + ("ibm", "", "--160 -c 40track_drive"), + ("ibm", "", "--320 -c 40track_drive"), + ("ibm", "", "--360 -c 40track_drive"), ("ibm", "", "--720_96"), ("ibm", "", "--720_135"), ("mac", "scripts/mac400_test.textpb", "--400"), ("mac", "scripts/mac800_test.textpb", "--800"), ("n88basic", "", ""), ("rx50", "", ""), - ("tartu", "", "--390 40track_drive"), + ("tartu", "", "--390 -c 40track_drive"), ("tartu", "", "--780"), ("tids990", "", ""), ("victor9k", "", "--612"), diff --git a/lib/config/flags.cc b/lib/config/flags.cc index bc54262a..f474673b 100644 --- a/lib/config/flags.cc +++ b/lib/config/flags.cc @@ -13,17 +13,23 @@ static std::vector all_flags; static std::map flags_by_name; static void doHelp(); +static void doLoadConfig(const std::string& filename); static void doShowConfig(); static void doDoc(); static FlagGroup helpGroup; static ActionFlag helpFlag = ActionFlag({"--help"}, "Shows the help.", doHelp); -static ActionFlag showConfigFlag = ActionFlag({"--config", "-C"}, +static FlagGroup configGroup; +static ActionFlag loadConfigFlag({"--config", "-c"}, + "Reads an internal or external configuration file.", + doLoadConfig); + +static ActionFlag showConfigFlag({"--show-config", "-C"}, "Shows the currently set configuration and halts.", doShowConfig); -static ActionFlag docFlag = ActionFlag( +static ActionFlag docFlag( {"--doc"}, "Shows the available configuration options and halts.", doDoc); FlagGroup::FlagGroup() @@ -182,17 +188,16 @@ void FlagGroup::parseFlags(int argc, "non-option parameter '{}' seen (try --help)", *filenames.begin()); } +static void doLoadConfig(const std::string& filename) +{ + globalConfig().readBaseConfigFile(filename); +} + void FlagGroup::parseFlagsWithConfigFiles(int argc, const char* argv[], const std::map& configFiles) { - parseFlags(argc, - argv, - [&](const auto& filename) - { - globalConfig().readBaseConfigFile(filename); - return true; - }); + FlagGroup({this, &configGroup}).parseFlags(argc, argv); } void FlagGroup::checkInitialised() const diff --git a/lib/config/flags.h b/lib/config/flags.h index 67be675f..d8b96af4 100644 --- a/lib/config/flags.h +++ b/lib/config/flags.h @@ -83,13 +83,23 @@ public: const std::string helptext, std::function callback): Flag(names, helptext), - _callback(callback) + _voidCallback(callback), + _hasArgument(false) + { + } + + ActionFlag(const std::vector& names, + const std::string helptext, + std::function callback): + Flag(names, helptext), + _callback(callback), + _hasArgument(true) { } bool hasArgument() const override { - return false; + return _hasArgument; } const std::string defaultValueAsString() const override @@ -99,11 +109,16 @@ public: void set(const std::string& value) override { - _callback(); + if (_hasArgument) + _callback(value); + else + _voidCallback(); } private: - const std::function _callback; + const std::function _callback; + const std::function _voidCallback; + bool _hasArgument; }; class SettableFlag : public Flag diff --git a/scripts/encodedecodetest.sh b/scripts/encodedecodetest.sh index 80842e24..d8cbf5b9 100755 --- a/scripts/encodedecodetest.sh +++ b/scripts/encodedecodetest.sh @@ -14,10 +14,10 @@ destfile=$dir/dest.img dd if=/dev/urandom of=$srcfile bs=1048576 count=2 2>&1 -echo $fluxengine write $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags -$fluxengine write $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags -echo $fluxengine read $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags -$fluxengine read $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags +echo $fluxengine write -c $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags +$fluxengine write -c $format -i $srcfile -d $fluxfile --drive.rotational_period_ms=200 $flags +echo $fluxengine read -c $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags +$fluxengine read -c $format -s $fluxfile -o $destfile --drive.rotational_period_ms=200 $flags if [ ! -s $destfile ]; then echo "Zero length output file!" >&2 exit 1