returns a one-byte character from the text; may change txt[]; moved from cmd.c in order to get access to escapes() */
| 6968 | /* returns a one-byte character from the text; may change txt[]; |
| 6969 | moved from cmd.c in order to get access to escapes() */ |
| 6970 | uchar |
| 6971 | txt2key(char *txt) |
| 6972 | { |
| 6973 | uchar uc; |
| 6974 | boolean makemeta = FALSE; |
| 6975 | |
| 6976 | txt = trimspaces(txt); |
| 6977 | if (!*txt) |
| 6978 | return '\0'; |
| 6979 | |
| 6980 | /* simple character */ |
| 6981 | if (!txt[1]) |
| 6982 | return (uchar) txt[0]; |
| 6983 | |
| 6984 | /* a few special entries */ |
| 6985 | if (!strcmp(txt, "<enter>")) |
| 6986 | return '\n'; |
| 6987 | if (!strcmp(txt, "<space>")) |
| 6988 | return ' '; |
| 6989 | if (!strcmp(txt, "<esc>")) |
| 6990 | return '\033'; |
| 6991 | |
| 6992 | /* handle things like \b and \7 and \mX */ |
| 6993 | if (*txt == '\\') { |
| 6994 | char tbuf[QBUFSZ]; |
| 6995 | |
| 6996 | if (strlen(txt) >= sizeof tbuf) |
| 6997 | txt[sizeof tbuf - 1] = '\0'; |
| 6998 | escapes(txt, tbuf); |
| 6999 | return *tbuf; |
| 7000 | } |
| 7001 | |
| 7002 | /* control and meta keys */ |
| 7003 | if (highc(*txt) == 'M') { |
| 7004 | /* |
| 7005 | * M <nothing> return 'M' |
| 7006 | * M - <nothing> return M-'-' |
| 7007 | * M <other><nothing> return M-<other> |
| 7008 | * otherwise M is pending until after ^/C- processing. |
| 7009 | * Since trailing spaces are discarded, the only way to |
| 7010 | * specify M-' ' is via "160". |
| 7011 | */ |
| 7012 | if (!txt[1]) |
| 7013 | return (uchar) *txt; |
| 7014 | /* skip past 'M' or 'm' and maybe '-' */ |
| 7015 | ++txt; |
| 7016 | if (*txt == '-' && txt[1]) |
| 7017 | ++txt; |
| 7018 | if (!txt[1]) |
| 7019 | return M((uchar) *txt); |
| 7020 | makemeta = TRUE; |
| 7021 | } |
| 7022 | if (*txt == '^' || highc(*txt) == 'C') { |
| 7023 | /* |
| 7024 | * C <nothing> return 'C' or M-'C' |
| 7025 | * C - <nothing> return '-' or M-'-' |
| 7026 | * C [-] <other><nothing> return C-<other> or M-C-<other> |
| 7027 | * C [-] ? return <rubout> |
no test coverage detected