/* CCL (Code Conversion Language) interpreter.
- Copyright (C) 2001-2013 Free Software Foundation, Inc.
+ Copyright (C) 2001-2016 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)
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 of the License, 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
#include "ccl.h"
#include "coding.h"
-Lisp_Object Qccl, Qcclp;
-
-/* This symbol is a property which associates with ccl program vector.
- Ex: (get 'ccl-big5-encoder 'ccl-program) returns ccl program vector. */
-static Lisp_Object Qccl_program;
-
-/* These symbols are properties which associate with code conversion
- map and their ID respectively. */
-static Lisp_Object Qcode_conversion_map;
-static Lisp_Object Qcode_conversion_map_id;
-
-/* Symbols of ccl program have this property, a value of the property
- is an index for Vccl_program_table. */
-static Lisp_Object Qccl_program_idx;
-
/* Table of registered CCL programs. Each element is a vector of
NAME, CCL_PROG, RESOLVEDP, and UPDATEDP, where NAME (symbol) is the
name of the program, CCL_PROG (vector) is the compiled code of the
{ \
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) \
{ \
}
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
case CCL_STAT_INVALID_CMD:
msglen = sprintf (msg,
"\nCCL: Invalid command %x (ccl_code = %x) at %d.",
- code & 0x1F, code, this_ic);
+ code & 0x1Fu, code + 0u, this_ic);
#ifdef CCL_DEBUG
{
int i = ccl_backtrace_idx - 1;
/* 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;
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;
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;
}
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);
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);
}
buf_magnification = ccl.buf_magnification ? ccl.buf_magnification : 1;
-
- if ((min (PTRDIFF_MAX, SIZE_MAX) - 256) / buf_magnification < str_bytes)
+ outbufsize = str_bytes;
+ if (INT_MULTIPLY_WRAPV (buf_magnification, outbufsize, &outbufsize)
+ || INT_ADD_WRAPV (256, outbufsize, &outbufsize))
memory_full (SIZE_MAX);
- outbufsize = (ccl.buf_magnification
- ? str_bytes * ccl.buf_magnification + 256
- : str_bytes + 256);
outp = outbuf = xmalloc (outbufsize);
consumed_chars = consumed_bytes = 0;
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;
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;
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);
DEFSYM (Qccl, "ccl");
DEFSYM (Qcclp, "cclp");
- DEFSYM (Qccl_program, "ccl-program");
+
+ /* Symbols of ccl program have this property, a value of the property
+ is an index for Vccl_program_table. */
DEFSYM (Qccl_program_idx, "ccl-program-idx");
+
+ /* These symbols are properties which associate with code conversion
+ map and their ID respectively. */
DEFSYM (Qcode_conversion_map, "code-conversion-map");
DEFSYM (Qcode_conversion_map_id, "code-conversion-map-id");