618 |
fwrite (p, 1, buf + sizeof buf - p, stdout); |
fwrite (p, 1, buf + sizeof buf - p, stdout); |
619 |
} |
} |
620 |
|
|
621 |
|
/* Print a whole line head (filename, line, byte). */ |
622 |
static void |
static void |
623 |
prline (char const *beg, char const *lim, int sep) |
print_line_head (char const *beg, char const *lim, int sep) |
624 |
{ |
{ |
625 |
if (out_file) |
if (out_file) |
626 |
printf ("%s%c", filename, sep & filename_mask); |
printf ("%s%c", filename, sep & filename_mask); |
627 |
if (out_line) |
if (out_line) |
628 |
{ |
{ |
629 |
nlscan (beg); |
if (lastnl < lim) |
630 |
totalnl = add_count (totalnl, 1); |
{ |
631 |
|
nlscan (beg); |
632 |
|
totalnl = add_count (totalnl, 1); |
633 |
|
lastnl = lim; |
634 |
|
} |
635 |
print_offset_sep (totalnl, sep); |
print_offset_sep (totalnl, sep); |
|
lastnl = lim; |
|
636 |
} |
} |
637 |
if (out_byte) |
if (out_byte) |
638 |
{ |
{ |
642 |
#endif |
#endif |
643 |
print_offset_sep (pos, sep); |
print_offset_sep (pos, sep); |
644 |
} |
} |
645 |
if (only_matching) |
} |
646 |
|
|
647 |
|
static void |
648 |
|
prline (char const *beg, char const *lim, int sep) |
649 |
|
{ |
650 |
|
if (!only_matching) |
651 |
|
print_line_head(beg, lim, sep); |
652 |
|
else |
653 |
{ |
{ |
654 |
size_t match_size; |
size_t match_size; |
655 |
size_t match_offset; |
size_t match_offset; |
670 |
break; |
break; |
671 |
if (match_size == 0) |
if (match_size == 0) |
672 |
break; |
break; |
673 |
|
print_line_head(b, lim, sep); |
674 |
PR_SGR_START_IF(grep_color); |
PR_SGR_START_IF(grep_color); |
675 |
fwrite(b, sizeof (char), match_size, stdout); |
fwrite(b, sizeof (char), match_size, stdout); |
676 |
PR_SGR_END_IF(grep_color); |
PR_SGR_END_IF(grep_color); |
692 |
break; |
break; |
693 |
if (match_size == 0) |
if (match_size == 0) |
694 |
break; |
break; |
695 |
|
print_line_head(b, lim, sep); |
696 |
PR_SGR_START_IF(grep_color); |
PR_SGR_START_IF(grep_color); |
697 |
fwrite(b, sizeof (char), match_size, stdout); |
fwrite(b, sizeof (char), match_size, stdout); |
698 |
PR_SGR_END_IF(grep_color); |
PR_SGR_END_IF(grep_color); |