Unified · Split
| @@ -0,0 +1,34 @@ | |||
| 1 | /* https://en.wikipedia.org/wiki/Code_page_437 */ | ||
| 2 | #include "tagspriv.h" | ||
| 3 | |||
| 4 | static Rune rh[] = | ||
| 5 | L"ΔÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧" | ||
| 6 | L"ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│d┤╡╢╖╕╣║╗╝╜" | ||
| 7 | L"╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌" | ||
| 8 | L"▐▀αßeΓπfΣgσµhτΦΘΩiδj∞φkεl∩≡±≥≤⌠m" | ||
| 9 | L"⌡÷≈°∙n·√oⁿ²■ "; | ||
| 10 | |||
| 11 | int | ||
| 12 | cp437toutf8(char *o, int osz, const char *s, int sz) | ||
| 13 | { | ||
| 14 | char c[UTFmax]; | ||
| 15 | int i, n; | ||
| 16 | Rune r; | ||
| 17 | |||
| 18 | for(i = 0; i < sz && osz > 1 && s[i] != 0; i++){ | ||
| 19 | if((uchar)s[i] < 127){ | ||
| 20 | *o++ = s[i]; | ||
| 21 | osz--; | ||
| 22 | continue; | ||
| 23 | } | ||
| 24 | r = rh[(uchar)s[i] - 127]; | ||
| 25 | if((n = runetochar(c, &r)) >= osz) | ||
| 26 | break; | ||
| 27 | memmove(o, c, n); | ||
| 28 | o += n; | ||
| 29 | osz -= n; | ||
| 30 | } | ||
| 31 | |||
| 32 | *o = 0; | ||
| 33 | return i; | ||
| 34 | } | ||
| @@ -3,12 +3,13 @@ · 2 unmodified lines | |||
| 3 | int | 3 | int |
| 4 | tagit(Tagctx *ctx) | 4 | tagit(Tagctx *ctx) |
| 5 | { | 5 | { |
| 6 | char d[4+26+1]; | 6 | char d[4+26+1], o[26*UTFmax+1]; |
| 7 | 7 | ||
| 8 | if(ctx->read(ctx, d, 4+26) != 4+26 || memcmp(d, "IMPM", 4) != 0) | 8 | if(ctx->read(ctx, d, 4+26) != 4+26 || memcmp(d, "IMPM", 4) != 0) |
| 9 | return -1; | 9 | return -1; |
| 10 | d[4+26] = 0; | 10 | d[4+26] = 0; |
| 11 | txtcb(ctx, Ttitle, "", d+4); | 11 | cp437toutf8(o, sizeof(o), d+4, 26); |
| 12 | txtcb(ctx, Ttitle, "", o); | ||
| 12 | 13 | ||
| 13 | return 0; | 14 | return 0; |
| 14 | } | 15 | } |
| @@ -2,6 +2,7 @@ · 1 unmodified line | |||
| 2 | LIB=/$objtype/lib/libtags.a | 2 | LIB=/$objtype/lib/libtags.a |
| 3 | 3 | ||
| 4 | OFILES=\ | 4 | OFILES=\ |
| 5 | 437.$O\ | ||
| 5 | 8859.$O\ | 6 | 8859.$O\ |
| 6 | flac.$O\ | 7 | flac.$O\ |
| 7 | id3genres.$O\ | 8 | id3genres.$O\ |
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "tagspriv.h" | 1 | #include "tagspriv.h" |
| 2 | 2 | ||
| 3 | /* insane. */ | 3 | /* insane. */ |
| 4 | static char* variants[] = | 4 | static char *variants[] = |
| 5 | { | 5 | { |
| 6 | "M.K.", | 6 | "M.K.", |
| 7 | "M!K!", | 7 | "M!K!", |
| @@ -24,23 +24,25 @@ static char* variants[] = · 16 unmodified lines | |||
| 24 | int | 24 | int |
| 25 | tagmod(Tagctx *ctx) | 25 | tagmod(Tagctx *ctx) |
| 26 | { | 26 | { |
| 27 | char d[20+1]; | 27 | char d[20], o[20*UTFmax+1]; |
| 28 | int i; | 28 | int i; |
| 29 | 29 | ||
| 30 | if (ctx->seek(ctx, 1080, 0) != 1080) | 30 | if(ctx->seek(ctx, 1080, 0) != 1080) |
| 31 | return -1; | 31 | return -1; |
| 32 | if (ctx->read(ctx, d, 4) != 4) | 32 | if(ctx->read(ctx, d, 4) != 4) |
| 33 | return -1; | 33 | return -1; |
| 34 | for (i = 0; ; i++) | 34 | for(i = 0; ; i++){ |
| 35 | if (variants[i] == nil) | 35 | if(variants[i] == nil) |
| 36 | return -1; | 36 | return -1; |
| 37 | else if (memcmp(d, variants[i], 4) == 0) | 37 | if(memcmp(d, variants[i], 4) == 0) |
| 38 | break; | 38 | break; |
| 39 | memset(d, 0, sizeof d); | 39 | } |
| 40 | if (ctx->seek(ctx, 0, 0) != 0) | 40 | if(ctx->seek(ctx, 0, 0) != 0) |
| 41 | return -1; | 41 | return -1; |
| 42 | if (ctx->read(ctx, d, 20) != 20) | 42 | if(ctx->read(ctx, d, 20) != 20) |
| 43 | return -1; | 43 | return -1; |
| 44 | txtcb(ctx, Ttitle, "", d); | 44 | cp437toutf8(o, sizeof(o), d, 20); |
| 45 | txtcb(ctx, Ttitle, "", o); | ||
| 46 | |||
| 45 | return 0; | 47 | return 0; |
| 46 | } | 48 | } |
| @@ -3,14 +3,15 @@ · 2 unmodified lines | |||
| 3 | int | 3 | int |
| 4 | tags3m(Tagctx *ctx) | 4 | tags3m(Tagctx *ctx) |
| 5 | { | 5 | { |
| 6 | char d[28+1+1], *s; | 6 | char d[28+1+1], o[28*UTFmax+1], *s; |
| 7 | 7 | ||
| 8 | if(ctx->read(ctx, d, 28+1+1) != 28+1+1 || (d[28] != 0x1a && d[28] != 0) || d[29] != 0x10) | 8 | if(ctx->read(ctx, d, 28+1+1) != 28+1+1 || (d[28] != 0x1a && d[28] != 0) || d[29] != 0x10) |
| 9 | return -1; | 9 | return -1; |
| 10 | d[28] = 0; | 10 | d[28] = 0; |
| 11 | for(s = d+27; s != d-1 && (*s == ' ' || *s == 0); s--); | 11 | for(s = d+27; s != d-1 && (*s == ' ' || *s == 0); s--); |
| 12 | s[1] = 0; | 12 | s[1] = 0; |
| 13 | txtcb(ctx, Ttitle, "", d); | 13 | cp437toutf8(o, sizeof(o), d, s+1-d); |
| 14 | txtcb(ctx, Ttitle, "", o); | ||
| 14 | 15 | ||
| 15 | return 0; | 16 | return 0; |
| 16 | } | 17 | } |
| @@ -40,6 +40,11 @@ int iso88591toutf8(uchar *out, int osz, const uchar *src, int sz); · 39 unmodified lines | |||
| 40 | */ | 40 | */ |
| 41 | int utf16to8(uchar *out, int osz, const uchar *src, int sz); | 41 | int utf16to8(uchar *out, int osz, const uchar *src, int sz); |
| 42 | 42 | ||
| 43 | /* | ||
| 44 | * Same as utf16to8, but CP437 to UTF-8. | ||
| 45 | */ | ||
| 46 | int cp437toutf8(char *o, int osz, const char *s, int sz); | ||
| 47 | |||
| 43 | /* | 48 | /* |
| 44 | * This one is common for both vorbis.c and flac.c | 49 | * This one is common for both vorbis.c and flac.c |
| 45 | * It maps a string k to tag type and executes the callback from ctx. | 50 | * It maps a string k to tag type and executes the callback from ctx. |
| @@ -3,13 +3,14 @@ · 2 unmodified lines | |||
| 3 | int | 3 | int |
| 4 | tagxm(Tagctx *ctx) | 4 | tagxm(Tagctx *ctx) |
| 5 | { | 5 | { |
| 6 | char d[17+20+1], *s; | 6 | char d[17+20+1], o[20*UTFmax+1], *s; |
| 7 | 7 | ||
| 8 | if(ctx->read(ctx, d, 17+20) != 17+20 || memcmp(d, "Extended Module: ", 17) != 0) | 8 | if(ctx->read(ctx, d, 17+20) != 17+20 || memcmp(d, "Extended Module: ", 17) != 0) |
| 9 | return -1; | 9 | return -1; |
| 10 | d[17+20] = 0; | 10 | d[17+20] = 0; |
| 11 | for(s = d+17; *s == ' '; s++); | 11 | for(s = d+17; *s == ' '; s++); |
| 12 | txtcb(ctx, Ttitle, "", s); | 12 | cp437toutf8(o, sizeof(o), d+17, 20); |
| 13 | txtcb(ctx, Ttitle, "", o); | ||
| 13 | 14 | ||
| 14 | return 0; | 15 | return 0; |
| 15 | } | 16 | } |