ref: 5dc44497e08df77ed4e7a12981a6a527bf70424e
dir: /main.c/
#include <u.h> #include <libc.h> #include <bio.h> #include "common.h" Biobuf stderr, out; int dflag, trackdump; static void usage(void) { fprint(2, "usage: %s [-t INDEX|audio|video] [FILE]\n", argv0); exits("usage"); } void main(int argc, char **argv) { Biobuf *f; char *s, *status; u8int d[4]; dflag = 0; trackdump = Nodump; ARGBEGIN{ case 'd': dflag++; break; case 't': s = EARGF(usage()); if(strcmp(s, "audio") == 0) trackdump = Dumpaudio; else if(strcmp(s, "video") == 0) trackdump = Dumpvideo; else trackdump = atoi(s); break; default: usage(); }ARGEND f = nil; if(argc == 1) f = Bopen(*argv, OREAD); else if(argc == 0) f = Bfdopen(0, OREAD); else usage(); if(f == nil) sysfatal("%r"); fmtinstall('H', encodefmt); fmtinstall('T', isotypefmt); fmtinstall('P', srttsfmt); Binit(&out, 1, OWRITE); Binit(&stderr, 2, OWRITE); status = nil; if(Bread(f, d, 4) != 4){ Bprint(&stderr, "unknown format\n"); status = "unknown format"; }else if(Bungetc(f) < 0 || Bungetc(f) < 0 || Bungetc(f) < 0 || Bungetc(f) < 0){ Bprint(&stderr, "seek back failed: %r\n"); status = "seek failed"; }else if(memcmp(d, "\x1a\x45\xdf\xa3", 4) == 0){ if(ebmlrun(f) != 0){ Bprint(&stderr, "embl: %r\n"); status = "ebml failed"; } }else if(isorun(f) != 0){ Bprint(&stderr, "iso: %r\n"); status = "iso failed"; } Bterm(f); Bterm(&out); Bterm(&stderr); exits(status); }