Improved standards compliance for ISO level 1 names with partly relaxed

constraints.
This commit is contained in:
Thomas Schmitt 2012-03-14 09:07:59 +01:00
parent ce35aefb32
commit 4eb4146474
4 changed files with 124 additions and 12 deletions

View File

@ -32,7 +32,7 @@
static static
int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name) int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
{ {
int ret, relaxed, free_ascii_name= 0, force_dots = 0, max_len; int ret, relaxed, free_ascii_name= 0, force_dots = 0;
char *ascii_name; char *ascii_name;
char *isoname= NULL; char *isoname= NULL;
@ -73,11 +73,22 @@ needs_transl:;
} else if (img->max_37_char_filenames) { } else if (img->max_37_char_filenames) {
isoname = iso_r_dirid(ascii_name, 37, relaxed); isoname = iso_r_dirid(ascii_name, 37, relaxed);
} else if (img->iso_level == 1) { } else if (img->iso_level == 1) {
#ifdef Libisofs_old_ecma119_nameS
if (relaxed) { if (relaxed) {
isoname = iso_r_dirid(ascii_name, 8, relaxed); isoname = iso_r_dirid(ascii_name, 8, relaxed);
} else { } else {
isoname = iso_1_dirid(ascii_name); isoname = iso_1_dirid(ascii_name, 0);
} }
#else /* Libisofs_old_ecma119_nameS */
isoname = iso_1_dirid(ascii_name, relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} else { } else {
if (relaxed) { if (relaxed) {
isoname = iso_r_dirid(ascii_name, 31, relaxed); isoname = iso_r_dirid(ascii_name, 31, relaxed);
@ -94,6 +105,11 @@ needs_transl:;
} else if (img->max_37_char_filenames) { } else if (img->max_37_char_filenames) {
isoname = iso_r_fileid(ascii_name, 36, relaxed, force_dots); isoname = iso_r_fileid(ascii_name, 36, relaxed, force_dots);
} else if (img->iso_level == 1) { } else if (img->iso_level == 1) {
#ifdef Libisofs_old_ecma119_nameS
int max_len;
if (relaxed) { if (relaxed) {
if (strchr(ascii_name, '.') == NULL) if (strchr(ascii_name, '.') == NULL)
max_len = 8; max_len = 8;
@ -102,8 +118,15 @@ needs_transl:;
isoname = iso_r_fileid(ascii_name, max_len, relaxed, isoname = iso_r_fileid(ascii_name, max_len, relaxed,
force_dots); force_dots);
} else { } else {
isoname = iso_1_fileid(ascii_name, force_dots); isoname = iso_1_fileid(ascii_name, 0, force_dots);
} }
#else /* Libisofs_old_ecma119_nameS */
isoname = iso_1_fileid(ascii_name, relaxed, force_dots);
#endif /* ! Libisofs_old_ecma119_nameS */
} else { } else {
if (relaxed || !force_dots) { if (relaxed || !force_dots) {
isoname = iso_r_fileid(ascii_name, 30, relaxed, force_dots); isoname = iso_r_fileid(ascii_name, 30, relaxed, force_dots);

View File

@ -1584,7 +1584,7 @@ int iso_write_opts_set_rr_reloc(IsoWriteOpts *opts, char *name, int flags);
int iso_write_opts_set_allow_longer_paths(IsoWriteOpts *opts, int allow); int iso_write_opts_set_allow_longer_paths(IsoWriteOpts *opts, int allow);
/** /**
* Allow a single file or directory hierarchy to have up to 37 characters. * Allow a single file or directory identifier to have up to 37 characters.
* This is larger than the 31 characters allowed by ISO level 2, and the * This is larger than the 31 characters allowed by ISO level 2, and the
* extra space is taken from the version number, so this also forces * extra space is taken from the version number, so this also forces
* omit_version_numbers. * omit_version_numbers.

View File

@ -685,8 +685,27 @@ static int valid_j_char(uint16_t c)
&& cmp_ucsbe(&c, '\\'); && cmp_ucsbe(&c, '\\');
} }
static char map_fileid_char(char c, int relaxed)
{
char upper;
if (relaxed == 2) /* all chars are allowed */
return c;
if (valid_d_char(c))
return c;
upper= toupper(c);
if (valid_d_char(upper)) {
if (relaxed) {
/* lower chars are allowed */
return c;
}
return upper;
}
return '_';
}
static static
char *iso_dirid(const char *src, int size) char *iso_dirid(const char *src, int size, int relaxed)
{ {
size_t len, i; size_t len, i;
char name[32]; char name[32];
@ -696,25 +715,35 @@ char *iso_dirid(const char *src, int size)
len = size; len = size;
} }
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= toupper(src[i]); char c= toupper(src[i]);
name[i] = valid_d_char(c) ? c : '_'; name[i] = valid_d_char(c) ? c : '_';
#else /* Libisofs_old_ecma119_nameS */
name[i] = map_fileid_char(src[i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
name[len] = '\0'; name[len] = '\0';
return strdup(name); return strdup(name);
} }
char *iso_1_dirid(const char *src) char *iso_1_dirid(const char *src, int relaxed)
{ {
return iso_dirid(src, 8); return iso_dirid(src, 8, relaxed);
} }
char *iso_2_dirid(const char *src) char *iso_2_dirid(const char *src)
{ {
return iso_dirid(src, 31); return iso_dirid(src, 31, 0);
} }
char *iso_1_fileid(const char *src, int force_dots) char *iso_1_fileid(const char *src, int relaxed, int force_dots)
{ {
char *dot; /* Position of the last dot in the filename, will be used char *dot; /* Position of the last dot in the filename, will be used
* to calculate lname and lext. */ * to calculate lname and lext. */
@ -739,9 +768,22 @@ char *iso_1_fileid(const char *src, int force_dots)
/* Convert up to 8 characters of the filename. */ /* Convert up to 8 characters of the filename. */
for (i = 0; i < lname && i < 8; i++) { for (i = 0; i < lname && i < 8; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= toupper(src[i]); char c= toupper(src[i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
#else /* Libisofs_old_ecma119_nameS */
if (dot == NULL && src[i] == '.')
dest[pos++] = '_'; /* make sure that ignored dots do not appear */
else
dest[pos++] = map_fileid_char(src[i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
/* This dot is mandatory, even if there is no extension. */ /* This dot is mandatory, even if there is no extension. */
@ -750,9 +792,19 @@ char *iso_1_fileid(const char *src, int force_dots)
/* Convert up to 3 characters of the extension, if any. */ /* Convert up to 3 characters of the extension, if any. */
for (i = 0; i < lext && i < 3; i++) { for (i = 0; i < lext && i < 3; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= toupper(src[lname + 1 + i]); char c= toupper(src[lname + 1 + i]);
dest[pos++] = valid_d_char(c) ? c : '_'; dest[pos++] = valid_d_char(c) ? c : '_';
#else /* Libisofs_old_ecma119_nameS */
dest[pos++] = map_fileid_char(src[lname + 1 + i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
dest[pos] = '\0'; dest[pos] = '\0';
@ -835,6 +887,9 @@ char *iso_r_dirid(const char *src, int size, int relaxed)
if (dest == NULL) if (dest == NULL)
return NULL; return NULL;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= src[i]; char c= src[i];
if (relaxed == 2) { if (relaxed == 2) {
/* all chars are allowed */ /* all chars are allowed */
@ -855,6 +910,13 @@ char *iso_r_dirid(const char *src, int size, int relaxed)
dest[i] = '_'; dest[i] = '_';
} }
} }
#else /* Libisofs_old_ecma119_nameS */
dest[i] = map_fileid_char(src[i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
dest[len] = '\0'; dest[len] = '\0';
@ -862,7 +924,8 @@ char *iso_r_dirid(const char *src, int size, int relaxed)
} }
/** /**
* Create a file name suitable for an ISO image with relaxed constraints. * Create a file name suitable for an ISO image with level > 1 and
* with relaxed constraints.
* *
* @param len * @param len
* Max len for the name, without taken the "." into account. * Max len for the name, without taken the "." into account.
@ -915,6 +978,9 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
/* Convert up to lnname characters of the filename. */ /* Convert up to lnname characters of the filename. */
for (i = 0; i < lnname; i++) { for (i = 0; i < lnname; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= src[i]; char c= src[i];
if (relaxed == 2) { if (relaxed == 2) {
/* all chars are allowed */ /* all chars are allowed */
@ -935,6 +1001,13 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
dest[pos++] = '_'; dest[pos++] = '_';
} }
} }
#else /* Libisofs_old_ecma119_nameS */
dest[pos++] = map_fileid_char(src[i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
if (lnext > 0 || forcedot) { if (lnext > 0 || forcedot) {
dest[pos++] = '.'; dest[pos++] = '.';
@ -942,6 +1015,9 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
/* Convert up to lnext characters of the extension, if any. */ /* Convert up to lnext characters of the extension, if any. */
for (i = lname + 1; i < lname + 1 + lnext; i++) { for (i = lname + 1; i < lname + 1 + lnext; i++) {
#ifdef Libisofs_old_ecma119_nameS
char c= src[i]; char c= src[i];
if (relaxed == 2) { if (relaxed == 2) {
/* all chars are allowed */ /* all chars are allowed */
@ -962,6 +1038,13 @@ char *iso_r_fileid(const char *src, size_t len, int relaxed, int forcedot)
dest[pos++] = '_'; dest[pos++] = '_';
} }
} }
#else /* Libisofs_old_ecma119_nameS */
dest[pos++] = map_fileid_char(src[i], relaxed);
#endif /* ! Libisofs_old_ecma119_nameS */
} }
dest[pos] = '\0'; dest[pos] = '\0';

View File

@ -93,8 +93,11 @@ int str2ucs(const char *icharset, const char *input, uint16_t **output);
* *
* @param src * @param src
* The identifier, in ASCII encoding. * The identifier, in ASCII encoding.
* @param relaxed
* 0 only allow d-characters, 1 allow also lowe case chars,
* 2 allow all characters
*/ */
char *iso_1_dirid(const char *src); char *iso_1_dirid(const char *src, int relaxed);
/** /**
* Create a level 2 directory identifier. * Create a level 2 directory identifier.
@ -124,10 +127,13 @@ char *iso_r_dirid(const char *src, int size, int relaxed);
* *
* @param src * @param src
* The identifier, in ASCII encoding. * The identifier, in ASCII encoding.
* @param relaxed
* 0 only allow d-characters, 1 allow also lowe case chars,
* 2 allow all characters
* @param force_dots * @param force_dots
* If 1 then prepend empty extension by SEPARATOR1 = '.' * If 1 then prepend empty extension by SEPARATOR1 = '.'
*/ */
char *iso_1_fileid(const char *src, int force_dots); char *iso_1_fileid(const char *src, int relaxed, int force_dots);
/** /**
* Create a level 2 file identifier. * Create a level 2 file identifier.