]> git.wh0rd.org Git - nano.git/commitdiff
get_verbatim_kbinput() should use an int*, not a char*, for consistency
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Fri, 6 Feb 2004 03:07:10 +0000 (03:07 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Fri, 6 Feb 2004 03:07:10 +0000 (03:07 +0000)
with get_kbinput()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1646 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/nano.c
src/proto.h
src/winio.c

index 0d0974539b5cec59556fdf132b3af0f6e0634655..f2b8da47800e6cfd01b42cf9f06d6c103218c99b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -60,12 +60,18 @@ CVS code -
          Also, with keypad() set to TRUE, xterm generates KEY_BACKSPACE
          when the user hits Ctrl-H, which, when cut down to ASCII
          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()
        - Don't use "kbinput = wgetch(win)" as a switch value. (DLR)
   get_escape_seq_kbinput()
        - Add support for the escape sequences for F1-F14 whenever
          possible (i.e, whenever a conflict doesn't occur), some
          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()
        - A resurrected version of the old abcd() function, readded in
          order to simplify get_escape_seq_kbinput(). (DLR)
index b5a5b1327080c5bc8597e5837d37197e08f3fca7..3e668f117dd096262c191a5604bda4ceb8dbb470 100644 (file)
@@ -1000,8 +1000,8 @@ void do_char(char ch)
 
 int do_verbatim_input(void)
 {
-    char *verbatim_kbinput;    /* Used to hold verbatim input */
-    int verbatim_len;          /* Length of verbatim input */
+    int *verbatim_kbinput;     /* Used to hold verbatim input. */
+    int verbatim_len;          /* Length of verbatim input. */
     int i;
 
     statusbar(_("Verbatim input"));
index 808b4b07c846dc8c89d18d831b37c189cf211da6..7a5a49c7eb5d83d3687627b9153ec664c48b384c 100644 (file)
@@ -440,12 +440,12 @@ int check_wildcard_match(const char *text, const char *pattern);
 
 /* Public functions in winio.c */
 int get_kbinput(WINDOW *win, int *meta);
-char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
-       int allow_ascii);
+int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
+       allow_ascii);
 int get_ignored_kbinput(WINDOW *win);
 int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta);
 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);
 int get_escape_seq_abcd(int kbinput);
 int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut);
index 9e6167d6f4c019cc46a21b9a9bc83fa588d76883..139cc8c7ffc7b60c2bfea754ec6ca0e1952f3ef1 100644 (file)
@@ -54,11 +54,10 @@ int get_kbinput(WINDOW *win, int *meta)
 /* Read in a string of input characters (e.g. an escape sequence)
  * verbatim, and return the length of the string in kbinput_len.  Assume
  * nodelay(win) is FALSE. */
-char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
-       int allow_ascii)
+int *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, int
+       allow_ascii)
 {
-    char *verbatim_kbinput;
-    int kbinput;
+    int kbinput, *verbatim_kbinput;
 
     /* 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
@@ -70,7 +69,7 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
 #endif
 
     kbinput = wgetch(win);
-    verbatim_kbinput = charalloc(1);
+    verbatim_kbinput = (int *)nmalloc(sizeof(int));
     verbatim_kbinput[0] = kbinput;
     *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
         * verbatim mode will produce the corresponding ASCII
         * character. */
-       verbatim_kbinput[0] = (char)get_ascii_kbinput(win, kbinput);
+       verbatim_kbinput[0] = get_ascii_kbinput(win, kbinput);
     else {
        nodelay(win, TRUE);
        while ((kbinput = wgetch(win)) != ERR) {
            (*kbinput_len)++;
-           verbatim_kbinput = charealloc(verbatim_kbinput, *kbinput_len);
-           verbatim_kbinput[*kbinput_len - 1] = (char)kbinput;
+           verbatim_kbinput = realloc(verbatim_kbinput, *kbinput_len * sizeof(int));
+           verbatim_kbinput[*kbinput_len - 1] = kbinput;
        }
        nodelay(win, FALSE);
     }
@@ -174,8 +173,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta)
                 * Hemel. */
                case '[':
                {
-                   int old_kbinput = kbinput, escape_seq_len;
-                   char *escape_seq;
+                   int old_kbinput = kbinput, *escape_seq, escape_seq_len;
                    nodelay(win, TRUE);
                    kbinput = wgetch(win);
                    switch (kbinput) {
@@ -350,7 +348,7 @@ int get_ascii_kbinput(WINDOW *win, int kbinput)
  *   omitted.  (Same as above.)
  * - The Hurd console has no escape sequences for F11, F12, F13, or
  *   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)
 {
     int kbinput = ERR;
@@ -436,36 +434,7 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int
            case '[':
                switch (escape_seq[1]) {
                    case '1':
-                       if (escape_seq_len >= 5) {
-                           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) {
+                       if (escape_seq_len >= 3) {
                            switch (escape_seq[2]) {
                                case '1': /* Esc [ 1 1 ~ == F1 on
                                           * rxvt/Eterm. */
@@ -499,6 +468,44 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int
                                           * console/xterm/rxvt/Eterm. */
                                    kbinput = KEY_F(8);
                                    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
                                          * console. */
                                    kbinput = NANO_HOME_KEY;