Category : C Source Code
Archive   : DIFF114.ZIP
Filename : PATCHES.OS2

 
Output of file : PATCHES.OS2 contained in archive : DIFF114.ZIP
Special versions of getopt.h/getopt.c/getopt1.c and regex.h/regex.c
ported to ANSI C were used in addition to this changes.

Kai Uwe Rommel
[email protected]

diff -cN old/analyze.c analyze.c
*** old/analyze.c Tue May 08 00:11:08 1990
--- analyze.c Mon May 07 23:41:10 1990
***************
*** 387,394 ****
--- 387,402 ----
}

/* Cancel provisional discards at the end, and shrink the run. */
+ #if defined(MSC_BUG)
while (j > i && discards[j - 1] == 2)
discards[j - 1] = 0, --provisional;
+ #else
+ {
+ int index = j - 1;
+ while (j > i && discards[index] == 2)
+ discards[index] = 0, --provisional;
+ }
+ #endif

/* Now we have the length of a run of discardable lines
whose first and last are not provisional. */
***************
*** 658,666 ****
--- 666,680 ----
/* See if the two named files are actually the same physical file.
If so, we know they are identical without actually reading them. */

+ #if !defined(MSDOS)
+ /*
+ ** since MSC always sets the inode and dev fields to zero under DOS
+ ** this test will always think two files are the same.
+ */
if (filevec[0].stat.st_ino == filevec[1].stat.st_ino
&& filevec[0].stat.st_dev == filevec[1].stat.st_dev)
return 0;
+ #endif /* MSDOS */

binary = read_files (filevec);

***************
*** 671,679 ****
--- 685,719 ----

