Get rid of funvec.
[bpt/emacs.git] / src / doc.c
index a8f6217..de20edb 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,6 +1,5 @@
 /* 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, 2009, 2010
+   Copyright (C) 1985-1986, 1993-1995, 1997-2011
                  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
@@ -25,18 +24,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #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>
-#endif
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
-#ifndef O_RDONLY
-#define O_RDONLY 0
-#endif
 
 #include "lisp.h"
 #include "buffer.h"
@@ -45,21 +34,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "keymap.h"
 #include "buildobj.h"
 
-#ifdef HAVE_INDEX
-extern char *index (const char *, int);
-#endif
-
-Lisp_Object Vdoc_file_name;
-
 Lisp_Object Qfunction_documentation;
 
-/* A list of files used to build this Emacs binary.  */
-static Lisp_Object Vbuild_files;
-
-extern Lisp_Object Voverriding_local_map;
-
-extern Lisp_Object Qremap;
-
+extern Lisp_Object Qclosure;
 /* Buffer used for reading from documentation file.  */
 static char *get_doc_string_buffer;
 static int get_doc_string_buffer_size;
@@ -107,8 +84,8 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
   register int fd;
   register char *name;
   register char *p, *p1;
-  int minsize;
-  int offset, position;
+  EMACS_INT minsize;
+  EMACS_INT offset, position;
   Lisp_Object file, tem;
 
   if (INTEGERP (filepos))
@@ -144,12 +121,12 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
       if (minsize < 8)
        minsize = 8;
       name = (char *) alloca (minsize + SCHARS (file) + 8);
-      strcpy (name, SDATA (Vdoc_directory));
-      strcat (name, SDATA (file));
+      strcpy (name, SSDATA (Vdoc_directory));
+      strcat (name, SSDATA (file));
     }
   else
     {
-      name = (char *) SDATA (file);
+      name = SSDATA (file);
     }
 
   fd = emacs_open (name, O_RDONLY, 0);
@@ -161,7 +138,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
          /* Preparing to dump; DOC file is probably not installed.
             So check in ../etc. */
          strcpy (name, "../etc/");
-         strcat (name, SDATA (file));
+         strcat (name, SSDATA (file));
 
          fd = emacs_open (name, O_RDONLY, 0);
        }
