/* * wdelch -- * Do a delete-char on the line, leaving (cury, curx) unchanged. */ int wdelch(WINDOW *win) { __LDATA *end, *temp1, *temp2; int cw, sx; nschar_t *np, *tnp; end = &win->alines[win->cury]->line[win->maxx - 1]; sx = win->curx; temp1 = &win->alines[win->cury]->line[win->curx]; cw = WCOL( *temp1 ); if ( cw < 0 ) { temp1 += cw; sx += cw; cw = WCOL( *temp1 ); } np = temp1->nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } temp1->nsp = NULL; } if ( sx + cw < win->maxx ) { temp2 = temp1 + cw; while ( temp1 < end - ( cw - 1 )) { ( void )memcpy( temp1, temp2, sizeof( __LDATA )); temp1++, temp2++; } } while ( temp1 <= end ) { temp1->ch = ( wchar_t )btowc(( int ) win->bch ); temp1->attr = 0; if (_cursesi_copy_nsp(win->bnsp, temp1) == ERR) return ERR; SET_WCOL(*temp1, 1); temp1++; } __touchline(win, (int) win->cury, sx, (int) win->maxx - 1); return (OK); }
/* * _cursesi_addwchar - * Internal function to add a wide character and update the row * and column positions. */ int _cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x, const cchar_t *wch) { #ifndef HAVE_WCHAR return (ERR); #else int sx = 0, ex = 0, cw = 0, i = 0, newx = 0; __LDATA *lp = &win->alines[*y]->line[*x], *tp = NULL; nschar_t *np = NULL; cchar_t cc; attr_t attributes; /* special characters handling */ switch (wch->vals[0]) { case L'\b': if (--*x < 0) *x = 0; win->curx = *x; return OK; case L'\r': *x = 0; return OK; case L'\n': wclrtoeol(win); PSYNCH_IN; *x = 0; (*lnp)->flags &= ~__ISPASTEOL; if (*y == win->scr_b) { if (!(win->flags & __SCROLLOK)) return ERR; PSYNCH_OUT; scroll(win); PSYNCH_IN; } else { (*y)++; } PSYNCH_OUT; return OK; case L'\t': cc.vals[0] = L' '; cc.elements = 1; cc.attributes = win->wattr; for (i = 0; i < 8 - (*x % 8); i++) { if (wadd_wch(win, &cc) == ERR) return ERR; } return OK; } /* check for non-spacing character */ if (!wcwidth(wch->vals[0])) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: char '%c' is non-spacing\n", wch->vals[0]); #endif /* DEBUG */ cw = WCOL(*lp); if (cw < 0) { lp += cw; *x += cw; } for (i = 0; i < wch->elements; i++) { if (!(np = (nschar_t *) malloc(sizeof(nschar_t)))) return ERR;; np->ch = wch->vals[i]; np->next = lp->nsp; lp->nsp = np; } (*lnp)->flags |= __ISDIRTY; newx = *x + win->ch_off; if (newx < *(*lnp)->firstchp) *(*lnp)->firstchp = newx; if (newx > *(*lnp)->lastchp) *(*lnp)->lastchp = newx; __touchline(win, *y, *x, *x); return OK; } /* check for new line first */ if ((*lnp)->flags & __ISPASTEOL) { *x = 0; (*lnp)->flags &= ~__ISPASTEOL; if (*y == win->scr_b) { if (!(win->flags & __SCROLLOK)) return ERR; PSYNCH_OUT; scroll(win); PSYNCH_IN; } else { (*y)++; } (*lnp) = win->alines[*y]; lp = &win->alines[*y]->line[*x]; } /* clear out the current character */ cw = WCOL(*lp); if (cw >= 0) { sx = *x; } else { for (sx = *x - 1; sx >= max(*x + cw, 0); sx--) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: clear current char (%d,%d)\n", *y, sx); #endif /* DEBUG */ tp = &win->alines[*y]->line[sx]; tp->ch = (wchar_t) btowc((int) win->bch); if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) return ERR; tp->attr = win->battr; SET_WCOL(*tp, 1); } sx = *x + cw; (*lnp)->flags |= __ISDIRTY; newx = sx + win->ch_off; if (newx < *(*lnp)->firstchp) *(*lnp)->firstchp = newx; } /* check for enough space before the end of line */ cw = wcwidth(wch->vals[0]); if (cw < 0) cw = 1; if (cw > win->maxx - *x) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: clear EOL (%d,%d)\n", *y, *x); #endif /* DEBUG */ (*lnp)->flags |= __ISDIRTY; newx = *x + win->ch_off; if (newx < *(*lnp)->firstchp) *(*lnp)->firstchp = newx; for (tp = lp; *x < win->maxx; tp++, (*x)++) { tp->ch = (wchar_t) btowc((int) win->bch); if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) return ERR; tp->attr = win->battr; SET_WCOL(*tp, 1); } newx = win->maxx - 1 + win->ch_off; if (newx > *(*lnp)->lastchp) *(*lnp)->lastchp = newx; __touchline(win, *y, sx, (int) win->maxx - 1); sx = *x = 0; if (*y == win->scr_b) { if (!(win->flags & __SCROLLOK)) return ERR; PSYNCH_OUT; scroll(win); PSYNCH_IN; } else { (*y)++; } lp = &win->alines[*y]->line[0]; (*lnp) = win->alines[*y]; } win->cury = *y; /* add spacing character */ #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add character (%d,%d) 0x%x\n", *y, *x, wch->vals[0]); #endif /* DEBUG */ (*lnp)->flags |= __ISDIRTY; newx = *x + win->ch_off; if (newx < *(*lnp)->firstchp) *(*lnp)->firstchp = newx; if (lp->nsp) { __cursesi_free_nsp(lp->nsp); lp->nsp = NULL; } lp->ch = wch->vals[0]; attributes = (win->wattr | wch->attributes) & (WA_ATTRIBUTES & ~__COLOR); if (wch->attributes & __COLOR) attributes |= wch->attributes & __COLOR; else if (win->wattr & __COLOR) attributes |= win->wattr & __COLOR; if (attributes & __COLOR) lp->attr = attributes | (win->battr & ~__COLOR); else lp->attr = attributes | win->battr; SET_WCOL(*lp, cw); #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add spacing char 0x%x, attr 0x%x\n", lp->ch, lp->attr); #endif /* DEBUG */ if (wch->elements > 1) { for (i = 1; i < wch->elements; i++) { np = (nschar_t *)malloc(sizeof(nschar_t)); if (!np) return ERR;; np->ch = wch->vals[i]; np->next = lp->nsp; #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add non-spacing char 0x%x\n", np->ch); #endif /* DEBUG */ lp->nsp = np; } } #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: non-spacing list header: %p\n", lp->nsp); __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add rest columns (%d:%d)\n", sx + 1, sx + cw - 1); #endif /* DEBUG */ for (tp = lp + 1, *x = sx + 1; *x - sx <= cw - 1; tp++, (*x)++) { if (tp->nsp) { __cursesi_free_nsp(tp->nsp); tp->nsp = NULL; } tp->ch = wch->vals[0]; tp->attr = lp->attr & WA_ATTRIBUTES; /* Mark as "continuation" cell */ tp->attr |= __WCWIDTH; } if (*x == win->maxx) { (*lnp)->flags |= __ISPASTEOL; newx = win->maxx - 1 + win->ch_off; if (newx > *(*lnp)->lastchp) *(*lnp)->lastchp = newx; __touchline(win, *y, sx, (int) win->maxx - 1); win->curx = sx; } else { win->curx = *x; /* clear the remining of the current characer */ if (*x && *x < win->maxx) { ex = sx + cw; tp = &win->alines[*y]->line[ex]; while (ex < win->maxx && WCOL(*tp) < 0) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: clear " "remaining of current char (%d,%d)nn", *y, ex); #endif /* DEBUG */ tp->ch = (wchar_t) btowc((int) win->bch); if (_cursesi_copy_nsp(win->bnsp, tp) == ERR) return ERR; tp->attr = win->battr; SET_WCOL(*tp, 1); tp++, ex++; } newx = ex - 1 + win->ch_off; if (newx > *(*lnp)->lastchp) *(*lnp)->lastchp = newx; __touchline(win, *y, sx, ex - 1); } } #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "add_wch: %d : 0x%x\n", lp->ch, lp->attr); #endif /* DEBUG */ return OK; #endif }
int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs, const cchar_t *ts, const cchar_t *bs, const cchar_t *tl, const cchar_t *tr, const cchar_t *bl, const cchar_t *br) { #ifndef HAVE_WCHAR return ERR; #else int endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw; cchar_t left, right, bottom, top, topleft, topright, botleft, botright; nschar_t *np, *tnp; if ( ls && wcwidth( ls->vals[ 0 ])) memcpy( &left, ls, sizeof( cchar_t )); else memcpy( &left, WACS_VLINE, sizeof( cchar_t )); if ( rs && wcwidth( rs->vals[ 0 ])) memcpy( &right, rs, sizeof( cchar_t )); else memcpy( &right, WACS_VLINE, sizeof( cchar_t )); if ( ts && wcwidth( ts->vals[ 0 ])) memcpy( &top, ts, sizeof( cchar_t )); else memcpy( &top, WACS_HLINE, sizeof( cchar_t )); if ( bs && wcwidth( bs->vals[ 0 ])) memcpy( &bottom, bs, sizeof( cchar_t )); else memcpy( &bottom, WACS_HLINE, sizeof( cchar_t )); if ( tl && wcwidth( tl->vals[ 0 ])) memcpy( &topleft, tl, sizeof( cchar_t )); else memcpy( &topleft, WACS_ULCORNER, sizeof( cchar_t )); if ( tr && wcwidth( tr->vals[ 0 ])) memcpy( &topright, tr, sizeof( cchar_t )); else memcpy( &topright, WACS_URCORNER, sizeof( cchar_t )); if ( bl && wcwidth( bl->vals[ 0 ])) memcpy( &botleft, bl, sizeof( cchar_t )); else memcpy( &botleft, WACS_LLCORNER, sizeof( cchar_t )); if ( br && wcwidth( br->vals[ 0 ])) memcpy( &botright, br, sizeof( cchar_t )); else memcpy( &botright, WACS_LRCORNER, sizeof( cchar_t )); #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n", left.vals[0], left.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n", right.vals[0], right.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n", top.vals[0], top.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n", bottom.vals[0], bottom.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n", topleft.vals[0], topleft.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n", topright.vals[0], topright.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n", botleft.vals[0], botleft.attributes ); __CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n", botright.vals[0], botright.attributes ); #endif /* Merge window attributes */ left.attributes |= (left.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; left.attributes |= (left.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; right.attributes |= (right.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; right.attributes |= (right.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; top.attributes |= (top.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; top.attributes |= (top.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; bottom.attributes |= (bottom.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; bottom.attributes |= (bottom.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; topleft.attributes |= (topleft.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; topleft.attributes |= (topleft.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; topright.attributes |= (topright.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; topright.attributes |= (topright.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; botleft.attributes |= (botleft.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; botleft.attributes |= (botleft.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; botright.attributes |= (botright.attributes & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr; botright.attributes |= (botright.attributes & __COLOR) ? (win->battr & ~__COLOR) : win->battr; endx = win->maxx - 1; endy = win->maxy - 1; /* Sides */ for (i = 1; i < endy; i++) { /* left border */ cw = wcwidth( left.vals[ 0 ]); if (cw < 0) cw = 1; for ( j = 0; j < cw; j++ ) { win->alines[i]->line[j].ch = left.vals[ 0 ]; win->alines[i]->line[j].attr = left.attributes; np = win->alines[i]->line[j].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[i]->line[j].nsp = NULL; } if ( j ) SET_WCOL( win->alines[i]->line[j], -j ); else { SET_WCOL( win->alines[i]->line[j], cw ); if ( left.elements > 1 ) { for (k = 1; k < left.elements; k++) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = left.vals[ k ]; np->next = win->alines[i]->line[j].nsp; win->alines[i]->line[j].nsp = np; } } } } for ( j = cw; WCOL( win->alines[i]->line[j]) < 0; j++ ) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "wborder_set: clean out partial char[%d]", j); #endif /* DEBUG */ win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch); if (_cursesi_copy_nsp(win->bnsp, &win->alines[i]->line[j]) == ERR) return ERR; SET_WCOL( win->alines[i]->line[j], 1 ); } /* right border */ cw = wcwidth( right.vals[ 0 ]); if (cw < 0) cw = 1; pcw = WCOL( win->alines[i]->line[endx - cw]); for ( j = endx - cw + 1; j <= endx; j++ ) { win->alines[i]->line[j].ch = right.vals[ 0 ]; win->alines[i]->line[j].attr = right.attributes; np = win->alines[i]->line[j].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[i]->line[j].nsp = NULL; } if ( j == endx - cw + 1 ) { SET_WCOL( win->alines[i]->line[j], cw ); if ( right.elements > 1 ) { for (k = 1; k < right.elements; k++) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = right.vals[ k ]; np->next = win->alines[i]->line[j].nsp; win->alines[i]->line[j].nsp = np; } } } else SET_WCOL( win->alines[i]->line[j], endx - cw + 1 - j ); } if ( pcw != 1 ) { #ifdef DEBUG __CTRACE(__CTRACE_INPUT, "wborder_set: clean out partial chars[%d:%d]", endx - cw + pcw, endx - cw ); #endif /* DEBUG */ k = pcw < 0 ? endx -cw + pcw : endx - cw; for ( j = endx - cw; j >= k; j-- ) { win->alines[i]->line[j].ch = (wchar_t)btowc(win->bch); if (_cursesi_copy_nsp(win->bnsp, &win->alines[i]->line[j]) == ERR) return ERR; win->alines[i]->line[j].attr = win->battr; SET_WCOL( win->alines[i]->line[j], 1 ); } } } tlcw = wcwidth( topleft.vals[ 0 ]); if (tlcw < 0) tlcw = 1; blcw = wcwidth( botleft.vals[ 0 ]); if (blcw < 0) blcw = 1; trcw = wcwidth( topright.vals[ 0 ]); if (trcw < 0) trcw = 1; brcw = wcwidth( botright.vals[ 0 ]); if (brcw < 0) brcw = 1; /* upper border */ cw = wcwidth( top.vals[ 0 ]); if (cw < 0) cw = 1; for (i = tlcw; i <= min( endx - cw, endx - trcw ); i += cw ) { for ( j = 0; j < cw; j++ ) { win->alines[ 0 ]->line[i + j].ch = top.vals[ 0 ]; win->alines[ 0 ]->line[i + j].attr = top.attributes; np = win->alines[ 0 ]->line[i + j].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ 0 ]->line[i + j].nsp = NULL; } if ( j ) SET_WCOL( win->alines[ 0 ]->line[ i + j ], -j ); else { SET_WCOL( win->alines[ 0 ]->line[ i + j ], cw ); if ( top.elements > 1 ) { for ( k = 1; k < top.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = top.vals[ k ]; np->next = win->alines[0]->line[i + j].nsp; win->alines[0]->line[i + j].nsp = np; } } } } } while ( i <= endx - trcw ) { win->alines[0]->line[i].ch = ( wchar_t )btowc(( int ) win->bch ); if (_cursesi_copy_nsp(win->bnsp, &win->alines[0]->line[i]) == ERR) return ERR; win->alines[ 0 ]->line[ i ].attr = win->battr; SET_WCOL( win->alines[ 0 ]->line[ i ], 1 ); i++; } /* lower border */ for (i = blcw; i <= min( endx - cw, endx - brcw ); i += cw ) { for ( j = 0; j < cw; j++ ) { win->alines[ endy ]->line[i + j].ch = bottom.vals[ 0 ]; win->alines[endy]->line[i + j].attr = bottom.attributes; np = win->alines[ endy ]->line[i + j].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ endy ]->line[i + j].nsp = NULL; } if ( j ) SET_WCOL( win->alines[endy]->line[i + j], -j); else { SET_WCOL( win->alines[endy]->line[i + j], cw ); if ( bottom.elements > 1 ) { for ( k = 1; k < bottom.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = bottom.vals[ k ]; np->next = win->alines[endy]->line[i + j].nsp; win->alines[endy]->line[i + j].nsp = np; } } } } } while ( i <= endx - brcw ) { win->alines[endy]->line[i].ch = (wchar_t)btowc((int) win->bch ); if (_cursesi_copy_nsp(win->bnsp, &win->alines[endy]->line[i]) == ERR) return ERR; win->alines[ endy ]->line[ i ].attr = win->battr; SET_WCOL( win->alines[ endy ]->line[ i ], 1 ); i++; } /* Corners */ if (!(win->maxx == LINES && win->maxy == COLS && (win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) { for ( i = 0; i < tlcw; i++ ) { win->alines[ 0 ]->line[i].ch = topleft.vals[ 0 ]; win->alines[ 0 ]->line[i].attr = topleft.attributes; np = win->alines[ 0 ]->line[i].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ 0 ]->line[i].nsp = NULL; } if ( i ) SET_WCOL( win->alines[ 0 ]->line[ i ], -i ); else { SET_WCOL( win->alines[ 0 ]->line[ i ], tlcw ); if ( topleft.elements > 1 ) { for ( k = 1; k < topleft.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = topleft.vals[ k ]; np->next = win->alines[ 0 ]->line[i].nsp; win->alines[ 0 ]->line[i].nsp = np; } } } } for ( i = endx - trcw + 1; i <= endx; i++ ) { win->alines[ 0 ]->line[i].ch = topright.vals[ 0 ]; win->alines[ 0 ]->line[i].attr = topright.attributes; np = win->alines[ 0 ]->line[i].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ 0 ]->line[i].nsp = NULL; } if ( i == endx - trcw + 1 ) { SET_WCOL( win->alines[ 0 ]->line[ i ], trcw ); if ( topright.elements > 1 ) { for ( k = 1; k < topright.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = topright.vals[ k ]; np->next = win->alines[0]->line[i].nsp; win->alines[ 0 ]->line[i].nsp = np; } } } else SET_WCOL( win->alines[ 0 ]->line[ i ], endx - trcw + 1 - i ); } for ( i = 0; i < blcw; i++ ) { win->alines[ endy ]->line[i].ch = botleft.vals[ 0 ]; win->alines[ endy ]->line[i].attr = botleft.attributes; np = win->alines[ endy ]->line[i].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ endy ]->line[i].nsp = NULL; } if ( i ) SET_WCOL( win->alines[endy]->line[i], -i ); else { SET_WCOL( win->alines[endy]->line[i], blcw ); if ( botleft.elements > 1 ) { for ( k = 1; k < botleft.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = botleft.vals[ k ]; np->next = win->alines[endy]->line[i].nsp; win->alines[endy]->line[i].nsp = np; } } } } for ( i = endx - brcw + 1; i <= endx; i++ ) { win->alines[ endy ]->line[i].ch = botright.vals[ 0 ]; win->alines[ endy ]->line[i].attr = botright.attributes; np = win->alines[ endy ]->line[i].nsp; if (np) { while ( np ) { tnp = np->next; free( np ); np = tnp; } win->alines[ endy ]->line[i].nsp = NULL; } if ( i == endx - brcw + 1 ) { SET_WCOL( win->alines[ endy ]->line[ i ], brcw ); if ( botright.elements > 1 ) { for ( k = 1; k < botright.elements; k++ ) { np = malloc(sizeof(nschar_t)); if (!np) return ERR; np->ch = botright.vals[ k ]; np->next = win->alines[endy]->line[i].nsp; win->alines[endy]->line[i].nsp = np; } } } else SET_WCOL( win->alines[ endy ]->line[ i ], endx - brcw + 1 - i ); } } __touchwin(win); return (OK); #endif /* HAVE_WCHAR */ }