[comp.sources.amiga] v89i219: rcs - revision control system, Part04/14

page%swap@Sun.COM (Bob Page) (11/19/89)

Submitted-by: rsbx@cbmvax.commodore.com (Raymond S. Brand)
Posting-number: Volume 89, Issue 219
Archive-name: unix/rcs.04

# This is a shell archive.
# Remove anything above and including the cut line.
# Then run the rest of the file through 'sh'.
# Unpacked files will be owned by you and have default permissions.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar: SHell ARchive
# Run the following text through 'sh' to create:
#	diff/util.c
#	diff/dir.h
#	diff/getopt.c
#	diff/ndir.c
#	diff/makefile
#	diff/amiga1.c
#	diff/readme
#	diff/diff.h
#	diff/limits.h
#	diff/regex.h
#	diff/stat.h
#	diff/diff.h.old
# This is archive 4 of a 14-part kit.
# This archive created: Sun Nov 19 01:12:06 1989
if `test ! -d diff`
then
  mkdir diff
  echo "mkdir diff"
fi
echo "extracting diff/util.c"
sed 's/^X//' << \SHAR_EOF > diff/util.c
X/* Support routines for GNU DIFF.
X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
X
XThis file is part of GNU DIFF.
X
XGNU DIFF is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation; either version 1, or (at your option)
Xany later version.
X
XGNU DIFF is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with GNU DIFF; see the file COPYING.  If not, write to
Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
X
X#include "diff.h"
X
X/* Use when a system call returns non-zero status.
X   TEXT should normally be the file name.  */
X
Xvoid
Xperror_with_name (text)
X     char *text;
X{
X  fprintf (stderr, "%s: ", program);
X  perror (text);
X}
X
X/* Use when a system call returns non-zero status and that is fatal.  */
X
Xvoid
Xpfatal_with_name (text)
X     char *text;
X{
X  print_message_queue ();
X  fprintf (stderr, "%s: ", program);
X  perror (text);
X  exit (2);
X}
X
X/* Print an error message from the format-string FORMAT
X   with args ARG1 and ARG2.  */
X
Xvoid
Xerror (format, arg, arg1)
X     char *format;
X     char *arg;
X     char *arg1;
X{
X  fprintf (stderr, "%s: ", program);
X  fprintf (stderr, format, arg, arg1);
X  fprintf (stderr, "\n");
X}
X
X/* Print an error message containing the string TEXT, then exit.  */
X
Xvoid
Xfatal (message)
X     char *message;
X{
X  print_message_queue ();
X  error (message, "");
X  exit (2);
X}
X
X/* Like printf, except if -l in effect then save the message and print later.
X   This is used for things like "binary files differ" and "Only in ...".  */
X
Xvoid
Xmessage (format, arg1, arg2)
X     char *format, *arg1, *arg2;
X{
X  if (paginate_flag)
X    {
X      struct msg *new = (struct msg *) xmalloc (sizeof (struct msg));
X      if (msg_chain_end == 0)
X	msg_chain = msg_chain_end = new;
X      else
X	{
X	  msg_chain_end->next = new;
X	  msg_chain_end = new;
X	}
X      new->format = format;
X      new->arg1 = concat (arg1, "", "");
X      new->arg2 = concat (arg2, "", "");
X      new->next = 0;
X    }
X  else
X    printf (format, arg1, arg2);
X}
X
X/* Output all the messages that were saved up by calls to `message'.  */
X
Xvoid
Xprint_message_queue ()
X{
X  struct msg *m;
X
X  for (m = msg_chain; m; m = m->next)
X    printf (m->format, m->arg1, m->arg2);
X}
X
X/* Call before outputting the results of comparing files NAME0 and NAME1
X   to set up OUTFILE, the stdio stream for the output to go to.
X
X   Usually, OUTFILE is just stdout.  But when -l was specified
X   we fork off a `pr' and make OUTFILE a pipe to it.
X   `pr' then outputs to our stdout.  */
X
Xvoid
Xsetup_output (name0, name1, depth)
X     char *name0, *name1;
X     int depth;
X{
X  char *name;
X
X  /* Construct the header of this piece of diff.  */
X  name = (char *) xmalloc (strlen (name0) + strlen (name1)
X			   + strlen (switch_string) + 15);
X
X  strcpy (name, "diff");
X  strcat (name, switch_string);
X  strcat (name, " ");
X  strcat (name, name0);
X  strcat (name, " ");
X  strcat (name, name1);
X
X  if (paginate_flag)
X    {
X#ifndef AMIGA
X      int pipes[2];
X      int desc;
X
X      /* For a `pr' and make OUTFILE a pipe to it.  */
X      pipe (pipes);
X
X      fflush (stdout);
X
X      desc = vfork ();
X      if (desc < 0)
X	pfatal_with_name ("vfork");
X
X      if (desc == 0)
X	{
X	  close (pipes[1]);
X	  close (fileno (stdin));
X	  if (dup2 (pipes[0], fileno (stdin)) < 0)
X	    pfatal_with_name ("dup2");
X	  close (pipes[0]);
X
X	  if (execl (PR_FILE_NAME, PR_FILE_NAME, "-f", "-h", name, 0) < 0)
X	    pfatal_with_name (PR_FILE_NAME);
X	}
X      else
X	{
X	  close (pipes[0]);
X	  outfile = fdopen (pipes[1], "w");
X	}
X#endif
X    }
X  else
X    {
X
X      /* If -l was not specified, output the diff straight to `stdout'.  */
X
X      outfile = stdout;
X
X      /* If handling multiple files (because scanning a directory),
X	 print which files the following output is about.  */
X      if (depth > 0)
X	printf ("%s\n", name);
X    }
X
X  free (name);
X}
X
X/* Call after the end of output of diffs for one file.
X   Close OUTFILE and get rid of the `pr' subfork.  */
X
Xvoid
Xfinish_output ()
X{
X  if (outfile != stdout)
X    {
X      fclose (outfile);
X#ifndef AMIGA
X      wait (0);
X#endif
X    }
X}
X
X/* Compare two lines (typically one from each input file)
X   according to the command line options.
X   Each line is described by a `struct line_def'.
X   Return 1 if the lines differ, like `bcmp'.  */
X
Xint
Xline_cmp (s1, s2)
X     struct line_def *s1, *s2;
X{
X  register char *t1, *t2;
X  register char end_char = line_end_char;
X  int savechar;
X
X  /* Check first for exact identity.
X     If that is true, return 0 immediately.
X     This detects the common case of exact identity
X     faster than complete comparison would.  */
X
X  t1 = s1->text;
X  t2 = s2->text;
X
X  /* Alter the character following line 1 so it doesn't
X     match that following line 2.  */
X  savechar = s1->text[s1->length];
X  s1->text[s1->length] = s2->text[s2->length] + 1;
X
X  /* Now find the first mismatch; this won't go past the
X     character we just changed.  */
X  while (*t1++ == *t2++);
X
X  /* Undo the alteration.  */
X  s1->text[s1->length] = savechar;
X
X  /* If the comparison stopped at the alteration,
X     the two lines are identical.  */
X  if (t1 == s1->text + s1->length + 1)
X    return 0;
X
X  /* Not exactly identical, but perhaps they match anyway
X     when case or whitespace is ignored.  */
X
X  if (ignore_case_flag || ignore_space_change_flag || ignore_all_space_flag)
X    {
X      t1 = s1->text;
X      t2 = s2->text;
X
X      while (1)
X	{
X	  register char c1 = *t1++;
X	  register char c2 = *t2++;
X
X	  /* Ignore horizontal whitespace if -b or -w is specified.  */
X
X	  if (ignore_all_space_flag)
X	    {
X	      /* For -w, just skip past any spaces or tabs.  */
X	      while (c1 == ' ' || c1 == '\t') c1 = *t1++;
X	      while (c2 == ' ' || c2 == '\t') c2 = *t2++;
X	    }
X	  else if (ignore_space_change_flag)
X	    {
X	      /* For -b, advance past any sequence of whitespace in line 1
X		 and consider it just one Space, or nothing at all
X		 if it is at the end of the line.  */
X	      if (c1 == ' ' || c1 == '\t')
X		{
X		  while (1)
X		    {
X		      c1 = *t1++;
X		      if (c1 == end_char)
X			break;
X		      if (c1 != ' ' && c1 != '\t')
X			{
X			  --t1;
X			  c1 = ' ';
X			  break;
X			}
X		    }
X		}
X
X	      /* Likewise for line 2.  */
X	      if (c2 == ' ' || c2 == '\t')
X		{
X		  while (1)
X		    {
X		      c2 = *t2++;
X		      if (c2 == end_char)
X			break;
X		      if (c2 != ' ' && c2 != '\t')
X			{
X			  --t2;
X			  c2 = ' ';
X			  break;
X			}
X		    }
X		}
X	    }
X
X	  /* Upcase all letters if -i is specified.  */
X
X	  if (ignore_case_flag)
X	    {
X	      if (islower (c1))
X		c1 = toupper (c1);
X	      if (islower (c2))
X		c2 = toupper (c2);
X	    }
X
X	  if (c1 != c2)
X	    break;
X	  if (c1 == end_char)
X	    return 0;
X	}
X    }
X
X  return (1);
X}
X
X/* Find the consecutive changes at the start of the script START.
X   Return the last link before the first gap.  */
X
Xstruct change *
Xfind_change (start)
X     struct change *start;
X{
X  return start;
X}
X
Xstruct change *
Xfind_reverse_change (start)
X     struct change *start;
X{
X  return start;
X}
X
X/* Divide SCRIPT into pieces by calling HUNKFUN and
X   print each piece with PRINTFUN.
X   Both functions take one arg, an edit script.
X
X   HUNKFUN is called with the tail of the script
X   and returns the last link that belongs together with the start
X   of the tail.
X
X   PRINTFUN takes a subscript which belongs together (with a null
X   link at the end) and prints it.  */
X
Xvoid
Xprint_script (script, hunkfun, printfun)
X     struct change *script;
X     struct change * (*hunkfun) ();
X     void (*printfun) ();
X{
X  struct change *next = script;
X
X  while (next)
X    {
X      struct change *this, *end;
X
X      /* Find a set of changes that belong together.  */
X      this = next;
X      end = (*hunkfun) (next);
X
X      /* Disconnect them from the rest of the changes,
X	 making them a hunk, and remember the rest for next iteration.  */
X      next = end->link;
X      end->link = NULL;
X#ifdef MYDEBUG
X      debug_script (this);
X#endif
X
X      /* Print this hunk.  */
X      (*printfun) (this);
X
X      /* Reconnect the script so it will all be freed properly.  */
X      end->link = next;
X    }
X}
X
X/* Print the text of a single line LINE,
X   flagging it with the characters in LINE_FLAG (which say whether
X   the line is inserted, deleted, changed, etc.).  */
X
Xvoid
Xprint_1_line (line_flag, line)
X     char *line_flag;
X     struct line_def *line;
X{
X  fprintf (outfile, "%s", line_flag);
X
X  /* If -T was specified, use a Tab between the line-flag and the text.
X     Otherwise use a Space (as Unix diff does).
X     Print neither space nor tab if line-flags are empty.  */
X
X  if (line_flag[0] != 0)
X    {
X      if (tab_align_flag)
X	fprintf (outfile, "\t");
X      else
X	fprintf (outfile, " ");
X    }
X
X  /* Now output the contents of the line.
X     If -t was specified, expand tabs to spaces.
X     Otherwise output verbatim.  */
X
X  if (tab_expand_flag)
X    {
X      register int column = 0;
X      register int i;
X      for (i = 0; i <= line->length; i++)
X	{
X	  register char c = line->text[i];
X	  if (c == '\t')
X	    {
X	      putc (' ', outfile);
X	      column++;
X	      while (column & 7)
X		{
X		  putc (' ', outfile);
X		  column++;
X		}
X	    }
X	  else if (c == '\b')
X	    {
X	      column--;
X	      putc (c, outfile);
X	    }
X	  else
X	    {
X	      column++;
X	      putc (c, outfile);
X	    }
X	}
X    }
X  else
X    fwrite (line->text, sizeof (char), line->length + 1, outfile);
X
X  if (line_end_char != '\n')
X    putc ('\n', outfile);
X}
X
Xchange_letter (inserts, deletes)
X     int inserts, deletes;
X{
X  if (!inserts)
X    return 'd';
X  else if (!deletes)
X    return 'a';
X  else
X    return 'c';
X}
X
X/* Translate an internal line number (an index into diff's table of lines)
X   into an actual line number in the input file.
X   The internal line number is LNUM.  FILE points to the data on the file.
X
X   Internal line numbers count from 0 within the current chunk.
X   Actual line numbers count from 1 within the entire file;
X   in addition, they include lines ignored for comparison purposes.
X
X   The `ltran' feature is no longer in use.  */
X
Xint
Xtranslate_line_number (file, lnum)
X     struct file_data *file;
X     int lnum;
X{
X  return lnum + 1;
X}
X
Xvoid
Xtranslate_range (file, a, b, aptr, bptr)
X     struct file_data *file;
X     int a, b;
X     int *aptr, *bptr;
X{
X  *aptr = translate_line_number (file, a - 1) + 1;
X  *bptr = translate_line_number (file, b + 1) - 1;
X}
X
X/* Print a pair of line numbers with SEPCHAR, translated for file FILE.
X   If the two numbers are identical, print just one number.
X
X   Args A and B are internal line numbers.
X   We print the translated (real) line numbers.  */
X
Xvoid
Xprint_number_range (sepchar, file, a, b)
X     char sepchar;
X     struct file_data *file;
X     int a, b;
X{
X  int trans_a, trans_b;
X  translate_range (file, a, b, &trans_a, &trans_b);
X
X  /* Note: we can have B < A in the case of a range of no lines.
X     In this case, we should print the line number before the range,
X     which is B.  */
X  if (trans_b > trans_a)
X    fprintf (outfile, "%d%c%d", trans_a, sepchar, trans_b);
X  else
X    fprintf (outfile, "%d", trans_b);
X}
X
X/* Look at a hunk of edit script and report the range of lines in each file
X   that it applies to.  HUNK is the start of the hunk, which is a chain
X   of `struct change'.  The first and last line numbers of file 0 are stored in
X   *FIRST0 and *LAST0, and likewise for file 1 in *FIRST1 and *LAST1. 
X   Note that these are internal line numbers that count from 0.
X
X   If no lines from file 0 are deleted, then FIRST0 is LAST0+1.
X
X   Also set *DELETES nonzero if any lines of file 0 are deleted
X   and set *INSERTS nonzero if any lines of file 1 are inserted.
X   If only ignorable lines are inserted or deleted, both are
X   set to 0.  */
X
Xvoid
Xanalyze_hunk (hunk, first0, last0, first1, last1, deletes, inserts)
X     struct change *hunk;
X     int *first0, *last0, *first1, *last1;
X     int *deletes, *inserts;
X{
X  int f0, l0, f1, l1, show_from, show_to;
X  int i;
X  int nontrivial = !(ignore_blank_lines_flag || ignore_regexp);
X  struct change *next;
X
X  show_from = show_to = 0;
X
X  f0 = hunk->line0;
X  f1 = hunk->line1;
X
X  for (next = hunk; next; next = next->link)
X    {
X      l0 = next->line0 + next->deleted - 1;
X      l1 = next->line1 + next->inserted - 1;
X      show_from += next->deleted;
X      show_to += next->inserted;
X
X      for (i = next->line0; i <= l0 && ! nontrivial; i++)
X	if ((!ignore_blank_lines_flag || files[0].linbuf[i].length > 1)
X	    && (!ignore_regexp
X		|| 0 > re_search (&ignore_regexp_compiled,
X				  files[0].linbuf[i].text,
X				  files[0].linbuf[i].length, 0,
X				  files[0].linbuf[i].length, 0)))
X	  nontrivial = 1;
X
X      for (i = next->line1; i <= l1 && ! nontrivial; i++)
X	if ((!ignore_blank_lines_flag || files[1].linbuf[i].length > 1)
X	    && (!ignore_regexp
X		|| 0 > re_search (&ignore_regexp_compiled,
X				  files[1].linbuf[i].text,
X				  files[1].linbuf[i].length, 0,
X				  files[1].linbuf[i].length, 0)))
X	  nontrivial = 1;
X    }
X
X  *first0 = f0;
X  *last0 = l0;
X  *first1 = f1;
X  *last1 = l1;
X
X  /* If all inserted or deleted lines are ignorable,
X     tell the caller to ignore this hunk.  */
X
X  if (!nontrivial)
X    show_from = show_to = 0;
X
X  *deletes = show_from;
X  *inserts = show_to;
X}
X
X/* malloc a block of memory, with fatal error message if we can't do it. */
X
Xvoid *
Xxmalloc (size)
X     unsigned size;
X{
X  register void *value;
X
X  if (!size) size = 4;
X
X  if (!(value = (void *) malloc (size)))
X    fatal ("virtual memory exhausted");
X  return value;
X}
X
X/* realloc a block of memory, with fatal error message if we can't do it. */
X
Xvoid *
Xxrealloc (old, size)
X     void *old;
X     unsigned int size;
X{
X  register void *value;
X
X  if (!size) size = 4;
X
X  if (!(value = (void *) realloc (old, size)))
X    fatal ("virtual memory exhausted");
X  return value;
X}
X
Xvoid *
Xxcalloc (nitems, size)
X     int nitems, size;
X{
X  void *value;
X
X  if (!size) size = 4;
X
X  if (!(value = (void *) calloc (nitems, size)))
X    fatal ("virtual memory exhausted");
X  return value;
X}
X
X/* Concatenate three strings, returning a newly malloc'd string.  */
X
Xchar *
Xconcat (s1, s2, s3)
X     char *s1, *s2, *s3;
X{
X  int len = strlen (s1) + strlen (s2) + strlen (s3);
X  char *new = (char *) xmalloc (len + 1);
X  strcpy (new, s1);
X  strcat (new, s2);
X  strcat (new, s3);
X  return new;
X}
X
Xdebug_script (sp)
X     struct change *sp;
X{
X  fflush (stdout);
X  for (; sp; sp = sp->link)
X    fprintf (stderr, "%3d %3d delete %d insert %d\n",
X	     sp->line0, sp->line1, sp->deleted, sp->inserted);
X  fflush (stderr);
X  return(0);
X}
SHAR_EOF
echo "extracting diff/dir.h"
sed 's/^X//' << \SHAR_EOF > diff/dir.h
X#ifndef DIR_H
X#define DIR_H
X
X#ifndef	EXEC_TYPES_H
X#include "exec/types.h"
X#endif
X
X#ifndef	LIBRARIES_DOS_H
X#include "libraries/dos.h"
X#endif
X
X#ifndef	LIBRARIES_DOSEXTENS_H
X#include "libraries/dosextens.h"
X#endif
X/*
X * MAXNAMELEN is the maximum length a file name can be. The direct structure
X * is lifted form 4BSD, and has not been changed so that code which uses
X * it will be compatable with 4BSD code. d_ino and d_reclen are unused,
X * and will probably be set to some non-zero value.
X */
X#define	MAXNAMLEN	31		/* AmigaDOS file max length */
X
Xstruct	direct {
X	ULONG	d_ino ;			/* unused - there for compatability */
X	USHORT	d_reclen ;		/* ditto */
X	USHORT	d_namlen ;		/* length of string in d_name */
X	char	d_name[MAXNAMLEN + 1] ;	/* name must be no longer than this */
X};
X/*
X * The DIRSIZ macro gives the minimum record length which will hold
X * the directory entry.  This requires the amount of space in struct direct
X * without the d_name field, plus enough space for the name with a terminating
X * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
X */
X
X#undef DIRSIZ
X#define DIRSIZ(dp) \
X    ((sizeof(struct direct) - (MAXNAMLEN+1)) + (((dp) -> d_namlen+1 + 3) &~ 3))
X/*
X * The DIR structure holds the things that AmigaDOS needs to know about
X * a file to keep track of where it is and what it's doing.
X */
X
Xtypedef struct {
X	struct FileInfoBlock	d_info ,	/* Default info block */
X				d_seek ;	/* Info block for seeks */
X	struct FileLock		*d_lock ;	/* Lock on directory */
X	} DIR ;
X	
Xextern	DIR *opendir(char *) ;
Xextern	struct direct *readdir(DIR *) ;
Xextern	long telldir(DIR *) ;
Xextern	void seekdir(DIR *, long) ;
Xextern	void rewinddir(DIR *) ;
Xextern	void closedir(DIR *) ;
X#endif	DIR_H
SHAR_EOF
echo "extracting diff/getopt.c"
sed 's/^X//' << \SHAR_EOF > diff/getopt.c
X/*
X * From std-unix@ut-sally.UUCP (Moderator, John Quarterman) Sun Nov  3 14:34:15 1985
X * Relay-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site gatech.CSNET
X * Posting-Version: version B 2.10.2 9/18/84; site ut-sally.UUCP
X * Path: gatech!akgua!mhuxv!mhuxt!mhuxr!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!ut-sally!std-unix
X * From: std-unix@ut-sally.UUCP (Moderator, John Quarterman)
X * Newsgroups: mod.std.unix
X * Subject: public domain AT&T getopt source
X * Message-ID: <3352@ut-sally.UUCP>
X * Date: 3 Nov 85 19:34:15 GMT
X * Date-Received: 4 Nov 85 12:25:09 GMT
X * Organization: IEEE/P1003 Portable Operating System Environment Committee
X * Lines: 91
X * Approved: jsq@ut-sally.UUCP
X * 
X * Here's something you've all been waiting for:  the AT&T public domain
X * source for getopt(3).  It is the code which was given out at the 1985
X * UNIFORUM conference in Dallas.  I obtained it by electronic mail
X * directly from AT&T.  The people there assure me that it is indeed
X * in the public domain.
X * 
X * There is no manual page.  That is because the one they gave out at
X * UNIFORUM was slightly different from the current System V Release 2
X * manual page.  The difference apparently involved a note about the
X * famous rules 5 and 6, recommending using white space between an option
X * and its first argument, and not grouping options that have arguments.
X * Getopt itself is currently lenient about both of these things White
X * space is allowed, but not mandatory, and the last option in a group can
X * have an argument.  That particular version of the man page evidently
X * has no official existence, and my source at AT&T did not send a copy.
X * The current SVR2 man page reflects the actual behavor of this getopt.
X * However, I am not about to post a copy of anything licensed by AT&T.
X * 
X * I will submit this source to Berkeley as a bug fix.
X * 
X * I, personally, make no claims or guarantees of any kind about the
X * following source.  I did compile it to get some confidence that
X * it arrived whole, but beyond that you're on your own.
X * 
X */
X
X/*LINTLIBRARY*/
X
X#ifndef NULL
X#define NULL	0
X#endif
X
X#ifndef EOF
X#define EOF	(-1)
X#endif
X
X#define ERR(s, c)	if(opterr){\
X	extern int strlen(), write();\
X	char errbuf[2];\
X	errbuf[0] = c; errbuf[1] = '\n';\
X	(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
X	(void) write(2, s, (unsigned)strlen(s));\
X	(void) write(2, errbuf, (unsigned)2);}
X
Xextern int strcmp();
Xextern char *strchr();
X
Xint	opterr = 1;
Xint	optind = 1;
Xint	optopt;
Xchar	*optarg;
X
Xint
Xgetopt(argc, argv, opts)
Xint	argc;
Xchar	**argv, *opts;
X{
X	static int sp = 1;
X	register int c;
X	register char *cp;
X
X	if(sp == 1)
X		if(optind >= argc ||
X		   argv[optind][0] != '-' || argv[optind][1] == '\0')
X			return(EOF);
X		else if(strcmp(argv[optind], "--") == NULL) {
X			optind++;
X			return(EOF);
X		}
X	optopt = c = argv[optind][sp];
X	if(c == ':' || (cp=strchr(opts, c)) == NULL) {
X		ERR("illegal option: ", c);
X		if(argv[optind][++sp] == '\0') {
X			optind++;
X			sp = 1;
X		}
X		return('?');
X	}
X	if(*++cp == ':') {
X		if(argv[optind][sp+1] != '\0' && argv[optind][sp+1] != '-')
X			optarg = &argv[optind++][sp+1];
X		else if(++optind >= argc || argv[optind][0] == '-') {
X			ERR("option requires an argument: ", c);
X			sp = 1;
X			return('?');
X		} else
X			optarg = argv[optind++];
X		sp = 1;
X	} else {
X		if(argv[optind][++sp] == '\0') {
X			sp = 1;
X			optind++;
X		}
X		optarg = NULL;
X	}
X	return(c);
X}
SHAR_EOF
echo "extracting diff/ndir.c"
sed 's/^X//' << \SHAR_EOF > diff/ndir.c
X/*
X * ndir - routines to simulate the 4BSD new directory code for AmigaDOS.
X */
X#include "dir.h"
X
XDIR *
Xopendir(dirname) char *dirname; {
X	register DIR	*my_dir, *AllocMem(int, int) ;
X	struct FileLock	*Lock(char *, int), *CurrentDir(struct FileLock *) ;
X
X	if ((my_dir = AllocMem(sizeof(DIR), 0)) == NULL) return NULL ;
X
X
X	if (((my_dir -> d_lock = Lock(dirname, ACCESS_READ)) == NULL)
X	/* If we can't examine it */
X	||  !Examine(my_dir -> d_lock, &(my_dir -> d_info))
X	/* Or it's not a directory */
X	||  (my_dir -> d_info . fib_DirEntryType < 0)) {
X		FreeMem(my_dir, sizeof(DIR)) ;
X		return NULL ;
X		}
X	return my_dir ;
X	}
X
Xstruct direct *
Xreaddir(my_dir) DIR *my_dir; {
X	static struct direct	result ;
X
X	if (!ExNext(my_dir -> d_lock, &(my_dir -> d_info))) return NULL ;
X
X	result . d_reclen = result . d_ino = 1 ;	/* Not NULL! */
X	(void) strcpy(result . d_name, my_dir -> d_info . fib_FileName) ;
X	result . d_namlen = strlen(result . d_name) ;
X	return &result ;
X	}
X
Xvoid
Xclosedir(my_dir) DIR *my_dir; {
X
X	UnLock(my_dir -> d_lock) ;
X	FreeMem(my_dir, sizeof(DIR)) ;
X	}
X/*
X * telldir and seekdir don't work quite right. The problem is that you have
X * to save more than a long's worth of stuff to indicate position, and it's
X * socially unacceptable to alloc stuff that you don't free later under
X * AmigaDOS. So we fake it - you get one level of seek, and dat's all.
X * As of now, these things are untested.
X */
X#define DIR_SEEK_RETURN		((long) 1)	/* Not 0! */
Xlong
Xtelldir(my_dir) DIR *my_dir; {
X
X	my_dir -> d_seek = my_dir -> d_info ;
X	return (long) DIR_SEEK_RETURN ;
X	}
X
Xvoid
Xseekdir(my_dir, where) DIR *my_dir; long where; {
X
X	if (where == DIR_SEEK_RETURN)
X		my_dir -> d_info = my_dir -> d_seek ;
X	else	/* Makes the next readdir fail */
X		setmem((char *) my_dir, sizeof(DIR), 0) ;
X	}
X
Xvoid
Xrewinddir(my_dir) DIR *my_dir; {
X
X	if (!Examine(my_dir -> d_lock, &(my_dir -> d_info)))
X		setmem((char *) my_dir, sizeof(DIR), 0) ;
X	}
X#ifdef	TEST
X/*
X * Simple code to list the files in the argument directory,
X *	lifted straight from the man page.
X */
X#include <stdio.h>
Xvoid
Xmain(argc, argv) int argc; char **argv; {
X	register DIR		*dirp ;
X	register struct direct	*dp ;
X	register char		*name ;
X
X	if (argc < 2) name = "" ;
X	else name = argv[1] ;
X
X	if ((dirp = opendir(name)) == NULL) {
X		fprintf(stderr, "Bogus! Can't opendir %s\n", name) ;
X		exit(1) ;
X		}
X
X	for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
X		printf("%s ", dp -> d_name) ;
X	closedir(dirp);
X	putchar('\n') ;
X	}
X#endif	TEST
X
SHAR_EOF
echo "extracting diff/makefile"
sed 's/^X//' << \SHAR_EOF > diff/makefile
X#$Header$
X#
X#
X#
X#
X#
X.SILENT:
X
XCC1=lc1
XCC2=go
XCC3=lc2
XC1FLAGS	= -j85i -d3
XC2FLAGS	=
XC3FLAGS	=
X
X#.c.o:
X#	$(CC1) -. $(C1FLAGS) $(CFLAGS) -oQUAD: $*
X#	$(CC2) -. $(C2FLAGS) QUAD:$*.q
X#	$(CC3) -. $(C3FLAGS) -o$*.o QUAD:$*.q
X#
X.c.o:
X	$(CC1) -. $(C1FLAGS) $(CFLAGS) -oQUAD: $*
X	$(CC3) -. $(C3FLAGS) -o$*.o QUAD:$*.q
X#
X#
X
XRCSDIR	= RCS:
X
XDIFF	= ${RCSDIR}diff
XDIFF3	= ${RCSDIR}diff3
XED	= ${RCSDIR}ked
X
XOS	= -dAMIGA
XARGS	= -dSTDARGS
X
XSIGNAL_TYPE = void
X
XLOCKING	= 1
X
XLDFLAGS	= quiet batch nodebug
XLDLIBS	= LIB:rsbx.lib LIB:lc.lib LIB:amiga.lib
X
XDEFINES	= $(OS) $(ARGS) -dSIGNAL_TYPE=$(SIGNAL_TYPE) -dSTRICT_LOCKING=$(LOCKING) -dED="$(ED)" -dDIFF="$(DIFF)" -dDIFF3="$(DIFF3)" -dCO="${RCSDIR}co" -dMERGE="${RCSDIR}merge"
XCFLAGS	= $(DEFINES)
X
XTARGETS = diff diff3
X
X
X
X
Xall:	$(TARGETS)
X
X
Xinstall:
X	copy diff  to RCS:
X	copy diff3 to RCS:
X
X
Xclean:
X	-delete \#?.o
X	-delete $(TARGETS)
X	-delete \#?.tmp
X
X
XDIFFOBJ	= analyze.o context.o diff.o ed.o io.o normal.o regex.o util.o getopt.o dir.o ndir.o amiga1.o
XDIFFSRC = analyze.c context.c diff.c ed.c io.c normal.c regex.c util.c getopt.c dir.c ndir.c amiga1.c
Xdiff:	$(DIFFOBJ) $(LDLIBS)
X	-delete $@
X	${LD} $(LDFLAGS) TO $@.tmp FROM LIB:xc.o $(DIFFOBJ) LIB $(LDLIBS)
X	rename $@.tmp $@
X
X
XDIFF3OBJ = diff3.o getopt.o
XDIFF3SRC = diff3.c getopt.c
Xdiff3:	$(DIFF3OBJ) $(LDLIBS)
X	-delete $@
X	${LD} $(LDFLAGS) TO $@.tmp FROM LIB:xc.o $(DIFF3OBJ) LIB $(LDLIBS)
X	rename $@.tmp $@
X
X
XSOURCE=	analyze.c context.c diff.c diff3.c dir.c ed.c getopt.c io.c ndir.c normal.c regex.c util.c \
X	amiga1.c
X
X
XHFILES=	diff.h dir.h limits.h regex.h stat.h
X
Xdepend:	${SOURCE} ${HFILES}
X	(sed '/^# DO NOT DELETE THIS LINE/q' Makefile && \
X	 cc -Em ${CFLAGS} ${SOURCE} | sed 's/\.\///; /\//d' \
X	) >Makefile.new
X	cp Makefile Makefile.bak
X	cp Makefile.new Makefile
X	rm -f Makefile.new
X
X
X# DO NOT DELETE THIS LINE - 
Xanalyze.o: analyze.c
Xanalyze.o: regex.h
Xanalyze.o: diff.h
Xcontext.o: context.c
Xcontext.o: diff.h
Xcontext.o: regex.h
Xdiff.o: diff.c
Xdiff.o: regex.h
Xdiff.o: diff.h
Xdiff3.o: diff3.c
Xdir.o: dir.c
Xdir.o: diff.h
Xdir.o: regex.h
Xed.o: ed.c
Xed.o: diff.h
Xed.o: regex.h
Xgetopt.o: getopt.c
Xio.o: io.c
Xio.o: diff.h
Xio.o: regex.h
Xndir.o: ndir.c
Xndir.o: dir.h
Xnormal.o: normal.c
Xnormal.o: diff.h
Xnormal.o: regex.h
Xregex.o: regex.c
Xregex.o: regex.h
Xutil.o: util.c
Xutil.o: diff.h
Xutil.o: regex.h
Xamiga1.o: amiga1.c
Xamiga1.o: stat.h
SHAR_EOF
echo "extracting diff/amiga1.c"
sed 's/^X//' << \SHAR_EOF > diff/amiga1.c
X/*
X**  Glue functions for the RCS system needed for the Amiga
X*/
X
X#include <stdio.h>
X#include <errno.h>
X#include <proto/exec.h>
X#include <exec/tasks.h>
X#include <ios1.h>
X#include <dos.h>
X#include <fcntl.h>
X#include <exec/exec.h>
X#include <libraries/dosextens.h>
X#include "stat.h"
X#include <stdarg.h>
X
X
X
Xumask(mode)
X{
X	return mode;
X}
X
X/*
X** This function is used in place of the lattice library function of
X** the same name.  It handles all modes, not just "rwed".
X*/
Xchmod(name,mode)
Xchar	*name;
Xint	mode;
X{
X	long	amigamode;
X	int	success;
X
X	amigamode = mode;
X	success = SetProtection(name,amigamode);
X	if (success)
X		return(0);
X	errno = ENOENT;
X	return(-1);
X}
X
Xint stat(name,buf)
Xchar	*name;
Xstruct stat *buf;
X{
X	long l;
X	struct FileInfoBlock *fp,*malloc();
X
X	if ((l=Lock(name, ACCESS_READ)) == 0)
X		return(-1);
X	fp = malloc(sizeof(struct FileInfoBlock));
X	Examine(l, fp);
X	buf->st_attr = fp->fib_Protection;
X	buf->st_size = fp->fib_Size;
X	buf->st_type = fp->fib_DirEntryType;
X	UnLock(l);
X	free(fp);
X	buf->st_mtime = getft(name);
X	return 0;
X}
X
Xisatty(fd)
Xint		fd;
X{
X	long IsInteractive();
X	struct UFB	*ufb;
X
X	ufb = chkufb(fd);
X	if (ufb == NULL)
X		return(-1);
X	return(IsInteractive(ufb->ufbfh) != 0);
X}
SHAR_EOF
echo "extracting diff/readme"
sed 's/^X//' << \SHAR_EOF > diff/readme
XThis directory contains the GNU DIFF and DIFF3 utilities, version 1.10.
XSee file COPYING for copying conditions.  To compile and install on
Xsystem V, you must edit the makefile according to comments therein.
X
XReport bugs to bug-gnu-utils@prep.ai.mit.edu
X 
XThis version of diff provides all the features of BSD's diff.
XIt has these additional features:
X
X   -a	Always treat files as text and compare them line-by-line,
X	even if they do not appear to be ASCII.
X
X   -B	ignore changes that just insert or delete blank lines.
X
X   -C #
X	request -c format and specify number of context lines.
X
X   -F regexp
X	in context format, for each unit of differences, show some of
X	the last preceding line that matches the specified regexp.
X
X   -H	use heuristics to speed handling of large files that
X	have numerous scattered small changes.  The algorithm becomes
X        asymptotically linear for such files!
X	
X   -I regexp
X	ignore changes that just insert or delete lines that
X	match the specified regexp.
X
X   -N	in directory comparison, if a file is found in only one directory,
X	treat it as present but empty in the other directory.
X
X   -p	equivalent to -c -F'^[_a-zA-Z]'.  This is useful for C code
X	because it shows which function each change is in.
X
X   -T	print a tab rather than a space before the text of a line
X	in normal or context format.  This causes the alignment
X	of tabs in the line to look normal.
X
X
X
XGNU DIFF was written by Mike Haertel, David Hayes, Richard Stallman
Xand Len Tower.  The basic algorithm is described in: "An O(ND)
XDifference Algorithm and its Variations", Eugene Myers, Algorithmica
XVol. 1 No. 2, 1986, p 251.
X
X
XSuggested projects for improving GNU DIFF:
X
X* Handle very large files by not keeping the entire text in core.
X
XOne way to do this is to scan the files sequentally to compute hash
Xcodes of the lines and put the lines in equivalence classes based only
Xon hash code.  Then compare the files normally.  This will produce
Xsome false matches.
X
XThen scan the two files sequentially again, checking each match to see
Xwhether it is real.  When a match is not real, mark both the
X"matching" lines as changed.  Then build an edit script as usual.
X
XThe output routines would have to be changed to scan the files
Xsequentially looking for the text to print.
SHAR_EOF
echo "extracting diff/diff.h"
sed 's/^X//' << \SHAR_EOF > diff/diff.h
X/* Shared definitions for GNU DIFF
X   Copyright (C) 1988, 1989 Free Software Foundation, Inc.
X
XThis file is part of GNU DIFF.
X
XGNU DIFF is free software; you can redistribute it and/or modify
Xit under the terms of the GNU General Public License as published by
Xthe Free Software Foundation; either version 1, or (at your option)
Xany later version.
X
XGNU DIFF is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY; without even the implied warranty of
XMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
XGNU General Public License for more details.
X
XYou should have received a copy of the GNU General Public License
Xalong with GNU DIFF; see the file COPYING.  If not, write to
Xthe Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
X
X
X#include <ctype.h>
X#include <stdio.h>
X#ifndef AMIGA
X#include <sys/types.h>
X#include <sys/stat.h>
X
X#ifdef USG
X#include <time.h>
X#ifdef hp9000s800
X#include <ndir.h>
X#else
X#include <dirent.h>
X#endif
X#include <fcntl.h>
X#define direct dirent
X#else
X#include <sys/time.h>
X#include <sys/dir.h>
X#include <sys/file.h>
X#endif USG
X#else
X#include "stat.h"
X#include "dir.h"
X#ifndef RE_NREGS
X#include "regex.h"
X#endif
X#endif AMIGA
X
X#ifdef AMIGA
X#define bcmp(a,b,l) memcmp((a),(b),(l))
X#define bcopy(f,t,l) movmem((f),(t),(l))
X#define bzero(a,l) memset((a),0,(l))
X#define index	strchr
X#define rindex	strrchr
X#endif
X
X#ifdef USG
X/* Define needed BSD functions in terms of sysV library.  */
X
X#define bcopy(s,d,n)	memcpy((d),(s),(n))
X#define bcmp(s1,s2,n)	memcmp((s1),(s2),(n))
X#define bzero(s,n)	memset((s),0,(n))
X
X#define dup2(f,t)	(close(t),fcntl((f),F_DUPFD,(t)))
X
X#define vfork	fork
X#define index	strchr
X#define rindex	strrchr
X#endif
X
X#include <errno.h>
Xextern int      errno;
Xextern int      sys_nerr;
Xextern char    *sys_errlist[];
X
X#define	EOS		(0)
X#ifdef AMIGA
X#undef FALSE
X#endif
X#define	FALSE		(0)
X#define TRUE		1
X
X#ifndef AMIGA
X#define min(a,b) ((a) <= (b) ? (a) : (b))
X#define max(a,b) ((a) >= (b) ? (a) : (b))
X#endif
X
X#ifndef PR_FILE_NAME
X#define PR_FILE_NAME "/bin/pr"
X#endif
X
X/* Support old-fashioned C compilers.  */
X#if defined (__STDC__) || defined (__GNUC__)
X#include "limits.h"
X#else
X#define INT_MAX 2147483647
X#define CHAR_BIT 8
X#endif
X
X/* Support old-fashioned C compilers.  */
X#if !defined (__STDC__) && !defined (__GNUC__)
X#define const
X#endif
X
X/* Variables for command line options */
X
X#ifndef GDIFF_MAIN
X#define EXTERN extern
X#else
X#define EXTERN
X#endif
X
Xenum output_style {
X  /* Default output style.  */
X  OUTPUT_NORMAL,
X  /* Output the differences with lines of context before and after (-c).  */
X  OUTPUT_CONTEXT,
X  /* Output the differences as commands suitable for `ed' (-e).  */
X  OUTPUT_ED,
X  /* Output the diff as a forward ed script (-f).  */
X  OUTPUT_FORWARD_ED,
X  /* Like -f, but output a count of changed lines in each "command" (-n). */
X  OUTPUT_RCS };
X
XEXTERN enum output_style output_style;
X
X/* Number of lines of context to show in each set of diffs.
X   This is zero when context is not to be shown.  */
XEXTERN int      context;
X
X/* Consider all files as text files (-a).
X   Don't interpret codes over 0177 as implying a "binary file".  */
XEXTERN int	always_text_flag;
X
X/* Ignore changes in horizontal whitespace (-b).  */
XEXTERN int      ignore_space_change_flag;
X
X/* Ignore all horizontal whitespace (-w).  */
XEXTERN int      ignore_all_space_flag;
X
X/* Ignore changes that affect only blank lines (-B).  */
XEXTERN int      ignore_blank_lines_flag;
X
X/* Ignore changes that affect only lines matching this regexp (-I).  */
XEXTERN char	*ignore_regexp;
X
X/* Result of regex-compilation of `ignore_regexp'.  */
XEXTERN struct re_pattern_buffer ignore_regexp_compiled;
X
X/* 1 if lines may match even if their lengths are different.
X   This depends on various options.  */
XEXTERN int      length_varies;
X
X/* Ignore differences in case of letters (-i).  */
XEXTERN int      ignore_case_flag;
X
X/* Regexp to identify function-header lines (-F).  */
XEXTERN char	*function_regexp;
X
X/* Result of regex-compilation of `function_regexp'.  */
XEXTERN struct re_pattern_buffer function_regexp_compiled;
X
X/* Report files compared that match (-s).
X   Normally nothing is output when that happens.  */
XEXTERN int      print_file_same_flag;
X
X/* character that ends a line.  Currently this is always `\n'.  */
XEXTERN char     line_end_char;
X
X/* Output the differences with exactly 8 columns added to each line
X   so that any tabs in the text line up properly (-T).  */
XEXTERN int	tab_align_flag;
X
X/* Expand tabs in the output so the text lines up properly
X   despite the characters added to the front of each line (-t).  */
XEXTERN int	tab_expand_flag;
X
X/* In directory comparison, specify file to start with (-S).
X   All file names less than this name are ignored.  */
XEXTERN char	*dir_start_file;
X
X/* If a file is new (appears in only one dir)
X   include its entire contents (-N).
X   Then `patch' would create the file with appropriate contents.  */
XEXTERN int	entire_new_file_flag;
X
X/* Pipe each file's output through pr (-l).  */
XEXTERN int	paginate_flag;
X
X/* String containing all the command options diff received,
X   with spaces between and at the beginning but none at the end.
X   If there were no options given, this string is empty.  */
XEXTERN char *	switch_string;
X
X/* Nonzero means use heuristics for better speed.  */
XEXTERN int	heuristic;
X
X/* Name of program the user invoked (for error messages).  */
XEXTERN char *	program;
X
X/* The result of comparison is an "edit script": a chain of `struct change'.
X   Each `struct change' represents one place where some lines are deleted
X   and some are inserted.
X   
X   LINE0 and LINE1 are the first affected lines in the two files (origin 0).
X   DELETED is the number of lines deleted here from file 0.
X   INSERTED is the number of lines inserted here in file 1.
X
X   If DELETED is 0 then LINE0 is the number of the line before
X   which the insertion was done; vice versa for INSERTED and LINE1.  */
X
Xstruct change
X{
X  struct change *link;		/* Previous or next edit command  */
X  int inserted;			/* # lines of file 1 changed here.  */
X  int deleted;			/* # lines of file 0 changed here.  */
X  int line0;			/* Line number of 1st deleted line.  */
X  int line1;			/* Line number of 1st inserted line.  */
X  char ignore;			/* Flag used in context.c */
X};
X
X/* Structures that describe the input files.  */
X
X/* Data on one line of text.  */
X
Xstruct line_def {
X    char        *text;
X    int         length;
X    unsigned	hash;
X};
X
X/* Data on one input file being compared.  */
X
Xstruct file_data {
X    int             desc;	/* File descriptor  */
X    char           *name;	/* File name  */
X    struct stat     stat;	/* File status from fstat()  */
X    int             dir_p;	/* 1 if file is a directory  */
X
X    /* Buffer in which text of file is read.  */
X    char *	    buffer;
X    /* Allocated size of buffer.  */
X    int		    bufsize;
X    /* Number of valid characters now in the buffer. */
X    int		    buffered_chars;
X
X    /* Array of data on analyzed lines of this chunk of this file.  */
X    struct line_def *linbuf;
X
X    /* Allocated size of linbuf array (# of elements).  */
X    int		    linbufsize;
X
X    /* Number of elements of linbuf containing valid data. */
X    int		    buffered_lines;
X
X    /* Pointer to end of prefix of this file to ignore when hashing. */
X    char *prefix_end;
X
X    /* Count of lines in the prefix. */
X    int prefix_lines;
X
X    /* Pointer to start of suffix of this file to ignore when hashing. */
X    char *suffix_begin;
X
X    /* Count of lines in the suffix. */
X    int suffix_lines;
X
X    /* Vector, indexed by line number, containing an equivalence code for
X       each line.  It is this vector that is actually compared with that
X       of another file to generate differences. */
X    int		   *equivs;
X
X    /* Vector, like the previous one except that
X       the elements for discarded lines have been squeezed out.  */
X    int		   *undiscarded;
X
X    /* Vector mapping virtual line numbers (not counting discarded lines)
X       to real ones (counting those lines).  Both are origin-0.  */
X    int		   *realindexes;
X
X    /* Total number of nondiscarded lines. */
X    int		    nondiscarded_lines;
X
X    /* Vector, indexed by real origin-0 line number,
X       containing 1 for a line that is an insertion or a deletion.
X       The results of comparison are stored here.  */
X    char	   *changed_flag;
X
X    /* 1 if file ends in a line with no final newline. */
X    int		    missing_newline;
X
X    /* 1 more than the maximum equivalence value used for this or its
X       sibling file. */
X    int equiv_max;
X
X    /* Table translating diff's internal line numbers 
X       to actual line numbers in the file.
X       This is needed only when some lines have been discarded.
X       The allocated size is always linbufsize
X       and the number of valid elements is buffered_lines.  */
X    int		   *ltran;
X};
X
X/* Describe the two files currently being compared.  */
X
XEXTERN struct file_data files[2];
X
X/* Queue up one-line messages to be printed at the end,
X   when -l is specified.  Each message is recorded with a `struct msg'.  */
X
Xstruct msg
X{
X  struct msg *next;
X  char *format;
X  char *arg1;
X  char *arg2;
X};
X
X/* Head of the chain of queues messages.  */
X
XEXTERN struct msg *msg_chain;
X
X/* Tail of the chain of queues messages.  */
X
XEXTERN struct msg *msg_chain_end;
X
X/* Stdio stream to output diffs to.  */
X
XEXTERN FILE *outfile;
X
X/* Declare various functions.  */
X
Xvoid *xmalloc ();
Xvoid *xrealloc ();
Xvoid *xcalloc();
Xchar *concat ();
Xvoid free ();
Xchar *rindex ();
Xchar *index ();
X
Xvoid message ();
Xvoid print_message_queue ();
SHAR_EOF
echo "extracting diff/limits.h"
sed 's/^X//' << \SHAR_EOF > diff/limits.h
X/* Number of bits in a `char'.  */
X#define CHAR_BIT 8
X
X/* No multibyte characters supported yet.  */
X#define MB_LEN_MAX 1
X
X/* Minimum and maximum values a `signed char' can hold.  */
X#define SCHAR_MIN -128
X#define SCHAR_MAX 127
X
X/* Maximum value an `unsigned char' can hold.  (Minimum is 0).  */
X#define UCHAR_MAX 255U
X
X/* Minimum and maximum values a `char' can hold.  */
X#ifdef __CHAR_UNSIGNED__
X#define CHAR_MIN 0
X#define CHAR_MAX 255U
X#else
X#define CHAR_MIN -128
X#define CHAR_MAX 127
X#endif
X
X/* Minimum and maximum values a `signed short int' can hold.  */
X#define SHRT_MIN -32768
X#define SHRT_MAX 32767
X
X/* Maximum value an `unsigned short int' can hold.  (Minimum is 0).  */
X#define USHRT_MAX 65535U
X
X/* Minimum and maximum values a `signed int' can hold.  */
X#define INT_MIN -2147483648
X#define INT_MAX 2147483647
X
X/* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
X#define UINT_MAX 4294967295U
X
X/* Minimum and maximum values a `signed long int' can hold.
X   (Same as `int').  */
X#define LONG_MIN -2147483648
X#define LONG_MAX 2147483647
X
X/* Maximum value an `unsigned long int' can hold.  (Minimum is 0).  */
X#define ULONG_MAX 4294967295U
SHAR_EOF
echo "extracting diff/regex.h"
sed 's/^X//' << \SHAR_EOF > diff/regex.h
X/* Definitions for data structures callers pass the regex library.
X   Copyright (C) 1985 Free Software Foundation, Inc.
X
X		       NO WARRANTY
X
X  BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
XNO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
XWHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
XRICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
XWITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
XBUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
XFITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
XAND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
XDEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
XCORRECTION.
X
X IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
XSTALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
XWHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
XLIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
XOTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
XUSE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
XDATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
XA FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
XPROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
XDAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
X
X		GENERAL PUBLIC LICENSE TO COPY
X
X  1. You may copy and distribute verbatim copies of this source file
Xas you receive it, in any medium, provided that you conspicuously and
Xappropriately publish on each copy a valid copyright notice "Copyright
X(C) 1985 Free Software Foundation, Inc."; and include following the
Xcopyright notice a verbatim copy of the above disclaimer of warranty
Xand of this License.  You may charge a distribution fee for the
Xphysical act of transferring a copy.
X
X  2. You may modify your copy or copies of this source file or
Xany portion of it, and copy and distribute such modifications under
Xthe terms of Paragraph 1 above, provided that you also do the following:
X
X    a) cause the modified files to carry prominent notices stating
X    that you changed the files and the date of any change; and
X
X    b) cause the whole of any work that you distribute or publish,
X    that in whole or in part contains or is a derivative of this
X    program or any part thereof, to be licensed at no charge to all
X    third parties on terms identical to those contained in this
X    License Agreement (except that you may choose to grant more extensive
X    warranty protection to some or all third parties, at your option).
X
X    c) You may charge a distribution fee for the physical act of
X    transferring a copy, and you may at your option offer warranty
X    protection in exchange for a fee.
X
XMere aggregation of another unrelated program with this program (or its
Xderivative) on a volume of a storage or distribution medium does not bring
Xthe other program under the scope of these terms.
X
X  3. You may copy and distribute this program (or a portion or derivative
Xof it, under Paragraph 2) in object code or executable form under the terms
Xof Paragraphs 1 and 2 above provided that you also do one of the following:
X
X    a) accompany it with the complete corresponding machine-readable
X    source code, which must be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    b) accompany it with a written offer, valid for at least three
X    years, to give any third party free (except for a nominal
X    shipping charge) a complete machine-readable copy of the
X    corresponding source code, to be distributed under the terms of
X    Paragraphs 1 and 2 above; or,
X
X    c) accompany it with the information you received as to where the
X    corresponding source code may be obtained.  (This alternative is
X    allowed only for noncommercial distribution and only if you
X    received the program in object code or executable form alone.)
X
XFor an executable file, complete source code means all the source code for
Xall modules it contains; but, as a special exception, it need not include
Xsource code for modules which are standard libraries that accompany the
Xoperating system on which the executable file runs.
X
X  4. You may not copy, sublicense, distribute or transfer this program
Xexcept as expressly provided under this License Agreement.  Any attempt
Xotherwise to copy, sublicense, distribute or transfer this program is void and
Xyour rights to use the program under this License agreement shall be
Xautomatically terminated.  However, parties who have received computer
Xsoftware programs from you with this License Agreement will not have
Xtheir licenses terminated so long as such parties remain in full compliance.
X
X  5. If you wish to incorporate parts of this program into other free
Xprograms whose distribution conditions are different, write to the Free
XSoftware Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
Xworked out a simple rule that can be stated here, but we will often permit
Xthis.  We will be guided by the two goals of preserving the free status of
Xall derivatives of our free software and of promoting the sharing and reuse of
Xsoftware.
X
X
XIn other words, you are welcome to use, share and improve this program.
XYou are forbidden to forbid anyone else to use, share and improve
Xwhat you give them.   Help stamp out software-hoarding!  */
X
X
X/* Define number of parens for which we record the beginnings and ends.
X   This affects how much space the `struct re_registers' type takes up.  */
X#ifndef RE_NREGS
X#define RE_NREGS 10
X#endif
X
X/* These bits are used in the obscure_syntax variable to choose among
X   alternative regexp syntaxes.  */
X
X/* 1 means plain parentheses serve as grouping, and backslash
X     parentheses are needed for literal searching.
X   0 means backslash-parentheses are grouping, and plain parentheses
X     are for literal searching.  */
X#define RE_NO_BK_PARENS 1
X
X/* 1 means plain | serves as the "or"-operator, and \| is a literal.
X   0 means \| serves as the "or"-operator, and | is a literal.  */
X#define RE_NO_BK_VBAR 2
X
X/* 0 means plain + or ? serves as an operator, and \+, \? are literals.
X   1 means \+, \? are operators and plain +, ? are literals.  */
X#define RE_BK_PLUS_QM 4
X
X/* 1 means | binds tighter than ^ or $.
X   0 means the contrary.  */
X#define RE_TIGHT_VBAR 8
X
X/* 1 means treat \n as an _OR operator
X   0 means treat it as a normal character */
X#define RE_NEWLINE_OR 16
X
X/* 0 means that a special characters (such as *, ^, and $) always have
X     their special meaning regardless of the surrounding context.
X   1 means that special characters may act as normal characters in some
X     contexts.  Specifically, this applies to:
X	^ - only special at the beginning, or after ( or |
X	$ - only special at the end, or before ) or |
X	*, +, ? - only special when not after the beginning, (, or | */
X#define RE_CONTEXT_INDEP_OPS 32
X
X/* Now define combinations of bits for the standard possibilities.  */
X#define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS)
X#define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
X#define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
X#define RE_SYNTAX_EMACS 0
X
X/* This data structure is used to represent a compiled pattern. */
X
Xstruct re_pattern_buffer
X  {
X    char *buffer;	/* Space holding the compiled pattern commands. */
X    int allocated;	/* Size of space that  buffer  points to */
X    int used;		/* Length of portion of buffer actually occupied */
X    char *fastmap;	/* Pointer to fastmap, if any, or zero if none. */
X			/* re_search uses the fastmap, if there is one,
X			   to skip quickly over totally implausible characters */
X    char *translate;	/* Translate table to apply to all characters before comparing.
X			   Or zero for no translation.
X			   The translation is applied to a pattern when it is compiled
X			   and to data when it is matched. */
X    char fastmap_accurate;
X			/* Set to zero when a new pattern is stored,
X			   set to one when the fastmap is updated from it. */
X    char can_be_null;   /* Set to one by compiling fastmap
X			   if this pattern might match the null string.
X			   It does not necessarily match the null string
X			   in that case, but if this is zero, it cannot.
X			   2 as value means can match null string
X			   but at end of range or before a character
X			   listed in the fastmap.  */
X  };
X
X/* Structure to store "register" contents data in.
X
X   Pass the address of such a structure as an argument to re_match, etc.,
X   if you want this information back.
X
X   start[i] and end[i] record the string matched by \( ... \) grouping i,
X   for i from 1 to RE_NREGS - 1.
X   start[0] and end[0] record the entire string matched. */
X
Xstruct re_registers
X  {
X    int start[RE_NREGS];
X    int end[RE_NREGS];
X  };
X
X/* These are the command codes that appear in compiled regular expressions, one per byte.
X  Some command codes are followed by argument bytes.
X  A command code can specify any interpretation whatever for its arguments.
X  Zero-bytes may appear in the compiled regular expression. */
X
Xenum regexpcode
X  {
X    unused,
X    exactn,    /* followed by one byte giving n, and then by n literal bytes */
X    begline,   /* fails unless at beginning of line */
X    endline,   /* fails unless at end of line */
X    jump,	 /* followed by two bytes giving relative address to jump to */
X    on_failure_jump,	 /* followed by two bytes giving relative address of place
X		            to resume at in case of failure. */
X    finalize_jump,	 /* Throw away latest failure point and then jump to address. */
X    maybe_finalize_jump, /* Like jump but finalize if safe to do so.
X			    This is used to jump back to the beginning
X			    of a repeat.  If the command that follows
X			    this jump is clearly incompatible with the
X			    one at the beginning of the repeat, such that
X			    we can be sure that there is no use backtracking
X			    out of repetitions already completed,
X			    then we finalize. */
X    dummy_failure_jump,  /* jump, and push a dummy failure point.
X			    This failure point will be thrown away
X			    if an attempt is made to use it for a failure.
X			    A + construct makes this before the first repeat.  */
X    anychar,	 /* matches any one character */
X    charset,     /* matches any one char belonging to specified set.
X		    First following byte is # bitmap bytes.
X		    Then come bytes for a bit-map saying which chars are in.
X		    Bits in each byte are ordered low-bit-first.
X		    A character is in the set if its bit is 1.
X		    A character too large to have a bit in the map
X		    is automatically not in the set */
X    charset_not, /* similar but match any character that is NOT one of those specified */
X    start_memory, /* starts remembering the text that is matched
X		    and stores it in a memory register.
X		    followed by one byte containing the register number.
X		    Register numbers must be in the range 0 through NREGS. */
X    stop_memory, /* stops remembering the text that is matched
X		    and stores it in a memory register.
X		    followed by one byte containing the register number.
X		    Register numbers must be in the range 0 through NREGS. */
X    duplicate,    /* match a duplicate of something remembered.
X		    Followed by one byte containing the index of the memory register. */
X    before_dot,	 /* Succeeds if before dot */
X    at_dot,	 /* Succeeds if at dot */
X    after_dot,	 /* Succeeds if after dot */
X    begbuf,      /* Succeeds if at beginning of buffer */
X    endbuf,      /* Succeeds if at end of buffer */
X    wordchar,    /* Matches any word-constituent character */
X    notwordchar, /* Matches any char that is not a word-constituent */
X    wordbeg,	 /* Succeeds if at word beginning */
X    wordend,	 /* Succeeds if at word end */
X    wordbound,   /* Succeeds if at a word boundary */
X    notwordbound, /* Succeeds if not at a word boundary */
X    syntaxspec,  /* Matches any character whose syntax is specified.
X		    followed by a byte which contains a syntax code, Sword or such like */
X    notsyntaxspec /* Matches any character whose syntax differs from the specified. */
X  };
X
Xextern char *re_compile_pattern ();
X/* Is this really advertised? */
Xextern void re_compile_fastmap ();
Xextern int re_search (), re_search_2 ();
Xextern int re_match (), re_match_2 ();
X
X/* 4.2 bsd compatibility (yuck) */
Xextern char *re_comp ();
Xextern int re_exec ();
X
X#ifdef SYNTAX_TABLE
Xextern char *re_syntax_table;
X#endif
SHAR_EOF
echo "extracting diff/stat.h"
sed 's/^X//' << \SHAR_EOF > diff/stat.h
X#include <fcntl.h>
X
Xstruct stat {
X	long st_attr;
X	long st_mtime;
X	long st_size;
X	long st_type;
X};
SHAR_EOF
echo "extracting diff/diff.h.old"
sed 's/^X//' << \SHAR_EOF > diff/diff.h.old
X/* Shared definitions for GNU DIFF
X   Copyright (C) 1988 Free Software Foundation, Inc.
X
XThis file is part of GNU DIFF.
X
XGNU DIFF is distributed in the hope that it will be useful,
Xbut WITHOUT ANY WARRANTY.  No author or distributor
Xaccepts responsibility to anyone for the consequences of using it
Xor for whether it serves any particular purpose or works at all,
Xunless he says so in writing.  Refer to the GNU DIFF General Public
XLicense for full details.
X
XEveryone is granted permission to copy, modify and redistribute
XGNU DIFF, but only under the conditions described in the
XGNU DIFF General Public License.   A copy of this license is
Xsupposed to have been given to you along with GNU DIFF so you
Xcan know your rights and responsibilities.  It should be in a
Xfile named COPYING.  Among other things, the copyright notice
Xand this notice must be preserved on all copies.  */
X
X
X#include <ctype.h>
X#include <stdio.h>
X#ifndef AMIGA
X#include <sys/file.h>
X#include <types.h>
X#include <stat.h>
X#else
X#include "stat.h"
X#endif
X#include <time.h>
X#ifdef AMIGA
X#include "dir.h"
X#else
X#include <sys/dir.h>
X#endif
X#include <errno.h>
X#ifndef RE_NREGS
X#include "regex.h"
X#endif
X#include <string.h>
X
X/* Support old-fashioned C compilers.  */
X#if defined (__STDC__) || defined (__GNUC__)
X#include "limits.h"
X#else
X#define INT_MAX 2147483647
X#define CHAR_BIT 8
X#endif
X
Xextern int      errno;
Xextern int      sys_nerr;
Xextern char    *sys_errlist[];
X
X#define	EOS		(0)
X#ifdef AMIGA
X#undef FALSE
X#endif
X#define	FALSE		(0)
X#define TRUE		1
X
X#ifndef AMIGA
X#define min(a,b) ((a) <= (b) ? (a) : (b))
X#define max(a,b) ((a) >= (b) ? (a) : (b))
X#endif
X#ifdef AMIGA
X#define bcmp(a,b,l) memcmp(a,b,l)
X#define bcopy(f,t,l) movmem(f,t,l)
X#define bzero(a,l) memset(a,0,l)
X#endif
X
X#ifndef PR_FILE_NAME
X#define PR_FILE_NAME "/bin/pr"
X#endif
X
X/* Support old-fashioned C compilers.  */
X#if !defined (__STDC__) && !defined (__GNUC__)
X#define const
X#endif
X
X/* Variables for command line options */
X
X#ifndef GDIFF_MAIN
X#define EXTERN extern
X#else
X#define EXTERN
X#endif
X
Xenum output_style {
X  /* Default output style.  */
X  OUTPUT_NORMAL,
X  /* Output the differences with lines of context before and after (-c).  */
X  OUTPUT_CONTEXT,
X  /* Output the differences as commands suitable for `ed' (-e).  */
X  OUTPUT_ED,
X  /* Output the diff as a forward ed script (-f).  */
X  OUTPUT_FORWARD_ED,
X  /* Like -f, but output a count of changed lines in each "command" (-n). */
X  OUTPUT_RCS };
X
XEXTERN enum output_style output_style;
X
X/* Number of lines of context to show in each set of diffs.
X   This is zero when context is not to be shown.  */
XEXTERN int      context;
X
X/* Consider all files as text files (-a).
X   Don't interpret codes over 0177 as implying a "binary file".  */
XEXTERN int	always_text_flag;
X
X/* Ignore changes in horizontal whitespace (-b).  */
XEXTERN int      ignore_space_change_flag;
X
X/* Ignore all horizontal whitespace (-w).  */
XEXTERN int      ignore_all_space_flag;
X
X/* Ignore changes that affect only blank lines (-B).  */
XEXTERN int      ignore_blank_lines_flag;
X
X/* Ignore changes that affect only lines matching this regexp (-I).  */
XEXTERN char	*ignore_regexp;
X
X/* Result of regex-compilation of `ignore_regexp'.  */
XEXTERN struct re_pattern_buffer ignore_regexp_compiled;
X
X/* 1 if lines may match even if their lengths are different.
X   This depends on various options.  */
XEXTERN int      length_varies;
X
X/* Ignore differences in case of letters (-i).  */
XEXTERN int      ignore_case_flag;
X
X/* Regexp to identify function-header lines (-F).  */
XEXTERN char	*function_regexp;
X
X/* Result of regex-compilation of `function_regexp'.  */
XEXTERN struct re_pattern_buffer function_regexp_compiled;
X
X/* Report files compared that match (-s).
X   Normally nothing is output when that happens.  */
XEXTERN int      print_file_same_flag;
X
X/* character that ends a line.  Currently this is always `\n'.  */
XEXTERN char     line_end_char;
X
X/* Output the differences with exactly 8 columns added to each line
X   so that any tabs in the text line up properly (-T).  */
XEXTERN int	tab_align_flag;
X
X/* Expand tabs in the output so the text lines up properly
X   despite the characters added to the front of each line (-t).  */
XEXTERN int	tab_expand_flag;
X
X/* In directory comparison, specify file to start with (-S).
X   All file names less than this name are ignored.  */
XEXTERN char	*dir_start_file;
X
X/* If a file is new (appears in only one dir)
X   include its entire contents (-N).
X   Then `patch' would create the file with appropriate contents.  */
XEXTERN int	entire_new_file_flag;
X
X/* Pipe each file's output through pr (-l).  */
XEXTERN int	paginate_flag;
X
X/* String containing all the command options diff received,
X   with spaces between and at the beginning but none at the end.
X   If there were no options given, this string is empty.  */
XEXTERN char *	switch_string;
X
X/* Nonzero means use heuristics for better speed.  */
XEXTERN int	heuristic;
X
X/* Name of program the user invoked (for error messages).  */
XEXTERN char *	program;
X
X/* The result of comparison is an "edit script": a chain of `struct change'.
X   Each `struct change' represents one place where some lines are deleted
X   and some are inserted.
X   
X   LINE0 and LINE1 are the first affected lines in the two files (origin 0).
X   DELETED is the number of lines deleted here from file 0.
X   INSERTED is the number of lines inserted here in file 1.
X
X   If DELETED is 0 then LINE0 is the number of the line before
X   which the insertion was done; vice versa for INSERTED and LINE1.  */
X
Xstruct change
X{
X  struct change *link;		/* Previous or next edit command  */
X  int inserted;			/* # lines of file 1 changed here.  */
X  int deleted;			/* # lines of file 0 changed here.  */
X  int line0;			/* Line number of 1st deleted line.  */
X  int line1;			/* Line number of 1st inserted line.  */
X  char ignore;			/* Flag used in context.c */
X};
X
X/* Structures that describe the input files.  */
X
X/* Data on one line of text.  */
X
Xstruct line_def {
X    char        *text;
X    int         length;
X    unsigned	hash;
X};
X
X/* Data on one input file being compared.  */
X
Xstruct file_data {
X    int             desc;	/* File descriptor  */
X    char           *name;	/* File name  */
X    struct stat     stat;	/* File status from fstat()  */
X    int             dir_p;	/* 1 if file is a directory  */
X
X    /* Buffer in which text of file is read.  */
X    char *	    buffer;
X    /* Allocated size of buffer.  */
X    int		    bufsize;
X    /* Number of valid characters now in the buffer. */
X    int		    buffered_chars;
X
X    /* Array of data on analyzed lines of this chunk of this file.  */
X    struct line_def *linbuf;
X
X    /* Allocated size of linbuf array (# of elements).  */
X    int		    linbufsize;
X
X    /* Number of elements of linbuf containing valid data. */
X    int		    buffered_lines;
X
X    /* Pointer to end of prefix of this file to ignore when hashing. */
X    char *prefix_end;
X
X    /* Count of lines in the prefix. */
X    int prefix_lines;
X
X    /* Pointer to start of suffix of this file to ignore when hashing. */
X    char *suffix_begin;
X
X    /* Count of lines in the suffix. */
X    int suffix_lines;
X
X    /* Vector, indexed by line number, containing an equivalence code for
X       each line.  It is this vector that is actually compared with that
X       of another file to generate differences. */
X    int		   *equivs;
X
X    /* Vector, like the previous one except that
X       the elements for discarded lines have been squeezed out.  */
X    int		   *undiscarded;
X
X    /* Vector mapping virtual line numbers (not counting discarded lines)
X       to real ones (counting those lines).  Both are origin-0.  */
X    int		   *realindexes;
X
X    /* Total number of nondiscarded lines. */
X    int		    nondiscarded_lines;
X
X    /* Vector, indexed by real origin-0 line number,
X       containing 1 for a line that is an insertion or a deletion.
X       The results of comparison are stored here.  */
X    char	   *changed_flag;
X
X    /* 1 if file ends in a line with no final newline. */
X    int		    missing_newline;
X
X    /* 1 more than the maximum equivalence value used for this or its
X       sibling file. */
X    int equiv_max;
X
X    /* Table translating diff's internal line numbers 
X       to actual line numbers in the file.
X       This is needed only when some lines have been discarded.
X       The allocated size is always linbufsize
X       and the number of valid elements is buffered_lines.  */
X    int		   *ltran;
X};
X
X/* Describe the two files currently being compared.  */
X
XEXTERN struct file_data files[2];
X
X/* Queue up one-line messages to be printed at the end,
X   when -l is specified.  Each message is recorded with a `struct msg'.  */
X
Xstruct msg
X{
X  struct msg *next;
X  char *format;
X  char *arg1;
X  char *arg2;
X};
X
X/* Head of the chain of queues messages.  */
X
XEXTERN struct msg *msg_chain;
X
X/* Tail of the chain of queues messages.  */
X
XEXTERN struct msg *msg_chain_end;
X
X/* Stdio stream to output diffs to.  */
X
XEXTERN FILE *outfile;
X
X/* Declare various functions.  */
X
Xvoid *xmalloc ();
Xvoid *xrealloc ();
Xvoid *xcalloc();
Xchar *concat ();
Xvoid free ();
X
Xvoid message ();
Xvoid print_message_queue ();
SHAR_EOF
echo "End of archive 4 (of 14)"
# if you want to concatenate archives, remove anything after this line
exit