From a370d748c4c88a9f1a47cf1ba6322f7fb697ccf8 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Sun, 22 Aug 2021 12:35:39 +0800 Subject: [PATCH] Revise line primitives linstr() and lover() --- line.c | 36 +++++++++++++++--------------------- line.h | 4 ++-- random.c | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/line.c b/line.c index 0fb61d8..abd7acc 100644 --- a/line.c +++ b/line.c @@ -266,8 +266,8 @@ void lchange(int flag) } } -/* - * insert spaces forward into text + +/* insert spaces forward into text * * int f, n; default flag and numeric argument */ @@ -278,23 +278,18 @@ BINDABLE( insspace) { return TRUE ; } -/* - * linstr -- Insert a string at the current point - */ - -int linstr( char *instr) { - int status = TRUE ; +/* linstr -- Insert a string at the current point */ +boolean linstr( char *instr) { + boolean status = TRUE ; if( instr != NULL) { - unicode_t tmpc ; - - while( (tmpc = *instr++ & 0xFF)) { - status = (tmpc == '\n') ? lnewline() : linsert_byte( 1, tmpc) ; + int c ; - /* Insertion error? */ - if( status != TRUE) { + while( (c = (unsigned char) *instr++)) { + status = (c == '\n') ? lnewline() : linsert_byte( 1, c) ; + if( status != TRUE) { /* Insertion error? */ mloutstr( "%Out of memory while inserting") ; - return status ; + break ; } } } @@ -432,14 +427,13 @@ static boolean lowrite( int c) { /* lover -- Overwrite a string at the current point */ -int lover( char *ostr) { - int status = TRUE ; - +boolean lover( char *ostr) { + boolean status = TRUE ; if( ostr != NULL) { - char tmpc ; + int c ; - while( (tmpc = *ostr++)) { - status = (tmpc == '\n' ? lnewline() : lowrite( tmpc)) ; + while( (c = (unsigned char) *ostr++)) { + status = (c == '\n') ? lnewline() : lowrite( c) ; if( status != TRUE) { /* Insertion error? */ mloutstr( "%Out of memory while overwriting") ; break ; diff --git a/line.h b/line.h index 01e28d7..5260386 100644 --- a/line.h +++ b/line.h @@ -39,10 +39,10 @@ BBINDABLE( forwchar) ; void lfree( line_p lp) ; void lchange( int flag) ; -int linstr( char *instr) ; +boolean linstr( char *instr) ; boolean linsert( int n, unicode_t c) ; boolean linsert_byte( int n, int c) ; -int lover( char *ostr) ; +boolean lover( char *ostr) ; boolean lnewline( void) ; boolean ldelete( long n, boolean kflag) ; boolean ldelchar( long n, boolean kflag) ; diff --git a/random.c b/random.c index 01a0b60..28ddfc3 100644 --- a/random.c +++ b/random.c @@ -837,7 +837,7 @@ static int adjustmode( int kind, int global) { } -static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { +static int iovstring( int f, int n, const char *prompt, boolean (*fun)( char *)) { char *tstring ; /* string to add */ /* ask for string to insert */