-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.cpp
38 lines (35 loc) · 1.22 KB
/
util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "util.h"
#include "common.h"
int error(const char *errs, ...) {
va_list args;
va_start(args, errs);
vprintf(errs, args); puts("");
va_end(args);
exit(0);
return 0;
}
char *replace_escape(char *str) {
int l = strlen(str);
for(int i = 0; i < l; i++) {
if(str[i] == '\\') {
i++; switch(str[i]) {
case 'a': str[i]='\a'; memmove(&str[i-1], &str[i], l); i--; break;
case 'n': str[i]='\n'; memmove(&str[i-1], &str[i], l); i--; break;
case 't': str[i]='\t'; memmove(&str[i-1], &str[i], l); i--; break;
case 'f': str[i]='\f'; memmove(&str[i-1], &str[i], l); i--; break;
case 'r': str[i]='\r'; memmove(&str[i-1], &str[i], l); i--; break;
case 'b': str[i]='\b'; memmove(&str[i-1], &str[i], l); i--; break;
case 'x': {
char hex[3]={str[i+1], str[i+2]}, *e=nullptr;
str[i+2]=strtol(hex, &e, 16);
memmove(&str[i-1], &str[i+2], l - 2 + 1);
i -= 2;
} break;
case '\\': str[i]='\\'; memmove(&str[i-1], &str[i], l); i--; break;
case '\'': str[i]='\''; memmove(&str[i-1], &str[i], l); i--; break;
case '\"': str[i]='\"'; memmove(&str[i-1], &str[i], l); i--; break;
}
}
}
return str;
}