[net.sources] 4.2 tar hack : take file names from stdin

ted@usceast.UUCP (Ted Nolan) (07/17/84)

: This is a shar archive.  Extract with sh, not csh.
echo x - README
cat > README << '!Funky!Stuff!'
This set of files is intended to produce from the original 4.2 source,
a version of tar that can take file names and -C commands from the
standard input, instead of the command line.  This can be handy in
many cases. The option to provoke this behavior is T, as in :
  cat filelist | tar Tcf /dev/rmt8

I would have liked to just post the whole thing, but I suspect that would
be illegal, so I have instead included editor scripts that feed on the 4.2
tar source. (Ie, only people entitled to the source will find the
scripts useful).  If you have already hacked the source, feed the
original to the scripts and then put your hacks back in.

For people without the 4.2 source, this is the (simple) strategy I used:

	Add a variable Tflag, and set it if the T option is found.
	If it is set, call a routine called dostdinrep instead of
	dorep.  To make dostdinrep, copy dorep, but get rid of argv
	and do gets (section 3) instead.  Go through the routine 
	substituting your buffer for references to *argv 
	(remember argv is char **argv, your buffer is just 
	char *buffer).

	Make sure that the '-' convention for stdin is disabled
	when the Tflag is set.

For people with the 4.2 source, put the original source in the directory
with the extracted files (as tar.c) and say make.

I make no guarantees about the suitability of the new tar for anything,
but it seems to work here.  (Of course, after I post this, ours will
explode horribly!) I have left parts of the original dorep in dostdinrep 
as comments for debugging purposes (char * and char ** kept throwing
me).

			Ted Nolan		..usceast!ted
!Funky!Stuff!
echo x - Makefile
cat > Makefile << '!Funky!Stuff!'
ntar : tar.c diff1 diff2 dorep dostdinrep ntar.c
	cc -o ntar ntar.c
#
ntar.c : tar.c dostdinrep
	ed tar.c < diff1
	ed ntar.c < script2
dostdinrep: dorep
	ed dorep < diff2
#
dorep : tar.c
	ed tar.c < script1
!Funky!Stuff!
echo x - diff1
cat > diff1 << '!Funky!Stuff!'
259a
		if(Tflag){		/* can't use stdin for 2 things */
			fprintf(stderr,"Can't use T option with '-'\n");
			done(1);
		}
.
256c
		if (Tflag) 
			dostdinrep();
		else
			dorep(argv);
.
123a
		case 'T' : 		/* use stdin for file arguments */
			 Tflag=1;
			 break;

.
63a
int	Tflag=0;				/*read file args from stdin */
.
6a
 *
 *  Modified July 1984 by Ted Nolan to take a T option.  This
 *  indicates that tar is to take filenames to archive from stdin,
 *  one per line ( no white space between name and newline).
 *  The -C covention also works from stdin with the T option.
.
w ntar.c
q
!Funky!Stuff!
echo x - diff2
cat > diff2 << '!Funky!Stuff!'
56c
/*		putfile(*argv++, cp2, parent);		*/
		putfile(inbuf, cp2, parent);
.
48,49c
/*			if (chdir(*argv) < 0) {		*/
			if (chdir(inbuf) < 0) {
				perror(inbuf);
/*				perror(*argv); 		*/
.
46c
/*		if (cp2 != *argv) {		*/
		if (cp2 != inbuf) {
.
43c
/*		for (cp = *argv; *cp; cp++)	*/
		for (cp = inbuf; *cp; cp++)
.
39c
/*			argv++;		*/
.
31,36c
	while((gets(inbuf)!= (char *) NULL ) && !term){
/*	while (*argv && ! term) { */
		cp2 = inbuf;
/*		cp2 = *argv;	*/
		if (!strcmp(cp2, "-C") ) {
/*		if (!strcmp(cp2, "-C") && argv[1]) {  */
			if (gets(inbuf)== (char *) NULL) {
			   fprintf(stderr,"Bad -C \n");
			   term=1;
			   continue;
			}
/*			argv++;				*/
/*			if (chdir(*argv) < 0) 	*/
			if (chdir(inbuf) < 0)
				perror(inbuf);
/*				perror(*argv);		*/
.
5a
	char *gets();
.
4a
	char inbuf[512];
.
1,2c
/*dorep(argv)	*/
dostdinrep()
/*	char *argv[];		*/
.
w dostdinrep
q
!Funky!Stuff!
echo x - script1
cat > script1 << '!Funky!Stuff!'
1
/dorep/
/dorep/kx
/endtape/
/endtape/ky
'x,'y-2 w dorep
q
!Funky!Stuff!
echo x - script2
cat > script2 << '!Funky!Stuff!'
$
r dostdinrep
w
q

!Funky!Stuff!
-- 
-------------------------------------------------------------------------------
Ted Nolan                               ...decvax!mcnc!ncsu!ncrcae!usceast!ted
6536 Brookside Circle                   ...akgua!usceast!ted
Columbia, SC 29206
      ("We pray for one last landing on the globe that gave us birth..")
-------------------------------------------------------------------------------