From: rouilj@dl5000.bc.edu (John P. Rouillard)
Subject: New gnu option for divering -v output to a file
Organization: Institute for Space Research, Boston College
Distribution: gnu
Date: Mon, 27 Jul 1992 02:45:53 GMT

In working with Steve Romig's backup software, I realized how useful
it would be to be able to divert the -v output to a file.  This is
especially useful if the tar archive is going to stdout.

The patches below add another option "-D" long name "dirlog", because
I use the -v option to maintain a directory of the file written to tape.

If you are on a system that supports named pipes, and you use a pipe
as the output file, you can compress the file list on the fly.

Here's the patch:

===================================================================
RCS file: /sources/cvsrepos/gtar/buffer.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 buffer.c
--- 1.1.1.1	1991/12/17 03:45:39
+++ buffer.c	1992/07/27 01:12:28
@@ -56,7 +56,8 @@
 #include "regex.h"
 
 /* Either stdout or stderr:  The thing we write messages (standard msgs, not
-   errors) to.  Stdout unless we're writing a pipe, in which case stderr */
+   errors) to.  Stdout unless we're writing a pipe, in which case stderr 
+   unless a file was specified with -D  */
 FILE *msg_file = stdout;
 
 #define	STDIN	0		/* Standard input  file descriptor */
@@ -496,7 +497,8 @@
 open_archive(reading)
 	int reading;
 {
-	msg_file = f_exstdout ? stderr : stdout;
+        if ( ! v_output_file )
+	        msg_file = f_exstdout ? stderr : stdout;
 
 	if (blocksize == 0) {
 		msg("invalid value for blocksize");
@@ -531,7 +533,8 @@
 			exit(EX_ARGSBAD);
 		}
 		child_open();
-		if(!reading && ar_file[0]=='-' && ar_file[1]=='\0')
+		if(!reading && ar_file[0]=='-' && ar_file[1]=='\0' &&
+		   !v_output_file)
 			msg_file = stderr;
 		/* child_open(rem_host, rem_file); */
 	} else if (ar_file[0] == '-' && ar_file[1] == '\0') {
@@ -542,13 +545,13 @@
 		}
 		if(reading==2) {
 			archive=STDIN;
-			msg_file=stderr;
+			if (! v_output_file) msg_file=stderr;
 			write_archive_to_stdout++;
 		} else if (reading)
 			archive = STDIN;
 		else {
 			archive = STDOUT;
-			msg_file = stderr;
+			if (!v_output_file) msg_file = stderr;
 		}
 	} else if (reading==2 || f_verify) {
 		archive = rmtopen(ar_file, O_RDWR|O_CREAT|O_BINARY, 0666);
===================================================================
RCS file: /sources/cvsrepos/gtar/tar.c,v
retrieving revision 1.2
diff -u -r1.2 tar.c
--- 1.2	1992/07/27 00:08:17
+++ tar.c	1992/07/27 01:35:54
@@ -152,6 +152,7 @@
 	{"compare",		0,	0,			'd'},
 	{"diff",		0,	0,			'd'},
 	{"delete",		0,	0,			14},
+	{"dirlog",		1,	0,			'D'},
 	{"help",		0,	0,			12},
 
 	{"directory",		1,	0,			'C'},
@@ -303,6 +304,7 @@
 
 	/* Set default option values */
 	blocking = DEFBLOCKING;		/* From Makefile */
+	v_output_file = 0;
 	ar_file = getenv("TAPE");	/* From environment, or */
 	if (ar_file == 0)
 		ar_file = DEF_AR_FILE;	/* From Makefile */
@@ -309,7 +311,7 @@
 
 	/* Parse options */
 	while ((c = getoldopt(argc, argv,
-			      "-01234567Ab:BcC:df:F:g:GhikK:lL:mMN:oOpPrRsStT:uvV:wWxX:zZ",
+			      "-01234567Ab:BcC:dD:f:F:g:GhikK:lL:mMN:oOpPrRsStT:uvV:wWxX:zZ",
 			      long_options, &ind)) != EOF) {
 		switch (c) {
 		case 0:		/* long options that set a single flag */
@@ -427,6 +429,22 @@
 			cmd_mode=CMD_DIFF;
 			break;
 
+		case 'D':			/* file for -v output */
+			f_verbose++;  /* imply -v */
+			v_output_file++;
+			if ( v_output_file > 1 )
+			  {
+			      msg("Only one -D arg allowed\n");
+			      exit(EX_ARGSBAD);
+			  }
+			
+			if ( (msg_file = fopen(optarg,"w")) ==  NULL)
+			  {
+			      msg_perror("can't open file %s", optarg);
+			      exit(EX_BADFILE);
+			  }
+			break;
+
 		case 'f':			/* Use ar_file for the archive */
 			ar_file = optarg;
 			break;
@@ -632,6 +650,7 @@
 	fputs ("\
 -B, +read-full-blocks	reblock as we read (for reading 4.2BSD pipes)\n\
 -C, +directory DIR	change to directory DIR\n\
+-D, +dirlog F           Put output from -v into file (implies -v)\n\
 ", stderr); /* KLUDGE */ fprintf(stderr, "\
 -f, +file [HOSTNAME:]F	use archive file or device F (default %s)\n",
 				 DEF_AR_FILE); fputs("\
===================================================================
RCS file: /sources/cvsrepos/gtar/tar.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 tar.h
--- 1.1.1.1	1991/12/17 03:45:48
+++ tar.h	1992/07/27 00:58:26
@@ -165,6 +165,7 @@
 TAR_EXTERN union record	*ar_last;	/* Last+1 record of archive block */
 TAR_EXTERN char		ar_reading;	/* 0 writing, !0 reading archive */
 TAR_EXTERN int		blocking;	/* Size of each block, in records */
+TAR_EXTERN int          v_output_file;  /* if != zero output file specifed */
 TAR_EXTERN int		blocksize;	/* Size of each block, in bytes */
 TAR_EXTERN char		*ar_file;	/* File containing archive */
 TAR_EXTERN char		*info_script;	/* Script to run at end of each tape change */


-- John

Newsgroups: gnu.utils.bug