]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - error.c
bash-20141003 remove leftover and stray files
[thirdparty/bash.git] / error.c
diff --git a/error.c b/error.c
index 39f562b5dab55712baa78952d6bd8bc7d0408437..64c4f411a61dc70f60fdaeaeb33899f7ed10a894 100644 (file)
--- a/error.c
+++ b/error.c
@@ -1,6 +1,6 @@
 /* error.c -- Functions for handling errors. */
 
-/* Copyright (C) 1993-2008 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -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, ...)