Support for setting an output charset for RR NM entries.

It will default to input charset (i.e. the locale charset for now). 
Names will be stored internally in that locale charset. Note that input 
charset musn't be changed by user. Instead, we can provide an input 
charset property to IsoFilesystem implementations.
This commit is contained in:
Vreixo Formoso
2007-12-28 00:20:02 +01:00
parent 6c7c54af93
commit 9a90afcf69
9 changed files with 94 additions and 30 deletions

View File

@@ -12,6 +12,7 @@
#include "ecma119_tree.h"
#include "error.h"
#include "writer.h"
#include "messages.h"
#include <string.h>
@@ -246,6 +247,30 @@ int rrip_add_CL(Ecma119Image *t, Ecma119Node *n, struct susp_info *susp)
return susp_append(t, susp, CL);
}
static
char *get_rr_name(Ecma119Image *t, Ecma119Node *n)
{
int ret;
char *name;
if (!strcmp(t->input_charset, t->output_charset)) {
/* no conversion needed */
return strdup(n->node->name);
}
ret = strconv(n->node->name, t->input_charset, t->output_charset, &name);
if (ret < 0) {
iso_msg_sorry(t->image, LIBISO_CHARSET_ERROR,
"Charset conversion error. Can't convert %s from %s to %s",
n->node->name, t->input_charset, t->output_charset);
/* use the original name, it's the best we can do */
name = strdup(n->node->name);
}
return name;
}
/**
* Add a NM System Use Entry to the given tree node. The purpose of this
* System Use Entry is to store the content of an Alternate Name to support
@@ -544,7 +569,9 @@ size_t rrip_calc_len(Ecma119Image *t, Ecma119Node *n, int type,
}
if (type == 0) {
size_t namelen = strlen(n->node->name);
char *name = get_rr_name(t, n);
size_t namelen = strlen(name);
free(name);
/* NM entry */
if (su_size + 5 + namelen <= space) {
@@ -727,6 +754,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
int ret;
size_t i;
Ecma119Node *node;
char *name = NULL;
if (t == NULL || n == NULL || info == NULL) {
return ISO_NULL_POINTER;
@@ -807,7 +835,6 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
}
if (type == 0) {
char *name;
size_t sua_free; /* free space in the SUA */
int nm_type = 0; /* 0 whole entry in SUA, 1 part in CE */
size_t ce_len = 0; /* len of the CE */
@@ -817,8 +844,7 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
uint8_t **comps = NULL; /* components of the SL field */
size_t n_comp = 0; /* number of components */
// TODO handle output charset
name = n->node->name;
name = get_rr_name(t, n);
namelen = strlen(name);
sua_free = space - info->suf_len;
@@ -1008,12 +1034,11 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
* Write the NM part that fits in SUA... Note that CE
* entry and NM in the continuation area is added below
*/
size_t len = space - info->suf_len - 28 - 5;
ret = rrip_add_NM(t, info, name, len, 1, 0);
namelen = space - info->suf_len - 28 - 5;
ret = rrip_add_NM(t, info, name, namelen, 1, 0);
if (ret < 0) {
goto add_susp_cleanup;
}
name += len;
}
if (ce_len > 0) {
@@ -1028,7 +1053,8 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
/*
* ..and the part that goes to continuation area.
*/
ret = rrip_add_NM(t, info, name, strlen(name), 0, 1);
ret = rrip_add_NM(t, info, name + namelen, strlen(name + namelen),
0, 1);
if (ret < 0) {
goto add_susp_cleanup;
}
@@ -1084,9 +1110,11 @@ int rrip_get_susp_fields(Ecma119Image *t, Ecma119Node *n, int type,
*/
info->suf_len += (info->suf_len % 2);
free(name);
return ISO_SUCCESS;
add_susp_cleanup:;
free(name);
susp_info_free(info);
return ret;
}