コード例 #1
0
ファイル: resize.c プロジェクト: AgamAgarwal/minix
/*
 * resizeterm --
 *	Resize the terminal window, resizing the dependent windows.
 */
int
resizeterm(int nlines, int ncols)
{
	WINDOW *win;
	struct __winlist *list;

#ifdef	DEBUG
	__CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
#endif

	if (__resizeterm(curscr, nlines, ncols) == ERR)
		return ERR;
	if (__resizeterm(__virtscr, nlines, ncols) == ERR)
		return ERR;
	if (__resizeterm(stdscr, nlines, ncols) == ERR)
		return ERR;

	LINES = nlines;
	COLS = ncols;

	  /* tweak the flags now that we have updated the LINES and COLS */
	for (list = _cursesi_screen->winlistp; list != NULL; list = list->nextp) {
		win = list->winp;

		if (!(win->flags & __ISPAD))
			__swflags(win);
	}

	wrefresh(curscr);
	return OK;
}
コード例 #2
0
ファイル: newwin.c プロジェクト: ryo/netbsd-src
/*
 * __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);
}
コード例 #3
0
ファイル: fileio.c プロジェクト: VargMon/netbsd-curses
/*
 * getwin --
 *	Read window data from file
 */
WINDOW *
getwin(FILE *fp)
{
	int major, minor;
	WINDOW *wtmp, *win;
	int y, x;
	__LDATA *sp;

#ifdef DEBUG
	__CTRACE(__CTRACE_FILEIO, "getwin\n");
#endif

	/* Check library version */
	if (fread(&major, sizeof(int), 1, fp) != 1)
		return NULL;
	if (fread(&minor, sizeof(int), 1, fp) != 1)
		return NULL;
	if(major != CURSES_LIB_MAJOR || minor != CURSES_LIB_MINOR)
		return NULL;

	/* Window parameters */
	wtmp = (WINDOW *)malloc(sizeof(WINDOW));
	if (wtmp == NULL)
		return NULL;
	if (fread(wtmp, sizeof(WINDOW), 1, fp) != 1)
		goto error0;
	win = __newwin(_cursesi_screen, wtmp->maxy, wtmp->maxx,
	    wtmp->begy, wtmp->begx, FALSE);
	if (win == NULL)
		goto error0;
	win->cury = wtmp->cury;
	win->curx = wtmp->curx;
	win->reqy = wtmp->reqy;
	win->reqx = wtmp->reqx;
	win->flags = wtmp->flags;
	win->delay = wtmp->delay;
	win->wattr = wtmp->wattr;
	win->bch = wtmp->bch;
	win->battr = wtmp->battr;
	win->scr_t = wtmp->scr_t;
	win->scr_b = wtmp->scr_b;
	free(wtmp);
	wtmp = NULL;
	__swflags(win);

#ifdef HAVE_WCHAR
	if (__getnsp(win->bnsp, fp) == ERR)
		goto error1;
#endif /* HAVE_WCHAR */

	/* Lines and line data */
	for (y = 0; y < win->maxy; y++) {
		for (sp = win->alines[y]->line, x = 0; x < win->maxx;
		    x++, sp++) {
			if (fread(&sp->ch, sizeof(wchar_t), 1, fp) != 1)
				goto error1;
			if (fread(&sp->attr, sizeof(attr_t), 1, fp) != 1)
				goto error1;
#ifdef HAVE_WCHAR
			if (sp->nsp != NULL) {
				if (__getnsp(win->bnsp, fp) == ERR)
					goto error1;
			}
#endif /* HAVE_WCHAR */
		}
		__touchline(win, y, 0, (int) win->maxx - 1);
	}
#ifdef DEBUG
	__CTRACE(__CTRACE_FILEIO, "getwin: win = 0x%p\n", win);
#endif
	return win;

error1:
	delwin(win);
error0:
	if (wtmp)
		free(wtmp);
	return NULL;
}
コード例 #4
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;
}