コード例 #1
0
ファイル: delwin.c プロジェクト: ryo/netbsd-src
/*
 * delwin --
 *	Delete a window and release it back to the system.
 */
int
delwin(WINDOW *win)
{
	WINDOW *wp, *np;
	struct __winlist *wl, *pwl;
	SCREEN *screen;

#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW, "delwin(%p)\n", win);
#endif

	if (win == NULL)
		return (OK);

	/*
	 * Free any storage used by non-spacing characters in the window.
	 */
#ifdef HAVE_WCHAR
	__cursesi_win_free_nsp(win);
#endif

	if (win->orig == NULL) {
		/*
		 * If we are the original window, delete the space for all
		 * the subwindows and the window space.
		 */
		free(win->wspace);
		wp = win->nextp;
		while (wp != win) {
			np = wp->nextp;
			delwin(wp);
			wp = np;
		}
		/* Remove ourselves from the list of windows on the screen. */
		pwl = NULL;
		screen = win->screen;
		for (wl = screen->winlistp; wl; pwl = wl, wl = wl->nextp) {
			if (wl->winp != win)
				continue;
			if (pwl != NULL)
				pwl->nextp = wl->nextp;
			else
				screen->winlistp = wl->nextp;
			free(wl);
			break;
		}
	} else {
		/*
		 * If we are a subwindow, take ourselves out of the list.
		 * NOTE: if we are a subwindow, the minimum list is orig
		 * followed by this subwindow, so there are always at least
		 * two windows in the list.
		 */
		for (wp = win->nextp; wp->nextp != win; wp = wp->nextp)
			continue;
		wp->nextp = win->nextp;
	}
	free(win->lspace);
	free(win->alines);
	if (win == _cursesi_screen->curscr)
		_cursesi_screen->curscr = NULL;
	if (win == _cursesi_screen->stdscr)
		_cursesi_screen->stdscr = NULL;
	if (win == _cursesi_screen->__virtscr)
		_cursesi_screen->__virtscr = NULL;
	if (win->fp)
		fclose(win->fp);
	free(win);
	return (OK);
}
コード例 #2
0
ファイル: resize.c プロジェクト: AgamAgarwal/minix
/*
 * __resizewin --
 *	Resize the given window.
 */
