home *** CD-ROM | disk | FTP | other *** search
- /*
- * Routine to convert a UNIX-style path to an AmigaDOS path.
- *
- * Based on routine by Martin W. Scott (from UnixDirs II).
- * Major cleanup and bugfixing for use in wu-ftpd by Blaz Zupan, 07/94
- */
-
- #include <string.h>
-
- /*
- * "path" is a pointer to the Unix path to be
- * converted. The result is put back into "path"
- * because it is never longer than the original path.
- */
- void
- UnixToAmiga (char *path)
- {
- char *s, *t, *start;
-
- s = path;
- start = path;
-
- if (t = strchr (path, ':')) /* check for ':' in path */
- {
- t++; /* copy device component */
- while (path < t)
- *s++ = *path++;
- }
-
- while (path[0])
- {
- if ((path == start || path[-1] == '/') && path[0] == '.')
- {
- if (path[1] == '.')
- {
- if (path[2] == '/')
- {
- path += 2;
- *s++ = *path++;
- }
- else if (!path[2])
- {
- path += 2;
- *s++ = '/';
- }
- else
- *s++ = *path++;
- }
- else
- {
- if (path[1] == '/')
- path += 2;
- else if (!path[1])
- path += 1;
- else
- *s++ = *path++;
- }
- }
- else
- *s++ = *path++;
- }
- *s = '\0';
- }
-
- #ifdef TEST
-
- #include <proto/exec.h>
- #include <stdio.h>
-
- int
- main (int argc, char **argv)
- {
- int i;
-
- for (i = 1; i < argc; i++)
- {
- char *buf;
-
- if (buf = AllocMem (512, 0))
- {
- CopyMem (argv[i], buf, 512);
- UnixToAmiga (buf);
- printf ("%s --> %s\n", argv[i], buf);
- FreeMem (buf, 512);
- }
- }
- return 0;
- }
-
- #endif
-