get_verbatim_kbinput() should use an int*, not a char*, for consistency

with get_kbinput()


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1646 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-02-06 03:07:10 +00:00
parent 1bc9219beb
commit ee383dbd6c
4 changed files with 59 additions and 46 deletions

View File

@ -60,12 +60,18 @@ CVS code -
Also, with keypad() set to TRUE, xterm generates KEY_BACKSPACE Also, with keypad() set to TRUE, xterm generates KEY_BACKSPACE
when the user hits Ctrl-H, which, when cut down to ASCII when the user hits Ctrl-H, which, when cut down to ASCII
range, ends up being Ctrl-G, which can be confusing. (DLR) range, ends up being Ctrl-G, which can be confusing. (DLR)
- For consistency with get_kbinput(), use an int* to store and
return the input instead of a char*, and tweak the functions
that call it to handle this. (DLR)
get_accepted_kbinput() get_accepted_kbinput()
- Don't use "kbinput = wgetch(win)" as a switch value. (DLR) - Don't use "kbinput = wgetch(win)" as a switch value. (DLR)
get_escape_seq_kbinput() get_escape_seq_kbinput()
- Add support for the escape sequences for F1-F14 whenever - Add support for the escape sequences for F1-F14 whenever
possible (i.e, whenever a conflict doesn't occur), some possible (i.e, whenever a conflict doesn't occur), some
additional comments, and a few cosmetic cleanups. (DLR) additional comments, and a few cosmetic cleanups. (DLR)
- Use switch statements instead of strncmp() to read in the long
xterm sequences for Ctrl-[arrow key] and Shift-[arrow key].
(DLR)
get_escape_seq_abcd() get_escape_seq_abcd()
- A resurrected version of the old abcd() function, readded in - A resurrected version of the old abcd() function, readded in
order to simplify get_escape_seq_kbinput(). (DLR) order to simplify get_escape_seq_kbinput(). (DLR)

View File

@ -1000,8 +1000,8 @@ void do_char(char ch)
int do_verbatim_input(void) int do_verbatim_input(void)
{ {
char *verbatim_kbinput; /* Used to hold verbatim input */ int *verbatim_kbinput; /* Used to hold verbatim input. */
int verbatim_len; /* Length of verbatim input */ int verbatim_len; /* Length of verbatim input. */
int i; int i;
statusbar(_("Verbatim input")); statusbar(_("Verbatim input"));

View File

@ -440,12 +440,12 @@ int check_wildcard_match(const char *text, const char *pattern);
/* Public functions in winio.c */ /* Public functions in winio.c */
int get_kbinput(WINDOW *win, int *meta); int get_kbinput(WINDOW *win, int *meta);
char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
int allow_ascii); allow_ascii);
int get_ignored_kbinput(WINDOW *win); int get_ignored_kbinput(WINDOW *win);
int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta); int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta);
int get_ascii_kbinput(WINDOW *win, int kbinput); int get_ascii_kbinput(WINDOW *win, int kbinput);
int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, int
escape_seq_len); escape_seq_len);
int get_escape_seq_abcd(int kbinput); int get_escape_seq_abcd(int kbinput);
int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut); int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut);

View File

