* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include "busybox.h"
+#include "libbb.h"
+
+/* This is a NOEXEC applet. Be very careful! */
+
/* option vars */
-static const char optstring[] = "b:c:f:d:sn";
+static const char optstring[] ALIGN1 = "b:c:f:d:sn";
#define CUT_OPT_BYTE_FLGS (1<<0)
#define CUT_OPT_CHAR_FLGS (1<<1)
#define CUT_OPT_FIELDS_FLGS (1<<2)
unsigned int linenum = 0; /* keep these zero-based to be consistent */
/* go through every line in the file */
- while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
+ while ((line = xmalloc_getline(file)) != NULL) {
/* set up a list so we can keep track of what's been printed */
char * printed = xzalloc(strlen(line) * sizeof(char));
}
}
-static const char _op_on_field[] = " only when operating on fields";
+static const char _op_on_field[] ALIGN1 = " only when operating on fields";
+int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cut_main(int argc, char **argv)
{
char *sopt, *ltok;
opt_complementary = "b--bcf:c--bcf:f--bcf";
- getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok);
+ getopt32(argv, optstring, &sopt, &sopt, &sopt, <ok);
+// argc -= optind;
+ argv += optind;
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
- if (option_mask32 & BB_GETOPT_ERROR)
- bb_error_msg_and_die("only one type of list may be specified");
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
if (strlen(ltok) > 1) {
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
}
- /* argv[(optind)..(argc-1)] should be names of file to process. If no
+ /* argv[0..argc-1] should be names of file to process. If no
* files were specified or '-' was specified, take input from stdin.
* Otherwise, we process all the files specified. */
- if (argv[optind] == NULL
- || (argv[optind][0] == '-' && argv[optind][1] == '\0')) {
+ if (argv[0] == NULL || LONE_DASH(argv[0])) {
cut_file(stdin);
} else {
FILE *file;
- for (; optind < argc; optind++) {
- file = bb_wfopen(argv[optind], "r");
+ do {
+ file = fopen_or_warn(argv[0], "r");
if (file) {
cut_file(file);
fclose(file);
}
- }
+ } while (*++argv);
}
if (ENABLE_FEATURE_CLEAN_UP)
free(cut_lists);