6 * Convert delimiter separated path to Canonical format.
9 convert_Path_to_win32(char *Path
, char to_delim
)
11 char *etok
; /* token separator for old Path */
12 char *p
; /* points to element of old Path */
14 /* is this a multi-element Path ? */
15 for (p
= Path
, etok
= strpbrk(p
, ":;");
17 etok
= strpbrk(p
, ":;"))
18 if ((etok
- p
) == 1) {
19 if (*(etok
- 1) == ';' ||
24 continue; /* ignore empty bucket */
25 } else if (etok
= strpbrk(etok
+1, ":;")) {
26 /* found one to count, handle drive letter */
30 /* all finished, force abort */
33 /* found another one, no drive letter */
39 /* convert to backward slashes */
40 for (p
= Path
, p
= strchr(p
, '/'); p
; p
= strchr(p
, '/'))
47 * Convert to forward slashes. Resolve to full pathname optionally
50 w32ify(char *filename
, int resolve
)
52 static char w32_path
[FILENAME_MAX
];
56 _fullpath(w32_path
, filename
, sizeof (w32_path
));
58 strncpy(w32_path
, filename
, sizeof (w32_path
));
60 for (p
= w32_path
; p
&& *p
; p
++)
68 getcwd_fs(char* buf
, int len
)
72 if (p
= getcwd(buf
, len
)) {
73 char *q
= w32ify(buf
, 0);
82 * Convert delimiter separated pathnames (e.g. PATH) or single file pathname
83 * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
84 * _NutPathToNutc() fails to convert, just return the path we were handed
85 * and assume the caller will know what to do with it (It was probably
86 * a mistake to try and convert it anyway due to some of the bizarre things
87 * that might look like pathnames in makefiles).
90 convert_path_to_nutc(char *path
)
92 int count
; /* count of path elements */
93 char *nutc_path
; /* new NutC path */
94 int nutc_path_len
; /* length of buffer to allocate for new path */
95 char *pathp
; /* pointer to nutc_path used to build it */
96 char *etok
; /* token separator for old path */
97 char *p
; /* points to element of old path */
98 char sep
; /* what flavor of separator used in old path */
101 /* is this a multi-element path ? */
102 for (p
= path
, etok
= strpbrk(p
, ":;"), count
= 0;
104 etok
= strpbrk(p
, ":;"))
105 if ((etok
- p
) == 1) {
106 if (*(etok
- 1) == ';' ||
107 *(etok
- 1) == ':') {
109 continue; /* ignore empty bucket */
110 } else if (etok
= strpbrk(etok
+1, ":;"))
111 /* found one to count, handle drive letter */
114 /* all finished, force abort */
117 /* found another one, no drive letter */
121 count
++; /* x1;x2;x3 <- need to count x3 */
124 * Hazard a guess on how big the buffer needs to be.
125 * We have to convert things like c:/foo to /c=/foo.
127 nutc_path_len
= strlen(path
) + (count
*2) + 1;
128 nutc_path
= xmalloc(nutc_path_len
);
133 * Loop through PATH and convert one elemnt of the path at at
134 * a time. Single file pathnames will fail this and fall
135 * to the logic below loop.
137 for (p
= path
, etok
= strpbrk(p
, ":;");
139 etok
= strpbrk(p
, ":;")) {
141 /* don't trip up on device specifiers or empty path slots */
143 if (*(etok
- 1) == ';' ||
144 *(etok
- 1) == ':') {
147 } else if ((etok
= strpbrk(etok
+1, ":;")) == NULL
)
148 break; /* thing found was a WIN32 pathname */
153 /* terminate the current path element -- temporarily */
157 /* convert to NutC format */
158 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
160 rval
= savestring(path
, strlen(path
));
168 strcpy(pathp
, &p
[2]);
171 pathp
+= strlen(pathp
);
172 *pathp
++ = ':'; /* use Unix style path separtor for new path */
173 *pathp
= '\0'; /* make sure we are null terminaed */
175 /* restore path separator */
178 /* point p to first char of next path element */
183 nutc_path_len
= strlen(path
) + 3;
184 nutc_path
= xmalloc(nutc_path_len
);
191 * OK, here we handle the last element in PATH (e.g. c of a;b;c)
192 * or the path was a single filename and will be converted
193 * here. Note, testing p here assures that we don't trip up
194 * on paths like a;b; which have trailing delimiter followed by
199 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
201 rval
= savestring(path
, strlen(path
));
209 strcpy(pathp
, &p
[2]);
212 *(pathp
-1) = '\0'; /* we're already done, don't leave trailing : */
214 rval
= savestring(nutc_path
, strlen(nutc_path
));