diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-07-09 04:36:43 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-07-09 05:16:37 +0200 |
commit | 98612f549202c491c9b97df54e77d413a8e35e8d (patch) | |
tree | 0784249facf2d5a3911d420ceebe63411497a062 /sdn.cpp | |
parent | 1034321f812a3e620063c21b7ce7a0d88be8ede2 (diff) | |
download | sdn-98612f549202c491c9b97df54e77d413a8e35e8d.tar.gz sdn-98612f549202c491c9b97df54e77d413a8e35e8d.tar.xz sdn-98612f549202c491c9b97df54e77d413a8e35e8d.zip |
Improve C-char parsing
I was hoping that a superoptimiser would help me find a miraculous
branchless equation to cover it, but in the end the branching
doesn't hurt at all in our case.
It's more readable than `(((char >> 2) - 0x38) & 0x60) ^ char`
or `(char ^ 0x40) & (((char >> 1) ^ 0x20) | 0x5f)`.
Diffstat (limited to 'sdn.cpp')
-rw-r--r-- | sdn.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -398,9 +398,9 @@ fun decode_attrs (const vector<string> &attrs) -> chtype { // --- Application ------------------------------------------------------------- -enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode +enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode #define KEY(name) (SYM | KEY_ ## name) -#define CTRL(char) ((char - 64) & 0x7f) // 60..7f aren't translated correctly +#define CTRL(char) ((char) == '?' ? 0x7f : (char) & 0x1f) #define ACTIONS(XX) XX(NONE) XX(HELP) XX(QUIT) XX(QUIT_NO_CHDIR) \ XX(CHOOSE) XX(CHOOSE_FULL) XX(VIEW) XX(EDIT) XX(SORT_LEFT) XX(SORT_RIGHT) \ @@ -1571,11 +1571,11 @@ fun parse_key (const string &key_name) -> wint_t { return c | g.name_to_key.at (p); } else if (!strncmp (p, "C-", 2)) { p += 2; - if (*p < '?' || *p > 'z') { + if (*p < '?' || *p > '~') { cerr << "bindings: invalid combination: " << key_name << endl; return WEOF; } - c |= CTRL (toupper (*p)); + c |= CTRL (*p); p += 1; } else { wchar_t w; mbstate_t mb {}; |