+ if (*format++ == '%')
+ {
+ *p++ = '%';
+ nchars++;
+ continue;
+ }
+
+ ++n;
+
+ if (STRINGP (args[n]))
+ {
+ int padding, nbytes;
+
+ nbytes = copy_text (XSTRING (args[n])->data, p,
+ XSTRING (args[n])->size_byte,
+ STRING_MULTIBYTE (args[n]), multibyte);
+ p += nbytes;
+ nchars += XSTRING (args[n])->size;
+
+ /* If spec requires it, pad on right with spaces. */
+ padding = minlen - XSTRING (args[n])->size;
+ while (padding-- > 0)
+ {
+ *p++ = ' ';
+ nchars++;
+ }
+ }
+ else if (INTEGERP (args[n]) || FLOATP (args[n]))
+ {
+ int this_nchars;
+
+ bcopy (this_format_start, this_format,
+ format - this_format_start);
+ this_format[format - this_format_start] = 0;
+
+ sprintf (p, this_format, XINT (args[n]));
+
+ this_nchars = strlen (p);
+ p += this_nchars;
+ nchars += this_nchars;
+ }
+ }
+ else if (STRING_MULTIBYTE (args[0]))
+ {
+ /* Copy a whole multibyte character. */
+ *p++ = *format++;
+ while (! CHAR_HEAD_P (*format)) *p++ = *format++;
+ nchars++;
+ }
+ else if (multibyte)
+ {
+ /* Convert a single-byte character to multibyte. */
+ int len = copy_text (format, p, 1, 0, 1);
+
+ p += len;
+ format++;
+ nchars++;
+ }
+ else
+ *p++ = *format++, nchars++;
+ }
+
+ val = make_multibyte_string (buf, nchars, p - buf);
+
+ /* If we allocated BUF with malloc, free it too. */
+ if (total >= 1000)
+ xfree (buf);
+
+ return val;