Lines 90-95
Link Here
|
90 |
#include <schily/unls.h> /* For UNICODE translation */ |
90 |
#include <schily/unls.h> /* For UNICODE translation */ |
91 |
#include <schily/schily.h> |
91 |
#include <schily/schily.h> |
92 |
|
92 |
|
|
|
93 |
#ifdef USE_ICONV |
94 |
#include <iconv.h> |
95 |
#include <errno.h> |
96 |
#endif |
97 |
|
93 |
static Uint jpath_table_index; |
98 |
static Uint jpath_table_index; |
94 |
static struct directory **jpathlist; |
99 |
static struct directory **jpathlist; |
95 |
static int next_jpath_index = 1; |
100 |
static int next_jpath_index = 1; |
Lines 103-115
Link Here
|
103 |
}; |
108 |
}; |
104 |
|
109 |
|
105 |
#ifdef UDF |
110 |
#ifdef UDF |
106 |
void convert_to_unicode __PR((unsigned char *buffer, |
111 |
# ifdef USE_ICONV |
|
|
112 |
size_t |
113 |
# else |
114 |
void |
115 |
# endif |
116 |
convert_to_unicode __PR((unsigned char *buffer, |
107 |
int size, char *source, struct unls_table *inls)); |
117 |
int size, char *source, struct unls_table *inls)); |
108 |
int joliet_strlen __PR((const char *string)); |
118 |
int joliet_strlen __PR((const char *string, struct unls_table *inls)); |
109 |
#else |
119 |
#else |
110 |
static void convert_to_unicode __PR((unsigned char *buffer, |
120 |
# ifdef USE_ICONV |
|
|
121 |
static size_t |
122 |
# else |
123 |
static void |
124 |
#endif |
125 |
convert_to_unicode __PR((unsigned char *buffer, |
111 |
int size, char *source, struct unls_table *inls)); |
126 |
int size, char *source, struct unls_table *inls)); |
112 |
static int joliet_strlen __PR((const char *string)); |
127 |
static int joliet_strlen __PR((const char *string, struct unls_table *inls)); |
113 |
#endif |
128 |
#endif |
114 |
static void get_joliet_vol_desc __PR((struct iso_primary_descriptor *jvol_desc)); |
129 |
static void get_joliet_vol_desc __PR((struct iso_primary_descriptor *jvol_desc)); |
115 |
static void assign_joliet_directory_addresses __PR((struct directory *node)); |
130 |
static void assign_joliet_directory_addresses __PR((struct directory *node)); |
Lines 161-166
Link Here
|
161 |
if (inls == onls) |
176 |
if (inls == onls) |
162 |
return (c); |
177 |
return (c); |
163 |
|
178 |
|
|
|
179 |
#ifdef USE_ICONV |
180 |
if(inls->unls_cs2uni == NULL || onls->unls_uni2cs == NULL) { |
181 |
/* |
182 |
* This shouldn't be reached |
183 |
*/ |
184 |
static BOOL iconv_warned = FALSE; |
185 |
if(!iconv_warned) { |
186 |
error("Warning: Iconv conversion not supported in conv_charset.\n"); |
187 |
iconv_warned = TRUE; |
188 |
} |
189 |
return (c); |
190 |
} |
191 |
#endif |
192 |
|
164 |
/* get high and low UNICODE bytes */ |
193 |
/* get high and low UNICODE bytes */ |
165 |
uh = inls->unls_cs2uni[c].unls_high; |
194 |
uh = inls->unls_cs2uni[c].unls_high; |
166 |
ul = inls->unls_cs2uni[c].unls_low; |
195 |
ul = inls->unls_cs2uni[c].unls_low; |
Lines 186-195
Link Here
|
186 |
* |
215 |
* |
187 |
* Notes: |
216 |
* Notes: |
188 |
*/ |
217 |
*/ |
189 |
#ifdef UDF |
218 |
#ifdef USE_ICONV |
190 |
void |
219 |
# if UDF |
|
|
220 |
size_t |
221 |
# else |
222 |
static size_t |
223 |
# endif |
191 |
#else |
224 |
#else |
|
|
225 |
# if UDF |
226 |
void |
227 |
# else |
192 |
static void |
228 |
static void |
|
|
229 |
# endif |
193 |
#endif |
230 |
#endif |
194 |
convert_to_unicode(buffer, size, source, inls) |
231 |
convert_to_unicode(buffer, size, source, inls) |
195 |
unsigned char *buffer; |
232 |
unsigned char *buffer; |
Lines 216-221
Link Here
|
216 |
tmpbuf = (Uchar *) source; |
253 |
tmpbuf = (Uchar *) source; |
217 |
} |
254 |
} |
218 |
|
255 |
|
|
|
256 |
#ifdef USE_ICONV |
257 |
if (inls->iconv_d && inls->unls_cs2uni==NULL && |
258 |
inls->unls_uni2cs==NULL) { |
259 |
char *inptr = tmpbuf; |
260 |
char *outptr = buffer; |
261 |
size_t inleft = strlen(tmpbuf); |
262 |
size_t inlen = inleft; |
263 |
size_t outleft = size; |
264 |
|
265 |
iconv(inls->iconv_d, NULL, NULL, NULL, NULL); |
266 |
if(iconv(inls->iconv_d, &inptr, &inleft, &outptr, &outleft) == |
267 |
(size_t)-1 && errno == EILSEQ) { |
268 |
fprintf(stderr, "Incorrectly encoded string (%s) " |
269 |
"encountered.\nPossibly creating an invalid " |
270 |
"Joliet extension. Aborting.\n", source); |
271 |
exit(1); |
272 |
} |
273 |
|
274 |
for (i = 0; (i + 1) < size - outleft; i += 2) { /* Size may be odd!!!*/ |
275 |
if (buffer[i]=='\0') { |
276 |
switch (buffer[i+1]) { /* Invalid characters for Joliet */ |
277 |
case '*': |
278 |
case '/': |
279 |
case ':': |
280 |
case ';': |
281 |
case '?': |
282 |
case '\\': |
283 |
buffer[i+1]='_'; |
284 |
default: |
285 |
if (buffer[i+1] == 0x7f || |
286 |
buffer[i+1] < 0x20) |
287 |
buffer[i+1]='_'; |
288 |
} |
289 |
} |
290 |
} |
291 |
if (size & 1) { /* beautification */ |
292 |
buffer[size - 1] = 0; |
293 |
} |
294 |
if (source == NULL) { |
295 |
free(tmpbuf); |
296 |
} |
297 |
return (inlen - inleft); |
298 |
} |
299 |
#endif |
300 |
|
219 |
/* |
301 |
/* |
220 |
* Now start copying characters. If the size was specified to be 0, |
302 |
* Now start copying characters. If the size was specified to be 0, |
221 |
* then assume the input was 0 terminated. |
303 |
* then assume the input was 0 terminated. |
Lines 271-276
Link Here
|
271 |
if (source == NULL) { |
353 |
if (source == NULL) { |
272 |
free(tmpbuf); |
354 |
free(tmpbuf); |
273 |
} |
355 |
} |
|
|
356 |
#ifdef USE_ICONV |
357 |
return j; |
358 |
#endif |
274 |
} |
359 |
} |
275 |
|
360 |
|
276 |
/* |
361 |
/* |
Lines 287-298
Link Here
|
287 |
#else |
372 |
#else |
288 |
static int |
373 |
static int |
289 |
#endif |
374 |
#endif |
290 |
joliet_strlen(string) |
375 |
joliet_strlen(string, inls) |
291 |
const char *string; |
376 |
const char *string; |
|
|
377 |
struct unls_table *inls; |
292 |
{ |
378 |
{ |
293 |
int rtn; |
379 |
int rtn; |
294 |
|
380 |
|
|
|
381 |
#ifdef USE_ICONV |
382 |
if (inls->iconv_d && inls->unls_cs2uni==NULL && |
383 |
inls->unls_uni2cs==NULL) { |
384 |
/* |
385 |
* we const-cast since we're sure iconv won't change |
386 |
* the string itself |
387 |
*/ |
388 |
char *string_ptr = (char *)string; |
389 |
size_t string_len = strlen(string); |
390 |
|
391 |
/* |
392 |
* iconv has no way of finding out the required size |
393 |
* in the target |
394 |
*/ |
395 |
|
396 |
char *tmp, *tmp_ptr; |
397 |
/* we assume that the maximum length is 2 * jlen */ |
398 |
size_t tmp_len = (size_t)jlen * 2 + 1; |
399 |
tmp = e_malloc(tmp_len); |
400 |
tmp_ptr = tmp; |
401 |
|
402 |
iconv(inls->iconv_d, NULL, NULL, NULL, NULL); |
403 |
iconv(inls->iconv_d, &string_ptr, &string_len, &tmp_ptr, |
404 |
&tmp_len); |
405 |
|
406 |
/* |
407 |
* iconv advanced the tmp pointer with as many chars |
408 |
* as it has written to it, so we add up the delta |
409 |
*/ |
410 |
rtn = (tmp_ptr - tmp); |
411 |
|
412 |
free(tmp); |
413 |
} else { |
414 |
rtn = strlen(string) << 1; |
415 |
} |
416 |
#else |
295 |
rtn = strlen(string) << 1; |
417 |
rtn = strlen(string) << 1; |
|
|
418 |
#endif |
296 |
|
419 |
|
297 |
/* |
420 |
/* |
298 |
* We do clamp the maximum length of a Joliet string to be the |
421 |
* We do clamp the maximum length of a Joliet string to be the |
Lines 481-496
Link Here
|
481 |
/* compare the Unicode names */ |
604 |
/* compare the Unicode names */ |
482 |
|
605 |
|
483 |
while (*rpnt && *lpnt) { |
606 |
while (*rpnt && *lpnt) { |
|
|
607 |
#ifdef USE_ICONV |
608 |
size_t ri, li; |
609 |
|
610 |
ri = convert_to_unicode(rtmp, 2, rpnt, rinls); |
611 |
li = convert_to_unicode(ltmp, 2, lpnt, linls); |
612 |
rpnt += ri; |
613 |
lpnt += li; |
614 |
if(!ri && !li) |
615 |
return (0); |
616 |
else if(ri && !li) |
617 |
return (1); |
618 |
else if(!ri && li) |
619 |
return (-1); |
620 |
#else |
484 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
621 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
485 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
622 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
|
|
623 |
#endif |
486 |
|
624 |
|
487 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
625 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
488 |
return (-1); |
626 |
return (-1); |
489 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
627 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
490 |
return (1); |
628 |
return (1); |
491 |
|
629 |
|
|
|
630 |
#ifndef USE_ICONV |
492 |
rpnt++; |
631 |
rpnt++; |
493 |
lpnt++; |
632 |
lpnt++; |
|
|
633 |
#endif |
494 |
} |
634 |
} |
495 |
|
635 |
|
496 |
if (*rpnt) |
636 |
if (*rpnt) |
Lines 564-573
Link Here
|
564 |
} |
704 |
} |
565 |
#ifdef APPLE_HYB |
705 |
#ifdef APPLE_HYB |
566 |
if (USE_MAC_NAME(de)) |
706 |
if (USE_MAC_NAME(de)) |
567 |
namelen = joliet_strlen(de->hfs_ent->name); |
707 |
namelen = joliet_strlen(de->hfs_ent->name, hfs_inls); |
568 |
else |
708 |
else |
569 |
#endif /* APPLE_HYB */ |
709 |
#endif /* APPLE_HYB */ |
570 |
namelen = joliet_strlen(de->name); |
710 |
namelen = joliet_strlen(de->name, in_nls); |
571 |
|
711 |
|
572 |
if (dpnt == root) { |
712 |
if (dpnt == root) { |
573 |
jpath_table_l[jpath_table_index] = 1; |
713 |
jpath_table_l[jpath_table_index] = 1; |
Lines 712-721
Link Here
|
712 |
#ifdef APPLE_HYB |
852 |
#ifdef APPLE_HYB |
713 |
/* Use the HFS name if it exists */ |
853 |
/* Use the HFS name if it exists */ |
714 |
if (USE_MAC_NAME(s_entry1)) |
854 |
if (USE_MAC_NAME(s_entry1)) |
715 |
cvt_len = joliet_strlen(s_entry1->hfs_ent->name); |
855 |
cvt_len = joliet_strlen(s_entry1->hfs_ent->name, hfs_inls); |
716 |
else |
856 |
else |
717 |
#endif /* APPLE_HYB */ |
857 |
#endif /* APPLE_HYB */ |
718 |
cvt_len = joliet_strlen(s_entry1->name); |
858 |
cvt_len = joliet_strlen(s_entry1->name, in_nls); |
719 |
|
859 |
|
720 |
/* |
860 |
/* |
721 |
* Fix the record length |
861 |
* Fix the record length |
Lines 849-860
Link Here
|
849 |
if (USE_MAC_NAME(s_entry)) |
989 |
if (USE_MAC_NAME(s_entry)) |
850 |
/* Use the HFS name if it exists */ |
990 |
/* Use the HFS name if it exists */ |
851 |
jpath_table_size += |
991 |
jpath_table_size += |
852 |
joliet_strlen(s_entry->hfs_ent->name) + |
992 |
joliet_strlen(s_entry->hfs_ent->name, hfs_inls) + |
853 |
offsetof(struct iso_path_table, name[0]); |
993 |
offsetof(struct iso_path_table, name[0]); |
854 |
else |
994 |
else |
855 |
#endif /* APPLE_HYB */ |
995 |
#endif /* APPLE_HYB */ |
856 |
jpath_table_size += |
996 |
jpath_table_size += |
857 |
joliet_strlen(s_entry->name) + |
997 |
joliet_strlen(s_entry->name, in_nls) + |
858 |
offsetof(struct iso_path_table, name[0]); |
998 |
offsetof(struct iso_path_table, name[0]); |
859 |
if (jpath_table_size & 1) { |
999 |
if (jpath_table_size & 1) { |
860 |
jpath_table_size++; |
1000 |
jpath_table_size++; |
Lines 876-888
Link Here
|
876 |
/* Use the HFS name if it exists */ |
1016 |
/* Use the HFS name if it exists */ |
877 |
s_entry->jreclen = |
1017 |
s_entry->jreclen = |
878 |
offsetof(struct iso_directory_record, name[0]) |
1018 |
offsetof(struct iso_directory_record, name[0]) |
879 |
+ joliet_strlen(s_entry->hfs_ent->name) |
1019 |
+ joliet_strlen(s_entry->hfs_ent->name, hfs_inls) |
880 |
+ 1; |
1020 |
+ 1; |
881 |
else |
1021 |
else |
882 |
#endif /* APPLE_HYB */ |
1022 |
#endif /* APPLE_HYB */ |
883 |
s_entry->jreclen = |
1023 |
s_entry->jreclen = |
884 |
offsetof(struct iso_directory_record, name[0]) |
1024 |
offsetof(struct iso_directory_record, name[0]) |
885 |
+ joliet_strlen(s_entry->name) |
1025 |
+ joliet_strlen(s_entry->name, in_nls) |
886 |
+ 1; |
1026 |
+ 1; |
887 |
} else { |
1027 |
} else { |
888 |
/* |
1028 |
/* |
Lines 1024-1029
Link Here
|
1024 |
#endif |
1164 |
#endif |
1025 |
|
1165 |
|
1026 |
while (*rpnt && *lpnt) { |
1166 |
while (*rpnt && *lpnt) { |
|
|
1167 |
#ifdef USE_ICONV |
1168 |
size_t ri, li; |
1169 |
#endif |
1027 |
if (*rpnt == ';' && *lpnt != ';') |
1170 |
if (*rpnt == ';' && *lpnt != ';') |
1028 |
return (-1); |
1171 |
return (-1); |
1029 |
if (*rpnt != ';' && *lpnt == ';') |
1172 |
if (*rpnt != ';' && *lpnt == ';') |
Lines 1044-1059
Link Here
|
1044 |
return (1); |
1187 |
return (1); |
1045 |
#endif |
1188 |
#endif |
1046 |
|
1189 |
|
|
|
1190 |
#ifdef USE_ICONV |
1191 |
|
1192 |
ri = convert_to_unicode(rtmp, 2, rpnt, rinls); |
1193 |
li = convert_to_unicode(ltmp, 2, lpnt, linls); |
1194 |
rpnt += ri; |
1195 |
lpnt += li; |
1196 |
if(!ri && !li) |
1197 |
return (0); |
1198 |
else if(ri && !li) |
1199 |
return (1); |
1200 |
else if(!ri && li) |
1201 |
return (-1); |
1202 |
#else |
1047 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
1203 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
1048 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
1204 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
|
|
1205 |
#endif |
1049 |
|
1206 |
|
1050 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
1207 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
1051 |
return (-1); |
1208 |
return (-1); |
1052 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
1209 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
1053 |
return (1); |
1210 |
return (1); |
1054 |
|
1211 |
|
|
|
1212 |
#ifndef USE_ICONV |
1055 |
rpnt++; |
1213 |
rpnt++; |
1056 |
lpnt++; |
1214 |
lpnt++; |
|
|
1215 |
#endif |
1057 |
} |
1216 |
} |
1058 |
if (*rpnt) |
1217 |
if (*rpnt) |
1059 |
return (1); |
1218 |
return (1); |