-#include <string.h>\r
-#include <stdlib.h>\r
-#include "make.h"\r
-\r
-/*\r
- * Convert delimiter separated path to Canonical format. \r
- */\r
-char *\r
-convert_Path_to_win32(char *Path, char to_delim)\r
-{\r
- char *etok; /* token separator for old Path */\r
- char *p; /* points to element of old Path */\r
-\r
- /* is this a multi-element Path ? */\r
- for (p = Path, etok = strpbrk(p, ":;");\r
- etok; \r
- etok = strpbrk(p, ":;"))\r
- if ((etok - p) == 1) {\r
- if (*(etok - 1) == ';' ||\r
- *(etok - 1) == ':') {\r
- etok[-1] = to_delim;\r
- etok[0] = to_delim;\r
- p = ++etok;\r
- continue; /* ignore empty bucket */\r
- } else if (etok = strpbrk(etok+1, ":;")) {\r
- /* found one to count, handle drive letter */\r
- *etok = to_delim;\r
- p = ++etok;\r
- } else\r
- /* all finished, force abort */\r
- p += strlen(p); \r
- } else {\r
- /* found another one, no drive letter */\r
- *etok = to_delim;\r
- p = ++etok;\r
- }\r
-\r
-#if 0\r
- /* convert to backward slashes */\r
- for (p = Path, p = strchr(p, '/'); p; p = strchr(p, '/'))\r
- *p = '\\';\r
-#endif\r
- return Path;\r
-} \r
-\r
-/*\r
- * Convert to forward slashes. Resolve to full pathname optionally\r
- */\r
-char *\r
-w32ify(char *filename, int resolve)\r
-{\r
- static char w32_path[FILENAME_MAX];\r
- char *p;\r
-\r
- if (resolve)\r
- _fullpath(w32_path, filename, sizeof (w32_path));\r
- else\r
- strncpy(w32_path, filename, sizeof (w32_path));\r
-\r
- for (p = w32_path; p && *p; p++)\r
- if (*p == '\\')\r
- *p = '/';\r
-\r
- return w32_path;\r
-}\r
-\r
-char *\r
-getcwd_fs(char* buf, int len)\r
-{\r
- char *p;\r
-\r
- if (p = getcwd(buf, len)) {\r
- char *q = w32ify(buf, 0);\r
- strncpy(buf, q, len);\r
- }\r
-\r
- return p;\r
-}\r
-\r
-#ifdef unused\r
-/*\r
- * Convert delimiter separated pathnames (e.g. PATH) or single file pathname\r
- * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that \r
- * _NutPathToNutc() fails to convert, just return the path we were handed \r
- * and assume the caller will know what to do with it (It was probably \r
- * a mistake to try and convert it anyway due to some of the bizarre things \r
- * that might look like pathnames in makefiles).\r
- */\r
-char *\r
-convert_path_to_nutc(char *path)\r
-{\r
- int count; /* count of path elements */\r
- char *nutc_path; /* new NutC path */\r
- int nutc_path_len; /* length of buffer to allocate for new path */\r
- char *pathp; /* pointer to nutc_path used to build it */\r
- char *etok; /* token separator for old path */\r
- char *p; /* points to element of old path */\r
- char sep; /* what flavor of separator used in old path */\r
- char *rval;\r
-\r
- /* is this a multi-element path ? */\r
- for (p = path, etok = strpbrk(p, ":;"), count = 0; \r
- etok; \r
- etok = strpbrk(p, ":;"))\r
- if ((etok - p) == 1) {\r
- if (*(etok - 1) == ';' ||\r
- *(etok - 1) == ':') {\r
- p = ++etok;\r
- continue; /* ignore empty bucket */\r
- } else if (etok = strpbrk(etok+1, ":;"))\r
- /* found one to count, handle drive letter */\r
- p = ++etok, count++;\r
- else\r
- /* all finished, force abort */\r
- p += strlen(p); \r
- } else \r
- /* found another one, no drive letter */\r
- p = ++etok, count++;\r
-\r
- if (count) {\r
- count++; /* x1;x2;x3 <- need to count x3 */\r
-\r
- /* \r
- * Hazard a guess on how big the buffer needs to be.\r
- * We have to convert things like c:/foo to /c=/foo.\r
- */\r
- nutc_path_len = strlen(path) + (count*2) + 1;\r
- nutc_path = xmalloc(nutc_path_len);\r
- pathp = nutc_path;\r
- *pathp = '\0';\r
-\r
- /*\r
- * Loop through PATH and convert one elemnt of the path at at\r
- * a time. Single file pathnames will fail this and fall\r
- * to the logic below loop.\r
- */\r
- for (p = path, etok = strpbrk(p, ":;"); \r
- etok; \r
- etok = strpbrk(p, ":;")) {\r
- \r
- /* don't trip up on device specifiers or empty path slots */\r
- if ((etok - p) == 1)\r
- if (*(etok - 1) == ';' ||\r
- *(etok - 1) == ':') {\r
- p = ++etok;\r
- continue;\r
- } else if ((etok = strpbrk(etok+1, ":;")) == NULL)\r
- break; /* thing found was a WIN32 pathname */\r
-\r
- /* save separator */\r
- sep = *etok;\r
-\r
- /* terminate the current path element -- temporarily */\r
- *etok = '\0';\r
- \r
-#ifdef __NUTC__\r
- /* convert to NutC format */\r
- if (_NutPathToNutc(p, pathp, 0) == FALSE) {\r
- free(nutc_path);\r
- rval = savestring(path, strlen(path));\r
- return rval;\r
- }\r
-#else\r
- *pathp++ = '/';\r
- *pathp++ = p[0];\r
- *pathp++ = '=';\r
- *pathp++ = '/';\r
- strcpy(pathp, &p[2]);\r
-#endif\r
- \r
- pathp += strlen(pathp);\r
- *pathp++ = ':'; /* use Unix style path separtor for new path */\r
- *pathp = '\0'; /* make sure we are null terminaed */\r
- \r
- /* restore path separator */\r
- *etok = sep;\r
- \r
- /* point p to first char of next path element */\r
- p = ++etok;\r
-\r
- }\r
- } else {\r
- nutc_path_len = strlen(path) + 3; \r
- nutc_path = xmalloc(nutc_path_len);\r
- pathp = nutc_path;\r
- *pathp = '\0';\r
- p = path;\r
- }\r
-\r
- /*\r
- * OK, here we handle the last element in PATH (e.g. c of a;b;c)\r
- * or the path was a single filename and will be converted\r
- * here. Note, testing p here assures that we don't trip up\r
- * on paths like a;b; which have trailing delimiter followed by \r
- * nothing.\r
- */\r
- if (*p != '\0') {\r
-#ifdef __NUTC__\r
- if (_NutPathToNutc(p, pathp, 0) == FALSE) {\r
- free(nutc_path);\r
- rval = savestring(path, strlen(path));\r
- return rval;\r
- }\r
-#else\r
- *pathp++ = '/';\r
- *pathp++ = p[0];\r
- *pathp++ = '=';\r
- *pathp++ = '/';\r
- strcpy(pathp, &p[2]);\r
-#endif\r
- } else\r
- *(pathp-1) = '\0'; /* we're already done, don't leave trailing : */\r
-\r
- rval = savestring(nutc_path, strlen(nutc_path));\r
- free(nutc_path);\r
- return rval;\r
-} \r
-\r
-#endif\r
+#include <string.h>
+#include <stdlib.h>
+#include "make.h"
+#include "pathstuff.h"
+
+/*
+ * Convert delimiter separated vpath to Canonical format.
+ */
+char *
+convert_vpath_to_win32(char *Path, char to_delim)
+{
+ char *etok; /* token separator for old Path */
+
+ /*
+ * Convert all spaces to delimiters. Note that pathnames which
+ * contain blanks get trounced here. Use 8.3 format as a workaround.
+ */
+ for (etok = Path; etok && *etok; etok++)
+ if (isblank(*etok))
+ *etok = to_delim;
+
+ return (convert_Path_to_win32(Path, to_delim));
+}
+
+/*
+ * Convert delimiter separated path to Canonical format.
+ */
+char *
+convert_Path_to_win32(char *Path, char to_delim)
+{
+ char *etok; /* token separator for old Path */
+ char *p; /* points to element of old Path */
+
+ /* is this a multi-element Path ? */
+ for (p = Path, etok = strpbrk(p, ":;");
+ etok;
+ etok = strpbrk(p, ":;"))
+ if ((etok - p) == 1) {
+ if (*(etok - 1) == ';' ||
+ *(etok - 1) == ':') {
+ etok[-1] = to_delim;
+ etok[0] = to_delim;
+ p = ++etok;
+ continue; /* ignore empty bucket */
+ } else if (etok = strpbrk(etok+1, ":;")) {
+ /* found one to count, handle drive letter */
+ *etok = to_delim;
+ p = ++etok;
+ } else
+ /* all finished, force abort */
+ p += strlen(p);
+ } else {
+ /* found another one, no drive letter */
+ *etok = to_delim;
+ p = ++etok;
+ }
+
+#if 0
+ /* convert to backward slashes */
+ for (p = Path, p = strchr(p, '/'); p; p = strchr(p, '/'))
+ *p = '\\';
+#endif
+ return Path;
+}
+
+/*
+ * Convert to forward slashes. Resolve to full pathname optionally
+ */
+char *
+w32ify(char *filename, int resolve)
+{
+ static char w32_path[FILENAME_MAX];
+ char *p;
+
+ if (resolve)
+ _fullpath(w32_path, filename, sizeof (w32_path));
+ else
+ strncpy(w32_path, filename, sizeof (w32_path));
+
+ for (p = w32_path; p && *p; p++)
+ if (*p == '\\')
+ *p = '/';
+
+ return w32_path;
+}
+
+char *
+getcwd_fs(char* buf, int len)
+{
+ char *p;
+
+ if (p = getcwd(buf, len)) {
+ char *q = w32ify(buf, 0);
+ strncpy(buf, q, len);
+ }
+
+ return p;
+}
+
+#ifdef unused
+/*
+ * Convert delimiter separated pathnames (e.g. PATH) or single file pathname
+ * (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
+ * _NutPathToNutc() fails to convert, just return the path we were handed
+ * and assume the caller will know what to do with it (It was probably
+ * a mistake to try and convert it anyway due to some of the bizarre things
+ * that might look like pathnames in makefiles).
+ */
+char *
+convert_path_to_nutc(char *path)
+{
+ int count; /* count of path elements */
+ char *nutc_path; /* new NutC path */
+ int nutc_path_len; /* length of buffer to allocate for new path */
+ char *pathp; /* pointer to nutc_path used to build it */
+ char *etok; /* token separator for old path */
+ char *p; /* points to element of old path */
+ char sep; /* what flavor of separator used in old path */
+ char *rval;
+
+ /* is this a multi-element path ? */
+ for (p = path, etok = strpbrk(p, ":;"), count = 0;
+ etok;
+ etok = strpbrk(p, ":;"))
+ if ((etok - p) == 1) {
+ if (*(etok - 1) == ';' ||
+ *(etok - 1) == ':') {
+ p = ++etok;
+ continue; /* ignore empty bucket */
+ } else if (etok = strpbrk(etok+1, ":;"))
+ /* found one to count, handle drive letter */
+ p = ++etok, count++;
+ else
+ /* all finished, force abort */
+ p += strlen(p);
+ } else
+ /* found another one, no drive letter */
+ p = ++etok, count++;
+
+ if (count) {
+ count++; /* x1;x2;x3 <- need to count x3 */
+
+ /*
+ * Hazard a guess on how big the buffer needs to be.
+ * We have to convert things like c:/foo to /c=/foo.
+ */
+ nutc_path_len = strlen(path) + (count*2) + 1;
+ nutc_path = xmalloc(nutc_path_len);
+ pathp = nutc_path;
+ *pathp = '\0';
+
+ /*
+ * Loop through PATH and convert one elemnt of the path at at
+ * a time. Single file pathnames will fail this and fall
+ * to the logic below loop.
+ */
+ for (p = path, etok = strpbrk(p, ":;");
+ etok;
+ etok = strpbrk(p, ":;")) {
+
+ /* don't trip up on device specifiers or empty path slots */
+ if ((etok - p) == 1)
+ if (*(etok - 1) == ';' ||
+ *(etok - 1) == ':') {
+ p = ++etok;
+ continue;
+ } else if ((etok = strpbrk(etok+1, ":;")) == NULL)
+ break; /* thing found was a WIN32 pathname */
+
+ /* save separator */
+ sep = *etok;
+
+ /* terminate the current path element -- temporarily */
+ *etok = '\0';
+
+#ifdef __NUTC__
+ /* convert to NutC format */
+ if (_NutPathToNutc(p, pathp, 0) == FALSE) {
+ free(nutc_path);
+ rval = savestring(path, strlen(path));
+ return rval;
+ }
+#else
+ *pathp++ = '/';
+ *pathp++ = p[0];
+ *pathp++ = '=';
+ *pathp++ = '/';
+ strcpy(pathp, &p[2]);
+#endif
+
+ pathp += strlen(pathp);
+ *pathp++ = ':'; /* use Unix style path separtor for new path */
+ *pathp = '\0'; /* make sure we are null terminaed */
+
+ /* restore path separator */
+ *etok = sep;
+
+ /* point p to first char of next path element */
+ p = ++etok;
+
+ }
+ } else {
+ nutc_path_len = strlen(path) + 3;
+ nutc_path = xmalloc(nutc_path_len);
+ pathp = nutc_path;
+ *pathp = '\0';
+ p = path;
+ }
+
+ /*
+ * OK, here we handle the last element in PATH (e.g. c of a;b;c)
+ * or the path was a single filename and will be converted
+ * here. Note, testing p here assures that we don't trip up
+ * on paths like a;b; which have trailing delimiter followed by
+ * nothing.
+ */
+ if (*p != '\0') {
+#ifdef __NUTC__
+ if (_NutPathToNutc(p, pathp, 0) == FALSE) {
+ free(nutc_path);
+ rval = savestring(path, strlen(path));
+ return rval;
+ }
+#else
+ *pathp++ = '/';
+ *pathp++ = p[0];
+ *pathp++ = '=';
+ *pathp++ = '/';
+ strcpy(pathp, &p[2]);
+#endif
+ } else
+ *(pathp-1) = '\0'; /* we're already done, don't leave trailing : */
+
+ rval = savestring(nutc_path, strlen(nutc_path));
+ free(nutc_path);
+ return rval;
+}
+
+#endif