home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / unx2dos.c < prev    next >
C/C++ Source or Header  |  1993-05-23  |  3KB  |  205 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <osbind.h>
  5. #include <types.h>
  6. #include <param.h>
  7. #include <support.h>
  8.  
  9. extern int __mint;
  10. extern char _rootdir;    /* in main.c: user's preferred root directory */
  11.  
  12. int _unixmode;        /* not used right now */
  13.  
  14. /*
  15.  * returns 0 for ordinary files, 1 for special files (like /dev/tty)
  16.  */
  17.  
  18. int
  19. _unx2dos(unx, dos)
  20.     const char *unx;
  21.     char *dos;
  22. {
  23.     const char *u;
  24.     char *d, c;
  25.  
  26.     dos[0] = 0;
  27.     u = unx; d = dos;
  28.     if (!strncmp(u, "/dev/", 5)) {
  29.         u += 5;
  30.     /* make /dev/A/foo the same as A:/foo */
  31.  
  32.         if (*u && (u[1] == 0 || (u[1] == '/' || u[1] == '\\'))) {
  33.             d[0] = *u++;
  34.             d[1] = ':';
  35.             d += 2;
  36.         }
  37.     /* check for a unix device name */
  38.         else if (__mint) {
  39.             if (__mint >= 8) {
  40.                 strcpy(d, "U:\\dev\\"); d += 7;
  41.             } else {
  42.                 strcpy(d, "V:\\");
  43.                 d += 3;
  44.             }
  45.         }
  46.         else {
  47.             strcpy(d, u);
  48.             strcat(d, ":");
  49.             if (!strcmp(d, "tty:"))
  50.                 strcpy(d, "con:");
  51.             return 1;
  52.         }
  53.     } else if (__mint && !strncmp(u, "/pipe/", 6)) {
  54.         u += 6;
  55.         if (__mint >= 9) {
  56.             strcpy(d, "U:\\pipe\\"); d += 8;
  57.         } else {
  58.             strcpy(d, "Q:\\"); d += 3;
  59.         }
  60.     } else if (*u == '/' && _rootdir) {
  61.         *d++ = _rootdir;
  62.         *d++ = ':';
  63.     }
  64.  
  65.     while( (c = *u++) != 0 ) {
  66.         if (c == '/')
  67.             c = '\\';
  68. #if 0
  69. /* translate "c:/foo/d:/bar" into "d:\bar" */
  70.         else if (c == ':') {
  71.             if (   (d > &dos[1] && d[-2] == '\\')
  72.                 || (d == &dos[1]) ) {
  73.                 *dos = d[-1];
  74.                 d = dos+1;
  75.             }
  76.         }
  77. #endif
  78.         *d++ = c;
  79.     }
  80.     *d++ = 0;
  81.     return 0;
  82. }
  83.  
  84. int
  85. _dos2unx(dos, unx)
  86.     const char *dos;
  87.     char *unx;
  88. {
  89.     register char c;
  90.  
  91.     /* replace A:\x with /dev/a/x,
  92.      * replace A:\x with /x, if _rootdir is 'a',
  93.      * replace A:\x with /a/x, if _rootdir is 'u'.
  94.      * BUG/FEATURE: A:x is converted to A:\x, you lose the feature
  95.      *              of one current directory per device.
  96.      *              This is because we assume that /dev/a/x is always 
  97.      *              an absolute path.
  98.      */ 
  99.     if (*dos && dos[1] == ':') {
  100.         register char dev = tolower(*dos);
  101.         dos += 2;
  102.         if (dev != _rootdir) {
  103.             if (_rootdir != 'u') {
  104.                 *unx++ = '/'; *unx++ = 'd'; 
  105.                 *unx++ = 'e'; *unx++ = 'v';
  106.             }
  107.             *unx++ = '/';
  108.             *unx++ = dev;
  109.         }
  110.         if (*dos != '/' && *dos != '\\') {
  111.                 *unx++ = '/';
  112.         }
  113.     }
  114.     /* convert slashes
  115.      */
  116.     while ( (c = *dos++) != 0) {
  117.         if (c == '\\')
  118.             c = '/';
  119.         else if (__mint < 7)
  120.             c = tolower(c);
  121.         *unx++ = c;
  122.     }
  123.     *unx++ = 0;
  124.     return 0;
  125. }
  126.  
  127. #ifdef __GNUC__
  128.  
  129. asm(".stabs \"_unx2dos\",5,0,0,__unx2dos"); /* dept of clean tricks */
  130. asm(".stabs \"_dos2unx\",5,0,0,__dos2unx"); /* dept of clean tricks */
  131.  
  132. #else /* ! __GNUC__ */
  133.  
  134. int
  135. unx2dos(unx, dos)
  136.         const char *unx;
  137.         char *dos;
  138. {
  139.     return _unx2dos(unx, dos);
  140. }
  141.  
  142. int
  143. dos2unx(dos, unx)
  144.         const char *dos;
  145.         char *unx;
  146. {
  147.     return _dos2unx(dos, unx);
  148. }
  149.  
  150. #endif
  151.  
  152. int
  153. _path_unx2dos(unx, dos)
  154.     const char *unx;
  155.     char *dos;
  156. {
  157.     char buf[MAXPATHLEN], *s;
  158.         
  159.     while (*unx) {
  160.         s = buf;
  161.         while (*unx) {
  162.             if (*unx == ':') {
  163.                 unx++;
  164.                 break;
  165.             }
  166.             *s++ = *unx++;
  167.         }
  168.         *s = 0;
  169.         _unx2dos(buf, dos);
  170.         while (*dos)
  171.             dos++;
  172.         *dos++ = ',';
  173.     }        
  174.  
  175.     *--dos = 0;
  176.     return 0;
  177. }        
  178.  
  179. int 
  180. _path_dos2unx(dos, unx)
  181.     const char *dos;
  182.     char *unx;
  183. {
  184.     char buf[MAXPATHLEN], *s;
  185.  
  186.     while (*dos) {
  187.         s = buf;
  188.         while (*dos) {
  189.             if (*dos == ';' || *dos == ',') {
  190.                 dos++;
  191.                 break;
  192.             }
  193.             *s++ = *dos++;
  194.         }
  195.         *s = 0;
  196.         _dos2unx(buf, unx);
  197.         while (*unx)
  198.             unx++;
  199.         *unx++ = ':';
  200.     }
  201.  
  202.     *--unx = 0;
  203.     return 0;
  204. }
  205.