示例#1
0
/*
 * waddnstr --
 *	Add a string (at most n characters) to the given window
 *	starting at (_cury, _curx).  If n is negative, add the
 *	entire string.
 */
int
waddnstr(WINDOW *win, const char *s, int n)
{
    size_t  len;
    const char *p;

#ifdef DEBUG
    __CTRACE(__CTRACE_INPUT, "ADDNSTR: win %p, length %d\n",
             win, n);
#endif
    /*
     * behavior changed from traditional BSD curses, for better XCURSES
     * conformance.
     *
     * BSD curses: if (n > 0) then "at most n", else "len = strlen(s)"
     * ncurses: if (n >= 0) then "at most n", else "len = strlen(s)"
     * XCURSES: if (n != -1) then "at most n", else "len = strlen(s)"
     *
     * Also SUSv2 says these functions do not wrap nor change the
     * cursor position.
     */
    if (n >= 0)
        for (p = s, len = 0; n-- && *p++; ++len);
    else
        len = strlen(s);

    if (len > (win->maxx - win->curx))
        len = win->maxx - win->curx;

    return(waddbytes(win, s, (int) len));
}
/*
 * waddnstr --
 *	Add a string (at most n characters) to the given window
 *	starting at (_cury, _curx).  If n is negative, add the
 *	entire string.
 */
int
waddnstr(WINDOW *win, const char *s, int n)
{
	size_t  len;
	const char *p;

#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT, "ADDNSTR: win %p, length %d\n",
			 win, n);
#endif
	/*
	 * behavior changed from traditional BSD curses, for better XCURSES
	 * conformance.
	 *
	 * BSD curses: if (n > 0) then "at most n", else "len = strlen(s)"
	 * ncurses: if (n >= 0) then "at most n", else "len = strlen(s)"
	 * XCURSES: if (n != -1) then "at most n", else "len = strlen(s)"
	 * 
	 */
	if (n >= 0)
		for (p = s, len = 0; n-- && *p++; ++len);
	else
		len = strlen(s);
	
	return(waddbytes(win, s, (int) len));
}
示例#3
0
文件: addstr.c 项目: jamjr/Helios-NG
/*
 *	This routine adds a string starting at (_cury,_curx)
 *
 */
int waddstr(
reg WINDOW	*win,
reg char	*str )
{
# ifdef DEBUG
	fprintf(outf, "WADDSTR(\"%s\")\n", str);
# endif
	return waddbytes(win, str, strlen(str));
}
示例#4
0
/*
 * waddnstr --
 *	Add a string (at most n characters) to the given window
 *	starting at (_cury, _curx).  If n is negative, add the
 *	entire string.
 */
int
waddnstr(WINDOW *win, const char *s, int n)
{
	size_t len;
	const char *p;

	if (n > 0)
		for (p = s, len = 0; n-- && *p++; ++len);
	else
		len = strlen(s);
	return (waddbytes(win, s, len));
}
示例#5
0
/*
 * _cursesi_addbyte -
 *	Internal function to add a byte and update the row and column
 * positions as appropriate.  This function is only used in the narrow
 * character version of curses.
 */
int
_cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c,
		 attr_t attr)
{
	static char	 blanks[] = "        ";
	int		 newx;
	attr_t		 attributes;

	switch (c) {
	case '\t':
		PSYNCH_OUT;
		if (waddbytes(win, blanks, 8 - (*x % 8)) == ERR)
			return (ERR);
		PSYNCH_IN;
		break;

	default:
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n",
			 win, *y, *x);
#endif

		if ((*lp)->flags & __ISPASTEOL) {
		  new_line:
			*x = 0;
			(*lp)->flags &= ~__ISPASTEOL;
			if (*y == win->scr_b) {
#ifdef DEBUG
				__CTRACE(__CTRACE_INPUT,
					 "ADDBYTES - on bottom "
					 "of scrolling region\n");
#endif
				if (!(win->flags & __SCROLLOK))
					return ERR;
				PSYNCH_OUT;
				scroll(win);
				PSYNCH_IN;
			} else {
				(*y)++;
			}
			*lp = win->alines[*y];
			if (c == '\n')
				break;
		}

		attributes = (win->wattr | attr) &
			(__ATTRIBUTES & ~__COLOR);
		if (attr & __COLOR)
			attributes |= attr & __COLOR;
		else if (win->wattr & __COLOR)
			attributes |= win->wattr & __COLOR;
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT,
			 "ADDBYTES: 1: y = %d, x = %d, firstch = %d, "
			 "lastch = %d\n",
			 *y, *x, *win->alines[*y]->firstchp,
			 *win->alines[*y]->lastchp);
