示例#1
0
slk_wset(int i, const wchar_t *astr, int format)
{
    int result = ERR;
    size_t arglen;
    const wchar_t *str;
    char *mystr;
    mbstate_t state;

    T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));

    init_mb(state);
    str = astr;
    if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) {
	if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) {
	    str = astr;
	    if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) {
		/* glibc documentation claims that the terminating L'\0'
		 * is written, but it is not...
		 */
		mystr[arglen] = 0;
		result = slk_set(i, mystr, format);
	    }
	    free(mystr);
	}
    }
    returnCode(result);
}
示例#2
0
setcchar(cchar_t *wcval,
	 const wchar_t *wch,
	 const attr_t attrs,
	 short color_pair,
	 const void *opts)
{
    unsigned i;
    unsigned len;
    int code = OK;

    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"),
		      (void *) wcval, _nc_viswbuf(wch),
		      (unsigned long) attrs, color_pair, opts));

    len = (unsigned) wcslen(wch);
    if (opts != NULL
	|| (len > 1 && wcwidth(wch[0]) < 0)) {
	code = ERR;
    } else {
	if (len > CCHARW_MAX)
	    len = CCHARW_MAX;

	/*
	 * If we have a following spacing-character, stop at that point.  We
	 * are only interested in adding non-spacing characters.
	 */
	for (i = 1; i < len; ++i) {
	    if (wcwidth(wch[i]) != 0) {
		len = i;
		break;
	    }
	}

	memset(wcval, 0, sizeof(*wcval));

	if (len != 0) {
	    SetAttr(*wcval, attrs | (attr_t) ColorPair(color_pair));
	    SetPair(CHDEREF(wcval), color_pair);
	    memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
	    TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
			      _tracecchar_t(wcval)));
	}
    }

    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}
示例#3
0
winnwstr(WINDOW *win, wchar_t *wstr, int n)
{
    int count = 0;
    cchar_t *text;

    T((T_CALLED("winnwstr(%p,%p,%d)"), (void *) win, (void *) wstr, n));
    if (wstr != 0) {
	if (win) {
	    int row, col;
	    int last = 0;

	    getyx(win, row, col);

	    text = win->_line[row].text;
	    while (count < n && count != ERR) {

		if (!isWidecExt(text[col])) {
		    int inx;
		    wchar_t wch;

		    for (inx = 0; (inx < CCHARW_MAX)
			 && ((wch = text[col].chars[inx]) != 0);
			 ++inx) {
			if (count + 1 > n) {
			    if ((count = last) == 0) {
				count = ERR;	/* error if we store nothing */
			    }
			    break;
			}
			wstr[count++] = wch;
		    }
		}
		last = count;
		if (++col > win->_maxx) {
		    break;
		}
	    }
	}
	if (count > 0) {
	    wstr[count] = '\0';
	    T(("winnwstr returns %s", _nc_viswbuf(wstr)));
	}
    }
    returnCode(count);
}
示例#4
0
setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs,
	 short color_pair, const void *opts)
{
    int i;
    int len;
    int code = OK;

    TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%ld,%d,%p)"),
		      wcval, _nc_viswbuf(wch), attrs, color_pair, opts));

    if (opts != NULL || (len = wcslen(wch)) > CCHARW_MAX
	|| (len > 0 && wcwidth(wch[0]) < 0)) {
	code = ERR;
    } else {

	for (i = 1; i < len; ++i) {
	    if (wcwidth(wch[i]) != 0) {
		code = ERR;
		break;
	    }
	}

	if (code != ERR) {
	    memset(wcval, 0, sizeof(*wcval));

	    if (len != 0) {
		SetAttr(*wcval, attrs | color_pair);
		memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
		TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
				  _tracecchar_t(wcval)));
	    }
	}
    }

    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}