~ft/libtags

173b32f09bc04f114dc22bdfd0315402667c5fa7 — Sigrid Solveig Haflínudóttir 2 years ago 7996f8d
trim text tags and ignore empty values
3 files changed, 15 insertions(+), 5 deletions(-)

M tags.c
M tagspriv.h
M xm.c
M tags.c => tags.c +13 -2
@@ 36,13 36,24 @@ static const Getter g[] =
};

void
tagscallcb(Tagctx *ctx, int type, const char *k, const char *s, int offset, int size, Tagread f)
tagscallcb(Tagctx *ctx, int type, const char *k, char *s, int offset, int size, Tagread f)
{
	char *e;

	if(f == nil && size == 0){
		while(*s <= ' ' && *s)
			s++;
		e = s + strlen(s);
		while(e != s && e[-1] <= ' ')
			e--;
		*e = 0;
	}
	if(type != Tunknown){
		ctx->found |= 1<<type;
		ctx->num++;
	}
	ctx->tag(ctx, type, k, s, offset, size, f);
	if(*s)
		ctx->tag(ctx, type, k, s, offset, size, f);
}

int

M tagspriv.h => tagspriv.h +1 -1
@@ 52,6 52,6 @@ int cp437toutf8(char *o, int osz, const char *s, int sz);
 */
void cbvorbiscomment(Tagctx *ctx, char *k, char *v);

void tagscallcb(Tagctx *ctx, int type, const char *k, const char *s, int offset, int size, Tagread f);
void tagscallcb(Tagctx *ctx, int type, const char *k, char *s, int offset, int size, Tagread f);

#define txtcb(ctx, type, k, s) tagscallcb(ctx, type, k, (const char*)s, 0, 0, nil)

M xm.c => xm.c +1 -2
@@ 3,12 3,11 @@
int
tagxm(Tagctx *ctx)
{
	char d[17+20+1], o[20*UTFmax+1], *s;
	char d[17+20+1], o[20*UTFmax+1];

	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++);
	if(cp437toutf8(o, sizeof(o), d+17, 20) > 0)
		txtcb(ctx, Ttitle, "", o);