From 9e8bd3c0228b1a2d6954167d274b60c789eb8e4a Mon Sep 17 00:00:00 2001 From: nova Date: Thu, 14 May 2026 23:10:06 +0200 Subject: [PATCH] parse_path --- backend.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/backend.c b/backend.c index b296f75..0fa6bd3 100644 --- a/backend.c +++ b/backend.c @@ -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; }