/* 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.
- Bash is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
+ Bash is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- Bash is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
+ Bash is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with Bash; see the file COPYING. If not, write to the Free Software
- Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bash. If not, see <http://www.gnu.org/licenses/>.
+*/
#include "config.h"
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;
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
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, ...)