diff options
Diffstat (limited to 'coreutils/cut.c')
-rw-r--r-- | coreutils/cut.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c index a538e3d20..a72b2c29a 100644 --- a/coreutils/cut.c +++ b/coreutils/cut.c | |||
@@ -168,6 +168,8 @@ int cut_main(int argc, char **argv) | |||
168 | 168 | ||
169 | opt_complementary = "b--bcf:c--bcf:f--bcf"; | 169 | opt_complementary = "b--bcf:c--bcf:f--bcf"; |
170 | getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); | 170 | getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok); |
171 | // argc -= optind; | ||
172 | argv += optind; | ||
171 | if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) | 173 | if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS))) |
172 | bb_error_msg_and_die("expected a list of bytes, characters, or fields"); | 174 | bb_error_msg_and_die("expected a list of bytes, characters, or fields"); |
173 | if (option_mask32 & BB_GETOPT_ERROR) | 175 | if (option_mask32 & BB_GETOPT_ERROR) |
@@ -262,22 +264,21 @@ int cut_main(int argc, char **argv) | |||
262 | qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc); | 264 | qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc); |
263 | } | 265 | } |
264 | 266 | ||
265 | /* argv[(optind)..(argc-1)] should be names of file to process. If no | 267 | /* argv[0..argc-1] should be names of file to process. If no |
266 | * files were specified or '-' was specified, take input from stdin. | 268 | * files were specified or '-' was specified, take input from stdin. |
267 | * Otherwise, we process all the files specified. */ | 269 | * Otherwise, we process all the files specified. */ |
268 | if (argv[optind] == NULL | 270 | if (argv[0] == NULL || LONE_DASH(argv[0])) { |
269 | || (argv[optind][0] == '-' && argv[optind][1] == '\0')) { | ||
270 | cut_file(stdin); | 271 | cut_file(stdin); |
271 | } else { | 272 | } else { |
272 | FILE *file; | 273 | FILE *file; |
273 | 274 | ||
274 | for (; optind < argc; optind++) { | 275 | do { |
275 | file = fopen_or_warn(argv[optind], "r"); | 276 | file = fopen_or_warn(argv[0], "r"); |
276 | if (file) { | 277 | if (file) { |
277 | cut_file(file); | 278 | cut_file(file); |
278 | fclose(file); | 279 | fclose(file); |
279 | } | 280 | } |
280 | } | 281 | } while (*++argv); |
281 | } | 282 | } |
282 | if (ENABLE_FEATURE_CLEAN_UP) | 283 | if (ENABLE_FEATURE_CLEAN_UP) |
283 | free(cut_lists); | 284 | free(cut_lists); |