magrep: add -h, which is like -p but doesn't print the file name.

pull/134/merge
Leah Neukirchen 6 years ago
parent c818ab8645
commit 1336ea5512

@ -14,6 +14,7 @@
static int aflag;
static int cflag;
static int dflag;
static int hflag;
static int iflag;
static int lflag;
static int oflag;
@ -42,6 +43,8 @@ match(char *file, char *hdr, char *s)
}
if (pflag)
printf("%s: %s: ", file, hdr);
else if (hflag)
printf("%s: ", hdr);
printf("%.*s\n", len, s);
s += len;
matched++;
@ -52,9 +55,12 @@ match(char *file, char *hdr, char *s)
exit(0);
matches++;
if (!cflag) {
printf("%s", file);
if (vflag || !hflag)
printf("%s", file);
if (pflag && !vflag)
printf(": %s: %s", hdr, s);
else if (hflag && !vflag)
printf("%s: %s", hdr, s);
putchar('\n');
}
if (mflag && matches >= mflag)
@ -82,7 +88,7 @@ match_part(int depth, struct message *msg, char *body, size_t bodylen)
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0) {
if (pflag && !cflag && !oflag && !vflag) {
if ((hflag || pflag) && !cflag && !oflag && !vflag) {
char *s, *p;
for (p = s = body; p < body+bodylen+1; p++) {
if (*p == '\r' || *p == '\n') {
@ -183,11 +189,12 @@ int
main(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "acdilm:opqv")) != -1)
while ((c = getopt(argc, argv, "acdhilm:opqv")) != -1)
switch (c) {
case 'a': aflag = 1; break;
case 'c': cflag = 1; break;
case 'd': dflag = 1; break;
case 'h': hflag = 1; break;
case 'i': iflag = REG_ICASE; break;
case 'l': lflag = 1; break;
case 'm': mflag = atol(optarg); break;
@ -198,7 +205,7 @@ main(int argc, char *argv[])
default:
usage:
fprintf(stderr,
"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
"Usage: magrep [-c|-h|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
exit(2);
}

@ -1,4 +1,4 @@
.Dd July 7, 2018
.Dd September 10, 2018
.Dt MAGREP 1
.Os
.Sh NAME
@ -6,7 +6,7 @@
.Nd search messages matching a pattern
.Sh SYNOPSIS
.Nm
.Op Fl c | Fl q | Fl m Ar max
.Op Fl c | Fl h | Fl o | Fl p | Fl q | Fl m Ar max
.Op Fl v
.Op Fl i
.Op Fl l
@ -75,6 +75,10 @@ count non-matching headers instead.
Decode the
.Ar header
according to RFC 2047 prior to searching.
.It Fl h
Like
.Fl p
but do not print the file name.
.It Fl i
Match
.Ar regex

Loading…
Cancel
Save