cut: rename some variables to hopefully better names

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2024-12-10 02:15:25 +01:00
parent 808155ebf3
commit 1220b1519d

View file

@ -152,7 +152,8 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
puts(line); puts(line);
goto next_line; goto next_line;
} else { /* cut by fields */ } else { /* cut by fields */
unsigned uu = 0, start = 0, end = 0, out = 0; unsigned next = 0, start = 0, end = 0;
int first_print = 1;
int dcount = 0; int dcount = 0;
/* Blank line? Check -s (later check for -s does not catch empty lines) */ /* Blank line? Check -s (later check for -s does not catch empty lines) */
@ -168,11 +169,11 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
if (++cl_pos >= nlists) if (++cl_pos >= nlists)
break; break;
if (option_mask32 & OPT_NOSORT) if (option_mask32 & OPT_NOSORT)
start = dcount = uu = 0; start = dcount = next = 0;
end = 0; end = 0;
} }
/* End of current line? */ /* End of current line? */
if (uu == linelen) { if (next == linelen) {
/* If we've seen no delimiters, check -s */ /* If we've seen no delimiters, check -s */
if (cl_pos == 0 && dcount == 0 && !opt_REGEX) { if (cl_pos == 0 && dcount == 0 && !opt_REGEX) {
if (option_mask32 & OPT_SUPPRESS) if (option_mask32 & OPT_SUPPRESS)
@ -185,31 +186,36 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
if (opt_REGEX) { if (opt_REGEX) {
regmatch_t rr = {-1, -1}; regmatch_t rr = {-1, -1};
if (!regexec(&reg, line + uu, 1, &rr, REG_NOTBOL|REG_NOTEOL)) { if (!regexec(&reg, line + next, 1, &rr, REG_NOTBOL|REG_NOTEOL)) {
end = uu + rr.rm_so; end = next + rr.rm_so;
uu += rr.rm_eo; next += rr.rm_eo;
} else { } else {
uu = linelen; next = linelen;
continue; continue;
} }
} else { } else {
end = uu++; end = next++;
if (line[end] != *delim) if (line[end] != *delim)
continue; continue;
} }
/* Got delimiter. Loop if not yet within range. */ /* Got delimiter. Loop if not yet within range. */
if (dcount++ < cut_lists[cl_pos].startpos) { if (dcount++ < cut_lists[cl_pos].startpos) {
start = uu; start = next;
continue; continue;
} }
} }
if (end != start || !opt_REGEX) if (end != start || !opt_REGEX) {
printf("%s%.*s", out++ ? odelim : "", end - start, line + start); if (first_print) {
start = uu; first_print = 0;
printf("%.*s", end - start, line + start);
} else
printf("%s%.*s", odelim, end - start, line + start);
}
start = next;
if (dcount == 0) if (dcount == 0)
break; break;
} } /* byte loop */
} }
/* if we printed anything, finish with newline */ /* if we printed anything, finish with newline */
putchar('\n'); putchar('\n');