Add patch to improve support of z/OS (OS/390). (Ralf Schandl)
diff --git a/src/INSTALL b/src/INSTALL
index a4a9925..82275d4 100644
--- a/src/INSTALL
+++ b/src/INSTALL
@@ -15,7 +15,7 @@
 See INSTALLpc.txt               for PC (MS-DOS, Windows 95/98/NT/XP)
 See INSTALLvms.txt              for VMS
 See INSTALLx.txt		for cross-compiling on Unix
-See ../runtime/doc/os_390.txt   for OS/390 Unix
+See ../README_390.txt           for OS/390 Unix
 See ../runtime/doc/os_beos.txt  for BeBox
 
 
diff --git a/src/auto/configure b/src/auto/configure
index b87825f..baeaebc 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -669,6 +669,7 @@
 compiledby
 dogvimdiff
 dovimdiff
+QUOTESED
 line_break
 VIEWNAME
 EXNAME
@@ -4384,10 +4385,10 @@
 
 
 if test "$cf_cv_ebcdic" = "yes"; then
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for OS/390 Unix" >&5
-$as_echo_n "checking for OS/390 Unix... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for z/OS Unix" >&5
+$as_echo_n "checking for z/OS Unix... " >&6; }
 case `uname` in
-    OS/390)	OS390Unix="yes";
+    OS/390)	zOSUnix="yes";
 										if test "$CC" = "cc"; then
 		  ccm="$_CC_CCMODE"
 		  ccn="CC"
@@ -4402,7 +4403,7 @@
 		if test "$ccm" != "1"; then
 		  echo ""
 		  echo "------------------------------------------"
-		  echo " On OS/390 Unix, the environment variable"
+		  echo " On z/OS Unix, the environment variable"
 		  echo " __CC_${ccn}MODE must be set to \"1\"!"
 		  echo " Do:"
 		  echo "    export _CC_${ccn}MODE=1"
@@ -4410,17 +4411,26 @@
 		  echo "------------------------------------------"
 		  exit 1
 		fi
-		CFLAGS="$CFLAGS -D_ALL_SOURCE"; LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
+		CFLAGS="$CFLAGS -D_ALL_SOURCE -Wc,float\\(IEEE\\)";
+                LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
 		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 		;;
-    *)		OS390Unix="no";
+    *)		zOSUnix="no";
 		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 		;;
 esac
 fi
 
+if test "$zOSUnix" = "yes"; then
+    QUOTESED="sed -e 's/[\\\\\"]/\\\\\\\\&/g' -e 's/\\\\\\\\\"/\"/' -e 's/\\\\\\\\\";\$\$/\";/'"
+else
+    QUOTESED="sed -e 's/[\\\\\"]/\\\\&/g' -e 's/\\\\\"/\"/' -e 's/\\\\\";\$\$/\";/'"
+fi
+
+
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking --disable-selinux argument" >&5
 $as_echo_n "checking --disable-selinux argument... " >&6; }
 # Check whether --enable-selinux was given.
@@ -6697,7 +6707,7 @@
 fi
 
 
-        if test "$OS390Unix" = "yes"; then
+        if test "$zOSUnix" = "yes"; then
     CFLAGS="$CFLAGS -W c,dll"
     LDFLAGS="$LDFLAGS -W l,dll"
     X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE -lXmu"
diff --git a/src/config.mk.in b/src/config.mk.in
index a950413..a298fae 100644
--- a/src/config.mk.in
+++ b/src/config.mk.in
@@ -100,6 +100,9 @@
 INSTALL_LANGS	= @INSTALL_LANGS@
 INSTALL_TOOL_LANGS	= @INSTALL_TOOL_LANGS@
 
+### sed command to fix quotes while creating pathdef.c
+QUOTESED        = @QUOTESED@
+
 ### Line break character as octal number for "tr"
 NL		= @line_break@
 
diff --git a/src/configure.in b/src/configure.in
index b98af27..f44cf0f 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -275,7 +275,7 @@
 	AC_MSG_RESULT($withval); AC_DEFINE_UNQUOTED(MODIFIED_BY, "$withval"),
 	AC_MSG_RESULT(no))
 
