

diff -ubB addext.c-orig addext.c

--- addext.c-orig	Sun May  7 06:50:55 2000

+++ addext.c	Thu May  4 11:03:46 2000

@@ -57,6 +57,7 @@

 void

 addext (char *filename, char const *ext, int e)

 {

+#ifndef VMS

   char *s = base_name (filename);

   size_t slen = strlen (s), extlen = strlen (ext);

   long slen_max = -1;

@@ -102,4 +103,32 @@

       s[slen] = e;

       s[slen + 1] = 0;

     }

+#else /* VMS - add the extension to the file type field */

+  int firstdot, lastdot;

+  char *p = malloc(strlen(ext)+1);

+  strcpy(p,ext);

+  ext = p;

+

+  lastdot=strlen(filename);

+

+  for (firstdot = lastdot-1; 

+       firstdot > 0 && filename[firstdot] != '/';

+       firstdot--);

+  for (;

+       ((firstdot<lastdot) && (filename[firstdot] != '.'));

+       firstdot++);

+  for (;

+       ((lastdot>0) && (filename[lastdot] != '.')

+                    && (filename[lastdot] != ';'));

+       lastdot--);

+

+  /* make sure extension appears in filetype */

+  if (lastdot==0) strcat(filename, ".");

+  else if (lastdot > firstdot) filename[lastdot] = '\0';

+  lastdot = strlen(ext);

+  for (firstdot = 0; firstdot <= lastdot; firstdot++)

+    if (ext[firstdot] == '.') ext[firstdot] = '_';

+  strcat(filename,ext);

+  free(ext);

+#endif /* VMS */

 }



diff -ubB argmatch.c-orig argmatch.c

--- argmatch.c-orig	Tue May 16 09:23:54 2000

+++ argmatch.c	Tue May 16 09:00:50 2000

@@ -56,7 +56,17 @@

 

 /* Non failing version of argmatch call this function after failing. */

 #ifndef ARGMATCH_DIE

+# if HAVE_STDLIB_H

+#  include <stdlib.h>

 # define ARGMATCH_DIE exit (EXIT_FAILURE)

+# else

+#  if HAVE_UNISTD_H

+#   include <unistd.h>

+#   define ARGMATCH_DIE _exit (EXIT_FAILURE)

+#  else

+#   define ARGMATCH_DIE exit (EXIT_FAILURE)

+#  endif

+# endif

 #endif

 

 #ifdef ARGMATCH_DIE_DECL



diff -ubB backupfile.c-orig backupfile.c

--- backupfile.c-orig	Sun May  7 06:51:05 2000

+++ backupfile.c	Tue May 16 09:00:50 2000

@@ -105,7 +105,11 @@

 

 /* The extension added to file names to produce a simple (as opposed

    to numbered) backup file name. */

+#ifdef VMS

+const char *simple_backup_suffix = "_orig"; /* ~ is illegal in filenames */

+#else

 const char *simple_backup_suffix = "~";

+#endif

 

 static int max_backup_version PARAMS ((const char *, const char *));

 static int version_number PARAMS ((const char *, const char *, size_t));

@@ -140,12 +144,20 @@

 	  int highest_backup;

 	  size_t dir_len = base_name (s) - s;

 

+#ifndef VMS

 	  strcpy (s + dir_len, ".");

+#else

+          strcpy (s + dir_len, ";");

+#endif

 	  highest_backup = max_backup_version (file + dir_len, s);

 	  if (! (backup_type == numbered_existing && highest_backup == 0))

 	    {

 	      char *numbered_suffix = s + (file_len + backup_suffix_size_max);

+#ifndef VMS

 	      sprintf (numbered_suffix, ".~%d~", highest_backup + 1);

+#else

+              sprintf (numbered_suffix, ";%d", highest_backup + 1);

+#endif

 	      suffix = numbered_suffix;

 	    }

 	  strcpy (s, file);

@@ -206,6 +218,7 @@

 

   version = 0;

   if (strncmp (base, backup, base_length) == 0

+#ifndef VMS

       && backup[base_length] == '.'

       && backup[base_length + 1] == '~')

     {

@@ -214,6 +227,13 @@

       if (p[0] != '~' || p[1])

 	version = 0;

     }

+#else

+      && backup[base_length] == ';')

+    {

+      for (p = &backup[base_length + 1]; ISDIGIT (*p); ++p)

+        version = version * 10 + *p - '0';

+    }

+#endif

   return version;

 }

 #endif /* HAVE_DIR */



diff -ubB config.vms-orig config.vms

--- config.vms-orig	Sun May  7 06:52:14 2000

+++ config.vms	Tue May 16 09:15:36 2000

@@ -0,0 +1,219 @@

+/* config.VMS  Generated manually by lane@duphy4.physics.drexel.edu */

+

+/* Define if on AIX 3.

+   System headers sometimes define this.

+   We just want to avoid a redefinition error message.  */

+#ifndef _ALL_SOURCE

+#undef _ALL_SOURCE

+#endif

+

+/* Define if the closedir function returns void instead of int.  */

+#undef CLOSEDIR_VOID

+

+/* Define to empty if the keyword does not work.  */

+#define const

+

+/* Define if you don't have vprintf but do have _doprnt.  */

+#undef HAVE_DOPRNT

+

+/* Define if you support file names longer than 14 characters.  */

+#define HAVE_LONG_FILE_NAMES    1

+

+/* Define if you have the vprintf function.  */

+#define HAVE_VPRINTF            1

+

+/* Define if on MINIX.  */

+#undef _MINIX

+

+/* Define to `int' if <sys/types.h> doesn't define.  */

+#undef mode_t

+

+/* Define to `long' if <sys/types.h> doesn't define.  */

+#undef off_t

+

+/* Define to `int' if <sys/types.h> doesn't define.  */

+#undef pid_t

+

+/* Define if the system does not provide POSIX.1 features except

+   with this defined.  */

+#undef _POSIX_1_SOURCE

+

