From fca4e3e7e0b2630f25996d89746e1a4ad4ea60ef Mon Sep 17 00:00:00 2001 From: judfs Date: Mon, 17 Jul 2023 17:10:54 -0400 Subject: [PATCH 1/3] lcm-logger: Fix -l option --- lcm-logger/lcm_logger.c | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/lcm-logger/lcm_logger.c b/lcm-logger/lcm_logger.c index b0b8f5a8..50a147cb 100644 --- a/lcm-logger/lcm_logger.c +++ b/lcm-logger/lcm_logger.c @@ -424,64 +424,71 @@ int main(int argc, char *argv[]) logger.append = 0; char *lcmurl = NULL; - char *optstring = "fic:shm:vu:qa"; - int c; + + // Arg Parsing: + // https://www.gnu.org/software/libc/manual/html_node/Getopt.html + char *optstring = "ac:fhil:m:qsu:v"; + + // Keep sorted based on the 4th (`val`) arg which needs to be a unique character (int) per + // option. + // If a short option is desired, it must be placed above in the optstring. struct option long_opts[] = { + {"append", no_argument, 0, 'a'}, {"split-mb", required_argument, 0, 'b'}, {"channel", required_argument, 0, 'c'}, {"force", no_argument, 0, 'f'}, {"increment", required_argument, 0, 'i'}, {"lcm-url", required_argument, 0, 'l'}, {"max-unwritten-mb", required_argument, 0, 'm'}, + {"quiet", no_argument, 0, 'q'}, {"rotate", required_argument, 0, 'r'}, {"strftime", required_argument, 0, 's'}, - {"quiet", no_argument, 0, 'q'}, - {"append", no_argument, 0, 'a'}, - {"invert-channels", no_argument, 0, 'v'}, {"flush-interval", required_argument, 0, 'u'}, + {"invert-channels", no_argument, 0, 'v'}, {0, 0, 0, 0}, }; + int c; while ((c = getopt_long(argc, argv, optstring, long_opts, 0)) >= 0) { switch (c) { - case 'b': + case 'b': /* --split-mb */ logger.auto_split_mb = strtod(optarg, NULL); if (logger.auto_split_mb <= 0) { usage(); return 1; } break; - case 'f': + case 'f': /* force */ logger.force_overwrite = 1; break; - case 'c': + case 'c': /* --channel */ free(chan_regex); chan_regex = strdup(optarg); break; - case 'i': + case 'i': /* --increment */ logger.auto_increment = 1; break; - case 's': + case 's': /* strftime */ logger.use_strftime = 1; break; - case 'l': + case 'l': /* --lcm-url */ free(lcmurl); lcmurl = strdup(optarg); break; - case 'q': + case 'q': /* quiet */ logger.quiet = 1; break; - case 'v': + case 'v': /* --invert-channels */ logger.invert_channels = 1; break; - case 'm': + case 'm': /* --invert-channels */ max_write_queue_size_mb = strtod(optarg, NULL); if (max_write_queue_size_mb <= 0) { usage(); return 1; } break; - case 'r': { + case 'r': { /* --rotate */ char *eptr = NULL; logger.rotate = strtol(optarg, &eptr, 10); if (*eptr) { @@ -489,18 +496,18 @@ int main(int argc, char *argv[]) return 1; } } break; - case 'u': + case 'u': /* --flush-interval */ logger.fflush_interval_ms = atol(optarg); if (logger.fflush_interval_ms <= 0) { usage(); return 1; } break; - case 'a': + case 'a': /* --append */ logger.append = 1; break; case 'h': - default: + default: /* implicit --help */ usage(); return 1; }; From 5338826d30349f13b22d154be98e0df9466f0d36 Mon Sep 17 00:00:00 2001 From: judfs Date: Mon, 17 Jul 2023 17:30:33 -0400 Subject: [PATCH 2/3] Ran formating modified: lcm-logger/glib_util.c modified: lcm-logger/lcm_logger.c modified: lcm/eventlog.c modified: lcm/ioutils.h modified: liblcm-test/lcm-logfilter.c modified: test/c/common.c modified: test/cpp/common.cpp --- lcm-logger/glib_util.c | 6 +++--- lcm-logger/lcm_logger.c | 4 ++-- lcm/eventlog.c | 2 +- lcm/ioutils.h | 2 +- liblcm-test/lcm-logfilter.c | 4 ++-- test/c/common.c | 4 ++-- test/cpp/common.cpp | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lcm-logger/glib_util.c b/lcm-logger/glib_util.c index 24b4f5b7..6453ee36 100644 --- a/lcm-logger/glib_util.c +++ b/lcm-logger/glib_util.c @@ -121,9 +121,9 @@ int signal_pipe_attach_glib(signal_pipe_glib_handler_t func, gpointer user_data) return -1; g_sp.ioc = g_io_channel_unix_new(g_sp.fds[0]); - g_io_channel_set_flags( - g_sp.ioc, (GIOFlags) (g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL); - g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition) (G_IO_IN | G_IO_PRI), + g_io_channel_set_flags(g_sp.ioc, + (GIOFlags)(g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL); + g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition)(G_IO_IN | G_IO_PRI), (GIOFunc) signal_handler_glib, NULL); g_sp.userfunc = func; diff --git a/lcm-logger/lcm_logger.c b/lcm-logger/lcm_logger.c index 50a147cb..d5e072bb 100644 --- a/lcm-logger/lcm_logger.c +++ b/lcm-logger/lcm_logger.c @@ -425,7 +425,7 @@ int main(int argc, char *argv[]) char *lcmurl = NULL; - // Arg Parsing: + // Arg Parsing: // https://www.gnu.org/software/libc/manual/html_node/Getopt.html char *optstring = "ac:fhil:m:qsu:v"; @@ -537,7 +537,7 @@ int main(int argc, char *argv[]) } logger.time0 = g_get_real_time(); - logger.max_write_queue_size = (int64_t) (max_write_queue_size_mb * (1 << 20)); + logger.max_write_queue_size = (int64_t)(max_write_queue_size_mb * (1 << 20)); if (0 != open_logfile(&logger)) return 1; diff --git a/lcm/eventlog.c b/lcm/eventlog.c index a59fec9a..5e5e154e 100644 --- a/lcm/eventlog.c +++ b/lcm/eventlog.c @@ -187,7 +187,7 @@ int lcm_eventlog_seek_to_timestamp(lcm_eventlog_t *l, int64_t timestamp) while (1) { frac = 0.5 * (frac1 + frac2); - off_t offset = (off_t) (frac * file_len); + off_t offset = (off_t)(frac * file_len); fseeko(l->f, offset, SEEK_SET); cur_time = get_event_time(l); if (cur_time < 0) diff --git a/lcm/ioutils.h b/lcm/ioutils.h index 3c86e035..58571c6b 100644 --- a/lcm/ioutils.h +++ b/lcm/ioutils.h @@ -59,7 +59,7 @@ static inline int fread64(FILE *f, int64_t *v64) // See Section 5.8 paragraph 3 of the standard // http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf // use uint for shifting instead if int - *v64 = (int64_t) (((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff); + *v64 = (int64_t)(((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff); return 0; } diff --git a/liblcm-test/lcm-logfilter.c b/liblcm-test/lcm-logfilter.c index 3e05a193..2b97e0f2 100644 --- a/liblcm-test/lcm-logfilter.c +++ b/liblcm-test/lcm-logfilter.c @@ -60,14 +60,14 @@ int main(int argc, char **argv) double start_time = strtod(optarg, &eptr); if (*eptr != 0) usage(); - start_utime = (int64_t) (start_time * 1000000); + start_utime = (int64_t)(start_time * 1000000); } break; case 'e': { char *eptr = NULL; double end_time = strtod(optarg, &eptr); if (*eptr != 0) usage(); - end_utime = (int64_t) (end_time * 1000000); + end_utime = (int64_t)(end_time * 1000000); have_end_utime = 1; } break; case 'i': diff --git a/test/c/common.c b/test/c/common.c index cd1e8876..fedc3169 100644 --- a/test/c/common.c +++ b/test/c/common.c @@ -200,7 +200,7 @@ int check_lcmtest_primitives_list_t(const lcmtest_primitives_list_t *msg, int ex const lcmtest_primitives_t *ex = &msg->items[n]; CHECK_FIELD(ex->i8, -(n % 100), "%d"); CHECK_FIELD(ex->i16, -n * 10, "%d"); - CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64); + CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64); CHECK_FIELD(ex->position[0], (double) -n, "%f"); CHECK_FIELD(ex->position[1], (double) -n, "%f"); CHECK_FIELD(ex->position[2], (double) -n, "%f"); @@ -269,7 +269,7 @@ int check_lcmtest_primitives_t(const lcmtest_primitives_t *msg, int expected) int n = expected; CHECK_FIELD(msg->i8, n % 100, "%d"); CHECK_FIELD(msg->i16, n * 10, "%d"); - CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64); + CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64); CHECK_FIELD(msg->position[0], (double) n, "%f"); CHECK_FIELD(msg->position[1], (double) n, "%f"); CHECK_FIELD(msg->position[2], (double) n, "%f"); diff --git a/test/cpp/common.cpp b/test/cpp/common.cpp index 5a7ade50..1bc1aa81 100644 --- a/test/cpp/common.cpp +++ b/test/cpp/common.cpp @@ -182,7 +182,7 @@ int CheckLcmType(const lcmtest::primitives_list_t *msg, int expected) const lcmtest::primitives_t *ex = &msg->items[n]; CHECK_FIELD(ex->i8, -(n % 100), "%d"); CHECK_FIELD(ex->i16, -n * 10, "%d"); - CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64); + CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64); CHECK_FIELD(ex->position[0], (double) -n, "%f"); CHECK_FIELD(ex->position[1], (double) -n, "%f"); CHECK_FIELD(ex->position[2], (double) -n, "%f"); @@ -246,7 +246,7 @@ int CheckLcmType(const lcmtest::primitives_t *msg, int expected) int n = expected; CHECK_FIELD(msg->i8, n % 100, "%d"); CHECK_FIELD(msg->i16, n * 10, "%d"); - CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64); + CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64); CHECK_FIELD(msg->position[0], (double) n, "%f"); CHECK_FIELD(msg->position[1], (double) n, "%f"); CHECK_FIELD(msg->position[2], (double) n, "%f"); From 48bbec12a5086438bd210cf50c25ef0cfe394c61 Mon Sep 17 00:00:00 2001 From: judfs Date: Sat, 5 Aug 2023 13:30:46 -0400 Subject: [PATCH 3/3] Format with clang-format-12 --- lcm-logger/glib_util.c | 6 +++--- lcm-logger/lcm_logger.c | 3 ++- lcm/eventlog.c | 2 +- lcm/ioutils.h | 2 +- liblcm-test/lcm-logfilter.c | 4 ++-- test/c/common.c | 4 ++-- test/cpp/common.cpp | 4 ++-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lcm-logger/glib_util.c b/lcm-logger/glib_util.c index 6453ee36..24b4f5b7 100644 --- a/lcm-logger/glib_util.c +++ b/lcm-logger/glib_util.c @@ -121,9 +121,9 @@ int signal_pipe_attach_glib(signal_pipe_glib_handler_t func, gpointer user_data) return -1; g_sp.ioc = g_io_channel_unix_new(g_sp.fds[0]); - g_io_channel_set_flags(g_sp.ioc, - (GIOFlags)(g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL); - g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition)(G_IO_IN | G_IO_PRI), + g_io_channel_set_flags( + g_sp.ioc, (GIOFlags) (g_io_channel_get_flags(g_sp.ioc) | G_IO_FLAG_NONBLOCK), NULL); + g_sp.ios = g_io_add_watch(g_sp.ioc, (GIOCondition) (G_IO_IN | G_IO_PRI), (GIOFunc) signal_handler_glib, NULL); g_sp.userfunc = func; diff --git a/lcm-logger/lcm_logger.c b/lcm-logger/lcm_logger.c index d5e072bb..e0887721 100644 --- a/lcm-logger/lcm_logger.c +++ b/lcm-logger/lcm_logger.c @@ -427,6 +427,7 @@ int main(int argc, char *argv[]) // Arg Parsing: // https://www.gnu.org/software/libc/manual/html_node/Getopt.html + // https://linux.die.net/man/3/getopt char *optstring = "ac:fhil:m:qsu:v"; // Keep sorted based on the 4th (`val`) arg which needs to be a unique character (int) per @@ -537,7 +538,7 @@ int main(int argc, char *argv[]) } logger.time0 = g_get_real_time(); - logger.max_write_queue_size = (int64_t)(max_write_queue_size_mb * (1 << 20)); + logger.max_write_queue_size = (int64_t) (max_write_queue_size_mb * (1 << 20)); if (0 != open_logfile(&logger)) return 1; diff --git a/lcm/eventlog.c b/lcm/eventlog.c index 5e5e154e..a59fec9a 100644 --- a/lcm/eventlog.c +++ b/lcm/eventlog.c @@ -187,7 +187,7 @@ int lcm_eventlog_seek_to_timestamp(lcm_eventlog_t *l, int64_t timestamp) while (1) { frac = 0.5 * (frac1 + frac2); - off_t offset = (off_t)(frac * file_len); + off_t offset = (off_t) (frac * file_len); fseeko(l->f, offset, SEEK_SET); cur_time = get_event_time(l); if (cur_time < 0) diff --git a/lcm/ioutils.h b/lcm/ioutils.h index 58571c6b..3c86e035 100644 --- a/lcm/ioutils.h +++ b/lcm/ioutils.h @@ -59,7 +59,7 @@ static inline int fread64(FILE *f, int64_t *v64) // See Section 5.8 paragraph 3 of the standard // http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/n4527.pdf // use uint for shifting instead if int - *v64 = (int64_t)(((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff); + *v64 = (int64_t) (((uint64_t) v1) << 32) | (((int64_t) v2) & 0xffffffff); return 0; } diff --git a/liblcm-test/lcm-logfilter.c b/liblcm-test/lcm-logfilter.c index 2b97e0f2..3e05a193 100644 --- a/liblcm-test/lcm-logfilter.c +++ b/liblcm-test/lcm-logfilter.c @@ -60,14 +60,14 @@ int main(int argc, char **argv) double start_time = strtod(optarg, &eptr); if (*eptr != 0) usage(); - start_utime = (int64_t)(start_time * 1000000); + start_utime = (int64_t) (start_time * 1000000); } break; case 'e': { char *eptr = NULL; double end_time = strtod(optarg, &eptr); if (*eptr != 0) usage(); - end_utime = (int64_t)(end_time * 1000000); + end_utime = (int64_t) (end_time * 1000000); have_end_utime = 1; } break; case 'i': diff --git a/test/c/common.c b/test/c/common.c index fedc3169..cd1e8876 100644 --- a/test/c/common.c +++ b/test/c/common.c @@ -200,7 +200,7 @@ int check_lcmtest_primitives_list_t(const lcmtest_primitives_list_t *msg, int ex const lcmtest_primitives_t *ex = &msg->items[n]; CHECK_FIELD(ex->i8, -(n % 100), "%d"); CHECK_FIELD(ex->i16, -n * 10, "%d"); - CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64); + CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64); CHECK_FIELD(ex->position[0], (double) -n, "%f"); CHECK_FIELD(ex->position[1], (double) -n, "%f"); CHECK_FIELD(ex->position[2], (double) -n, "%f"); @@ -269,7 +269,7 @@ int check_lcmtest_primitives_t(const lcmtest_primitives_t *msg, int expected) int n = expected; CHECK_FIELD(msg->i8, n % 100, "%d"); CHECK_FIELD(msg->i16, n * 10, "%d"); - CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64); + CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64); CHECK_FIELD(msg->position[0], (double) n, "%f"); CHECK_FIELD(msg->position[1], (double) n, "%f"); CHECK_FIELD(msg->position[2], (double) n, "%f"); diff --git a/test/cpp/common.cpp b/test/cpp/common.cpp index 1bc1aa81..5a7ade50 100644 --- a/test/cpp/common.cpp +++ b/test/cpp/common.cpp @@ -182,7 +182,7 @@ int CheckLcmType(const lcmtest::primitives_list_t *msg, int expected) const lcmtest::primitives_t *ex = &msg->items[n]; CHECK_FIELD(ex->i8, -(n % 100), "%d"); CHECK_FIELD(ex->i16, -n * 10, "%d"); - CHECK_FIELD(ex->i64, (int64_t)(-n * 10000), "%" PRId64); + CHECK_FIELD(ex->i64, (int64_t) (-n * 10000), "%" PRId64); CHECK_FIELD(ex->position[0], (double) -n, "%f"); CHECK_FIELD(ex->position[1], (double) -n, "%f"); CHECK_FIELD(ex->position[2], (double) -n, "%f"); @@ -246,7 +246,7 @@ int CheckLcmType(const lcmtest::primitives_t *msg, int expected) int n = expected; CHECK_FIELD(msg->i8, n % 100, "%d"); CHECK_FIELD(msg->i16, n * 10, "%d"); - CHECK_FIELD(msg->i64, (int64_t)(n * 10000), "%" PRId64); + CHECK_FIELD(msg->i64, (int64_t) (n * 10000), "%" PRId64); CHECK_FIELD(msg->position[0], (double) n, "%f"); CHECK_FIELD(msg->position[1], (double) n, "%f"); CHECK_FIELD(msg->position[2], (double) n, "%f");