upd utility functions

This commit is contained in:
onyx-and-iris 2024-07-08 16:01:14 +01:00
parent 6b7e0afb91
commit dc8a4036c8
4 changed files with 16 additions and 17 deletions

View File

@ -8,8 +8,8 @@
#ifndef __UTIL_H__ #ifndef __UTIL_H__
#define __UTIL_H__ #define __UTIL_H__
void remove_name_in_path(char *szPath); void remove_last_part_of_path(char *szPath);
int replace_multiple_space_with_one(char *s, size_t len); int replace_blanks_with_single_space(char *s, size_t len);
char *kind_as_string(char *s, int kind, int n); char *kind_as_string(char *s, int kind, int n);
char *version_as_string(char *, long v, int n); char *version_as_string(char *, long v, int n);

View File

@ -211,7 +211,7 @@ static bool registry_get_voicemeeter_folder(char *szDir)
if (rep != ERROR_SUCCESS) if (rep != ERROR_SUCCESS)
return false; return false;
// remove name to get the path only // remove name to get the path only
remove_name_in_path(sss); remove_last_part_of_path(sss);
if (nnsize > 512) if (nnsize > 512)
nnsize = 512; nnsize = 512;
strncpy(szDir, sss, nnsize); strncpy(szDir, sss, nnsize);

View File

@ -11,24 +11,24 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "wrapper.h" #include "wrapper.h"
#include "util.h" #include "util.h"
/** /**
* @brief Removes the last part of a path * @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++) if ((p = strrchr(fullpath, '\\')) != NULL)
; {
while (p > szPath && *p != '\\')
p--;
if (*p == '\\')
*p = '\0'; *p = '\0';
}
} }
/** /**
@ -38,12 +38,12 @@ void remove_name_in_path(char *szPath)
* @param len Current length of the string * @param len Current length of the string
* @return int New 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 j = 0;
int count = 0; int count = 0;
if (len == 1 && (s[0] == ' ' || s[0] == '\t')) if (len == 1 && isblank(s[0]))
{ {
s[0] = '\0'; s[0] = '\0';
return len; 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++) for (int i = 0; s[i] != '\0'; i++)
{ {
if (s[i] == ' ' || s[i] == '\t') if (isblank(s[i]))
{ {
count++; count++;
} }
else
if (s[i] != ' ' && s[i] != '\t')
{ {
if (count >= 1) if (count >= 1)
{ {

View File

@ -268,7 +268,7 @@ void parse_input(PT_VMR vmr, char *input, int len)
{ {
char *token; char *token;
replace_multiple_space_with_one(input, len); replace_blanks_with_single_space(input, len);
token = strtok(input, " "); token = strtok(input, " ");
while (token != NULL) while (token != NULL)
{ {