|
Lines 90-95
Link Here
|
| 90 |
#include <unls.h> /* For UNICODE translation */ |
90 |
#include <unls.h> /* For UNICODE translation */ |
| 91 |
#include <schily.h> |
91 |
#include <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 nls_table *inls)); |
117 |
int size, char *source, struct nls_table *inls)); |
| 108 |
int joliet_strlen __PR((const char *string)); |
118 |
int joliet_strlen __PR((const char *string, struct nls_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 nls_table *inls)); |
126 |
int size, char *source, struct nls_table *inls)); |
| 112 |
static int joliet_strlen __PR((const char *string)); |
127 |
static int joliet_strlen __PR((const char *string, struct nls_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->charset2uni == NULL || onls->page_uni2charset == 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->charset2uni[c].uni2; |
194 |
uh = inls->charset2uni[c].uni2; |
| 166 |
ul = inls->charset2uni[c].uni1; |
195 |
ul = inls->charset2uni[c].uni1; |
|
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->charset2uni==NULL && |
| 258 |
inls->page_uni2charset==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 nls_table *inls; |
| 292 |
{ |
378 |
{ |
| 293 |
int rtn; |
379 |
int rtn; |
| 294 |
|
380 |
|
|
|
381 |
#ifdef USE_ICONV |
| 382 |
if (inls->iconv_d && inls->charset2uni==NULL && |
| 383 |
inls->page_uni2charset==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 480-495
Link Here
|
| 480 |
/* compare the Unicode names */ |
603 |
/* compare the Unicode names */ |
| 481 |
|
604 |
|
| 482 |
while (*rpnt && *lpnt) { |
605 |
while (*rpnt && *lpnt) { |
|
|
606 |
#ifdef USE_ICONV |
| 607 |
size_t ri, li; |
| 608 |
|
| 609 |
ri = convert_to_unicode(rtmp, 2, rpnt, rinls); |
| 610 |
li = convert_to_unicode(ltmp, 2, lpnt, linls); |
| 611 |
rpnt += ri; |
| 612 |
lpnt += li; |
| 613 |
if(!ri && !li) |
| 614 |
return (0); |
| 615 |
else if(ri && !li) |
| 616 |
return (1); |
| 617 |
else if(!ri && li) |
| 618 |
return (-1); |
| 619 |
#else |
| 483 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
620 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
| 484 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
621 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
|
|
622 |
#endif |
| 485 |
|
623 |
|
| 486 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
624 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
| 487 |
return (-1); |
625 |
return (-1); |
| 488 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
626 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
| 489 |
return (1); |
627 |
return (1); |
| 490 |
|
628 |
|
|
|
629 |
#ifndef USE_ICONV |
| 491 |
rpnt++; |
630 |
rpnt++; |
| 492 |
lpnt++; |
631 |
lpnt++; |
|
|
632 |
#endif |
| 493 |
} |
633 |
} |
| 494 |
|
634 |
|
| 495 |
if (*rpnt) |
635 |
if (*rpnt) |
|
Lines 574-583
Link Here
|
| 574 |
} |
714 |
} |
| 575 |
#ifdef APPLE_HYB |
715 |
#ifdef APPLE_HYB |
| 576 |
if (USE_MAC_NAME(de)) |
716 |
if (USE_MAC_NAME(de)) |
| 577 |
namelen = joliet_strlen(de->hfs_ent->name); |
717 |
namelen = joliet_strlen(de->hfs_ent->name, hfs_inls); |
| 578 |
else |
718 |
else |
| 579 |
#endif /* APPLE_HYB */ |
719 |
#endif /* APPLE_HYB */ |
| 580 |
namelen = joliet_strlen(de->name); |
720 |
namelen = joliet_strlen(de->name, in_nls); |
| 581 |
|
721 |
|
| 582 |
if (dpnt == root) { |
722 |
if (dpnt == root) { |
| 583 |
jpath_table_l[jpath_table_index] = 1; |
723 |
jpath_table_l[jpath_table_index] = 1; |
|
Lines 742-751
Link Here
|
| 742 |
#ifdef APPLE_HYB |
882 |
#ifdef APPLE_HYB |
| 743 |
/* Use the HFS name if it exists */ |
883 |
/* Use the HFS name if it exists */ |
| 744 |
if (USE_MAC_NAME(s_entry1)) |
884 |
if (USE_MAC_NAME(s_entry1)) |
| 745 |
cvt_len = joliet_strlen(s_entry1->hfs_ent->name); |
885 |
cvt_len = joliet_strlen(s_entry1->hfs_ent->name, hfs_inls); |
| 746 |
else |
886 |
else |
| 747 |
#endif /* APPLE_HYB */ |
887 |
#endif /* APPLE_HYB */ |
| 748 |
cvt_len = joliet_strlen(s_entry1->name); |
888 |
cvt_len = joliet_strlen(s_entry1->name, in_nls); |
| 749 |
|
889 |
|
| 750 |
/* |
890 |
/* |
| 751 |
* Fix the record length |
891 |
* Fix the record length |
|
Lines 891-902
Link Here
|
| 891 |
if (USE_MAC_NAME(s_entry)) |
1031 |
if (USE_MAC_NAME(s_entry)) |
| 892 |
/* Use the HFS name if it exists */ |
1032 |
/* Use the HFS name if it exists */ |
| 893 |
jpath_table_size += |
1033 |
jpath_table_size += |
| 894 |
joliet_strlen(s_entry->hfs_ent->name) + |
1034 |
joliet_strlen(s_entry->hfs_ent->name, hfs_inls) + |
| 895 |
offsetof(struct iso_path_table, name[0]); |
1035 |
offsetof(struct iso_path_table, name[0]); |
| 896 |
else |
1036 |
else |
| 897 |
#endif /* APPLE_HYB */ |
1037 |
#endif /* APPLE_HYB */ |
| 898 |
jpath_table_size += |
1038 |
jpath_table_size += |
| 899 |
joliet_strlen(s_entry->name) + |
1039 |
joliet_strlen(s_entry->name, in_nls) + |
| 900 |
offsetof(struct iso_path_table, name[0]); |
1040 |
offsetof(struct iso_path_table, name[0]); |
| 901 |
if (jpath_table_size & 1) { |
1041 |
if (jpath_table_size & 1) { |
| 902 |
jpath_table_size++; |
1042 |
jpath_table_size++; |
|
Lines 918-930
Link Here
|
| 918 |
/* Use the HFS name if it exists */ |
1058 |
/* Use the HFS name if it exists */ |
| 919 |
s_entry->jreclen = |
1059 |
s_entry->jreclen = |
| 920 |
offsetof(struct iso_directory_record, name[0]) |
1060 |
offsetof(struct iso_directory_record, name[0]) |
| 921 |
+ joliet_strlen(s_entry->hfs_ent->name) |
1061 |
+ joliet_strlen(s_entry->hfs_ent->name, hfs_inls) |
| 922 |
+ 1; |
1062 |
+ 1; |
| 923 |
else |
1063 |
else |
| 924 |
#endif /* APPLE_HYB */ |
1064 |
#endif /* APPLE_HYB */ |
| 925 |
s_entry->jreclen = |
1065 |
s_entry->jreclen = |
| 926 |
offsetof(struct iso_directory_record, name[0]) |
1066 |
offsetof(struct iso_directory_record, name[0]) |
| 927 |
+ joliet_strlen(s_entry->name) |
1067 |
+ joliet_strlen(s_entry->name, in_nls) |
| 928 |
+ 1; |
1068 |
+ 1; |
| 929 |
} else { |
1069 |
} else { |
| 930 |
/* |
1070 |
/* |
|
Lines 1072-1077
Link Here
|
| 1072 |
#endif |
1212 |
#endif |
| 1073 |
|
1213 |
|
| 1074 |
while (*rpnt && *lpnt) { |
1214 |
while (*rpnt && *lpnt) { |
|
|
1215 |
#ifdef USE_ICONV |
| 1216 |
size_t ri, li; |
| 1217 |
#endif |
| 1075 |
if (*rpnt == ';' && *lpnt != ';') |
1218 |
if (*rpnt == ';' && *lpnt != ';') |
| 1076 |
return (-1); |
1219 |
return (-1); |
| 1077 |
if (*rpnt != ';' && *lpnt == ';') |
1220 |
if (*rpnt != ';' && *lpnt == ';') |
|
Lines 1092-1107
Link Here
|
| 1092 |
return (1); |
1235 |
return (1); |
| 1093 |
#endif |
1236 |
#endif |
| 1094 |
|
1237 |
|
|
|
1238 |
#ifdef USE_ICONV |
| 1239 |
|
| 1240 |
ri = convert_to_unicode(rtmp, 2, rpnt, rinls); |
| 1241 |
li = convert_to_unicode(ltmp, 2, lpnt, linls); |
| 1242 |
rpnt += ri; |
| 1243 |
lpnt += li; |
| 1244 |
if(!ri && !li) |
| 1245 |
return (0); |
| 1246 |
else if(ri && !li) |
| 1247 |
return (1); |
| 1248 |
else if(!ri && li) |
| 1249 |
return (-1); |
| 1250 |
#else |
| 1095 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
1251 |
convert_to_unicode(rtmp, 2, rpnt, rinls); |
| 1096 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
1252 |
convert_to_unicode(ltmp, 2, lpnt, linls); |
|
|
1253 |
#endif |
| 1097 |
|
1254 |
|
| 1098 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
1255 |
if (a_to_u_2_byte(rtmp) < a_to_u_2_byte(ltmp)) |
| 1099 |
return (-1); |
1256 |
return (-1); |
| 1100 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
1257 |
if (a_to_u_2_byte(rtmp) > a_to_u_2_byte(ltmp)) |
| 1101 |
return (1); |
1258 |
return (1); |
| 1102 |
|
1259 |
|
|
|
1260 |
#ifndef USE_ICONV |
| 1103 |
rpnt++; |
1261 |
rpnt++; |
| 1104 |
lpnt++; |
1262 |
lpnt++; |
|
|
1263 |
#endif |
| 1105 |
} |
1264 |
} |
| 1106 |
if (*rpnt) |
1265 |
if (*rpnt) |
| 1107 |
return (1); |
1266 |
return (1); |