static int
__resizewin(WINDOW *win, int nlines, int ncols)
{
	__LINE			*lp, *olp, **newlines, *newlspace;
	__LDATA			*sp;
	__LDATA			*newwspace;
	int			 i, j;
	int			 y, x;
	WINDOW			*swin;

#ifdef	DEBUG
	__CTRACE(__CTRACE_WINDOW, "resize: (%p, %d, %d)\n", win, nlines, ncols);
	__CTRACE(__CTRACE_WINDOW, "resize: win->wattr = %08x\n", win->wattr);
	__CTRACE(__CTRACE_WINDOW, "resize: win->flags = %#.4x\n", win->flags);
	__CTRACE(__CTRACE_WINDOW, "resize: win->maxy = %d\n", win->maxy);
	__CTRACE(__CTRACE_WINDOW, "resize: win->maxx = %d\n", win->maxx);
	__CTRACE(__CTRACE_WINDOW, "resize: win->begy = %d\n", win->begy);
	__CTRACE(__CTRACE_WINDOW, "resize: win->begx = %d\n", win->begx);
	__CTRACE(__CTRACE_WINDOW, "resize: win->scr_t = %d\n", win->scr_t);
	__CTRACE(__CTRACE_WINDOW, "resize: win->scr_b = %d\n", win->scr_b);
#endif

	/*
	 * free up any non-spacing storage before we lose the
	 * pointers...
	 */
#ifdef HAVE_WCHAR
	__cursesi_win_free_nsp(win);
#endif

	if (nlines <= 0 || ncols <= 0)
		nlines = ncols = 0;
	else {
		/* Reallocate line pointer array and line space. */
		newlines = realloc(win->alines, nlines * sizeof(__LINE *));
		if (newlines == NULL)
			return ERR;
		win->alines = newlines;

		newlspace = realloc(win->lspace, nlines * sizeof(__LINE));
		if (newlspace == NULL)
			return ERR;
		win->lspace = newlspace;
	}

	/* Don't allocate window and line space if it's a subwindow */
	if (win->orig == NULL) {
		/*
		 * Allocate window space in one chunk.
		 */
		if (ncols != 0) {
			newwspace = realloc(win->wspace,
					    ncols * nlines * sizeof(__LDATA));
			if (newwspace == NULL)
				return ERR;
			win->wspace = newwspace;
		}

		/*
		 * 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;
			lp->firstch = 0;
			lp->lastch = ncols - 1;
			lp->flags = __ISDIRTY;
		}
	} else {

		win->ch_off = win->begx - win->orig->begx;
		  /* Point line pointers to line space. */
		for (lp = win->lspace, i = 0; i < nlines; i++, lp++) {
			win->alines[i] = lp;
			olp = win->orig->alines[i + win->begy - win->orig->begy];
			lp->line = &olp->line[win->ch_off];
#ifdef DEBUG
			lp->sentinel = SENTINEL_VALUE;
#endif
			lp->firstchp = &olp->firstch;
			lp->lastchp = &olp->lastch;
			lp->flags = __ISDIRTY;
		}
	}


	win->cury = win->curx = 0;
	win->maxy = nlines;
	win->maxx = ncols;
	win->scr_b = win->maxy - 1;
	__swflags(win);

	  /*
	   * we must zot the window contents otherwise lines may pick
	   * up attributes from the previous line when the window is
	   * made smaller.  The client will redraw the window anyway
	   * so this is no big deal.
	   */
	for (i = 0; i < win->maxy; i++) {
		lp = win->alines[i];
		for (sp = lp->line, j = 0; j < win->maxx; j++, sp++) {
			sp->attr = 0;
#ifndef HAVE_WCHAR
			sp->ch = win->bch;
#else
			sp->ch = ( wchar_t )btowc(( int ) win->bch );
			sp->nsp = NULL;
			if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
				return ERR;
			SET_WCOL( *sp, 1 );
#endif /* HAVE_WCHAR */
		}
		lp->hash = __hash((char *)(void *)lp->line,
				  (size_t) (ncols * __LDATASIZE));
	}

#ifdef DEBUG
	__CTRACE(__CTRACE_WINDOW, "resize: win->wattr = %08x\n", win->wattr);
	__CTRACE(__CTRACE_WINDOW, "resize: win->flags = %#.4x\n", win->flags);
	__CTRACE(__CTRACE_WINDOW, "resize: win->maxy = %d\n", win->maxy);
	__CTRACE(__CTRACE_WINDOW, "resize: win->maxx = %d\n", win->maxx);
	__CTRACE(__CTRACE_WINDOW, "resize: win->begy = %d\n", win->begy);
	__CTRACE(__CTRACE_WINDOW, "resize: win->begx = %d\n", win->begx);
	__CTRACE(__CTRACE_WINDOW, "resize: win->scr_t = %d\n", win->scr_t);
	__CTRACE(__CTRACE_WINDOW, "resize: win->scr_b = %d\n", win->scr_b);
#endif

	if (win->orig == NULL) {
		/* bound subwindows to new size and fixup their pointers */
		for (swin = win->nextp; swin != win; swin = swin->nextp) {
			y = swin->reqy;
			if (swin->begy > win->begy + win->maxy)
				swin->begy = win->begy + win->maxy - 1;
			if (swin->begy + y > win->begy + win->maxy)
				y = 0;
			if (y <= 0)
				y += win->begy + win->maxy - swin->begy;
			if (y < 1)
				y = 1;
			x = swin->reqx;
			if (swin->begx > win->begx + win->maxx)
				swin->begx = win->begx + win->maxx - 1;
			if (swin->begx + x > win->begx + win->maxx)
				x = 0;
			if (x <= 0)
				x += win->begy + win->maxx - swin->begx;
			if (x < 1)
				x = 1;
			__resizewin(swin, y, x);
		}
	}

	return OK;
}