If kbd_buffer is becoming full, stop reading until it drains (Bug#6571).
[bpt/emacs.git] / src / doc.c
index c307119..57e1bc8 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,6 +1,6 @@
 /* Record indices of function doc strings stored in a file.
    Copyright (C) 1985, 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006, 2007, 2008
+                 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -22,8 +22,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 
 #include <sys/types.h>
-#include <sys/file.h>  /* Must be after sys/types.h for USG and BSD4_1*/
+#include <sys/file.h>  /* Must be after sys/types.h for USG*/
 #include <ctype.h>
+#include <setjmp.h>
 
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
@@ -42,9 +43,10 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "keyboard.h"
 #include "character.h"
 #include "keymap.h"
+#include "buildobj.h"
 
 #ifdef HAVE_INDEX
-extern char *index P_ ((const char *, int));
+extern char *index (const char *, int);
 #endif
 
 Lisp_Object Vdoc_file_name;
@@ -58,41 +60,18 @@ extern Lisp_Object Voverriding_local_map;
 
 extern Lisp_Object Qremap;
 
-/* For VMS versions with limited file name syntax,
-   convert the name to something VMS will allow.  */
-static void
-munge_doc_file_name (name)
-     char *name;
-{
-#ifdef VMS
-#ifndef NO_HYPHENS_IN_FILENAMES
-  extern char * sys_translate_unix (char *ufile);
-  strcpy (name, sys_translate_unix (name));
-#else /* NO_HYPHENS_IN_FILENAMES */
-  char *p = name;
-  while (*p)
-    {
-      if (*p == '-')
-       *p = '_';
-      p++;
-    }
-#endif /* NO_HYPHENS_IN_FILENAMES */
-#endif /* VMS */
-}
-
 /* Buffer used for reading from documentation file.  */
 static char *get_doc_string_buffer;
 static int get_doc_string_buffer_size;
 
 static unsigned char *read_bytecode_pointer;
-Lisp_Object Fsnarf_documentation P_ ((Lisp_Object));
+Lisp_Object Fsnarf_documentation (Lisp_Object);
 
 /* readchar in lread.c calls back here to fetch the next byte.
    If UNREADFLAG is 1, we unread a byte.  */
 
 int
-read_bytecode_char (unreadflag)
-     int unreadflag;
+read_bytecode_char (int unreadflag)
 {
   if (unreadflag)
     {
@@ -122,9 +101,7 @@ read_bytecode_char (unreadflag)
    and return a cons cell.  */
 
 Lisp_Object
-get_doc_string (filepos, unibyte, definition)
-     Lisp_Object filepos;
-     int unibyte, definition;
+get_doc_string (Lisp_Object filepos, int unibyte, int definition)
 {
   char *from, *to;
   register int fd;
@@ -169,7 +146,6 @@ get_doc_string (filepos, unibyte, definition)
       name = (char *) alloca (minsize + SCHARS (file) + 8);
       strcpy (name, SDATA (Vdoc_directory));
       strcat (name, SDATA (file));
-      munge_doc_file_name (name);
     }
   else
     {
@@ -186,7 +162,6 @@ get_doc_string (filepos, unibyte, definition)
             So check in ../etc. */
          strcpy (name, "../etc/");
          strcat (name, SDATA (file));
-         munge_doc_file_name (name);
 
          fd = emacs_open (name, O_RDONLY, 0);
        }
@@ -333,15 +308,13 @@ get_doc_string (filepos, unibyte, definition)
    of a compiled function from the .elc file.  */
 
 Lisp_Object
-read_doc_string (filepos)
-     Lisp_Object filepos;
+read_doc_string (Lisp_Object filepos)
 {
   return get_doc_string (filepos, 0, 1);
 }
 
 static int
-reread_doc_file (file)
-     Lisp_Object file;
+reread_doc_file (Lisp_Object file)
 {
 #if 0
   Lisp_Object reply, prompt[3];
@@ -537,10 +510,8 @@ aren't strings.  */)
 /* Scanning the DOC files and placing docstring offsets into functions.  */
 
 static void
-store_function_docstring (fun, offset)
-     Lisp_Object fun;
-     /* Use EMACS_INT because we get this from pointer subtraction.  */
-     EMACS_INT offset;
+store_function_docstring (Lisp_Object fun, EMACS_INT offset)
+/* Use EMACS_INT because we get offset from pointer subtraction.  */
 {
   fun = indirect_function (fun);
 
@@ -560,7 +531,7 @@ store_function_docstring (fun, offset)
        {
          tem = Fcdr (Fcdr (fun));
          if (CONSP (tem) && INTEGERP (XCAR (tem)))
-           XSETCARFASTINT (tem, offset);
+           XSETCAR (tem, make_number (offset));
        }
       else if (EQ (tem, Qmacro))
        store_function_docstring (XCDR (fun), offset);
@@ -576,6 +547,7 @@ store_function_docstring (fun, offset)
     }
 }
 
+static const char buildobj[] = BUILDOBJ;
 
 DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation,
        1, 1, 0,
@@ -618,37 +590,13 @@ the same file name is found in the `doc-directory'.  */)
       strcpy (name, SDATA (Vdoc_directory));
     }
   strcat (name, SDATA (filename));     /*** Add this line ***/
-  munge_doc_file_name (name);
 
   /* Vbuild_files is nil when temacs is run, and non-nil after that.  */
   if (NILP (Vbuild_files))
   {
-    size_t cp_size = 0;
-    size_t to_read;
-    int nr_read;
-    char *cp = NULL;
-    char *beg, *end;
-
-    fd = emacs_open ("buildobj.lst", O_RDONLY, 0);
-    if (fd < 0)
-      report_file_error ("Opening file buildobj.lst", Qnil);
-
-    filled = 0;
-    for (;;)
-      {
-        cp_size += 1024;
-        to_read = cp_size - 1 - filled;
-        cp = xrealloc (cp, cp_size);
-        nr_read = emacs_read (fd, &cp[filled], to_read);
-        filled += nr_read;
-        if (nr_read < to_read)
-          break;
-      }
+    const char *beg, *end;
 
-    emacs_close (fd);
-    cp[filled] = 0;
-
-    for (beg = cp; *beg; beg = end)
+    for (beg = buildobj; *beg; beg = end)
       {
         int len;
 
@@ -664,8 +612,7 @@ the same file name is found in the `doc-directory'.  */)
         if (len > 0)
           Vbuild_files = Fcons (make_string (beg, len), Vbuild_files);
       }
-
-    xfree (cp);
+    Vbuild_files = Fpurecopy (Vbuild_files);
   }
 
   fd = emacs_open (name, O_RDONLY, 0);
@@ -813,9 +760,8 @@ a new string, without any text properties, is returned.  */)
          if (multibyte)
            {
              int len;
-             int maxlen = SDATA (string) + SBYTES (string) - strp;
 
-             STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+             STRING_CHAR_AND_LENGTH (strp, len);
              if (len == 1)
                *bufp = *strp;
              else
@@ -850,10 +796,7 @@ a new string, without any text properties, is returned.  */)
          name = Fintern (make_string (start, length_byte), Qnil);
 
        do_remap:
-         /* Ignore remappings unless there are no ordinary bindings. */
-         tem = Fwhere_is_internal (name, keymap, Qt, Qnil, Qt);
-         if (NILP (tem))
-           tem = Fwhere_is_internal (name, keymap, Qt, Qnil, Qnil);
+         tem = Fwhere_is_internal (name, keymap, Qt, Qnil, Qnil);
 
          if (VECTORP (tem) && XVECTOR (tem)->size > 1
              && EQ (AREF (tem, 0), Qremap) && SYMBOLP (AREF (tem, 1))
@@ -980,9 +923,8 @@ a new string, without any text properties, is returned.  */)
       else
        {
          int len;
-         int maxlen = SDATA (string) + SBYTES (string) - strp;
 
-         STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+         STRING_CHAR_AND_LENGTH (strp, len);
          if (len == 1)
            *bufp = *strp;
          else
@@ -1002,9 +944,9 @@ a new string, without any text properties, is returned.  */)
 }
 \f
 void
-syms_of_doc ()
+syms_of_doc (void)
 {
-  Qfunction_documentation = intern ("function-documentation");
+  Qfunction_documentation = intern_c_string ("function-documentation");
   staticpro (&Qfunction_documentation);
 
   DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,