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

  1. /* Lisp parsing and input streams.
  2.    Copyright (C) 1985, 86, 87, 88, 89, 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. /* Modified for emx by Jeremy Bowen, May 1999 based on patches
  23.    to v19.33 by Eberhard Mattes */
  24.  
  25. #include <config.h>
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include <sys/file.h>
  30. #include <errno.h>
  31. #include "lisp.h"
  32.  
  33. #ifndef standalone
  34. #include "buffer.h"
  35. #include "charset.h"
  36. #include <paths.h>
  37. #include "commands.h"
  38. #include "keyboard.h"
  39. #include "termhooks.h"
  40. #endif
  41.  
  42. #ifdef lint
  43. #include <sys/inode.h>
  44. #endif /* lint */
  45.  
  46. #ifdef MSDOS
  47. #if __DJGPP__ < 2
  48. #include <unistd.h>    /* to get X_OK */
  49. #endif
  50. #include "msdos.h"
  51. #endif
  52.  
  53. #ifdef HAVE_UNISTD_H
  54. #include <unistd.h>
  55. #endif
  56.  
  57. #ifndef X_OK
  58. #define X_OK 01
  59. #endif
  60.  
  61. #ifdef LISP_FLOAT_TYPE
  62. #ifdef STDC_HEADERS
  63. #include <stdlib.h>
  64. #endif
  65.  
  66. #include <math.h>
  67. #endif /* LISP_FLOAT_TYPE */
  68.  
  69. #ifdef HAVE_SETLOCALE
  70. #include <locale.h>
  71. #endif /* HAVE_SETLOCALE */
  72.  
  73. #ifndef O_RDONLY
  74. #define O_RDONLY 0
  75. #endif
  76.  
  77. extern int errno;
  78.  
  79. Lisp_Object Qread_char, Qget_file_char, Qstandard_input, Qcurrent_load_list;
  80. Lisp_Object Qvariable_documentation, Vvalues, Vstandard_input, Vafter_load_alist;
  81. Lisp_Object Qascii_character, Qload, Qload_file_name;
  82. Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
  83. Lisp_Object Qinhibit_file_name_operation;
  84.  
  85. extern Lisp_Object Qevent_symbol_element_mask;
  86. extern Lisp_Object Qfile_exists_p;
  87.  
  88. /* non-zero if inside `load' */
  89. int load_in_progress;
  90.  
  91. /* Directory in which the sources were found.  */
  92. Lisp_Object Vsource_directory;
  93.  
  94. /* Search path for files to be loaded. */
  95. Lisp_Object Vload_path;
  96.  
  97. /* This is the user-visible association list that maps features to
  98.    lists of defs in their load files. */
  99. Lisp_Object Vload_history;
  100.  
  101. /* This is used to build the load history. */
  102. Lisp_Object Vcurrent_load_list;
  103.  
  104. #ifdef EMX
  105. /* Try replacing `-' with `_' in `load' if this is non-zero. */
  106. int emx_cdrom_load;
  107. #endif /* EMX */
  108.  
  109. /* List of files that were preloaded.  */
  110. Lisp_Object Vpreloaded_file_list;
  111.  
  112. /* Name of file actually being read by `load'.  */
  113. Lisp_Object Vload_file_name;
  114.  
  115. /* Function to use for reading, in `load' and friends.  */
  116. Lisp_Object Vload_read_function;
  117.  
  118. /* The association list of objects read with the #n=object form.
  119.    Each member of the list has the form (n . object), and is used to
  120.    look up the object for the corresponding #n# construct.
  121.    It must be set to nil before all top-level calls to read0.  */
  122. Lisp_Object read_objects;
  123.  
  124. /* Nonzero means load should forcibly load all dynamic doc strings.  */
  125. static int load_force_doc_strings;
  126.  
  127. /* Nonzero means read should convert strings to unibyte.  */
  128. static int load_convert_to_unibyte;
  129.  
  130. /* Function to use for loading an Emacs lisp source file (not
  131.    compiled) instead of readevalloop.  */
  132. Lisp_Object Vload_source_file_function;
  133.  
  134. /* List of descriptors now open for Fload.  */
  135. static Lisp_Object load_descriptor_list;
  136.  
  137. /* File for get_file_char to read from.  Use by load.  */
  138. static FILE *instream;
  139.  
  140. /* When nonzero, read conses in pure space */
  141. static int read_pure;
  142.  
  143. /* For use within read-from-string (this reader is non-reentrant!!)  */
  144. static int read_from_string_index;
  145. static int read_from_string_index_byte;
  146. static int read_from_string_limit;
  147.  
  148. /* Number of bytes left to read in the buffer character
  149.    that `readchar' has already advanced over.  */
  150. static int readchar_backlog;
  151.  
  152. /* This contains the last string skipped with #@.  */
  153. static char *saved_doc_string;
  154. /* Length of buffer allocated in saved_doc_string.  */
  155. static int saved_doc_string_size;
  156. /* Length of actual data in saved_doc_string.  */
  157. static int saved_doc_string_length;
  158. /* This is the file position that string came from.  */
  159. static int saved_doc_string_position;
  160.  
  161. /* This contains the previous string skipped with #@.
  162.    We copy it from saved_doc_string when a new string
  163.    is put in saved_doc_string.  */
  164. static char *prev_saved_doc_string;
  165. /* Length of buffer allocated in prev_saved_doc_string.  */
  166. static int prev_saved_doc_string_size;
  167. /* Length of actual data in prev_saved_doc_string.  */
  168. static int prev_saved_doc_string_length;
  169. /* This is the file position that string came from.  */
  170. static int prev_saved_doc_string_position;
  171.  
  172. /* Nonzero means inside a new-style backquote
  173.    with no surrounding parentheses.
  174.    Fread initializes this to zero, so we need not specbind it
  175.    or worry about what happens to it when there is an error.  */
  176. static int new_backquote_flag;
  177.  
  178. /* Handle unreading and rereading of characters.
  179.    Write READCHAR to read a character,
  180.    UNREAD(c) to unread c to be read again.
  181.  
  182.    These macros actually read/unread a byte code, multibyte characters
  183.    are not handled here.  The caller should manage them if necessary.
  184.  */
  185.  
  186. #define READCHAR readchar (readcharfun)
  187. #define UNREAD(c) unreadchar (readcharfun, c)
  188.  
  189. static int
  190. readchar (readcharfun)
  191.      Lisp_Object readcharfun;
  192. {
  193.   Lisp_Object tem;
  194.   register int c, mpos;
  195.  
  196.   if (BUFFERP (readcharfun))
  197.     {
  198.       register struct buffer *inbuffer = XBUFFER (readcharfun);
  199.  
  200.       int pt_byte = BUF_PT_BYTE (inbuffer);
  201.       int orig_pt_byte = pt_byte;
  202.  
  203.       if (readchar_backlog > 0)
  204.     /* We get the address of the byte just passed,
  205.        which is the last byte of the character.
  206.        The other bytes in this character are consecutive with it,
  207.        because the gap can't be in the middle of a character.  */
  208.     return *(BUF_BYTE_ADDRESS (inbuffer, BUF_PT_BYTE (inbuffer) - 1)
  209.          - --readchar_backlog);
  210.  
  211.       if (pt_byte >= BUF_ZV_BYTE (inbuffer))
  212.     return -1;
  213.  
  214.       readchar_backlog = -1;
  215.  
  216.       if (! NILP (inbuffer->enable_multibyte_characters))
  217.     {
  218.       unsigned char workbuf[4];
  219.       unsigned char *str = workbuf;
  220.       int length;
  221.  
  222.       /* Fetch the character code from the buffer.  */
  223.       unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
  224.       BUF_INC_POS (inbuffer, pt_byte);
  225.       c = STRING_CHAR (p, pt_byte - orig_pt_byte);
  226.  
  227.       /* Find the byte-sequence representation of that character.  */
  228.       if (SINGLE_BYTE_CHAR_P (c))
  229.         length = 1, workbuf[0] = c;
  230.       else
  231.         length = non_ascii_char_to_string (c, workbuf, &str);
  232.  
  233.       /* If the bytes for this character in the buffer
  234.          are not identical with what the character code implies,
  235.          read the bytes one by one from the buffer.  */
  236.       if (length != pt_byte - orig_pt_byte
  237.           || (length == 1 ? *str != *p : bcmp (str, p, length)))
  238.         {
  239.           readchar_backlog = pt_byte - orig_pt_byte;
  240.           c = BUF_FETCH_BYTE (inbuffer, orig_pt_byte);
  241.           readchar_backlog--;
  242.         }
  243.     }
  244.       else
  245.     {
  246.       c = BUF_FETCH_BYTE (inbuffer, pt_byte);
  247.       pt_byte++;
  248.     }
  249.       SET_BUF_PT_BOTH (inbuffer, BUF_PT (inbuffer) + 1, pt_byte);
  250.  
  251.       return c;
  252.     }
  253.   if (MARKERP (readcharfun))
  254.     {
  255.       register struct buffer *inbuffer = XMARKER (readcharfun)->buffer;
  256.  
  257.       int bytepos = marker_byte_position (readcharfun);
  258.       int orig_bytepos = bytepos;
  259.  
  260.       if (readchar_backlog > 0)
  261.     /* We get the address of the byte just passed,
  262.        which is the last byte of the character.
  263.        The other bytes in this character are consecutive with it,
  264.        because the gap can't be in the middle of a character.  */
  265.     return *(BUF_BYTE_ADDRESS (inbuffer, XMARKER (readcharfun)->bytepos - 1)
  266.          - --readchar_backlog);
  267.  
  268.       if (bytepos >= BUF_ZV_BYTE (inbuffer))
  269.     return -1;
  270.  
  271.       readchar_backlog = -1;
  272.  
  273.       if (! NILP (inbuffer->enable_multibyte_characters))
  274.     {
  275.       unsigned char workbuf[4];
  276.       unsigned char *str = workbuf;
  277.       int length;
  278.  
  279.       /* Fetch the character code from the buffer.  */
  280.       unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
  281.       BUF_INC_POS (inbuffer, bytepos);
  282.       c = STRING_CHAR (p, bytepos - orig_bytepos);
  283.  
  284.       /* Find the byte-sequence representation of that character.  */
  285.       if (SINGLE_BYTE_CHAR_P (c))
  286.         length = 1, workbuf[0] = c;
  287.       else
  288.         length = non_ascii_char_to_string (c, workbuf, &str);
  289.  
  290.       /* If the bytes for this character in the buffer
  291.          are not identical with what the character code implies,
  292.          read the bytes one by one from the buffer.  */
  293.       if (length != bytepos - orig_bytepos
  294.           || (length == 1 ? *str != *p : bcmp (str, p, length)))
  295.         {
  296.           readchar_backlog = bytepos - orig_bytepos;
  297.           c = BUF_FETCH_BYTE (inbuffer, orig_bytepos);
  298.           readchar_backlog--;
  299.         }
  300.     }
  301.       else
  302.     {
  303.       c = BUF_FETCH_BYTE (inbuffer, bytepos);
  304.       bytepos++;
  305.     }
  306.  
  307.       XMARKER (readcharfun)->bytepos = bytepos;
  308.       XMARKER (readcharfun)->charpos++;
  309.  
  310.       return c;
  311.     }
  312.  
  313.   if (EQ (readcharfun, Qlambda))
  314.     return read_bytecode_char (0);
  315.  
  316.   if (EQ (readcharfun, Qget_file_char))
  317.     {
  318.       c = getc (instream);
  319. #ifdef EINTR
  320.       /* Interrupted reads have been observed while reading over the network */
  321.       while (c == EOF && ferror (instream) && errno == EINTR)
  322.     {
  323.       clearerr (instream);
  324.       c = getc (instream);
  325.     }
  326. #endif
  327.       return c;
  328.     }
  329.  
  330.   if (STRINGP (readcharfun))
  331.     {
  332.       if (read_from_string_index >= read_from_string_limit)
  333.     c = -1;
  334.       else if (STRING_MULTIBYTE (readcharfun))
  335.     FETCH_STRING_CHAR_ADVANCE (c, readcharfun,
  336.                    read_from_string_index,
  337.                    read_from_string_index_byte);
  338.       else
  339.     c = XSTRING (readcharfun)->data[read_from_string_index++];
  340.  
  341.       return c;
  342.     }
  343.  
  344.   tem = call0 (readcharfun);
  345.  
  346.   if (NILP (tem))
  347.     return -1;
  348.   return XINT (tem);
  349. }
  350.  
  351. /* Unread the character C in the way appropriate for the stream READCHARFUN.
  352.    If the stream is a user function, call it with the char as argument.  */
  353.  
  354. static void
  355. unreadchar (readcharfun, c)
  356.      Lisp_Object readcharfun;
  357.      int c;
  358. {
  359.   if (c == -1)
  360.     /* Don't back up the pointer if we're unreading the end-of-input mark,
  361.        since readchar didn't advance it when we read it.  */
  362.     ;
  363.   else if (BUFFERP (readcharfun))
  364.     {
  365.       struct buffer *b = XBUFFER (readcharfun);
  366.       int bytepos = BUF_PT_BYTE (b);
  367.  
  368.       if (readchar_backlog >= 0)
  369.     readchar_backlog++;
  370.       else
  371.     {
  372.       BUF_PT (b)--;
  373.       if (! NILP (b->enable_multibyte_characters))
  374.         BUF_DEC_POS (b, bytepos);
  375.       else
  376.         bytepos--;
  377.  
  378.       BUF_PT_BYTE (b) = bytepos;
  379.     }
  380.     }
  381.   else if (MARKERP (readcharfun))
  382.     {
  383.       struct buffer *b = XMARKER (readcharfun)->buffer;
  384.       int bytepos = XMARKER (readcharfun)->bytepos;
  385.  
  386.       if (readchar_backlog >= 0)
  387.     readchar_backlog++;
  388.       else
  389.     {
  390.       XMARKER (readcharfun)->charpos--;
  391.       if (! NILP (b->enable_multibyte_characters))
  392.         BUF_DEC_POS (b, bytepos);
  393.       else
  394.         bytepos--;
  395.  
  396.       XMARKER (readcharfun)->bytepos = bytepos;
  397.     }
  398.     }
  399.   else if (STRINGP (readcharfun))
  400.     {
  401.       read_from_string_index--;
  402.       read_from_string_index_byte
  403.     = string_char_to_byte (readcharfun, read_from_string_index);
  404.     }
  405.   else if (EQ (readcharfun, Qlambda))
  406.     read_bytecode_char (1);
  407.   else if (EQ (readcharfun, Qget_file_char))
  408.     ungetc (c, instream);
  409.   else
  410.     call1 (readcharfun, make_number (c));
  411. }
  412.  
  413. static Lisp_Object read0 (), read1 (), read_list (), read_vector ();
  414. static int read_multibyte ();
  415.  
  416. /* Get a character from the tty.  */
  417.  
  418. extern Lisp_Object read_char ();
  419.  
  420. /* Read input events until we get one that's acceptable for our purposes.
  421.  
  422.    If NO_SWITCH_FRAME is non-zero, switch-frame events are stashed
  423.    until we get a character we like, and then stuffed into
  424.    unread_switch_frame.
  425.  
  426.    If ASCII_REQUIRED is non-zero, we check function key events to see
  427.    if the unmodified version of the symbol has a Qascii_character
  428.    property, and use that character, if present.
  429.  
  430.    If ERROR_NONASCII is non-zero, we signal an error if the input we
  431.    get isn't an ASCII character with modifiers.  If it's zero but
  432.    ASCII_REQUIRED is non-zero, we just re-read until we get an ASCII
  433.    character.
  434.  
  435.    If INPUT_METHOD is nonzero, we invoke the current input method
  436.    if the character warrants that.  */
  437.  
  438. Lisp_Object
  439. read_filtered_event (no_switch_frame, ascii_required, error_nonascii,
  440.              input_method)
  441.      int no_switch_frame, ascii_required, error_nonascii, input_method;
  442. {
  443. #ifdef standalone
  444.   return make_number (getchar ());
  445. #else
  446.   register Lisp_Object val, delayed_switch_frame;
  447.  
  448.   delayed_switch_frame = Qnil;
  449.  
  450.   /* Read until we get an acceptable event.  */
  451.  retry:
  452.   val = read_char (0, 0, 0,
  453.            (input_method ? Qnil : Qt),
  454.            0);
  455.  
  456.   if (BUFFERP (val))
  457.     goto retry;
  458.  
  459.   /* switch-frame events are put off until after the next ASCII
  460.      character.  This is better than signaling an error just because
  461.      the last characters were typed to a separate minibuffer frame,
  462.      for example.  Eventually, some code which can deal with
  463.      switch-frame events will read it and process it.  */
  464.   if (no_switch_frame
  465.       && EVENT_HAS_PARAMETERS (val)
  466.       && EQ (EVENT_HEAD (val), Qswitch_frame))
  467.     {
  468.       delayed_switch_frame = val;
  469.       goto retry;
  470.     }
  471.  
  472.   if (ascii_required)
  473.     {
  474.       /* Convert certain symbols to their ASCII equivalents.  */
  475.       if (SYMBOLP (val))
  476.     {
  477.       Lisp_Object tem, tem1, tem2;
  478.       tem = Fget (val, Qevent_symbol_element_mask);
  479.       if (!NILP (tem))
  480.         {
  481.           tem1 = Fget (Fcar (tem), Qascii_character);
  482.           /* Merge this symbol's modifier bits
  483.          with the ASCII equivalent of its basic code.  */
  484.           if (!NILP (tem1))
  485.         XSETFASTINT (val, XINT (tem1) | XINT (Fcar (Fcdr (tem))));
  486.         }
  487.     }
  488.       
  489.       /* If we don't have a character now, deal with it appropriately.  */
  490.       if (!INTEGERP (val))
  491.     {
  492.       if (error_nonascii)
  493.         {
  494.           Vunread_command_events = Fcons (val, Qnil);
  495.           error ("Non-character input-event");
  496.         }
  497.       else
  498.         goto retry;
  499.     }
  500.     }
  501.  
  502.   if (! NILP (delayed_switch_frame))
  503.     unread_switch_frame = delayed_switch_frame;
  504.  
  505.   return val;
  506. #endif
  507. }
  508.  
  509. DEFUN ("read-char", Fread_char, Sread_char, 0, 2, 0,
  510.   "Read a character from the command input (keyboard or macro).\n\
  511. It is returned as a number.\n\
  512. If the user generates an event which is not a character (i.e. a mouse\n\
  513. click or function key event), `read-char' signals an error.  As an\n\
  514. exception, switch-frame events are put off until non-ASCII events can\n\
  515. be read.\n\
  516. If you want to read non-character events, or ignore them, call\n\
  517. `read-event' or `read-char-exclusive' instead.\n\
  518. \n\
  519. If the optional argument PROMPT is non-nil, display that as a prompt.\n\
  520. If the optional argument SUPPRESS-INPUT-METHOD is non-nil,\n\
  521. disable input method processing for this character.")
  522.   (prompt, suppress_input_method)
  523.      Lisp_Object prompt, suppress_input_method;
  524. {
  525.   if (! NILP (prompt))
  526.     message_with_string ("%s", prompt, 0);
  527.   return read_filtered_event (1, 1, 1, NILP (suppress_input_method));
  528. }
  529.  
  530. DEFUN ("read-event", Fread_event, Sread_event, 0, 2, 0,
  531.   "Read an event object from the input stream.\n\
  532. If the optional argument PROMPT is non-nil, display that as a prompt.\n\
  533. If the optional argument SUPPRESS-INPUT-METHOD is non-nil,\n\
  534. disable input method processing for this character.")
  535.   (prompt, suppress_input_method)
  536.      Lisp_Object prompt, suppress_input_method;
  537. {
  538.   if (! NILP (prompt))
  539.     message_with_string ("%s", prompt, 0);
  540.   return read_filtered_event (0, 0, 0, NILP (suppress_input_method));
  541. }
  542.  
  543. DEFUN ("read-char-exclusive", Fread_char_exclusive, Sread_char_exclusive, 0, 2, 0,
  544.   "Read a character from the command input (keyboard or macro).\n\
  545. It is returned as a number.  Non-character events are ignored.\n\
  546. \n\
  547. If the optional argument PROMPT is non-nil, display that as a prompt.\n\
  548. If the optional argument SUPPRESS-INPUT-METHOD is non-nil,\n\
  549. disable input method processing for this character.")
  550.   (prompt, suppress_input_method)
  551.      Lisp_Object prompt, suppress_input_method;
  552. {
  553.   if (! NILP (prompt))
  554.     message_with_string ("%s", prompt, 0);
  555.   return read_filtered_event (1, 1, 0, NILP (suppress_input_method));
  556. }
  557.  
  558. DEFUN ("get-file-char", Fget_file_char, Sget_file_char, 0, 0, 0,
  559.   "Don't use this yourself.")
  560.   ()
  561. {
  562.   register Lisp_Object val;
  563.   XSETINT (val, getc (instream));
  564.   return val;
  565. }
  566.  
  567. static void readevalloop ();
  568. static Lisp_Object load_unwind ();
  569. static Lisp_Object load_descriptor_unwind ();
  570.  
  571. DEFUN ("load", Fload, Sload, 1, 5, 0,
  572.   "Execute a file of Lisp code named FILE.\n\
  573. First try FILE with `.elc' appended, then try with `.el',\n\
  574.  then try FILE unmodified.\n\
  575. This function searches the directories in `load-path'.\n\
  576. If optional second arg NOERROR is non-nil,\n\
  577.  report no error if FILE doesn't exist.\n\
  578. Print messages at start and end of loading unless\n\
  579.  optional third arg NOMESSAGE is non-nil.\n\
  580. If optional fourth arg NOSUFFIX is non-nil, don't try adding\n\
  581.  suffixes `.elc' or `.el' to the specified name FILE.\n\
  582. If optional fifth arg MUST-SUFFIX is non-nil, insist on\n\
  583.  the suffix `.elc' or `.el'; don't accept just FILE unless\n\
  584.  it ends in one of those suffixes or includes a directory name.\n\
  585. Return t if file exists.")
  586.   (file, noerror, nomessage, nosuffix, must_suffix)
  587.      Lisp_Object file, noerror, nomessage, nosuffix, must_suffix;
  588. {
  589.   register FILE *stream;
  590.   register int fd = -1;
  591.   register Lisp_Object lispstream;
  592.   int count = specpdl_ptr - specpdl;
  593.   Lisp_Object temp;
  594.   struct gcpro gcpro1;
  595.   Lisp_Object found;
  596.   /* 1 means we printed the ".el is newer" message.  */
  597.   int newer = 0;
  598.   /* 1 means we are loading a compiled file.  */
  599.   int compiled = 0;
  600.   Lisp_Object handler;
  601.   char *fmode = "r";
  602. #ifdef DOS_NT
  603.   fmode = "rt";
  604. #endif /* DOS_NT */
  605.  
  606.   CHECK_STRING (file, 0);
  607.  
  608.   /* If file name is magic, call the handler.  */
  609.   handler = Ffind_file_name_handler (file, Qload);
  610.   if (!NILP (handler))
  611.     return call5 (handler, Qload, file, noerror, nomessage, nosuffix);
  612.  
  613.   /* Do this after the handler to avoid
  614.      the need to gcpro noerror, nomessage and nosuffix.
  615.      (Below here, we care only whether they are nil or not.)  */
  616.   file = Fsubstitute_in_file_name (file);
  617.  
  618.   /* Avoid weird lossage with null string as arg,
  619.      since it would try to load a directory as a Lisp file */
  620.   if (XSTRING (file)->size > 0)
  621.     {
  622.       int size = XSTRING (file)->size;
  623.  
  624.       GCPRO1 (file);
  625.  
  626.       if (! NILP (must_suffix))
  627.     {
  628.       /* Don't insist on adding a suffix if FILE already ends with one.  */
  629.       if (size > 3
  630.           && !strcmp (XSTRING (file)->data + size - 3, ".el"))
  631.         must_suffix = Qnil;
  632.       else if (size > 4
  633.            && !strcmp (XSTRING (file)->data + size - 4, ".elc"))
  634.         must_suffix = Qnil;
  635.       /* Don't insist on adding a suffix
  636.          if the argument includes a directory name.  */
  637.       else if (! NILP (Ffile_name_directory (file)))
  638.         must_suffix = Qnil;
  639.     }
  640.  
  641.       fd = openp (Vload_path, file,
  642.           (!NILP (nosuffix) ? ""
  643.            : ! NILP (must_suffix) ? ".elc:.el"
  644.            : ".elc:.el:"),
  645.           &found, 0);
  646. #ifdef EMX
  647.       /* If the file was not found and emx-cdrom-load is non-nil, try
  648.          again, replacing `-' with `_'. */
  649.       if (fd < 0 && emx_cdrom_load)
  650.         {
  651.           int len = XSTRING (file)->size;
  652.           char *new_file = alloca (len + 1);
  653.           int i, ok = 0;
  654.  
  655.           memcpy (new_file, XSTRING (file)->data, len);
  656.           new_file[len] = 0;
  657.           for (i = 0; i < len; ++i)
  658.             if (new_file[i] == '-')
  659.               {
  660.                 new_file[i] = '_'; ok = 1;
  661.               }
  662.           if (ok)
  663.             fd = openp (Vload_path, build_string (new_file),
  664.                         !NILP (nosuffix) ? "" : ".elc:.el:", &found, 0);
  665.         }
  666. #endif /* EMX */
  667.       UNGCPRO;
  668.     }
  669.  
  670.   if (fd < 0)
  671.     {
  672.       if (NILP (noerror))
  673.     while (1)
  674.       Fsignal (Qfile_error, Fcons (build_string ("Cannot open load file"),
  675.                        Fcons (file, Qnil)));
  676.       else
  677.     return Qnil;
  678.     }
  679.  
  680.   /* If FD is 0, that means openp found a remote file.  */
  681.   if (fd == 0)
  682.     {
  683.       handler = Ffind_file_name_handler (found, Qload);
  684.       return call5 (handler, Qload, found, noerror, nomessage, Qt);
  685.     }
  686.  
  687.   if (!bcmp (&(XSTRING (found)->data[XSTRING (found)->size - 4]),
  688.          ".elc", 4))
  689.     {
  690.       struct stat s1, s2;
  691.       int result;
  692.  
  693.       compiled = 1;
  694.  
  695. #ifdef DOS_NT
  696.       fmode = "rb";
  697. #endif /* DOS_NT */
  698.       stat ((char *)XSTRING (found)->data, &s1);
  699.       XSTRING (found)->data[XSTRING (found)->size - 1] = 0;
  700.       result = stat ((char *)XSTRING (found)->data, &s2);
  701.       if (result >= 0 && (unsigned) s1.st_mtime < (unsigned) s2.st_mtime)
  702.     {
  703.       /* Make the progress messages mention that source is newer.  */
  704.       newer = 1;
  705.  
  706.       /* If we won't print another message, mention this anyway.  */
  707.       if (! NILP (nomessage))
  708.         message_with_string ("Source file `%s' newer than byte-compiled file",
  709.                  found, 1);
  710.     }
  711.       XSTRING (found)->data[XSTRING (found)->size - 1] = 'c';
  712.     }
  713.   else
  714.     {
  715.       /* We are loading a source file (*.el).  */
  716.       if (!NILP (Vload_source_file_function))
  717.     {
  718.       close (fd);
  719.       return call4 (Vload_source_file_function, found, file,
  720.             NILP (noerror) ? Qnil : Qt,
  721.             NILP (nomessage) ? Qnil : Qt);
  722.     }
  723.     }
  724.  
  725. #ifdef WINDOWSNT
  726.   close (fd);
  727.   stream = fopen ((char *) XSTRING (found)->data, fmode);
  728. #else  /* not WINDOWSNT */
  729.   stream = fdopen (fd, fmode);
  730. #endif /* not WINDOWSNT */
  731.   if (stream == 0)
  732.     {
  733.       close (fd);
  734.       error ("Failure to create stdio stream for %s", XSTRING (file)->data);
  735.     }
  736.  
  737.   if (! NILP (Vpurify_flag))
  738.     Vpreloaded_file_list = Fcons (file, Vpreloaded_file_list);
  739.  
  740.   if (NILP (nomessage))
  741.     {
  742.       if (!compiled)
  743.     message_with_string ("Loading %s (source)...", file, 1);
  744.       else if (newer)
  745.     message_with_string ("Loading %s (compiled; note, source file is newer)...",
  746.          file, 1);
  747.       else /* The typical case; compiled file newer than source file.  */
  748.     message_with_string ("Loading %s...", file, 1);
  749.     }
  750.  
  751.   GCPRO1 (file);
  752.   lispstream = Fcons (Qnil, Qnil);
  753.   XSETFASTINT (XCONS (lispstream)->car, (EMACS_UINT)stream >> 16);
  754.   XSETFASTINT (XCONS (lispstream)->cdr, (EMACS_UINT)stream & 0xffff);
  755.   record_unwind_protect (load_unwind, lispstream);
  756.   record_unwind_protect (load_descriptor_unwind, load_descriptor_list);
  757.   specbind (Qload_file_name, found);
  758.   specbind (Qinhibit_file_name_operation, Qnil);
  759.   load_descriptor_list
  760.     = Fcons (make_number (fileno (stream)), load_descriptor_list);
  761.   load_in_progress++;
  762.   readevalloop (Qget_file_char, stream, file, Feval, 0, Qnil, Qnil);
  763.   unbind_to (count, Qnil);
  764.  
  765.   /* Run any load-hooks for this file.  */
  766.   temp = Fassoc (file, Vafter_load_alist);
  767.   if (!NILP (temp))
  768.     Fprogn (Fcdr (temp));
  769.   UNGCPRO;
  770.  
  771.   if (saved_doc_string)
  772.     free (saved_doc_string);
  773.   saved_doc_string = 0;
  774.   saved_doc_string_size = 0;
  775.  
  776.   if (prev_saved_doc_string)
  777.     free (prev_saved_doc_string);
  778.   prev_saved_doc_string = 0;
  779.   prev_saved_doc_string_size = 0;
  780.  
  781.   if (!noninteractive && NILP (nomessage))
  782.     {
  783.       if (!compiled)
  784.     message_with_string ("Loading %s (source)...done", file, 1);
  785.       else if (newer)
  786.     message_with_string ("Loading %s (compiled; note, source file is newer)...done",
  787.          file, 1);
  788.       else /* The typical case; compiled file newer than source file.  */
  789.     message_with_string ("Loading %s...done", file, 1);
  790.     }
  791.   return Qt;
  792. }
  793.  
  794. static Lisp_Object
  795. load_unwind (stream)  /* used as unwind-protect function in load */
  796.      Lisp_Object stream;
  797. {
  798.   fclose ((FILE *) (XFASTINT (XCONS (stream)->car) << 16
  799.             | XFASTINT (XCONS (stream)->cdr)));
  800.   if (--load_in_progress < 0) load_in_progress = 0;
  801.   return Qnil;
  802. }
  803.  
  804. static Lisp_Object
  805. load_descriptor_unwind (oldlist)
  806.      Lisp_Object oldlist;
  807. {
  808.   load_descriptor_list = oldlist;
  809.   return Qnil;
  810. }
  811.  
  812. /* Close all descriptors in use for Floads.
  813.    This is used when starting a subprocess.  */
  814.  
  815. void
  816. close_load_descs ()
  817. {
  818. #ifndef WINDOWSNT
  819.   Lisp_Object tail;
  820.   for (tail = load_descriptor_list; !NILP (tail); tail = XCONS (tail)->cdr)
  821.     close (XFASTINT (XCONS (tail)->car));
  822. #endif
  823. }
  824.  
  825. static int
  826. complete_filename_p (pathname)
  827.      Lisp_Object pathname;
  828. {
  829.   register unsigned char *s = XSTRING (pathname)->data;
  830.   return (IS_DIRECTORY_SEP (s[0])
  831.       || (XSTRING (pathname)->size > 2
  832.           && IS_DEVICE_SEP (s[1]) && IS_DIRECTORY_SEP (s[2]))
  833. #ifdef ALTOS
  834.       || *s == '@'
  835. #endif
  836. #ifdef VMS
  837.       || index (s, ':')
  838. #endif /* VMS */
  839.       );
  840. }
  841.  
  842. /* Search for a file whose name is STR, looking in directories
  843.    in the Lisp list PATH, and trying suffixes from SUFFIX.
  844.    SUFFIX is a string containing possible suffixes separated by colons.
  845.    On success, returns a file descriptor.  On failure, returns -1.
  846.  
  847.    EXEC_ONLY nonzero means don't open the files,
  848.    just look for one that is executable.  In this case,
  849.    returns 1 on success.
  850.  
  851.    If STOREPTR is nonzero, it points to a slot where the name of
  852.    the file actually found should be stored as a Lisp string.
  853.    nil is stored there on failure.
  854.  
  855.    If the file we find is remote, return 0
  856.    but store the found remote file name in *STOREPTR.
  857.    We do not check for remote files if EXEC_ONLY is nonzero.  */
  858.  
  859. int
  860. openp (path, str, suffix, storeptr, exec_only)
  861.      Lisp_Object path, str;
  862.      char *suffix;
  863.      Lisp_Object *storeptr;
  864.      int exec_only;
  865. {
  866.   register int fd;
  867.   int fn_size = 100;
  868.   char buf[100];
  869.   register char *fn = buf;
  870.   int absolute = 0;
  871.   int want_size;
  872.   Lisp_Object filename;
  873.   struct stat st;
  874.   struct gcpro gcpro1;
  875.  
  876.   GCPRO1 (str);
  877.   if (storeptr)
  878.     *storeptr = Qnil;
  879.  
  880.   if (complete_filename_p (str))
  881.     absolute = 1;
  882.  
  883.   for (; !NILP (path); path = Fcdr (path))
  884.     {
  885.       char *nsuffix;
  886.  
  887.       filename = Fexpand_file_name (str, Fcar (path));
  888.       if (!complete_filename_p (filename))
  889.     /* If there are non-absolute elts in PATH (eg ".") */
  890.     /* Of course, this could conceivably lose if luser sets
  891.        default-directory to be something non-absolute... */
  892.     {
  893.       filename = Fexpand_file_name (filename, current_buffer->directory);
  894.       if (!complete_filename_p (filename))
  895.         /* Give up on this path element! */
  896.         continue;
  897.     }
  898.  
  899.       /* Calculate maximum size of any filename made from
  900.      this path element/specified file name and any possible suffix.  */
  901.       want_size = strlen (suffix) + XSTRING (filename)->size + 1;
  902.       if (fn_size < want_size)
  903.     fn = (char *) alloca (fn_size = 100 + want_size);
  904.  
  905.       nsuffix = suffix;
  906.  
  907.       /* Loop over suffixes.  */
  908.       while (1)
  909.     {
  910.       char *esuffix = (char *) index (nsuffix, ':');
  911.       int lsuffix = esuffix ? esuffix - nsuffix : strlen (nsuffix);
  912.       Lisp_Object handler;
  913.  
  914.       /* Concatenate path element/specified name with the suffix.
  915.          If the directory starts with /:, remove that.  */
  916.       if (XSTRING (filename)->size > 2
  917.           && XSTRING (filename)->data[0] == '/'
  918.           && XSTRING (filename)->data[1] == ':')
  919.         {
  920.           strncpy (fn, XSTRING (filename)->data + 2,
  921.                XSTRING (filename)->size - 2);
  922.           fn[XSTRING (filename)->size - 2] = 0;
  923.         }
  924.       else
  925.         {
  926.           strncpy (fn, XSTRING (filename)->data, XSTRING (filename)->size);
  927.           fn[XSTRING (filename)->size] = 0;
  928.         }
  929.  
  930.       if (lsuffix != 0)  /* Bug happens on CCI if lsuffix is 0.  */
  931.         strncat (fn, nsuffix, lsuffix);
  932.  
  933.       /* Check that the file exists and is not a directory.  */
  934.       if (absolute)
  935.         handler = Qnil;
  936.       else
  937.         handler = Ffind_file_name_handler (filename, Qfile_exists_p);
  938.       if (! NILP (handler) && ! exec_only)
  939.         {
  940.           Lisp_Object string;
  941.           int exists;
  942.  
  943.           string = build_string (fn);
  944.           exists = ! NILP (exec_only ? Ffile_executable_p (string)
  945.                    : Ffile_readable_p (string));
  946.           if (exists
  947.           && ! NILP (Ffile_directory_p (build_string (fn))))
  948.         exists = 0;
  949.  
  950.           if (exists)
  951.         {
  952.           /* We succeeded; return this descriptor and filename.  */
  953.           if (storeptr)
  954.             *storeptr = build_string (fn);
  955.           UNGCPRO;
  956.           return 0;
  957.         }
  958.         }
  959.       else
  960.         {
  961.           int exists = (stat (fn, &st) >= 0
  962.                 && (st.st_mode & S_IFMT) != S_IFDIR);
  963.           if (exists)
  964.         {
  965.           /* Check that we can access or open it.  */
  966.           if (exec_only)
  967.             fd = (access (fn, X_OK) == 0) ? 1 : -1;
  968.           else
  969.             fd = open (fn, O_RDONLY, 0);
  970.  
  971.           if (fd >= 0)
  972.             {
  973.               /* We succeeded; return this descriptor and filename.  */
  974.               if (storeptr)
  975.             *storeptr = build_string (fn);
  976.               UNGCPRO;
  977.               return fd;
  978.             }
  979.         }
  980.         }
  981.  
  982.       /* Advance to next suffix.  */
  983.       if (esuffix == 0)
  984.         break;
  985.       nsuffix += lsuffix + 1;
  986.     }
  987.       if (absolute)
  988.     break;
  989.     }
  990.  
  991.   UNGCPRO;
  992.   return -1;
  993. }
  994.  
  995.  
  996. /* Merge the list we've accumulated of globals from the current input source
  997.    into the load_history variable.  The details depend on whether
  998.    the source has an associated file name or not. */
  999.  
  1000. static void
  1001. build_load_history (stream, source)
  1002.      FILE *stream;
  1003.      Lisp_Object source;
  1004. {
  1005.   register Lisp_Object tail, prev, newelt;
  1006.   register Lisp_Object tem, tem2;
  1007.   register int foundit, loading;
  1008.  
  1009.   /* Don't bother recording anything for preloaded files.  */
  1010.   if (!NILP (Vpurify_flag))
  1011.     return;
  1012.  
  1013.   loading = stream || !NARROWED;
  1014.  
  1015.   tail = Vload_history;
  1016.   prev = Qnil;
  1017.   foundit = 0;
  1018.   while (!NILP (tail))
  1019.     {
  1020.       tem = Fcar (tail);
  1021.  
  1022.       /* Find the feature's previous assoc list... */
  1023.       if (!NILP (Fequal (source, Fcar (tem))))
  1024.     {
  1025.       foundit = 1;
  1026.  
  1027.       /*  If we're loading, remove it. */
  1028.       if (loading)
  1029.         {      
  1030.           if (NILP (prev))
  1031.         Vload_history = Fcdr (tail);
  1032.           else
  1033.         Fsetcdr (prev, Fcdr (tail));
  1034.         }
  1035.  
  1036.       /*  Otherwise, cons on new symbols that are not already members.  */
  1037.       else
  1038.         {
  1039.           tem2 = Vcurrent_load_list;
  1040.  
  1041.           while (CONSP (tem2))
  1042.         {
  1043.           newelt = Fcar (tem2);
  1044.  
  1045.           if (NILP (Fmemq (newelt, tem)))
  1046.             Fsetcar (tail, Fcons (Fcar (tem),
  1047.                       Fcons (newelt, Fcdr (tem))));
  1048.  
  1049.           tem2 = Fcdr (tem2);
  1050.           QUIT;
  1051.         }
  1052.         }
  1053.     }
  1054.       else
  1055.     prev = tail;
  1056.       tail = Fcdr (tail);
  1057.       QUIT;
  1058.     }
  1059.  
  1060.   /* If we're loading, cons the new assoc onto the front of load-history,
  1061.      the most-recently-loaded position.  Also do this if we didn't find
  1062.      an existing member for the current source.  */
  1063.   if (loading || !foundit)
  1064.     Vload_history = Fcons (Fnreverse (Vcurrent_load_list),
  1065.                Vload_history);
  1066. }
  1067.  
  1068. Lisp_Object
  1069. unreadpure ()    /* Used as unwind-protect function in readevalloop */
  1070. {
  1071.   read_pure = 0;
  1072.   return Qnil;
  1073. }
  1074.  
  1075. static Lisp_Object
  1076. readevalloop_1 (old)
  1077.      Lisp_Object old;
  1078. {
  1079.   load_convert_to_unibyte = ! NILP (old);
  1080.   return Qnil;
  1081. }
  1082.  
  1083. /* UNIBYTE specifies how to set load_convert_to_unibyte
  1084.    for this invocation.
  1085.    READFUN, if non-nil, is used instead of `read'.  */
  1086.  
  1087. static void
  1088. readevalloop (readcharfun, stream, sourcename, evalfun, printflag, unibyte, readfun)
  1089.      Lisp_Object readcharfun;
  1090.      FILE *stream;
  1091.      Lisp_Object sourcename;
  1092.      Lisp_Object (*evalfun) ();
  1093.      int printflag;
  1094.      Lisp_Object unibyte, readfun;
  1095. {
  1096.   register int c;
  1097.   register Lisp_Object val;
  1098.   int count = specpdl_ptr - specpdl;
  1099.   struct gcpro gcpro1;
  1100.   struct buffer *b = 0;
  1101.  
  1102.   if (BUFFERP (readcharfun))
  1103.     b = XBUFFER (readcharfun);
  1104.   else if (MARKERP (readcharfun))
  1105.     b = XMARKER (readcharfun)->buffer;
  1106.  
  1107.   specbind (Qstandard_input, readcharfun);
  1108.   specbind (Qcurrent_load_list, Qnil);
  1109.   record_unwind_protect (readevalloop_1, load_convert_to_unibyte ? Qt : Qnil);
  1110.   load_convert_to_unibyte = !NILP (unibyte);
  1111.  
  1112.   readchar_backlog = -1;
  1113.  
  1114.   GCPRO1 (sourcename);
  1115.  
  1116.   LOADHIST_ATTACH (sourcename);
  1117.  
  1118.   while (1)
  1119.     {
  1120.       if (b != 0 && NILP (b->name))
  1121.     error ("Reading from killed buffer");
  1122.  
  1123.       instream = stream;
  1124.       c = READCHAR;
  1125.       if (c == ';')
  1126.     {
  1127.       while ((c = READCHAR) != '\n' && c != -1);
  1128.       continue;
  1129.     }
  1130.       if (c < 0) break;
  1131.  
  1132.       /* Ignore whitespace here, so we can detect eof.  */
  1133.       if (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\r')
  1134.     continue;
  1135.  
  1136.       if (!NILP (Vpurify_flag) && c == '(')
  1137.     {
  1138.       int count1 = specpdl_ptr - specpdl;
  1139.       record_unwind_protect (unreadpure, Qnil);
  1140.       val = read_list (-1, readcharfun);
  1141.       unbind_to (count1, Qnil);
  1142.     }
  1143.       else
  1144.     {
  1145.       UNREAD (c);
  1146.       read_objects = Qnil;
  1147.       if (! NILP (readfun))
  1148.         val = call1 (readfun, readcharfun);
  1149.       else if (! NILP (Vload_read_function))
  1150.         val = call1 (Vload_read_function, readcharfun);
  1151.       else
  1152.         val = read0 (readcharfun);
  1153.     }
  1154.  
  1155.       val = (*evalfun) (val);
  1156.       if (printflag)
  1157.     {
  1158.       Vvalues = Fcons (val, Vvalues);
  1159.       if (EQ (Vstandard_output, Qt))
  1160.         Fprin1 (val, Qnil);
  1161.       else
  1162.         Fprint (val, Qnil);
  1163.     }
  1164.     }
  1165.  
  1166.   build_load_history (stream, sourcename);
  1167.   UNGCPRO;
  1168.  
  1169.   unbind_to (count, Qnil);
  1170. }
  1171.  
  1172. #ifndef standalone
  1173.  
  1174. DEFUN ("eval-buffer", Feval_buffer, Seval_buffer, 0, 4, "",
  1175.   "Execute the current buffer as Lisp code.\n\
  1176. Programs can pass two arguments, BUFFER and PRINTFLAG.\n\
  1177. BUFFER is the buffer to evaluate (nil means use current buffer).\n\
  1178. PRINTFLAG controls printing of output:\n\
  1179. nil means discard it; anything else is stream for print.\n\
  1180. \n\
  1181. If the optional third argument FILENAME is non-nil,\n\
  1182. it specifies the file name to use for `load-history'.\n\
  1183. \n\
  1184. This function preserves the position of point.")
  1185.   (buffer, printflag, filename, unibyte)
  1186.      Lisp_Object buffer, printflag, filename, unibyte;
  1187. {
  1188.   int count = specpdl_ptr - specpdl;
  1189.   Lisp_Object tem, buf;
  1190.  
  1191.   if (NILP (buffer))
  1192.     buf = Fcurrent_buffer ();
  1193.   else
  1194.     buf = Fget_buffer (buffer);
  1195.   if (NILP (buf))
  1196.     error ("No such buffer");
  1197.  
  1198.   if (NILP (printflag))
  1199.     tem = Qsymbolp;
  1200.   else
  1201.     tem = printflag;
  1202.  
  1203.   if (NILP (filename))
  1204.     filename = XBUFFER (buf)->filename;
  1205.  
  1206.   specbind (Qstandard_output, tem);
  1207.   record_unwind_protect (save_excursion_restore, save_excursion_save ());
  1208.   BUF_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
  1209.   readevalloop (buf, 0, filename, Feval, !NILP (printflag), unibyte, Qnil);
  1210.   unbind_to (count, Qnil);
  1211.  
  1212.   return Qnil;
  1213. }
  1214.  
  1215. #if 0
  1216. XDEFUN ("eval-current-buffer", Feval_current_buffer, Seval_current_buffer, 0, 1, "",
  1217.   "Execute the current buffer as Lisp code.\n\
  1218. Programs can pass argument PRINTFLAG which controls printing of output:\n\
  1219. nil means discard it; anything else is stream for print.\n\
  1220. \n\
  1221. If there is no error, point does not move.  If there is an error,\n\
  1222. point remains at the end of the last character read from the buffer.")
  1223.   (printflag)
  1224.      Lisp_Object printflag;
  1225. {
  1226.   int count = specpdl_ptr - specpdl;
  1227.   Lisp_Object tem, cbuf;
  1228.  
  1229.   cbuf = Fcurrent_buffer ()
  1230.  
  1231.   if (NILP (printflag))
  1232.     tem = Qsymbolp;
  1233.   else
  1234.     tem = printflag;
  1235.   specbind (Qstandard_output, tem);
  1236.   record_unwind_protect (save_excursion_restore, save_excursion_save ());
  1237.   SET_PT (BEGV);
  1238.   readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
  1239.         !NILP (printflag), Qnil, Qnil);
  1240.   return unbind_to (count, Qnil);
  1241. }
  1242. #endif
  1243.  
  1244. DEFUN ("eval-region", Feval_region, Seval_region, 2, 4, "r",
  1245.   "Execute the region as Lisp code.\n\
  1246. When called from programs, expects two arguments,\n\
  1247. giving starting and ending indices in the current buffer\n\
  1248. of the text to be executed.\n\
  1249. Programs can pass third argument PRINTFLAG which controls output:\n\
  1250. nil means discard it; anything else is stream for printing it.\n\
  1251. Also the fourth argument READ-FUNCTION, if non-nil, is used\n\
  1252. instead of `read' to read each expression.  It gets one argument\n\
  1253. which is the input stream for reading characters.\n\
  1254. \n\
  1255. This function does not move point.")
  1256.   (start, end, printflag, read_function)
  1257.      Lisp_Object start, end, printflag, read_function;
  1258. {
  1259.   int count = specpdl_ptr - specpdl;
  1260.   Lisp_Object tem, cbuf;
  1261.  
  1262.   cbuf = Fcurrent_buffer ();
  1263.  
  1264.   if (NILP (printflag))
  1265.     tem = Qsymbolp;
  1266.   else
  1267.     tem = printflag;
  1268.   specbind (Qstandard_output, tem);
  1269.  
  1270.   if (NILP (printflag))
  1271.     record_unwind_protect (save_excursion_restore, save_excursion_save ());
  1272.   record_unwind_protect (save_restriction_restore, save_restriction_save ());
  1273.  
  1274.   /* This both uses start and checks its type.  */
  1275.   Fgoto_char (start);
  1276.   Fnarrow_to_region (make_number (BEGV), end);
  1277.   readevalloop (cbuf, 0, XBUFFER (cbuf)->filename, Feval,
  1278.         !NILP (printflag), Qnil, read_function);
  1279.  
  1280.   return unbind_to (count, Qnil);
  1281. }
  1282.  
  1283. #endif /* standalone */
  1284.  
  1285. DEFUN ("read", Fread, Sread, 0, 1, 0,
  1286.   "Read one Lisp expression as text from STREAM, return as Lisp object.\n\
  1287. If STREAM is nil, use the value of `standard-input' (which see).\n\
  1288. STREAM or the value of `standard-input' may be:\n\
  1289.  a buffer (read from point and advance it)\n\
  1290.  a marker (read from where it points and advance it)\n\
  1291.  a function (call it with no arguments for each character,\n\
  1292.      call it with a char as argument to push a char back)\n\
  1293.  a string (takes text from string, starting at the beginning)\n\
  1294.  t (read text line using minibuffer and use it).")
  1295.   (stream)
  1296.      Lisp_Object stream;
  1297. {
  1298.   extern Lisp_Object Fread_minibuffer ();
  1299.  
  1300.   if (NILP (stream))
  1301.     stream = Vstandard_input;
  1302.   if (EQ (stream, Qt))
  1303.     stream = Qread_char;
  1304.  
  1305.   readchar_backlog = -1;
  1306.   new_backquote_flag = 0;
  1307.   read_objects = Qnil;
  1308.  
  1309. #ifndef standalone
  1310.   if (EQ (stream, Qread_char))
  1311.     return Fread_minibuffer (build_string ("Lisp expression: "), Qnil);
  1312. #endif
  1313.  
  1314.   if (STRINGP (stream))
  1315.     return Fcar (Fread_from_string (stream, Qnil, Qnil));
  1316.  
  1317.   return read0 (stream);
  1318. }
  1319.  
  1320. DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
  1321.   "Read one Lisp expression which is represented as text by STRING.\n\
  1322. Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).\n\
  1323. START and END optionally delimit a substring of STRING from which to read;\n\
  1324.  they default to 0 and (length STRING) respectively.")
  1325.   (string, start, end)
  1326.      Lisp_Object string, start, end;
  1327. {
  1328.   int startval, endval;
  1329.   Lisp_Object tem;
  1330.  
  1331.   CHECK_STRING (string,0);
  1332.  
  1333.   if (NILP (end))
  1334.     endval = XSTRING (string)->size;
  1335.   else
  1336.     {
  1337.       CHECK_NUMBER (end, 2);
  1338.       endval = XINT (end);
  1339.       if (endval < 0 || endval > XSTRING (string)->size)
  1340.     args_out_of_range (string, end);
  1341.     }
  1342.  
  1343.   if (NILP (start))
  1344.     startval = 0;
  1345.   else
  1346.     {
  1347.       CHECK_NUMBER (start, 1);
  1348.       startval = XINT (start);
  1349.       if (startval < 0 || startval > endval)
  1350.     args_out_of_range (string, start);
  1351.     }
  1352.  
  1353.   read_from_string_index = startval;
  1354.   read_from_string_index_byte = string_char_to_byte (string, startval);
  1355.   read_from_string_limit = endval;
  1356.  
  1357.   new_backquote_flag = 0;
  1358.   read_objects = Qnil;
  1359.  
  1360.   tem = read0 (string);
  1361.   return Fcons (tem, make_number (read_from_string_index));
  1362. }
  1363.  
  1364. /* Use this for recursive reads, in contexts where internal tokens
  1365.    are not allowed. */
  1366.  
  1367. static Lisp_Object
  1368. read0 (readcharfun)
  1369.      Lisp_Object readcharfun;
  1370. {
  1371.   register Lisp_Object val;
  1372.   int c;
  1373.  
  1374.   val = read1 (readcharfun, &c, 0);
  1375.   if (c)
  1376.     Fsignal (Qinvalid_read_syntax, Fcons (Fmake_string (make_number (1),
  1377.                             make_number (c)),
  1378.                       Qnil));
  1379.  
  1380.   return val;
  1381. }
  1382.  
  1383. static int read_buffer_size;
  1384. static char *read_buffer;
  1385.  
  1386. /* Read multibyte form and return it as a character.  C is a first
  1387.    byte of multibyte form, and rest of them are read from
  1388.    READCHARFUN.  */
  1389.  
  1390. static int
  1391. read_multibyte (c, readcharfun)
  1392.      register int c;
  1393.      Lisp_Object readcharfun;
  1394. {
  1395.   /* We need the actual character code of this multibyte
  1396.      characters.  */
  1397.   unsigned char str[MAX_LENGTH_OF_MULTI_BYTE_FORM];
  1398.   int len = 0;
  1399.  
  1400.   str[len++] = c;
  1401.   while ((c = READCHAR) >= 0xA0
  1402.      && len < MAX_LENGTH_OF_MULTI_BYTE_FORM)
  1403.     str[len++] = c;
  1404.   UNREAD (c);
  1405.   return STRING_CHAR (str, len);
  1406. }
  1407.  
  1408. /* Read a \-escape sequence, assuming we already read the `\'.  */
  1409.  
  1410. static int
  1411. read_escape (readcharfun, stringp)
  1412.      Lisp_Object readcharfun;
  1413.      int stringp;
  1414. {
  1415.   register int c = READCHAR;
  1416.   switch (c)
  1417.     {
  1418.     case -1:
  1419.       error ("End of file");
  1420.  
  1421.     case 'a':
  1422.       return '\007';
  1423.     case 'b':
  1424.       return '\b';
  1425.     case 'd':
  1426.       return 0177;
  1427.     case 'e':
  1428.       return 033;
  1429.     case 'f':
  1430.       return '\f';
  1431.     case 'n':
  1432.       return '\n';
  1433.     case 'r':
  1434.       return '\r';
  1435.     case 't':
  1436.       return '\t';
  1437.     case 'v':
  1438.       return '\v';
  1439.     case '\n':
  1440.       return -1;
  1441.     case ' ':
  1442.       if (stringp)
  1443.     return -1;
  1444.       return ' ';
  1445.  
  1446.     case 'M':
  1447.       c = READCHAR;
  1448.       if (c != '-')
  1449.     error ("Invalid escape character syntax");
  1450.       c = READCHAR;
  1451.       if (c == '\\')
  1452.     c = read_escape (readcharfun, 0);
  1453.       return c | meta_modifier;
  1454.  
  1455.     case 'S':
  1456.       c = READCHAR;
  1457.       if (c != '-')
  1458.     error ("Invalid escape character syntax");
  1459.       c = READCHAR;
  1460.       if (c == '\\')
  1461.     c = read_escape (readcharfun, 0);
  1462.       return c | shift_modifier;
  1463.  
  1464.     case 'H':
  1465.       c = READCHAR;
  1466.       if (c != '-')
  1467.     error ("Invalid escape character syntax");
  1468.       c = READCHAR;
  1469.       if (c == '\\')
  1470.     c = read_escape (readcharfun, 0);
  1471.       return c | hyper_modifier;
  1472.  
  1473.     case 'A':
  1474.       c = READCHAR;
  1475.       if (c != '-')
  1476.     error ("Invalid escape character syntax");
  1477.       c = READCHAR;
  1478.       if (c == '\\')
  1479.     c = read_escape (readcharfun, 0);
  1480.       return c | alt_modifier;
  1481.  
  1482.     case 's':
  1483.       c = READCHAR;
  1484.       if (c != '-')
  1485.     error ("Invalid escape character syntax");
  1486.       c = READCHAR;
  1487.       if (c == '\\')
  1488.     c = read_escape (readcharfun, 0);
  1489.       return c | super_modifier;
  1490.  
  1491.     case 'C':
  1492.       c = READCHAR;
  1493.       if (c != '-')
  1494.     error ("Invalid escape character syntax");
  1495.     case '^':
  1496.       c = READCHAR;
  1497.       if (c == '\\')
  1498.     c = read_escape (readcharfun, 0);
  1499.       if ((c & 0177) == '?')
  1500.     return 0177 | c;
  1501.       /* ASCII control chars are made from letters (both cases),
  1502.      as well as the non-letters within 0100...0137.  */
  1503.       else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
  1504.     return (c & (037 | ~0177));
  1505.       else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
  1506.     return (c & (037 | ~0177));
  1507.       else
  1508.     return c | ctrl_modifier;
  1509.  
  1510.     case '0':
  1511.     case '1':
  1512.     case '2':
  1513.     case '3':
  1514.     case '4':
  1515.     case '5':
  1516.     case '6':
  1517.     case '7':
  1518.       /* An octal escape, as in ANSI C.  */
  1519.       {
  1520.     register int i = c - '0';
  1521.     register int count = 0;
  1522.     while (++count < 3)
  1523.       {
  1524.         if ((c = READCHAR) >= '0' && c <= '7')
  1525.           {
  1526.         i *= 8;
  1527.         i += c - '0';
  1528.           }
  1529.         else
  1530.           {
  1531.         UNREAD (c);
  1532.         break;
  1533.           }
  1534.       }
  1535.     return i;
  1536.       }
  1537.  
  1538.     case 'x':
  1539.       /* A hex escape, as in ANSI C.  */
  1540.       {
  1541.     int i = 0;
  1542.     while (1)
  1543.       {
  1544.         c = READCHAR;
  1545.         if (c >= '0' && c <= '9')
  1546.           {
  1547.         i *= 16;
  1548.         i += c - '0';
  1549.           }
  1550.         else if ((c >= 'a' && c <= 'f')
  1551.              || (c >= 'A' && c <= 'F'))
  1552.           {
  1553.         i *= 16;
  1554.         if (c >= 'a' && c <= 'f')
  1555.           i += c - 'a' + 10;
  1556.         else
  1557.           i += c - 'A' + 10;
  1558.           }
  1559.         else
  1560.           {
  1561.         UNREAD (c);
  1562.         break;
  1563.           }
  1564.       }
  1565.     return i;
  1566.       }
  1567.  
  1568.     default:
  1569.       if (BASE_LEADING_CODE_P (c))
  1570.     c = read_multibyte (c, readcharfun);
  1571.       return c;
  1572.     }
  1573. }
  1574.  
  1575. /* If the next token is ')' or ']' or '.', we store that character
  1576.    in *PCH and the return value is not interesting.  Else, we store
  1577.    zero in *PCH and we read and return one lisp object.
  1578.  
  1579.    FIRST_IN_LIST is nonzero if this is the first element of a list.  */
  1580.  
  1581. static Lisp_Object
  1582. read1 (readcharfun, pch, first_in_list)
  1583.      register Lisp_Object readcharfun;
  1584.      int *pch;
  1585.      int first_in_list;
  1586. {
  1587.   register int c;
  1588.   int uninterned_symbol = 0;
  1589.  
  1590.   *pch = 0;
  1591.  
  1592.  retry:
  1593.  
  1594.   c = READCHAR;
  1595.   if (c < 0) return Fsignal (Qend_of_file, Qnil);
  1596.  
  1597.   switch (c)
  1598.     {
  1599.     case '(':
  1600.       return read_list (0, readcharfun);
  1601.  
  1602.     case '[':
  1603.       return read_vector (readcharfun, 0);
  1604.  
  1605.     case ')':
  1606.     case ']':
  1607.       {
  1608.     *pch = c;
  1609.     return Qnil;
  1610.       }
  1611.  
  1612.     case '#':
  1613.       c = READCHAR;
  1614.       if (c == '^')
  1615.     {
  1616.       c = READCHAR;
  1617.       if (c == '[')
  1618.         {
  1619.           Lisp_Object tmp;
  1620.           tmp = read_vector (readcharfun, 0);
  1621.           if (XVECTOR (tmp)->size < CHAR_TABLE_STANDARD_SLOTS
  1622.           || XVECTOR (tmp)->size > CHAR_TABLE_STANDARD_SLOTS + 10)
  1623.         error ("Invalid size char-table");
  1624.           XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
  1625.           XCHAR_TABLE (tmp)->top = Qt;
  1626.           return tmp;
  1627.         }
  1628.       else if (c == '^')
  1629.         {
  1630.           c = READCHAR;
  1631.           if (c == '[')
  1632.         {
  1633.           Lisp_Object tmp;
  1634.           tmp = read_vector (readcharfun, 0);
  1635.           if (XVECTOR (tmp)->size != SUB_CHAR_TABLE_STANDARD_SLOTS)
  1636.             error ("Invalid size char-table");
  1637.           XSETCHAR_TABLE (tmp, XCHAR_TABLE (tmp));
  1638.           XCHAR_TABLE (tmp)->top = Qnil;
  1639.           return tmp;
  1640.         }
  1641.           Fsignal (Qinvalid_read_syntax,
  1642.                Fcons (make_string ("#^^", 3), Qnil));
  1643.         }
  1644.       Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#^", 2), Qnil));
  1645.     }
  1646.       if (c == '&')
  1647.     {
  1648.       Lisp_Object length;
  1649.       length = read1 (readcharfun, pch, first_in_list);
  1650.       c = READCHAR;
  1651.       if (c == '"')
  1652.         {
  1653.           Lisp_Object tmp, val;
  1654.           int size_in_chars = ((XFASTINT (length) + BITS_PER_CHAR - 1)
  1655.                    / BITS_PER_CHAR);
  1656.  
  1657.           UNREAD (c);
  1658.           tmp = read1 (readcharfun, pch, first_in_list);
  1659.           if (size_in_chars != XSTRING (tmp)->size
  1660.           /* We used to print 1 char too many
  1661.              when the number of bits was a multiple of 8.
  1662.              Accept such input in case it came from an old version.  */
  1663.           && ! (XFASTINT (length)
  1664.             == (XSTRING (tmp)->size - 1) * BITS_PER_CHAR))
  1665.         Fsignal (Qinvalid_read_syntax,
  1666.              Fcons (make_string ("#&...", 5), Qnil));
  1667.         
  1668.           val = Fmake_bool_vector (length, Qnil);
  1669.           bcopy (XSTRING (tmp)->data, XBOOL_VECTOR (val)->data,
  1670.              size_in_chars);
  1671.           /* Clear the extraneous bits in the last byte.  */
  1672.           if (XINT (length) != size_in_chars * BITS_PER_CHAR)
  1673.         XBOOL_VECTOR (val)->data[size_in_chars - 1]
  1674.           &= (1 << (XINT (length) % BITS_PER_CHAR)) - 1;
  1675.           return val;
  1676.         }
  1677.       Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#&...", 5),
  1678.                         Qnil));
  1679.     }
  1680.       if (c == '[')
  1681.     {
  1682.       /* Accept compiled functions at read-time so that we don't have to
  1683.          build them using function calls.  */
  1684.       Lisp_Object tmp;
  1685.       tmp = read_vector (readcharfun, 1);
  1686.       return Fmake_byte_code (XVECTOR (tmp)->size,
  1687.                   XVECTOR (tmp)->contents);
  1688.     }
  1689. #ifdef USE_TEXT_PROPERTIES
  1690.       if (c == '(')
  1691.     {
  1692.       Lisp_Object tmp;
  1693.       struct gcpro gcpro1;
  1694.       int ch;
  1695.  
  1696.       /* Read the string itself.  */
  1697.       tmp = read1 (readcharfun, &ch, 0);
  1698.       if (ch != 0 || !STRINGP (tmp))
  1699.         Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
  1700.       GCPRO1 (tmp);
  1701.       /* Read the intervals and their properties.  */
  1702.       while (1)
  1703.         {
  1704.           Lisp_Object beg, end, plist;
  1705.  
  1706.           beg = read1 (readcharfun, &ch, 0);
  1707.           if (ch == ')')
  1708.         break;
  1709.           if (ch == 0)
  1710.         end = read1 (readcharfun, &ch, 0);
  1711.           if (ch == 0)
  1712.         plist = read1 (readcharfun, &ch, 0);
  1713.           if (ch)
  1714.         Fsignal (Qinvalid_read_syntax,
  1715.              Fcons (build_string ("invalid string property list"),
  1716.                 Qnil));
  1717.           Fset_text_properties (beg, end, plist, tmp);
  1718.         }
  1719.       UNGCPRO;
  1720.       return tmp;
  1721.     }
  1722. #endif
  1723.       /* #@NUMBER is used to skip NUMBER following characters.
  1724.      That's used in .elc files to skip over doc strings
  1725.      and function definitions.  */
  1726.       if (c == '@')
  1727.     {
  1728.       int i, nskip = 0;
  1729.  
  1730.       /* Read a decimal integer.  */
  1731.       while ((c = READCHAR) >= 0
  1732.          && c >= '0' && c <= '9')
  1733.         {
  1734.           nskip *= 10;
  1735.           nskip += c - '0';
  1736.         }
  1737.       if (c >= 0)
  1738.         UNREAD (c);
  1739.       
  1740.       if (load_force_doc_strings && EQ (readcharfun, Qget_file_char))
  1741.         {
  1742.           /* If we are supposed to force doc strings into core right now,
  1743.          record the last string that we skipped,
  1744.          and record where in the file it comes from.  */
  1745.  
  1746.           /* But first exchange saved_doc_string
  1747.          with prev_saved_doc_string, so we save two strings.  */
  1748.           {
  1749.         char *temp = saved_doc_string;
  1750.         int temp_size = saved_doc_string_size;
  1751.         int temp_pos = saved_doc_string_position;
  1752.         int temp_len = saved_doc_string_length;
  1753.  
  1754.         saved_doc_string = prev_saved_doc_string;
  1755.         saved_doc_string_size = prev_saved_doc_string_size;
  1756.         saved_doc_string_position = prev_saved_doc_string_position;
  1757.         saved_doc_string_length = prev_saved_doc_string_length;
  1758.  
  1759.         prev_saved_doc_string = temp;
  1760.         prev_saved_doc_string_size = temp_size;
  1761.         prev_saved_doc_string_position = temp_pos;
  1762.         prev_saved_doc_string_length = temp_len;
  1763.           }
  1764.  
  1765.           if (saved_doc_string_size == 0)
  1766.         {
  1767.           saved_doc_string_size = nskip + 100;
  1768.           saved_doc_string = (char *) xmalloc (saved_doc_string_size);
  1769.         }
  1770.           if (nskip > saved_doc_string_size)
  1771.         {
  1772.           saved_doc_string_size = nskip + 100;
  1773.           saved_doc_string = (char *) xrealloc (saved_doc_string,
  1774.                             saved_doc_string_size);
  1775.         }
  1776.  
  1777.           saved_doc_string_position = ftell (instream);
  1778.  
  1779.           /* Copy that many characters into saved_doc_string.  */
  1780.           for (i = 0; i < nskip && c >= 0; i++)
  1781.         saved_doc_string[i] = c = READCHAR;
  1782.  
  1783.           saved_doc_string_length = i;
  1784.         }
  1785.       else
  1786.         {
  1787.           /* Skip that many characters.  */
  1788.           for (i = 0; i < nskip && c >= 0; i++)
  1789.         c = READCHAR;
  1790.         }
  1791.  
  1792.       goto retry;
  1793.     }
  1794.       if (c == '$')
  1795.     return Vload_file_name;
  1796.       if (c == '\'')
  1797.     return Fcons (Qfunction, Fcons (read0 (readcharfun), Qnil));
  1798.       /* #:foo is the uninterned symbol named foo.  */
  1799.       if (c == ':')
  1800.     {
  1801.       uninterned_symbol = 1;
  1802.       c = READCHAR;
  1803.       goto default_label;
  1804.     }
  1805.       /* Reader forms that can reuse previously read objects.  */
  1806.       if (c >= '0' && c <= '9')
  1807.     {
  1808.       int n = 0;
  1809.       Lisp_Object tem;
  1810.  
  1811.       /* Read a non-negative integer.  */
  1812.       while (c >= '0' && c <= '9')
  1813.         {
  1814.           n *= 10;
  1815.           n += c - '0';
  1816.           c = READCHAR;
  1817.         }
  1818.       /* #n=object returns object, but associates it with n for #n#.  */
  1819.       if (c == '=')
  1820.         {
  1821.           tem = read0 (readcharfun);
  1822.           read_objects = Fcons (Fcons (make_number (n), tem), read_objects);
  1823.           return tem;
  1824.         }
  1825.       /* #n# returns a previously read object.  */
  1826.       if (c == '#')
  1827.         {
  1828.           tem = Fassq (make_number (n), read_objects);
  1829.           if (CONSP (tem))
  1830.         return XCDR (tem);
  1831.           /* Fall through to error message.  */
  1832.         }
  1833.       /* Fall through to error message.  */
  1834.     }
  1835.  
  1836.       UNREAD (c);
  1837.       Fsignal (Qinvalid_read_syntax, Fcons (make_string ("#", 1), Qnil));
  1838.  
  1839.     case ';':
  1840.       while ((c = READCHAR) >= 0 && c != '\n');
  1841.       goto retry;
  1842.  
  1843.     case '\'':
  1844.       {
  1845.     return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
  1846.       }
  1847.  
  1848.     case '`':
  1849.       if (first_in_list)
  1850.     goto default_label;
  1851.       else
  1852.     {
  1853.       Lisp_Object value;
  1854.  
  1855.       new_backquote_flag = 1;
  1856.       value = read0 (readcharfun);
  1857.       new_backquote_flag = 0;
  1858.  
  1859.       return Fcons (Qbackquote, Fcons (value, Qnil));
  1860.     }
  1861.  
  1862.     case ',':
  1863.       if (new_backquote_flag)
  1864.     {
  1865.       Lisp_Object comma_type = Qnil;
  1866.       Lisp_Object value;
  1867.       int ch = READCHAR;
  1868.  
  1869.       if (ch == '@')
  1870.         comma_type = Qcomma_at;
  1871.       else if (ch == '.')
  1872.         comma_type = Qcomma_dot;
  1873.       else
  1874.         {
  1875.           if (ch >= 0) UNREAD (ch);
  1876.           comma_type = Qcomma;
  1877.         }
  1878.  
  1879.       new_backquote_flag = 0;
  1880.       value = read0 (readcharfun);
  1881.       new_backquote_flag = 1;
  1882.       return Fcons (comma_type, Fcons (value, Qnil));
  1883.     }
  1884.       else
  1885.     goto default_label;
  1886.  
  1887.     case '?':
  1888.       {
  1889.     register Lisp_Object val;
  1890.  
  1891.     c = READCHAR;
  1892.     if (c < 0) return Fsignal (Qend_of_file, Qnil);
  1893.  
  1894.     if (c == '\\')
  1895.       c = read_escape (readcharfun, 0);
  1896.     else if (BASE_LEADING_CODE_P (c))
  1897.       c = read_multibyte (c, readcharfun);
  1898.  
  1899.     return make_number (c);
  1900.       }
  1901.  
  1902.     case '"':
  1903.       {
  1904.     register char *p = read_buffer;
  1905.     register char *end = read_buffer + read_buffer_size;
  1906.     register int c;
  1907.     /* Nonzero if we saw an escape sequence specifying
  1908.        a multibyte character.  */
  1909.     int force_multibyte = 0;
  1910.     /* Nonzero if we saw an escape sequence specifying
  1911.        a single-byte character.  */
  1912.     int force_singlebyte = 0;
  1913.     int cancel = 0;
  1914.     int nchars;
  1915.  
  1916.     while ((c = READCHAR) >= 0
  1917.            && c != '\"')
  1918.       {
  1919.         if (end - p < MAX_LENGTH_OF_MULTI_BYTE_FORM)
  1920.           {
  1921.         char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
  1922.         p += new - read_buffer;
  1923.         read_buffer += new - read_buffer;
  1924.         end = read_buffer + read_buffer_size;
  1925.           }
  1926.  
  1927.         if (c == '\\')
  1928.           {
  1929.         c = read_escape (readcharfun, 1);
  1930.  
  1931.         /* C is -1 if \ newline has just been seen */
  1932.         if (c == -1)
  1933.           {
  1934.             if (p == read_buffer)
  1935.               cancel = 1;
  1936.             continue;
  1937.           }
  1938.  
  1939.         /* If an escape specifies a non-ASCII single-byte character,
  1940.            this must be a unibyte string.  */
  1941.         if (SINGLE_BYTE_CHAR_P ((c & ~CHAR_META))
  1942.             && ! ASCII_BYTE_P (c))
  1943.           force_singlebyte = 1;
  1944.           }
  1945.  
  1946.         if (! SINGLE_BYTE_CHAR_P ((c & ~CHAR_META)))
  1947.           {
  1948.         unsigned char workbuf[4];
  1949.         unsigned char *str = workbuf;
  1950.         int length;
  1951.  
  1952.         length = non_ascii_char_to_string (c, workbuf, &str);
  1953.         if (length > 1)
  1954.           force_multibyte = 1;
  1955.  
  1956.         bcopy (str, p, length);
  1957.         p += length;
  1958.           }
  1959.         else
  1960.           {
  1961.         /* Allow `\C- ' and `\C-?'.  */
  1962.         if (c == (CHAR_CTL | ' '))
  1963.           c = 0;
  1964.         else if (c == (CHAR_CTL | '?'))
  1965.           c = 127;
  1966.  
  1967.         if (c & CHAR_META)
  1968.           /* Move the meta bit to the right place for a string.  */
  1969.           c = (c & ~CHAR_META) | 0x80;
  1970.         if (c & ~0xff)
  1971.           error ("Invalid modifier in string");
  1972.         *p++ = c;
  1973.           }
  1974.       }
  1975.     if (c < 0)
  1976.       return Fsignal (Qend_of_file, Qnil);
  1977.  
  1978.     /* If purifying, and string starts with \ newline,
  1979.        return zero instead.  This is for doc strings
  1980.        that we are really going to find in etc/DOC.nn.nn  */
  1981.     if (!NILP (Vpurify_flag) && NILP (Vdoc_file_name) && cancel)
  1982.       return make_number (0);
  1983.  
  1984.     if (force_multibyte)
  1985.       nchars = multibyte_chars_in_text (read_buffer, p - read_buffer);
  1986.     else if (force_singlebyte)
  1987.       nchars = p - read_buffer;
  1988.     else if (load_convert_to_unibyte)
  1989.       {
  1990.         Lisp_Object string;
  1991.         nchars = multibyte_chars_in_text (read_buffer, p - read_buffer);
  1992.         if (p - read_buffer != nchars)
  1993.           {
  1994.         string = make_multibyte_string (read_buffer, nchars,
  1995.                         p - read_buffer);
  1996.         return Fstring_make_unibyte (string);
  1997.           }
  1998.       }
  1999.     else if (EQ (readcharfun, Qget_file_char)
  2000.          || EQ (readcharfun, Qlambda))
  2001.       /* Nowadays, reading directly from a file
  2002.          is used only for compiled Emacs Lisp files,
  2003.          and those always use the Emacs internal encoding.
  2004.          Meanwhile, Qlambda is used for reading dynamic byte code
  2005.          (compiled with byte-compile-dynamic = t).  */
  2006.       nchars = multibyte_chars_in_text (read_buffer, p - read_buffer);
  2007.     else
  2008.       /* In all other cases, if we read these bytes as
  2009.          separate characters, treat them as separate characters now.  */
  2010.       nchars = p - read_buffer;
  2011.  
  2012.     if (read_pure)
  2013.       return make_pure_string (read_buffer, nchars, p - read_buffer,
  2014.                    (force_multibyte
  2015.                     || (p - read_buffer != nchars)));
  2016.     return make_specified_string (read_buffer, nchars, p - read_buffer,
  2017.                       (force_multibyte
  2018.                        || (p - read_buffer != nchars)));
  2019.       }
  2020.  
  2021.     case '.':
  2022.       {
  2023. #ifdef LISP_FLOAT_TYPE
  2024.     /* If a period is followed by a number, then we should read it
  2025.        as a floating point number.  Otherwise, it denotes a dotted
  2026.        pair.  */
  2027.     int next_char = READCHAR;
  2028.     UNREAD (next_char);
  2029.  
  2030.     if (! (next_char >= '0' && next_char <= '9'))
  2031. #endif
  2032.       {
  2033.         *pch = c;
  2034.         return Qnil;
  2035.       }
  2036.  
  2037.     /* Otherwise, we fall through!  Note that the atom-reading loop
  2038.        below will now loop at least once, assuring that we will not
  2039.        try to UNREAD two characters in a row.  */
  2040.       }
  2041.     default:
  2042.     default_label:
  2043.       if (c <= 040) goto retry;
  2044.       {
  2045.     register char *p = read_buffer;
  2046.     int quoted = 0;
  2047.  
  2048.     {
  2049.       register char *end = read_buffer + read_buffer_size;
  2050.  
  2051.       while (c > 040
  2052.          && !(c == '\"' || c == '\'' || c == ';' || c == '?'
  2053.               || c == '(' || c == ')'
  2054. #ifndef LISP_FLOAT_TYPE
  2055.               /* If we have floating-point support, then we need
  2056.              to allow <digits><dot><digits>.  */
  2057.               || c =='.'
  2058. #endif /* not LISP_FLOAT_TYPE */
  2059.               || c == '[' || c == ']' || c == '#'
  2060.               ))
  2061.         {
  2062.           if (end - p < MAX_LENGTH_OF_MULTI_BYTE_FORM)
  2063.         {
  2064.           register char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
  2065.           p += new - read_buffer;
  2066.           read_buffer += new - read_buffer;
  2067.           end = read_buffer + read_buffer_size;
  2068.         }
  2069.           if (c == '\\')
  2070.         {
  2071.           c = READCHAR;
  2072.           quoted = 1;
  2073.         }
  2074.  
  2075.           if (! SINGLE_BYTE_CHAR_P (c))
  2076.         {
  2077.           unsigned char workbuf[4];
  2078.           unsigned char *str = workbuf;
  2079.           int length;
  2080.  
  2081.           length = non_ascii_char_to_string (c, workbuf, &str);
  2082.  
  2083.           bcopy (str, p, length);
  2084.           p += length;
  2085.         }
  2086.           else
  2087.         *p++ = c;
  2088.  
  2089.           c = READCHAR;
  2090.         }
  2091.  
  2092.       if (p == end)
  2093.         {
  2094.           char *new = (char *) xrealloc (read_buffer, read_buffer_size *= 2);
  2095.           p += new - read_buffer;
  2096.           read_buffer += new - read_buffer;
  2097. /*          end = read_buffer + read_buffer_size;  */
  2098.         }
  2099.       *p = 0;
  2100.       if (c >= 0)
  2101.         UNREAD (c);
  2102.     }
  2103.  
  2104.     if (!quoted && !uninterned_symbol)
  2105.       {
  2106.         register char *p1;
  2107.         register Lisp_Object val;
  2108.         p1 = read_buffer;
  2109.         if (*p1 == '+' || *p1 == '-') p1++;
  2110.         /* Is it an integer? */
  2111.         if (p1 != p)
  2112.           {
  2113.         while (p1 != p && (c = *p1) >= '0' && c <= '9') p1++;
  2114. #ifdef LISP_FLOAT_TYPE
  2115.         /* Integers can have trailing decimal points.  */
  2116.         if (p1 > read_buffer && p1 < p && *p1 == '.') p1++;
  2117. #endif
  2118.         if (p1 == p)
  2119.           /* It is an integer. */
  2120.           {
  2121. #ifdef LISP_FLOAT_TYPE
  2122.             if (p1[-1] == '.')
  2123.               p1[-1] = '\0';
  2124. #endif
  2125.             if (sizeof (int) == sizeof (EMACS_INT))
  2126.               XSETINT (val, atoi (read_buffer));
  2127.             else if (sizeof (long) == sizeof (EMACS_INT))
  2128.               XSETINT (val, atol (read_buffer));
  2129.             else
  2130.               abort ();
  2131.             return val;
  2132.           }
  2133.           }
  2134. #ifdef LISP_FLOAT_TYPE
  2135.         if (isfloat_string (read_buffer))
  2136.           {
  2137.         double zero = 0.0;
  2138.         double value = atof (read_buffer);
  2139.         if (read_buffer[0] == '-' && value == 0.0)
  2140.           value *= -1.0;
  2141.         /* The only way this can be true, after isfloat_string
  2142.            returns 1, is if the input ends in e+INF or e+NaN.  */
  2143.         if (p[-1] == 'F' || p[-1] == 'N')
  2144.           {
  2145.             if (p[-1] == 'N')
  2146.               value = zero / zero;
  2147.             else if (read_buffer[0] == '-')
  2148.               value = - 1.0 / zero;
  2149.             else
  2150.               value = 1.0 / zero;
  2151.           }
  2152.         return make_float (value);
  2153.           }
  2154. #endif
  2155.       }
  2156.  
  2157.     if (uninterned_symbol)
  2158.       return make_symbol (read_buffer);
  2159.     else
  2160.       return intern (read_buffer);
  2161.       }
  2162.     }
  2163. }
  2164.  
  2165. #ifdef LISP_FLOAT_TYPE
  2166.  
  2167. #define LEAD_INT 1
  2168. #define DOT_CHAR 2
  2169. #define TRAIL_INT 4
  2170. #define E_CHAR 8
  2171. #define EXP_INT 16
  2172.  
  2173. int
  2174. isfloat_string (cp)
  2175.      register char *cp;
  2176. {
  2177.   register int state;
  2178.   
  2179.   char *start = cp;
  2180.  
  2181.   state = 0;
  2182.   if (*cp == '+' || *cp == '-')
  2183.     cp++;
  2184.  
  2185.   if (*cp >= '0' && *cp <= '9')
  2186.     {
  2187.       state |= LEAD_INT;
  2188.       while (*cp >= '0' && *cp <= '9')
  2189.     cp++;
  2190.     }
  2191.   if (*cp == '.')
  2192.     {
  2193.       state |= DOT_CHAR;
  2194.       cp++;
  2195.     }
  2196.   if (*cp >= '0' && *cp <= '9')
  2197.     {
  2198.       state |= TRAIL_INT;
  2199.       while (*cp >= '0' && *cp <= '9')
  2200.     cp++;
  2201.     }
  2202.   if (*cp == 'e' || *cp == 'E')
  2203.     {
  2204.       state |= E_CHAR;
  2205.       cp++;
  2206.       if (*cp == '+' || *cp == '-')
  2207.     cp++;
  2208.     }
  2209.  
  2210.   if (*cp >= '0' && *cp <= '9')
  2211.     {
  2212.       state |= EXP_INT;
  2213.       while (*cp >= '0' && *cp <= '9')
  2214.     cp++;
  2215.     }
  2216.   else if (cp == start)
  2217.     ;
  2218.   else if (cp[-1] == '+' && cp[0] == 'I' && cp[1] == 'N' && cp[2] == 'F')
  2219.     {
  2220.       state |= EXP_INT;
  2221.       cp += 3;
  2222.     }
  2223.   else if (cp[-1] == '+' && cp[0] == 'N' && cp[1] == 'a' && cp[2] == 'N')
  2224.     {
  2225.       state |= EXP_INT;
  2226.       cp += 3;
  2227.     }
  2228.  
  2229.   return (((*cp == 0) || (*cp == ' ') || (*cp == '\t') || (*cp == '\n') || (*cp == '\r') || (*cp == '\f'))
  2230.       && (state == (LEAD_INT|DOT_CHAR|TRAIL_INT)
  2231.           || state == (DOT_CHAR|TRAIL_INT)
  2232.           || state == (LEAD_INT|E_CHAR|EXP_INT)
  2233.           || state == (LEAD_INT|DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)
  2234.           || state == (DOT_CHAR|TRAIL_INT|E_CHAR|EXP_INT)));
  2235. }
  2236. #endif /* LISP_FLOAT_TYPE */
  2237.  
  2238. static Lisp_Object
  2239. read_vector (readcharfun, bytecodeflag)
  2240.      Lisp_Object readcharfun;
  2241.      int bytecodeflag;
  2242. {
  2243.   register int i;
  2244.   register int size;
  2245.   register Lisp_Object *ptr;
  2246.   register Lisp_Object tem, item, vector;
  2247.   register struct Lisp_Cons *otem;
  2248.   Lisp_Object len;
  2249.  
  2250.   tem = read_list (1, readcharfun);
  2251.   len = Flength (tem);
  2252.   vector = (read_pure ? make_pure_vector (XINT (len)) : Fmake_vector (len, Qnil));
  2253.  
  2254.   size = XVECTOR (vector)->size;
  2255.   ptr = XVECTOR (vector)->contents;
  2256.   for (i = 0; i < size; i++)
  2257.     {
  2258.       item = Fcar (tem);
  2259.       /* If `load-force-doc-strings' is t when reading a lazily-loaded
  2260.      bytecode object, the docstring containing the bytecode and
  2261.      constants values must be treated as unibyte and passed to
  2262.      Fread, to get the actual bytecode string and constants vector.  */
  2263.       if (bytecodeflag && load_force_doc_strings)
  2264.     {
  2265.       if (i == COMPILED_BYTECODE)
  2266.         {
  2267.           if (!STRINGP (item))
  2268.         error ("invalid byte code");
  2269.  
  2270.           /* Delay handling the bytecode slot until we know whether
  2271.          it is lazily-loaded (we can tell by whether the
  2272.          constants slot is nil).  */
  2273.           ptr[COMPILED_CONSTANTS] = item;
  2274.           item = Qnil;
  2275.         }
  2276.       else if (i == COMPILED_CONSTANTS)
  2277.         {
  2278.           Lisp_Object bytestr = ptr[COMPILED_CONSTANTS];
  2279.  
  2280.           if (NILP (item))
  2281.         {
  2282.           /* Coerce string to unibyte (like string-as-unibyte,
  2283.              but without generating extra garbage and
  2284.              guaranteeing no change in the contents).  */
  2285.           XSTRING (bytestr)->size = STRING_BYTES (XSTRING (bytestr));
  2286.           SET_STRING_BYTES (XSTRING (bytestr), -1);
  2287.  
  2288.           item = Fread (bytestr);
  2289.           if (!CONSP (item))
  2290.             error ("invalid byte code");
  2291.  
  2292.           otem = XCONS (item);
  2293.           bytestr = XCONS (item)->car;
  2294.           item = XCONS (item)->cdr;
  2295.           free_cons (otem);
  2296.         }
  2297.  
  2298.           /* Now handle the bytecode slot.  */
  2299.           ptr[COMPILED_BYTECODE] = read_pure ? Fpurecopy (bytestr) : bytestr;
  2300.         }
  2301.     }
  2302.       ptr[i] = read_pure ? Fpurecopy (item) : item;
  2303.       otem = XCONS (tem);
  2304.       tem = Fcdr (tem);
  2305.       free_cons (otem);
  2306.     }
  2307.   return vector;
  2308. }
  2309.   
  2310. /* FLAG = 1 means check for ] to terminate rather than ) and .
  2311.    FLAG = -1 means check for starting with defun
  2312.     and make structure pure.  */
  2313.  
  2314. static Lisp_Object
  2315. read_list (flag, readcharfun)
  2316.      int flag;
  2317.      register Lisp_Object readcharfun;
  2318. {
  2319.   /* -1 means check next element for defun,
  2320.      0 means don't check,
  2321.      1 means already checked and found defun. */
  2322.   int defunflag = flag < 0 ? -1 : 0;
  2323.   Lisp_Object val, tail;
  2324.   register Lisp_Object elt, tem;
  2325.   struct gcpro gcpro1, gcpro2;
  2326.   /* 0 is the normal case.
  2327.      1 means this list is a doc reference; replace it with the number 0.
  2328.      2 means this list is a doc reference; replace it with the doc string.  */ 
  2329.   int doc_reference = 0;
  2330.  
  2331.   /* Initialize this to 1 if we are reading a list.  */
  2332.   int first_in_list = flag <= 0;
  2333.  
  2334.   val = Qnil;
  2335.   tail = Qnil;
  2336.  
  2337.   while (1)
  2338.     {
  2339.       int ch;
  2340.       GCPRO2 (val, tail);
  2341.       elt = read1 (readcharfun, &ch, first_in_list);
  2342.       UNGCPRO;
  2343.  
  2344.       first_in_list = 0;
  2345.  
  2346.       /* While building, if the list starts with #$, treat it specially.  */
  2347.       if (EQ (elt, Vload_file_name)
  2348.       && ! NILP (elt)
  2349.       && !NILP (Vpurify_flag))
  2350.     {
  2351.       if (NILP (Vdoc_file_name))
  2352.         /* We have not yet called Snarf-documentation, so assume
  2353.            this file is described in the DOC-MM.NN file
  2354.            and Snarf-documentation will fill in the right value later.
  2355.            For now, replace the whole list with 0.  */
  2356.         doc_reference = 1;
  2357.       else
  2358.         /* We have already called Snarf-documentation, so make a relative
  2359.            file name for this file, so it can be found properly
  2360.            in the installed Lisp directory.
  2361.            We don't use Fexpand_file_name because that would make
  2362.            the directory absolute now.  */
  2363.         elt = concat2 (build_string ("../lisp/"),
  2364.                Ffile_name_nondirectory (elt));
  2365.     }
  2366.       else if (EQ (elt, Vload_file_name)
  2367.            && ! NILP (elt)
  2368.            && load_force_doc_strings)
  2369.     doc_reference = 2;
  2370.  
  2371.       if (ch)
  2372.     {
  2373.       if (flag > 0)
  2374.         {
  2375.           if (ch == ']')
  2376.         return val;
  2377.           Fsignal (Qinvalid_read_syntax,
  2378.                Fcons (make_string (") or . in a vector", 18), Qnil));
  2379.         }
  2380.       if (ch == ')')
  2381.         return val;
  2382.       if (ch == '.')
  2383.         {
  2384.           GCPRO2 (val, tail);
  2385.           if (!NILP (tail))
  2386.         XCONS (tail)->cdr = read0 (readcharfun);
  2387.           else
  2388.         val = read0 (readcharfun);
  2389.           read1 (readcharfun, &ch, 0);
  2390.           UNGCPRO;
  2391.           if (ch == ')')
  2392.         {
  2393.           if (doc_reference == 1)
  2394.             return make_number (0);
  2395.           if (doc_reference == 2)
  2396.             {
  2397.               /* Get a doc string from the file we are loading.
  2398.              If it's in saved_doc_string, get it from there.  */
  2399.               int pos = XINT (XCONS (val)->cdr);
  2400.               /* Position is negative for user variables.  */
  2401.               if (pos < 0) pos = -pos;
  2402.               if (pos >= saved_doc_string_position
  2403.               && pos < (saved_doc_string_position
  2404.                     + saved_doc_string_length))
  2405.             {
  2406.               int start = pos - saved_doc_string_position;
  2407.               int from, to;
  2408.  
  2409.               /* Process quoting with ^A,
  2410.                  and find the end of the string,
  2411.                  which is marked with ^_ (037).  */
  2412.               for (from = start, to = start;
  2413.                    saved_doc_string[from] != 037;)
  2414.                 {
  2415.                   int c = saved_doc_string[from++];
  2416.                   if (c == 1)
  2417.                 {
  2418.                   c = saved_doc_string[from++];
  2419.                   if (c == 1)
  2420.                     saved_doc_string[to++] = c;
  2421.                   else if (c == '0')
  2422.                     saved_doc_string[to++] = 0;
  2423.                   else if (c == '_')
  2424.                     saved_doc_string[to++] = 037;
  2425.                 }
  2426.                   else
  2427.                 saved_doc_string[to++] = c;
  2428.                 }
  2429.  
  2430.               return make_string (saved_doc_string + start,
  2431.                           to - start);
  2432.             }
  2433.               /* Look in prev_saved_doc_string the same way.  */
  2434.               else if (pos >= prev_saved_doc_string_position
  2435.                    && pos < (prev_saved_doc_string_position
  2436.                      + prev_saved_doc_string_length))
  2437.             {
  2438.               int start = pos - prev_saved_doc_string_position;
  2439.               int from, to;
  2440.  
  2441.               /* Process quoting with ^A,
  2442.                  and find the end of the string,
  2443.                  which is marked with ^_ (037).  */
  2444.               for (from = start, to = start;
  2445.                    prev_saved_doc_string[from] != 037;)
  2446.                 {
  2447.                   int c = prev_saved_doc_string[from++];
  2448.                   if (c == 1)
  2449.                 {
  2450.                   c = prev_saved_doc_string[from++];
  2451.                   if (c == 1)
  2452.                     prev_saved_doc_string[to++] = c;
  2453.                   else if (c == '0')
  2454.                     prev_saved_doc_string[to++] = 0;
  2455.                   else if (c == '_')
  2456.                     prev_saved_doc_string[to++] = 037;
  2457.                 }
  2458.                   else
  2459.                 prev_saved_doc_string[to++] = c;
  2460.                 }
  2461.  
  2462.               return make_string (prev_saved_doc_string + start,
  2463.                           to - start);
  2464.             }
  2465.               else
  2466.             return get_doc_string (val, 0, 0);
  2467.             }
  2468.  
  2469.           return val;
  2470.         }
  2471.           return Fsignal (Qinvalid_read_syntax, Fcons (make_string (". in wrong context", 18), Qnil));
  2472.         }
  2473.       return Fsignal (Qinvalid_read_syntax, Fcons (make_string ("] in a list", 11), Qnil));
  2474.     }
  2475.       tem = (read_pure && flag <= 0
  2476.          ? pure_cons (elt, Qnil)
  2477.          : Fcons (elt, Qnil));
  2478.       if (!NILP (tail))
  2479.     XCONS (tail)->cdr = tem;
  2480.       else
  2481.     val = tem;
  2482.       tail = tem;
  2483.       if (defunflag < 0)
  2484.     defunflag = EQ (elt, Qdefun);
  2485.       else if (defunflag > 0)
  2486.     read_pure = 1;
  2487.     }
  2488. }
  2489.  
  2490. Lisp_Object Vobarray;
  2491. Lisp_Object initial_obarray;
  2492.  
  2493. /* oblookup stores the bucket number here, for the sake of Funintern.  */
  2494.  
  2495. int oblookup_last_bucket_number;
  2496.  
  2497. static int hash_string ();
  2498. Lisp_Object oblookup ();
  2499.  
  2500. /* Get an error if OBARRAY is not an obarray.
  2501.    If it is one, return it.  */
  2502.  
  2503. Lisp_Object
  2504. check_obarray (obarray)
  2505.      Lisp_Object obarray;
  2506. {
  2507.   while (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
  2508.     {
  2509.       /* If Vobarray is now invalid, force it to be valid.  */
  2510.       if (EQ (Vobarray, obarray)) Vobarray = initial_obarray;
  2511.  
  2512.       obarray = wrong_type_argument (Qvectorp, obarray);
  2513.     }
  2514.   return obarray;
  2515. }
  2516.  
  2517. /* Intern the C string STR: return a symbol with that name,
  2518.    interned in the current obarray.  */
  2519.  
  2520. Lisp_Object
  2521. intern (str)
  2522.      char *str;
  2523. {
  2524.   Lisp_Object tem;
  2525.   int len = strlen (str);
  2526.   Lisp_Object obarray;
  2527.  
  2528.   obarray = Vobarray;
  2529.   if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
  2530.     obarray = check_obarray (obarray);
  2531.   tem = oblookup (obarray, str, len, len);
  2532.   if (SYMBOLP (tem))
  2533.     return tem;
  2534.   return Fintern (make_string (str, len), obarray);
  2535. }
  2536.  
  2537. /* Create an uninterned symbol with name STR.  */
  2538.  
  2539. Lisp_Object
  2540. make_symbol (str)
  2541.      char *str;
  2542. {
  2543.   int len = strlen (str);
  2544.  
  2545.   return Fmake_symbol ((!NILP (Vpurify_flag)
  2546.             ? make_pure_string (str, len, len, 0)
  2547.             : make_string (str, len)));
  2548. }
  2549.  
  2550. DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
  2551.   "Return the canonical symbol whose name is STRING.\n\
  2552. If there is none, one is created by this function and returned.\n\
  2553. A second optional argument specifies the obarray to use;\n\
  2554. it defaults to the value of `obarray'.")
  2555.   (string, obarray)
  2556.      Lisp_Object string, obarray;
  2557. {
  2558.   register Lisp_Object tem, sym, *ptr;
  2559.  
  2560.   if (NILP (obarray)) obarray = Vobarray;
  2561.   obarray = check_obarray (obarray);
  2562.  
  2563.   CHECK_STRING (string, 0);
  2564.  
  2565.   tem = oblookup (obarray, XSTRING (string)->data,
  2566.           XSTRING (string)->size,
  2567.           STRING_BYTES (XSTRING (string)));
  2568.   if (!INTEGERP (tem))
  2569.     return tem;
  2570.  
  2571.   if (!NILP (Vpurify_flag))
  2572.     string = Fpurecopy (string);
  2573.   sym = Fmake_symbol (string);
  2574.   XSYMBOL (sym)->obarray = obarray;
  2575.  
  2576.   if ((XSTRING (string)->data[0] == ':')
  2577.       && EQ (obarray, initial_obarray))
  2578.     XSYMBOL (sym)->value = sym;
  2579.  
  2580.   ptr = &XVECTOR (obarray)->contents[XINT (tem)];
  2581.   if (SYMBOLP (*ptr))
  2582.     XSYMBOL (sym)->next = XSYMBOL (*ptr);
  2583.   else
  2584.     XSYMBOL (sym)->next = 0;
  2585.   *ptr = sym;
  2586.   return sym;
  2587. }
  2588.  
  2589. DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
  2590.   "Return the canonical symbol whose name is STRING, or nil if none exists.\n\
  2591. A second optional argument specifies the obarray to use;\n\
  2592. it defaults to the value of `obarray'.")
  2593.   (string, obarray)
  2594.      Lisp_Object string, obarray;
  2595. {
  2596.   register Lisp_Object tem;
  2597.  
  2598.   if (NILP (obarray)) obarray = Vobarray;
  2599.   obarray = check_obarray (obarray);
  2600.  
  2601.   CHECK_STRING (string, 0);
  2602.  
  2603.   tem = oblookup (obarray, XSTRING (string)->data,
  2604.           XSTRING (string)->size,
  2605.           STRING_BYTES (XSTRING (string)));
  2606.   if (!INTEGERP (tem))
  2607.     return tem;
  2608.   return Qnil;
  2609. }
  2610.  
  2611. DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
  2612.   "Delete the symbol named NAME, if any, from OBARRAY.\n\
  2613. The value is t if a symbol was found and deleted, nil otherwise.\n\
  2614. NAME may be a string or a symbol.  If it is a symbol, that symbol\n\
  2615. is deleted, if it belongs to OBARRAY--no other symbol is deleted.\n\
  2616. OBARRAY defaults to the value of the variable `obarray'.")
  2617.   (name, obarray)
  2618.      Lisp_Object name, obarray;
  2619. {
  2620.   register Lisp_Object string, tem;
  2621.   int hash;
  2622.  
  2623.   if (NILP (obarray)) obarray = Vobarray;
  2624.   obarray = check_obarray (obarray);
  2625.  
  2626.   if (SYMBOLP (name))
  2627.     XSETSTRING (string, XSYMBOL (name)->name);
  2628.   else
  2629.     {
  2630.       CHECK_STRING (name, 0);
  2631.       string = name;
  2632.     }
  2633.  
  2634.   tem = oblookup (obarray, XSTRING (string)->data,
  2635.           XSTRING (string)->size,
  2636.           STRING_BYTES (XSTRING (string)));
  2637.   if (INTEGERP (tem))
  2638.     return Qnil;
  2639.   /* If arg was a symbol, don't delete anything but that symbol itself.  */
  2640.   if (SYMBOLP (name) && !EQ (name, tem))
  2641.     return Qnil;
  2642.  
  2643.   XSYMBOL (tem)->obarray = Qnil;
  2644.  
  2645.   hash = oblookup_last_bucket_number;
  2646.  
  2647.   if (EQ (XVECTOR (obarray)->contents[hash], tem))
  2648.     {
  2649.       if (XSYMBOL (tem)->next)
  2650.     XSETSYMBOL (XVECTOR (obarray)->contents[hash], XSYMBOL (tem)->next);
  2651.       else
  2652.     XSETINT (XVECTOR (obarray)->contents[hash], 0);
  2653.     }
  2654.   else
  2655.     {
  2656.       Lisp_Object tail, following;
  2657.  
  2658.       for (tail = XVECTOR (obarray)->contents[hash];
  2659.        XSYMBOL (tail)->next;
  2660.        tail = following)
  2661.     {
  2662.       XSETSYMBOL (following, XSYMBOL (tail)->next);
  2663.       if (EQ (following, tem))
  2664.         {
  2665.           XSYMBOL (tail)->next = XSYMBOL (following)->next;
  2666.           break;
  2667.         }
  2668.     }
  2669.     }
  2670.  
  2671.   return Qt;
  2672. }
  2673.  
  2674. /* Return the symbol in OBARRAY whose names matches the string
  2675.    of SIZE characters (SIZE_BYTE bytes) at PTR.
  2676.    If there is no such symbol in OBARRAY, return nil.
  2677.  
  2678.    Also store the bucket number in oblookup_last_bucket_number.  */
  2679.  
  2680. Lisp_Object
  2681. oblookup (obarray, ptr, size, size_byte)
  2682.      Lisp_Object obarray;
  2683.      register char *ptr;
  2684.      int size, size_byte;
  2685. {
  2686.   int hash;
  2687.   int obsize;
  2688.   register Lisp_Object tail;
  2689.   Lisp_Object bucket, tem;
  2690.  
  2691.   if (!VECTORP (obarray)
  2692.       || (obsize = XVECTOR (obarray)->size) == 0)
  2693.     {
  2694.       obarray = check_obarray (obarray);
  2695.       obsize = XVECTOR (obarray)->size;
  2696.     }
  2697.   /* This is sometimes needed in the middle of GC.  */
  2698.   obsize &= ~ARRAY_MARK_FLAG;
  2699.   /* Combining next two lines breaks VMS C 2.3.  */
  2700.   hash = hash_string (ptr, size_byte);
  2701.   hash %= obsize;
  2702.   bucket = XVECTOR (obarray)->contents[hash];
  2703.   oblookup_last_bucket_number = hash;
  2704.   if (XFASTINT (bucket) == 0)
  2705.     ;
  2706.   else if (!SYMBOLP (bucket))
  2707.     error ("Bad data in guts of obarray"); /* Like CADR error message */
  2708.   else
  2709.     for (tail = bucket; ; XSETSYMBOL (tail, XSYMBOL (tail)->next))
  2710.       {
  2711.     if (STRING_BYTES (XSYMBOL (tail)->name) == size_byte
  2712.         && XSYMBOL (tail)->name->size == size
  2713.         && !bcmp (XSYMBOL (tail)->name->data, ptr, size_byte))
  2714.       return tail;
  2715.     else if (XSYMBOL (tail)->next == 0)
  2716.       break;
  2717.       }
  2718.   XSETINT (tem, hash);
  2719.   return tem;
  2720. }
  2721.  
  2722. static int
  2723. hash_string (ptr, len)
  2724.      unsigned char *ptr;
  2725.      int len;
  2726. {
  2727.   register unsigned char *p = ptr;
  2728.   register unsigned char *end = p + len;
  2729.   register unsigned char c;
  2730.   register int hash = 0;
  2731.  
  2732.   while (p != end)
  2733.     {
  2734.       c = *p++;
  2735.       if (c >= 0140) c -= 40;
  2736.       hash = ((hash<<3) + (hash>>28) + c);
  2737.     }
  2738.   return hash & 07777777777;
  2739. }
  2740.  
  2741. void
  2742. map_obarray (obarray, fn, arg)
  2743.      Lisp_Object obarray;
  2744.      void (*fn) P_ ((Lisp_Object, Lisp_Object));
  2745.      Lisp_Object arg;
  2746. {
  2747.   register int i;
  2748.   register Lisp_Object tail;
  2749.   CHECK_VECTOR (obarray, 1);
  2750.   for (i = XVECTOR (obarray)->size - 1; i >= 0; i--)
  2751.     {
  2752.       tail = XVECTOR (obarray)->contents[i];
  2753.       if (SYMBOLP (tail))
  2754.     while (1)
  2755.       {
  2756.         (*fn) (tail, arg);
  2757.         if (XSYMBOL (tail)->next == 0)
  2758.           break;
  2759.         XSETSYMBOL (tail, XSYMBOL (tail)->next);
  2760.       }
  2761.     }
  2762. }
  2763.  
  2764. void
  2765. mapatoms_1 (sym, function)
  2766.      Lisp_Object sym, function;
  2767. {
  2768.   call1 (function, sym);
  2769. }
  2770.  
  2771. DEFUN ("mapatoms", Fmapatoms, Smapatoms, 1, 2, 0,
  2772.   "Call FUNCTION on every symbol in OBARRAY.\n\
  2773. OBARRAY defaults to the value of `obarray'.")
  2774.   (function, obarray)
  2775.      Lisp_Object function, obarray;
  2776. {
  2777.   Lisp_Object tem;
  2778.  
  2779.   if (NILP (obarray)) obarray = Vobarray;
  2780.   obarray = check_obarray (obarray);
  2781.  
  2782.   map_obarray (obarray, mapatoms_1, function);
  2783.   return Qnil;
  2784. }
  2785.  
  2786. #define OBARRAY_SIZE 1511
  2787.  
  2788. void
  2789. init_obarray ()
  2790. {
  2791.   Lisp_Object oblength;
  2792.   int hash;
  2793.   Lisp_Object *tem;
  2794.  
  2795.   XSETFASTINT (oblength, OBARRAY_SIZE);
  2796.  
  2797.   Qnil = Fmake_symbol (make_pure_string ("nil", 3, 3, 0));
  2798.   Vobarray = Fmake_vector (oblength, make_number (0));
  2799.   initial_obarray = Vobarray;
  2800.   staticpro (&initial_obarray);
  2801.   /* Intern nil in the obarray */
  2802.   XSYMBOL (Qnil)->obarray = Vobarray;
  2803.   /* These locals are to kludge around a pyramid compiler bug. */
  2804.   hash = hash_string ("nil", 3);
  2805.   /* Separate statement here to avoid VAXC bug. */
  2806.   hash %= OBARRAY_SIZE;
  2807.   tem = &XVECTOR (Vobarray)->contents[hash];
  2808.   *tem = Qnil;
  2809.  
  2810.   Qunbound = Fmake_symbol (make_pure_string ("unbound", 7, 7, 0));
  2811.   XSYMBOL (Qnil)->function = Qunbound;
  2812.   XSYMBOL (Qunbound)->value = Qunbound;
  2813.   XSYMBOL (Qunbound)->function = Qunbound;
  2814.  
  2815.   Qt = intern ("t");
  2816.   XSYMBOL (Qnil)->value = Qnil;
  2817.   XSYMBOL (Qnil)->plist = Qnil;
  2818.   XSYMBOL (Qt)->value = Qt;
  2819.  
  2820.   /* Qt is correct even if CANNOT_DUMP.  loadup.el will set to nil at end.  */
  2821.   Vpurify_flag = Qt;
  2822.  
  2823.   Qvariable_documentation = intern ("variable-documentation");
  2824.   staticpro (&Qvariable_documentation);
  2825.  
  2826.   read_buffer_size = 100 + MAX_LENGTH_OF_MULTI_BYTE_FORM;
  2827.   read_buffer = (char *) malloc (read_buffer_size);
  2828. }
  2829.  
  2830. void
  2831. defsubr (sname)
  2832.      struct Lisp_Subr *sname;
  2833. {
  2834.   Lisp_Object sym;
  2835.   sym = intern (sname->symbol_name);
  2836.   XSETSUBR (XSYMBOL (sym)->function, sname);
  2837. }
  2838.  
  2839. #ifdef NOTDEF /* use fset in subr.el now */
  2840. void
  2841. defalias (sname, string)
  2842.      struct Lisp_Subr *sname;
  2843.      char *string;
  2844. {
  2845.   Lisp_Object sym;
  2846.   sym = intern (string);
  2847.   XSETSUBR (XSYMBOL (sym)->function, sname);
  2848. }
  2849. #endif /* NOTDEF */
  2850.  
  2851. /* Define an "integer variable"; a symbol whose value is forwarded
  2852.    to a C variable of type int.  Sample call: */
  2853.   /* DEFVAR_INT ("indent-tabs-mode", &indent_tabs_mode, "Documentation");  */
  2854. void
  2855. defvar_int (namestring, address)
  2856.      char *namestring;
  2857.      int *address;
  2858. {
  2859.   Lisp_Object sym, val;
  2860.   sym = intern (namestring);
  2861.   val = allocate_misc ();
  2862.   XMISCTYPE (val) = Lisp_Misc_Intfwd;
  2863.   XINTFWD (val)->intvar = address;
  2864.   XSYMBOL (sym)->value = val;
  2865. }
  2866.  
  2867. /* Similar but define a variable whose value is T if address contains 1,
  2868.    NIL if address contains 0 */
  2869. void
  2870. defvar_bool (namestring, address)
  2871.      char *namestring;
  2872.      int *address;
  2873. {
  2874.   Lisp_Object sym, val;
  2875.   sym = intern (namestring);
  2876.   val = allocate_misc ();
  2877.   XMISCTYPE (val) = Lisp_Misc_Boolfwd;
  2878.   XBOOLFWD (val)->boolvar = address;
  2879.   XSYMBOL (sym)->value = val;
  2880. }
  2881.  
  2882. /* Similar but define a variable whose value is the Lisp Object stored
  2883.    at address.  Two versions: with and without gc-marking of the C
  2884.    variable.  The nopro version is used when that variable will be
  2885.    gc-marked for some other reason, since marking the same slot twice
  2886.    can cause trouble with strings.  */
  2887. void
  2888. defvar_lisp_nopro (namestring, address)
  2889.      char *namestring;
  2890.      Lisp_Object *address;
  2891. {
  2892.   Lisp_Object sym, val;
  2893.   sym = intern (namestring);
  2894.   val = allocate_misc ();
  2895.   XMISCTYPE (val) = Lisp_Misc_Objfwd;
  2896.   XOBJFWD (val)->objvar = address;
  2897.   XSYMBOL (sym)->value = val;
  2898. }
  2899.  
  2900. void
  2901. defvar_lisp (namestring, address)
  2902.      char *namestring;
  2903.      Lisp_Object *address;
  2904. {
  2905.   defvar_lisp_nopro (namestring, address);
  2906.   staticpro (address);
  2907. }
  2908.  
  2909. #ifndef standalone
  2910.  
  2911. /* Similar but define a variable whose value is the Lisp Object stored in
  2912.    the current buffer.  address is the address of the slot in the buffer
  2913.    that is current now. */
  2914.  
  2915. void
  2916. defvar_per_buffer (namestring, address, type, doc)
  2917.      char *namestring;
  2918.      Lisp_Object *address;
  2919.      Lisp_Object type;
  2920.      char *doc;
  2921. {
  2922.   Lisp_Object sym, val;
  2923.   int offset;
  2924.   extern struct buffer buffer_local_symbols;
  2925.  
  2926.   sym = intern (namestring);
  2927.   val = allocate_misc ();
  2928.   offset = (char *)address - (char *)current_buffer;
  2929.  
  2930.   XMISCTYPE (val) = Lisp_Misc_Buffer_Objfwd;
  2931.   XBUFFER_OBJFWD (val)->offset = offset;
  2932.   XSYMBOL (sym)->value = val;
  2933.   *(Lisp_Object *)(offset + (char *)&buffer_local_symbols) = sym;
  2934.   *(Lisp_Object *)(offset + (char *)&buffer_local_types) = type;
  2935.   if (XINT (*(Lisp_Object *)(offset + (char *)&buffer_local_flags)) == 0)
  2936.     /* Did a DEFVAR_PER_BUFFER without initializing the corresponding
  2937.        slot of buffer_local_flags */
  2938.     abort ();
  2939. }
  2940.  
  2941. #endif /* standalone */
  2942.  
  2943. /* Similar but define a variable whose value is the Lisp Object stored
  2944.    at a particular offset in the current kboard object.  */
  2945.  
  2946. void
  2947. defvar_kboard (namestring, offset)
  2948.      char *namestring;
  2949.      int offset;
  2950. {
  2951.   Lisp_Object sym, val;
  2952.   sym = intern (namestring);
  2953.   val = allocate_misc ();
  2954.   XMISCTYPE (val) = Lisp_Misc_Kboard_Objfwd;
  2955.   XKBOARD_OBJFWD (val)->offset = offset;
  2956.   XSYMBOL (sym)->value = val;
  2957. }
  2958.  
  2959. /* Record the value of load-path used at the start of dumping
  2960.    so we can see if the site changed it later during dumping.  */
  2961. static Lisp_Object dump_path;
  2962.  
  2963. void
  2964. init_lread ()
  2965. {
  2966.   char *normal;
  2967.   int turn_off_warning = 0;
  2968.  
  2969. #ifdef HAVE_SETLOCALE
  2970.   /* Make sure numbers are parsed as we expect.  */
  2971.   setlocale (LC_NUMERIC, "C");
  2972. #endif /* HAVE_SETLOCALE */
  2973.  
  2974.   /* Compute the default load-path.  */
  2975. #ifdef CANNOT_DUMP
  2976.   normal = PATH_LOADSEARCH;
  2977.   Vload_path = decode_env_path (0, normal);
  2978. #else
  2979.   if (NILP (Vpurify_flag))
  2980.     normal = PATH_LOADSEARCH;
  2981.   else
  2982.     normal = PATH_DUMPLOADSEARCH;
  2983.  
  2984.   /* In a dumped Emacs, we normally have to reset the value of
  2985.      Vload_path from PATH_LOADSEARCH, since the value that was dumped
  2986.      uses ../lisp, instead of the path of the installed elisp
  2987.      libraries.  However, if it appears that Vload_path was changed
  2988.      from the default before dumping, don't override that value.  */
  2989.   if (initialized)
  2990.     {
  2991.       if (! NILP (Fequal (dump_path, Vload_path)))
  2992.     {
  2993.       Vload_path = decode_env_path (0, normal);
  2994.       if (!NILP (Vinstallation_directory))
  2995.         {
  2996.           /* Add to the path the lisp subdir of the
  2997.          installation dir, if it exists.  */
  2998.           Lisp_Object tem, tem1;
  2999.           tem = Fexpand_file_name (build_string ("lisp"),
  3000.                        Vinstallation_directory);
  3001.           tem1 = Ffile_exists_p (tem);
  3002.           if (!NILP (tem1))
  3003.         {
  3004.           if (NILP (Fmember (tem, Vload_path)))
  3005.             {
  3006.               turn_off_warning = 1;
  3007.               Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3008.             }
  3009.         }
  3010.           else
  3011.         /* That dir doesn't exist, so add the build-time
  3012.            Lisp dirs instead.  */
  3013.         Vload_path = nconc2 (Vload_path, dump_path);
  3014.  
  3015.           /* Add leim under the installation dir, if it exists.  */
  3016.           tem = Fexpand_file_name (build_string ("leim"),
  3017.                        Vinstallation_directory);
  3018.           tem1 = Ffile_exists_p (tem);
  3019.           if (!NILP (tem1))
  3020.         {
  3021.           if (NILP (Fmember (tem, Vload_path)))
  3022.             Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3023.         }
  3024.  
  3025.           /* Add site-list under the installation dir, if it exists.  */
  3026.           tem = Fexpand_file_name (build_string ("site-lisp"),
  3027.                        Vinstallation_directory);
  3028.           tem1 = Ffile_exists_p (tem);
  3029.           if (!NILP (tem1))
  3030.         {
  3031.           if (NILP (Fmember (tem, Vload_path)))
  3032.             Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3033.         }
  3034.  
  3035.           /* If Emacs was not built in the source directory,
  3036.          and it is run from where it was built, add to load-path
  3037.          the lisp, leim and site-lisp dirs under that directory.  */
  3038.  
  3039.           if (NILP (Fequal (Vinstallation_directory, Vsource_directory)))
  3040.         {
  3041.           Lisp_Object tem2;
  3042.  
  3043.           tem = Fexpand_file_name (build_string ("src/Makefile"),
  3044.                        Vinstallation_directory);
  3045.           tem1 = Ffile_exists_p (tem);
  3046.  
  3047.           /* Don't be fooled if they moved the entire source tree
  3048.              AFTER dumping Emacs.  If the build directory is indeed
  3049.              different from the source dir, src/Makefile.in and
  3050.              src/Makefile will not be found together.  */
  3051.           tem = Fexpand_file_name (build_string ("src/Makefile.in"),
  3052.                        Vinstallation_directory);
  3053.           tem2 = Ffile_exists_p (tem);
  3054.           if (!NILP (tem1) && NILP (tem2))
  3055.             {
  3056.               tem = Fexpand_file_name (build_string ("lisp"),
  3057.                            Vsource_directory);
  3058.  
  3059.               if (NILP (Fmember (tem, Vload_path)))
  3060.             Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3061.  
  3062.               tem = Fexpand_file_name (build_string ("leim"),
  3063.                            Vsource_directory);
  3064.  
  3065.               if (NILP (Fmember (tem, Vload_path)))
  3066.             Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3067.  
  3068.               tem = Fexpand_file_name (build_string ("site-lisp"),
  3069.                            Vsource_directory);
  3070.  
  3071.               if (NILP (Fmember (tem, Vload_path)))
  3072.             Vload_path = nconc2 (Vload_path, Fcons (tem, Qnil));
  3073.             }
  3074.         }
  3075.         }
  3076.     }
  3077.     }
  3078.   else
  3079.     {
  3080.       /* NORMAL refers to the lisp dir in the source directory.  */
  3081.       /* We used to add ../lisp at the front here, but
  3082.      that caused trouble because it was copied from dump_path
  3083.      into Vload_path, aboe, when Vinstallation_directory was non-nil.
  3084.      It should be unnecessary.  */
  3085.       Vload_path = decode_env_path (0, normal);
  3086.       dump_path = Vload_path;
  3087.     }
  3088. #endif
  3089.  
  3090. #ifndef WINDOWSNT
  3091.   /* When Emacs is invoked over network shares on NT, PATH_LOADSEARCH is 
  3092.      almost never correct, thereby causing a warning to be printed out that 
  3093.      confuses users.  Since PATH_LOADSEARCH is always overridden by the
  3094.      EMACSLOADPATH environment variable below, disable the warning on NT.  */
  3095.  
  3096.   /* Warn if dirs in the *standard* path don't exist.  */
  3097.   if (!turn_off_warning)
  3098.     {
  3099.       Lisp_Object path_tail;
  3100.  
  3101.       for (path_tail = Vload_path;
  3102.        !NILP (path_tail);
  3103.        path_tail = XCONS (path_tail)->cdr)
  3104.     {
  3105.       Lisp_Object dirfile;
  3106.       dirfile = Fcar (path_tail);
  3107.       if (STRINGP (dirfile))
  3108.         {
  3109.           dirfile = Fdirectory_file_name (dirfile);
  3110.           if (access (XSTRING (dirfile)->data, 0) < 0)
  3111.         dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
  3112.                  XCONS (path_tail)->car);
  3113.         }
  3114.     }
  3115.     }
  3116. #endif /* WINDOWSNT */
  3117.  
  3118.   /* If the EMACSLOADPATH environment variable is set, use its value.
  3119.      This doesn't apply if we're dumping.  */
  3120. #ifndef CANNOT_DUMP
  3121.   if (NILP (Vpurify_flag)
  3122.       && egetenv ("EMACSLOADPATH"))
  3123. #endif
  3124.     Vload_path = decode_env_path ("EMACSLOADPATH", normal);
  3125.  
  3126.   Vvalues = Qnil;
  3127.  
  3128.   load_in_progress = 0;
  3129.   Vload_file_name = Qnil;
  3130.  
  3131.   load_descriptor_list = Qnil;
  3132.  
  3133.   Vstandard_input = Qt;
  3134. }
  3135.  
  3136. /* Print a warning, using format string FORMAT, that directory DIRNAME
  3137.    does not exist.  Print it on stderr and put it in *Message*.  */
  3138.  
  3139. void
  3140. dir_warning (format, dirname)
  3141.      char *format;
  3142.      Lisp_Object dirname;
  3143. {
  3144.   char *buffer
  3145.     = (char *) alloca (XSTRING (dirname)->size + strlen (format) + 5);
  3146.  
  3147.   fprintf (stderr, format, XSTRING (dirname)->data);
  3148.   sprintf (buffer, format, XSTRING (dirname)->data);
  3149.   /* Don't log the warning before we've initialized!! */
  3150.   if (initialized)
  3151.     message_dolog (buffer, strlen (buffer), 0, STRING_MULTIBYTE (dirname));
  3152. }
  3153.  
  3154. void
  3155. syms_of_lread ()
  3156. {
  3157.   defsubr (&Sread);
  3158.   defsubr (&Sread_from_string);
  3159.   defsubr (&Sintern);
  3160.   defsubr (&Sintern_soft);
  3161.   defsubr (&Sunintern);
  3162.   defsubr (&Sload);
  3163.   defsubr (&Seval_buffer);
  3164.   defsubr (&Seval_region);
  3165.   defsubr (&Sread_char);
  3166.   defsubr (&Sread_char_exclusive);
  3167.   defsubr (&Sread_event);
  3168.   defsubr (&Sget_file_char);
  3169.   defsubr (&Smapatoms);
  3170.  
  3171.   DEFVAR_LISP ("obarray", &Vobarray,
  3172.     "Symbol table for use by `intern' and `read'.\n\
  3173. It is a vector whose length ought to be prime for best results.\n\
  3174. The vector's contents don't make sense if examined from Lisp programs;\n\
  3175. to find all the symbols in an obarray, use `mapatoms'.");
  3176.  
  3177.   DEFVAR_LISP ("values", &Vvalues,
  3178.     "List of values of all expressions which were read, evaluated and printed.\n\
  3179. Order is reverse chronological.");
  3180.  
  3181.   DEFVAR_LISP ("standard-input", &Vstandard_input,
  3182.     "Stream for read to get input from.\n\
  3183. See documentation of `read' for possible values.");
  3184.   Vstandard_input = Qt;
  3185.  
  3186.   DEFVAR_LISP ("load-path", &Vload_path,
  3187.     "*List of directories to search for files to load.\n\
  3188. Each element is a string (directory name) or nil (try default directory).\n\
  3189. Initialized based on EMACSLOADPATH environment variable, if any,\n\
  3190. otherwise to default specified by file `paths.h' when Emacs was built.");
  3191.  
  3192.   DEFVAR_BOOL ("load-in-progress", &load_in_progress,
  3193.     "Non-nil iff inside of `load'.");
  3194.  
  3195.   DEFVAR_LISP ("after-load-alist", &Vafter_load_alist,
  3196.     "An alist of expressions to be evalled when particular files are loaded.\n\
  3197. Each element looks like (FILENAME FORMS...).\n\
  3198. When `load' is run and the file-name argument is FILENAME,\n\
  3199. the FORMS in the corresponding element are executed at the end of loading.\n\n\
  3200. FILENAME must match exactly!  Normally FILENAME is the name of a library,\n\
  3201. with no directory specified, since that is how `load' is normally called.\n\
  3202. An error in FORMS does not undo the load,\n\
  3203. but does prevent execution of the rest of the FORMS.");
  3204.   Vafter_load_alist = Qnil;
  3205.  
  3206.   DEFVAR_LISP ("load-history", &Vload_history,
  3207.     "Alist mapping source file names to symbols and features.\n\
  3208. Each alist element is a list that starts with a file name,\n\
  3209. except for one element (optional) that starts with nil and describes\n\
  3210. definitions evaluated from buffers not visiting files.\n\
  3211. The remaining elements of each list are symbols defined as functions\n\
  3212. or variables, and cons cells `(provide . FEATURE)' and `(require . FEATURE)'.");
  3213.   Vload_history = Qnil;
  3214.  
  3215.   DEFVAR_LISP ("load-file-name", &Vload_file_name,
  3216.     "Full name of file being loaded by `load'.");
  3217.   Vload_file_name = Qnil;
  3218.  
  3219.   DEFVAR_LISP ("current-load-list", &Vcurrent_load_list,
  3220.     "Used for internal purposes by `load'.");
  3221.   Vcurrent_load_list = Qnil;
  3222.  
  3223. #ifdef EMX
  3224.   DEFVAR_BOOL ("emx-cdrom-load", &emx_cdrom_load,
  3225.     "*Non-nil if `load' should try again if the file is not found,\n\
  3226. replacing `-' with `_' in the file name.");
  3227. #endif /* EMX */
  3228.  
  3229.   DEFVAR_LISP ("load-read-function", &Vload_read_function,
  3230.     "Function used by `load' and `eval-region' for reading expressions.\n\
  3231. The default is nil, which means use the function `read'.");
  3232.   Vload_read_function = Qnil;
  3233.  
  3234.   DEFVAR_LISP ("load-source-file-function", &Vload_source_file_function,
  3235.     "Function called in `load' for loading an Emacs lisp source file.\n\
  3236. This function is for doing code conversion before reading the source file.\n\
  3237. If nil, loading is done without any code conversion.\n\
  3238. Arguments are FULLNAME, FILE, NOERROR, NOMESSAGE, where\n\
  3239.  FULLNAME is the full name of FILE.\n\
  3240. See `load' for the meaning of the remaining arguments.");
  3241.   Vload_source_file_function = Qnil;
  3242.  
  3243.   DEFVAR_BOOL ("load-force-doc-strings", &load_force_doc_strings,
  3244.      "Non-nil means `load' should force-load all dynamic doc strings.\n\
  3245. This is useful when the file being loaded is a temporary copy.");
  3246.   load_force_doc_strings = 0;
  3247.  
  3248.   DEFVAR_BOOL ("load-convert-to-unibyte", &load_convert_to_unibyte,
  3249.      "Non-nil means `load' converts strings to unibyte whenever possible.\n\
  3250. This is normally used in `load-with-code-conversion'\n\
  3251. for loading non-compiled files.");
  3252.   load_convert_to_unibyte = 0;
  3253.  
  3254.   DEFVAR_LISP ("source-directory", &Vsource_directory,
  3255.      "Directory in which Emacs sources were found when Emacs was built.\n\
  3256. You cannot count on them to still be there!");
  3257.   Vsource_directory
  3258.     = Fexpand_file_name (build_string ("../"),
  3259.              Fcar (decode_env_path (0, PATH_DUMPLOADSEARCH)));
  3260.  
  3261.   DEFVAR_LISP ("preloaded-file-list", &Vpreloaded_file_list,
  3262.      "List of files that were preloaded (when dumping Emacs).");
  3263.   Vpreloaded_file_list = Qnil;
  3264.  
  3265.   /* Vsource_directory was initialized in init_lread.  */
  3266.  
  3267.   load_descriptor_list = Qnil;
  3268.   staticpro (&load_descriptor_list);
  3269.  
  3270.   Qcurrent_load_list = intern ("current-load-list");
  3271.   staticpro (&Qcurrent_load_list);
  3272.  
  3273.   Qstandard_input = intern ("standard-input");
  3274.   staticpro (&Qstandard_input);
  3275.  
  3276.   Qread_char = intern ("read-char");
  3277.   staticpro (&Qread_char);
  3278.  
  3279.   Qget_file_char = intern ("get-file-char");
  3280.   staticpro (&Qget_file_char);
  3281.  
  3282.   Qbackquote = intern ("`");
  3283.   staticpro (&Qbackquote);
  3284.   Qcomma = intern (",");
  3285.   staticpro (&Qcomma);
  3286.   Qcomma_at = intern (",@");
  3287.   staticpro (&Qcomma_at);
  3288.   Qcomma_dot = intern (",.");
  3289.   staticpro (&Qcomma_dot);
  3290.  
  3291.   Qinhibit_file_name_operation = intern ("inhibit-file-name-operation");
  3292.   staticpro (&Qinhibit_file_name_operation);
  3293.  
  3294.   Qascii_character = intern ("ascii-character");
  3295.   staticpro (&Qascii_character);
  3296.  
  3297.   Qfunction = intern ("function");
  3298.   staticpro (&Qfunction);
  3299.  
  3300.   Qload = intern ("load");
  3301.   staticpro (&Qload);
  3302.  
  3303.   Qload_file_name = intern ("load-file-name");
  3304.   staticpro (&Qload_file_name);
  3305.  
  3306.   staticpro (&dump_path);
  3307.  
  3308.   staticpro (&read_objects);
  3309.   read_objects = Qnil;
  3310. }
  3311.