From 14e6240b9c0e78759c4d5933c31e166609fbaf3f Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Sat, 21 May 2016 07:52:19 +0800 Subject: [PATCH] Transpose-characters valid with mixed UTF-8 and extended ASCII. --- line.c | 7 ++----- line.h | 1 + random.c | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/line.c b/line.c index 5e39617..25d41d8 100644 --- a/line.c +++ b/line.c @@ -277,8 +277,6 @@ int insspace(int f, int n) return TRUE; } -static int linsert_byte( int n, int c) ; - /* * linstr -- Insert a string at the current point */ @@ -291,7 +289,7 @@ int linstr( char *instr) { while( (tmpc = *instr++ & 0xFF)) { status = - (tmpc == '\n' ? lnewline() : linsert_byte( 1, tmpc)) ; + (tmpc == '\n' ? lnewline() : (int) linsert_byte( 1, tmpc)) ; /* Insertion error? */ if( status != TRUE) { @@ -314,8 +312,7 @@ int linstr( char *instr) { * well, and FALSE on errors. */ -static int linsert_byte(int n, int c) -{ +boolean linsert_byte( int n, int c) { char *cp1; char *cp2; struct line *lp1; diff --git a/line.h b/line.h index fb88741..1234524 100644 --- a/line.h +++ b/line.h @@ -38,6 +38,7 @@ void lchange( int flag) ; int insspace( int f, int n) ; int linstr( char *instr) ; int linsert( int n, unicode_t c) ; +boolean linsert_byte( int n, int c) ; int lover( char *ostr) ; int lnewline( void) ; boolean ldelete( long n, boolean kflag) ; diff --git a/random.c b/random.c index 25f1c2a..34c4765 100644 --- a/random.c +++ b/random.c @@ -219,7 +219,7 @@ int setccol(int pos) /* set us at the new position */ curwp->w_doto = i; - /* and tell weather we made it */ + /* and tell whether we made it */ return col >= pos; } @@ -247,10 +247,14 @@ boolean twiddle( int f, int n) { eof_f = TRUE ; } - lgetchar( &c) ; + len = lgetchar( &c) ; /* len => unicode or extended ASCII */ ldelchar( 1, FALSE) ; backchar( FALSE, 1) ; - linsert( 1, c) ; + if( len == 1) + linsert_byte( 1, c) ; + else + linsert( 1, c) ; + if( eof_f == TRUE) forwchar( FALSE, 1) ; @@ -346,7 +350,9 @@ int detab(int f, int n) } /* advance/or back to the next line */ - forwline(TRUE, inc); + if( forwline( TRUE, inc) == FALSE) + break ; + n -= inc; } curwp->w_doto = 0; /* to the begining of the line */ @@ -419,7 +425,9 @@ int entab(int f, int n) } /* advance/or back to the next line */ - forwline(TRUE, inc); + if( forwline( TRUE, inc) == FALSE) + break ; + n -= inc; } curwp->w_doto = 0; /* to the begining of the line */ @@ -463,7 +471,9 @@ int trim(int f, int n) lp->l_used = length; /* advance/or back to the next line */ - forwline(TRUE, inc); + if( forwline( TRUE, inc) == FALSE) + break ; + n -= inc; } lchange(WFEDIT);