Revise line primitives linstr() and lover()

This commit is contained in:
Renaud 2021-08-22 12:35:39 +08:00
parent 62e1109802
commit a370d748c4
3 changed files with 18 additions and 24 deletions

36
line.c
View File

@ -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 ;
int c ;
while( (tmpc = *instr++ & 0xFF)) {
status = (tmpc == '\n') ? lnewline() : linsert_byte( 1, tmpc) ;
/* 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 ;

4
line.h
View File

@ -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) ;

View File

@ -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 */