Esempio n. 1
0
/* strip: nr of chars to be stripped from each line (0 or 1) */
static void
page_more(FILE *fp, int strip)
{
	char *bufr, *ep;
	sig_t prevsig = signal(SIGINT, intruph);

	set_pager(0);
	bufr = alloc((unsigned)CO);
	bufr[CO - 1] = 0;
	while (fgets(bufr, CO - 1, fp) && (!strip || *bufr == '\t') && !got_intrup) {
		ep = strchr(bufr, '\n');
		if (ep)
			*ep = 0;
		if (page_line(bufr + strip)) {
			set_pager(2);
			goto ret;
		}
	}
	set_pager(1);
ret:
	free(bufr);
	fclose(fp);
	signal(SIGINT, prevsig);
	got_intrup = 0;
}
Esempio n. 2
0
/* strip: nr of chars to be stripped from each line (0 or 1) */
static void
page_more(FILE *fp, int strip)
{
	char *bufr;
	sig_t prevsig = signal(SIGINT, intruph);

	set_pager(0);
	bufr = (char *) alloc((unsigned) CO);
	while (fgets(bufr, CO, fp) && (!strip || *bufr == '\t') &&
	    !got_intrup) {
		bufr[strcspn(bufr, "\n")] = '\0';
		if (page_line(bufr+strip)) {
			set_pager(2);
			goto ret;
		}
	}
	set_pager(1);
ret:
	free(bufr);
	(void) fclose(fp);
	(void) signal(SIGINT, prevsig);
	got_intrup = 0;
}
Esempio n. 3
0
int
doinvbill(int mode)	/* 0: deliver count 1: paged */
{
	struct bill_x *bp;
	struct obj *obj;
	long totused, thisused;
	char buf[BUFSZ];

	if (mode == 0) {
		int cnt = 0;

		if (shopkeeper)
			for (bp = bill; bp - bill < ESHK(shopkeeper)->billct; bp++)
				if (bp->useup ||
				    ((obj = bp_to_obj(bp)) && obj->quan < bp->bquan))
					cnt++;
		return (cnt);
	}

	if (!shopkeeper) {
		impossible("doinvbill: no shopkeeper?");
		return (0);
	}

	set_pager(0);
	if (page_line("Unpaid articles already used up:") || page_line(""))
		goto quit;

	totused = 0;
	for (bp = bill; bp - bill < ESHK(shopkeeper)->billct; bp++) {
		obj = bp_to_obj(bp);
		if (!obj) {
			impossible("Bad shopkeeper administration.");
			goto quit;
		}
		if (bp->useup || bp->bquan > obj->quan) {
			int cnt, oquan, uquan;

			oquan = obj->quan;
			uquan = (bp->useup ? bp->bquan : bp->bquan - oquan);
			thisused = bp->price * uquan;
			totused += thisused;
			obj->quan = uquan;	/* cheat doname */
			sprintf(buf, "x -  %s", doname(obj));
			obj->quan = oquan;	/* restore value */
			for (cnt = 0; buf[cnt]; cnt++)
				; /* nothing */
			while (cnt < 50)
				buf[cnt++] = ' ';
			sprintf(&buf[cnt], " %5ld zorkmids", thisused);
			if (page_line(buf))
				goto quit;
		}
	}
	sprintf(buf, "Total:%50ld zorkmids", totused);
	if (page_line("") || page_line(buf))
		goto quit;
	set_pager(1);
	return (0);
quit:
	set_pager(2);
	return (0);
}
Esempio n. 4
0
/*
 * Flexible pager: feed it with a number of lines and it will decide
 * whether these should be fed to the pager above, or displayed in a
 * corner.
 * Call:
 *	cornline(0, title or 0)	: initialize
 *	cornline(1, text)	: add text to the chain of texts
 *	cornline(2, morcs)	: output everything and cleanup
 *	cornline(3, 0)		: cleanup
 */
void
cornline(int mode, char *text)
{
	static struct line {
		struct line *next_line;
		char *line_text;
	} *texthead, *texttail;
	static int maxlen;
	static int linect;
	struct line *tl;

	if(mode == 0) {
		texthead = 0;
		maxlen = 0;
		linect = 0;
		if(text) {
			cornline(1, text);	/* title */
			cornline(1, "");	/* blank line */
		}
		return;
	}

	if(mode == 1) {
	    int len;

	    if(!text) return;	/* superfluous, just to be sure */
	    linect++;
	    len = strlen(text);
	    if(len > maxlen)
		maxlen = len;
	    tl = (struct line *)
		alloc((unsigned)(len + sizeof(struct line) + 1));
	    tl->next_line = 0;
	    tl->line_text = (char *)(tl + 1);
	    (void) strlcpy(tl->line_text, text, len + 1);
	    if(!texthead)
		texthead = tl;
	    else
		texttail->next_line = tl;
	    texttail = tl;
	    return;
	}

	/* --- now we really do it --- */
	if(mode == 2 && linect == 1)			    /* topline only */
		pline(texthead->line_text);
	else
	if(mode == 2) {
	    int curline, lth;

	    if(flags.toplin == 1) more();	/* ab@unido */
	    remember_topl();

	    lth = CO - maxlen - 2;		   /* Use full screen width */
	    if (linect < LI && lth >= 10) {		     /* in a corner */
		home();
		cl_end();
		flags.toplin = 0;
		curline = 1;
		for (tl = texthead; tl; tl = tl->next_line) {
		    curs(lth, curline);
		    if(curline > 1)
			cl_end();
		    putsym(' ');
		    putstr (tl->line_text);
		    curline++;
		}
		curs(lth, curline);
		cl_end();
		cmore(text);
		home();
		cl_end();
		docorner(lth, curline-1);
	    } else {					/* feed to pager */
		set_pager(0);
		for (tl = texthead; tl; tl = tl->next_line) {
		    if (page_line (tl->line_text)) {
			set_pager(2);
			goto cleanup;
		    }
		}
		if(text) {
			cgetret(text);
			set_pager(2);
		} else
			set_pager(1);
	    }
	}

cleanup:
	while ((tl = texthead)) {
		texthead = tl->next_line;
		free((char *) tl);
	}
}