From 42e6c110817c0aae31ee53441e66fff67466c643 Mon Sep 17 00:00:00 2001 From: dg Date: Wed, 10 May 2023 23:13:33 +0000 Subject: [PATCH] Migrate to a new global config object. --- lib/build.mk | 1 + lib/config.cc | 25 +++++++++++++++ lib/config.h | 14 ++++++++ lib/decoders/fluxmapreader.cc | 4 +-- lib/encoders/encoders.cc | 2 +- lib/fl2.cc | 10 +++--- lib/flags.cc | 18 +++++------ lib/fluxsink/a2rfluxsink.cc | 6 ++-- lib/fluxsink/fl2fluxsink.cc | 2 +- lib/fluxsink/fluxsink.cc | 2 +- lib/fluxsink/hardwarefluxsink.cc | 8 ++--- lib/fluxsink/scpfluxsink.cc | 2 +- lib/fluxsource/a2rfluxsource.cc | 10 +++--- lib/fluxsource/fl2fluxsource.cc | 4 +-- lib/fluxsource/fluxsource.cc | 2 +- lib/fluxsource/hardwarefluxsource.cc | 10 +++--- lib/fluxsource/scpfluxsource.cc | 4 +-- lib/globals.cc | 5 ++- lib/globals.h | 2 ++ lib/imagereader/d88imagereader.cc | 14 ++++---- lib/imagereader/dimimagereader.cc | 8 ++--- lib/imagereader/fdiimagereader.cc | 6 ++-- lib/imagereader/imdimagereader.cc | 6 ++-- lib/imagereader/imgimagereader.cc | 2 +- lib/imagereader/nfdimagereader.cc | 10 +++--- lib/imagewriter/imgimagewriter.cc | 2 +- lib/layout.cc | 38 +++++++++++----------- lib/proto.cc | 2 +- lib/proto.h | 2 +- lib/readerwriter.cc | 48 ++++++++++++++-------------- lib/usb/usb.cc | 12 +++---- lib/vfs/amigaffs.cc | 4 +-- lib/vfs/cbmfs.cc | 2 +- lib/vfs/vfs.cc | 2 +- scripts/mkdocindex.cc | 16 +++++----- src/fe-analysedriveresponse.cc | 12 +++---- src/fe-inspect.cc | 10 +++--- src/fe-rawread.cc | 20 ++++++------ src/fe-rawwrite.cc | 22 ++++++------- src/fe-read.cc | 21 ++++++------ src/fe-rpm.cc | 10 +++--- src/fe-seek.cc | 8 ++--- src/fe-write.cc | 29 +++++++++-------- src/fileutils.cc | 8 ++--- src/gui/explorerpanel.cc | 2 +- src/gui/idlepanel.cc | 34 ++++++++++---------- src/gui/imagerpanel.cc | 40 +++++++++++------------ tests/cpmfs.cc | 10 +++--- tests/layout.cc | 4 +-- 49 files changed, 287 insertions(+), 248 deletions(-) create mode 100644 lib/config.cc create mode 100644 lib/config.h diff --git a/lib/build.mk b/lib/build.mk index 8fc6b76e..61ef1b93 100644 --- a/lib/build.mk +++ b/lib/build.mk @@ -1,6 +1,7 @@ LIBFLUXENGINE_SRCS = \ lib/bitmap.cc \ lib/bytes.cc \ + lib/config.cc \ lib/crc.cc \ lib/csvreader.cc \ lib/decoders/decoders.cc \ diff --git a/lib/config.cc b/lib/config.cc new file mode 100644 index 00000000..0346a4ea --- /dev/null +++ b/lib/config.cc @@ -0,0 +1,25 @@ +#include "lib/globals.h" +#include "lib/config.h" +#include "lib/proto.h" + +static Config config; + +Config& globalConfig() +{ + return config; +} + +ConfigProto* Config::operator->() const +{ + return &globalConfigProto(); +} + +Config::operator ConfigProto*() const +{ + return &globalConfigProto(); +} + +Config::operator ConfigProto&() const +{ + return globalConfigProto(); +} diff --git a/lib/config.h b/lib/config.h new file mode 100644 index 00000000..1b510e78 --- /dev/null +++ b/lib/config.h @@ -0,0 +1,14 @@ +#pragma once + +class ConfigProto; + +class Config +{ +public: + ConfigProto* operator -> () const; + operator ConfigProto* () const; + operator ConfigProto& () const; +}; + +extern Config& globalConfig(); + diff --git a/lib/decoders/fluxmapreader.cc b/lib/decoders/fluxmapreader.cc index 17f85f68..49d38016 100644 --- a/lib/decoders/fluxmapreader.cc +++ b/lib/decoders/fluxmapreader.cc @@ -12,7 +12,7 @@ FluxmapReader::FluxmapReader(const Fluxmap& fluxmap): _fluxmap(fluxmap), _bytes(fluxmap.ptr()), _size(fluxmap.bytes()), - _config(globalConfig().decoder()) + _config(globalConfig()->decoder()) { rewind(); } @@ -133,7 +133,7 @@ FluxPattern::FluxPattern(unsigned bits, uint64_t pattern): _bits(bits) bool FluxPattern::matches(const unsigned* end, FluxMatch& match) const { const double clockDecodeThreshold = - globalConfig().decoder().bit_error_threshold(); + globalConfig()->decoder().bit_error_threshold(); const unsigned* start = end - _intervals.size(); unsigned candidatelength = std::accumulate(start, end - _lowzero, 0); if (!candidatelength) diff --git a/lib/encoders/encoders.cc b/lib/encoders/encoders.cc index cad47e00..3043d431 100644 --- a/lib/encoders/encoders.cc +++ b/lib/encoders/encoders.cc @@ -48,7 +48,7 @@ nanoseconds_t Encoder::calculatePhysicalClockPeriod( nanoseconds_t targetClockPeriod, nanoseconds_t targetRotationalPeriod) { nanoseconds_t currentRotationalPeriod = - globalConfig().drive().rotational_period_ms() * 1e6; + globalConfig()->drive().rotational_period_ms() * 1e6; if (currentRotationalPeriod == 0) error( "you must set --drive.rotational_period_ms as it can't be " diff --git a/lib/fl2.cc b/lib/fl2.cc index b4c1ff8c..339fe340 100644 --- a/lib/fl2.cc +++ b/lib/fl2.cc @@ -26,12 +26,12 @@ static void upgradeFluxFile(FluxFileProto& proto) proto.set_version(FluxFileVersion::VERSION_2); } - if (proto.version() == FluxFileVersion::VERSION_2) - { - proto.mutable_drive()->set_rotational_period_ms( - proto.rotational_period_ms()); + if (proto.version() == FluxFileVersion::VERSION_2) + { + proto.mutable_drive()->set_rotational_period_ms( + proto.rotational_period_ms()); proto.set_version(FluxFileVersion::VERSION_3); - } + } if (proto.version() > FluxFileVersion::VERSION_3) error( diff --git a/lib/flags.cc b/lib/flags.cc index d4fc3925..89a55f8b 100644 --- a/lib/flags.cc +++ b/lib/flags.cc @@ -52,7 +52,7 @@ void FlagGroup::applyOption(const OptionProto& option) log("OPTION: {}", option.has_message() ? option.message() : option.comment()); - globalConfig().MergeFrom(option.config()); + globalConfig()->MergeFrom(option.config()); } bool FlagGroup::applyOption(const std::string& optionName) @@ -70,10 +70,10 @@ bool FlagGroup::applyOption(const std::string& optionName) return false; }; - if (searchOptionList(globalConfig().option())) + if (searchOptionList(globalConfig()->option())) return true; - for (const auto& optionGroup : globalConfig().option_group()) + for (const auto& optionGroup : globalConfig()->option_group()) { if (searchOptionList(optionGroup.option())) return true; @@ -213,7 +213,7 @@ std::vector FlagGroup::parseFlagsWithFilenames(int argc, /* Apply any default options in groups. */ - for (auto& group : globalConfig().option_group()) + for (auto& group : globalConfig()->option_group()) { const OptionProto* defaultOption = &*group.option().begin(); bool isSet = false; @@ -232,7 +232,7 @@ std::vector FlagGroup::parseFlagsWithFilenames(int argc, /* Next, any standalone options. */ - for (auto& option : globalConfig().option()) + for (auto& option : globalConfig()->option()) { if (options.find(option.name()) != options.end()) { @@ -249,7 +249,7 @@ std::vector FlagGroup::parseFlagsWithFilenames(int argc, for (auto [k, v] : overrides) { - ProtoField protoField = resolveProtoPath(&globalConfig(), k); + ProtoField protoField = resolveProtoPath(globalConfig(), k); setProtoFieldFromString(protoField, v); } @@ -296,7 +296,7 @@ ConfigProto FlagGroup::parseSingleConfigFile(const std::string& filename, ConfigProto config; if (!google::protobuf::TextFormat::MergeFromString( - ss.str(), &globalConfig())) + ss.str(), globalConfig())) error("couldn't load external config proto"); return config; } @@ -305,7 +305,7 @@ ConfigProto FlagGroup::parseSingleConfigFile(const std::string& filename, void FlagGroup::parseConfigFile(const std::string& filename, const std::map& configFiles) { - globalConfig().MergeFrom(parseSingleConfigFile(filename, configFiles)); + globalConfig()->MergeFrom(parseSingleConfigFile(filename, configFiles)); } void FlagGroup::checkInitialised() const @@ -377,7 +377,7 @@ static void doShowConfig() static void doDoc() { - const auto fields = findAllProtoFields(&globalConfig()); + const auto fields = findAllProtoFields(globalConfig()); for (const auto field : fields) { const std::string& path = field.first; diff --git a/lib/fluxsink/a2rfluxsink.cc b/lib/fluxsink/a2rfluxsink.cc index 6c229a7b..7953c0bb 100644 --- a/lib/fluxsink/a2rfluxsink.cc +++ b/lib/fluxsink/a2rfluxsink.cc @@ -24,7 +24,7 @@ namespace bool singlesided(void) { - return globalConfig().heads().start() == globalConfig().heads().end(); + return globalConfig()->heads().start() == globalConfig()->heads().end(); } class A2RFluxSink : public FluxSink @@ -38,8 +38,8 @@ namespace log("A2R: writing A2R {} file containing {} tracks\n", singlesided() ? "single sided" : "double sided", - globalConfig().tracks().end() - - globalConfig().tracks().start() + 1); + globalConfig()->tracks().end() - + globalConfig()->tracks().start() + 1); time_t now{std::time(nullptr)}; auto t = gmtime(&now); diff --git a/lib/fluxsink/fl2fluxsink.cc b/lib/fluxsink/fl2fluxsink.cc index 6897fca7..1c2dfeee 100644 --- a/lib/fluxsink/fl2fluxsink.cc +++ b/lib/fluxsink/fl2fluxsink.cc @@ -43,7 +43,7 @@ public: track->add_flux(fluxBytes); } - proto.mutable_drive()->MergeFrom(globalConfig().drive()); + proto.mutable_drive()->MergeFrom(globalConfig()->drive()); saveFl2File(_filename, proto); } diff --git a/lib/fluxsink/fluxsink.cc b/lib/fluxsink/fluxsink.cc index d254869e..8bce3e71 100644 --- a/lib/fluxsink/fluxsink.cc +++ b/lib/fluxsink/fluxsink.cc @@ -74,7 +74,7 @@ void FluxSink::updateConfigForFilename( [](auto& s, auto* proto) { proto->set_type(FluxSinkProto::DRIVE); - globalConfig().mutable_drive()->set_drive(std::stoi(s)); + globalConfig()->mutable_drive()->set_drive(std::stoi(s)); }}, }; diff --git a/lib/fluxsink/hardwarefluxsink.cc b/lib/fluxsink/hardwarefluxsink.cc index a50bbed7..a3181b87 100644 --- a/lib/fluxsink/hardwarefluxsink.cc +++ b/lib/fluxsink/hardwarefluxsink.cc @@ -22,9 +22,9 @@ public: public: void writeFlux(int track, int side, const Fluxmap& fluxmap) override { - usbSetDrive(globalConfig().drive().drive(), - globalConfig().drive().high_density(), - globalConfig().drive().index_mode()); + usbSetDrive(globalConfig()->drive().drive(), + globalConfig()->drive().high_density(), + globalConfig()->drive().index_mode()); #if 0 if (fluxSourceSinkFortyTrack) { @@ -41,7 +41,7 @@ public: operator std::string() const { - return fmt::format("drive {}", globalConfig().drive().drive()); + return fmt::format("drive {}", globalConfig()->drive().drive()); } private: diff --git a/lib/fluxsink/scpfluxsink.cc b/lib/fluxsink/scpfluxsink.cc index 5fdfdaa0..a8155e47 100644 --- a/lib/fluxsink/scpfluxsink.cc +++ b/lib/fluxsink/scpfluxsink.cc @@ -55,7 +55,7 @@ public: _fileheader.start_track = strackno(minTrack, minSide); _fileheader.end_track = strackno(maxTrack, maxSide); _fileheader.flags = SCP_FLAG_INDEXED; - if (globalConfig().drive().tpi() != 48) + if (globalConfig()->drive().tpi() != 48) _fileheader.flags |= SCP_FLAG_96TPI; _fileheader.cell_width = 0; if ((minSide == 0) && (maxSide == 0)) diff --git a/lib/fluxsource/a2rfluxsource.cc b/lib/fluxsource/a2rfluxsource.cc index 534f52fb..aacc64b6 100644 --- a/lib/fluxsource/a2rfluxsource.cc +++ b/lib/fluxsource/a2rfluxsource.cc @@ -78,15 +78,15 @@ public: if (disktype == 1) { /* 5.25" with quarter stepping. */ - ::globalConfig().mutable_drive()->set_tracks(160); - ::globalConfig().mutable_drive()->set_heads(1); - ::globalConfig().mutable_drive()->set_head_width(4); - ::globalConfig().mutable_drive()->set_tpi(48 * 4); + ::globalConfig()->mutable_drive()->set_tracks(160); + ::globalConfig()->mutable_drive()->set_heads(1); + ::globalConfig()->mutable_drive()->set_head_width(4); + ::globalConfig()->mutable_drive()->set_tpi(48 * 4); } else { /* 3.5". */ - ::globalConfig().mutable_drive()->set_tpi(135); + ::globalConfig()->mutable_drive()->set_tpi(135); } Bytes stream = findChunk("STRM"); diff --git a/lib/fluxsource/fl2fluxsource.cc b/lib/fluxsource/fl2fluxsource.cc index bfcf9e9d..67a6415a 100644 --- a/lib/fluxsource/fl2fluxsource.cc +++ b/lib/fluxsource/fl2fluxsource.cc @@ -37,10 +37,10 @@ public: { _proto = loadFl2File(_config.filename()); - if (::globalConfig().has_drive()) + if (::globalConfig()->has_drive()) warning( "FLUX: overriding drive configuration with flux file contents"); - ::globalConfig().mutable_drive()->MergeFrom(_proto.drive()); + ::globalConfig()->mutable_drive()->MergeFrom(_proto.drive()); } public: diff --git a/lib/fluxsource/fluxsource.cc b/lib/fluxsource/fluxsource.cc index 23a2edd2..71eea15b 100644 --- a/lib/fluxsource/fluxsource.cc +++ b/lib/fluxsource/fluxsource.cc @@ -102,7 +102,7 @@ void FluxSource::updateConfigForFilename( [](auto& s, auto* proto) { proto->set_type(FluxSourceProto::DRIVE); - globalConfig().mutable_drive()->set_drive(std::stoi(s)); + globalConfig()->mutable_drive()->set_drive(std::stoi(s)); }}, {std::regex("^flx:(.*)$"), [](auto& s, auto* proto) diff --git a/lib/fluxsource/hardwarefluxsource.cc b/lib/fluxsource/hardwarefluxsource.cc index f9041b35..ab718b6d 100644 --- a/lib/fluxsource/hardwarefluxsource.cc +++ b/lib/fluxsource/hardwarefluxsource.cc @@ -29,14 +29,14 @@ private: std::unique_ptr next() { - usbSetDrive(globalConfig().drive().drive(), - globalConfig().drive().high_density(), - globalConfig().drive().index_mode()); + usbSetDrive(globalConfig()->drive().drive(), + globalConfig()->drive().high_density(), + globalConfig()->drive().index_mode()); usbSeek(_track); Bytes data = usbRead(_head, - globalConfig().drive().sync_with_index(), - globalConfig().drive().revolutions() * + globalConfig()->drive().sync_with_index(), + globalConfig()->drive().revolutions() * _fluxsource._oneRevolution, _fluxsource._hardSectorThreshold); auto fluxmap = std::make_unique(); diff --git a/lib/fluxsource/scpfluxsource.cc b/lib/fluxsource/scpfluxsource.cc index c82d0eb0..8adb25e7 100644 --- a/lib/fluxsource/scpfluxsource.cc +++ b/lib/fluxsource/scpfluxsource.cc @@ -43,8 +43,8 @@ public: error("input not a SCP file"); int tpi = (_header.flags & SCP_FLAG_96TPI) ? 96 : 48; - if (!::globalConfig().drive().has_tpi()) - ::globalConfig().mutable_drive()->set_tpi(tpi); + if (!::globalConfig()->drive().has_tpi()) + ::globalConfig()->mutable_drive()->set_tpi(tpi); _resolution = 25 * (_header.resolution + 1); int startSide = (_header.heads == 2) ? 1 : 0; diff --git a/lib/globals.cc b/lib/globals.cc index 0b3a6e5e..bd28af65 100644 --- a/lib/globals.cc +++ b/lib/globals.cc @@ -13,7 +13,6 @@ double getCurrentTime(void) void warning(const std::string msg) { - log(msg); - fmt::print("Warning: {}\n", msg); + log(msg); + fmt::print("Warning: {}\n", msg); } - diff --git a/lib/globals.h b/lib/globals.h index c3ad39d4..5ed89056 100644 --- a/lib/globals.h +++ b/lib/globals.h @@ -60,4 +60,6 @@ inline void warning(fmt::string_view fstr, const Args&... args) template struct overloaded : Ts... { using Ts::operator()...; }; template overloaded(Ts...) -> overloaded; +#include "lib/config.h" + #endif diff --git a/lib/imagereader/d88imagereader.cc b/lib/imagereader/d88imagereader.cc index 7041e8dc..fdd5a6d3 100644 --- a/lib/imagereader/d88imagereader.cc +++ b/lib/imagereader/d88imagereader.cc @@ -56,27 +56,27 @@ public: inputFile.read((char*)trackTable.begin(), trackTable.size()); ByteReader trackTableReader(trackTable); - if (globalConfig().encoder().format_case() != + if (globalConfig()->encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET) log("D88: overriding configured format"); - auto ibm = globalConfig().mutable_encoder()->mutable_ibm(); + auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); int clockRate = 500; if (mediaFlag == 0x20) { log("D88: forcing high density mode"); - globalConfig().mutable_drive()->set_high_density(true); - globalConfig().mutable_layout()->set_tpi(96); + globalConfig()->mutable_drive()->set_high_density(true); + globalConfig()->mutable_layout()->set_tpi(96); } else { log("D88: forcing single/double density mode"); clockRate = 300; - globalConfig().mutable_drive()->set_high_density(false); - globalConfig().mutable_layout()->set_tpi(48); + globalConfig()->mutable_drive()->set_high_density(false); + globalConfig()->mutable_layout()->set_tpi(48); } - auto layout = globalConfig().mutable_layout(); + auto layout = globalConfig()->mutable_layout(); std::unique_ptr image(new Image); for (int track = 0; track < trackTableSize / 4; track++) { diff --git a/lib/imagereader/dimimagereader.cc b/lib/imagereader/dimimagereader.cc index 9d71cf85..dbb1dd01 100644 --- a/lib/imagereader/dimimagereader.cc +++ b/lib/imagereader/dimimagereader.cc @@ -91,11 +91,11 @@ public: trackCount++; } - auto layout = globalConfig().mutable_layout(); - if (globalConfig().encoder().format_case() == + auto layout = globalConfig()->mutable_layout(); + if (globalConfig()->encoder().format_case() == EncoderProto::FormatCase::FORMAT_NOT_SET) { - auto ibm = globalConfig().mutable_encoder()->mutable_ibm(); + auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); trackdata->set_target_clock_period_us(2); @@ -134,7 +134,7 @@ public: break; } - globalConfig().mutable_decoder()->mutable_ibm(); + globalConfig()->mutable_decoder()->mutable_ibm(); } image->calculateSize(); diff --git a/lib/imagereader/fdiimagereader.cc b/lib/imagereader/fdiimagereader.cc index 0dde44dd..fcb1c734 100644 --- a/lib/imagereader/fdiimagereader.cc +++ b/lib/imagereader/fdiimagereader.cc @@ -70,11 +70,11 @@ public: trackCount++; } - auto layout = globalConfig().mutable_layout(); - if (globalConfig().encoder().format_case() == + auto layout = globalConfig()->mutable_layout(); + if (globalConfig()->encoder().format_case() == EncoderProto::FormatCase::FORMAT_NOT_SET) { - auto ibm = globalConfig().mutable_encoder()->mutable_ibm(); + auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); trackdata->set_target_clock_period_us(2); diff --git a/lib/imagereader/imdimagereader.cc b/lib/imagereader/imdimagereader.cc index 7cb665c2..58636c25 100644 --- a/lib/imagereader/imdimagereader.cc +++ b/lib/imagereader/imdimagereader.cc @@ -157,7 +157,7 @@ public: TrackHeader header = {0, 0, 0, 0, 0}; TrackHeader previousheader = {0, 0, 0, 0, 0}; - auto layout = globalConfig().mutable_layout(); + auto layout = globalConfig()->mutable_layout(); unsigned n = 0; unsigned headerPtr = 0; @@ -259,7 +259,7 @@ public: headerPtr++; } - auto ibm = globalConfig().mutable_encoder()->mutable_ibm(); + auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); auto trackdata = ibm->add_trackdata(); auto layoutdata = layout->add_layoutdata(); @@ -443,7 +443,7 @@ public: } } - if (globalConfig().encoder().format_case() != + if (globalConfig()->encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET) log("IMD: overriding configured format"); diff --git a/lib/imagereader/imgimagereader.cc b/lib/imagereader/imgimagereader.cc index 0398637c..94449731 100644 --- a/lib/imagereader/imgimagereader.cc +++ b/lib/imagereader/imgimagereader.cc @@ -24,7 +24,7 @@ public: if (!inputFile.is_open()) error("cannot open input file"); - auto layout = globalConfig().layout(); + auto layout = globalConfig()->layout(); if (!layout.tracks() || !layout.sides()) error( "IMG: bad configuration; did you remember to set the " diff --git a/lib/imagereader/nfdimagereader.cc b/lib/imagereader/nfdimagereader.cc index e741e9e1..7347f499 100644 --- a/lib/imagereader/nfdimagereader.cc +++ b/lib/imagereader/nfdimagereader.cc @@ -49,16 +49,16 @@ public: error("NFD: unsupported number of heads"); } - if (globalConfig().encoder().format_case() != + if (globalConfig()->encoder().format_case() != EncoderProto::FormatCase::FORMAT_NOT_SET) log("NFD: overriding configured format"); - auto ibm = globalConfig().mutable_encoder()->mutable_ibm(); - auto layout = globalConfig().mutable_layout(); + auto ibm = globalConfig()->mutable_encoder()->mutable_ibm(); + auto layout = globalConfig()->mutable_layout(); log("NFD: HD 1.2MB mode"); log("NFD: forcing hign density mode"); - globalConfig().mutable_drive()->set_high_density(true); - globalConfig().mutable_layout()->set_tpi(96); + globalConfig()->mutable_drive()->set_high_density(true); + globalConfig()->mutable_layout()->set_tpi(96); std::unique_ptr image(new Image); for (int track = 0; track < 163; track++) diff --git a/lib/imagewriter/imgimagewriter.cc b/lib/imagewriter/imgimagewriter.cc index fb65ea9f..33099776 100644 --- a/lib/imagewriter/imgimagewriter.cc +++ b/lib/imagewriter/imgimagewriter.cc @@ -21,7 +21,7 @@ public: { const Geometry geometry = image.getGeometry(); - auto& layout = globalConfig().layout(); + auto& layout = globalConfig()->layout(); int tracks = layout.has_tracks() ? layout.tracks() : geometry.numTracks; int sides = layout.has_sides() ? layout.sides() : geometry.numSides; diff --git a/lib/layout.cc b/lib/layout.cc index 56bc7fa1..525507ec 100644 --- a/lib/layout.cc +++ b/lib/layout.cc @@ -10,16 +10,16 @@ bool approximatelyEqual(float a, float b, float epsilon) static unsigned getTrackStep() { - if (!globalConfig().layout().tpi()) + if (!globalConfig()->layout().tpi()) error("no layout TPI set"); - if (!globalConfig().drive().tpi()) + if (!globalConfig()->drive().tpi()) error("no drive TPI set"); - if (globalConfig().layout().tpi() == 0.0) + if (globalConfig()->layout().tpi() == 0.0) error("layout TPI is zero; this shouldn't happen?"); float trackStepFactor = - globalConfig().drive().tpi() / globalConfig().layout().tpi(); + globalConfig()->drive().tpi() / globalConfig()->layout().tpi(); if (!approximatelyEqual(trackStepFactor, round(trackStepFactor), 0.001)) error( @@ -34,37 +34,37 @@ static unsigned getTrackStep() unsigned Layout::remapTrackPhysicalToLogical(unsigned ptrack) { - return (ptrack - globalConfig().drive().head_bias()) / getTrackStep(); + return (ptrack - globalConfig()->drive().head_bias()) / getTrackStep(); } unsigned Layout::remapTrackLogicalToPhysical(unsigned ltrack) { - return globalConfig().drive().head_bias() + ltrack * getTrackStep(); + return globalConfig()->drive().head_bias() + ltrack * getTrackStep(); } unsigned Layout::remapSidePhysicalToLogical(unsigned pside) { - return pside ^ globalConfig().layout().swap_sides(); + return pside ^ globalConfig()->layout().swap_sides(); } unsigned Layout::remapSideLogicalToPhysical(unsigned lside) { - return lside ^ globalConfig().layout().swap_sides(); + return lside ^ globalConfig()->layout().swap_sides(); } std::vector> Layout::computeLocations() { std::set tracks; - if (globalConfig().has_tracks()) - tracks = iterate(globalConfig().tracks()); + if (globalConfig()->has_tracks()) + tracks = iterate(globalConfig()->tracks()); else - tracks = iterate(0, globalConfig().layout().tracks()); + tracks = iterate(0, globalConfig()->layout().tracks()); std::set heads; - if (globalConfig().has_heads()) - heads = iterate(globalConfig().heads()); + if (globalConfig()->has_heads()) + heads = iterate(globalConfig()->heads()); else - heads = iterate(0, globalConfig().layout().sides()); + heads = iterate(0, globalConfig()->layout().sides()); std::vector> locations; for (unsigned logicalTrack : tracks) @@ -97,7 +97,7 @@ void Layout::getBounds( std::vector> Layout::getTrackOrdering( unsigned guessedTracks, unsigned guessedSides) { - auto layout = globalConfig().layout(); + auto layout = globalConfig()->layout(); int tracks = layout.has_tracks() ? layout.tracks() : guessedTracks; int sides = layout.has_sides() ? layout.sides() : guessedSides; @@ -179,7 +179,7 @@ std::shared_ptr Layout::getLayoutOfTrack( auto trackInfo = std::make_shared(); LayoutProto::LayoutdataProto layoutdata; - for (const auto& f : globalConfig().layout().layoutdata()) + for (const auto& f : globalConfig()->layout().layoutdata()) { if (f.has_track() && f.has_up_to_track() && ((logicalTrack < f.track()) || (logicalTrack > f.up_to_track()))) @@ -193,14 +193,14 @@ std::shared_ptr Layout::getLayoutOfTrack( layoutdata.MergeFrom(f); } - trackInfo->numTracks = globalConfig().layout().tracks(); - trackInfo->numSides = globalConfig().layout().sides(); + trackInfo->numTracks = globalConfig()->layout().tracks(); + trackInfo->numSides = globalConfig()->layout().sides(); trackInfo->sectorSize = layoutdata.sector_size(); trackInfo->logicalTrack = logicalTrack; trackInfo->logicalSide = logicalSide; trackInfo->physicalTrack = remapTrackLogicalToPhysical(logicalTrack); trackInfo->physicalSide = - logicalSide ^ globalConfig().layout().swap_sides(); + logicalSide ^ globalConfig()->layout().swap_sides(); trackInfo->groupSize = getTrackStep(); trackInfo->diskSectorOrder = expandSectorList(layoutdata.physical()); trackInfo->naturalSectorOrder = trackInfo->diskSectorOrder; diff --git a/lib/proto.cc b/lib/proto.cc index 4716889f..4cc9dd91 100644 --- a/lib/proto.cc +++ b/lib/proto.cc @@ -11,7 +11,7 @@ static ConfigProto config = []() return config; }(); -ConfigProto& globalConfig() +ConfigProto& globalConfigProto() { return config; } diff --git a/lib/proto.h b/lib/proto.h index 06637cd5..0b73425e 100644 --- a/lib/proto.h +++ b/lib/proto.h @@ -28,6 +28,6 @@ extern ConfigProto parseConfigBytes(const std::string_view& bytes); extern const std::map formats; -extern ConfigProto& globalConfig(); +extern ConfigProto& globalConfigProto(); #endif diff --git a/lib/readerwriter.cc b/lib/readerwriter.cc index 04a2e636..30b71e97 100644 --- a/lib/readerwriter.cc +++ b/lib/readerwriter.cc @@ -61,13 +61,13 @@ void measureDiskRotation( log(BeginSpeedOperationLogMessage()); int retries = 5; - usbSetDrive(globalConfig().drive().drive(), - globalConfig().drive().high_density(), - globalConfig().drive().index_mode()); - oneRevolution = globalConfig().drive().rotational_period_ms() * 1e6; - if (globalConfig().drive().hard_sector_count() != 0) + usbSetDrive(globalConfig()->drive().drive(), + globalConfig()->drive().high_density(), + globalConfig()->drive().index_mode()); + oneRevolution = globalConfig()->drive().rotational_period_ms() * 1e6; + if (globalConfig()->drive().hard_sector_count() != 0) hardSectorThreshold = oneRevolution * 3 / - (4 * globalConfig().drive().hard_sector_count()); + (4 * globalConfig()->drive().hard_sector_count()); else hardSectorThreshold = 0; @@ -77,15 +77,15 @@ void measureDiskRotation( do { oneRevolution = usbGetRotationalPeriod( - globalConfig().drive().hard_sector_count()); - if (globalConfig().drive().hard_sector_count() != 0) + globalConfig()->drive().hard_sector_count()); + if (globalConfig()->drive().hard_sector_count() != 0) hardSectorThreshold = oneRevolution * 3 / - (4 * globalConfig().drive().hard_sector_count()); + (4 * globalConfig()->drive().hard_sector_count()); retries--; } while ((oneRevolution == 0) && (retries > 0)); - globalConfig().mutable_drive()->set_rotational_period_ms( + globalConfig()->mutable_drive()->set_rotational_period_ms( oneRevolution / 1e6); log(EndOperationLogMessage{}); } @@ -191,7 +191,7 @@ BadSectorsState combineRecordAndSectors(TrackFlux& trackFlux, static void adjustTrackOnError(FluxSource& fluxSource, int baseTrack) { - switch (globalConfig().drive().error_behaviour()) + switch (globalConfig()->drive().error_behaviour()) { case DriveProto::NOTHING: break; @@ -217,7 +217,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder, ReadResult result = BAD_AND_CAN_NOT_RETRY; for (unsigned offset = 0; offset < trackInfo->groupSize; - offset += globalConfig().drive().head_width()) + offset += globalConfig()->drive().head_width()) { auto& fluxSourceIterator = fluxSourceIteratorHolder.getIterator( trackInfo->physicalTrack + offset, trackInfo->physicalSide); @@ -228,7 +228,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder, trackInfo->physicalTrack + offset, trackInfo->physicalSide}); std::shared_ptr fluxmap = fluxSourceIterator.next(); // ->rescale( - // 1.0 / globalConfig().flux_source().rescale()); + // 1.0 / globalConfig()->flux_source().rescale()); log(EndReadOperationLogMessage()); log("{0} ms in {1} bytes", (int)(fluxmap->duration() / 1e6), @@ -240,7 +240,7 @@ ReadResult readGroup(FluxSourceIteratorHolder& fluxSourceIteratorHolder, HAS_NO_BAD_SECTORS) { result = GOOD_READ; - if (globalConfig().decoder().skip_unnecessary_tracks()) + if (globalConfig()->decoder().skip_unnecessary_tracks()) return result; } else if (fluxSourceIterator.hasNext()) @@ -267,18 +267,18 @@ void writeTracks(FluxSink& fluxSink, testForEmergencyStop(); - int retriesRemaining = globalConfig().decoder().retries(); + int retriesRemaining = globalConfig()->decoder().retries(); for (;;) { for (int offset = 0; offset < trackInfo->groupSize; - offset += globalConfig().drive().head_width()) + offset += globalConfig()->drive().head_width()) { unsigned physicalTrack = trackInfo->physicalTrack + offset; log(BeginWriteOperationLogMessage{ physicalTrack, trackInfo->physicalSide}); - if (offset == globalConfig().drive().group_offset()) + if (offset == globalConfig()->drive().group_offset()) { auto fluxmap = producer(trackInfo); if (!fluxmap) @@ -454,7 +454,7 @@ std::shared_ptr readAndDecodeTrack(FluxSource& fluxSource, trackFlux->trackInfo = trackInfo; FluxSourceIteratorHolder fluxSourceIteratorHolder(fluxSource); - int retriesRemaining = globalConfig().decoder().retries(); + int retriesRemaining = globalConfig()->decoder().retries(); for (;;) { auto result = @@ -488,9 +488,9 @@ std::shared_ptr readDiskCommand( FluxSource& fluxSource, Decoder& decoder) { std::unique_ptr outputFluxSink; - if (globalConfig().decoder().has_copy_flux_to()) + if (globalConfig()->decoder().has_copy_flux_to()) outputFluxSink = - FluxSink::create(globalConfig().decoder().copy_flux_to()); + FluxSink::create(globalConfig()->decoder().copy_flux_to()); auto diskflux = std::make_shared(); @@ -516,7 +516,7 @@ std::shared_ptr readDiskCommand( *data->fluxmap); } - if (globalConfig().decoder().dump_records()) + if (globalConfig()->decoder().dump_records()) { std::vector> sorted_records; @@ -543,7 +543,7 @@ std::shared_ptr readDiskCommand( } } - if (globalConfig().decoder().dump_sectors()) + if (globalConfig()->decoder().dump_sectors()) { auto collected_sectors = collectSectors(trackFlux->sectors, false); std::vector> sorted_sectors( @@ -595,9 +595,9 @@ void readDiskCommand( auto diskflux = readDiskCommand(fluxsource, decoder); writer.printMap(*diskflux->image); - if (globalConfig().decoder().has_write_csv_to()) + if (globalConfig()->decoder().has_write_csv_to()) writer.writeCsv( - *diskflux->image, globalConfig().decoder().write_csv_to()); + *diskflux->image, globalConfig()->decoder().write_csv_to()); writer.writeMappedImage(*diskflux->image); } diff --git a/lib/usb/usb.cc b/lib/usb/usb.cc index c0c20d80..1a6c071e 100644 --- a/lib/usb/usb.cc +++ b/lib/usb/usb.cc @@ -23,9 +23,9 @@ static std::shared_ptr selectDevice() "no devices found (is one plugged in? Do you have the " "appropriate permissions?"); - if (globalConfig().usb().has_serial()) + if (globalConfig()->usb().has_serial()) { - auto wantedSerial = globalConfig().usb().serial(); + auto wantedSerial = globalConfig()->usb().serial(); for (auto& c : candidates) { if (c->serial == wantedSerial) @@ -63,10 +63,10 @@ USB* get_usb_impl() { /* Special case for certain configurations. */ - if (globalConfig().usb().has_greaseweazle() && - globalConfig().usb().greaseweazle().has_port()) + if (globalConfig()->usb().has_greaseweazle() && + globalConfig()->usb().greaseweazle().has_port()) { - const auto& conf = globalConfig().usb().greaseweazle(); + const auto& conf = globalConfig()->usb().greaseweazle(); log("Using GreaseWeazle on serial port {}", conf.port()); return createGreaseWeazleUsb(conf.port(), conf); } @@ -85,7 +85,7 @@ USB* get_usb_impl() candidate->serial, candidate->serialPort); return createGreaseWeazleUsb( - candidate->serialPort, globalConfig().usb().greaseweazle()); + candidate->serialPort, globalConfig()->usb().greaseweazle()); default: error("internal"); diff --git a/lib/vfs/amigaffs.cc b/lib/vfs/amigaffs.cc index afdb683b..4ca44f22 100644 --- a/lib/vfs/amigaffs.cc +++ b/lib/vfs/amigaffs.cc @@ -88,8 +88,8 @@ public: dev.readOnly = false; dev.isNativeDev = true; dev.devType = DEVTYPE_FLOPDD; - dev.cylinders = globalConfig().layout().tracks(); - dev.heads = globalConfig().layout().sides(); + dev.cylinders = globalConfig()->layout().tracks(); + dev.heads = globalConfig()->layout().sides(); dev.sectors = Layout::getLayoutOfTrack(0, 0)->numSectors; adfInitDevice(&dev, nullptr, false); int res = adfCreateFlop(&dev, (char*)volumeName.c_str(), 0); diff --git a/lib/vfs/cbmfs.cc b/lib/vfs/cbmfs.cc index 17b43ce8..d2c0ad7a 100644 --- a/lib/vfs/cbmfs.cc +++ b/lib/vfs/cbmfs.cc @@ -126,7 +126,7 @@ class CbmfsFilesystem : public Filesystem bam.resize(fs->getLogicalSectorCount()); usedBlocks = 0; unsigned block = 0; - for (int track = 0; track < globalConfig().layout().tracks(); + for (int track = 0; track < globalConfig()->layout().tracks(); track++) { uint8_t blocks = br.read_8(); diff --git a/lib/vfs/vfs.cc b/lib/vfs/vfs.cc index 21b08c8c..3df1db55 100644 --- a/lib/vfs/vfs.cc +++ b/lib/vfs/vfs.cc @@ -151,7 +151,7 @@ void Filesystem::discardChanges() Filesystem::Filesystem(std::shared_ptr sectors): _sectors(sectors) { - auto& layout = globalConfig().layout(); + auto& layout = globalConfig()->layout(); if (!layout.has_tracks() || !layout.has_sides()) error( "FS: filesystem support cannot be used without concrete layout " diff --git a/scripts/mkdocindex.cc b/scripts/mkdocindex.cc index 4eb91e15..6df9a3c4 100644 --- a/scripts/mkdocindex.cc +++ b/scripts/mkdocindex.cc @@ -7,16 +7,16 @@ extern const std::map formats; static std::string supportStatus(SupportStatus status) { - switch (status) - { - case SupportStatus::DINOSAUR: - return "🦖"; + switch (status) + { + case SupportStatus::DINOSAUR: + return "🦖"; - case SupportStatus::UNICORN: + case SupportStatus::UNICORN: return "🦄"; - } + } - return ""; + return ""; } int main(int argc, const char* argv[]) @@ -24,7 +24,7 @@ int main(int argc, const char* argv[]) fmt::print("\n"); fmt::print( "\n"); - fmt::print("\n"); + fmt::print("\n"); fmt::print("| Profile | Format | Read? | Write? | Filesystem? |\n"); fmt::print("|:--------|:-------|:-----:|:------:|:------------|\n"); diff --git a/src/fe-analysedriveresponse.cc b/src/fe-analysedriveresponse.cc index 5d9c5bc2..7ee72c01 100644 --- a/src/fe-analysedriveresponse.cc +++ b/src/fe-analysedriveresponse.cc @@ -20,7 +20,7 @@ static StringFlag destFlux({"--dest", "-d"}, [](const auto& value) { FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), value); + globalConfig()->mutable_flux_sink(), value); }); static IntFlag destTrack({"--cylinder", "-c"}, "track to write to", 0); @@ -247,15 +247,15 @@ static void draw_x_graticules(Agg2D& painter, int mainAnalyseDriveResponse(int argc, const char* argv[]) { - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig().flux_sink().type() != FluxSinkProto::DRIVE) + if (globalConfig()->flux_sink().type() != FluxSinkProto::DRIVE) error("this only makes sense with a real disk drive"); - usbSetDrive(globalConfig().drive().drive(), - globalConfig().drive().high_density(), - globalConfig().drive().index_mode()); + usbSetDrive(globalConfig()->drive().drive(), + globalConfig()->drive().high_density(), + globalConfig()->drive().index_mode()); usbSeek(destTrack); std::cout << "Measuring rotational speed...\n"; diff --git a/src/fe-inspect.cc b/src/fe-inspect.cc index 281b9ef2..c862af60 100644 --- a/src/fe-inspect.cc +++ b/src/fe-inspect.cc @@ -19,7 +19,7 @@ static StringFlag sourceFlux({"--source", "-s"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static IntFlag trackFlag({"--cylinder", "-c"}, "Track to read.", 0); @@ -132,11 +132,11 @@ static nanoseconds_t guessClock(const Fluxmap& fluxmap) int mainInspect(int argc, const char* argv[]) { - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, {}); std::unique_ptr fluxSource( - FluxSource::create(globalConfig().flux_source())); + FluxSource::create(globalConfig()->flux_source())); const auto fluxmap = fluxSource->readFlux(trackFlag, headFlag)->next(); std::cout << fmt::format("0x{:x} bytes of data in {:.3f}ms\n", @@ -220,7 +220,7 @@ int mainInspect(int argc, const char* argv[]) "\n\nAligned bitstream from {:.3f}ms follows:\n", fmr.tell().ns() / 1000000.0); - FluxDecoder decoder(&fmr, clockPeriod, globalConfig().decoder()); + FluxDecoder decoder(&fmr, clockPeriod, globalConfig()->decoder()); while (!fmr.eof()) { std::cout << fmt::format("{:06x} {: 10.3f} : ", @@ -245,7 +245,7 @@ int mainInspect(int argc, const char* argv[]) dumpRawFlag.get(), fmr.tell().ns() / 1000000.0); - FluxDecoder decoder(&fmr, clockPeriod, globalConfig().decoder()); + FluxDecoder decoder(&fmr, clockPeriod, globalConfig()->decoder()); for (int i = 0; i < dumpRawFlag; i++) decoder.readBit(); diff --git a/src/fe-rawread.cc b/src/fe-rawread.cc index bd0a55b3..2348b858 100644 --- a/src/fe-rawread.cc +++ b/src/fe-rawread.cc @@ -23,7 +23,7 @@ static StringFlag sourceFlux({"-s", "--source"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static StringFlag destFlux({"-d", "--dest"}, @@ -32,7 +32,7 @@ static StringFlag destFlux({"-d", "--dest"}, [](const auto& value) { FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), value); + globalConfig()->mutable_flux_sink(), value); }); static StringFlag srcTracks({"--cylinders", "-c"}, @@ -40,7 +40,7 @@ static StringFlag srcTracks({"--cylinders", "-c"}, "", [](const auto& value) { - setRange(globalConfig().mutable_tracks(), value); + setRange(globalConfig()->mutable_tracks(), value); }); static StringFlag srcHeads({"--heads", "-h"}, @@ -48,26 +48,26 @@ static StringFlag srcHeads({"--heads", "-h"}, "", [](const auto& value) { - setRange(globalConfig().mutable_heads(), value); + setRange(globalConfig()->mutable_heads(), value); }); int mainRawRead(int argc, const char* argv[]) { - setRange(globalConfig().mutable_tracks(), "0-79"); - setRange(globalConfig().mutable_heads(), "0-1"); + setRange(globalConfig()->mutable_tracks(), "0-79"); + setRange(globalConfig()->mutable_heads(), "0-1"); if (argc == 1) showProfiles("rawread", formats); - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig().flux_sink().type() == FluxSinkProto::DRIVE) + if (globalConfig()->flux_sink().type() == FluxSinkProto::DRIVE) error("you can't use rawread to write to hardware"); std::unique_ptr fluxSource( - FluxSource::create(globalConfig().flux_source())); + FluxSource::create(globalConfig()->flux_source())); std::unique_ptr fluxSink( - FluxSink::create(globalConfig().flux_sink())); + FluxSink::create(globalConfig()->flux_sink())); rawReadDiskCommand(*fluxSource, *fluxSink); diff --git a/src/fe-rawwrite.cc b/src/fe-rawwrite.cc index 2c5aa972..099a501d 100644 --- a/src/fe-rawwrite.cc +++ b/src/fe-rawwrite.cc @@ -18,7 +18,7 @@ static StringFlag sourceFlux({"--source", "-s"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static StringFlag destFlux({"--dest", "-d"}, @@ -27,7 +27,7 @@ static StringFlag destFlux({"--dest", "-d"}, [](const auto& value) { FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), value); + globalConfig()->mutable_flux_sink(), value); }); static StringFlag destTracks({"--cylinders", "-c"}, @@ -35,7 +35,7 @@ static StringFlag destTracks({"--cylinders", "-c"}, "", [](const auto& value) { - setRange(globalConfig().mutable_tracks(), value); + setRange(globalConfig()->mutable_tracks(), value); }); static StringFlag destHeads({"--heads", "-h"}, @@ -43,33 +43,33 @@ static StringFlag destHeads({"--heads", "-h"}, "", [](const auto& value) { - setRange(globalConfig().mutable_heads(), value); + setRange(globalConfig()->mutable_heads(), value); }); static ActionFlag eraseFlag({"--erase"}, "erases the destination", []() { - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::ERASE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::ERASE); }); int mainRawWrite(int argc, const char* argv[]) { - setRange(globalConfig().mutable_tracks(), "0-79"); - setRange(globalConfig().mutable_heads(), "0-1"); + setRange(globalConfig()->mutable_tracks(), "0-79"); + setRange(globalConfig()->mutable_heads(), "0-1"); if (argc == 1) showProfiles("rawwrite", formats); - globalConfig().mutable_flux_sink()->set_type(FluxSinkProto::DRIVE); + globalConfig()->mutable_flux_sink()->set_type(FluxSinkProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig().flux_source().type() == FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() == FluxSourceProto::DRIVE) error("you can't use rawwrite to read from hardware"); std::unique_ptr fluxSource( - FluxSource::create(globalConfig().flux_source())); + FluxSource::create(globalConfig()->flux_source())); std::unique_ptr fluxSink( - FluxSink::create(globalConfig().flux_sink())); + FluxSink::create(globalConfig()->flux_sink())); writeRawDiskCommand(*fluxSource, *fluxSink); return 0; diff --git a/src/fe-read.cc b/src/fe-read.cc index 6ecc95b6..1f529d44 100644 --- a/src/fe-read.cc +++ b/src/fe-read.cc @@ -23,7 +23,7 @@ static StringFlag sourceFlux({"-s", "--source"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static StringFlag destImage({"-o", "--output"}, @@ -32,7 +32,7 @@ static StringFlag destImage({"-o", "--output"}, [](const auto& value) { ImageWriter::updateConfigForFilename( - globalConfig().mutable_image_writer(), value); + globalConfig()->mutable_image_writer(), value); }); static StringFlag copyFluxTo({"--copy-flux-to"}, @@ -41,7 +41,7 @@ static StringFlag copyFluxTo({"--copy-flux-to"}, [](const auto& value) { FluxSink::updateConfigForFilename( - globalConfig().mutable_decoder()->mutable_copy_flux_to(), value); + globalConfig()->mutable_decoder()->mutable_copy_flux_to(), value); }); static StringFlag srcTracks({"--cylinders", "-c"}, @@ -49,7 +49,7 @@ static StringFlag srcTracks({"--cylinders", "-c"}, "", [](const auto& value) { - setRange(globalConfig().mutable_tracks(), value); + setRange(globalConfig()->mutable_tracks(), value); }); static StringFlag srcHeads({"--heads", "-h"}, @@ -57,24 +57,25 @@ static StringFlag srcHeads({"--heads", "-h"}, "", [](const auto& value) { - setRange(globalConfig().mutable_heads(), value); + setRange(globalConfig()->mutable_heads(), value); }); int mainRead(int argc, const char* argv[]) { if (argc == 1) showProfiles("read", formats); - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); - if (globalConfig().decoder().copy_flux_to().type() == FluxSinkProto::DRIVE) + if (globalConfig()->decoder().copy_flux_to().type() == FluxSinkProto::DRIVE) error("you cannot copy flux to a hardware device"); std::unique_ptr fluxSource( - FluxSource::create(globalConfig().flux_source())); - std::unique_ptr decoder(Decoder::create(globalConfig().decoder())); + FluxSource::create(globalConfig()->flux_source())); + std::unique_ptr decoder( + Decoder::create(globalConfig()->decoder())); std::unique_ptr writer( - ImageWriter::create(globalConfig().image_writer())); + ImageWriter::create(globalConfig()->image_writer())); readDiskCommand(*fluxSource, *decoder, *writer); diff --git a/src/fe-rpm.cc b/src/fe-rpm.cc index 762eefee..dfd75b7a 100644 --- a/src/fe-rpm.cc +++ b/src/fe-rpm.cc @@ -13,21 +13,21 @@ static StringFlag sourceFlux({"-s", "--source"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); int mainRpm(int argc, const char* argv[]) { flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig().flux_source().type() != FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE) error("this only makes sense with a real disk drive"); - usbSetDrive(globalConfig().drive().drive(), + usbSetDrive(globalConfig()->drive().drive(), false, - globalConfig().drive().index_mode()); + globalConfig()->drive().index_mode()); nanoseconds_t period = - usbGetRotationalPeriod(globalConfig().drive().hard_sector_count()); + usbGetRotationalPeriod(globalConfig()->drive().hard_sector_count()); if (period != 0) std::cout << "Rotational period is " << period / 1000000 << " ms (" << 60e9 / period << " rpm)" << std::endl; diff --git a/src/fe-seek.cc b/src/fe-seek.cc index a2667cca..afb6546c 100644 --- a/src/fe-seek.cc +++ b/src/fe-seek.cc @@ -13,7 +13,7 @@ static StringFlag sourceFlux({"-s", "--source"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static IntFlag track({"--cylinder", "-c"}, "track to seek to", 0); @@ -24,12 +24,12 @@ int mainSeek(int argc, const char* argv[]) { flags.parseFlagsWithConfigFiles(argc, argv, {}); - if (globalConfig().flux_source().type() != FluxSourceProto::DRIVE) + if (globalConfig()->flux_source().type() != FluxSourceProto::DRIVE) error("this only makes sense with a real disk drive"); - usbSetDrive(globalConfig().drive().drive(), + usbSetDrive(globalConfig()->drive().drive(), false, - globalConfig().drive().index_mode()); + globalConfig()->drive().index_mode()); usbSeek(track); return 0; } diff --git a/src/fe-write.cc b/src/fe-write.cc index 9c1fcfa6..721299ae 100644 --- a/src/fe-write.cc +++ b/src/fe-write.cc @@ -24,7 +24,7 @@ static StringFlag sourceImage({"--input", "-i"}, [](const auto& value) { ImageReader::updateConfigForFilename( - globalConfig().mutable_image_reader(), value); + globalConfig()->mutable_image_reader(), value); }); static StringFlag destFlux({"--dest", "-d"}, @@ -33,9 +33,9 @@ static StringFlag destFlux({"--dest", "-d"}, [](const auto& value) { FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), value); + globalConfig()->mutable_flux_sink(), value); FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); }); static StringFlag destTracks({"--cylinders", "-c"}, @@ -43,7 +43,7 @@ static StringFlag destTracks({"--cylinders", "-c"}, "", [](const auto& value) { - setRange(globalConfig().mutable_tracks(), value); + setRange(globalConfig()->mutable_tracks(), value); }); static StringFlag destHeads({"--heads", "-h"}, @@ -51,7 +51,7 @@ static StringFlag destHeads({"--heads", "-h"}, "", [](const auto& value) { - setRange(globalConfig().mutable_heads(), value); + setRange(globalConfig()->mutable_heads(), value); }); static ActionFlag noVerifyFlag({"--no-verify", "-n"}, @@ -65,27 +65,28 @@ int mainWrite(int argc, const char* argv[]) { if (argc == 1) showProfiles("write", formats); - globalConfig().mutable_flux_sink()->set_type(FluxSinkProto::DRIVE); + globalConfig()->mutable_flux_sink()->set_type(FluxSinkProto::DRIVE); if (verify) - globalConfig().mutable_flux_source()->set_type(FluxSourceProto::DRIVE); + globalConfig()->mutable_flux_source()->set_type(FluxSourceProto::DRIVE); flags.parseFlagsWithConfigFiles(argc, argv, formats); std::unique_ptr reader( - ImageReader::create(globalConfig().image_reader())); + ImageReader::create(globalConfig()->image_reader())); std::shared_ptr image = reader->readMappedImage(); - std::unique_ptr encoder(Encoder::create(globalConfig().encoder())); + std::unique_ptr encoder( + Encoder::create(globalConfig()->encoder())); std::unique_ptr fluxSink( - FluxSink::create(globalConfig().flux_sink())); + FluxSink::create(globalConfig()->flux_sink())); std::unique_ptr decoder; - if (globalConfig().has_decoder() && verify) - decoder = Decoder::create(globalConfig().decoder()); + if (globalConfig()->has_decoder() && verify) + decoder = Decoder::create(globalConfig()->decoder()); std::unique_ptr fluxSource; if (verify && - (globalConfig().flux_source().type() == FluxSourceProto::DRIVE)) - fluxSource = FluxSource::create(globalConfig().flux_source()); + (globalConfig()->flux_source().type() == FluxSourceProto::DRIVE)) + fluxSource = FluxSource::create(globalConfig()->flux_source()); writeDiskCommand( *image, *encoder, *fluxSink, decoder.get(), fluxSource.get()); diff --git a/src/fileutils.cc b/src/fileutils.cc index 821fa037..e9001c54 100644 --- a/src/fileutils.cc +++ b/src/fileutils.cc @@ -22,9 +22,9 @@ static StringFlag image({"-i", "--image"}, [](const auto& value) { ImageReader::updateConfigForFilename( - globalConfig().mutable_image_reader(), value); + globalConfig()->mutable_image_reader(), value); ImageWriter::updateConfigForFilename( - globalConfig().mutable_image_writer(), value); + globalConfig()->mutable_image_writer(), value); }); static StringFlag flux({"-f", "--flux"}, @@ -33,7 +33,7 @@ static StringFlag flux({"-f", "--flux"}, [](const auto& value) { FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), value); + globalConfig()->mutable_flux_source(), value); FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), value); + globalConfig()->mutable_flux_sink(), value); }); diff --git a/src/gui/explorerpanel.cc b/src/gui/explorerpanel.cc index 732c4d2d..e0b66d61 100644 --- a/src/gui/explorerpanel.cc +++ b/src/gui/explorerpanel.cc @@ -164,7 +164,7 @@ private: (desiredSide != _explorerSide)) { auto fluxSource = - FluxSource::create(globalConfig().flux_source()); + FluxSource::create(globalConfig()->flux_source()); _explorerFluxmap = fluxSource->readFlux(desiredTrack, desiredSide)->next(); _explorerTrack = desiredTrack; diff --git a/src/gui/idlepanel.cc b/src/gui/idlepanel.cc index dd2d5118..631acc28 100644 --- a/src/gui/idlepanel.cc +++ b/src/gui/idlepanel.cc @@ -180,7 +180,7 @@ public: if (formatSelection == wxNOT_FOUND) error("no format selected"); - globalConfig().Clear(); + globalConfig()->Clear(); auto formatName = _formatNames[formatChoice->GetSelection()]; FlagGroup::parseConfigFile(formatName, formats); @@ -196,9 +196,9 @@ public: auto serial = _selectedDevice; if (!serial.empty() && (serial[0] == '/')) - setProtoByString(&globalConfig(), "usb.greaseweazle.port", serial); + setProtoByString(globalConfig(), "usb.greaseweazle.port", serial); else - setProtoByString(&globalConfig(), "usb.serial", serial); + setProtoByString(globalConfig(), "usb.serial", serial); ClearLog(); @@ -208,15 +208,15 @@ public: { case SELECTEDSOURCE_REAL: { - globalConfig().mutable_drive()->set_high_density( + globalConfig()->mutable_drive()->set_high_density( _selectedHighDensity); - globalConfig().MergeFrom(*_selectedDriveType); + globalConfig()->MergeFrom(*_selectedDriveType); std::string filename = _selectedDrive ? "drive:1" : "drive:0"; FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), filename); + globalConfig()->mutable_flux_sink(), filename); FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), filename); + globalConfig()->mutable_flux_source(), filename); break; } @@ -224,9 +224,9 @@ public: case SELECTEDSOURCE_FLUX: { FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), _selectedFluxfilename); + globalConfig()->mutable_flux_sink(), _selectedFluxfilename); FluxSource::updateConfigForFilename( - globalConfig().mutable_flux_source(), + globalConfig()->mutable_flux_source(), _selectedFluxfilename); break; } @@ -234,10 +234,10 @@ public: case SELECTEDSOURCE_IMAGE: { ImageReader::updateConfigForFilename( - globalConfig().mutable_image_reader(), + globalConfig()->mutable_image_reader(), _selectedImagefilename); ImageWriter::updateConfigForFilename( - globalConfig().mutable_image_writer(), + globalConfig()->mutable_image_writer(), _selectedImagefilename); break; } @@ -258,7 +258,7 @@ public: { auto key = setting.substr(0, equals); auto value = setting.substr(equals + 1); - setProtoByString(&globalConfig(), key, value); + setProtoByString(globalConfig(), key, value); } else FlagGroup::parseConfigFile(setting, formats); @@ -589,12 +589,12 @@ private: formatOptionsContainer, wxID_ANY, "(no format selected)")); else { - globalConfig().Clear(); + globalConfig()->Clear(); std::string formatName = _formatNames[formatChoice->GetSelection()]; FlagGroup::parseConfigFile(formatName, formats); - for (auto& group : globalConfig().option_group()) + for (auto& group : globalConfig()->option_group()) { sizer->Add(new wxStaticText(formatOptionsContainer, wxID_ANY, @@ -646,7 +646,7 @@ private: /* Anything that's _not_ in a group gets a checkbox. */ - for (auto& option : globalConfig().option()) + for (auto& option : globalConfig()->option()) { auto* choice = new wxCheckBox( formatOptionsContainer, wxID_ANY, option.comment()); @@ -669,8 +669,8 @@ private: }); } - if (globalConfig().option().empty() && - globalConfig().option_group().empty()) + if (globalConfig()->option().empty() && + globalConfig()->option_group().empty()) sizer->Add(new wxStaticText(formatOptionsContainer, wxID_ANY, "(no options for this format)")); diff --git a/src/gui/imagerpanel.cc b/src/gui/imagerpanel.cc index dc8cd4d3..ccf6112c 100644 --- a/src/gui/imagerpanel.cc +++ b/src/gui/imagerpanel.cc @@ -99,8 +99,8 @@ public: Environment::reset(); auto fluxSource = - FluxSource::create(globalConfig().flux_source()); - auto decoder = Decoder::create(globalConfig().decoder()); + FluxSource::create(globalConfig()->flux_source()); + auto decoder = Decoder::create(globalConfig()->decoder()); auto diskflux = readDiskCommand(*fluxSource, *decoder); runOnUiThread( @@ -124,15 +124,13 @@ public: { SetPage(MainWindow::PAGE_IMAGER); PrepareConfig(); - if (!globalConfig().has_image_reader()) + if (!globalConfig()->has_image_reader()) error("This format cannot be read from images."); auto filename = wxFileSelector("Choose a image file to read", /* default_path= */ wxEmptyString, /* default_filename= */ - globalConfig() - .image_reader() - .filename(), + globalConfig()->image_reader().filename(), /* default_extension= */ wxEmptyString, /* wildcard= */ wxEmptyString, /* flags= */ wxFD_OPEN | wxFD_FILE_MUST_EXIST); @@ -140,9 +138,9 @@ public: return; ImageReader::updateConfigForFilename( - globalConfig().mutable_image_reader(), filename.ToStdString()); + globalConfig()->mutable_image_reader(), filename.ToStdString()); ImageWriter::updateConfigForFilename( - globalConfig().mutable_image_writer(), filename.ToStdString()); + globalConfig()->mutable_image_writer(), filename.ToStdString()); visualiser->Clear(); _currentDisk = nullptr; @@ -151,19 +149,19 @@ public: [this]() { auto image = - ImageReader::create(globalConfig().image_reader()) + ImageReader::create(globalConfig()->image_reader()) ->readMappedImage(); - auto encoder = Encoder::create(globalConfig().encoder()); + auto encoder = Encoder::create(globalConfig()->encoder()); auto fluxSink = - FluxSink::create(globalConfig().flux_sink()); + FluxSink::create(globalConfig()->flux_sink()); std::unique_ptr decoder; std::unique_ptr fluxSource; - if (globalConfig().has_decoder()) + if (globalConfig()->has_decoder()) { - decoder = Decoder::create(globalConfig().decoder()); + decoder = Decoder::create(globalConfig()->decoder()); fluxSource = - FluxSource::create(globalConfig().flux_source()); + FluxSource::create(globalConfig()->flux_source()); } writeDiskCommand(*image, @@ -250,16 +248,14 @@ public: { try { - if (!globalConfig().has_image_writer()) + if (!globalConfig()->has_image_writer()) error("This format cannot be saved."); auto filename = wxFileSelector("Choose the name of the image file to write", /* default_path= */ wxEmptyString, /* default_filename= */ - globalConfig() - .image_writer() - .filename(), + globalConfig()->image_writer().filename(), /* default_extension= */ wxEmptyString, /* wildcard= */ wxEmptyString, /* flags= */ wxFD_SAVE | wxFD_OVERWRITE_PROMPT); @@ -267,7 +263,7 @@ public: return; ImageWriter::updateConfigForFilename( - globalConfig().mutable_image_writer(), filename.ToStdString()); + globalConfig()->mutable_image_writer(), filename.ToStdString()); auto image = _currentDisk->image; @@ -275,7 +271,7 @@ public: [image, this]() { auto imageWriter = - ImageWriter::create(globalConfig().image_writer()); + ImageWriter::create(globalConfig()->image_writer()); imageWriter->writeMappedImage(*image); }); } @@ -300,7 +296,7 @@ public: return; FluxSink::updateConfigForFilename( - globalConfig().mutable_flux_sink(), filename.ToStdString()); + globalConfig()->mutable_flux_sink(), filename.ToStdString()); QueueJob( [this]() @@ -308,7 +304,7 @@ public: auto fluxSource = FluxSource::createMemoryFluxSource(*_currentDisk); auto fluxSink = - FluxSink::create(globalConfig().flux_sink()); + FluxSink::create(globalConfig()->flux_sink()); writeRawDiskCommand(*fluxSource, *fluxSink); }); } diff --git a/tests/cpmfs.cc b/tests/cpmfs.cc index 0d390026..e0423060 100644 --- a/tests/cpmfs.cc +++ b/tests/cpmfs.cc @@ -72,8 +72,8 @@ static void setBlock( static void testPartialExtent() { auto sectors = std::make_shared(); - auto fs = - Filesystem::createCpmFsFilesystem(globalConfig().filesystem(), sectors); + auto fs = Filesystem::createCpmFsFilesystem( + globalConfig()->filesystem(), sectors); setBlock(sectors, 0, @@ -92,8 +92,8 @@ static void testPartialExtent() static void testLogicalExtents() { auto sectors = std::make_shared(); - auto fs = - Filesystem::createCpmFsFilesystem(globalConfig().filesystem(), sectors); + auto fs = Filesystem::createCpmFsFilesystem( + globalConfig()->filesystem(), sectors); setBlock(sectors, 0, @@ -143,7 +143,7 @@ int main(void) } } )M"; - google::protobuf::TextFormat::MergeFromString(text, &globalConfig()); + google::protobuf::TextFormat::MergeFromString(text, globalConfig()); testPartialExtent(); testLogicalExtents(); diff --git a/tests/layout.cc b/tests/layout.cc index 4cc56018..cbf53b10 100644 --- a/tests/layout.cc +++ b/tests/layout.cc @@ -19,9 +19,9 @@ static std::string cleanup(const std::string& s) static void load_config(const std::string s) { - globalConfig().Clear(); + globalConfig()->Clear(); if (!google::protobuf::TextFormat::MergeFromString( - cleanup(s), &globalConfig())) + cleanup(s), globalConfig())) error("couldn't load test config"); }