@@ -187,14 +164,14 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
   p = get_doc_string_buffer;
   while (1)
     {
-      int space_left = (get_doc_string_buffer_size
-                       - (p - get_doc_string_buffer));
+      EMACS_INT space_left = (get_doc_string_buffer_size
+                             - (p - get_doc_string_buffer));
       int nread;
 
       /* Allocate or grow the buffer if we need to.  */
       if (space_left == 0)
        {
-         int in_buffer = p - get_doc_string_buffer;
+         EMACS_INT in_buffer = p - get_doc_string_buffer;
          get_doc_string_buffer_size += 16 * 1024;
          get_doc_string_buffer
            = (char *) xrealloc (get_doc_string_buffer,
@@ -218,9 +195,9 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
       if (!nread)
        break;
       if (p == get_doc_string_buffer)
-       p1 = (char *) index (p + offset, '\037');
+       p1 = strchr (p + offset, '\037');
       else
-       p1 = (char *) index (p, '\037');
+       p1 = strchr (p, '\037');
       if (p1)
        {
          *p1 = 0;
@@ -284,7 +261,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
      the same way we would read bytes from a file.  */
   if (definition)
     {
-      read_bytecode_pointer = get_doc_string_buffer + offset;
+      read_bytecode_pointer = (unsigned char *) get_doc_string_buffer + offset;
       return Fread (Qlambda);
     }
 
@@ -293,10 +270,11 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
                                to - (get_doc_string_buffer + offset));
   else
     {
-      /* Let the data determine whether the string is multibyte,
-        even if Emacs is running in --unibyte mode.  */
-      int nchars = multibyte_chars_in_text (get_doc_string_buffer + offset,
-                                           to - (get_doc_string_buffer + offset));
+      /* The data determines whether the string is multibyte.  */
+      EMACS_INT nchars =
+       multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer
+                                 + offset),
+                                to - (get_doc_string_buffer + offset));
       return make_string_from_bytes (get_doc_string_buffer + offset,
                                     nchars,
                                     to - (get_doc_string_buffer + offset));
@@ -406,6 +384,8 @@ string is passed through `substitute-command-keys'.  */)
          else
            return Qnil;
        }
+      else if (EQ (funcar, Qclosure))
+       return Fdocumentation (Fcdr (XCDR (fun)), raw);
       else if (EQ (funcar, Qmacro))
        return Fdocumentation (Fcdr (fun), raw);
       else
@@ -498,7 +478,7 @@ aren't strings.  */)
     }
   else if (!STRINGP (tem))
     /* Feval protects its argument.  */
-    tem = Feval (tem);
+    tem = Feval (tem, Qnil);
 
   if (NILP (raw) && STRINGP (tem))
     tem = Fsubstitute_command_keys (tem);
@@ -533,6 +513,8 @@ store_function_docstring (Lisp_Object fun, EMACS_INT offset)
        }
       else if (EQ (tem, Qmacro))
        store_function_docstring (XCDR (fun), offset);
+      else if (EQ (tem, Qclosure))
+       store_function_docstring (Fcdr (XCDR (fun)), offset);
     }
 
   /* Bytecode objects sometimes have slots for it.  */
@@ -560,8 +542,8 @@ the same file name is found in the `doc-directory'.  */)
 {
   int fd;
   char buf[1024 + 1];
-  register int filled;
-  register int pos;
+  register EMACS_INT filled;
+  register EMACS_INT pos;
   register char *p, *end;
   Lisp_Object sym;
   char *name;
@@ -584,9 +566,9 @@ the same file name is found in the `doc-directory'.  */)
       CHECK_STRING (Vdoc_directory);
       name = (char *) alloca (SCHARS (filename)
                          + SCHARS (Vdoc_directory) + 1);
-      strcpy (name, SDATA (Vdoc_directory));
+      strcpy (name, SSDATA (Vdoc_directory));
     }
-  strcat (name, SDATA (filename));     /*** Add this line ***/
+  strcat (name, SSDATA (filename));    /*** Add this line ***/
 
   /* Vbuild_files is nil when temacs is run, and non-nil after that.  */
   if (NILP (Vbuild_files))
@@ -595,7 +577,7 @@ the same file name is found in the `doc-directory'.  */)
 
     for (beg = buildobj; *beg; beg = end)
       {
-        int len;
+        EMACS_INT len;
 
         while (*beg && isspace (*beg)) ++beg;
 
@@ -630,28 +612,33 @@ 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');
+         end = strchr (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'))
+                {
+                  EMACS_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,
-                         multibyte_chars_in_text (p + 2, end - p - 2),
+                         multibyte_chars_in_text ((unsigned char *) p + 2,
+                                                  end - p - 2),
                          end - p - 2);
          /* Check skip_file so that when a function is defined several
             times in different files (typically, once in xterm, once in
@@ -683,7 +670,7 @@ the same file name is found in the `doc-directory'.  */)
        }
       pos += end - buf;
       filled -= end - buf;
-      memcpy (buf, end, filled);
+      memmove (buf, end, filled);
     }
   emacs_close (fd);
   return Qnil;
@@ -706,20 +693,20 @@ Returns original STRING if no substitutions were made.  Otherwise,
 a new string, without any text properties, is returned.  */)
   (Lisp_Object string)
 {
-  unsigned char *buf;
+  char *buf;
   int changed = 0;
   register unsigned char *strp;
-  register unsigned char *bufp;
-  int idx;
-  int bsize;
+  register char *bufp;
+  EMACS_INT idx;
+  EMACS_INT bsize;
   Lisp_Object tem;
   Lisp_Object keymap;
   unsigned char *start;
-  int length, length_byte;
+  EMACS_INT length, length_byte;
   Lisp_Object name;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   int multibyte;
-  int nchars;
+  EMACS_INT nchars;
 
   if (NILP (string))
     return Qnil;
@@ -737,12 +724,12 @@ a new string, without any text properties, is returned.  */)
      or a specified local map (which means search just that and the
      global map).  If non-nil, it might come from Voverriding_local_map,
      or from a \\<mapname> construct in STRING itself..  */
-  keymap = current_kboard->Voverriding_terminal_local_map;
+  keymap = KVAR (current_kboard, Voverriding_terminal_local_map);
   if (NILP (keymap))
     keymap = Voverriding_local_map;
 
   bsize = SBYTES (string);
-  bufp = buf = (unsigned char *) xmalloc (bsize);
+  bufp = buf = (char *) xmalloc (bsize);
 
   strp = SDATA (string);
   while (strp < SDATA (string) + SBYTES (string))
@@ -771,7 +758,7 @@ a new string, without any text properties, is returned.  */)
        }
       else if (strp[0] == '\\' && strp[1] == '[')
        {
-         int start_idx;
+         EMACS_INT start_idx;
          int follow_remap = 1;
 
          changed = 1;
@@ -789,7 +776,7 @@ a new string, without any text properties, is returned.  */)
 
          /* Save STRP in IDX.  */
          idx = strp - SDATA (string);
