History

mod formats: use CP437 as the default encoding

Sigrid Solveig Haflínudóttir committed 5 years ago

Commit bde33591 parent 1ea45f37 files · +62 −17Browse files

Unified · Split

7 files
  1. 437.c +34 −0
  2. it.c +3 −2
  3. mkfile +1 −0
  4. mod.c +13 −11
  5. s3m.c +3 −2
  6. tagspriv.h +5 −0
  7. xm.c +3 −2
437.c+34−0
@@ -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+}
it.c+3−2
@@ -3,12 +3,13 @@ · 2 unmodified lines
33 int
44 tagit(Tagctx *ctx)
55 {
6− char d[4+26+1];
6+ char d[4+26+1], o[26*UTFmax+1];
77
88 if(ctx->read(ctx, d, 4+26) != 4+26 || memcmp(d, "IMPM", 4) != 0)
99 return -1;
1010 d[4+26] = 0;
11− txtcb(ctx, Ttitle, "", d+4);
11+ cp437toutf8(o, sizeof(o), d+4, 26);
12+ txtcb(ctx, Ttitle, "", o);
1213
1314 return 0;
1415 }
mkfile+1−0
@@ -2,6 +2,7 @@ · 1 unmodified line
22 LIB=/$objtype/lib/libtags.a
33
44 OFILES=\
5+ 437.$O\
56 8859.$O\
67 flac.$O\
78 id3genres.$O\
mod.c+13−11
@@ -1,7 +1,7 @@
11 #include "tagspriv.h"
22
33 /* insane. */
4−static char* variants[] =
4+static char *variants[] =
55 {
66 "M.K.",
77 "M!K!",
@@ -24,23 +24,25 @@ static char* variants[] = · 16 unmodified lines
2424 int
2525 tagmod(Tagctx *ctx)
2626 {
27− char d[20+1];
27+ char d[20], o[20*UTFmax+1];
2828 int i;
2929
30− if (ctx->seek(ctx, 1080, 0) != 1080)
30+ if(ctx->seek(ctx, 1080, 0) != 1080)
3131 return -1;
32− if (ctx->read(ctx, d, 4) != 4)
32+ if(ctx->read(ctx, d, 4) != 4)
3333 return -1;
34− for (i = 0; ; i++)
35− if (variants[i] == nil)
34+ for(i = 0; ; i++){
35+ if(variants[i] == nil)
3636 return -1;
37− else if (memcmp(d, variants[i], 4) == 0)
37+ if(memcmp(d, variants[i], 4) == 0)
3838 break;
39− memset(d, 0, sizeof d);
40− if (ctx->seek(ctx, 0, 0) != 0)
39+ }
40+ if(ctx->seek(ctx, 0, 0) != 0)
4141 return -1;
42− if (ctx->read(ctx, d, 20) != 20)
42+ if(ctx->read(ctx, d, 20) != 20)
4343 return -1;
44− txtcb(ctx, Ttitle, "", d);
44+ cp437toutf8(o, sizeof(o), d, 20);
45+ txtcb(ctx, Ttitle, "", o);
46+
4547 return 0;
4648 }
s3m.c+3−2
@@ -3,14 +3,15 @@ · 2 unmodified lines
33 int
44 tags3m(Tagctx *ctx)
55 {
6− char d[28+1+1], *s;
6+ char d[28+1+1], o[28*UTFmax+1], *s;
77
88 if(ctx->read(ctx, d, 28+1+1) != 28+1+1 || (d[28] != 0x1a && d[28] != 0) || d[29] != 0x10)
99 return -1;
1010 d[28] = 0;
1111 for(s = d+27; s != d-1 && (*s == ' ' || *s == 0); s--);
1212 s[1] = 0;
13− txtcb(ctx, Ttitle, "", d);
13+ cp437toutf8(o, sizeof(o), d, s+1-d);
14+ txtcb(ctx, Ttitle, "", o);
1415
1516 return 0;
1617 }
tagspriv.h+5−0
@@ -40,6 +40,11 @@ int iso88591toutf8(uchar *out, int osz, const uchar *src, int sz); · 39 unmodified lines
4040 */
4141 int utf16to8(uchar *out, int osz, const uchar *src, int sz);
4242
43+/*
44+ * Same as utf16to8, but CP437 to UTF-8.
45+ */
46+int cp437toutf8(char *o, int osz, const char *s, int sz);
47+
4348 /*
4449 * This one is common for both vorbis.c and flac.c
4550 * It maps a string k to tag type and executes the callback from ctx.
xm.c+3−2
@@ -3,13 +3,14 @@ · 2 unmodified lines
33 int
44 tagxm(Tagctx *ctx)
55 {
6− char d[17+20+1], *s;
6+ char d[17+20+1], o[20*UTFmax+1], *s;
77
88 if(ctx->read(ctx, d, 17+20) != 17+20 || memcmp(d, "Extended Module: ", 17) != 0)
99 return -1;
1010 d[17+20] = 0;
1111 for(s = d+17; *s == ' '; s++);
12− txtcb(ctx, Ttitle, "", s);
12+ cp437toutf8(o, sizeof(o), d+17, 20);
13+ txtcb(ctx, Ttitle, "", o);
1314
1415 return 0;
1516 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t