RestorerZ | e214692 | 2023-11-23 20:58:32 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Simplistic program to correct Big5 inside strings. When a trail byte is a |
| 3 | * backslash it needs to be doubled. |
| 4 | * Public domain. |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * 06.11.23, added by Restorer: |
| 9 | * For more details, see: |
| 10 | * https://github.com/vim/vim/pull/3261 |
| 11 | * https://github.com/vim/vim/pull/3476 |
| 12 | * https://github.com/vim/vim/pull/12153 |
| 13 | * (read all comments) |
| 14 | * |
| 15 | * I checked the workability on the list of backslash characters |
| 16 | * specified in zh_TW.UTF-8.po. It works. |
| 17 | * But it is better to have someone native speaker check it. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <string.h> |
| 23 | |
| 24 | int |
| 25 | main(int argc, char **argv) |
| 26 | { |
| 27 | char buffer[BUFSIZ]; |
| 28 | char *p; |
| 29 | |
| 30 | while (fgets(buffer, BUFSIZ, stdin) != NULL) |
| 31 | { |
| 32 | for (p = buffer; *p != 0; p++) |
| 33 | { |
| 34 | if (strncmp(p, "charset=utf-8", 13) == 0 |
| 35 | || strncmp(p, "charset=UTF-8", 13) == 0) |
| 36 | { |
| 37 | fputs("charset=BIG-5", stdout); |
| 38 | p += 12; |
| 39 | } |
| 40 | else if (strncmp(p, "# Original translations", 23) == 0) |
| 41 | { |
| 42 | fputs("# Generated from zh_TW.UTF-8.po, DO NOT EDIT.", stdout); |
| 43 | while (p[1] != '\n') |
| 44 | ++p; |
| 45 | } |
| 46 | else |
| 47 | { |
| 48 | if (*(unsigned char *)p >= 0xA1) |
| 49 | { |
| 50 | putchar(*p++); |
| 51 | if (*p == '\\') |
| 52 | putchar(*p); |
| 53 | } |
| 54 | putchar(*p); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |