* UTF-8 support patch

This commit is contained in:
gmerlin
2006-06-02 21:54:21 +00:00
parent 5d3ef6fa82
commit 511c0b9416
6 changed files with 54 additions and 101 deletions

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.30 2006/02/27 10:10:08 flameeyes Exp $
# $Id: Makefile.am,v 1.31 2006/06/02 21:54:21 gmerlin Exp $
#
# Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
#
@@ -50,6 +50,7 @@ libcdioinclude_HEADERS = \
udf.h \
udf_file.h \
udf_time.h \
utf8.h \
util.h \
version.h \
xa.h

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660.h,v 1.93 2006/05/06 16:08:06 rocky Exp $
$Id: iso9660.h,v 1.94 2006/06/02 21:54:21 gmerlin Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@gnu.org>
@@ -916,7 +916,7 @@ char * iso9660_get_application_id(iso9660_pvd_t *p_pvd);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_application_id(iso9660_t *p_iso,
/*out*/ char **p_psz_app_id);
/*out*/ cdio_utf8_t **p_psz_app_id);
/*!
Return the Joliet level recognized for p_iso.
@@ -954,7 +954,7 @@ lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
/*out*/ char **p_psz_preparer_id);
/*out*/ cdio_utf8_t **p_psz_preparer_id);
/*!
Return a string containing the PVD's publisher id with trailing
@@ -967,7 +967,7 @@ lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
/*out*/ char **p_psz_publisher_id);
/*out*/ cdio_utf8_t **p_psz_publisher_id);
uint8_t iso9660_get_pvd_type(const iso9660_pvd_t *p_pvd);
@@ -993,7 +993,7 @@ lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
/*out*/ char **p_psz_system_id);
/*out*/ cdio_utf8_t **p_psz_system_id);
/*! Return the LSN of the root directory for pvd.
@@ -1012,7 +1012,7 @@ lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
/*out*/ char **p_psz_volume_id);
/*out*/ cdio_utf8_t **p_psz_volume_id);
/*!
Return the volumeset ID in the PVD.
@@ -1025,7 +1025,7 @@ lsn_t iso9660_get_dir_extent(const iso9660_dir_t *p_idr);
is some problem in getting this and false is returned.
*/
bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
/*out*/ char **p_psz_volumeset_id);
/*out*/ cdio_utf8_t **p_psz_volumeset_id);
/* pathtable */

View File