+/* Define if you need to in order for stat and other things to work.  */

+#undef _POSIX_SOURCE

+

+#define _POSIX_C_SOURCE 2

+

+/* Define as the return type of signal handlers (int or void).  */

+#define RETSIGTYPE void

+

+/* Define to `unsigned' if <sys/types.h> doesn't define.  */

+#undef size_t

+

+/* Define if you have the ANSI C header files.  */

+#define STDC_HEADERS    1

+

+/* Define if you can safely include both <sys/time.h> and <time.h>.  */

+#undef TIME_WITH_SYS_TIME

+

+/* Define if you have the _doprintf function.  */

+#undef HAVE__DOPRINTF

+

+/* Define if you have the fseeko function.  */

+#undef HAVE_FSEEKO

+

+/* Define if you have the isascii function.  */

+#define HAVE_ISASCII    1

+

+/* Define if you have the memchr function.  */

+#define HAVE_MEMCHR     1

+

+/* Define if you have the memcmp function.  */

+#define HAVE_MEMCMP     1

+

+/* Define if you have the mkdir function.  */

+#define HAVE_MKDIR      1

+

+/* Define if you have the mktemp function.  */

+#define HAVE_MKTEMP     1

+

+/* Define if you have the pathconf function.  */

+#define HAVE_PATHCONF   1

+

+/* Define if you have the raise function.  */

+#define HAVE_RAISE      1

+

+/* Define if you have the rename function.  */

+#define HAVE_RENAME     1

+

+/* Define if you have the rmdir function.   .. a guess ...*/

+#define HAVE_RMDIR      (__CRTL_VER >= 70000000)

+

+/* Define if you have the setmode function.  */

+#undef HAVE_SETMODE

+

+/* Define if you have the sigaction function.  */

+#define HAVE_SIGACTION   (__VMS_VER >= 70000000)

+

+/* Define if you have the sigprocmask function.  */

+#define HAVE_SIGPROCMASK (__VMS_VER >= 70000000)

+

+/* Define if you have the sigsetmask function.  */

+#define HAVE_SIGSETMASK  (__VMS_VER >= 70000000)

+

+/* Define if you have the strerror function.  */

+#define HAVE_STRERROR    1

+

+/* Define if you have the <dirent.h> header file.  */

+#define HAVE_DIRENT_H    (__VMS_VER >= 70000000)

+

+/* Define if you have the <fcntl.h> header file.  */

+#define HAVE_FCNTL_H   1

+

+/* Define if you have the <limits.h> header file.  */

+#define HAVE_LIMITS_H  1

+

+/* Define if you have the <ndir.h> header file.  */

+#undef HAVE_NDIR_H

+

+/* Define if you have the <string.h> header file.  */

+#define HAVE_STRING_H   1

+

+/* Define if you have the <sys/dir.h> header file.  */

+#undef HAVE_SYS_DIR_H

+

+/* Define if you have the <sys/ndir.h> header file.  */

+#undef HAVE_SYS_NDIR_H

+

+/* Define if you have the <unistd.h> header file.  */

+#define HAVE_UNISTD_H   1

+

+/* Define if you have the <utime.h> header file.  */

+#undef HAVE_UTIME_H

+

+/* Define if you have the <varargs.h> header file.  */

+#define HAVE_VARARGS_H

+

+/* Number of bits in a file offset, on hosts where this is settable. */

+#undef _FILE_OFFSET_BITS

+

+/* Define to make fseeko etc. visible, on some hosts. */

+#undef _LARGEFILE_SOURCE

+

+/* Define for large files, on AIX-style hosts. */

+#undef _LARGE_FILES

+

+/* Define if compiler has function prototypes */

+#define PROTOTYPES      1

+

+/* Define if <inttypes.h> exists, doesn't clash with <sys/types.h>,

+   and declares uintmax_t.  */

+#undef HAVE_INTTYPES_H

+

+/* Define if struct utimbuf is declared -- usually in <utime.h>.

+   Some systems have utime.h but don't declare the struct anywhere.  */

+#undef HAVE_STRUCT_UTIMBUF

+

+/* Define if the malloc check has been performed.  */

+#define HAVE_DONE_WORKING_MALLOC_CHECK   1

+

+/* Define to rpl_malloc if the replacement function should be used. */

+#undef malloc

+

+/* Define if the realloc check has been performed.  */

+#define HAVE_DONE_WORKING_REALLOC_CHECK   1

+

+/* Define to rpl_realloc if the replacement function should be used. */

+#undef realloc

+

+/* Define if there is a member named d_ino in the struct describing

+   directory headers. */

+#undef D_INO_IN_DIRENT

+

+

+#include <stdlib.h>

+#include <strings.h>

+#include <stdio.h>

+

+#define Fseek  my_fseek

+

+#define TMPDIR     "/sys$scratch"

+#define TTY_DEVICE "tt:"

+

+#define ed_PROGRAM ""

+

+void io_redirection(int *argc, char ***argv);

+

+#if __VMS_VER < 70000000

+int strncasecmp(const char *s0, const char *s1, size_t n);

+#include <unixio.h>

+#define unlink(f) delete(f)

+#endif

+

+/*

+    Oh, the weird stuff you find..

+                                  

+    on some systems (vms6.2, DECC 5.5) the CRTL barfs on "unix" style

+    filenames that have the "file type" begin with a '-'...VMS style

+    is okay...  so:

+        fopen("blah.-blah","w")     OK, defaults to VMS style

+        fopen("[]blah.-blah","w")   OK

+        fopen("./blah.-blah","w")   FAILS with file specification syntax err

+

+    To ADD to the fun, the DECC$TO_VMS routine has the same problem;

+    so instead of using a straight conversion, we hack off everything

+    from the ".", translate to VMS, and tack it back on.

+

+    The filenames are converted to VMS form for open/creat/rename/unlink

+    etc. CRTL functions; otherwise we use the unix form for compatibility

+    with filename mangling. 

+

+    Here I'll assume that all pre 7.0 systems have broken .- handling

+    YMMV.  It doesn't hurt to assume brokeness, there's a very minor

+    speed penalty.

+*/

