diff --git a/display.c b/display.c index 4f2455b..08756a2 100644 --- a/display.c +++ b/display.c @@ -28,7 +28,6 @@ #include "termio.h" #include "terminal.h" #include "version.h" -//#include "wrapper.h" #include "utf8.h" #include "window.h" @@ -122,22 +121,18 @@ static void *xmalloc( size_t size) { compile time. The original window has "WFCHG" set, so that it will get completely redrawn on the first call to "update". */ -void vtinit( void) { -#ifdef SIGWINCH - signal( SIGWINCH, sizesignal) ; -#endif - setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */ - TTopen() ; /* open the screen */ - TTkopen() ; /* open the keyboard */ - TTrev( FALSE) ; - vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ; +static int lastmrow ; /* remember mrow for later free */ + +static void vtalloc( int maxrow, int maxcol) { + lastmrow = maxrow ; /* remember mrow for later free */ + vscreen = xmalloc( maxrow * sizeof( video_p )) ; #if MEMMAP == 0 || SCROLLCODE - pscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ; + pscreen = xmalloc( maxrow * sizeof( video_p )) ; #endif - for( int i = 0 ; i < term.t_maxrow ; ++i) { - video_p vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ; + for( int i = 0 ; i < maxrow ; ++i) { + video_p vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ; vp->v_flag = 0 ; #if COLOR vp->v_rfcolor = 7 ; @@ -145,18 +140,30 @@ void vtinit( void) { #endif vscreen[ i] = vp ; #if MEMMAP == 0 || SCROLLCODE - vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ; + vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ; vp->v_flag = 0 ; pscreen[ i] = vp ; #endif } } -#if CLEAN -/* free up all the dynamically allocated video structures */ +void vtinit( void) { +#ifdef SIGWINCH + signal( SIGWINCH, sizesignal) ; +#endif + + setlocale( LC_CTYPE, "") ; /* expects $LANG like en_GB.UTF-8 */ + TTopen() ; /* open the screen */ + TTkopen() ; /* open the keyboard */ + TTrev( FALSE) ; + vtalloc( term.t_mrow, term.t_mcol) ; +} + + +/* free up all the dynamically video structures allocated by vtalloc */ void vtfree( void) { /* as xmalloc bypass the malloc macro, we need bypass the free macro too */ - for( int i = 0 ; i < term.t_maxrow ; ++i ) { + for( int i = 0 ; i < lastmrow ; ++i ) { (free)( vscreen[ i]) ; #if MEMMAP == 0 || SCROLLCODE (free)( pscreen[ i]) ; @@ -168,7 +175,7 @@ void vtfree( void) { (free)( pscreen) ; #endif } -#endif + /* Clean up the virtual terminal system, in anticipation for a return to @@ -1455,6 +1462,8 @@ static int newscreensize( int h, int w) { } chg_width = chg_height = 0 ; + vtfree() ; + vtalloc( h, w) ; if( h <= term.t_mrow) newsize( TRUE, h) ;