From dc8a4036c834c20d8fdea9d49cb2b178d3a2fec2 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 8 Jul 2024 16:01:14 +0100 Subject: [PATCH] upd utility functions --- include/util.h | 4 ++-- src/ivmr.c | 2 +- src/util.c | 25 ++++++++++++------------- src/vmrcli.c | 2 +- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/util.h b/include/util.h index bbbab8c..7b0f7b4 100644 --- a/include/util.h +++ b/include/util.h @@ -8,8 +8,8 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -void remove_name_in_path(char *szPath); -int replace_multiple_space_with_one(char *s, size_t len); +void remove_last_part_of_path(char *szPath); +int replace_blanks_with_single_space(char *s, size_t len); char *kind_as_string(char *s, int kind, int n); char *version_as_string(char *, long v, int n); diff --git a/src/ivmr.c b/src/ivmr.c index f192bd8..806b7ed 100644 --- a/src/ivmr.c +++ b/src/ivmr.c @@ -211,7 +211,7 @@ static bool registry_get_voicemeeter_folder(char *szDir) if (rep != ERROR_SUCCESS) return false; // remove name to get the path only - remove_name_in_path(sss); + remove_last_part_of_path(sss); if (nnsize > 512) nnsize = 512; strncpy(szDir, sss, nnsize); diff --git a/src/util.c b/src/util.c index 31631e5..4bddd5f 100644 --- a/src/util.c +++ b/src/util.c @@ -11,24 +11,24 @@ #include #include +#include +#include #include "wrapper.h" #include "util.h" /** * @brief Removes the last part of a path * - * @param szPath Pointer to the path string + * @param fullpath The entire path */ -void remove_name_in_path(char *szPath) +void remove_last_part_of_path(char *fullpath) { - char *p = szPath; + char *p; - while (*p++) - ; - while (p > szPath && *p != '\\') - p--; - if (*p == '\\') + if ((p = strrchr(fullpath, '\\')) != NULL) + { *p = '\0'; + } } /** @@ -38,12 +38,12 @@ void remove_name_in_path(char *szPath) * @param len Current length of the string * @return int New length of the string */ -int replace_multiple_space_with_one(char *s, size_t len) +int replace_blanks_with_single_space(char *s, size_t len) { int j = 0; int count = 0; - if (len == 1 && (s[0] == ' ' || s[0] == '\t')) + if (len == 1 && isblank(s[0])) { s[0] = '\0'; return len; @@ -54,12 +54,11 @@ int replace_multiple_space_with_one(char *s, size_t len) for (int i = 0; s[i] != '\0'; i++) { - if (s[i] == ' ' || s[i] == '\t') + if (isblank(s[i])) { count++; } - - if (s[i] != ' ' && s[i] != '\t') + else { if (count >= 1) { diff --git a/src/vmrcli.c b/src/vmrcli.c index c54b71e..b22cb23 100644 --- a/src/vmrcli.c +++ b/src/vmrcli.c @@ -268,7 +268,7 @@ void parse_input(PT_VMR vmr, char *input, int len) { char *token; - replace_multiple_space_with_one(input, len); + replace_blanks_with_single_space(input, len); token = strtok(input, " "); while (token != NULL) {