diff --git a/display.c b/display.c index 11bb8e8..fcf0126 100644 --- a/display.c +++ b/display.c @@ -49,7 +49,7 @@ static video_p *vscreen ; /* Virtual screen. */ static video_p *pscreen ; /* Physical screen. */ #endif -static int displaying = TRUE; +static int displaying = TRUE ; #if UNIX # include #endif @@ -76,19 +76,23 @@ int disinp = TRUE ; /* display input characters (echo) */ static int reframe( window_p wp) ; static void updone( window_p wp) ; static void updall( window_p wp) ; -static int scrolls(int inserts); -static void scrscroll(int from, int to, int count); -static int texttest(int vrow, int prow); -static int endofline(unicode_t *s, int n); -static void updext(void); -static int updateline(int row, video_p vp1, video_p vp2); +static int scrolls( int inserts) ; +static void scrscroll( int from, int to, int count) ; +static int texttest( int vrow, int prow) ; +static int endofline( unicode_t *s, int n) ; +static void upddex( void) ; +static void updext( void) ; +static void updgar( void) ; +static void updpos( void) ; +static int updateline( int row, video_p vp1, video_p vp2) ; +static boolean updupd( boolean force_f) ; static void modeline( window_p wp) ; -static void mlputi(int i, int r); -static void mlputli(long l, int r); -static void mlputf(int s); +static void mlputi( int i, int r) ; +static void mlputli( long l, int r) ; +static void mlputf( int s) ; static void mlputs( const char *s) ; #if SIGWINCH -static int newscreensize(int h, int w); +static int newscreensize( int h, int w) ; #endif @@ -101,7 +105,7 @@ static int newscreensize(int h, int w); void vtinit( void) { TTopen() ; /* open the screen */ TTkopen() ; /* open the keyboard */ - TTrev(FALSE) ; + TTrev( FALSE) ; vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ; #if MEMMAP == 0 || SCROLLCODE @@ -126,7 +130,7 @@ void vtinit( void) { #if CLEAN /* free up all the dynamically allocated video structures */ void vtfree( void) { - for( int i = 0 ; i < term.t_maxrow; ++i ) { + for( int i = 0 ; i < term.t_maxrow ; ++i ) { free( vscreen[ i]) ; #if MEMMAP == 0 || SCROLLCODE free( pscreen[ i]) ; @@ -202,7 +206,7 @@ static void vtputc( unicode_t c) { sane_vtputc( '^') ; sane_vtputc( c ^ 0x40) ; } else if( c >= 0x80 && c <= 0xA0) { - static const char hex[] = "0123456789abcdef"; + static const char hex[] = "0123456789abcdef" ; sane_vtputc( '\\') ; sane_vtputc( hex[ c >> 4]) ; sane_vtputc( hex[ c & 15]) ; @@ -227,8 +231,8 @@ static int vtputs( const char *s) { return n ; } -/* - * Erase from the end of the software cursor to the end of the line on which + +/* Erase from the end of the software cursor to the end of the line on which * the software cursor is located. */ static void vteeol( void) { @@ -248,7 +252,7 @@ BINDABLE( upscreen) { } #if SCROLLCODE -static int scrflags; +static int scrflags ; #endif @@ -260,17 +264,17 @@ static int scrflags; boolean force_f ; force update past type ahead? */ -int update( boolean force_f) { +boolean update( boolean force_f) { #if TYPEAH && ! PKCODE if( force_f == FALSE && typahead()) - return TRUE; + return TRUE ; #endif #if VISMAC == 0 if( force_f == FALSE && kbdmode == PLAY) - return TRUE; + return TRUE ; #endif - displaying = TRUE; + displaying = TRUE ; #if SCROLLCODE @@ -316,195 +320,182 @@ int update( boolean force_f) { #if MEMMAP && ! SCROLLCODE /* update the cursor and flush the buffers */ - movecursor(currow, curcol - lbound); + movecursor( currow, curcol - lbound) ; #endif /* check for lines to de-extend */ - upddex(); + upddex() ; /* if screen is garbage, re-plot it */ - if (sgarbf != FALSE) - updgar(); + if( sgarbf != FALSE) + updgar() ; /* update the virtual screen to the physical screen */ updupd( force_f) ; /* update the cursor and flush the buffers */ - movecursor(currow, curcol - lbound); - TTflush(); - displaying = FALSE; + movecursor( currow, curcol - lbound) ; + TTflush() ; + displaying = FALSE ; #if SIGWINCH - while (chg_width || chg_height) - newscreensize(chg_height, chg_width); + while( chg_width || chg_height) + newscreensize( chg_height, chg_width) ; #endif - return TRUE; + return TRUE ; } -/* - * reframe: + +/* reframe: * check to see if the cursor is on in the window * and re-frame it if needed or wanted */ static int reframe( window_p wp) { line_p lp, lp0 ; - int i = 0; + int i = 0 ; /* if not a requested reframe, check for a needed one */ - if ((wp->w_flag & WFFORCE) == 0) { + if( (wp->w_flag & WFFORCE) == 0) { #if SCROLLCODE /* loop from one line above the window to one line after */ - lp = wp->w_linep; - lp0 = lback(lp); - if (lp0 == wp->w_bufp->b_linep) - i = 0; + lp = wp->w_linep ; + lp0 = lback( lp) ; + if( lp0 == wp->w_bufp->b_linep) + i = 0 ; else { - i = -1; - lp = lp0; + i = -1 ; + lp = lp0 ; } - for (; i <= (int) (wp->w_ntrows); i++) + for( ; i <= (int) (wp->w_ntrows) ; i++) #else - lp = wp->w_linep; - for (i = 0; i < wp->w_ntrows; i++) + lp = wp->w_linep ; + for( i = 0 ; i < wp->w_ntrows ; i++) #endif { /* if the line is in the window, no reframe */ - if (lp == wp->w_dotp) { + if( lp == wp->w_dotp) { #if SCROLLCODE /* if not _quite_ in, we'll reframe gently */ - if (i < 0 || i == wp->w_ntrows) { + if( i < 0 || i == wp->w_ntrows) { /* if the terminal can't help, then we're simply outside */ - if (term.t_scroll == NULL) - i = wp->w_force; - break; + if( term.t_scroll == NULL) + i = wp->w_force ; + break ; } #endif - return TRUE; + return TRUE ; } /* if we are at the end of the file, reframe */ - if (lp == wp->w_bufp->b_linep) - break; + if( lp == wp->w_bufp->b_linep) + break ; /* on to the next line */ - lp = lforw(lp); + lp = lforw( lp) ; } } #if SCROLLCODE - if (i == -1) { /* we're just above the window */ - i = scrollcount; /* put dot at first line */ - scrflags |= WFINS; - } else if (i == wp->w_ntrows) { /* we're just below the window */ - i = -scrollcount; /* put dot at last line */ - scrflags |= WFKILLS; + if( i == -1) { /* we're just above the window */ + i = scrollcount ; /* put dot at first line */ + scrflags |= WFINS ; + } else if( i == wp->w_ntrows) { /* we're just below the window */ + i = -scrollcount ; /* put dot at last line */ + scrflags |= WFKILLS ; } else /* put dot where requested */ #endif - i = wp->w_force; /* (is 0, unless reposition() was called) */ + i = wp->w_force ; /* (is 0, unless reposition() was called) */ - wp->w_flag |= WFMODE; + wp->w_flag |= WFMODE ; /* how far back to reframe? */ - if (i > 0) { /* only one screen worth of lines max */ - if (--i >= wp->w_ntrows) - i = wp->w_ntrows - 1; - } else if (i < 0) { /* negative update???? */ - i += wp->w_ntrows; - if (i < 0) - i = 0; + if( i > 0) { /* only one screen worth of lines max */ + if( --i >= wp->w_ntrows) + i = wp->w_ntrows - 1 ; + } else if( i < 0) { /* negative update???? */ + i += wp->w_ntrows ; + if( i < 0) + i = 0 ; } else - i = wp->w_ntrows / 2; + i = wp->w_ntrows / 2 ; /* backup to new line at top of window */ - lp = wp->w_dotp; - while (i != 0 && lback(lp) != wp->w_bufp->b_linep) { - --i; - lp = lback(lp); + lp = wp->w_dotp ; + while( i != 0 && lback( lp) != wp->w_bufp->b_linep) { + --i ; + lp = lback( lp) ; } /* and reset the current line at top of window */ - wp->w_linep = lp; - wp->w_flag |= WFHARD; - wp->w_flag &= ~WFFORCE; - return TRUE; + wp->w_linep = lp ; + wp->w_flag |= WFHARD ; + wp->w_flag &= ~WFFORCE ; + return TRUE ; } -static void show_line( line_p lp) -{ - int i = 0, len = llength(lp); +static void show_line( line_p lp) { + int i = 0, len = llength( lp) ; - while (i < len) { - unicode_t c; - i += utf8_to_unicode(lp->l_text, i, len, &c); - vtputc(c); + while( i < len) { + unicode_t c ; + i += utf8_to_unicode( lp->l_text, i, len, &c) ; + vtputc( c) ; } } -/* - * updone: + +/* updone: * update the current line to the virtual screen * * window_p wp; window to update current line in */ -static void updone(window_p wp) -{ - line_p lp; /* line to update */ - int sline; /* physical screen line to update */ +static void updone( window_p wp) { +/* search down the line we want */ + int sline = wp->w_toprow ; /* physical screen line to update */ + line_p lp ; + for( lp = wp->w_linep ; lp != wp->w_dotp ; lp = lforw( lp)) + ++sline ; - /* search down the line we want */ - lp = wp->w_linep; - sline = wp->w_toprow; - while (lp != wp->w_dotp) { - ++sline; - lp = lforw(lp); - } - - /* and update the virtual line */ - vscreen[sline]->v_flag |= VFCHG; - vscreen[sline]->v_flag &= ~VFREQ; +/* and update the virtual line */ + vscreen[ sline]->v_flag |= VFCHG ; + vscreen[ sline]->v_flag &= ~VFREQ ; vtmove( sline, 0) ; - show_line(lp); + show_line( lp) ; #if COLOR - vscreen[sline]->v_rfcolor = wp->w_fcolor; - vscreen[sline]->v_rbcolor = wp->w_bcolor; + vscreen[ sline]->v_rfcolor = wp->w_fcolor ; + vscreen[ sline]->v_rbcolor = wp->w_bcolor ; #endif - vteeol(); + vteeol() ; } -/* - * updall: + +/* updall: * update all the lines in a window on the virtual screen * * window_p wp; window to update lines in */ -static void updall(window_p wp) -{ - line_p lp; /* line to update */ - int sline; /* physical screen line to update */ - - /* search down the lines, updating them */ - lp = wp->w_linep; - sline = wp->w_toprow; - while (sline < wp->w_toprow + wp->w_ntrows) { - - /* and update the virtual line */ - vscreen[sline]->v_flag |= VFCHG; - vscreen[sline]->v_flag &= ~VFREQ; +static void updall( window_p wp) { +/* search down the lines, updating them */ + line_p lp = wp->w_linep ; /* line to update */ + int sline = wp->w_toprow ; /* physical screen line to update */ + while( sline < wp->w_toprow + wp->w_ntrows) { + /* and update the virtual line */ + vscreen[ sline]->v_flag |= VFCHG ; + vscreen[ sline]->v_flag &= ~VFREQ ; vtmove( sline, 0) ; - if (lp != wp->w_bufp->b_linep) { - /* if we are not at the end */ - show_line(lp); - lp = lforw(lp); + if( lp != wp->w_bufp->b_linep) { + /* if we are not at the end */ + show_line( lp) ; + lp = lforw( lp) ; } - /* on to the next one */ + /* on to the next one */ #if COLOR - vscreen[sline]->v_rfcolor = wp->w_fcolor; - vscreen[sline]->v_rbcolor = wp->w_bcolor; + vscreen[ sline]->v_rfcolor = wp->w_fcolor ; + vscreen[ sline]->v_rbcolor = wp->w_bcolor ; #endif - vteeol(); - ++sline; + vteeol() ; + ++sline ; } - } @@ -512,7 +503,7 @@ static void updall(window_p wp) update the position of the hardware cursor and handle extended lines. This is the only update for simple moves. */ -void updpos(void) { +static void updpos( void) { /* find the current row */ line_p lp = curwp->w_linep ; currow = curwp->w_toprow ; @@ -522,7 +513,7 @@ void updpos(void) { } /* find the current column */ - curcol = 0; + curcol = 0 ; int i = 0 ; while( i < curwp->w_doto) { unicode_t c ; @@ -546,348 +537,322 @@ void updpos(void) { lbound = 0 ; } -/* - * upddex: + +/* upddex: * de-extend any line that deserves it */ -void upddex(void) -{ - window_p wp; - line_p lp; - int i; - - wp = wheadp; - - while (wp != NULL) { - lp = wp->w_linep; - i = wp->w_toprow; - - while (i < wp->w_toprow + wp->w_ntrows) { - if (vscreen[i]->v_flag & VFEXT) { - if ((wp != curwp) || (lp != wp->w_dotp) || - (curcol < term.t_ncol - 1)) { +static void upddex( void) { + for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) { + line_p lp = wp->w_linep ; + for( int i = wp->w_toprow ; i < wp->w_toprow + wp->w_ntrows ; i++) { + if( vscreen[ i]->v_flag & VFEXT) { + if( (wp != curwp) + || (lp != wp->w_dotp) + || (curcol < term.t_ncol - 1)) { vtmove( i, 0) ; - show_line(lp); - vteeol(); + show_line( lp) ; + vteeol() ; - /* this line no longer is extended */ - vscreen[i]->v_flag &= ~VFEXT; - vscreen[i]->v_flag |= VFCHG; + /* this line no longer is extended */ + vscreen[ i]->v_flag &= ~VFEXT ; + vscreen[ i]->v_flag |= VFCHG ; } } - lp = lforw(lp); - ++i; + + lp = lforw( lp) ; } - /* and onward to the next window */ - wp = wp->w_wndp; } } -/* - * updgar: + +/* updgar: * if the screen is garbage, clear the physical screen and * the virtual screen and force a full update */ -void updgar(void) -{ - unicode_t *txt; - int i, j; - - for (i = 0; i < term.t_nrow; ++i) { - vscreen[i]->v_flag |= VFCHG; +static void updgar( void) { + for( int i = 0 ; i < term.t_nrow ; ++i) { + vscreen[ i]->v_flag |= VFCHG ; #if REVSTA - vscreen[i]->v_flag &= ~VFREV; + vscreen[ i]->v_flag &= ~VFREV ; #endif #if COLOR - vscreen[i]->v_fcolor = gfcolor; - vscreen[i]->v_bcolor = gbcolor; + vscreen[ i]->v_fcolor = gfcolor ; + vscreen[ i]->v_bcolor = gbcolor ; #endif #if MEMMAP == 0 || SCROLLCODE - txt = pscreen[i]->v_text; - for (j = 0; j < term.t_ncol; ++j) - txt[j] = ' '; + unicode_t *txt = pscreen[ i]->v_text ; + for( int j = 0 ; j < term.t_ncol ; ++j) + txt[ j] = ' ' ; #endif } - movecursor(0, 0); /* Erase the screen. */ - (*term.t_eeop) (); - sgarbf = FALSE; /* Erase-page clears */ - mpresf = FALSE; /* the message area. */ + movecursor( 0, 0) ; /* Erase the screen. */ + term.t_eeop() ; + sgarbf = FALSE ; /* Erase-page clears */ + mpresf = FALSE ; /* the message area. */ #if COLOR - mlerase(); /* needs to be cleared if colored */ + mlerase() ; /* needs to be cleared if colored */ #endif } -/* - * updupd: + +/* updupd: * update the physical screen from the virtual screen * * int force; forced update flag */ -int updupd(int force) -{ - video_p vp1; - int i; - +static boolean updupd( boolean force_f) { #if SCROLLCODE - if (scrflags & WFKILLS) - scrolls(FALSE); - if (scrflags & WFINS) - scrolls(TRUE); - scrflags = 0; + if( scrflags & WFKILLS) + scrolls( FALSE) ; + + if( scrflags & WFINS) + scrolls( TRUE) ; + + scrflags = 0 ; #endif - for (i = 0; i < term.t_nrow; ++i) { - vp1 = vscreen[i]; + for( int i = 0 ; i < term.t_nrow ; ++i) { + video_p vp1 = vscreen[ i] ; - /* for each line that needs to be updated */ - if ((vp1->v_flag & VFCHG) != 0) { + /* for each line that needs to be updated */ + if( (vp1->v_flag & VFCHG) != 0) { #if TYPEAH && ! PKCODE - if (force == FALSE && typahead()) - return TRUE; + if( force_f == FALSE && typahead()) + return TRUE ; #endif #if MEMMAP && ! SCROLLCODE - updateline(i, vp1); + updateline( i, vp1) ; #else - updateline(i, vp1, pscreen[i]); + updateline( i, vp1, pscreen[ i]) ; #endif } } - return TRUE; + + return TRUE ; } #if SCROLLCODE -/* - * optimize out scrolls (line breaks, and newlines) +/* optimize out scrolls (line breaks, and newlines) * arg. chooses between looking for inserts or deletes + + * returns true if it does something */ -static int scrolls(int inserts) -{ /* returns true if it does something */ - video_p vpv; /* virtual screen image */ - video_p vpp; /* physical screen image */ - int i, j, k; - int rows, cols; - int first, match, count, target, end; - int longmatch, longcount; - int from, to; +static int scrolls( int inserts) { + int i, j, k ; + int count, target, end ; + int to ; - if (!term.t_scroll) /* no way to scroll */ - return FALSE; + if( !term.t_scroll) /* no way to scroll */ + return FALSE ; - rows = term.t_nrow; - cols = term.t_ncol; + int rows = term.t_nrow ; + int cols = term.t_ncol ; - first = -1; - for (i = 0; i < rows; i++) { /* find first wrong line */ - if (!texttest(i, i)) { - first = i; - break; - } - } + for( i = 0 ; i < rows ; i++) /* find first wrong line */ + if( !texttest( i, i)) + break ; - if (first < 0) - return FALSE; /* no text changes */ + if( i == rows) /* no text changes */ + return FALSE ; - vpv = vscreen[first]; - vpp = pscreen[first]; + int first = i ; - if (inserts) { - /* determine types of potential scrolls */ - end = endofline(vpv->v_text, cols); - if (end == 0) - target = first; /* newlines */ - else if (memcmp(vpp->v_text, vpv->v_text, 4*end) == 0) - target = first + 1; /* broken line newlines */ + video_p vpv = vscreen[ first] ; + video_p vpp = pscreen[ first] ; + + if( inserts) { + /* determine types of potential scrolls */ + end = endofline( vpv->v_text, cols) ; + if( end == 0) + target = first ; /* newlines */ + else if( memcmp( vpp->v_text, vpv->v_text, 4*end) == 0) + target = first + 1 ; /* broken line newlines */ else - target = first; + target = first ; } else { - target = first + 1; + target = first + 1 ; } /* find the matching shifted area */ - match = -1; - longmatch = -1; - longcount = 0; - from = target; - for (i = from + 1; i < rows - longcount /* P.K. */ ; i++) { - if (inserts ? texttest(i, from) : texttest(from, i)) { - match = i; - count = 1; - for (j = match + 1, k = from + 1; - j < rows && k < rows; j++, k++) { - if (inserts ? texttest(j, k) : - texttest(k, j)) - count++; + int match = -1 ; + int longmatch = -1 ; + int longcount = 0 ; + int from = target ; + for( i = from + 1 ; i < rows - longcount /* P.K. */ ; i++) { + if( inserts ? texttest( i, from) : texttest( from, i)) { + match = i ; + count = 1 ; + for( j = match + 1, k = from + 1 ; + j < rows && k < rows ; j++, k++) { + if( inserts ? texttest( j, k) : + texttest( k, j)) + count++ ; else - break; + break ; } - if (longcount < count) { - longcount = count; - longmatch = match; + if( longcount < count) { + longcount = count ; + longmatch = match ; } } } - match = longmatch; - count = longcount; - if (!inserts) { + match = longmatch ; + count = longcount ; + + if( !inserts) { /* full kill case? */ - if (match > 0 && texttest(first, match - 1)) { - target--; - match--; - count++; + if( match > 0 && texttest( first, match - 1)) { + target-- ; + match-- ; + count++ ; } } /* do the scroll */ - if (match > 0 && count > 2) { /* got a scroll */ + if( match > 0 && count > 2) { /* got a scroll */ /* move the count lines starting at target to match */ - if (inserts) { - from = target; - to = match; + if( inserts) { + from = target ; + to = match ; } else { - from = match; - to = target; + from = match ; + to = target ; } - if (2 * count < abs(from - to)) - return FALSE; - scrscroll(from, to, count); - for (i = 0; i < count; i++) { - vpp = pscreen[to + i]; - vpv = vscreen[to + i]; - memcpy(vpp->v_text, vpv->v_text, 4*cols); - vpp->v_flag = vpv->v_flag; /* XXX */ - if (vpp->v_flag & VFREV) { - vpp->v_flag &= ~VFREV; - vpp->v_flag |= ~VFREQ; + if( 2 * count < abs( from - to)) + return FALSE ; + scrscroll( from, to, count) ; + for( i = 0 ; i < count ; i++) { + vpp = pscreen[ to + i] ; + vpv = vscreen[ to + i] ; + memcpy( vpp->v_text, vpv->v_text, 4*cols) ; + vpp->v_flag = vpv->v_flag ; /* XXX */ + if( vpp->v_flag & VFREV) { + vpp->v_flag &= ~VFREV ; + vpp->v_flag |= ~VFREQ ; } #if MEMMAP - vscreen[to + i]->v_flag &= ~VFCHG; + vscreen[ to + i]->v_flag &= ~VFCHG ; #endif } - if (inserts) { - from = target; - to = match; + if( inserts) { + from = target ; + to = match ; } else { - from = target + count; - to = match + count; + from = target + count ; + to = match + count ; } #if MEMMAP == 0 - for (i = from; i < to; i++) { - unicode_t *txt; - txt = pscreen[i]->v_text; - for (j = 0; j < term.t_ncol; ++j) - txt[j] = ' '; - vscreen[i]->v_flag |= VFCHG; + for( i = from ; i < to ; i++) { + unicode_t *txt ; + txt = pscreen[ i]->v_text ; + for( j = 0 ; j < term.t_ncol ; ++j) + txt[ j] = ' ' ; + vscreen[ i]->v_flag |= VFCHG ; } #endif - return TRUE; + return TRUE ; } - return FALSE; + return FALSE ; } + /* move the "count" lines starting at "from" to "to" */ -static void scrscroll(int from, int to, int count) -{ - ttrow = ttcol = -1; - (*term.t_scroll) (from, to, count); +static void scrscroll( int from, int to, int count) { + ttrow = ttcol = -1 ; + term.t_scroll( from, to, count) ; } -/* - * return TRUE on text match + +/* return TRUE on text match * * int vrow, prow; virtual, physical rows */ -static int texttest(int vrow, int prow) -{ - video_p vpv = vscreen[vrow]; /* virtual screen image */ - video_p vpp = pscreen[prow]; /* physical screen image */ +static int texttest( int vrow, int prow) { + video_p vpv = vscreen[ vrow] ; /* virtual screen image */ + video_p vpp = pscreen[ prow] ; /* physical screen image */ - return !memcmp(vpv->v_text, vpp->v_text, 4*term.t_ncol); + return !memcmp( vpv->v_text, vpp->v_text, 4*term.t_ncol) ; } -/* - * return the index of the first blank of trailing whitespace - */ -static int endofline(unicode_t *s, int n) -{ - int i; - for (i = n - 1; i >= 0; i--) - if (s[i] != ' ') - return i + 1; - return 0; + +/* return the index of the first blank of trailing whitespace */ +static int endofline( unicode_t *s, int n) { + int i ; + for( i = n - 1 ; i >= 0 ; i--) + if( s[ i] != ' ') + return i + 1 ; + return 0 ; } #endif /* SCROLLCODE */ -/* - * updext: + +/* updext: * update the extended line which the cursor is currently * on at a column greater than the terminal width. The line * will be scrolled right or left to let the user see where * the cursor is */ -static void updext(void) -{ - int rcursor; /* real cursor location */ - line_p lp; /* pointer to current line */ +static void updext( void) { + int rcursor ; /* real cursor location */ + line_p lp ; /* pointer to current line */ /* calculate what column the real cursor will end up in */ - rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin; - taboff = lbound = curcol - rcursor + 1; + rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin ; + taboff = lbound = curcol - rcursor + 1 ; /* scan through the line outputing characters to the virtual screen */ /* once we reach the left edge */ vtmove( currow, -lbound) ; /* start scanning offscreen */ - lp = curwp->w_dotp; /* line to output */ - show_line(lp); + lp = curwp->w_dotp ; /* line to output */ + show_line( lp) ; /* truncate the virtual line, restore tab offset */ - vteeol(); - taboff = 0; + vteeol() ; + taboff = 0 ; /* and put a '$' in column 1 */ - vscreen[currow]->v_text[0] = '$'; + vscreen[ currow]->v_text[ 0] = '$' ; } -/* - * Update a single line. This does not know how to use insert or delete + +/* Update a single line. This does not know how to use insert or delete * character sequences; we are using VT52 functionality. Update the physical * row and column variables. It does try an exploit erase to end of line. */ #if MEMMAP /* UPDATELINE specific code for the IBM-PC and other compatables */ -static int updateline(int row, video_p vp1, video_p vp2) -{ +static int updateline( int row, video_p vp1, video_p vp2) { #if SCROLLCODE - unicode_t *cp1; - unicode_t *cp2; - int nch; + unicode_t *cp1 ; + unicode_t *cp2 ; + int nch ; - cp1 = &vp1->v_text[0]; - cp2 = &vp2->v_text[0]; - nch = term.t_ncol; + cp1 = &vp1->v_text[ 0] ; + cp2 = &vp2->v_text[ 0] ; + nch = term.t_ncol ; do { - *cp2 = *cp1; - ++cp2; - ++cp1; + *cp2 = *cp1 ; + ++cp2 ; + ++cp1 ; } - while (--nch); + while( --nch) ; #endif #if COLOR - scwrite(row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor); - vp1->v_fcolor = vp1->v_rfcolor; - vp1->v_bcolor = vp1->v_rbcolor; + scwrite( row, vp1->v_text, vp1->v_rfcolor, vp1->v_rbcolor) ; + vp1->v_fcolor = vp1->v_rfcolor ; + vp1->v_bcolor = vp1->v_rbcolor ; #else - if (vp1->v_flag & VFREQ) - scwrite(row, vp1->v_text, 0, 7); + if( vp1->v_flag & VFREQ) + scwrite( row, vp1->v_text, 0, 7) ; else - scwrite(row, vp1->v_text, 7, 0); + scwrite( row, vp1->v_text, 7, 0) ; #endif - vp1->v_flag &= ~(VFCHG | VFCOL); /* flag this line as changed */ - + vp1->v_flag &= ~(VFCHG | VFCOL) ; /* flag this line as changed */ } #else @@ -898,42 +863,42 @@ static int updateline(int row, video_p vp1, video_p vp2) * video_p vp1 ; virtual screen image * video_p vp2 ; physical screen image */ -static int updateline(int row, video_p vp1, video_p vp2) { +static int updateline( int row, video_p vp1, video_p vp2) { /* UPDATELINE code for all other versions */ - unicode_t *cp1; - unicode_t *cp2; - unicode_t *cp3; - unicode_t *cp4; - unicode_t *cp5; - int nbflag; /* non-blanks to the right flag? */ + unicode_t *cp1 ; + unicode_t *cp2 ; + unicode_t *cp3 ; + unicode_t *cp4 ; + unicode_t *cp5 ; + int nbflag ; /* non-blanks to the right flag? */ #if REVSTA - int rev; /* reverse video flag */ + int rev ; /* reverse video flag */ #endif int req = FALSE ; /* reverse video request flag */ /* set up pointers to virtual and physical lines */ - cp1 = &vp1->v_text[0]; - cp2 = &vp2->v_text[0]; + cp1 = &vp1->v_text[ 0] ; + cp2 = &vp2->v_text[ 0] ; #if COLOR - TTforg(vp1->v_rfcolor); - TTbacg(vp1->v_rbcolor); + TTforg( vp1->v_rfcolor) ; + TTbacg( vp1->v_rbcolor) ; #endif #if REVSTA | COLOR /* do a re-write of the entire line if it is reverse or there ** is a request to change the reverse status */ - rev = (vp1->v_flag & VFREV) == VFREV; - req = (vp1->v_flag & VFREQ) == VFREQ; + rev = (vp1->v_flag & VFREV) == VFREV ; + req = (vp1->v_flag & VFREQ) == VFREQ ; if( req || (req != rev) #if COLOR || (vp1->v_fcolor != vp1->v_rfcolor) || (vp1->v_bcolor != vp1->v_rbcolor) #endif ) { - movecursor(row, 0); /* Go to start of line. */ + movecursor( row, 0) ; /* Go to start of line. */ TTrev( req) ; /* set needed rev video state */ /* scan through the line and dump it to the screen and @@ -949,23 +914,23 @@ static int updateline(int row, video_p vp1, video_p vp2) { TTrev( FALSE) ; /* turn rev video off */ /* update the needed flags */ - vp1->v_flag &= ~VFCHG; - if (req) - vp1->v_flag |= VFREV; + vp1->v_flag &= ~VFCHG ; + if( req) + vp1->v_flag |= VFREV ; else - vp1->v_flag &= ~VFREV; + vp1->v_flag &= ~VFREV ; #if COLOR - vp1->v_fcolor = vp1->v_rfcolor; - vp1->v_bcolor = vp1->v_rbcolor; + vp1->v_fcolor = vp1->v_rfcolor ; + vp1->v_bcolor = vp1->v_rbcolor ; #endif - return TRUE; + return TRUE ; } #endif /* advance past any common chars at the left */ - while (cp1 != &vp1->v_text[term.t_ncol] && cp1[0] == cp2[0]) { - ++cp1; - ++cp2; + while( cp1 != &vp1->v_text[ term.t_ncol] && cp1[ 0] == cp2[ 0]) { + ++cp1 ; + ++cp2 ; } /* This can still happen, even though we only call this routine on changed @@ -975,94 +940,94 @@ static int updateline(int row, video_p vp1, video_p vp2) { * be hard operations that do a lot of update, so I don't really care. */ /* if both lines are the same, no update needs to be done */ - if (cp1 == &vp1->v_text[term.t_ncol]) { - vp1->v_flag &= ~VFCHG; /* flag this line is changed */ - return TRUE; + if( cp1 == &vp1->v_text[ term.t_ncol]) { + vp1->v_flag &= ~VFCHG ; /* flag this line is changed */ + return TRUE ; } /* find out if there is a match on the right */ - nbflag = FALSE; - cp3 = &vp1->v_text[term.t_ncol]; - cp4 = &vp2->v_text[term.t_ncol]; + nbflag = FALSE ; + cp3 = &vp1->v_text[ term.t_ncol] ; + cp4 = &vp2->v_text[ term.t_ncol] ; - while (cp3[-1] == cp4[-1]) { - --cp3; - --cp4; - if (cp3[0] != ' ') /* Note if any nonblank */ - nbflag = TRUE; /* in right match. */ + while( cp3[ -1] == cp4[ -1]) { + --cp3 ; + --cp4 ; + if( cp3[ 0] != ' ') /* Note if any nonblank */ + nbflag = TRUE ; /* in right match. */ } - cp5 = cp3; + cp5 = cp3 ; /* Erase to EOL ? */ - if (nbflag == FALSE && eolexist == TRUE && (req != TRUE)) { - while (cp5 != cp1 && cp5[-1] == ' ') - --cp5; + if( nbflag == FALSE && eolexist == TRUE && (req != TRUE)) { + while( cp5 != cp1 && cp5[ -1] == ' ') + --cp5 ; - if (cp3 - cp5 <= 3) /* Use only if erase is */ - cp5 = cp3; /* fewer characters. */ + if( cp3 - cp5 <= 3) /* Use only if erase is */ + cp5 = cp3 ; /* fewer characters. */ } - movecursor(row, cp1 - &vp1->v_text[0]); /* Go to start of line. */ + movecursor( row, cp1 - &vp1->v_text[ 0]) ; /* Go to start of line. */ #if REVSTA - TTrev(rev); + TTrev( rev) ; #endif - while (cp1 != cp5) { /* Ordinary. */ + while( cp1 != cp5) { /* Ordinary. */ unicode_t c = *cp1++ ; TTputc( c) ; ttcol += utf8_width( c) ; *cp2++ = c ; } - if (cp5 != cp3) { /* Erase. */ - TTeeol(); - while (cp1 != cp3) - *cp2++ = *cp1++; + if( cp5 != cp3) { /* Erase. */ + TTeeol() ; + while( cp1 != cp3) + *cp2++ = *cp1++ ; } #if REVSTA - TTrev(FALSE); + TTrev( FALSE) ; #endif - vp1->v_flag &= ~VFCHG; /* flag this line as updated */ - return TRUE; + vp1->v_flag &= ~VFCHG ; /* flag this line as updated */ + return TRUE ; } #endif -/* - * Redisplay the mode line for the window pointed to by the "wp". This is the + +/* Redisplay the mode line for the window pointed to by the "wp". This is the * only routine that has any idea of how the modeline is formatted. You can * change the modeline format by hacking at this routine. Called by "update" * any time there is a dirty window. */ static void modeline( window_p wp) { - int n; /* cursor position count */ + int n ; /* cursor position count */ buffer_p bp ; - int i; /* loop index */ - int lchar; /* character to draw line in buffer with */ - int firstm; /* is this the first mode? */ + int i ; /* loop index */ + int lchar ; /* character to draw line in buffer with */ + int firstm ; /* is this the first mode? */ - n = wp->w_toprow + wp->w_ntrows; /* Location. */ - vscreen[n]->v_flag |= VFCHG | VFREQ | VFCOL; /* Redraw next time. */ + n = wp->w_toprow + wp->w_ntrows ; /* Location. */ + vscreen[ n]->v_flag |= VFCHG | VFREQ | VFCOL ; /* Redraw next time. */ #if COLOR - vscreen[n]->v_rfcolor = 0; /* black on */ - vscreen[n]->v_rbcolor = 7; /* white..... */ + vscreen[ n]->v_rfcolor = 0 ; /* black on */ + vscreen[ n]->v_rbcolor = 7 ; /* white..... */ #endif vtmove( n, 0) ; /* Seek to right line. */ - if (wp == curwp) /* mark the current buffer */ + if( wp == curwp) /* mark the current buffer */ #if PKCODE && REVSTA - lchar = '-'; + lchar = '-' ; #else - lchar = '='; + lchar = '=' ; #endif else #if REVSTA - if (revexist) - lchar = ' '; + if( revexist) + lchar = ' ' ; else #endif - lchar = '-'; + lchar = '-' ; - bp = wp->w_bufp; + bp = wp->w_bufp ; vtputc( ((bp->b_flag & BFTRUNC) != 0) ? '#' : lchar) ; /* truncated? */ vtputc( ((bp->b_flag & BFCHG) != 0) ? '*' : lchar) ; /* changed? */ vtputc( ' ') ; @@ -1077,15 +1042,15 @@ static void modeline( window_p wp) { /* display the modes */ - if ((bp->b_flag & BFTRUNC) != 0) { - firstm = FALSE; + if( (bp->b_flag & BFTRUNC) != 0) { + firstm = FALSE ; n += vtputs( "Truncated") ; } else firstm = TRUE ; - for (i = 0; i < NUMMODES; i++) /* add in the mode flags */ - if (wp->w_bufp->b_mode & (1 << i)) { - if (firstm != TRUE) + for( i = 0 ; i < NUMMODES ; i++) /* add in the mode flags */ + if( wp->w_bufp->b_mode & (1 << i)) { + if( firstm != TRUE) n += vtputs( " ") ; else firstm = FALSE ; @@ -1096,69 +1061,68 @@ static void modeline( window_p wp) { n += vtputs( ") ") ; #if PKCODE - if (bp->b_fname[0] != 0 && strcmp(bp->b_bname, bp->b_fname) != 0) { + if( bp->b_fname[ 0] != 0 && strcmp( bp->b_bname, bp->b_fname) != 0) { #else - if (bp->b_fname[0] != 0) { /* File name. */ + if( bp->b_fname[ 0] != 0) { /* File name. */ n += vtputs( "File: ") ; #endif n += vtputs( bp->b_fname) ; - vtputc(' '); - ++n; + vtputc(' ') ; + ++n ; } - while (n < term.t_ncol) { /* Pad to full width. */ - vtputc(lchar); - ++n; + while( n < term.t_ncol) { /* Pad to full width. */ + vtputc( lchar) ; + ++n ; } { /* determine if top line, bottom line, or both are visible */ - line_p lp = wp->w_linep; - int rows = wp->w_ntrows; - char *msg = NULL; + line_p lp = wp->w_linep ; + int rows = wp->w_ntrows ; + char *msg = NULL ; char tline[ 6] ; /* buffer for part of mode line */ vtcol -= 7 ; /* strlen(" top ") plus a couple */ - while (rows--) { - lp = lforw(lp); - if (lp == wp->w_bufp->b_linep) { - msg = " Bot "; - break; + while( rows--) { + lp = lforw( lp) ; + if( lp == wp->w_bufp->b_linep) { + msg = " Bot " ; + break ; } } - if (lback(wp->w_linep) == wp->w_bufp->b_linep) { - if (msg) { - if (wp->w_linep == wp->w_bufp->b_linep) - msg = " Emp "; + if( lback( wp->w_linep) == wp->w_bufp->b_linep) { + if( msg) { + if( wp->w_linep == wp->w_bufp->b_linep) + msg = " Emp " ; else - msg = " All "; + msg = " All " ; } else { - msg = " Top "; + msg = " Top " ; } } - if (!msg) { - line_p lp; + if( !msg) { + line_p lp ; int numlines, predlines ; - lp = lforw(bp->b_linep); - numlines = 0; - predlines = 0; - while (lp != bp->b_linep) { - if (lp == wp->w_linep) { - predlines = numlines; + lp = lforw( bp->b_linep) ; + numlines = 0 ; + predlines = 0 ; + while( lp != bp->b_linep) { + if( lp == wp->w_linep) { + predlines = numlines ; } - ++numlines; - lp = lforw(lp); + ++numlines ; + lp = lforw( lp) ; } - if (wp->w_dotp == bp->b_linep) { - msg = " Bot "; + if( wp->w_dotp == bp->b_linep) { + msg = " Bot " ; } else { int ratio = 0 ; - if (numlines != 0) - ratio = - (100L * predlines) / numlines; - if (ratio > 99) - ratio = 99; + if( numlines != 0) + ratio = (100L * predlines) / numlines ; + if( ratio > 99) + ratio = 99 ; tline[ 0] = ' ' ; tline[ 1] = ratio / 10 + '0' ; @@ -1169,7 +1133,7 @@ static void modeline( window_p wp) { if( tline[ 1] == '0') tline[ 1] = ' ' ; - msg = tline; + msg = tline ; } } @@ -1177,33 +1141,31 @@ static void modeline( window_p wp) { } } -void upmode(void) -{ /* update all the mode lines */ - window_p wp; +void upmode( void) { /* update all the mode lines */ + window_p wp ; - wp = wheadp; - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; + wp = wheadp ; + while( wp != NULL) { + wp->w_flag |= WFMODE ; + wp = wp->w_wndp ; } } -/* - * Send a command to the terminal to move the hardware cursor to row "row" + +/* Send a command to the terminal to move the hardware cursor to row "row" * and column "col". The row and column arguments are origin 0. Optimize out * random calls. Update "ttrow" and "ttcol". */ -void movecursor(int row, int col) -{ - if (row != ttrow || col != ttcol) { - ttrow = row; - ttcol = col; - TTmove(row, col); +void movecursor( int row, int col) { + if( row != ttrow || col != ttcol) { + ttrow = row ; + ttcol = col ; + TTmove( row, col) ; } } -/* - * Erase the message line. This is a special routine because the message line + +/* Erase the message line. This is a special routine because the message line * is not considered to be part of the virtual screen. It always works * immediately; the terminal buffer is flushed via a call to the flusher. */ @@ -1236,8 +1198,8 @@ static void mlputc( unicode_t c) { } } -/* - * output a string of output characters + +/* output a string of output characters * * char *s; string to output */ @@ -1247,8 +1209,8 @@ void ostring( const char *s) { } -/* - * Write a message into the message line. Keep track of the physical cursor + +/* Write a message into the message line. Keep track of the physical cursor * position. A small class of printf like format items is handled. Assumes the * stack grows down; this assumption is made by the "++" in the argument scan * loop. Set the "message line" flag TRUE. @@ -1258,14 +1220,14 @@ void ostring( const char *s) { */ void vmlwrite( const char *fmt, va_list ap) { /* if we are not currently echoing on the command line, abort this */ - if (discmd == FALSE) { - movecursor(term.t_nrow, 0); - return; + if( discmd == FALSE) { + movecursor( term.t_nrow, 0) ; + return ; } #if COLOR /* set up the proper colors for the command line */ - TTforg(7); - TTbacg(0); + TTforg( 7) ; + TTbacg( 0) ; #endif /* if we can not erase to end-of-line, do it manually */ @@ -1288,28 +1250,28 @@ void vmlwrite( const char *fmt, va_list ap) { fmt += utf8_to_unicode( fmt, 0, 4, &c) ; switch( c) { case 'd': - mlputi(va_arg(ap, int), 10); - break; + mlputi( va_arg( ap, int), 10) ; + break ; case 'o': - mlputi(va_arg(ap, int), 8); - break; + mlputi( va_arg( ap, int), 8) ; + break ; case 'x': - mlputi(va_arg(ap, int), 16); - break; + mlputi( va_arg( ap, int), 16) ; + break ; case 'D': - mlputli(va_arg(ap, long), 10); - break; + mlputli( va_arg( ap, long), 10) ; + break ; case 's': mlputs( (char *) va_arg( ap, char *)) ; - break; + break ; case 'f': - mlputf(va_arg(ap, int)); - break; + mlputf( va_arg( ap, int)) ; + break ; case 'B': /* ring a bell */ TTbeep() ; @@ -1328,7 +1290,7 @@ void vmlwrite( const char *fmt, va_list ap) { if( eolexist == TRUE && ttcol < term.t_ncol) TTeeol() ; - TTflush(); + TTflush() ; } void mlwrite( const char *fmt, ...) { @@ -1339,8 +1301,8 @@ void mlwrite( const char *fmt, ...) { va_end( ap) ; } -/* - * Write out a string. Update the physical cursor position. This assumes that + +/* Write out a string. Update the physical cursor position. This assumes that * the characters in the string all have width "1"; if this is not the case * things will get screwed up a little. */ @@ -1357,8 +1319,8 @@ static void mlputs( const char *s) { } } -/* - * Write out an integer, in the specified radix. Update the physical cursor + +/* Write out an integer, in the specified radix. Update the physical cursor * position. */ static void mlputi( int i, int r) { @@ -1381,9 +1343,8 @@ static void mlputi( int i, int r) { mlputc( hexdigits[ u % r]) ; } -/* - * do the same except as a long integer. - */ + +/* do the same except as a long integer. */ static void mlputli( long l, int r) { long q ; @@ -1400,8 +1361,8 @@ static void mlputli( long l, int r) { mlputc( (int) (l % r) + '0') ; } -/* - * write out a scaled integer with two decimal places + +/* write out a scaled integer with two decimal places * * int s; scaled integer to output */ @@ -1415,9 +1376,9 @@ static void mlputf( int s) { /* send out the integer portion */ mlputi( i, 10) ; - mlputc('.') ; - mlputc((f / 10) + '0') ; - mlputc((f % 10) + '0') ; + mlputc( '.') ; + mlputc( (f / 10) + '0') ; + mlputc( (f % 10) + '0') ; } @@ -1425,29 +1386,27 @@ static void mlputf( int s) { Store number of lines into *heightp and width into *widthp. If zero or a negative number is stored, the value is not valid. */ -void getscreensize(int *widthp, int *heightp) -{ +void getscreensize( int *widthp, int *heightp) { #ifdef TIOCGWINSZ - struct winsize size; - *widthp = 0; - *heightp = 0; - if (ioctl(0, TIOCGWINSZ, &size) < 0) - return; - *widthp = size.ws_col; - *heightp = size.ws_row; + struct winsize size ; + *widthp = 0 ; + *heightp = 0 ; + if( ioctl( 0, TIOCGWINSZ, &size) < 0) + return ; + *widthp = size.ws_col ; + *heightp = size.ws_row ; #else - *widthp = 0; - *heightp = 0; + *widthp = 0 ; + *heightp = 0 ; #endif } #ifdef SIGWINCH -void sizesignal(int signr) -{ - int w, h; - int old_errno = errno; +void sizesignal( int signr) { + int w, h ; + int old_errno = errno ; - getscreensize(&w, &h); + getscreensize( &w, &h) ; if( h > 0 && w > 0) { term.t_mrow = h = h < term.t_maxrow ? h : term.t_maxrow ; @@ -1456,32 +1415,33 @@ void sizesignal(int signr) newscreensize( h, w) ; } - signal(SIGWINCH, sizesignal); - errno = old_errno; + signal( SIGWINCH, sizesignal) ; + errno = old_errno ; } -static int newscreensize(int h, int w) -{ - /* do the change later */ - if (displaying) { - chg_width = w; - chg_height = h; - return FALSE; +static int newscreensize( int h, int w) { +/* do the change later */ + if( displaying) { + chg_width = w ; + chg_height = h ; + return FALSE ; } - chg_width = chg_height = 0; - if( h <= term.t_mrow) - newsize(TRUE, h); - if( w <= term.t_mcol) - newwidth(TRUE, w); - update(TRUE); - return TRUE; + chg_width = chg_height = 0 ; + if( h <= term.t_mrow) + newsize( TRUE, h) ; + + if( w <= term.t_mcol) + newwidth( TRUE, w) ; + + update( TRUE) ; + return TRUE ; } #endif -/* - * output a character when echo is enabled + +/* output a character when echo is enabled * * char c ; character to output */ @@ -1492,8 +1452,8 @@ void echoc( unicode_t c) { } } -/* - * output a string of characters when display input is enabled + +/* output a string of characters when display input is enabled * * char *s; string to output */ @@ -1507,6 +1467,7 @@ void echos( const char *s) { } } + void rubout( void) { if( disinp) { TTputc( '\b') ; diff --git a/display.h b/display.h index cd5564c..89371fd 100644 --- a/display.h +++ b/display.h @@ -21,11 +21,7 @@ BINDABLE( upscreen) ; void vtinit( void) ; void vtfree( void) ; void vttidy( void) ; -int update( boolean force_f) ; -void updpos( void) ; -void upddex( void) ; -void updgar( void) ; -int updupd( int force) ; +boolean update( boolean force_f) ; void upmode( void) ; void movecursor( int row, int col) ; void mlerase( void) ;