svn commit: r1932710 - subversion/trunk/subversion/svnbrowse

[email protected]
Newsgroups gmane.comp.version-control.subversion.svn
Message-ID <177506601539.1776731.11036055777985702867@svn03-he-fi>
Author: rinrab
Date: Wed Apr  1 17:53:35 2026
New Revision: 1932710

Log:
svnbrowse: Use switch statement instead of if-else to process getch() input
data.

* subversion/svnbrowse/svnbrowse.c
  (sub_main): Change logical construction in the main event loop and
   forward-declare some variables.

Modified:
   subversion/trunk/subversion/svnbrowse/svnbrowse.c

Modified: subversion/trunk/subversion/svnbrowse/svnbrowse.c
==============================================================================
--- subversion/trunk/subversion/svnbrowse/svnbrowse.c	Wed Apr  1 17:47:29 2026	(r1932709)
+++ subversion/trunk/subversion/svnbrowse/svnbrowse.c	Wed Apr  1 17:53:35 2026	(r1932710)
@@ -166,14 +166,13 @@ sub_main(int *code, int argc, char *argv
 
   while (TRUE)
     {
-      int ch;
+      svn_browse__item_t *item;
+      const char *new_url;
 
       clear();
       ui_draw(&ctx, pool);
       refresh();
 
-      ch = getch();
-
       /* getch() reads the next character/key with the following additional
        * rules:
        * 1. as we configured it to use keypad(), arrows and other special keys
@@ -183,35 +182,37 @@ sub_main(int *code, int argc, char *argv
        * 3. The rest of keys remain as their equivalents on the current layout.
        * 4. If shift is held, they just become uppercased.
        */
-
-      if (ch == KEY_UP || ch == 'k')
-        {
-          ctx.selection--;
-        }
-      else if (ch == KEY_DOWN || ch == 'j')
-        {
-          ctx.selection++;
-        }
-      else if (ch == '\n' || ch == '\r')
-        {
-          svn_browse__item_t *item = APR_ARRAY_IDX(ctx.list, ctx.selection,
-                                                   svn_browse__item_t *);
-          const char *new_url = svn_relpath_join(ctx.relpath, item->relpath, pool);
-          SVN_ERR(enter_path(&ctx, new_url, pool));
-        }
-      else if (ch == KEY_BACKSPACE || ch == '-' || ch == 'u')
-        {
-          const char *new_url = svn_relpath_dirname(ctx.relpath, pool);
-          SVN_ERR(enter_path(&ctx, new_url, pool));
-        }
-      /* TODO: quit via escape. some say just check for 27, but it I think it's
-       * a bit ugly. */
-      else if (ch == 'q')
+      switch (getch())
         {
-          break;
+          case KEY_UP:
+          case 'k':
+            ctx.selection--;
+            break;
+          case KEY_DOWN:
+          case 'j':
+            ctx.selection++;
+            break;
+          case '\n':
+          case '\r':
+            item = APR_ARRAY_IDX(ctx.list, ctx.selection,
+                                 svn_browse__item_t *);
+            new_url = svn_relpath_join(ctx.relpath, item->relpath, pool);
+            SVN_ERR(enter_path(&ctx, new_url, pool));
+            break;
+          case KEY_BACKSPACE:
+          case '-':
+          case 'u':
+            new_url = svn_relpath_dirname(ctx.relpath, pool);
+            SVN_ERR(enter_path(&ctx, new_url, pool));
+            break;
+          /* TODO: quit via escape. some say just check for 27, but it I think it's
+           * a bit ugly. */
+          case 'q':
+            goto quit;
         }
     }
 
+quit:
 	endwin();
 
   return SVN_NO_ERROR;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.