Example #1
0
static void
ginit(void)
{
	static int first = 1;
	int i;
	
	if(!first)
		return;
		
	first = 0;
	memimageinit();
#ifdef PLAN9PORT
	smallfont = openmemsubfont(unsharp("#9/font/lucsans/lstr.10"));
#else
	smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10");
#endif
	black = memblack;
	blue = allocrepl(DBlue);
	red = allocrepl(DRed);
	grid = allocrepl(0x77777777);
	for(i=0; i<nelem(fill)/2 && i<nelem(lofill) && i<nelem(hifill); i++){
		lofill[i] = allocrepl(fill[2*i]);
		hifill[i] = allocrepl(fill[2*i+1]);
	}
}
Example #2
0
void
main(int argc, char **argv)
{
	Memimage *x;
	Point c = {208,871};
	int a = 441;
	int b = 441;
	int thick = 0;
	Point sp = {0,0};
	int alpha = 51;
	int phi = 3;
	vlong t0, t1;
	int i, n;
	vlong del;

	if (argc != 2) {
		fprint(2, "usage: arctest number\n");
		exits("usage");
	}
	memimageinit();

	x = allocmemimage(Rect(0,0,1000,1000), CMAP8);
	n = atoi(argv[1]);

	t0 = nsec();
	t0 = nsec();
	t0 = nsec();
	t1 = nsec();
	del = t1-t0;
	t0 = nsec();
	for(i=0; i<n; i++)
		memarc(x, c, a, b, thick, memblack, sp, alpha, phi, SoverD);
	t1 = nsec();
	print("%lld %lld\n", t1-t0-del, del);
}
Example #3
0
File: topng.c Project: aahud/harvey
void
main(int argc, char *argv[])
{
	Biobuf bout;
	Memimage *i;
	int fd;
	char *err, *filename;
	ImageInfo II;

	ARGBEGIN{
	case 'c':
		II.comment = ARGF();
		if(II.comment == nil)
			usage();
		II.fields_set |= II_COMMENT;
		break;
	case 'g':
		II.gamma = atof(ARGF());
		if(II.gamma == 0.)
			usage();
		II.fields_set |= II_GAMMA;
		break;
	case 't':
		break;
	default:
		usage();
	}ARGEND

	if(Binit(&bout, 1, OWRITE) < 0)
		sysfatal("Binit failed: %r");
	memimageinit();

	if(argc == 0){
		fd = 0;
		filename = "<stdin>";
	}else{
		fd = open(argv[0], OREAD);
		if(fd < 0)
			sysfatal("can't open %s: %r", argv[0]);
		filename = argv[0];
	}

	i = readmemimage(fd);
	if(i == nil)
		sysfatal("can't readimage %s: %r", filename);
	close(fd);

	err = memwritepng(&bout, i, &II);
	freememimage(i);

	if(err != nil)
		fprint(2, "topng: %s\n", err);
	exits(err);
}
Example #4
0
void
screeninit(void)
{
	int i;

	/* map the lcd regs into the kernel's virtual space */
	lcd = (struct sa1110regs*)mapspecial(LCDREGS, sizeof(struct sa1110regs));;

	framebuf = xspanalloc(sizeof *framebuf, 0x100, 0);

	vscreen = xalloc(sizeof(ushort)*Wid*Ht);

	lcdpower(1);
	lcdinit();

	gscreen = &xgscreen;

	xgdata.ref = 1;
	i = 0;
	if (landscape) {
		gscreen->r = Rect(0, 0, Ht, Wid);
		gscreen->clipr = gscreen->r;
		gscreen->width = Ht/2;
		xgdata.bdata = (uchar *)framebuf->pixel;
		while (i < Wid*Ht*1/3)	framebuf->pixel[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	framebuf->pixel[i++] = 0xffff;		/* white */
		while (i < Wid*Ht*3/3)	framebuf->pixel[i++] = 0x001f;	/* blue */
	} else {
		gscreen->r = Rect(0, 0, Wid, Ht);
		gscreen->clipr = gscreen->r;
		gscreen->width = Wid/2;
		xgdata.bdata = (uchar *)vscreen;
		while (i < Wid*Ht*1/3)	vscreen[i++] = 0xf800;	/* red */
		while (i < Wid*Ht*2/3)	vscreen[i++] = 0xffff;	/* white */
		while (i < Wid*Ht*3/3)	vscreen[i++] = 0x001f;	/* blue */
		flushmemscreen(gscreen->r);
	}
	memimageinit();
	memdefont = getmemdefont();

	out.pos.x = MINX;
	out.pos.y = 0;
	out.bwid = memdefont->info[' '].width;

	blanktime = 3;	/* minutes */

	screenwin();
//	screenputs = bitsyscreenputs;
	screenputs = nil;
}
Example #5
0
void
main(int argc, char *argv[])
{
	Memimage *m;
	int fd, r;
	char f;

	f = 0;
	r = 0;
	fd = 0;
	ARGBEGIN {
	case 'u':
		f = 'u';
		break;
	case 'l':
		f = 'l';
		break;
	case 'r':
		r = atoi(EARGF(usage()));
		break;
	default:
		usage();
	} ARGEND;
	if(*argv){
		fd = open(*argv, OREAD);
		if(fd < 0)
			sysfatal("open: %r");
	}
	memimageinit();
	if((m = readmemimage(fd)) == nil)
		sysfatal("readmemimage: %r");
	if(f == 'u' || f == 'l'){
		m = upsidedown(m);
		if(f == 'l')
			r = 180;
	}
	switch(r % 360){
	case 270:
		m = rot90(m);
	case 180:
		m = rot90(m);
	case 90:
		m = rot90(m);
		break;
	}
	if(writememimage(1, m) < 0)
		sysfatal("writememimage: %r");
	exits(0);
}
Example #6
0
void
screeninit(void)
{
	uchar *fb;

	fb = xspanalloc(Dx(xgscreen.r) * Dy(xgscreen.r) * 3, 64, 0);
	print("%p\n", PADDR(fb));
	memsetchan(&xgscreen, BGR24);
	conf.monitor = 1;
	xgdata.bdata = fb;
	xgdata.ref = 1;
	gscreen = &xgscreen;
	gscreen->width = wordsperline(gscreen->r, gscreen->depth);

	memimageinit();
}
Example #7
0
void
screeninit(void)
{
	uchar *fb;
	int set;
	ulong chan;

	set = screensize() == 0;
	fb = fbinit(set, &xgscreen.r.max.x, &xgscreen.r.max.y, &xgscreen.depth);
	if(fb == nil){
		print("can't initialise %dx%dx%d framebuffer \n",
			xgscreen.r.max.x, xgscreen.r.max.y, xgscreen.depth);
		return;
	}
	xgscreen.clipr = xgscreen.r;
	switch(xgscreen.depth){
	default:
		print("unsupported screen depth %d\n", xgscreen.depth);
		xgscreen.depth = 16;
		/* fall through */
	case 16:
		chan = RGB16;
		break;
	case 24:
		chan = BGR24;
		break;
	case 32:
		chan = ARGB32;
		break;
	}
	memsetchan(&xgscreen, chan);
	conf.monitor = 1;
	xgdata.bdata = fb;
	xgdata.ref = 1;
	gscreen = &xgscreen;
	gscreen->width = wordsperline(gscreen->r, gscreen->depth);

	memimageinit();
	memdefont = getmemdefont();
	screenwin();
	screenputs = myscreenputs;
	swcursorinit();
}
Example #8
0
void
screeninit(void)
{
	int fmt;
	int dx, dy;

	memimageinit();
	if(depth == 0)
		depth = GetDeviceCaps(GetDC(NULL), BITSPIXEL);
	switch(depth){
	case 32:
		screen.dibtype = DIB_RGB_COLORS;
		screen.depth = 32;
		fmt = XRGB32;
		break;
	case 24:
		screen.dibtype = DIB_RGB_COLORS;
		screen.depth = 24;
		fmt = RGB24;
		break;
	case 16:
		screen.dibtype = DIB_RGB_COLORS;
		screen.depth = 16;
		fmt = RGB15;	/* [sic] */
		break;
	case 8:
	default:
		screen.dibtype = DIB_PAL_COLORS;
		screen.depth = 8;
		depth = 8;
		fmt = CMAP8;
		break;
	}
	dx = GetDeviceCaps(GetDC(NULL), HORZRES);
	dy = GetDeviceCaps(GetDC(NULL), VERTRES);

	gscreen = allocmemimage(Rect(0,0,dx,dy), fmt);
	kproc("winscreen", winproc, 0);
	ksleep(&rend, isready, 0);
}
Example #9
0
void
screeninit(int x, int y, char *chanstr)
{
	Point p, q;
	char *greet;
	char buf[128];
	Memimage *grey;
	Rectangle r;
	int chan;

	cursorver = 0;

	memimageinit();
	chan = strtochan(chanstr);
	if(chan == 0)
		error("bad screen channel string");

	r = Rect(0, 0, x, y);
	gscreen = allocmemimage(r, chan);
	if(gscreen == nil){
		snprint(buf, sizeof buf, "can't allocate screen image: %r");
		error(buf);
	}

	offscreen = Pt(x + 100, y + 100);
	cursorr = Rect(0, 0, CURSORDIM, CURSORDIM);
	cursorset = allocmemimage(cursorr, GREY8);
	cursorclear = allocmemimage(cursorr, GREY1);
	if(cursorset == nil || cursorclear == nil){
		freememimage(gscreen);
		freememimage(cursorset);
		freememimage(cursorclear);
		gscreen = nil;
		cursorset = nil;
		cursorclear = nil;
		snprint(buf, sizeof buf, "can't allocate cursor images: %r");
		error(buf);
	}

	drawlock();

	/*
	 * set up goo for screenputs
	 */
	memdefont = getmemdefont();

	back = memwhite;
	conscol = memblack;

	/* a lot of work to get a grey color */
	curscol = allocmemimage(Rect(0,0,1,1), RGBA32);
	curscol->flags |= Frepl;
	curscol->clipr = gscreen->r;
	memfillcolor(curscol, 0xff0000ff);

	memfillcolor(gscreen, 0x444488FF);

	w = memdefont->info[' '].width;
	h = memdefont->height;

	window.min = addpt(gscreen->r.min, Pt(20,20));
	window.max.x = window.min.x + Dx(gscreen->r)*3/4-40;
	window.max.y = window.min.y + Dy(gscreen->r)*3/4-100;

	memimagedraw(gscreen, window, memblack, ZP, memopaque, ZP, S);
	window = insetrect(window, 4);
	memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);

	/* a lot of work to get a grey color */
	grey = allocmemimage(Rect(0,0,1,1), CMAP8);
	grey->flags |= Frepl;
	grey->clipr = gscreen->r;
	memfillcolor(grey, 0xAAAAAAFF);
	memimagedraw(gscreen, Rect(window.min.x, window.min.y,
			window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP, S);
	freememimage(grey);
	window = insetrect(window, 5);

	greet = " Plan 9 Console ";
	p = addpt(window.min, Pt(10, 0));
	q = memsubfontwidth(memdefont, greet);
	memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
	window.min.y += h+6;
	curpos = window.min;
	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
	flushmemscreen(gscreen->r);

	drawunlock();

	setcursor(&arrow);
}
Example #10
0
void
main(int argc, char **argv)
{
	char *mtpt, *srvname;

	mtpt = nil;
	srvname = "font";

	ARGBEGIN{
	case 'D':
		chatty9p++;
		break;
	case 'F':
		chattyfuse++;
		break;
	case 'm':
		mtpt = EARGF(usage());
		break;
	case 's':
		srvname = EARGF(usage());
		break;
	case 'p':
		pflag++;
		break;
	default:
		usage();
	}ARGEND
	
	xsrv.attach = xattach;
	xsrv.open = xopen;
	xsrv.read = xread;
	xsrv.stat = xstat;
	xsrv.walk1 = xwalk1;
	xsrv.destroyfid = xdestroyfid;

	fmtinstall('R', Rfmt);
	fmtinstall('P', Pfmt);
	memimageinit();
	defont = getmemdefont();
	loadfonts();
	qsort(xfont, nxfont, sizeof xfont[0], fontcmp);
	
	if(pflag) {
		if(argc != 1 || chatty9p || chattyfuse)
			usage();
		dump(argv[0]);
		exits(0);
	}

	if(pflag || argc != 0)
		usage();

	/*
	 * Check twice -- if there is an exited instance
	 * mounted there, the first access will fail but unmount it.
	 */
	if(mtpt && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0)
		sysfatal("mountpoint %s does not exist", mtpt);

	xsrv.foreground = 1;
	threadpostmountsrv(&xsrv, srvname, mtpt, 0);
}
Example #11
0
void
main(int argc, char **argv)
{
	int fd, xsize, ysize;
	Memimage *im, *nim;
	ulong ochan, tchan;

	xsize = ysize = 0;
	ARGBEGIN{
	case 'a':
		xsize = ysize = getsize(EARGF(usage()));
		break;
	case 'x':
		xsize = getsize(EARGF(usage()));
		break;
	case 'y':
		ysize = getsize(EARGF(usage()));
		break;
	default:
		usage();
	}ARGEND
	fd = 0;
	if(*argv){
		fd = open(*argv, OREAD);
		if(fd < 0)
			sysfatal("open: %r");
	}
	memimageinit();
	if((im = readmemimage(fd)) == nil)
		sysfatal("readmemimage: %r");
	if(xsize & PERCENT)
		xsize = ((xsize & ~PERCENT) * Dx(im->r)) / 100;
	if(ysize & PERCENT)
		ysize = ((ysize & ~PERCENT) * Dy(im->r)) / 100;
	if(xsize || ysize){
		if(ysize == 0)
			ysize = (xsize * Dy(im->r)) / Dx(im->r);
		if(xsize == 0)
			xsize = (ysize * Dx(im->r)) / Dy(im->r);
		ochan = im->chan;
		switch(ochan){
		default:
			for(tchan = ochan; tchan; tchan >>= 8)
				if(TYPE(tchan) == CAlpha){
					tchan = RGBA32;
					break;
				}
			if(tchan == 0)
				tchan = RGB24;
			break;
		case GREY8:
		case RGB24:
		case RGBA32:
		case ARGB32:
		case XRGB32:
			tchan = ochan;
			break;
		case GREY1:
		case GREY2:
		case GREY4:
			tchan = GREY8;
			break;
		}
		if(tchan != ochan){
			if((nim = allocmemimage(im->r, tchan)) == nil)
				sysfatal("allocimage: %r");
			memimagedraw(nim, nim->r, im, im->r.min, nil, ZP, S);
			freememimage(im);
			im = nim;
		}
		if((nim = allocmemimage(
			Rect(im->r.min.x, im->r.min.y, im->r.min.x+xsize, im->r.min.y+ysize), 
			tchan)) == nil)
			sysfatal("allocmemimage: %r");
		resample(nim, nim->r, im, im->r);
		freememimage(im);
		im = nim;
		if(tchan != ochan){
			if((im = allocmemimage(nim->r, ochan)) == nil)
				sysfatal("allocimage: %r");
			memimagedraw(im, im->r, nim, nim->r.min, nil, ZP, S);
			freememimage(nim);
		}
	}
	if(writememimage(1, im) < 0)
		sysfatal("writememimage: %r");
	exits(0);
}
Example #12
0
File: togif.c Project: aahud/harvey
void
main(int argc, char *argv[])
{
	Biobuf bout;
	Memimage *i, *ni;
	int fd, j, dt, trans, loop;
	char buf[256];
	char *err, *comment, *s;

	comment = nil;
	dt = -1;
	trans = -1;
	loop = UNSET;
	ARGBEGIN{
	case 'l':
		s = ARGF();
		if(s==nil || (!isdigit(s[0]) && s[0]!='-'))
			usage();
		loop = atoi(s);
		break;
	case 'c':
		comment = ARGF();
		if(comment == nil)
			usage();
		break;
	case 'd':
		s = ARGF();
		if(s==nil || !isdigit(s[0]))
			usage();
		dt = atoi(s);
		break;
	case 't':
		s = ARGF();
		if(s==nil || !isdigit(s[0]))
			usage();
		trans = atoi(s);
		if(trans > 255)
			usage();
		break;
	default:
		usage();
	}ARGEND

	if(Binit(&bout, 1, OWRITE) < 0)
		sysfatal("Binit failed: %r");

	memimageinit();

	err = nil;

	if(argc == 0){
		i = readmemimage(0);
		if(i == nil)
			sysfatal("reading input: %r");
		ni = memonechan(i);
		if(ni == nil)
			sysfatal("converting image to RGBV: %r");
		if(i != ni){
			freememimage(i);
			i = ni;
		}
		err = memstartgif(&bout, i, -1);
		if(err == nil){
			if(comment)
				err = memwritegif(&bout, i, comment, dt, trans);
			else{
				snprint(buf, sizeof buf, "Converted by Plan 9 from <stdin>");
				err = memwritegif(&bout, i, buf, dt, trans);
			}
		}
	}else{
		if(loop == UNSET){
			if(argc == 1)
				loop = -1;	/* no loop for single image */
			else
				loop = 0;	/* the default case: 0 means infinite loop */
		}
		for(j=0; j<argc; j++){
			if(argv[j][0] == '-' && argv[j][1]=='d'){
				/* time change */
				if(argv[j][2] == '\0'){
					s = argv[++j];
					if(j == argc)
						usage();
				}else
					s = &argv[j][2];
				if(!isdigit(s[0]))
					usage();
				dt = atoi(s);
				if(j == argc-1)	/* last argument must be file */
					usage();
				continue;
			}
			fd = open(argv[j], OREAD);
			if(fd < 0)
				sysfatal("can't open %s: %r", argv[j]);
			i = readmemimage(fd);
			if(i == nil)
				sysfatal("can't readimage %s: %r", argv[j]);
			close(fd);
			ni = memonechan(i);
			if(ni == nil)
				sysfatal("converting image to RGBV: %r");
			if(i != ni){
				freememimage(i);
				i = ni;
			}
			if(j == 0){
				err = memstartgif(&bout, i, loop);
				if(err != nil)
					break;
			}
			if(comment)
				err = memwritegif(&bout, i, comment, dt, trans);
			else{
				snprint(buf, sizeof buf, "Converted by Plan 9 from %s", argv[j]);
				err = memwritegif(&bout, i, buf, dt, trans);
			}
			if(err != nil)
				break;
			freememimage(i);
			comment = nil;
		}
	}
	memendgif(&bout);

	if(err != nil)
		fprint(2, "togif: %s\n", err);
	exits(err);
}
Example #13
0
/* 
 * Handle a single wsysmsg. 
 * Might queue for later (kbd, mouse read)
 */
void
runmsg(Wsysmsg *m)
{
	uchar buf[65536];
	int n;
	Memimage *i;
	
	switch(m->type){
	case Tinit:
		memimageinit();
		i = _xattach(m->label, m->winsize);
		_initdisplaymemimage(i);
		replymsg(m);
		break;

	case Trdmouse:
		mousetags.t[mousetags.wi++] = m->tag;
		if(mousetags.wi == nelem(mousetags.t))
			mousetags.wi = 0;
		if(mousetags.wi == mousetags.ri)
			sysfatal("too many queued mouse reads");
		/* fprint(2, "mouse unstall\n"); */
		mouse.stall = 0;
		matchmouse();
		break;

	case Trdkbd:
		kbdtags.t[kbdtags.wi++] = m->tag;
		if(kbdtags.wi == nelem(kbdtags.t))
			kbdtags.wi = 0;
		if(kbdtags.wi == kbdtags.ri)
			sysfatal("too many queued keyboard reads");
		kbd.stall = 0;
		matchkbd();
		break;

	case Tmoveto:
		_xmoveto(m->mouse.xy);
		replymsg(m);
		break;

	case Tcursor:
		if(m->arrowcursor)
			_xsetcursor(nil);
		else
			_xsetcursor(&m->cursor);
		replymsg(m);
		break;
			
	case Tbouncemouse:
		_xbouncemouse(&m->mouse);
		replymsg(m);
		break;

	case Tlabel:
		_xsetlabel(m->label);
		replymsg(m);
		break;

	case Trdsnarf:
		m->snarf = _xgetsnarf();
		replymsg(m);
		free(m->snarf);
		break;

	case Twrsnarf:
		_xputsnarf(m->snarf);
		replymsg(m);
		break;

	case Trddraw:
		n = m->count;
		if(n > sizeof buf)
			n = sizeof buf;
		n = _drawmsgread(buf, n);
		if(n < 0)
			replyerror(m);
		else{
			m->count = n;
			m->data = buf;
			replymsg(m);
		}
		break;

	case Twrdraw:
		if(_drawmsgwrite(m->data, m->count) < 0)
			replyerror(m);
		else
			replymsg(m);
		break;
	
	case Ttop:
		_xtopwindow();
		replymsg(m);
		break;
	
	case Tresize:
		_xresizewindow(m->rect);
		replymsg(m);
		break;
	}
}
Example #14
0
int
screensize(int x, int y, int z, uint32_t chan)
{
	Proc *up = externup();
	VGAscr *scr;
	void *oldsoft;

	lock(&vgascreenlock);
	if(waserror()){
		unlock(&vgascreenlock);
		nexterror();
	}

	memimageinit();
	scr = &vgascreen[0];
	oldsoft = softscreen;

	if(scr->paddr == 0){
		int width = (x*z)/BI2WD;
		void *p;

		p = malloc(width*BY2WD*y);
		if(p == nil)
			error("no memory for vga soft screen");
		gscreendata.bdata = softscreen = p;
		if(scr->dev && scr->dev->page){
			scr->vaddr = KADDR(VGAMEM());
			scr->apsize = 1<<16;
		}
		scr->useflush = 1;
	}
	else{
		gscreendata.bdata = scr->vaddr;
		scr->useflush = scr->dev && scr->dev->flush;
	}

	scr->gscreen = nil;
	if(gscreen)
		freememimage(gscreen);
	gscreen = allocmemimaged(Rect(0,0,x,y), chan, &gscreendata);
	if(gscreen == nil)
		error("no memory for vga memimage");
	vgaimageinit(chan);

	scr->palettedepth = 6;	/* default */
	scr->gscreendata = &gscreendata;
	scr->memdefont = getmemdefont();
	scr->gscreen = gscreen;

	physgscreenr = gscreen->r;
	unlock(&vgascreenlock);
	poperror();
	if(oldsoft)
		free(oldsoft);

	memimagedraw(gscreen, gscreen->r, memblack, ZP, nil, ZP, S);
	flushmemscreen(gscreen->r);

	if(didswcursorinit)
		swcursorinit();
	drawcmap();
	return 0;
}
Example #15
0
void
main(int argc, char *argv[])
{
	char *tostr, *file;
	int fd, uncompressed;
	ulong tochan;
	Memimage *m, *n;

	tostr = nil;
	uncompressed = 0;
	ARGBEGIN{
	case 'c':
		tostr = EARGF(usage());
		break;
	case 'u':
		uncompressed = 1;
		break;
	default:
		usage();
	}ARGEND

	memimageinit();

	file = "<stdin>";
	m = nil;

	switch(argc){
	case 0:
		m = readmemimage(0);
		break;
	case 1:
		file = argv[0];
		fd = open(file, OREAD);
		if(fd < 0)
			sysfatal("can't open %s: %r", file);
		m = readmemimage(fd);
		close(fd);
		break;
	default:
		usage();
	}

	if(m == nil)
		sysfatal("can't read %s: %r", file);

	if(tostr == nil)
		tochan = m->chan;
	else{
		tochan = strtochan(tostr);
		if(tochan == 0)
			sysfatal("bad channel descriptor '%s'", tostr);
	}

	n = allocmemimage(m->r, tochan);
	if(n == nil)
		sysfatal("can't allocate new image: %r");

	memimagedraw(n, n->r, m, m->r.min, nil, ZP, S);
	if(uncompressed)
		writeuncompressed(1, n);
	else
		writememimage(1, n);
	exits(nil);
}
Example #16
0
File: main.c Project: 99years/plan9
void
threadmain(int argc, char *argv[])
{
	Column *c;
	char buf[256];
	int i, ncol;

	rfork(RFENVG|RFNAMEG);

	ncol = 1;
	ARGBEGIN{
	case 'c':
		ncol = atoi(EARGF(usage()));
		if(ncol <= 0)
			usage();
		break;
	case 'm':
		webmountpt = EARGF(usage());
		break;
	case 'p':
		procstderr++;
		break;
	case 't':
		charset = EARGF(usage());
		break;
	default:
		usage();
		break;
	}ARGEND

	snprint(buf, sizeof(buf), "%s/ctl", webmountpt);
	webctlfd = open(buf, ORDWR);
	if(webctlfd < 0)
		sysfatal("can't initialize webfs: %r");

	snarffd = open("/dev/snarf", OREAD|OCEXEC);

	if(initdraw(derror, fontnames[0], "abaco") < 0)
		sysfatal("can't open display: %r");
	memimageinit();
	iconinit();
	timerinit();
	initfontpaths();

	cexit = chancreate(sizeof(int), 0);
	crefresh = chancreate(sizeof(Page *), 0);
	if(cexit==nil || crefresh==nil)
		sysfatal("can't create initial channels: %r");

	mousectl = initmouse(nil, screen);
	if(mousectl == nil)
		sysfatal("can't initialize mouse: %r");
	mouse = mousectl;
	keyboardctl = initkeyboard(nil);
	if(keyboardctl == nil)
		sysfatal("can't initialize keyboard: %r");
	mainpid = getpid();
	plumbwebfd = plumbopen("web", OREAD|OCEXEC);
	if(plumbwebfd >= 0){
		cplumb = chancreate(sizeof(Plumbmsg*), 0);
		proccreate(plumbproc, nil, STACK);
	}
	plumbsendfd = plumbopen("send", OWRITE|OCEXEC);

	rowinit(&row, screen->clipr);
	for(i=0; i<ncol; i++){
		c = rowadd(&row, nil, -1);
		if(c==nil && i==0)
			error("initializing columns");
	}
	c = row.col[row.ncol-1];
	for(i=0; i<argc; i++)
		if(i/WPERCOL >= row.ncol)
			readpage(c, argv[i]);
		else
			readpage(row.col[i/WPERCOL], argv[i]);
	flushimage(display, 1);
	threadcreate(keyboardthread, nil, STACK);
	threadcreate(mousethread, nil, STACK);

	threadnotify(shutdown, 1);
	recvul(cexit);
	threadexitsall(nil);
}
Example #17
0
void
main(int argc, char *argv[]) {
	int i, fd = 0;
	double xmag = 1.0, ymag = 1.0;
	char *optstr, *Patch;
	Memimage *memimage;

	Patch = nil;
	for (i=1; i<argc; i++) {
		if (*argv[i] != '-') break;
		switch(argv[i][1]) {
		case 'b':
			if (argv[i][2] == '\0')
				dpi = atoi(argv[++i]);
			else
				dpi = atoi(&(argv[i][2]));
			break;
		case 'd':
			debug = 1;
			break;
		case 'm':
			if (argv[i][2] == '\0')
				optstr = argv[++i];
			else
				optstr = &(argv[i][2]);
			if ((optstr=strtok(optstr, " ,")) != 0)
				xmag = ymag = atof(optstr);
			if ((optstr=strtok(0, " ,")) != 0)
				ymag = atof(optstr);
			break;
		case 'L':
			landscape = 1;
			break;
		case 'P':
			if (argv[i][2] == '\0')
				Patch = argv[++i];
			else
				Patch = &(argv[i][2]);
			break;
		case 'p':
			optstr = argv[++i];
			if(optstr == nil)
				goto Usage;
			paperlength = 72*atof(optstr);
			optstr = argv[++i];
			if(optstr == nil)
				goto Usage;
			paperwidth = 72*atof(optstr);
			if(paperlength < 72 || paperwidth < 72)
				goto Usage;
			break;
		default:
		Usage:
			fprint(2, "usage: %s [-b dpi] [-m magnification] [-L] [-P postscript_patch_string] [-p paperlength paperwidth (in inches)] inputfile\n", argv[0]);
			exits("usage");
		}
	}

	if (i < argc) {
		file = argv[i];
		fd = open(file, OREAD);
		if (fd < 0)
			error("open");
	}

	memimageinit();
	memimage = readmemimage(fd);
	if(memimage == nil)
		error("alloc memory for");

	psinit(0, 0);
	if(xmag != 1.0)
		psopt("xmagnification", &xmag);
	if(ymag != 1.0)
		psopt("ymagnification", &ymag);
	if(landscape)
		psopt("landscape", &landscape);
	if(Patch)
		psopt("Patch", &Patch);
	image2psfile(1, memimage, dpi);
	exits("");
}