make-dfsg/w32/pathstuff.c
Roland McGrath e7a525c5d5 Wed May 15 10:14:14 CDT 1996 Rob Tulloh <tulloh@tivoli.com>
* dir.c: WIN32 does not support inode. For now, fully qualified
	pathname along with st_mtime will be keys for files.
	Fixed problem where vpath can be confused when files
	are added to a directory after the directory has already been
	read in. The code now attempts to reread the directory if it
	discovers that the datestamp on the directory has changed since
	it was cached by make. This problem only seems to occur on WIN32
	right now so it is lumped under port #ifdef WIN32.

	* function.c: WIN32: call subproc library (CreateProcess()) instead of
	fork/exec.

	* job.c: WIN32: Added the code to do fork/exec/waitpid style processing
	on WIN32 systems via calls to subproc library.

	* main.c: WIN32: Several things added here. First, there is code
	for dealing with PATH and SHELL defaults. Make tries to figure
	out if the user has %PATH% set in the environment and sets it to
	%Path% if it is not set already. Make also looks to see if sh.exe
	is anywhere to be found. Code path through job.c will change
	based on existence of a working Bourne shell. The checking for
	default shell is done twice: once before makefiles are read in
	and again after. Fall back to MSDOS style execution mode if no sh.exe
	is found. Also added some debug support that allows user to pause make
	with -D switch and attach a debugger. This is especially useful for
	debugging recursive calls to make where problems appear only in the
	sub-make.

	* make.h: WIN32: A few macros and header files for WIN32 support.

	* misc.c: WIN32: Added a function end_of_token_w32() to assist
	in parsing code in read.c.

	* read.c: WIN32: Fixes similar to MSDOS which allow colon to
	appear in filenames. Use of colon in filenames would otherwise
	confuse make.

	* remake.c: WIN32: Added include of io.h to eliminate compiler
	warnings. Added some code to default LIBDIR if it is not set
	on WIN32.

	* variable.c: WIN32: Added support for detecting Path/PATH
	and converting them to semicolon separated lists for make's
	internal use. New function sync_Path_environment()
	which is called in job.c and function.c before creating a new
	process. Caller must set Path in environment since we don't
	have fork() to do this for us.

	* vpath.c: WIN32: Added detection for filenames containing
	forward or backward slashes.

	* NMakefile: WIN32: Visual C compatible makefile for use with nmake.
	Use this to build GNU make the first time on Windows NT or Windows 95.

	* README.WIN32: WIN32: Contains some helpful notes.

	* build_w32.bat: WIN32: If you don't like nmake, use this the first
	time you build GNU make on Windows NT or Windows 95.

	* config.h.WIN32: WIN32 version of config.h

	* subproc.bat: WIN32: A bat file used to build the
	subproc library from the top-level NMakefile. Needed because
	WIndows 95 (nmake) doesn't allow you to cd in a make rule.

	* w32/include/dirent.h
	* w32/compat/dirent.c: WIN32: opendir, readdir, closedir, etc.

	* w32/include/pathstuff.h: WIN32: used by files needed functions
	defined in pathstuff.c (prototypes).

	* w32/include/sub_proc.h: WIN32: prototypes for subproc.lib functions.

	* w32/include/w32err.h: WIN32: prototypes for w32err.c.

	* w32/pathstuff.c: WIN32: File and Path/Path conversion functions.

	* w32/subproc/build.bat: WIN32: build script for subproc library
	if you don't wish to use nmake.

	* w32/subproc/NMakefile: WIN32: Visual C compatible makefile for use
	with nmake. Used to build subproc library.

	* w32/subproc/misc.c: WIN32: subproc library support code
	* w32/subproc/proc.h: WIN32: subproc library support code
	* w32/subproc/sub_proc.c: WIN32: subproc library source code
	* w32/subproc/w32err.c: WIN32: subproc library support code
1996-05-22 21:51:45 +00:00

220 lines
6.3 KiB
C

#include <string.h>
#include <stdlib.h>
#include "make.h"
/*
* 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