]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: restructure print_buf() if-else with continue
authorSami Kerola <kerolasa@iki.fi>
Wed, 18 Mar 2020 20:13:00 +0000 (20:13 +0000)
committerSami Kerola <kerolasa@iki.fi>
Sat, 28 Mar 2020 07:55:58 +0000 (07:55 +0000)
Replacing long 'else' with 'continue' allows dropping one level of
indentation.  Main aim is to improve code readability by reducing
complexity one needs to keep track while looking the code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/more.c

index 4801317c31630bfda496572ec5a9ba08a468f7c1..f426b662692042cc84bcded991c9496b855ccefd 100644 (file)
@@ -622,55 +622,56 @@ static int would_underline(char *s, int n)
 /* Print a buffer of n characters */
 static void print_buf(struct more_control *ctl, char *s, int n)
 {
-       char c; /* next output character */
+       char c;         /* next output character */
        int state;      /* next output char's UL state */
 
-       while (--n >= 0)
-               if (!ctl->enable_underlining)
+       while (--n >= 0) {
+               if (!ctl->enable_underlining) {
                        putchar(*s++);
-               else {
-                       if (*s == ' ' && ctl->underline_state == 0 && ctl->underline_glitch
-                           && would_underline(s + 1, n - 1)) {
-                               s++;
-                               continue;
-                       }
-                       if ((state = would_underline(s, n)) != 0) {
-                               c = (*s == '_') ? s[2] : *s;
-                               n -= 2;
-                               s += 3;
-                       } else
-                               c = *s++;
-                       if (state != ctl->underline_state) {
-                               if (c == ' ' && state == 0 && ctl->underline_glitch
-                                   && would_underline(s, n - 1))
-                                       state = 1;
-                               else
-                                       putp(state ? ctl->enter_underline : ctl->exit_underline);
-                       }
-                       if (c != ' ' || ctl->underline_state == 0 || state != 0
-                           || ctl->underline_glitch == 0)
+                       continue;
+               }
+               if (*s == ' ' && ctl->underline_state == 0 && ctl->underline_glitch
+                   && would_underline(s + 1, n - 1)) {
+                       s++;
+                       continue;
+               }
+               if ((state = would_underline(s, n)) != 0) {
+                       c = (*s == '_') ? s[2] : *s;
+                       n -= 2;
+                       s += 3;
+               } else
+                       c = *s++;
+               if (state != ctl->underline_state) {
+                       if (c == ' ' && state == 0 && ctl->underline_glitch
+                           && would_underline(s, n - 1))
+                               state = 1;
+                       else
+                               putp(state ? ctl->enter_underline : ctl->exit_underline);
+               }
+               if (c != ' ' || ctl->underline_state == 0 || state != 0
+                   || ctl->underline_glitch == 0) {
 #ifdef HAVE_WIDECHAR
-                       {
-                               wchar_t wc;
-                               size_t mblength;
-                               mbstate_t mbstate;
-                               memset(&mbstate, '\0', sizeof(mbstate_t));
-                               s--;
-                               n++;
-                               mblength = xmbrtowc(&wc, s, n, &mbstate);
-                               while (mblength--)
-                                       putchar(*s++);
-                               n += mblength;
-                       }
+                       wchar_t wc;
+                       size_t mblength;
+                       mbstate_t mbstate;
+
+                       memset(&mbstate, '\0', sizeof(mbstate_t));
+                       s--;
+                       n++;
+                       mblength = xmbrtowc(&wc, s, n, &mbstate);
+                       while (mblength--)
+                               putchar(*s++);
+                       n += mblength;
 #else
-                               putchar(c);
-#endif                         /* HAVE_WIDECHAR */
-                       if (state && *ctl->underline_ch) {
-                               fputs(ctl->backspace_ch, stdout);
-                               putp(ctl->underline_ch);
-                       }
-                       ctl->underline_state = state;
+                       putchar(c);
+#endif
                }
+               if (state && *ctl->underline_ch) {
+                       fputs(ctl->backspace_ch, stdout);
+                       putp(ctl->underline_ch);
+               }
+               ctl->underline_state = state;
+       }
 }
 
 /* Erase the current line entirely */