[comp.sources.misc] v13i024: GNU diff 1.14 patches for MSDOS Turbo C 2.0

ward@sneezy.cs.wisc.edu (Michael Ward) (06/03/90)

Posting-number: Volume 13, Issue 24
Submitted-by: ward@sneezy.cs.wisc.edu (Michael Ward)
Archive-name: gdiff-tc/part01

The following patches will allow GNU diff v1.14 to compile with Turbo C 2.0
and run under MSDOS. I have only checked a couple of context and normal diffs,
but it seems to work fine. One major restriction is that the files to be
compared must both be less than 64K in size. Hope this is useful anyway.

Mike Ward
ward@sneezy.cs.wisc.edu

    remove this header and then use patch to apply the diffs
    if you don't have patch, there are not that many changes ...


---------- cut here --------------------------------------------------
*** ../gnudiff/diff.h	Fri Feb 23 07:55:14 1990
--- diff.h	Sat Jun 02 07:53:46 1990
***************
*** 23,28 ****
--- 23,43 ----
  #include <sys/types.h>
  #include <sys/stat.h>
  
+ #ifdef TURBOC20
+ #define MEMSZ unsigned
+ #define MAXMEMBLK 65530L
+ #else
+ #define MEMSZ int
+ #endif
+ 
+ 
+ #ifdef TURBOC20
+ #include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
+ #include <dir.h>
+ #include <fcntl.h>
+ #else
  #ifdef USG
  #include <time.h>
  #ifdef HAVE_NDIR
***************
*** 39,45 ****
--- 54,69 ----
  #include <sys/dir.h>
  #include <sys/file.h>
  #endif
+ #endif
  
+ #ifdef TURBOC20
+ #define bcopy(s,d,n)	memcpy((d),(s),(n))
+ #define bcmp(s1,s2,n)	memcmp((s1),(s2),(n))
+ #define bzero(s,n)	memset((s),0,(n))
+ 
+ #define index	strchr
+ #define rindex	strrchr
+ #else
  #ifdef USG
  /* Define needed BSD functions in terms of sysV library.  */
  
***************
*** 53,58 ****
--- 77,83 ----
  #define index	strchr
  #define rindex	strrchr
  #endif
+ #endif
  
  #include <errno.h>
  extern int      errno;
***************
*** 229,237 ****
      /* Buffer in which text of file is read.  */
      char *	    buffer;
      /* Allocated size of buffer.  */
!     int		    bufsize;
      /* Number of valid characters now in the buffer. */
!     int		    buffered_chars;
  
      /* Array of data on analyzed lines of this chunk of this file.  */
      struct line_def *linbuf;
--- 254,262 ----
      /* Buffer in which text of file is read.  */
      char *	    buffer;
      /* Allocated size of buffer.  */
!     MEMSZ		    bufsize;
      /* Number of valid characters now in the buffer. */
!     MEMSZ		    buffered_chars;
  
      /* Array of data on analyzed lines of this chunk of this file.  */
      struct line_def *linbuf;
***************
*** 292,298 ****
  
  /* Describe the two files currently being compared.  */
  
! struct file_data files[2];
  
  /* Queue up one-line messages to be printed at the end,
     when -l is specified.  Each message is recorded with a `struct msg'.  */
--- 317,323 ----
  
  /* Describe the two files currently being compared.  */
  
! EXTERN struct file_data files[2];
  
  /* Queue up one-line messages to be printed at the end,
     when -l is specified.  Each message is recorded with a `struct msg'.  */
*** ../gnudiff/limits.h	Thu Mar 01 14:31:40 1990
--- limits.h	Sat Jun 02 07:53:48 1990
***************
*** 28,38 ****
  #define USHRT_MAX 65535U
  
  /* Minimum and maximum values a `signed int' can hold.  */
! #define INT_MIN (-INT_MAX-1)
! #define INT_MAX 2147483647
  
  /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
! #define UINT_MAX 4294967295U
  
  /* Minimum and maximum values a `signed long int' can hold.
     (Same as `int').  */
--- 28,38 ----
  #define USHRT_MAX 65535U
  
  /* Minimum and maximum values a `signed int' can hold.  */
