mhdr: -H to print file name

pull/2/head
Christian Neukirchen 8 years ago
parent bfe841eb1e
commit 7604589738

@ -1,4 +1,4 @@
.Dd July 28, 2016 .Dd August 17, 2016
.Dt MHDR 1 .Dt MHDR 1
.Os .Os
.Sh NAME .Sh NAME
@ -8,6 +8,7 @@
.Nm .Nm
.Op Fl h Ar header .Op Fl h Ar header
.Op Fl d .Op Fl d
.Op Fl H
.Op Fl M .Op Fl M
.Op Fl A | Fl D .Op Fl A | Fl D
.Op Ar msgs\ ... .Op Ar msgs\ ...
@ -32,6 +33,9 @@ Only print the values of the headers in the colon-separated list
.Ar header . .Ar header .
.It Fl d .It Fl d
Decode the headers according to RFC 2047. Decode the headers according to RFC 2047.
.It Fl H
Prefix all output lines with the file name of the message, separated
by a tab.
.It Fl M .It Fl M
Search for all occurrences of the headers Search for all occurrences of the headers
(default: only the first). (default: only the first).

@ -14,9 +14,11 @@
static char *hflag; static char *hflag;
static int Aflag; static int Aflag;
static int Dflag; static int Dflag;
static int Hflag;
static int Mflag; static int Mflag;
static int dflag; static int dflag;
static char *curfile;
static int status; static int status;
static void static void
@ -24,6 +26,9 @@ printhdr(char *hdr)
{ {
int uc = 1; int uc = 1;
if (Hflag)
printf("%s\t", curfile);
while (*hdr && *hdr != ':') { while (*hdr && *hdr != ':') {
putc(uc ? toupper(*hdr) : *hdr, stdout); putc(uc ? toupper(*hdr) : *hdr, stdout);
uc = (*hdr == '-'); uc = (*hdr == '-');
@ -57,6 +62,8 @@ print_addresses(char *s)
{ {
char *disp, *addr; char *disp, *addr;
while ((s = blaze822_addr(s, &disp, &addr))) { while ((s = blaze822_addr(s, &disp, &addr))) {
if (Hflag && (disp || addr))
printf("%s\t", curfile);
if (disp && addr) { if (disp && addr) {
if (dflag) { if (dflag) {
char d[4096]; char d[4096];
@ -94,6 +101,9 @@ print_header(char *v)
{ {
status = 0; status = 0;
if (Hflag && !Aflag)
printf("%s\t", curfile);
if (Aflag) if (Aflag)
print_addresses(v); print_addresses(v);
else if (Dflag) else if (Dflag)
@ -143,6 +153,8 @@ header(char *file)
while (*file == ' ' || *file == '\t') while (*file == ' ' || *file == '\t')
file++; file++;
curfile = file;
msg = blaze822(file); msg = blaze822(file);
if (!msg) if (!msg)
return; return;
@ -175,16 +187,17 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c; int c;
while ((c = getopt(argc, argv, "h:ADMd")) != -1) while ((c = getopt(argc, argv, "h:ADHMd")) != -1)
switch(c) { switch(c) {
case 'h': hflag = optarg; break; case 'h': hflag = optarg; break;
case 'A': Aflag = 1; break; case 'A': Aflag = 1; break;
case 'D': Dflag = 1; break; case 'D': Dflag = 1; break;
case 'H': Hflag = 1; break;
case 'M': Mflag = 1; break; case 'M': Mflag = 1; break;
case 'd': dflag = 1; break; case 'd': dflag = 1; break;
default: default:
fprintf(stderr, fprintf(stderr,
"Usage: mhdr [-h header] [-d] [-M] [-A|-D] [msgs...]\n"); "Usage: mhdr [-h header] [-d] [-H] [-M] [-A|-D] [msgs...]\n");
exit(2); exit(2);
} }

Loading…
Cancel
Save