|
|
ff19ae |
diff --git a/lib/sh/strtrans.c b/lib/sh/strtrans.c
|
|
|
ff19ae |
--- a/lib/sh/strtrans.c
|
|
|
ff19ae |
+++ b/lib/sh/strtrans.c
|
|
|
ff19ae |
@@ -30,6 +30,9 @@
|
|
|
ff19ae |
|
|
|
ff19ae |
#include "shell.h"
|
|
|
ff19ae |
|
|
|
ff19ae |
+#include "shmbchar.h"
|
|
|
ff19ae |
+#include "shmbutil.h"
|
|
|
ff19ae |
+
|
|
|
ff19ae |
#ifdef ESC
|
|
|
ff19ae |
#undef ESC
|
|
|
ff19ae |
#endif
|
|
|
ff19ae |
@@ -74,7 +77,7 @@ ansicstr (string, len, flags, sawc, rlen)
|
|
|
ff19ae |
case 'a': c = '\a'; break;
|
|
|
ff19ae |
case 'v': c = '\v'; break;
|
|
|
ff19ae |
#else
|
|
|
ff19ae |
- case 'a': c = '\007'; break;
|
|
|
ff19ae |
+ case 'a': c = (int) 0x07; break;
|
|
|
ff19ae |
case 'v': c = (int) 0x0B; break;
|
|
|
ff19ae |
#endif
|
|
|
ff19ae |
case 'b': c = '\b'; break;
|
|
|
ff19ae |
@@ -208,6 +211,11 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
char *r, *ret, *s;
|
|
|
ff19ae |
int l, rsize;
|
|
|
ff19ae |
unsigned char c;
|
|
|
ff19ae |
+ size_t clen;
|
|
|
ff19ae |
+ int b;
|
|
|
ff19ae |
+#if defined (HANDLE_MULTIBYTE)
|
|
|
ff19ae |
+ wchar_t wc;
|
|
|
ff19ae |
+#endif
|
|
|
ff19ae |
|
|
|
ff19ae |
if (str == 0 || *str == 0)
|
|
|
ff19ae |
return ((char *)0);
|
|
|
ff19ae |
@@ -219,10 +227,11 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
*r++ = '$';
|
|
|
ff19ae |
*r++ = '\'';
|
|
|
ff19ae |
|
|
|
ff19ae |
- for (s = str, l = 0; *s; s++)
|
|
|
ff19ae |
+ for (s = str; c = *s; s++)
|
|
|
ff19ae |
{
|
|
|
ff19ae |
- c = *s;
|
|
|
ff19ae |
- l = 1; /* 1 == add backslash; 0 == no backslash */
|
|
|
ff19ae |
+ b = l = 1; /* 1 == add backslash; 0 == no backslash */
|
|
|
ff19ae |
+ clen = 1;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
switch (c)
|
|
|
ff19ae |
{
|
|
|
ff19ae |
case ESC: c = 'E'; break;
|
|
|
ff19ae |
@@ -230,7 +239,7 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
case '\a': c = 'a'; break;
|
|
|
ff19ae |
case '\v': c = 'v'; break;
|
|
|
ff19ae |
#else
|
|
|
ff19ae |
- case '\007': c = 'a'; break;
|
|
|
ff19ae |
+ case 0x07: c = 'a'; break;
|
|
|
ff19ae |
case 0x0b: c = 'v'; break;
|
|
|
ff19ae |
#endif
|
|
|
ff19ae |
|
|
|
ff19ae |
@@ -243,7 +252,13 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
case '\'':
|
|
|
ff19ae |
break;
|
|
|
ff19ae |
default:
|
|
|
ff19ae |
+#if defined (HANDLE_MULTIBYTE)
|
|
|
ff19ae |
+ b = is_basic (c);
|
|
|
ff19ae |
+ if ((b == 0 && ((clen = mbrtowc (&wc, s, MB_CUR_MAX, 0)) < 0 || MB_INVALIDCH (clen) || iswprint (wc) == 0)) ||
|
|
|
ff19ae |
+ (b == 1 && ISPRINT (c) == 0))
|
|
|
ff19ae |
+#else
|
|
|
ff19ae |
if (ISPRINT (c) == 0)
|
|
|
ff19ae |
+#endif
|
|
|
ff19ae |
{
|
|
|
ff19ae |
*r++ = '\\';
|
|
|
ff19ae |
*r++ = TOCHAR ((c >> 6) & 07);
|
|
|
ff19ae |
@@ -254,9 +269,20 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
l = 0;
|
|
|
ff19ae |
break;
|
|
|
ff19ae |
}
|
|
|
ff19ae |
+ if (b == 0 && clen == 0)
|
|
|
ff19ae |
+ break;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
if (l)
|
|
|
ff19ae |
*r++ = '\\';
|
|
|
ff19ae |
- *r++ = c;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (clen == 1)
|
|
|
ff19ae |
+ *r++ = c;
|
|
|
ff19ae |
+ else
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ for (b = 0; b < (int)clen; b++)
|
|
|
ff19ae |
+ *r++ = (unsigned char)s[b];
|
|
|
ff19ae |
+ s += clen - 1; /* -1 because of the increment above */
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
}
|
|
|
ff19ae |
|
|
|
ff19ae |
*r++ = '\'';
|
|
|
ff19ae |
@@ -266,6 +292,37 @@ ansic_quote (str, flags, rlen)
|
|
|
ff19ae |
return ret;
|
|
|
ff19ae |
}
|
|
|
ff19ae |
|
|
|
ff19ae |
+#if defined (HANDLE_MULTIBYTE)
|
|
|
ff19ae |
+int
|
|
|
ff19ae |
+ansic_wshouldquote (string)
|
|
|
ff19ae |
+ const char *string;
|
|
|
ff19ae |
+{
|
|
|
ff19ae |
+ const wchar_t *wcs;
|
|
|
ff19ae |
+ wchar_t wcc;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ wchar_t *wcstr = NULL;
|
|
|
ff19ae |
+ size_t slen;
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ slen = mbstowcs (wcstr, string, 0);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ if (slen == -1)
|
|
|
ff19ae |
+ slen = 0;
|
|
|
ff19ae |
+ wcstr = (wchar_t *)xmalloc (sizeof (wchar_t) * (slen + 1));
|
|
|
ff19ae |
+ mbstowcs (wcstr, string, slen + 1);
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ for (wcs = wcstr; wcc = *wcs; wcs++)
|
|
|
ff19ae |
+ if (iswprint(wcc) == 0)
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+ free (wcstr);
|
|
|
ff19ae |
+ return 1;
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
+
|
|
|
ff19ae |
+ free (wcstr);
|
|
|
ff19ae |
+ return 0;
|
|
|
ff19ae |
+}
|
|
|
ff19ae |
+#endif
|
|
|
ff19ae |
+
|
|
|
ff19ae |
/* return 1 if we need to quote with $'...' because of non-printing chars. */
|
|
|
ff19ae |
int
|
|
|
ff19ae |
ansic_shouldquote (string)
|
|
|
ff19ae |
@@ -278,8 +335,14 @@ ansic_shouldquote (string)
|
|
|
ff19ae |
return 0;
|
|
|
ff19ae |
|
|
|
ff19ae |
for (s = string; c = *s; s++)
|
|
|
ff19ae |
- if (ISPRINT (c) == 0)
|
|
|
ff19ae |
- return 1;
|
|
|
ff19ae |
+ {
|
|
|
ff19ae |
+#if defined (HANDLE_MULTIBYTE)
|
|
|
ff19ae |
+ if (is_basic (c) == 0)
|
|
|
ff19ae |
+ return (ansic_wshouldquote (s));
|
|
|
ff19ae |
+#endif
|
|
|
ff19ae |
+ if (ISPRINT (c) == 0)
|
|
|
ff19ae |
+ return 1;
|
|
|
ff19ae |
+ }
|
|
|
ff19ae |
|
|
|
ff19ae |
return 0;
|
|
|
ff19ae |
}
|