! #define INT_MIN (-32768)
! #define INT_MAX 32767
  
  /* Maximum value an `unsigned int' can hold.  (Minimum is 0).  */
! #define UINT_MAX 65535U
  
  /* Minimum and maximum values a `signed long int' can hold.
     (Same as `int').  */
*** ../gnudiff/analyze.c	Thu Mar 01 14:20:26 1990
--- analyze.c	Sat Jun 02 07:53:56 1990
***************
*** 655,660 ****
--- 655,661 ----
    int binary;
    int changes;
  
+ #ifndef TURBOC20
    /* See if the two named files are actually the same physical file.
       If so, we know they are identical without actually reading them.  */
  
***************
*** 661,666 ****
--- 662,668 ----
    if (filevec[0].stat.st_ino == filevec[1].stat.st_ino
        && filevec[0].stat.st_dev == filevec[1].stat.st_dev)
      return 0;
+ #endif
  
    binary = read_files (filevec);
  
*** ../gnudiff/diff.c	Sun Feb 18 17:29:34 1990
--- diff.c	Sat Jun 02 07:53:56 1990
***************
*** 260,269 ****
--- 260,271 ----
  	  ignore_regexp = optarg;
  	  break;
  
+ #ifndef TURBOC20
  	case 'l':
  	  /* Pass the output through `pr' to paginate it.  */
  	  paginate_flag = 1;
  	  break;
+ #endif
  
  	case 'n':
  	  /* Output RCS-style diffs, like `-f' except that each command
***************
*** 366,372 ****
  
    switch_string = option_list (argv + 1, optind - 1);
  
!   val = compare_files (0, argv[optind], 0, argv[optind + 1], 0);
  
    /* Print any messages that were saved up for last.  */
    print_message_queue ();
--- 368,374 ----
  
    switch_string = option_list (argv + 1, optind - 1);
  
!   val = compare_files (NULL, argv[optind], NULL, argv[optind + 1], 0);
  
    /* Print any messages that were saved up for last.  */
    print_message_queue ();
***************
*** 426,433 ****
  
    if (! entire_new_file_flag && (name0 == 0 || name1 == 0))
      {
!       char *name = name0 == 0 ? name1 : name0;
!       char *dir = name0 == 0 ? dir1 : dir0;
        message ("Only in %s: %s\n", dir, name);
        /* Return 1 so that diff_dirs will return 1 ("some files differ").  */
        return 1;
--- 428,435 ----
  
    if (! entire_new_file_flag && (name0 == 0 || name1 == 0))
      {
!       char *name = name0 == NULL ? name1 : name0;
!       char *dir = name0 == NULL ? dir1 : dir0;
        message ("Only in %s: %s\n", dir, name);
        /* Return 1 so that diff_dirs will return 1 ("some files differ").  */
        return 1;
***************
*** 435,452 ****
  
    /* Mark any nonexistent file with -1 in the desc field.  */
  
!   inf[0].desc = name0 == 0 ? -1 : 0;
!   inf[1].desc = name1 == 0 ? -1 : 0;
  
    /* Now record the full name of each file, including nonexistent ones.  */
  
!   if (name0 == 0)
      name0 = name1;
!   if (name1 == 0)
      name1 = name0;
  
!   inf[0].name = dir0 == 0 ? name0 : concat (dir0, "/", name0);
!   inf[1].name = dir1 == 0 ? name1 : concat (dir1, "/", name1);
  
    /* Stat the files.  Record whether they are directories.
       Record in stat_result whether stat fails.  */
--- 437,454 ----
  
    /* Mark any nonexistent file with -1 in the desc field.  */
  
!   inf[0].desc = name0 == NULL ? -1 : 0;
!   inf[1].desc = name1 == NULL ? -1 : 0;
  
    /* Now record the full name of each file, including nonexistent ones.  */
  
!   if (name0 == NULL)
      name0 = name1;
!   if (name1 == NULL)
      name1 = name0;
  
!   inf[0].name = dir0 == NULL ? name0 : concat (dir0, "/", name0);
!   inf[1].name = dir1 == NULL ? name1 : concat (dir1, "/", name1);
  
    /* Stat the files.  Record whether they are directories.
       Record in stat_result whether stat fails.  */
***************
*** 473,478 ****
--- 475,481 ----
  	}
      }
  
