File tcsh-6.18.01-SJIS.patch of Package tcsh.12475

---
 sh.c       |   41 ++++++++++++++++++++++++++++++++++++++++-
 sh.decls.h |    4 ++++
 sh.func.c  |    2 ++
 sh.set.c   |   11 +++++++++++
 tc.str.c   |    8 ++++++++
 5 files changed, 65 insertions(+), 1 deletion(-)

--- sh.c
+++ sh.c	2017-12-12 13:08:52.253207919 +0000
@@ -250,6 +250,7 @@ main(int argc, char **argv)
     char **tempv;
     int osetintr;
     struct sigaction oparintr;
+    const char *cmd = NULL;
 
     (void)memset(&reslab, 0, sizeof(reslab));
 #ifdef WINNT_NATIVE
@@ -262,6 +263,7 @@ main(int argc, char **argv)
 #ifdef NLS
 # ifdef LC_CTYPE
     (void) setlocale(LC_CTYPE, ""); /* for iscntrl */
+    autoset_sjis();
 # endif /* LC_CTYPE */
 #endif /* NLS */
 
@@ -925,6 +927,13 @@ main(int argc, char **argv)
 #endif
 		arginp = SAVE(tempv[0]);
 
+		if (shiftjis) {
+		    cmd = tempv[0];
+		    prompt = 0;
+		    nofile = 1;
+		    break;
+		}
+
 		/*
 		 * we put the command into a variable
 		 */
@@ -1401,7 +1410,37 @@ main(int argc, char **argv)
 	setNS(STRverbose);
     if (nexececho)
 	setNS(STRecho);
-    
+
+    if (cmd != NULL) {
+	if (arginp != NULL) {
+	    xfree(arginp);
+	    arginp = SAVE(cmd);
+	}
+
+	/*
+	 * we put the command into a variable
+	 */
+	if (arginp != NULL)
+	    setv(STRcommand, quote(Strsave(arginp)), VAR_READWRITE);
+
+	/*
+	 * * Give an error on -c arguments that end in * backslash to
+	 * ensure that you don't make * nonportable csh scripts.
+	 */
+	{
+	    int count;
+
+	    cp = Strend(arginp);
+	    count = 0;
+	    while (cp > arginp && *--cp == '\\')
+		++count;
+	    if ((count & 1) != 0) {
+		exiterr = 1;
+		stderror(ERR_ARGC);
+	    }
+	}
+    }
+
     /*
      * All the rest of the world is inside this call. The argument to process
      * indicates whether it should catch "error unwinds".  Thus if we are a
--- sh.decls.h
+++ sh.decls.h	2017-12-12 12:54:35.841788967 +0000
@@ -399,6 +399,10 @@ extern	void		  autoset_dspmbyte	(const C
 #if defined(AUTOSET_KANJI)
 extern	void		  autoset_kanji	(void);
 #endif
+#if defined(NLS) && defined(LC_CTYPE)
+extern	void		  autoset_sjis	(void);
+extern	int		  shiftjis;
+#endif
 
 /*
  * sh.time.c
--- sh.func.c
+++ sh.func.c	2017-12-12 13:02:38.464241737 +0000
@@ -1419,6 +1419,7 @@ dosetenv(Char **v, struct command *c)
 # endif
 # ifdef LC_CTYPE
 	(void) setlocale(LC_CTYPE, ""); /* for iscntrl */
+	autoset_sjis();
 # endif /* LC_CTYPE */
 # if defined(AUTOSET_KANJI)
         autoset_kanji();
@@ -1632,6 +1633,7 @@ dounsetenv(Char **v, struct command *c)
 # endif
 # ifdef LC_CTYPE
 		    (void) setlocale(LC_CTYPE, ""); /* for iscntrl */
+		    autoset_sjis();
 # endif /* LC_CTYPE */
 # ifdef NLS_CATALOGS
 #  ifdef LC_MESSAGES
--- sh.set.c
+++ sh.set.c	2017-12-12 13:00:22.366800676 +0000
@@ -1305,5 +1305,16 @@ autoset_kanji(void)
     if (adrof(STRnokanji) != NULL)
 	unsetv(STRnokanji);
 }
+#else
+int shiftjis = 0;
+void
+autoset_sjis(void)
+{
+    char *codeset = nl_langinfo(CODESET);
+    if (strcasestr (codeset, "JIS") != 0 && MB_CUR_MAX == 2)
+	shiftjis = 1;
+    else
+	shiftjis = 0;
+}
 #endif
 #endif
--- tc.str.c
+++ tc.str.c	2017-12-12 13:25:46.234095792 +0000
@@ -136,6 +136,14 @@ rt_mbtowc(Char *pwc, const char *s, size
 		ret += n2;
 	    }
 	} else
+#else
+	if (shiftjis)
+	    /* Special case for Shift-JIS, so the output is always
+	       ASCII-compatible.  */
+	    if (ret == 1 && 0x00 <= *s && *s <= 0x7F && *pwc != *s) {
+		*pwc = *s;
+		return ret;
+	    }
 #endif
       	if (wctomb(back, *pwc) != ret || memcmp(s, back, ret) != 0)
 	    ret = -1;
openSUSE Build Service is sponsored by