1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-10-01 09:45:58 -04: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) ; 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 * 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 * 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) ; return nextarg( prompt, buf, nbuf, metac) ;
} }
char *newmlreplyt( const char *prompt) {
return newnextarg( prompt, metac) ;
}
/* /*
* ectoc: * ectoc:
* expanded character to character * expanded character to character

View File

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

View File

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