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 / backtrans.c next >
C/C++ Source or Header  |  1995-10-18  |  3KB  |  105 lines

  1. #include "masks.h"
  2.  
  3. /* Map a command line given name to a Mac name.  If LATIN1 is not defined
  4.    the translation is direct, except that \ is handled special.  \\ is
  5.    translated to \, \ddd (three digits) is translated to the octal code.
  6.    If LATIN1 is defined, special care has been taken with the 8 bit chars
  7.    to get a proper mapping, if possible.  Note: colon is translated to _. */
  8. static char char_mapping[] = {
  9.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  10.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  11.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  12.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  13.      ' ',  '!',  '"',  '#',  '$',  '%',  '&', '\'',
  14.      '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
  15.      '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
  16.      '8',  '9',  '_',  ';',  '<',  '=',  '>',  '?',
  17.      '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
  18.      'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
  19.      'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
  20.      'X',  'Y',  'Z',  '[', '\\',  ']',  '^',  '_',
  21.      '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
  22.      'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
  23.      'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
  24.      'x',  'y',  'z',  '{',  '|',  '}',  '~', 0177,
  25.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  26.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  27.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  28.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  29. #ifndef LATIN1
  30.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  31.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  32.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  33.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  34.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  35.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  36.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  37.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  38.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  39.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  40.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_',
  41.      '_',  '_',  '_',  '_',  '_',  '_',  '_',  '_'};
  42. #else /* LATIN1 */
  43.      '_', 0301, 0242, 0243, 0327, 0265,  '_', 0244,
  44.     0254, 0251,  '_', 0307, 0302,  '_', 0250,  '_',
  45.     0241, 0261,  '_',  '_', 0253,  '_', 0246, 0245,
  46.      '_',  '_',  '_', 0310,  '_',  '_',  '_', 0300,
  47.     0313, 0207, 0211, 0313, 0200, 0201, 0256, 0202,
  48.     0217, 0203, 0220, 0221, 0223, 0314, 0224, 0225,
  49.      '_', 0204, 0230, 0227, 0231, 0233, 0205,  '_',
  50.     0257, 0235, 0234, 0236, 0206,  '_',  '_', 0247,
  51.     0210, 0207, 0211, 0213, 0212, 0214, 0276, 0215,
  52.     0217, 0216, 0220, 0221, 0223, 0222, 0224, 0225,
  53.      '_', 0226, 0230, 0227, 0231, 0233, 0232, 0326,
  54.     0277, 0235, 0234, 0236, 0237,  '_',  '_', 0330};
  55. #endif /* LATIN1 */
  56.  
  57. void backtrans(macname, name)
  58. char *macname, *name;
  59. {
  60.     char *in, *out;
  61.     int c, count = 0;
  62.  
  63.     out = macname;
  64.     for (in = name; *in; in++){
  65.     if(count == 31) {
  66.         break;
  67.     }
  68.     if(*in != '\\') {
  69.         *out++ = char_mapping[*in & BYTEMASK];
  70.         count++;
  71.         continue;
  72.     }
  73.     in++;
  74.     if(*in == 0) {
  75.         break;;
  76.     }
  77.     if(*in < '0' || *in > '9') {
  78.         *out++ = char_mapping[*in & BYTEMASK];
  79.         count++;
  80.         continue;
  81.     }
  82.     c = *in - '0';
  83.     in++;
  84.     if(*in < '0' || *in > '9') {
  85.         *out++ = c;
  86.         count++;
  87.         in--;
  88.         continue;
  89.     }
  90.     c = (c << 3) + *in - '0';
  91.     in++;
  92.     if(*in < '0' || *in > '9') {
  93.         *out++ = c;
  94.         count++;
  95.         in--;
  96.         continue;
  97.     }
  98.     c = (c << 3) + *in - '0';
  99.     *out++ = c;
  100.     count++;
  101.     }
  102.     *out++ = 0;
  103. }
  104.  
  105.