]> granicus.if.org Git - neomutt/commitdiff
Refactor decode_xbit
authorFederico Kircheis <federico.kircheis@gmail.com>
Sat, 3 Mar 2018 08:12:34 +0000 (09:12 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 3 Mar 2018 08:12:34 +0000 (09:12 +0100)
Reduce number of scopes, should improve readability

handler.c

index afe60c7447d609f384c3e58f7e6191a72ded4090..4def5ceda9c3790d034d4ca801e1cacdf884f1aa 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -112,40 +112,40 @@ static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *s)
 
 static void decode_xbit(struct State *s, long len, int istext, iconv_t cd)
 {
-  int c, ch;
+  if (!istext)
+  {
+    mutt_file_copy_bytes(s->fpin, s->fpout, len);
+    return;
+  }
+
+  state_set_prefix(s);
+
+  int c;
   char bufi[BUFI_SIZE];
   size_t l = 0;
-
-  if (istext)
+  while ((c = fgetc(s->fpin)) != EOF && len--)
   {
-    state_set_prefix(s);
-
-    while ((c = fgetc(s->fpin)) != EOF && len--)
+    if (c == '\r' && len)
     {
-      if (c == '\r' && len)
+      const int ch = fgetc(s->fpin);
+      if (ch == '\n')
       {
-        ch = fgetc(s->fpin);
-        if (ch == '\n')
-        {
-          c = ch;
-          len--;
-        }
-        else
-          ungetc(ch, s->fpin);
+        c = ch;
+        len--;
       }
-
-      bufi[l++] = c;
-      if (l == sizeof(bufi))
-        convert_to_state(cd, bufi, &l, s);
+      else
+        ungetc(ch, s->fpin);
     }
 
-    convert_to_state(cd, bufi, &l, s);
-    convert_to_state(cd, 0, 0, s);
-
-    state_reset_prefix(s);
+    bufi[l++] = c;
+    if (l == sizeof(bufi))
+      convert_to_state(cd, bufi, &l, s);
   }
-  else
-    mutt_file_copy_bytes(s->fpin, s->fpout, len);
+
+  convert_to_state(cd, bufi, &l, s);
+  convert_to_state(cd, 0, 0, s);
+
+  state_reset_prefix(s);
 }
 
 static int qp_decode_triple(char *s, char *d)