From acc6eddbba75d5a941a589b72a3a39708242c8d8 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 1 Oct 2023 14:29:11 +0200 Subject: [PATCH] fix previous commit, formatting --- src/ebusd/mainloop.cpp | 5 +++-- src/lib/utils/Makefile.am | 1 + src/lib/utils/arg.cpp | 18 +++++++++++------- src/lib/utils/arg.h | 6 +++--- src/tools/ebuspicloader.cpp | 8 ++++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index c457431e..48e83c4f 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -208,7 +208,7 @@ MainLoop::~MainLoop() { void MainLoop::shutdown() { m_shutdown = true; if (m_requestQueue != nullptr) { - m_requestQueue->push(nullptr); // just to notify potentially waiting thread + m_requestQueue->push(nullptr); // just to notify potentially waiting thread } } @@ -314,7 +314,8 @@ void MainLoop::run() { if (scanCompleted > SCAN_REPEAT_COUNT) { // repeat failed scan only every Nth time scanCompleted = 0; scanRetry++; - logNotice(lf_main, "scan completed %d time(s), %s", scanRetry, scanRetry <= m_scanRetries ? "check again" : "end"); + logNotice(lf_main, "scan completed %d time(s), %s", scanRetry, + scanRetry <= m_scanRetries ? "check again" : "end"); } } else { m_scanStatus = SCAN_STATUS_RUNNING; diff --git a/src/lib/utils/Makefile.am b/src/lib/utils/Makefile.am index b4814602..a8a9e070 100755 --- a/src/lib/utils/Makefile.am +++ b/src/lib/utils/Makefile.am @@ -5,6 +5,7 @@ AM_CXXFLAGS = -I$(top_srcdir)/src \ noinst_LIBRARIES = libutils.a libutils_a_SOURCES = \ + arg.h arg.cpp \ log.h log.cpp \ tcpsocket.h tcpsocket.cpp \ thread.h thread.cpp \ diff --git a/src/lib/utils/arg.cpp b/src/lib/utils/arg.cpp index f6ae7712..4e9683de 100755 --- a/src/lib/utils/arg.cpp +++ b/src/lib/utils/arg.cpp @@ -48,7 +48,8 @@ void calcCounts(const argDef *argDefs, int &count, int &shortCharsCount, int &sh } } -void buildOpts(const argDef *argDefs, int &count, int &shortCharsCount, int &shortOptsCount, struct option *longOpts, char *shortChars, int *shortIndexes, char *shortOpts, int argDefIdx) { +void buildOpts(const argDef *argDefs, int &count, int &shortCharsCount, int &shortOptsCount, + struct option *longOpts, char *shortChars, int *shortIndexes, char *shortOpts, int argDefIdx) { struct option *opt = longOpts+count; for (const argDef *arg = argDefs; arg && arg->help; arg++, argDefIdx++) { if (!arg->name) { @@ -108,15 +109,19 @@ int argParse(const argParseOpt *parseOpt, int argc, char **argv, int *argIndex) shortOpts[shortOptsCount++] = '+'; // posix mode to stop at first non-option shortOpts[shortOptsCount++] = ':'; // return ':' for missing option if (!(parseOpt->flags & af_noHelp)) { - buildOpts(helpArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0xff00); + buildOpts(helpArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, + shortIndexes, shortOpts, 0xff00); } if (!(parseOpt->flags & af_noVersion)) { - buildOpts(versionArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0xff01); + buildOpts(versionArgDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, + shortIndexes, shortOpts, 0xff01); } - buildOpts(parseOpt->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0); + buildOpts(parseOpt->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, + shortIndexes, shortOpts, 0); int children = 0; for (const argParseChildOpt *child = parseOpt->childOpts; child && child->argDefs; child++) { - buildOpts(child->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, shortIndexes, shortOpts, 0x100*(++children)); + buildOpts(child->argDefs, count, shortCharsCount, shortOptsCount, longOpts, shortChars, + shortIndexes, shortOpts, 0x100*(++children)); } optind = 1; // setting to 0 does not work int c = 0, longIdx = -1, ret = 0; @@ -320,8 +325,7 @@ void argHelp(const argParseOpt *parseOpt) { } printf("Usage: %s [OPTION...] %s\n", parseOpt->name, - parseOpt->positional ? parseOpt->positional : "" - ); + parseOpt->positional ? parseOpt->positional : ""); wrap(parseOpt->help, 0, 0); printArgs(parseOpt->argDefs, indent); for (const argParseChildOpt *child = parseOpt->childOpts; child && child->argDefs; child++) { diff --git a/src/lib/utils/arg.h b/src/lib/utils/arg.h index f8abb3d9..4a43c6fe 100755 --- a/src/lib/utils/arg.h +++ b/src/lib/utils/arg.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef LIB_UTILS_ARGS_H_ -#define LIB_UTILS_ARGS_H_ +#ifndef LIB_UTILS_ARG_H_ +#define LIB_UTILS_ARG_H_ namespace ebusd { @@ -94,4 +94,4 @@ void argHelp(const argParseOpt *parseOpt); } // namespace ebusd -#endif // LIB_UTILS_ARGS_H_ +#endif // LIB_UTILS_ARG_H_ diff --git a/src/tools/ebuspicloader.cpp b/src/tools/ebuspicloader.cpp index 5ce3cc72..35d27bc6 100644 --- a/src/tools/ebuspicloader.cpp +++ b/src/tools/ebuspicloader.cpp @@ -1053,7 +1053,7 @@ int readSettings(int fd, uint8_t* currentData = nullptr) { // non-mask bits outside of |gw reach uint8_t mask = maskLen <= 24 ? 0 : (255^((1 << (8 - (maskLen-24))) - 1)); ip[3] |= ((~mask)^0x1f) | (gw&0x1f); - if (maskLen<24) { + if (maskLen < 24) { // more than just the last IP byte are affected: set non-mask bits to 1 as well in bytes 0-2 for (uint8_t pos = 0, maskRemain = maskLen; pos < 3; pos++, maskRemain -= maskRemain >= 8 ? 8 : maskRemain) { mask = maskRemain >= 8 ? 255 : maskRemain == 0 ? 0 : (255^((1 << (8 - maskRemain)) - 1)); @@ -1107,7 +1107,7 @@ int readSettings(int fd, uint8_t* currentData = nullptr) { } else { std::cout << ", ignore hardware jumpers"; } - if ((configData[5]&0x07)==0x07) { + if ((configData[5]&0x07) == 0x07) { std::cout << " (default)"; } std::cout << std::endl; @@ -1144,7 +1144,7 @@ bool writeSettings(int fd, uint8_t* currentData = nullptr) { } if (setVariant) { configData[5] = (configData[5]&0x38) | (setVariantForced?0:0x04) | (setVariantValue&0x03); - if (setVariantValue==0) { + if (setVariantValue == 0) { configData[1] = (configData[1]&~0x1f); // set mask=0 to disable Ethernet } } @@ -1191,7 +1191,7 @@ int main(int argc, char* argv[]) { std::cerr << "incomplete IP arguments" << std::endl; arg_index = argc; // force help output } - if (argc-arg_index < 1) { + if (arg_index < 0 || argc-arg_index < 1) { if (flashFile) { printFileChecksum(); exit(EXIT_SUCCESS);