Fix -Wimplicit warnings.
[bpt/emacs.git] / src / ccl.c
index 3a65ee8..d68367f 100644 (file)
--- a/src/ccl.c
+++ b/src/ccl.c
@@ -24,6 +24,11 @@ Boston, MA 02111-1307, USA.  */
 #ifdef emacs
 
 #include <config.h>
+
+#ifdef STDC_HEADERS
+#include <stdlib.h>
+#endif
+
 #include "lisp.h"
 #include "charset.h"
 #include "ccl.h"
@@ -659,6 +664,7 @@ struct ccl_prog_stack
     int ic;                    /* Instruction Counter.  */
   };
 
+int
 ccl_driver (ccl, source, destination, src_bytes, dst_bytes, consumed)
      struct ccl_program *ccl;
      unsigned char *source, *destination;
@@ -1519,7 +1525,7 @@ As side effect, each element of REGISTER holds the value of\n\
 }
 
 DEFUN ("ccl-execute-on-string", Fccl_execute_on_string, Sccl_execute_on_string,
-       3, 4, 0,
+       3, 5, 0,
   "Execute CCL-PROGRAM with initial STATUS on STRING.\n\
 CCL-PROGRAM is a compiled code generated by `ccl-compile'.\n\
 Read buffer is set to STRING, and write buffer is allocated automatically.\n\
@@ -1528,13 +1534,17 @@ STATUS is a vector of [R0 R1 ... R7 IC], where\n\
  IC is the instruction counter specifying from where to start the program.\n\
 If R0..R7 are nil, they are initialized to 0.\n\
 If IC is nil, it is initialized to head of the CCL program.\n\
-Returns the contents of write buffer as a string,\n\
- and as side effect, STATUS is updated.\n\
-If optional 4th arg CONTINUE is non-nil, keep IC on read operation\n\
+\n\
+If optional 4th arg CONTIN is non-nil, keep IC on read operation\n\
 when read buffer is exausted, else, IC is always set to the end of\n\
-CCL-PROGRAM on exit.")
-  (ccl_prog, status, str, contin)
-     Lisp_Object ccl_prog, status, str, contin;
+CCL-PROGRAM on exit.\n\
+\n\
+It returns the contents of write buffer as a string,\n\
+and as side effect, STATUS is updated.\n\
+If the optional 5th arg UNIBYTE-P is non-nil, the returned string\n\
+is a unibyte string.  By default it is a multibyte string.")
+  (ccl_prog, status, str, contin, unibyte_p)
+     Lisp_Object ccl_prog, status, str, contin, unibyte_p;
 {
   Lisp_Object val;
   struct ccl_program ccl;
@@ -1564,19 +1574,22 @@ CCL-PROGRAM on exit.")
       if (ccl.ic < i && i < ccl.size)
        ccl.ic = i;
     }
-  outbufsize = XSTRING (str)->size_byte * ccl.buf_magnification + 256;
+  outbufsize = STRING_BYTES (XSTRING (str)) * ccl.buf_magnification + 256;
   outbuf = (char *) xmalloc (outbufsize);
   if (!outbuf)
     error ("Not enough memory");
   ccl.last_block = NILP (contin);
   produced = ccl_driver (&ccl, XSTRING (str)->data, outbuf,
-                        XSTRING (str)->size_byte, outbufsize, (int *)0);
+                        STRING_BYTES (XSTRING (str)), outbufsize, (int *)0);
   for (i = 0; i < 8; i++)
     XSET (XVECTOR (status)->contents[i], Lisp_Int, ccl.reg[i]);
   XSETINT (XVECTOR (status)->contents[8], ccl.ic);
   UNGCPRO;
 
-  val = make_string (outbuf, produced);
+  if (NILP (unibyte_p))
+    val = make_string (outbuf, produced);
+  else
+    val = make_unibyte_string (outbuf, produced);
   free (outbuf);
   QUIT;
   if (ccl.status != CCL_STAT_SUCCESS
@@ -1692,6 +1705,7 @@ Return index number of the registered translation table.")
 }
 
 
+void
 syms_of_ccl ()
 {
   staticpro (&Vccl_program_table);