]> code.delx.au - gnu-emacs/blobdiff - src/doc.c
Rework C source files to avoid ^(
[gnu-emacs] / src / doc.c
index 7a298e286319b77d20d67d14211d2a8156257903..1d466612c668aa777356f406fa050e2dad548413 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,14 +1,14 @@
 /* Record indices of function doc strings stored in a file. -*- coding: utf-8 -*-
 
-Copyright (C) 1985-1986, 1993-1995, 1997-2015 Free Software Foundation,
+Copyright (C) 1985-1986, 1993-1995, 1997-2016 Free Software Foundation,
 Inc.
 
 This file is part of GNU Emacs.
 
 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 of the License, 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
@@ -31,9 +31,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "lisp.h"
 #include "character.h"
+#include "coding.h"
 #include "buffer.h"
 #include "disptab.h"
-#include "keyboard.h"
 #include "keymap.h"
 
 /* Buffer used for reading from documentation file.  */
@@ -138,6 +138,9 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
 #endif
       if (fd < 0)
        {
+         if (errno == EMFILE || errno == ENFILE)
+           report_file_error ("Read error on documentation file", file);
+
          SAFE_FREE ();
          AUTO_STRING (cannot_open, "Cannot open doc string file \"");
          AUTO_STRING (quote_nl, "\"\n");
@@ -407,10 +410,7 @@ string is passed through `substitute-command-keys'.  */)
       if (NILP (tem) && try_reload)
        {
          /* The file is newer, we need to reset the pointers.  */
-         struct gcpro gcpro1, gcpro2;
-         GCPRO2 (function, raw);
          try_reload = reread_doc_file (Fcar_safe (doc));
-         UNGCPRO;
          if (try_reload)
            {
              try_reload = 0;
@@ -452,10 +452,7 @@ aren't strings.  */)
       if (NILP (tem) && try_reload)
        {
          /* The file is newer, we need to reset the pointers.  */
-         struct gcpro gcpro1, gcpro2, gcpro3;
-         GCPRO3 (symbol, prop, raw);
          try_reload = reread_doc_file (Fcar_safe (doc));
-         UNGCPRO;
          if (try_reload)
            {
              try_reload = 0;
@@ -684,10 +681,7 @@ the same file name is found in the `doc-directory'.  */)
   return unbind_to (count, Qnil);
 }
 \f
-/* Curved quotation marks.  */
-static unsigned char const LSQM[] = { uLSQM0, uLSQM1, uLSQM2 };
-static unsigned char const RSQM[] = { uRSQM0, uRSQM1, uRSQM2 };
-
+/* Return true if text quoting style should default to quote `like this'.  */
 static bool
 default_to_grave_quoting_style (void)
 {
@@ -733,7 +727,7 @@ as the keymap for future \\=\\[COMMAND] substrings.
 
 Each \\=‘ and \\=` is replaced by left quote, and each \\=’ and \\='
 is replaced by right quote.  Left and right quote characters are
-specified by ‘text-quoting-style’.
+specified by `text-quoting-style'.
 
 \\=\\= quotes the following character and is discarded; thus,
 \\=\\=\\=\\= puts \\=\\= into the output, \\=\\=\\=\\[ puts \\=\\[ into the output, and
@@ -754,7 +748,6 @@ Otherwise, return a new string.  */)
   unsigned char const *start;
   ptrdiff_t length, length_byte;
   Lisp_Object name;
-  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   bool multibyte;
   ptrdiff_t nchars;
 
@@ -765,7 +758,6 @@ Otherwise, return a new string.  */)
   tem = Qnil;
   keymap = Qnil;
   name = Qnil;
-  GCPRO4 (string, tem, keymap, name);
 
   enum text_quoting_style quoting_style = text_quoting_style ();
 
@@ -925,14 +917,13 @@ Otherwise, return a new string.  */)
          if (NILP (tem))
            {
              name = Fsymbol_name (name);
-             insert1 (Fsubstitute_command_keys
-                      (build_string ("\nUses keymap "uLSQM)));
+             AUTO_STRING (msg_prefix, "\nUses keymap `");
+             insert1 (Fsubstitute_command_keys (msg_prefix));
              insert_from_string (name, 0, 0,
                                  SCHARS (name),
                                  SBYTES (name), 1);
-             insert1 (Fsubstitute_command_keys
-                      (build_string
-                       (uRSQM", which is not currently defined.\n")));
+             AUTO_STRING (msg_suffix, "', which is not currently defined.\n");
+             insert1 (Fsubstitute_command_keys (msg_suffix));
              if (start[-1] == '<') keymap = Qnil;
            }
          else if (start[-1] == '<')
@@ -972,9 +963,9 @@ Otherwise, return a new string.  */)
       else if ((strp[0] == '`' || strp[0] == '\'')
               && quoting_style == CURVE_QUOTING_STYLE)
        {
-         start = strp[0] == '`' ? LSQM : RSQM;
+         start = (unsigned char const *) (strp[0] == '`' ? uLSQM : uRSQM);
          length = 1;
-         length_byte = 3;
+         length_byte = sizeof uLSQM - 1;
          idx = strp - SDATA (string) + 1;
          goto subst;
        }
@@ -985,29 +976,28 @@ Otherwise, return a new string.  */)
          nchars++;
          changed = true;
        }
