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:
28
backend.c
28
backend.c
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user