[alt.sources] Another directory tree shadower

bothner@sevenlayer.cs.wisc.edu (Per Bothner) (11/13/90)

The mkshadow programs makes a "shadow tree" of a directory tree.
It logically copies all of the "MASTER" directory into ".".
However, ordinary files, and RCS directories are "copied"
by creating a sybolic link to the corresponding file in MASTER.

I saw the posting for "lktree" right after I've spent a
day working on the following program. But went ahead
working on mkshadow, which has one major win over lktree:
It does all the system calls itself, whereas lktree emits
shell commands to a temporary file, which it then runs with sh.
This makes mkshadow very fast, and I suspect more robust
(errors are reported by mkshadow, not the shell).

Bugs, comments, suggestions to me.

	--Per Bothner
bothner@cs.wisc.edu Computer Sciences Dept, U. of Wisconsin-Madison

#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	README
#	Makefile
#	mkshadow.c
#	savedir.c
#	wildmat.c
#	COPYING
# This archive created: Mon Nov 12 15:50:22 1990
export PATH; PATH=/bin:$PATH
if test -f 'README'
then
	echo shar: over-writing existing file "'README'"
fi
cat << \SHAR_EOF > 'README'
The mkshadow programs makes a "shadow tree" of a directory tree.
It logically copies all of the "MASTER" directory into ".".
However, ordinary files, and RCS directories are "copied"
by creating a sybolic link to the corresponding file in MASTER.

