Sigrid Solveig Haflínudóttiradd a harness target, leave readtags example alone013e8392 years agoHistory
106 lines · 2.0 KB · C
RawDownload
#include <fcntl.h>#include <stdio.h>#include <sys/types.h>#include <unistd.h>#define USED(x) (void)x#include "tags.h" typedef struct Aux Aux; struct Aux {	int fd;}; static const char *t2s[] = {	[Talbum] = "album",	[Talbumgain] = "albumgain",	[Talbumpeak] = "albumpeak",	[Tartist] = "artist",	[Tcomment] = "comment",	[Tcomposer] = "composer",	[Tdate] = "date",	[Tgenre] = "genre",	[Timage] = "image",	[Ttitle] = "title",	[Ttrack] = "track",	[Ttrackgain] = "trackgain",	[Ttrackpeak] = "trackpeak",}; static voidtag(Tagctx *ctx, int t, const char *k, const char *v, int offset, int size, Tagread f){	USED(ctx); USED(k); USED(f);	if(t == Timage)		printf("%-12s %s %d %d\n", t2s[t], v, offset, size);	else if(t == Tunknown)		printf("%-12s %s\n", k, v);	else		printf("%-12s %s\n", t2s[t], v);} static voidtoc(Tagctx *ctx, int ms, int offset){	USED(ctx); USED(ms); USED(offset);} static intctxread(Tagctx *ctx, void *buf, int cnt){	Aux *aux = ctx->aux;	return read(aux->fd, buf, cnt);} static intctxseek(Tagctx *ctx, int offset, int whence){	Aux *aux = ctx->aux;	return lseek(aux->fd, offset, whence);} intmain(int argc, char **argv){	int i;	char buf[256];	Aux aux;	Tagctx ctx = {		.read = ctxread,		.seek = ctxseek,		.tag = tag,		.toc = toc,		.buf = buf,		.bufsz = sizeof(buf),		.aux = &aux,	}; 	if(argc < 2){		printf("usage: readtags FILE...\n");		return 1;	} 	for(i = 1; i < argc; i++){		printf("*** %s\n", argv[i]);		if((aux.fd = open(argv[i], O_RDONLY)) < 0)			perror("failed to open");		else{			if(tagsget(&ctx) != 0)				printf("no tags or failed to read tags\n");			else{				if(ctx.duration > 0)					printf("%-12s %d ms\n", "duration", ctx.duration);				if(ctx.samplerate > 0)					printf("%-12s %d\n", "samplerate", ctx.samplerate);				if(ctx.channels > 0)					printf("%-12s %d\n", "channels", ctx.channels);				if(ctx.bitrate > 0)					printf("%-12s %d\n", "bitrate", ctx.bitrate);			}			close(aux.fd);		}		printf("\n");	} 	return 0;}

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