aboutsummaryrefslogtreecommitdiff
path: root/coreutils/cut.c
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils/cut.c')
-rw-r--r--coreutils/cut.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index 3ed264870..c24cf6611 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -92,7 +92,7 @@ static void parse_lists(char *lists)
92 } else { 92 } else {
93 s = strtoul(ntok, &junk, 10); 93 s = strtoul(ntok, &junk, 10);
94 if(*junk != '\0' || s < 0) 94 if(*junk != '\0' || s < 0)
95 error_msg_and_die("invalid byte or field list"); 95 bb_error_msg_and_die("invalid byte or field list");
96 96
97 /* account for the fact that arrays are zero based, while the user 97 /* account for the fact that arrays are zero based, while the user
98 * expects the first char on the line to be char # 1 */ 98 * expects the first char on the line to be char # 1 */
@@ -109,7 +109,7 @@ static void parse_lists(char *lists)
109 } else { 109 } else {
110 e = strtoul(ntok, &junk, 10); 110 e = strtoul(ntok, &junk, 10);
111 if(*junk != '\0' || e < 0) 111 if(*junk != '\0' || e < 0)
112 error_msg_and_die("invalid byte or field list"); 112 bb_error_msg_and_die("invalid byte or field list");
113 /* if the user specified and end position of 0, that means "til the 113 /* if the user specified and end position of 0, that means "til the
114 * end of the line */ 114 * end of the line */
115 if (e == 0) 115 if (e == 0)
@@ -121,7 +121,7 @@ static void parse_lists(char *lists)
121 121
122 /* if there's something left to tokenize, the user past an invalid list */ 122 /* if there's something left to tokenize, the user past an invalid list */
123 if (ltok) 123 if (ltok)
124 error_msg_and_die("invalid byte or field list"); 124 bb_error_msg_and_die("invalid byte or field list");
125 125
126 /* add the new list */ 126 /* add the new list */
127 cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists)); 127 cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
@@ -131,7 +131,7 @@ static void parse_lists(char *lists)
131 131
132 /* make sure we got some cut positions out of all that */ 132 /* make sure we got some cut positions out of all that */
133 if (nlists == 0) 133 if (nlists == 0)
134 error_msg_and_die("missing list of positions"); 134 bb_error_msg_and_die("missing list of positions");
135 135
136 /* now that the lists are parsed, we need to sort them to make life easier 136 /* now that the lists are parsed, we need to sort them to make life easier
137 * on us when it comes time to print the chars / fields / lines */ 137 * on us when it comes time to print the chars / fields / lines */
@@ -267,8 +267,7 @@ static void cut_file(FILE *file)
267 unsigned int linenum = 0; /* keep these zero-based to be consistent */ 267 unsigned int linenum = 0; /* keep these zero-based to be consistent */
268 268
269 /* go through every line in the file */ 269 /* go through every line in the file */
270 while ((line = get_line_from_file(file)) != NULL) { 270 while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
271 chomp(line);
272 271
273 /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */ 272 /* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
274 if (part == 'c' || part == 'b') 273 if (part == 'c' || part == 'b')
@@ -299,14 +298,14 @@ extern int cut_main(int argc, char **argv)
299 case 'f': 298 case 'f':
300 /* make sure they didn't ask for two types of lists */ 299 /* make sure they didn't ask for two types of lists */
301 if (part != 0) { 300 if (part != 0) {
302 error_msg_and_die("only one type of list may be specified"); 301 bb_error_msg_and_die("only one type of list may be specified");
303 } 302 }
304 part = (char)opt; 303 part = (char)opt;
305 parse_lists(optarg); 304 parse_lists(optarg);
306 break; 305 break;
307 case 'd': 306 case 'd':
308 if (strlen(optarg) > 1) { 307 if (strlen(optarg) > 1) {
309 error_msg_and_die("the delimiter must be a single character"); 308 bb_error_msg_and_die("the delimiter must be a single character");
310 } 309 }
311 delim = optarg[0]; 310 delim = optarg[0];
312 break; 311 break;
@@ -320,17 +319,17 @@ extern int cut_main(int argc, char **argv)
320 } 319 }
321 320
322 if (part == 0) { 321 if (part == 0) {
323 error_msg_and_die("you must specify a list of bytes, characters, or fields"); 322 bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
324 } 323 }
325 324
326 /* non-field (char or byte) cutting has some special handling */ 325 /* non-field (char or byte) cutting has some special handling */
327 if (part != 'f') { 326 if (part != 'f') {
328 if (supress_non_delimited_lines) { 327 if (supress_non_delimited_lines) {
329 error_msg_and_die("suppressing non-delimited lines makes sense" 328 bb_error_msg_and_die("suppressing non-delimited lines makes sense"
330 " only when operating on fields"); 329 " only when operating on fields");
331 } 330 }
332 if (delim != '\t' && part != 'f') { 331 if (delim != '\t' && part != 'f') {
333 error_msg_and_die("a delimiter may be specified only when operating on fields"); 332 bb_error_msg_and_die("a delimiter may be specified only when operating on fields");
334 } 333 }
335 } 334 }
336 335
@@ -344,7 +343,7 @@ extern int cut_main(int argc, char **argv)
344 int i; 343 int i;
345 FILE *file; 344 FILE *file;
346 for (i = optind; i < argc; i++) { 345 for (i = optind; i < argc; i++) {
347 file = wfopen(argv[i], "r"); 346 file = bb_wfopen(argv[i], "r");
348 if(file) { 347 if(file) {
349 cut_file(file); 348 cut_file(file);
350 fclose(file); 349 fclose(file);