From 6d3226c4e76d8360d1e94917f9f0d208a09011d0 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Mon, 18 Jul 2005 09:31:37 +0000 Subject: [PATCH] * util.c: Added ascii_alpha_to_cntrl(), which converts 'x' to ^X. Useful for entering control characters literally. * util.h: Likewise. * widget.c: Use that function after C-q. --- src/ChangeLog | 7 +++++++ src/util.c | 15 +++++++++++++++ src/util.h | 4 ++++ src/widget.c | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6d882e0fd..169d197f2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2005-07-17 Roland Illig + + * util.c: Added ascii_alpha_to_cntrl(), which converts 'x' to + ^X. Useful for entering control characters literally. + * util.h: Likewise. + * widget.c: Use that function after C-q. + 2005-07-17 Roland Illig * view.c: The viewer can remember the last file position and diff --git a/src/util.c b/src/util.c index 48aee1349..f3865da73 100644 --- a/src/util.c +++ b/src/util.c @@ -1449,3 +1449,18 @@ str_unconst (const char *s) { return (char *) s; } + +#define ASCII_A (0x40 + 1) +#define ASCII_Z (0x40 + 26) +#define ASCII_a (0x60 + 1) +#define ASCII_z (0x60 + 26) + +extern int +ascii_alpha_to_cntrl (int ch) +{ + if ((ch >= ASCII_A && ch <= ASCII_Z) + || (ch >= ASCII_a && ch <= ASCII_z)) { + ch &= 0x1f; + } + return ch; +} diff --git a/src/util.h b/src/util.h index 9c66c7052..eddbb5711 100644 --- a/src/util.h +++ b/src/util.h @@ -255,4 +255,8 @@ void save_file_position (const char *filename, long line, long column); /* usage: str_cmp ("foo", !=, "bar") */ #define str_cmp(a,rel,b) (strcmp ((a), (b)) rel 0) +/* if ch is in [A-Za-z], returns the corresponding control character, + * else returns the argument. */ +extern int ascii_alpha_to_cntrl (int ch); + #endif diff --git a/src/widget.c b/src/widget.c index 299971a98..880164a9c 100644 --- a/src/widget.c +++ b/src/widget.c @@ -1586,7 +1586,7 @@ input_callback (Widget *w, widget_msg_t msg, int parm) case WIDGET_KEY: if (parm == XCTRL ('q')) { quote = 1; - v = handle_char (in, mi_getch ()); + v = handle_char (in, ascii_alpha_to_cntrl (mi_getch ())); quote = 0; return v; }