-         name = Fintern (make_string (start, length_byte), Qnil);
+         name = Fintern (make_string ((char *) start, length_byte), Qnil);
 
        do_remap:
          tem = Fwhere_is_internal (name, keymap, Qt, Qnil, Qnil);
@@ -810,8 +797,8 @@ a new string, without any text properties, is returned.  */)
 
          if (NILP (tem))       /* but not on any keys */
            {
-             int offset = bufp - buf;
-             buf = (unsigned char *) xrealloc (buf, bsize += 4);
+             EMACS_INT offset = bufp - buf;
+             buf = (char *) xrealloc (buf, bsize += 4);
              bufp = buf + offset;
              memcpy (bufp, "M-x ", 4);
              bufp += 4;
@@ -833,7 +820,7 @@ a new string, without any text properties, is returned.  */)
       else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
        {
          struct buffer *oldbuf;
-         int start_idx;
+         EMACS_INT start_idx;
          /* This is for computing the SHADOWS arg for describe_map_tree.  */
          Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil);
          Lisp_Object earlier_maps;
@@ -856,7 +843,7 @@ a new string, without any text properties, is returned.  */)
          /* Get the value of the keymap in TEM, or nil if undefined.
             Do this while still in the user's current buffer
             in case it is a local variable.  */
-         name = Fintern (make_string (start, length_byte), Qnil);
+         name = Fintern (make_string ((char *) start, length_byte), Qnil);
          tem = Fboundp (name);
          if (! NILP (tem))
            {
@@ -904,14 +891,14 @@ a new string, without any text properties, is returned.  */)
          length_byte = SBYTES (tem);
        subst:
          {
-           int offset = bufp - buf;
-           buf = (unsigned char *) xrealloc (buf, bsize += length_byte);
+           EMACS_INT offset = bufp - buf;
+           buf = (char *) xrealloc (buf, bsize += length_byte);
            bufp = buf + offset;
            memcpy (bufp, start, length_byte);
            bufp += length_byte;
            nchars += length;
            /* Check STRING again in case gc relocated it.  */
-           strp = (unsigned char *) SDATA (string) + idx;
+           strp = SDATA (string) + idx;
          }
        }
       else if (! multibyte)            /* just copy other chars */
@@ -945,11 +932,11 @@ syms_of_doc (void)
   Qfunction_documentation = intern_c_string ("function-documentation");
   staticpro (&Qfunction_documentation);
 
-  DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,
+  DEFVAR_LISP ("internal-doc-file-name", Vdoc_file_name,
               doc: /* Name of file containing documentation strings of built-in symbols.  */);
   Vdoc_file_name = Qnil;
 
-  DEFVAR_LISP ("build-files", &Vbuild_files,
+  DEFVAR_LISP ("build-files", Vbuild_files,
                doc: /* A list of files used to build this Emacs binary.  */);
   Vbuild_files = Qnil;
 
@@ -958,6 +945,3 @@ syms_of_doc (void)
   defsubr (&Ssnarf_documentation);
   defsubr (&Ssubstitute_command_keys);
 }
-
-/* arch-tag: 56281d4d-6949-43e2-be2e-f6517de744ba
-   (do not change this comment) */