/* * waddchnstr -- * Add a string (at most n characters) to the given window * starting at (_cury, _curx) until the end of line is reached or * n characters have been added. If n is negative, add as much * of the string that will fit on the current line. SUSv2 says * that the addchnstr family does not wrap and strings are truncated * to the RHS of the window. */ int waddchnstr(WINDOW *win, const chtype *chstr, int n) { size_t len; const chtype *chp; attr_t attr; char *ocp, *cp, *start; int i, ret, ox, oy; #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "waddchnstr: win = %p, chstr = %p, n = %d\n", win, chstr, n); #endif if (n >= 0) for (chp = chstr, len = 0; n-- && *chp++; ++len); else for (chp = chstr, len = 0; *chp++; ++len); /* check if string is too long for current location */ if (len > (win->maxx - win->curx)) len = win->maxx - win->curx; if ((ocp = malloc(len + 1)) == NULL) return ERR; chp = chstr; cp = ocp; start = ocp; i = 0; attr = (*chp) & __ATTRIBUTES; ox = win->curx; oy = win->cury; while (len) { *cp = (*chp) & __CHARTEXT; cp++; chp++; i++; len--; if (((*chp) & __ATTRIBUTES) != attr) { *cp = '\0'; if (_cursesi_waddbytes(win, start, i, attr, 0) == ERR) { free(ocp); return ERR; } attr = (*chp) & __ATTRIBUTES; start = cp; i = 0; } } *cp = '\0'; ret = _cursesi_waddbytes(win, start, i, attr, 0); free(ocp); wmove(win, oy, ox); return ret; }
int __waddch(WINDOW *win, __LDATA *dp) { char buf[2]; buf[0] = dp->ch; buf[1] = '\0'; return (_cursesi_waddbytes(win, buf, 1, dp->attr, 1)); }