summaryrefslogtreecommitdiff
path: root/vpath.c
diff options
context:
space:
mode:
Diffstat (limited to 'vpath.c')
-rw-r--r--vpath.c237
1 files changed, 117 insertions, 120 deletions
diff --git a/vpath.c b/vpath.c
index 9f41b27..94956fa 100644
--- a/vpath.c
+++ b/vpath.c
@@ -1,7 +1,5 @@
/* Implementation of pattern-matching file search paths for GNU Make.
-Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-2010 Free Software Foundation, Inc.
+Copyright (C) 1988-2013 Free Software Foundation, Inc.
This file is part of GNU Make.
GNU Make is free software; you can redistribute it and/or modify it under the
@@ -16,7 +14,7 @@ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
-#include "make.h"
+#include "makeint.h"
#include "filedef.h"
#include "variable.h"
#ifdef WINDOWS32
@@ -28,9 +26,9 @@ this program. If not, see <http://www.gnu.org/licenses/>. */
struct vpath
{
- struct vpath *next; /* Pointer to next struct in the linked list. */
+ struct vpath *next; /* Pointer to next struct in the linked list. */
const char *pattern;/* The pattern to match. */
- const char *percent;/* Pointer into `pattern' where the `%' is. */
+ const char *percent;/* Pointer into 'pattern' where the '%' is. */
unsigned int patlen;/* Length of the pattern. */
const char **searchpath; /* Null-terminated list of directories. */
unsigned int maxlen;/* Maximum length of any entry in the list. */
@@ -90,15 +88,15 @@ build_vpath_lists ()
struct vpath *save_vpaths = vpaths;
char gp[] = "%";
- /* Empty `vpaths' so the new one will have no next, and `vpaths'
- will still be nil if P contains no existing directories. */
+ /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
+ will still be nil if P contains no existing directories. */
vpaths = 0;
/* Parse P. */
construct_vpath_list (gp, p);
/* Store the created path as the general path,
- and restore the old list of vpaths. */
+ and restore the old list of vpaths. */
general_vpath = vpaths;
vpaths = save_vpaths;
}
@@ -123,15 +121,15 @@ build_vpath_lists ()
struct vpath *save_vpaths = vpaths;
char gp[] = "%";
- /* Empty `vpaths' so the new one will have no next, and `vpaths'
- will still be nil if P contains no existing directories. */
+ /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
+ will still be nil if P contains no existing directories. */
vpaths = 0;
/* Parse P. */
construct_vpath_list (gp, p);
/* Store the created path as the GPATH,
- and restore the old list of vpaths. */
+ and restore the old list of vpaths. */
gpaths = vpaths;
vpaths = save_vpaths;
}
@@ -148,7 +146,7 @@ build_vpath_lists ()
If DIRPATH is nil, remove all previous listings with the same
pattern. If PATTERN is nil, remove all VPATH listings. Existing
and readable directories that are not "." given in the DIRPATH
- separated by the path element separator (defined in make.h) are
+ separated by the path element separator (defined in makeint.h) are
loaded into the directory hash table if they are not there already
and put in the VPATH searchpath for the given pattern with trailing
slashes stripped off if present (and if the directory is not the
@@ -177,36 +175,36 @@ construct_vpath_list (char *pattern, char *dirpath)
lastpath = 0;
path = vpaths;
while (path != 0)
- {
- struct vpath *next = path->next;
-
- if (pattern == 0
- || (((percent == 0 && path->percent == 0)
- || (percent - pattern == path->percent - path->pattern))
- && streq (pattern, path->pattern)))
- {
- /* Remove it from the linked list. */
- if (lastpath == 0)
- vpaths = path->next;
- else
- lastpath->next = next;
-
- /* Free its unused storage. */
+ {
+ struct vpath *next = path->next;
+
+ if (pattern == 0
+ || (((percent == 0 && path->percent == 0)
+ || (percent - pattern == path->percent - path->pattern))
+ && streq (pattern, path->pattern)))
+ {
+ /* Remove it from the linked list. */
+ if (lastpath == 0)
+ vpaths = path->next;
+ else
+ lastpath->next = next;
+
+ /* Free its unused storage. */
/* MSVC erroneously warns without a cast here. */
- free ((void *)path->searchpath);
- free (path);
- }
- else
- lastpath = path;
+ free ((void *)path->searchpath);
+ free (path);
+ }
+ else
+ lastpath = path;
- path = next;
- }
+ path = next;
+ }
return;
}
#ifdef WINDOWS32
- convert_vpath_to_windows32(dirpath, ';');
+ convert_vpath_to_windows32 (dirpath, ';');
#endif
/* Skip over any initial separators and blanks. */
@@ -237,49 +235,49 @@ construct_vpath_list (char *pattern, char *dirpath)
v = p;
while (*p != '\0'
#if defined(HAVE_DOS_PATHS) && (PATH_SEPARATOR_CHAR == ':')
- /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
- also define HAVE_DOS_PATHS would like us to recognize
- colons after the drive letter in the likes of
- "D:/foo/bar:C:/xyzzy". */
- && (*p != PATH_SEPARATOR_CHAR
- || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
+ /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
+ also define HAVE_DOS_PATHS would like us to recognize
+ colons after the drive letter in the likes of
+ "D:/foo/bar:C:/xyzzy". */
+ && (*p != PATH_SEPARATOR_CHAR
+ || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
#else
- && *p != PATH_SEPARATOR_CHAR
+ && *p != PATH_SEPARATOR_CHAR
#endif
- && !isblank ((unsigned char)*p))
- ++p;
+ && !isblank ((unsigned char)*p))
+ ++p;
len = p - v;
/* Make sure there's no trailing slash,
- but still allow "/" as a directory. */
+ but still allow "/" as a directory. */
#if defined(__MSDOS__) || defined(__EMX__) || defined(HAVE_DOS_PATHS)
/* We need also to leave alone a trailing slash in "d:/". */
if (len > 3 || (len > 1 && v[1] != ':'))
#endif
if (len > 1 && p[-1] == '/')
- --len;
+ --len;
/* Put the directory on the vpath list. */
if (len > 1 || *v != '.')
- {
+ {
vpath[elem++] = dir_name (strcache_add_len (v, len));
if (len > maxvpath)
maxvpath = len;
- }
+ }
/* Skip over separators and blanks between entries. */
while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
- ++p;
+ ++p;
}
if (elem > 0)
{
struct vpath *path;
/* ELEM is now incremented one element past the last
- entry, to where the nil-pointer terminator goes.
- Usually this is maxelem - 1. If not, shrink down. */
+ entry, to where the nil-pointer terminator goes.
+ Usually this is maxelem - 1. If not, shrink down. */
if (elem < (maxelem - 1))
- vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
+ vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
/* Put the nil-pointer terminator on the end of the VPATH list. */
vpath[elem] = NULL;
@@ -308,12 +306,13 @@ construct_vpath_list (char *pattern, char *dirpath)
int
gpath_search (const char *file, unsigned int len)
{
- const char **gp;
-
if (gpaths && (len <= gpaths->maxlen))
- for (gp = gpaths->searchpath; *gp != NULL; ++gp)
- if (strneq (*gp, file, len) && (*gp)[len] == '\0')
- return 1;
+ {
+ const char **gp;
+ for (gp = gpaths->searchpath; *gp != NULL; ++gp)
+ if (strneq (*gp, file, len) && (*gp)[len] == '\0')
+ return 1;
+ }
return 0;
}
@@ -336,7 +335,7 @@ selective_vpath_search (struct vpath *path, const char *file,
const char **vpath = path->searchpath;
unsigned int maxvpath = path->maxlen;
unsigned int i;
- unsigned int flen, vlen, name_dplen;
+ unsigned int flen, name_dplen;
int exists = 0;
/* Find out if *FILE is a target.
@@ -357,7 +356,7 @@ selective_vpath_search (struct vpath *path, const char *file,
#ifdef HAVE_DOS_PATHS
/* We need the rightmost slash or backslash. */
{
- const char *bslash = strrchr(file, '\\');
+ const char *bslash = strrchr (file, '\\');
if (!n || bslash > n)
n = bslash;
}
@@ -376,54 +375,52 @@ selective_vpath_search (struct vpath *path, const char *file,
for (i = 0; vpath[i] != 0; ++i)
{
int exists_in_cache = 0;
- char *p;
-
- p = name;
+ char *p = name;
+ unsigned int vlen = strlen (vpath[i]);
/* Put the next VPATH entry into NAME at P and increment P past it. */
- vlen = strlen (vpath[i]);
memcpy (p, vpath[i], vlen);
p += vlen;
/* Add the directory prefix already in *FILE. */
if (name_dplen > 0)
- {
+ {
#ifndef VMS
- *p++ = '/';
+ *p++ = '/';
#endif
- memcpy (p, file, name_dplen);
- p += name_dplen;
- }
+ memcpy (p, file, name_dplen);
+ p += name_dplen;
+ }
#ifdef HAVE_DOS_PATHS
/* Cause the next if to treat backslash and slash alike. */
if (p != name && p[-1] == '\\' )
- p[-1] = '/';
+ p[-1] = '/';
#endif
/* Now add the name-within-directory at the end of NAME. */
#ifndef VMS
if (p != name && p[-1] != '/')
- {
- *p = '/';
- memcpy (p + 1, filename, flen + 1);
- }
+ {
+ *p = '/';
+ memcpy (p + 1, filename, flen + 1);
+ }
else
#endif
- memcpy (p, filename, flen + 1);
+ memcpy (p, filename, flen + 1);
/* Check if the file is mentioned in a makefile. If *FILE is not
- a target, that is enough for us to decide this file exists.
- If *FILE is a target, then the file must be mentioned in the
- makefile also as a target to be chosen.
+ a target, that is enough for us to decide this file exists.
+ If *FILE is a target, then the file must be mentioned in the
+ makefile also as a target to be chosen.
- The restriction that *FILE must not be a target for a
- makefile-mentioned file to be chosen was added by an
- inadequately commented change in July 1990; I am not sure off
- hand what problem it fixes.
+ The restriction that *FILE must not be a target for a
+ makefile-mentioned file to be chosen was added by an
+ inadequately commented change in July 1990; I am not sure off
+ hand what problem it fixes.
- In December 1993 I loosened this restriction to allow a file
- to be chosen if it is mentioned as a target in a makefile. This
- seem logical.
+ In December 1993 I loosened this restriction to allow a file
+ to be chosen if it is mentioned as a target in a makefile. This
+ seem logical.
Special handling for -W / -o: make sure we preserve the special
values here. Actually this whole thing is a little bogus: I think
@@ -433,8 +430,8 @@ selective_vpath_search (struct vpath *path, const char *file,
we use it.
*/
{
- struct file *f = lookup_file (name);
- if (f != 0)
+ struct file *f = lookup_file (name);
+ if (f != 0)
{
exists = not_target || f->is_target;
if (exists && mtime_ptr
@@ -447,41 +444,41 @@ selective_vpath_search (struct vpath *path, const char *file,
}
if (!exists)
- {
- /* That file wasn't mentioned in the makefile.
- See if it actually exists. */
+ {
+ /* That file wasn't mentioned in the makefile.
+ See if it actually exists. */
#ifdef VMS
- exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
+ exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
#else
- /* Clobber a null into the name at the last slash.
- Now NAME is the name of the directory to look in. */
- *p = '\0';
-
- /* We know the directory is in the hash table now because either
- construct_vpath_list or the code just above put it there.
- Does the file we seek exist in it? */
- exists_in_cache = exists = dir_file_exists_p (name, filename);
+ /* Clobber a null into the name at the last slash.
+ Now NAME is the name of the directory to look in. */
+ *p = '\0';
+
+ /* We know the directory is in the hash table now because either
+ construct_vpath_list or the code just above put it there.
+ Does the file we seek exist in it? */
+ exists_in_cache = exists = dir_file_exists_p (name, filename);
#endif
- }
+ }
if (exists)
- {
- /* The file is in the directory cache.
- Now check that it actually exists in the filesystem.
- The cache may be out of date. When vpath thinks a file
- exists, but stat fails for it, confusion results in the
- higher levels. */
+ {
+ /* The file is in the directory cache.
+ Now check that it actually exists in the filesystem.
+ The cache may be out of date. When vpath thinks a file
+ exists, but stat fails for it, confusion results in the
+ higher levels. */
- struct stat st;
+ struct stat st;
#ifndef VMS
- /* Put the slash back in NAME. */
- *p = '/';
+ /* Put the slash back in NAME. */
+ *p = '/';
#endif
- if (exists_in_cache) /* Makefile-mentioned file need not exist. */
- {
+ if (exists_in_cache) /* Makefile-mentioned file need not exist. */
+ {
int e;
EINTRLOOP (e, stat (name, &st)); /* Does it really exist? */
@@ -511,7 +508,7 @@ selective_vpath_search (struct vpath *path, const char *file,
*path_index = i;
return strcache_add_len (name, (p + 1 - name) + flen);
- }
+ }
}
return 0;
@@ -595,26 +592,26 @@ print_vpath_data_base (void)
printf ("vpath %s ", v->pattern);
for (i = 0; v->searchpath[i] != 0; ++i)
- printf ("%s%c", v->searchpath[i],
- v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
+ printf ("%s%c", v->searchpath[i],
+ v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
}
if (vpaths == 0)
- puts (_("# No `vpath' search paths."));
+ puts (_("# No 'vpath' search paths."));
else
- printf (_("\n# %u `vpath' search paths.\n"), nvpaths);
+ printf (_("\n# %u 'vpath' search paths.\n"), nvpaths);
if (general_vpath == 0)
- puts (_("\n# No general (`VPATH' variable) search path."));
+ puts (_("\n# No general ('VPATH' variable) search path."));
else
{
const char **path = general_vpath->searchpath;
unsigned int i;
- fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
+ fputs (_("\n# General ('VPATH' variable) search path:\n# "), stdout);
for (i = 0; path[i] != 0; ++i)
- printf ("%s%c", path[i],
- path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
+ printf ("%s%c", path[i],
+ path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
}
}