code style

This commit is contained in:
John
2022-02-12 12:50:11 +01:00
parent 7ae43351da
commit d4ae0e9e46
5 changed files with 14 additions and 12 deletions
+7 -6
View File
@@ -193,8 +193,8 @@ static const struct argp_option argpoptions[] = {
{"latency", O_DEVLAT, "MSEC", 0, "Extra transfer latency in ms [0]", 0 },
{nullptr, 0, nullptr, 0, "Message configuration options:", 2 },
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTPS URL) [" CONFIG_PATH
"]", 0 },
{"configpath", 'c', "PATH", 0, "Read CSV config files from PATH (local folder or HTTPS URL) ["
CONFIG_PATH "]", 0 },
{"scanconfig", 's', "ADDR", OPTION_ARG_OPTIONAL, "Pick CSV config files matching initial scan (ADDR="
"\"none\" or empty for no initial scan message, \"full\" for full scan, or a single hex address to scan, "
"default is broadcast ident message). If combined with --checkconfig, you can add scan message data as "
@@ -202,7 +202,8 @@ static const struct argp_option argpoptions[] = {
{"configlang", O_CFGLNG, "LANG", 0,
"Prefer LANG in multilingual configuration files [system default language]", 0 },
{"checkconfig", O_CHKCFG, nullptr, 0, "Check config files, then stop", 0 },
{"dumpconfig", O_DMPCFG, "FORMAT", OPTION_ARG_OPTIONAL, "Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop", 0 },
{"dumpconfig", O_DMPCFG, "FORMAT", OPTION_ARG_OPTIONAL,
"Check and dump config files in FORMAT (\"json\" or \"csv\"), then stop", 0 },
{"pollinterval", O_POLINT, "SEC", 0, "Poll for data every SEC seconds (0=disable) [5]", 0 },
{"inject", 'i', nullptr, 0, "Inject remaining arguments as already seen messages (e.g. "
"\"FF08070400/0AB5454850303003277201\")", 0 },
@@ -1263,7 +1264,7 @@ int main(int argc, char* argv[]) {
if (len <= 1 || len > sizeof(envname)-3) { // no single char long args
continue;
}
for (size_t i=0; i<len; i++) {
for (size_t i=0; i < len; i++) {
envopt[i] = static_cast<char>(tolower(start[i]));
}
envopt[len] = 0;
@@ -1286,7 +1287,7 @@ int main(int argc, char* argv[]) {
opt.injectMessages = true; // for skipping unknown values
error_t err = argp_parse(&aargp, cnt, envargv, ARGP_PARSE_ARGV0|ARGP_SILENT|ARGP_IN_ORDER,
&idx, &opt);
if (err!=0 && idx==-1) { // ignore args for non-arg boolean options
if (err != 0 && idx == -1) { // ignore args for non-arg boolean options
logError(lf_main, "invalid/unknown argument in env: %s", envopt);
}
opt.injectMessages = false; // restore
@@ -1312,7 +1313,7 @@ int main(int argc, char* argv[]) {
logError(lf_main, "invalid configPath URL");
return EINVAL;
}
if (!s_configHttpClient.connect(configHost, configPort, proto=="https", PACKAGE_NAME "/" PACKAGE_VERSION)) {
if (!s_configHttpClient.connect(configHost, configPort, proto == "https", PACKAGE_NAME "/" PACKAGE_VERSION)) {
logError(lf_main, "invalid configPath URL");
return EINVAL;
}
+3 -3
View File
@@ -395,7 +395,7 @@ std::pair<string, int> makeField(const string& name, bool isField) {
void addPart(ostringstream& stack, int inField, vector<std::pair<string, int>>& parts) {
string str = stack.str();
if (inField == 1 && str == "_") {
inField = 0; // single "%_" pattern to reduce to "_"
inField = 0; // single "%_" pattern to reduce to "_"
} else if (inField == 2) {
str = "%{" + str;
inField = 0;
@@ -894,7 +894,7 @@ void MqttHandler::parseIntegration(const string& line) {
string value = line.substr(pos+1);
FileReader::trim(&value);
if (value.find('%') == string::npos) {
m_replacers.set(key, value); // constant value
m_replacers.set(key, value); // constant value
} else {
// simple variable
m_replacers.get(key).parse(value, false, false, emptyIfMissing);
@@ -1555,7 +1555,7 @@ void MqttHandler::run() {
if (!typeSwitchNames.empty()) {
vector<string> strs;
splitFields(typeSwitch, &strs);
for (size_t pos = 0; pos<strs.size() && pos < typeSwitchNames.size(); pos++) {
for (size_t pos = 0; pos < strs.size() && pos < typeSwitchNames.size(); pos++) {
values.set(typeSwitchNames[pos], strs[pos]);
}
}
+2 -1
View File
@@ -83,7 +83,8 @@ class MqttReplacer {
* is empty or not defined.
* @return true on success, false on malformed template string.
*/
bool parse(const string& templateStr, bool onlyKnown = false, bool noKnownDuplicates = false, bool emptyIfMissing = false);
bool parse(const string& templateStr, bool onlyKnown = false, bool noKnownDuplicates = false,
bool emptyIfMissing = false);
/**
* Ensure the default topic parts are present (circuit and message).