アルゴリズム・ベースのステートレス・コンバーター

各コンバーターには、以前に指定したサブルーチンが必要です。 詳細のないサブルーチン・ヘッダーだけが提供されますが、 すべてのコンバーターに共通の instantiate サブルーチンは例外で、 同じ方法でコード化されていなければなりません。

次に示すアルゴリズム・ベースのステートレス・コンバーターの例は、 IBM-850 コード・セットから ISO8859-1 コード・セットへのサンプル・コンバーターです。

#include <stdlib.h>
#include <iconv.h>
#include "850_88591.h"
/*
 *      Name :  _iconv_exec()
 *      
 *      This contains actual conversion method.  
 */
static size_t   _iconv_exec(_LC_sample_iconv_t *cd, 
                         unsigned char** inbuf, 
                         size_t *inbytesleft,
                         unsigned char** outbuf, 
                         size_t *outbytesleft)
/*
 *      cd               : converter descriptor
 *      inbuf            : input buffer
 *      outbuf           : output buffer
 *      inbytesleft      : number of data(in bytes) in input buffer
 *      outbytesleft     : number of data(in bytes) in output buffer
 */

{
}
 
/*
 *      Name :   _iconv_close()
 *      
 *      Free the allocated converter descriptor
 */
static void      _iconv_close(iconv_t cd)
{
}
 
/*
 *      Name :  init()
 *      
 *      This allocates and initializes the converter descriptor.
 */
static _LC_sample_iconv_t        *init (_LC_core_iconv_t *core_cd, 
                                  char* toname, char* fromname)
{
}
 
/*
 *       Name :  instantiate()
 *       
 *       Core part of a converter descriptor is initialized here.
 */
_LC_core_iconv_t         *instantiate(void)
{
        static _LC_core_iconv_t   cd;
 
        /*
        * * Initialize _LC_MAGIC and _LC_VERSION are 
        ** defined in <lc_core.h>. _LC_ICONV and _LC_core_iconv_t
        ** are defined in <iconv.h>.
         */
        cd.hdr.magic = _LC_MAGIC;
        cd.hdr.version = _LC_VERSION;
        cd.hdr.type_id = _LC_ICONV;
        cd.hdr.size = sizeof (_LC_core_iconv_t);
 
        /*
         *      Set pointers to each method.
         */
        cd.init = init;
        cd.exec = _iconv_exec;
        cd.close = _iconv_close;
 
        /*
         *      Returns the core part
         */
        return &cd;
}