diff src/lread.c @ 91093:3de299ab846c

(READCHAR): Call readchar with the 2nd arg NULL. (READCHAR_REPORT_MULTIBYTE): New macro. (readchar): New 2nd arg MULTIBYTE. (read1): Use READCHAR_REPORT_MULTIBYTE for the first read. Make symbol's name multibyte according to the multibyteness of the source.
author Kenichi Handa <handa@m17n.org>
date Wed, 14 Nov 2007 04:52:07 +0000
parents 1251cabc40b7
children 1805a65e7746
line wrap: on
line diff
--- a/src/lread.c	Mon Nov 12 10:16:48 2007 +0000
+++ b/src/lread.c	Wed Nov 14 04:52:07 2007 +0000
@@ -250,9 +250,12 @@
 
    These macros correctly read/unread multibyte characters.  */
 
-#define READCHAR readchar (readcharfun)
+#define READCHAR readchar (readcharfun, NULL)
 #define UNREAD(c) unreadchar (readcharfun, c)
 
+/* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source.  */
+#define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte)
+
 /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char,
    Qlambda, or a cons, we use this to keep an unread character because
    a file stream can't handle multibyte-char unreading.  The value -1
@@ -260,8 +263,9 @@
 static int unread_char;
 
 static int
-readchar (readcharfun)
+readchar (readcharfun, multibyte)
      Lisp_Object readcharfun;
+     int *multibyte;
 {
   Lisp_Object tem;
   register int c;
@@ -270,6 +274,9 @@
   int i, len;
   int emacs_mule_encoding = 0;
 
+  if (multibyte)
+    *multibyte = 0;
+
   readchar_count++;
 
   if (BUFFERP (readcharfun))
@@ -287,6 +294,8 @@
 	  unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, pt_byte);
 	  BUF_INC_POS (inbuffer, pt_byte);
 	  c = STRING_CHAR (p, pt_byte - orig_pt_byte);
+	  if (multibyte)
+	    *multibyte = 1;
 	}
       else
 	{
@@ -314,6 +323,8 @@
 	  unsigned char *p = BUF_BYTE_ADDRESS (inbuffer, bytepos);
 	  BUF_INC_POS (inbuffer, bytepos);
 	  c = STRING_CHAR (p, bytepos - orig_bytepos);
+	  if (multibyte)
+	    *multibyte = 1;
 	}
       else
 	{
@@ -345,11 +356,20 @@
     {
       if (read_from_string_index >= read_from_string_limit)
 	c = -1;
+      else if (STRING_MULTIBYTE (readcharfun))
+	{
+	  if (multibyte)
+	    *multibyte = 1;
+	  FETCH_STRING_CHAR_ADVANCE_NO_CHECK (c, readcharfun,
+					      read_from_string_index,
+					      read_from_string_index_byte);
+	}
       else
-	FETCH_STRING_CHAR_ADVANCE (c, readcharfun,
-				   read_from_string_index,
-				   read_from_string_index_byte);
-
+	{
+	  c = SREF (readcharfun, read_from_string_index_byte);
+	  read_from_string_index++;
+	  read_from_string_index_byte++;
+	}
       return c;
     }
 
@@ -387,7 +407,11 @@
       return c;
     }
   c = (*readbyte) (-1, readcharfun);
-  if (c < 0 || ASCII_BYTE_P (c) || load_each_byte)
+  if (c < 0 || load_each_byte)
+    return c;
+  if (multibyte)
+    *multibyte = 1;
+  if (ASCII_BYTE_P (c))
     return c;
   if (emacs_mule_encoding)
     return read_emacs_mule_char (c, readbyte, readcharfun);
@@ -2288,13 +2312,14 @@
 {
   register int c;
   int uninterned_symbol = 0;
+  int multibyte;
 
   *pch = 0;
   load_each_byte = 0;
 
  retry:
 
-  c = READCHAR;
+  c = READCHAR_REPORT_MULTIBYTE (&multibyte);
   if (c < 0)
     end_of_file_error ();
 
@@ -2868,7 +2893,10 @@
 		  quoted = 1;
 		}
 
-	      p += CHAR_STRING (c, p);
+	      if (multibyte)
+		p += CHAR_STRING (c, p);
+	      else
+		*p++ = c;
 	      c = READCHAR;
 	    }
 
@@ -2964,8 +2992,12 @@
 	      }
 	  }
 	{
-	  Lisp_Object result = uninterned_symbol ? make_symbol (read_buffer)
-	    : intern (read_buffer);
+	  Lisp_Object name = make_specified_string (read_buffer, -1,
+						    p - read_buffer,
+						    multibyte);
+	  Lisp_Object result = (uninterned_symbol ? Fmake_symbol (name)
+				: Fintern (name, Qnil));
+
 	  if (EQ (Vread_with_symbol_positions, Qt)
 	      || EQ (Vread_with_symbol_positions, readcharfun))
 	    Vread_symbol_positions_list =