Ignore:
Timestamp:
May 23, 2007, 5:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

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

    r501 r900  
    3030  {
    3131    struct vpath *next; /* Pointer to next struct in the linked list.  */
    32     char *pattern;      /* The pattern to match.  */
    33     char *percent;      /* Pointer into `pattern' where the `%' is.  */
     32    const char *pattern;/* The pattern to match.  */
     33    const char *percent;/* Pointer into `pattern' where the `%' is.  */
    3434    unsigned int patlen;/* Length of the pattern.  */
    35     char **searchpath;  /* Null-terminated list of directories.  */
     35    const char **searchpath; /* Null-terminated list of directories.  */
    3636    unsigned int maxlen;/* Maximum length of any entry in the list.  */
    3737  };
     
    5050
    5151
    52 static int selective_vpath_search PARAMS ((struct vpath *path, char **file, FILE_TIMESTAMP *mtime_ptr));
    53 
    54 /* Reverse the chain of selective VPATH lists so they
    55    will be searched in the order given in the makefiles
    56    and construct the list from the VPATH variable.  */
     52
     53/* Reverse the chain of selective VPATH lists so they will be searched in the
     54   order given in the makefiles and construct the list from the VPATH
     55   variable.  */
    5756
    5857void
     
    9190      /* Save the list of vpaths.  */
    9291      struct vpath *save_vpaths = vpaths;
     92      char gp[] = "%";
    9393
    9494      /* Empty `vpaths' so the new one will have no next, and `vpaths'
     
    9797
    9898      /* Parse P.  */
    99       construct_vpath_list ("%", p);
     99      construct_vpath_list (gp, p);
    100100
    101101      /* Store the created path as the general path,
     
    123123      /* Save the list of vpaths.  */
    124124      struct vpath *save_vpaths = vpaths;
     125      char gp[] = "%";
    125126
    126127      /* Empty `vpaths' so the new one will have no next, and `vpaths'
     
    129130
    130131      /* Parse P.  */
    131       construct_vpath_list ("%", p);
     132      construct_vpath_list (gp, p);
    132133
    133134      /* Store the created path as the GPATH,
     
    161162construct_vpath_list (char *pattern, char *dirpath)
    162163{
    163   register unsigned int elem;
    164   register char *p;
    165   register char **vpath;
    166   register unsigned int maxvpath;
     164  unsigned int elem;
     165  char *p;
     166  const char **vpath;
     167  unsigned int maxvpath;
    167168  unsigned int maxelem;
    168   char *percent = NULL;
     169  const char *percent = NULL;
    169170
    170171  if (pattern != 0)
    171     {
    172       pattern = xstrdup (pattern);
    173       percent = find_percent (pattern);
    174     }
     172    percent = find_percent (pattern);
    175173
    176174  if (dirpath == 0)
    177175    {
    178176      /* Remove matching listings.  */
    179       register struct vpath *path, *lastpath;
     177      struct vpath *path, *lastpath;
    180178
    181179      lastpath = 0;
     
    197195
    198196              /* Free its unused storage.  */
    199               free (path->pattern);
    200               free ((char *) path->searchpath);
    201               free ((char *) path);
     197              free (path->searchpath);
     198              free (path);
    202199            }
    203200          else
     
    207204        }
    208205
    209       if (pattern != 0)
    210         free (pattern);
    211206      return;
    212207    }
     
    215210    convert_vpath_to_windows32(dirpath, ';');
    216211#endif
     212
     213  /* Skip over any initial separators and blanks.  */
     214  while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath))
     215    ++dirpath;
    217216
    218217  /* Figure out the maximum number of VPATH entries and put it in
     
    226225      ++maxelem;
    227226
    228   vpath = (char **) xmalloc (maxelem * sizeof (char *));
     227  vpath = xmalloc (maxelem * sizeof (const char *));
    229228  maxvpath = 0;
    230229
    231   /* Skip over any initial separators and blanks.  */
     230  elem = 0;
    232231  p = dirpath;
    233   while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))
    234     ++p;
    235 
    236   elem = 0;
    237232  while (*p != '\0')
    238233    {
     
    256251        --len;
    257252
     253      /* Put the directory on the vpath list.  */
    258254      if (len > 1 || *v != '.')
    259255        {
    260           v = savestring (v, len);
    261 
    262           /* Verify that the directory actually exists.  */
    263 
    264           if (dir_file_exists_p (v, ""))
    265             {
    266               /* It does.  Put it in the list.  */
    267               vpath[elem++] = dir_name (v);
    268               free (v);
    269               if (len > maxvpath)
    270                 maxvpath = len;
    271             }
    272           else
    273             /* The directory does not exist.  Omit from the list.  */
    274             free (v);
     256          vpath[elem++] = dir_name (strcache_add_len (v, len));
     257          if (len > maxvpath)
     258            maxvpath = len;
    275259        }
    276260
     
    287271         Usually this is maxelem - 1.  If not, shrink down.  */
    288272      if (elem < (maxelem - 1))
    289         vpath = (char **) xrealloc ((char *) vpath,
    290                                     (elem + 1) * sizeof (char *));
     273        vpath = xrealloc (vpath, (elem+1) * sizeof (const char *));
    291274
    292275      /* Put the nil-pointer terminator on the end of the VPATH list.  */
    293       vpath[elem] = 0;
     276      vpath[elem] = NULL;
    294277
    295278      /* Construct the vpath structure and put it into the linked list.  */
    296       path = (struct vpath *) xmalloc (sizeof (struct vpath));
     279      path = xmalloc (sizeof (struct vpath));
    297280      path->searchpath = vpath;
    298281      path->maxlen = maxvpath;
     
    301284
    302285      /* Set up the members.  */
    303       path->pattern = pattern;
    304       path->percent = percent;
     286      path->pattern = strcache_add (pattern);
    305287      path->patlen = strlen (pattern);
     288      path->percent = percent ? path->pattern + (percent - pattern) : 0;
    306289    }
    307290  else
    308     {
    309       /* There were no entries, so free whatever space we allocated.  */
    310       free ((char *) vpath);
    311       if (pattern != 0)
    312         free (pattern);
    313     }
     291    /* There were no entries, so free whatever space we allocated.  */
     292    free (vpath);
    314293}
    315294
     
    319298
    320299int
    321 gpath_search (char *file, unsigned int len)
     300gpath_search (const char *file, unsigned int len)
    322301{
    323   char **gp;
     302  const char **gp;
    324303
    325304  if (gpaths && (len <= gpaths->maxlen))
     
    332311
    333312
    334 /* Search the VPATH list whose pattern matches *FILE for a directory
    335    where the name pointed to by FILE exists.  If it is found, we set *FILE to
    336    the newly malloc'd name of the existing file, *MTIME_PTR (if MTIME_PTR is
    337    not NULL) to its modtime (or zero if no stat call was done), and return 1.
    338    Otherwise we return 0.  */
    339 
    340 int
    341 vpath_search (char **file, FILE_TIMESTAMP *mtime_ptr)
    342 {
    343   register struct vpath *v;
    344 
    345   /* If there are no VPATH entries or FILENAME starts at the root,
    346      there is nothing we can do.  */
    347 
    348   if (**file == '/'
    349 #ifdef HAVE_DOS_PATHS
    350       || **file == '\\'
    351       || (*file)[1] == ':'
    352 #endif
    353       || (vpaths == 0 && general_vpath == 0))
    354     return 0;
    355 
    356   for (v = vpaths; v != 0; v = v->next)
    357     if (pattern_matches (v->pattern, v->percent, *file))
    358       if (selective_vpath_search (v, file, mtime_ptr))
    359         return 1;
    360 
    361   if (general_vpath != 0
    362       && selective_vpath_search (general_vpath, file, mtime_ptr))
    363     return 1;
    364 
    365   return 0;
    366 }
    367 
    368 
    369 /* Search the given VPATH list for a directory where the name pointed
    370    to by FILE exists.  If it is found, we set *FILE to the newly malloc'd
    371    name of the existing file, *MTIME_PTR (if MTIME_PTR is not NULL) to
    372    its modtime (or zero if no stat call was done), and we return 1.
    373    Otherwise we return 0.  */
    374 
    375 static int
    376 selective_vpath_search (struct vpath *path, char **file,
     313
     314/* Search the given VPATH list for a directory where the name pointed to by
     315   FILE exists.  If it is found, we return a cached name of the existing file
     316   and set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no
     317   stat call was done).  Otherwise we return NULL.  */
     318
     319static const char *
     320selective_vpath_search (struct vpath *path, const char *file,
    377321                        FILE_TIMESTAMP *mtime_ptr)
    378322{
    379323  int not_target;
    380   char *name, *n;
    381   char *filename;
    382   register char **vpath = path->searchpath;
     324  char *name;
     325  const char *n;
     326  const char *filename;
     327  const char **vpath = path->searchpath;
    383328  unsigned int maxvpath = path->maxlen;
    384   register unsigned int i;
     329  unsigned int i;
    385330  unsigned int flen, vlen, name_dplen;
    386331  int exists = 0;
     
    390335     files that don't exist but are mentioned in a makefile.  */
    391336  {
    392     struct file *f = lookup_file (*file);
     337    struct file *f = lookup_file (file);
    393338    not_target = f == 0 || !f->is_target;
    394339  }
    395340
    396   flen = strlen (*file);
     341  flen = strlen (file);
    397342
    398343  /* Split *FILE into a directory prefix and a name-within-directory.
    399      NAME_DPLEN gets the length of the prefix; FILENAME gets the
    400      pointer to the name-within-directory and FLEN is its length.  */
    401 
    402   n = strrchr (*file, '/');
     344     NAME_DPLEN gets the length of the prefix; FILENAME gets the pointer to
     345     the name-within-directory and FLEN is its length.  */
     346
     347  n = strrchr (file, '/');
    403348#ifdef HAVE_DOS_PATHS
    404349  /* We need the rightmost slash or backslash.  */
    405350  {
    406     char *bslash = strrchr(*file, '\\');
     351    const char *bslash = strrchr(file, '\\');
    407352    if (!n || bslash > n)
    408353      n = bslash;
    409354  }
    410355#endif
    411   name_dplen = n != 0 ? n - *file : 0;
    412   filename = name_dplen > 0 ? n + 1 : *file;
     356  name_dplen = n != 0 ? n - file : 0;
     357  filename = name_dplen > 0 ? n + 1 : file;
    413358  if (name_dplen > 0)
    414359    flen -= name_dplen + 1;
    415360
    416   /* Allocate enough space for the biggest VPATH entry,
    417      a slash, the directory prefix that came with *FILE,
    418      another slash (although this one may not always be
    419      necessary), the filename, and a null terminator.  */
    420   name = (char *) xmalloc (maxvpath + 1 + name_dplen + 1 + flen + 1);
     361  /* Get enough space for the biggest VPATH entry, a slash, the directory
     362     prefix that came with FILE, another slash (although this one may not
     363     always be necessary), the filename, and a null terminator.  */
     364  name = alloca (maxvpath + 1 + name_dplen + 1 + flen + 1);
    421365
    422366  /* Try each VPATH entry.  */
     
    424368    {
    425369      int exists_in_cache = 0;
    426 
    427       n = name;
    428 
    429       /* Put the next VPATH entry into NAME at N and increment N past it.  */
     370      char *p;
     371
     372      p = name;
     373
     374      /* Put the next VPATH entry into NAME at P and increment P past it.  */
    430375      vlen = strlen (vpath[i]);
    431       bcopy (vpath[i], n, vlen);
    432       n += vlen;
     376      memcpy (p, vpath[i], vlen);
     377      p += vlen;
    433378
    434379      /* Add the directory prefix already in *FILE.  */
     
    436381        {
    437382#ifndef VMS
    438           *n++ = '/';
    439 #endif
    440           bcopy (*file, n, name_dplen);
    441           n += name_dplen;
     383          *p++ = '/';
     384#endif
     385          memcpy (p, file, name_dplen);
     386          p += name_dplen;
    442387        }
    443388
    444389#ifdef HAVE_DOS_PATHS
    445390      /* Cause the next if to treat backslash and slash alike.  */
    446       if (n != name && n[-1] == '\\' )
    447         n[-1] = '/';
     391      if (p != name && p[-1] == '\\' )
     392        p[-1] = '/';
    448393#endif
    449394      /* Now add the name-within-directory at the end of NAME.  */
    450395#ifndef VMS
    451       if (n != name && n[-1] != '/')
     396      if (p != name && p[-1] != '/')
    452397        {
    453           *n = '/';
    454           bcopy (filename, n + 1, flen + 1);
     398          *p = '/';
     399          memcpy (p + 1, filename, flen + 1);
    455400        }
    456401      else
    457402#endif
    458         bcopy (filename, n, flen + 1);
     403        memcpy (p, filename, flen + 1);
    459404
    460405      /* Check if the file is mentioned in a makefile.  If *FILE is not
     
    503448          /* Clobber a null into the name at the last slash.
    504449             Now NAME is the name of the directory to look in.  */
    505           *n = '\0';
     450          *p = '\0';
    506451
    507452          /* We know the directory is in the hash table now because either
     
    524469#ifndef VMS
    525470          /* Put the slash back in NAME.  */
    526           *n = '/';
     471          *p = '/';
    527472#endif
    528473
     
    547492
    548493          /* We have found a file.
    549              Store the name we found into *FILE for the caller.  */
    550 
    551           *file = savestring (name, (n + 1 - name) + flen);
    552 
    553           /* If we get here and mtime_ptr hasn't been set, record
     494             If we get here and mtime_ptr hasn't been set, record
    554495             UNKNOWN_MTIME to indicate this.  */
    555496          if (mtime_ptr != 0)
    556497            *mtime_ptr = UNKNOWN_MTIME;
    557498
    558           free (name);
    559           return 1;
     499          /* Store the name we found and return it.  */
     500
     501          return strcache_add_len (name, (p + 1 - name) + flen);
    560502        }
    561503    }
    562504
    563   free (name);
     505  return 0;
     506}
     507
     508
     509/* Search the VPATH list whose pattern matches FILE for a directory where FILE
     510   exists.  If it is found, return the cached name of an existing file, and
     511   set *MTIME_PTR (if MTIME_PTR is not NULL) to its modtime (or zero if no
     512   stat call was done).  Otherwise we return 0.  */
     513
     514const char *
     515vpath_search (const char *file, FILE_TIMESTAMP *mtime_ptr)
     516{
     517  struct vpath *v;
     518
     519  /* If there are no VPATH entries or FILENAME starts at the root,
     520     there is nothing we can do.  */
     521
     522  if (file[0] == '/'
     523#ifdef HAVE_DOS_PATHS
     524      || file[0] == '\\' || file[1] == ':'
     525#endif
     526      || (vpaths == 0 && general_vpath == 0))
     527    return 0;
     528
     529  for (v = vpaths; v != 0; v = v->next)
     530    if (pattern_matches (v->pattern, v->percent, file))
     531      {
     532        const char *p = selective_vpath_search (v, file, mtime_ptr);
     533        if (p)
     534          return p;
     535      }
     536
     537  if (general_vpath != 0)
     538    {
     539      const char *p = selective_vpath_search (general_vpath, file, mtime_ptr);
     540      if (p)
     541        return p;
     542    }
     543
    564544  return 0;
    565545}
     
    571551print_vpath_data_base (void)
    572552{
    573   register unsigned int nvpaths;
    574   register struct vpath *v;
     553  unsigned int nvpaths;
     554  struct vpath *v;
    575555
    576556  puts (_("\n# VPATH Search Paths\n"));
     
    599579  else
    600580    {
    601       register char **path = general_vpath->searchpath;
    602       register unsigned int i;
     581      const char **path = general_vpath->searchpath;
     582      unsigned int i;
    603583
    604584      fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
Note: See TracChangeset for help on using the changeset viewer.