Changeset 3138 for vendor/gnumake/current/vpath.c
- Timestamp:
- Mar 12, 2018, 8:32:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/vpath.c
r2596 r3138 1 1 /* 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. 2 Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 19 #include "make .h"17 #include "makeint.h" 20 18 #include "filedef.h" 21 19 #include "variable.h" … … 29 27 struct vpath 30 28 { 31 struct vpath *next; 29 struct vpath *next; /* Pointer to next struct in the linked list. */ 32 30 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. */ 34 32 unsigned int patlen;/* Length of the pattern. */ 35 33 const char **searchpath; /* Null-terminated list of directories. */ … … 56 54 57 55 void 58 build_vpath_lists ( )56 build_vpath_lists (void) 59 57 { 60 58 register struct vpath *new = 0; … … 92 90 char gp[] = "%"; 93 91 94 /* Empty `vpaths' so the new one will have no next, and `vpaths'95 92 /* Empty 'vpaths' so the new one will have no next, and 'vpaths' 93 will still be nil if P contains no existing directories. */ 96 94 vpaths = 0; 97 95 … … 100 98 101 99 /* Store the created path as the general path, 102 100 and restore the old list of vpaths. */ 103 101 general_vpath = vpaths; 104 102 vpaths = save_vpaths; … … 125 123 char gp[] = "%"; 126 124 127 /* Empty `vpaths' so the new one will have no next, and `vpaths'128 125 /* Empty 'vpaths' so the new one will have no next, and 'vpaths' 126 will still be nil if P contains no existing directories. */ 129 127 vpaths = 0; 130 128 … … 133 131 134 132 /* Store the created path as the GPATH, 135 133 and restore the old list of vpaths. */ 136 134 gpaths = vpaths; 137 135 vpaths = save_vpaths; … … 151 149 pattern. If PATTERN is nil, remove all VPATH listings. Existing 152 150 and readable directories that are not "." given in the DIRPATH 153 separated by the path element separator (defined in make .h) are151 separated by the path element separator (defined in makeint.h) are 154 152 loaded into the directory hash table if they are not there already 155 153 and put in the VPATH searchpath for the given pattern with trailing … … 180 178 path = vpaths; 181 179 while (path != 0) 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 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. */ 197 195 /* MSVC erroneously warns without a cast here. */ 198 199 200 201 202 203 204 205 196 free ((void *)path->searchpath); 197 free (path); 198 } 199 else 200 lastpath = path; 201 202 path = next; 203 } 206 204 207 205 return; … … 209 207 210 208 #ifdef WINDOWS32 211 convert_vpath_to_windows32 (dirpath, ';');209 convert_vpath_to_windows32 (dirpath, ';'); 212 210 #endif 213 211 214 212 /* 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)) 216 214 ++dirpath; 217 215 … … 223 221 p = dirpath; 224 222 while (*p != '\0') 225 if ( *p++ == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))223 if (STOP_SET (*p++, MAP_BLANK|MAP_PATHSEP)) 226 224 ++maxelem; 227 225 … … 240 238 while (*p != '\0' 241 239 #if defined(HAVE_DOS_PATHS) && (PATH_SEPARATOR_CHAR == ':') 242 243 244 245 246 247 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] == '\\'))) 248 246 #else 249 250 #endif 251 && !isblank ((unsigned char)*p))252 247 && *p != PATH_SEPARATOR_CHAR 248 #endif 249 && !ISBLANK (*p)) 250 ++p; 253 251 254 252 len = p - v; 255 253 /* Make sure there's no trailing slash, 256 254 but still allow "/" as a directory. */ 257 255 #if defined(__MSDOS__) || defined(__EMX__) || defined(HAVE_DOS_PATHS) 258 256 /* We need also to leave alone a trailing slash in "d:/". */ … … 260 258 #endif 261 259 if (len > 1 && p[-1] == '/') 262 260 --len; 263 261 264 262 /* Put the directory on the vpath list. */ 265 263 if (len > 1 || *v != '.') 266 264 { 267 265 vpath[elem++] = dir_name (strcache_add_len (v, len)); 268 266 if (len > maxvpath) 269 267 maxvpath = len; 270 268 } 271 269 272 270 /* Skip over separators and blanks between entries. */ 273 while ( *p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))274 271 while (STOP_SET (*p, MAP_BLANK|MAP_PATHSEP)) 272 ++p; 275 273 } 276 274 … … 279 277 struct vpath *path; 280 278 /* ELEM is now incremented one element past the last 281 282 279 entry, to where the nil-pointer terminator goes. 280 Usually this is maxelem - 1. If not, shrink down. */ 283 281 if (elem < (maxelem - 1)) 284 282 vpath = xrealloc (vpath, (elem+1) * sizeof (const char *)); 285 283 286 284 /* Put the nil-pointer terminator on the end of the VPATH list. */ … … 312 310 gpath_search (const char *file, unsigned int len) 313 311 { 314 const char **gp;315 316 312 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 } 320 319 321 320 return 0; … … 341 340 unsigned int maxvpath = path->maxlen; 342 341 unsigned int i; 343 unsigned int flen, vlen,name_dplen;342 unsigned int flen, name_dplen; 344 343 int exists = 0; 345 344 … … 362 361 /* We need the rightmost slash or backslash. */ 363 362 { 364 const char *bslash = strrchr (file, '\\');363 const char *bslash = strrchr (file, '\\'); 365 364 if (!n || bslash > n) 366 365 n = bslash; … … 381 380 { 382 381 int exists_in_cache = 0; 383 char *p; 384 385 p = name; 382 char *p = name; 383 unsigned int vlen = strlen (vpath[i]); 386 384 387 385 /* Put the next VPATH entry into NAME at P and increment P past it. */ 388 vlen = strlen (vpath[i]);389 386 memcpy (p, vpath[i], vlen); 390 387 p += vlen; … … 392 389 /* Add the directory prefix already in *FILE. */ 393 390 if (name_dplen > 0) 394 391 { 395 392 #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 } 401 402 402 403 #ifdef HAVE_DOS_PATHS 403 404 /* Cause the next if to treat backslash and slash alike. */ 404 405 if (p != name && p[-1] == '\\' ) 405 406 p[-1] = '/'; 406 407 #endif 407 408 /* Now add the name-within-directory at the end of NAME. */ 408 409 #ifndef VMS 409 410 if (p != name && p[-1] != '/') 410 411 412 413 411 { 412 *p = '/'; 413 memcpy (p + 1, filename, flen + 1); 414 } 414 415 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); 417 427 418 428 /* Check if the file is mentioned in a makefile. If *FILE is not 419 420 421 422 423 424 425 426 427 428 429 430 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. 431 441 432 442 Special handling for -W / -o: make sure we preserve the special … … 438 448 */ 439 449 { 440 441 450 struct file *f = lookup_file (name); 451 if (f != 0) 442 452 { 443 453 exists = not_target || f->is_target; … … 452 462 453 463 if (!exists) 454 455 456 464 { 465 /* That file wasn't mentioned in the makefile. 466 See if it actually exists. */ 457 467 458 468 #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 = '/'; 460 498 #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 { 489 506 int e; 490 507 … … 516 533 517 534 return strcache_add_len (name, (p + 1 - name) + flen); 518 535 } 519 536 } 520 537 … … 601 618 602 619 for (i = 0; v->searchpath[i] != 0; ++i) 603 604 620 printf ("%s%c", v->searchpath[i], 621 v->searchpath[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR); 605 622 } 606 623 607 624 if (vpaths == 0) 608 puts (_("# No `vpath' search paths."));625 puts (_("# No 'vpath' search paths.")); 609 626 else 610 printf (_("\n# %u `vpath' search paths.\n"), nvpaths);627 printf (_("\n# %u 'vpath' search paths.\n"), nvpaths); 611 628 612 629 if (general_vpath == 0) 613 puts (_("\n# No general ( `VPATH' variable) search path."));630 puts (_("\n# No general ('VPATH' variable) search path.")); 614 631 else 615 632 { … … 617 634 unsigned int i; 618 635 619 fputs (_("\n# General ( `VPATH' variable) search path:\n# "), stdout);636 fputs (_("\n# General ('VPATH' variable) search path:\n# "), stdout); 620 637 621 638 for (i = 0; path[i] != 0; ++i) 622 623 639 printf ("%s%c", path[i], 640 path[i + 1] == 0 ? '\n' : PATH_SEPARATOR_CHAR); 624 641 } 625 642 }
Note:
See TracChangeset
for help on using the changeset viewer.