1 /* Path conversion for Windows pathnames.
2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 2, or (at your option) any later version.
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 GNU Make; see the file COPYING. If not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
21 #include "pathstuff.h"
24 * Convert delimiter separated vpath to Canonical format.
27 convert_vpath_to_windows32(char *Path
, char to_delim
)
29 char *etok
; /* token separator for old Path */
32 * Convert all spaces to delimiters. Note that pathnames which
33 * contain blanks get trounced here. Use 8.3 format as a workaround.
35 for (etok
= Path
; etok
&& *etok
; etok
++)
36 if (isblank ((unsigned char) *etok
))
39 return (convert_Path_to_windows32(Path
, to_delim
));
43 * Convert delimiter separated path to Canonical format.
46 convert_Path_to_windows32(char *Path
, char to_delim
)
48 char *etok
; /* token separator for old Path */
49 char *p
; /* points to element of old Path */
51 /* is this a multi-element Path ? */
52 for (p
= Path
, etok
= strpbrk(p
, ":;");
54 etok
= strpbrk(p
, ":;"))
55 if ((etok
- p
) == 1) {
56 if (*(etok
- 1) == ';' ||
61 continue; /* ignore empty bucket */
62 } else if (!isalpha ((unsigned char) *p
)) {
63 /* found one to count, handle things like '.' */
66 } else if ((*etok
== ':') && (etok
= strpbrk(etok
+1, ":;"))) {
67 /* found one to count, handle drive letter */
71 /* all finished, force abort */
74 /* found another one, no drive letter */
83 * Convert to forward slashes. Resolve to full pathname optionally
86 w32ify(char *filename
, int resolve
)
88 static char w32_path
[FILENAME_MAX
];
92 _fullpath(w32_path
, filename
, sizeof (w32_path
));
94 strncpy(w32_path
, filename
, sizeof (w32_path
));
96 for (p
= w32_path
; p
&& *p
; p
++)
104 getcwd_fs(char* buf
, int len
)
106 char *p
= getcwd(buf
, len
);
109 char *q
= w32ify(buf
, 0);
110 strncpy(buf
, q
, len
);
118 * Convert delimiter separated pathnames (e.g. PATH) or single file pathname
119 * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
120 * _NutPathToNutc() fails to convert, just return the path we were handed
121 * and assume the caller will know what to do with it (It was probably
122 * a mistake to try and convert it anyway due to some of the bizarre things
123 * that might look like pathnames in makefiles).
126 convert_path_to_nutc(char *path
)
128 int count
; /* count of path elements */
129 char *nutc_path
; /* new NutC path */
130 int nutc_path_len
; /* length of buffer to allocate for new path */
131 char *pathp
; /* pointer to nutc_path used to build it */
132 char *etok
; /* token separator for old path */
133 char *p
; /* points to element of old path */
134 char sep
; /* what flavor of separator used in old path */
137 /* is this a multi-element path ? */
138 for (p
= path
, etok
= strpbrk(p
, ":;"), count
= 0;
140 etok
= strpbrk(p
, ":;"))
141 if ((etok
- p
) == 1) {
142 if (*(etok
- 1) == ';' ||
143 *(etok
- 1) == ':') {
145 continue; /* ignore empty bucket */
146 } else if (etok
= strpbrk(etok
+1, ":;"))
147 /* found one to count, handle drive letter */
150 /* all finished, force abort */
153 /* found another one, no drive letter */
157 count
++; /* x1;x2;x3 <- need to count x3 */
160 * Hazard a guess on how big the buffer needs to be.
161 * We have to convert things like c:/foo to /c=/foo.
163 nutc_path_len
= strlen(path
) + (count
*2) + 1;
164 nutc_path
= xmalloc(nutc_path_len
);
169 * Loop through PATH and convert one elemnt of the path at at
170 * a time. Single file pathnames will fail this and fall
171 * to the logic below loop.
173 for (p
= path
, etok
= strpbrk(p
, ":;");
175 etok
= strpbrk(p
, ":;")) {
177 /* don't trip up on device specifiers or empty path slots */
179 if (*(etok
- 1) == ';' ||
180 *(etok
- 1) == ':') {
183 } else if ((etok
= strpbrk(etok
+1, ":;")) == NULL
)
184 break; /* thing found was a WINDOWS32 pathname */
189 /* terminate the current path element -- temporarily */
193 /* convert to NutC format */
194 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
196 rval
= savestring(path
, strlen(path
));
204 strcpy(pathp
, &p
[2]);
207 pathp
+= strlen(pathp
);
208 *pathp
++ = ':'; /* use Unix style path separtor for new path */
209 *pathp
= '\0'; /* make sure we are null terminaed */
211 /* restore path separator */
214 /* point p to first char of next path element */
219 nutc_path_len
= strlen(path
) + 3;
220 nutc_path
= xmalloc(nutc_path_len
);
227 * OK, here we handle the last element in PATH (e.g. c of a;b;c)
228 * or the path was a single filename and will be converted
229 * here. Note, testing p here assures that we don't trip up
230 * on paths like a;b; which have trailing delimiter followed by
235 if (_NutPathToNutc(p
, pathp
, 0) == FALSE
) {
237 rval
= savestring(path
, strlen(path
));
245 strcpy(pathp
, &p
[2]);
248 *(pathp
-1) = '\0'; /* we're already done, don't leave trailing : */
250 rval
= savestring(nutc_path
, strlen(nutc_path
));