]> code.delx.au - gnu-emacs/blobdiff - src/ccl.c
*** empty log message ***
[gnu-emacs] / src / ccl.c
index 1750ce2f075dfd44fc9d6365f3abcada4d493947..b9dd47ff17c57cd1446e97e876ded21623016ffe 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1,8 +1,8 @@
 /* CCL (Code Conversion Language) interpreter.
    Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN.
-   Copyright (C) 2001 Free Software Foundation, Inc.
-   Licensed to the Free Software Foundation.
-   Copyright (C) 2001, 2002
+     Licensed to the Free Software Foundation.
+   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2003
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -67,8 +67,6 @@ Lisp_Object Vtranslation_hash_table_vector;
 /* Return a hash table of id number ID.  */
 #define GET_HASH_TABLE(id) \
   (XHASH_TABLE (XCDR(XVECTOR(Vtranslation_hash_table_vector)->contents[(id)])))
-/* Copied from fns.c.  */
-#define HASH_VALUE(H, IDX) AREF ((H)->key_and_value, 2 * (IDX) + 1)
 
 extern int charset_unicode;
 
@@ -436,7 +434,7 @@ extern int charset_unicode;
                                        extended_command (rrr,RRR,Rrr,ARGS)
                                      */
 
-/* 
+/*
    Here after, Extended CCL Instructions.
    Bit length of extended command is 14.
    Therefore, the instruction code range is 0..16384(0x3fff).
@@ -494,7 +492,7 @@ extern int charset_unicode;
                                        3:MAP-ID1
                                        4:MAP-ID2
                                        ...
-                                    */ 
+                                    */
 
 /* Map the code in reg[rrr] by MAPs starting from the Nth (N =
    reg[RRR]) map.
@@ -572,7 +570,7 @@ extern int charset_unicode;
    where
        STARTPOINT is an offset to be used for indexing a map,
        ENDPOINT is a maximum index number of a map,
-       VAL and VALn is a number, nil, t, or lambda.  
+       VAL and VALn is a number, nil, t, or lambda.
 
    Valid index range of a map of type (a) is:
        STARTPOINT <= index < STARTPOINT + map_size - 1
@@ -779,26 +777,23 @@ while(0)
   ((id) == 0 ? (code)                  \
    : (charset = CHARSET_FROM_ID ((id)), DECODE_CHAR (charset, (code))))
 
-
 /* Encode character C by some of charsets in CHARSET_LIST.  Set ID to
    the id of the used charset, ENCODED to the resulf of encoding.
    Assume that we can use the variable `charset'.  */
 
-#define CCL_ENCODE_CHAR(c, charset_list, id, encoded)                  \
-  do {                                                                 \
-    unsigned code;                                                     \
-                                                                       \
-    charset = char_charset ((c), (charset_list), &code);               \
-    if (! charset && ! NILP (charset_list))                            \
-      charset = char_charset ((c), Qnil, &code);                       \
-    if (charset)                                                       \
-      {                                                                        \
-       (id) = CHARSET_ID (charset);                                    \
-       (encoded) = code;                                               \
-      }                                                                        \
-  } while (0)
-
-
+#define CCL_ENCODE_CHAR(c, charset_list, id, encoded)          \
+  do {                                                         \
+    unsigned code;                                             \
+                                                               \
+    charset = char_charset ((c), (charset_list), &code);       \
+    if (! charset && ! NILP (charset_list))                    \
+      charset = char_charset ((c), Qnil, &code);               \
+    if (charset)                                               \
+      {                                                                \
+       (id) = CHARSET_ID (charset);                            \
+       (encoded) = code;                                       \
+      }                                                                \
+   } while (0)
 
 /* Execute CCL code on characters at SOURCE (length SRC_SIZE).  The
    resulting text goes to a place pointed by DESTINATION, the length
@@ -810,7 +805,7 @@ while(0)
 
 #ifdef CCL_DEBUG
 #define CCL_DEBUG_BACKTRACE_LEN 256
-int ccl_backtrace_table[CCL_BACKTRACE_TABLE];
+int ccl_backtrace_table[CCL_DEBUG_BACKTRACE_LEN];
 int ccl_backtrace_idx;
 #endif
 
@@ -820,7 +815,7 @@ struct ccl_prog_stack
     int ic;                    /* Instruction Counter.  */
   };
 
-/* For the moment, we only support depth 256 of stack.  */ 
+/* For the moment, we only support depth 256 of stack.  */
 static struct ccl_prog_stack ccl_prog_stack_struct[256];
 
 void
@@ -1050,7 +1045,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                  }
                CCL_INVALID_CMD;
              }
-           
+
            ccl_prog_stack_struct[stack_idx].ccl_prog = ccl_prog;
            ccl_prog_stack_struct[stack_idx].ic = ic;
            stack_idx++;
@@ -1250,15 +1245,15 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
            case CCL_LookupIntConstTbl:
              op = XINT (ccl_prog[ic]); /* table */
              ic++;
