]> Sergey Matveev's repositories - nnn.git/commitdiff
Replace multiple if with switch
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 4 Jul 2018 13:32:47 +0000 (19:02 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 4 Jul 2018 13:32:47 +0000 (19:02 +0530)
nnn.c

diff --git a/nnn.c b/nnn.c
index b1366994762f031497dd048312d616d92d4d824c..fa4c177b5ed96fef55c195c5b5680c1c3e7b1f0c 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -1213,35 +1213,30 @@ xreadline(char *fname, char *prompt)
 
                if ((r = get_wch(ch)) != ERR) {
                        if (r == OK) {
-                               if (*ch == KEY_ENTER || *ch == '\n' || *ch == '\r')
-                                       break;
-
-                               if (*ch == '\b') {
+                               switch (*ch) {
+                               case KEY_ENTER: //fallthrough
+                               case '\n': //fallthrough
+                               case '\r':
+                                       goto END;
+                               case '\b': /* some old curses (e.g. rhel25) still send '\b' for backspace */
                                        if (pos > 0) {
                                                memmove(buf + pos - 1, buf + pos, (len - pos) << 2);
                                                --len, --pos;
-                                       }
+                                       } //fallthrough
+                               case '\t': /* TAB breaks cursor position, ignore it */
                                        continue;
-                               }
-
-                               if (*ch == CONTROL('L')) {
+                               case CONTROL('L'):
                                        clearprompt();
                                        printprompt(prompt);
                                        len = pos = 0;
                                        continue;
-                               }
-
-                               if (*ch == CONTROL('A')) {
+                               case CONTROL('A'):
                                        pos = 0;
                                        continue;
-                               }
-
-                               if (*ch == CONTROL('E')) {
+                               case CONTROL('E'):
                                        pos = len;
                                        continue;
-                               }
-
-                               if (*ch == CONTROL('U')) {
+                               case CONTROL('U'):
                                        clearprompt();
                                        printprompt(prompt);
                                        memmove(buf, buf + pos, (len - pos) << 2);
@@ -1254,10 +1249,6 @@ xreadline(char *fname, char *prompt)
                                if (keyname(*ch)[0] == '^')
                                        continue;
 
-                               /* TAB breaks cursor position, ignore it */
-                               if (*ch == '\t')
-                                       continue;
-
                                if (pos < NAME_MAX - 1) {
                                        memmove(buf + pos + 1, buf + pos, (len - pos) << 2);
                                        buf[pos] = *ch;
@@ -1293,6 +1284,7 @@ xreadline(char *fname, char *prompt)
                }
        }
 
+END:
        buf[len] = '\0';
        if (old_curs != ERR)
                curs_set(old_curs);