Skip to content

Commit

Permalink
Use explicit constants for smallest size of display rows and columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfivet committed Aug 31, 2021
1 parent f96ace9 commit 64eb0d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
16 changes: 10 additions & 6 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ static void vtalloc( int maxrow, int maxcol) {
}

void updmargin( void) {
#define MINMARGIN 3 /* MINMARGIN - 1 enough for $ + prev before current */
#if MINCOLS < 2 * MINMARGIN + 1
# error "MINCOLS and MINMARGIN are not consistent"
#endif
term.t_margin = term.t_ncol / 10 ;
if( term.t_margin < 3) /* t_margin - 1 enough for $ + prev before current */
term.t_margin = 3 ;
if( term.t_margin < MINMARGIN)
term.t_margin = MINMARGIN ;

term.t_scrsiz = term.t_ncol - 2 * term.t_margin ;
}
Expand Down Expand Up @@ -1327,11 +1331,11 @@ static void sizesignal( int signr) {
static void newscreensize( int h, int w) {
chg_width = chg_height = 0 ;
vtfree() ;
if( h < 3)
h = 3 ;
if( h < MINROWS)
h = MINROWS ;

if( w < 10)
w = 10 ;
if( w < MINCOLS)
w = MINCOLS ;

vtalloc( h, w) ;
if( h <= term.t_mrow)
Expand Down
3 changes: 3 additions & 0 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "names.h" /* BINDABLE() */
#include "utf8.h" /* unicode_t */

#define MINROWS 3
#define MINCOLS 10

extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
extern int discmd ; /* display command flag */
Expand Down
27 changes: 13 additions & 14 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ BINDABLE( restwnd) {
}


static void adjust( window_p wp, int screenrows) {
wp->w_ntrows = screenrows - wp->w_toprow - 2 ;
wp->w_flag |= WFHARD | WFMODE ;
}

/* resize the screen, re-writing the screen
*
* int f; default flag
Expand All @@ -574,7 +579,7 @@ BBINDABLE( newsize) {
n = term.t_mrow ;

/* make sure it's in range */
if( n < 3 || n > term.t_mrow)
if( n < MINROWS || n > term.t_mrow)
return mloutfail( "%%Screen size out of range") ;

if( term.t_nrow == n - 1)
Expand All @@ -587,8 +592,7 @@ BBINDABLE( newsize) {
;

/* and enlarge it as needed */
wp->w_ntrows = n - wp->w_toprow - 2 ;
wp->w_flag |= WFHARD | WFMODE ;
adjust( wp, n) ;
} else {
/* new size is smaller */
/* rebuild the window structure */
Expand All @@ -598,10 +602,9 @@ BBINDABLE( newsize) {
wp = nextwp ;
nextwp = wp->w_wndp ;

if( wp->w_toprow == n - 2) {
lastwp->w_ntrows = n - lastwp->w_toprow - 2 ;
lastwp->w_flag |= WFHARD | WFMODE ;
}
/* expand previous window if current would have zero lines */
if( wp->w_toprow == n - 2)
adjust( lastwp, n) ;

/* get rid of it if it is too low */
if( wp->w_toprow >= n - 2) {
Expand All @@ -624,12 +627,8 @@ BBINDABLE( newsize) {
lastwp->w_wndp = NULL ;
} else {
/* need to change this window size? */
int lastline = wp->w_toprow + wp->w_ntrows - 1 ;
if( lastline >= n - 2) {
wp->w_ntrows = n - wp->w_toprow - 2 ;
assert( wp->w_ntrows) ;
wp->w_flag |= WFHARD | WFMODE ;
}
if( (wp->w_toprow + wp->w_ntrows - 1) >= n - 2)
adjust( wp, n) ;

lastwp = wp ;
}
Expand All @@ -654,7 +653,7 @@ BBINDABLE( newwidth) {
n = term.t_mcol ;

/* make sure it's in range */
if( n < 10 || n > term.t_mcol)
if( n < MINCOLS || n > term.t_mcol)
return mloutfail( "%%Screen width out of range") ;

/* otherwise, just re-width it (no big deal) */
Expand Down

0 comments on commit 64eb0d5

Please sign in to comment.