Ejemplo n.º 1
0
/*
 * snippy-snip
 */
static void cut_file(FILE *file)
{
	char *line = NULL;
	unsigned int linenum = 0; /* keep these zero-based to be consistent */

	/* go through every line in the file */
	while ((line = get_line_from_file(file)) != NULL) {
		chomp(line);

		/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
		if (part == 'c' || part == 'b')
			cut_line_by_chars(line);

		/* cut based on fields */
		else if (part == 'f') {
			if (delim == '\n')
				cut_file_by_lines(line, linenum);
			else
				cut_line_by_fields(line);
		}

		linenum++;
		free(line);
	}
}
Ejemplo n.º 2
0
Archivo: cut.c Proyecto: K0T0LI/busybox
/*
 * snippy-snip
 */
static void cut_file(FILE *file)
{
	char *line = NULL;
	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) {

		/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
		if ((part & (OPT_CHAR_FLGS | OPT_BYTE_FLGS)))
			cut_line_by_chars(line);

		/* cut based on fields */
		else {
			if (delim == '\n')
				cut_file_by_lines(line, linenum);
			else
				cut_line_by_fields(line);
		}

		linenum++;
		free(line);
	}
}