if (binary || no_details_flag)
{
+ #if !defined(MSDOS)
int differs = (filevec[0].buffered_chars != filevec[1].buffered_chars
|| bcmp (filevec[0].buffer, filevec[1].buffer,
filevec[1].buffered_chars));
+ #else
+ int differs;
+ if(filevec[0].buffered_chars != filevec[1].buffered_chars)
+ differs = 1;
+ else {
+ /*
+ ** we've got to do it in chunks because of our
+ ** poor 16 bit processor
+ */
+ char huge *b0 = filevec[0].buffer,
+ *b1 = filevec[1].buffer;
+ long int count;
+ unsigned int delta;
+ count = filevec[0].buffered_chars;
+ while(count > 0) {
+ delta = (unsigned)(count > 65000 ? 65000 : count);
+ if(bcmp(b0,b1,delta) != 0)
+ break;
+ count -= delta;
+ b0 += delta;
+ b1 += delta;
+ }
+ differs = count != 0;
+ }
+ #endif
if (differs)
message (binary ? "Binary files %s and %s differ\n"
: "Files %s and %s differ\n",
***************
*** 681,687 ****
--- 721,731 ----

for (i = 0; i < 2; ++i)
if (filevec[i].buffer)
+ #ifndef MSDOS
free (filevec[i].buffer);
+ #else
+ hfree (filevec[i].buffer);
+ #endif
return differs;
}

***************
*** 832,839 ****
--- 876,888 ----

for (i = 0; i < 2; ++i)
{
+ #if !defined(MSDOS)
if (filevec[i].buffer != 0)
free (filevec[i].buffer);
+ #else /* MSDOS */
+ if (filevec[i].buffer != 0)
+ hfree (filevec[i].buffer);
+ #endif
free (filevec[i].linbuf);
}

diff -cN old/context.c context.c
*** old/context.c Tue May 08 00:11:08 1990
--- context.c Mon May 07 23:41:12 1990
***************
*** 33,46 ****

/* Print a header for a context diff, with the file names and dates. */

void
print_context_header (inf)
struct file_data *inf;
{
! fprintf (outfile, "*** %s\t%s", inf[0].name,
! ctime (&inf[0].stat.st_mtime));
! fprintf (outfile, "--- %s\t%s", inf[1].name,
! ctime (&inf[1].stat.st_mtime));
}

/* Print an edit script in context format. */
--- 33,63 ----

/* Print a header for a context diff, with the file names and dates. */

+ #ifdef MSDOS
+ void dosname(char *ptr)
+ {
+ for ( ; *ptr; ptr++ )
+ if ( *ptr == '\\' )
+ *ptr = '/';
+ else
+ *ptr = tolower(*ptr);
+ }
+ #endif
+
void
print_context_header (inf)
struct file_data *inf;
{
! char *ct;
!
! #ifdef MSDOS
! dosname(inf[0].name);
! dosname(inf[1].name);
! #endif
! ct = ctime (&inf[0].stat.st_mtime);
! fprintf (outfile, "*** %s\t%s", inf[0].name, ct ? ct : "\n");
! ct = ctime (&inf[1].stat.st_mtime);
! fprintf (outfile, "--- %s\t%s", inf[1].name, ct ? ct : "\n");
}

/* Print an edit script in context format. */
diff -cN old/diff.c diff.c
*** old/diff.c Tue May 08 00:11:08 1990
--- diff.c Tue May 08 00:17:24 1990
***************
*** 34,40 ****
--- 34,99 ----
/* For debugging: don't do discard_confusing_lines. */

int no_discards;
+ extern char *version_string;

+ usage()
+ {
+ printf("\nGNU diff, version %s\n", version_string);
+
+ printf("\nUsage: %s [-options] file1 file2\n\n", program);
+ printf(
+ " -[0-9] digits combined into decimal to specify the context-size.\n"
+ " -a Treat all files as text files; never treat as binary.\n"
+ " -b Ignore changes in amount of whitespace.\n"
+ " -B Ignore changes affecting only blank lines.\n"
+ " -c Make context-style output.\n"
+ );
+ printf(
+ " -C n Make context-style output and show name of last C function.\n"
+ " Define context size to be n lines.\n"
+ " -d Don't discard lines. This makes things slower (sometimes much\n"
+ " slower) but will find a guaranteed minimal set of changes.\n"
+ " -D Make merged #ifdef output.\n"
+ " -e Make output that is a valid `ed' script.\n"
+ " -f Make output that looks vaguely like an `ed' script\n"
+ " but has changes in the order they appear in the file.\n"
+ );
+ printf(
+ " -F re Show, for each set of changes, the previous line that matches the\n"
+ " specified regexp. Currently affects only context-style output.\n"
+ " -h Split the files into chunks of around 1500 lines\n"
+ " for faster processing. Usually does not change the result.\n"
+ " -H Use heuristic.\n"
+ " -i Ignore changes in case.\n"
+ " -I re Ignore changes affecting only lines that match the specified regexp.\n"
+ " -l Pass the output through `pr' to paginate it.\n"
+ );
+ printf(
+ " -n Output RCS-style diffs, like `-f' except that each command\n"
+ " specifies the number of lines affected.\n"
+ " -N When comparing directories, if a file appears only in one\n"
+ " directory, treat it as present but empty in the other.\n"
+ " -p Make context-style output and show name of last C function.\n"
+ " -q Treat all files as binaries.\n"
+ " -r When comparing directories, recursively compare subdir's found.\n"
+ " -s Print a message if the files are the same.\n"
+ );
+ printf(
+ " -S file When comparing directories, start with the specified\n"
+ " file name. This is used for resuming an aborted comparison.\n"
+ " -t Expand tabs to spaces in the output so that it preserves\n"
+ " the alignment of the input files.\n"
+ " -T Use a tab in the output, rather than a space, before the\n"
+ " text of an input line, so as to keep the proper alignment\n"
+ " in the input line without changing the characters in it.\n");
+ printf(
+ " -v Print version number.\n"
+ " -w Ignore horizontal whitespace when comparing lines.\n"
+ );
+
+ exit(1);
+ }
+
/* Return a string containing the command options with which diff was invoked.
Spaces appear between what were separate ARGV-elements.
There is a space at the beginning but none at the end.
***************
*** 99,105 ****
{0, 0, 0, 0}
};

! main (argc, argv)
int argc;
char *argv[];
{
--- 158,164 ----
{0, 0, 0, 0}
};

! void main (argc, argv)
int argc;
char *argv[];
{
***************
*** 374,379 ****
--- 433,439 ----
exit (val);
}

+ /*
usage ()
{
fprintf (stderr, "\
***************
*** 390,395 ****
--- 450,456 ----
[+version] path1 path2\n");
exit (1);
}
+ */

specify_style (style)
enum output_style style;
***************
*** 473,478 ****
--- 534,546 ----
}
}

+ #if !defined(MSDOS)
+ /*
+ ** this stuff is real bad idea under MSDOS, at least for MSC 5.1
+ ** because the st_ino and st_dev fields are not supported by
+ ** MSDOS, and so stat sets them to zero; therefore
+ ** this test always succeeds.
+ */
/* See if the two named files are actually the same physical file.
If so, we know they are identical without actually reading them. */

***************
*** 484,489 ****
--- 552,558 ----
val = 0;
goto done;
}
+ #endif /* MSDOS */

