1
0
mirror of https://gittea.dev/nova/th.git synced 2026-01-30 16:50:10 -05:00

better string handling

This commit is contained in:
nova
2025-12-12 20:28:39 +01:00
parent 217884d920
commit 393864c80f
4 changed files with 65 additions and 40 deletions

View File

@@ -1,5 +1,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "config.h"
#define concat(out, s1, s2, _free) { \
concat## _free(out, s1, s2); \
@@ -78,3 +80,29 @@ char* smartstrcasestr(const char *haystack, const char *needle){
return ret;
}
char* parse_cmd_char(const char *cmd, const char *path){
char *index = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
char *out;
if (index) {
out = malloc(strlen(cmd) + 1 + strlen(path) + 1);
char *o = out;
memcpy(out, cmd, index - cmd);
o += index-cmd;
*o = '\"';
o++;
memcpy(o, path, strlen(path));
o += strlen(path);
*o = '\"';
memcpy(o+1, index + 1, strlen(index+1));
*(o+strlen(index+1)+1) = '\0';
return out;
} else {
concat(out, cmd, " ./\"", 0);
concat(out, out, path, 1);
concat(out, out, "\"", 1);
}
return out;
}