From 92078e5595c56ec78150448189932b22ecf3e27f Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 20 May 2016 19:46:54 +0800 Subject: [PATCH] Check consistency of forwchar/backchar calls. Review entab dot movement. --- line.c | 2 ++ random.c | 17 ++++++++++------- window.h | 21 ++++++++++++--------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/line.c b/line.c index f085b8c..5e39617 100644 --- a/line.c +++ b/line.c @@ -114,6 +114,7 @@ static unsigned utf8_revdelta( unsigned char *p, unsigned pos) { } boolean backchar( int f, int n) { + assert( f == TRUE || (f == FALSE && n == 1)) ; if( n < 0) return forwchar( f, -n) ; @@ -147,6 +148,7 @@ boolean backchar( int f, int n) { * buffer. Set the flag if the line pointer for dot changes. */ boolean forwchar( int f, int n) { + assert( f == TRUE || (f == FALSE && n == 1)) ; if( n < 0) return backchar( f, -n) ; diff --git a/random.c b/random.c index d0e239f..c4e9506 100644 --- a/random.c +++ b/random.c @@ -329,12 +329,15 @@ int detab(int f, int n) /* detab the entire current line */ while (curwp->w_doto < llength(curwp->w_dotp)) { /* if we have a tab */ - if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') { - ldelchar(1, FALSE); - insspace( TRUE, tabwidth - curwp->w_doto % tabwidth); - } + if( curwbyte() == '\t') { + int size ; - forwchar(FALSE, 1); + ldelchar( 1, FALSE) ; + size = tabwidth - curwp->w_doto % tabwidth ; + insspace( TRUE, size) ; + forwchar( TRUE, size) ; + } else + forwchar( FALSE, 1) ; } /* advance/or back to the next line */ @@ -391,7 +394,7 @@ int entab(int f, int n) } /* get the current character */ - switch( lgetc( curwp->w_dotp, curwp->w_doto)) { + switch( curwbyte()) { case '\t': /* a tab...count em up */ ccol = nextab(ccol); break; @@ -967,7 +970,7 @@ int getfence(int f, int n) /* if no eol */ if( curwp->w_doto != llength(curwp->w_dotp)) { - c = lgetc( curwp->w_dotp, curwp->w_doto) ; + c = curwbyte() ; if( c == ch) ++count ; else if( c == ofence) diff --git a/window.h b/window.h index e9351ec..8a7f781 100644 --- a/window.h +++ b/window.h @@ -13,13 +13,13 @@ * the full blown redisplay is just too expensive to run for every input * character. */ -struct window { +typedef struct window { struct window *w_wndp; /* Next window */ struct buffer *w_bufp; /* Buffer displayed in window */ - struct line *w_linep; /* Top line in the window */ - struct line *w_dotp; /* Line containing "." */ - struct line *w_markp; /* Line containing "mark" */ - int w_doto; /* Byte offset for "." */ + line_p w_linep ; /* Top line in the window */ + line_p w_dotp ; /* Line containing "." */ + line_p w_markp ; /* Line containing "mark" */ + int w_doto ; /* Byte offset for "." */ int w_marko; /* Byte offset for "mark" */ int w_toprow ; /* Origin 0 top row of window */ int w_ntrows ; /* # of rows of text in window */ @@ -29,10 +29,13 @@ struct window { char w_fcolor; /* current forground color */ char w_bcolor; /* current background color */ #endif -}; +} *window_p ; -extern struct window *curwp ; /* Current window */ -extern struct window *wheadp ; /* Head of list of windows */ +extern window_p curwp ; /* Current window */ +extern window_p wheadp ; /* Head of list of windows */ + +/* curwbyte return the byte after the dot in current window */ +#define curwbyte() lgetc( curwp->w_dotp, curwp->w_doto) #define WFFORCE 0x01 /* Window needs forced reframe */ #define WFMOVE 0x02 /* Movement from line to line */ @@ -66,6 +69,6 @@ int newsize( int f, int n) ; int newwidth( int f, int n) ; int getwpos( void) ; void cknewwindow( void) ; -struct window *wpopup( void) ; /* Pop up window creation. */ +window_p wpopup( void) ; /* Pop up window creation. */ #endif