Exemple #1
0
int main(int argc, char **argv){
	#if DBG
		int l;
	#endif
	parse_args(argc,argv);
	if (OPTL){
		if(DEBUG){printf("case-wise subsetting is requested\n\n");}
		parse_list_g(RSSET);
	}
	if ((RECNUM>0) && (RECLEN<1)) {
		/* no reclen specified must determine reclength from data*/
		char input[NBUFSIZ];

		fgets(input, NBUFSIZ, stdin);
		/* contents of input after fgets: data themselve + '\n' + '\0'*/
		RECLEN = strlen(input)-1;/*RECLEN includes a new line character */
		if (RECLEN<1) {
		   fprintf(stderr,"can't determine record length\n");
		   usage();
		}
		/*
		offset=ftell(stdin);
		if(DEBUG){printf("++++++ ftell=%d ++++++\n",offset);}
		*/
		/* move back the origin of th stream */
		/*
		fseek(stdin, 0,SEEK_SET);
		*/
		strcpy ( LINE_BUFFERED, input ); 
		/*bytes_buffered = RECLEN; */
		parse_lists(LINE);
		cut_col(stdin);
	} else {
		parse_lists(LINE);
	}
	if (OPTC==1) {
		cut_col(stdin);
		#if DBG
			if (DEBUG){
				printf("\ncontents of args array\n");
				for (l=0;args[l] != 0 ;l++){
					printf("%d-%d\n",l, args[l]);
				}
				printf("\n");
			}
		#endif
	}  else {
		if (PIDNO == -1) {
			cut_fields(stdin);
		} else if (PIDNO >= 0) {
			fcut_fields(stdin, PIDNO);
		}
	}
	if(DEBUG){printf("last row number=%d\n", crrntRN);}
	return(0);
}
Exemple #2
0
extern int cut_main(int argc, char **argv)
{
	unsigned long opt;
	char *sopt, *sdopt;

	bb_opt_complementally = "b--bcf:c--bcf:f--bcf";
	opt = bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &sdopt);
	part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS);
	if(part == 0)
		bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
	if(opt & BB_GETOPT_ERROR)
		bb_error_msg_and_die("only one type of list may be specified");
	parse_lists(sopt);
	if((opt & (OPT_DELIM_FLGS))) {
		if (strlen(sdopt) > 1) {
			bb_error_msg_and_die("the delimiter must be a single character");
		}
		delim = sdopt[0];
	}
	supress_non_delimited_lines = opt & OPT_SUPRESS_FLGS;

	/*  non-field (char or byte) cutting has some special handling */
	if (part != OPT_FIELDS_FLGS) {
		if (supress_non_delimited_lines) {
			bb_error_msg_and_die("suppressing non-delimited lines makes sense"
					" only when operating on fields");
		}
		if (delim != '\t') {
			bb_error_msg_and_die("a delimiter may be specified only when operating on fields");
		}
	}

	/* argv[(optind)..(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 || (strcmp(argv[optind], "-") == 0)) {
		cut_file(stdin);
	}
	else {
		int i;
		FILE *file;
		for (i = optind; i < argc; i++) {
			file = bb_wfopen(argv[i], "r");
			if(file) {
				cut_file(file);
				fclose(file);
			}
		}
	}

	return EXIT_SUCCESS;
}
Exemple #3
0
extern int cut_main(int argc, char **argv)
{
	int opt;

	while ((opt = getopt(argc, argv, "b:c:d:f:ns")) > 0) {
		switch (opt) {
			case 'b':
			case 'c':
			case 'f':
				/* make sure they didn't ask for two types of lists */
				if (part != 0) {
					error_msg_and_die("only one type of list may be specified");
				}
				part = (char)opt;
				parse_lists(optarg);
				break;
			case 'd':
				if (strlen(optarg) > 1) {
					error_msg_and_die("the delimiter must be a single character");
				}
				delim = optarg[0];
				break;
			case 'n':
				/* no-op */
				break;
			case 's':
				supress_non_delimited_lines++;
				break;
		}
	}

	if (part == 0) {
		error_msg_and_die("you must specify a list of bytes, characters, or fields");
	}

	/*  non-field (char or byte) cutting has some special handling */
	if (part != 'f') {
		if (supress_non_delimited_lines) {
			error_msg_and_die("suppressing non-delimited lines makes sense"
					" only when operating on fields");
		}
		if (delim != '\t' && part != 'f') {
			error_msg_and_die("a delimiter may be specified only when operating on fields");
		}
	}

	/* argv[(optind)..(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 || (strcmp(argv[optind], "-") == 0)) {
		cut_file(stdin);
	}
	else {
		int i;
		FILE *file;
		for (i = optind; i < argc; i++) {
			file = wfopen(argv[i], "r");
			if(file) {
				cut_file(file);
				fclose(file);
			}
		}
	}

	return EXIT_SUCCESS;
}