+/* Print character CH to the stdio stream STREAM. */
+
+static void
+printchar_to_stream (unsigned int ch, FILE *stream)
+{
+ Lisp_Object dv IF_LINT (= Qnil);
+ ptrdiff_t i = 0, n = 1;
+
+ if (CHAR_VALID_P (ch) && DISP_TABLE_P (Vstandard_display_table))
+ {
+ dv = DISP_CHAR_VECTOR (XCHAR_TABLE (Vstandard_display_table), ch);
+ if (VECTORP (dv))
+ {
+ n = ASIZE (dv);
+ goto next_char;
+ }
+ }
+
+ while (true)
+ {
+ if (ASCII_CHAR_P (ch))
+ {
+ putc (ch, stream);
+#ifdef WINDOWSNT
+ /* Send the output to a debugger (nothing happens if there
+ isn't one). */
+ if (print_output_debug_flag && stream == stderr)
+ OutputDebugString ((char []) {ch, '\0'});
+#endif
+ }
+ else
+ {
+ unsigned char mbstr[MAX_MULTIBYTE_LENGTH];
+ int len = CHAR_STRING (ch, mbstr);
+ Lisp_Object encoded_ch =
+ ENCODE_SYSTEM (make_multibyte_string ((char *) mbstr, 1, len));
+
+ fwrite (SSDATA (encoded_ch), 1, SBYTES (encoded_ch), stream);
+#ifdef WINDOWSNT
+ if (print_output_debug_flag && stream == stderr)
+ OutputDebugString (SSDATA (encoded_ch));
+#endif
+ }
+
+ i++;
+
+ next_char:
+ for (; i < n; i++)
+ if (CHARACTERP (AREF (dv, i)))
+ break;
+ if (! (i < n))
+ break;
+ ch = XFASTINT (AREF (dv, i));
+ }
+}