#endif
		/*
		 * Always update the change pointers.  Otherwise,
		 * we could end up not displaying 'blank' characters
		 * when overlapping windows are displayed.
		 */
		newx = *x + win->ch_off;
		(*lp)->flags |= __ISDIRTY;
		/*
		 * firstchp/lastchp are shared between
		 * parent window and sub-window.
		 */
		if (newx < *(*lp)->firstchp)
			*(*lp)->firstchp = newx;
		if (newx > *(*lp)->lastchp)
			*(*lp)->lastchp = newx;
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT,
			 "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
			 *(*lp)->firstchp, *(*lp)->lastchp,
			 *(*lp)->firstchp - win->ch_off,
			 *(*lp)->lastchp - win->ch_off);
#endif
		if (win->bch != ' ' && c == ' ')
			(*lp)->line[*x].ch = win->bch;
		else
			(*lp)->line[*x].ch = c;

		if (attributes & __COLOR)
			(*lp)->line[*x].attr =
				attributes | (win->battr & ~__COLOR);
		else
			(*lp)->line[*x].attr = attributes | win->battr;

		if (*x == win->maxx - 1)
			(*lp)->flags |= __ISPASTEOL;
		else
			(*x)++;
#ifdef DEBUG
		__CTRACE(__CTRACE_INPUT,
			 "ADDBYTES: 2: y = %d, x = %d, firstch = %d, "
			 "lastch = %d\n",
			 *y, *x, *win->alines[*y]->firstchp,
			 *win->alines[*y]->lastchp);
#endif
		break;
	case '\n':
		PSYNCH_OUT;
		wclrtoeol(win);
		PSYNCH_IN;
		goto new_line;
	case '\r':
		*x = 0;
		break;
	case '\b':
		if (--(*x) < 0)
			*x = 0;
		break;
	}

	return (OK);
}
示例#6
0
/*
 *	This routine adds the character to the current position
 *
waddbytes(register WINDOW *win, register const char *bytes, register int count)
 */
int
waddbytes(WINDOW *win, const char *bytes, int count)
{
#define	SYNCH_OUT()	{win->_cury = y; win->_curx = x;}
#define	SYNCH_IN()	{y = win->_cury; x = win->_curx;}
	register int		x, y;
	register int		newx;

	SYNCH_IN();
# ifdef FULLDEBUG
	fprintf(outf, "ADDBYTES('%c') at (%d, %d)\n", c, y, x);
# endif
	while (count--) {
	    register int c;
	    static char blanks[] = "        ";

	    c = *bytes++;
	    switch (c) {
	      case '\t':
		    SYNCH_IN();
		    if (waddbytes(win, blanks, 8-(x%8)) == ERR) {
			return ERR;
		    }
		    SYNCH_OUT();
		    break;

	      default:
# ifdef FULLDEBUG
		    fprintf(outf, "ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
# endif
		    if (win->_flags & _STANDOUT)
			    c |= _STANDOUT;
		    {
# ifdef	FULLDEBUG
			    fprintf(outf, "ADDBYTES(%0.2o, %d, %d)\n", win, y, x);
# endif
			    if (win->_y[y][x] != c) {
				    newx = x + win->_ch_off;
				    if (win->_firstch[y] == _NOCHANGE) {
					    win->_firstch[y] =
							    win->_lastch[y] = newx;
				    } else if (newx < win->_firstch[y])
					    win->_firstch[y] = newx;
				    else if (newx > win->_lastch[y])
					    win->_lastch[y] = newx;
# ifdef FULLDEBUG
				    fprintf(outf, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
					    win->_firstch[y], win->_lastch[y],
					    win->_firstch[y] - win->_ch_off,
					    win->_lastch[y] - win->_ch_off);
# endif
			    }
		    }
		    win->_y[y][x++] = c;
		    if (x >= win->_maxx) {
			    x = 0;
    newline:
			    if (++y >= win->_maxy)
				    if (win->_scroll) {
					    SYNCH_OUT();
					    scroll(win);
					    SYNCH_IN();
					    --y;
				    }
				    else
					    return ERR;
		    }
# ifdef FULLDEBUG
		    fprintf(outf, "ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n", y, x, win->_firstch[y], win->_lastch[y]);
# endif
		    break;
	      case '\n':
		    SYNCH_OUT();
		    wclrtoeol(win);
		    SYNCH_IN();
		    if (!NONL)
			    x = 0;
		    goto newline;
	      case '\r':
		    x = 0;
		    break;
	      case '\b':
		    if (--x < 0)
			    x = 0;
		    break;
	    }
    }
    SYNCH_OUT();
    return OK;
}