Plan 9 from Bell Labs’s /usr/web/sources/contrib/nemo/sys/src/cmd/pager.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <plumb.h>

int debug;
char* fname;

static void
msg(Plumbmsg* m)
{

	free(fname);
	if (m->wdir && m->data[0] != '/')
		fname = smprint("%s/%s", m->wdir, m->data);
	else
		fname = strdup(m->data);
	switch(rfork(RFPROC|RFNOWAIT|RFMEM|RFFDG)){
	case 0:
		execl("/bin/page", "page", "-w", fname, nil);
		exits("exec");
	case -1:
		sysfatal("fork: %r");
	default:
		if (debug)
			fprint(2, "plumbing %s\n", fname);
	}
}

int
createport(char* name)
{
	int	fd;
	char*	fname;

	fname = smprint("/devs/ports/%s", name);
	assert(fname);
	if (access(fname, AREAD) >= 0)
		fd = open(fname, OREAD|OCEXEC);
	else
		fd = create(fname, OREAD|OCEXEC, 0660);
	free(fname);
	return fd;
}

static void
usage(void)
{
		fprint(2, "usage: %s [-p port] \n", argv0);
		sysfatal("usage");
}

void
main(int argc, char* argv[])
{
	Plumbmsg* m;
	int plumbfd;
	char*	port;


	port="postscript";
	ARGBEGIN{
	case 'd':
		debug++;
		break;
	case 'p':
		port = EARGF(usage());
	default:
		usage();
	}ARGEND;
	if (argc > 0)
		usage();
	plumbfd = createport(port);
	if (plumbfd < 0)
		sysfatal("port %s: %r", port);
	for(;;){
		m = plumbrecv(plumbfd);
		if(m == nil)
			sysfatal("plumbrecv port %s: %r", port);
		msg(m);
		plumbfree(m);
	}
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.