]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(set_fields): Mark all selected indices before trying to
authorJim Meyering <jim@meyering.net>
Tue, 22 Jul 2003 13:00:45 +0000 (13:00 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 22 Jul 2003 13:00:45 +0000 (13:00 +0000)
determine range endpoints.

src/cut.c

index 90190aee07c0d8cc44c3443b0671d094133c737f..cb3b7c57de12b239c58eea31cf17abccb873553e 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -452,29 +452,34 @@ set_fields (const char *fieldstr)
   /* Set the array entries corresponding to integers in the ranges of RP.  */
   for (i = 0; i < n_rp; i++)
     {
-      unsigned int j = rp[i].lo;
+      unsigned int j;
+      for (j = rp[i].lo; j <= rp[i].hi; j++)
+       {
+         printable_field[j] = 1;
+       }
+    }
 
-      /* Mark the first position of each field or range with a sentinel,
-        but not if it's already part of another range.  */
-      if (j <= rp[i].hi && ! printable_field[j])
+  if (output_delimiter_specified)
+    {
+      /* Record the range-start indices.  */
+      for (i = 0; i < n_rp; i++)
        {
-         if (output_delimiter_specified)
+         unsigned int j = rp[i].lo;
+         for (j = rp[i].lo; j <= rp[i].hi; j++)
            {
-             /* Remember that `j' is a range-start index.  */
-             void *ent_from_table = hash_insert (range_start_ht, (void*) j);
-             if (ent_from_table == NULL)
+             if (0 < j && printable_field[j] && !printable_field[j - 1])
                {
-                 /* Insertion failed due to lack of memory.  */
-                 xalloc_die ();
+                 /* Remember that `j' is a range-start index.  */
+                 void *ent_from_table = hash_insert (range_start_ht,
+                                                     (void*) j);
+                 if (ent_from_table == NULL)
+                   {
+                     /* Insertion failed due to lack of memory.  */
+                     xalloc_die ();
+                   }
+                 assert ((unsigned int) ent_from_table == j);
                }
-             assert ((unsigned int) ent_from_table == j);
            }
-         printable_field[j] = 1;
-       }
-
-      for (++j; j <= rp[i].hi; j++)
-       {
-         printable_field[j] = 1;
        }
     }