[comp.sources.atari.st] v02i054: gnutar -- GNU's version of UNIX "tar" part08/08

koreth%panarthea.ebay@sun.com (Steven Grimm) (07/20/89)

Submitted-by: 7103_300@uwovax.uwo.ca (Eric R. Smith)
Posting-number: Volume 2, Issue 54
Archive-name: gnutar/part08

#!/bin/sh
# this is part 8 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file UPDATE.C continued
#
CurArch=8
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
echo "x - Continuing file UPDATE.C"
sed 's/^X//' << 'SHAR_EOF' >> UPDATE.C
X					number_of_kept_records_in_block = number_of_records_to_keep;
X			}
X			n = number_of_kept_records_in_block;
X			if(n>number_of_records_needed)
X				n = number_of_records_needed;
X
X /* fprintf(stderr,"Copying %d\n",n); */
X			bcopy((void *)ar_record, (void *)(new_block+number_of_new_records), n*RECORDSIZE);
X			number_of_new_records           += n;
X			number_of_records_needed        -= n;
X			ar_record                       += n;
X			number_of_records_to_keep       -= n;
X			number_of_kept_records_in_block -= n;
X /* fprintf(stderr,"Now new %d  need %d  keep %d  keep_in %d rec %d/%d\n", 
X number_of_new_records,number_of_records_needed,number_of_records_to_keep,
X number_of_kept_records_in_block,ar_record-ar_block,ar_last-ar_block); */
X 
X			if(number_of_records_needed == 0) {
X				write_block(1);
X			}
X		}
X	}
X
X	write_eot();
X	close_archive();
X	names_notfound();
X}
X
Xwrite_block(f)
X{
X /* fprintf(stderr,"Write block\n"); */
X	/* We've filled out a block.  Write it out. */
X
X	/* Backspace back to where we started. . . */
X	if(archive!=STDIN)
X		(void)move_arch(-(number_of_blocks_read+1));
X
X	save_block = ar_block;
X	ar_block = new_block;
X
X	if(archive==STDIN)
X		archive=STDOUT;
X	fl_write();
X
X	if(archive==STDOUT)
X		archive=STDIN;
X	ar_block = save_block;
X
X	if(f) {
X		/* Move the tape head back to where we were */
X		if(archive!=STDIN)
X			(void)move_arch(number_of_blocks_read);
X		number_of_blocks_read--;
X	}
X
X	number_of_records_needed = blocking;
X	number_of_new_records = 0;
X}
X
X/* Move archive descriptor by n blocks worth.  If n is positive we move
X   forward, else we move negative.   If its a tape, MTIOCTOP had better
X   work.  If its something else, we try to seek on it.  If we can't
X   seek, we lose! */
Xmove_arch(n)
X{
X	long cur;
X	extern int errno;
X
X#ifdef MTIOCTOP
X	struct mtop t;
X	int er;
X
X	if(n>0) {
X		t.mt_op = MTFSR;
X		t.mt_count = n;
X	} else {
X		t.mt_op = MTBSR;
X		t.mt_count = -n;
X	}
X	if((er=rmtioctl(archive,MTIOCTOP,&t))>=0)
X		return 1;
X	if(errno==EIO && (er=rmtioctl(archive,MTIOCTOP,&t))>=0)
X		return 1;
X#endif
X
X	cur=rmtlseek(archive,0L,1);
X	cur+=blocksize*n;
X
X /* fprintf(stderr,"Fore to %x\n",cur); */
X	if(rmtlseek(archive,cur,0)!=cur) {
X		/* Lseek failed.  Try a different method */
X		fprintf(stderr,"tar: Couldn't re-position archive file.\n");
X		exit(EX_BADARCH);
X	}
X	return 3;
X}
X
SHAR_EOF
echo "File UPDATE.C is complete"
chmod 0644 UPDATE.C || echo "restore of UPDATE.C fails"
echo "x - extracting VERSION.C (Text)"
sed 's/^X//' << 'SHAR_EOF' > VERSION.C &&
X#ifdef atarist
Xchar version_string[] = "GNU tar version 1.04 (GEMDOS)";
X#else
Xchar version_string[] = "GNU tar version 1.04";
X#endif
X/* Version 1.00:  This file added.  -version option added */
X
X/*		Installed new version of the remote-tape library */
X/*		Added -help option */
X/*	1.01	Fixed typoes in tar.texinfo */
X/*		Fixed a bug in the #define for rmtcreat() */
X/*		Fixed the -X option to not call realloc() of 0. */
X
X/*	1.02	Fixed tar.c so 'tar -h' and 'tar -v' don't cause core dump */
X/*		Also fixed the 'usage' message to be more up-to-date. */
X/*		Fixed diffarch.c so verify should compile without MTIOCTOP
X			defined */
X
X/*	1.03	Fixed buffer.c so 'tar tzf NON_EXISTENT_FILE' returns an error
X			message instead of hanging forever */
X
X/*		More fixes to tar.texinfo */
X/*	1.04	Added functions msg() and msg_perror()  Modified all the
X			files to call them.  Also checked that all (I hope)
X			calls to msg_perror() have a valid errno value
X			(modified anno() to leave errno alone), etc
X		Re-fixed the -X option.  This
X 		time for sure. . . */	
X/*		re-modified the msg stuff.  flushed anno() completely */
X/*		Modified the directory stuff so it should work on sysV boxes */
X/*		added ftime() to getdate.y */
X/*		Fixed un_quote_string() so it won't wedge on \" Also fixed
X		\ddd (like \123, etc) */
X/*		More fixes to tar.texinfo */
SHAR_EOF
chmod 0644 VERSION.C || echo "restore of VERSION.C fails"
echo "x - extracting WILDMAT.C (Text)"
sed 's/^X//' << 'SHAR_EOF' > WILDMAT.C &&
X/*
X
X	Copyright (C) 1988 Free Software Foundation
X
XGNU tar is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the GNU tar General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute GNU tar,
Xbut only under the conditions described in the GNU tar General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with GNU tar so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share GNU tar, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X*/
X
X/*
X * @(#)wildmat.c 1.3 87/11/06
X *
XFrom: rs@mirror.TMC.COM (Rich Salz)
XNewsgroups: net.sources
XSubject: Small shell-style pattern matcher
XMessage-ID: <596@mirror.TMC.COM>
XDate: 27 Nov 86 00:06:40 GMT
X
XThere have been several regular-expression subroutines and one or two
Xfilename-globbing routines in mod.sources.  They handle lots of
Xcomplicated patterns.  This small piece of code handles the *?[]\
Xwildcard characters the way the standard Unix(tm) shells do, with the
Xaddition that "[^.....]" is an inverse character class -- it matches
Xany character not in the range ".....".  Read the comments for more
Xinfo.
X
XFor my application, I had first ripped off a copy of the "glob" routine
Xfrom within the find(1) source, but that code is bad news:  it recurses
Xon every character in the pattern.  I'm putting this replacement in the
Xpublic domain.  It's small, tight, and iterative.  Compile with -DTEST
Xto get a test driver.  After you're convinced it works, install in
Xwhatever way is appropriate for you.
X
XI would like to hear of bugs, but am not interested in additions; if I
Xwere, I'd use the code I mentioned above.
X*/
X/*
X**  Do shell-style pattern matching for ?, \, [], and * characters.
X**  Might not be robust in face of malformed patterns; e.g., "foo[a-"
X**  could cause a segmentation violation.
X**
X**  Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
X*/
X
X/*
X * Modified 6Nov87 by John Gilmore (hoptoad!gnu) to return a "match"
X * if the pattern is immediately followed by a "/", as well as \0.
X * This matches what "tar" does for matching whole subdirectories.
X *
X * The "*" code could be sped up by only recursing one level instead
X * of two for each trial pattern, perhaps, and not recursing at all
X * if a literal match of the next 2 chars would fail.
X */
X#define TRUE		1
X#define FALSE		0
X
X
Xstatic int
XStar(s, p)
X    register char	*s;
X    register char	*p;
X{
X    while (wildmat(s, p) == FALSE)
X	if (*++s == '\0')
X	    return(FALSE);
X    return(TRUE);
X}
X
X
Xint
Xwildmat(s, p)
X    register char	*s;
X    register char	*p;
X{
X    register int 	 last;
X    register int 	 matched;
X    register int 	 reverse;
X
X    for ( ; *p; s++, p++)
X	switch (*p) {
X	    case '\\':
X		/* Literal match with following character; fall through. */
X		p++;
X	    default:
X		if (*s != *p)
X		    return(FALSE);
X		continue;
X	    case '?':
X		/* Match anything. */
X		if (*s == '\0')
X		    return(FALSE);
X		continue;
X	    case '*':
X		/* Trailing star matches everything. */
X		return(*++p ? Star(s, p) : TRUE);
X	    case '[':
X		/* [^....] means inverse character class. */
X		if (reverse = p[1] == '^')
X		    p++;
X		for (last = 0400, matched = FALSE; *++p && *p != ']'; last = *p)
X		    /* This next line requires a good C compiler. */
X		    if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
X			matched = TRUE;
X		if (matched == reverse)
X		    return(FALSE);
X		continue;
X	}
X
X    /* For "tar" use, matches that end at a slash also work. --hoptoad!gnu */
X    return(*s == '\0' || *s == '/');
X}
X
X
X#ifdef	TEST
X#include <stdio.h>
X
Xextern char	*gets();
X
X
Xmain()
X{
X    char	 pattern[80];
X    char	 text[80];
X
X    while (TRUE) {
X	printf("Enter pattern:  ");
X	if (gets(pattern) == NULL)
X	    break;
X	while (TRUE) {
X	    printf("Enter text:  ");
X	    if (gets(text) == NULL)
X		exit(0);
X	    if (text[0] == '\0')
X		/* Blank line; go back and get a new pattern. */
X		break;
X	    printf("      %d\n", wildmat(text, pattern));
X	}
X    }
X    exit(0);
X}
X#endif	/* TEST */
SHAR_EOF
chmod 0644 WILDMAT.C || echo "restore of WILDMAT.C fails"
rm -f s2_seq_.tmp
echo "You have unpacked the last part"
exit 0