M mod.c => mod.c +10 -7
@@ 19,25 19,28 @@ static char *variants[] =
"10CH",
"16CN",
"32CN",
+ nil,
};
int
tagmod(Tagctx *ctx)
{
- uchar d[20+4], o[20*UTFmax+1];
+ uchar d[20], o[20*2+1];
int i;
- if(ctx->read(ctx, d, 20) != 20)
- return -1;
if(ctx->seek(ctx, 1080, 0) != 1080)
return -1;
- if(ctx->read(ctx, d+20, 4) != 4)
+ if(ctx->read(ctx, d, 4) != 4)
return -1;
- for(i = 0; i < nelem(variants); i++){
- if(memcmp(d+20, variants[i], 4) == 0)
+ for(i = 0; ; i++){
+ if(variants[i] == nil)
+ return -1;
+ if(memcmp(d, variants[i], 4) == 0)
break;
}
- if(i >= nelem(variants))
+ if(ctx->seek(ctx, 0, 0) != 0)
+ return -1;
+ if(ctx->read(ctx, d, 20) != 20)
return -1;
if(iso88591toutf8(o, sizeof(o), d, 20) > 0)
txtcb(ctx, Ttitle, "", o);
M opus.c => opus.c +2 -3
@@ 8,8 8,7 @@ tagopus(Tagctx *ctx)
int sz, numtags, i, npages;
d = (uchar*)ctx->buf;
- /* need to find vorbis frame with type=3 */
- for(npages = 0; npages < 2; npages++){ /* vorbis comment is the second header */
+ for(npages = 0; npages < 2; npages++){
int nsegs;
if(ctx->read(ctx, d, 27) != 27)
return -1;
@@ 76,7 75,7 @@ tagopus(Tagctx *ctx)
break;
for(; v != nil && v < ctx->buf+sz;){
v = memchr(v, 'O', ctx->buf+sz - v - 14);
- if(v != nil && v[1] == 'g' && v[2] == 'g' && v[3] == 'S' && (v[5] & 4) == 4){ /* last page */
+ if(v != nil && v[1] == 'g' && v[2] == 'g' && v[3] == 'S'){
uvlong g = leuint(v+6) | (uvlong)leuint(v+10)<<32;
ctx->duration = g * 1000 / 48000; /* granule positions are always 48KHz */
return 0;
M tags.c => tags.c +1 -2
@@ 69,9 69,8 @@ tagsget(Tagctx *ctx)
for(i = 0; i < nelem(g); i++){
ctx->num = 0;
if(g[i].f(ctx) == 0){
- if(ctx->num > 0)
- res = 0;
ctx->format = g[i].format;
+ res = 0;
}
ctx->seek(ctx, 0, 0);
}
M tagspriv.h => tagspriv.h +5 -2
@@ 4,14 4,17 @@
#include <string.h>
#include <stdlib.h>
#include <strings.h>
+#include <stdint.h>
#define snprint snprintf
#define cistrcmp strcasecmp
#define cistrncmp strncasecmp
#define nil NULL
#define UTFmax 4
#define nelem(x) (int)(sizeof(x)/sizeof((x)[0]))
-typedef unsigned char uchar;
-typedef unsigned long long uvlong;
+typedef uint8_t uchar;
+typedef uint16_t u16int;
+typedef uint32_t u32int;
+typedef uint64_t uvlong;
#else
#include <u.h>
#include <libc.h>
M wav.c => wav.c +4 -4
@@ 1,6 1,6 @@
#include "tagspriv.h"
-#define le16u(d) ((d)[0] | (d)[1]<<8)
+#define le16u(d) (u16int)((d)[0] | (d)[1]<<8)
static struct {
char *s;
@@ 17,10 17,10 @@ static struct {
int
tagwav(Tagctx *ctx)
{
+ uchar *d;
int i, n, info;
+ u32int csz;
uvlong sz;
- uchar *d;
- uint csz;
d = (uchar*)ctx->buf;
@@ 69,7 69,7 @@ tagwav(Tagctx *ctx)
csz++;
for(n = 0; n < nelem(t); n++){
if(memcmp(d, t[n].s, 4) == 0){
- if((uint)ctx->read(ctx, d, csz) != csz)
+ if(ctx->read(ctx, d, csz) != csz)
return -1;
d[csz-1] = 0;
txtcb(ctx, t[n].type, "", d);