+

+#define BROKEN_DOT_MINUS  (__VMS_VER < 70000000)

+

+char * vms_vmsify(char *name);

+

+char * vms_unixify(char *name);



diff -ubB descrip.mms-orig descrip.mms

--- descrip.mms-orig	Sun May  7 06:52:30 2000

+++ descrip.mms	Sun May  7 06:37:24 2000

@@ -0,0 +1,207 @@

+# Makefile for GNU patch.

+# Copyright 1993, 1997-1998, 1999 Free Software Foundation, Inc.

+

+# This program is free software; you can redistribute it and/or modify

+# it under the terms of the GNU General Public License as published by

+# the Free Software Foundation; either version 2, or (at your option)

+# any later version.

+

+# This program is distributed in the hope that it will be useful,

+# but WITHOUT ANY WARRANTY; without even the implied warranty of

+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+# GNU General Public License for more details.

+

+# You should have received a copy of the GNU General Public License

+# along with this program; see the file COPYING.

+# If not, write to the Free Software Foundation,

+# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

+

+#### Start of system configuration section. ####

+

+.IFDEF SHARED_BUILD

+.IFDEF __AXP__

+EXEEXT = .AXE

+OBJ    = .ABJ

+.ENDIF

+.ENDIF

+

+.IFDEF __AXP__

+ARCH = _AXP

+.ENDIF

+.IFDEF __VAX__

+ARCH = _VAX

+.ENDIF

+

+CC = cc

+

+.ifdef DEBUG

+CDF = /debug/noopt

+LDF = /debug

+.endif

+.ifdef VERBOSE

+.ifdef VERBOSE_SHOW

+CVF = /list/show=($(VERBOSE_SHOW))

+.else

+CVF = /list

+.endif

+LFV = /map

+.endif

+

+        

+

+CFLAGS = /stand=ansi89/prefix=(all,except=(getopt,optarg,optopt,optind,opterr)) $(cdf)$(cvf)

+LFLAGS = $(LDF)$(LVF)

+

+DEFS = VMS,HAVE_CONFIG_H

+

+.ifdef EXEEXT

+.else

+EXEEXT = .exe

+OBJ    = .obj

+.endif

+

+

+#### End of system configuration section. ####

+.SUFFIXES

+.SUFFIXES $(EXEEXT) .OLB $(OBJ) .c

+

+

+LIBSRCS = getopt.c getopt1.c

+SRCS = addext.c argmatch.c backupfile.c basename.c error.c inp.c maketime.c \

+	mkdir.c partime.c patch.c pch.c quotearg.c quotesys.c \

+	rmdir.c util.c version.c xmalloc.c vms.c

+OBJS = addext$(OBJ) argmatch$(OBJ) backupfile$(OBJ) basename$(OBJ) error$(OBJ) inp$(OBJ) \

+	maketime$(OBJ) partime$(OBJ) patch$(OBJ) pch$(OBJ) quotearg$(OBJ) quotesys$(OBJ) \

+	util$(OBJ) version$(OBJ) xmalloc$(OBJ) vms$(OBJ)

+LIBOBJS = getopt$(OBJ) getopt1$(OBJ) 

+HDRS = argmatch.h backupfile.h basename.h common.h error.h getopt.h \

+	inp.h maketime.h partime.h patchlevel.h pch.h quotearg.h quotesys.h \

+	util.h version.h xalloc.h

+

+LIB = PATCHLIB$(ARCH)

+LIBFILE = $(LIB).OLB

+!patch_name = `echo patch | sed '$(transform)'`

+

+all :: $(LIB) patch$(EXEEXT)

+        @ continue

+info ::

+check ::

+installcheck ::

+

+COMPILE = $(CC) /DEFINE=($(DEFS))  \

+	/include=(sys$disk:[]) $(CFLAGS)

+

+.c$(OBJ) :

+	$(COMPILE) /OBJ=$(MMS$TARGET) $(MMS$SOURCE)

+$(OBJ).OLB : 

+   LIB $(MMS$TARGET) $(MMS$SOURCE)

+patch$(EXEEXT) : PATCH$(obj) $(LIB)

+	LINK $(LFLAGS)/EXE=$(MMS$TARGET) PATCH$(OBJ),$(lib)/LIB

+

+install :: all installdirs

+	$(INSTALL_PROGRAM) patch$(EXEEXT) $(bindir)/$(patch_name)$(EXEEXT)

+	-$(INSTALL_DATA) patch.man $(man1dir)/$(patch_name)$(man1ext)

+

+installdirs ::

+	$(SHELL) mkinstalldirs $(bindir) $(man1dir)

+

+install-strip ::

+	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install

+

+uninstall ::

+	rm -f $(bindir)/$(patch_name)$(EXEEXT)

+	rm -f $(man1dir)/$(patch_name)$(man1ext)

+

+!Makefile :  Makefile.in $(CONFIG_STATUS)

+!	$(SHELL) $(CONFIG_STATUS)

+!config.status: configure

+!	$(SHELL) $(CONFIG_STATUS) --recheck

+

+patchlevel.h : configure.in

+	open/write fd patchlevel.h

+	write fd "#define PATCH_VERSION ""$(VERSION)""

+	close fd

+

+mostlyclean ::

+    if f$search("*.lis") .nes. "" then delete *.lis;*

+    if f$search("*.map") .nes. "" then delete *.map;*

+    if f$search("*$(OBJ)") .nes. "" then delete *$(OBJ);*

+

+clean :: mostlyclean

+    if f$search("*$(EXEEXT)") .nes. "" then delete patch$(EXEEXT);*

+

+distclean :: clean

+    if f$search("config.h") .nes. "" then delete config.h;*

+!!!	rm -f Makefile config.cache config.log config.status config.h

+

+PV = $(PACKAGE)-$(VERSION)

