-/* Return true if print_wchar can display W without resorting to a
- numeric escape, false otherwise. */
-
-static int
-wchar_printable (gdb_wchar_t w)
-{
- return (gdb_iswprint (w)
- || w == LCST ('\a') || w == LCST ('\b')
- || w == LCST ('\f') || w == LCST ('\n')
- || w == LCST ('\r') || w == LCST ('\t')
- || w == LCST ('\v'));
-}
-
-/* A helper function that converts the contents of STRING to wide
- characters and then appends them to OUTPUT. */
-
-static void
-append_string_as_wide (const char *string, struct obstack *output)
-{
- for (; *string; ++string)
- {
- gdb_wchar_t w = gdb_btowc (*string);
- obstack_grow (output, &w, sizeof (gdb_wchar_t));
- }
-}
-
-/* Print a wide character W to OUTPUT. ORIG is a pointer to the
- original (target) bytes representing the character, ORIG_LEN is the
- number of valid bytes. WIDTH is the number of bytes in a base
- characters of the type. OUTPUT is an obstack to which wide
- characters are emitted. QUOTER is a (narrow) character indicating
- the style of quotes surrounding the character to be printed.
- NEED_ESCAPE is an in/out flag which is used to track numeric
- escapes across calls. */
-
-static void
-print_wchar (gdb_wint_t w, const gdb_byte *orig, int orig_len,
- int width, enum bfd_endian byte_order, struct obstack *output,
- int quoter, int *need_escapep)
-{
- int need_escape = *need_escapep;
- *need_escapep = 0;
- if (gdb_iswprint (w) && (!need_escape || (!gdb_iswdigit (w)
- && w != LCST ('8')
- && w != LCST ('9'))))
- {
- gdb_wchar_t wchar = w;
-
- if (w == gdb_btowc (quoter) || w == LCST ('\\'))
- obstack_grow_wstr (output, LCST ("\\"));
- obstack_grow (output, &wchar, sizeof (gdb_wchar_t));
- }
- else
- {
- switch (w)
- {
- case LCST ('\a'):
- obstack_grow_wstr (output, LCST ("\\a"));
- break;
- case LCST ('\b'):
- obstack_grow_wstr (output, LCST ("\\b"));
- break;
- case LCST ('\f'):
- obstack_grow_wstr (output, LCST ("\\f"));
- break;
- case LCST ('\n'):
- obstack_grow_wstr (output, LCST ("\\n"));
- break;
- case LCST ('\r'):
- obstack_grow_wstr (output, LCST ("\\r"));
- break;
- case LCST ('\t'):
- obstack_grow_wstr (output, LCST ("\\t"));
- break;
- case LCST ('\v'):
- obstack_grow_wstr (output, LCST ("\\v"));
- break;
- default:
- {
- int i;
-
- for (i = 0; i + width <= orig_len; i += width)
- {
- char octal[30];
- ULONGEST value;
- value = extract_unsigned_integer (&orig[i], width, byte_order);
- /* If the value fits in 3 octal digits, print it that
- way. Otherwise, print it as a hex escape. */
- if (value <= 0777)
- sprintf (octal, "\\%.3o", (int) (value & 0777));
- else
- sprintf (octal, "\\x%lx", (long) value);
- append_string_as_wide (octal, output);
- }
- /* If we somehow have extra bytes, print them now. */
- while (i < orig_len)
- {
- char octal[5];
- sprintf (octal, "\\%.3o", orig[i] & 0xff);
- append_string_as_wide (octal, output);
- ++i;
- }
-
- *need_escapep = 1;
- }
- break;
- }
- }
-}
-
-/* Print the character C on STREAM as part of the contents of a literal
- string whose delimiter is QUOTER. Note that that format for printing
- characters and strings is language specific. */