Ignore:
Timestamp:
Mar 12, 2018, 8:32:29 PM (7 years ago)
Author:
bird
Message:

Imported make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6) from https://git.savannah.gnu.org/git/make.git.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/vpath.c

    r2596 r3138  
    11/* Implementation of pattern-matching file search paths for GNU Make.
    2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1988-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
    2018#include "filedef.h"
    2119#include "variable.h"
     
    2927struct vpath
    3028  {
    31     struct vpath *next; /* Pointer to next struct in the linked list.  */
     29    struct vpath *next; /* Pointer to next struct in the linked list.  */
    3230    const char *pattern;/* The pattern to match.  */
    33     const char *percent;/* Pointer into `pattern' where the `%' is.  */
     31    const char *percent;/* Pointer into 'pattern' where the '%' is.  */
    3432    unsigned int patlen;/* Length of the pattern.  */
    3533    const char **searchpath; /* Null-terminated list of directories.  */
     
    5654
    5755void
    58 build_vpath_lists ()
     56build_vpath_lists (void)
    5957{
    6058  register struct vpath *new = 0;
     
    9290      char gp[] = "%";
    9391
    94       /* Empty `vpaths' so the new one will have no next, and `vpaths'
    95         will still be nil if P contains no existing directories.  */
     92      /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
     93        will still be nil if P contains no existing directories.  */
    9694      vpaths = 0;
    9795
     
    10098
    10199      /* Store the created path as the general path,
    102         and restore the old list of vpaths.  */
     100        and restore the old list of vpaths.  */
    103101      general_vpath = vpaths;
    104102      vpaths = save_vpaths;
     
    125123      char gp[] = "%";
    126124
    127       /* Empty `vpaths' so the new one will have no next, and `vpaths'
    128         will still be nil if P contains no existing directories.  */
     125      /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
     126        will still be nil if P contains no existing directories.  */
    129127      vpaths = 0;
    130128
     
    133131
    134132      /* Store the created path as the GPATH,
    135         and restore the old list of vpaths.  */
     133        and restore the old list of vpaths.  */
    136134      gpaths = vpaths;
    137135      vpaths = save_vpaths;
     
    151149   pattern.  If PATTERN is nil, remove all VPATH listings.  Existing
    152150   and readable directories that are not "." given in the DIRPATH
    153    separated by the path element separator (defined in make.h) are
     151   separated by the path element separator (defined in makeint.h) are
    154152   loaded into the directory hash table if they are not there already
    155153   and put in the VPATH searchpath for the given pattern with trailing
     
    180178      path = vpaths;
    181179      while (path != 0)
    182         {
    183           struct vpath *next = path->next;
    184 
    185           if (pattern == 0
    186               || (((percent == 0 && path->percent == 0)
    187                    || (percent - pattern == path->percent - path->pattern))
    188                   && streq (pattern, path->pattern)))
    189             {
    190               /* Remove it from the linked list.  */
    191               if (lastpath == 0)
    192                 vpaths = path->next;
    193               else
    194                 lastpath->next = next;
    195 
    196               /* Free its unused storage.  */
     180        {
     181          struct vpath *next = path->next;
     182
     183          if (pattern == 0
     184              || (((percent == 0 && path->percent == 0)
     185                   || (percent - pattern == path->percent - path->pattern))
     186                  && streq (pattern, path->pattern)))
     187            {
     188              /* Remove it from the linked list.  */
     189              if (lastpath == 0)
     190                vpaths = path->next;
     191              else
     192                lastpath->next = next;
     193
     194              /* Free its unused storage.  */
    197195              /* MSVC erroneously warns without a cast here.  */
    198               free ((void *)path->searchpath);
    199               free (path);
    200             }
    201           else
    202             lastpath = path;
    203 
    204           path = next;
    205         }
     196              free ((void *)path->searchpath);
     197              free (path);
     198            }
     199          else
     200            lastpath = path;
     201
     202          path = next;
     203        }
    206204
    207205      return;
     
    209207
    210208#ifdef WINDOWS32
    211     convert_vpath_to_windows32(dirpath, ';');
     209    convert_vpath_to_windows32 (dirpath, ';');
    212210#endif
    213211
    214212  /* Skip over any initial separators and blanks.  */
    215   while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath))
     213  while (STOP_SET (*dirpath, MAP_BLANK|MAP_PATHSEP))
    216214    ++dirpath;
    217215
     
    223221  p = dirpath;
    224222  while (*p != '\0')
    225     if (*p++ == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
     223    if (STOP_SET (*p++, MAP_BLANK|MAP_PATHSEP))
    226224      ++maxelem;
    227225
     
    240238      while (*p != '\0'
    241239#if defined(HAVE_DOS_PATHS) && (PATH_SEPARATOR_CHAR == ':')
    242              /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
    243                 also define HAVE_DOS_PATHS would like us to recognize
    244                 colons after the drive letter in the likes of
    245                 "D:/foo/bar:C:/xyzzy".  */
    246              && (*p != PATH_SEPARATOR_CHAR
    247                 || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
     240             /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
     241                also define HAVE_DOS_PATHS would like us to recognize
     242                colons after the drive letter in the likes of
     243                "D:/foo/bar:C:/xyzzy".  */
     244             && (*p != PATH_SEPARATOR_CHAR
     245                || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
    248246#else
    249              && *p != PATH_SEPARATOR_CHAR
    250 #endif
    251              && !isblank ((unsigned char)*p))
    252         ++p;
     247             && *p != PATH_SEPARATOR_CHAR
     248#endif
     249             && !ISBLANK (*p))
     250        ++p;
    253251
    254252      len = p - v;
    255253      /* Make sure there's no trailing slash,
    256         but still allow "/" as a directory.  */
     254        but still allow "/" as a directory.  */
    257255#if defined(__MSDOS__) || defined(__EMX__) || defined(HAVE_DOS_PATHS)
    258256      /* We need also to leave alone a trailing slash in "d:/".  */
     
    260258#endif
    261259      if (len > 1 && p[-1] == '/')
    262         --len;
     260        --len;
    263261
    264262      /* Put the directory on the vpath list.  */
    265263      if (len > 1 || *v != '.')
    266         {
     264        {
    267265          vpath[elem++] = dir_name (strcache_add_len (v, len));
    268266          if (len > maxvpath)
    269267            maxvpath = len;
    270         }
     268        }
    271269
    272270      /* Skip over separators and blanks between entries.  */
    273       while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
    274         ++p;
     271      while (STOP_SET (*p, MAP_BLANK|MAP_PATHSEP))
     272        ++p;
    275273    }
    276274
     
    279277      struct vpath *path;
    280278      /* ELEM is now incremented one element past the last
    281         entry, to where the nil-pointer terminator goes.
    282         Usually this is maxelem - 1.  If not, shrink down.  */
     279        entry, to where the nil-pointer terminator goes.
     280        Usually this is maxelem - 1.  If not, shrink down.  */
    283281      if (elem < (maxelem - 1))
    284         vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
     282        vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
    285283
    286284      /* Put the nil-pointer terminator on the end of the VPATH list.  */
     
    312310gpath_search (const char *file, unsigned int len)
    313311{
    314   const char **gp;
    315 
    316312  if (gpaths && (len <= gpaths->maxlen))
    317     for (gp = gpaths->searchpath; *gp != NULL; ++gp)
    318       if (strneq (*gp, file, len) && (*gp)[len] == '\0')
    319         return 1;
     313    {
     314      const char **gp;
     315      for (gp = gpaths->searchpath; *gp != NULL; ++gp)
     316        if (strneq (*gp, file, len) && (*gp)[len] == '\0')
     317          return 1;
     318    }
    320319
    321320  return 0;
     
    341340  unsigned int maxvpath = path->maxlen;
    342341  unsigned int i;
    343   unsigned int flen, vlen, name_dplen;
     342  unsigned int flen, name_dplen;
    344343  int exists = 0;
    345344
     
    362361  /* We need the rightmost slash or backslash.  */
    363362  {
    364     const char *bslash = strrchr(file, '\\');
     363    const char *bslash = strrchr (file, '\\');
    365364    if (!n || bslash > n)
    366365      n = bslash;
     
    381380    {
    382381      int exists_in_cache = 0;
    383       char *p;
    384 
    385       p = name;
     382      char *p = name;
     383      unsigned int vlen = strlen (vpath[i]);
    386384
    387385      /* Put the next VPATH entry into NAME at P and increment P past it.  */
    388       vlen = strlen (vpath[i]);
    389386      memcpy (p, vpath[i], vlen);
    390387      p += vlen;
     
    392389      /* Add the directory prefix already in *FILE.  */
    393390      if (name_dplen > 0)
    394         {
     391        {
    395392#ifndef VMS
    396           *p++ = '/';
    397 #endif
    398           memcpy (p, file, name_dplen);
    399           p += name_dplen;
    400         }
     393          *p++ = '/';
     394#else
     395          /* VMS: if this is not in VMS format, treat as Unix format */
     396          if ((*p != ':') && (*p != ']') && (*p != '>'))
     397            *p++ = '/';
     398#endif
     399          memcpy (p, file, name_dplen);
     400          p += name_dplen;
     401        }
    401402
    402403#ifdef HAVE_DOS_PATHS
    403404      /* Cause the next if to treat backslash and slash alike.  */
    404405      if (p != name && p[-1] == '\\' )
    405         p[-1] = '/';
     406        p[-1] = '/';
    406407#endif
    407408      /* Now add the name-within-directory at the end of NAME.  */
    408409#ifndef VMS
    409410      if (p != name && p[-1] != '/')
    410         {
    411           *p = '/';
    412           memcpy (p + 1, filename, flen + 1);
    413         }
     411        {
     412          *p = '/';
     413          memcpy (p + 1, filename, flen + 1);
     414        }
    414415      else
    415 #endif
    416         memcpy (p, filename, flen + 1);
     416#else
     417      /* VMS use a slash if no directory terminator present */
     418      if (p != name && p[-1] != '/' && p[-1] != ':' &&
     419          p[-1] != '>' && p[-1] != ']')
     420        {
     421          *p = '/';
     422          memcpy (p + 1, filename, flen + 1);
     423        }
     424      else
     425#endif
     426        memcpy (p, filename, flen + 1);
    417427
    418428      /* Check if the file is mentioned in a makefile.  If *FILE is not
    419         a target, that is enough for us to decide this file exists.
    420         If *FILE is a target, then the file must be mentioned in the
    421         makefile also as a target to be chosen.
    422 
    423         The restriction that *FILE must not be a target for a
    424         makefile-mentioned file to be chosen was added by an
    425         inadequately commented change in July 1990; I am not sure off
    426         hand what problem it fixes.
    427 
    428         In December 1993 I loosened this restriction to allow a file
    429         to be chosen if it is mentioned as a target in a makefile.  This
    430         seem logical.
     429        a target, that is enough for us to decide this file exists.
     430        If *FILE is a target, then the file must be mentioned in the
     431        makefile also as a target to be chosen.
     432
     433        The restriction that *FILE must not be a target for a
     434        makefile-mentioned file to be chosen was added by an
     435        inadequately commented change in July 1990; I am not sure off
     436        hand what problem it fixes.
     437
     438        In December 1993 I loosened this restriction to allow a file
     439        to be chosen if it is mentioned as a target in a makefile.  This
     440        seem logical.
    431441
    432442         Special handling for -W / -o: make sure we preserve the special
     
    438448      */
    439449      {
    440         struct file *f = lookup_file (name);
    441         if (f != 0)
     450        struct file *f = lookup_file (name);
     451        if (f != 0)
    442452          {
    443453            exists = not_target || f->is_target;
     
    452462
    453463      if (!exists)
    454         {
    455           /* That file wasn't mentioned in the makefile.
    456              See if it actually exists.  */
     464        {
     465          /* That file wasn't mentioned in the makefile.
     466             See if it actually exists.  */
    457467
    458468#ifdef VMS
    459           exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
     469          /* For VMS syntax just use the original vpath */
     470          if (*p != '/')
     471            exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
     472          else
     473#endif
     474            {
     475              /* Clobber a null into the name at the last slash.
     476                 Now NAME is the name of the directory to look in.  */
     477              *p = '\0';
     478              /* We know the directory is in the hash table now because either
     479                 construct_vpath_list or the code just above put it there.
     480                 Does the file we seek exist in it?  */
     481              exists_in_cache = exists = dir_file_exists_p (name, filename);
     482            }
     483        }
     484
     485      if (exists)
     486        {
     487          /* The file is in the directory cache.
     488             Now check that it actually exists in the filesystem.
     489             The cache may be out of date.  When vpath thinks a file
     490             exists, but stat fails for it, confusion results in the
     491             higher levels.  */
     492
     493          struct stat st;
     494
     495#ifndef VMS
     496          /* Put the slash back in NAME.  */
     497          *p = '/';
    460498#else
    461           /* Clobber a null into the name at the last slash.
    462              Now NAME is the name of the directory to look in.  */
    463           *p = '\0';
    464 
    465           /* We know the directory is in the hash table now because either
    466              construct_vpath_list or the code just above put it there.
    467              Does the file we seek exist in it?  */
    468           exists_in_cache = exists = dir_file_exists_p (name, filename);
    469 #endif
    470         }
    471 
    472       if (exists)
    473         {
    474           /* The file is in the directory cache.
    475              Now check that it actually exists in the filesystem.
    476              The cache may be out of date.  When vpath thinks a file
    477              exists, but stat fails for it, confusion results in the
    478              higher levels.  */
    479 
    480           struct stat st;
    481 
    482 #ifndef VMS
    483           /* Put the slash back in NAME.  */
    484           *p = '/';
    485 #endif
    486 
    487           if (exists_in_cache)  /* Makefile-mentioned file need not exist.  */
    488             {
     499          /* If the slash was removed, put it back */
     500          if (*p == 0)
     501            *p = '/';
     502#endif
     503
     504          if (exists_in_cache)  /* Makefile-mentioned file need not exist.  */
     505            {
    489506              int e;
    490507
     
    516533
    517534          return strcache_add_len (name, (p + 1 - name) + flen);
    518         }
     535        }
    519536    }
    520537
     
    601618
    602619      for (i = 0; v->searchpath[i] != 0; ++i)
    603         printf ("%s%c", v->searchpath[i],
    604                 v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
     620        printf ("%s%c", v->searchpath[i],
     621                v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
    605622    }
    606623
    607624  if (vpaths == 0)
    608     puts (_("# No `vpath' search paths."));
     625    puts (_("# No 'vpath' search paths."));
    609626  else
    610     printf (_("\n# %u `vpath' search paths.\n"), nvpaths);
     627    printf (_("\n# %u 'vpath' search paths.\n"), nvpaths);
    611628
    612629  if (general_vpath == 0)
    613     puts (_("\n# No general (`VPATH' variable) search path."));
     630    puts (_("\n# No general ('VPATH' variable) search path."));
    614631  else
    615632    {
     
    617634      unsigned int i;
    618635
    619       fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
     636      fputs (_("\n# General ('VPATH' variable) search path:\n# "), stdout);
    620637
    621638      for (i = 0; path[i] != 0; ++i)
    622         printf ("%s%c", path[i],
    623                 path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
     639        printf ("%s%c", path[i],
     640                path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
    624641    }
    625642}
Note: See TracChangeset for help on using the changeset viewer.