version 1.2, 2000/04/13 06:12:15 |
version 1.3, 2000/09/01 14:59:08 |
|
|
/* |
/* |
* Terminal independent keyboard handling. |
* Terminal independent keyboard handling. |
*/ |
*/ |
#include "def.h" |
|
#include "kbd.h" |
|
|
|
#define EXTERN |
#define EXTERN |
#include "key.h" |
|
|
|
|
#include "def.h" |
|
#include "kbd.h" |
|
#include "key.h" |
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
#include "macro.h" |
#include "macro.h" |
#endif |
#endif /* !NO_MACRO */ |
|
|
#ifdef DO_METAKEY |
#ifdef DO_METAKEY |
#ifndef METABIT |
#ifndef METABIT |
#define METABIT 0x80 |
#define METABIT 0x80 |
#endif |
#endif /* !METABIT */ |
|
|
int use_metakey = TRUE; |
#ifndef NO_DPROMPT |
|
#define PROMPTL 80 |
|
char prompt[PROMPTL], *promptp; |
|
#endif /* !NO_DPROMPT */ |
|
|
|
static int use_metakey = TRUE; |
|
static int pushed = FALSE; |
|
static int pushedc; |
|
|
|
MAP_ELEMENT *ele; |
|
|
/* |
/* |
* Toggle the value of use_metakey |
* Toggle the value of use_metakey |
*/ |
*/ |
|
|
do_meta(f, n) |
do_meta(f, n) |
int f, n; |
int f, n; |
{ |
{ |
|
|
if (f & FFARG) |
if (f & FFARG) |
use_metakey = n > 0; |
use_metakey = n > 0; |
else |
else |
|
|
ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis"); |
ewprintf("Meta keys %sabled", use_metakey ? "en" : "dis"); |
return TRUE; |
return TRUE; |
} |
} |
#endif |
#endif /* DO_METAKEY */ |
|
|
#ifdef BSMAP |
#ifdef BSMAP |
static int bs_map = BSMAP; |
static int bs_map = BSMAP; |
/* |
/* |
* Toggle backspace mapping |
* Toggle backspace mapping |
*/ |
*/ |
|
|
bsmap(f, n) |
bsmap(f, n) |
int f, n; |
int f, n; |
{ |
{ |
|
|
if (f & FFARG) |
if (f & FFARG) |
bs_map = n > 0; |
bs_map = n > 0; |
else |
else |
|
|
ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis"); |
ewprintf("Backspace mapping %sabled", bs_map ? "en" : "dis"); |
return TRUE; |
return TRUE; |
} |
} |
#endif |
#endif /* BSMAP */ |
|
|
#ifndef NO_DPROMPT |
|
#define PROMPTL 80 |
|
char prompt[PROMPTL], *promptp; |
|
#endif |
|
|
|
static int pushed = FALSE; |
|
static int pushedc; |
|
|
|
VOID |
VOID |
ungetkey(c) |
ungetkey(c) |
int c; |
int c; |
{ |
{ |
|
#ifdef DO_METAKEY |
#ifdef DO_METAKEY |
|
if (use_metakey && pushed && c == CCHR('[')) |
if (use_metakey && pushed && c == CCHR('[')) |
pushedc |= METABIT; |
pushedc |= METABIT; |
else |
else |
#endif |
#endif /* DO_METAKEY */ |
pushedc = c; |
pushedc = c; |
pushed = TRUE; |
pushed = TRUE; |
} |
} |
|
|
int |
int |
getkey(flag) |
getkey(flag) |
int flag; |
int flag; |
{ |
{ |
int c; |
int c; |
|
|
#ifndef NO_DPROMPT |
#ifndef NO_DPROMPT |
if (flag && !pushed) { |
if (flag && !pushed) { |
if (prompt[0] != '\0' && ttwait()) { |
if (prompt[0] != '\0' && ttwait()) { |
ewprintf("%s", prompt); /* avoid problems with % */ |
/* avoid problems with % */ |
update(); /* put the cursor back */ |
ewprintf("%s", prompt); |
|
/* put the cursor back */ |
|
update(); |
epresf = KPROMPT; |
epresf = KPROMPT; |
} |
} |
if (promptp > prompt) |
if (promptp > prompt) |
*(promptp - 1) = ' '; |
*(promptp - 1) = ' '; |
} |
} |
#endif |
#endif /* !NO_DPROMPT */ |
if (pushed) { |
if (pushed) { |
c = pushedc; |
c = pushedc; |
pushed = FALSE; |
pushed = FALSE; |
} else |
} else |
c = getkbd(); |
c = getkbd(); |
#ifdef BSMAP |
#ifdef BSMAP |
if (bs_map) |
if (bs_map) |
if (c == CCHR('H')) |
if (c == CCHR('H')) |
c = CCHR('?'); |
c = CCHR('?'); |
else if (c == CCHR('?')) |
else if (c == CCHR('?')) |
c = CCHR('H'); |
c = CCHR('H'); |
#endif |
#endif /* BSMAP */ |
#ifdef DO_METAKEY |
#ifdef DO_METAKEY |
if (use_metakey && (c & METABIT)) { |
if (use_metakey && (c & METABIT)) { |
pushedc = c & ~METABIT; |
pushedc = c & ~METABIT; |
pushed = TRUE; |
pushed = TRUE; |
c = CCHR('['); |
c = CCHR('['); |
} |
} |
#endif |
#endif /* DO_METAKEY */ |
#ifndef NO_DPROMPT |
#ifndef NO_DPROMPT |
if (flag && promptp < &prompt[PROMPTL - 5]) { |
if (flag && promptp < &prompt[PROMPTL - 5]) { |
promptp = keyname(promptp, c); |
promptp = keyname(promptp, c); |
*promptp++ = '-'; |
*promptp++ = '-'; |
*promptp = '\0'; |
*promptp = '\0'; |
} |
} |
#endif |
#endif /* !NO_DPROMPT */ |
return c; |
return c; |
} |
} |
|
|
|
|
* to the function associated with that character. Sets ele to the |
* to the function associated with that character. Sets ele to the |
* keymap element the keyboard was found in as a side effect. |
* keymap element the keyboard was found in as a side effect. |
*/ |
*/ |
|
|
MAP_ELEMENT *ele; |
|
|
|
PF |
PF |
doscan(map, c) |
doscan(map, c) |
KEYMAP *map; |
KEYMAP *map; |
int c; |
int c; |
{ |
{ |
MAP_ELEMENT *elec = &map->map_element[0]; |
MAP_ELEMENT *elec = &map->map_element[0]; |
MAP_ELEMENT *last = &map->map_element[map->map_num]; |
MAP_ELEMENT *last = &map->map_element[map->map_num]; |
|
|
while (elec < last && c > elec->k_num) |
while (elec < last && c > elec->k_num) |
elec++; |
elec++; |
ele = elec; /* used by prefix and binding code */ |
|
|
/* used by prefix and binding code */ |
|
ele = elec; |
if (elec >= last || c < elec->k_base) |
if (elec >= last || c < elec->k_base) |
return map->map_default; |
return map->map_default; |
return elec->k_funcp[c - elec->k_base]; |
return elec->k_funcp[c - elec->k_base]; |
|
|
int |
int |
doin() |
doin() |
{ |
{ |
KEYMAP *curmap; |
KEYMAP *curmap; |
PF funct; |
PF funct; |
|
|
#ifndef NO_DPROMPT |
#ifndef NO_DPROMPT |
*(promptp = prompt) = '\0'; |
*(promptp = prompt) = '\0'; |
#endif |
#endif /* !NO_DPROMPT */ |
curmap = curbp->b_modes[curbp->b_nmodes]->p_map; |
curmap = curbp->b_modes[curbp->b_nmodes]->p_map; |
key.k_count = 0; |
key.k_count = 0; |
while ((funct = doscan(curmap, (key.k_chars[key.k_count++] = |
while ((funct = doscan(curmap, (key.k_chars[key.k_count++] = |
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef && macrocount < MAXMACRO) |
if (macrodef && macrocount < MAXMACRO) |
macro[macrocount++].m_funct = funct; |
macro[macrocount++].m_funct = funct; |
#endif |
#endif /* !NO_MACRO */ |
return (*funct) (0, 1); |
return (*funct)(0, 1); |
} |
} |
|
|
int |
int |
rescan(f, n) |
rescan(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int c; |
int c; |
KEYMAP *curmap; |
KEYMAP *curmap; |
int i; |
int i; |
PF fp; |
PF fp = NULL; |
int mode = curbp->b_nmodes; |
int mode = curbp->b_nmodes; |
|
|
for (;;) { |
for (;;) { |
if (ISUPPER(key.k_chars[key.k_count - 1])) { |
if (ISUPPER(key.k_chars[key.k_count - 1])) { |
c = TOLOWER(key.k_chars[key.k_count - 1]); |
c = TOLOWER(key.k_chars[key.k_count - 1]); |
curmap = curbp->b_modes[mode]->p_map; |
curmap = curbp->b_modes[mode]->p_map; |
for (i = 0; i < key.k_count - 1; i++) { |
for (i = 0; i < key.k_count - 1; i++) { |
if ((fp = doscan(curmap, (key.k_chars[i]))) != prefix) |
if ((fp = doscan(curmap, (key.k_chars[i]))) |
|
!= prefix) |
break; |
break; |
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
} |
} |
|
|
if ((fp = doscan(curmap, c)) == prefix) |
if ((fp = doscan(curmap, c)) == prefix) |
while ((fp = doscan(curmap, |
while ((fp = doscan(curmap, |
key.k_chars[key.k_count++] = |
key.k_chars[key.k_count++] = |
getkey(TRUE))) == prefix) |
getkey(TRUE))) == prefix) |
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
if (fp != rescan) { |
if (fp != rescan) { |
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef && macrocount <= MAXMACRO) |
if (macrodef && macrocount <= MAXMACRO) |
macro[macrocount - 1].m_funct = fp; |
macro[macrocount - 1].m_funct |
#endif |
= fp; |
return (*fp) (f, n); |
#endif /* !NO_MACRO */ |
|
return (*fp)(f, n); |
} |
} |
} |
} |
} |
} |
|
|
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
} |
} |
if (fp == prefix) { |
if (fp == prefix) { |
while ((fp = doscan(curmap, key.k_chars[i++] = getkey(TRUE))) |
while ((fp = doscan(curmap, key.k_chars[i++] = |
== prefix) |
getkey(TRUE))) == prefix) |
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
key.k_count = i; |
key.k_count = i; |
} |
} |
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef && macrocount <= MAXMACRO) |
if (macrodef && macrocount <= MAXMACRO) |
macro[macrocount - 1].m_funct = fp; |
macro[macrocount - 1].m_funct = fp; |
#endif |
#endif /* !NO_MACRO */ |
return (*fp) (f, n); |
return (*fp)(f, n); |
} |
} |
} |
} |
} |
} |
|
|
int |
int |
universal_argument(f, n) |
universal_argument(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int c, nn = 4; |
KEYMAP *curmap; |
KEYMAP *curmap; |
PF funct; |
PF funct; |
int c; |
|
int nn = 4; |
|
|
if (f & FFUNIV) |
if (f & FFUNIV) |
nn *= n; |
nn *= n; |
|
|
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_funct = funct; |
macro[macrocount++].m_funct = funct; |
} |
} |
#endif |
#endif /* !NO_MACRO */ |
return (*funct) (FFUNIV, nn); |
return (*funct)(FFUNIV, nn); |
} |
} |
nn <<= 2; |
nn <<= 2; |
} |
} |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
digit_argument(f, n) |
digit_argument(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int nn, c; |
KEYMAP *curmap; |
KEYMAP *curmap; |
PF funct; |
PF funct; |
int nn, c; |
|
|
nn = key.k_chars[key.k_count - 1] - '0'; |
nn = key.k_chars[key.k_count - 1] - '0'; |
for (;;) { |
for (;;) { |
|
|
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_funct = funct; |
macro[macrocount++].m_funct = funct; |
} |
} |
#endif |
#endif /* !NO_MACRO */ |
return (*funct) (FFOTHARG, nn); |
return (*funct)(FFOTHARG, nn); |
} |
} |
|
|
int |
int |
negative_argument(f, n) |
negative_argument(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int nn = 0, c; |
KEYMAP *curmap; |
KEYMAP *curmap; |
PF funct; |
PF funct; |
int c; |
|
int nn = 0; |
|
|
for (;;) { |
for (;;) { |
c = getkey(TRUE); |
c = getkey(TRUE); |
|
|
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_count = nn; |
macro[macrocount++].m_funct = funct; |
macro[macrocount++].m_funct = funct; |
} |
} |
#endif |
#endif /* !NO_MACRO */ |
return (*funct) (FFNEGARG, nn); |
return (*funct)(FFNEGARG, nn); |
} |
} |
|
|
/* |
/* |
|
|
*/ |
*/ |
int |
int |
selfinsert(f, n) |
selfinsert(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int c; |
|
int count; |
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
LINE *lp; |
LINE *lp; |
#endif |
#endif /* !NO_MACRO */ |
|
int c; |
|
int count; |
|
|
if (n < 0) |
if (n < 0) |
return FALSE; |
return FALSE; |
|
|
if (macrodef && macrocount < MAXMACRO) { |
if (macrodef && macrocount < MAXMACRO) { |
if (f & FFARG) |
if (f & FFARG) |
macrocount -= 2; |
macrocount -= 2; |
if (lastflag & CFINS) { /* last command was insert -- tack on |
|
* end */ |
/* last command was insert -- tack on the end */ |
|
if (lastflag & CFINS) { |
macrocount--; |
macrocount--; |
if (maclcur->l_size < maclcur->l_used + n) { |
if (maclcur->l_size < maclcur->l_used + n) { |
if ((lp = lallocx(maclcur->l_used + n)) == NULL) |
if ((lp = lallocx(maclcur->l_used + n)) == NULL) |
|
|
lp->l_fp = maclcur->l_fp; |
lp->l_fp = maclcur->l_fp; |
lp->l_bp = maclcur->l_bp; |
lp->l_bp = maclcur->l_bp; |
lp->l_fp->l_bp = lp->l_bp->l_fp = lp; |
lp->l_fp->l_bp = lp->l_bp->l_fp = lp; |
bcopy(maclcur->l_text, lp->l_text, maclcur->l_used); |
bcopy(maclcur->l_text, lp->l_text, |
for (count = maclcur->l_used; count < lp->l_used; count++) |
maclcur->l_used); |
|
for (count = maclcur->l_used; |
|
count < lp->l_used; count++) |
lp->l_text[count] = c; |
lp->l_text[count] = c; |
free((char *) maclcur); |
free((char *)maclcur); |
maclcur = lp; |
maclcur = lp; |
} else { |
} else { |
maclcur->l_used += n; |
maclcur->l_used += n; |
|
|
} |
} |
thisflag |= CFINS; |
thisflag |= CFINS; |
} |
} |
#endif |
#endif /* !NO_MACRO */ |
if (c == '\n') { |
if (c == '\n') { |
do { |
do { |
count = lnewline(); |
count = lnewline(); |
} while (--n && count == TRUE); |
} while (--n && count == TRUE); |
return count; |
return count; |
} |
} |
if (curbp->b_flag & BFOVERWRITE) { /* Overwrite mode */ |
|
|
/* overwrite mode */ |
|
if (curbp->b_flag & BFOVERWRITE) { |
lchange(WFEDIT); |
lchange(WFEDIT); |
while (curwp->w_doto < llength(curwp->w_dotp) && n--) |
while (curwp->w_doto < llength(curwp->w_dotp) && n--) |
lputc(curwp->w_dotp, curwp->w_doto++, c); |
lputc(curwp->w_dotp, curwp->w_doto++, c); |
|
|
} |
} |
|
|
/* |
/* |
* This could be implemented as a keymap with everthing defined |
* This could be implemented as a keymap with everthing defined as self-insert. |
* as self-insert. |
|
*/ |
*/ |
int |
int |
quote(f, n) |
quote(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int c; |
int c; |
|
|
key.k_count = 1; |
key.k_count = 1; |
if ((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') { |
if ((key.k_chars[0] = getkey(TRUE)) >= '0' && key.k_chars[0] <= '7') { |