* src/profiler.c: Delete.
[bpt/emacs.git] / src / ccl.c
index 5da90ad..daff3c6 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1,5 +1,5 @@
 /* CCL (Code Conversion Language) interpreter.
-   Copyright (C) 2001-2012 Free Software Foundation, Inc.
+   Copyright (C) 2001-2014 Free Software Foundation, Inc.
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
      2005, 2006, 2007, 2008, 2009, 2010, 2011
      National Institute of Advanced Industrial Science and Technology (AIST)
@@ -26,7 +26,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 
 #include <stdio.h>
-#include <setjmp.h>
 #include <limits.h>
 
 #include "lisp.h"
@@ -61,7 +60,7 @@ static Lisp_Object Vccl_program_table;
 
 /* Return a hash table of id number ID.  */
 #define GET_HASH_TABLE(id) \
-  (XHASH_TABLE (XCDR (XVECTOR (Vtranslation_hash_table_vector)->contents[(id)])))
+  (XHASH_TABLE (XCDR (AREF (Vtranslation_hash_table_vector, (id)))))
 
 /* CCL (Code Conversion Language) is a simple language which has
    operations on one input buffer, one output buffer, and 7 registers.
@@ -629,7 +628,7 @@ do                                                          \
   {                                                            \
     struct ccl_program called_ccl;                             \
     if (stack_idx >= 256                                       \
-       || (setup_ccl_program (&called_ccl, (symbol)) != 0))    \
+       || ! setup_ccl_program (&called_ccl, (symbol)))         \
       {                                                                \
        if (stack_idx > 0)                                      \
          {                                                     \
@@ -1713,9 +1712,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
     }
 
  ccl_error_handler:
-  /* The suppress_error member is set when e.g. a CCL-based coding
-     system is used for terminal output.  */
-  if (!ccl->suppress_error && destination)
+  if (destination)
     {
       /* We can insert an error message only if DESTINATION is
          specified and we still have a room to store the message
@@ -1729,14 +1726,14 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
       switch (ccl->status)
        {
        case CCL_STAT_INVALID_CMD:
-         sprintf (msg, "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
-                   code & 0x1F, code, this_ic);
+         msglen = sprintf (msg,
+                           "\nCCL: Invalid command %x (ccl_code = %x) at %d.",
+                           code & 0x1F, code, this_ic);
 #ifdef CCL_DEBUG
          {
            int i = ccl_backtrace_idx - 1;
            int j;
 
-           msglen = strlen (msg);
            if (dst + msglen <= (dst_bytes ? dst_end : src))
              {
                memcpy (dst, msg, msglen);
@@ -1748,8 +1745,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
                if (i < 0) i = CCL_DEBUG_BACKTRACE_LEN - 1;
                if (ccl_backtrace_table[i] == 0)
                  break;
-               sprintf (msg, " %d", ccl_backtrace_table[i]);
-               msglen = strlen (msg);
+               msglen = sprintf (msg, " %d", ccl_backtrace_table[i]);
                if (dst + msglen > (dst_bytes ? dst_end : src))
                  break;
                memcpy (dst, msg, msglen);
@@ -1761,15 +1757,13 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size
          break;
 
        case CCL_STAT_QUIT:
-         if (! ccl->quit_silently)
-           sprintf (msg, "\nCCL: Quitted.");
+         msglen = ccl->quit_silently ? 0 : sprintf (msg, "\nCCL: Quitted.");
          break;
 
        default:
-         sprintf (msg, "\nCCL: Unknown error type (%d)", ccl->status);
+         msglen = sprintf (msg, "\nCCL: Unknown error type (%d)", ccl->status);
        }
 
-      msglen = strlen (msg);
       if (msglen <= dst_end - dst)
        {
          for (i = 0; i < msglen; i++)
@@ -1923,10 +1917,10 @@ ccl_get_compiled_code (Lisp_Object ccl_prog, ptrdiff_t *idx)
 /* Setup fields of the structure pointed by CCL appropriately for the
    execution of CCL program CCL_PROG.  CCL_PROG is the name (symbol)
    of the CCL program or the already compiled code (vector).
-   Return 0 if we succeed this setup, else return -1.
+   Return true iff successful.
 
-   If CCL_PROG is nil, we just reset the structure pointed by CCL.  */
-int
+   If CCL_PROG is nil, just reset the structure pointed by CCL.  */
+bool
 setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
 {
   int i;
@@ -1937,7 +1931,7 @@ setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
 
       ccl_prog = ccl_get_compiled_code (ccl_prog, &ccl->idx);
       if (! VECTORP (ccl_prog))
-       return -1;
+       return false;
       vp = XVECTOR (ccl_prog);
       ccl->size = vp->header.size;
       ccl->prog = vp->contents;
@@ -1954,14 +1948,11 @@ setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
   ccl->ic = CCL_HEADER_MAIN;
   for (i = 0; i < 8; i++)
     ccl->reg[i] = 0;
-  ccl->last_block = 0;
-  ccl->private_state = 0;
+  ccl->last_block = false;
   ccl->status = 0;
   ccl->stack_idx = 0;
-  ccl->suppress_error = 0;
-  ccl->eight_bit_control = 0;
-  ccl->quit_silently = 0;
-  return 0;
+  ccl->quit_silently = false;
+  return true;
 }
 
 
@@ -2007,7 +1998,7 @@ programs.  */)
   struct ccl_program ccl;
   int i;
 