+ #ifndef TURBOC20
    /* See if the two named files are actually the same physical file.
       If so, we know they are identical without actually reading them.  */
  
***************
*** 484,493 ****
        val = 0;
        goto done;
      }
  
!   if (name0 == 0)
      inf[0].dir_p = inf[1].dir_p;
!   if (name1 == 0)
      inf[1].dir_p = inf[0].dir_p;
  
    /* Open the files and record their descriptors.  */
--- 487,497 ----
        val = 0;
        goto done;
      }
+ #endif
  
!   if (name0 == NULL)
      inf[0].dir_p = inf[1].dir_p;
!   if (name1 == NULL)
      inf[1].dir_p = inf[0].dir_p;
  
    /* Open the files and record their descriptors.  */
***************
*** 646,654 ****
    else
      fflush (stdout);
  
!   if (dir0 != 0)
      free (inf[0].name);
!   if (dir1 != 0)
      free (inf[1].name);
  
    return val;
--- 650,658 ----
    else
      fflush (stdout);
  
!   if (dir0 != NULL)
      free (inf[0].name);
!   if (dir1 != NULL)
      free (inf[1].name);
  
    return val;
*** ../gnudiff/diff3.c	Fri Feb 23 07:57:34 1990
--- diff3.c	Sat Jun 02 07:54:14 1990
***************
*** 30,35 ****
--- 30,43 ----
  #include <stdio.h>
  #include <ctype.h>
  
+ #ifdef TURBOC20
+ #define bcopy(s,d,n)	memcpy((d),(s),(n))
+ #define bcmp(s1,s2,n)	memcmp((s1),(s2),(n))
+ #define bzero(s,n)	memset((s),0,(n))
+ 
+ #define index	strchr
+ #define rindex	strrchr
+ #else
  #ifdef USG
  #include <fcntl.h>
  
***************
*** 44,49 ****
--- 52,58 ----
  #define vfork	fork
  #define index	strchr
  #define rindex	strrchr
+ #endif
  #endif
  /*
   * Internal data structures and macros for the diff3 program; includes
*** ../gnudiff/dir.c	Thu Nov 16 11:10:46 1989
--- dir.c	Sat Jun 02 07:54:18 1990
***************
*** 36,43 ****
--- 36,51 ----
       char *dirname;
       int nonex;
  {
+ #ifdef TURBOC20
+   int err;
+   char *name;
+   struct ffblk info;
+   struct ffblk *next = &info;
+ #else
    register DIR *reading;
    register struct direct *next;
+ #endif
+ 
    struct dirdata dirdata;
  
    /* Address of block containing the files that are described.  */
***************
*** 49,54 ****
--- 57,63 ----
    /* Index of first unused in `files'.  */
    int files_index;
  
+ 
    if (nonex)
      {
        dirdata.length = 0;
***************
*** 56,61 ****
--- 65,78 ----
        return dirdata;
      }
  
+ #ifdef TURBOC20
+   name = (char *) xmalloc (strlen (dirname) + 4);
+   strcpy(name,dirname);
+   if (strlen(name) && name[strlen(name)-1]!='/') strcat(name,"/");
+   strcat(name,"*.*");
+   err = findfirst(name,next,0x3f);
+   free(name);
+ #else
    /* Open the directory and check for errors.  */
    reading = opendir (dirname);
    if (!reading)
***************
*** 64,69 ****
--- 81,87 ----
        dirdata.length = -1;
        return dirdata;
      }
+ #endif
  
    /* Initialize the table of filenames.  */
  
***************
*** 74,79 ****
--- 92,118 ----
    /* Read the directory entries, and insert the subfiles
       into the `files' table.  */
  
