home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / e20313sr.zip / emacs / 20.3.1 / src / print.c < prev    next >
C/C++ Source or Header  |  1999-07-31  |  55KB  |  1,919 lines

  1. /* Lisp object printing and output streams.
  2.    Copyright (C) 1985, 86, 88, 93, 94, 95, 97, 1998
  3.     Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU Emacs.
  6.  
  7. GNU Emacs is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU Emacs is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU Emacs; see the file COPYING.  If not, write to
  19. the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22.  
  23. #include <config.h>
  24. #include <stdio.h>
  25. #include "lisp.h"
  26.  
  27. #ifndef standalone
  28. #include "buffer.h"
  29. #include "charset.h"
  30. #include "frame.h"
  31. #include "window.h"
  32. #include "process.h"
  33. #include "dispextern.h"
  34. #include "termchar.h"
  35. #include "keyboard.h"
  36. #endif /* not standalone */
  37.  
  38. #ifdef USE_TEXT_PROPERTIES
  39. #include "intervals.h"
  40. #endif
  41.  
  42. Lisp_Object Vstandard_output, Qstandard_output;
  43.  
  44. /* These are used to print like we read.  */
  45. extern Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
  46.  
  47. #ifdef LISP_FLOAT_TYPE
  48. Lisp_Object Vfloat_output_format, Qfloat_output_format;
  49.  
  50. /* Work around a problem that happens because math.h on hpux 7
  51.    defines two static variables--which, in Emacs, are not really static,
  52.    because `static' is defined as nothing.  The problem is that they are
  53.    defined both here and in lread.c.
  54.    These macros prevent the name conflict.  */
  55. #if defined (HPUX) && !defined (HPUX8)
  56. #define _MAXLDBL print_maxldbl
  57. #define _NMAXLDBL print_nmaxldbl
  58. #endif
  59.  
  60. #include <math.h>
  61.  
  62. #if STDC_HEADERS
  63. #include <float.h>
  64. #include <stdlib.h>
  65. #endif
  66.  
  67. /* Default to values appropriate for IEEE floating point.  */
  68. #ifndef FLT_RADIX
  69. #define FLT_RADIX 2
  70. #endif
  71. #ifndef DBL_MANT_DIG
  72. #define DBL_MANT_DIG 53
  73. #endif
  74. #ifndef DBL_DIG
  75. #define DBL_DIG 15
  76. #endif
  77. #ifndef DBL_MIN
  78. #define DBL_MIN 2.2250738585072014e-308
  79. #endif
  80.  
  81. #ifdef DBL_MIN_REPLACEMENT
  82. #undef DBL_MIN
  83. #define DBL_MIN DBL_MIN_REPLACEMENT
  84. #endif
  85.  
  86. /* Define DOUBLE_DIGITS_BOUND, an upper bound on the number of decimal digits
  87.    needed to express a float without losing information.
  88.    The general-case formula is valid for the usual case, IEEE floating point,
  89.    but many compilers can't optimize the formula to an integer constant,
  90.    so make a special case for it.  */
  91. #if FLT_RADIX == 2 && DBL_MANT_DIG == 53
  92. #define DOUBLE_DIGITS_BOUND 17 /* IEEE floating point */
  93. #else
  94. #define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG))))
  95. #endif
  96.  
  97. #endif /* LISP_FLOAT_TYPE */
  98.  
  99. /* Avoid actual stack overflow in print.  */
  100. int print_depth;
  101.  
  102. /* Detect most circularities to print finite output.  */
  103. #define PRINT_CIRCLE 200
  104. Lisp_Object being_printed[PRINT_CIRCLE];
  105.  
  106. /* When printing into a buffer, first we put the text in this
  107.    block, then insert it all at once.  */
  108. char *print_buffer;
  109.  
  110. /* Size allocated in print_buffer.  */
  111. int print_buffer_size;
  112. /* Chars stored in print_buffer.  */
  113. int print_buffer_pos;
  114. /* Bytes stored in print_buffer.  */
  115. int print_buffer_pos_byte;
  116.  
  117. /* Maximum length of list to print in full; noninteger means
  118.    effectively infinity */
  119.  
  120. Lisp_Object Vprint_length;
  121.  
  122. /* Maximum depth of list to print in full; noninteger means
  123.    effectively infinity.  */
  124.  
  125. Lisp_Object Vprint_level;
  126.  
  127. /* Nonzero means print newlines in strings as \n.  */
  128.  
  129. int print_escape_newlines;
  130.  
  131. /* Nonzero means to print single-byte non-ascii characters in strings as
  132.    octal escapes.  */
  133.  
  134. int print_escape_nonascii;
  135.  
  136. /* Nonzero means to print multibyte characters in strings as hex escapes.  */
  137.  
  138. int print_escape_multibyte;
  139.  
  140. Lisp_Object Qprint_escape_newlines;
  141. Lisp_Object Qprint_escape_multibyte, Qprint_escape_nonascii;
  142.  
  143. /* Nonzero means print (quote foo) forms as 'foo, etc.  */
  144.  
  145. int print_quoted;
  146.  
  147. /* Non-nil means print #: before uninterned symbols.
  148.    Neither t nor nil means so that and don't clear Vprint_gensym_alist
  149.    on entry to and exit from print functions.  */
  150.  
  151. Lisp_Object Vprint_gensym;
  152.  
  153. /* Association list of certain objects that are `eq' in the form being
  154.    printed and which should be `eq' when read back in, using the #n=object
  155.    and #n# reader forms.  Each element has the form (object . n).  */
  156.  
  157. Lisp_Object Vprint_gensym_alist;
  158.  
  159. /* Nonzero means print newline to stdout before next minibuffer message.
  160.    Defined in xdisp.c */
  161.  
  162. extern int noninteractive_need_newline;
  163.  
  164. extern int minibuffer_auto_raise;
  165.  
  166. #ifdef MAX_PRINT_CHARS
  167. static int print_chars;
  168. static int max_print;
  169. #endif /* MAX_PRINT_CHARS */
  170.  
  171. void print_interval ();
  172.  
  173. #if 0
  174. /* Convert between chars and GLYPHs */
  175.  
  176. int
  177. glyphlen (glyphs)
  178.      register GLYPH *glyphs;
  179. {
  180.   register int i = 0;
  181.  
  182.   while (glyphs[i])
  183.     i++;
  184.   return i;
  185. }
  186.  
  187. void
  188. str_to_glyph_cpy (str, glyphs)
  189.      char *str;
  190.      GLYPH *glyphs;
  191. {
  192.   register GLYPH *gp = glyphs;
  193.   register char *cp = str;
  194.  
  195.   while (*cp)
  196.     *gp++ = *cp++;
  197. }
  198.  
  199. void
  200. str_to_glyph_ncpy (str, glyphs, n)
  201.      char *str;
  202.      GLYPH *glyphs;
  203.      register int n;
  204. {
  205.   register GLYPH *gp = glyphs;
  206.   register char *cp = str;
  207.  
  208.   while (n-- > 0)
  209.     *gp++ = *cp++;
  210. }
  211.  
  212. void
  213. glyph_to_str_cpy (glyphs, str)
  214.      GLYPH *glyphs;
  215.      char *str;
  216. {
  217.   register GLYPH *gp = glyphs;
  218.   register char *cp = str;
  219.  
  220.   while (*gp)
  221.     *str++ = *gp++ & 0377;
  222. }
  223. #endif
  224.  
  225. /* Low level output routines for characters and strings */
  226.  
  227. /* Lisp functions to do output using a stream
  228.    must have the stream in a variable called printcharfun
  229.    and must start with PRINTPREPARE, end with PRINTFINISH,
  230.    and use PRINTDECLARE to declare common variables.
  231.    Use PRINTCHAR to output one character,
  232.    or call strout to output a block of characters.
  233. */ 
  234.  
  235. #define PRINTDECLARE                        \
  236.    struct buffer *old = current_buffer;                \
  237.    int old_point = -1, start_point;                \
  238.    int old_point_byte, start_point_byte;            \
  239.    int specpdl_count = specpdl_ptr - specpdl;            \
  240.    int free_print_buffer = 0;                    \
  241.    Lisp_Object original
  242.  
  243. #define PRINTPREPARE                        \
  244.    original = printcharfun;                    \
  245.    if (NILP (printcharfun)) printcharfun = Qt;            \
  246.    if (BUFFERP (printcharfun))                    \
  247.      {                                \
  248.        if (XBUFFER (printcharfun) != current_buffer)        \
  249.      Fset_buffer (printcharfun);                \
  250.        printcharfun = Qnil;                    \
  251.      }                                \
  252.    if (MARKERP (printcharfun))                    \
  253.      {                                \
  254.        if (!(XMARKER (original)->buffer))            \
  255.          error ("Marker does not point anywhere");        \
  256.        if (XMARKER (original)->buffer != current_buffer)    \
  257.          set_buffer_internal (XMARKER (original)->buffer);    \
  258.        old_point = PT;                        \
  259.        old_point_byte = PT_BYTE;                \
  260.        SET_PT_BOTH (marker_position (printcharfun),        \
  261.             marker_byte_position (printcharfun));    \
  262.        start_point = PT;                    \
  263.        start_point_byte = PT_BYTE;                \
  264.        printcharfun = Qnil;                    \
  265.      }                                \
  266.    if (NILP (printcharfun))                    \
  267.      {                                \
  268.        Lisp_Object string;                    \
  269.        if (NILP (current_buffer->enable_multibyte_characters)    \
  270.        && ! print_escape_multibyte)                \
  271.          specbind (Qprint_escape_multibyte, Qt);        \
  272.        if (! NILP (current_buffer->enable_multibyte_characters)    \
  273.        && ! print_escape_nonascii)                \
  274.          specbind (Qprint_escape_nonascii, Qt);            \
  275.        if (print_buffer != 0)                    \
  276.      {                            \
  277.        string = make_string_from_bytes (print_buffer,    \
  278.                         print_buffer_pos,    \
  279.                         print_buffer_pos_byte); \
  280.        record_unwind_protect (print_unwind, string);    \
  281.      }                            \
  282.        else                            \
  283.      {                            \
  284.            print_buffer_size = 1000;                \
  285.            print_buffer = (char *) xmalloc (print_buffer_size);    \
  286.        free_print_buffer = 1;                \
  287.      }                            \
  288.        print_buffer_pos = 0;                    \
  289.        print_buffer_pos_byte = 0;                \
  290.      }                                \
  291.    if (!CONSP (Vprint_gensym))                    \
  292.      Vprint_gensym_alist = Qnil
  293.  
  294. #define PRINTFINISH                            \
  295.    if (NILP (printcharfun))                        \
  296.      {                                    \
  297.        if (print_buffer_pos != print_buffer_pos_byte            \
  298.        && NILP (current_buffer->enable_multibyte_characters))    \
  299.      {                                \
  300.        unsigned char *temp                        \
  301.          = (unsigned char *) alloca (print_buffer_pos + 1);        \
  302.        copy_text (print_buffer, temp, print_buffer_pos_byte,    \
  303.               1, 0);                        \
  304.        insert_1_both (temp, print_buffer_pos,            \
  305.               print_buffer_pos, 0, 1, 0);            \
  306.      }                                \
  307.        else                                \
  308.      insert_1_both (print_buffer, print_buffer_pos,            \
  309.             print_buffer_pos_byte, 0, 1, 0);        \
  310.      }                                    \
  311.    if (free_print_buffer)                        \
  312.      {                                    \
  313.        xfree (print_buffer);                        \
  314.        print_buffer = 0;                        \
  315.      }                                    \
  316.    unbind_to (specpdl_count, Qnil);                    \
  317.    if (MARKERP (original))                        \
  318.      set_marker_both (original, Qnil, PT, PT_BYTE);            \
  319.    if (old_point >= 0)                            \
  320.      SET_PT_BOTH (old_point + (old_point >= start_point            \
  321.                    ? PT - start_point : 0),            \
  322.           old_point_byte + (old_point_byte >= start_point_byte    \
  323.                    ? PT_BYTE - start_point_byte : 0));    \
  324.    if (old != current_buffer)                        \
  325.      set_buffer_internal (old);                        \
  326.    if (!CONSP (Vprint_gensym))                        \
  327.      Vprint_gensym_alist = Qnil
  328.  
  329. #define PRINTCHAR(ch) printchar (ch, printcharfun)
  330.  
  331. /* Nonzero if there is no room to print any more characters
  332.    so print might as well return right away.  */
  333.  
  334. #define PRINTFULLP()                    \
  335.  (EQ (printcharfun, Qt) && !noninteractive        \
  336.   && printbufidx >= FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)))))
  337.  
  338. /* This is used to restore the saved contents of print_buffer
  339.    when there is a recursive call to print.  */
  340. static Lisp_Object
  341. print_unwind (saved_text)
  342.      Lisp_Object saved_text;
  343. {
  344.   bcopy (XSTRING (saved_text)->data, print_buffer, XSTRING (saved_text)->size);
  345. }
  346.  
  347. /* Index of first unused element of FRAME_MESSAGE_BUF (mini_frame). */
  348. static int printbufidx;
  349.  
  350. static void
  351. printchar (ch, fun)
  352.      unsigned int ch;
  353.      Lisp_Object fun;
  354. {
  355.   Lisp_Object ch1;
  356.  
  357. #ifdef MAX_PRINT_CHARS
  358.   if (max_print)
  359.     print_chars++;
  360. #endif /* MAX_PRINT_CHARS */
  361. #ifndef standalone
  362.   if (EQ (fun, Qnil))
  363.     {
  364.       int len;
  365.       unsigned char work[4], *str;
  366.  
  367.       QUIT;
  368.       len = CHAR_STRING (ch, work, str);
  369.       if (print_buffer_pos_byte + len >= print_buffer_size)
  370.     print_buffer = (char *) xrealloc (print_buffer,
  371.                       print_buffer_size *= 2);
  372.       bcopy (str, print_buffer + print_buffer_pos_byte, len);
  373.       print_buffer_pos += 1;
  374.       print_buffer_pos_byte += len;
  375.       return;
  376.     }
  377.  
  378.   if (EQ (fun, Qt))
  379.     {
  380.       FRAME_PTR mini_frame
  381.     = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
  382.       unsigned char work[4], *str;
  383.       int len = CHAR_STRING (ch, work, str);
  384.  
  385.       QUIT;
  386.  
  387.       if (noninteractive)
  388.     {
  389.       while (len--)
  390.         putchar (*str), str++;
  391.       noninteractive_need_newline = 1;
  392.       return;
  393.     }
  394.  
  395.       if (echo_area_glyphs != FRAME_MESSAGE_BUF (mini_frame)
  396.       || !message_buf_print)
  397.     {
  398.       message_log_maybe_newline ();
  399.       echo_area_glyphs = FRAME_MESSAGE_BUF (mini_frame);
  400.       printbufidx = 0;
  401.       echo_area_glyphs_length = 0;
  402.       message_buf_print = 1;
  403.  
  404.       if (minibuffer_auto_raise)
  405.         {
  406.           Lisp_Object mini_window;
  407.  
  408.           /* Get the frame containing the minibuffer
  409.          that the selected frame is using.  */
  410.           mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
  411.  
  412.           Fraise_frame  (WINDOW_FRAME (XWINDOW (mini_window)));
  413.         }
  414.     }
  415.  
  416.       message_dolog (str, len, 0, len > 1);
  417.  
  418.       /* Convert message to multibyte if we are now adding multibyte text.  */
  419.       if (! NILP (current_buffer->enable_multibyte_characters)
  420.       && ! message_enable_multibyte
  421.       && printbufidx > 0)
  422.     {
  423.       int size = count_size_as_multibyte (FRAME_MESSAGE_BUF (mini_frame),
  424.                           printbufidx);
  425.       unsigned char *tembuf = (unsigned char *) alloca (size + 1);
  426.       copy_text (FRAME_MESSAGE_BUF (mini_frame), tembuf, printbufidx,
  427.              0, 1);
  428.       printbufidx = size;
  429.       if (printbufidx > FRAME_MESSAGE_BUF_SIZE (mini_frame))
  430.         {
  431.           printbufidx = FRAME_MESSAGE_BUF_SIZE (mini_frame);
  432.           /* Rewind incomplete multi-byte form.  */
  433.           while (printbufidx > 0 && tembuf[printbufidx] >= 0xA0)
  434.         printbufidx--;
  435.         }
  436.       bcopy (tembuf, FRAME_MESSAGE_BUF (mini_frame), printbufidx);
  437.       message_enable_multibyte = 1;
  438.     }
  439.  
  440.       if (printbufidx < FRAME_MESSAGE_BUF_SIZE (mini_frame) - len)
  441.     bcopy (str, &FRAME_MESSAGE_BUF (mini_frame)[printbufidx], len),
  442.     printbufidx += len;
  443.       FRAME_MESSAGE_BUF (mini_frame)[printbufidx] = 0;
  444.       echo_area_glyphs_length = printbufidx;
  445.  
  446.       return;
  447.     }
  448. #endif /* not standalone */
  449.  
  450.   XSETFASTINT (ch1, ch);
  451.   call1 (fun, ch1);
  452. }
  453.  
  454. static void
  455. strout (ptr, size, size_byte, printcharfun, multibyte)
  456.      char *ptr;
  457.      int size, size_byte;
  458.      Lisp_Object printcharfun;
  459.      int multibyte;
  460. {
  461.   int i = 0;
  462.  
  463.   if (size < 0)
  464.     size_byte = size = strlen (ptr);
  465.  
  466.   if (EQ (printcharfun, Qnil))
  467.     {
  468.       if (print_buffer_pos_byte + size_byte > print_buffer_size)
  469.     {
  470.       print_buffer_size = print_buffer_size * 2 + size_byte;
  471.       print_buffer = (char *) xrealloc (print_buffer,
  472.                         print_buffer_size);
  473.     }
  474.       bcopy (ptr, print_buffer + print_buffer_pos_byte, size_byte);
  475.       print_buffer_pos += size;
  476.       print_buffer_pos_byte += size_byte;
  477.  
  478. #ifdef MAX_PRINT_CHARS
  479.       if (max_print)
  480.         print_chars += size;
  481. #endif /* MAX_PRINT_CHARS */
  482.       return;
  483.     }
  484.   if (EQ (printcharfun, Qt))
  485.     {
  486.       FRAME_PTR mini_frame
  487.     = XFRAME (WINDOW_FRAME (XWINDOW (minibuf_window)));
  488.  
  489.       QUIT;
  490.  
  491. #ifdef MAX_PRINT_CHARS
  492.       if (max_print)
  493.         print_chars += size;
  494. #endif /* MAX_PRINT_CHARS */
  495.  
  496.       if (noninteractive)
  497.     {
  498.       fwrite (ptr, 1, size_byte, stdout);
  499.       noninteractive_need_newline = 1;
  500.       return;
  501.     }
  502.  
  503.       if (echo_area_glyphs != FRAME_MESSAGE_BUF (mini_frame)
  504.       || !message_buf_print)
  505.     {
  506.       message_log_maybe_newline ();
  507.       echo_area_glyphs = FRAME_MESSAGE_BUF (mini_frame);
  508.       printbufidx = 0;
  509.       echo_area_glyphs_length = 0;
  510.       message_buf_print = 1;
  511.  
  512.       if (minibuffer_auto_raise)
  513.         {
  514.           Lisp_Object mini_window;
  515.  
  516.           /* Get the frame containing the minibuffer
  517.          that the selected frame is using.  */
  518.           mini_window = FRAME_MINIBUF_WINDOW (selected_frame);
  519.  
  520.           Fraise_frame  (WINDOW_FRAME (XWINDOW (mini_window)));
  521.         }
  522.     }
  523.  
  524.       message_dolog (ptr, size_byte, 0, multibyte);
  525.  
  526.       /* Convert message to multibyte if we are now adding multibyte text.  */
  527.       if (multibyte
  528.       && ! message_enable_multibyte
  529.       && printbufidx > 0)
  530.     {
  531.       int size = count_size_as_multibyte (FRAME_MESSAGE_BUF (mini_frame),
  532.                           printbufidx);
  533.       unsigned char *tembuf = (unsigned char *) alloca (size + 1);
  534.       copy_text (FRAME_MESSAGE_BUF (mini_frame), tembuf, printbufidx,
  535.              0, 1);
  536.       printbufidx = size;
  537.       if (printbufidx > FRAME_MESSAGE_BUF_SIZE (mini_frame))
  538.         {
  539.           printbufidx = FRAME_MESSAGE_BUF_SIZE (mini_frame);
  540.           /* Rewind incomplete multi-byte form.  */
  541.           while (printbufidx > 0 && tembuf[printbufidx] >= 0xA0)
  542.         printbufidx--;
  543.         }
  544.  
  545.       bcopy (tembuf, FRAME_MESSAGE_BUF (mini_frame), printbufidx);
  546.     }
  547.  
  548.       if (multibyte)
  549.     message_enable_multibyte = 1;
  550.  
  551.       /* Compute how much of the new text will fit there.  */
  552.       if (size_byte > FRAME_MESSAGE_BUF_SIZE (mini_frame) - printbufidx - 1)
  553.     {
  554.       size_byte = FRAME_MESSAGE_BUF_SIZE (mini_frame) - printbufidx - 1;
  555.       /* Rewind incomplete multi-byte form.  */
  556.       while (size_byte && (unsigned char) ptr[size_byte] >= 0xA0)
  557.         size_byte--;
  558.     }
  559.  
  560.       /* Put that part of the new text in.  */
  561.       bcopy (ptr, &FRAME_MESSAGE_BUF (mini_frame) [printbufidx], size_byte);
  562.       printbufidx += size_byte;
  563.       FRAME_MESSAGE_BUF (mini_frame) [printbufidx] = 0;
  564.       echo_area_glyphs_length = printbufidx;
  565.  
  566.       return;
  567.     }
  568.  
  569.   i = 0;
  570.   if (size == size_byte)
  571.     while (i < size_byte)
  572.       {
  573.     int ch = ptr[i++];
  574.  
  575.     PRINTCHAR (ch);
  576.       }
  577.   else
  578.     while (i < size_byte)
  579.       {
  580.     /* Here, we must convert each multi-byte form to the
  581.        corresponding character code before handing it to PRINTCHAR.  */
  582.     int len;
  583.     int ch = STRING_CHAR_AND_LENGTH (ptr + i, size_byte - i, len);
  584.  
  585.     PRINTCHAR (ch);
  586.     i += len;
  587.       }
  588. }
  589.  
  590. /* Print the contents of a string STRING using PRINTCHARFUN.
  591.    It isn't safe to use strout in many cases,
  592.    because printing one char can relocate.  */
  593.  
  594. static void
  595. print_string (string, printcharfun)
  596.      Lisp_Object string;
  597.      Lisp_Object printcharfun;
  598. {
  599.   if (EQ (printcharfun, Qt) || NILP (printcharfun))
  600.     {
  601.       int chars;
  602.  
  603.       if (STRING_MULTIBYTE (string))
  604.     chars = XSTRING (string)->size;
  605.       else if (EQ (printcharfun, Qt)
  606.            ? ! NILP (buffer_defaults.enable_multibyte_characters)
  607.            : ! NILP (current_buffer->enable_multibyte_characters))
  608.     chars = multibyte_chars_in_text (XSTRING (string)->data,
  609.                      STRING_BYTES (XSTRING (string)));
  610.       else
  611.     chars = STRING_BYTES (XSTRING (string));
  612.  
  613.       /* strout is safe for output to a frame (echo area) or to print_buffer.  */
  614.       strout (XSTRING (string)->data,
  615.           chars, STRING_BYTES (XSTRING (string)),
  616.           printcharfun, STRING_MULTIBYTE (string));
  617.     }
  618.   else
  619.     {
  620.       /* Otherwise, string may be relocated by printing one char.
  621.      So re-fetch the string address for each character.  */
  622.       int i;
  623.       int size = XSTRING (string)->size;
  624.       int size_byte = STRING_BYTES (XSTRING (string));
  625.       struct gcpro gcpro1;
  626.       GCPRO1 (string);
  627.       if (size == size_byte)
  628.     for (i = 0; i < size; i++)
  629.       PRINTCHAR (XSTRING (string)->data[i]);
  630.       else
  631.     for (i = 0; i < size_byte; i++)
  632.       {
  633.         /* Here, we must convert each multi-byte form to the
  634.            corresponding character code before handing it to PRINTCHAR.  */
  635.         int len;
  636.         int ch = STRING_CHAR_AND_CHAR_LENGTH (XSTRING (string)->data + i,
  637.                           size_byte - i, len);
  638.  
  639.         PRINTCHAR (ch);
  640.         i += len;
  641.       }
  642.       UNGCPRO;
  643.     }
  644. }
  645.  
  646. DEFUN ("write-char", Fwrite_char, Swrite_char, 1, 2, 0,
  647.   "Output character CHARACTER to stream PRINTCHARFUN.\n\
  648. PRINTCHARFUN defaults to the value of `standard-output' (which see).")
  649.   (character, printcharfun)
  650.      Lisp_Object character, printcharfun;
  651. {
  652.   PRINTDECLARE;
  653.  
  654.   if (NILP (printcharfun))
  655.     printcharfun = Vstandard_output;
  656.   CHECK_NUMBER (character, 0);
  657.   PRINTPREPARE;
  658.   PRINTCHAR (XINT (character));
  659.   PRINTFINISH;
  660.   return character;
  661. }
  662.  
  663. /* Used from outside of print.c to print a block of SIZE
  664.    single-byte chars at DATA on the default output stream.
  665.    Do not use this on the contents of a Lisp string.  */
  666.  
  667. void
  668. write_string (data, size)
  669.      char *data;
  670.      int size;
  671. {
  672.   PRINTDECLARE;
  673.   Lisp_Object printcharfun;
  674.  
  675.   printcharfun = Vstandard_output;
  676.  
  677.   PRINTPREPARE;
  678.   strout (data, size, size, printcharfun, 0);
  679.   PRINTFINISH;
  680. }
  681.  
  682. /* Used from outside of print.c to print a block of SIZE
  683.    single-byte chars at DATA on a specified stream PRINTCHARFUN.
  684.    Do not use this on the contents of a Lisp string.  */
  685.  
  686. void
  687. write_string_1 (data, size, printcharfun)
  688.      char *data;
  689.      int size;
  690.      Lisp_Object printcharfun;
  691. {
  692.   PRINTDECLARE;
  693.  
  694.   PRINTPREPARE;
  695.   strout (data, size, size, printcharfun, 0);
  696.   PRINTFINISH;
  697. }
  698.  
  699.  
  700. #ifndef standalone
  701.  
  702. void
  703. temp_output_buffer_setup (bufname)
  704.     char *bufname;
  705. {
  706.   register struct buffer *old = current_buffer;
  707.   register Lisp_Object buf;
  708.  
  709.   Fset_buffer (Fget_buffer_create (build_string (bufname)));
  710.  
  711.   current_buffer->directory = old->directory;
  712.   current_buffer->read_only = Qnil;
  713.   current_buffer->filename = Qnil;
  714.   current_buffer->undo_list = Qt;
  715.   current_buffer->overlays_before = Qnil;
  716.   current_buffer->overlays_after = Qnil;
  717.   current_buffer->enable_multibyte_characters
  718.     = buffer_defaults.enable_multibyte_characters;
  719.   Ferase_buffer ();
  720.  
  721.   XSETBUFFER (buf, current_buffer);
  722.   specbind (Qstandard_output, buf);
  723.  
  724.   set_buffer_internal (old);
  725. }
  726.  
  727. Lisp_Object
  728. internal_with_output_to_temp_buffer (bufname, function, args)
  729.      char *bufname;
  730.      Lisp_Object (*function) P_ ((Lisp_Object));
  731.      Lisp_Object args;
  732. {
  733.   int count = specpdl_ptr - specpdl;
  734.   Lisp_Object buf, val;
  735.   struct gcpro gcpro1;
  736.  
  737.   GCPRO1 (args);
  738.   record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
  739.   temp_output_buffer_setup (bufname);
  740.   buf = Vstandard_output;
  741.   UNGCPRO;
  742.  
  743.   val = (*function) (args);
  744.  
  745.   GCPRO1 (val);
  746.   temp_output_buffer_show (buf);
  747.   UNGCPRO;
  748.  
  749.   return unbind_to (count, val);
  750. }
  751.  
  752. DEFUN ("with-output-to-temp-buffer", Fwith_output_to_temp_buffer, Swith_output_to_temp_buffer,
  753.        1, UNEVALLED, 0,
  754.   "Bind `standard-output' to buffer BUFNAME, eval BODY, then show that buffer.\n\
  755. The buffer is cleared out initially, and marked as unmodified when done.\n\
  756. All output done by BODY is inserted in that buffer by default.\n\
  757. The buffer is displayed in another window, but not selected.\n\
  758. The value of the last form in BODY is returned.\n\
  759. If BODY does not finish normally, the buffer BUFNAME is not displayed.\n\n\
  760. If variable `temp-buffer-show-function' is non-nil, call it at the end\n\
  761. to get the buffer displayed.  It gets one argument, the buffer to display.")
  762.   (args)
  763.      Lisp_Object args;
  764. {
  765.   struct gcpro gcpro1;
  766.   Lisp_Object name;
  767.   int count = specpdl_ptr - specpdl;
  768.   Lisp_Object buf, val;
  769.  
  770.   GCPRO1(args);
  771.   name = Feval (Fcar (args));
  772.   UNGCPRO;
  773.  
  774.   CHECK_STRING (name, 0);
  775.   temp_output_buffer_setup (XSTRING (name)->data);
  776.   buf = Vstandard_output;
  777.  
  778.   val = Fprogn (Fcdr (args));
  779.  
  780.   temp_output_buffer_show (buf);
  781.  
  782.   return unbind_to (count, val);
  783. }
  784. #endif /* not standalone */
  785.  
  786. static void print ();
  787.  
  788. DEFUN ("terpri", Fterpri, Sterpri, 0, 1, 0,
  789.   "Output a newline to stream PRINTCHARFUN.\n\
  790. If PRINTCHARFUN is omitted or nil, the value of `standard-output' is used.")
  791.   (printcharfun)
  792.      Lisp_Object printcharfun;
  793. {
  794.   PRINTDECLARE;
  795.  
  796.   if (NILP (printcharfun))
  797.     printcharfun = Vstandard_output;
  798.   PRINTPREPARE;
  799.   PRINTCHAR ('\n');
  800.   PRINTFINISH;
  801.   return Qt;
  802. }
  803.  
  804. DEFUN ("prin1", Fprin1, Sprin1, 1, 2, 0,
  805.   "Output the printed representation of OBJECT, any Lisp object.\n\
  806. Quoting characters are printed when needed to make output that `read'\n\
  807. can handle, whenever this is possible.\n\
  808. Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
  809.   (object, printcharfun)
  810.      Lisp_Object object, printcharfun;
  811. {
  812.   PRINTDECLARE;
  813.  
  814. #ifdef MAX_PRINT_CHARS
  815.   max_print = 0;
  816. #endif /* MAX_PRINT_CHARS */
  817.   if (NILP (printcharfun))
  818.     printcharfun = Vstandard_output;
  819.   PRINTPREPARE;
  820.   print_depth = 0;
  821.   print (object, printcharfun, 1);
  822.   PRINTFINISH;
  823.   return object;
  824. }
  825.  
  826. /* a buffer which is used to hold output being built by prin1-to-string */
  827. Lisp_Object Vprin1_to_string_buffer;
  828.  
  829. DEFUN ("prin1-to-string", Fprin1_to_string, Sprin1_to_string, 1, 2, 0,
  830.   "Return a string containing the printed representation of OBJECT,\n\
  831. any Lisp object.  Quoting characters are used when needed to make output\n\
  832. that `read' can handle, whenever this is possible, unless the optional\n\
  833. second argument NOESCAPE is non-nil.")
  834.   (object, noescape)
  835.      Lisp_Object object, noescape;
  836. {
  837.   PRINTDECLARE;
  838.   Lisp_Object printcharfun;
  839.   struct gcpro gcpro1, gcpro2;
  840.   Lisp_Object tem;
  841.  
  842.   /* Save and restore this--we are altering a buffer
  843.      but we don't want to deactivate the mark just for that.
  844.      No need for specbind, since errors deactivate the mark.  */
  845.   tem = Vdeactivate_mark;
  846.   GCPRO2 (object, tem);
  847.  
  848.   printcharfun = Vprin1_to_string_buffer;
  849.   PRINTPREPARE;
  850.   print_depth = 0;
  851.   print (object, printcharfun, NILP (noescape));
  852.   /* Make Vprin1_to_string_buffer be the default buffer after PRINTFINSH */
  853.   PRINTFINISH;
  854.   set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
  855.   object = Fbuffer_string ();
  856.  
  857.   Ferase_buffer ();
  858.   set_buffer_internal (old);
  859.  
  860.   Vdeactivate_mark = tem;
  861.   UNGCPRO;
  862.  
  863.   return object;
  864. }
  865.  
  866. DEFUN ("princ", Fprinc, Sprinc, 1, 2, 0,
  867.   "Output the printed representation of OBJECT, any Lisp object.\n\
  868. No quoting characters are used; no delimiters are printed around\n\
  869. the contents of strings.\n\
  870. Output stream is PRINTCHARFUN, or value of standard-output (which see).")
  871.   (object, printcharfun)
  872.      Lisp_Object object, printcharfun;
  873. {
  874.   PRINTDECLARE;
  875.  
  876.   if (NILP (printcharfun))
  877.     printcharfun = Vstandard_output;
  878.   PRINTPREPARE;
  879.   print_depth = 0;
  880.   print (object, printcharfun, 0);
  881.   PRINTFINISH;
  882.   return object;
  883. }
  884.  
  885. DEFUN ("print", Fprint, Sprint, 1, 2, 0,
  886.   "Output the printed representation of OBJECT, with newlines around it.\n\
  887. Quoting characters are printed when needed to make output that `read'\n\
  888. can handle, whenever this is possible.\n\
  889. Output stream is PRINTCHARFUN, or value of `standard-output' (which see).")
  890.   (object, printcharfun)
  891.      Lisp_Object object, printcharfun;
  892. {
  893.   PRINTDECLARE;
  894.   struct gcpro gcpro1;
  895.  
  896. #ifdef MAX_PRINT_CHARS
  897.   print_chars = 0;
  898.   max_print = MAX_PRINT_CHARS;
  899. #endif /* MAX_PRINT_CHARS */
  900.   if (NILP (printcharfun))
  901.     printcharfun = Vstandard_output;
  902.   GCPRO1 (object);
  903.   PRINTPREPARE;
  904.   print_depth = 0;
  905.   PRINTCHAR ('\n');
  906.   print (object, printcharfun, 1);
  907.   PRINTCHAR ('\n');
  908.   PRINTFINISH;
  909. #ifdef MAX_PRINT_CHARS
  910.   max_print = 0;
  911.   print_chars = 0;
  912. #endif /* MAX_PRINT_CHARS */
  913.   UNGCPRO;
  914.   return object;
  915. }
  916.  
  917. /* The subroutine object for external-debugging-output is kept here
  918.    for the convenience of the debugger.  */
  919. Lisp_Object Qexternal_debugging_output;
  920.  
  921. DEFUN ("external-debugging-output", Fexternal_debugging_output, Sexternal_debugging_output, 1, 1, 0,
  922.   "Write CHARACTER to stderr.\n\
  923. You can call print while debugging emacs, and pass it this function\n\
  924. to make it write to the debugging output.\n")
  925.   (character)
  926.      Lisp_Object character;
  927. {
  928.   CHECK_NUMBER (character, 0);
  929.   putc (XINT (character), stderr);
  930.  
  931. #ifdef WINDOWSNT
  932.   /* Send the output to a debugger (nothing happens if there isn't one).  */
  933.   {
  934.     char buf[2] = {(char) XINT (character), '\0'};
  935.     OutputDebugString (buf);
  936.   }
  937. #endif
  938.  
  939.   return character;
  940. }
  941.  
  942. /* This is the interface for debugging printing.  */
  943.  
  944. void
  945. debug_print (arg)
  946.      Lisp_Object arg;
  947. {
  948.   Fprin1 (arg, Qexternal_debugging_output);
  949.   fprintf (stderr, "\r\n");
  950. }
  951.  
  952. DEFUN ("error-message-string", Ferror_message_string, Serror_message_string,
  953.        1, 1, 0,
  954.   "Convert an error value (ERROR-SYMBOL . DATA) to an error message.")
  955.   (obj)
  956.      Lisp_Object obj;
  957. {
  958.   struct buffer *old = current_buffer;
  959.   Lisp_Object original, printcharfun, value;
  960.   struct gcpro gcpro1;
  961.  
  962.   /* If OBJ is (error STRING), just return STRING.
  963.      That is not only faster, it also avoids the need to allocate
  964.      space here when the error is due to memory full.  */
  965.   if (CONSP (obj) && EQ (XCONS (obj)->car, Qerror)
  966.       && CONSP (XCONS (obj)->cdr)
  967.       && STRINGP (XCONS (XCONS (obj)->cdr)->car)
  968.       && NILP (XCONS (XCONS (obj)->cdr)->cdr))
  969.     return XCONS (XCONS (obj)->cdr)->car;
  970.  
  971.   print_error_message (obj, Vprin1_to_string_buffer);
  972.  
  973.   set_buffer_internal (XBUFFER (Vprin1_to_string_buffer));
  974.   value = Fbuffer_string ();
  975.  
  976.   GCPRO1 (value);
  977.   Ferase_buffer ();
  978.   set_buffer_internal (old);
  979.   UNGCPRO;
  980.  
  981.   return value;
  982. }
  983.  
  984. /* Print an error message for the error DATA
  985.    onto Lisp output stream STREAM (suitable for the print functions).  */
  986.  
  987. void
  988. print_error_message (data, stream)
  989.      Lisp_Object data, stream;
  990. {
  991.   Lisp_Object errname, errmsg, file_error, tail;
  992.   struct gcpro gcpro1;
  993.   int i;
  994.  
  995.   errname = Fcar (data);
  996.  
  997.   if (EQ (errname, Qerror))
  998.     {
  999.       data = Fcdr (data);
  1000.       if (!CONSP (data)) data = Qnil;
  1001.       errmsg = Fcar (data);
  1002.       file_error = Qnil;
  1003.     }
  1004.   else
  1005.     {
  1006.       errmsg = Fget (errname, Qerror_message);
  1007.       file_error = Fmemq (Qfile_error,
  1008.               Fget (errname, Qerror_conditions));
  1009.     }
  1010.  
  1011.   /* Print an error message including the data items.  */
  1012.  
  1013.   tail = Fcdr_safe (data);
  1014.   GCPRO1 (tail);
  1015.  
  1016.   /* For file-error, make error message by concatenating
  1017.      all the data items.  They are all strings.  */
  1018.   if (!NILP (file_error) && !NILP (tail))
  1019.     errmsg = XCONS (tail)->car, tail = XCONS (tail)->cdr;
  1020.  
  1021.   if (STRINGP (errmsg))
  1022.     Fprinc (errmsg, stream);
  1023.   else
  1024.     write_string_1 ("peculiar error", -1, stream);
  1025.  
  1026.   for (i = 0; CONSP (tail); tail = Fcdr (tail), i++)
  1027.     {
  1028.       write_string_1 (i ? ", " : ": ", 2, stream);
  1029.       if (!NILP (file_error))
  1030.     Fprinc (Fcar (tail), stream);
  1031.       else
  1032.     Fprin1 (Fcar (tail), stream);
  1033.     }
  1034.   UNGCPRO;
  1035. }
  1036.  
  1037. #ifdef LISP_FLOAT_TYPE
  1038.  
  1039. /*
  1040.  * The buffer should be at least as large as the max string size of the
  1041.  * largest float, printed in the biggest notation.  This is undoubtedly
  1042.  * 20d float_output_format, with the negative of the C-constant "HUGE"
  1043.  * from <math.h>.
  1044.  * 
  1045.  * On the vax the worst case is -1e38 in 20d format which takes 61 bytes.
  1046.  * 
  1047.  * I assume that IEEE-754 format numbers can take 329 bytes for the worst
  1048.  * case of -1e307 in 20d float_output_format. What is one to do (short of
  1049.  * re-writing _doprnt to be more sane)?
  1050.  *             -wsr
  1051.  */
  1052.  
  1053. void
  1054. float_to_string (buf, data)
  1055.      unsigned char *buf;
  1056.      double data;
  1057. {
  1058.   unsigned char *cp;
  1059.   int width;
  1060.       
  1061.   /* Check for plus infinity in a way that won't lose
  1062.      if there is no plus infinity.  */
  1063.   if (data == data / 2 && data > 1.0)
  1064.     {
  1065.       strcpy (buf, "1.0e+INF");
  1066.       return;
  1067.     }
  1068.   /* Likewise for minus infinity.  */
  1069.   if (data == data / 2 && data < -1.0)
  1070.     {
  1071.       strcpy (buf, "-1.0e+INF");
  1072.       return;
  1073.     }
  1074.   /* Check for NaN in a way that won't fail if there are no NaNs.  */
  1075.   if (! (data * 0.0 >= 0.0))
  1076.     {
  1077.       strcpy (buf, "0.0e+NaN");
  1078.       return;
  1079.     }
  1080.  
  1081.   if (NILP (Vfloat_output_format)
  1082.       || !STRINGP (Vfloat_output_format))
  1083.   lose:
  1084.     {
  1085.       /* Generate the fewest number of digits that represent the
  1086.      floating point value without losing information.
  1087.      The following method is simple but a bit slow.
  1088.      For ideas about speeding things up, please see:
  1089.  
  1090.      Guy L Steele Jr & Jon L White, How to print floating-point numbers
  1091.      accurately.  SIGPLAN notices 25, 6 (June 1990), 112-126.
  1092.  
  1093.      Robert G Burger & R Kent Dybvig, Printing floating point numbers
  1094.      quickly and accurately, SIGPLAN notices 31, 5 (May 1996), 108-116.  */
  1095.  
  1096.       width = fabs (data) < DBL_MIN ? 1 : DBL_DIG;
  1097.       do
  1098.     sprintf (buf, "%.*g", width, data);
  1099.       while (width++ < DOUBLE_DIGITS_BOUND && atof (buf) != data);
  1100.     }
  1101.   else            /* oink oink */
  1102.     {
  1103.       /* Check that the spec we have is fully valid.
  1104.      This means not only valid for printf,
  1105.      but meant for floats, and reasonable.  */
  1106.       cp = XSTRING (Vfloat_output_format)->data;
  1107.  
  1108.       if (cp[0] != '%')
  1109.     goto lose;
  1110.       if (cp[1] != '.')
  1111.     goto lose;
  1112.  
  1113.       cp += 2;
  1114.  
  1115.       /* Check the width specification.  */
  1116.       width = -1;
  1117.       if ('0' <= *cp && *cp <= '9')
  1118.     {
  1119.       width = 0;
  1120.       do
  1121.         width = (width * 10) + (*cp++ - '0');
  1122.       while (*cp >= '0' && *cp <= '9');
  1123.  
  1124.       /* A precision of zero is valid only for %f.  */
  1125.       if (width > DBL_DIG
  1126.           || (width == 0 && *cp != 'f'))
  1127.         goto lose;
  1128.     }
  1129.  
  1130.       if (*cp != 'e' && *cp != 'f' && *cp != 'g')
  1131.     goto lose;
  1132.  
  1133.       if (cp[1] != 0)
  1134.     goto lose;
  1135.  
  1136.       sprintf (buf, XSTRING (Vfloat_output_format)->data, data);
  1137.     }
  1138.  
  1139.   /* Make sure there is a decimal point with digit after, or an
  1140.      exponent, so that the value is readable as a float.  But don't do
  1141.      this with "%.0f"; it's valid for that not to produce a decimal
  1142.      point.  Note that width can be 0 only for %.0f.  */
  1143.   if (width != 0)
  1144.     {
  1145.       for (cp = buf; *cp; cp++)
  1146.     if ((*cp < '0' || *cp > '9') && *cp != '-')
  1147.       break;
  1148.  
  1149.       if (*cp == '.' && cp[1] == 0)
  1150.     {
  1151.       cp[1] = '0';
  1152.       cp[2] = 0;
  1153.     }
  1154.  
  1155.       if (*cp == 0)
  1156.     {
  1157.       *cp++ = '.';
  1158.       *cp++ = '0';
  1159.       *cp++ = 0;
  1160.     }
  1161.     }
  1162. }
  1163. #endif /* LISP_FLOAT_TYPE */
  1164.  
  1165. static void
  1166. print (obj, printcharfun, escapeflag)
  1167.      Lisp_Object obj;
  1168.      register Lisp_Object printcharfun;
  1169.      int escapeflag;
  1170. {
  1171.   char buf[30];
  1172.  
  1173.   QUIT;
  1174.  
  1175. #if 1  /* I'm not sure this is really worth doing.  */
  1176.   /* Detect circularities and truncate them.
  1177.      No need to offer any alternative--this is better than an error.  */
  1178.   if (CONSP (obj) || VECTORP (obj) || COMPILEDP (obj))
  1179.     {
  1180.       int i;
  1181.       for (i = 0; i < print_depth; i++)
  1182.     if (EQ (obj, being_printed[i]))
  1183.       {
  1184.         sprintf (buf, "#%d", i);
  1185.         strout (buf, -1, -1, printcharfun, 0);
  1186.         return;
  1187.       }
  1188.     }
  1189. #endif
  1190.  
  1191.   being_printed[print_depth] = obj;
  1192.   print_depth++;
  1193.  
  1194.   if (print_depth > PRINT_CIRCLE)
  1195.     error ("Apparently circular structure being printed");
  1196. #ifdef MAX_PRINT_CHARS
  1197.   if (max_print && print_chars > max_print)
  1198.     {
  1199.       PRINTCHAR ('\n');
  1200.       print_chars = 0;
  1201.     }
  1202. #endif /* MAX_PRINT_CHARS */
  1203.  
  1204.   switch (XGCTYPE (obj))
  1205.     {
  1206.     case Lisp_Int:
  1207.       if (sizeof (int) == sizeof (EMACS_INT))
  1208.     sprintf (buf, "%d", XINT (obj));
  1209.       else if (sizeof (long) == sizeof (EMACS_INT))
  1210.     sprintf (buf, "%ld", XINT (obj));
  1211.       else
  1212.     abort ();
  1213.       strout (buf, -1, -1, printcharfun, 0);
  1214.       break;
  1215.  
  1216. #ifdef LISP_FLOAT_TYPE
  1217.     case Lisp_Float:
  1218.       {
  1219.     char pigbuf[350];    /* see comments in float_to_string */
  1220.  
  1221.     float_to_string (pigbuf, XFLOAT(obj)->data);
  1222.     strout (pigbuf, -1, -1, printcharfun, 0);
  1223.       }
  1224.       break;
  1225. #endif
  1226.  
  1227.     case Lisp_String:
  1228.       if (!escapeflag)
  1229.     print_string (obj, printcharfun);
  1230.       else
  1231.     {
  1232.       register int i, i_byte;
  1233.       register unsigned char c;
  1234.       struct gcpro gcpro1;
  1235.       unsigned char *str;
  1236.       int size_byte;
  1237.       /* 1 means we must ensure that the next character we output
  1238.          cannot be taken as part of a hex character escape.  */
  1239.       int need_nonhex = 0;
  1240.  
  1241.       GCPRO1 (obj);
  1242.  
  1243. #ifdef USE_TEXT_PROPERTIES
  1244.       if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
  1245.         {
  1246.           PRINTCHAR ('#');
  1247.           PRINTCHAR ('(');
  1248.         }
  1249. #endif
  1250.  
  1251.       PRINTCHAR ('\"');
  1252.       str = XSTRING (obj)->data;
  1253.       size_byte = STRING_BYTES (XSTRING (obj));
  1254.  
  1255.       for (i = 0, i_byte = 0; i_byte < size_byte;)
  1256.         {
  1257.           /* Here, we must convert each multi-byte form to the
  1258.          corresponding character code before handing it to PRINTCHAR.  */
  1259.           int len;
  1260.           int c;
  1261.  
  1262.           if (STRING_MULTIBYTE (obj))
  1263.         {
  1264.           c = STRING_CHAR_AND_CHAR_LENGTH (str + i_byte,
  1265.                            size_byte - i_byte, len);
  1266.           i_byte += len;
  1267.         }
  1268.           else
  1269.         c = str[i_byte++];
  1270.  
  1271.           QUIT;
  1272.  
  1273.           if (c == '\n' && print_escape_newlines)
  1274.         {
  1275.           PRINTCHAR ('\\');
  1276.           PRINTCHAR ('n');
  1277.         }
  1278.           else if (c == '\f' && print_escape_newlines)
  1279.         {
  1280.           PRINTCHAR ('\\');
  1281.           PRINTCHAR ('f');
  1282.         }
  1283.           else if (! SINGLE_BYTE_CHAR_P (c) && print_escape_multibyte)
  1284.         {
  1285.           /* When multibyte is disabled,
  1286.              print multibyte string chars using hex escapes.  */
  1287.           unsigned char outbuf[50];
  1288.           sprintf (outbuf, "\\x%x", c);
  1289.           strout (outbuf, -1, -1, printcharfun, 0);
  1290.           need_nonhex = 1;
  1291.         }
  1292.           else if (SINGLE_BYTE_CHAR_P (c) && ! ASCII_BYTE_P (c)
  1293.                && print_escape_nonascii)
  1294.         {
  1295.           /* When printing in a multibyte buffer
  1296.              or when explicitly requested,
  1297.              print single-byte non-ASCII string chars
  1298.              using octal escapes.  */
  1299.           unsigned char outbuf[5];
  1300.           sprintf (outbuf, "\\%03o", c);
  1301.           strout (outbuf, -1, -1, printcharfun, 0);
  1302.         }
  1303.           else
  1304.         {
  1305.           /* If we just had a hex escape, and this character
  1306.              could be taken as part of it,
  1307.              output `\ ' to prevent that.  */
  1308.           if (need_nonhex)
  1309.             {
  1310.               need_nonhex = 0;
  1311.               if ((c >= 'a' && c <= 'f')
  1312.               || (c >= 'A' && c <= 'F')
  1313.               || (c >= '0' && c <= '9'))
  1314.             strout ("\\ ", -1, -1, printcharfun, 0);
  1315.             }
  1316.  
  1317.           if (c == '\"' || c == '\\')
  1318.             PRINTCHAR ('\\');
  1319.           PRINTCHAR (c);
  1320.         }
  1321.         }
  1322.       PRINTCHAR ('\"');
  1323.  
  1324. #ifdef USE_TEXT_PROPERTIES
  1325.       if (!NULL_INTERVAL_P (XSTRING (obj)->intervals))
  1326.         {
  1327.           traverse_intervals (XSTRING (obj)->intervals,
  1328.                   0, 0, print_interval, printcharfun);
  1329.           PRINTCHAR (')');
  1330.         }
  1331. #endif
  1332.  
  1333.       UNGCPRO;
  1334.     }
  1335.       break;
  1336.  
  1337.     case Lisp_Symbol:
  1338.       {
  1339.     register int confusing;
  1340.     register unsigned char *p = XSYMBOL (obj)->name->data;
  1341.     register unsigned char *end = p + STRING_BYTES (XSYMBOL (obj)->name);
  1342.     register int c;
  1343.     int i, i_byte, size_byte;
  1344.     Lisp_Object name;
  1345.  
  1346.     XSETSTRING (name, XSYMBOL (obj)->name);
  1347.  
  1348.     if (p != end && (*p == '-' || *p == '+')) p++;
  1349.     if (p == end)
  1350.       confusing = 0;
  1351.     /* If symbol name begins with a digit, and ends with a digit,
  1352.        and contains nothing but digits and `e', it could be treated
  1353.        as a number.  So set CONFUSING.
  1354.  
  1355.        Symbols that contain periods could also be taken as numbers,
  1356.        but periods are always escaped, so we don't have to worry
  1357.        about them here.  */
  1358.     else if (*p >= '0' && *p <= '9'
  1359.          && end[-1] >= '0' && end[-1] <= '9')
  1360.       {
  1361.         while (p != end && ((*p >= '0' && *p <= '9')
  1362.                 /* Needed for \2e10.  */
  1363.                 || *p == 'e'))
  1364.           p++;
  1365.         confusing = (end == p);
  1366.       }
  1367.     else
  1368.       confusing = 0;
  1369.  
  1370.     /* If we print an uninterned symbol as part of a complex object and
  1371.        the flag print-gensym is non-nil, prefix it with #n= to read the
  1372.        object back with the #n# reader syntax later if needed.  */
  1373.     if (! NILP (Vprint_gensym) && NILP (XSYMBOL (obj)->obarray))
  1374.       {
  1375.         if (print_depth > 1)
  1376.           {
  1377.         Lisp_Object tem;
  1378.         tem = Fassq (obj, Vprint_gensym_alist);
  1379.         if (CONSP (tem))
  1380.           {
  1381.             PRINTCHAR ('#');
  1382.             print (XCDR (tem), printcharfun, escapeflag);
  1383.             PRINTCHAR ('#');
  1384.             break;
  1385.           }
  1386.         else
  1387.           {
  1388.             if (CONSP (Vprint_gensym_alist))
  1389.               XSETFASTINT (tem, XFASTINT (XCDR (XCAR (Vprint_gensym_alist))) + 1);
  1390.             else
  1391.               XSETFASTINT (tem, 1);
  1392.             Vprint_gensym_alist = Fcons (Fcons (obj, tem), Vprint_gensym_alist);
  1393.  
  1394.             PRINTCHAR ('#');
  1395.             print (tem, printcharfun, escapeflag);
  1396.             PRINTCHAR ('=');
  1397.           }
  1398.           }
  1399.         PRINTCHAR ('#');
  1400.         PRINTCHAR (':');
  1401.       }
  1402.  
  1403.     size_byte = STRING_BYTES (XSTRING (name));
  1404.  
  1405.     for (i = 0, i_byte = 0; i_byte < size_byte;)
  1406.       {
  1407.         /* Here, we must convert each multi-byte form to the
  1408.            corresponding character code before handing it to PRINTCHAR.  */
  1409.  
  1410.         if (STRING_MULTIBYTE (name))
  1411.           FETCH_STRING_CHAR_ADVANCE (c, name, i, i_byte);
  1412.         else
  1413.           c = XSTRING (name)->data[i_byte++];
  1414.  
  1415.         QUIT;
  1416.  
  1417.         if (escapeflag)
  1418.           {
  1419.         if (c == '\"' || c == '\\' || c == '\''
  1420.             || c == ';' || c == '#' || c == '(' || c == ')'
  1421.             || c == ',' || c =='.' || c == '`'
  1422.             || c == '[' || c == ']' || c == '?' || c <= 040
  1423.             || confusing)
  1424.           PRINTCHAR ('\\'), confusing = 0;
  1425.           }
  1426.         PRINTCHAR (c);
  1427.       }
  1428.       }
  1429.       break;
  1430.  
  1431.     case Lisp_Cons:
  1432.       /* If deeper than spec'd depth, print placeholder.  */
  1433.       if (INTEGERP (Vprint_level)
  1434.       && print_depth > XINT (Vprint_level))
  1435.     strout ("...", -1, -1, printcharfun, 0);
  1436.       else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
  1437.            && (EQ (XCAR (obj), Qquote)))
  1438.     {
  1439.       PRINTCHAR ('\'');
  1440.       print (XCAR (XCDR (obj)), printcharfun, escapeflag);
  1441.     }
  1442.       else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
  1443.            && (EQ (XCAR (obj), Qfunction)))
  1444.     {
  1445.       PRINTCHAR ('#');
  1446.       PRINTCHAR ('\'');
  1447.       print (XCAR (XCDR (obj)), printcharfun, escapeflag);
  1448.     }
  1449.       else if (print_quoted && CONSP (XCDR (obj)) && NILP (XCDR (XCDR (obj)))
  1450.            && ((EQ (XCAR (obj), Qbackquote)
  1451.             || EQ (XCAR (obj), Qcomma)
  1452.             || EQ (XCAR (obj), Qcomma_at)
  1453.             || EQ (XCAR (obj), Qcomma_dot))))
  1454.     {
  1455.       print (XCAR (obj), printcharfun, 0);
  1456.       print (XCAR (XCDR (obj)), printcharfun, escapeflag);
  1457.     }
  1458.       else
  1459.     {
  1460.       PRINTCHAR ('(');
  1461.       {
  1462.         register int i = 0;
  1463.         register int print_length = 0;
  1464.         Lisp_Object halftail = obj;
  1465.  
  1466.         if (INTEGERP (Vprint_length))
  1467.           print_length = XINT (Vprint_length);
  1468.         while (CONSP (obj))
  1469.           {
  1470.         /* Detect circular list.  */
  1471.         if (i != 0 && EQ (obj, halftail))
  1472.           {
  1473.             sprintf (buf, " . #%d", i / 2);
  1474.             strout (buf, -1, -1, printcharfun, 0);
  1475.             obj = Qnil;
  1476.             break;
  1477.           }
  1478.         if (i++)
  1479.           PRINTCHAR (' ');
  1480.         if (print_length && i > print_length)
  1481.           {
  1482.             strout ("...", 3, 3, printcharfun, 0);
  1483.             break;
  1484.           }
  1485.         print (XCAR (obj), printcharfun, escapeflag);
  1486.         obj = XCDR (obj);
  1487.         if (!(i & 1))
  1488.           halftail = XCDR (halftail);
  1489.           }
  1490.       }
  1491.       if (!NILP (obj))
  1492.         {
  1493.           strout (" . ", 3, 3, printcharfun, 0);
  1494.           print (obj, printcharfun, escapeflag);
  1495.         }
  1496.       PRINTCHAR (')');
  1497.     }
  1498.       break;
  1499.  
  1500.     case Lisp_Vectorlike:
  1501.       if (PROCESSP (obj))
  1502.     {
  1503.       if (escapeflag)
  1504.         {
  1505.           strout ("#<process ", -1, -1, printcharfun, 0);
  1506.           print_string (XPROCESS (obj)->name, printcharfun);
  1507.           PRINTCHAR ('>');
  1508.         }
  1509.       else
  1510.         print_string (XPROCESS (obj)->name, printcharfun);
  1511.     }
  1512.       else if (BOOL_VECTOR_P (obj))
  1513.     {
  1514.       register int i;
  1515.       register unsigned char c;
  1516.       struct gcpro gcpro1;
  1517.       int size_in_chars
  1518.         = (XBOOL_VECTOR (obj)->size + BITS_PER_CHAR - 1) / BITS_PER_CHAR;
  1519.  
  1520.       GCPRO1 (obj);
  1521.  
  1522.       PRINTCHAR ('#');
  1523.       PRINTCHAR ('&');
  1524.       sprintf (buf, "%d", XBOOL_VECTOR (obj)->size);
  1525.       strout (buf, -1, -1, printcharfun, 0);
  1526.       PRINTCHAR ('\"');
  1527.  
  1528.       /* Don't print more characters than the specified maximum.  */
  1529.       if (INTEGERP (Vprint_length)
  1530.           && XINT (Vprint_length) < size_in_chars)
  1531.         size_in_chars = XINT (Vprint_length);
  1532.  
  1533.       for (i = 0; i < size_in_chars; i++)
  1534.         {
  1535.           QUIT;
  1536.           c = XBOOL_VECTOR (obj)->data[i];
  1537.           if (c == '\n' && print_escape_newlines)
  1538.         {
  1539.           PRINTCHAR ('\\');
  1540.           PRINTCHAR ('n');
  1541.         }
  1542.           else if (c == '\f' && print_escape_newlines)
  1543.         {
  1544.           PRINTCHAR ('\\');
  1545.           PRINTCHAR ('f');
  1546.         }
  1547.           else
  1548.         {
  1549.           if (c == '\"' || c == '\\')
  1550.             PRINTCHAR ('\\');
  1551.           PRINTCHAR (c);
  1552.         }
  1553.         }
  1554.       PRINTCHAR ('\"');
  1555.  
  1556.       UNGCPRO;
  1557.     }
  1558.       else if (SUBRP (obj))
  1559.     {
  1560.       strout ("#<subr ", -1, -1, printcharfun, 0);
  1561.       strout (XSUBR (obj)->symbol_name, -1, -1, printcharfun, 0);
  1562.       PRINTCHAR ('>');
  1563.     }
  1564. #ifndef standalone
  1565.       else if (WINDOWP (obj))
  1566.     {
  1567.       strout ("#<window ", -1, -1, printcharfun, 0);
  1568.       sprintf (buf, "%d", XFASTINT (XWINDOW (obj)->sequence_number));
  1569.       strout (buf, -1, -1, printcharfun, 0);
  1570.       if (!NILP (XWINDOW (obj)->buffer))
  1571.         {
  1572.           strout (" on ", -1, -1, printcharfun, 0);
  1573.           print_string (XBUFFER (XWINDOW (obj)->buffer)->name, printcharfun);
  1574.         }
  1575.       PRINTCHAR ('>');
  1576.     }
  1577.       else if (BUFFERP (obj))
  1578.     {
  1579.       if (NILP (XBUFFER (obj)->name))
  1580.         strout ("#<killed buffer>", -1, -1, printcharfun, 0);
  1581.       else if (escapeflag)
  1582.         {
  1583.           strout ("#<buffer ", -1, -1, printcharfun, 0);
  1584.           print_string (XBUFFER (obj)->name, printcharfun);
  1585.           PRINTCHAR ('>');
  1586.         }
  1587.       else
  1588.         print_string (XBUFFER (obj)->name, printcharfun);
  1589.     }
  1590.       else if (WINDOW_CONFIGURATIONP (obj))
  1591.     {
  1592.       strout ("#<window-configuration>", -1, -1, printcharfun, 0);
  1593.     }
  1594.       else if (FRAMEP (obj))
  1595.     {
  1596.       strout ((FRAME_LIVE_P (XFRAME (obj))
  1597.            ? "#<frame " : "#<dead frame "),
  1598.           -1, -1, printcharfun, 0);
  1599.       print_string (XFRAME (obj)->name, printcharfun);
  1600.       sprintf (buf, " 0x%lx\\ ", (unsigned long) (XFRAME (obj)));
  1601.       strout (buf, -1, -1, printcharfun, 0);
  1602.       PRINTCHAR ('>');
  1603.     }
  1604. #endif /* not standalone */
  1605.       else
  1606.     {
  1607.       int size = XVECTOR (obj)->size;
  1608.       if (COMPILEDP (obj))
  1609.         {
  1610.           PRINTCHAR ('#');
  1611.           size &= PSEUDOVECTOR_SIZE_MASK;
  1612.         }
  1613.       if (CHAR_TABLE_P (obj))
  1614.         {
  1615.           /* We print a char-table as if it were a vector,
  1616.          lumping the parent and default slots in with the
  1617.          character slots.  But we add #^ as a prefix.  */
  1618.           PRINTCHAR ('#');
  1619.           PRINTCHAR ('^');
  1620.           if (SUB_CHAR_TABLE_P (obj))
  1621.         PRINTCHAR ('^');
  1622.           size &= PSEUDOVECTOR_SIZE_MASK;
  1623.         }
  1624.       if (size & PSEUDOVECTOR_FLAG)
  1625.         goto badtype;
  1626.  
  1627.       PRINTCHAR ('[');
  1628.       {
  1629.         register int i;
  1630.         register Lisp_Object tem;
  1631.  
  1632.         /* Don't print more elements than the specified maximum.  */
  1633.         if (INTEGERP (Vprint_length)
  1634.         && XINT (Vprint_length) < size)
  1635.           size = XINT (Vprint_length);
  1636.  
  1637.         for (i = 0; i < size; i++)
  1638.           {
  1639.         if (i) PRINTCHAR (' ');
  1640.         tem = XVECTOR (obj)->contents[i];
  1641.         print (tem, printcharfun, escapeflag);
  1642.           }
  1643.       }
  1644.       PRINTCHAR (']');
  1645.     }
  1646.       break;
  1647.  
  1648. #ifndef standalone
  1649.     case Lisp_Misc:
  1650.       switch (XMISCTYPE (obj))
  1651.     {
  1652.     case Lisp_Misc_Marker:
  1653.       strout ("#<marker ", -1, -1, printcharfun, 0);
  1654.       /* Do you think this is necessary?  */
  1655.       if (XMARKER (obj)->insertion_type != 0)
  1656.         strout ("(before-insertion) ", -1, -1, printcharfun, 0);
  1657.       if (!(XMARKER (obj)->buffer))
  1658.         strout ("in no buffer", -1, -1, printcharfun, 0);
  1659.       else
  1660.         {
  1661.           sprintf (buf, "at %d", marker_position (obj));
  1662.           strout (buf, -1, -1, printcharfun, 0);
  1663.           strout (" in ", -1, -1, printcharfun, 0);
  1664.           print_string (XMARKER (obj)->buffer->name, printcharfun);
  1665.         }
  1666.       PRINTCHAR ('>');
  1667.       break;
  1668.  
  1669.     case Lisp_Misc_Overlay:
  1670.       strout ("#<overlay ", -1, -1, printcharfun, 0);
  1671.       if (!(XMARKER (OVERLAY_START (obj))->buffer))
  1672.         strout ("in no buffer", -1, -1, printcharfun, 0);
  1673.       else
  1674.         {
  1675.           sprintf (buf, "from %d to %d in ",
  1676.                marker_position (OVERLAY_START (obj)),
  1677.                marker_position (OVERLAY_END   (obj)));
  1678.           strout (buf, -1, -1, printcharfun, 0);
  1679.           print_string (XMARKER (OVERLAY_START (obj))->buffer->name,
  1680.                 printcharfun);
  1681.         }
  1682.       PRINTCHAR ('>');
  1683.       break;
  1684.  
  1685.       /* Remaining cases shouldn't happen in normal usage, but let's print
  1686.      them anyway for the benefit of the debugger.  */
  1687.     case Lisp_Misc_Free:
  1688.       strout ("#<misc free cell>", -1, -1, printcharfun, 0);
  1689.       break;
  1690.  
  1691.     case Lisp_Misc_Intfwd:
  1692.       sprintf (buf, "#<intfwd to %d>", *XINTFWD (obj)->intvar);
  1693.       strout (buf, -1, -1, printcharfun, 0);
  1694.       break;
  1695.  
  1696.     case Lisp_Misc_Boolfwd:
  1697.       sprintf (buf, "#<boolfwd to %s>",
  1698.            (*XBOOLFWD (obj)->boolvar ? "t" : "nil"));
  1699.       strout (buf, -1, -1, printcharfun, 0);
  1700.       break;
  1701.  
  1702.     case Lisp_Misc_Objfwd:
  1703.       strout ("#<objfwd to ", -1, -1, printcharfun, 0);
  1704.       print (*XOBJFWD (obj)->objvar, printcharfun, escapeflag);
  1705.       PRINTCHAR ('>');
  1706.       break;
  1707.  
  1708.     case Lisp_Misc_Buffer_Objfwd:
  1709.       strout ("#<buffer_objfwd to ", -1, -1, printcharfun, 0);
  1710.       print (*(Lisp_Object *)((char *)current_buffer
  1711.                   + XBUFFER_OBJFWD (obj)->offset),
  1712.          printcharfun, escapeflag);
  1713.       PRINTCHAR ('>');
  1714.       break;
  1715.  
  1716.     case Lisp_Misc_Kboard_Objfwd:
  1717.       strout ("#<kboard_objfwd to ", -1, -1, printcharfun, 0);
  1718.       print (*(Lisp_Object *)((char *) current_kboard
  1719.                   + XKBOARD_OBJFWD (obj)->offset),
  1720.          printcharfun, escapeflag);
  1721.       PRINTCHAR ('>');
  1722.       break;
  1723.  
  1724.     case Lisp_Misc_Buffer_Local_Value:
  1725.       strout ("#<buffer_local_value ", -1, -1, printcharfun, 0);
  1726.       goto do_buffer_local;
  1727.     case Lisp_Misc_Some_Buffer_Local_Value:
  1728.       strout ("#<some_buffer_local_value ", -1, -1, printcharfun, 0);
  1729.     do_buffer_local:
  1730.       strout ("[realvalue] ", -1, -1, printcharfun, 0);
  1731.       print (XBUFFER_LOCAL_VALUE (obj)->realvalue, printcharfun, escapeflag);
  1732.       if (XBUFFER_LOCAL_VALUE (obj)->found_for_buffer)
  1733.         strout ("[local in buffer] ", -1, -1, printcharfun, 0);
  1734.       else
  1735.         strout ("[buffer] ", -1, -1, printcharfun, 0);
  1736.       print (XBUFFER_LOCAL_VALUE (obj)->buffer,
  1737.          printcharfun, escapeflag);
  1738.       if (XBUFFER_LOCAL_VALUE (obj)->check_frame)
  1739.         {
  1740.           if (XBUFFER_LOCAL_VALUE (obj)->found_for_frame)
  1741.         strout ("[local in frame] ", -1, -1, printcharfun, 0);
  1742.           else
  1743.         strout ("[frame] ", -1, -1, printcharfun, 0);
  1744.           print (XBUFFER_LOCAL_VALUE (obj)->frame,
  1745.              printcharfun, escapeflag);
  1746.         }
  1747.       strout ("[alist-elt] ", -1, -1, printcharfun, 0);
  1748.       print (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->car,
  1749.          printcharfun, escapeflag);
  1750.       strout ("[default-value] ", -1, -1, printcharfun, 0);
  1751.       print (XCONS (XBUFFER_LOCAL_VALUE (obj)->cdr)->cdr,
  1752.          printcharfun, escapeflag);
  1753.       PRINTCHAR ('>');
  1754.       break;
  1755.  
  1756.     default:
  1757.       goto badtype;
  1758.     }
  1759.       break;
  1760. #endif /* standalone */
  1761.  
  1762.     default:
  1763.     badtype:
  1764.       {
  1765.     /* We're in trouble if this happens!
  1766.        Probably should just abort () */
  1767.     strout ("#<EMACS BUG: INVALID DATATYPE ", -1, -1, printcharfun, 0);
  1768.     if (MISCP (obj))
  1769.       sprintf (buf, "(MISC 0x%04x)", (int) XMISCTYPE (obj));
  1770.     else if (VECTORLIKEP (obj))
  1771.       sprintf (buf, "(PVEC 0x%08x)", (int) XVECTOR (obj)->size);
  1772.     else
  1773.       sprintf (buf, "(0x%02x)", (int) XTYPE (obj));
  1774.     strout (buf, -1, -1, printcharfun, 0);
  1775.     strout (" Save your buffers immediately and please report this bug>",
  1776.         -1, -1, printcharfun, 0);
  1777.       }
  1778.     }
  1779.  
  1780.   print_depth--;
  1781. }
  1782.  
  1783. #ifdef USE_TEXT_PROPERTIES
  1784.  
  1785. /* Print a description of INTERVAL using PRINTCHARFUN.
  1786.    This is part of printing a string that has text properties.  */
  1787.  
  1788. void
  1789. print_interval (interval, printcharfun)
  1790.      INTERVAL interval;
  1791.      Lisp_Object printcharfun;
  1792. {
  1793.   PRINTCHAR (' ');
  1794.   print (make_number (interval->position), printcharfun, 1);
  1795.   PRINTCHAR (' ');
  1796.   print (make_number (interval->position + LENGTH (interval)),
  1797.      printcharfun, 1);
  1798.   PRINTCHAR (' ');
  1799.   print (interval->plist, printcharfun, 1);
  1800. }
  1801.  
  1802. #endif /* USE_TEXT_PROPERTIES */
  1803.  
  1804. void
  1805. syms_of_print ()
  1806. {
  1807.   DEFVAR_LISP ("standard-output", &Vstandard_output,
  1808.     "Output stream `print' uses by default for outputting a character.\n\
  1809. This may be any function of one argument.\n\
  1810. It may also be a buffer (output is inserted before point)\n\
  1811. or a marker (output is inserted and the marker is advanced)\n\
  1812. or the symbol t (output appears in the echo area).");
  1813.   Vstandard_output = Qt;
  1814.   Qstandard_output = intern ("standard-output");
  1815.   staticpro (&Qstandard_output);
  1816.  
  1817. #ifdef LISP_FLOAT_TYPE
  1818.   DEFVAR_LISP ("float-output-format", &Vfloat_output_format,
  1819.     "The format descriptor string used to print floats.\n\
  1820. This is a %-spec like those accepted by `printf' in C,\n\
  1821. but with some restrictions.  It must start with the two characters `%.'.\n\
  1822. After that comes an integer precision specification,\n\
  1823. and then a letter which controls the format.\n\
  1824. The letters allowed are `e', `f' and `g'.\n\
  1825. Use `e' for exponential notation \"DIG.DIGITSeEXPT\"\n\
  1826. Use `f' for decimal point notation \"DIGITS.DIGITS\".\n\
  1827. Use `g' to choose the shorter of those two formats for the number at hand.\n\
  1828. The precision in any of these cases is the number of digits following\n\
  1829. the decimal point.  With `f', a precision of 0 means to omit the\n\
  1830. decimal point.  0 is not allowed with `e' or `g'.\n\n\
  1831. A value of nil means to use the shortest notation\n\
  1832. that represents the number without losing information.");
  1833.   Vfloat_output_format = Qnil;
  1834.   Qfloat_output_format = intern ("float-output-format");
  1835.   staticpro (&Qfloat_output_format);
  1836. #endif /* LISP_FLOAT_TYPE */
  1837.  
  1838.   DEFVAR_LISP ("print-length", &Vprint_length,
  1839.     "Maximum length of list to print before abbreviating.\n\
  1840. A value of nil means no limit.");
  1841.   Vprint_length = Qnil;
  1842.  
  1843.   DEFVAR_LISP ("print-level", &Vprint_level,
  1844.     "Maximum depth of list nesting to print before abbreviating.\n\
  1845. A value of nil means no limit.");
  1846.   Vprint_level = Qnil;
  1847.  
  1848.   DEFVAR_BOOL ("print-escape-newlines", &print_escape_newlines,
  1849.     "Non-nil means print newlines in strings as backslash-n.\n\
  1850. Also print formfeeds as backslash-f.");
  1851.   print_escape_newlines = 0;
  1852.  
  1853.   DEFVAR_BOOL ("print-escape-nonascii", &print_escape_nonascii,
  1854.     "Non-nil means print unibyte non-ASCII chars in strings as \\OOO.\n\
  1855. \(OOO is the octal representation of the character code.)\n\
  1856. Only single-byte characters are affected, and only in `prin1'.");
  1857.   print_escape_nonascii = 0;
  1858.  
  1859.   DEFVAR_BOOL ("print-escape-multibyte", &print_escape_multibyte,
  1860.     "Non-nil means print multibyte characters in strings as \\xXXXX.\n\
  1861. \(XXX is the hex representation of the character code.)\n\
  1862. This affects only `prin1'.");
  1863.   print_escape_multibyte = 0;
  1864.  
  1865.   DEFVAR_BOOL ("print-quoted", &print_quoted,
  1866.     "Non-nil means print quoted forms with reader syntax.\n\
  1867. I.e., (quote foo) prints as 'foo, (function foo) as #'foo, and, backquoted\n\
  1868. forms print in the new syntax.");
  1869.   print_quoted = 0;
  1870.  
  1871.   DEFVAR_LISP ("print-gensym", &Vprint_gensym,
  1872.     "Non-nil means print uninterned symbols so they will read as uninterned.\n\
  1873. I.e., the value of (make-symbol \"foobar\") prints as #:foobar.\n\
  1874. When the uninterned symbol appears within a larger data structure,\n\
  1875. in addition use the #...# and #...= constructs as needed,\n\
  1876. so that multiple references to the same symbol are shared once again\n\
  1877. when the text is read back.\n\
  1878. \n\
  1879. If the value of `print-gensym' is a cons cell, then in addition refrain from\n\
  1880. clearing `print-gensym-alist' on entry to and exit from printing functions,\n\
  1881. so that the use of #...# and #...= can carry over for several separately\n\
  1882. printed objects.");
  1883.   Vprint_gensym = Qnil;
  1884.  
  1885.   DEFVAR_LISP ("print-gensym-alist", &Vprint_gensym_alist,
  1886.     "Association list of elements (GENSYM . N) to guide use of #N# and #N=.\n\
  1887. In each element, GENSYM is an uninterned symbol that has been associated\n\
  1888. with #N= for the specified value of N.");
  1889.   Vprint_gensym_alist = Qnil;
  1890.  
  1891.   /* prin1_to_string_buffer initialized in init_buffer_once in buffer.c */
  1892.   staticpro (&Vprin1_to_string_buffer);
  1893.  
  1894.   defsubr (&Sprin1);
  1895.   defsubr (&Sprin1_to_string);
  1896.   defsubr (&Serror_message_string);
  1897.   defsubr (&Sprinc);
  1898.   defsubr (&Sprint);
  1899.   defsubr (&Sterpri);
  1900.   defsubr (&Swrite_char);
  1901.   defsubr (&Sexternal_debugging_output);
  1902.  
  1903.   Qexternal_debugging_output = intern ("external-debugging-output");
  1904.   staticpro (&Qexternal_debugging_output);
  1905.  
  1906.   Qprint_escape_newlines = intern ("print-escape-newlines");
  1907.   staticpro (&Qprint_escape_newlines);
  1908.  
  1909.   Qprint_escape_multibyte = intern ("print-escape-multibyte");
  1910.   staticpro (&Qprint_escape_multibyte);
  1911.  
  1912.   Qprint_escape_nonascii = intern ("print-escape-nonascii");
  1913.   staticpro (&Qprint_escape_nonascii);
  1914.  
  1915. #ifndef standalone
  1916.   defsubr (&Swith_output_to_temp_buffer);
  1917. #endif /* not standalone */
  1918. }
  1919.