The wildmat.c file is from GNU tar-1.09.
The savedir.c file is from GNU find.
Hence, the GNU license applies.

 * Usage: mkshadow [-X exclude_file] [-x exclude_pattern] ... MASTER
 * Makes the current directory be a "shadow copy" of MASTER.
 * Sort of like a recursive copy of MASTER to .
 * However, symbolic links are used instead of actually
 * copying (non-directory) files.
 * Also, directories named RCS are shared (with a symbolic link).
 * Warning messages are printed for files (and directories) in .
 * that don't match a corresponding file in MASTER (though
 * symbolic links are silently removed).
 * Also, a warning message is printed for non-directory files
 * under . that are  not symbolic links.
 *
 * Files and directories can be excluded from the sharing
 * with the -X and -x flags. The flag `-x pattern' (or `-xpattern')
 * means that mkshadow should ignore any file whose name matches
 * the pattern. The pattern is a "globbing" pattern, i.e. the
 * characters *?[^-] are interpreted as by the shell.
 * If the pattern contains a '/' is is matched against the complete
 * current path (relative to '.'); otherwise, it is matched
 * against the last component of the path.
 * A `-X filename' flag means to read a set of exclusion patterns
 * from the named file, one pattern to a line.
 *
 * Author: Per Bothner. bothner@cs.wisc.edu. November 1990.
SHAR_EOF
if test -f 'Makefile'
then
	echo shar: over-writing existing file "'Makefile'"
fi
cat << \SHAR_EOF > 'Makefile'
mkshadow: mkshadow.o savedir.o wildmat.o
	$(CC) -o mkshadow mkshadow.o savedir.o wildmat.o
SHAR_EOF
if test -f 'mkshadow.c'
then
	echo shar: over-writing existing file "'mkshadow.c'"
fi
cat << \SHAR_EOF > 'mkshadow.c'
/*
 * Usage: mkshadow [-X exclude_file] [-x exclude_pattern] ... MASTER
 * Makes the current directory be a "shadow copy" of MASTER.
 * Sort of like a recursive copy of MASTER to .
 * However, symbolic links are used instead of actually
 * copying (non-directory) files.
 * Also, directories named RCS are shared (with a symbolic link).
 * Warning messages are printed for files (and directories) in .
 * that don't match a corresponding file in MASTER (though
 * symbolic links are silently removed).
 * Also, a warning message is printed for non-directory files
 * under . that are  not symbolic links.
 *
 * Files and directories can be excluded from the sharing
 * with the -X and -x flags. The flag `-x pattern' (or `-xpattern')
 * means that mkshadow should ignore any file whose name matches
 * the pattern. The pattern is a "globbing" pattern, i.e. the
 * characters *?[^-] are interpreted as by the shell.
 * If the pattern contains a '/' is is matched against the complete
 * current path (relative to '.'); otherwise, it is matched
 * against the last component of the path.
 * A `-X filename' flag means to read a set of exclusion patterns
 * from the named file, one pattern to a line.
 *
 * Author: Per Bothner. bothner@cs.wisc.edu. November 1990.
 */

/* Wildcard matching routines.
   Copyright (C) 1990 Per Bothner.

This file is part of mkshadow.

mkshadow is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.

GNU Tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Tar; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

#include <sys/param.h>
#include <sys/types.h>
#include <stdio.h>
#ifndef USG
#include <strings.h>
#else
#include <string.h>
#define index strchr
#define rindex strrchr
#endif
#include <sys/stat.h>
#ifndef S_IFLNK
#define lstat stat
#endif
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif
#include "errno.h"
#ifndef errno
extern int errno;
#endif

extern char * savedir();

fatal(msg)
     char *msg;
{
    if (errno) perror(msg ? msg : "");
    else if (msg) fprintf(stderr, "mkshadow: %s\n", msg);
    exit(-1);
}

char master_buffer[MAXPATHLEN];
char current_buffer[MAXPATHLEN];

void bad_args(msg)
{
    if (msg) fprintf(stderr, "%s\n", msg);
    fprintf(stderr, 
      "usage: mkshadow [-X exclude_file] [-x exclude_pattern] master_src\n");
    exit(-1);
}

int exclude_count = 0;
char **exclude_patterns = NULL;
int exclude_limit = 0;

void add_exclude(pattern)
    char *pattern;
{
    if (exclude_limit == 0) {
	exclude_limit = 100;
	exclude_patterns = (char**)malloc(exclude_limit * sizeof(char*));
    } else if (exclude_count + 1 >= exclude_limit) {
	exclude_limit += 100;
	exclude_patterns = (char**)realloc(exclude_patterns, 
					   exclude_limit * sizeof(char*));
    }
    exclude_patterns[exclude_count] = pattern;
    exclude_count++;
}

void add_exclude_file(name)
     char *name;
{
    char buf[MAXPATHLEN];
    FILE *file = fopen(name, "r");
    if (file == NULL) fatal("failed to find -X (exclude) file");
    for (;;) {
	int len;
	char *str = fgets(buf, MAXPATHLEN, file);
	if (str == NULL) break;
	len = strlen(str);
	if (len && str[len-1] == '\n') str[--len] = 0;
	if (!len) continue;
	str = (char*)malloc(len+1);
	strcpy(str, buf);
	add_exclude(str);
    }
    fclose(file);
}

main(argc, argv)
     char **argv;
{
    char *root_name = NULL;
    int i;
    for (i = 1; i < argc; i++) {
	if (argv[i][0] == '-') {
	    switch(argv[i][1]) {
	      case 'X':
		if (argv[i][2]) add_exclude_file(&argv[i][2]);
		else if (++i >= argc) bad_args(NULL);
		else add_exclude_file(argv[i]);
		break;
	      case 'x':
		if (argv[i][2]) add_exclude(&argv[i][2]);
		else if (++i >= argc) bad_args(NULL);
		else add_exclude(argv[i]);
		break;
	      default:
		bad_args(NULL);
	    }
	} else if (root_name) bad_args(NULL);
	else root_name = argv[i];
    }
    if (root_name == NULL) bad_args(NULL);
    strcpy(current_buffer, ".");
    strcpy(master_buffer, root_name);
    DoCopy(master_buffer, current_buffer);
    return 0;
}

int compare_strings(ptr1, ptr2)
     char **ptr1, **ptr2;
{
    return strcmp(*ptr1, *ptr2);
}

/* Get a sorted NULL_terminator array of (char*) using 'names'
 * (created by save_dir) as data.
 */
char ** get_name_pointers(names)
     char *names;
{
    int n_names = 0;
    int names_buf_size = 64;
    char *namep;
    char ** pointers = (char**)malloc(names_buf_size * sizeof(char*));
    if (!names || !pointers) fatal("virtual memory exhausted");

    for (namep = names; *namep; namep += strlen(namep) + 1) {
	if (n_names + 1 >= names_buf_size) {
	    names_buf_size *= 2;
	    pointers = (char**)realloc(pointers,
				       names_buf_size * sizeof(char*));
	    if (!pointers) fatal("virtual memory exhausted");
	}
	pointers[n_names++] = namep;
    }
    pointers[n_names] = 0;
    qsort(pointers, n_names, sizeof(char*), compare_strings);
    return pointers;
}

DoCopy(master, current)
     char *master;
     char *current;
{
    struct stat stat_master, stat_current;
    char **master_pointer, **current_pointer;
    char **master_names, **current_names;
    char *master_end, *current_end;
    char *master_name_buf, *current_name_buf;
    master_end = master + strlen(master);
    current_end = current + strlen(current);

    /* Get rid of terminal '/' */
    if (master_end[-1] == '/' && master != master_end - 1)
	*--master_end = 0;
    if (current_end[-1] == '/' && current != current_end - 1)
	*--current_end = 0;

    master_name_buf = savedir(master, 500);
    current_name_buf = savedir(current, 500);

    master_names = get_name_pointers(master_name_buf);
    current_names = get_name_pointers(current_name_buf);

    master_pointer = master_names;
    current_pointer = current_names;
    for (;;) {
	int cmp, ipat;
	int in_master, in_current;
	char *cur_name;
	if (*master_pointer == NULL && *current_pointer == NULL)
	    break;
	if (*master_pointer == NULL) cmp = 1;
	else if (*current_pointer == NULL) cmp = -1;
	else cmp = strcmp(*master_pointer, *current_pointer);
	if (cmp < 0) { /* file only exists in master directory */
	    in_master = 1; in_current = 0;
	} else if (cmp == 0) { /* file exists in both directories */
	    in_master = 1; in_current = 1;
	} else { /* file only exists in current directory */
	    in_current = 1; in_master = 0;
	}
	cur_name = in_master ? *master_pointer : *current_pointer;
	sprintf(master_end, "/%s", cur_name);
	sprintf(current_end, "/%s", cur_name);
	for (ipat = 0; ipat < exclude_count; ipat++) {
	    char *pat = exclude_patterns[ipat];
	    char *cur;
	    if (index(pat, '/')) cur = current + 2; /* Skip initial "./" */
	    else cur = cur_name;
	    if (wildmat(cur, pat)) goto skip;
	}
	if (in_master)
	    if (lstat(master, &stat_master) != 0) fatal("stat failed");
	if (in_current)
	    if (lstat(current, &stat_current) != 0) fatal("stat failed");
	if (in_current && !in_master) {
	    if ((stat_current.st_mode & S_IFMT) == S_IFLNK)
		if (unlink(current)) {
		    fprintf(stderr, "Failed to remove symbolic link %s.\n",
			    current);
		}
		else
		    fprintf(stderr, "Removed symbolic link %s.\n",
			    current);
	    else {
		fprintf(stderr,
			"The file %s does not exist in the master tree.\n",
			current);
	    }
	}
	else if ((stat_master.st_mode & S_IFMT) == S_IFDIR
		 && strcmp(cur_name, "RCS") != 0) {
	    if (!in_current) {
		if (mkdir(current, 0775)) fatal("mkdir failed");
	    }
	    else if (stat(current, &stat_current)) fatal("stat failed");
	    if (!in_current || stat_current.st_dev != stat_master.st_dev
		|| stat_current.st_ino != stat_master.st_ino)
		DoCopy(master, current);
	    else
		fprintf(stderr, "Link %s is the same as directory %s.\n",
			current, master);
	}
	else {
	    if (!in_current) {
		if (symlink(master, current)) {
		    fprintf(stderr, "Failed to create symbolic link %s->%s\n",
			    current, master);
		    exit (-1);
		}
	    } else if ((stat_current.st_mode & S_IFMT) != S_IFLNK) {
		fprintf(stderr, "Existing file %s is not a symbolc link.\n",
			current);
	    } else {
		if (stat(current, &stat_current) || stat(master, &stat_master))
		    fatal("stat failed");
		if (stat_current.st_dev != stat_master.st_dev
		    || stat_current.st_ino != stat_master.st_ino) {
		    fprintf(stderr, "Fixing incorrect symbolic link %s.\n",
			    current);
		    if (unlink(current)) {
			fprintf(stderr, "Failed to remove symbolic link %s.\n",
				current);
		    }
		    else if (symlink(master, current)) {
			fprintf(stderr,
				"Failed to create symbolic link %s->%s\n",
				current, master);
			exit (-1);
		    }
		}
	    }
	}
      skip:
	if (in_master) master_pointer++;
	if (in_current) current_pointer++;
    }

    free(master_names); free(current_names);
    free(master_name_buf); free(current_name_buf);
}
SHAR_EOF
if test -f 'savedir.c'
then
	echo shar: over-writing existing file "'savedir.c'"
fi
cat << \SHAR_EOF > 'savedir.c'
/* savedir.c -- save the list of files in a directory in a string
   Copyright (C) 1990 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 1, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */

/* Written by David MacKenzie <djm@ai.mit.edu>. */

#include <sys/types.h>
#ifdef DIRENT
#include <dirent.h>
#define direct dirent
#define NLENGTH(direct) (strlen((direct)->d_name))
#else
#define NLENGTH(direct) ((direct)->d_namlen)
#ifdef USG
#ifdef SYSNDIR
#include <sys/ndir.h>
#else
#include <ndir.h>
#endif
#else
#include <sys/dir.h>
#endif
#endif

#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#else
char *malloc ();
char *realloc ();
int strlen ();
#ifndef NULL
#define NULL 0
#endif
#endif

char *stpcpy ();

/* Return a freshly allocated string containing the filenames
   in directory DIR, separated by '\0' characters;
   the end is marked by two '\0' characters in a row.
   NAME_SIZE is the number of bytes to initially allocate
   for the string; it will be enlarged as needed.
   Return NULL if DIR cannot be opened or if out of memory. */

char *
savedir (dir, name_size)
     char *dir;
     unsigned name_size;
{
  DIR *dirp;
  struct direct *dp;
  char *name_space;
  char *namep;

  dirp = opendir (dir);
  if (dirp == NULL)
    return NULL;

  name_space = (char *) malloc (name_size);
  if (name_space == NULL)
    return NULL;
  namep = name_space;

  while ((dp = readdir (dirp)) != NULL)
    {
      /* Skip "." and ".." (some NFS filesystems' directories lack them). */
      if (dp->d_name[0] != '.'
	  || (dp->d_name[1] != '\0'
	      && (dp->d_name[1] != '.' || dp->d_name[2] != '\0')))
	{
	  unsigned size_needed = (namep - name_space) + NLENGTH (dp) + 2;

	  if (size_needed > name_size)
	    {
	      char *new_name_space;

	      while (size_needed > name_size)
		name_size += 1024;

	      new_name_space = realloc (name_space, name_size);
	      if (new_name_space == NULL)
		{
		  closedir (dirp);
		  return NULL;
		}
	      namep += new_name_space - name_space;
	      name_space = new_name_space;
	    }
	  namep = stpcpy (namep, dp->d_name) + 1;
	}
    }
  *namep = '\0';
  closedir (dirp);
  return name_space;
}

/* Copy SOURCE into DEST, stopping after copying the first '\0', and
   return a pointer to the '\0' at the end of DEST;
   in other words, return DEST + strlen (SOURCE). */

char *
stpcpy (dest, source)
     char *dest;
     char *source;
{
  while ((*dest++ = *source++) != '\0')
    /* Do nothing. */ ;
  return dest - 1;
}
SHAR_EOF
if test -f 'wildmat.c'
then
	echo shar: over-writing existing file "'wildmat.c'"
fi
cat << \SHAR_EOF > 'wildmat.c'
/* Wildcard matching routines.
   Copyright (C) 1988 Free Software Foundation

This file is part of GNU Tar.

GNU Tar is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.

GNU Tar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Tar; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */

/*
 * @(#)wildmat.c 1.3 87/11/06
 *
From: rs@mirror.TMC.COM (Rich Salz)
Newsgroups: net.sources
Subject: Small shell-style pattern matcher
Message-ID: <596@mirror.TMC.COM>
Date: 27 Nov 86 00:06:40 GMT

There have been several regular-expression subroutines and one or two
filename-globbing routines in mod.sources.  They handle lots of
complicated patterns.  This small piece of code handles the *?[]\
wildcard characters the way the standard Unix(tm) shells do, with the
addition that "[^.....]" is an inverse character class -- it matches
any character not in the range ".....".  Read the comments for more
info.

For my application, I had first ripped off a copy of the "glob" routine
from within the find source, but that code is bad news:  it recurses
on every character in the pattern.  I'm putting this replacement in the
public domain.  It's small, tight, and iterative.  Compile with -DTEST
to get a test driver.  After you're convinced it works, install in
whatever way is appropriate for you.

I would like to hear of bugs, but am not interested in additions; if I
were, I'd use the code I mentioned above.
*/
/*
**  Do shell-style pattern matching for ?, \, [], and * characters.
**  Might not be robust in face of malformed patterns; e.g., "foo[a-"
**  could cause a segmentation violation.
**
**  Written by Rich $alz, mirror!rs, Wed Nov 26 19:03:17 EST 1986.
*/

/*
 * Modified 6Nov87 by John Gilmore (hoptoad!gnu) to return a "match"
 * if the pattern is immediately followed by a "/", as well as \0.
 * This matches what "tar" does for matching whole subdirectories.
 *
 * The "*" code could be sped up by only recursing one level instead
 * of two for each trial pattern, perhaps, and not recursing at all
 * if a literal match of the next 2 chars would fail.
 */
#define TRUE		1
#define FALSE		0


static int
Star(s, p)
    register char	*s;
    register char	*p;
{
    while (wildmat(s, p) == FALSE)
	if (*++s == '\0')
	    return(FALSE);
    return(TRUE);
}


int
wildmat(s, p)
    register char	*s;
    register char	*p;
{
    register int 	 last;
    register int 	 matched;
    register int 	 reverse;

    for ( ; *p; s++, p++)
	switch (*p) {
	    case '\\':
		/* Literal match with following character; fall through. */
		p++;
	    default:
		if (*s != *p)
		    return(FALSE);
		continue;
	    case '?':
		/* Match anything. */
		if (*s == '\0')
		    return(FALSE);
		continue;
	    case '*':
		/* Trailing star matches everything. */
		return(*++p ? Star(s, p) : TRUE);
	    case '[':
		/* [^....] means inverse character class. */
		if (reverse = p[1] == '^')
		    p++;
		for (last = 0400, matched = FALSE; *++p && *p != ']'; last = *p)
		    /* This next line requires a good C compiler. */
		    if (*p == '-' ? *s <= *++p && *s >= last : *s == *p)
			matched = TRUE;
		if (matched == reverse)
		    return(FALSE);
		continue;
	}

    /* For "tar" use, matches that end at a slash also work. --hoptoad!gnu */
    return(*s == '\0' || *s == '/');
}


#ifdef	TEST
#include <stdio.h>

extern char	*gets();


main()
{
    char	 pattern[80];
    char	 text[80];

    while (TRUE) {
	printf("Enter pattern:  ");
	if (gets(pattern) == NULL)
	    break;
	while (TRUE) {
	    printf("Enter text:  ");
	    if (gets(text) == NULL)
		exit(0);
	    if (text[0] == '\0')
		/* Blank line; go back and get a new pattern. */
		break;
	    printf("      %d\n", wildmat(text, pattern));
	}
    }
    exit(0);
}
#endif	/* TEST */
SHAR_EOF
if test -f 'COPYING'
then
	echo shar: over-writing existing file "'COPYING'"
fi
cat << \SHAR_EOF > 'COPYING'

		    GNU GENERAL PUBLIC LICENSE
		     Version 1, February 1989

 Copyright (C) 1989 Free Software Foundation, Inc.
                    675 Mass Ave, Cambridge, MA 02139, USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must tell them their rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License.  The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications.  Each
licensee is addressed as "you".

  1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program.  You may charge a fee for the physical act of
transferring a copy.

  2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:

    a) cause the modified files to carry prominent notices stating that
    you changed the files and the date of any change; and

    b) cause the whole of any work that you distribute or publish, that
    in whole or in part contains the Program or any part thereof, either
    with or without modifications, to be licensed at no charge to all
    third parties under the terms of this General Public License (except
    that you may choose to grant warranty protection to some or all
    third parties, at your option).

    c) If the modified program normally reads commands interactively when
    run, you must cause it, when started running for such interactive use
    in the simplest and most usual way, to print or display an
    announcement including an appropriate copyright notice and a notice
    that there is no warranty (or else, saying that you provide a
    warranty) and that users may redistribute the program under these
    conditions, and telling the user how to view a copy of this General
    Public License.

    d) You may charge a fee for the physical act of transferring a
    copy, and you may at your option offer warranty protection in
    exchange for a fee.

Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.

  3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:

    a) accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    b) accompany it with a written offer, valid for at least three
    years, to give any third party free (except for a nominal charge
    for the cost of distribution) a complete machine-readable copy of the
    corresponding source code, to be distributed under the terms of
    Paragraphs 1 and 2 above; or,

    c) accompany it with the information you received as to where the
    corresponding source code may be obtained.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form alone.)

Source code for a work means the preferred form of the work for making
modifications to it.  For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.

  4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License.  However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.

  5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions.  You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.

  7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.

  8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

		     END OF TERMS AND CONDITIONS

	Appendix: How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.

  To do so, attach the following notices to the program.  It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 19yy  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 1, or (at your option)
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) 19xx name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License.  Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the
  program `Gnomovision' (a program to direct compilers to make passes
  at assemblers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

That's all there is to it!
SHAR_EOF
#	End of shell archive
exit 0

-- 
	--Per Bothner
bothner@cs.wisc.edu Computer Sciences Dept, U. of Wisconsin-Madison