Backport revisions 2011-04-24T05:30:24Z!eggert@cs.ucla.edu..2011-04-25T19:40:22Z...
[bpt/emacs.git] / src / doc.c
index 81285c0..d22c3bf 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,14 +1,14 @@
 /* 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, 2011
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,16 +16,15 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+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>
@@ -44,6 +43,7 @@ Boston, MA 02110-1301, USA.  */
 #include "keyboard.h"
 #include "character.h"
 #include "keymap.h"
+#include "buildobj.h"
 
 #ifdef HAVE_INDEX
 extern char *index P_ ((const char *, int));
@@ -60,28 +60,6 @@ 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;
@@ -171,7 +149,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
     {
@@ -188,7 +165,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);
        }
@@ -578,6 +554,7 @@ store_function_docstring (fun, offset)
     }
 }
 
+static const char buildobj[] = BUILDOBJ;
 
 DEFUN ("Snarf-documentation", Fsnarf_documentation, Ssnarf_documentation,
        1, 1, 0,
@@ -620,37 +597,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;
 
@@ -666,8 +619,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);
@@ -688,24 +640,28 @@ the same file name is found in the `doc-directory'.  */)
       p = buf;
       end = buf + (filled < 512 ? filled : filled - 128);
       while (p != end && *p != '\037') p++;
-      /* p points to ^_Ffunctionname\n or ^_Vvarname\n.  */
+      /* p points to ^_Ffunctionname\n or ^_Vvarname\n or ^_Sfilename\n.  */
       if (p != end)
        {
          end = (char *) index (p, '\n');
 
           /* See if this is a file name, and if it is a file in build-files.  */
-          if (p[1] == 'S' && end - p > 4 && end[-2] == '.'
-              && (end[-1] == 'o' || end[-1] == 'c'))
+          if (p[1] == 'S')
             {
-              int len = end - p - 2;
-              char *fromfile = alloca (len + 1);
-              strncpy (fromfile, &p[2], len);
-              fromfile[len] = 0;
-              if (fromfile[len-1] == 'c')
-                fromfile[len-1] = 'o';
-
-             skip_file = NILP (Fmember (build_string (fromfile),
-                                        Vbuild_files));
+              skip_file = 0;
+              if (end - p > 4 && end[-2] == '.'
+                  && (end[-1] == 'o' || end[-1] == 'c'))
+                {
+                  int len = end - p - 2;
+                  char *fromfile = alloca (len + 1);
+                  strncpy (fromfile, &p[2], len);
+                  fromfile[len] = 0;
+                  if (fromfile[len-1] == 'c')
+                    fromfile[len-1] = 'o';
+
+                  skip_file = NILP (Fmember (build_string (fromfile),
+                                             Vbuild_files));
+                }
             }
 
          sym = oblookup (Vobarray, p + 2,
@@ -815,9 +771,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
@@ -852,12 +807,9 @@ 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
+         if (VECTORP (tem) && XVECTOR_SIZE (tem) > 1
              && EQ (AREF (tem, 0), Qremap) && SYMBOLP (AREF (tem, 1))
              && follow_remap)
            {
@@ -982,9 +934,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
@@ -1006,7 +957,7 @@ a new string, without any text properties, is returned.  */)
 void
 syms_of_doc ()
 {
-  Qfunction_documentation = intern ("function-documentation");
+  Qfunction_documentation = intern_c_string ("function-documentation");
   staticpro (&Qfunction_documentation);
 
   DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,