-      else if (strp[0] == uLSQM0 && strp[1] == uLSQM1
-              && (strp[2] == uLSQM2 || strp[2] == uRSQM2)
-              && quoting_style != CURVE_QUOTING_STYLE)
-        {
-         *bufp++ = (strp[2] == uLSQM2 && quoting_style == GRAVE_QUOTING_STYLE
-                    ? '`' : '\'');
-         strp += 3;
-         nchars++;
-         changed = true;
-        }
-      else if (! multibyte)            /* just copy other chars */
+      else if (! multibyte)
        *bufp++ = *strp++, nchars++;
       else
        {
          int len;
-
-         STRING_CHAR_AND_LENGTH (strp, len);
-         if (len == 1)
-           *bufp = *strp;
+         int ch = STRING_CHAR_AND_LENGTH (strp, len);
+         if ((ch == LEFT_SINGLE_QUOTATION_MARK
+              || ch == RIGHT_SINGLE_QUOTATION_MARK)
+             && quoting_style != CURVE_QUOTING_STYLE)
+           {
+             *bufp++ = ((ch == LEFT_SINGLE_QUOTATION_MARK
+                         && quoting_style == GRAVE_QUOTING_STYLE)
+                        ? '`' : '\'');
+             strp += len;
+             changed = true;
+           }
          else
-           memcpy (bufp, strp, len);
-         strp += len;
-         bufp += len;
+           {
+             do
+               *bufp++ = *strp++;
+             while (--len != 0);
+           }
          nchars++;
        }
     }
@@ -1017,68 +1007,7 @@ Otherwise, return a new string.  */)
   else
     tem = string;
   xfree (buf);
-  RETURN_UNGCPRO (tem);
-}
-
-DEFUN ("internal--text-restyle", Finternal__text_restyle,
-       Sinternal__text_restyle, 1, 1, 0,
-       doc: /* Return STRING, possibly substituting quote characters.
-
-In the result, replace each curved single quote (\\=‘ and \\=’) by
-left and right quote characters as specified by ‘text-quoting-style’.
-
-Return the original STRING in the common case where no changes are needed.
-Otherwise, return a new string.  */)
-  (Lisp_Object string)
-{
-  bool changed = false;
-
-  CHECK_STRING (string);
-  if (! STRING_MULTIBYTE (string))
-    return string;
-
-  enum text_quoting_style quoting_style = text_quoting_style ();
-  if (quoting_style == CURVE_QUOTING_STYLE)
-    return string;
-
-  ptrdiff_t bsize = SBYTES (string);
-  unsigned char const *strp = SDATA (string);
-  unsigned char const *strlim = strp + bsize;
-  USE_SAFE_ALLOCA;
-  char *buf = SAFE_ALLOCA (bsize);
-  char *bufp = buf;
-  ptrdiff_t nchars = 0;
-
-  while (strp < strlim)
-    {
-      unsigned char const *cp = strp;
-      switch (STRING_CHAR_ADVANCE (strp))
-       {
-       case LEFT_SINGLE_QUOTATION_MARK:
-         *bufp++ = quoting_style == GRAVE_QUOTING_STYLE ? '`': '\'';
-         changed = true;
-         break;
-
-       case RIGHT_SINGLE_QUOTATION_MARK:
-         *bufp++ = '\'';
-         changed = true;
-         break;
-
-       default:
-         do
-           *bufp++ = *cp++;
-         while (cp != strp);
-
-         break;
-       }
-
-      nchars++;
-    }
-
-  Lisp_Object result
-    = changed ? make_string_from_bytes (buf, nchars, bufp - buf) : string;
-  SAFE_FREE ();
-  return result;
+  return tem;
 }
 \f
 void
@@ -1097,21 +1026,21 @@ syms_of_doc (void)
   Vbuild_files = Qnil;
 
   DEFVAR_LISP ("text-quoting-style", Vtext_quoting_style,
-               doc: /* Style to use for single quotes when generating text.
-‘curve’ means quote with curved single quotes \\=‘like this\\=’.
-‘straight’ means quote with straight apostrophes \\='like this\\='.
-‘grave’ means quote with grave accent and apostrophe \\=`like this\\='.
-The default value nil acts like ‘curve’ if curved single quotes are
-displayable, and like ‘grave’ otherwise.  */);
+               doc: /* Style to use for single quotes in help and messages.
+Its value should be a symbol.
+`curve' means quote with curved single quotes \\=‘like this\\=’.
+`straight' means quote with straight apostrophes \\='like this\\='.
+`grave' means quote with grave accent and apostrophe \\=`like this\\='.
+The default value nil acts like `curve' if curved single quotes are
+displayable, and like `grave' otherwise.  */);
   Vtext_quoting_style = Qnil;
 
   DEFVAR_BOOL ("internal--text-quoting-flag", text_quoting_flag,
-              doc: /* If nil, a nil ‘text-quoting-style’ is treated as ‘grave’.  */);
+              doc: /* If nil, a nil `text-quoting-style' is treated as `grave'.  */);
   /* Initialized by ‘main’.  */
 
   defsubr (&Sdocumentation);
   defsubr (&Sdocumentation_property);
   defsubr (&Ssnarf_documentation);
   defsubr (&Ssubstitute_command_keys);
-  defsubr (&Sinternal__text_restyle);
 }