ref: bde3359eb05ab492444a9ce87c05d855524c33b8
parent: 1ea45f339a2046b608a05417c2a124eedd82f384
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Apr 29 15:40:08 EDT 2021
mod formats: use CP437 as the default encoding
binary files /dev/null b/437.c differ
--- a/it.c
+++ b/it.c
@@ -3,12 +3,13 @@
int
tagit(Tagctx *ctx)
{
- char d[4+26+1];
+ char d[4+26+1], o[26*UTFmax+1];
if(ctx->read(ctx, d, 4+26) != 4+26 || memcmp(d, "IMPM", 4) != 0)
return -1;
d[4+26] = 0;
- txtcb(ctx, Ttitle, "", d+4);
+ cp437toutf8(o, sizeof(o), d+4, 26);
+ txtcb(ctx, Ttitle, "", o);
return 0;
}
--- a/mkfile
+++ b/mkfile
@@ -2,6 +2,7 @@
LIB=/$objtype/lib/libtags.a
OFILES=\
+ 437.$O\
8859.$O\
flac.$O\
id3genres.$O\
--- a/mod.c
+++ b/mod.c
@@ -1,7 +1,7 @@
#include "tagspriv.h"
/* insane. */
-static char* variants[] =
+static char *variants[] =
{
"M.K.",
"M!K!",
@@ -24,23 +24,25 @@
int
tagmod(Tagctx *ctx)
{
- char d[20+1];
+ char d[20], o[20*UTFmax+1];
int i;
- if (ctx->seek(ctx, 1080, 0) != 1080)
+ if(ctx->seek(ctx, 1080, 0) != 1080)
return -1;
- if (ctx->read(ctx, d, 4) != 4)
+ if(ctx->read(ctx, d, 4) != 4)
return -1;
- for (i = 0; ; i++)
- if (variants[i] == nil)
+ for(i = 0; ; i++){
+ if(variants[i] == nil)
return -1;
- else if (memcmp(d, variants[i], 4) == 0)
+ if(memcmp(d, variants[i], 4) == 0)
break;
- memset(d, 0, sizeof d);
- if (ctx->seek(ctx, 0, 0) != 0)
+ }
+ if(ctx->seek(ctx, 0, 0) != 0)
return -1;
- if (ctx->read(ctx, d, 20) != 20)
+ if(ctx->read(ctx, d, 20) != 20)
return -1;
- txtcb(ctx, Ttitle, "", d);
+ cp437toutf8(o, sizeof(o), d, 20);
+ txtcb(ctx, Ttitle, "", o);
+
return 0;
}
--- a/s3m.c
+++ b/s3m.c
@@ -3,7 +3,7 @@
int
tags3m(Tagctx *ctx)
{
- char d[28+1+1], *s;
+ char d[28+1+1], o[28*UTFmax+1], *s;
if(ctx->read(ctx, d, 28+1+1) != 28+1+1 || (d[28] != 0x1a && d[28] != 0) || d[29] != 0x10)
return -1;
@@ -10,7 +10,8 @@
d[28] = 0;
for(s = d+27; s != d-1 && (*s == ' ' || *s == 0); s--);
s[1] = 0;
- txtcb(ctx, Ttitle, "", d);
+ cp437toutf8(o, sizeof(o), d, s+1-d);
+ txtcb(ctx, Ttitle, "", o);
return 0;
}
--- a/tagspriv.h
+++ b/tagspriv.h
@@ -41,6 +41,11 @@
int utf16to8(uchar *out, int osz, const uchar *src, int sz);
/*
+ * Same as utf16to8, but CP437 to UTF-8.
+ */
+int cp437toutf8(char *o, int osz, const char *s, int sz);
+
+/*
* This one is common for both vorbis.c and flac.c
* It maps a string k to tag type and executes the callback from ctx.
* Returns 1 if callback was called, 0 otherwise.
--- a/xm.c
+++ b/xm.c
@@ -3,13 +3,14 @@
int
tagxm(Tagctx *ctx)
{
- char d[17+20+1], *s;
+ char d[17+20+1], o[20*UTFmax+1], *s;
if(ctx->read(ctx, d, 17+20) != 17+20 || memcmp(d, "Extended Module: ", 17) != 0)
return -1;
d[17+20] = 0;
for(s = d+17; *s == ' '; s++);
- txtcb(ctx, Ttitle, "", s);
+ cp437toutf8(o, sizeof(o), d+17, 20);
+ txtcb(ctx, Ttitle, "", o);
return 0;
}