string escaping
This commit is contained in:
65
backend.c
65
backend.c
@@ -80,27 +80,54 @@ char* smartstrcasestr(const char *haystack, const char *needle){
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* parse_cmd_char(const char *cmd, const char *path){
|
||||
char *index = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||
char *out;
|
||||
|
||||
if (index) {
|
||||
out = malloc(strlen(cmd) + 1 + strlen(path) + 1);
|
||||
char *o = out;
|
||||
memcpy(out, cmd, index - cmd);
|
||||
o += index-cmd;
|
||||
*o = '\"';
|
||||
o++;
|
||||
memcpy(o, path, strlen(path));
|
||||
o += strlen(path);
|
||||
*o = '\"';
|
||||
memcpy(o+1, index + 1, strlen(index+1));
|
||||
*(o+strlen(index+1)+1) = '\0';
|
||||
return out;
|
||||
char* parse_cmd(const char *cmd, file *f){
|
||||
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||
|
||||
int count = 0;
|
||||
char *out;
|
||||
char *pos;
|
||||
unsigned long i = 0;
|
||||
while(f->file_name[i]) {
|
||||
if (f->file_name[i] == '\'') {
|
||||
count++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 1);
|
||||
|
||||
pos = out;
|
||||
if (offset) {
|
||||
memcpy(pos, cmd, offset - cmd);
|
||||
pos += offset - cmd + 1;
|
||||
} else {
|
||||
concat(out, cmd, " ./\"", 0);
|
||||
concat(out, out, path, 1);
|
||||
concat(out, out, "\"", 1);
|
||||
memcpy(pos, cmd, strlen(cmd));
|
||||
pos += strlen(cmd) + 1;
|
||||
}
|
||||
pos[-1] = ' ';
|
||||
pos[0] = '\'';
|
||||
pos++;
|
||||
|
||||
i = 0;
|
||||
while(f->file_name[i]) {
|
||||
if (f->file_name[i] == '\'') {
|
||||
*pos++ = '\'';
|
||||
*pos++ = '\\';
|
||||
*pos++ = '\'';
|
||||
}
|
||||
*pos = f->file_name[i];
|
||||
pos++;
|
||||
i++;
|
||||
}
|
||||
*pos = '\'';
|
||||
|
||||
if (offset) {
|
||||
pos[1]= ' ';
|
||||
memcpy(pos + 1, offset+1, strlen(offset+1));
|
||||
pos[strlen(offset+1)] = '\0';
|
||||
} else {
|
||||
pos[1] = '\0';
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user