#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"
#define ISATTY(FP) (isatty (fileno (FP)))
#endif
-#ifdef MISSING_VPRINTF
-#ifdef __GNU_LIBRARY
-#undef MISSING_VPRINTF
-#else /* !__GNU_LIBRARY */
-
-#ifndef vfprintf
-#define vfprintf(file, format, ap) _doprnt (format, ap, file)
-#endif /* vfprintf */
-
-#ifndef vprintf
-/* Can't #define it since printcmd.c needs it */
-void
-vprintf (format, ap)
- char *format;
- va_list ap;
-{
- vfprintf (stdout, format, ap);
-}
-#endif /* vprintf */
-
-#endif /* GNU_LIBRARY */
-#endif /* MISSING_VPRINTF */
-
-void error ();
-void fatal ();
-
/* Chain of cleanup actions established with make_cleanup,
to be executed if an error happens. */
/* String to be printed before error messages, if any. */
char *error_pre_print;
+char *warning_pre_print;
\f
/* Add a new cleanup to the cleanup_chain,
and return the previous chain pointer
free (*location);
}
\f
+/* 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. */
/* VARARGS */
-void
+volatile void
error (va_alist)
va_dcl
{
va_start (args);
target_terminal_ours ();
+ wrap_here(""); /* Force out any buffered output */
fflush (stdout);
if (error_pre_print)
fprintf (stderr, error_pre_print);
The arguments are printed a la printf. */
/* VARARGS */
-void
+volatile void
fatal (va_alist)
va_dcl
{
return savestring (ptr, strlen (ptr));
}
-char *
-concat (s1, s2, s3)
- char *s1, *s2, *s3;
-{
- register int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
- register char *val = (char *) xmalloc (len);
- strcpy (val, s1);
- strcat (val, s2);
- strcat (val, s3);
- return val;
-}
-
void
print_spaces (n, file)
register int n;
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';
{
register int c = ch;
- if (c < 040 || (sevenbit_strings && c >= 0177))
+ if (c < 040 || (sevenbit_strings && c >= 0177)) {
switch (c)
{
case '\n':
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);
+ }
}
\f
/* Number of lines per page or UINT_MAX if paging is disabled. */
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)
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. */
}
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);
(since prompt_for_continue may do so) so this routine should not be
called when cleanups are not in place. */
-#if !defined(MISSING_VPRINTF) || defined (vsprintf)
/* VARARGS */
void
vfprintf_filtered (stream, format, args)
va_list args;
-#else
-void fprintf_filtered (stream, format, arg1, arg2, arg3, arg4, arg5, arg6)
-#endif
FILE *stream;
char *format;
{
/* This won't blow up if the restrictions described above are
followed. */
-#if !defined(MISSING_VPRINTF) || defined (vsprintf)
(void) vsprintf (linebuffer, format, args);
-#else
- (void) sprintf (linebuffer, format, arg1, arg2, arg3, arg4, arg5, arg6);
-#endif
fputs_filtered (linebuffer, stream);
}
-#if !defined(MISSING_VPRINTF) || defined (vsprintf)
/* VARARGS */
void
fprintf_filtered (va_alist)
(void) vfprintf_filtered (stdout, format, args);
va_end (args);
}
-#else
-void
-printf_filtered (format, arg1, arg2, arg3, arg4, arg5, arg6)
- char *format;
- int arg1, arg2, arg3, arg4, arg5, arg6;
-{
- fprintf_filtered (stdout, format, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-#endif
/* Easy */
}
}
\f
-#if !defined (USG_UTILS)
-#define USG_UTILS defined (USG)
-#endif
-
-#if USG_UTILS
-bcopy (from, to, count)
-char *from, *to;
-{
- memcpy (to, from, count);
-}
-
-bcmp (from, to, count)
-{
- return (memcmp (to, from, count));
-}
-
-bzero (to, count)
-char *to;
-{
- while (count--)
- *to++ = 0;
-}
-
-getwd (buf)
-char *buf;
-{
- getcwd (buf, MAXPATHLEN);
-}
-
-char *
-index (s, c)
- char *s;
-{
- char *strchr ();
- return strchr (s, c);
-}
-
-char *
-rindex (s, c)
- char *s;
-{
- char *strrchr ();
- return strrchr (s, c);
-}
-#endif /* USG_UTILS. */
-
-#if !defined (QUEUE_MISSING)
-#define QUEUE_MISSING defined (USG)
-#endif
-
-#if QUEUE_MISSING
-/* Queue routines */
-
-struct queue {
- struct queue *forw;
- struct queue *back;
-};
-
-insque (item, after)
-struct queue *item;
-struct queue *after;
-{
- item->forw = after->forw;
- after->forw->back = item;
-
- item->back = after;
- after->forw = item;
-}
-
-remque (item)
-struct queue *item;
-{
- item->forw->back = item->back;
- item->back->forw = item->forw;
-}
-#endif /* QUEUE_MISSING */
-\f
-#ifndef HAVE_STRSTR
-/* Simple implementation of strstr, since some implementations lack it. */
-const char *
-strstr (in, find)
- const char *in, *find;
-{
- register const char *p = in - 1;
-
- while (0 != (p = strchr (p+1, *find))) {
- if (strcmp (p, find))
- return p;
- }
- return 0;
-}
-#endif /* do not HAVE_STRSTR */
-\f
void
_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