+

+config.h : config.vms

+    copy config.vms config.h

+

+

+$(OBJS) : config.h

+addext$(OBJ) : backupfile.h

+argmatch$(OBJ) : argmatch.h error.h quotearg.h

+backupfile$(OBJ) : argmatch.h backupfile.h

+error$(OBJ) : error.h

+getopt$(OBJ) : getopt.h

+getopt1$(OBJ) : getopt.h

+inp$(OBJ) : backupfile.h common.h inp.h pch.h quotearg.h util.h xalloc.h

+maketime$(OBJ) : maketime.h partime.h

+partime$(OBJ) : partime.h

+patch$(OBJ) : argmatch.h backupfile.h common.h getopt.h inp.h \

+	pch.h quotearg.h util.h version.h xalloc.h

+pch$(OBJ) : backupfile.h basename.h common.h inp.h pch.h quotearg.h util.h

+quotearg$(OBJ) : quotearg.h xalloc.h

+quotesys$(OBJ) : quotesys.h

+util$(OBJ) : backupfile.h basename.h common.h maketime.h \

+	partime.h quotearg.h quotesys.h util.h version.h xalloc.h

+version$(OBJ) : common.h patchlevel.h util.h version.h

+xmalloc$(OBJ) : xalloc.h

+

+$(LIBFILE) : 

+    if f$search("$(MMS$TARGET)") .eqs. "" then lib/create $(MMS$TARGET)

+                                       

+$(LIB)(ADDEXT)     : ADDEXT$(OBJ)

+                     library $(mms$target)  $(mms$source)

+$(LIB)(argmatch)   : argmatch$(OBJ)      

+                     library $(mms$target)  $(mms$source)

+$(LIB)(backupfile) : backupfile$(OBJ)    

+                     library $(mms$target)  $(mms$source)

+$(LIB)(basename)   : basename$(OBJ)      

+                     library $(mms$target)  $(mms$source)

+$(LIB)(error)      : error$(OBJ)         

+                     library $(mms$target)  $(mms$source)

+$(LIB)(inp)        : inp$(OBJ)           

+                     library $(mms$target)  $(mms$source)

+$(LIB)(maketime)   : maketime$(OBJ)      

+                     library $(mms$target)  $(mms$source)

+$(LIB)(partime)    : partime$(OBJ)       

+                     library $(mms$target)  $(mms$source)

+$(LIB)(pch)        : pch$(OBJ)           

+                     library $(mms$target)  $(mms$source)

+$(LIB)(quotearg)   : quotearg$(OBJ)      

+                     library $(mms$target)  $(mms$source)

+$(LIB)(quotesys)   : quotesys$(OBJ)      

+                     library $(mms$target)  $(mms$source)

+$(LIB)(util)       : util$(OBJ)          

+                     library $(mms$target)  $(mms$source)

+$(LIB)(version)    : version$(OBJ)       

+                     library $(mms$target)  $(mms$source)

+$(LIB)(xmalloc)    : xmalloc$(OBJ)       

+                     library $(mms$target)  $(mms$source)

+$(LIB)(vms)        : vms$(OBJ)       

+                     library $(mms$target)  $(mms$source)

+

+$(LIB)(getopt)     : getopt$(OBJ)

+                     library $(mms$target)  $(mms$source)

+$(LIB)(getopt1)    : getopt1$(OBJ)

+                     library $(mms$target)  $(mms$source)

+

+$(LIB) : $(LIBFILE) $(LIB)(ADDEXT) $(LIB)(argmatch) $(LIB)(backupfile) $(LIB)(basename) \

+         $(LIB)(error) $(LIB)(inp) $(LIB)(maketime) $(LIB)(partime)   \

+         $(LIB)(pch) $(LIB)(quotearg) $(LIB)(quotesys) \

+         $(LIB)(util) $(LIB)(version) $(LIB)(xmalloc) $(LIB)(vms)\

+         $(LIB)(getopt) $(LIB)(getopt1)

+        @ CONTINUE



diff -ubB inp.c-orig inp.c

--- inp.c-orig	Sun May  7 06:51:14 2000

+++ inp.c	Fri May  5 12:06:44 2000

