Exemple #1
0
_nc_tracechar(SCREEN *sp, int ch)
{
    NCURSES_CONST char *name;
    char *MyBuffer = ((sp != 0)
		      ? sp->tracechr_buf
		      : _nc_globals.tracechr_buf);
    size_t len = ((sp != 0)
		  ? _nc_screen_tracechr_buf_size
		  : _nc_globals_traceatr_color_buf_size);

    if (ch > KEY_MIN || ch < 0) {
	name = _nc_keyname(sp, ch);
	if (name == 0 || *name == '\0')
	    name = "NULL";
	(void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch);
    } else if (!is8bits(ch) || !isprint(UChar(ch))) {
	/*
	 * workaround for glibc bug:
	 * sprintf changes the result from unctrl() to an empty string if it
	 * does not correspond to a valid multibyte sequence.
	 */
	(void) snprintf(MyBuffer, len, "%#03o", ch);
    } else {
	name = _nc_unctrl(sp, (chtype) ch);
	if (name == 0 || *name == 0)
	    name = "null";	/* shouldn't happen */
	(void) snprintf(MyBuffer, len, "'%.30s' = %#03o", name, ch);
    }
    return (MyBuffer);
}
Exemple #2
0
wadd_wch(WINDOW *win, const cchar_t *wch)
{
    PUTC_DATA;
    int n;
    int code = ERR;

    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
				      _tracech_t(wch)));

    if (win != 0) {
	PUTC_INIT;
	for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
	    attr_t attrs = (wch->attr & A_ATTRIBUTES);

	    if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
		break;
	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
		code = ERR;
		if (is8bits(PUTC_ch))
		    code = waddch(win, UChar(PUTC_ch) | attrs);
		break;
	    }
	    for (n = 0; n < PUTC_n; n++) {
		if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
		    break;
		}
	    }
	    if (code == ERR)
		break;
	}
    }

    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}
Exemple #3
0
wecho_wchar(WINDOW *win, const cchar_t * wch)
{
    PUTC_DATA;
    int n;
    int code = ERR;

    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
				      _tracech_t(wch)));

    if (win != 0) {
	PUTC_INIT;
	while (PUTC_i < CCHARW_MAX) {
	    if ((PUTC_ch = wch->chars[PUTC_i++]) == L'\0')
		break;
	    if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
		code = ERR;
		if (is8bits(PUTC_ch))
		    code = waddch(win, UChar(PUTC_ch) | wch->attr);
		break;
	    }
	    for (n = 0; n < PUTC_n; n++) {
		if ((code = waddch(win, UChar(PUTC_buf[n]) | wch->attr)) == ERR) {
		    break;
		}
	    }
	    if (code == ERR)
		break;
	}
	wrefresh(win);
    }

    TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}
Exemple #4
0
wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
{
    int code = ERR;
    NCURSES_SIZE_T oy;
    NCURSES_SIZE_T ox;
    const wchar_t *cp;

    T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n));

    if (win != 0
            && wstr != 0) {
        if (n < 1)
            n = wcslen(wstr);
        code = OK;
        if (n > 0) {
            oy = win->_cury;
            ox = win->_curx;
            for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
                int len = wcwidth(*cp);

                if (len != 1 || !is8bits(*cp)) {
                    cchar_t tmp_cchar;
                    wchar_t tmp_wchar = *cp;
                    memset(&tmp_cchar, 0, sizeof(tmp_cchar));
                    (void) setcchar(&tmp_cchar,
                                    &tmp_wchar,
                                    WA_NORMAL,
                                    0,
                                    (void *) 0);
                    code = _nc_insert_wch(win, &tmp_cchar);
                } else {
                    /* tabs, other ASCII stuff */
                    code = _nc_insert_ch(win, (chtype) (*cp));
                }
                if (code != OK)
                    break;
            }

            win->_curx = ox;
            win->_cury = oy;
            _nc_synchook(win);
        }
    }
    returnCode(code);
}
Exemple #5
0
static
#if !USE_WIDEC_SUPPORT		/* cannot be inline if it is recursive */
NCURSES_INLINE
#endif
int
waddch_literal(WINDOW *win, NCURSES_CH_T ch)
{
    int x;
    int y;
    struct ldat *line;

    x = win->_curx;
    y = win->_cury;

    CHECK_POSITION(win, x, y);

    ch = render_char(win, ch);

    line = win->_line + y;

    CHANGED_CELL(line, x);

    /*
     * Build up multibyte characters until we have a wide-character.
     */
    if_WIDEC({
	if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
	    int len = _nc_build_wch(win, CHREF(ch));

	    if (len >= -1) {
		/* handle EILSEQ */
		if (is8bits(CharOf(ch))) {
		    const char *s = unctrl((chtype) CharOf(ch));
		    if (s[1] != 0) {
			return waddstr(win, s);
		    }
		}
		if (len == -1)
		    return waddch(win, ' ');
	    } else {
		return OK;
	    }
	}
    });
