Exemple #1
0
/* return: 0 - cannot open fnam; 1 - otherwise */
bool
page_file(const char *fnam, bool silent)
{
#ifdef DEF_PAGER		/* this implies that UNIX is defined */
	/* use external pager; this may give security problems */
	int fd = open(fnam, O_RDONLY);

	if (fd < 0) {
		if (!silent)
			pline("Cannot open %s.", fnam);
		return (0);
	}
	if (child(1)) {
		extern char *catmore;

		/*
		 * Now that child() does a setuid(getuid()) and a
		 * chdir(), we may not be able to open file fnam
		 * anymore, so make it stdin.
		 */
		close(0);
		if (dup(fd)) {
			if (!silent)
				printf("Cannot open %s as stdin.\n", fnam);
		} else {
			execl(catmore, "page", NULL);
			if (!silent)
				printf("Cannot exec %s.\n", catmore);
		}
		exit(1);
	}
	close(fd);
#else /* DEF_PAGER */
	FILE *f;		/* free after Robert Viduya */

	if ((f = fopen(fnam, "r")) == NULL) {
		if (!silent) {
			home();
			perror(fnam);
			flags.toplin = 1;
			pline("Cannot open %s.", fnam);
		}
		return (0);
	}
	page_more(f, 0);
#endif /* DEF_PAGER */

	return (1);
}
Exemple #2
0
int
dowhatis()
{
	FILE *fp;
	char bufr[BUFSZ+6];
	char *buf = &bufr[6], q;
	size_t len;
	extern char readchar();

	if (!(fp = fopen(DATAFILE, "r")))
		pline("Cannot open data file!");
	else {
		pline("Specify what? ");
		q = readchar();
		if (q != '\t')
			while (fgets(buf,BUFSZ,fp))
				if (*buf == q) {
					len = strcspn(buf, "\n");
					/* bad data file */
					if (len == 0)
						continue;
					buf[len] = '\0';
					/* Expand tab 'by hand' */
					if (buf[1] == '\t'){
						buf = bufr;
						buf[0] = q;
						(void) strncpy(buf+1, "       ", 7);
						len = strlen(buf);
					}
					pline(buf);
					if (buf[len - 1] == ';') {
						pline("More info? ");
						if (readchar() == 'y') {
							page_more(fp,1); /* does fclose() */
							return(0);
						}
					}
					(void) fclose(fp); 	/* kopper@psuvax1 */
					return(0);
				}
		pline("I've never heard of such things.");
		(void) fclose(fp);
	}
	return(0);
}
Exemple #3
0
varargs int page(string data, string title, function callback, int no_ansi)
{
    if(!stringp(data)) return 0;
    if(stringp(title)) write("*===| Paging: " + title + " |===*\n\n");
    if(functionp(callback)) cb = callback;
    if(no_ansi) ansi = 0;
    currentLine = 0;

    if(!this_player()->query_env("morelines"))
	myLinesPerCycle = DEF_LINESPERCYCLE;
    else
	myLinesPerCycle = to_int(this_player()->query_env("morelines"));

    linesPerCycle = myLinesPerCycle - 1;

    exploded = explode(data, "\n");
    totalLines = sizeof(exploded);
    page_more();
}
Exemple #4
0
int
dowhatis()
{
	FILE           *fp;
	char            bufr[BUFSZ + 6];
	char           *buf = &bufr[6], *ep, q;

	if (!(fp = fopen(DATAFILE, "r")))
		pline("Cannot open data file!");
	else {
		pline("Specify what? ");
		q = readchar();
		if (q != '\t')
			while (fgets(buf, BUFSZ, fp))
				if (*buf == q) {
					ep = strchr(buf, '\n');
					if (ep)
						*ep = 0;
					/* else: bad data file */
					/* Expand tab 'by hand' */
					if (buf[1] == '\t') {
						buf = bufr;
						buf[0] = q;
						(void) strncpy(buf + 1, "       ", 7);
					}
					pline(buf);
					if (ep[-1] == ';') {
						pline("More info? ");
						if (readchar() == 'y') {
							page_more(fp, 1);	/* does fclose() */
							return (0);
						}
					}
					(void) fclose(fp);	/* kopper@psuvax1 */
					return (0);
				}
		pline("I've never heard of such things.");
		(void) fclose(fp);
	}
	return (0);
}