From b7fa15d87d41994093180bde5a6e1536bf2b9ffc Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 3 Jul 2024 12:58:34 +0100 Subject: [PATCH] log_warn an incorrect -D arg. log_fatal possible exit points. --- include/vmr.h | 1 + src/vmrcli.c | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/include/vmr.h b/include/vmr.h index 0f1776d..111c502 100644 --- a/include/vmr.h +++ b/include/vmr.h @@ -6,6 +6,7 @@ enum kind { + UNKNOWN = -1, BASIC = 1, BANANA, POTATO, diff --git a/src/vmrcli.c b/src/vmrcli.c index 0d9e6c9..75b6215 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -36,7 +36,7 @@ struct result void help(void); enum kind set_kind(char *kval); -int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind); +int init_voicemeeter(T_VBVMR_INTERFACE *vmr, enum kind kind); void interactive(T_VBVMR_INTERFACE *vmr); void parse_input(T_VBVMR_INTERFACE *vmr, char *input, int len); void parse_command(T_VBVMR_INTERFACE *vmr, char *command); @@ -46,11 +46,10 @@ bool vflag = false; int main(int argc, char *argv[]) { - bool iflag = false; - bool mflag = false; - bool sflag = false; + bool iflag = false, + mflag = false, + sflag = false; int opt; - char *kvalue = ""; int dvalue; enum kind kind = BANANAX64; @@ -70,8 +69,12 @@ int main(int argc, char *argv[]) help(); exit(EXIT_SUCCESS); case 'k': - kvalue = optarg; - kind = set_kind(kvalue); + kind = set_kind(optarg); + if (kind == UNKNOWN) + { + log_fatal("Unknown Voicemeeter kind '%s'", optarg); + exit(EXIT_FAILURE); + } break; case 'm': mflag = true; @@ -90,7 +93,7 @@ int main(int argc, char *argv[]) } else { - log_error( + log_warn( "-D arg out of range, expected value from 0 up to 5\n" "Log level will default to LOG_WARN (3).\n"); } @@ -193,8 +196,7 @@ enum kind set_kind(char *kval) } else { - log_error("Unknown Voicemeeter kind '%s'\n", kval); - exit(EXIT_FAILURE); + return UNKNOWN; } } @@ -206,18 +208,18 @@ enum kind set_kind(char *kval) * @param kind * @return int */ -int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind) +int init_voicemeeter(T_VBVMR_INTERFACE *vmr, enum kind kind) { int rep = initialize_dll_interfaces(vmr); if (rep < 0) { if (rep == -100) { - log_error("Voicemeeter is not installed"); + log_fatal("Voicemeeter is not installed"); } else { - log_error("Error loading Voicemeeter dll with code %d\n", rep); + log_fatal("Error loading Voicemeeter dll with code %d\n", rep); } return rep; } @@ -225,7 +227,7 @@ int init_voicemeeter(T_VBVMR_INTERFACE *vmr, int kind) rep = login(vmr, kind); if (rep != 0) { - log_error("Error logging into Voicemeeter"); + log_fatal("Error logging into Voicemeeter"); return rep; }