remove use of nested function in map_obarray
[bpt/emacs.git] / lib-src / make-docfile.c
index bd87b5b..15ffa13 100644 (file)
@@ -1,6 +1,7 @@
 /* Generate doc-string file for GNU Emacs from source files.
-   Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2012
-                 Free Software Foundation, Inc.
+
+Copyright (C) 1985-1986, 1992-1994, 1997, 1999-2014 Free Software
+Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -35,56 +36,41 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
-/* Defined to be emacs_main, sys_fopen, etc. in config.h.  */
-#undef main
-#undef fopen
-#undef chdir
-
 #include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h>   /* config.h unconditionally includes this anyway */
 #ifdef MSDOS
 #include <fcntl.h>
 #endif /* MSDOS */
 #ifdef WINDOWSNT
+/* Defined to be sys_fopen in ms-w32.h, but only #ifdef emacs, so this
+   is really just insurance.  */
+#undef fopen
 #include <fcntl.h>
 #include <direct.h>
 #endif /* WINDOWSNT */
 
 #ifdef DOS_NT
+/* Defined to be sys_chdir in ms-w32.h, but only #ifdef emacs, so this
+   is really just insurance.
+
+   Similarly, msdos defines this as sys_chdir, but we're not linking with the
+   file where that function is defined.  */
+#undef chdir
 #define READ_TEXT "rt"
 #define READ_BINARY "rb"
+#define IS_SLASH(c)  ((c) == '/' || (c) == '\\' || (c) == ':')
 #else  /* not DOS_NT */
 #define READ_TEXT "r"
 #define READ_BINARY "r"
+#define IS_SLASH(c)  ((c) == '/')
 #endif /* not DOS_NT */
 
-#ifndef DIRECTORY_SEP
-#define DIRECTORY_SEP '/'
-#endif
-
-#ifndef IS_DIRECTORY_SEP
-#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
-#endif
-
-/* Use this to suppress gcc's `...may be used before initialized' warnings.  */
-#ifdef lint
-# define IF_LINT(Code) Code
-#else
-# define IF_LINT(Code) /* empty */
-#endif
-
 static int scan_file (char *filename);
 static int scan_lisp_file (const char *filename, const char *mode);
 static int scan_c_file (char *filename, const char *mode);
 static void start_globals (void);
 static void write_globals (void);
 
-#ifdef MSDOS
-/* s/msdos.h defines this as sys_chdir, but we're not linking with the
-   file where that function is defined.  */
-#undef chdir
-#endif
-
 #include <unistd.h>
 
 /* Stdio stream for output to the DOC file.  */
@@ -290,7 +276,7 @@ struct rcsoc_state
 /* Output CH to the file or buffer in STATE.  Any pending newlines or
    spaces are output first.  */
 
-static inline void
+static void
 put_char (int ch, struct rcsoc_state *state)
 {
   int out_ch;
@@ -561,14 +547,15 @@ write_c_args (FILE *out, char *func, char *buf, int minargs, int maxargs)
   putc (')', out);
 }
 \f
-/* The types of globals.  */
+/* The types of globals.  These are sorted roughly in decreasing alignment
+   order to avoid allocation gaps, except that functions are last.  */
 enum global_type
 {
-  FUNCTION,
+  INVALID,
+  LISP_OBJECT,
   EMACS_INTEGER,
   BOOLEAN,
-  LISP_OBJECT,
-  INVALID
+  FUNCTION
 };
 
 /* A single global.  */
@@ -617,13 +604,8 @@ compare_globals (const void *a, const void *b)
   const struct global *ga = a;
   const struct global *gb = b;
 
-  if (ga->type == FUNCTION)
-    {
-      if (gb->type != FUNCTION)
-       return 1;
-    }
-  else if (gb->type == FUNCTION)
-    return -1;
+  if (ga->type != gb->type)
+    return ga->type - gb->type;
 
   return strcmp (ga->name, gb->name);
 }
