Algorithm-based stateless converters
Every converter should have the subroutines previously specified. Only the subroutine headers are provided without details, except for the instantiate subroutine that is common to all converters and should be coded in the same way.
The following example of an algorithm-based stateless converter is a sample converter of the IBM-850 code set to the ISO8859-1 code set.
#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;
}