@@ -234,8 +234,15 @@

      When creating files, the files do not actually exist.  */

   if (size)

     {

+#ifndef VMS

       int ifd = open (filename, O_RDONLY|binary_transput);

       size_t buffered = 0, n;

+#else

+      char *filename_vms = vms_vmsify(filename);

+      int ifd = open (filename_vms, O_RDONLY|binary_transput,0,"ctx=rec");

+      size_t buffered = 0, n;

+      free(filename_vms);

+#endif

       if (ifd < 0)

 	pfatal ("can't open file %s", quotearg (filename));

 

@@ -335,8 +342,17 @@

 

   if (instat.st_size == 0)

     filename = NULL_DEVICE;

+#ifndef VMS

   if (! (ifp = fopen (filename, binary_transput ? "rb" : "r")))

     pfatal ("Can't open file %s", quotearg (filename));

+#else

+  {

+    char *filename_vms = vms_vmsify(filename);

+  if (! (ifp = fopen (filename_vms, binary_transput ? "rb" : "r")))

+    pfatal ("Can't open file %s", quotearg (filename));

+    free(filename_vms);

+  }

+#endif

   exclusive = TMPINNAME_needs_removal ? 0 : O_EXCL;

   TMPINNAME_needs_removal = 1;

   tifd = create_file (TMPINNAME, O_RDWR | O_BINARY | exclusive, (mode_t) 0);



diff -ubB patch.c-orig patch.c

--- patch.c-orig	Sun May  7 06:51:20 2000

+++ patch.c	Tue May 16 09:00:50 2000

@@ -34,9 +34,24 @@

 #include <version.h>

 #include <xalloc.h>

 

-#if HAVE_UTIME_H

+#ifdef VMS

+#include <ssdef.h>

+#include <climsgdef.h>

+# define BAD_OPTION CLI$_INVQUAL

+# define BAD_PARAMETER CLI$_NULFIL

+#else

+# define BAD_OPTION 2

+# define BAD_PARAMETER 2

+#endif

+

+#ifdef HAVE_UTIME_H

 # include <utime.h>

+#else

+#ifdef VMS

+# define utime(a, b) -1  /* don't have the function */

 #endif

+#endif

+

 /* Some nonstandard hosts don't declare this structure even in <utime.h>.  */

 #if ! HAVE_STRUCT_UTIMBUF

 struct utimbuf

@@ -121,6 +136,9 @@

     struct outstate outstate;

     char numbuf[LINENUM_LENGTH_BOUND + 1];

 

+#ifdef VMS

+    io_redirection(&argc, &argv);

+#endif

     init_time ();

 

     setbuf(stderr, serrbuf);

@@ -426,7 +444,11 @@

 		if (!rejname) {

 		    rej = xmalloc (strlen (outname) + 5);

 		    strcpy (rej, outname);

+#ifdef VMS

+		    addext (rej, "_rej", '#');

+#else

 		    addext (rej, ".rej", '#');

+#endif

 		}

 		say (" -- saving rejects to file %s", quotearg (rej));

 		if (! dry_run)

@@ -493,7 +515,9 @@

   {"context", no_argument, NULL, 'c'},

   {"directory", required_argument, NULL, 'd'},

   {"ifdef", required_argument, NULL, 'D'},

+#ifndef VMS

   {"ed", no_argument, NULL, 'e'},

+#endif

   {"remove-empty-files", no_argument, NULL, 'E'},

   {"force", no_argument, NULL, 'f'},

   {"fuzz", required_argument, NULL, 'F'},

@@ -537,7 +561,9 @@

 "  -l  --ignore-whitespace  Ignore white space changes between patch and input.",

 "",

 "  -c  --context  Interpret the patch as a context difference.",

+#ifdef HAVE_ED

 "  -e  --ed  Interpret the patch as an ed script.",

+#endif

 "  -n  --normal  Interpret the patch as a normal difference.",

 "  -u  --unified  Interpret the patch as a unified difference.",

 "",

@@ -616,7 +642,11 @@

 	fprintf (stream, "%s\n", *p);

     }

 

+#ifndef VMS

   exit (status);

+#else

+  exit (status? 44 : 1);

+#endif

 }

 

 /* Process switches and filenames.  */

@@ -667,9 +697,11 @@

 	    case 'D':

 		do_defines = savestr (optarg);

 		break;

+#ifdef HAVE_ED

 	    case 'e':

 		diff_type = ED_DIFF;

 		break;

+#endif

 	    case 'E':

 		remove_empty_files = TRUE;

 		break;

@@ -776,14 +808,14 @@

 		  if (i < 0)

 		    {

 		      invalid_arg ("quoting style", optarg, i);

-		      usage (stderr, 2);

+		      usage (stderr, BAD_OPTION);

 		    }

 		  set_quoting_style ((struct quoting_options *) 0,

 				     (enum quoting_style) i);

 		}

 		break;

 	    default:

-		usage (stderr, 2);

+		usage (stderr, BAD_OPTION);

 	}

     }

 

@@ -799,7 +831,7 @@

 	      {

 		fprintf (stderr, "%s: %s: extra operand\n",

 			 program_name, quotearg (Argv[optind]));

-		usage (stderr, 2);

+		usage (stderr, BAD_PARAMETER);

 	      }

 	  }

       }

@@ -1343,7 +1375,11 @@

   if (sig)

     exit_with_signal (sig);

 

+#ifdef VMS

+  exit (SS$_ABORT);

+#else

   exit (2);

+#endif

 }

 

 static void



diff -ubB pch.c-orig pch.c

--- pch.c-orig	Sun May  7 06:51:27 2000

+++ pch.c	Tue May 16 09:00:50 2000

