7 * Convert delimiter separated vpath to Canonical format.
10 convert_vpath_to_windows32(char *Path
, char to_delim
)
12 char *etok
; /* token separator for old Path */
15 * Convert all spaces to delimiters. Note that pathnames which
16 * contain blanks get trounced here. Use 8.3 format as a workaround.
18 for (etok
= Path
; etok
&& *etok
; etok
++)
19 if (isblank ((unsigned char) *etok
))
22 return (convert_Path_to_windows32(Path
, to_delim
));
26 * Convert delimiter separated path to Canonical format.
29 convert_Path_to_windows32(char *Path
, char to_delim
)
31 char *etok
; /* token separator for old Path */
32 char *p
; /* points to element of old Path */
34 /* is this a multi-element Path ? */
35 for (p
= Path
, etok
= strpbrk(p
, ":;");
37 etok
= strpbrk(p
, ":;"))
38 if ((etok
- p
) == 1) {
39 if (*(etok
- 1) == ';' ||
44 continue; /* ignore empty bucket */
45 } else if (!isalpha ((unsigned char) *p
)) {
46 /* found one to count, handle things like '.' */
49 } else if ((*etok
== ':') && (etok
= strpbrk(etok
+1, ":;"))) {
50 /* found one to count, handle drive letter */
54 /* all finished, force abort */
57 /* found another one, no drive letter */
66 * Convert to forward slashes. Resolve to full pathname optionally
69 w32ify(char *filename
, int resolve
)
71 static char w32_path
[FILENAME_MAX
];
75 _fullpath(w32_path
, filename
, sizeof (w32_path
));
77 strncpy(w32_path
, filename
, sizeof (w32_path
));
79 for (p
= w32_path
; p
&& *p
; p
++)
87 getcwd_fs(char* buf
, int len
)
91 if (p
= getcwd(buf
, len
)) {
92 char *q
= w32ify(buf
, 0);
101 * Convert delimiter separated pathnames (e.g. PATH) or single file pathname
102 * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
103 * _NutPathToNutc() fails to convert, just return the path we were handed
104 * and assume the caller will know what to do with it (It was probably
105 * a mistake to try and convert it anyway due to some of the bizarre things
106 * that might look like pathnames in makefiles).
109 convert_path_to_nutc(char *path
)
111 int count
; /* count of path elements */
112 char *nutc_path
; /* new NutC path */
113 int nutc_path_len
; /* length of buffer to allocate for new path */
114 char *pathp
; /* pointer to nutc_path used to build it */
115 char *etok
; /* token separator for old path */
116 char *p
; /* points to element of old path */
117 char sep
; /* what flavor of separator used in old path */
120 /* is this a multi-element path ? */
121 for (p
= path
, etok
= strpbrk(p
, ":;"), count
= 0;
123 etok
= strpbrk(p
, ":;"))
124 if ((etok
- p
) == 1) {
125 if (*(etok
- 1) == ';' ||
126 *(etok
- 1) == ':') {
128 continue; /* ignore empty bucket */
129 } else if (etok
= strpbrk(etok
+1, ":;"))
130 /* found one to count, handle drive letter */
133 /* all finished, force abort */
136 /* found another one, no drive letter */
140 count
++; /* x1;x2;x3 <- need to count x3 */
143 * Hazard a guess on how big the buffer needs to be.
144 * We have to convert things like c:/foo to /c=/foo.
146 nutc_path_len
= strlen(path
) + (count
*2) + 1;
147 nutc_path
= xmalloc(nutc_path_len
);
152 * Loop through PATH and convert one elemnt of the path at at
153 * a time. Single file pathnames will fail this and fall
154 * to the logic below loop.
156 for (p
= path
, etok
= strpbrk(p
, ":;");
158 etok
= strpbrk(p
, ":;")) {
160 /* don't trip up on device specifiers or empty path slots */
162 if (*(etok
- 1) == ';' ||
163 *(etok
- 1) == ':') {
166 } else if ((etok
= strpbrk(etok
+1, ":;")) == NULL
)
167 break; /* thing found was a WINDOWS32 pathname */
172 /* terminate the current path element -- temporarily */
176 /* convert to NutC format */
177 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
179 rval
= savestring(path
, strlen(path
));
187 strcpy(pathp
, &p
[2]);
190 pathp
+= strlen(pathp
);
191 *pathp
++ = ':'; /* use Unix style path separtor for new path */
192 *pathp
= '\0'; /* make sure we are null terminaed */
194 /* restore path separator */
197 /* point p to first char of next path element */
202 nutc_path_len
= strlen(path
) + 3;
203 nutc_path
= xmalloc(nutc_path_len
);
210 * OK, here we handle the last element in PATH (e.g. c of a;b;c)
211 * or the path was a single filename and will be converted
212 * here. Note, testing p here assures that we don't trip up
213 * on paths like a;b; which have trailing delimiter followed by
218 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
220 rval
= savestring(path
, strlen(path
));
228 strcpy(pathp
, &p
[2]);
231 *(pathp
-1) = '\0'; /* we're already done, don't leave trailing : */
233 rval
= savestring(nutc_path
, strlen(nutc_path
));