+ #ifdef TURBOC20
+   while (!err)
+     {
+       /* Ignore the files `.' and `..' */
+       if (next->ff_name[0] == '.'
+ 	  && (next->ff_name[1] == 0
+ 	      || (next->ff_name[1] == '.'
+ 		  && next->ff_name[2] == 0)))
+ 	continue;
+ 
+       if (files_index == nfiles)
+ 	{
+ 	  nfiles *= 2;
+ 	  files
+ 	    = (char **) xrealloc (files, sizeof (char *) * nfiles);
+ 	}
+       strlwr(next->ff_name);
+       files[files_index++] = concat (next->ff_name, "", "");
+       err = findnext(next);
+     }
+ #else
    while (next = readdir (reading))
      {
        /* Ignore the files `.' and `..' */
***************
*** 93,98 ****
--- 132,138 ----
      }
  
    closedir (reading);
+ #endif
  
    /* Sort the table.  */
    qsort (files, files_index, sizeof (char *), compare_names);
*** ../gnudiff/getopt.c	Thu Mar 01 10:53:00 1990
--- getopt.c	Sat Jun 02 07:54:24 1990
***************
*** 32,37 ****
--- 32,41 ----
  #include <stdio.h>
  
  /* If compiled with GNU C, use the built-in alloca */
+ #ifdef TURBOC20
+ char *xmalloc ();
+ #define alloca(x) xmalloc(x)
+ #else
  #ifdef __GNUC__
  #define alloca __builtin_alloca
  #else /* not __GNUC__ */
***************
*** 41,50 ****
--- 45,60 ----
  char *alloca ();
  #endif
  #endif /* not __GNUC__ */
+ #endif
  
+ #ifdef TURBOC20
+ #define bcopy(s, d, l) memcpy((d), (s), (l))
+ #define index strchr
+ #else
  #ifdef USG
  #define bcopy(s, d, l) memcpy((d), (s), (l))
  #define index strchr
+ #endif
  #endif
  
  char *getenv ();
*** ../gnudiff/io.c	Sun Dec 24 08:03:12 1989
--- io.c	Sat Jun 02 07:54:30 1990
***************
*** 68,83 ****
       and one for a sentinel in find_identical_ends.  */
    else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
      {
        current->bufsize = current->stat.st_size;
        current->buffer = (char *) xmalloc (current->bufsize + 2);
        current->buffered_chars
  	= read (current->desc, current->buffer, current->bufsize);
!       if (current->buffered_chars < 0)
  	pfatal_with_name (current->name);
      }
    else
      {
!       int cc;
  
        current->bufsize = 4096;
        current->buffer = (char *) xmalloc (current->bufsize + 2);
--- 68,87 ----
       and one for a sentinel in find_identical_ends.  */
    else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
      {
+ #ifdef TURBOC20
+       if (current->stat.st_size > MAXMEMBLK)
+         pfatal_with_name("file too large!");
+ #endif
        current->bufsize = current->stat.st_size;
        current->buffer = (char *) xmalloc (current->bufsize + 2);
        current->buffered_chars
  	= read (current->desc, current->buffer, current->bufsize);
!       if (current->buffered_chars == (MEMSZ)-1)
  	pfatal_with_name (current->name);
      }
    else
      {
!       MEMSZ cc;
  
        current->bufsize = 4096;
        current->buffer = (char *) xmalloc (current->bufsize + 2);
***************
*** 88,104 ****
        while ((cc = read (current->desc,
  			 current->buffer + current->buffered_chars,
  			 current->bufsize - current->buffered_chars))
! 	     > 0)
  	{
  	  current->buffered_chars += cc;
  	  if (current->buffered_chars == current->bufsize)
  	    {
  	      current->bufsize = current->bufsize * 2;
  	      current->buffer = (char *) xrealloc (current->buffer,
  						   current->bufsize + 2);
  	    }
  	}
!       if (cc < 0)
  	pfatal_with_name (current->name);
      }
    
--- 92,112 ----
        while ((cc = read (current->desc,
  			 current->buffer + current->buffered_chars,
  			 current->bufsize - current->buffered_chars))
! 	     != (MEMSZ)-1 && cc != 0)
  	{
  	  current->buffered_chars += cc;
  	  if (current->buffered_chars == current->bufsize)
  	    {
+ #ifdef TURBOC20
+               if (2L * (long)(current->bufsize) > MAXMEMBLK)
+                 pfatal_with_name("file too large!");
+ #endif
  	      current->bufsize = current->bufsize * 2;
  	      current->buffer = (char *) xrealloc (current->buffer,
  						   current->bufsize + 2);
  	    }
  	}
!       if (cc == (MEMSZ)-1)
  	pfatal_with_name (current->name);
      }
    
