Bash-4.3 distribution sources and documentation
[platform/upstream/bash.git] / error.c
diff --git a/error.c b/error.c
index 1eac01c..64c4f41 100644 (file)
--- a/error.c
+++ b/error.c
@@ -340,6 +340,36 @@ parser_error (lineno, format, va_alist)
 }
 
 #ifdef DEBUG
+/* This assumes ASCII and is suitable only for debugging */
+char *
+strescape (str)
+     const char *str;
+{
+  char *r, *result;
+  unsigned char *s;
+
+  r = result = (char *)xmalloc (strlen (str) * 2 + 1);
+
+  for (s = (unsigned char *)str; s && *s; s++)
+    {
+      if (*s < ' ')
+       {
+         *r++ = '^';
+         *r++ = *s+64;
+       }
+      else if (*s == 127)
+       {
+         *r++ = '^';
+         *r++ = '?';
+       }
+     else
+       *r++ = *s;
+    }
+
+  *r = '\0';
+  return result;
+}
+
 void
 #if defined (PREFER_STDARG)
 itrace (const char *format, ...)