@ -54,11 +54,10 @@ int get_kbinput(WINDOW *win, int *meta)
/* Read in a string of input characters (e.g. an escape sequence) /* Read in a string of input characters (e.g. an escape sequence)
* verbatim, and return the length of the string in kbinput_len. Assume * verbatim, and return the length of the string in kbinput_len. Assume
* nodelay(win) is FALSE. */ * nodelay(win) is FALSE. */
char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
int allow_ascii) allow_ascii)
{ {
char *verbatim_kbinput; int kbinput, *verbatim_kbinput;
int kbinput;
/* Turn the keypad off so that we don't get extended keypad values, /* Turn the keypad off so that we don't get extended keypad values,
* all of which are outside the ASCII range, and switch to raw mode * all of which are outside the ASCII range, and switch to raw mode
@ -70,7 +69,7 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
#endif #endif
kbinput = wgetch(win); kbinput = wgetch(win);
verbatim_kbinput = charalloc(1); verbatim_kbinput = (int *)nmalloc(sizeof(int));
verbatim_kbinput[0] = kbinput; verbatim_kbinput[0] = kbinput;
*kbinput_len = 1; *kbinput_len = 1;
@ -78,13 +77,13 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
/* Entering a three-digit decimal ASCII code from 000-255 in /* Entering a three-digit decimal ASCII code from 000-255 in
* verbatim mode will produce the corresponding ASCII * verbatim mode will produce the corresponding ASCII
* character. */ * character. */
verbatim_kbinput[0] = (char)get_ascii_kbinput(win, kbinput); verbatim_kbinput[0] = get_ascii_kbinput(win, kbinput);
else { else {
nodelay(win, TRUE); nodelay(win, TRUE);
while ((kbinput = wgetch(win)) != ERR) { while ((kbinput = wgetch(win)) != ERR) {
(*kbinput_len)++; (*kbinput_len)++;
verbatim_kbinput = charealloc(verbatim_kbinput, *kbinput_len); verbatim_kbinput = realloc(verbatim_kbinput, *kbinput_len * sizeof(int));
verbatim_kbinput[*kbinput_len - 1] = (char)kbinput; verbatim_kbinput[*kbinput_len - 1] = kbinput;
} }
nodelay(win, FALSE); nodelay(win, FALSE);
} }
@ -174,8 +173,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
* Hemel. */ * Hemel. */
case '[': case '[':
{ {
int old_kbinput = kbinput, escape_seq_len; int old_kbinput = kbinput, *escape_seq, escape_seq_len;
char *escape_seq;
nodelay(win, TRUE); nodelay(win, TRUE);
kbinput = wgetch(win); kbinput = wgetch(win);
switch (kbinput) { switch (kbinput) {
@ -350,7 +348,7 @@ int get_ascii_kbinput(WINDOW *win, int kbinput)
* omitted. (Same as above.) * omitted. (Same as above.)
* - The Hurd console has no escape sequences for F11, F12, F13, or * - The Hurd console has no escape sequences for F11, F12, F13, or
* F14. */ * F14. */
int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int int get_escape_seq_kbinput(WINDOW *win, int *escape_seq, int
escape_seq_len) escape_seq_len)
{ {
int kbinput = ERR; int kbinput = ERR;
@ -436,36 +434,7 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int
case '[': case '[':
switch (escape_seq[1]) { switch (escape_seq[1]) {
case '1': case '1':
if (escape_seq_len >= 5) { if (escape_seq_len >= 3) {
if (!strncmp(escape_seq + 2, ";2", 2)) {
switch (escape_seq[4]) {
case 'A': /* Esc [ 1 ; 2 A ==
* Shift-Up on xterm. */
case 'B': /* Esc [ 1 ; 2 B ==
* Shift-Down on xterm. */
case 'C': /* Esc [ 1 ; 2 C ==
* Shift-Right on
* xterm. */
case 'D': /* Esc [ 1 ; 2 D ==
* Shift-Left on xterm. */
kbinput = get_escape_seq_abcd(escape_seq[1]);
break;
}
} else if (!strncmp(escape_seq + 2, ";5", 2)) {
switch (escape_seq[4]) {
case 'A': /* Esc [ 1 ; 5 A ==
* Ctrl-Up on xterm. */
case 'B': /* Esc [ 1 ; 5 B ==
* Ctrl-Down on xterm. */
case 'C': /* Esc [ 1 ; 5 C ==
* Ctrl-Right on xterm. */
case 'D': /* Esc [ 1 ; 5 D ==
* Ctrl-Left on xterm. */
kbinput = get_escape_seq_abcd(escape_seq[1]);
break;
}
}
} else if (escape_seq_len >= 3) {
switch (escape_seq[2]) { switch (escape_seq[2]) {
case '1': /* Esc [ 1 1 ~ == F1 on case '1': /* Esc [ 1 1 ~ == F1 on
* rxvt/Eterm. */ * rxvt/Eterm. */
@ -499,6 +468,44 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int
* console/xterm/rxvt/Eterm. */ * console/xterm/rxvt/Eterm. */
kbinput = KEY_F(8); kbinput = KEY_F(8);
break; break;
case ';':
if (escape_seq_len >= 4) {
switch (escape_seq[3]) {
case '2':
if (escape_seq_len >= 5) {
switch (escape_seq[4]) {
case 'A': /* Esc [ 1 ; 2 A == Shift-Up on
* xterm. */
case 'B': /* Esc [ 1 ; 2 B == Shift-Down on
* xterm. */
case 'C': /* Esc [ 1 ; 2 C == Shift-Right on
* xterm. */
case 'D': /* Esc [ 1 ; 2 D == Shift-Left on
* xterm. */
kbinput = get_escape_seq_abcd(escape_seq[4]);
break;
}
}
break;
case '5':
if (escape_seq_len >= 5) {
switch (escape_seq[4]) {
case 'A': /* Esc [ 1 ; 5 A == Ctrl-Up on
* xterm. */
case 'B': /* Esc [ 1 ; 5 B == Ctrl-Down on
* xterm. */
case 'C': /* Esc [ 1 ; 5 C == Ctrl-Right on
* xterm. */
case 'D': /* Esc [ 1 ; 5 D == Ctrl-Left on
* xterm. */
kbinput = get_escape_seq_abcd(escape_seq[4]);
break;
}
}
break;
}
}
break;
default: /* Esc [ 1 ~ == Home on Linux default: /* Esc [ 1 ~ == Home on Linux
* console. */ * console. */
kbinput = NANO_HOME_KEY; kbinput = NANO_HOME_KEY;