diff options
author | Jim Meyering <jim@meyering.net> | 2003-07-22 13:00:45 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-07-22 13:00:45 +0000 |
commit | 3fe298f13f3665b2f1a083161928163c3848bfc8 (patch) | |
tree | a9affd3dba2121994e2d941547a0ea682eeb962d /src | |
parent | c55974d115e2430acab42cf06b004c9f7e83b4e2 (diff) | |
download | coreutils-3fe298f13f3665b2f1a083161928163c3848bfc8.tar.xz |
(set_fields): Mark all selected indices before trying to
determine range endpoints.
Diffstat (limited to 'src')
-rw-r--r-- | src/cut.c | 39 |
1 files changed, 22 insertions, 17 deletions
@@ -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; } } |