changeset 88475:9d54c1d6cd0a

(load_charset_map): Fix previous change. (read_hex): Don't treat SPC as a comment starter. (decode_char): If CODE_POINT_TO_INDEX retruns -1, always return -1. (Fdecode_char): Fix typo. (CODE_POINT_TO_INDEX): Utilize `code_space_mask' member to check if CODE is valid or not. (Fdefine_charset_internal): Initialize `code_space_mask' member. (encode_char): Before calling CODE_POINT_TO_INDEX, check if CODE is within the range of charset->min_code and carset->max_code.
author Kenichi Handa <handa@m17n.org>
date Fri, 10 May 2002 03:54:48 +0000
parents fcc1029dcac2
children 47c2e6825a1e
files src/charset.c
diffstat 1 files changed, 48 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/charset.c	Thu May 09 18:00:40 2002 +0000
+++ b/src/charset.c	Fri May 10 03:54:48 2002 +0000
@@ -118,20 +118,20 @@
 
 Lisp_Object Vchar_unified_charset_table;
 
-#define CODE_POINT_TO_INDEX(charset, code)			\
-  ((charset)->code_linear_p					\
-   ? (code) - (charset)->min_code				\
-   : ((((code) >> 24) <= (charset)->code_space[13])		\
-      && ((((code) >> 16) & 0xFF) <= (charset)->code_space[9])	\
-      && ((((code) >> 8) & 0xFF) <= (charset)->code_space[5])	\
-      && (((code) & 0xFF) <= (charset)->code_space[1]))		\
-   ? (((((code) >> 24) - (charset)->code_space[12])		\
-       * (charset)->code_space[11])				\
-      + (((((code) >> 16) & 0xFF) - (charset)->code_space[8])	\
-	 * (charset)->code_space[7])				\
-      + (((((code) >> 8) & 0xFF) - (charset)->code_space[4])	\
-	 * (charset)->code_space[3])				\
-      + (((code) & 0xFF) - (charset)->code_space[0]))		\
+#define CODE_POINT_TO_INDEX(charset, code)				\
+  ((charset)->code_linear_p						\
+   ? (code) - (charset)->min_code					\
+   : (((charset)->code_space_mask[(code) >> 24] & 0x8)			\
+      && ((charset)->code_space_mask[((code) >> 16) & 0xFF] & 0x4)	\
+      && ((charset)->code_space_mask[((code) >> 8) & 0xFF] & 0x2)	\
+      && ((charset)->code_space_mask[(code) & 0xFF] & 0x1))		\
+   ? (((((code) >> 24) - (charset)->code_space[12])			\
+       * (charset)->code_space[11])					\
+      + (((((code) >> 16) & 0xFF) - (charset)->code_space[8])		\
+	 * (charset)->code_space[7])					\
+      + (((((code) >> 8) & 0xFF) - (charset)->code_space[4])		\
+	 * (charset)->code_space[3])					\
+      + (((code) & 0xFF) - (charset)->code_space[0]))			\
    : -1)
 
 
@@ -268,10 +268,20 @@
 	}
       else
 	{
-	  for (; from <= to; from++)
+	  unsigned code = from;
+	  int from_index, to_index;
+
+	  from_index = CODE_POINT_TO_INDEX (charset, from);
+	  if (from == to)
+	    to_index = from_index;
+	  else
+	    to_index = CODE_POINT_TO_INDEX (charset, to);
+	  if (from_index < 0 || to_index < 0)
+	    continue;
+	  while (1)
 	    {
-	      int c1 = DECODE_CHAR (charset, from);
-
+	      int c1 = DECODE_CHAR (charset, code);
+	      
 	      if (c1 >= 0)
 		{
 		  CHAR_TABLE_SET (table, c, make_number (c1));
@@ -280,6 +290,10 @@
 		    CHAR_TABLE_SET (Vchar_unified_charset_table, c1,
 				    CHARSET_NAME (charset));
 		}
+	      if (from_index == to_index)
+		break;
+	      from_index++, c++;
+	      code = INDEX_TO_CODE_POINT (charset, from_index);
 	    }
 	}
     }
@@ -313,7 +327,7 @@
 
   while ((c = getc (fp)) != EOF)
     {
-      if (c == '#' || c == ' ')
+      if (c == '#')
 	{
 	  while ((c = getc (fp)) != EOF && c != '\n');
 	}
@@ -648,7 +662,7 @@
   Lisp_Object val;
   unsigned hash_code;
   struct Lisp_Hash_Table *hash_table = XHASH_TABLE (Vcharset_hash_table);
-  int i;
+  int i, j;
   struct charset charset;
   int id;
   int dimension;
@@ -702,6 +716,16 @@
 		   && (charset.dimension == 3
 		       || charset.code_space[10] == 256)))));
 
+  if (! charset.code_linear_p)
+    {
+      charset.code_space_mask = (unsigned char *) xmalloc (256);
+      bzero (charset.code_space_mask, sizeof (charset.code_space_mask));
+      for (i = 0; i < 4; i++)
+	for (j = charset.code_space[i * 4]; j <= charset.code_space[i * 4 + 1];
+	     j++)
+	  charset.code_space_mask[j] |= (1 << i);
+    }
+
   charset.iso_chars_96 = charset.code_space[2] == 96;
 
   charset.min_code = (charset.code_space[0]
@@ -1277,6 +1301,8 @@
   else
     {
       char_index = CODE_POINT_TO_INDEX (charset, code);
+      if (char_index < 0)
+	return -1;
 
       if (method == CHARSET_METHOD_MAP)
 	{
@@ -1350,7 +1376,8 @@
 	      && (code_offset < 0 || code >= code_offset))
 	    {
 	      code -= code_offset;
-	      if (CODE_POINT_TO_INDEX (charset, code) >= 0)
+	      if (code >= charset->min_code && code <= charset->max_code
+		  && CODE_POINT_TO_INDEX (charset, code) >= 0)
 		return code;
 	    }
 	}
@@ -1406,7 +1433,7 @@
     {
       CHECK_NATNUM (XCAR (code_point));
       CHECK_NATNUM (XCDR (code_point));
-      code = (XINT (XCAR (code_point)) << 16) | (XINT (XCAR (code_point)));
+      code = (XINT (XCAR (code_point)) << 16) | (XINT (XCDR (code_point)));
     }
   else
     {