2013-05-18 02:21:28 -04:00
|
|
|
/* input.c -- implements input.h */
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* input.c
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* Various input routines
|
2005-05-31 11:50:56 -04:00
|
|
|
*
|
2013-10-08 22:48:00 -04:00
|
|
|
* written by Daniel Lawrence 5/9/86
|
|
|
|
* modified by Petri Kutvonen
|
2005-05-31 11:50:56 -04:00
|
|
|
*/
|
|
|
|
|
2010-12-03 20:32:08 -05:00
|
|
|
#include <stdio.h>
|
2019-08-06 22:19:47 -04:00
|
|
|
#include <stdlib.h>
|
2013-10-08 21:43:15 -04:00
|
|
|
#include <string.h>
|
2010-12-03 20:32:08 -05:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2013-05-28 01:04:39 -04:00
|
|
|
#include "bind.h"
|
2013-10-09 01:43:32 -04:00
|
|
|
#include "estruct.h"
|
2013-06-04 23:48:40 -04:00
|
|
|
#include "bindable.h"
|
2013-05-28 02:57:03 -04:00
|
|
|
#include "display.h"
|
2013-05-25 00:37:03 -04:00
|
|
|
#include "exec.h"
|
2019-07-25 07:13:40 -04:00
|
|
|
#include "isa.h"
|
2013-05-31 01:18:10 -04:00
|
|
|
#include "names.h"
|
2013-09-25 09:45:05 -04:00
|
|
|
#include "terminal.h"
|
2015-02-10 04:07:43 -05:00
|
|
|
#include "utf8.h"
|
2010-12-03 20:32:08 -05:00
|
|
|
#include "wrapper.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2019-07-23 09:04:50 -04:00
|
|
|
#if PKCODE && UNIX
|
2013-10-08 22:48:00 -04:00
|
|
|
#define COMPLC 1
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2013-10-08 22:48:00 -04:00
|
|
|
#define COMPLC 0
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
#define NKBDM 256 /* # of strokes, keyboard macro */
|
|
|
|
int kbdm[ NKBDM] ; /* Macro */
|
|
|
|
int *kbdptr ; /* current position in keyboard buf */
|
|
|
|
int *kbdend = &kbdm[0] ; /* ptr to end of the keyboard */
|
2013-09-27 02:29:26 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
kbdstate kbdmode = STOP ; /* current keyboard macro mode */
|
|
|
|
int lastkey = 0 ; /* last keystoke */
|
|
|
|
int kbdrep = 0 ; /* number of repetitions */
|
2013-10-08 05:41:49 -04:00
|
|
|
|
2013-10-10 00:33:13 -04:00
|
|
|
int metac = CONTROL | '[' ; /* current meta character */
|
|
|
|
int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
|
|
|
|
int reptc = CONTROL | 'U' ; /* current universal repeat char */
|
|
|
|
int abortc = CONTROL | 'G' ; /* current abort command char */
|
|
|
|
|
2015-08-24 21:17:41 -04:00
|
|
|
const int nlc = CONTROL | 'J' ; /* end of input char */
|
|
|
|
|
2015-02-13 08:48:05 -05:00
|
|
|
|
2019-08-06 22:19:47 -04:00
|
|
|
void ue_system( const char *cmd) {
|
|
|
|
int ret ;
|
|
|
|
|
|
|
|
ret = system( cmd) ;
|
|
|
|
if( ret == -1) {
|
|
|
|
/* some actual handling needed here */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* Ask a yes or no question in the message line. Return either TRUE, FALSE, or
|
|
|
|
* ABORT. The ABORT status is returned if the user bumps out of the question
|
|
|
|
* with a ^G. Used any time a confirmation is required.
|
|
|
|
*/
|
2013-09-19 04:10:29 -04:00
|
|
|
int mlyesno( const char *prompt)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2019-08-09 08:47:05 -04:00
|
|
|
int c ; /* input character */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
for (;;) {
|
2015-01-16 04:55:23 -05:00
|
|
|
/* prompt the user */
|
|
|
|
mlwrite( "%s (y/n)? ", prompt) ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2014-06-02 03:16:18 -04:00
|
|
|
/* get the response */
|
2019-08-09 08:47:05 -04:00
|
|
|
c = get1key() ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2019-08-09 08:47:05 -04:00
|
|
|
if( c == abortc) /* Bail out! */
|
2013-10-08 22:48:00 -04:00
|
|
|
return ABORT;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == 'y' || c == 'Y')
|
|
|
|
return TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == 'n' || c == 'N')
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2015-08-25 04:34:15 -04:00
|
|
|
/*
|
2015-10-05 02:15:24 -04:00
|
|
|
* newnextarg:
|
2015-08-25 04:34:15 -04:00
|
|
|
* get the next argument
|
|
|
|
*
|
2015-10-05 02:15:24 -04:00
|
|
|
* char **outbufref ; buffer to put token into
|
|
|
|
* const char *prompt ; prompt to use if we must be interactive
|
|
|
|
* int size ; size of the buffer
|
|
|
|
* int terminator ; terminating char to be used on interactive fetch
|
2015-08-25 04:34:15 -04:00
|
|
|
*/
|
2015-09-28 22:25:36 -04:00
|
|
|
static int newnextarg( char **outbufref, const char *prompt, int size,
|
|
|
|
int terminator) {
|
|
|
|
int status ;
|
|
|
|
char *buf ;
|
|
|
|
|
|
|
|
/* if we are interactive, go get it! */
|
|
|
|
if( clexec == FALSE) {
|
|
|
|
if( size <= 1) {
|
|
|
|
size = term.t_ncol - strlen( prompt) + 1 ;
|
|
|
|
if( size < 24)
|
|
|
|
size = 24 ;
|
2015-09-28 05:46:00 -04:00
|
|
|
}
|
2015-09-28 22:25:36 -04:00
|
|
|
|
|
|
|
buf = malloc( size) ;
|
|
|
|
if( buf == NULL)
|
|
|
|
status = FALSE ;
|
|
|
|
else {
|
|
|
|
status = getstring( prompt, buf, size, terminator) ;
|
|
|
|
if( TRUE != status) {
|
|
|
|
free( buf) ;
|
|
|
|
buf = NULL ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buf = getnewtokval() ;
|
|
|
|
status = (buf == NULL) ? FALSE : TRUE ;
|
2015-09-28 05:46:00 -04:00
|
|
|
}
|
2015-09-28 22:25:36 -04:00
|
|
|
|
|
|
|
*outbufref = buf ;
|
|
|
|
return status ;
|
2015-09-27 10:13:20 -04:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* macro throw the prompt away, and return the remembered response. This
|
|
|
|
* lets macros run at full speed. The reply is always terminated by a carriage
|
|
|
|
* return. Handle erase, kill, and abort keys.
|
|
|
|
*/
|
|
|
|
|
2015-09-28 22:43:19 -04:00
|
|
|
int newmlarg( char **outbufref, const char *prompt, int size) {
|
|
|
|
return newnextarg( outbufref, prompt, size, nlc) ;
|
|
|
|
}
|
|
|
|
|
2015-09-28 22:25:36 -04:00
|
|
|
int newmlargt( char **outbufref, const char *prompt, int size) {
|
|
|
|
return newnextarg( outbufref, prompt, size, metac) ;
|
2015-09-27 10:13:20 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:37:16 -04:00
|
|
|
/*
|
|
|
|
* ectoc:
|
2013-10-08 22:48:00 -04:00
|
|
|
* expanded character to character
|
|
|
|
* collapse the CONTROL and SPEC flags back into an ascii code
|
2005-09-30 20:37:16 -04:00
|
|
|
*/
|
2019-08-09 08:47:05 -04:00
|
|
|
int ectoc( int c) {
|
|
|
|
if( c & CONTROL)
|
|
|
|
c ^= CONTROL | 0x40 ;
|
|
|
|
|
|
|
|
if( c & SPEC)
|
|
|
|
c &= 255 ;
|
|
|
|
|
|
|
|
return c ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-09-30 20:37:16 -04:00
|
|
|
/*
|
|
|
|
* get a command name from the command line. Command completion means
|
|
|
|
* that pressing a <SPACE> will attempt to complete an unfinished command
|
|
|
|
* name if it is unique.
|
|
|
|
*/
|
2021-07-19 03:39:00 -04:00
|
|
|
const name_bind *getname( void) {
|
2013-10-08 22:48:00 -04:00
|
|
|
int cpos; /* current column on screen output */
|
2021-07-19 03:39:00 -04:00
|
|
|
const name_bind *ffp; /* first ptr to entry in name binding table */
|
|
|
|
const name_bind *cffp; /* current ptr to entry in name binding table */
|
|
|
|
const name_bind *lffp; /* last ptr to entry in name binding table */
|
2013-10-08 22:48:00 -04:00
|
|
|
char buf[NSTRING]; /* buffer to hold tentative command name */
|
|
|
|
|
|
|
|
/* starting at the beginning of the string buffer */
|
|
|
|
cpos = 0;
|
|
|
|
|
|
|
|
/* if we are executing a command line get the next arg and match it */
|
|
|
|
if (clexec) {
|
2015-08-31 23:29:08 -04:00
|
|
|
if( TRUE != gettokval( buf, sizeof buf))
|
2013-10-08 22:48:00 -04:00
|
|
|
return NULL;
|
2021-07-19 03:39:00 -04:00
|
|
|
return fncmatch( buf) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* build a name string from the keyboard */
|
|
|
|
while (TRUE) {
|
2016-03-11 23:58:05 -05:00
|
|
|
int c ;
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
c = tgetc();
|
|
|
|
|
|
|
|
/* if we are at the end, just match it */
|
|
|
|
if (c == 0x0d) {
|
|
|
|
buf[cpos] = 0;
|
|
|
|
|
|
|
|
/* and match it off */
|
2021-07-19 03:39:00 -04:00
|
|
|
return fncmatch( buf) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
} else if (c == ectoc(abortc)) { /* Bell, abort */
|
|
|
|
ctrlg(FALSE, 0);
|
|
|
|
TTflush();
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */
|
|
|
|
if (cpos != 0) {
|
2019-08-07 04:51:00 -04:00
|
|
|
rubout() ;
|
2013-10-08 22:48:00 -04:00
|
|
|
--cpos;
|
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (c == 0x15) { /* C-U, kill */
|
|
|
|
while (cpos != 0) {
|
2019-08-07 04:51:00 -04:00
|
|
|
rubout() ;
|
2013-10-08 22:48:00 -04:00
|
|
|
--cpos;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTflush();
|
|
|
|
|
|
|
|
} else if (c == ' ' || c == 0x1b || c == 0x09) {
|
2005-05-31 11:50:56 -04:00
|
|
|
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
|
2021-07-19 23:24:32 -04:00
|
|
|
/* attempt a completion */
|
|
|
|
buf[ cpos] = 0 ; /* terminate it for us */
|
|
|
|
int buflen = strlen( buf) ;
|
|
|
|
/* scan for matches */
|
|
|
|
for( ffp = names ; ffp->n_func != NULL ; ffp++) {
|
|
|
|
if( strncmp( buf, bind_name( ffp), buflen) == 0) {
|
2013-10-08 22:48:00 -04:00
|
|
|
/* a possible match! More than one? */
|
2021-07-19 23:24:32 -04:00
|
|
|
if( (ffp + 1)->n_func == NULL ||
|
|
|
|
(strncmp( buf, bind_name( ffp + 1), buflen) != 0)) {
|
2013-10-08 22:48:00 -04:00
|
|
|
/* no...we match, print it */
|
2021-07-19 23:24:32 -04:00
|
|
|
echos( &bind_name( ffp)[ cpos]) ;
|
|
|
|
TTflush() ;
|
2021-07-19 03:39:00 -04:00
|
|
|
return ffp ;
|
2013-10-08 22:48:00 -04:00
|
|
|
} else {
|
2005-05-31 11:50:56 -04:00
|
|
|
/* << << << << << << << << << << << << << << << << << */
|
2013-10-08 22:48:00 -04:00
|
|
|
/* try for a partial match against the list */
|
|
|
|
|
2021-07-19 23:24:32 -04:00
|
|
|
/* first scan down until we no longer match the
|
|
|
|
* current input */
|
|
|
|
for( lffp = ffp + 1 ; (lffp + 1)->n_func != NULL ;
|
|
|
|
lffp++)
|
|
|
|
if( strncmp( buf, bind_name( lffp + 1),
|
|
|
|
buflen) != 0)
|
|
|
|
break ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2021-07-19 23:24:32 -04:00
|
|
|
/* and now, attempt to partial complete the string,
|
|
|
|
* one char at a time */
|
2013-10-08 22:48:00 -04:00
|
|
|
while (TRUE) {
|
|
|
|
/* add the next char in */
|
2021-07-19 23:24:32 -04:00
|
|
|
buf[ cpos] = bind_name( ffp)[ cpos] ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* scan through the candidates */
|
2021-07-19 23:24:32 -04:00
|
|
|
for( cffp = ffp + 1 ; cffp <= lffp ; cffp++)
|
|
|
|
if( bind_name( cffp)[ cpos] != buf[ cpos])
|
|
|
|
goto onward ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* add the character */
|
2016-03-11 23:58:05 -05:00
|
|
|
echoc( buf[ cpos++]) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
/* << << << << << << << << << << << << << << << << << */
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no match.....beep and onward */
|
|
|
|
TTbeep();
|
2021-07-19 23:24:32 -04:00
|
|
|
onward:
|
2013-10-08 22:48:00 -04:00
|
|
|
TTflush();
|
2005-05-31 11:50:56 -04:00
|
|
|
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
|
2013-10-08 22:48:00 -04:00
|
|
|
} else {
|
2019-08-09 08:47:05 -04:00
|
|
|
if( cpos < NSTRING - 1 && (islower( c) || c == '-')) {
|
2013-10-08 22:48:00 -04:00
|
|
|
buf[cpos++] = c;
|
2016-03-11 23:58:05 -05:00
|
|
|
echoc( c) ;
|
2019-08-07 04:51:00 -04:00
|
|
|
TTflush();
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* tgetc: Get a key from the terminal driver, resolve any keyboard
|
|
|
|
macro action */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 20:37:16 -04:00
|
|
|
int tgetc(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int c; /* fetched character */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* if we are playing a keyboard macro back, */
|
|
|
|
if (kbdmode == PLAY) {
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* if there is some left... */
|
|
|
|
if (kbdptr < kbdend)
|
|
|
|
return (int) *kbdptr++;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2019-08-12 09:41:51 -04:00
|
|
|
/* at the end of last repetition? */
|
2013-10-08 22:48:00 -04:00
|
|
|
if (--kbdrep < 1) {
|
|
|
|
kbdmode = STOP;
|
|
|
|
#if VISMAC == 0
|
|
|
|
/* force a screen update after all is done */
|
|
|
|
update(FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/* reset the macro to the begining for the next rep */
|
|
|
|
kbdptr = &kbdm[0];
|
|
|
|
return (int) *kbdptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fetch a character from the terminal driver */
|
|
|
|
c = TTgetc();
|
|
|
|
|
|
|
|
/* record it for $lastkey */
|
|
|
|
lastkey = c;
|
|
|
|
|
|
|
|
/* save it if we need to */
|
|
|
|
if (kbdmode == RECORD) {
|
|
|
|
*kbdptr++ = c;
|
|
|
|
kbdend = kbdptr;
|
|
|
|
|
|
|
|
/* don't overrun the buffer */
|
|
|
|
if (kbdptr == &kbdm[NKBDM - 1]) {
|
|
|
|
kbdmode = STOP;
|
|
|
|
TTbeep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and finally give the char back */
|
|
|
|
return c;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2019-08-09 08:47:05 -04:00
|
|
|
/* GET1KEY: Get one keystroke. The only prefixs legal here are the SPEC
|
|
|
|
and CONTROL prefixes. */
|
|
|
|
int get1key( void) {
|
|
|
|
int c ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
|
|
|
/* get a keystroke */
|
|
|
|
c = tgetc();
|
|
|
|
|
2019-08-09 08:47:05 -04:00
|
|
|
if( (c >= 0x00 && c <= 0x1F) || c == 0x7F) /* C0 control -> C- */
|
|
|
|
c ^= CONTROL | 0x40 ;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2019-08-09 08:47:05 -04:00
|
|
|
return c ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* GETCMD: Get a command from the keyboard. Process all applicable
|
2019-08-12 09:41:51 -04:00
|
|
|
prefix keys */
|
|
|
|
|
|
|
|
static int get1unicode( int *k) {
|
|
|
|
/* Accept UTF-8 sequence */
|
|
|
|
int c = *k ;
|
|
|
|
if( c > 0xC1 && c <= 0xF4) {
|
|
|
|
char utf[ 4] ;
|
|
|
|
char cc ;
|
|
|
|
|
|
|
|
utf[ 0] = c ;
|
|
|
|
utf[ 1] = cc = get1key() ;
|
|
|
|
if( (c & 0x20) && ((cc & 0xC0) == 0x80)) { /* at least 3 bytes and a valid encoded char */
|
|
|
|
utf[ 2] = cc = get1key() ;
|
|
|
|
if( (c & 0x10) && ((cc & 0xC0) == 0x80)) /* at least 4 bytes and a valid encoded char */
|
|
|
|
utf[ 3] = get1key() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) k) ;
|
|
|
|
} else
|
|
|
|
return 1 ;
|
|
|
|
}
|
|
|
|
|
2005-09-30 20:37:16 -04:00
|
|
|
int getcmd(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int c; /* fetched keystroke */
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VT220
|
2013-10-08 22:48:00 -04:00
|
|
|
int d; /* second character P.K. */
|
|
|
|
int cmask = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
/* get initial character */
|
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VT220
|
2005-09-30 18:26:09 -04:00
|
|
|
proc_metac:
|
2013-09-14 09:31:42 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == 128+27) /* CSI */
|
|
|
|
goto handle_CSI;
|
|
|
|
/* process META prefix */
|
|
|
|
if (c == (CONTROL | '[')) {
|
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VT220
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == '[' || c == 'O') { /* CSI P.K. */
|
2008-06-07 14:48:44 -04:00
|
|
|
handle_CSI:
|
2013-10-08 22:48:00 -04:00
|
|
|
c = get1key();
|
|
|
|
if (c >= 'A' && c <= 'D')
|
|
|
|
return SPEC | c | cmask;
|
|
|
|
if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c')
|
|
|
|
return SPEC | c | cmask;
|
|
|
|
d = get1key();
|
|
|
|
if (d == '~') /* ESC [ n ~ P.K. */
|
|
|
|
return SPEC | c | cmask;
|
|
|
|
switch (c) { /* ESC [ n n ~ P.K. */
|
|
|
|
case '1':
|
|
|
|
c = d + 32;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
c = d + 48;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
c = d + 64;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
c = '?';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (d != '~') /* eat tilde P.K. */
|
|
|
|
get1key();
|
|
|
|
if (c == 'i') { /* DO key P.K. */
|
|
|
|
c = ctlxc;
|
|
|
|
goto proc_ctlxc;
|
|
|
|
} else if (c == 'c') /* ESC key P.K. */
|
|
|
|
c = get1key();
|
|
|
|
else
|
|
|
|
return SPEC | c | cmask;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if VT220
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == (CONTROL | '[')) {
|
|
|
|
cmask = META;
|
|
|
|
goto proc_metac;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2019-07-25 07:13:40 -04:00
|
|
|
if( islower( c)) /* Force to upper */
|
|
|
|
c = flipcase( c) ;
|
|
|
|
else if( c >= 0x00 && c <= 0x1F) /* control key */
|
2013-10-08 22:48:00 -04:00
|
|
|
c = CONTROL | (c + '@');
|
|
|
|
return META | c;
|
|
|
|
}
|
|
|
|
#if PKCODE
|
|
|
|
else if (c == metac) {
|
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VT220
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == (CONTROL | '[')) {
|
|
|
|
cmask = META;
|
|
|
|
goto proc_metac;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2019-07-25 07:13:40 -04:00
|
|
|
if( islower( c)) /* Force to upper */
|
|
|
|
c = flipcase( c) ;
|
|
|
|
else if( c >= 0x00 && c <= 0x1F) /* control key */
|
2013-10-08 22:48:00 -04:00
|
|
|
c = CONTROL | (c + '@');
|
|
|
|
return META | c;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
#if VT220
|
2005-09-30 18:26:09 -04:00
|
|
|
proc_ctlxc:
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
/* process CTLX prefix */
|
|
|
|
if (c == ctlxc) {
|
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
#if VT220
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == (CONTROL | '[')) {
|
|
|
|
cmask = CTLX;
|
|
|
|
goto proc_metac;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c >= 'a' && c <= 'z') /* Force to upper */
|
|
|
|
c -= 0x20;
|
|
|
|
if (c >= 0x00 && c <= 0x1F) /* control key */
|
|
|
|
c = CONTROL | (c + '@');
|
|
|
|
return CTLX | c;
|
|
|
|
}
|
|
|
|
|
2015-02-13 21:21:50 -05:00
|
|
|
#ifdef CYGWIN
|
2019-08-12 09:41:51 -04:00
|
|
|
get1unicode( &c) ;
|
2015-02-13 21:21:50 -05:00
|
|
|
#endif
|
2015-02-10 04:07:43 -05:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* otherwise, just return it */
|
|
|
|
return c;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* A more generalized prompt/reply function allowing the caller
|
|
|
|
to specify the proper terminator. If the terminator is not
|
|
|
|
a return ('\n') it will echo as "<NL>"
|
2019-08-07 04:51:00 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void echov( int c) {
|
|
|
|
/* verbose echo of a character */
|
|
|
|
if( c == '\n') /* put out <NL> for <ret> */
|
|
|
|
echos( "<NL>") ;
|
|
|
|
else {
|
2019-08-07 22:55:17 -04:00
|
|
|
if( c < ' ' || c == 0x7F) {
|
2019-08-07 04:51:00 -04:00
|
|
|
echoc( '^') ;
|
|
|
|
c ^= 0x40 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
echoc( c) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rubc( char c) {
|
|
|
|
rubout() ;
|
2019-08-12 09:41:51 -04:00
|
|
|
if( (c >= 0 && c < ' ') || c == 0x7F) {
|
2019-08-07 22:55:17 -04:00
|
|
|
/* ^x range */
|
2019-08-07 04:51:00 -04:00
|
|
|
rubout() ;
|
|
|
|
if( c == '\n') {
|
|
|
|
rubout() ;
|
|
|
|
rubout() ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-19 04:10:29 -04:00
|
|
|
int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int cpos; /* current character position in string */
|
|
|
|
int c;
|
2019-08-07 04:51:00 -04:00
|
|
|
boolean quote_f ; /* are we quoting the next char? */
|
|
|
|
int retval ; /* TRUE, FALSE, ABORT */
|
2013-10-08 22:48:00 -04:00
|
|
|
#if COMPLC
|
2019-08-07 04:51:00 -04:00
|
|
|
boolean file_f ;
|
|
|
|
int ocpos, nskip = 0, didtry = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#if MSDOS
|
2013-10-08 22:48:00 -04:00
|
|
|
struct ffblk ffblk;
|
|
|
|
char *fcp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
#if UNIX
|
|
|
|
static char tmp[] = "/tmp/meXXXXXX";
|
|
|
|
FILE *tmpf = NULL;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2016-03-11 23:58:05 -05:00
|
|
|
/* Look for "Find file: ", "View file: ", "Insert file: ", "Write file: ",
|
|
|
|
** "Read file: ", "Execute file: " */
|
2019-08-07 04:51:00 -04:00
|
|
|
file_f = NULL != strstr( prompt, " file: ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
cpos = 0;
|
2019-08-07 04:51:00 -04:00
|
|
|
quote_f = FALSE;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* prompt the user for the input string */
|
2015-02-15 04:32:13 -05:00
|
|
|
mlwrite( "%s", prompt);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
for (;;) {
|
|
|
|
#if COMPLC
|
|
|
|
if (!didtry)
|
|
|
|
nskip = -1;
|
|
|
|
didtry = 0;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2019-08-07 04:51:00 -04:00
|
|
|
/* get a character from the user */
|
2013-10-08 22:48:00 -04:00
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
/* Quoting? Store as it is */
|
|
|
|
if( quote_f == TRUE) {
|
|
|
|
quote_f = FALSE ;
|
|
|
|
if( cpos < nbuf - 1) {
|
|
|
|
c = ectoc( c) ;
|
|
|
|
buf[ cpos++] = c ;
|
|
|
|
echov( c) ;
|
|
|
|
TTflush() ;
|
2015-03-22 10:02:16 -04:00
|
|
|
}
|
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
continue ;
|
|
|
|
}
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
/* If it is a <ret>, change it to a <NL> */
|
|
|
|
if( c == (CONTROL | 'M'))
|
|
|
|
c = CONTROL | 0x40 | '\n' ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
if( c == eolchar) {
|
|
|
|
/* if they hit the line terminator, wrap it up */
|
|
|
|
buf[ cpos] = 0 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
/* clear the message line */
|
|
|
|
mlwrite("");
|
2015-03-22 10:02:16 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
/* if we default the buffer, return FALSE */
|
|
|
|
retval = cpos != 0 ;
|
|
|
|
break ;
|
|
|
|
} else if( c == abortc) {
|
|
|
|
/* Abort the input? */
|
|
|
|
ctrlg( FALSE, 0) ;
|
|
|
|
retval = ABORT ;
|
|
|
|
break ;
|
|
|
|
}
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
/* change from command form back to character form */
|
|
|
|
c = ectoc( c) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
if( c == 0x7F || c == 0x08) {
|
|
|
|
/* rubout/erase */
|
|
|
|
if (cpos != 0) {
|
|
|
|
rubc( buf[ --cpos]) ;
|
2019-08-12 09:41:51 -04:00
|
|
|
cpos -= utf8_revdelta( (unsigned char *) &buf[ cpos], cpos) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
TTflush();
|
|
|
|
}
|
2019-08-07 04:51:00 -04:00
|
|
|
} else if( c == 0x15) {
|
|
|
|
/* C-U, kill */
|
2019-08-12 09:41:51 -04:00
|
|
|
mlwrite( "%s", prompt) ;
|
|
|
|
cpos = 0 ;
|
2013-10-08 22:48:00 -04:00
|
|
|
#if COMPLC
|
2019-08-07 04:51:00 -04:00
|
|
|
} else if( (c == 0x09 || c == ' ') && file_f) {
|
|
|
|
/* TAB, complete file name */
|
2013-10-08 22:48:00 -04:00
|
|
|
char ffbuf[255];
|
|
|
|
#if MSDOS
|
|
|
|
char sffbuf[128];
|
|
|
|
int lsav = -1;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
int n, iswild = 0;
|
|
|
|
|
|
|
|
didtry = 1;
|
|
|
|
ocpos = cpos;
|
2019-08-12 09:41:51 -04:00
|
|
|
mlwrite( "%s", prompt) ;
|
|
|
|
while( cpos != 0) {
|
|
|
|
c = buf[ --cpos] ;
|
|
|
|
if( c == '*' || c == '?') {
|
|
|
|
iswild = 1 ;
|
|
|
|
cpos = 0 ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
if (nskip < 0) {
|
|
|
|
buf[ocpos] = 0;
|
|
|
|
#if UNIX
|
2015-03-22 10:02:16 -04:00
|
|
|
if (tmpf != NULL) {
|
2013-10-08 22:48:00 -04:00
|
|
|
fclose(tmpf);
|
2015-03-22 10:02:16 -04:00
|
|
|
tmpf = NULL ;
|
|
|
|
unlink( tmp) ;
|
|
|
|
}
|
|
|
|
|
2015-07-16 22:44:35 -04:00
|
|
|
strcpy( tmp, "/tmp/meXXXXXX") ;
|
|
|
|
xmkstemp( tmp) ;
|
|
|
|
if( strlen( buf) < sizeof ffbuf - 26 - 1)
|
|
|
|
sprintf( ffbuf, "echo %s%s >%s 2>&1", buf,
|
|
|
|
!iswild ? "*" : "", tmp) ;
|
|
|
|
else
|
|
|
|
sprintf( ffbuf, "echo ERROR >%s 2>&1", tmp) ;
|
|
|
|
|
2015-01-02 01:20:07 -05:00
|
|
|
ue_system( ffbuf) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
tmpf = fopen(tmp, "r");
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
#if MSDOS
|
|
|
|
strcpy(sffbuf, buf);
|
|
|
|
if (!iswild)
|
|
|
|
strcat(sffbuf, "*.*");
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
nskip = 0;
|
|
|
|
}
|
|
|
|
#if UNIX
|
|
|
|
c = ' ';
|
|
|
|
for (n = nskip; n > 0; n--)
|
|
|
|
while ((c = getc(tmpf)) != EOF
|
|
|
|
&& c != ' ');
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
#if MSDOS
|
|
|
|
if (nskip == 0) {
|
|
|
|
strcpy(ffbuf, sffbuf);
|
|
|
|
c = findfirst(ffbuf, &ffblk,
|
|
|
|
FA_DIREC) ? '*' : ' ';
|
|
|
|
} else if (nskip > 0)
|
|
|
|
c = findnext(&ffblk) ? 0 : ' ';
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
nskip++;
|
|
|
|
|
|
|
|
if (c != ' ') {
|
|
|
|
TTbeep();
|
|
|
|
nskip = 0;
|
|
|
|
}
|
|
|
|
#if UNIX
|
|
|
|
while ((c = getc(tmpf)) != EOF && c != '\n'
|
|
|
|
&& c != ' ' && c != '*')
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
#if MSDOS
|
|
|
|
if (c == '*')
|
|
|
|
fcp = sffbuf;
|
|
|
|
else {
|
|
|
|
strncpy(buf, sffbuf, lsav + 1);
|
|
|
|
cpos = lsav + 1;
|
|
|
|
fcp = ffblk.ff_name;
|
|
|
|
}
|
|
|
|
while (c != 0 && (c = *fcp++) != 0 && c != '*')
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
{
|
|
|
|
if (cpos < nbuf - 1)
|
|
|
|
buf[cpos++] = c;
|
|
|
|
}
|
|
|
|
#if UNIX
|
|
|
|
if (c == '*')
|
|
|
|
TTbeep();
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2019-08-12 09:41:51 -04:00
|
|
|
for( n = 0 ; n < cpos ; ) {
|
|
|
|
n += utf8_to_unicode( buf, n, nbuf, (unicode_t *) &c) ;
|
2019-08-07 04:51:00 -04:00
|
|
|
echov( c) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2019-08-07 04:51:00 -04:00
|
|
|
|
|
|
|
TTflush() ;
|
2013-10-08 22:48:00 -04:00
|
|
|
#if UNIX
|
|
|
|
rewind(tmpf);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-08-07 04:51:00 -04:00
|
|
|
} else if( c == 0x11 || c == 0x16)
|
|
|
|
/* ^Q or ^V */
|
|
|
|
quote_f = TRUE ;
|
2019-08-12 09:41:51 -04:00
|
|
|
else {
|
2019-08-07 04:51:00 -04:00
|
|
|
/* store as it is */
|
2019-08-12 09:41:51 -04:00
|
|
|
int n ;
|
|
|
|
|
|
|
|
n = get1unicode( &c) ; /* fetch multiple bytes */
|
|
|
|
if( cpos + n < nbuf) {
|
|
|
|
cpos += unicode_to_utf8( c, &buf[ cpos]) ;
|
2019-08-07 04:51:00 -04:00
|
|
|
echov( c) ;
|
|
|
|
TTflush() ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2019-08-12 09:41:51 -04:00
|
|
|
}
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
2019-08-07 04:51:00 -04:00
|
|
|
|
|
|
|
TTflush() ;
|
|
|
|
if( tmpf != NULL) {
|
|
|
|
fclose( tmpf) ;
|
|
|
|
unlink( tmp) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval ;
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|