diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-21 00:43:45 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-21 00:43:45 +0100 |
commit | 14f57f5357cb674b88e7cdaff6267bf9d84c6b80 (patch) | |
tree | 2f90b79cb88bc02a5da30c058818ad131ac04026 | |
parent | 1ea89fa98a7c4b1b6924f136963c91caf5a5dccb (diff) | |
download | busybox-w32-14f57f5357cb674b88e7cdaff6267bf9d84c6b80.tar.gz busybox-w32-14f57f5357cb674b88e7cdaff6267bf9d84c6b80.tar.bz2 busybox-w32-14f57f5357cb674b88e7cdaff6267bf9d84c6b80.zip |
cut: code shrinkbusybox
move "linenum" manipulations to the one place where it is used.
function old new delta
cut_main 1373 1360 -13
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/cut.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index 93b58b493..d81f36bcd 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -143,15 +143,15 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
143 | } else if (!opt_REGEX && *delim == '\n') { | 143 | } else if (!opt_REGEX && *delim == '\n') { |
144 | unsigned spos = cut_list[cl_pos].startpos; | 144 | unsigned spos = cut_list[cl_pos].startpos; |
145 | 145 | ||
146 | linenum++; | ||
146 | /* get out if we have no more ranges to process or if the lines | 147 | /* get out if we have no more ranges to process or if the lines |
147 | * are lower than what we're interested in */ | 148 | * are lower than what we're interested in */ |
148 | if ((linenum < spos) || END_OF_LIST(cut_list[cl_pos])) | 149 | if (linenum <= spos || END_OF_LIST(cut_list[cl_pos])) |
149 | goto next_line; | 150 | goto next_line; |
150 | 151 | ||
151 | /* if the line we're looking for is lower than the one we were | 152 | /* if the line we're looking for is lower than the one we were |
152 | * passed, it means we displayed it already, so move on */ | 153 | * passed, it means we displayed it already, so move on */ |
153 | while (spos < linenum) { | 154 | while (++spos < linenum) { |
154 | spos++; | ||
155 | /* go to the next list if we're at the end of this one */ | 155 | /* go to the next list if we're at the end of this one */ |
156 | if (spos > cut_list[cl_pos].endpos) { | 156 | if (spos > cut_list[cl_pos].endpos) { |
157 | cl_pos++; | 157 | cl_pos++; |
@@ -161,7 +161,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
161 | spos = cut_list[cl_pos].startpos; | 161 | spos = cut_list[cl_pos].startpos; |
162 | /* get out if the current line is lower than the one | 162 | /* get out if the current line is lower than the one |
163 | * we just became interested in */ | 163 | * we just became interested in */ |
164 | if (linenum < spos) | 164 | if (linenum <= spos) |
165 | goto next_line; | 165 | goto next_line; |
166 | } | 166 | } |
167 | } | 167 | } |
@@ -280,7 +280,6 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
280 | /* if we printed anything, finish with newline */ | 280 | /* if we printed anything, finish with newline */ |
281 | putchar('\n'); | 281 | putchar('\n'); |
282 | next_line: | 282 | next_line: |
283 | linenum++; | ||
284 | free(line); | 283 | free(line); |
285 | } /* while (got line) */ | 284 | } /* while (got line) */ |
286 | 285 | ||
@@ -399,7 +398,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
399 | //if (nranges == 0) | 398 | //if (nranges == 0) |
400 | // bb_simple_error_msg_and_die("missing list of positions"); | 399 | // bb_simple_error_msg_and_die("missing list of positions"); |
401 | //^^^ this is impossible since one of -bcfF is required, | 400 | //^^^ this is impossible since one of -bcfF is required, |
402 | // they populate LIST with non-empty string and when it is parsed, | 401 | // they populate LIST with non-NULL string and when it is parsed, |
403 | // cut_list[] gets at least one element. | 402 | // cut_list[] gets at least one element. |
404 | 403 | ||
405 | /* now that the lists are parsed, we need to sort them to make life | 404 | /* now that the lists are parsed, we need to sort them to make life |