shithub: pdffs

ref: 2ff084d1629e80f99b35576f10ea87dc4d9f8941
dir: /main.c/

View raw version
#include <u.h>
#include <libc.h>
#include <thread.h>
#include <bio.h>
#include <flate.h>
#include "pdf.h"

int mainstacksize = 32768;

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->root, i = 1; i < argc; i++){
		if(argv[i][0] == '['){
			n = atoi(argv[i]+1);
			v = arrayget(v, n);
		}else if(argv[i][0] == '@' && argv[i][1] == 0 && v->type == Ostream){
			if((s = Sopen(v)) == nil)
				sysfatal("%r");
			print("%.*s\n", s->buf.sz, s->buf.b);
			Sclose(s);
			break;
		}else{
			v = dictget(v, argv[i]);
		}
	}
	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);
}