Add new function warning() which behaves the same as error() but returns

rather than jumping back to command level.  Modules that want to print
their own warnings without calling warning() can call warning_setup() to
handle the terminal compatibly with warning() and error().
This commit is contained in:
Fred Fish 1991-10-24 10:38:56 +00:00
parent eaa1ef1df1
commit 2bc2e684ad
2 changed files with 81 additions and 28 deletions

View file

@ -1,5 +1,12 @@
Thu Oct 24 01:32:51 1991 Fred Fish (fnf at cygnus.com)
* utils.c: Add warning_setup() and warning(). Warning() behaves
the same as error() except that it returns normally rather than
jumping back to command level. Modules that don't want to call
warning() for some reason, but want to produce their own warnings,
can call warning_setup() to ensure compatibility with the way
warning() and error() deal with the terminal.
* symtab.c: Make internal errors produce more useful messages.
* tm-68k.h: Move code that is duplicated in almost every single

View file

@ -21,14 +21,15 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <sys/ioctl.h>
#include <sys/param.h>
#include <pwd.h>
#include <varargs.h>
#include <ctype.h>
#include <string.h>
#include "defs.h"
#include "param.h"
#include "signals.h"
#include "gdbcmd.h"
#include "terminal.h"
#include <varargs.h>
#include <ctype.h>
#include <string.h>
#include "bfd.h"
#include "target.h"
@ -51,7 +52,15 @@ extern char *realloc();
#else /* !__GNU_LIBRARY */
#ifndef vfprintf
#define vfprintf(file, format, ap) _doprnt (format, ap, file)
/* Can't #define it since language.c needs it (though FIXME it shouldn't) */
void
vfprintf (file, format, ap)
FILE *file;
char *format;
va_list ap;
{
_doprnt (format, ap, file);
}
#endif /* vfprintf */
#ifndef vprintf
@ -105,6 +114,7 @@ int sevenbit_strings = 0;
/* String to be printed before error messages, if any. */
char *error_pre_print;
char *warning_pre_print;
/* Add a new cleanup to the cleanup_chain,
and return the previous chain pointer
@ -192,6 +202,44 @@ free_current_contents (location)
free (*location);
}
/* Provide a hook for modules wishing to print their own warning messages
to set up the terminal state in a compatible way, without them having
to import all the target_<...> macros. */
void
warning_setup ()
{
target_terminal_ours ();
wrap_here(""); /* Force out any buffered output */
fflush (stdout);
}
/* Print a warning message.
The first argument STRING is the warning message, used as a fprintf string,
and the remaining args are passed as arguments to it.
The primary difference between warnings and errors is that a warning
does not force the return to command level. */
/* VARARGS */
void
warning (va_alist)
va_dcl
{
va_list args;
char *string;
va_start (args);
target_terminal_ours ();
wrap_here(""); /* Force out any buffered output */
fflush (stdout);
if (warning_pre_print)
fprintf (stderr, warning_pre_print);
string = va_arg (args, char *);
vfprintf (stderr, string, args);
fprintf (stderr, "\n");
va_end (args);
}
/* Print an error message and return to command level.
The first argument STRING is the error message, used as a fprintf string,
and the remaining args are passed as arguments to it. */
@ -206,6 +254,7 @@ error (va_alist)
va_start (args);
target_terminal_ours ();
wrap_here(""); /* Force out any buffered output */
fflush (stdout);
if (error_pre_print)
fprintf (stderr, error_pre_print);
@ -558,10 +607,10 @@ parse_escape (string_ptr)
switch (c)
{
case 'a':
return '\a';
return 007; /* Bell (alert) char */
case 'b':
return '\b';
case 'e':
case 'e': /* Escape character */
return 033;
case 'f':
return '\f';
@ -628,7 +677,7 @@ printchar (ch, stream, quoter)
{
register int c = ch;
if (c < 040 || (sevenbit_strings && c >= 0177))
if (c < 040 || (sevenbit_strings && c >= 0177)) {
switch (c)
{
case '\n':
@ -656,12 +705,11 @@ printchar (ch, stream, quoter)
fprintf_filtered (stream, "\\%.3o", (unsigned int) c);
break;
}
else
{
if (c == '\\' || c == quoter)
fputs_filtered ("\\", stream);
fprintf_filtered (stream, "%c", c);
}
} else {
if (c == '\\' || c == quoter)
fputs_filtered ("\\", stream);
fprintf_filtered (stream, "%c", c);
}
}
/* Number of lines per page or UINT_MAX if paging is disabled. */
@ -690,20 +738,6 @@ static unsigned int lines_printed, chars_printed;
static char *wrap_buffer, *wrap_pointer, *wrap_indent;
static int wrap_column;
/* Get the number of lines to print with commands like "list".
This is based on guessing how many long (i.e. more than chars_per_line
characters) lines there will be. To be completely correct, "list"
and friends should be rewritten to count characters and see where
things are wrapping, but that would be a fair amount of work. */
int
lines_to_list ()
{
/* RMS didn't like the following algorithm. Let's set it back to
10 and see if anyone else complains. */
/* return lines_per_page == UINT_MAX ? 10 : lines_per_page / 2; */
return 10;
}
/* ARGSUSED */
static void
set_width_command (args, from_tty, c)
@ -754,6 +788,10 @@ reinitialize_more_filter ()
If the line is already overfull, we immediately print a newline and
the indentation, and disable further wrapping.
If we don't know the width of lines, but we know the page height,
we must not wrap words, but should still keep track of newlines
that were explicitly printed.
INDENT should not contain tabs, as that
will mess up the char count on the next line. FIXME. */
@ -768,7 +806,11 @@ wrap_here(indent)
}
wrap_pointer = wrap_buffer;
wrap_buffer[0] = '\0';
if (chars_printed >= chars_per_line)
if (chars_per_line == UINT_MAX) /* No line overflow checking */
{
wrap_column = 0;
}
else if (chars_printed >= chars_per_line)
{
puts_filtered ("\n");
puts_filtered (indent);
@ -1291,6 +1333,10 @@ _initialize_utils ()
}
}
/* If the output is not a terminal, don't paginate it. */
if (!ISATTY (stdout))
lines_per_page = UINT_MAX;
set_width_command ((char *)NULL, 0, c);
add_show_from_set