-             {         
+             {
                struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
 
                op = hash_lookup (h, make_number (reg[RRR]), NULL);
                if (op >= 0)
                  {
-                    Lisp_Object opl;
+                   Lisp_Object opl;
                    opl = HASH_VALUE (h, op);
-                   if (!CHARACTERP (opl))
+                   if (! CHARACTERP (XINT (opl)))
                      CCL_INVALID_CMD;
                    reg[RRR] = charset_unicode;
                    reg[rrr] = op;
@@ -1273,13 +1268,13 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
              op = XINT (ccl_prog[ic]); /* table */
              ic++;
              i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]);
-             {         
+             {
                struct Lisp_Hash_Table *h = GET_HASH_TABLE (op);
 
                op = hash_lookup (h, make_number (i), NULL);
                if (op >= 0)
                  {
-                    Lisp_Object opl;
+                   Lisp_Object opl;
                    opl = HASH_VALUE (h, op);
                    if (!INTEGERP (opl))
                      CCL_INVALID_CMD;
@@ -1347,7 +1342,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                        else
                          continue;
                      }
-                   else 
+                   else
                      continue;
 
                    if (NILP (content))
@@ -1383,7 +1378,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                ic = fin_ic;
              }
              break;
-             
+
            case CCL_MapMultiple:
              {
                Lisp_Object map, content, attrib, value;
@@ -1470,7 +1465,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                      }
                  }
                map_vector_size = ASIZE (Vcode_conversion_map_vector);
-               
+
                do {
                  for (;map_set_rest_length > 0;i++, ic++, map_set_rest_length--)
                    {
@@ -1520,7 +1515,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                          else
                            continue;
                        }
-                     else 
+                     else
                        continue;
 
                      if (NILP (content))
@@ -1638,7 +1633,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                  }
              }
              break;
-             
+
            default:
              CCL_INVALID_CMD;
            }
@@ -1711,6 +1706,24 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
          for (i = 0; i < msglen; i++)
            *dst++ = msg[i];
        }
+
+      if (ccl->status == CCL_STAT_INVALID_CMD)
+       {
+#if 0 /* If the remaining bytes contain 0x80..0x9F, copying them
+        results in an invalid multibyte sequence.  */
+
+         /* Copy the remaining source data.  */
+         int i = src_end - src;
+         if (dst_bytes && (dst_end - dst) < i)
+           i = dst_end - dst;
+         bcopy (src, dst, i);
+         src += i;
+         dst += i;
+#else
+         /* Signal that we've consumed everything.  */
+         src = src_end;
+#endif
+       }
     }
 
  ccl_finish:
@@ -1869,6 +1882,7 @@ setup_ccl_program (ccl, ccl_prog)
   ccl->status = 0;
   ccl->stack_idx = 0;
   ccl->suppress_error = 0;
+  ccl->eight_bit_control = 0;
   return 0;
 }
 
@@ -1984,8 +1998,9 @@ See the documentation of `define-ccl-program' for the detail of CCL program.  */
   if (ASIZE (status) != 9)
     error ("Length of vector STATUS is not 9");
   CHECK_STRING (str);
-  str_chars = XSTRING (str)->size;
-  str_bytes = STRING_BYTES (XSTRING (str));
+
+  str_chars = SCHARS (str);
+  str_bytes = SBYTES (str);
 
   for (i = 0; i < 8; i++)
     {
@@ -2010,8 +2025,8 @@ See the documentation of `define-ccl-program' for the detail of CCL program.  */
   produced_chars = 0;
   while (consumed_bytes < str_bytes)
     {
-      const unsigned char *p = XSTRING (str)->data + consumed_bytes;
-      const unsigned char *endp = XSTRING (str)->data + str_bytes;
+      const unsigned char *p = SDATA (str) + consumed_bytes;
+      const unsigned char *endp = SDATA (str) + str_bytes;
       int i = 0;
       int *src, src_size;
 
@@ -2022,7 +2037,7 @@ See the documentation of `define-ccl-program' for the detail of CCL program.  */
        while (i < CCL_EXECUTE_BUF_SIZE && p < endp)
          source[i++] = STRING_CHAR_ADVANCE (p);
       consumed_chars += i;
-      consumed_bytes = p - XSTRING (str)->data;
+      consumed_bytes = p - SDATA (str);
 
       if (consumed_bytes == str_bytes)
        ccl.last_block = NILP (contin);
@@ -2066,12 +2081,12 @@ See the documentation of `define-ccl-program' for the detail of CCL program.  */
 
       if (ccl.status != CCL_STAT_SUSPEND_BY_SRC)
        break;
-      }
+    }
 
   if (ccl.status != CCL_STAT_SUCCESS
       && ccl.status != CCL_STAT_SUSPEND_BY_SRC)
     error ("Error in CCL program at %dth code", ccl.ic);
-  
+
   for (i = 0; i < 8; i++)
     XSET (XVECTOR (status)->contents[i], Lisp_Int, ccl.reg[i]);
   XSETINT (XVECTOR (status)->contents[8], ccl.ic);
@@ -2184,7 +2199,7 @@ Return index number of the registered map.  */)
 
   CHECK_SYMBOL (symbol);
   CHECK_VECTOR (map);
-  
+
   for (i = 0; i < len; i++)
     {
       Lisp_Object slot = AREF (Vcode_conversion_map_vector, i);