On Sun, 3 Mar 2002, Oyvind A. Holm wrote: > On 2002-03-03 14:59 Radovan Garabik wrote:
> > Especially since now I looked into mkisofs sources and indeed there > > does not seem any support for utf-8 input encoding. > > This looks like a feature that should be added. I'll look into the > mkisofs source and try to figure out if it would be a big operation to > add an option to convert UTF-8 strings into a "decent Joliet format" > (what a self-contradiction). If it's worthwhile working on such > formats. Especially the 64 character length limit on file names is hard > to swallow. The question forms in my head -- "Why, Microsoft®, why?". I believe the way to go is UDF (Universal Disk Format??) which is much better thought-out than poorly defined Joliet and is supposed to work across platforms (unlike Joliet). To be fair, I have to mention that the author of cdrtools (which include mkisofs) wrote to me that he plans to support UDF asap. I also realized that I made a critical mistake when sending my patch to him by omitting a new file (which is the heart of my patch to use iconv(3). I forgot to give '-N' option to 'gnu diff'). Perhaps, what happened is that he tried to apply my patch but it didn't work because of the missing file and didn't bother to ask me back. > Jungshik Shin mentioned a quick and dirty patch he'd made to address > this very problem. Could you share it, please? It's a really quick and dirty (and non-portable) patch and there's no guarantee that it will work even on Linux although I used it to burn a couple of Joliet CDs with filenames in EUC-KR. I haven't tried UTF-8, but it shouldn't make any difference because it makes use of libc-provided iconv. Anyway, I'm attaching it. It'll be nice if you can make a much better/cleaner/portable patch based on it. Jungshik Shin
diff -r -u cdrtools-1.10/include/unls.h cdrtools-1.10.jshin/include/unls.h --- cdrtools-1.10/include/unls.h Thu Jan 18 05:53:10 2001 +++ cdrtools-1.10.jshin/include/unls.h Mon Feb 4 17:08:06 2002 @@ -27,6 +27,10 @@ #include <mconfig.h> #endif +#ifdef USE_ICONV +#include <iconv.h> +#endif + #ifdef __cplusplus extern "C" { #endif @@ -40,6 +44,9 @@ char *charset; unsigned char **page_uni2charset; struct nls_unicode *charset2uni; +#ifdef USE_ICONV + iconv_t iconv_d; +#endif void (*inc_use_count) __PR((void)); void (*dec_use_count) __PR((void)); diff -r -u cdrtools-1.10/libunls/Targets cdrtools-1.10.jshin/libunls/Targets --- cdrtools-1.10/libunls/Targets Sat Jan 20 16:18:32 2001 +++ cdrtools-1.10.jshin/libunls/Targets Mon Feb 4 18:08:22 2002 @@ -36,4 +36,5 @@ nls_cp10029.c \ nls_cp10079.c \ nls_cp10081.c \ - nls_file.c + nls_file.c \ + nls_iconv.c diff -r -u cdrtools-1.10/libunls/libunls.mk cdrtools-1.10.jshin/libunls/libunls.mk --- cdrtools-1.10/libunls/libunls.mk Sat Mar 25 07:51:56 2000 +++ cdrtools-1.10.jshin/libunls/libunls.mk Mon Feb 4 16:47:48 2002 @@ -8,6 +8,7 @@ INSDIR= lib TARGETLIB= unls #CPPOPTS += -Istdio +CPPOPTS += -DUSE_ICONV include Targets LIBS= diff -r -u cdrtools-1.10/libunls/nls.h cdrtools-1.10.jshin/libunls/nls.h --- cdrtools-1.10/libunls/nls.h Wed Jan 17 19:40:10 2001 +++ cdrtools-1.10.jshin/libunls/nls.h Mon Feb 4 16:41:25 2002 @@ -105,5 +105,8 @@ extern int init_nls_cp10079 __PR((void)); extern int init_nls_cp10081 __PR((void)); extern int init_nls_file __PR((char * name)); +#ifdef USE_ICONV +extern int init_nls_iconv __PR((char * name)); +#endif #endif /* _NLS_H */ diff -r -u cdrtools-1.10/mkisofs/Makefile cdrtools-1.10.jshin/mkisofs/Makefile --- cdrtools-1.10/mkisofs/Makefile Tue Apr 3 16:33:26 2001 +++ cdrtools-1.10.jshin/mkisofs/Makefile Mon Feb 4 16:47:18 2002 @@ -26,6 +26,7 @@ CPPOPTS += -DUSE_LARGEFILES CPPOPTS += -DAPPLE_HYB CPPOPTS += -DSORTING +CPPOPTS += -DUSE_ICONV CPPOPTS += -I../libhfs_iso/ CPPOPTS += -DHAVE_CONFIG_H -DUSE_LIBSCHILY -DUSE_SCG \ '-DAPPID_DEFAULT="MKISOFS ISO 9660/HFS FILESYSTEM BUILDER & CDRECORD CD-R/DVD CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING"' \ diff -r -u cdrtools-1.10/mkisofs/joliet.c cdrtools-1.10.jshin/mkisofs/joliet.c --- cdrtools-1.10/mkisofs/joliet.c Tue Jan 23 07:28:41 2001 +++ cdrtools-1.10.jshin/mkisofs/joliet.c Mon Feb 4 20:13:09 2002 @@ -89,6 +89,10 @@ #include <unls.h> /* For UNICODE translation */ #include <schily.h> +#ifdef USE_ICONV +#include <iconv.h> +#endif + static Uint jpath_table_index; static struct directory **jpathlist; static int next_jpath_index = 1; @@ -204,6 +208,42 @@ } else { tmpbuf = (Uchar *) source; } + +#ifdef USE_ICONV + if ( inls->iconv_d && inls->charset2uni==NULL && +inls->page_uni2charset==NULL){ + char *inptr=tmpbuf; + char *outptr=buffer; + size_t inleft=strlen(tmpbuf); + size_t outleft=size; + + + iconv(inls->iconv_d,&inptr,&inleft,&outptr,&outleft); + + for (i=0; (i + 1) < size-outleft ; i += 2) { /* Size may be odd!!!*/ + if ( buffer[i]=='\0') { + switch (buffer[i+1]) { /* Invalid characters for +Joliet */ + case '*': + case '/': + case ':': + case ';': + case '?': + case '\\': + buffer[i+1]='_'; + default: + if (buffer[i+1] == 0x7f || buffer[i+1] +< 0x20) + buffer[i+1]='_'; + } + } + } + if (size & 1) { /* beautification */ + buffer[size - 1] = 0; + } + if (source == NULL) { + free(tmpbuf); + } + return; + } +#endif /* * Now start copying characters. If the size was specified to be 0, diff -r -u cdrtools-1.10/mkisofs/mkisofs.c cdrtools-1.10.jshin/mkisofs/mkisofs.c --- cdrtools-1.10/mkisofs/mkisofs.c Fri Apr 20 11:45:50 2001 +++ cdrtools-1.10.jshin/mkisofs/mkisofs.c Mon Feb 4 18:38:31 2002 @@ -1999,6 +1999,14 @@ init_nls_file(hfs_ocharset); #endif /* APPLE_HYB */ +#ifdef USE_ICONV + if ( init_nls_iconv(icharset)==-1) { + fprintf (stderr,"%s: failed to initialize nls_iconv with %s\n", + "mkisofs", icharset); + } + init_nls_iconv(ocharset); +#endif + if (icharset == NULL) { #if (defined(__CYGWIN32__) || defined(__CYGWIN__)) && !defined(IS_CYGWIN_1) in_nls = load_nls("cp437"); diff -N -u cdrtools-1.10/libunls/nls_iconv.c cdrtools-1.10.jshin/libunls/nls_iconv.c --- cdrtools-1.10/libunls/nls_iconv.c Wed Dec 31 19:00:00 1969 +++ cdrtools-1.10.jshin/libunls/nls_iconv.c Mon Feb 4 18:49:06 2002 @@ -0,0 +1,96 @@ +/* @(#)nls_iconv.c 1.0 02/04/20 2002 J. Schilling */ +#ifndef lint +static char sccsid[] = + "@(#)nls_iconv.c 1.0 02/01/20 2002 J. Schilling"; +#endif +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* + * Modifications to make the code portable Copyright (c) 2000 J. Schilling + * + * nls_iconv: create a pseudo-charset table to use iconv() provided by C + * library or libiconv by Bruno Haible + * The Unicode to charset table has only exact mappings. + * + * + * Jungshik Shin ([EMAIL PROTECTED]) 04-Feb-2002 + */ + +#ifdef USE_ICONV +#include <mconfig.h> +#include <stdio.h> +#include <stdxlib.h> +#include <strdefs.h> +#include "nls.h" +#include <iconv.h> + +static void inc_use_count __PR((void)); +static void dec_use_count __PR((void)); + + +static void +inc_use_count() +{ + MOD_INC_USE_COUNT; +} + +static void +dec_use_count() +{ + MOD_DEC_USE_COUNT; +} + +int +init_nls_iconv(charset) + char *charset; +{ + iconv_t iconv_d; /* iconv conversion descriptor */ + struct nls_table *table; + + /* give up if no charset is given */ + if (charset == NULL) + return -1; + + /* see if we already have a table with this name - built in tables + have precedence over iconv() - i.e. can't have the name of an + existing table. Also, we may have already registered this file + table */ + if (find_nls(charset) != NULL) + return -1; + + if ((iconv_d = iconv_open("UCS-2BE", charset)) == (iconv_t) -1) + return -1; + + + /* set up the table */ + if ((table = (struct nls_table *)malloc(sizeof (struct nls_table))) + == NULL) { + return -1; + } + + /* give the table the file name, so we can find it again if needed */ + table->charset = strdup(charset); + table->iconv_d = iconv_d; + table->page_uni2charset = NULL; + table->charset2uni = NULL; + table->inc_use_count = inc_use_count; + table->dec_use_count = dec_use_count; + table->next = NULL; + + /* register the table */ + return register_nls(table); +} +#endif