Exemple #1
0
void
clrlin(void)
{
	if(flags.toplin) {
		home();
		cl_end();
		if(tly > 1) docorner(1, tly-1);
		remember_topl();
	}
	flags.toplin = 0;
}
Exemple #2
0
void
vpline(const char *line, va_list ap)
{
	char pbuf[BUFSZ];
	char *bp = pbuf, *tl;
	int n,n0;

	if(!line || !*line) return;
	(void) vsnprintf(pbuf, sizeof pbuf, line, ap);
	if(flags.toplin == 1 && !strcmp(pbuf, toplines)) return;
	nscr();		/* %% */

	/* If there is room on the line, print message on same line */
	/* But messages like "You die..." deserve their own line */
	n0 = strlen(bp);
	if(flags.toplin == 1 && tly == 1 &&
	    n0 + strlen(toplines) + 3 < CO-8 &&  /* leave room for --More-- */
	    strncmp(bp, "You ", 4)) {
		(void) strlcat(toplines, "  ", sizeof toplines);
		(void) strlcat(toplines, bp, sizeof toplines);
		tlx += 2;
		addtopl(bp);
		return;
	}
	if(flags.toplin == 1) more();
	remember_topl();
	toplines[0] = 0;
	while(n0){
		if(n0 >= CO){
			/* look for appropriate cut point */
			n0 = 0;
			for(n = 0; n < CO; n++) if(bp[n] == ' ')
				n0 = n;
			if(!n0) for(n = 0; n < CO-1; n++)
				if(!letter(bp[n])) n0 = n;
			if(!n0) n0 = CO-2;
		}
		(void) strncpy((tl = eos(toplines)), bp, n0);
		tl[n0] = '\0';
		bp += n0;

		/* remove trailing spaces, but leave one */
		while(n0 > 1 && tl[n0-1] == ' ' && tl[n0-2] == ' ')
			tl[--n0] = 0;

		n0 = strlen(bp);
		if(n0 && tl[0])
			(void) strlcat(tl, "\n",
			    toplines + sizeof toplines - tl);
	}
	redotoplin();
}
Exemple #3
0
void clrlin()
{
    if(flags.topl != 0) {
        home();
        cl_end();

        if(tly > 1) {
            docorner(1, tly - 1);
        }

        remember_topl();
    }

    flags.topl = 0;
}
Exemple #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);
	}
}
Exemple #5
0
void pline(char *line, ...)
{
    char pbuf[BUFSZ];
    char *bp = pbuf;
    char *tl;
    int n;
    int n0;

    if((line == NULL) || (*line == 0)) {
        return;
    }

    if(index(line, '%') == 0) {
        strcpy(pbuf, line);
    }
    else {
        va_list args;
        va_start(args, line);
        vsprintf(pbuf, line, args);
        va_end(args);
    }

    if((flags.topl == 1) && (strcmp(pbuf, toplines) == 0)) {
        return;
    }

    /* %% */
    nscr();

    /*
     * If there is room on the line, print message on same line.
     * But messages like "You die..." deserve their own line
     */
    n0 = strlen(bp);

    if((flags.topl == 1)
       && (tly == 1)
       && (((n0 + strlen(toplines)) + 3) < TOPLSZ)
       && (strncmp(bp, "You ", 4) != 0)) {
        strcat(toplines, "  ");
        strcat(toplines, bp);
        tlx +=2;
        
        return;
    }

    if(flags.topl == 1) {
        more();
    }

    remember_topl();
    toplines[0] = 0;

    while(n0 != 0) {
        if(n0 >= COLNO) {
            /* Look for appropriate cut point */
            n0 = 0;
            for(n = 0; n < COLNO; ++n) {
                if(bp[n] == ' ') {
                    n0 = n;
                }
            }

            if(n0 == 0) {
                for(n = 0; n < COLNO - 1; ++n) {
                    if(letter(bp[n]) == 0) {
                        n0 = n;
                    }
                }
            }

            if(n0 == 0) {
                n0 = COLNO - 2;
            }
        }

        tl = eos(toplines);
        strncpy(tl, bp, n0);
        tl[n0] = 0;
        bp += n0;

        /* Remove the trailing spaces, but leave one */
        while((n0 > 1) && (tl[n0 - 1] == ' ') && (tl[n0 - 2] == ' ')) {
            --n0;
            tl[n0] = 0;
        }

        n0 = strlen(bp);

        if((n0 != 0) && (tl[0] != 0)) {
            strcat(tl, "\n");
        }
    }

    redotoplin();
}