- QUIT;
-
- if (need_comma)
- {
- obstack_grow_wstr (&wchar_buf, LCST (", "));
- need_comma = 0;
- }
-
- num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
- /* We only look at repetitions when we were able to convert a
- single character in isolation. This makes the code simpler
- and probably does the sensible thing in the majority of
- cases. */
- while (num_chars == 1)
- {
- /* Count the number of repetitions. */
- unsigned int reps = 0;
- gdb_wchar_t current_char = chars[0];
- const gdb_byte *orig_buf = buf;
- int orig_len = buflen;
-
- if (need_comma)
- {
- obstack_grow_wstr (&wchar_buf, LCST (", "));
- need_comma = 0;
- }
-
- while (num_chars == 1 && current_char == chars[0])
- {
- num_chars = wchar_iterate (iter, &result, &chars, &buf, &buflen);
- ++reps;
- }
-
- /* Emit CURRENT_CHAR according to the repetition count and
- options. */
- if (reps > options->repeat_count_threshold)
- {
- if (in_quotes)
- {
- if (options->inspect_it)
- obstack_grow_wstr (&wchar_buf, LCST ("\\\", "));
- else
- obstack_grow_wstr (&wchar_buf, LCST ("\", "));
- in_quotes = 0;
- }
- obstack_grow_wstr (&wchar_buf, LCST ("'"));
- need_escape = 0;
- print_wchar (current_char, orig_buf, orig_len, width,
- &wchar_buf, '\'', &need_escape);
- obstack_grow_wstr (&wchar_buf, LCST ("'"));
- {
- /* Painful gyrations. */
- int j;
- char *s = xstrprintf (_(" <repeats %u times>"), reps);
- for (j = 0; s[j]; ++j)
- {
- gdb_wchar_t w = gdb_btowc (s[j]);
- obstack_grow (&wchar_buf, &w, sizeof (gdb_wchar_t));
- }
- xfree (s);
- }
- things_printed += options->repeat_count_threshold;
- need_comma = 1;
- }
- else
- {
- /* Saw the character one or more times, but fewer than
- the repetition threshold. */
- if (!in_quotes)
- {
- if (options->inspect_it)
- obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
- else
- obstack_grow_wstr (&wchar_buf, LCST ("\""));
- in_quotes = 1;
- need_escape = 0;
- }
-
- while (reps-- > 0)
- {
- print_wchar (current_char, orig_buf, orig_len, width,
- &wchar_buf, '"', &need_escape);
- ++things_printed;
- }
- }
- }
-
- /* NUM_CHARS and the other outputs from wchar_iterate are valid
- here regardless of which branch was taken above. */
- if (num_chars < 0)
- {
- /* Hit EOF. */
- finished = 1;
- break;
- }
-
- switch (result)
- {
- case wchar_iterate_invalid:
- if (!in_quotes)
- {
- if (options->inspect_it)
- obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
- else
- obstack_grow_wstr (&wchar_buf, LCST ("\""));
- in_quotes = 1;
- }
- need_escape = 0;
- print_wchar (gdb_WEOF, buf, buflen, width, &wchar_buf,
- '"', &need_escape);
- break;
-
- case wchar_iterate_incomplete:
- if (in_quotes)
- {
- if (options->inspect_it)
- obstack_grow_wstr (&wchar_buf, LCST ("\\\","));
- else
- obstack_grow_wstr (&wchar_buf, LCST ("\","));
- in_quotes = 0;
- }
- obstack_grow_wstr (&wchar_buf, LCST (" <incomplete sequence "));
- print_wchar (gdb_WEOF, buf, buflen, width, &wchar_buf,
- 0, &need_escape);
- obstack_grow_wstr (&wchar_buf, LCST (">"));
- finished = 1;
- break;
- }
- }
-
- /* Terminate the quotes if necessary. */
- if (in_quotes)
- {
- if (options->inspect_it)
- obstack_grow_wstr (&wchar_buf, LCST ("\\\""));
- else
- obstack_grow_wstr (&wchar_buf, LCST ("\""));
- }
-
- if (force_ellipses || !finished)
- obstack_grow_wstr (&wchar_buf, LCST ("..."));
-
- /* OUTPUT is where we collect `char's for printing. */
- obstack_init (&output);
- make_cleanup_obstack_free (&output);
-
- convert_between_encodings ("wchar_t", host_charset (),
- obstack_base (&wchar_buf),
- obstack_object_size (&wchar_buf),
- 1, &output, translit_char);
- obstack_1grow (&output, '\0');
-
- fputs_filtered (obstack_base (&output), stream);
-
- do_cleanups (cleanup);