Browse Source

xlate: for generating sed scripts for translations

master
vampirefrog 2 years ago
parent
commit
dd0ab51095
  1. 3
      .gitignore
  2. 31
      xlate.c

3
.gitignore vendored

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

31
xlate.c

@ -0,0 +1,31 @@
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char buf[512];
while(fgets(buf, sizeof(buf), stdin)) {
char *from = buf;
char *to = strchr(buf, '\t');
if(!to) continue;
*to = 0;
to++;
char *end = strchr(to, '\n');
if(end) *end = 0;
printf("s/");
for(unsigned char *c = from; *c; c++) {
if(*c > 127) printf("\\x%02x", *c);
else if(strchr("$.*[\\^/", *c)) printf("\\%c", *c);
else printf("%c", *c);
}
printf("/");
for(unsigned char *c = to; *c; c++) {
if(*c == '/') printf("\\%c", *c);
else printf("%c", *c);
}
printf("/g\n");
}
return 0;
}
Loading…
Cancel
Save