-dnl Check for EBCDIC stolen from the LYNX port to OS390 Unix
+dnl Check for EBCDIC stolen from the LYNX port to z/OS Unix
 AC_MSG_CHECKING(if character set is EBCDIC)
 AC_TRY_COMPILE([ ],
 [ /* TryCompile function for CharSet.
@@ -301,10 +301,10 @@
 AC_SUBST(line_break)
 
 if test "$cf_cv_ebcdic" = "yes"; then
-dnl If we have EBCDIC we most likley have OS390 Unix, let's test it!
-AC_MSG_CHECKING(for OS/390 Unix)
+dnl If we have EBCDIC we most likley have z/OS Unix, let's test it!
+AC_MSG_CHECKING(for z/OS Unix)
 case `uname` in
-    OS/390)	OS390Unix="yes";
+    OS/390)	zOSUnix="yes";
 		dnl If using cc the environment variable _CC_CCMODE must be
 		dnl set to "1", so that some compiler extensions are enabled.
 		dnl If using c89 the environment variable is named _CC_C89MODE.
@@ -323,7 +323,7 @@
 		if test "$ccm" != "1"; then
 		  echo ""
 		  echo "------------------------------------------"
-		  echo " On OS/390 Unix, the environment variable"
+		  echo " On z/OS Unix, the environment variable"
 		  echo " __CC_${ccn}MODE must be set to \"1\"!"
 		  echo " Do:"
 		  echo "    export _CC_${ccn}MODE=1"
@@ -331,15 +331,25 @@
 		  echo "------------------------------------------"
 		  exit 1
 		fi
-		CFLAGS="$CFLAGS -D_ALL_SOURCE"; LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
+		CFLAGS="$CFLAGS -D_ALL_SOURCE -Wc,float\\(IEEE\\)";
+                LDFLAGS="$LDFLAGS -Wl,EDIT=NO"
 		AC_MSG_RESULT(yes)
 		;;
-    *)		OS390Unix="no";
+    *)		zOSUnix="no";
 		AC_MSG_RESULT(no)
 		;;
 esac
 fi
 
+dnl Set QUOTESED. Needs additional backslashes on zOS
+if test "$zOSUnix" = "yes"; then
+    QUOTESED="sed -e 's/[[\\\\\"]]/\\\\\\\\&/g' -e 's/\\\\\\\\\"/\"/' -e 's/\\\\\\\\\";\$\$/\";/'"
+else
+    QUOTESED="sed -e 's/[[\\\\\"]]/\\\\&/g' -e 's/\\\\\"/\"/' -e 's/\\\\\";\$\$/\";/'"
+fi
+AC_SUBST(QUOTESED)
+
+
 dnl Link with -lselinux for SELinux stuff; if not found
 AC_MSG_CHECKING(--disable-selinux argument)
 AC_ARG_ENABLE(selinux,
@@ -1166,10 +1176,10 @@
 
   AC_PATH_XTRA
 
-  dnl On OS390Unix the X libraries are DLLs. To use them the code must
+  dnl On z/OS Unix the X libraries are DLLs. To use them the code must
   dnl be compiled with a special option.
   dnl Also add SM, ICE and Xmu to X_EXTRA_LIBS.
-  if test "$OS390Unix" = "yes"; then
+  if test "$zOSUnix" = "yes"; then
     CFLAGS="$CFLAGS -W c,dll"
     LDFLAGS="$LDFLAGS -W l,dll"
     X_EXTRA_LIBS="$X_EXTRA_LIBS -lSM -lICE -lXmu"
diff --git a/src/eval.c b/src/eval.c
index 865dc3a..6ad71d5 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -820,6 +820,13 @@
 static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp));
 static void setwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
 
+
+#ifdef EBCDIC
+static int compare_func_name __ARGS((const void *s1, const void *s2));
+static void sortFunctions __ARGS(());
+#endif
+
+
 /* Character used as separated in autoload function/variable names. */
 #define AUTOLOAD_CHAR '#'
 
@@ -856,6 +863,13 @@
 	    hash_add(&compat_hashtab, p->vv_di.di_key);
     }
     set_vim_var_nr(VV_SEARCHFORWARD, 1L);
+
+#ifdef EBCDIC
+    /*
+     * Sort the function table, to enable binary sort.
+     */
+    sortFunctions();
+#endif
 }
 
 #if defined(EXITFREE) || defined(PROTO)
@@ -7901,6 +7915,36 @@
 
 #endif /* FEAT_CMDL_COMPL */
 
+#if defined(EBCDIC) || defined(PROTO)
+/*
+ * Compare struct fst by function name.
+ */
+    static int
+compare_func_name(s1, s2)
+    const void *s1;
+    const void *s2;
+{
+    struct fst *p1 = (struct fst *)s1;
+    struct fst *p2 = (struct fst *)s2;
+
+    return STRCMP(p1->f_name, p2->f_name);
+}
+
+/*
+ * Sort the function table by function name.
+ * The sorting of the table above is ASCII dependant.
+ * On machines using EBCDIC we have to sort it.
+ */
+    static void
+sortFunctions()
+{
+    int		funcCnt = (int)(sizeof(functions) / sizeof(struct fst)) - 1;
+
+    qsort(functions, (size_t)funcCnt, sizeof(struct fst), compare_func_name);
+}
+#endif
+
+
 /*
  * Find internal function in table above.
  * Return index, or -1 if not found
@@ -19243,7 +19287,7 @@
 
 	while (ga_scripts.ga_len < id)
 	{
-	    sv = SCRIPT_SV(ga_scripts.ga_len + 1) = 
+	    sv = SCRIPT_SV(ga_scripts.ga_len + 1) =
 		(scriptvar_T *)alloc_clear(sizeof(scriptvar_T));
 	    init_var_dict(&sv->sv_dict, &sv->sv_var);
 	    ++ga_scripts.ga_len;
@@ -22481,7 +22525,7 @@
  * append the remaining non-existing path.
  *
  * fname - Pointer to the filename to shorten.  On return, contains the
- *         pointer to the shortened pathname
+ *	   pointer to the shortened pathname
  * bufp -  Pointer to an allocated buffer for the filename.
  * fnamelen - Length of the filename pointed to by fname
  *
diff --git a/src/feature.h b/src/feature.h
index e786e28..4f35280 100644
--- a/src/feature.h
+++ b/src/feature.h
@@ -300,16 +300,20 @@
 
 /*
  * +rightleft		Right-to-left editing/typing support.
+ *
+ * Disabled for EBCDIC as it requires multibyte.
  */
