3 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 Desc: utility internal function __path_u2a()
10 #include "__arosc_privdata.h"
16 static const char *__path_devstuff_u2a(const char *path
);
17 static void __path_normalstuff_u2a(const char *path
, char *buf
);
20 static int __doupath
= 1;
21 static char *__apathbuf
;
22 # define realloc_nocopy realloc
25 /*****************************************************************************
31 const char *__path_u2a(
37 Translates an unix-style path into an AmigaDOS one.
40 upath - Unix-style path to translate into an AmigaDOS-style equivalent.
43 A pointer to a string containing the AmigaDOS-style path, or NULL in
46 The pointer is valid only until next call to this function, so if
47 you need to call this function recursively, you must save the string
48 pointed to by the pointer before calling this function again.
51 This function is for private usage by system code. Do not use it
58 ******************************************************************************/
62 /* Does the path really need to be converted? */
74 First see whether the path is in the /dev/#? form and,
75 if so, if it's handled internally
77 newpath
= __path_devstuff_u2a(upath
);
80 /* Else, convert it normally */
81 newpath
= realloc_nocopy(__apathbuf
, strlen(upath
) + 1);
89 __apathbuf
= (char *)newpath
;
90 __path_normalstuff_u2a(upath
, __apathbuf
);
96 /*****************************************************************************
102 const char *__path_a2u(
108 Translates an AmigaDOS-style path into an unix one.
111 apath - AmigaDOS-style path to translate into an unix-style equivalent.
114 A pointer to a string containing the unix-style path, or NULL in
117 The pointer is valid only until next call to this function, so if
118 you need to call this function recursively, you must save the string
119 pointed to by the pointer before calling this function again.
122 This function is for private usage by system code. Do not use it
129 ******************************************************************************/
131 const char *old_apath
= apath
;
132 char ch
, *upath
, *old_upath
;
155 while ((ch
= *apath
++))
166 old_upath
= realloc_nocopy(__apathbuf
, 1 + size
+ 1);
167 if (old_upath
== NULL
)
173 __apathbuf
= old_upath
;
181 register char ch
= apath
[0];
212 (--old_upath
)[0] = '/';
232 upath
[0] = '.'; upath
[1] = '.'; upath
[2] = '/'; upath
+= 3;
252 static const char *__path_devstuff_u2a(const char *path
)
255 Translate the various /dev/#? most used files into the AROS equivalent.
256 Use a tree-like handmade search to speed things up
259 if (path
[0] == '/' && path
[1] == 'd' && path
[2] == 'e' && path
[3] == 'v')
263 if (path
[5] == 'n' && path
[6] == 'u' && path
[7] == 'l' && path
[8] == 'l' && path
[9] == '\0')
266 if (path
[5] == 'z' && path
[6] == 'e' && path
[7] == 'r' && path
[8] == 'o' && path
[9] == '\0')
269 if (path
[5] == 's' && path
[6] == 't' && path
[7] == 'd')
271 if (path
[8] == 'i' && path
[9] == 'n' && path
[10] == '\0')
274 if (path
[8] == 'o' && path
[9] == 'u' && path
[10] == 't' && path
[11] == '\0')
277 if (path
[8] == 'e' && path
[9] == 'r' && path
[10] == 'r' && path
[11] == '\0')
292 static void __path_normalstuff_u2a(const char *path
, char *buf
)
294 register char dir_sep
= '\0';
295 register int makevol
= 0;
307 while (path
[0] == '/')
315 register char ch
= path
[0];
371 if (ch
== '/' || ch
== '\0')
421 int main(int argc
, char *argv
[])
426 printf("%s\n", __path_u2a(argv
[1]));
427 printf("%s\n", __path_a2u(argv
[2]));