From 2cb0ea982aa271c4753a57b80337f970d48dcbd5 Mon Sep 17 00:00:00 2001
From: tg <tg@mirbsd.org>
Date: Wed, 29 Apr 2015 18:38:54 +0000
Subject: [PATCH] EBCDIC helpers and OS/390 signals

---
 Build.sh |  4 ++--
 misc.c   |  8 ++++----
 sh.h     |  3 ++-
 var.c    | 14 +++++++-------
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/Build.sh b/Build.sh
index ffbb98d..0284fdb 100644
--- a/Build.sh
+++ b/Build.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.674 2015/04/19 18:50:35 tg Exp $'
+srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.675 2015/04/29 18:38:50 tg Exp $'
 #-
 # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
 #		2011, 2012, 2013, 2014, 2015
@@ -2284,7 +2284,7 @@ mksh_cfg= NSIG
 	sigs="ABRT FPE ILL INT SEGV TERM ALRM BUS CHLD CONT HUP KILL PIPE QUIT"
 	sigs="$sigs STOP TSTP TTIN TTOU USR1 USR2 POLL PROF SYS TRAP URG VTALRM"
 	sigs="$sigs XCPU XFSZ INFO WINCH EMT IO DIL LOST PWR SAK CLD IOT RESV"
-	sigs="$sigs STKFLT UNUSED"
+	sigs="$sigs STKFLT ABND DCE DUMP IOERR TRACE DANGER UNUSED"
 	test 1 = $HAVE_CPP_DD && test $NSIG -gt 1 && sigs="$sigs "`vq \
 	    "$CPP $CFLAGS $CPPFLAGS $NOWARN -dD conftest.c" | \
 	    grep '[	 ]SIG[A-Z0-9][A-Z0-9]*[	 ]' | \
diff --git a/misc.c b/misc.c
index 763d861..0a13f99 100644
--- a/misc.c
+++ b/misc.c
@@ -30,7 +30,7 @@
 #include <grp.h>
 #endif
 
-__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.227 2015/04/29 18:32:44 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.228 2015/04/29 18:38:52 tg Exp $");
 
 #define KSH_CHVT_FLAG
 #ifdef MKSH_SMALL
@@ -52,7 +52,7 @@ static const unsigned char *pat_scan(const unsigned char *,
     const unsigned char *, bool) MKSH_A_PURE;
 static int do_gmatch(const unsigned char *, const unsigned char *,
     const unsigned char *, const unsigned char *) MKSH_A_PURE;
-static const unsigned char *cclass(const unsigned char *, unsigned char)
+static const unsigned char *gmatch_cclass(const unsigned char *, unsigned char)
     MKSH_A_PURE;
 #ifdef KSH_CHVT_CODE
 static void chvt(const Getopt *);
@@ -776,7 +776,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
 		}
 		switch (*p++) {
 		case '[':
-			if (sc == 0 || (p = cclass(p, sc)) == NULL)
+			if (sc == 0 || (p = gmatch_cclass(p, sc)) == NULL)
 				return (0);
 			break;
 
@@ -889,7 +889,7 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
 }
 
 static const unsigned char *
-cclass(const unsigned char *p, unsigned char sub)
+gmatch_cclass(const unsigned char *p, unsigned char sub)
 {
 	unsigned char c, d;
 	bool notp, found = false;
diff --git a/sh.h b/sh.h
index 453de5a..367959d 100644
--- a/sh.h
+++ b/sh.h
@@ -169,7 +169,7 @@
 #endif
 
 #ifdef EXTERN
-__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.725 2015/04/19 19:18:07 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.726 2015/04/29 18:38:54 tg Exp $");
 #endif
 #define MKSH_VERSION "R51 2015/04/19"
 
@@ -305,6 +305,7 @@ struct rusage {
 #define ksh_toupper(c)	(((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
 #define ksh_isdash(s)	(((s)[0] == '-') && ((s)[1] == '\0'))
 #define ksh_isspace(c)	((((c) >= 0x09) && ((c) <= 0x0D)) || ((c) == 0x20))
+#define ksh_eq(c,u,l)	(((c) | 0x20) == (l))
 #define ksh_min(x,y)	((x) < (y) ? (x) : (y))
 #define ksh_max(x,y)	((x) > (y) ? (x) : (y))
 
diff --git a/var.c b/var.c
index c769144..e230db9 100644
--- a/var.c
+++ b/var.c
@@ -28,7 +28,7 @@
 #include <sys/sysctl.h>
 #endif
 
-__RCSID("$MirOS: src/bin/mksh/var.c,v 1.190 2015/04/19 18:50:38 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/var.c,v 1.191 2015/04/29 18:38:54 tg Exp $");
 
 /*-
  * Variables
@@ -510,7 +510,7 @@ getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
 	}
 
 	if (c == '0' && arith) {
-		if ((s[0] | 0x20) == 'x') {
+		if (ksh_eq(s[0], 'X', 'x')) {
 			/* interpret as hexadecimal */
 			base = 16;
 			++s;
@@ -554,12 +554,12 @@ getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
 		}
 		if (ksh_isdigit(c))
 			c -= '0';
-		else {
-			c |= 0x20;
-			if (!ksh_islower(c))
-				return (-1);
+		else if (ksh_isupper(c))
+			c -= 'A' - 10;
+		else if (ksh_islower(c))
 			c -= 'a' - 10;
-		}
+		else
+			return (-1);
 		if (c >= base)
 			return (-1);
 		/* handle overflow as truncation */