update.
[chise/libchise.git] / chise.c
diff --git a/chise.c b/chise.c
index ea6f086..6e8bb46 100644 (file)
--- a/chise.c
+++ b/chise.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include "chise.h"
 
 #define xzero(lvalue) ((void) memset (&(lvalue), '\0', sizeof (lvalue)))
@@ -52,16 +56,32 @@ chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
   if (!status)
     {
       unsigned char *str
-       = (unsigned char *)chise_value_to_c_string (&valdatum);
-      int len = strlen (str);
-      int i;
+       = (unsigned char *)chise_value_data (&valdatum);
+      int len = strnlen (str, chise_value_size (&valdatum));
+      int i = 0;
 
-      if ( (len >= 2) && (str[0] == '?') )
+      if ( (len >= 2) && (str[i++] == '?') )
        {
-         unsigned char c = str[1];
+         unsigned char c = str[i++];
          int counter;
          CHISE_Char_ID cid;
 
+         if (c == '\\')
+           {
+             if (len < 3)
+               return -1;
+             c = str[i++];
+             if (c == '^')
+               {
+                 if (len < 4)
+                   return -1;
+                 c = str[i++];
+                 if (c == '?')
+                   return 0x7F;
+                 else
+                   return c & (0x80 | 0x1F);
+               }
+           }
          if ( c < 0xC0 )
            {
              cid = c;
@@ -95,10 +115,10 @@ chise_dt_get_char (CHISE_Decoding_Table *db, int code_point)
 
          if (counter + 2 <= len)
            {
-             int i;
+             int j;
 
-             for (i = 0; i < counter; i++)
-               cid = (cid << 6) | (str[i + 2] & 0x3F);
+             for (j = 0; j < counter; j++)
+               cid = (cid << 6) | (str[j + i] & 0x3F);
              return cid;
            }
        }