1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 23:36:23 -05:00

Rework insert-string for dynamic token input.

This commit is contained in:
Renaud 2015-09-27 22:13:20 +08:00
parent cfa5c7fb65
commit cbbd860bdc
3 changed files with 41 additions and 13 deletions

24
input.c
View File

@ -102,6 +102,26 @@ static int nextarg( const char *prompt, char *buf, int size, int terminator) {
return gettokval( buf, size) ;
}
static char *newnextarg( const char *prompt, int terminator) {
/* if we are interactive, go get it! */
if( clexec == FALSE) {
char *buf ;
int size ;
size = term.t_ncol + 1 ;
buf = malloc( size) ;
if( buf != NULL) {
if( TRUE != getstring( prompt, buf, size, terminator)) {
free( buf) ;
buf = NULL ;
}
}
return buf ;
} else
return getnewtokval() ;
}
/*
* Write a prompt into the message line, then read back a response. Keep
* track of the physical position of the cursor. If we are in a keyboard
@ -118,6 +138,10 @@ int mlreplyt( const char *prompt, char *buf, int nbuf) {
return nextarg( prompt, buf, nbuf, metac) ;
}
char *newmlreplyt( const char *prompt) {
return newnextarg( prompt, metac) ;
}
/*
* ectoc:
* expanded character to character

View File

@ -25,6 +25,7 @@ extern const int nlc ; /* end of input char */
int mlyesno( const char *prompt) ;
int mlreply( const char *prompt, char *buf, int nbuf) ;
int mlreplyt( const char *prompt, char *buf, int nbuf) ;
char *newmlreplyt( const char *prompt) ;
int ectoc( int c) ;
fn_t getname( void) ;
int tgetc( void) ;

View File

@ -12,6 +12,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic.h"
@ -1191,24 +1192,26 @@ int fmatch(int ch)
*/
int istring(int f, int n)
{
int status; /* status return code */
char tstring[ 512] ; /* string to add */
int status ; /* status return code */
char *tstring ; /* string to add */
/* ask for string to insert */
status =
mlreplyt( "String to insert<META>: ", tstring, sizeof tstring - 1) ;
if (status != TRUE)
return status;
tstring = newmlreplyt( "String to insert<META>: ") ;
if( tstring == NULL)
return FALSE ;
if (f == FALSE)
n = 1;
if (n < 0)
n = -n;
if( f == FALSE)
n = 1 ;
else if( n < 0)
n = -n ;
/* insert it */
while (n-- && (status = linstr(tstring)));
return status;
status = TRUE ;
while( n-- && status)
status = linstr( tstring) ;
free( tstring) ;
return status ;
}
/*