aboutsummaryrefslogtreecommitdiff
path: root/coreutils/cut.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/cut.c')
-rw-r--r--coreutils/cut.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index d129f9b9d..b7fe11126 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -152,11 +152,18 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
152 unsigned uu = 0, start = 0, end = 0, out = 0; 152 unsigned uu = 0, start = 0, end = 0, out = 0;
153 int dcount = 0; 153 int dcount = 0;
154 154
155 /* Blank line? Check -s (later check for -s does not catch empty lines) */
156 if (linelen == 0) {
157 if (option_mask32 & CUT_OPT_SUPPRESS_FLGS)
158 goto next_line;
159 }
160
155 /* Loop through bytes, finding next delimiter */ 161 /* Loop through bytes, finding next delimiter */
156 for (;;) { 162 for (;;) {
157 /* End of current range? */ 163 /* End of current range? */
158 if (end == linelen || dcount > cut_lists[cl_pos].endpos) { 164 if (end == linelen || dcount > cut_lists[cl_pos].endpos) {
159 if (++cl_pos >= nlists) break; 165 if (++cl_pos >= nlists)
166 break;
160 if (option_mask32 & CUT_OPT_NOSORT_FLGS) 167 if (option_mask32 & CUT_OPT_NOSORT_FLGS)
161 start = dcount = uu = 0; 168 start = dcount = uu = 0;
162 end = 0; 169 end = 0;
@@ -175,15 +182,18 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
175 if (shoe) { 182 if (shoe) {
176 regmatch_t rr = {-1, -1}; 183 regmatch_t rr = {-1, -1};
177 184
178 if (!regexec(&reg, line+uu, 1, &rr, REG_NOTBOL|REG_NOTEOL)) { 185 if (!regexec(&reg, line + uu, 1, &rr, REG_NOTBOL|REG_NOTEOL)) {
179 end = uu + rr.rm_so; 186 end = uu + rr.rm_so;
180 uu += rr.rm_eo; 187 uu += rr.rm_eo;
181 } else { 188 } else {
182 uu = linelen; 189 uu = linelen;
183 continue; 190 continue;
184 } 191 }
185 } else if (line[end = uu++] != *delim) 192 } else {
186 continue; 193 end = uu++;
194 if (line[end] != *delim)
195 continue;
196 }
187 197
188 /* Got delimiter. Loop if not yet within range. */ 198 /* Got delimiter. Loop if not yet within range. */
189 if (dcount++ < cut_lists[cl_pos].startpos) { 199 if (dcount++ < cut_lists[cl_pos].startpos) {
@@ -192,7 +202,7 @@ static void cut_file(FILE *file, const char *delim, const char *odelim,
192 } 202 }
193 } 203 }
194 if (end != start || !shoe) 204 if (end != start || !shoe)
195 printf("%s%.*s", out++ ? odelim : "", end-start, line + start); 205 printf("%s%.*s", out++ ? odelim : "", end - start, line + start);
196 start = uu; 206 start = uu;
197 if (!dcount) 207 if (!dcount)
198 break; 208 break;