]> git.pld-linux.org Git - packages/cdrtools.git/blame - cdrtools-mkisofs-iconv-10.patch
- up to 2.01.01a03; added dvd support
[packages/cdrtools.git] / cdrtools-mkisofs-iconv-10.patch
CommitLineData
b2f9b8e5
AM
1diff -urN --exclude-from=- cdrtools-2.01/include/unls.h cdrtools-2.01-jh/include/unls.h
2--- cdrtools-2.01/include/unls.h 2003-06-16 00:41:23.000000000 +0300
3+++ cdrtools-2.01-jh/include/unls.h 2004-02-02 18:31:22.000000000 +0200
4@@ -30,6 +30,10 @@
5 #include <prototyp.h>
6 #endif
7
8+#ifdef USE_ICONV
9+#include <iconv.h>
10+#endif
11+
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15@@ -43,6 +47,9 @@
16 char *charset;
17 unsigned char **page_uni2charset;
18 struct nls_unicode *charset2uni;
19+#ifdef USE_ICONV
20+ iconv_t iconv_d;
21+#endif
22
23 void (*inc_use_count) __PR((void));
24 void (*dec_use_count) __PR((void));
25@@ -58,6 +65,9 @@
26 extern void unload_nls __PR((struct nls_table *));
27 extern struct nls_table *load_nls_default __PR((void));
28 extern int init_nls_file __PR((char * name));
29+#ifdef USE_ICONV
30+extern int init_nls_iconv __PR((char * name));
31+#endif
32
33 #ifdef __cplusplus
34 }
35diff -urN --exclude-from=- cdrtools-2.01/libunls/libunls.mk cdrtools-2.01-jh/libunls/libunls.mk
36--- cdrtools-2.01/libunls/libunls.mk 2000-03-25 14:51:56.000000000 +0200
37+++ cdrtools-2.01-jh/libunls/libunls.mk 2004-02-02 18:31:22.000000000 +0200
38@@ -8,6 +8,7 @@
39 INSDIR= lib
40 TARGETLIB= unls
41 #CPPOPTS += -Istdio
42+CPPOPTS += -DUSE_ICONV
43 include Targets
44 LIBS=
45
46diff -urN --exclude-from=- cdrtools-2.01/libunls/nls.h cdrtools-2.01-jh/libunls/nls.h
47--- cdrtools-2.01/libunls/nls.h 2002-12-03 02:34:27.000000000 +0200
48+++ cdrtools-2.01-jh/libunls/nls.h 2004-02-02 18:31:22.000000000 +0200
49@@ -111,5 +111,8 @@
50 extern int init_nls_cp10079 __PR((void));
51 extern int init_nls_cp10081 __PR((void));
52 extern int init_nls_file __PR((char * name));
53+#ifdef USE_ICONV
54+extern int init_nls_iconv __PR((char * name));
55+#endif
56
57 #endif /* _NLS_H */
58diff -urN --exclude-from=- cdrtools-2.01/libunls/nls_iconv.c cdrtools-2.01-jh/libunls/nls_iconv.c
59--- cdrtools-2.01/libunls/nls_iconv.c 1970-01-01 02:00:00.000000000 +0200
60+++ cdrtools-2.01-jh/libunls/nls_iconv.c 2004-02-02 18:31:22.000000000 +0200
61@@ -0,0 +1,96 @@
62+/* @(#)nls_iconv.c 1.0 02/04/20 2002 J. Schilling */
63+#ifndef lint
64+static char sccsid[] =
65+ "@(#)nls_iconv.c 1.0 02/01/20 2002 J. Schilling";
66+#endif
67+/*
68+ * This program is free software; you can redistribute it and/or modify
69+ * it under the terms of the GNU General Public License as published by
70+ * the Free Software Foundation; either version 2, or (at your option)
71+ * any later version.
72+ *
73+ * This program is distributed in the hope that it will be useful,
74+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
75+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
76+ * GNU General Public License for more details.
77+ *
78+ * You should have received a copy of the GNU General Public License
79+ * along with this program; see the file COPYING. If not, write to
80+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
81+ */
82+/*
83+ * Modifications to make the code portable Copyright (c) 2000 J. Schilling
84+ *
85+ * nls_iconv: create a pseudo-charset table to use iconv() provided by C
86+ * library or libiconv by Bruno Haible
87+ * The Unicode to charset table has only exact mappings.
88+ *
89+ *
90+ * Jungshik Shin (jshin@mailaps.org) 04-Feb-2002
91+ */
92+
93+#ifdef USE_ICONV
94+#include <mconfig.h>
95+#include <stdio.h>
96+#include <stdxlib.h>
97+#include <strdefs.h>
98+#include "nls.h"
99+#include <iconv.h>
100+
101+static void inc_use_count __PR((void));
102+static void dec_use_count __PR((void));
103+
104+
105+static void
106+inc_use_count()
107+{
108+ MOD_INC_USE_COUNT;
109+}
110+
111+static void
112+dec_use_count()
113+{
114+ MOD_DEC_USE_COUNT;
115+}
116+
117+int
118+init_nls_iconv(charset)
119+ char *charset;
120+{
121+ iconv_t iconv_d; /* iconv conversion descriptor */
122+ struct nls_table *table;
123+
124+ /* give up if no charset is given */
125+ if (charset == NULL)
126+ return -1;
127+
128+ /* see if we already have a table with this name - built in tables
129+ have precedence over iconv() - i.e. can't have the name of an
130+ existing table. Also, we may have already registered this file
131+ table */
132+ if (find_nls(charset) != NULL)
133+ return -1;
134+
135+ if ((iconv_d = iconv_open("UCS-2BE", charset)) == (iconv_t) -1)
136+ return -1;
137+
138+
139+ /* set up the table */
140+ if ((table = (struct nls_table *)malloc(sizeof (struct nls_table)))
141+ == NULL) {
142+ return -1;
143+ }
144+
145+ /* give the table the file name, so we can find it again if needed */
146+ table->charset = strdup(charset);
147+ table->iconv_d = iconv_d;
148+ table->page_uni2charset = NULL;
149+ table->charset2uni = NULL;
150+ table->inc_use_count = inc_use_count;
151+ table->dec_use_count = dec_use_count;
152+ table->next = NULL;
153+
154+ /* register the table */
155+ return register_nls(table);
156+}
157+#endif
158diff -urN --exclude-from=- cdrtools-2.01/libunls/Targets cdrtools-2.01-jh/libunls/Targets
159--- cdrtools-2.01/libunls/Targets 2002-12-03 02:34:27.000000000 +0200
160+++ cdrtools-2.01-jh/libunls/Targets 2004-02-02 18:31:22.000000000 +0200
161@@ -39,4 +39,5 @@
162 nls_cp10029.c \
163 nls_cp10079.c \
164 nls_cp10081.c \
165- nls_file.c
166+ nls_file.c \
167+ nls_iconv.c
168diff -urN --exclude-from=- cdrtools-2.01/mkisofs/joliet.c cdrtools-2.01-jh/mkisofs/joliet.c
169--- cdrtools-2.01/mkisofs/joliet.c 2003-04-28 01:36:08.000000000 +0300
170+++ cdrtools-2.01-jh/mkisofs/joliet.c 2004-02-03 14:15:17.000000000 +0200
171@@ -90,6 +90,11 @@
172 #include <unls.h> /* For UNICODE translation */
173 #include <schily.h>
174
175+#ifdef USE_ICONV
176+#include <iconv.h>
177+#include <errno.h>
178+#endif
179+
180 static Uint jpath_table_index;
181 static struct directory **jpathlist;
182 static int next_jpath_index = 1;
183@@ -103,13 +108,23 @@
184 };
185
186 #ifdef UDF
187- void convert_to_unicode __PR((unsigned char *buffer,
188+# ifdef USE_ICONV
189+ size_t
190+# else
191+ void
192+# endif
193+ convert_to_unicode __PR((unsigned char *buffer,
194 int size, char *source, struct nls_table *inls));
195- int joliet_strlen __PR((const char *string));
196+ int joliet_strlen __PR((const char *string, struct nls_table *inls));
197 #else
198-static void convert_to_unicode __PR((unsigned char *buffer,
199+# ifdef USE_ICONV
200+ static size_t
201+# else
202+ static void
203+#endif
204+ convert_to_unicode __PR((unsigned char *buffer,
205 int size, char *source, struct nls_table *inls));
206-static int joliet_strlen __PR((const char *string));
207+static int joliet_strlen __PR((const char *string, struct nls_table *inls));
208 #endif
209 static void get_joliet_vol_desc __PR((struct iso_primary_descriptor *jvol_desc));
210 static void assign_joliet_directory_addresses __PR((struct directory *node));
211@@ -161,6 +176,20 @@
212 if (inls == onls)
213 return (c);
214
215+#ifdef USE_ICONV
216+ if(inls->charset2uni == NULL || onls->page_uni2charset == NULL) {
217+ /*
218+ * This shouldn't be reached
219+ */
220+ static BOOL iconv_warned = FALSE;
221+ if(!iconv_warned) {
222+ error("Warning: Iconv conversion not supported in conv_charset.\n");
223+ iconv_warned = TRUE;
224+ }
225+ return (c);
226+ }
227+#endif
228+
229 /* get high and low UNICODE bytes */
230 uh = inls->charset2uni[c].uni2;
231 ul = inls->charset2uni[c].uni1;
232@@ -186,10 +215,18 @@
233 *
234 * Notes:
235 */
236-#ifdef UDF
237-void
238+#ifdef USE_ICONV
239+# if UDF
240+size_t
241+# else
242+static size_t
243+# endif
244 #else
245+# if UDF
246+void
247+# else
248 static void
249+# endif
250 #endif
251 convert_to_unicode(buffer, size, source, inls)
252 unsigned char *buffer;
253@@ -216,6 +253,51 @@
254 tmpbuf = (Uchar *) source;
255 }
256
257+#ifdef USE_ICONV
258+ if (inls->iconv_d && inls->charset2uni==NULL &&
259+ inls->page_uni2charset==NULL) {
260+ char *inptr = tmpbuf;
261+ char *outptr = buffer;
262+ size_t inleft = strlen(tmpbuf);
263+ size_t inlen = inleft;
264+ size_t outleft = size;
265+
266+ iconv(inls->iconv_d, NULL, NULL, NULL, NULL);
267+ if(iconv(inls->iconv_d, &inptr, &inleft, &outptr, &outleft) ==
268+ (size_t)-1 && errno == EILSEQ) {
269+ fprintf(stderr, "Incorrectly encoded string (%s) "
270+ "encountered.\nPossibly creating an invalid "
271+ "Joliet extension. Aborting.\n", source);
272+ exit(1);
273+ }
274+
275+ for (i = 0; (i + 1) < size - outleft; i += 2) { /* Size may be odd!!!*/
276+ if (buffer[i]=='\0') {
277+ switch (buffer[i+1]) { /* Invalid characters for Joliet */
278+ case '*':
279+ case '/':
280+ case ':':
281+ case ';':
282+ case '?':
283+ case '\\':
284+ buffer[i+1]='_';
285+ default:
286+ if (buffer[i+1] == 0x7f ||
287+ buffer[i+1] < 0x20)
288+ buffer[i+1]='_';
289+ }
290+ }
291+ }
292+ if (size & 1) { /* beautification */
293+ buffer[size - 1] = 0;
294+ }
295+ if (source == NULL) {
296+ free(tmpbuf);
297+ }
298+ return (inlen - inleft);
299+ }
300+#endif
301+
302 /*
303 * Now start copying characters. If the size was specified to be 0,
304 * then assume the input was 0 terminated.
305@@ -271,6 +353,9 @@
306 if (source == NULL) {
307 free(tmpbuf);
308 }
309+#ifdef USE_ICONV
310+ return j;
311+#endif
312 }
313
314 /*
315@@ -287,12 +372,50 @@
316 #else
317 static int
318 #endif
319-joliet_strlen(string)
320+joliet_strlen(string, inls)
321 const char *string;
322+ struct nls_table *inls;
323 {
324 int rtn;
325
326+#ifdef USE_ICONV
327+ if (inls->iconv_d && inls->charset2uni==NULL &&
328+ inls->page_uni2charset==NULL) {
329+ /*
330+ * we const-cast since we're sure iconv won't change
331+ * the string itself
332+ */
333+ char *string_ptr = (char *)string;
334+ size_t string_len = strlen(string);
335+
336+ /*
337+ * iconv has no way of finding out the required size
338+ * in the target
339+ */
340+
341+ char *tmp, *tmp_ptr;
342+ /* we assume that the maximum length is 2 * jlen */
343+ size_t tmp_len = (size_t)jlen * 2 + 1;
344+ tmp = e_malloc(tmp_len);
345+ tmp_ptr = tmp;
346+
347+ iconv(inls->iconv_d, NULL, NULL, NULL, NULL);
348+ iconv(inls->iconv_d, &string_ptr, &string_len, &tmp_ptr,
349+ &tmp_len);
350+
351+ /*
352+ * iconv advanced the tmp pointer with as many chars
353+ * as it has written to it, so we add up the delta
354+ */
355+ rtn = (tmp_ptr - tmp);
356+
357+ free(tmp);
358+ } else {
359+ rtn = strlen(string) << 1;
360+ }
361+#else
362 rtn = strlen(string) << 1;
363+#endif
364
365 /*
366 * We do clamp the maximum length of a Joliet string to be the
367@@ -480,16 +603,33 @@
368 /* compare the Unicode names */
369
370 while (*rpnt && *lpnt) {
371+#ifdef USE_ICONV
372+ size_t ri, li;
373+
374+ ri = convert_to_unicode(rtmp, 2, rpnt, rinls);
375+ li = convert_to_unicode(ltmp, 2, lpnt, linls);
376+ rpnt += ri;
377+ lpnt += li;
378+ if(!ri && !li)
379+ return (0);
380+ else if(ri && !li)
381+ return (1);
382+ else if(!ri && li)
383+ return (-1);
384+#else
385 convert_to_unicode(rtmp, 2, rpnt, rinls);
386 convert_to_unicode(ltmp, 2, lpnt, linls);
387+#endif
388
389 if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp))
390 return (-1);
391 if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp))
392 return (1);
393
394+#ifndef USE_ICONV
395 rpnt++;
396 lpnt++;
397+#endif
398 }
399
400 if (*rpnt)
401@@ -574,10 +714,10 @@
402 }
403 #ifdef APPLE_HYB
404 if (USE_MAC_NAME(de))
405- namelen = joliet_strlen(de->hfs_ent->name);
406+ namelen = joliet_strlen(de->hfs_ent->name, hfs_inls);
407 else
408 #endif /* APPLE_HYB */
409- namelen = joliet_strlen(de->name);
410+ namelen = joliet_strlen(de->name, in_nls);
411
412 if (dpnt == root) {
413 jpath_table_l[jpath_table_index] = 1;
414@@ -742,10 +882,10 @@
415 #ifdef APPLE_HYB
416 /* Use the HFS name if it exists */
417 if (USE_MAC_NAME(s_entry1))
418- cvt_len = joliet_strlen(s_entry1->hfs_ent->name);
419+ cvt_len = joliet_strlen(s_entry1->hfs_ent->name, hfs_inls);
420 else
421 #endif /* APPLE_HYB */
422- cvt_len = joliet_strlen(s_entry1->name);
423+ cvt_len = joliet_strlen(s_entry1->name, in_nls);
424
425 /*
426 * Fix the record length
427@@ -891,12 +1031,12 @@
428 if (USE_MAC_NAME(s_entry))
429 /* Use the HFS name if it exists */
430 jpath_table_size +=
431- joliet_strlen(s_entry->hfs_ent->name) +
432+ joliet_strlen(s_entry->hfs_ent->name, hfs_inls) +
433 offsetof(struct iso_path_table, name[0]);
434 else
435 #endif /* APPLE_HYB */
436 jpath_table_size +=
437- joliet_strlen(s_entry->name) +
438+ joliet_strlen(s_entry->name, in_nls) +
439 offsetof(struct iso_path_table, name[0]);
440 if (jpath_table_size & 1) {
441 jpath_table_size++;
442@@ -918,13 +1058,13 @@
443 /* Use the HFS name if it exists */
444 s_entry->jreclen =
445 offsetof(struct iso_directory_record, name[0])
446- + joliet_strlen(s_entry->hfs_ent->name)
447+ + joliet_strlen(s_entry->hfs_ent->name, hfs_inls)
448 + 1;
449 else
450 #endif /* APPLE_HYB */
451 s_entry->jreclen =
452 offsetof(struct iso_directory_record, name[0])
453- + joliet_strlen(s_entry->name)
454+ + joliet_strlen(s_entry->name, in_nls)
455 + 1;
456 } else {
457 /*
458@@ -1072,6 +1212,9 @@
459 #endif
460
461 while (*rpnt && *lpnt) {
462+#ifdef USE_ICONV
463+ size_t ri, li;
464+#endif
465 if (*rpnt == ';' && *lpnt != ';')
466 return (-1);
467 if (*rpnt != ';' && *lpnt == ';')
468@@ -1092,16 +1235,32 @@
469 return (1);
470 #endif
471
472+#ifdef USE_ICONV
473+
474+ ri = convert_to_unicode(rtmp, 2, rpnt, rinls);
475+ li = convert_to_unicode(ltmp, 2, lpnt, linls);
476+ rpnt += ri;
477+ lpnt += li;
478+ if(!ri && !li)
479+ return (0);
480+ else if(ri && !li)
481+ return (1);
482+ else if(!ri && li)
483+ return (-1);
484+#else
485 convert_to_unicode(rtmp, 2, rpnt, rinls);
486 convert_to_unicode(ltmp, 2, lpnt, linls);
487+#endif
488
489 if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp))
490 return (-1);
491 if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp))
492 return (1);
493
494+#ifndef USE_ICONV
495 rpnt++;
496 lpnt++;
497+#endif
498 }
499 if (*rpnt)
500 return (1);
501diff -urN --exclude-from=- cdrtools-2.01/mkisofs/Makefile cdrtools-2.01-jh/mkisofs/Makefile
502--- cdrtools-2.01/mkisofs/Makefile 2004-01-02 17:23:32.000000000 +0200
503+++ cdrtools-2.01-jh/mkisofs/Makefile 2004-02-02 18:31:22.000000000 +0200
504@@ -32,6 +32,7 @@
505 CPPOPTS += -DUDF
506 CPPOPTS += -DDVD_VIDEO
507 CPPOPTS += -DSORTING
508+CPPOPTS += -DUSE_ICONV
509 CPPOPTS += -I../libhfs_iso/
510 CPPOPTS += -DHAVE_CONFIG_H -DUSE_LIBSCHILY -DUSE_SCG \
511 '-DAPPID_DEFAULT="MKISOFS ISO 9660/HFS FILESYSTEM BUILDER & CDRECORD CD-R/DVD CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING"' \
512diff -urN --exclude-from=- cdrtools-2.01/mkisofs/mkisofs.c cdrtools-2.01-jh/mkisofs/mkisofs.c
513--- cdrtools-2.01/mkisofs/mkisofs.c 2004-01-07 01:23:46.000000000 +0200
514+++ cdrtools-2.01-jh/mkisofs/mkisofs.c 2004-02-02 18:31:22.000000000 +0200
515@@ -59,6 +59,11 @@
516 #endif
517 #endif /* no_more_needed */
518
519+#ifdef USE_ICONV
520+#include <locale.h>
521+#include <langinfo.h>
522+#endif
523+
524 struct directory *root = NULL;
525 int path_ind;
526
527@@ -223,6 +228,10 @@
528 int do_sort = 0; /* sort file data */
529 #endif /* SORTING */
530
531+#ifdef USE_ICONV
532+int iconv_possible;
533+#endif
534+
535 struct nls_table *in_nls = NULL; /* input UNICODE conversion table */
536 struct nls_table *out_nls = NULL; /* output UNICODE conversion table */
537 #ifdef APPLE_HYB
538@@ -2235,6 +2244,37 @@
539 init_nls_file(hfs_ocharset);
540 #endif /* APPLE_HYB */
541
542+#ifdef USE_ICONV
543+ iconv_possible = !(iso9660_level >= 4 || ((ocharset &&
544+ strcmp(ocharset, icharset ? icharset : "")) &&
545+ use_RockRidge) || apple_ext || apple_hyb);
546+
547+ setlocale(LC_CTYPE, "");
548+
549+ if (icharset == NULL && iconv_possible) {
550+ char *charset = nl_langinfo(CODESET);
551+ /* set to detected value but only if it is not pure US-ASCII */
552+ if(strcmp(charset, "ANSI_X3.4-1968") != 0)
553+ icharset = charset;
554+
555+ if(icharset && verbose > 0)
556+ fprintf(stderr, "INFO:\t"
557+ "%s character encoding detected by locale settings."
558+ "\n\tAssuming %s encoded filenames on source "
559+ "filesystem,\n"
560+ "\tuse -input-charset to override.\n",
561+ icharset, icharset);
562+ }
563+
564+ if(iconv_possible) {
565+ /*
566+ * don't care if initialization fails
567+ */
568+ init_nls_iconv(icharset);
569+ init_nls_iconv(ocharset);
570+ }
571+#endif
572+
573 if (icharset == NULL) {
574 #if (defined(__CYGWIN32__) || defined(__CYGWIN__)) && !defined(IS_CYGWIN_1)
575 in_nls = load_nls("cp437");
576@@ -2262,6 +2302,12 @@
577 if (in_nls == NULL || out_nls == NULL) { /* Unknown charset specified */
578 fprintf(stderr, "Unknown charset\nKnown charsets are:\n");
579 list_nls(); /* List all known charset names */
580+#ifdef USE_ICONV
581+ if(!iconv_possible)
582+ fprintf(stderr, "Iconv charsets cannot be used with "
583+ "Apple extension, HFS, ISO9660 version 2 or\n"
584+ "Rock Ridge.\n");
585+#endif
586 exit(1);
587 }
588
589diff -urN --exclude-from=- cdrtools-2.01/mkisofs/mkisofs.h cdrtools-2.01-jh/mkisofs/mkisofs.h
590--- cdrtools-2.01/mkisofs/mkisofs.h 2003-12-28 15:38:51.000000000 +0200
591+++ cdrtools-2.01-jh/mkisofs/mkisofs.h 2004-02-02 18:31:22.000000000 +0200
592@@ -501,9 +501,14 @@
593
594 /* joliet.c */
595 #ifdef UDF
596+# ifdef USE_ICONV
597+extern size_t convert_to_unicode __PR((unsigned char *buffer,
598+ int size, char *source, struct nls_table *inls));
599+# else
600 extern void convert_to_unicode __PR((unsigned char *buffer,
601 int size, char *source, struct nls_table *inls));
602-extern int joliet_strlen __PR((const char *string));
603+# endif
604+extern int joliet_strlen __PR((const char *string, struct nls_table *inls));
605 #endif
606 extern unsigned char conv_charset __PR((unsigned char, struct nls_table *,
607 struct nls_table *));
608diff -urN --exclude-from=- cdrtools-2.01/mkisofs/udf.c cdrtools-2.01-jh/mkisofs/udf.c
609--- cdrtools-2.01/mkisofs/udf.c 2003-04-28 01:34:52.000000000 +0300
610+++ cdrtools-2.01-jh/mkisofs/udf.c 2004-02-02 18:31:22.000000000 +0200
611@@ -442,7 +442,7 @@
612 int i;
613 int expanded_length;
614
615- expanded_length = joliet_strlen(src);
616+ expanded_length = joliet_strlen(src, in_nls);
617 if (expanded_length > 1024)
618 expanded_length = 1024;
619 if (expanded_length > (dst_size-1)*2)
This page took 0.147107 seconds and 4 git commands to generate.