-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-json-escape-initializer-list.c
More file actions
63 lines (57 loc) · 2.38 KB
/
create-json-escape-initializer-list.c
File metadata and controls
63 lines (57 loc) · 2.38 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
Copyright (C) 2024-2025 sys4 AG
Author Boris Lohner bl@sys4.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program.
If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
void print_license() {
printf("/*\n\
Copyright (C) 2024-2025 sys4 AG\n\
Author Boris Lohner bl@sys4.de\n\
\n\
This program is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU Lesser General Public License as\n\
published by the Free Software Foundation, either version 3 of the\n\
License, or (at your option) any later version.\n\
\n\
This program is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU Lesser General Public License for more details.\n\
\n\
You should have received a copy of the GNU Lesser General Public\n\
License along with this program.\n\
If not, see <http://www.gnu.org/licenses/>.\n\
*/\n\
\n\
");
}
int main(void) {
print_license();
const char* sep="const char *tlsrpt_json_escape_values[256]={\n";
for(int i=0; i<256; ++i) {
if(((unsigned char)i)=='\b') printf("%s \"\\\\b\"",sep);
else if(((unsigned char)i)=='\f') printf("%s \"\\\\f\"",sep);
else if(((unsigned char)i)=='\n') printf("%s \"\\\\n\"",sep);
else if(((unsigned char)i)=='\r') printf("%s \"\\\\r\"",sep);
else if(((unsigned char)i)=='\t') printf("%s \"\\\\t\"",sep);
else if(((unsigned char)i)=='\\') printf("%s \"\\\\\\\\\"",sep);
else if(((unsigned char)i)=='"') printf("%s \"\\\\\\\"\"",sep);
else if(i==127 || i<32) printf("%s \"\\\\u%04x\"",sep,i);
else if(i>127) printf("%s \"\\x%02x\"",sep,i);
else printf("%s \"%c\"",sep,i);
if(i%8==7) sep=",\n";
else sep=",";
}
printf("};\n");
}