Browse Source

xlate: for generating sed scripts for translations

vampirefrog 3 weeks ago
parent
commit
dd0ab51095
2 changed files with 34 additions and 0 deletions
  1. 3
    0
      .gitignore
  2. 31
    0
      xlate.c

+ 3
- 0
.gitignore View File

@@ -1 +1,4 @@
1 1
 *.sublime-workspace
2
+xlate
3
+xlate.exe
4
+*.exe

+ 31
- 0
xlate.c View File

@@ -0,0 +1,31 @@
1
+#include <stdio.h>
2
+#include <string.h>
3
+
4
+int main(int argc, char **argv) {
5
+	char buf[512];
6
+	while(fgets(buf, sizeof(buf), stdin)) {
7
+		char *from = buf;
8
+		char *to = strchr(buf, '\t');
9
+		if(!to) continue;
10
+		*to = 0;
11
+		to++;
12
+
13
+		char *end = strchr(to, '\n');
14
+		if(end) *end = 0;
15
+
16
+		printf("s/");
17
+		for(unsigned char *c = from; *c; c++) {
18
+			if(*c > 127) printf("\\x%02x", *c);
19
+			else if(strchr("$.*[\\^/", *c)) printf("\\%c", *c);
20
+			else printf("%c", *c);
21
+		}
22
+		printf("/");
23
+		for(unsigned char *c = to; *c; c++) {
24
+			if(*c == '/') printf("\\%c", *c);
25
+			else printf("%c", *c);
26
+		}
27
+		printf("/g\n");
28
+	}
29
+
30
+	return 0;
31
+}

Loading…
Cancel
Save