New API functions iso_set_local_charset() and iso_get_local_charset()

This commit is contained in:
Thomas Schmitt 2008-11-25 12:13:51 +01:00
parent 88ef351e74
commit eccaac09cc
4 changed files with 70 additions and 3 deletions

View File

@ -911,9 +911,13 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
target->catalog = src->bootcat;
/* default to locale charset */
/* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ?
*/
setlocale(LC_CTYPE, "");
target->input_charset = strdup(nl_langinfo(CODESET));
target->input_charset = strdup(iso_get_local_charset(0));
if (target->input_charset == NULL) {
iso_image_unref(src);
free(target);

View File

@ -1996,8 +1996,12 @@ int iso_image_filesystem_new(IsoDataSource *src, struct iso_read_opts *opts,
data->dir_mode = opts->dir_mode & ~S_IFMT;
data->msgid = msgid;
/* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ?
*/
setlocale(LC_CTYPE, "");
data->local_charset = strdup(nl_langinfo(CODESET));
data->local_charset = strdup(iso_get_local_charset(0));
if (data->local_charset == NULL) {
ret = ISO_OUT_OF_MEM;
goto fs_cleanup;

View File

@ -835,6 +835,36 @@ int iso_init();
*/
void iso_finish();
/**
* Override the reply of libc function nl_langinfo(CODESET) which may or may
* not give the name of the character set which is in effect for your
* environment. So this call can compensate for inconsistent terminal setups.
* Another use case is to choose UTF-8 as intermediate character set for a
* conversion from an exotic input character set to an exotic output set.
*
* @param name
* Name of the character set to be assumed as "local" one.
* @param flag
* Unused yet. Submit 0.
* @return
* 1 indicates success, <=0 failure
*
* @since 0.6.12
*/
int iso_set_local_charset(char *name, int flag);
/**
* Obtain the local charset as currently assumed by libisofs.
* The result points to internal memory. It is volatile and must not be
* altered.
*
* @param flag
* Unused yet. Submit 0.
*
* @since 0.6.12
*/
char *iso_get_local_charset(int flag);
/**
* Create a new image, empty.
*

View File

@ -40,6 +40,30 @@ int int_pow(int base, int power)
return result;
}
/* This static variable can override the locale's charset by its getter
function which should be used whenever the local character set name
is to be inquired. I.e. instead of calling nl_langinfo(CODESET) directly.
If the variable is empty then it forwards nl_langinfo(CODESET).
*/
static char libisofs_local_charset[4096]= {""};
/* API function */
int iso_set_local_charset(char *name, int flag)
{
if(strlen(name) >= sizeof(libisofs_local_charset))
return(0);
strcpy(libisofs_local_charset, name);
return 1;
}
/* API function */
char *iso_get_local_charset(int flag)
{
if(libisofs_local_charset[0])
return libisofs_local_charset;
return nl_langinfo(CODESET);
}
int strconv(const char *str, const char *icharset, const char *ocharset,
char **output)
{
@ -1219,8 +1243,13 @@ char *ucs2str(const char *buf, size_t len)
out = alloca(outbytes);
/* convert to local charset */
/* ??? ts Nov 25 2008 :
Shouldn't this go to library initialization or even to app ?
*/
setlocale(LC_CTYPE, "");
conv = iconv_open(nl_langinfo(CODESET), "UCS-2BE");
conv = iconv_open(iso_get_local_charset(0), "UCS-2BE");
if (conv == (iconv_t)(-1)) {
return NULL;
}