Skip to content

Commit

Permalink
fix previous commit, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Oct 1, 2023
1 parent 22b6f02 commit acc6edd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/ebusd/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/lib/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
18 changes: 11 additions & 7 deletions src/lib/utils/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utils/arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIB_UTILS_ARGS_H_
#define LIB_UTILS_ARGS_H_
#ifndef LIB_UTILS_ARG_H_
#define LIB_UTILS_ARG_H_

namespace ebusd {

Expand Down Expand Up @@ -94,4 +94,4 @@ void argHelp(const argParseOpt *parseOpt);

} // namespace ebusd

#endif // LIB_UTILS_ARGS_H_
#endif // LIB_UTILS_ARG_H_
8 changes: 4 additions & 4 deletions src/tools/ebuspicloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit acc6edd

Please sign in to comment.