home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / unx2dos.c < prev    next >
C/C++ Source or Header  |  1992-06-08  |  2KB  |  104 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <osbind.h>
  5. #include <types.h>
  6.  
  7. extern int __mint;
  8. extern char _rootdir;    /* in main.c: user's preferred root directory */
  9.  
  10. int _unixmode;        /* not used right now */
  11.  
  12. /*
  13.  * returns 0 for ordinary files, 1 for special files (like /dev/tty)
  14.  */
  15.  
  16. int
  17. _unx2dos(unx, dos)
  18.     const char *unx;
  19.     char *dos;
  20. {
  21.     const char *u;
  22.     char *d, c;
  23.  
  24.     dos[0] = 0;
  25.     u = unx; d = dos;
  26.     if (!strncmp(u, "/dev/", 5)) {
  27.         u += 5;
  28.     /* make /dev/A/foo the same as A:/foo */
  29.  
  30.         if (*u && (u[1] == 0 || (u[1] == '/' || u[1] == '\\'))) {
  31.             d[0] = *u++;
  32.             d[1] = ':';
  33.             d += 2;
  34.         }
  35.     /* check for a unix device name */
  36.         else if (__mint) {
  37.             if (__mint >= 8) {
  38.                 strcpy(d, "U:\\dev\\"); d += 7;
  39.             } else {
  40.                 strcpy(d, "V:\\");
  41.                 d += 3;
  42.             }
  43.         }
  44.         else {
  45.             strcpy(d, u);
  46.             strcat(d, ":");
  47.             if (!strcmp(d, "tty:"))
  48.                 strcpy(d, "con:");
  49.             return 1;
  50.         }
  51.     } else if (__mint && !strncmp(u, "/pipe/", 6)) {
  52.         u += 6;
  53.         if (__mint >= 9) {
  54.             strcpy(d, "U:\\pipe\\"); d += 8;
  55.         } else {
  56.             strcpy(d, "Q:\\"); d += 3;
  57.         }
  58.     } else if (*u == '/' && _rootdir) {
  59.         *d++ = _rootdir;
  60.         *d++ = ':';
  61.     }
  62.  
  63.     while( (c = *u++) != 0 ) {
  64.         if (c == '/')
  65.             c = '\\';
  66. #if 0
  67. /* translate "c:/foo/d:/bar" into "d:\bar" */
  68.         else if (c == ':') {
  69.             if (   (d > &dos[1] && d[-2] == '\\')
  70.                 || (d == &dos[1]) ) {
  71.                 *dos = d[-1];
  72.                 d = dos+1;
  73.             }
  74.         }
  75. #endif
  76.         *d++ = c;
  77.     }
  78.     *d++ = 0;
  79.     return 0;
  80. }
  81.  
  82. int
  83. _dos2unx(dos, unx)
  84.     const char *dos;
  85.     char *unx;
  86. {
  87.     char c;
  88.  
  89.     while ( (c = *dos++) != 0) {
  90.         if (c == '\\')
  91.             c = '/';
  92.         else if (__mint < 7)
  93.             c = tolower(c);
  94.         *unx++ = c;
  95.     }
  96.     *unx++ = 0;
  97.     return 0;
  98. }
  99.  
  100. #ifdef __GNUC__
  101. asm(".stabs \"_unx2dos\",5,0,0,__unx2dos"); /* dept of clean tricks */
  102. asm(".stabs \"_dos2unx\",5,0,0,__dos2unx"); /* dept of clean tricks */
  103. #endif
  104.