@@ -642,7 +624,7 @@ write_globals (void)
   qsort (globals, num_globals, sizeof (struct global), compare_globals);
   for (i = 0; i < num_globals; ++i)
     {
-      char const *type;
+      char const *type = 0;
 
       switch (globals[i].type)
        {
@@ -650,7 +632,7 @@ write_globals (void)
          type = "EMACS_INT";
          break;
        case BOOLEAN:
-         type = "int";
+         type = "bool";
          break;
        case LISP_OBJECT:
          type = "Lisp_Object";
@@ -667,7 +649,7 @@ write_globals (void)
          fatal ("not a recognized DEFVAR_", 0);
        }
 
-      if (globals[i].type != FUNCTION)
+      if (type)
        {
          fprintf (outfile, "  %s f_%s;\n", type, globals[i].name);
          fprintf (outfile, "#define %s globals.f_%s\n",
@@ -679,8 +661,11 @@ write_globals (void)
             special hacks.  */
          if (strcmp (globals[i].name, "Fthrow") == 0
              || strcmp (globals[i].name, "Ftop_level") == 0
-             || strcmp (globals[i].name, "Fkill_emacs") == 0)
+             || strcmp (globals[i].name, "Fkill_emacs") == 0
+             || strcmp (globals[i].name, "Fexit_recursive_edit") == 0
+             || strcmp (globals[i].name, "Fabort_recursive_edit") == 0)
            fprintf (outfile, "_Noreturn ");
+
          fprintf (outfile, "EXFUN (%s, ", globals[i].name);
          if (globals[i].value == -1)
            fprintf (outfile, "MANY");
@@ -688,7 +673,17 @@ write_globals (void)
            fprintf (outfile, "UNEVALLED");
          else
            fprintf (outfile, "%d", globals[i].value);
-         fprintf (outfile, ");\n");
+         fprintf (outfile, ")");
+
+         /* It would be nice to have a cleaner way to deal with these
+            special hacks, too.  */
+         if (strcmp (globals[i].name, "Fbyteorder") == 0
+             || strcmp (globals[i].name, "Ftool_bar_height") == 0
+             || strcmp (globals[i].name, "Fmax_char") == 0
+             || strcmp (globals[i].name, "Fidentity") == 0)
+           fprintf (outfile, " ATTRIBUTE_CONST");
+
+         fprintf (outfile, ";\n");
        }
 
       while (i + 1 < num_globals
@@ -1043,9 +1038,9 @@ scan_c_file (char *filename, const char *mode)
  arglist, but the doc string must still have a backslash and newline
  immediately after the double quote.
  The only source files that must follow this convention are preloaded
- uncompiled ones like loaddefs.el and bindings.el; aside
- from that, it is always the .elc file that we look at, and they are no
problem because byte-compiler output follows this convention.
+ uncompiled ones like loaddefs.el; aside from that, it is always the .elc
+ file that we should look at, and they are no problem because byte-compiler
+ output follows this convention.
  The NAME and DOCSTRING are output.
  NAME is preceded by `F' for a function or `V' for a variable.
  An entry is output only if DOCSTRING has \ newline just after the opening ".
@@ -1091,7 +1086,7 @@ read_lisp_symbol (FILE *infile, char *buffer)
 static int
 search_lisp_doc_at_eol (FILE *infile)
 {
-  char c = 0, c1 = 0, c2 = 0;
+  int c = 0, c1 = 0, c2 = 0;
 
   /* Skip until the end of line; remember two previous chars.  */
   while (c != '\n' && c != '\r' && c != EOF)
@@ -1106,8 +1101,7 @@ search_lisp_doc_at_eol (FILE *infile)
   if (c2 != '"' || c1 != '\\')
     {
 #ifdef DEBUG
-      fprintf (stderr, "## non-docstring in %s (%s)\n",
-              buffer, filename);
+      fprintf (stderr, "## non-docstring found\n");
 #endif
       if (c != EOF)
        ungetc (c, infile);
@@ -1116,15 +1110,50 @@ search_lisp_doc_at_eol (FILE *infile)
   return 1;
 }
 
+#define DEF_ELISP_FILE(fn)  { #fn, sizeof(#fn) - 1 }
+
 static int
 scan_lisp_file (const char *filename, const char *mode)
 {
   FILE *infile;
   register int c;
   char *saved_string = 0;
+  /* These are the only files that are loaded uncompiled, and must
+     follow the conventions of the doc strings expected by this
+     function.  These conventions are automatically followed by the
+     byte compiler when it produces the .elc files.  */
+  static struct {
+    const char *fn;
+    size_t fl;
+  } const uncompiled[] = {
+    DEF_ELISP_FILE (loaddefs.el),
+    DEF_ELISP_FILE (loadup.el),
+    DEF_ELISP_FILE (charprop.el),
+    DEF_ELISP_FILE (cp51932.el),
+    DEF_ELISP_FILE (eucjp-ms.el)
+  };
+  int i, match;
+  size_t flen = strlen (filename);
 
   if (generate_globals)
     fatal ("scanning lisp file when -g specified", 0);
+  if (flen > 3 && !strcmp (filename + flen - 3, ".el"))
+    {
+      for (i = 0, match = 0; i < sizeof (uncompiled) / sizeof (uncompiled[0]);
+          i++)
+       {
+         if (uncompiled[i].fl <= flen
+             && !strcmp (filename + flen - uncompiled[i].fl, uncompiled[i].fn)
+             && (flen == uncompiled[i].fl
+                 || IS_SLASH (filename[flen - uncompiled[i].fl - 1])))
+           {
+             match = 1;
+             break;
+           }
+       }
+      if (!match)
+       fatal ("uncompiled lisp file %s is not supported", filename);
+    }
 
   infile = fopen (filename, mode);
   if (infile == NULL)