(sys_rename): Don't examine errno if rename didn't fail.
[bpt/emacs.git] / src / doc.c
index c3888b7..8ca7670 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -81,11 +81,14 @@ static int get_doc_string_buffer_size;
    and INTEGER as the position in that file.
    But if INTEGER is negative, make it positive.
    (A negative integer is used for user variables, so we can distinguish
-   them without actually fetching the doc string.)  */
+   them without actually fetching the doc string.)
 
-static Lisp_Object
-get_doc_string (filepos)
+   If UNIBYTE is nonzero, always return the result as a unibyte string.  */
+
+Lisp_Object
+get_doc_string (filepos, unibyte)
      Lisp_Object filepos;
+     int unibyte;
 {
   char *from, *to;
   register int fd;
@@ -239,8 +242,12 @@ get_doc_string (filepos)
        *to++ = *from++;
     }
 
-  return make_string (get_doc_string_buffer + offset,
-                     to - (get_doc_string_buffer + offset));
+  if (unibyte)
+    return make_unibyte_string (get_doc_string_buffer + offset,
+                               to - (get_doc_string_buffer + offset));
+  else
+    return make_string (get_doc_string_buffer + offset,
+                       to - (get_doc_string_buffer + offset));
 }
 
 /* Get a string from position FILEPOS and pass it through the Lisp reader.
@@ -251,7 +258,7 @@ Lisp_Object
 read_doc_string (filepos)
      Lisp_Object filepos;
 {
-  return Fread (get_doc_string (filepos));
+  return Fread (get_doc_string (filepos, 1));
 }
 
 DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 2, 0,
@@ -273,7 +280,7 @@ string is passed through `substitute-command-keys'.")
       if ((EMACS_INT) XSUBR (fun)->doc >= 0)
        doc = build_string (XSUBR (fun)->doc);
       else
-       doc = get_doc_string (make_number (- (EMACS_INT) XSUBR (fun)->doc));
+       doc = get_doc_string (make_number (- (EMACS_INT) XSUBR (fun)->doc), 0);
     }
   else if (COMPILEDP (fun))
     {
@@ -283,7 +290,7 @@ string is passed through `substitute-command-keys'.")
       if (STRINGP (tem))
        doc = tem;
       else if (NATNUMP (tem) || CONSP (tem))
-       doc = get_doc_string (tem);
+       doc = get_doc_string (tem, 1);
       else
        return Qnil;
     }
@@ -311,7 +318,7 @@ subcommands.)");
             in the function body, so reject them if they are last.  */
          else if ((NATNUMP (tem) || CONSP (tem))
                   && ! NILP (XCONS (tem1)->cdr))
-           doc = get_doc_string (tem);
+           doc = get_doc_string (tem, 1);
          else
            return Qnil;
        }
@@ -352,9 +359,9 @@ translation.")
 
   tem = Fget (symbol, prop);
   if (INTEGERP (tem))
-    tem = get_doc_string (XINT (tem) > 0 ? tem : make_number (- XINT (tem)));
+    tem = get_doc_string (XINT (tem) > 0 ? tem : make_number (- XINT (tem)), 0);
   else if (CONSP (tem))
-    tem = get_doc_string (tem);
+    tem = get_doc_string (tem, 0);
   if (NILP (raw) && STRINGP (tem))
     return Fsubstitute_command_keys (tem);
   return tem;
@@ -536,7 +543,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
   Lisp_Object tem;
   Lisp_Object keymap;
   unsigned char *start;
-  int length;
+  int length, length_byte;
   Lisp_Object name;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   int multibyte;
@@ -562,11 +569,11 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
   if (NILP (keymap))
     keymap = Voverriding_local_map;
 
-  bsize = XSTRING (string)->size_byte;
+  bsize = STRING_BYTES (XSTRING (string));
   bufp = buf = (unsigned char *) xmalloc (bsize);
 
   strp = (unsigned char *) XSTRING (string)->data;
-  while (strp < XSTRING (string)->data + XSTRING (string)->size_byte)
+  while (strp < XSTRING (string)->data + STRING_BYTES (XSTRING (string)))
     {
       if (strp[0] == '\\' && strp[1] == '=')
        {
@@ -577,7 +584,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
          if (multibyte)
            {
              int len;
-             int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+             int maxlen = XSTRING (string)->data + STRING_BYTES (XSTRING (string)) - strp;
 
              STRING_CHAR_AND_LENGTH (strp, maxlen, len);
              if (len == 1)
@@ -594,14 +601,13 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
       else if (strp[0] == '\\' && strp[1] == '[')
        {
          Lisp_Object firstkey;
-         int length_byte;
 
          changed = 1;
          strp += 2;            /* skip \[ */
          start = strp;
 
          while ((strp - (unsigned char *) XSTRING (string)->data
-                 < XSTRING (string)->size_byte)
+                 < STRING_BYTES (XSTRING (string)))
                 && *strp != ']')
            strp++;
          length_byte = strp - start;
@@ -648,7 +654,6 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
       else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
        {
          struct buffer *oldbuf;
-         int length_byte;
 
          changed = 1;
          strp += 2;            /* skip \{ or \< */
@@ -687,7 +692,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
              insert_string ("\nUses keymap \"");
              insert_from_string (name, 0, 0,
                                  XSTRING (name)->size,
-                                 XSTRING (name)->size_byte, 1);
+                                 STRING_BYTES (XSTRING (name)), 1);
              insert_string ("\", which is not currently defined.\n");
              if (start[-1] == '<') keymap = Qnil;
            }
@@ -702,7 +707,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
        subst_string:
          start = XSTRING (tem)->data;
          length = XSTRING (tem)->size;
-         length_byte = XSTRING (tem)->size_byte;
+         length_byte = STRING_BYTES (XSTRING (tem));
        subst:
          new = (unsigned char *) xrealloc (buf, bsize += length_byte);
          bufp += new - buf;
@@ -718,7 +723,7 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
       else
        {
          int len;
-         int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+         int maxlen = XSTRING (string)->data + STRING_BYTES (XSTRING (string)) - strp;
 
          STRING_CHAR_AND_LENGTH (strp, maxlen, len);
          if (len == 1)
@@ -732,13 +737,14 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int
     }
 
   if (changed)                 /* don't bother if nothing substituted */
-    tem = make_multibyte_string (buf, nchars, bufp - buf);
+    tem = make_string_from_bytes (buf, nchars, bufp - buf);
   else
     tem = string;
   xfree (buf);
   RETURN_UNGCPRO (tem);
 }
 \f
+void
 syms_of_doc ()
 {
   DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,