Use gnulib's mktime module.
[bpt/emacs.git] / src / ccl.c
index 380403c..ca4a147 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -1,8 +1,8 @@
 /* CCL (Code Conversion Language) interpreter.
    Copyright (C) 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007, 2008 Free Software Foundation, Inc.
+                 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-     2005, 2006, 2007, 2008
+     2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H14PRO021
    Copyright (C) 2003
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,13 +22,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
 #include <stdio.h>
+#include <setjmp.h>
 
 #include "lisp.h"
 #include "character.h"
@@ -44,7 +43,7 @@ Lisp_Object Vcode_conversion_map_vector;
 /* Alist of fontname patterns vs corresponding CCL program.  */
 Lisp_Object Vfont_ccl_encoder_alist;
 
-/* This symbol is a property which assocates with ccl program vector.
+/* This symbol is a property which associates with ccl program vector.
    Ex: (get 'ccl-big5-encoder 'ccl-program) returns ccl program vector.  */
 Lisp_Object Qccl_program;
 
@@ -73,8 +72,6 @@ Lisp_Object Vtranslation_hash_table_vector;
 #define GET_HASH_TABLE(id) \
   (XHASH_TABLE (XCDR(XVECTOR(Vtranslation_hash_table_vector)->contents[(id)])))
 
-extern int charset_unicode;
-
 /* CCL (Code Conversion Language) is a simple language which has
    operations on one input buffer, one output buffer, and 7 registers.
    The syntax of CCL is described in `ccl.el'.  Emacs Lisp function
@@ -451,7 +448,7 @@ extern int charset_unicode;
    Therefore, the instruction code range is 0..16384(0x3fff).
  */
 
-/* Read a multibyte characeter.
+/* Read a multibyte character.
    A code point is stored into reg[rrr].  A charset ID is stored into
    reg[RRR].  */
 
@@ -863,11 +860,7 @@ struct ccl_prog_stack
 static struct ccl_prog_stack ccl_prog_stack_struct[256];
 
 void
-ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
-     struct ccl_program *ccl;
-     int *source, *destination;
-     int src_size, dst_size;
-     Lisp_Object charset_list;
+ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size, int dst_size, Lisp_Object charset_list)
 {
   register int *reg = ccl->reg;
   register int ic = ccl->ic;
@@ -884,9 +877,6 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
   int eof_ic = ccl->eof_ic;
   int eof_hit = 0;
 
-  if (ic >= eof_ic)
-    ic = CCL_HEADER_MAIN;
-
   if (ccl->buf_magnification == 0) /* We can't read/produce any bytes.  */
     dst = NULL;
 
@@ -1366,7 +1356,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                    if (point >= size) continue;
                    map = AREF (Vcode_conversion_map_vector, point);
 
-                   /* Check map varidity.  */
+                   /* Check map validity.  */
                    if (!CONSP (map)) continue;
                    map = XCDR (map);
                    if (!VECTORP (map)) continue;
@@ -1377,7 +1367,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
 
                    /* check map type,
                       [STARTPOINT VAL1 VAL2 ...] or
-                      [t ELELMENT STARTPOINT ENDPOINT]  */
+                      [t ELEMENT STARTPOINT ENDPOINT]  */
                    if (NUMBERP (content))
                      {
                        point = XUINT (content);
@@ -1539,7 +1529,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                      if (point >= map_vector_size) continue;
                      map = AREF (Vcode_conversion_map_vector, point);
 
-                     /* Check map varidity.  */
+                     /* Check map validity.  */
                      if (!CONSP (map)) continue;
                      map = XCDR (map);
                      if (!VECTORP (map)) continue;
@@ -1723,7 +1713,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
            msglen = strlen (msg);
            if (dst + msglen <= (dst_bytes ? dst_end : src))
              {
-               bcopy (msg, dst, msglen);
+               memcpy (dst, msg, msglen);
                dst += msglen;
              }
 
@@ -1736,7 +1726,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
                msglen = strlen (msg);
                if (dst + msglen > (dst_bytes ? dst_end : src))
                  break;
-               bcopy (msg, dst, msglen);
+               memcpy (dst, msg, msglen);
                dst += msglen;
              }
            goto ccl_finish;
@@ -1769,7 +1759,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
          int i = src_end - src;
          if (dst_bytes && (dst_end - dst) < i)
            i = dst_end - dst;
-         bcopy (src, dst, i);
+         memcpy (dst, src, i);
          src += i;
          dst += i;
 #else
@@ -1799,8 +1789,7 @@ ccl_driver (ccl, source, destination, src_size, dst_size, charset_list)
    or nil if CCL contains invalid data.  */
 
 static Lisp_Object
-resolve_symbol_ccl_program (ccl)
-     Lisp_Object ccl;
+resolve_symbol_ccl_program (Lisp_Object ccl)
 {
   int i, veclen, unresolved = 0;
   Lisp_Object result, contents, val;
@@ -1871,9 +1860,7 @@ resolve_symbol_ccl_program (ccl)
    symbols, return Qnil.  */
 
 static Lisp_Object
-ccl_get_compiled_code (ccl_prog, idx)
-     Lisp_Object ccl_prog;
-     int *idx;
+ccl_get_compiled_code (Lisp_Object ccl_prog, int *idx)
 {
   Lisp_Object val, slot;
 
@@ -1914,9 +1901,7 @@ ccl_get_compiled_code (ccl_prog, idx)
 
    If CCL_PROG is nil, we just reset the structure pointed by CCL.  */
 int
-setup_ccl_program (ccl, ccl_prog)
-     struct ccl_program *ccl;
-     Lisp_Object ccl_prog;
+setup_ccl_program (struct ccl_program *ccl, Lisp_Object ccl_prog)
 {
   int i;
 
@@ -1957,8 +1942,7 @@ setup_ccl_program (ccl, ccl_prog)
 /* Check if CCL is updated or not.  If not, re-setup members of CCL.  */
 
 int
-check_ccl_update (ccl)
-     struct ccl_program *ccl;
+check_ccl_update (struct ccl_program *ccl)
 {
   Lisp_Object slot, ccl_prog;
 
@@ -1981,9 +1965,8 @@ check_ccl_update (ccl)
 
 DEFUN ("ccl-program-p", Fccl_program_p, Sccl_program_p, 1, 1, 0,
        doc: /* Return t if OBJECT is a CCL program name or a compiled CCL program code.
-See the documentation of  `define-ccl-program' for the detail of CCL program.  */)
-     (object)
-     Lisp_Object object;
+See the documentation of `define-ccl-program' for the detail of CCL program.  */)
+  (Lisp_Object object)
 {
   Lisp_Object val;
 
@@ -2017,8 +2000,7 @@ the corresponding register after the execution.
 
 See the documentation of `define-ccl-program' for a definition of CCL
 programs.  */)
-     (ccl_prog, reg)
-     Lisp_Object ccl_prog, reg;
+  (Lisp_Object ccl_prog, Lisp_Object reg)
 {
   struct ccl_program ccl;
   int i;
@@ -2062,7 +2044,7 @@ If R0..R7 are nil, they are initialized to 0.
 If IC is nil, it is initialized to head of the CCL program.
 
 If optional 4th arg CONTINUE is non-nil, keep IC on read operation
-when read buffer is exausted, else, IC is always set to the end of
+when read buffer is exhausted, else, IC is always set to the end of
 CCL-PROGRAM on exit.
 
 It returns the contents of write buffer as a string,
@@ -2072,18 +2054,17 @@ is a unibyte string.  By default it is a multibyte string.
 
 See the documentation of `define-ccl-program' for the detail of CCL program.
 usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBYTE-P)  */)
-     (ccl_prog, status, str, contin, unibyte_p)
-     Lisp_Object ccl_prog, status, str, contin, unibyte_p;
+  (Lisp_Object ccl_prog, Lisp_Object status, Lisp_Object str, Lisp_Object contin, Lisp_Object unibyte_p)
 {
   Lisp_Object val;
   struct ccl_program ccl;
   int i;
   int outbufsize;
   unsigned char *outbuf, *outp;
-  int str_chars, str_bytes;
+  EMACS_INT str_chars, str_bytes;
 #define CCL_EXECUTE_BUF_SIZE 1024
   int source[CCL_EXECUTE_BUF_SIZE], destination[CCL_EXECUTE_BUF_SIZE];
-  int consumed_chars, consumed_bytes, produced_chars;
+  EMACS_INT consumed_chars, consumed_bytes, produced_chars;
 
   if (setup_ccl_program (&ccl, ccl_prog) < 0)
     error ("Invalid CCL program");
@@ -2147,7 +2128,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
              if (outp - outbuf + MAX_MULTIBYTE_LENGTH * ccl.produced
                  > outbufsize)
                {
-                 int offset = outp - outbuf;
+                 EMACS_INT offset = outp - outbuf;
                  outbufsize += MAX_MULTIBYTE_LENGTH * ccl.produced;
                  outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
                  outp = outbuf + offset;
@@ -2159,7 +2140,7 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY
            {
              if (outp - outbuf + ccl.produced > outbufsize)
                {
-                 int offset = outp - outbuf;
+                 EMACS_INT offset = outp - outbuf;
                  outbufsize += ccl.produced;
                  outbuf = (unsigned char *) xrealloc (outbuf, outbufsize);
                  outp = outbuf + offset;
@@ -2203,8 +2184,7 @@ DEFUN ("register-ccl-program", Fregister_ccl_program, Sregister_ccl_program,
 CCL-PROG should be a compiled CCL program (vector), or nil.
 If it is nil, just reserve NAME as a CCL program name.
 Return index number of the registered CCL program.  */)
-     (name, ccl_prog)
-     Lisp_Object name, ccl_prog;
+     (Lisp_Object name, Lisp_Object ccl_prog)
 {
   int len = ASIZE (Vccl_program_table);
   int idx;
@@ -2233,7 +2213,7 @@ Return index number of the registered CCL program.  */)
 
       slot = AREF (Vccl_program_table, idx);
       if (!VECTORP (slot))
-       /* This is the first unsed slot.  Register NAME here.  */
+       /* This is the first unused slot.  Register NAME here.  */
        break;
 
       if (EQ (name, AREF (slot, 0)))
@@ -2279,8 +2259,7 @@ DEFUN ("register-code-conversion-map", Fregister_code_conversion_map,
        2, 2, 0,
        doc: /* Register SYMBOL as code conversion map MAP.
 Return index number of the registered map.  */)
-     (symbol, map)
-     Lisp_Object symbol, map;
+  (Lisp_Object symbol, Lisp_Object map)
 {
   int len = ASIZE (Vcode_conversion_map_vector);
   int i;
@@ -2319,27 +2298,27 @@ Return index number of the registered map.  */)
 
 
 void
-syms_of_ccl ()
+syms_of_ccl (void)
 {
   staticpro (&Vccl_program_table);
   Vccl_program_table = Fmake_vector (make_number (32), Qnil);
 
-  Qccl = intern ("ccl");
+  Qccl = intern_c_string ("ccl");
   staticpro (&Qccl);
 
-  Qcclp = intern ("cclp");
+  Qcclp = intern_c_string ("cclp");
   staticpro (&Qcclp);
 
-  Qccl_program = intern ("ccl-program");
+  Qccl_program = intern_c_string ("ccl-program");
   staticpro (&Qccl_program);
 
-  Qccl_program_idx = intern ("ccl-program-idx");
+  Qccl_program_idx = intern_c_string ("ccl-program-idx");
   staticpro (&Qccl_program_idx);
 
-  Qcode_conversion_map = intern ("code-conversion-map");
+  Qcode_conversion_map = intern_c_string ("code-conversion-map");
   staticpro (&Qcode_conversion_map);
 
-  Qcode_conversion_map_id = intern ("code-conversion-map-id");
+  Qcode_conversion_map_id = intern_c_string ("code-conversion-map-id");
   staticpro (&Qcode_conversion_map_id);
 
   DEFVAR_LISP ("code-conversion-map-vector", &Vcode_conversion_map_vector,