_tracechar(int ch)
{
    NCURSES_CONST char *name;

    if (ch > KEY_MIN || ch < 0) {
        name = keyname(ch);
        if (name == 0 || *name == '\0')
            name = "NULL";
        (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
    } else if (!is8bits(ch) || !isprint(UChar(ch))) {
        /*
         * workaround for glibc bug:
         * sprintf changes the result from unctrl() to an empty string if it
         * does not correspond to a valid multibyte sequence.
         */
        (void) sprintf(MyBuffer, "%#03o", ch);
    } else {
        name = unctrl((chtype) ch);
        if (name == 0 || *name == 0)
            name = "null";	/* shouldn't happen */
        (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
    }
    return (MyBuffer);
}
Exemple #7
0
static int
relative_move(string_desc * target, int from_y, int from_x, int to_y, int
	      to_x, bool ovw)
/* move via local motions (cuu/cuu1/cud/cud1/cub1/cub/cuf1/cuf/vpa/hpa) */
{
    string_desc save;
    int n, vcost = 0, hcost = 0;

    (void) _nc_str_copy(&save, target);

    if (to_y != from_y) {
	vcost = INFINITY;

	if (row_address != 0
	    && _nc_safe_strcat(target, TPARM_1(row_address, to_y))) {
	    vcost = SP->_vpa_cost;
	}

	if (to_y > from_y) {
	    n = (to_y - from_y);

	    if (parm_down_cursor
		&& SP->_cud_cost < vcost
		&& _nc_safe_strcat(_nc_str_copy(target, &save),
				   TPARM_1(parm_down_cursor, n))) {
		vcost = SP->_cud_cost;
	    }

	    if (cursor_down
		&& (*cursor_down != '\n' || SP->_nl)
		&& (n * SP->_cud1_cost < vcost)) {
		vcost = repeated_append(_nc_str_copy(target, &save), 0,
					SP->_cud1_cost, n, cursor_down);
	    }
	} else {		/* (to_y < from_y) */
	    n = (from_y - to_y);

	    if (parm_up_cursor
		&& SP->_cuu_cost < vcost
		&& _nc_safe_strcat(_nc_str_copy(target, &save),
				   TPARM_1(parm_up_cursor, n))) {
		vcost = SP->_cuu_cost;
	    }

	    if (cursor_up && (n * SP->_cuu1_cost < vcost)) {
		vcost = repeated_append(_nc_str_copy(target, &save), 0,
					SP->_cuu1_cost, n, cursor_up);
	    }
	}

	if (vcost == INFINITY)
	    return (INFINITY);
    }

    save = *target;

    if (to_x != from_x) {
	char str[OPT_SIZE];
	string_desc check;

	hcost = INFINITY;

	if (column_address
	    && _nc_safe_strcat(_nc_str_copy(target, &save),
			       TPARM_1(column_address, to_x))) {
	    hcost = SP->_hpa_cost;
	}

	if (to_x > from_x) {
	    n = to_x - from_x;

	    if (parm_right_cursor
		&& SP->_cuf_cost < hcost
		&& _nc_safe_strcat(_nc_str_copy(target, &save),
				   TPARM_1(parm_right_cursor, n))) {
		hcost = SP->_cuf_cost;
	    }

	    if (cursor_right) {
		int lhcost = 0;

		(void) _nc_str_init(&check, str, sizeof(str));

#if USE_HARD_TABS
		/* use hard tabs, if we have them, to do as much as possible */
		if (init_tabs > 0 && tab) {
		    int nxt, fr;

		    for (fr = from_x; (nxt = NEXTTAB(fr)) <= to_x; fr = nxt) {
			lhcost = repeated_append(&check, lhcost,
						 SP->_ht_cost, 1, tab);
			if (lhcost == INFINITY)
			    break;
		    }

		    n = to_x - fr;
		    from_x = fr;
		}
#endif /* USE_HARD_TABS */

		if (n <= 0 || n >= (int) check.s_size)
		    ovw = FALSE;
#if BSD_TPUTS
		/*
		 * If we're allowing BSD-style padding in tputs, don't generate
		 * a string with a leading digit.  Otherwise, that will be
		 * interpreted as a padding value rather than sent to the
		 * screen.
		 */
		if (ovw
		    && n > 0
		    && n < (int) check.s_size
		    && vcost == 0
		    && str[0] == '\0') {
		    int wanted = CharOf(WANT_CHAR(to_y, from_x));
		    if (is8bits(wanted) && isdigit(wanted))
			ovw = FALSE;
		}
#endif
		/*
		 * If we have no attribute changes, overwrite is cheaper.
		 * Note: must suppress this by passing in ovw = FALSE whenever
		 * WANT_CHAR would return invalid data.  In particular, this
		 * is true between the time a hardware scroll has been done
		 * and the time the structure WANT_CHAR would access has been
		 * updated.
		 */
		if (ovw) {
		    int i;

		    for (i = 0; i < n; i++) {
			NCURSES_CH_T ch = WANT_CHAR(to_y, from_x + i);
			if (!SameAttrOf(ch, SCREEN_ATTRS(SP))
#if USE_WIDEC_SUPPORT
			    || !Charable(ch)
#endif
			    ) {
			    ovw = FALSE;
			    break;
			}
		    }
		}
		if (ovw) {
		    int i;

		    for (i = 0; i < n; i++)
			*check.s_tail++ = CharOf(WANT_CHAR(to_y, from_x + i));
		    *check.s_tail = '\0';
		    check.s_size -= n;
		    lhcost += n * SP->_char_padding;
		} else {
		    lhcost = repeated_append(&check, lhcost, SP->_cuf1_cost,
					     n, cursor_right);
		}

		if (lhcost < hcost
		    && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
		    hcost = lhcost;
		}
	    }
	} else {		/* (to_x < from_x) */
	    n = from_x - to_x;

	    if (parm_left_cursor
		&& SP->_cub_cost < hcost
		&& _nc_safe_strcat(_nc_str_copy(target, &save),
				   TPARM_1(parm_left_cursor, n))) {
		hcost = SP->_cub_cost;
	    }

	    if (cursor_left) {
		int lhcost = 0;

		(void) _nc_str_init(&check, str, sizeof(str));

#if USE_HARD_TABS
		if (init_tabs > 0 && back_tab) {
		    int nxt, fr;

		    for (fr = from_x; (nxt = LASTTAB(fr)) >= to_x; fr = nxt) {
			lhcost = repeated_append(&check, lhcost,
						 SP->_cbt_cost, 1, back_tab);
			if (lhcost == INFINITY)
			    break;
		    }

		    n = fr - to_x;
		}
#endif /* USE_HARD_TABS */

		lhcost = repeated_append(&check, lhcost, SP->_cub1_cost, n, cursor_left);

		if (lhcost < hcost
		    && _nc_safe_strcat(_nc_str_copy(target, &save), str)) {
		    hcost = lhcost;
		}
	    }
	}

	if (hcost == INFINITY)
	    return (INFINITY);
    }

    return (vcost + hcost);
}
Exemple #8
0
static
#if !USE_WIDEC_SUPPORT		/* cannot be inline if it is recursive */
NCURSES_INLINE
#endif
int
waddch_literal(WINDOW *win, NCURSES_CH_T ch)
{
    int x;
    int y;
    struct ldat *line;

    x = win->_curx;
    y = win->_cury;

    CHECK_POSITION(win, x, y);

    ch = render_char(win, ch);

    line = win->_line + y;

    CHANGED_CELL(line, x);

    /*
     * Build up multibyte characters until we have a wide-character.
     */
#if NCURSES_SP_FUNCS
#define DeriveSP() SCREEN *sp = _nc_screen_of(win);
#else
#define DeriveSP()		/*nothing */
#endif
    if_WIDEC({
	DeriveSP();
	if (WINDOW_EXT(win, addch_used) != 0 || !Charable(ch)) {
	    int len = _nc_build_wch(win, CHREF(ch));

	    if (len >= -1) {
		attr_t attr = AttrOf(ch);

		/* handle EILSEQ (i.e., when len >= -1) */
		if (len == -1 && is8bits(CharOf(ch))) {
		    int rc = OK;
		    const char *s = NCURSES_SP_NAME(unctrl)
		      (NCURSES_SP_ARGx (chtype) CharOf(ch));

		    if (s[1] != '\0') {
			while (*s != '\0') {
			    rc = waddch(win, UChar(*s) | attr);
			    if (rc != OK)
				break;
			    ++s;
			}
			return rc;
		    }
		}
		if (len == -1)
		    return waddch(win, ' ' | attr);
	    } else {
		return OK;
	    }
	}
    });