@@ -145,7 +145,13 @@

       }

     else

       {

+#ifndef VMS

 	pfp = fopen (filename, binary_transput ? "rb" : "r");

+#else

+	char *filename_vms = vms_vmsify(filename);

+	pfp = fopen (filename_vms, binary_transput ? "rb" : "r");

+	free(filename_vms);

+#endif

 	if (!pfp)

 	  pfatal ("Can't open patch file %s", quotearg (filename));

 	if (fstat (fileno (pfp), &st) != 0)

@@ -556,17 +562,17 @@

 		      char const *cs;

 		      char *getbuf;

 		      char *diffbuf;

-		      int readonly = outfile && strcmp (outfile, name[i]) != 0;

+		      int read_only = outfile && strcmp (outfile, name[i]) != 0;

 

 		      if (nope == NONE || strcmp (name[nope], name[i]) != 0)

 			{

 			  cs = (version_controller

-			        (name[i], readonly, (struct stat *) 0,

+			        (name[i], read_only, (struct stat *) 0,

 				 &getbuf, &diffbuf));

 			  version_controlled[i] = !! cs;

 			  if (cs)

 			    {

-			      if (version_get (name[i], cs, 0, readonly,

+			      if (version_get (name[i], cs, 0, read_only,

 					       getbuf, &st[i]))

 				stat_errno[i] = 0;

 			      else

@@ -1840,6 +1846,7 @@

 void

 do_ed_script (FILE *ofp)

 {

+#ifdef HAVE_ED

     static char const ed_program[] = ed_PROGRAM;

 

     register char *t;

@@ -1910,4 +1917,7 @@

 	if (ferror (ifp) || fclose (ifp) != 0)

 	  read_fatal ();

       }

+#else

+    return;

+#endif

 }



diff -ubB util.c-orig util.c

--- util.c-orig	Sun May  7 06:51:35 2000

+++ util.c	Tue May 16 09:00:51 2000

@@ -74,13 +74,27 @@

 	   char *to, mode_t mode, int backup)

 {

   struct stat to_st;

+#ifndef VMS

   int to_errno = ! backup ? -1 : stat (to, &to_st) == 0 ? 0 : errno;

+#else

+  int to_errno;

+  char *to_vms, *from_vms;

+

+  to_vms   = vms_vmsify(to);

+  from_vms = vms_vmsify(from);

+  to = vms_unixify(to_vms);

+  from = vms_unixify(from_vms);

+

+  to_errno = ! backup ? -1 : stat (to_vms, &to_st) == 0 ? 0 : errno;

+#endif

 

   if (backup)

     {

       int try_makedirs_errno = 0;

       char *bakname;

-

+#ifdef VMS

+      char *bakname_vms;

+#endif

       if (origprae || origbase)

 	{

 	  char const *p = origprae ? origprae : "";

@@ -108,7 +122,9 @@

 	  if (!bakname)

 	    memory_fatal ();

 	}

-

+#ifdef VMS

+    bakname_vms = vms_vmsify(bakname);

+#endif

       if (to_errno)

 	{

 	  int fd;

@@ -117,8 +132,13 @@

 	    say ("Creating empty unreadable file %s\n", quotearg (bakname));

 

 	  try_makedirs_errno = ENOENT;

+#ifndef VMS

 	  unlink (bakname);

 	  while ((fd = creat (bakname, 0)) < 0)

+#else

+	  unlink (bakname_vms);

+	  while ((fd = creat (bakname_vms, 0)) < 0)

+#endif

 	    {

 	      if (errno != try_makedirs_errno)

 		pfatal ("Can't create file %s", quotearg (bakname));

@@ -133,7 +153,11 @@

 	  if (debug & 4)

 	    say ("Renaming file %s to %s\n",

 		 quotearg_n (0, to), quotearg_n (1, bakname));

+#ifndef VMS

 	  while (rename (to, bakname) != 0)

+#else

+	  while (rename (to_vms, bakname_vms) != 0)

+#endif

 	    {

 	      if (errno != try_makedirs_errno)

 		pfatal ("Can't rename file %s to %s",

@@ -144,6 +168,9 @@

 	}

 

       free (bakname);

+#ifdef VMS

+      free (bakname_vms);

+#endif

     }

 

   if (from)

@@ -152,7 +179,11 @@

 	say ("Renaming file %s to %s\n",

 	     quotearg_n (0, from), quotearg_n (1, to));

 

+#ifndef VMS

       if (rename (from, to) == 0)

+#else

+      if (rename (from_vms, to_vms) == 0)

+#endif

 	*from_needs_removal = 0;

       else

 	{

@@ -163,15 +194,24 @@

 	    {

 	      makedirs (to);

 	      to_dir_known_to_exist = 1;

+#ifndef VMS

 	      if (rename (from, to) == 0)

+#else

+	      if (rename (from_vms, to_vms) == 0)

+#endif

 		{

 		  *from_needs_removal = 0;

 		  return;

 		}

 	    }

 

+#ifndef VMS

 	  if (errno == EXDEV)

+#else

+	  if (errno == EXDEV || errno == ENOENT || errno == ENXIO)

+#endif

 	    {

+#ifndef VMS

 	      if (! backup)

 		{

 		  if (unlink (to) == 0)

@@ -179,6 +219,7 @@

 		  else if (errno != ENOENT)

 		    pfatal ("Can't remove file %s", quotearg (to));

 		}

+#endif

 	      if (! to_dir_known_to_exist)

 		makedirs (to);

 	      copy_file (from, to, 0, mode);

@@ -193,9 +234,17 @@

     {

       if (debug & 4)

 	say ("Removing file %s\n", quotearg (to));

+#ifndef VMS

       if (unlink (to) != 0)

+#else

+      if (unlink (to_vms) != 0)

+#endif

 	pfatal ("Can't remove file %s", quotearg (to));

     }

+#ifdef VMS

+    if (to_vms)   free(to_vms);

+    if (from_vms) free(from_vms);

+#endif

 }

 

 /* Create FILE with OPEN_FLAGS, and with MODE adjusted so that

@@ -205,6 +254,9 @@

 create_file (char const *file, int open_flags, mode_t mode)

 {

   int fd;

+#ifdef VMS

+  file = vms_vmsify(file);

+#endif

   mode |= S_IRUSR | S_IWUSR;

   mode &= ~ (S_IXUSR | S_IXGRP | S_IXOTH);

   if (! (O_CREAT && O_TRUNC))

@@ -212,6 +264,9 @@

   fd = open (file, O_CREAT | O_TRUNC | open_flags, mode);

   if (fd < 0)

     pfatal ("Can't create file %s", quotearg (file));

+#ifdef VMS

+  free(file);

+#endif

   return fd;

 }

 

@@ -224,7 +279,13 @@

   int fromfd;

   size_t i;

 

+#ifndef VMS

   if ((fromfd = open (from, O_RDONLY | O_BINARY)) < 0)

+#else

+  char *from_vms = vms_vmsify(from);

+

+  if ((fromfd = open (from_vms, O_RDONLY | O_BINARY, 0, "ctx=rec")) < 0)

+#endif

     pfatal ("Can't reopen file %s", quotearg (from));

   tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode);

   while ((i = read (fromfd, buf, bufsize)) != 0)

@@ -238,6 +299,9 @@

     read_fatal ();

   if (close (tofd) != 0)

     write_fatal ();

+#ifdef VMS

+  if (from_vms) free(from_vms);

+#endif

 }

 

 static char const DEV_NULL[] = NULL_DEVICE;

@@ -258,14 +322,14 @@

 /* Return "RCS" if FILENAME is controlled by RCS,

    "SCCS" if it is controlled by SCCS,

    "ClearCase" if it is controlled by Clearcase, and 0 otherwise.

-   READONLY is nonzero if we desire only readonly access to FILENAME.

+   READ_ONLY is nonzero if we desire only read_only access to FILENAME.

    FILESTAT describes FILENAME's status or is 0 if FILENAME does not exist.

    If successful and if GETBUF is nonzero, set *GETBUF to a command

    that gets the file; similarly for DIFFBUF and a command to diff the file

    (but set *DIFFBUF to 0 if the diff operation is meaningless).

    *GETBUF and *DIFFBUF must be freed by the caller.  */

 char const *

-version_controller (char const *filename, int readonly,

+version_controller (char const *filename, int read_only,

 		    struct stat const *filestat, char **getbuf, char **diffbuf)

 {

   struct stat cstat;

@@ -301,7 +365,7 @@

       if (getbuf)

 	{

 	  char *p = *getbuf = xmalloc (maxgetsize);

-	  sprintf (p, readonly ? CHECKOUT : CHECKOUT_LOCKED, dotslash);

+	  sprintf (p, read_only ? CHECKOUT : CHECKOUT_LOCKED, dotslash);

 	  p += strlen (p);

 	  p += quote_system_arg (p, filename);

 	  *p = '\0';

@@ -325,7 +389,7 @@

       if (getbuf)

 	{

 	  char *p = *getbuf = xmalloc (maxgetsize);

-	  sprintf (p, readonly ? GET : GET_LOCKED);

+	  sprintf (p, read_only ? GET : GET_LOCKED);

 	  p += strlen (p);

 	  p += quote_system_arg (p, trybuf);

 	  *p = '\0';

@@ -346,7 +410,7 @@

 

       r = "SCCS";

     }

-  else if (!readonly && filestat

+  else if (!read_only && filestat

 	   && try1 ("%s@@", filebase) && S_ISDIR (cstat.st_mode))

     {

       if (getbuf)

@@ -369,18 +433,18 @@

 }

 

 /* Get FILENAME from version control system CS.  The file already exists if

-   EXISTS is nonzero.  Only readonly access is needed if READONLY is nonzero.

+   EXISTS is nonzero.  Only read_only access is needed if READ_ONLY is nonzero.

    Use the command GETBUF to actually get the named file.

    Store the resulting file status into *FILESTAT.

    Return nonzero if successful.  */

 int

-version_get (char const *filename, char const *cs, int exists, int readonly,

+version_get (char const *filename, char const *cs, int exists, int read_only,

 	     char const *getbuf, struct stat *filestat)

 {

   if (patch_get < 0)

     {

       ask ("Get file %s from %s%s? [y] ",

-	   quotearg (filename), cs, readonly ? "" : " with lock");

+	   quotearg (filename), cs, read_only ? "" : " with lock");

       if (*buf == 'n')

 	return 0;

     }

@@ -395,7 +459,7 @@

     {

       if (verbosity == VERBOSE)

 	say ("Getting file %s from %s%s...\n", quotearg (filename),

-	     cs, readonly ? "" : " with lock");

+	     cs, read_only ? "" : " with lock");

       if (systemic (getbuf) != 0)

 	fatal ("Can't get file %s from %s", quotearg (filename), cs);

       if (stat (filename, filestat) != 0)

@@ -568,6 +632,9 @@

 	 which makes a call-process `patch' hang when it reads from /dev/tty.

 	 POSIX.2 requires that we read /dev/tty, though.  */

       ttyfd = (posixly_correct || isatty (STDOUT_FILENO)

+#ifdef VMS

+            || isatty(STDIN_FILENO)

+#endif

 	       ? open (TTY_DEVICE, O_RDONLY)

 	       : -1);

     }

@@ -883,6 +950,7 @@

 void

 removedirs (char *filename)

 {

+#if HAVE_RMDIR

   size_t i;

 

   for (i = strlen (filename);  i != 0;  i--)

@@ -900,6 +968,7 @@

 	  say ("Removed empty directory %s\n", quotearg (filename));

 	filename[i] = '/';

       }

+#endif

 }

 

 static time_t initial_time;



diff -ubB vms.c-orig vms.c

--- vms.c-orig	Sun May  7 06:51:47 2000

+++ vms.c	Tue May  9 13:56:59 2000

@@ -0,0 +1,271 @@

+/* vms specific utility routines... */

+

+#define XTERN extern

+#include <common.h>

+#include <ssdef.h>

+

+void

+io_redirection(int *argc, char **argv[])

+{

+    int i, k, new_argc = 0;

+    int append;

+    char ** vms_argv;

+    FILE *f;

+

+    vms_argv = (char **) malloc((*argc+1) * sizeof(char*));

+

+    vms_argv[new_argc++] = **argv;

+

+    for (i = 1; i < *argc; i++) {

+        if (argv[0][i][0] == '>') {

+            k = 1;

+            append = 0;

+            if (argv[0][i][k] == '>') {

+                k++;

+                append++;

+            }

+            if (argv[0][i][k]) {

+                f = freopen(argv[0][i]+k,append?"a":"w",stdout);

+                if (!f) {

+                    perror("stdout redirection");

+                    exit(SS$_ABORT);

+                }

+            } else if (i+1 < *argc && argv[0][i+1] && *argv[0][i+1]) {

+                f = freopen(argv[0][i+1],append?"a":"w",stdout);

+                if (!f) {

+                    perror("stdout redirection");

+                    exit(SS$_ABORT);

+                }

+                i++;

+            }

+        } else if (argv[0][i][0] == '2' && argv[0][i][1] == '>') {

+            k = 2;

+            append = 0;

+            if (argv[0][i][k] == '>') {

+                k++;

+                append++;

+            }

+            if (argv[0][i][k]) {

+                f = freopen(argv[0][i]+k,append?"a":"w",stderr);

+                if (!f) {

+                    perror("stderr redirection");

+                    exit(SS$_ABORT);

+                }

+            } else if (i+1 < *argc && argv[0][i+1] && *argv[0][i+1]) {

+                f = freopen(argv[0][i+1],append?"a":"w",stderr);

+                if (!f) {

+                    perror("stderr redirection");

+                    exit(SS$_ABORT);

+                }

+                i++;

+            }

+        } else if (*argv[0][i] == '<') {

+            if (argv[0][i][1]) {

+                f = freopen(argv[0][i]+1,"r",stdin);

+                if (!f) {

+                    perror("stdin redirection");

+                    exit(SS$_ABORT);

+                }

+            } else if (i+1 < *argc && argv[0][i+1] && *argv[0][i+1]) {

+                f = freopen(argv[0][i+1],"r",stdin);

+                if (!f) {

+                    perror("stdin redirection");

+                    exit(SS$_ABORT);

+                }

+                i++;

+            }

+        } else {

+            vms_argv[new_argc++] = argv[0][i];

+        }

+    }

+

+    *argc = new_argc;

+    vms_argv[new_argc] = NULL;

+    *argv = vms_argv;

+}

+

+

+#if __VMS_VER < 70000000

+

+int

+strncasecmp(const char *s1, const char *s2, size_t n)

+{

+    int i;

+    char c1, c2;

+

+    for (i=0; i < n; i++) {

+        c1 = toupper(s1[i]);

+        c2 = toupper(s2[i]);

+        if (c1 != c2) return c1 < c2 ? -1 : 1;

+        if (c1 == '\0') return  c2 ? 1: 0; /* s2 is longer */

+    }

+    return 0;

+}

+#endif

+

+/* there's apparantly a BUG in several of the CRTL functions for 

+  dealing with unix-style filenames that have a filetype that begins

+  with "-".  The most likely place for this to occur is a rename

+  (i.e., renaming "CHANGES." to "CHANGES.-ORIG"), so

+  we try and fix it here... by converting to VMS filenames./

+

+    But note that we can't use the CRTL to convert *directly* for us,

+    since it's broken...*sigh* 

+*/

+

+

+#include <unixlib.h>

+

+static char *tmpname;

+

+static int

+vms_name_fetcher(char *name, int type)

+{

+    if( type == DECC$K_DIRECTORY  ||

+        type == DECC$K_FOREIGN)  return 0;

+

+    if (name[0] == '[' && name[1] == ']') {

+        tmpname = malloc(strlen(name)+10);

+        strcpy(tmpname,"SYS$DISK:");

+        strcat(tmpname, name);

+    } else {

+        tmpname = malloc(strlen(name)+1);

+        strcpy(tmpname, name);

+    }

+    return 1;

+}

+

+static int

+unix_name_fetcher(char *name)

+{

+    tmpname = malloc(strlen(name)+1);

+    strcpy(tmpname, name);

+    return 1;

+}

+

+

+char *

+vms_vmsify(char *name)

+{

+    char *p, *q;

+

+    if (!name) return 0;

+

+    if (strchr(name,'[') || strchr(name,':') || strchr(name,'<')) {

+        p = malloc(strlen(name)+1);

+        strcpy(p,name);

+        return p;

+    }

+

+    if (!strchr(name,'/')) {

+        p = malloc(strlen(name)+12);

+        strcpy(p,"SYS$DISK:[]");

+        strcat(p,name);

+        return p;

+    }

+

+    tmpname = 0;

+#if BROKEN_DOT_MINUS

+    q = strstr(name,".-");

+    if (!q) q = name+strlen(name);

+    p = malloc(strlen(name)+1);

+    strcpy(p,name);

+    p[q-name] = '\0';

+

+    if (decc$to_vms(p,vms_name_fetcher,0,0) != 1) {

+        if (tmpname) free(tmpname);

+        free(p);

+        return 0;

+    }

+

+    p = realloc(p, strlen(tmpname)+strlen(q)+1);

+    strcpy(p,tmpname);

+    strcat(p,q);

+    free(tmpname);

+    return p;

+#else

+    if (decc$to_vms(name,vms_name_fetcher,0,0) != 1) {

+        if (tmpname) free(tmpname);

+        return 0;

+    }

+    return tmpname;

+#endif

+}

+

+

+char *

+vms_unixify(char *name)

+{

+    char *p, *q;

+    int is_sub;

+

+    if (!name) return 0;

+

+    if (strchr(name,'/')) {

+        p = malloc(strlen(name)+1);

+        strcpy(p,name);

+        return p;

+    }

+

+    if (!strchr(name,'[') && !strchr(name,'<') && !strchr(name,':')) {

+        p = malloc(strlen(name)+2);

+        strcpy(p,"./");

+        strcat(p,name);

+        return p;

+    }

+

+    if (strncasecmp(name,"SYS$DISK:[]",11) == 0) {

+        p = malloc(strlen(name)-11+2+1);

+        strcpy(p,"./");

+        strcat(p,name+11);

+        return p;

+    }

+    is_sub = strncmp(name,"[.",2) == 0;

+

+#if BROKEN_DOT_MINUS

+    q = strrchr(name,']');

+    if (!q) q = name;

+    q = strrchr(q,'>');

+    if (!q) q = name;

+

+    q = strstr(q,".-");

+    if (!q) q = name+strlen(name);

+    p = malloc(strlen(name)+1);

+    strcpy(p,name);

+    p[q-name] = '\0';

+

+    tmpname = 0;

+    if (decc$from_vms(p,unix_name_fetcher,0) != 1) {

+        if (tmpname) free(tmpname);

+        free(p);

+        return 0;

+    }

+

+    p = realloc(p, strlen(tmpname)+strlen(q)+1);

+    if (is_sub && *tmpname == '/') {

+        strcpy(p,tmpname+1);

+    } else {

+        strcpy(p,tmpname);

+    }

+    strcat(p,q);

+    free(tmpname);

+    return p;

+#else

+    tmpname = 0;

+    if (decc$from_vms(name,unix_name_fetcher,0) != 1) {

+        if (tmpname) free(tmpname);

+        return 0;

+    }

+    if (is_sub && *tmpname == '/') {

+        p = malloc(strlen(tmpname));

+        strcpy(p,tmpname+1);

+        free(tmpname);

+        return p;

+    }

+    return tmpname;

+#endif

+}

+

+

+

+

