From 511c0b94168327151ec97b23cbf92d50f33212ed Mon Sep 17 00:00:00 2001 From: gmerlin Date: Fri, 2 Jun 2006 21:54:21 +0000 Subject: [PATCH] * UTF-8 support patch --- include/cdio/Makefile.am | 3 +- include/cdio/iso9660.h | 14 ++--- include/cdio/types.h | 12 +++- lib/driver/Makefile.am | 3 +- lib/driver/libcdio.sym | 5 ++ lib/iso9660/iso9660_fs.c | 118 ++++++++++----------------------------- 6 files changed, 54 insertions(+), 101 deletions(-) diff --git a/include/cdio/Makefile.am b/include/cdio/Makefile.am index 2fae181c..ef07d60d 100644 --- a/include/cdio/Makefile.am +++ b/include/cdio/Makefile.am @@ -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 # @@ -50,6 +50,7 @@ libcdioinclude_HEADERS = \ udf.h \ udf_file.h \ udf_time.h \ + utf8.h \ util.h \ version.h \ xa.h diff --git a/include/cdio/iso9660.h b/include/cdio/iso9660.h index 40a35cda..eb8586fa 100644 --- a/include/cdio/iso9660.h +++ b/include/cdio/iso9660.h @@ -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 Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein @@ -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 */ diff --git a/include/cdio/types.h b/include/cdio/types.h index a588fc07..b07da396 100644 --- a/include/cdio/types.h +++ b/include/cdio/types.h @@ -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 Copyright (C) 2002, 2003, 2004, 2005, 2006 @@ -202,7 +202,15 @@ typedef uint8_t ubyte; typedef struct msf_s msf_t; #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, diff --git a/lib/driver/Makefile.am b/lib/driver/Makefile.am index efa8d6cb..6284d513 100644 --- a/lib/driver/Makefile.am +++ b/lib/driver/Makefile.am @@ -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 # @@ -94,6 +94,7 @@ libcdio_sources = \ sector.c \ solaris.c \ track.c \ + utf8.c \ util.c lib_LTLIBRARIES = libcdio.la diff --git a/lib/driver/libcdio.sym b/lib/driver/libcdio.sym index 3e2ca4b0..fa5a9202 100644 --- a/lib/driver/libcdio.sym +++ b/lib/driver/libcdio.sym @@ -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 diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index 7c767cbb..945a0b8b 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -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 Copyright (C) 2003, 2004, 2005, 2006 Rocky Bernstein @@ -33,10 +33,6 @@ # include #endif -#ifdef HAVE_ICONV -# include -#endif - #ifdef HAVE_LANGINFO_CODESET #include #endif @@ -45,6 +41,7 @@ #include #include #include +#include /* Private headers */ #include "cdio_assert.h" @@ -53,7 +50,7 @@ #include -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); }