Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/deliv1.c

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


# include "stdio.h"
# include "error.h"
# include "def.h"

void
main(int argc, char **argv)
{
	/* goes from file:begin,l to actual characters */
	char	line[750], *p, name[100];
	FILE * fa = NULL;
	long	lp;
	int	len;

	progname = mkprogname(argv[0]);
	if (argc > 1 && argv[1] && argv[1][0])
		chdir (argv[1]);
	name[0] = 0;
	while (gets(line)) {
		if (line[0] == '$' && line[1] == '$') {
			if (chdir(line + 2) < 0)
				err("can't chdir to %s", line+2);
			continue;
		}
		if ((p = strchr(line, ':')) == 0)
			continue;
		*p++ = 0;
		sscanf(p, "%ld,%d", &lp, &len);
		if (strcmp (name, line) != 0) {
			if (fa != NULL)
				fclose(fa);
			fa = efopen(line, "r");
			strcpy(name, line);
		}
		if (fa != NULL) {
			fseek (fa, lp, 0);
			if (len >= sizeof(line))
				len = sizeof(line)-1;
			fread(line, 1, len, fa);
			line[len] = 0;
			fputs(line, stdout);
		}
	}
	exit(0);
}

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.