coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] seq cleanup


From: Dmitry Bogatov
Subject: [PATCH] seq cleanup
Date: Sat, 1 Dec 2012 22:55:37 +0400
User-agent: Mutt/1.5.21 (2010-09-15)

Here is simple patch that allow reduce indentation in `print_numbers`
in `seq.c` by one level to improve readability.

--
Best regards, Dmitry Bogatov <address@hidden>,
        GNU Thales maintainer and netiquette guardian.
GPG: D1E0591E0037BDCCBEE56002788BE01254B7F00D

diff --git a/src/seq.c b/src/seq.c
index 9c2c51f..01b5927 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -256,60 +256,61 @@ print_numbers (char const *fmt, struct layout layout,
 {
   bool out_of_range = (step < 0 ? first < last : last < first);

-  if (! out_of_range)
-    {
-      long double x = first;
-      long double i;
+  if (out_of_range)
+    return;
+
+  long double x = first;
+  long double i;

-      for (i = 1; ; i++)
+  for (i = 1; ; i++)
+    {
+      long double x0 = x;
+      printf (fmt, x);
+      if (out_of_range)
+        break;
+      x = first + i * step;
+      out_of_range = (step < 0 ? x < last : last < x);
+
+      if (out_of_range)
         {
-          long double x0 = x;
-          printf (fmt, x);
-          if (out_of_range)
-            break;
-          x = first + i * step;
-          out_of_range = (step < 0 ? x < last : last < x);
-
-          if (out_of_range)
+          /* If the number just past LAST prints as a value equal
+             to LAST, and prints differently from the previous
+             number, then print the number.  This avoids problems
+             with rounding.  For example, with the x86 it causes
+             "seq 0 0.000001 0.000003" to print 0.000003 instead
+             of stopping at 0.000002.  */
+
+          bool print_extra_number = false;
+          long double x_val;
+          char *x_str;
+          int x_strlen;
+          setlocale (LC_NUMERIC, "C");
+          x_strlen = asprintf (&x_str, fmt, x);
+          setlocale (LC_NUMERIC, "");
+          if (x_strlen < 0)
+            xalloc_die ();
+          x_str[x_strlen - layout.suffix_len] = '\0';
+
+          if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
+              && x_val == last)
             {
-              /* If the number just past LAST prints as a value equal
-                 to LAST, and prints differently from the previous
-                 number, then print the number.  This avoids problems
-                 with rounding.  For example, with the x86 it causes
-                 "seq 0 0.000001 0.000003" to print 0.000003 instead
-                 of stopping at 0.000002.  */
-
-              bool print_extra_number = false;
-              long double x_val;
-              char *x_str;
-              int x_strlen;
-              setlocale (LC_NUMERIC, "C");
-              x_strlen = asprintf (&x_str, fmt, x);
-              setlocale (LC_NUMERIC, "");
-              if (x_strlen < 0)
+              char *x0_str = NULL;
+              if (asprintf (&x0_str, fmt, x0) < 0)
                 xalloc_die ();
-              x_str[x_strlen - layout.suffix_len] = '\0';
-
-              if (xstrtold (x_str + layout.prefix_len, NULL, &x_val, c_strtold)
-                  && x_val == last)
-                {
-                  char *x0_str = NULL;
-                  if (asprintf (&x0_str, fmt, x0) < 0)
-                    xalloc_die ();
-                  print_extra_number = !STREQ (x0_str, x_str);
-                  free (x0_str);
-                }
-
-              free (x_str);
-              if (! print_extra_number)
-                break;
+              print_extra_number = !STREQ (x0_str, x_str);
+              free (x0_str);
             }

-          fputs (separator, stdout);
+          free (x_str);
+          if (! print_extra_number)
+            break;
         }

-      fputs (terminator, stdout);
+      fputs (separator, stdout);
     }
+
+  fputs (terminator, stdout);
+
 }

 /* Return the default format given FIRST, STEP, and LAST.  */

Attachment: pgpCPy5dOKM51.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]