]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - error.c
Bash-4.3 patch 32
[thirdparty/bash.git] / error.c
diff --git a/error.c b/error.c
index 2ae48543068c97ca2a171577b013d006e657ed93..64c4f411a61dc70f60fdaeaeb33899f7ed10a894 100644 (file)
--- a/error.c
+++ b/error.c
@@ -53,6 +53,7 @@ extern int errno;
 
 extern int executing_line_number __P((void));
 
+extern int last_command_exit_value;
 extern char *shell_name;
 #if defined (JOB_CONTROL)
 extern pid_t shell_pgrp;
@@ -199,7 +200,11 @@ report_error (format, va_alist)
 
   va_end (args);
   if (exit_immediately_on_error)
-    exit_shell (1);
+    {
+      if (last_command_exit_value == 0)
+       last_command_exit_value = 1;
+      exit_shell (last_command_exit_value);
+    }
 }
 
 void
@@ -331,10 +336,40 @@ parser_error (lineno, format, va_alist)
   va_end (args);
 
   if (exit_immediately_on_error)
-    exit_shell (2);
+    exit_shell (last_command_exit_value = 2);
 }
 
 #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, ...)