ref: 75ceb243faad4aa529afef047473ece203113eff
dir: /main.c/
#include <u.h> #include <libc.h> #include <thread.h> #include <ctype.h> #include <bio.h> #include <flate.h> #include "pdf.h" int mainstacksize = 128*1024; static void usage(void) { fprint(2, "usage: %s FILE\n", argv0); threadexitsall("usage"); } void threadmain(int argc, char **argv) { Pdf *pdf; Biobuf *b; Object *v; Stream *s; int i, n; quotefmtinstall(); inflateinit(); ARGBEGIN{ default: usage(); }ARGEND if(argc < 1) usage(); if((b = Bopen(argv[0], OREAD)) == nil) sysfatal("%r"); if((pdf = pdfopen(b)) == nil) sysfatal("%s: %r", argv[0]); for(v = pdf->top, i = 1; v != nil && i < argc; i++){ if(isdigit(argv[i][0])){ n = atoi(argv[i]); v = arrayget(v, n); }else if(argv[i][0] == '.' && argv[i][1] == 0 && v->type == Ostream){ if((s = Sopen(v)) == nil) sysfatal("%r"); if(write(1, s->buf.b, s->buf.sz) != s->buf.sz) sysfatal("write failed"); Sclose(s); v = nil; break; }else if(argv[i][0] == '@' && argv[i][1] == 0 && v->type == Ostream){ fprint(2, "%d %d\n", v->stream.off, v->stream.len); v = nil; break; }else{ v = dictget(v, argv[i]); } } if(v == &null) fprint(2, "%r\n"); else if(v != nil) print("%O\n", v); /* if((v = dictget(pdf->info, "Creator")) != nil) fprint(2, "creator: %s\n", v->str); if((v = dictget(pdf->info, "Producer")) != nil) fprint(2, "producer: %s\n", v->str); */ pdfclose(pdf); threadexitsall(nil); }