Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Simplistic program to correct SJIS inside strings. When a trail byte is a |
| 3 | * backslash it needs to be doubled. |
| 4 | * Public domain. |
| 5 | */ |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | |
| 9 | int |
| 10 | main(argc, argv) |
| 11 | int argc; |
| 12 | char **argv; |
| 13 | { |
| 14 | char buffer[BUFSIZ]; |
| 15 | char *p; |
| 16 | |
| 17 | while (fgets(buffer, BUFSIZ, stdin) != NULL) |
| 18 | { |
| 19 | for (p = buffer; *p != 0; p++) |
| 20 | { |
| 21 | if (strncmp(p, "charset=euc-jp", 14) == 0) |
| 22 | { |
| 23 | fputs("charset=cp932", stdout); |
| 24 | p += 13; |
| 25 | } |
| 26 | else if (strncmp(p, "ja.po - Japanese message file", 29) == 0) |
| 27 | { |
| 28 | fputs("ja.sjis.po - Japanese message file for Vim (version 6.x)\n", stdout); |
| 29 | fputs("# generated from ja.po, DO NOT EDIT", stdout); |
| 30 | while (p[1] != '\n') |
| 31 | ++p; |
| 32 | } |
| 33 | else if (*(unsigned char *)p == 0x81 && p[1] == '_') |
| 34 | { |
| 35 | putchar('\\'); |
| 36 | ++p; |
| 37 | } |
| 38 | else |
| 39 | { |
| 40 | if (*p & 0x80) |
| 41 | { |
| 42 | putchar(*p++); |
| 43 | if (*p == '\\') |
| 44 | putchar(*p); |
| 45 | } |
| 46 | putchar(*p); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |