Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

static int TruncateName ( unsigned char *  name  )  [static]

Truncate the file name in-place to ISO9660 compliant format.

Parameters:
name a null-terminated string that is at least 1 character long (excluding the terminating NUL character)
Returns:
the length of the truncated string, excluding the terminating NUL character

Definition at line 96 of file write.c.

References isWovel(), and REMOVED.

Referenced by Write9660(), and WritePC64().

{
  unsigned char* c;
  int len, efflen;

  for (c = name; *c; c++) {
    if (*c >= 'a' && *c <= 'z')     /* Lower case chars are OK */
      continue;
    else if (*c >= '0' && *c <= '9')/* So are numbers */
      continue;
    else if (*c >= 'A' && *c <= 'Z')/* Convert characters to lower case */
      *c -= 'A' - 'a';
    else if (*c >= 0xC1 && *c <= 0xDA) /* Convert upper case PETSCII chars */
      *c -= 0xC1 - 'a';
    else
      *c = '_';                     /* Convert anything else to underscore */
  }

  efflen = len = c - name;

  if (efflen > 8) {
    /* Remove underscores from the end */
    for (c = &name[len]; c > name; c--) {
      if (*c == '_') {
      *c = REMOVED;
      if (--efflen <= 8) break;
      }
    }
  }

  if (efflen > 8) {
    /* remove wovels from the end */
    int i;

    /* Search for the first non-wovel */
    for (i = 0; i < len && isWovel (name[i]); i++);

    if (i < len) {
      for (c = &name[len]; c > &name[i]; c--)
      if (isWovel (*c)) {
        *c = REMOVED;
        if (--efflen <= 8) break;
      }
    }
  }

  if (efflen > 8) {
    /* remove letters from the end */
    for (c = &name[len]; c > name; c--)
      if (*c >= 'A' && *c <= 'Z') {
      *c = REMOVED;
      if (--efflen <= 8) break;
      }
  }

  if (efflen > 8) {
    /* remove anything from the end */

    for (c = &name[len]; c > name; c--)
      if (*c && *c != REMOVED) {
      *c = REMOVED;
      if (--efflen <= 8) break;
      }
  }

  if (!efflen) {
    /* create a file name for empty file names */
    name[0] = '_';
    name[1] = 0;
  }
  else {
    /* remove removed characters */
    unsigned char* t;

    for (c = t = name; *c; c++)
      if (*c != REMOVED)
      *t++ = *c;

    *t = 0;
  }

  return efflen;
}


Generated by  Doxygen 1.6.0   Back to index