mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 16:31:24 +00:00
Applied patch from Brent Priddy <brent.priddy@adtran.com> to handle the
special-case of using newlines as field delimiters.
This commit is contained in:
parent
9028e2c96a
commit
0053087587
@ -102,10 +102,10 @@ static void decompose_list(const char *list)
|
||||
static void cut_file(FILE *file)
|
||||
{
|
||||
char *line;
|
||||
unsigned int cr_hits = 0;
|
||||
|
||||
/* go through every line in the file */
|
||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||
|
||||
/* cut based on chars/bytes */
|
||||
if (part == 'c' || part == 'b') {
|
||||
int i;
|
||||
@ -129,6 +129,17 @@ static void cut_file(FILE *file)
|
||||
char *start = line;
|
||||
unsigned int delims_hit = 0;
|
||||
|
||||
if (delim == '\n') {
|
||||
cr_hits++;
|
||||
if (cr_hits >= startpos && cr_hits <= endpos) {
|
||||
while (*start && *start != '\n') {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
|
||||
delims_hit++;
|
||||
if (delims_hit == (startpos - 1)) {
|
||||
@ -138,6 +149,7 @@ static void cut_file(FILE *file)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* we didn't hit any delimeters */
|
||||
if (delims_hit == 0 && !supress_non_delimited_lines) {
|
||||
fputs(line, stdout);
|
||||
@ -163,6 +175,7 @@ static void cut_file(FILE *file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int cut_main(int argc, char **argv)
|
||||
{
|
||||
|
15
cut.c
15
cut.c
@ -102,10 +102,10 @@ static void decompose_list(const char *list)
|
||||
static void cut_file(FILE *file)
|
||||
{
|
||||
char *line;
|
||||
unsigned int cr_hits = 0;
|
||||
|
||||
/* go through every line in the file */
|
||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||
|
||||
/* cut based on chars/bytes */
|
||||
if (part == 'c' || part == 'b') {
|
||||
int i;
|
||||
@ -129,6 +129,17 @@ static void cut_file(FILE *file)
|
||||
char *start = line;
|
||||
unsigned int delims_hit = 0;
|
||||
|
||||
if (delim == '\n') {
|
||||
cr_hits++;
|
||||
if (cr_hits >= startpos && cr_hits <= endpos) {
|
||||
while (*start && *start != '\n') {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
|
||||
delims_hit++;
|
||||
if (delims_hit == (startpos - 1)) {
|
||||
@ -138,6 +149,7 @@ static void cut_file(FILE *file)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* we didn't hit any delimeters */
|
||||
if (delims_hit == 0 && !supress_non_delimited_lines) {
|
||||
fputs(line, stdout);
|
||||
@ -163,6 +175,7 @@ static void cut_file(FILE *file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int cut_main(int argc, char **argv)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user