1 Submitted By: Alexander E. Patrakov
3 Initial Package Version: 2.01
4 Origin: RedHat (but maybe they initially obtained the patch from elsewhere)
5 Upstream Status: Not applied
6 Description: Allows one to specify any glibc-supported source charset
7 for Joliet filenames, instead of the very limited choice offered by mkisofs
8 itself. Required for writing Windows-readable data CDs in UTF-8 locales when
9 filenames contain national characters.
11 diff -urN --exclude-from=- cdrtools-2.01/include/unls.h cdrtools-2.01-jh/include/unls.h
12 --- cdrtools-2.01/include/unls.h 2003-06-16 00:41:23.000000000 +0300
13 +++ cdrtools-2.01-jh/include/unls.h 2004-02-02 18:31:22.000000000 +0200
27 unsigned char **page_uni2charset;
28 struct nls_unicode *charset2uni;
33 void (*inc_use_count) __PR((void));
34 void (*dec_use_count) __PR((void));
36 extern void unload_nls __PR((struct nls_table *));
37 extern struct nls_table *load_nls_default __PR((void));
38 extern int init_nls_file __PR((char * name));
40 +extern int init_nls_iconv __PR((char * name));
45 diff -urN --exclude-from=- cdrtools-2.01/libunls/libunls.mk cdrtools-2.01-jh/libunls/libunls.mk
46 --- cdrtools-2.01/libunls/libunls.mk 2000-03-25 14:51:56.000000000 +0200
47 +++ cdrtools-2.01-jh/libunls/libunls.mk 2004-02-02 18:31:22.000000000 +0200
52 +CPPOPTS += -DUSE_ICONV
56 diff -urN --exclude-from=- cdrtools-2.01/libunls/nls.h cdrtools-2.01-jh/libunls/nls.h
57 --- cdrtools-2.01/libunls/nls.h 2002-12-03 02:34:27.000000000 +0200
58 +++ cdrtools-2.01-jh/libunls/nls.h 2004-02-02 18:31:22.000000000 +0200
60 extern int init_nls_cp10079 __PR((void));
61 extern int init_nls_cp10081 __PR((void));
62 extern int init_nls_file __PR((char * name));
64 +extern int init_nls_iconv __PR((char * name));
68 diff -urN --exclude-from=- cdrtools-2.01/libunls/nls_iconv.c cdrtools-2.01-jh/libunls/nls_iconv.c
69 --- cdrtools-2.01/libunls/nls_iconv.c 1970-01-01 02:00:00.000000000 +0200
70 +++ cdrtools-2.01-jh/libunls/nls_iconv.c 2004-02-02 18:31:22.000000000 +0200
72 +/* @(#)nls_iconv.c 1.0 02/04/20 2002 J. Schilling */
74 +static char sccsid[] =
75 + "@(#)nls_iconv.c 1.0 02/01/20 2002 J. Schilling";
78 + * This program is free software; you can redistribute it and/or modify
79 + * it under the terms of the GNU General Public License as published by
80 + * the Free Software Foundation; either version 2, or (at your option)
81 + * any later version.
83 + * This program is distributed in the hope that it will be useful,
84 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
85 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86 + * GNU General Public License for more details.
88 + * You should have received a copy of the GNU General Public License
89 + * along with this program; see the file COPYING. If not, write to
90 + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
93 + * Modifications to make the code portable Copyright (c) 2000 J. Schilling
95 + * nls_iconv: create a pseudo-charset table to use iconv() provided by C
96 + * library or libiconv by Bruno Haible
97 + * The Unicode to charset table has only exact mappings.
100 + * Jungshik Shin (jshin@mailaps.org) 04-Feb-2002
104 +#include <mconfig.h>
106 +#include <stdxlib.h>
107 +#include <strdefs.h>
111 +static void inc_use_count __PR((void));
112 +static void dec_use_count __PR((void));
128 +init_nls_iconv(charset)
131 + iconv_t iconv_d; /* iconv conversion descriptor */
132 + struct nls_table *table;
134 + /* give up if no charset is given */
135 + if (charset == NULL)
138 + /* see if we already have a table with this name - built in tables
139 + have precedence over iconv() - i.e. can't have the name of an
140 + existing table. Also, we may have already registered this file
142 + if (find_nls(charset) != NULL)
145 + if ((iconv_d = iconv_open("UCS-2BE", charset)) == (iconv_t) -1)
149 + /* set up the table */
150 + if ((table = (struct nls_table *)malloc(sizeof (struct nls_table)))
155 + /* give the table the file name, so we can find it again if needed */
156 + table->charset = strdup(charset);
157 + table->iconv_d = iconv_d;
158 + table->page_uni2charset = NULL;
159 + table->charset2uni = NULL;
160 + table->inc_use_count = inc_use_count;
161 + table->dec_use_count = dec_use_count;
162 + table->next = NULL;
164 + /* register the table */
165 + return register_nls(table);
168 diff -urN --exclude-from=- cdrtools-2.01/libunls/Targets cdrtools-2.01-jh/libunls/Targets
169 --- cdrtools-2.01/libunls/Targets 2002-12-03 02:34:27.000000000 +0200
170 +++ cdrtools-2.01-jh/libunls/Targets 2004-02-02 18:31:22.000000000 +0200
178 diff -urN --exclude-from=- cdrtools-2.01/mkisofs/joliet.c cdrtools-2.01-jh/mkisofs/joliet.c
179 --- cdrtools-2.01/mkisofs/joliet.c 2003-04-28 01:36:08.000000000 +0300
180 +++ cdrtools-2.01-jh/mkisofs/joliet.c 2004-02-03 14:15:17.000000000 +0200
182 #include <unls.h> /* For UNICODE translation */
190 static Uint jpath_table_index;
191 static struct directory **jpathlist;
192 static int next_jpath_index = 1;
193 @@ -103,13 +108,23 @@
197 - void convert_to_unicode __PR((unsigned char *buffer,
203 + convert_to_unicode __PR((unsigned char *buffer,
204 int size, char *source, struct nls_table *inls));
205 - int joliet_strlen __PR((const char *string));
206 + int joliet_strlen __PR((const char *string, struct nls_table *inls));
208 -static void convert_to_unicode __PR((unsigned char *buffer,
214 + convert_to_unicode __PR((unsigned char *buffer,
215 int size, char *source, struct nls_table *inls));
216 -static int joliet_strlen __PR((const char *string));
217 +static int joliet_strlen __PR((const char *string, struct nls_table *inls));
219 static void get_joliet_vol_desc __PR((struct iso_primary_descriptor *jvol_desc));
220 static void assign_joliet_directory_addresses __PR((struct directory *node));
226 + if(inls->charset2uni == NULL || onls->page_uni2charset == NULL) {
228 + * This shouldn't be reached
230 + static BOOL iconv_warned = FALSE;
231 + if(!iconv_warned) {
232 + error("Warning: Iconv conversion not supported in conv_charset.\n");
233 + iconv_warned = TRUE;
239 /* get high and low UNICODE bytes */
240 uh = inls->charset2uni[c].uni2;
241 ul = inls->charset2uni[c].uni1;
242 @@ -186,10 +215,18 @@
261 convert_to_unicode(buffer, size, source, inls)
262 unsigned char *buffer;
264 tmpbuf = (Uchar *) source;
268 + if (inls->iconv_d && inls->charset2uni==NULL &&
269 + inls->page_uni2charset==NULL) {
270 + char *inptr = tmpbuf;
271 + char *outptr = buffer;
272 + size_t inleft = strlen(tmpbuf);
273 + size_t inlen = inleft;
274 + size_t outleft = size;
276 + iconv(inls->iconv_d, NULL, NULL, NULL, NULL);
277 + if(iconv(inls->iconv_d, &inptr, &inleft, &outptr, &outleft) ==
278 + (size_t)-1 && errno == EILSEQ) {
279 + fprintf(stderr, "Incorrectly encoded string (%s) "
280 + "encountered.\nPossibly creating an invalid "
281 + "Joliet extension. Aborting.\n", source);
285 + for (i = 0; (i + 1) < size - outleft; i += 2) { /* Size may be odd!!!*/
286 + if (buffer[i]=='\0') {
287 + switch (buffer[i+1]) { /* Invalid characters for Joliet */
296 + if (buffer[i+1] == 0x7f ||
297 + buffer[i+1] < 0x20)
302 + if (size & 1) { /* beautification */
303 + buffer[size - 1] = 0;
305 + if (source == NULL) {
308 + return (inlen - inleft);
313 * Now start copying characters. If the size was specified to be 0,
314 * then assume the input was 0 terminated.
316 if (source == NULL) {
325 @@ -287,12 +372,50 @@
329 -joliet_strlen(string)
330 +joliet_strlen(string, inls)
332 + struct nls_table *inls;
337 + if (inls->iconv_d && inls->charset2uni==NULL &&
338 + inls->page_uni2charset==NULL) {
340 + * we const-cast since we're sure iconv won't change
341 + * the string itself
343 + char *string_ptr = (char *)string;
344 + size_t string_len = strlen(string);
347 + * iconv has no way of finding out the required size
351 + char *tmp, *tmp_ptr;
352 + /* we assume that the maximum length is 2 * jlen */
353 + size_t tmp_len = (size_t)jlen * 2 + 1;
354 + tmp = e_malloc(tmp_len);
357 + iconv(inls->iconv_d, NULL, NULL, NULL, NULL);
358 + iconv(inls->iconv_d, &string_ptr, &string_len, &tmp_ptr,
362 + * iconv advanced the tmp pointer with as many chars
363 + * as it has written to it, so we add up the delta
365 + rtn = (tmp_ptr - tmp);
369 + rtn = strlen(string) << 1;
372 rtn = strlen(string) << 1;
376 * We do clamp the maximum length of a Joliet string to be the
377 @@ -480,16 +603,33 @@
378 /* compare the Unicode names */
380 while (*rpnt && *lpnt) {
384 + ri = convert_to_unicode(rtmp, 2, rpnt, rinls);
385 + li = convert_to_unicode(ltmp, 2, lpnt, linls);
395 convert_to_unicode(rtmp, 2, rpnt, rinls);
396 convert_to_unicode(ltmp, 2, lpnt, linls);
399 if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp))
401 if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp))
411 @@ -574,10 +714,10 @@
414 if (USE_MAC_NAME(de))
415 - namelen = joliet_strlen(de->hfs_ent->name);
416 + namelen = joliet_strlen(de->hfs_ent->name, hfs_inls);
418 #endif /* APPLE_HYB */
419 - namelen = joliet_strlen(de->name);
420 + namelen = joliet_strlen(de->name, in_nls);
423 jpath_table_l[jpath_table_index] = 1;
424 @@ -742,10 +882,10 @@
426 /* Use the HFS name if it exists */
427 if (USE_MAC_NAME(s_entry1))
428 - cvt_len = joliet_strlen(s_entry1->hfs_ent->name);
429 + cvt_len = joliet_strlen(s_entry1->hfs_ent->name, hfs_inls);
431 #endif /* APPLE_HYB */
432 - cvt_len = joliet_strlen(s_entry1->name);
433 + cvt_len = joliet_strlen(s_entry1->name, in_nls);
436 * Fix the record length
437 @@ -891,12 +1031,12 @@
438 if (USE_MAC_NAME(s_entry))
439 /* Use the HFS name if it exists */
441 - joliet_strlen(s_entry->hfs_ent->name) +
442 + joliet_strlen(s_entry->hfs_ent->name, hfs_inls) +
443 offsetof(struct iso_path_table, name[0]);
445 #endif /* APPLE_HYB */
447 - joliet_strlen(s_entry->name) +
448 + joliet_strlen(s_entry->name, in_nls) +
449 offsetof(struct iso_path_table, name[0]);
450 if (jpath_table_size & 1) {
452 @@ -918,13 +1058,13 @@
453 /* Use the HFS name if it exists */
455 offsetof(struct iso_directory_record, name[0])
456 - + joliet_strlen(s_entry->hfs_ent->name)
457 + + joliet_strlen(s_entry->hfs_ent->name, hfs_inls)
460 #endif /* APPLE_HYB */
462 offsetof(struct iso_directory_record, name[0])
463 - + joliet_strlen(s_entry->name)
464 + + joliet_strlen(s_entry->name, in_nls)
468 @@ -1072,6 +1212,9 @@
471 while (*rpnt && *lpnt) {
475 if (*rpnt == ';' && *lpnt != ';')
477 if (*rpnt != ';' && *lpnt == ';')
478 @@ -1092,16 +1235,32 @@
484 + ri = convert_to_unicode(rtmp, 2, rpnt, rinls);
485 + li = convert_to_unicode(ltmp, 2, lpnt, linls);
495 convert_to_unicode(rtmp, 2, rpnt, rinls);
496 convert_to_unicode(ltmp, 2, lpnt, linls);
499 if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp))
501 if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp))
511 diff -urN --exclude-from=- cdrtools-2.01/mkisofs/Makefile cdrtools-2.01-jh/mkisofs/Makefile
512 --- cdrtools-2.01/mkisofs/Makefile 2004-01-02 17:23:32.000000000 +0200
513 +++ cdrtools-2.01-jh/mkisofs/Makefile 2004-02-02 18:31:22.000000000 +0200
516 CPPOPTS += -DDVD_VIDEO
518 +CPPOPTS += -DUSE_ICONV
519 CPPOPTS += -I../libhfs_iso/
520 CPPOPTS += -DHAVE_CONFIG_H -DUSE_LIBSCHILY -DUSE_SCG \
521 '-DAPPID_DEFAULT="MKISOFS ISO 9660/HFS FILESYSTEM BUILDER & CDRECORD CD-R/DVD CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING"' \
522 diff -urN --exclude-from=- cdrtools-2.01/mkisofs/mkisofs.c cdrtools-2.01-jh/mkisofs/mkisofs.c
523 --- cdrtools-2.01/mkisofs/mkisofs.c 2004-01-07 01:23:46.000000000 +0200
524 +++ cdrtools-2.01-jh/mkisofs/mkisofs.c 2004-02-02 18:31:22.000000000 +0200
527 #endif /* no_more_needed */
531 +#include <langinfo.h>
534 struct directory *root = NULL;
538 int do_sort = 0; /* sort file data */
545 struct nls_table *in_nls = NULL; /* input UNICODE conversion table */
546 struct nls_table *out_nls = NULL; /* output UNICODE conversion table */
548 @@ -2235,6 +2244,37 @@
549 init_nls_file(hfs_ocharset);
550 #endif /* APPLE_HYB */
553 + iconv_possible = !(iso9660_level >= 4 || ((ocharset &&
554 + strcmp(ocharset, icharset ? icharset : "")) &&
555 + use_RockRidge) || apple_ext || apple_hyb);
557 + setlocale(LC_CTYPE, "");
559 + if (icharset == NULL && iconv_possible) {
560 + char *charset = nl_langinfo(CODESET);
561 + /* set to detected value but only if it is not pure US-ASCII */
562 + if(strcmp(charset, "ANSI_X3.4-1968") != 0)
563 + icharset = charset;
565 + if(icharset && verbose > 0)
566 + fprintf(stderr, "INFO:\t"
567 + "%s character encoding detected by locale settings."
568 + "\n\tAssuming %s encoded filenames on source "
570 + "\tuse -input-charset to override.\n",
571 + icharset, icharset);
574 + if(iconv_possible) {
576 + * don't care if initialization fails
578 + init_nls_iconv(icharset);
579 + init_nls_iconv(ocharset);
583 if (icharset == NULL) {
584 #if (defined(__CYGWIN32__) || defined(__CYGWIN__)) && !defined(IS_CYGWIN_1)
585 in_nls = load_nls("cp437");
586 @@ -2262,6 +2302,12 @@
587 if (in_nls == NULL || out_nls == NULL) { /* Unknown charset specified */
588 fprintf(stderr, "Unknown charset\nKnown charsets are:\n");
589 list_nls(); /* List all known charset names */
591 + if(!iconv_possible)
592 + fprintf(stderr, "Iconv charsets cannot be used with "
593 + "Apple extension, HFS, ISO9660 version 2 or\n"
599 diff -urN --exclude-from=- cdrtools-2.01/mkisofs/mkisofs.h cdrtools-2.01-jh/mkisofs/mkisofs.h
600 --- cdrtools-2.01/mkisofs/mkisofs.h 2003-12-28 15:38:51.000000000 +0200
601 +++ cdrtools-2.01-jh/mkisofs/mkisofs.h 2004-02-02 18:31:22.000000000 +0200
607 +extern size_t convert_to_unicode __PR((unsigned char *buffer,
608 + int size, char *source, struct nls_table *inls));
610 extern void convert_to_unicode __PR((unsigned char *buffer,
611 int size, char *source, struct nls_table *inls));
612 -extern int joliet_strlen __PR((const char *string));
614 +extern int joliet_strlen __PR((const char *string, struct nls_table *inls));
616 extern unsigned char conv_charset __PR((unsigned char, struct nls_table *,
617 struct nls_table *));
618 diff -urN --exclude-from=- cdrtools-2.01/mkisofs/udf.c cdrtools-2.01-jh/mkisofs/udf.c
619 --- cdrtools-2.01/mkisofs/udf.c 2003-04-28 01:34:52.000000000 +0300
620 +++ cdrtools-2.01-jh/mkisofs/udf.c 2004-02-02 18:31:22.000000000 +0200
625 - expanded_length = joliet_strlen(src);
626 + expanded_length = joliet_strlen(src, in_nls);
627 if (expanded_length > 1024)
628 expanded_length = 1024;
629 if (expanded_length > (dst_size-1)*2)