From b6c89d6eca35573d6830350527c4e1a55d2f2e75 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Thu, 1 Jun 2017 13:02:47 +0800 Subject: [PATCH] Cleanup virtual terminal allocation code. --- display.c | 18 +++++++++--------- tcap.c | 10 ++++++---- terminal.h | 16 ++++++---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/display.c b/display.c index 3185a0d..b1a9c07 100644 --- a/display.c +++ b/display.c @@ -39,7 +39,7 @@ struct video { int v_rfcolor; /* requested forground color */ int v_rbcolor; /* requested background color */ #endif - unicode_t v_text[1]; /* Screen data. */ + unicode_t v_text[] ; /* Screen data. */ }; #define VFCHG 0x0001 /* Changed flag */ @@ -109,13 +109,13 @@ void vtinit(void) TTopen(); /* open the screen */ TTkopen(); /* open the keyboard */ TTrev(FALSE); - vscreen = xmalloc( MAXROW * sizeof( struct video *)) ; + vscreen = xmalloc( term.t_maxrow * sizeof( struct video *)) ; #if MEMMAP == 0 || SCROLLCODE - pscreen = xmalloc( MAXROW * sizeof( struct video *)) ; + pscreen = xmalloc( term.t_maxrow * sizeof( struct video *)) ; #endif - for( i = 0 ; i < MAXROW ; ++i) { - vp = xmalloc( sizeof( struct video) + MAXCOL * 4) ; + for( i = 0 ; i < term.t_maxrow ; ++i) { + vp = xmalloc( sizeof( struct video) + term.t_maxcol * sizeof( unicode_t)) ; vp->v_flag = 0; #if COLOR vp->v_rfcolor = 7; @@ -123,7 +123,7 @@ void vtinit(void) #endif vscreen[i] = vp; #if MEMMAP == 0 || SCROLLCODE - vp = xmalloc( sizeof( struct video) + MAXCOL * 4 ) ; + vp = xmalloc( sizeof( struct video) + term.t_maxcol * sizeof( unicode_t)) ; vp->v_flag = 0; pscreen[i] = vp; #endif @@ -136,7 +136,7 @@ void vtinit(void) void vtfree(void) { int i; - for( i = 0 ; i < MAXROW; ++i ) { + for( i = 0 ; i < term.t_maxrow; ++i ) { free(vscreen[i]); #if MEMMAP == 0 || SCROLLCODE free(pscreen[i]); @@ -1521,8 +1521,8 @@ void sizesignal(int signr) getscreensize(&w, &h); if( h > 0 && w > 0) { - term.t_mrow = h = h < MAXROW ? h : MAXROW ; - term.t_mcol = w = w < MAXCOL ? w : MAXCOL ; + term.t_mrow = h = h < term.t_maxrow ? h : term.t_maxrow ; + term.t_mcol = w = w < term.t_maxcol ? w : term.t_maxcol ; if( h - 1 != term.t_nrow || w != term.t_ncol) newscreensize( h, w) ; } diff --git a/tcap.c b/tcap.c index 5501b0f..07b44f4 100644 --- a/tcap.c +++ b/tcap.c @@ -88,7 +88,9 @@ static char *CS, *DL, *AL, *SF, *SR; #endif struct terminal term = { - 0, /* These four values are set dynamically at open time. */ + 210, /* actual 204 on 1920x1080 landscape terminal window */ + 500, /* actual 475 */ + 0, /* These four values are set dynamically at open time. */ 0, 0, 0, @@ -157,11 +159,11 @@ static void tcapopen(void) exit( EXIT_FAILURE) ; } - term.t_mrow = int_row < MAXROW ? int_row : MAXROW ; + term.t_mrow = int_row < term.t_maxrow ? int_row : term.t_maxrow ; term.t_nrow = term.t_mrow - 1 ; - term.t_mcol = int_col < MAXCOL ? int_col : MAXCOL ; + term.t_mcol = int_col < term.t_maxcol ? int_col : term.t_maxcol ; term.t_ncol = term.t_mcol ; - + p = tcapbuf; t = tgetstr("pc", &p); if (t) diff --git a/terminal.h b/terminal.h index 72603b1..a25218d 100644 --- a/terminal.h +++ b/terminal.h @@ -7,12 +7,6 @@ #include "utf8.h" -/* Actual 471x175 on a 1920x1080 screen in landscape, - if smaller font or portrait orientation limit to 500x200 */ -#define MAXCOL 500 -#define MAXROW 200 - - /* * The editor communicates with the display using a high level interface. A * "TERM" structure holds useful variables, and indirect pointers to routines @@ -23,10 +17,12 @@ * one terminal type. */ struct terminal { - short t_mrow; /* max number of rows allowable */ - short t_nrow; /* current number of rows used */ - short t_mcol; /* max Number of columns. */ - short t_ncol; /* current Number of columns. */ + const short t_maxrow ; /* max number of rows allowable */ + const short t_maxcol ; /* max number of columns allowable */ + short t_mrow ; /* max number of rows displayable */ + short t_nrow ; /* current number of rows displayed */ + short t_mcol ; /* max number of rows displayable */ + short t_ncol ; /* current number of columns displayed */ short t_margin; /* min margin for extended lines */ short t_scrsiz; /* size of scroll region " */ int t_pause; /* # times thru update to pause */