-#ifdef FEAT_BIG
+#if defined(FEAT_BIG) && !defined(EBCDIC)
 # define FEAT_RIGHTLEFT
 #endif
 
 /*
  * +farsi		Farsi (Persian language) Keymap support.
  *			Requires FEAT_RIGHTLEFT.
+ *
+ * Disabled for EBCDIC as it requires multibyte.
  */
-#ifdef FEAT_BIG
+#if defined(FEAT_BIG) && !defined(EBCDIC)
 # define FEAT_FKMAP
 #endif
 #ifdef FEAT_FKMAP
@@ -321,6 +325,8 @@
 /*
  * +arabic		Arabic keymap and shaping support.
  *			Requires FEAT_RIGHTLEFT and FEAT_MBYTE.
+ *
+ * Disabled for EBCDIC as it requires multibyte.
  */
 #if defined(FEAT_BIG) && !defined(WIN16) && SIZEOF_INT >= 4 && !defined(EBCDIC)
 # define FEAT_ARABIC
@@ -343,7 +349,7 @@
  * +tag_binary		Can use a binary search for the tags file.
  *
  * Disabled for EBCDIC:
- * On OS/390 Unix we have the problem that /bin/sort sorts ASCII instead of
+ * On z/OS Unix we have the problem that /bin/sort sorts ASCII instead of
  * EBCDIC.  With this binary search doesn't work, as VIM expects a tag file
  * sorted by character values.  I'm not sure how to fix this. Should we really
  * do a EBCDIC to ASCII conversion for this??
@@ -530,8 +536,11 @@
 
 /*
  * +spell		spell checking
+ *
+ * Disabled for EBCDIC:
+ * Doesn't work (SIGSEGV). 
  */
-#if defined(FEAT_NORMAL) || defined(PROTO)
+#if (defined(FEAT_NORMAL) || defined(PROTO)) && !defined(EBCDIC)
 # define FEAT_SPELL
 #endif
 
@@ -622,7 +631,7 @@
  *			with 16 bit ints.  Required for GTK+ 2.
  *
  * Disabled for EBCDIC:
- * Multibyte support doesn't work on OS390 Unix currently.
+ * Multibyte support doesn't work on z/OS Unix currently.
  */
 #if (defined(FEAT_BIG) || defined(HAVE_GTK2) || defined(FEAT_ARABIC)) \
 	&& !defined(FEAT_MBYTE) && !defined(WIN16) \
diff --git a/src/regexp.c b/src/regexp.c
index 5355945..ae1b03a 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -731,6 +731,30 @@
     return 0;
 }
 
+#ifdef EBCDIC
+/*
+ * Table for equivalence class "c". (IBM-1047)
+ */
+char *EQUIVAL_CLASS_C[16] = {
+    "A\x62\x63\x64\x65\x66\x67",
+    "C\x68",
+    "E\x71\x72\x73\x74",
+    "I\x75\x76\x77\x78",
+    "N\x69",
+    "O\xEB\xEC\xED\xEE\xEF",
+    "U\xFB\xFC\xFD\xFE",
+    "Y\xBA",
+    "a\x42\x43\x44\x45\x46\x47",
+    "c\x48",
+    "e\x51\x52\x53\x54",
+    "i\x55\x56\x57\x58",
+    "n\x49",
+    "o\xCB\xCC\xCD\xCE\xCF",
+    "u\xDB\xDC\xDD\xDE",
+    "y\x8D\xDF",
+};
+#endif
+
 /*
  * Produce the bytes for equivalence class "c".
  * Currently only handles latin1, latin9 and utf-8.
@@ -744,6 +768,22 @@
 					 || STRCMP(p_enc, "iso-8859-15") == 0)
 #endif
     {
+#ifdef EBCDIC
+	int i;
+
+	/* This might be slower than switch/case below. */
+	for (i = 0; i < 16; i++)
+	{
+	    if (vim_strchr(EQUIVAL_CLASS_C[i], c) != NULL)
+	    {
+		char *p = EQUIVAL_CLASS_C[i];
+
+		while (*p != 0)
+		    regmbc(*p++);
+		return;
+	    }
+	}
+#else
 	switch (c)
 	{
 	    case 'A': case '\300': case '\301': case '\302':
@@ -811,6 +851,7 @@
 		      regmbc('y'); regmbc('\375'); regmbc('\377');
 		      return;
 	}
+#endif
     }
     regmbc(c);
 }