parse_path
This commit is contained in:
37
backend.c
37
backend.c
@@ -131,5 +131,40 @@ char* parse_cmd(const char *cmd, file *f){
|
|||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user