options key parsing

OPTIONS=menu_previous_page:\mv
  BINDINGS=M-v:menu_previous_page
both worked, but
  OPTIONS=menu_previous_page:M-v
  BINDINGS=\mv:menu_previous_page
both failed.  Make all four variations work.  Tiny change made large
by the need to move some things around.

The option definition for menu_first_page had a couple of its flag
bits swapped.  I didn't try to figure out whether that had any impact.
This commit is contained in:
PatR
2021-03-10 12:28:09 -08:00
parent 28b7a70b33
commit d8bef90009
6 changed files with 129 additions and 116 deletions

109
src/cmd.c
View File

@@ -6,25 +6,6 @@
#include "hack.h"
#include "func_tab.h"
/* Macros for meta and ctrl modifiers:
* M and C return the meta/ctrl code for the given character;
* e.g., (C('c') is ctrl-c
*/
#ifndef M
#ifndef NHSTDC
#define M(c) (0x80 | (c))
#else
#define M(c) ((c) - 128)
#endif /* NHSTDC */
#endif
#ifndef C
#define C(c) (0x1f & (c))
#endif
#define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c))
#define unmeta(c) (0x7f & (c))
#ifdef ALTMETA
static boolean alt_esc = FALSE;
#endif
@@ -3045,96 +3026,6 @@ spkey_name(int nhkf)
return name;
}
/* returns a one-byte character from the text; may change txt[] */
uchar
txt2key(char *txt)
{
uchar uc;
boolean makemeta = FALSE;
txt = trimspaces(txt);
if (!*txt)
return '\0';
/* simple character */
if (!txt[1])
return (uchar) txt[0];
/* a few special entries */
if (!strcmp(txt, "<enter>"))
return '\n';
if (!strcmp(txt, "<space>"))
return ' ';
if (!strcmp(txt, "<esc>"))
return '\033';
/* control and meta keys */
if (highc(*txt) == 'M') {
/*
* M <nothing> return 'M'
* M - <nothing> return M-'-'
* M <other><nothing> return M-<other>
* otherwise M is pending until after ^/C- processing.
* Since trailing spaces are discarded, the only way to
* specify M-' ' is via "160".
*/
if (!txt[1])
return (uchar) *txt;
/* skip past 'M' or 'm' and maybe '-' */
++txt;
if (*txt == '-' && txt[1])
++txt;
if (!txt[1])
return M((uchar) *txt);
makemeta = TRUE;
}
if (*txt == '^' || highc(*txt) == 'C') {
/*
* C <nothing> return 'C' or M-'C'
* C - <nothing> return '-' or M-'-'
* C [-] <other><nothing> return C-<other> or M-C-<other>
* C [-] ? return <rubout>
* otherwise return C-<other> or M-C-<other>
*/
uc = (uchar) *txt;
if (!txt[1])
return makemeta ? M(uc) : uc;
++txt;
/* unlike M-x, lots of values of x are invalid for C-x;
checking and rejecting them is not worthwhile; GIGO;
we do accept "^-x" as synonym for "^x" or "C-x" */
if (*txt == '-' && txt[1])
++txt;
/* and accept ^?, which gets used despite not being a control char */
if (*txt == '?')
return (uchar) (makemeta ? '\377' : '\177'); /* rubout/delete */
uc = C((uchar) *txt);
return makemeta ? M(uc) : uc;
}
if (makemeta && *txt)
return M((uchar) *txt);
/* FIXME: should accept single-quote single-character single-quote
and probably single-quote backslash octal-digits single-quote;
if we do that, the M- and C- results should be pending until
after, so that C-'X' becomes valid for ^X */
/* ascii codes: must be three-digit decimal */
if (*txt >= '0' && *txt <= '9') {
uchar key = 0;
int i;
for (i = 0; i < 3; i++) {
if (txt[i] < '0' || txt[i] > '9')
return '\0';
key = 10 * key + txt[i] - '0';
}
return key;
}
return '\0';
}
/* returns the text for a one-byte encoding;
* must be shorter than a tab for proper formatting */
char *