parse_path

This commit is contained in:
nova
2026-05-14 23:10:06 +02:00
parent f40cc91cce
commit 9e8bd3c022

View File

@@ -131,5 +131,40 @@ char* parse_cmd(const char *cmd, file *f){
}
return out;
}
char* parse_path(char *path){
int count = 0;
char *out;
char *pos;
unsigned long i = 0;
while(path[i]) {
if (path[i] == '\'') {
count++;
}
i++;
}
out = malloc((strlen(path)+(count*3)) + 4);
pos = out;
pos++;
out[0] = '\'';
i = 0;
while(path[i]) {
if (path[i] == '\'') {
*pos++ = '\'';
*pos++ = '\\';
*pos++ = '\'';
}
*pos = path[i];
pos++;
i++;
}
pos[0] = '\'';
pos[1]= ' ';
pos[2] = '\0';
return out;
}