Changeset 900 for vendor/gnumake/current/vpath.c
- Timestamp:
- May 23, 2007, 5:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/vpath.c
r501 r900 30 30 { 31 31 struct vpath *next; /* Pointer to next struct in the linked list. */ 32 c har *pattern;/* The pattern to match. */33 c har *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. */ 34 34 unsigned int patlen;/* Length of the pattern. */ 35 c har **searchpath;/* Null-terminated list of directories. */35 const char **searchpath; /* Null-terminated list of directories. */ 36 36 unsigned int maxlen;/* Maximum length of any entry in the list. */ 37 37 }; … … 50 50 51 51 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. */ 57 56 58 57 void … … 91 90 /* Save the list of vpaths. */ 92 91 struct vpath *save_vpaths = vpaths; 92 char gp[] = "%"; 93 93 94 94 /* Empty `vpaths' so the new one will have no next, and `vpaths' … … 97 97 98 98 /* Parse P. */ 99 construct_vpath_list ( "%", p);99 construct_vpath_list (gp, p); 100 100 101 101 /* Store the created path as the general path, … … 123 123 /* Save the list of vpaths. */ 124 124 struct vpath *save_vpaths = vpaths; 125 char gp[] = "%"; 125 126 126 127 /* Empty `vpaths' so the new one will have no next, and `vpaths' … … 129 130 130 131 /* Parse P. */ 131 construct_vpath_list ( "%", p);132 construct_vpath_list (gp, p); 132 133 133 134 /* Store the created path as the GPATH, … … 161 162 construct_vpath_list (char *pattern, char *dirpath) 162 163 { 163 registerunsigned int elem;164 registerchar *p;165 registerchar **vpath;166 registerunsigned int maxvpath;164 unsigned int elem; 165 char *p; 166 const char **vpath; 167 unsigned int maxvpath; 167 168 unsigned int maxelem; 168 c har *percent = NULL;169 const char *percent = NULL; 169 170 170 171 if (pattern != 0) 171 { 172 pattern = xstrdup (pattern); 173 percent = find_percent (pattern); 174 } 172 percent = find_percent (pattern); 175 173 176 174 if (dirpath == 0) 177 175 { 178 176 /* Remove matching listings. */ 179 registerstruct vpath *path, *lastpath;177 struct vpath *path, *lastpath; 180 178 181 179 lastpath = 0; … … 197 195 198 196 /* Free its unused storage. */ 199 free (path->pattern); 200 free ((char *) path->searchpath); 201 free ((char *) path); 197 free (path->searchpath); 198 free (path); 202 199 } 203 200 else … … 207 204 } 208 205 209 if (pattern != 0)210 free (pattern);211 206 return; 212 207 } … … 215 210 convert_vpath_to_windows32(dirpath, ';'); 216 211 #endif 212 213 /* Skip over any initial separators and blanks. */ 214 while (*dirpath == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*dirpath)) 215 ++dirpath; 217 216 218 217 /* Figure out the maximum number of VPATH entries and put it in … … 226 225 ++maxelem; 227 226 228 vpath = (char **) xmalloc (maxelem * sizeof (char *));227 vpath = xmalloc (maxelem * sizeof (const char *)); 229 228 maxvpath = 0; 230 229 231 /* Skip over any initial separators and blanks. */230 elem = 0; 232 231 p = dirpath; 233 while (*p == PATH_SEPARATOR_CHAR || isblank ((unsigned char)*p))234 ++p;235 236 elem = 0;237 232 while (*p != '\0') 238 233 { … … 256 251 --len; 257 252 253 /* Put the directory on the vpath list. */ 258 254 if (len > 1 || *v != '.') 259 255 { 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; 275 259 } 276 260 … … 287 271 Usually this is maxelem - 1. If not, shrink down. */ 288 272 if (elem < (maxelem - 1)) 289 vpath = (char **) xrealloc ((char *) vpath, 290 (elem + 1) * sizeof (char *)); 273 vpath = xrealloc (vpath, (elem+1) * sizeof (const char *)); 291 274 292 275 /* Put the nil-pointer terminator on the end of the VPATH list. */ 293 vpath[elem] = 0;276 vpath[elem] = NULL; 294 277 295 278 /* 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)); 297 280 path->searchpath = vpath; 298 281 path->maxlen = maxvpath; … … 301 284 302 285 /* Set up the members. */ 303 path->pattern = pattern; 304 path->percent = percent; 286 path->pattern = strcache_add (pattern); 305 287 path->patlen = strlen (pattern); 288 path->percent = percent ? path->pattern + (percent - pattern) : 0; 306 289 } 307 290 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); 314 293 } 315 294 … … 319 298 320 299 int 321 gpath_search (c har *file, unsigned int len)300 gpath_search (const char *file, unsigned int len) 322 301 { 323 c har **gp;302 const char **gp; 324 303 325 304 if (gpaths && (len <= gpaths->maxlen)) … … 332 311 333 312 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 319 static const char * 320 selective_vpath_search (struct vpath *path, const char *file, 377 321 FILE_TIMESTAMP *mtime_ptr) 378 322 { 379 323 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; 383 328 unsigned int maxvpath = path->maxlen; 384 registerunsigned int i;329 unsigned int i; 385 330 unsigned int flen, vlen, name_dplen; 386 331 int exists = 0; … … 390 335 files that don't exist but are mentioned in a makefile. */ 391 336 { 392 struct file *f = lookup_file ( *file);337 struct file *f = lookup_file (file); 393 338 not_target = f == 0 || !f->is_target; 394 339 } 395 340 396 flen = strlen ( *file);341 flen = strlen (file); 397 342 398 343 /* 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 tothe 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, '/'); 403 348 #ifdef HAVE_DOS_PATHS 404 349 /* We need the rightmost slash or backslash. */ 405 350 { 406 c har *bslash = strrchr(*file, '\\');351 const char *bslash = strrchr(file, '\\'); 407 352 if (!n || bslash > n) 408 353 n = bslash; 409 354 } 410 355 #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; 413 358 if (name_dplen > 0) 414 359 flen -= name_dplen + 1; 415 360 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); 421 365 422 366 /* Try each VPATH entry. */ … … 424 368 { 425 369 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. */ 430 375 vlen = strlen (vpath[i]); 431 bcopy (vpath[i], n, vlen);432 n+= vlen;376 memcpy (p, vpath[i], vlen); 377 p += vlen; 433 378 434 379 /* Add the directory prefix already in *FILE. */ … … 436 381 { 437 382 #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; 442 387 } 443 388 444 389 #ifdef HAVE_DOS_PATHS 445 390 /* 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] = '/'; 448 393 #endif 449 394 /* Now add the name-within-directory at the end of NAME. */ 450 395 #ifndef VMS 451 if ( n != name && n[-1] != '/')396 if (p != name && p[-1] != '/') 452 397 { 453 * n= '/';454 bcopy (filename, n + 1, flen + 1);398 *p = '/'; 399 memcpy (p + 1, filename, flen + 1); 455 400 } 456 401 else 457 402 #endif 458 bcopy (filename, n, flen + 1);403 memcpy (p, filename, flen + 1); 459 404 460 405 /* Check if the file is mentioned in a makefile. If *FILE is not … … 503 448 /* Clobber a null into the name at the last slash. 504 449 Now NAME is the name of the directory to look in. */ 505 * n= '\0';450 *p = '\0'; 506 451 507 452 /* We know the directory is in the hash table now because either … … 524 469 #ifndef VMS 525 470 /* Put the slash back in NAME. */ 526 * n= '/';471 *p = '/'; 527 472 #endif 528 473 … … 547 492 548 493 /* 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 554 495 UNKNOWN_MTIME to indicate this. */ 555 496 if (mtime_ptr != 0) 556 497 *mtime_ptr = UNKNOWN_MTIME; 557 498 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); 560 502 } 561 503 } 562 504 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 514 const char * 515 vpath_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 564 544 return 0; 565 545 } … … 571 551 print_vpath_data_base (void) 572 552 { 573 registerunsigned int nvpaths;574 registerstruct vpath *v;553 unsigned int nvpaths; 554 struct vpath *v; 575 555 576 556 puts (_("\n# VPATH Search Paths\n")); … … 599 579 else 600 580 { 601 registerchar **path = general_vpath->searchpath;602 registerunsigned int i;581 const char **path = general_vpath->searchpath; 582 unsigned int i; 603 583 604 584 fputs (_("\n# General (`VPATH' variable) search path:\n# "), stdout);
Note:
See TracChangeset
for help on using the changeset viewer.