Changeset 3140 for trunk/src/kmk/vpath.c


Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/vpath.c

    r2592 r3140  
    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;
     
    9896      char gp[] = "%";
    9997
    100       /* Empty `vpaths' so the new one will have no next, and `vpaths'
    101         will still be nil if P contains no existing directories.  */
     98      /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
     99        will still be nil if P contains no existing directories.  */
    102100      vpaths = 0;
    103101
     
    106104
    107105      /* Store the created path as the general path,
    108         and restore the old list of vpaths.  */
     106        and restore the old list of vpaths.  */
    109107      general_vpath = vpaths;
    110108      vpaths = save_vpaths;
     
    135133      char gp[] = "%";
    136134
    137       /* Empty `vpaths' so the new one will have no next, and `vpaths'
    138         will still be nil if P contains no existing directories.  */
     135      /* Empty 'vpaths' so the new one will have no next, and 'vpaths'
     136        will still be nil if P contains no existing directories.  */
    139137      vpaths = 0;
    140138
     
    143141
    144142      /* Store the created path as the GPATH,
    145         and restore the old list of vpaths.  */
     143        and restore the old list of vpaths.  */
    146144      gpaths = vpaths;
    147145      vpaths = save_vpaths;
     
    161159   pattern.  If PATTERN is nil, remove all VPATH listings.  Existing
    162160   and readable directories that are not "." given in the DIRPATH
    163    separated by the path element separator (defined in make.h) are
     161   separated by the path element separator (defined in makeint.h) are
    164162   loaded into the directory hash table if they are not there already
    165163   and put in the VPATH searchpath for the given pattern with trailing
     
    190188      path = vpaths;
    191189      while (path != 0)
    192         {
    193           struct vpath *next = path->next;
    194 
    195           if (pattern == 0
    196               || (((percent == 0 && path->percent == 0)
    197                    || (percent - pattern == path->percent - path->pattern))
    198                   && streq (pattern, path->pattern)))
    199             {
    200               /* Remove it from the linked list.  */
    201               if (lastpath == 0)
    202                 vpaths = path->next;
    203               else
    204                 lastpath->next = next;
    205 
    206               /* Free its unused storage.  */
     190        {
     191          struct vpath *next = path->next;
     192
     193          if (pattern == 0
     194              || (((percent == 0 && path->percent == 0)
     195                   || (percent - pattern == path->percent - path->pattern))
     196                  && streq (pattern, path->pattern)))
     197            {
     198              /* Remove it from the linked list.  */
     199              if (lastpath == 0)
     200                vpaths = path->next;
     201              else
     202                lastpath->next = next;
     203
     204              /* Free its unused storage.  */
    207205              /* MSVC erroneously warns without a cast here.  */
    208               free ((void *)path->searchpath);
    209               free (path);
    210             }
    211           else
    212             lastpath = path;
    213 
    214           path = next;
    215         }
     206              free ((void *)path->searchpath);
     207              free (path);
     208            }
     209          else
     210            lastpath = path;
     211
     212          path = next;
     213        }
    216214
    217215      return;
     
    219217
    220218#ifdef WINDOWS32
    221     convert_vpath_to_windows32(dirpath, ';');
     219    convert_vpath_to_windows32 (dirpath, ';');
    222220#endif
    223221
    224222  /* Skip over any initial separators and blanks.  */
    225   while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath))
     223  while (STOP_SET (*dirpath, MAP_BLANK|MAP_PATHSEP))
    226224    ++dirpath;
    227225
     
    233231  p = dirpath;
    234232  while (*p != '\0')
    235     if (*p++ == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
     233    if (STOP_SET (*p++, MAP_BLANK|MAP_PATHSEP))
    236234      ++maxelem;
    237235
     
    250248      while (*p != '\0'
    251249#if defined(HAVE_DOS_PATHS) && (PATH_SEPARATOR_CHAR == ':')
    252              /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
    253                 also define HAVE_DOS_PATHS would like us to recognize
    254                 colons after the drive letter in the likes of
    255                 "D:/foo/bar:C:/xyzzy".  */
    256              && (*p != PATH_SEPARATOR_CHAR
    257                 || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
     250             /* Platforms whose PATH_SEPARATOR_CHAR is ':' and which
     251                also define HAVE_DOS_PATHS would like us to recognize
     252                colons after the drive letter in the likes of
     253                "D:/foo/bar:C:/xyzzy".  */
     254             && (*p != PATH_SEPARATOR_CHAR
     255                || (p == v + 1 && (p[1] == '/' || p[1] == '\\')))
    258256#else
    259              && *p != PATH_SEPARATOR_CHAR
    260 #endif
    261              && !isblank ((unsigned char)*p))
    262         ++p;
     257             && *p != PATH_SEPARATOR_CHAR
     258#endif
     259             && !ISBLANK (*p))
     260        ++p;
    263261
    264262      len = p - v;
    265263      /* Make sure there's no trailing slash,
    266         but still allow "/" as a directory.  */
     264        but still allow "/" as a directory.  */
    267265#if defined(__MSDOS__) || defined(__EMX__) || defined(HAVE_DOS_PATHS)
    268266      /* We need also to leave alone a trailing slash in "d:/".  */
     
    270268#endif
    271269      if (len > 1 && p[-1] == '/')
    272         --len;
     270        --len;
    273271
    274272      /* Put the directory on the vpath list.  */
    275273      if (len > 1 || *v != '.')
    276         {
     274        {
    277275          vpath[elem++] = dir_name (strcache_add_len (v, len));
    278276          if (len > maxvpath)
    279277            maxvpath = len;
    280         }
     278        }
    281279
    282280      /* Skip over separators and blanks between entries.  */
    283       while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
    284         ++p;
     281      while (STOP_SET (*p, MAP_BLANK|MAP_PATHSEP))
     282        ++p;
    285283    }
    286284
     
    289287      struct vpath *path;
    290288      /* ELEM is now incremented one element past the last
    291         entry, to where the nil-pointer terminator goes.
    292         Usually this is maxelem - 1.  If not, shrink down.  */
     289        entry, to where the nil-pointer terminator goes.
     290        Usually this is maxelem - 1.  If not, shrink down.  */
    293291      if (elem < (maxelem - 1))
    294         vpath = (const char **)xrealloc (vpath, (elem+1) * sizeof (const char *));
     292        vpath = xrealloc ((void *)vpath, (elem+1) * sizeof (const char *)); /* bird: Weird cast for msc. */
    295293
    296294      /* Put the nil-pointer terminator on the end of the VPATH list.  */
     
    322320gpath_search (const char *file, unsigned int len)
    323321{
    324   const char **gp;
    325 
    326322  if (gpaths && (len <= gpaths->maxlen))
    327     for (gp = gpaths->searchpath; *gp != NULL; ++gp)
    328       if (strneq (*gp, file, len) && (*gp)[len] == '\0')
    329         return 1;
     323    {
     324      const char **gp;
     325      for (gp = gpaths->searchpath; *gp != NULL; ++gp)
     326        if (strneq (*gp, file, len) && (*gp)[len] == '\0')
     327          return 1;
     328    }
    330329
    331330  return 0;
     
    351350  unsigned int maxvpath = path->maxlen;
    352351  unsigned int i;
    353   unsigned int flen, vlen, name_dplen;
     352  unsigned int flen, name_dplen;
    354353  int exists = 0;
    355354
     
    372371  /* We need the rightmost slash or backslash.  */
    373372  {
    374     const char *bslash = strrchr(file, '\\');
     373    const char *bslash = strrchr (file, '\\');
    375374    if (!n || bslash > n)
    376375      n = bslash;
     
    391390    {
    392391      int exists_in_cache = 0;
    393       char *p;
    394 
    395       p = name;
     392      char *p = name;
     393      unsigned int vlen = strlen (vpath[i]);
    396394
    397395      /* Put the next VPATH entry into NAME at P and increment P past it.  */
    398       vlen = strlen (vpath[i]);
    399396      memcpy (p, vpath[i], vlen);
    400397      p += vlen;
     
    402399      /* Add the directory prefix already in *FILE.  */
    403400      if (name_dplen > 0)
    404         {
     401        {
    405402#ifndef VMS
    406           *p++ = '/';
    407 #endif
    408           memcpy (p, file, name_dplen);
    409           p += name_dplen;
    410         }
     403          *p++ = '/';
     404#else
     405          /* VMS: if this is not in VMS format, treat as Unix format */
     406          if ((*p != ':') && (*p != ']') && (*p != '>'))
     407            *p++ = '/';
     408#endif
     409          memcpy (p, file, name_dplen);
     410          p += name_dplen;
     411        }
    411412
    412413#ifdef HAVE_DOS_PATHS
    413414      /* Cause the next if to treat backslash and slash alike.  */
    414415      if (p != name && p[-1] == '\\' )
    415         p[-1] = '/';
     416        p[-1] = '/';
    416417#endif
    417418      /* Now add the name-within-directory at the end of NAME.  */
    418419#ifndef VMS
    419420      if (p != name && p[-1] != '/')
    420         {
    421           *p = '/';
    422           memcpy (p + 1, filename, flen + 1);
    423         }
     421        {
     422          *p = '/';
     423          memcpy (p + 1, filename, flen + 1);
     424        }
    424425      else
    425 #endif
    426         memcpy (p, filename, flen + 1);
     426#else
     427      /* VMS use a slash if no directory terminator present */
     428      if (p != name && p[-1] != '/' && p[-1] != ':' &&
     429          p[-1] != '>' && p[-1] != ']')
     430        {
     431          *p = '/';
     432          memcpy (p + 1, filename, flen + 1);
     433        }
     434      else
     435#endif
     436        memcpy (p, filename, flen + 1);
    427437
    428438      /* Check if the file is mentioned in a makefile.  If *FILE is not
    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.
     439        a target, that is enough for us to decide this file exists.
     440        If *FILE is a target, then the file must be mentioned in the
     441        makefile also as a target to be chosen.
     442
     443        The restriction that *FILE must not be a target for a
     444        makefile-mentioned file to be chosen was added by an
     445        inadequately commented change in July 1990; I am not sure off
     446        hand what problem it fixes.
     447
     448        In December 1993 I loosened this restriction to allow a file
     449        to be chosen if it is mentioned as a target in a makefile.  This
     450        seem logical.
    441451
    442452         Special handling for -W / -o: make sure we preserve the special
     
    448458      */
    449459      {
    450         struct file *f = lookup_file (name);
    451         if (f != 0)
     460        struct file *f = lookup_file (name);
     461        if (f != 0)
    452462          {
    453463            exists = not_target || f->is_target;
     
    462472
    463473      if (!exists)
    464         {
    465           /* That file wasn't mentioned in the makefile.
    466              See if it actually exists.  */
     474        {
     475          /* That file wasn't mentioned in the makefile.
     476             See if it actually exists.  */
    467477
    468478#ifdef VMS
    469           exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
     479          /* For VMS syntax just use the original vpath */
     480          if (*p != '/')
     481            exists_in_cache = exists = dir_file_exists_p (vpath[i], filename);
     482          else
     483#endif
     484            {
     485              /* Clobber a null into the name at the last slash.
     486                 Now NAME is the name of the directory to look in.  */
     487              *p = '\0';
     488              /* We know the directory is in the hash table now because either
     489                 construct_vpath_list or the code just above put it there.
     490                 Does the file we seek exist in it?  */
     491              exists_in_cache = exists = dir_file_exists_p (name, filename);
     492            }
     493        }
     494
     495      if (exists)
     496        {
     497          /* The file is in the directory cache.
     498             Now check that it actually exists in the filesystem.
     499             The cache may be out of date.  When vpath thinks a file
     500             exists, but stat fails for it, confusion results in the
     501             higher levels.  */
     502
     503          struct stat st;
     504
     505#ifndef VMS
     506          /* Put the slash back in NAME.  */
     507          *p = '/';
    470508#else
    471           /* Clobber a null into the name at the last slash.
    472              Now NAME is the name of the directory to look in.  */
    473           *p = '\0';
    474 
    475           /* We know the directory is in the hash table now because either
    476              construct_vpath_list or the code just above put it there.
    477              Does the file we seek exist in it?  */
    478           exists_in_cache = exists = dir_file_exists_p (name, filename);
    479 #endif
    480         }
    481 
    482       if (exists)
    483         {
    484           /* The file is in the directory cache.
    485              Now check that it actually exists in the filesystem.
    486              The cache may be out of date.  When vpath thinks a file
    487              exists, but stat fails for it, confusion results in the
    488              higher levels.  */
    489 
    490           struct stat st;
    491 
    492 #ifndef VMS
    493           /* Put the slash back in NAME.  */
    494           *p = '/';
    495 #endif
    496 
    497           if (exists_in_cache)  /* Makefile-mentioned file need not exist.  */
    498             {
     509          /* If the slash was removed, put it back */
     510          if (*p == 0)
     511            *p = '/';
     512#endif
     513
     514          if (exists_in_cache)  /* Makefile-mentioned file need not exist.  */
     515            {
    499516              int e;
    500517
     
    526543
    527544          return strcache_add_len (name, (p + 1 - name) + flen);
    528         }
     545        }
    529546    }
    530547
     
    611628
    612629      for (i = 0; v->searchpath[i] != 0; ++i)
    613         printf ("%s%c", v->searchpath[i],
    614                 v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
     630        printf ("%s%c", v->searchpath[i],
     631                v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
    615632    }
    616633
    617634  if (vpaths == 0)
    618     puts (_("# No `vpath' search paths."));
     635    puts (_("# No 'vpath' search paths."));
    619636  else
    620     printf (_("\n# %u `vpath' search paths.\n"), nvpaths);
     637    printf (_("\n# %u 'vpath' search paths.\n"), nvpaths);
    621638
    622639  if (general_vpath == 0)
    623     puts (_("\n# No general (`VPATH' variable) search path."));
     640    puts (_("\n# No general ('VPATH' variable) search path."));
    624641  else
    625642    {
     
    627644      unsigned int i;
    628645
    629       fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
     646      fputs (_("\n# General ('VPATH' variable) search path:\n# "), stdout);
    630647
    631648      for (i = 0; path[i] != 0; ++i)
    632         printf ("%s%c", path[i],
    633                 path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
     649        printf ("%s%c", path[i],
     650                path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR);
    634651    }
    635652}
Note: See TracChangeset for help on using the changeset viewer.