version 1.4, 2000/04/13 06:12:14 |
version 1.5, 2000/09/01 14:59:08 |
|
|
/* |
/* |
* Extended (M-X) commands, rebinding, and |
* Extended (M-X) commands, rebinding, and startup file processing. |
* startup file processing. |
|
*/ |
*/ |
#include "def.h" |
|
#include "kbd.h" |
|
|
|
|
#include "def.h" |
|
#include "kbd.h" |
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
#include "macro.h" |
#include "macro.h" |
#endif |
#endif /* !NO_MACRO */ |
|
|
#ifdef FKEYS |
#ifdef FKEYS |
#include "key.h" |
#include "key.h" |
#ifndef NO_STARTUP |
#ifndef NO_STARTUP |
#ifndef BINDKEY |
#ifndef BINDKEY |
#define BINDKEY /* bindkey is used by FKEYS startup code */ |
#define BINDKEY /* bindkey is used by FKEYS startup code */ |
#endif |
#endif /* !BINDKEY */ |
#endif |
#endif /* !NO_STARTUP */ |
#endif |
#endif /* FKEYS */ |
|
|
static KEYMAP *realocmap __P((KEYMAP *)); |
static int remap __P((KEYMAP *, int, PF, KEYMAP *)); |
static VOID fixmap __P((KEYMAP *, KEYMAP*, KEYMAP*)); |
static KEYMAP *realocmap __P((KEYMAP *)); |
static char *skipwhite __P((char *)); |
static VOID fixmap __P((KEYMAP *, KEYMAP *, KEYMAP *)); |
static char *parsetoken __P((char *)); |
static int dobind __P((KEYMAP *, char *, int)); |
int load __P((char *)); |
static char *skipwhite __P((char *)); |
int excline __P((char *)); |
static char *parsetoken __P((char *)); |
|
static int bindkey __P((KEYMAP **, char *, KCHAR *, int)); |
|
|
/* insert a string, mainly for use from macros (created by selfinsert) */ |
/* |
|
* Insert a string, mainly for use from macros (created by selfinsert) |
|
*/ |
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
insert(f, n) |
insert(f, n) |
int f, n; |
int f, n; |
{ |
{ |
char *cp; |
char *cp; |
char buf[128]; |
char buf[128]; |
#ifndef NO_MACRO |
#ifndef NO_MACRO |
int count; |
int count, c; |
int c; |
|
|
|
if (inmacro) { |
if (inmacro) { |
while (--n >= 0) { |
while (--n >= 0) { |
|
|
return TRUE; |
return TRUE; |
} |
} |
if (n == 1) |
if (n == 1) |
thisflag |= CFINS; /* CFINS means selfinsert can tack on |
/* CFINS means selfinsert can tack on the end */ |
* end */ |
thisflag |= CFINS; |
#endif |
#endif /* !NO_MACRO */ |
if (eread("Insert: ", buf, sizeof(buf), EFNEW) == FALSE) |
if (eread("Insert: ", buf, sizeof(buf), EFNEW) == FALSE) |
return FALSE; |
return FALSE; |
while (--n >= 0) { |
while (--n >= 0) { |
|
|
PF funct; /* function being changed to */ |
PF funct; /* function being changed to */ |
KEYMAP *pref_map; /* if funct==prefix, map to bind to or |
KEYMAP *pref_map; /* if funct==prefix, map to bind to or |
NULL for new */ |
NULL for new */ |
/* extern MAP_ELEMENT *ele; must be set before calling */ |
|
{ |
{ |
int i; |
int i, n1, n2, nold; |
int n1, n2, nold; |
KEYMAP *mp; |
KEYMAP *mp; |
PF *pfp; |
PF *pfp; |
MAP_ELEMENT *mep; |
MAP_ELEMENT *mep; |
|
|
|
if (ele >= &curmap->map_element[curmap->map_num] || c < ele->k_base) { |
if (ele >= &curmap->map_element[curmap->map_num] || c < ele->k_base) { |
if (ele > &curmap->map_element[0] && (funct != prefix || |
if (ele > &curmap->map_element[0] && (funct != prefix || |
(ele - 1)->k_prefmap == NULL)) { |
(ele - 1)->k_prefmap == NULL)) |
n1 = c - (ele - 1)->k_num; |
n1 = c - (ele - 1)->k_num; |
} else |
else |
n1 = HUGE; |
n1 = HUGE; |
if (ele < &curmap->map_element[curmap->map_num] && |
if (ele < &curmap->map_element[curmap->map_num] && |
(funct != prefix || ele->k_prefmap == NULL)) { |
(funct != prefix || ele->k_prefmap == NULL)) |
n2 = ele->k_base - c; |
n2 = ele->k_base - c; |
} else |
else |
n2 = HUGE; |
n2 = HUGE; |
if (n1 <= MAPELEDEF && n1 <= n2) { |
if (n1 <= MAPELEDEF && n1 <= n2) { |
ele--; |
ele--; |
if ((pfp = (PF *) malloc((c - ele->k_base + 1) * |
if ((pfp = (PF *)malloc((c - ele->k_base + 1) * |
sizeof(PF))) == NULL) { |
sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return FALSE; |
|
|
ele->k_num = c; |
ele->k_num = c; |
ele->k_funcp = pfp; |
ele->k_funcp = pfp; |
} else if (n2 <= MAPELEDEF) { |
} else if (n2 <= MAPELEDEF) { |
if ((pfp = (PF *) malloc((ele->k_num - c + 1) |
if ((pfp = (PF *)malloc((ele->k_num - c + 1) * |
* sizeof(PF))) == NULL) { |
sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return FALSE; |
} |
} |
|
|
if (curmap->map_num >= curmap->map_max && |
if (curmap->map_num >= curmap->map_max && |
(curmap = realocmap(curmap)) == NULL) |
(curmap = realocmap(curmap)) == NULL) |
return FALSE; |
return FALSE; |
if ((pfp = (PF *) malloc(sizeof(PF))) == NULL) { |
if ((pfp = (PF *)malloc(sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return FALSE; |
} |
} |
|
|
if (pref_map != NULL) { |
if (pref_map != NULL) { |
ele->k_prefmap = pref_map; |
ele->k_prefmap = pref_map; |
} else { |
} else { |
if (!(mp = (KEYMAP *) malloc(sizeof(KEYMAP) + |
if (!(mp = (KEYMAP *)malloc(sizeof(KEYMAP) + |
(MAPINIT - 1) * sizeof(MAP_ELEMENT)))) { |
(MAPINIT - 1) * sizeof(MAP_ELEMENT)))) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
ele->k_funcp[c - ele->k_base] = |
ele->k_funcp[c - ele->k_base] = |
|
|
n1 = c - ele->k_base; |
n1 = c - ele->k_base; |
if (ele->k_funcp[n1] == funct && (funct != prefix || |
if (ele->k_funcp[n1] == funct && (funct != prefix || |
pref_map == NULL || pref_map == ele->k_prefmap)) |
pref_map == NULL || pref_map == ele->k_prefmap)) |
return TRUE; /* no change */ |
/* no change */ |
|
return TRUE; |
if (funct != prefix || ele->k_prefmap == NULL) { |
if (funct != prefix || ele->k_prefmap == NULL) { |
if (ele->k_funcp[n1] == prefix) |
if (ele->k_funcp[n1] == prefix) |
ele->k_prefmap = (KEYMAP *) NULL; |
ele->k_prefmap = (KEYMAP *) NULL; |
ele->k_funcp[n1] = funct; /* easy case */ |
/* easy case */ |
|
ele->k_funcp[n1] = funct; |
if (funct == prefix) { |
if (funct == prefix) { |
if (pref_map != NULL) |
if (pref_map != NULL) |
ele->k_prefmap = pref_map; |
ele->k_prefmap = pref_map; |
else { |
else { |
if (!(mp = malloc(sizeof(KEYMAP) + |
if (!(mp = malloc(sizeof(KEYMAP) + |
(MAPINIT - 1) * sizeof(MAP_ELEMENT)))) { |
(MAPINIT - 1) * |
|
sizeof(MAP_ELEMENT)))) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
ele->k_funcp[c - ele->k_base] = |
ele->k_funcp[c - ele->k_base] = |
curmap->map_default; |
curmap->map_default; |
|
|
} |
} |
} else { |
} else { |
/* |
/* |
* This case is the splits |
* This case is the splits. |
* determine which side of the break c goes on |
* Determine which side of the break c goes on |
* 0 = after break; 1 = before break |
* 0 = after break; 1 = before break |
*/ |
*/ |
n2 = 1; |
n2 = 1; |
|
|
if (curmap->map_num >= curmap->map_max && |
if (curmap->map_num >= curmap->map_max && |
(curmap = realocmap(curmap)) == NULL) |
(curmap = realocmap(curmap)) == NULL) |
return FALSE; |
return FALSE; |
if (!(pfp = malloc((ele->k_num - c + !n2) * sizeof(PF)))) { |
if ((pfp = malloc((ele->k_num - c + !n2) * |
|
sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return FALSE; |
} |
} |
|
|
*/ |
*/ |
static KEYMAP * |
static KEYMAP * |
realocmap(curmap) |
realocmap(curmap) |
KEYMAP *curmap; |
KEYMAP *curmap; |
{ |
{ |
KEYMAP *mp; |
KEYMAP *mp; |
int i; |
int i; |
extern int nmaps; |
|
|
|
if ((mp = (KEYMAP *) malloc((unsigned) (sizeof(KEYMAP) + |
if ((mp = (KEYMAP *)malloc((unsigned)(sizeof(KEYMAP) + |
(curmap->map_max + (MAPGROW - 1)) * sizeof(MAP_ELEMENT)))) == NULL) { |
(curmap->map_max + (MAPGROW - 1)) * |
|
sizeof(MAP_ELEMENT)))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return NULL; |
return NULL; |
} |
} |
|
|
KEYMAP *curmap; |
KEYMAP *curmap; |
KEYMAP *mp; |
KEYMAP *mp; |
{ |
{ |
int i; |
int i; |
|
|
for (i = mt->map_num; i--;) { |
for (i = mt->map_num; i--;) { |
if (mt->map_element[i].k_prefmap != NULL) { |
if (mt->map_element[i].k_prefmap != NULL) { |
|
|
char *p; |
char *p; |
int unbind; |
int unbind; |
{ |
{ |
PF funct; |
KEYMAP *pref_map = NULL; |
char prompt[80]; |
PF funct; |
char *pep; |
char prompt[80]; |
int c; |
char *pep; |
int s; |
int c, s; |
KEYMAP *pref_map = NULL; |
|
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef) { |
if (macrodef) { |
|
|
for (s = 0; s < maclcur->l_used - 1; s++) { |
for (s = 0; s < maclcur->l_used - 1; s++) { |
if (doscan(curmap, c = CHARMASK(maclcur->l_text[s])) |
if (doscan(curmap, c = CHARMASK(maclcur->l_text[s])) |
!= prefix) { |
!= prefix) { |
if (remap(curmap, c, prefix, (KEYMAP *) NULL) |
if (remap(curmap, c, prefix, (KEYMAP *)NULL) |
!= TRUE) |
!= TRUE) |
return FALSE; |
return FALSE; |
} |
} |
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
} |
} |
(VOID) doscan(curmap, c = maclcur->l_text[s]); |
(VOID)doscan(curmap, c = maclcur->l_text[s]); |
maclcur = maclcur->l_fp; |
maclcur = maclcur->l_fp; |
} else { |
} else { |
#endif |
#endif /* !NO_STARTUP */ |
#endif |
#endif /* !NO_MACRO */ |
(VOID) strcpy(prompt, p); |
(VOID)strcpy(prompt, p); |
pep = prompt + strlen(prompt); |
pep = prompt + strlen(prompt); |
for (;;) { |
for (;;) { |
ewprintf("%s", prompt); |
ewprintf("%s", prompt); |
|
|
} |
} |
#ifndef NO_STARTUP |
#ifndef NO_STARTUP |
} |
} |
#endif |
#endif /* !NO_STARTUP */ |
if (unbind) |
if (unbind) |
funct = rescan; |
funct = rescan; |
else { |
else { |
|
|
} |
} |
|
|
/* |
/* |
* bindkey: bind key sequence to a function in |
* bindkey: bind key sequence to a function in the specified map. Used by |
* the specified map. Used by excline so it can bind function keys. |
* excline so it can bind function keys. To close to release to change |
* To close to release to change calling sequence, should just pass |
* calling sequence, should just pass KEYMAP *curmap rather than |
* KEYMAP *curmap rather than KEYMAP **mapp. |
* KEYMAP **mapp. |
*/ |
*/ |
#ifdef BINDKEY |
#ifdef BINDKEY |
int |
static int |
bindkey(mapp, fname, keys, kcount) |
bindkey(mapp, fname, keys, kcount) |
KEYMAP **mapp; |
KEYMAP **mapp; |
char *fname; |
char *fname; |
KCHAR *keys; |
KCHAR *keys; |
int kcount; |
int kcount; |
{ |
{ |
KEYMAP *curmap = *mapp; |
KEYMAP *curmap = *mapp; |
PF funct; |
KEYMAP *pref_map = NULL; |
int c; |
PF funct; |
KEYMAP *pref_map = NULL; |
int c; |
|
|
if (fname == NULL) |
if (fname == NULL) |
funct = rescan; |
funct = rescan; |
else if (((funct = name_function(fname)) == prefix) ? |
else if (((funct = name_function(fname)) == prefix) ? |
(pref_map = name_map(fname)) == NULL : funct == NULL) { |
(pref_map = name_map(fname)) == NULL : funct == NULL) { |
ewprintf("[No match: %s]", fname); |
ewprintf("[No match: %s]", fname); |
return FALSE; |
return FALSE; |
} |
} |
while (--kcount) { |
while (--kcount) { |
if (doscan(curmap, c = *keys++) != prefix) { |
if (doscan(curmap, c = *keys++) != prefix) { |
if (remap(curmap, c, prefix, (KEYMAP *) NULL) != TRUE) |
if (remap(curmap, c, prefix, (KEYMAP *)NULL) != TRUE) |
return FALSE; |
return FALSE; |
} |
} |
curmap = ele->k_prefmap; |
curmap = ele->k_prefmap; |
} |
} |
(VOID) doscan(curmap, c = *keys); |
(VOID)doscan(curmap, c = *keys); |
return remap(curmap, c, funct, pref_map); |
return remap(curmap, c, funct, pref_map); |
} |
} |
|
|
|
|
char *func; |
char *func; |
char *str; |
char *str; |
{ |
{ |
int i; |
int i; |
|
|
for (i = 0; *str && i < MAXKEY; i++) { |
for (i = 0; *str && i < MAXKEY; i++) { |
/* XXX - convert numbers w/ strol()? */ |
/* XXX - convert numbers w/ strol()? */ |
|
|
key.k_count = i; |
key.k_count = i; |
return (bindkey(&map, func, key.k_chars, key.k_count)); |
return (bindkey(&map, func, key.k_chars, key.k_count)); |
} |
} |
#endif |
#endif /* FKEYS */ |
#endif |
#endif /* BINDKEY */ |
|
|
/* |
/* |
* This function modifies the fundamental keyboard map. |
* This function modifies the fundamental keyboard map. |
|
|
localbind(f, n) |
localbind(f, n) |
int f, n; |
int f, n; |
{ |
{ |
|
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, |
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, "Local set key: ", |
"Local set key: ", FALSE); |
FALSE); |
|
} |
} |
|
|
/* |
/* |
|
|
define_key(f, n) |
define_key(f, n) |
int f, n; |
int f, n; |
{ |
{ |
static char buf[48] = "Define key map: "; |
static char buf[48] = "Define key map: "; |
MAPS *mp; |
MAPS *mp; |
char *strncat(); |
|
|
|
buf[16] = '\0'; |
buf[16] = '\0'; |
if (eread(buf, &buf[16], 48 - 16, EFNEW) != TRUE) |
if (eread(buf, &buf[16], 48 - 16, EFNEW) != TRUE) |
|
|
ewprintf("Unknown map %s", &buf[16]); |
ewprintf("Unknown map %s", &buf[16]); |
return FALSE; |
return FALSE; |
} |
} |
(VOID) strncat(&buf[16], " key: ", 48 - 16 - 1); |
(VOID)strncat(&buf[16], " key: ", 48 - 16 - 1); |
return dobind(mp->p_map, buf, FALSE); |
return dobind(mp->p_map, buf, FALSE); |
} |
} |
|
|
|
|
unbindtokey(f, n) |
unbindtokey(f, n) |
int f, n; |
int f, n; |
{ |
{ |
|
|
return dobind(map_table[0].p_map, "Global unset key: ", TRUE); |
return dobind(map_table[0].p_map, "Global unset key: ", TRUE); |
} |
} |
|
|
|
|
localunbind(f, n) |
localunbind(f, n) |
int f, n; |
int f, n; |
{ |
{ |
|
|
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, |
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, |
"Local unset key: ", TRUE); |
"Local unset key: ", TRUE); |
} |
} |
|
|
/* |
/* |
* Extended command. Call the message line |
* Extended command. Call the message line routine to read in the command |
* routine to read in the command name and apply autocompletion |
* name and apply autocompletion to it. When it comes back, look the name |
* to it. When it comes back, look the name up in the symbol table |
* up in the symbol table and run the command if it is found. Print an |
* and run the command if it is found. |
* error if there is anything wrong. |
* Print an error if there is anything wrong. |
|
*/ |
*/ |
int |
int |
extend(f, n) |
extend(f, n) |
int f, n; |
int f, n; |
{ |
{ |
PF funct; |
PF funct; |
int s; |
int s; |
char xname[NXNAME]; |
char xname[NXNAME]; |
|
|
if (!(f & FFARG)) |
if (!(f & FFARG)) |
s = eread("M-x ", xname, NXNAME, EFNEW | EFFUNC); |
s = eread("M-x ", xname, NXNAME, EFNEW | EFFUNC); |
|
|
if ((funct = name_function(xname)) != NULL) { |
if ((funct = name_function(xname)) != NULL) { |
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef) { |
if (macrodef) { |
LINE *lp = maclcur; |
LINE *lp = maclcur; |
macro[macrocount - 1].m_funct = funct; |
macro[macrocount - 1].m_funct = funct; |
maclcur = lp->l_bp; |
maclcur = lp->l_bp; |
maclcur->l_fp = lp->l_fp; |
maclcur->l_fp = lp->l_fp; |
free((char *) lp); |
free((char *)lp); |
} |
} |
#endif |
#endif /* !NO_MACRO */ |
return (*funct) (f, n); |
return (*funct)(f, n); |
} |
} |
ewprintf("[No match]"); |
ewprintf("[No match]"); |
return FALSE; |
return FALSE; |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
evalexpr(f, n) |
evalexpr(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int s; |
int s; |
char exbuf[128]; |
char exbuf[128]; |
|
|
if ((s = ereply("Eval: ", exbuf, 128)) != TRUE) |
if ((s = ereply("Eval: ", exbuf, 128)) != TRUE) |
return s; |
return s; |
|
|
} |
} |
|
|
/* |
/* |
* evalbuffer - evaluate the current buffer as line commands. Useful |
* evalbuffer - evaluate the current buffer as line commands. Useful for |
* for testing startup files. |
* testing startup files. |
*/ |
*/ |
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
evalbuffer(f, n) |
evalbuffer(f, n) |
int f, n; |
int f, n; |
{ |
{ |
LINE *lp; |
LINE *lp; |
BUFFER *bp = curbp; |
BUFFER *bp = curbp; |
int s; |
int s; |
static char excbuf[128]; |
static char excbuf[128]; |
|
|
for (lp = lforw(bp->b_linep); lp != bp->b_linep; lp = lforw(lp)) { |
for (lp = lforw(bp->b_linep); lp != bp->b_linep; lp = lforw(lp)) { |
if (llength(lp) >= 128) |
if (llength(lp) >= 128) |
return FALSE; |
return FALSE; |
(VOID) strncpy(excbuf, ltext(lp), llength(lp)); |
(VOID)strncpy(excbuf, ltext(lp), llength(lp)); |
excbuf[llength(lp)] = '\0'; /* make sure it's terminated */ |
|
|
/* make sure it's terminated */ |
|
excbuf[llength(lp)] = '\0'; |
if ((s = excline(excbuf)) != TRUE) |
if ((s = excline(excbuf)) != TRUE) |
return s; |
return s; |
} |
} |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
evalfile(f, n) |
evalfile(f, n) |
int f, n; |
int f, n; |
{ |
{ |
int s; |
int s; |
char fname[NFILEN]; |
char fname[NFILEN]; |
|
|
if ((s = ereply("Load file: ", fname, NFILEN)) != TRUE) |
if ((s = ereply("Load file: ", fname, NFILEN)) != TRUE) |
return s; |
return s; |
|
|
*/ |
*/ |
int |
int |
load(fname) |
load(fname) |
char *fname; |
char *fname; |
{ |
{ |
int s = TRUE; |
int s = TRUE; |
int nbytes; |
int nbytes; |
char excbuf[128]; |
char excbuf[128]; |
|
|
if ((fname = adjustname(fname)) == NULL) |
if ((fname = adjustname(fname)) == NULL) |
return FALSE; /* just to be careful */ |
/* just to be careful */ |
|
return FALSE; |
|
|
if (ffropen(fname, (BUFFER *) NULL) != FIOSUC) |
if (ffropen(fname, (BUFFER *)NULL) != FIOSUC) |
return FALSE; |
return FALSE; |
|
|
while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { |
while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { |
excbuf[nbytes] = '\0'; |
excbuf[nbytes] = '\0'; |
if (excline(excbuf) != TRUE) { |
if (excline(excbuf) != TRUE) { |
|
|
break; |
break; |
} |
} |
} |
} |
(VOID) ffclose((BUFFER *) NULL); |
(VOID)ffclose((BUFFER *)NULL); |
excbuf[nbytes] = '\0'; |
excbuf[nbytes] = '\0'; |
if (s != FIOEOF || (nbytes && excline(excbuf) != TRUE)) |
if (s != FIOEOF || (nbytes && excline(excbuf) != TRUE)) |
return FALSE; |
return FALSE; |
|
|
} |
} |
|
|
/* |
/* |
* excline - run a line from a load file or eval-expression. |
* excline - run a line from a load file or eval-expression. if FKEYS is |
* if FKEYS is defined, duplicate functionallity of dobind so function |
* defined, duplicate functionallity of dobind so function key values don't |
* key values don't have to fit in type char. |
* have to fit in type char. |
*/ |
*/ |
int |
int |
excline(line) |
excline(line) |
char *line; |
char *line; |
{ |
{ |
char *funcp, *argp = NULL; |
PF fp; |
int c; |
LINE *lp, *np; |
int status; |
int status, c, f, n; |
int f, n; |
char *funcp; |
LINE *lp, *np; |
char *argp = NULL; |
PF fp; |
|
#ifdef FKEYS |
#ifdef FKEYS |
int bind; |
int bind; |
KEYMAP *curmap; |
KEYMAP *curmap; |
MAPS *mp; |
MAPS *mp; |
#define BINDARG 0 /* this arg is key to bind (local/global set |
#define BINDARG 0 /* this arg is key to bind (local/global set key) */ |
* key) */ |
#define BINDNO 1 /* not binding or non-quoted BINDARG */ |
#define BINDNO 1 /* not binding or non-quoted BINDARG */ |
#define BINDNEXT 2 /* next arg " (define-key) */ |
#define BINDNEXT 2 /* next arg " (define-key) */ |
#define BINDDO 3 /* already found key to bind */ |
#define BINDDO 3 /* already found key to bind */ |
#define BINDEXT 1 /* space for trailing \0 */ |
#define BINDEXT 1 /* space for trailing \0 */ |
#else /* FKEYS */ |
#else |
#define BINDEXT 0 |
#define BINDEXT 0 |
#endif /* FKEYS */ |
#endif |
|
|
|
|
lp = NULL; |
|
|
if (macrodef || inmacro) { |
if (macrodef || inmacro) { |
ewprintf("Not now!"); |
ewprintf("Not now!"); |
return FALSE; |
return FALSE; |
|
|
bind = BINDNEXT; |
bind = BINDNEXT; |
else |
else |
bind = BINDNO; |
bind = BINDNO; |
#endif |
#endif /* FKEYS */ |
/* Pack away all the args now... */ |
/* Pack away all the args now... */ |
if ((np = lalloc(0)) == FALSE) |
if ((np = lalloc(0)) == FALSE) |
return FALSE; |
return FALSE; |
np->l_fp = np->l_bp = maclcur = np; |
np->l_fp = np->l_bp = maclcur = np; |
|
|
status = FALSE; |
status = FALSE; |
goto cleanup; |
goto cleanup; |
} |
} |
bcopy(argp, ltext(lp), (int) (line - argp)); |
bcopy(argp, ltext(lp), (int)(line - argp)); |
#ifdef FKEYS |
#ifdef FKEYS |
lp->l_used--; /* don't count BINDEXT! */ |
/* don't count BINDEXT */ |
|
lp->l_used--; |
if (bind == BINDARG) |
if (bind == BINDARG) |
bind = BINDNO; |
bind = BINDNO; |
#endif |
#endif /* FKEYS */ |
} else { /* Quoted strings special */ |
} else { |
|
/* quoted strings are special */ |
++argp; |
++argp; |
#ifdef FKEYS |
#ifdef FKEYS |
if (bind != BINDARG) { |
if (bind != BINDARG) { |
#endif |
#endif /* FKEYS */ |
lp = lalloc((int) (line - argp) + BINDEXT); |
lp = lalloc((int)(line - argp) + BINDEXT); |
if (lp == NULL) { |
if (lp == NULL) { |
status = FALSE; |
status = FALSE; |
goto cleanup; |
goto cleanup; |
|
|
} else { |
} else { |
key.k_count = 0; |
key.k_count = 0; |
} |
} |
#endif |
#endif /* FKEYS */ |
while (*argp != '"' && *argp != '\0') { |
while (*argp != '"' && *argp != '\0') { |
if (*argp != '\\') |
if (*argp != '\\') |
c = *argp++; |
c = *argp++; |
|
|
case '6': |
case '6': |
case '7': |
case '7': |
c = *argp - '0'; |
c = *argp - '0'; |
if (argp[1] <= '7' && argp[1] >= '0') { |
if (argp[1] <= '7' && |
|
argp[1] >= '0') { |
c <<= 3; |
c <<= 3; |
c += *++argp - '0'; |
c += *++argp - '0'; |
if (argp[1] <= '7' && |
if (argp[1] <= '7' && |
|
|
} |
} |
c += KFIRST; |
c += KFIRST; |
break; |
break; |
#endif |
#endif /* FKEYS */ |
default: |
default: |
c = CHARMASK(*argp); |
c = CHARMASK(*argp); |
break; |
break; |
|
|
if (bind == BINDARG) |
if (bind == BINDARG) |
key.k_chars[key.k_count++] = c; |
key.k_chars[key.k_count++] = c; |
else |
else |
#endif |
#endif /* FKEYS */ |
lp->l_text[lp->l_used++] = c; |
lp->l_text[lp->l_used++] = c; |
} |
} |
if (*line) |
if (*line) |
|
|
if ((mp = name_mode(lp->l_text)) == NULL) { |
if ((mp = name_mode(lp->l_text)) == NULL) { |
ewprintf("No such mode: %s", lp->l_text); |
ewprintf("No such mode: %s", lp->l_text); |
status = FALSE; |
status = FALSE; |
free((char *) lp); |
free((char *)lp); |
goto cleanup; |
goto cleanup; |
} |
} |
curmap = mp->p_map; |
curmap = mp->p_map; |
free((char *) lp); |
free((char *)lp); |
bind = BINDARG; |
bind = BINDARG; |
break; |
break; |
default: |
default: |
#endif |
#endif /* FKEYS */ |
lp->l_fp = np->l_fp; |
lp->l_fp = np->l_fp; |
lp->l_bp = np; |
lp->l_bp = np; |
np->l_fp = lp; |
np->l_fp = lp; |
np = lp; |
np = lp; |
#ifdef FKEYS |
#ifdef FKEYS |
} |
} |
#endif |
#endif /* FKEYS */ |
} |
} |
#ifdef FKEYS |
#ifdef FKEYS |
switch (bind) { |
switch (bind) { |
|
|
status = bindkey(&curmap, lp->l_text, key.k_chars, |
status = bindkey(&curmap, lp->l_text, key.k_chars, |
key.k_count); |
key.k_count); |
} else |
} else |
status = bindkey(&curmap, (char *) NULL, key.k_chars, |
status = bindkey(&curmap, (char *)NULL, key.k_chars, |
key.k_count); |
key.k_count); |
break; |
break; |
case BINDNO: |
case BINDNO: |
#endif |
#endif /* FKEYS */ |
inmacro = TRUE; |
inmacro = TRUE; |
maclcur = maclcur->l_fp; |
maclcur = maclcur->l_fp; |
status = (*fp) (f, n); |
status = (*fp)(f, n); |
inmacro = FALSE; |
inmacro = FALSE; |
#ifdef FKEYS |
#ifdef FKEYS |
} |
} |
#endif |
#endif /* FKEYS */ |
cleanup: |
cleanup: |
lp = maclcur->l_fp; |
lp = maclcur->l_fp; |
while (lp != maclcur) { |
while (lp != maclcur) { |
np = lp->l_fp; |
np = lp->l_fp; |
free((char *) lp); |
free((char *)lp); |
lp = np; |
lp = np; |
} |
} |
free((char *) lp); |
free((char *)lp); |
return status; |
return status; |
} |
} |
|
|
|
|
*/ |
*/ |
static char * |
static char * |
skipwhite(s) |
skipwhite(s) |
char *s; |
char *s; |
{ |
{ |
|
|
while (*s == ' ' || *s == '\t' || *s == ')' || *s == '(') |
while (*s == ' ' || *s == '\t' || *s == ')' || *s == '(') |
s++; |
s++; |
if (*s == ';') |
if (*s == ';') |
|
|
parsetoken(s) |
parsetoken(s) |
char *s; |
char *s; |
{ |
{ |
|
|
if (*s != '"') { |
if (*s != '"') { |
while (*s && *s != ' ' && *s != '\t' && *s != ')' && *s != '(') |
while (*s && *s != ' ' && *s != '\t' && *s != ')' && *s != '(') |
s++; |
s++; |
if (*s == ';') |
if (*s == ';') |
*s = '\0'; |
*s = '\0'; |
} else |
} else |
do { /* Strings get special treatment */ |
do { |
/* Beware: You can \ out the end of the string! */ |
/* |
|
* Strings get special treatment. |
|
* Beware: You can \ out the end of the string! |
|
*/ |
if (*s == '\\') |
if (*s == '\\') |
++s; |
++s; |
} while (*++s != '"' && *s != '\0'); |
} while (*++s != '"' && *s != '\0'); |
return s; |
return s; |
} |
} |
#endif |
#endif /* !NO_STARTUP */ |