diff options
author | Fred Fish <fnf@specifix.com> | 1991-10-24 10:38:56 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1991-10-24 10:38:56 +0000 |
commit | 2bc2e684ad390d727cd9637b59815d12a16fbaf4 (patch) | |
tree | 3c8602a214aecdf661d021015bcffbe6999c1dc2 /gdb | |
parent | eaa1ef1df185459a3bacf9cb5b2cd2cfc10cd8ac (diff) | |
download | gdb-2bc2e684ad390d727cd9637b59815d12a16fbaf4.zip gdb-2bc2e684ad390d727cd9637b59815d12a16fbaf4.tar.gz gdb-2bc2e684ad390d727cd9637b59815d12a16fbaf4.tar.bz2 |
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().
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/utils.c | 102 |
2 files changed, 81 insertions, 28 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6c45b93..01c9d942 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -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 diff --git a/gdb/utils.c b/gdb/utils.c index 98adad0..43b8472 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -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 |