aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-17 15:45:09 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-17 15:45:09 +0200
commit7604589738034f0ad9eae9bfc804433e3edd5dbc (patch)
tree23d8771850044392af9d5738d0607dfc1be914e7
parentbfe841eb1e433effa71b42b43206fef78d6e2e2c (diff)
downloadmblaze-7604589738034f0ad9eae9bfc804433e3edd5dbc.tar.gz
mhdr: -H to print file name
-rw-r--r--man/mhdr.16
-rw-r--r--mhdr.c17
2 files changed, 20 insertions, 3 deletions
diff --git a/man/mhdr.1 b/man/mhdr.1
index b7a064e..efd4fbf 100644
--- a/man/mhdr.1
+++ b/man/mhdr.1
@@ -1,4 +1,4 @@
-.Dd July 28, 2016
+.Dd August 17, 2016
.Dt MHDR 1
.Os
.Sh NAME
@@ -8,6 +8,7 @@
.Nm
.Op Fl h Ar header
.Op Fl d
+.Op Fl H
.Op Fl M
.Op Fl A | Fl D
.Op Ar msgs\ ...
@@ -32,6 +33,9 @@ Only print the values of the headers in the colon-separated list
.Ar header .
.It Fl d
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
Search for all occurrences of the headers
(default: only the first).
diff --git a/mhdr.c b/mhdr.c
index 955c0f2..25f5a89 100644
--- a/mhdr.c
+++ b/mhdr.c
@@ -14,9 +14,11 @@
static char *hflag;
static int Aflag;
static int Dflag;
+static int Hflag;
static int Mflag;
static int dflag;
+static char *curfile;
static int status;
static void
@@ -24,6 +26,9 @@ printhdr(char *hdr)
{
int uc = 1;
+ if (Hflag)
+ printf("%s\t", curfile);
+
while (*hdr && *hdr != ':') {
putc(uc ? toupper(*hdr) : *hdr, stdout);
uc = (*hdr == '-');
@@ -57,6 +62,8 @@ print_addresses(char *s)
{
char *disp, *addr;
while ((s = blaze822_addr(s, &disp, &addr))) {
+ if (Hflag && (disp || addr))
+ printf("%s\t", curfile);
if (disp && addr) {
if (dflag) {
char d[4096];
@@ -94,6 +101,9 @@ print_header(char *v)
{
status = 0;
+ if (Hflag && !Aflag)
+ printf("%s\t", curfile);
+
if (Aflag)
print_addresses(v);
else if (Dflag)
@@ -143,6 +153,8 @@ header(char *file)
while (*file == ' ' || *file == '\t')
file++;
+ curfile = file;
+
msg = blaze822(file);
if (!msg)
return;
@@ -175,16 +187,17 @@ int
main(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "h:ADMd")) != -1)
+ while ((c = getopt(argc, argv, "h:ADHMd")) != -1)
switch(c) {
case 'h': hflag = optarg; break;
case 'A': Aflag = 1; break;
case 'D': Dflag = 1; break;
+ case 'H': Hflag = 1; break;
case 'M': Mflag = 1; break;
case 'd': dflag = 1; break;
default:
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);
}