Exemplo n.º 1
0
void wbkgrndset(WINDOW *win, const cchar_t *wch)
{
	attr_t battr;
	nschar_t *np, *tnp;
	unsigned int i;

	/* ignore multi-column characters */
	if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 )
		return;

	/* Background character. */
	tnp = np = win->bnsp;
	if ( wcwidth( wch->vals[ 0 ]))
		win->bch = wch->vals[ 0 ];
	else {
		if ( !np ) {
			np = (nschar_t *)malloc(sizeof(nschar_t));
			if (!np)
				return;
			np->next = NULL;
			win->bnsp = np;
		}
		np->ch = wch->vals[ 0 ];
		tnp = np;
		np = np->next;
	}
	/* add non-spacing characters */
	if ( wch->elements > 1 ) {
		for ( i = 1; i < wch->elements; i++ ) {
			if ( !np ) {
				np = (nschar_t *)malloc(sizeof(nschar_t));
				if (!np)
					return;
				np->next = NULL;
				if ( tnp )
					tnp->next = np;
				else
					win->bnsp = np;
			}
			np->ch = wch->vals[ i ];
			tnp = np;
			np = np->next;
		}
	}
	/* clear the old non-spacing characters */
	while ( np ) {
		tnp = np->next;
		free( np );
		np = tnp;
	}

	/* Background attributes (check colour). */
	battr = wch->attributes & WA_ATTRIBUTES;
	if (__using_color && !( battr & __COLOR))
		battr |= __default_color;
	win->battr = battr;
	SET_BGWCOL((*win), 1);
}
Exemplo n.º 2
0
/*
 * __makenew --
 *	Set up a window buffer and returns a pointer to it.
 */
static WINDOW *
__makenew(SCREEN *screen, int nlines, int ncols, int by, int bx, int sub,
	int ispad)
{
	WINDOW			*win;
	__LINE			*lp;
	struct __winlist	*wlp, *wlp2;
	int			 i;


#ifdef	DEBUG
	__CTRACE(__CTRACE_WINDOW, "makenew: (%d, %d, %d, %d)\n",
	    nlines, ncols, by, bx);
#endif
	if (nlines <= 0 || ncols <= 0)
		return NULL;

	if ((win = malloc(sizeof(WINDOW))) == NULL)
		return (NULL);
#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW, "makenew: win = %p\n", win);
#endif
	win->fp = NULL;

	/* Set up line pointer array and line space. */
	if ((win->alines = malloc(nlines * sizeof(__LINE *))) == NULL) {
		free(win);
		return NULL;
	}
	if ((win->lspace = malloc(nlines * sizeof(__LINE))) == NULL) {
		free(win->alines);
		free(win);
		return NULL;
	}
	/* Don't allocate window and line space if it's a subwindow */
	if (sub)
		win->wspace = NULL;
	else {
		/*
		 * Allocate window space in one chunk.
		 */
		if ((win->wspace =
			malloc(ncols * nlines * sizeof(__LDATA))) == NULL) {
			free(win->lspace);
			free(win->alines);
			free(win);
			return NULL;
		}
		/*
		 * Append window to window list.
		 */
		if ((wlp = malloc(sizeof(struct __winlist))) == NULL) {
			free(win->wspace);
			free(win->lspace);
			free(win->alines);
			free(win);
			return NULL;
		}
		wlp->winp = win;
		wlp->nextp = NULL;
		if (screen->winlistp == NULL)
			screen->winlistp = wlp;
		else {
			wlp2 = screen->winlistp;
			while (wlp2->nextp != NULL)
				wlp2 = wlp2->nextp;
			wlp2->nextp = wlp;
		}
		/*
		 * Point line pointers to line space, and lines themselves into
		 * window space.
		 */
		for (lp = win->lspace, i = 0; i < nlines; i++, lp++) {
			win->alines[i] = lp;
			lp->line = &win->wspace[i * ncols];
#ifdef DEBUG
			lp->sentinel = SENTINEL_VALUE;
#endif
			lp->firstchp = &lp->firstch;
			lp->lastchp = &lp->lastch;
			if (ispad) {
				lp->firstch = 0;
				lp->lastch = ncols;
			} else {
				lp->firstch = ncols;
				lp->lastch = 0;
			}
		}
	}
#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW, "makenew: ncols = %d\n", ncols);
#endif
	win->screen = screen;
	win->cury = win->curx = 0;
	win->maxy = nlines;
	win->maxx = ncols;
	win->reqy = nlines;
	win->reqx = ncols;

	win->begy = by;
	win->begx = bx;
	win->flags = (__IDLINE | __IDCHAR);
	win->delay = -1;
	win->wattr = 0;
#ifdef HAVE_WCHAR
	win->bnsp = NULL;
	SET_BGWCOL( *win, 1 );
#endif /* HAVE_WCHAR */
	win->scr_t = 0;
	win->scr_b = win->maxy - 1;
	if (ispad) {
		win->flags |= __ISPAD;
		win->pbegy = 0;
		win->pbegx = 0;
		win->sbegy = 0;
		win->sbegx = 0;
		win->smaxy = 0;
		win->smaxx = 0;
	} else
		__swflags(win);
#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW, "makenew: win->wattr = %08x\n", win->wattr);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->flags = %#.4x\n", win->flags);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->maxy = %d\n", win->maxy);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->maxx = %d\n", win->maxx);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->begy = %d\n", win->begy);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->begx = %d\n", win->begx);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->scr_t = %d\n", win->scr_t);
	__CTRACE(__CTRACE_WINDOW, "makenew: win->scr_b = %d\n", win->scr_b);
#endif
	return (win);
}
Exemplo n.º 3
0
void wbkgrndset(WINDOW *win, const cchar_t *wch)
{
#ifdef HAVE_WCHAR
	attr_t battr;
	nschar_t *np, *tnp;
	int i;

#ifdef DEBUG
	__CTRACE(__CTRACE_ATTR, "wbkgrndset: (%p), '%s', %x\n",
		win, (const char *) wunctrl(wch), wch->attributes);
#endif

	/* ignore multi-column characters */
	if ( !wch->elements || wcwidth( wch->vals[ 0 ]) > 1 )
		return;

	/* Background character. */
	tnp = np = win->bnsp;
	if ( wcwidth( wch->vals[ 0 ]))
		win->bch = wch->vals[ 0 ];
	else {
		if ( !np ) {
			np = malloc(sizeof(nschar_t));
			if (!np)
				return;
			np->next = NULL;
			win->bnsp = np;
		}
		np->ch = wch->vals[ 0 ];
		tnp = np;
		np = np->next;
	}
	/* add non-spacing characters */
	if ( wch->elements > 1 ) {
		for ( i = 1; i < wch->elements; i++ ) {
			if ( !np ) {
				np = malloc(sizeof(nschar_t));
				if (!np)
					return;
				np->next = NULL;
				if ( tnp )
					tnp->next = np;
				else
					win->bnsp = np;
			}
			np->ch = wch->vals[ i ];
			tnp = np;
			np = np->next;
		}
	}
	/* clear the old non-spacing characters */
	while ( np ) {
		tnp = np->next;
		free( np );
		np = tnp;
	}

	/* Background attributes (check colour). */
	battr = wch->attributes & WA_ATTRIBUTES;
	if (__using_color && !( battr & __COLOR))
		battr |= __default_color;
	win->battr = battr;
	SET_BGWCOL((*win), 1);
#endif /* HAVE_WCHAR */
}