if (name0 == 0)
inf[0].dir_p = inf[1].dir_p;
***************
*** 502,511 ****
inf[i].name = "Standard Input";
}
/* Don't bother opening if stat already failed. */
! else if (stat_result[i] == 0 && ! inf[i].dir_p)
{
char *filename = inf[i].name;
!
inf[i].desc = open (filename, O_RDONLY, 0);
if (0 > inf[i].desc)
{
--- 571,589 ----
inf[i].name = "Standard Input";
}
/* Don't bother opening if stat already failed. */
! else if (stat_result[i] == 0)
{
char *filename = inf[i].name;
! #if !defined(MSDOS)
! inf[i].desc = open (filename, O_RDONLY, 0);
! if (0 > inf[i].desc)
! {
! perror_with_name (filename);
! errorcount = 1;
! }
! #else
! if(inf[i].dir_p == 0)
! {
inf[i].desc = open (filename, O_RDONLY, 0);
if (0 > inf[i].desc)
{
***************
*** 512,519 ****
--- 590,605 ----
perror_with_name (filename);
errorcount = 1;
}
+ } else
+ inf[i].desc = 0;
+ #endif /* MSDOS */
}
}
+
+ if (name0 == 0)
+ inf[0].dir_p = inf[1].dir_p;
+ if (name1 == 0)
+ inf[1].dir_p = inf[0].dir_p;

if (errorcount)
{
diff -cN old/diff.cs diff.cs
*** old/diff.cs
--- diff.cs Tue May 08 00:13:14 1990
***************
*** 0 ****
--- 1,8 ----
+ (-W1 -DUSG -DOS2
+ analyze.c context.c diff.c dir.c ed.c getopt.c getopt1.c
+ ifdef.c io.c normal.c regex.c util.c version.c
+ )
+ setargv.obj
+ diff.def
+ diff.exe
+ -AH -LB -S0x8000
diff -cN old/diff.def diff.def
*** old/diff.def
--- diff.def Mon May 07 23:49:44 1990
***************
*** 0 ****
--- 1,2 ----
+ NAME DIFF WINDOWCOMPAT
+ DESCRIPTION 'GNU diff version 1.14 - for MS-DOS and OS/2'
diff -cN old/diff.h diff.h
*** old/diff.h Tue May 08 00:11:08 1990
--- diff.h Mon May 07 23:44:56 1990
***************
*** 23,34 ****
--- 23,38 ----
#include
#include

+ #include
+
#ifdef USG
#include
#ifdef HAVE_NDIR
#include
#else
+ #ifndef MSDOS
#include
+ #endif
#endif /* not HAVE_NDIR */
#include
#ifndef HAVE_DIRECT
***************
*** 47,53 ****
--- 51,59 ----
#define bcmp(s1,s2,n) memcmp((s1),(s2),(n))
#define bzero(s,n) memset((s),0,(n))

+ #if !defined(MSDOS)
#define dup2(f,t) (close(t),fcntl((f),F_DUPFD,(t)))
+ #endif

#define vfork fork
#define index strchr
***************
*** 54,70 ****
--- 60,85 ----
#define rindex strrchr
#endif

+ #ifdef MSDOS
+ #include
+ #include
+ #endif /* MSDOS */
+
#include
+ #if !defined(MSDOS)
extern int errno;
extern int sys_nerr;
extern char *sys_errlist[];
+ #endif

#define EOS (0)
#define FALSE (0)
#define TRUE 1

+ #if !defined(min)
#define min(a,b) ((a) <= (b) ? (a) : (b))
#define max(a,b) ((a) >= (b) ? (a) : (b))
+ #endif /* MSDOS */

#ifndef PR_FILE_NAME
#define PR_FILE_NAME "/bin/pr"
***************
*** 72,85 ****

/* Support old-fashioned C compilers. */
#if defined (__STDC__) || defined (__GNUC__)
#include "limits.h"
#else
#define INT_MAX 2147483647
#define CHAR_BIT 8
#endif

/* Support old-fashioned C compilers. */
! #if !defined (__STDC__) && !defined (__GNUC__)
#define const
#endif

--- 87,118 ----

/* Support old-fashioned C compilers. */
#if defined (__STDC__) || defined (__GNUC__)
+ #if !defined(MSDOS)
#include "limits.h"
#else
+ #include
+ #endif /* MSDOS */
+ #else
#define INT_MAX 2147483647
#define CHAR_BIT 8
#endif

+ #if defined(MSDOS)
+ #ifdef INT_MAX
+ #undef INT_MAX
+ #include
+ #endif
+ #if !defined(MAKING_PROTO_H)
+ #include "proto.h"
+ #endif
+ #include
+ #include
+ #include
+ extern int getopt(int nargc,char **nargv,char *ostr);
+ #endif
+
/* Support old-fashioned C compilers. */
! #if !defined (__STDC__) && !defined (__GNUC__) || defined(MSDOS)
#define const
#endif

***************
*** 226,237 ****
struct stat stat; /* File status from fstat() */
int dir_p; /* 1 if file is a directory */

/* 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;
--- 259,279 ----
struct stat stat; /* File status from fstat() */
int dir_p; /* 1 if file is a directory */

+ #if !defined(MSDOS)
/* Buffer in which text of file is read. */
char * buffer;
/* Allocated size of buffer. */
int bufsize;
/* Number of valid characters now in the buffer. */
! long int buffered_chars;
! #else /* MSDOS */
! /* Buffer in which text of file is read. */
! char huge *buffer;
! /* Allocated size of buffer. */
! long int bufsize;
! /* Number of valid characters now in the buffer. */
! long int buffered_chars;
! #endif /* MSDOS */

/* Array of data on analyzed lines of this chunk of this file. */
struct line_def *linbuf;
diff -cN old/dir.c dir.c
*** old/dir.c Tue May 08 00:11:08 1990
--- dir.c Mon May 07 23:41:34 1990
***************
*** 31,36 ****
--- 31,127 ----
char **files; /* Sorted names of files in the dir */
};

