diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-10 01:44:13 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-12-10 01:44:13 +0100 |
| commit | ad12ab439b5d0383ac4ebe41479b694df0b2e70d (patch) | |
| tree | 07eeef386bf40c9c90bd7ef91a06c5069bf41812 /coreutils | |
| parent | 73e9d25d7503896e94b5c00093a77b33d1a17a0d (diff) | |
| download | busybox-w32-ad12ab439b5d0383ac4ebe41479b694df0b2e70d.tar.gz busybox-w32-ad12ab439b5d0383ac4ebe41479b694df0b2e70d.tar.bz2 busybox-w32-ad12ab439b5d0383ac4ebe41479b694df0b2e70d.zip | |
cut: localize 'spos' variable, convert !NUMVAR to NUMVAR == 0
This imporves readability
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/cut.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index 48f3656b4..e81c6fecb 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
| @@ -92,7 +92,6 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 92 | char *line; | 92 | char *line; |
| 93 | unsigned linenum = 0; /* keep these zero-based to be consistent */ | 93 | unsigned linenum = 0; /* keep these zero-based to be consistent */ |
| 94 | regex_t reg; | 94 | regex_t reg; |
| 95 | int spos; | ||
| 96 | 95 | ||
| 97 | if (opt_REGEX) | 96 | if (opt_REGEX) |
| 98 | xregcomp(®, delim, REG_EXTENDED); | 97 | xregcomp(®, delim, REG_EXTENDED); |
| @@ -110,6 +109,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 110 | if (option_mask32 & (OPT_CHAR | OPT_BYTE)) { | 109 | if (option_mask32 & (OPT_CHAR | OPT_BYTE)) { |
| 111 | /* print the chars specified in each cut list */ | 110 | /* print the chars specified in each cut list */ |
| 112 | for (; cl_pos < nlists; cl_pos++) { | 111 | for (; cl_pos < nlists; cl_pos++) { |
| 112 | int spos; | ||
| 113 | for (spos = cut_lists[cl_pos].startpos; spos < linelen;) { | 113 | for (spos = cut_lists[cl_pos].startpos; spos < linelen;) { |
| 114 | if (!printed[spos]) { | 114 | if (!printed[spos]) { |
| 115 | printed[spos] = 'X'; | 115 | printed[spos] = 'X'; |
| @@ -121,7 +121,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 121 | } | 121 | } |
| 122 | } | 122 | } |
| 123 | } else if (*delim == '\n') { /* cut by lines */ | 123 | } else if (*delim == '\n') { /* cut by lines */ |
| 124 | spos = cut_lists[cl_pos].startpos; | 124 | int spos = cut_lists[cl_pos].startpos; |
| 125 | 125 | ||
| 126 | /* get out if we have no more lists to process or if the lines | 126 | /* get out if we have no more lists to process or if the lines |
| 127 | * are lower than what we're interested in */ | 127 | * are lower than what we're interested in */ |
| @@ -173,7 +173,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 173 | /* End of current line? */ | 173 | /* End of current line? */ |
| 174 | if (uu == linelen) { | 174 | if (uu == linelen) { |
| 175 | /* If we've seen no delimiters, check -s */ | 175 | /* If we've seen no delimiters, check -s */ |
| 176 | if (!cl_pos && !dcount && !opt_REGEX) { | 176 | if (cl_pos == 0 && dcount == 0 && !opt_REGEX) { |
| 177 | if (option_mask32 & OPT_SUPPRESS) | 177 | if (option_mask32 & OPT_SUPPRESS) |
| 178 | goto next_line; | 178 | goto next_line; |
| 179 | } else if (dcount < cut_lists[cl_pos].startpos) | 179 | } else if (dcount < cut_lists[cl_pos].startpos) |
| @@ -206,7 +206,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim, | |||
| 206 | if (end != start || !opt_REGEX) | 206 | if (end != start || !opt_REGEX) |
| 207 | printf("%s%.*s", out++ ? odelim : "", end - start, line + start); | 207 | printf("%s%.*s", out++ ? odelim : "", end - start, line + start); |
| 208 | start = uu; | 208 | start = uu; |
| 209 | if (!dcount) | 209 | if (dcount == 0) |
| 210 | break; | 210 | break; |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| @@ -239,7 +239,8 @@ int cut_main(int argc UNUSED_PARAM, char **argv) | |||
| 239 | ); | 239 | ); |
| 240 | if (!delim || !*delim) | 240 | if (!delim || !*delim) |
| 241 | delim = (opt & OPT_REGEX) ? "[[:space:]]+" : "\t"; | 241 | delim = (opt & OPT_REGEX) ? "[[:space:]]+" : "\t"; |
| 242 | if (!odelim) odelim = (opt & OPT_REGEX) ? " " : delim; | 242 | if (!odelim) |
| 243 | odelim = (opt & OPT_REGEX) ? " " : delim; | ||
| 243 | 244 | ||
| 244 | // argc -= optind; | 245 | // argc -= optind; |
| 245 | argv += optind; | 246 | argv += optind; |
