+ output_buffer *buffer = pp->buffer;
+ const char *p;
+ const char **args;
+ struct chunk_info *new_chunk_array;
+
+ unsigned int curarg = 0, chunk = 0, argno;
+ pp_wrapping_mode_t old_wrapping_mode;
+ bool any_unnumbered = false, any_numbered = false;
+ const char **formatters[PP_NL_ARGMAX];
+
+ /* Allocate a new chunk structure. */
+ new_chunk_array = XOBNEW (&buffer->chunk_obstack, struct chunk_info);
+ new_chunk_array->prev = buffer->cur_chunk_array;
+ buffer->cur_chunk_array = new_chunk_array;
+ args = new_chunk_array->args;
+
+ /* Formatting phase 1: split up TEXT->format_spec into chunks in
+ PP->buffer->args[]. Even-numbered chunks are to be output
+ verbatim, odd-numbered chunks are format specifiers.
+ %m, %%, %<, %>, and %' are replaced with the appropriate text at
+ this point. */
+
+ memset (formatters, 0, sizeof formatters);
+
+ for (p = text->format_spec; *p; )
+ {
+ while (*p != '\0' && *p != '%')
+ {
+ obstack_1grow (&buffer->chunk_obstack, *p);
+ p++;
+ }
+
+ if (*p == '\0')
+ break;
+
+ switch (*++p)
+ {
+ case '\0':
+ gcc_unreachable ();
+
+ case '%':
+ obstack_1grow (&buffer->chunk_obstack, '%');
+ p++;
+ continue;
+
+ case '<':
+ obstack_grow (&buffer->chunk_obstack,
+ open_quote, strlen (open_quote));
+ p++;
+ continue;
+
+ case '>':
+ case '\'':
+ obstack_grow (&buffer->chunk_obstack,
+ close_quote, strlen (close_quote));
+ p++;
+ continue;
+
+ case 'm':
+ {
+ const char *errstr = xstrerror (text->err_no);
+ obstack_grow (&buffer->chunk_obstack, errstr, strlen (errstr));
+ }
+ p++;
+ continue;
+
+ default:
+ /* Handled in phase 2. Terminate the plain chunk here. */
+ obstack_1grow (&buffer->chunk_obstack, '\0');
+ gcc_assert (chunk < PP_NL_ARGMAX * 2);
+ args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+ break;
+ }
+
+ if (ISDIGIT (*p))
+ {
+ char *end;
+ argno = strtoul (p, &end, 10) - 1;
+ p = end;
+ gcc_assert (*p == '$');
+ p++;
+
+ any_numbered = true;
+ gcc_assert (!any_unnumbered);
+ }
+ else
+ {
+ argno = curarg++;
+ any_unnumbered = true;
+ gcc_assert (!any_numbered);
+ }
+ gcc_assert (argno < PP_NL_ARGMAX);
+ gcc_assert (!formatters[argno]);
+ formatters[argno] = &args[chunk];
+ do
+ {
+ obstack_1grow (&buffer->chunk_obstack, *p);
+ p++;
+ }
+ while (strchr ("qwl+#", p[-1]));
+
+ if (p[-1] == '.')
+ {
+ /* We handle '%.Ns' and '%.*s' or '%M$.*N$s'
+ (where M == N + 1). */
+ if (ISDIGIT (*p))
+ {
+ do
+ {
+ obstack_1grow (&buffer->chunk_obstack, *p);
+ p++;
+ }
+ while (ISDIGIT (p[-1]));
+ gcc_assert (p[-1] == 's');
+ }
+ else
+ {
+ gcc_assert (*p == '*');
+ obstack_1grow (&buffer->chunk_obstack, '*');
+ p++;
+
+ if (ISDIGIT (*p))
+ {
+ char *end;
+ unsigned int argno2 = strtoul (p, &end, 10) - 1;
+ p = end;
+ gcc_assert (argno2 == argno - 1);
+ gcc_assert (!any_unnumbered);
+ gcc_assert (*p == '$');
+
+ p++;
+ formatters[argno2] = formatters[argno];
+ }
+ else
+ {
+ gcc_assert (!any_numbered);
+ formatters[argno+1] = formatters[argno];
+ curarg++;
+ }
+ gcc_assert (*p == 's');
+ obstack_1grow (&buffer->chunk_obstack, 's');
+ p++;
+ }
+ }
+ if (*p == '\0')
+ break;
+
+ obstack_1grow (&buffer->chunk_obstack, '\0');
+ gcc_assert (chunk < PP_NL_ARGMAX * 2);
+ args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+ }
+
+ obstack_1grow (&buffer->chunk_obstack, '\0');
+ gcc_assert (chunk < PP_NL_ARGMAX * 2);
+ args[chunk++] = XOBFINISH (&buffer->chunk_obstack, const char *);
+ args[chunk] = 0;
+
+ /* Set output to the argument obstack, and switch line-wrapping and
+ prefixing off. */
+ buffer->obstack = &buffer->chunk_obstack;
+ old_wrapping_mode = pp_set_verbatim_wrapping (pp);
+
+ /* Second phase. Replace each formatter with the formatted text it
+ corresponds to. */
+
+ for (argno = 0; formatters[argno]; argno++)