*** ../gnudiff/regex.c	Mon Jan 08 09:33:40 1990
--- regex.c	Sat Jun 02 07:54:46 1990
***************
*** 32,37 ****
--- 32,42 ----
  
  #else  /* not emacs */
  
+ #ifdef TURBOC20
+ #define bcopy(s,d,n)	memcpy((d),(s),(n))
+ #define bcmp(s1,s2,n)	memcmp((s1),(s2),(n))
+ #define bzero(s,n)	memset((s),0,(n))
+ #else
  #ifdef USG
  #ifndef BSTRING
  #define bcopy(s,d,n)	memcpy((d),(s),(n))
***************
*** 39,49 ****
--- 44,59 ----
  #define bzero(s,n)	memset((s),0,(n))
  #endif
  #endif
+ #endif
  
  char *malloc ();
  char *realloc ();
  
  /* Make alloca work the best possible way.  */
+ #ifdef TURBOC20
+ char *xmalloc ();
+ #define alloca(x) xmalloc(x)
+ #else
  #ifdef __GNUC__
  #define alloca __builtin_alloca
  #else
***************
*** 51,56 ****
--- 61,67 ----
  #include <alloca.h>
  #else
  char *alloca ();
+ #endif
  #endif
  #endif
  
*** ../gnudiff/util.c	Fri Feb 23 07:56:12 1990
--- util.c	Sat Jun 02 07:54:52 1990
***************
*** 129,134 ****
--- 129,135 ----
    strcat (name, " ");
    strcat (name, name1);
  
+ #ifndef TURBOC20  
    if (paginate_flag)
      {
        int pipes[2];
***************
*** 161,166 ****
--- 162,168 ----
  	} 
      }
    else