@@ -1,5 +1,5 @@
/*
$Id: types.h,v 1.35 2006/01/23 20:47:33 rocky Exp $
$Id: types.h,v 1.36 2006/06/02 21:54:21 gmerlin Exp $
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2002, 2003, 2004, 2005, 2006
@@ -203,6 +203,14 @@ typedef uint8_t ubyte;
#define msf_t_SIZEOF 3
/*!
\brief UTF-8 char definition
Type to denote UTF-8 strings.
*/
typedef char cdio_utf8_t;
typedef enum {
nope = 0,
yep = 1,

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.15 2006/03/14 12:05:16 rocky Exp $
# $Id: Makefile.am,v 1.16 2006/06/02 21:54:21 gmerlin Exp $
#
# Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
#
@@ -94,6 +94,7 @@ libcdio_sources = \
sector.c \
solaris.c \
track.c \
utf8.c \
util.c
lib_LTLIBRARIES = libcdio.la

View File

@@ -205,3 +205,8 @@ mmc_set_speed
mmc_start_stop_media
mmc_timeout_ms
track_format2str
cdio_charset_converter_create
cdio_charset_converter_destroy
cdio_charset_convert
cdio_charset_from_utf8
cdio_charset_to_utf8

View File

@@ -1,5 +1,5 @@
/*
$Id: iso9660_fs.c,v 1.35 2006/03/17 22:36:31 rocky Exp $
$Id: iso9660_fs.c,v 1.36 2006/06/02 21:54:21 gmerlin Exp $
Copyright (C) 2001 Herbert Valerio Riedel <hvr@gnu.org>
Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein <rocky@panix.com>
@@ -33,10 +33,6 @@
# include <errno.h>
#endif
#ifdef HAVE_ICONV
# include <iconv.h>
#endif
#ifdef HAVE_LANGINFO_CODESET
#include <langinfo.h>
#endif
@@ -45,6 +41,7 @@
#include <cdio/bytesex.h>
#include <cdio/iso9660.h>
#include <cdio/util.h>
#include <cdio/utf8.h>
/* Private headers */
#include "cdio_assert.h"
@@ -53,7 +50,7 @@
#include <stdio.h>
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.35 2006/03/17 22:36:31 rocky Exp $";
static const char _rcsid[] = "$Id: iso9660_fs.c,v 1.36 2006/06/02 21:54:21 gmerlin Exp $";
/* Implementation of iso9660_t type */
struct _iso9660_s {
@@ -277,71 +274,13 @@ check_pvd (const iso9660_pvd_t *p_pvd, cdio_log_level_t log_level)
return true;
}
#ifdef HAVE_JOLIET
static bool
ucs2be_to_locale(ICONV_CONST char *psz_ucs2be, size_t i_inlen,
char **p_psz_out, size_t i_outlen)
{
iconv_t ic =
#if defined(HAVE_LANGINFO_CODESET)
iconv_open(nl_langinfo(CODESET), "UCS-2BE");
#else
iconv_open("ASCII", "UCS-2BE");
#endif
int rc;
char *psz_buf = NULL;
char *psz_buf2;
int i_outlen_max = i_outlen;
int i_outlen_actual;
if (-1 == (size_t) ic) {
#if defined(HAVE_LANGINFO_CODESET)
cdio_info("Failed to get conversion table for locale, trying ASCII");
ic = iconv_open("ASCII", "UCS-2BE");
if (-1 == (size_t) ic) {
cdio_info("Failed to get conversion table for ASCII too");
return false;
}
#else
cdio_info("Failed to get conversion table for locale");
return false;
#endif
}
psz_buf = (char *) realloc(psz_buf, i_outlen);
psz_buf2 = psz_buf;
if (!psz_buf) {
/* XXX: report out of memory error */
goto error;
}
rc = iconv(ic, &psz_ucs2be, &i_inlen, &psz_buf2, &i_outlen);
iconv_close(ic);
if ((rc == -1) && (errno != E2BIG)) {
/* conversion failed */
goto error;
}
i_outlen_actual = i_outlen_max - i_outlen;
*p_psz_out = malloc(i_outlen_actual + 1);
memcpy(*p_psz_out, psz_buf, i_outlen_actual);
*(*p_psz_out + i_outlen_actual) = '\0';
free(psz_buf);
return true;
error:
free(psz_buf);
*p_psz_out = NULL;
return false;
}
#endif /*HAVE_JOLIET*/
/*!
Return the application ID. NULL is returned in psz_app_id if there
is some problem in getting this.
*/
bool
iso9660_ifs_get_application_id(iso9660_t *p_iso,
/*out*/ char **p_psz_app_id)
/*out*/ cdio_utf8_t **p_psz_app_id)
{
if (!p_iso) {
*p_psz_app_id = NULL;
@@ -355,10 +294,9 @@ iso9660_ifs_get_application_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if ( ucs2be_to_locale(p_iso->svd.application_id,
ISO_MAX_APPLICATION_ID,
p_psz_app_id,
ISO_MAX_APPLICATION_ID))
if ( cdio_charset_to_utf8(p_iso->svd.application_id,
ISO_MAX_APPLICATION_ID,
p_psz_app_id, "UCS-2BE"))
return true;
}
#endif /*HAVE_JOLIET*/
@@ -381,7 +319,7 @@ uint8_t iso9660_ifs_get_joliet_level(iso9660_t *p_iso)
*/
bool
iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
/*out*/ char **p_psz_preparer_id)
/*out*/ cdio_utf8_t **p_psz_preparer_id)
{
if (!p_iso) {
*p_psz_preparer_id = NULL;
@@ -395,8 +333,8 @@ iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if ( ucs2be_to_locale(p_iso->svd.preparer_id, ISO_MAX_PREPARER_ID,
p_psz_preparer_id, ISO_MAX_PREPARER_ID) )
if ( cdio_charset_to_utf8(p_iso->svd.preparer_id, ISO_MAX_PREPARER_ID,
p_psz_preparer_id, "UCS-2BE") )
return true;
}
#endif /*HAVE_JOLIET*/
@@ -409,7 +347,7 @@ iso9660_ifs_get_preparer_id(iso9660_t *p_iso,
blanks removed.
*/
bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
/*out*/ char **p_psz_publisher_id)
/*out*/ cdio_utf8_t **p_psz_publisher_id)
{
if (!p_iso) {
*p_psz_publisher_id = NULL;
@@ -423,8 +361,8 @@ bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if( ucs2be_to_locale(p_iso->svd.publisher_id, ISO_MAX_PUBLISHER_ID,
p_psz_publisher_id, ISO_MAX_PUBLISHER_ID) )
if( cdio_charset_to_utf8(p_iso->svd.publisher_id, ISO_MAX_PUBLISHER_ID,
p_psz_publisher_id, "UCS-2BE") )
return true;
}
#endif /*HAVE_JOLIET*/
@@ -438,7 +376,7 @@ bool iso9660_ifs_get_publisher_id(iso9660_t *p_iso,
blanks removed.
*/
bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
/*out*/ char **p_psz_system_id)
/*out*/ cdio_utf8_t **p_psz_system_id)
{
if (!p_iso) {
*p_psz_system_id = NULL;
@@ -452,8 +390,8 @@ bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if ( ucs2be_to_locale(p_iso->svd.system_id, ISO_MAX_SYSTEM_ID,
p_psz_system_id, ISO_MAX_SYSTEM_ID) )
if ( cdio_charset_to_utf8(p_iso->svd.system_id, ISO_MAX_SYSTEM_ID,
p_psz_system_id, "UCS-2BE") )
return true;
}
#endif /*HAVE_JOLIET*/
@@ -467,7 +405,7 @@ bool iso9660_ifs_get_system_id(iso9660_t *p_iso,
blanks removed.
*/
bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
/*out*/ char **p_psz_volume_id)
/*out*/ cdio_utf8_t **p_psz_volume_id)
{
if (!p_iso) {
*p_psz_volume_id = NULL;
@@ -481,8 +419,8 @@ bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if ( ucs2be_to_locale(p_iso->svd.volume_id, ISO_MAX_VOLUME_ID,
p_psz_volume_id, ISO_MAX_VOLUME_ID) )
if ( cdio_charset_to_utf8(p_iso->svd.volume_id, ISO_MAX_VOLUME_ID,
p_psz_volume_id, "UCS-2BE") )
return true;
}
#endif /* HAVE_JOLIET */
@@ -496,7 +434,7 @@ bool iso9660_ifs_get_volume_id(iso9660_t *p_iso,
blanks removed.
*/
bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
/*out*/ char **p_psz_volumeset_id)
/*out*/ cdio_utf8_t **p_psz_volumeset_id)
{
if (!p_iso) {
*p_psz_volumeset_id = NULL;
@@ -510,10 +448,10 @@ bool iso9660_ifs_get_volumeset_id(iso9660_t *p_iso,
longer results *and* have the same character using
the PVD, do that.
*/
if ( ucs2be_to_locale(p_iso->svd.volume_set_id,
ISO_MAX_VOLUMESET_ID,
p_psz_volumeset_id,
ISO_MAX_VOLUMESET_ID) )
if ( cdio_charset_to_utf8(p_iso->svd.volume_set_id,
ISO_MAX_VOLUMESET_ID,
p_psz_volumeset_id,
"UCS-2BE") )
return true;
}
#endif /*HAVE_JOLIET*/
@@ -843,10 +781,10 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa,
#ifdef HAVE_JOLIET
else if (i_joliet_level) {
int i_inlen = i_fname;
int i_outlen = (i_inlen / 2);
char *p_psz_out = NULL;
ucs2be_to_locale(p_iso9660_dir->filename, i_inlen, &p_psz_out,
i_outlen);
cdio_utf8_t *p_psz_out = NULL;
cdio_charset_to_utf8(p_iso9660_dir->filename, i_inlen,
&p_psz_out, "UCS-2BE");
strncpy(p_stat->filename, p_psz_out, i_fname);
free(p_psz_out);
}