parse_cmd now using file name strings rather than file struct

This commit is contained in:
nova
2026-06-25 22:42:43 +02:00
parent 441e02e289
commit 94ca039248
3 changed files with 40 additions and 45 deletions
+9 -11
View File
@@ -81,26 +81,24 @@ char* smartstrcasestr(const char *haystack, const char *needle){
}
char* parse_cmd(const char *cmd, file *f){
char* parse_cmd(const char *cmd, char *file_name){
char *out;
if (f == NULL) {
out = malloc(strlen(cmd)+1);
memcpy(out, cmd, strlen(cmd)+1);
return out;
if (file_name == NULL) {
return NULL;
}
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
int count = 0;
char *pos;
unsigned long i = 0;
while(f->file_name[i]) {
if (f->file_name[i] == '\'') {
while(file_name[i]) {
if (file_name[i] == '\'') {
count++;
}
i++;
}
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 3);
out = malloc(strlen(cmd) + 1 + (strlen(file_name)+(count*3)) + 3);
pos = out;
if (offset) {
@@ -115,13 +113,13 @@ char* parse_cmd(const char *cmd, file *f){
pos++;
i = 0;
while(f->file_name[i]) {
if (f->file_name[i] == '\'') {
while(file_name[i]) {
if (file_name[i] == '\'') {
*pos++ = '\'';
*pos++ = '\\';
*pos++ = '\'';
}
*pos = f->file_name[i];
*pos = file_name[i];
pos++;
i++;
}