From 3ffa8967efcad51d9c257638fe0498c281d97fec Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Mon, 28 Sep 2015 13:37:22 +0800 Subject: [PATCH] Align implementation of overwrite-string with insert-string. --- random.c | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/random.c b/random.c index 934b9c3..1dcc0bb 100644 --- a/random.c +++ b/random.c @@ -1184,19 +1184,12 @@ int fmatch(int ch) return TRUE; } -/* - * ask for and insert a string into the current - * buffer at the current point - * - * int f, n; ignored arguments - */ -int istring(int f, int n) -{ +static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { int status ; /* status return code */ char *tstring ; /* string to add */ /* ask for string to insert */ - tstring = newmlreplyt( "String to insert: ") ; + tstring = newmlreplyt( prompt) ; if( tstring == NULL) return FALSE ; @@ -1208,36 +1201,30 @@ int istring(int f, int n) /* insert it */ status = TRUE ; while( n-- && status) - status = linstr( tstring) ; + status = fun( tstring) ; free( tstring) ; return status ; } +/* + * ask for and insert a string into the current + * buffer at the current point + * + * int f, n; ignored arguments + */ +int istring( int f, int n) { + return iovstring( f, n, "String to insert: ", linstr) ; +} + /* * ask for and overwite a string into the current * buffer at the current point * * int f, n; ignored arguments */ -int ovstring(int f, int n) -{ - int status; /* status return code */ - char tstring[ NSTRING + 1] ; /* string to add */ - - /* ask for string to insert */ - status = - mlreplyt( "String to overwrite: ", tstring, NSTRING) ; - if (status != TRUE) - return status; - - if (f == FALSE) - n = 1; - - if (n < 0) - n = -n; - - /* insert it */ - while (n-- && (status = lover(tstring))); - return status; +int ovstring( int f, int n) { + return iovstring( f, n, "String to overwrite: ", lover) ; } + +/* end of random.c */