root/ext/charconv/charconv.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ScmConvInfo

   1 /*
   2  * charconv.h - character code conversion library
   3  *
   4  *   Copyright (c) 2000-2003 Shiro Kawai, All rights reserved.
   5  * 
   6  *   Redistribution and use in source and binary forms, with or without
   7  *   modification, are permitted provided that the following conditions
   8  *   are met:
   9  * 
  10  *   1. Redistributions of source code must retain the above copyright
  11  *      notice, this list of conditions and the following disclaimer.
  12  *
  13  *   2. Redistributions in binary form must reproduce the above copyright
  14  *      notice, this list of conditions and the following disclaimer in the
  15  *      documentation and/or other materials provided with the distribution.
  16  *
  17  *   3. Neither the name of the authors nor the names of its contributors
  18  *      may be used to endorse or promote products derived from this
  19  *      software without specific prior written permission.
  20  *
  21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  *  $Id: charconv.h.in,v 1.13 2003/07/05 03:29:10 shirok Exp $
  34  */
  35 
  36 #ifndef GAUCHE_CHARCONV_H
  37 #define GAUCHE_CHARCONV_H
  38 
  39 #include <gauche.h>
  40 
  41 #ifdef HAVE_ICONV_H
  42 #include <iconv.h>
  43 #else
  44 /* Dummy definitions */
  45 typedef int iconv_t;
  46 #endif /* !HAVE_ICONV_H */
  47 
  48 SCM_DECL_BEGIN
  49 
  50 struct ScmConvInfoRec;
  51 
  52 typedef size_t (*ScmConvProc)(struct ScmConvInfoRec*, const char*, size_t,
  53                               char*, size_t, size_t*);
  54 typedef size_t (*ScmConvReset)(struct ScmConvInfoRec*, char*, size_t);
  55 typedef size_t (*ScmConvHandler)(struct ScmConvInfoRec*, const char **,
  56                                  size_t*, char**, size_t*);
  57 
  58 /* Packaging conversion context info.*/
  59 typedef struct ScmConvInfoRec {
  60     ScmConvHandler jconv;       /* jconv handler */
  61     ScmConvProc convproc[2];    /* conversion routine */
  62     ScmConvReset reset;         /* reset routine */
  63     iconv_t handle;             /* iconv handle, if the conversion is
  64                                    handled by iconv */
  65     const char *fromCode;       /* convert from ... */
  66     const char *toCode;         /* conver to ... */
  67     int istate;                 /* current input state */
  68     int ostate;                 /* current output state */
  69     ScmPort *remote;            /* source or drain port */
  70     int ownerp;                 /* do I own remote port? */
  71     int remoteClosed;           /* true if remore port is closed */
  72     int bufsiz;                 /* size of conversion buffer */
  73     char *buf;                  /* internal conversion buffer */
  74     char *ptr;                  /* current ptr in the internal conv buf */
  75 } ScmConvInfo;
  76 
  77 extern ScmObj Scm_MakeInputConversionPort(ScmPort *source,
  78                                           const char *fromCode,
  79                                           const char *toCode,
  80                                           ScmObj handler,
  81                                           int bufsiz,
  82                                           int ownerp);
  83 extern ScmObj Scm_MakeOutputConversionPort(ScmPort *sink,
  84                                            const char *toCode,
  85                                            const char *fromCode,
  86                                            int bufsiz,
  87                                            int ownerp);
  88 
  89 typedef const char *(*ScmCodeGuessingProc)(const char *buf,
  90                                            int bufsiz,
  91                                            void *data);
  92 
  93 extern const char *Scm_GetCESName(ScmObj code, const char *argname);
  94 extern int Scm_ConversionSupportedP(const char *from, const char *to);
  95 
  96 extern void Scm_RegisterCodeGuessingProc(const char *code,
  97                                          ScmCodeGuessingProc proc,
  98                                          void *data);
  99 
 100 extern const char *Scm_GuessCES(const char *code,
 101                                 const char *buf,
 102                                 int buflen);
 103 
 104 /* jconv error code */
 105 #define ILLEGAL_SEQUENCE  ((size_t)-1)
 106 #define INPUT_NOT_ENOUGH  ((size_t)-2)
 107 #define OUTPUT_NOT_ENOUGH ((size_t)-3)
 108 
 109 extern ScmConvInfo *jconv_open(const char *toCode, const char *fromCode);
 110 extern int jconv_close(ScmConvInfo*);
 111 extern size_t jconv(ScmConvInfo*, const char **inptr, size_t *inroom,
 112                     char **outptr, size_t *outroom);
 113 extern size_t jconv_reset(ScmConvInfo *, char *outptr, size_t outroom);
 114 
 115 /* Given UCS char, return # of bytes required for UTF8 encoding. */
 116 #define UCS2UTF_NBYTES(ucs)                      \
 117     (((ucs) < 0x80) ? 1 :                        \
 118      (((ucs) < 0x800) ? 2 :                      \
 119       (((ucs) < 0x10000) ? 3 :                   \
 120        (((ucs) < 0x200000) ? 4 :                 \
 121         (((ucs) < 0x4000000) ? 5 : 6)))))
 122 
 123 extern void jconv_ucs4_to_utf8(unsigned int ucs, char *cp);
 124 
 125 SCM_DECL_END
 126 
 127 #endif /*GAUCHE_CHARCONV_H*/
 128 
 129 /*
 130  * Local variables:
 131  * mode: c
 132  * end:
 133  */

/* [<][>][^][v][top][bottom][index][help] */