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; }