From 368e897fbe3511e11d4e9aded84a9b7f895f229f Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 20 Nov 2022 09:35:13 -0700 Subject: [PATCH] fix tidy bugprone-reserved-identifier this was partially automatic and partially manual. --- gbser.cc | 12 ++++++------ gbser.h | 6 +++--- gbser_posix.cc | 22 +++++++++++----------- gbser_private.h | 6 +++--- gbser_win.cc | 20 ++++++++++---------- wbt-200.cc | 41 ++++++++++++++++++++++++++++------------- 6 files changed, 61 insertions(+), 46 deletions(-) diff --git a/gbser.cc b/gbser.cc index fe787000d..bda793e52 100644 --- a/gbser.cc +++ b/gbser.cc @@ -27,7 +27,7 @@ #include #include -void gbser__db(int l, const char* msg, ...) +void gbser_db(int l, const char* msg, ...) { va_list ap; va_start(ap, msg); @@ -109,7 +109,7 @@ int gbser_setup(void* handle, const char* spec) */ int gbser_avail(void* handle) { - return gbser__fill_buffer(handle, 1, nullptr); + return gbser_fill_buffer(handle, 1, nullptr); } /* Read as many bytes as are available without blocking. At most |len| @@ -121,7 +121,7 @@ int gbser_read(void* handle, void* buf, unsigned len) int got = 0; while (len > 0) { - int rc = gbser__fill_buffer(handle, len, nullptr); + int rc = gbser_fill_buffer(handle, len, nullptr); if (rc < 0) { /* error */ return rc; @@ -129,7 +129,7 @@ int gbser_read(void* handle, void* buf, unsigned len) /* nothing available */ break; } - got += gbser__read_buffer(handle, &buf, &len); + got += gbser_read_buffer(handle, &buf, &len); } return got; @@ -144,10 +144,10 @@ int gbser_read_wait(void* handle, void* buf, unsigned len, unsigned ms) while (len > 0 && ms != 0) { int rc; - if (rc = gbser__fill_buffer(handle, len, &ms), rc < 0) { + if (rc = gbser_fill_buffer(handle, len, &ms), rc < 0) { return rc; } - got += gbser__read_buffer(handle, &buf, &len); + got += gbser_read_buffer(handle, &buf, &len); } return got; diff --git a/gbser.h b/gbser.h index 46f4647e5..d6b332a5d 100644 --- a/gbser.h +++ b/gbser.h @@ -19,8 +19,8 @@ */ -#ifndef __GBSER_H -#define __GBSER_H +#ifndef GBSER_H_INCLUDED_ +#define GBSER_H_INCLUDED_ #include // for size_t @@ -136,4 +136,4 @@ int gbser_is_serial(const char* port_name); const char* fix_win_serial_name_r(const char* comname, char* obuf, size_t len); const char* fix_win_serial_name(const char* comname); -#endif /* GBSER_H */ +#endif /* GBSER_H_INCLUDED_ */ diff --git a/gbser_posix.cc b/gbser_posix.cc index a8b4f80dc..9cf9904e6 100644 --- a/gbser_posix.cc +++ b/gbser_posix.cc @@ -44,7 +44,7 @@ struct gbser_handle { }; /* Wrapper to safely cast a void * into a gbser_handle */ -static gbser_handle* gbser__get_handle(void* p) +static gbser_handle* gbser_get_handle(void* p) { auto* h = (gbser_handle*) p; assert(h->magic == MYMAGIC); @@ -133,7 +133,7 @@ void* gbser_init(const char* port_name) { gbser_handle* h; - gbser__db(4, "gbser_init(\"%s\")\n", port_name); + gbser_db(4, "gbser_init(\"%s\")\n", port_name); h = (gbser_handle*) xcalloc(sizeof *h, 1); h->magic = MYMAGIC; @@ -173,7 +173,7 @@ void* gbser_init(const char* port_name) */ void gbser_deinit(void* handle) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); tcsetattr(h->fd, TCSAFLUSH, &h->old_tio); close(h->fd); @@ -183,7 +183,7 @@ void gbser_deinit(void* handle) int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); speed_t s; static unsigned bit_flags[] = { @@ -251,9 +251,9 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, return tcsetattr(h->fd, TCSADRAIN, &h->new_tio) ? gbser_ERROR : gbser_OK; } -unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len) +unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); unsigned count = *len; auto* cp = (unsigned char*) *buf; if (count > h->inbuf_used) { @@ -276,10 +276,10 @@ unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len) * be updated to indicate the remaining time on exit. * Returns the number of bytes available (>=0) or an error code (<0). */ -int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) +int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms) { int rc; - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); if (want > BUFSIZE) { want = BUFSIZE; @@ -362,7 +362,7 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) */ int gbser_flush(void* handle) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); h->inbuf_used = 0; if (tcflush(h->fd, TCIFLUSH)) { return gbser_ERROR; @@ -375,7 +375,7 @@ int gbser_flush(void* handle) */ int gbser_write(void* handle, const void* buf, unsigned len) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); const char* bp = (const char*) buf; int rc; while (len > 0) { @@ -402,7 +402,7 @@ int gbser_is_serial(const char* port_name) int is_port = 0; if (fd = open(port_name, O_RDWR | O_NOCTTY), fd == -1) { - gbser__db(1, "Failed to open port (%s) to check its type\n", strerror(errno)); + gbser_db(1, "Failed to open port (%s) to check its type\n", strerror(errno)); return 0; } diff --git a/gbser_private.h b/gbser_private.h index 4c6a35abb..37c889eec 100644 --- a/gbser_private.h +++ b/gbser_private.h @@ -22,6 +22,6 @@ #define MYMAGIC 0x91827364 #define BUFSIZE 512 -void gbser__db(int l, const char* msg, ...); -int gbser__fill_buffer(void* h, unsigned want, unsigned* ms); -unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len); +void gbser_db(int l, const char* msg, ...); +int gbser_fill_buffer(void* h, unsigned want, unsigned* ms); +unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len); diff --git a/gbser_win.cc b/gbser_win.cc index f47ea88c3..3a19406a2 100644 --- a/gbser_win.cc +++ b/gbser_win.cc @@ -42,7 +42,7 @@ struct gbser_handle { #define DEV_PREFIX "\\\\.\\\\" /* Wrapper to safely cast a void * into a gbser_handle */ -static gbser_handle* gbser__get_handle(void* p) +static gbser_handle* gbser_get_handle(void* p) { gbser_handle* h = (gbser_handle*) p; assert(h->magic == MYMAGIC); @@ -182,7 +182,7 @@ void* gbser_init(const char* port_name) gbser_handle* h = (gbser_handle*) xcalloc(1, sizeof(*h)); const char* xname = fix_win_serial_name(port_name); - gbser__db(2, "Translated port name: \"%s\"\n", xname); + gbser_db(2, "Translated port name: \"%s\"\n", xname); h->magic = MYMAGIC; @@ -214,7 +214,7 @@ void* gbser_init(const char* port_name) */ void gbser_deinit(void* handle) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); CloseHandle(h->comport); @@ -223,7 +223,7 @@ void gbser_deinit(void* handle) int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, unsigned stop) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); DCB tio; if (bits < 5 || bits > 8) { @@ -266,9 +266,9 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, return gbser_OK; } -unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len) +unsigned gbser_read_buffer(void* handle, void** buf, unsigned* len) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); unsigned count = *len; unsigned char* cp = (unsigned char*) *buf; if (count > h->inbuf_used) { @@ -291,10 +291,10 @@ unsigned gbser__read_buffer(void* handle, void** buf, unsigned* len) * be updated to indicate the remaining time on exit. * Returns the number of bytes available (>=0) or an error code (<0). */ -int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) +int gbser_fill_buffer(void* handle, unsigned want, unsigned* ms) { int rc; - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); if (want > BUFSIZE) { want = BUFSIZE; @@ -353,7 +353,7 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) */ int gbser_flush(void* handle) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); h->inbuf_used = 0; if (!PurgeComm(h->comport, PURGE_RXCLEAR)) { return gbser_ERROR; @@ -365,7 +365,7 @@ int gbser_flush(void* handle) */ int gbser_write(void* handle, const void* buf, unsigned len) { - gbser_handle* h = gbser__get_handle(handle); + gbser_handle* h = gbser_get_handle(handle); DWORD nwritten; const char* bp = (const char*) buf; /* Not sure we need to spin here - but this'll work even if we don't */ diff --git a/wbt-200.cc b/wbt-200.cc index bc9164b38..7efd06ed8 100644 --- a/wbt-200.cc +++ b/wbt-200.cc @@ -18,11 +18,23 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include // for array +#include // for isprint +#include // for va_end, va_list, va_start +#include // for size_t, sprintf, fread, fclose, feof +#include // for uint32_t, int32_t, int16_t, uint16_t +#include // for strtod, strtoul +#include // for strlen, memcmp, memcpy +#include // for time_t, tm + +#include // for QByteArray +#include // for qPrintable +#include // for QString +#include // for QVector + #include "defs.h" -#include "gbser.h" -#include "grtcirc.h" -#include -#include +#include "gbser.h" // for gbser_set_port, gbser_deinit, gbse... + #define MYNAME "WBT-100/200" #define NL "\x0D\x0A" @@ -499,17 +511,20 @@ static double get_param_float(const char* cmd) } /* Decompose binary date into discreet fields */ -#define _SPLIT_DATE(tim) \ - int sec = (((tim) >> 0) & 0x3F); \ - int min = (((tim) >> 6) & 0x3F); \ - int hour = (((tim) >> 12) & 0x1F); \ - int mday = (((tim) >> 17) & 0x1F); \ - int mon = (((tim) >> 22) & 0x0F); \ - int year = (((tim) >> 26) & 0x3F); +std::array split_date(uint32_t tim) +{ + int sec = (((tim) >> 0) & 0x3F); + int min = (((tim) >> 6) & 0x3F); + int hour = (((tim) >> 12) & 0x1F); + int mday = (((tim) >> 17) & 0x1F); + int mon = (((tim) >> 22) & 0x0F); + int year = (((tim) >> 26) & 0x3F); + return {sec, min, hour, mday, mon, year}; +} static time_t decode_date(uint32_t tim) { - _SPLIT_DATE(tim) + auto [sec, min, hour, mday, mon, year] = split_date(tim); struct tm t; t.tm_sec = sec; @@ -524,7 +539,7 @@ static time_t decode_date(uint32_t tim) static int check_date(uint32_t tim) { - _SPLIT_DATE(tim) + auto [sec, min, hour, mday, mon, year] = split_date(tim); /* Sanity check the date. We don't allow years prior to 2004 because zero in * those bits will usually indicate that we have an altitude instead of a