+ #if defined(MSDOS)
+ /*
+ ** due to difference of opinion btw gnu and microsoft about what
+ ** const means, const is defined away in diff.h, which causes warnings
+ ** when compiling the headers. This ugliness is avoided here.
+ */
+ #ifdef const
+ #undef const
+ #endif
+ #include
+ #ifdef OS2
+ #define INCL_NOPM
+ #include
+ #define _A_NORMAL 0x00
+ #define _A_SUBDIR 0x10
+ #else
+ #include
+ #endif
+
+ struct direct {
+ char d_name[14];
+ };
+
+ typedef struct _dir {
+ int first;
+ #ifdef OS2
+ FILEFINDBUF find;
+ #else
+ struct find_t dta;
+ #endif
+ struct direct current;
+ } DIR;
+
+ #ifdef OS2
+ static HDIR hdir;
+ static USHORT count;
+ #endif
+
+ DIR *
+ opendir(char *name) {
+ char localname[65];
+ DIR *rval = malloc(sizeof(DIR));
+ strcpy(localname,name);
+ strcat(localname,"/*.*");
+ #ifdef OS2
+ hdir = count = 1;
+ #endif
+ if(rval == NULL ||
+ #ifdef OS2
+ DosFindFirst(localname, &hdir, _A_NORMAL|_A_SUBDIR, &rval->find,
+ sizeof(FILEFINDBUF), &count, 0L) != 0)
+ #else
+ _dos_findfirst(localname,_A_NORMAL|_A_SUBDIR,&rval->dta) != 0)
+ #endif
+ return NULL;
+ rval->first = 1;
+ return rval;
+ }
+
+ void
+ closedir(DIR *x) {
+ free(x);
+ }
+
+ struct direct *
+ readdir(DIR *thisdir) {
+ /*
+ ** first time through, we don't need to look for a file
+ */
+ if(!thisdir->first) {
+ #ifdef OS2
+ if(DosFindNext(hdir, &thisdir->find, sizeof(FILEFINDBUF),
+ &count) != 0)
+ #else
+ if(_dos_findnext(&thisdir->dta) != 0)
+ #endif
+ return NULL;
+ } else
+ thisdir->first = 0;
+ #ifdef OS2
+ strncpy(thisdir->current.d_name,thisdir->find.achName,13);
+ #else
+ strncpy(thisdir->current.d_name,thisdir->dta.name,13);
+ #endif
+ thisdir->current.d_name[13] = '\0';
+ strlwr(thisdir->current.d_name);
+ return &thisdir->current;
+ }
+
+ #endif /* MSDOS */
+
static struct dirdata
dir_sort (dirname, nonex)
char *dirname;
***************
*** 135,141 ****
--- 226,240 ----
int
diff_dirs (name1, name2, handle_file, depth, nonex1, nonex2)
char *name1, *name2;
+ #if !defined(MSDOS)
int (*handle_file) ();
+ #else
+ /* sorry, rms, I can't live with the assumption that
+ ** sizeof(char *) == sizeof(int)
+ */
+ int (*handle_file)(char *dir0,char *name0,
+ char *dir1,char *name1,int depth);
+ #endif
int nonex1, nonex2;
{
struct dirdata data1, data2;
diff -cN old/io.c io.c
*** old/io.c Tue May 08 00:11:10 1990
--- io.c Mon May 07 23:47:30 1990
***************
*** 20,27 ****
--- 20,31 ----
#include "diff.h"

/* Rotate a value n bits to the left. */
+ #if !defined(MSDOS)
#define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
#define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
+ #else
+ #define ROL(v,n) ((v) << (n) | (v) >> (sizeof(v) * CHAR_BIT) - (n))
+ #endif

/* Given a hash value and a new character, return a new hash value. */
#define HASH(h, c) ((c) + ROL (h, 7))
***************
*** 40,46 ****
--- 44,54 ----
int size;
{
while (--size >= 0)
+ #ifdef MSDOS
+ if (*buf == 0 || *buf == 127)
+ #else
if (*buf == 0 || (*buf++ & 0200) != 0)
+ #endif
return 1;
return 0;
}
***************
*** 66,71 ****
--- 74,80 ----
beyond those that current->bufsize describes:
one for a newline (in case the text does not end with one)
and one for a sentinel in find_identical_ends. */
+ #if !defined(MSDOS)
else if ((current->stat.st_mode & S_IFMT) == S_IFREG)
{
current->bufsize = current->stat.st_size;
***************
*** 72,80 ****
--- 81,105 ----
current->buffer = (char *) xmalloc (current->bufsize + 2);
current->buffered_chars
= read (current->desc, current->buffer, current->bufsize);
+ #else /* MSDOS */
+ else {
+ current->bufsize = current->stat.st_size + 1;
+ if((current->buffer =
+ (char huge *)halloc(current->bufsize + 2,sizeof(char))) == NULL)
+ fatal("virtual memory exhausted");
+ {
+ int count;
+ current->buffered_chars = 0;
+ while((count = read(current->desc,
+ current->buffer+current->buffered_chars,
+ 32000)) > 0)
+ current->buffered_chars += count;
+ }
+ #endif /* MSDOS */
if (current->buffered_chars < 0)
pfatal_with_name (current->name);
}
+ #if !defined(MSDOS)
else
{
int cc;
***************
*** 101,106 ****
--- 126,132 ----
if (cc < 0)
pfatal_with_name (current->name);
}
+ #endif /* MSDOS */

/* Check first part of file to see if it's a binary file. */
if (! always_text_flag
***************
*** 137,145 ****
--- 163,181 ----
unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;

/* Attempt to get a good initial guess as to the number of lines. */
+ #if !defined(MSDOS)
current->linbufsize = current->buffered_chars / 50 + 5;
current->linbuf
= (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
+ #else
+ long int buffersize;
+ current->linbufsize = (int)
+ (buffersize = (long int)(current->buffered_chars / 50 + 5));
+ buffersize *= sizeof(struct line_def);
+ if(buffersize > 65535L)
+ fatal("Too many lines to compare");
+ current->linbuf = (struct line_def *) xmalloc((size_t)buffersize);
+ #endif

if (function_regexp || output_style == OUTPUT_IFDEF)
{
***************
*** 469,474 ****
--- 505,511 ----
16381,
32749,
65521,
+ #if !defined MSDOS
131071,
262139,
524287,
***************
*** 480,485 ****
--- 517,523 ----
33554393,
67108859, /* Preposterously large . . . */
-1
+ #endif
};

/* Index of current nbuckets in primes. */
diff -cN old/util.c util.c
*** old/util.c Tue May 08 00:11:12 1990
--- util.c Mon May 07 23:41:38 1990
***************
*** 51,57 ****
char *arg;
char *arg1;
{
! fprintf (stderr, "%s: ", program);
fprintf (stderr, format, arg, arg1);
fprintf (stderr, "\n");
}
--- 51,57 ----
char *arg;
char *arg1;
{
! fprintf (stderr, "\n%s: ", program);
fprintf (stderr, format, arg, arg1);
fprintf (stderr, "\n");
}
***************
*** 129,134 ****
--- 129,135 ----
strcat (name, " ");
strcat (name, name1);

+ #if !defined(MSDOS)
if (paginate_flag)
{
int pipes[2];
***************
*** 161,166 ****
--- 162,168 ----
}
}
else
+ #endif
{

/* If -l was not specified, output the diff straight to `stdout'. */
***************
*** 185,191 ****
--- 187,195 ----
if (outfile != stdout)
{
fclose (outfile);
+ #if !defined(MSDOS)
wait (0);
+ #endif
}
}



  3 Responses to “Category : C Source Code
Archive   : DIFF114.ZIP
Filename : PATCHES.OS2

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/