From e84502b443222722b11354369d86d0c52843b0d5 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sat, 4 Jun 2022 08:53:44 -0500 Subject: [PATCH] Add rig_error2 for single-line debug message output --- include/hamlib/rig.h | 2 ++ src/rig.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index e9c8bdce8..7ba49bda3 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -3253,6 +3253,8 @@ rig_passband_wide HAMLIB_PARAMS((RIG *rig, extern HAMLIB_EXPORT(const char *) rigerror HAMLIB_PARAMS((int errnum)); +extern HAMLIB_EXPORT(const char *) +rigerror2 HAMLIB_PARAMS((int errnum)); extern HAMLIB_EXPORT(int) rig_setting2idx HAMLIB_PARAMS((setting_t s)); diff --git a/src/rig.c b/src/rig.c index 579dace78..44bab1f06 100644 --- a/src/rig.c +++ b/src/rig.c @@ -390,6 +390,21 @@ void add2debugmsgsave(const char *s) * * \todo support gettext/localization */ +const char *HAMLIB_API rigerror2(int errnum) // returns single-line message +{ + errnum = abs(errnum); + + if (errnum >= ERROR_TBL_SZ) + { + // This should not happen, but if it happens don't return NULL + return "ERR_OUT_OF_RANGE"; + } + + static char msg[DEBUGMSGSAVE_SIZE]; + snprintf(msg, sizeof(msg), "%s\n", rigerror_table[errnum]); + return msg; +} + const char *HAMLIB_API rigerror(int errnum) { errnum = abs(errnum); @@ -795,7 +810,7 @@ int HAMLIB_API rig_open(RIG *rig) rs->rigport.rig = rig; rs->rigport_deprecated.rig = rig; - if (strcmp(rs->rigport.pathname,"USB")==0) + if (strcmp(rs->rigport.pathname, "USB") == 0) { rig_debug(RIG_DEBUG_ERR, "%s: 'USB' is not a valid COM port name\n", __func__); errno = 2;