home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / macutils.lzh / MACUTILS / UTIL / transname.c < prev    next >
Text File  |  1996-01-31  |  5KB  |  115 lines

  1. #ifndef OSK
  2. #include <sys/types.h>
  3. #include <sys/dir.h>
  4. #else
  5. #include "/dd/blarsdefs/sys/types.h"
  6. #include <dir.h>
  7. #endif
  8.  
  9. char *strncpy();
  10.  
  11. #ifdef MAXNAMLEN    /* 4.2 BSD */ /* and OSK :) */
  12. #define FNAMELEN MAXNAMLEN
  13. #else
  14. #define FNAMELEN DIRSIZ
  15. #endif
  16.  
  17. /* Create a Unix file name based on the Mac filename.  First off we have
  18.  * possible problems with filename sizes (Sys V) and also with allowable
  19.  * characters.  Mac filename characters can be anything from 1 to 254 (I
  20.  * think 0 and 255 are not allowed) with colon disallowed.  Unix filenames
  21.  * have also a lot of freedom, but cannot contain 0 or '/'.  Also on Unix
  22.  * non-printable are a trouble (you will never see the filename correctly;
  23.  * and it may even lock your terminal with some versions of Unix).
  24.  * So first off non-printable characters are mapped to underscore.
  25.  * Although there are Unix systems that allow the high order bit set in
  26.  * a filename character in all programs, nearly all implementations do not
  27.  * allow that, so also characters in the range 0200-0377 are mapped to
  28.  * underscore (except as noted below).  Some people would also like to
  29.  * remap characters that are special to some shells (open brackets,
  30.  * asterisks, exclamation point (csh), etc.)  I did elect not to do so
  31.  * because there is no end.  (The previous code disallowed a lot, but not
  32.  * the braces that are special to some shells, obviously he was a C-shell user!)
  33.  * Characters in the range 0200-0377 are in part accented letters
  34.  * (the Swedes, Norwegians and Danes would not agree, but who listens to
  35.  * them!); those are mapped to the unaccented version.  All other characters
  36.  * in this range are mapped to underscore.  Note: this is based on the
  37.  * Geneva font!
  38.  * This stuff is now largely table driven.
  39.  * One day I may modify this so that an environment variable may be used
  40.  * to define mappings. */
  41.  
  42. static char char_mapping[] = {
  43.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  44.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  45.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  46.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  47.      '_',  '!',  '"',  '#',  '$',  '%',  '&', '\'',
  48.      '(',  ')',  '*',  '+',  ',',  '-',  '.',  '_',
  49.      '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
  50.      '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
  51.      '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
  52.      'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
  53.      'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
  54.      'X',  'Y',  'Z',  '[', '\\',  ']',  '^',  '_',
  55.      '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
  56.      'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
  57.      'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
  58.      'x',  'y',  'z',  '{',  '|',  '}',  '~',  '_',
  59. #ifndef LATIN1
  60.      'A',  'A',  'C',  'E',  'N',  'O',  'U',  'a',
  61.      'a',  'a',  'a',  'a',  'a',  'c',  'e',  'e',
  62.      'e',  'e',  'i',  'i',  'i',  'i',  'n',  'o',
  63.      'o',  'o',  'o',  'o',  'u',  'u',  'u',  'u',
  64.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  65.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  'O',
  66.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  67.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  'o',
  68.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  69.      '_',  '_',  '_',  'A',  'A',  'O',  '_',  '_',
  70.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  71.      'y',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  72. #else /* LATIN1 */
  73.     0304, 0305, 0307, 0311, 0321, 0326, 0334, 0341,
  74.     0340, 0342, 0344, 0343, 0345, 0347, 0351, 0350,
  75.     0352, 0353, 0355, 0354, 0356, 0357, 0361, 0363,
  76.     0362, 0364, 0366, 0365, 0372, 0371, 0373, 0374,
  77.      '_', 0260, 0242, 0243, 0247, 0267, 0266, 0337,
  78.     0256, 0251,  '_', 0264, 0250,  '_', 0306, 0330,
  79.      '_', 0261,  '_',  '_', 0245,  '_',  '_',  '_',
  80.      '_',  '_',  '_',  '_',  '_',  '_', 0346, 0370,
  81.     0277, 0241, 0254,  '_',  '_',  '_',  '_', 0253,
  82.     0273,  '_',  '_', 0300, 0303, 0325,  '_',  '_',
  83.      '_',  '_',  '_',  '_',  '_',  '_', 0367, 0244,
  84.     0377,  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  85. #endif /* LATIN1 */
  86.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  87.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  88.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  89.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_'};
  90.  
  91. void transname(name, namebuf, n)
  92. char *name, *namebuf;
  93. int n;
  94. {
  95.     char *np;
  96.  
  97.     /* make sure host file name doesn't get truncated beyond recognition */
  98.     if (n > FNAMELEN - 2) {
  99.     n = FNAMELEN - 2;
  100.     }
  101.     (void)strncpy(namebuf, name, n);
  102.     namebuf[n] = '\0';
  103.  
  104.     /* now: translate name */
  105.     for (np = namebuf; *np; np++){
  106.     *np = char_mapping[*np & 0xff];
  107.     }
  108. #ifdef NODOT
  109.     if(*namebuf == '.') {
  110.     *namebuf = '_';
  111.     }
  112. #endif /* NODOT */
  113. }
  114.  
  115.