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
4static 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
11int
12cp437toutf8(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
3int3int
4tagit(Tagctx *ctx)4tagit(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}
mkfile+1−0
@@ -2,6 +2,7 @@ · 1 unmodified line
2LIB=/$objtype/lib/libtags.a2LIB=/$objtype/lib/libtags.a
3 3
4OFILES=\4OFILES=\
5 437.$O\
5 8859.$O\6 8859.$O\
6 flac.$O\7 flac.$O\
7 id3genres.$O\8 id3genres.$O\
mod.c+13−11
@@ -1,7 +1,7 @@
1#include "tagspriv.h"1#include "tagspriv.h"
2 2
3/* insane. */3/* insane. */
4static char* variants[] =4static 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
24int24int
25tagmod(Tagctx *ctx)25tagmod(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}
s3m.c+3−2
@@ -3,14 +3,15 @@ · 2 unmodified lines
3int3int
4tags3m(Tagctx *ctx)4tags3m(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}
tagspriv.h+5−0
@@ -40,6 +40,11 @@ int iso88591toutf8(uchar *out, int osz, const uchar *src, int sz); · 39 unmodified lines
40 */40 */
41int utf16to8(uchar *out, int osz, const uchar *src, int sz);41int utf16to8(uchar *out, int osz, const uchar *src, int sz);
42 42
43/*
44 * Same as utf16to8, but CP437 to UTF-8.
45 */
46int cp437toutf8(char *o, int osz, const char *s, int sz);
47
43/*48/*
44 * This one is common for both vorbis.c and flac.c49 * 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.
xm.c+3−2
@@ -3,13 +3,14 @@ · 2 unmodified lines
3int3int
4tagxm(Tagctx *ctx)4tagxm(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}

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