+ #endif
      {
  
        /* If -l was not specified, output the diff straight to `stdout'.  */
***************
*** 182,192 ****
--- 184,196 ----
  void
  finish_output ()
  {
+ #ifndef TURBOC20
    if (outfile != stdout)
      {
        fclose (outfile);
        wait (0);
      }
+ #endif
  }
  
  /* Compare two lines (typically one from each input file)
*** ../gnudiff/makefile	Sun Feb 18 19:11:30 1990
--- makefile	Sat Jun 02 07:54:56 1990
***************
*** 1,4 ****
! # Makefile for GNU DIFF
  # Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  
  # This file is part of GNU DIFF.
--- 1,4 ----
! # Turbo C Makefile for GNU DIFF
  # Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  
  # This file is part of GNU DIFF.
***************
*** 21,29 ****
  # You can compile this with ordinary cc as well,
  # but gcc makes it faster.
  # Also, gcc supports -O and -g together.
! CC=gcc -O
! CFLAGS = -g
! INSTALL = install
  
  # On system V, enable these three lines:
  # CFLAGS = -g -DUSG
--- 21,28 ----
  # You can compile this with ordinary cc as well,
  # but gcc makes it faster.
  # Also, gcc supports -O and -g together.
! CC=tcc
! CFLAGS = -A -N -v -1 -ml -DTURBOC20
  
  # On system V, enable these three lines:
  # CFLAGS = -g -DUSG
***************
*** 36,95 ****
  # Add -DHAVE_DIRECT to CFLAGS if your system uses 'struct direct' instead of
  # 'struct dirent' (this is the case at least with one add-on ndir library).
  
- bindir=/usr/local/bin
- prefix=
- 
- # All source files
  srcs=diff.c analyze.c io.c context.c ed.c normal.c ifdef.c util.c dir.c \
! 	version.c diff.h regex.c regex.h limits.h diff3.c \
! 	getopt.c getopt1.c getopt.h
! # Object files for diff only.
! objs=$(archpfx)diff.o $(archpfx)analyze.o $(archpfx)io.o $(archpfx)context.o \
!      $(archpfx)ed.o $(archpfx)normal.o $(archpfx)util.o $(archpfx)dir.o \
!      $(archpfx)regex.o $(archpfx)ifdef.o $(archpfx)version.o \
!      $(archpfx)getopt.o $(archpfx)getopt1.o
! tapefiles = $(srcs) README diagmeet.note Makefile COPYING ChangeLog
! 
! all: $(archpfx)diff $(archpfx)diff3
! 
! $(archpfx)diff3: $(archpfx)diff3.o
! 	$(CC) -o $(archpfx)diff3 $(CFLAGS) $(LDFLAGS) $(archpfx)diff3.o $(LIBS)
! 
! $(archpfx)diff: $(objs)
! 	$(CC) -o $(archpfx)diff $(CFLAGS) $(LDFLAGS) $(objs) $(LIBS)
! 
! $(objs): diff.h
! 
! $(archpfx)context.o $(archpfx)diff.o: regex.h
! 
! $(archpfx)diff3.o: diff3.c
! 	$(CC) -c $(CFLAGS) -DDIFF_PROGRAM=\"$(bindir)/diff\" diff3.c \
!  $(OUTPUT_OPTION)
! 
! clean:
! 	rm -f *.o $(archpfx)diff $(archpfx)diff3 diff.tar diff.tar.Z
! 
! install: install-diff install-diff3
! 
! install-diff: $(prefix)$(bindir)/diff
! 
! $(prefix)$(bindir)/diff: $(archpfx)diff
! 	$(INSTALL) $(archpfx)diff $(prefix)$(bindir)/diff
! 
! install-diff3: $(prefix)$(bindir)/diff3
! 
! $(prefix)$(bindir)/diff3: $(archpfx)diff3
! 	$(INSTALL) $(archpfx)diff3 $(prefix)$(bindir)/diff3
! 
! diff.tar: $(tapefiles)
! 	mkdir tmp
! 	mkdir tmp/diff
! 	-ln $(tapefiles) tmp/diff
! 	for file in $(tapefiles); do \
! 		if [ ! -r tmp/diff/$$file ]; then cp $$file tmp/diff; fi \
! 	done
! 	cd tmp; tar cf ../diff.tar diff
! 	rm -rf tmp
  
! diff.tar.Z: diff.tar
! 	compress < diff.tar > diff.tar.Z
--- 35,88 ----
  # Add -DHAVE_DIRECT to CFLAGS if your system uses 'struct direct' instead of
  # 'struct dirent' (this is the case at least with one add-on ndir library).
  
  srcs=diff.c analyze.c io.c context.c ed.c normal.c ifdef.c util.c dir.c \
! 	version.c diff.h regex.c regex.h limits.h diff3.c getopt.c \
! 	getopt1.c getopt.h
! allobj=analyze.obj io.obj ed.obj normal.obj util.obj dir.obj regex.obj \
! 	ifdef.obj version.obj getopt.obj getopt1.obj context.obj diff.obj
! 
! 
! .h.obj:
! 	$(CC) -c $(CFLAGS) $(LDFLAGS) $*
! 
! .c.obj:
! 	$(CC) -c $(CFLAGS) $(LDFLAGS) $*
! 
! 
! # all: diff.exe diff3.exe
! all: diff.exe
! 
! diff3.exe: diff3.obj getopt.obj
! 	$(CC) -ediff3 $(CFLAGS) $(LDFLAGS) diff3.obj getopt.obj
! 
! diff.exe: $(allobj)
! 	$(CC) -ediff $(CFLAGS) $(LDFLAGS) *.obj
! 
! analyze.obj: diff.h analyze.c
! 
! io.obj: diff.h io.c
! 
! ed.obj: diff.h ed.c
! 
! normal.obj: diff.h normal.c
! 
! util.obj: diff.h util.c
! 
! dir.obj: diff.h dir.c
! 
! regex.obj: diff.h regex.c
! 
! ifdef.obj: diff.h ifdef.c
! 
! version.obj: diff.h version.c
! 
! getopt.obj: diff.h getopt.c
! 
! getopt1.obj: diff.h getopt1.c
! 
! context.obj: regex.h diff.h context.c
! 
! diff.obj: regex.h diff.h diff.c
  
! diff3.obj: diff3.c
! 	$(CC) -c $(CFLAGS) -DDIFF_PROGRAM="\"diff\"" diff3.c