-  if (setup_ccl_program (&ccl, ccl_prog) < 0)
+  if (! setup_ccl_program (&ccl, ccl_prog))
     error ("Invalid CCL program");
 
   CHECK_VECTOR (reg);
@@ -2069,7 +2060,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
   ptrdiff_t consumed_chars, consumed_bytes, produced_chars;
   int buf_magnification;
 
-  if (setup_ccl_program (&ccl, ccl_prog) < 0)
+  if (! setup_ccl_program (&ccl, ccl_prog))
     error ("Invalid CCL program");
 
   CHECK_VECTOR (status);
@@ -2101,7 +2092,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
   outbufsize = (ccl.buf_magnification
                ? str_bytes * ccl.buf_magnification + 256
                : str_bytes + 256);
-  outp = outbuf = (unsigned char *) xmalloc (outbufsize);
+  outp = outbuf = xmalloc_atomic (outbufsize);
 
   consumed_chars = consumed_bytes = 0;
   produced_chars = 0;
@@ -2134,7 +2125,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
          produced_chars += ccl.produced;
          offset = outp - outbuf;
          shortfall = ccl.produced * max_expansion - (outbufsize - offset);
-         if (0 < shortfall)
+         if (shortfall > 0)
            {
              outbuf = xpalloc (outbuf, &outbufsize, shortfall, -1, 1);
              outp = outbuf + offset;
@@ -2169,11 +2160,8 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
     ASET (status, i, make_number (ccl.reg[i]));
   ASET (status, 8, make_number (ccl.ic));
 
-  if (NILP (unibyte_p))
-    val = make_multibyte_string ((char *) outbuf, produced_chars,
-                                outp - outbuf);
-  else
-    val = make_unibyte_string ((char *) outbuf, produced_chars);
+  val = make_specified_string ((const char *) outbuf, produced_chars,
+                              outp - outbuf, NILP (unibyte_p));
   xfree (outbuf);
 
   return val;
@@ -2232,9 +2220,8 @@ Return index number of the registered CCL program.  */)
     Vccl_program_table = larger_vector (Vccl_program_table, 1, -1);
 
   {
-    Lisp_Object elt;
+    Lisp_Object elt = make_uninit_vector (4);
 
-    elt = Fmake_vector (make_number (4), Qnil);
     ASET (elt, 0, name);
     ASET (elt, 1, ccl_prog);
     ASET (elt, 2, resolved);
@@ -2305,6 +2292,8 @@ Return index number of the registered map.  */)
 void
 syms_of_ccl (void)
 {
+#include "ccl.x"
+
   staticpro (&Vccl_program_table);
   Vccl_program_table = Fmake_vector (make_number (32), Qnil);
 
@@ -2338,10 +2327,4 @@ Comprises pairs (SYMBOL . TABLE) where SYMBOL and TABLE were set up by calls
 to `define-translation-hash-table'.  The vector is indexed by the table id
 used by CCL.  */);
     Vtranslation_hash_table_vector = Qnil;
-
-  defsubr (&Sccl_program_p);
-  defsubr (&Sccl_execute);
-  defsubr (&Sccl_execute_on_string);
-  defsubr (&Sregister_ccl_program);
-  defsubr (&Sregister_code_conversion_map);
 }