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>
|
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-10-05 02:15:24 -04:00
|
|
|
static const int quotec = 0x11 ; /* quote char during getstring() */
|
2013-09-29 09:58:54 -04:00
|
|
|
|
2015-02-13 08:48:05 -05:00
|
|
|
|
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
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
char 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 */
|
2013-10-08 22:48:00 -04:00
|
|
|
c = tgetc();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == ectoc(abortc)) /* Bail out! */
|
|
|
|
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
|
|
|
*/
|
|
|
|
int ectoc(int c)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c & CONTROL)
|
|
|
|
c = c & ~(CONTROL | 0x40);
|
|
|
|
if (c & SPEC)
|
|
|
|
c = 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.
|
|
|
|
*/
|
2005-09-30 20:52:20 -04:00
|
|
|
fn_t getname(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int cpos; /* current column on screen output */
|
|
|
|
struct name_bind *ffp; /* first ptr to entry in name binding table */
|
|
|
|
struct name_bind *cffp; /* current ptr to entry in name binding table */
|
|
|
|
struct name_bind *lffp; /* last ptr to entry in name binding table */
|
|
|
|
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;
|
|
|
|
return fncmatch(&buf[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
return fncmatch(&buf[0]);
|
|
|
|
|
|
|
|
} else if (c == ectoc(abortc)) { /* Bell, abort */
|
|
|
|
ctrlg(FALSE, 0);
|
|
|
|
TTflush();
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */
|
|
|
|
if (cpos != 0) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos( "\b \b") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
--cpos;
|
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (c == 0x15) { /* C-U, kill */
|
|
|
|
while (cpos != 0) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos( "\b \b") ;
|
2013-10-08 22:48:00 -04:00
|
|
|
--cpos;
|
|
|
|
--ttcol;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTflush();
|
|
|
|
|
|
|
|
} else if (c == ' ' || c == 0x1b || c == 0x09) {
|
2005-05-31 11:50:56 -04:00
|
|
|
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
|
2013-10-08 22:48:00 -04:00
|
|
|
/* attempt a completion */
|
|
|
|
buf[cpos] = 0; /* terminate it for us */
|
|
|
|
ffp = &names[0]; /* scan for matches */
|
|
|
|
while (ffp->n_func != NULL) {
|
|
|
|
if (strncmp(buf, ffp->n_name, strlen(buf))
|
|
|
|
== 0) {
|
|
|
|
/* a possible match! More than one? */
|
|
|
|
if ((ffp + 1)->n_func == NULL ||
|
|
|
|
(strncmp
|
|
|
|
(buf, (ffp + 1)->n_name,
|
|
|
|
strlen(buf)) != 0)) {
|
|
|
|
/* no...we match, print it */
|
2016-03-11 23:58:05 -05:00
|
|
|
echos( ffp->n_name + cpos) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
TTflush();
|
|
|
|
return ffp->n_func;
|
|
|
|
} 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 */
|
|
|
|
|
|
|
|
/* first scan down until we no longer match the current input */
|
|
|
|
lffp = (ffp + 1);
|
|
|
|
while ((lffp +
|
|
|
|
1)->n_func !=
|
|
|
|
NULL) {
|
|
|
|
if (strncmp
|
|
|
|
(buf,
|
|
|
|
(lffp +
|
|
|
|
1)->n_name,
|
|
|
|
strlen(buf))
|
|
|
|
!= 0)
|
|
|
|
break;
|
|
|
|
++lffp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and now, attempt to partial complete the string, char at a time */
|
|
|
|
while (TRUE) {
|
|
|
|
/* add the next char in */
|
|
|
|
buf[cpos] =
|
|
|
|
ffp->
|
|
|
|
n_name[cpos];
|
|
|
|
|
|
|
|
/* scan through the candidates */
|
|
|
|
cffp = ffp + 1;
|
|
|
|
while (cffp <=
|
|
|
|
lffp) {
|
|
|
|
if (cffp->
|
|
|
|
n_name
|
|
|
|
[cpos]
|
|
|
|
!=
|
|
|
|
buf
|
|
|
|
[cpos])
|
|
|
|
goto onward;
|
|
|
|
++cffp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
++ffp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no match.....beep and onward */
|
|
|
|
TTbeep();
|
|
|
|
onward:;
|
|
|
|
TTflush();
|
2005-05-31 11:50:56 -04:00
|
|
|
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
|
2013-10-08 22:48:00 -04:00
|
|
|
} else {
|
|
|
|
if (cpos < NSTRING - 1 && c > ' ') {
|
|
|
|
buf[cpos++] = c;
|
2016-03-11 23:58:05 -05:00
|
|
|
echoc( c) ;
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
++ttcol;
|
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* at the end of last repitition? */
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* GET1KEY: Get one keystroke. The only prefixs legal here
|
|
|
|
are the SPEC and CONTROL prefixes.
|
|
|
|
*/
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 20:37:16 -04:00
|
|
|
int get1key(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2013-10-08 22:48:00 -04:00
|
|
|
int c;
|
|
|
|
|
|
|
|
/* get a keystroke */
|
|
|
|
c = tgetc();
|
|
|
|
|
|
|
|
#if MSDOS
|
|
|
|
if (c == 0) { /* Apply SPEC prefix */
|
|
|
|
c = tgetc();
|
|
|
|
if (c >= 0x00 && c <= 0x1F) /* control key? */
|
|
|
|
c = CONTROL | (c + '@');
|
|
|
|
return SPEC | c;
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */
|
|
|
|
c = CONTROL | (c + '@');
|
|
|
|
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
|
|
|
|
prefix keys
|
|
|
|
*/
|
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
|
2015-02-10 05:09:59 -05:00
|
|
|
/* Accept UTF-8 sequence */
|
2015-02-10 04:07:43 -05:00
|
|
|
if( c <= 0xC1 || c > 0xF4)
|
|
|
|
return c ;
|
|
|
|
else {
|
|
|
|
char utf[ 4] ;
|
2015-02-10 05:09:59 -05:00
|
|
|
char cc ;
|
2015-02-10 04:07:43 -05:00
|
|
|
|
|
|
|
utf[ 0] = c ;
|
2015-02-10 05:09:59 -05:00
|
|
|
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() ;
|
2015-02-10 04:07:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
utf8_to_unicode( utf, 0, sizeof utf, (unicode_t *) &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>"
|
|
|
|
*/
|
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;
|
|
|
|
boolean quotef ; /* are we quoting the next char? */
|
|
|
|
#if COMPLC
|
|
|
|
int ffile, 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: " */
|
|
|
|
ffile = NULL != strstr( prompt, " file: ") ;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
cpos = 0;
|
|
|
|
quotef = 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
|
2013-10-08 22:48:00 -04:00
|
|
|
/* get a character from the user */
|
|
|
|
c = get1key();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* If it is a <ret>, change it to a <NL> */
|
|
|
|
#if PKCODE
|
|
|
|
if (c == (CONTROL | 0x4d) && !quotef)
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2013-10-08 22:48:00 -04:00
|
|
|
if (c == (CONTROL | 0x4d))
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
c = CONTROL | 0x40 | '\n';
|
|
|
|
|
|
|
|
/* if they hit the line terminate, wrap it up */
|
|
|
|
if (c == eolchar && quotef == FALSE) {
|
|
|
|
buf[cpos++] = 0;
|
|
|
|
|
|
|
|
/* clear the message line */
|
|
|
|
mlwrite("");
|
|
|
|
TTflush();
|
|
|
|
|
2015-03-22 10:02:16 -04:00
|
|
|
if( tmpf != NULL) {
|
|
|
|
fclose( tmpf) ;
|
|
|
|
unlink( tmp) ;
|
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
/* if we default the buffer, return FALSE */
|
|
|
|
if (buf[0] == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* change from command form back to character form */
|
|
|
|
c = ectoc(c);
|
|
|
|
|
|
|
|
if (c == ectoc(abortc) && quotef == FALSE) {
|
|
|
|
/* Abort the input? */
|
|
|
|
ctrlg(FALSE, 0);
|
|
|
|
TTflush();
|
2015-03-22 10:02:16 -04:00
|
|
|
if( tmpf != NULL) {
|
|
|
|
fclose( tmpf) ;
|
|
|
|
unlink( tmp) ;
|
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
return ABORT;
|
|
|
|
} else if ((c == 0x7F || c == 0x08) && quotef == FALSE) {
|
|
|
|
/* rubout/erase */
|
|
|
|
if (cpos != 0) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
|
|
|
|
if (buf[--cpos] < 0x20) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
}
|
|
|
|
if (buf[cpos] == '\n') {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b\b \b\b");
|
2013-10-08 22:48:00 -04:00
|
|
|
ttcol -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (c == 0x15 && quotef == FALSE) {
|
|
|
|
/* C-U, kill */
|
|
|
|
while (cpos != 0) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
|
|
|
|
if (buf[--cpos] < 0x20) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
}
|
|
|
|
if (buf[cpos] == '\n') {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b\b \b\b");
|
2013-10-08 22:48:00 -04:00
|
|
|
ttcol -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TTflush();
|
|
|
|
|
|
|
|
#if COMPLC
|
|
|
|
} else if ((c == 0x09 || c == ' ') && quotef == FALSE
|
|
|
|
&& ffile) {
|
|
|
|
/* TAB, complete file name */
|
|
|
|
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;
|
|
|
|
while (cpos != 0) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
|
|
|
|
if (buf[--cpos] < 0x20) {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b \b");
|
2013-10-08 22:48:00 -04:00
|
|
|
--ttcol;
|
|
|
|
}
|
|
|
|
if (buf[cpos] == '\n') {
|
2016-03-11 23:58:05 -05:00
|
|
|
echos("\b\b \b\b");
|
2013-10-08 22:48:00 -04:00
|
|
|
ttcol -= 2;
|
|
|
|
}
|
|
|
|
if (buf[cpos] == '*' || buf[cpos] == '?')
|
|
|
|
iswild = 1;
|
|
|
|
#if MSDOS
|
|
|
|
if (lsav < 0 && (buf[cpos] == '\\' ||
|
|
|
|
buf[cpos] == '/' ||
|
|
|
|
buf[cpos] == ':'
|
|
|
|
&& cpos == 1))
|
|
|
|
lsav = cpos;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2013-10-08 22:48:00 -04:00
|
|
|
}
|
|
|
|
TTflush();
|
|
|
|
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
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
for (n = 0; n < cpos; n++) {
|
|
|
|
c = buf[n];
|
|
|
|
if ((c < ' ') && (c != '\n')) {
|
2016-04-08 23:46:40 -04:00
|
|
|
echoc( '^') ;
|
2013-10-08 22:48:00 -04:00
|
|
|
++ttcol;
|
|
|
|
c ^= 0x40;
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:58:05 -05:00
|
|
|
if( c != '\n')
|
|
|
|
echoc( c) ;
|
|
|
|
else { /* put out <NL> for <ret> */
|
|
|
|
echos("<NL>");
|
2013-10-08 22:48:00 -04:00
|
|
|
ttcol += 3;
|
|
|
|
}
|
|
|
|
++ttcol;
|
|
|
|
}
|
|
|
|
TTflush();
|
|
|
|
#if UNIX
|
|
|
|
rewind(tmpf);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-10-08 22:48:00 -04:00
|
|
|
} else if ((c == quotec || c == 0x16) && quotef == FALSE) {
|
|
|
|
quotef = TRUE;
|
|
|
|
} else {
|
|
|
|
quotef = FALSE;
|
|
|
|
if (cpos < nbuf - 1) {
|
|
|
|
buf[cpos++] = c;
|
|
|
|
|
|
|
|
if ((c < ' ') && (c != '\n')) {
|
2016-04-08 23:46:40 -04:00
|
|
|
echoc( '^') ;
|
2013-10-08 22:48:00 -04:00
|
|
|
++ttcol;
|
|
|
|
c ^= 0x40;
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:58:05 -05:00
|
|
|
if( c != '\n')
|
|
|
|
echoc( c) ;
|
|
|
|
else { /* put out <NL> for <ret> */
|
|
|
|
echos("<NL>");
|
2013-10-08 22:48:00 -04:00
|
|
|
ttcol += 3;
|
|
|
|
}
|
|
|
|
++ttcol;
|
|
|
|
TTflush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|