changeset 20619:0a559893331d

Include charset.h. (Fsubstitute_command_keys): Scan by bytes.
author Richard M. Stallman <rms@gnu.org>
date Fri, 09 Jan 1998 23:08:46 +0000
parents d5acac3af6e3
children a3cb242e8349
files src/doc.c
diffstat 1 files changed, 67 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/doc.c	Fri Jan 09 23:07:47 1998 +0000
+++ b/src/doc.c	Fri Jan 09 23:08:46 1998 +0000
@@ -39,6 +39,7 @@
 #include "lisp.h"
 #include "buffer.h"
 #include "keyboard.h"
+#include "charset.h"
 
 Lisp_Object Vdoc_file_name;
 
@@ -478,7 +479,9 @@
       if (p != end)
 	{
 	  end = index (p, '\n');
-	  sym = oblookup (Vobarray, p + 2, end - p - 2);
+	  sym = oblookup (Vobarray, p + 2,
+			  multibyte_chars_in_text (p + 2, end - p - 2),
+			  end - p - 2);
 	  if (SYMBOLP (sym))
 	    {
 	      /* Attach a docstring to a variable?  */
@@ -536,6 +539,8 @@
   int length;
   Lisp_Object name;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
+  int multibyte;
+  int nchars;
 
   if (NILP (string))
     return Qnil;
@@ -546,6 +551,9 @@
   name = Qnil;
   GCPRO4 (string, tem, keymap, name);
 
+  multibyte = STRING_MULTIBYTE (string);
+  nchars = 0;
+
   /* KEYMAP is either nil (which means search all the active keymaps)
      or a specified local map (which means search just that and the
      global map).  If non-nil, it might come from Voverriding_local_map,
@@ -554,38 +562,55 @@
   if (NILP (keymap))
     keymap = Voverriding_local_map;
 
-  bsize = XSTRING (string)->size;
+  bsize = XSTRING (string)->size_byte;
   bufp = buf = (unsigned char *) xmalloc (bsize);
 
   strp = (unsigned char *) XSTRING (string)->data;
-  while (strp < (unsigned char *) XSTRING (string)->data + XSTRING (string)->size)
+  while (strp < XSTRING (string)->data + XSTRING (string)->size_byte)
     {
       if (strp[0] == '\\' && strp[1] == '=')
 	{
 	  /* \= quotes the next character;
 	     thus, to put in \[ without its special meaning, use \=\[.  */
 	  changed = 1;
-	  *bufp++ = strp[2];
-	  strp += 3;
+	  strp += 2;
+	  if (multibyte)
+	    {
+	      int len;
+	      int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+
+	      STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+	      if (len == 1)
+		*bufp = *strp;
+	      else
+		bcopy (strp, bufp, len);
+	      strp += len;
+	      bufp += len;
+	      nchars++;
+	    }
+	  else
+	    *bufp++ = *strp++, nchars++;
 	}
       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)
+		  < XSTRING (string)->size_byte)
 		 && *strp != ']')
 	    strp++;
-	  length = strp - start;
+	  length_byte = strp - start;
+
 	  strp++;		/* skip ] */
 
 	  /* Save STRP in IDX.  */
 	  idx = strp - (unsigned char *) XSTRING (string)->data;
-	  tem = Fintern (make_string (start, length), Qnil);
+	  tem = Fintern (make_string (start, length_byte), Qnil);
 	  tem = Fwhere_is_internal (tem, keymap, Qt, Qnil);
 
 	  /* Disregard menu bar bindings; it is positively annoying to
@@ -605,6 +630,11 @@
 	      buf = new;
 	      bcopy ("M-x ", bufp, 4);
 	      bufp += 4;
+	      nchars += 4;
+	      if (multibyte)
+		length = multibyte_chars_in_text (start, length_byte);
+	      else
+		length = length_byte;
 	      goto subst;
 	    }
 	  else
@@ -618,6 +648,7 @@
       else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
 	{
 	  struct buffer *oldbuf;
+	  int length_byte;
 
 	  changed = 1;
 	  strp += 2;		/* skip \{ or \< */
@@ -627,7 +658,8 @@
 		  < XSTRING (string)->size)
 		 && *strp != '}' && *strp != '>')
 	    strp++;
-	  length = strp - start;
+
+	  length_byte = strp - start;
 	  strp++;			/* skip } or > */
 
 	  /* Save STRP in IDX.  */
@@ -636,7 +668,7 @@
 	  /* 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), Qnil);
+	  name = Fintern (make_string (start, length_byte), Qnil);
 	  tem = Fboundp (name);
 	  if (! NILP (tem))
 	    {
@@ -653,7 +685,9 @@
 	    {
 	      name = Fsymbol_name (name);
 	      insert_string ("\nUses keymap \"");
-	      insert_from_string (name, 0, XSTRING (name)->size, 1);
+	      insert_from_string (name, 0, 0,
+				  XSTRING (name)->size,
+				  XSTRING (name)->size_byte, 1);
 	      insert_string ("\", which is not currently defined.\n");
 	      if (start[-1] == '<') keymap = Qnil;
 	    }
@@ -668,21 +702,37 @@
 	subst_string:
 	  start = XSTRING (tem)->data;
 	  length = XSTRING (tem)->size;
+	  length_byte = XSTRING (tem)->size_byte;
 	subst:
-	  new = (unsigned char *) xrealloc (buf, bsize += length);
+	  new = (unsigned char *) xrealloc (buf, bsize += length_byte);
 	  bufp += new - buf;
 	  buf = new;
-	  bcopy (start, bufp, length);
-	  bufp += length;
+	  bcopy (start, bufp, length_byte);
+	  bufp += length_byte;
+	  nchars += length;
 	  /* Check STRING again in case gc relocated it.  */
 	  strp = (unsigned char *) XSTRING (string)->data + idx;
 	}
-      else			/* just copy other chars */
-	*bufp++ = *strp++;
+      else if (! multibyte)		/* just copy other chars */
+	*bufp++ = *strp++, nchars++;
+      else
+	{
+	  int len;
+	  int maxlen = XSTRING (string)->data + XSTRING (string)->size_byte - strp;
+
+	  STRING_CHAR_AND_LENGTH (strp, maxlen, len);
+	  if (len == 1)
+	    *bufp = *strp;
+	  else
+	    bcopy (strp, bufp, len);
+	  strp += len;
+	  bufp += len;
+	  nchars++;
+	}
     }
 
   if (changed)			/* don't bother if nothing substituted */
-    tem = make_string (buf, bufp - buf);
+    tem = make_multibyte_string (buf, nchars, bufp - buf);
   else
     tem = string;
   xfree (buf);