version 1.32, 2005/03/10 16:58:57 |
version 1.33, 2005/04/03 02:09:28 |
|
|
static int bindkey(KEYMAP **, const char *, KCHAR *, int); |
static int bindkey(KEYMAP **, const 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 |
|
|
for (count = 0; count < maclcur->l_used; count++) { |
for (count = 0; count < maclcur->l_used; count++) { |
if ((((c = maclcur->l_text[count]) == '\n') |
if ((((c = maclcur->l_text[count]) == '\n') |
? lnewline() : linsert(1, c)) != TRUE) |
? lnewline() : linsert(1, c)) != TRUE) |
return FALSE; |
return (FALSE); |
} |
} |
} |
} |
maclcur = maclcur->l_fp; |
maclcur = maclcur->l_fp; |
return TRUE; |
return (TRUE); |
} |
} |
if (n == 1) |
if (n == 1) |
/* CFINS means selfinsert can tack on the end */ |
/* CFINS means selfinsert can tack on the end */ |
thisflag |= CFINS; |
thisflag |= CFINS; |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
if ((bufp = eread("Insert: ", buf, sizeof(buf), EFNEW)) == NULL) |
if ((bufp = eread("Insert: ", buf, sizeof(buf), EFNEW)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
while (--n >= 0) { |
while (--n >= 0) { |
cp = buf; |
cp = buf; |
while (*cp) { |
while (*cp) { |
if (((*cp == '\n') ? lnewline() : linsert(1, *cp)) |
if (((*cp == '\n') ? lnewline() : linsert(1, *cp)) |
!= TRUE) |
!= TRUE) |
return FALSE; |
return (FALSE); |
cp++; |
cp++; |
} |
} |
} |
} |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
* Bind a key to a function. Cases range from the trivial (replacing an |
* Bind a key to a function. Cases range from the trivial (replacing an |
* existing binding) to the extremly complex (creating a new prefix in a |
* existing binding) to the extremely complex (creating a new prefix in a |
* map_element that already has one, so the map_element must be split, |
* map_element that already has one, so the map_element must be split, |
* but the keymap doesn't have enough room for another map_element, so |
* but the keymap doesn't have enough room for another map_element, so |
* the keymap is reallocated). No attempt is made to reclaim space no |
* the keymap is reallocated). No attempt is made to reclaim space no |
|
|
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); |
} |
} |
nold = ele->k_num - ele->k_base + 1; |
nold = ele->k_num - ele->k_base + 1; |
for (i = 0; i < nold; i++) |
for (i = 0; i < nold; i++) |
|
|
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); |
} |
} |
nold = ele->k_num - ele->k_base + 1; |
nold = ele->k_num - ele->k_base + 1; |
for (i = 0; i < nold; i++) |
for (i = 0; i < nold; i++) |
|
|
} else { |
} else { |
if (curmap->map_num >= curmap->map_max) { |
if (curmap->map_num >= curmap->map_max) { |
if ((newmap = reallocmap(curmap)) == NULL) |
if ((newmap = reallocmap(curmap)) == NULL) |
return FALSE; |
return (FALSE); |
curmap = newmap; |
curmap = newmap; |
} |
} |
if ((pfp = malloc(sizeof(PF))) == NULL) { |
if ((pfp = malloc(sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return (FALSE); |
} |
} |
pfp[0] = funct; |
pfp[0] = funct; |
for (mep = &curmap->map_element[curmap->map_num]; |
for (mep = &curmap->map_element[curmap->map_num]; |
|
|
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; |
return FALSE; |
return (FALSE); |
} |
} |
mp->map_num = 0; |
mp->map_num = 0; |
mp->map_max = MAPINIT; |
mp->map_max = MAPINIT; |
|
|
if (ele->k_funcp[n1] == funct && (funct != NULL || |
if (ele->k_funcp[n1] == funct && (funct != NULL || |
pref_map == NULL || pref_map == ele->k_prefmap)) |
pref_map == NULL || pref_map == ele->k_prefmap)) |
/* no change */ |
/* no change */ |
return TRUE; |
return (TRUE); |
if (funct != NULL || ele->k_prefmap == NULL) { |
if (funct != NULL || ele->k_prefmap == NULL) { |
if (ele->k_funcp[n1] == NULL) |
if (ele->k_funcp[n1] == NULL) |
ele->k_prefmap = NULL; |
ele->k_prefmap = NULL; |
|
|
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; |
return FALSE; |
return (FALSE); |
} |
} |
mp->map_num = 0; |
mp->map_num = 0; |
mp->map_max = MAPINIT; |
mp->map_max = MAPINIT; |
|
|
n2 &= ele->k_funcp[i] != NULL; |
n2 &= ele->k_funcp[i] != NULL; |
if (curmap->map_num >= curmap->map_max && |
if (curmap->map_num >= curmap->map_max && |
(curmap = reallocmap(curmap)) == NULL) |
(curmap = reallocmap(curmap)) == NULL) |
return FALSE; |
return (FALSE); |
if ((pfp = malloc((ele->k_num - c + !n2) * |
if ((pfp = malloc((ele->k_num - c + !n2) * |
sizeof(PF))) == NULL) { |
sizeof(PF))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return FALSE; |
return (FALSE); |
} |
} |
ele->k_funcp[n1] = NULL; |
ele->k_funcp[n1] = NULL; |
for (i = n1 + n2; i <= ele->k_num - ele->k_base; i++) |
for (i = n1 + n2; i <= ele->k_num - ele->k_base; i++) |
|
|
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; |
return FALSE; |
return (FALSE); |
} |
} |
mp->map_num = 0; |
mp->map_num = 0; |
mp->map_max = MAPINIT; |
mp->map_max = MAPINIT; |
|
|
ele->k_prefmap = pref_map; |
ele->k_prefmap = pref_map; |
} |
} |
} |
} |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
|
|
static KEYMAP * |
static KEYMAP * |
reallocmap(KEYMAP *curmap) |
reallocmap(KEYMAP *curmap) |
{ |
{ |
MAPS *mps; |
MAPS *mps; |
KEYMAP *mp; |
KEYMAP *mp; |
int i; |
int i; |
|
|
|
|
(curmap->map_max + (MAPGROW - 1)) * |
(curmap->map_max + (MAPGROW - 1)) * |
sizeof(MAP_ELEMENT)))) == NULL) { |
sizeof(MAP_ELEMENT)))) == NULL) { |
ewprintf("Out of memory"); |
ewprintf("Out of memory"); |
return NULL; |
return (NULL); |
} |
} |
mp->map_num = curmap->map_num; |
mp->map_num = curmap->map_num; |
mp->map_max = curmap->map_max + MAPGROW; |
mp->map_max = curmap->map_max + MAPGROW; |
|
|
fixmap(curmap, mp, mps->p_map); |
fixmap(curmap, mp, mps->p_map); |
} |
} |
ele = &mp->map_element[ele - &curmap->map_element[0]]; |
ele = &mp->map_element[ele - &curmap->map_element[0]]; |
return mp; |
return (mp); |
} |
} |
|
|
/* |
/* |
|
|
} |
} |
|
|
/* |
/* |
* do the input for local-set-key, global-set-key and define-key |
* Do the input for local-set-key, global-set-key and define-key |
* then call remap to do the work. |
* then call remap to do the work. |
*/ |
*/ |
static int |
static int |
|
|
{ |
{ |
KEYMAP *pref_map = NULL; |
KEYMAP *pref_map = NULL; |
PF funct; |
PF funct; |
char prompt[80], *bufp; |
char prompt[80], *bufp, *pep; |
char *pep; |
|
int c, s, n; |
int c, s, n; |
|
|
#ifndef NO_MACRO |
#ifndef NO_MACRO |
|
|
* Would not work for function keys in any case. |
* Would not work for function keys in any case. |
*/ |
*/ |
ewprintf("Can't rebind key in macro"); |
ewprintf("Can't rebind key in macro"); |
return FALSE; |
return (FALSE); |
} |
} |
#ifndef NO_STARTUP |
#ifndef NO_STARTUP |
if (inmacro) { |
if (inmacro) { |
|
|
!= NULL) { |
!= NULL) { |
if (remap(curmap, c, NULL, NULL) |
if (remap(curmap, c, NULL, NULL) |
!= TRUE) |
!= TRUE) |
return FALSE; |
return (FALSE); |
} |
} |
} |
} |
(void)doscan(curmap, c = maclcur->l_text[s], NULL); |
(void)doscan(curmap, c = maclcur->l_text[s], NULL); |
|
|
} else { |
} else { |
#endif /* !NO_STARTUP */ |
#endif /* !NO_STARTUP */ |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
n = strlcpy(prompt, p, sizeof prompt); |
n = strlcpy(prompt, p, sizeof(prompt)); |
if (n >= sizeof prompt) |
if (n >= sizeof(prompt)) |
n = sizeof prompt - 1; |
n = sizeof(prompt) - 1; |
pep = prompt + n; |
pep = prompt + n; |
for (;;) { |
for (;;) { |
ewprintf("%s", prompt); |
ewprintf("%s", prompt); |
|
|
else { |
else { |
if ((bufp = eread("%s to command: ", prompt, 80, EFFUNC | EFNEW, |
if ((bufp = eread("%s to command: ", prompt, 80, EFFUNC | EFNEW, |
prompt)) == NULL) |
prompt)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
if (((funct = name_function(prompt)) == NULL) ? |
if (((funct = name_function(prompt)) == NULL) ? |
(pref_map = name_map(prompt)) == NULL : funct == NULL) { |
(pref_map = name_map(prompt)) == NULL : funct == NULL) { |
ewprintf("[No match]"); |
ewprintf("[No match]"); |
return FALSE; |
return (FALSE); |
} |
} |
} |
} |
return remap(curmap, c, funct, pref_map); |
return (remap(curmap, c, funct, pref_map)); |
} |
} |
|
|
/* |
/* |
|
|
else if (((funct = name_function(fname)) == NULL) ? |
else if (((funct = name_function(fname)) == NULL) ? |
(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++, &curmap) != NULL) { |
if (doscan(curmap, c = *keys++, &curmap) != NULL) { |
if (remap(curmap, c, NULL, NULL) != TRUE) |
if (remap(curmap, c, NULL, NULL) != TRUE) |
return FALSE; |
return (FALSE); |
/* |
/* |
* XXX - Bizzarreness. remap creates an empty KEYMAP |
* XXX - Bizzarreness. remap creates an empty KEYMAP |
* that the last key is supposed to point to. |
* that the last key is supposed to point to. |
|
|
} |
} |
} |
} |
(void)doscan(curmap, c = *keys, NULL); |
(void)doscan(curmap, c = *keys, NULL); |
return remap(curmap, c, funct, pref_map); |
return (remap(curmap, c, funct, pref_map)); |
} |
} |
|
|
#ifdef FKEYS |
#ifdef FKEYS |
|
|
int |
int |
bindtokey(int f, int n) |
bindtokey(int f, int n) |
{ |
{ |
return dobind(fundamental_map, "Global set key: ", FALSE); |
return (dobind(fundamental_map, "Global set key: ", FALSE)); |
} |
} |
|
|
/* |
/* |
|
|
int |
int |
localbind(int f, int n) |
localbind(int f, int n) |
{ |
{ |
return dobind(curbp->b_modes[curbp->b_nmodes]->p_map, |
return (dobind(curbp->b_modes[curbp->b_nmodes]->p_map, |
"Local set key: ", FALSE); |
"Local set key: ", FALSE)); |
} |
} |
|
|
/* |
/* |
|
|
int |
int |
define_key(int f, int n) |
define_key(int f, int n) |
{ |
{ |
static char buf[48]; |
static char buf[48]; |
char tmp[32], *bufp; |
char tmp[32], *bufp; |
KEYMAP *mp; |
KEYMAP *mp; |
|
|
strlcpy(buf, "Define key map: ", sizeof buf); |
strlcpy(buf, "Define key map: ", sizeof(buf)); |
if ((bufp = eread(buf, tmp, sizeof tmp, EFNEW)) == NULL) |
if ((bufp = eread(buf, tmp, sizeof(tmp), EFNEW)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
strlcat(buf, tmp, sizeof buf); |
strlcat(buf, tmp, sizeof(buf)); |
if ((mp = name_map(tmp)) == NULL) { |
if ((mp = name_map(tmp)) == NULL) { |
ewprintf("Unknown map %s", tmp); |
ewprintf("Unknown map %s", tmp); |
return FALSE; |
return (FALSE); |
} |
} |
strlcat(buf, "key: ", sizeof buf); |
strlcat(buf, "key: ", sizeof(buf)); |
|
|
return dobind(mp, buf, FALSE); |
return (dobind(mp, buf, FALSE)); |
} |
} |
|
|
int |
int |
unbindtokey(int f, int n) |
unbindtokey(int f, int n) |
{ |
{ |
return dobind(fundamental_map, "Global unset key: ", TRUE); |
return (dobind(fundamental_map, "Global unset key: ", TRUE)); |
} |
} |
|
|
int |
int |
localunbind(int f, int n) |
localunbind(int f, int 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)); |
} |
} |
|
|
/* |
/* |
|
|
else |
else |
bufp = eread("%d M-x ", xname, NXNAME, EFNEW | EFFUNC, n); |
bufp = eread("%d M-x ", xname, NXNAME, EFNEW | EFFUNC, n); |
if (bufp == NULL) |
if (bufp == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
if ((funct = name_function(bufp)) != NULL) { |
if ((funct = name_function(bufp)) != NULL) { |
#ifndef NO_MACRO |
#ifndef NO_MACRO |
if (macrodef) { |
if (macrodef) { |
|
|
free((char *)lp); |
free((char *)lp); |
} |
} |
#endif /* !NO_MACRO */ |
#endif /* !NO_MACRO */ |
return (*funct)(f, n); |
return ((*funct)(f, n)); |
} |
} |
ewprintf("[No match]"); |
ewprintf("[No match]"); |
return FALSE; |
return (FALSE); |
} |
} |
|
|
#ifndef NO_STARTUP |
#ifndef NO_STARTUP |
|
|
char exbuf[128], *bufp; |
char exbuf[128], *bufp; |
|
|
if ((bufp = ereply("Eval: ", exbuf, sizeof(exbuf))) == NULL) |
if ((bufp = ereply("Eval: ", exbuf, sizeof(exbuf))) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
return excline(exbuf); |
return (excline(exbuf)); |
} |
} |
|
|
/* |
/* |
|
|
|
|
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)); |
|
|
/* make sure it's terminated */ |
/* make sure it's terminated */ |
excbuf[llength(lp)] = '\0'; |
excbuf[llength(lp)] = '\0'; |
if ((s = excline(excbuf)) != TRUE) |
if ((s = excline(excbuf)) != TRUE) |
return s; |
return (s); |
} |
} |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
|
|
char fname[NFILEN], *bufp; |
char fname[NFILEN], *bufp; |
|
|
if ((bufp = ereply("Load file: ", fname, NFILEN)) == NULL) |
if ((bufp = ereply("Load file: ", fname, NFILEN)) == NULL) |
return ABORT; |
return (ABORT); |
else if (bufp[0] == '\0') |
else if (bufp[0] == '\0') |
return FALSE; |
return (FALSE); |
return load(fname); |
return (load(fname)); |
} |
} |
|
|
/* |
/* |
|
|
|
|
if ((fname = adjustname(fname)) == NULL) |
if ((fname = adjustname(fname)) == NULL) |
/* just to be careful */ |
/* just to be careful */ |
return FALSE; |
return (FALSE); |
|
|
if (ffropen(fname, NULL) != FIOSUC) |
if (ffropen(fname, NULL) != FIOSUC) |
return FALSE; |
return (FALSE); |
|
|
line = 0; |
line = 0; |
while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { |
while ((s = ffgetline(excbuf, sizeof(excbuf) - 1, &nbytes)) == FIOSUC) { |
|
|
(void)ffclose(NULL); |
(void)ffclose(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); |
return TRUE; |
return (TRUE); |
} |
} |
|
|
/* |
/* |
* excline - run a line from a load file or eval-expression. if FKEYS is |
* excline - run a line from a load file or eval-expression. If FKEYS is |
* defined, duplicate functionallity of dobind so function key values don't |
* defined, duplicate functionality of dobind so function key values don't |
* have to fit in type char. |
* have to fit in type char. |
*/ |
*/ |
int |
int |
|
|
|
|
if (macrodef || inmacro) { |
if (macrodef || inmacro) { |
ewprintf("Not now!"); |
ewprintf("Not now!"); |
return FALSE; |
return (FALSE); |
} |
} |
f = 0; |
f = 0; |
n = 1; |
n = 1; |
funcp = skipwhite(line); |
funcp = skipwhite(line); |
if (*funcp == '\0') |
if (*funcp == '\0') |
return TRUE; /* No error on blank lines */ |
return (TRUE); /* No error on blank lines */ |
line = parsetoken(funcp); |
line = parsetoken(funcp); |
if (*line != '\0') { |
if (*line != '\0') { |
*line++ = '\0'; |
*line++ = '\0'; |
|
|
f = FFARG; |
f = FFARG; |
nl = strtol(argp, &tmp, 10); |
nl = strtol(argp, &tmp, 10); |
if (*tmp != '\0') |
if (*tmp != '\0') |
return FALSE; |
return (FALSE); |
if (nl >= INT_MAX || nl <= INT_MIN) |
if (nl >= INT_MAX || nl <= INT_MIN) |
return FALSE; |
return (FALSE); |
n = (int)nl; |
n = (int)nl; |
} |
} |
if ((fp = name_function(funcp)) == NULL) { |
if ((fp = name_function(funcp)) == NULL) { |
ewprintf("Unknown function: %s", funcp); |
ewprintf("Unknown function: %s", funcp); |
return FALSE; |
return (FALSE); |
} |
} |
#ifdef FKEYS |
#ifdef FKEYS |
if (fp == bindtokey || fp == unbindtokey) { |
if (fp == bindtokey || fp == unbindtokey) { |
|
|
#endif /* FKEYS */ |
#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; |
while (*line != '\0') { |
while (*line != '\0') { |
argp = skipwhite(line); |
argp = skipwhite(line); |
|
|
} |
} |
lp->l_used = 0; |
lp->l_used = 0; |
#ifdef FKEYS |
#ifdef FKEYS |
} else { |
} else |
key.k_count = 0; |
key.k_count = 0; |
} |
|
#endif /* FKEYS */ |
#endif /* FKEYS */ |
while (*argp != '"' && *argp != '\0') { |
while (*argp != '"' && *argp != '\0') { |
if (*argp != '\\') |
if (*argp != '\\') |
|
|
lp->l_text[lp->l_used] = '\0'; |
lp->l_text[lp->l_used] = '\0'; |
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, NULL, key.k_chars, |
status = bindkey(&curmap, NULL, key.k_chars, |
key.k_count); |
key.k_count); |
} |
|
break; |
break; |
case BINDNO: |
case BINDNO: |
#endif /* FKEYS */ |
#endif /* FKEYS */ |
|
|
lp = np; |
lp = np; |
} |
} |
free((char *)lp); |
free((char *)lp); |
return status; |
return (status); |
} |
} |
|
|
/* |
/* |
|
|
s++; |
s++; |
if (*s == ';') |
if (*s == ';') |
*s = '\0'; |
*s = '\0'; |
return s; |
return (s); |
} |
} |
|
|
static char * |
static char * |
|
|
if (*s == '\\') |
if (*s == '\\') |
++s; |
++s; |
} while (*++s != '"' && *s != '\0'); |
} while (*++s != '"' && *s != '\0'); |
return s; |
return (s); |
} |
} |
#endif /* !NO_STARTUP */ |
#endif /* !NO_STARTUP */ |