about summary refs log tree commit diff
path: root/mhdr.c
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 /mhdr.c
parentbfe841eb1e433effa71b42b43206fef78d6e2e2c (diff)
downloadmblaze-7604589738034f0ad9eae9bfc804433e3edd5dbc.tar.gz
mblaze-7604589738034f0ad9eae9bfc804433e3edd5dbc.tar.xz
mblaze-7604589738034f0ad9eae9bfc804433e3edd5dbc.zip
mhdr: -H to print file name
Diffstat (limited to 'mhdr.c')
-rw-r--r--mhdr.c17
1 files changed, 15 insertions, 2 deletions
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);
 		}