more control key formatting
The previous fix to use highc(UNCTRL(x)) worked for ^A through ^Z,
but not for NUL (yielded ^` instead of usual ^@) or ^[ through ^_
(yielded lowercase ^{ and so on). The problem was UNCTRL(); it
shouldn't have been forcing on the lowercase bit to begin with.
Also, the code that used UNMETA() for formatting wouldn't work as
intended for M-control char since it stripped off the 8th bit but
didn't apply any fixup for control chars.
Just get rid of ISCTRL/ISMETA/UNCTRL/UNMETA and use the existing
visctrl() routine instead. (Its 3.6.0 edition didn't handle
M-control char, but the to-be-3.6.1 branch has done so since a
week or two after the 3.6.0 release.)
This commit is contained in:
@@ -2737,24 +2737,18 @@ int final;
|
|||||||
/* Macros for meta and ctrl modifiers:
|
/* Macros for meta and ctrl modifiers:
|
||||||
* M and C return the meta/ctrl code for the given character;
|
* M and C return the meta/ctrl code for the given character;
|
||||||
* e.g., (C('c') is ctrl-c
|
* e.g., (C('c') is ctrl-c
|
||||||
* ISMETA and ISCTRL return TRUE iff the code is a meta/ctrl code
|
*/
|
||||||
* UNMETA and UNCTRL are the opposite of M/C and return the key for a given
|
|
||||||
* meta/ctrl code. */
|
|
||||||
#ifndef M
|
#ifndef M
|
||||||
#ifndef NHSTDC
|
#ifndef NHSTDC
|
||||||
#define M(c) (0x80 | (c))
|
#define M(c) (0x80 | (c))
|
||||||
#else
|
#else
|
||||||
#define M(c) ((c) -128)
|
#define M(c) ((c) - 128)
|
||||||
#endif /* NHSTDC */
|
#endif /* NHSTDC */
|
||||||
#endif
|
#endif
|
||||||
#define ISMETA(c) (((c) & 0x80) != 0)
|
|
||||||
#define UNMETA(c) ((c) & 0x7f)
|
|
||||||
|
|
||||||
#ifndef C
|
#ifndef C
|
||||||
#define C(c) (0x1f & (c))
|
#define C(c) (0x1f & (c))
|
||||||
#endif
|
#endif
|
||||||
#define ISCTRL(c) ((uchar)(c) < 0x20)
|
|
||||||
#define UNCTRL(c) (ISCTRL(c) ? (0x60 | (c)) : (c))
|
|
||||||
|
|
||||||
/* ordered by command name */
|
/* ordered by command name */
|
||||||
struct ext_func_tab extcmdlist[] = {
|
struct ext_func_tab extcmdlist[] = {
|
||||||
@@ -3727,27 +3721,25 @@ char *txt;
|
|||||||
return '\0';
|
return '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns the text for a one-byte encoding
|
/* returns the text for a one-byte encoding;
|
||||||
* must be shorter than a tab for proper formatting */
|
* must be shorter than a tab for proper formatting */
|
||||||
char *
|
char *
|
||||||
key2txt(c, txt)
|
key2txt(c, txt)
|
||||||
uchar c;
|
uchar c;
|
||||||
char *txt; /* sufficiently long buffer */
|
char *txt; /* sufficiently long buffer */
|
||||||
{
|
{
|
||||||
|
/* should probably switch to "SPC", "ESC", "RET"
|
||||||
|
since nethack's documentation uses ESC for <escape> */
|
||||||
if (c == ' ')
|
if (c == ' ')
|
||||||
Sprintf(txt, "<space>");
|
Sprintf(txt, "<space>");
|
||||||
else if (c == '\033')
|
else if (c == '\033')
|
||||||
Sprintf(txt, "<esc>");
|
Sprintf(txt, "<esc>");
|
||||||
else if (c == '\n')
|
else if (c == '\n')
|
||||||
Sprintf(txt, "<enter>");
|
Sprintf(txt, "<enter>");
|
||||||
else if (ISCTRL(c))
|
else if (c == '\177')
|
||||||
Sprintf(txt, "^%c", highc(UNCTRL(c)));
|
Sprintf(txt, "<del>"); /* "<delete>" won't fit */
|
||||||
else if (ISMETA(c))
|
|
||||||
Sprintf(txt, "M-%c", UNMETA(c));
|
|
||||||
else if (c >= 33 && c <= 126)
|
|
||||||
Sprintf(txt, "%c", c); /* regular keys: ! through ~ */
|
|
||||||
else
|
else
|
||||||
Sprintf(txt, "A-%i", c); /* arbitrary ascii combinations */
|
Strcpy(txt, visctrl((char) c));
|
||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user