dir.c (138441) | dir.c (138455) |
---|---|
1/* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1988, 1989 by Adam de Boor 5 * Copyright (c) 1989 by Berkeley Softworks 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)dir.c 8.2 (Berkeley) 1/2/94 40 */ 41 42#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1988, 1989 by Adam de Boor 5 * Copyright (c) 1989 by Berkeley Softworks 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 26 unchanged lines hidden (view full) --- 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * @(#)dir.c 8.2 (Berkeley) 1/2/94 40 */ 41 42#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/usr.bin/make/dir.c 138441 2004-12-06 11:30:36Z harti $"); | 43__FBSDID("$FreeBSD: head/usr.bin/make/dir.c 138455 2004-12-06 15:20:12Z harti $"); |
44 45/*- 46 * dir.c -- 47 * Directory searching using wildcards and/or normal names... 48 * Used both for source wildcarding in the Makefile and for finding 49 * implicit sources. 50 * 51 * The interface for this module is: --- 133 unchanged lines hidden (view full) --- 185 * XXX: If this is done way early, there's a chance other rules will 186 * have already updated the file, in which case we'll update it again. 187 * Generally, there won't be two rules to update a single file, so this 188 * should be ok, but... 189 */ 190static Hash_Table mtimes; 191 192static int DirFindName(void *, void *); | 44 45/*- 46 * dir.c -- 47 * Directory searching using wildcards and/or normal names... 48 * Used both for source wildcarding in the Makefile and for finding 49 * implicit sources. 50 * 51 * The interface for this module is: --- 133 unchanged lines hidden (view full) --- 185 * XXX: If this is done way early, there's a chance other rules will 186 * have already updated the file, in which case we'll update it again. 187 * Generally, there won't be two rules to update a single file, so this 188 * should be ok, but... 189 */ 190static Hash_Table mtimes; 191 192static int DirFindName(void *, void *); |
193static int DirMatchFiles(char *, Path *, Lst); 194static void DirExpandCurly(char *, char *, Lst, Lst); 195static void DirExpandInt(char *, Lst, Lst); | |
196static int DirPrintWord(void *, void *); 197static int DirPrintDir(void *, void *); 198 199/*- 200 *----------------------------------------------------------------------- 201 * Dir_Init -- 202 * initialize things for this module 203 * --- 96 unchanged lines hidden (view full) --- 300 * Results: 301 * returns TRUE if the word should be expanded, FALSE otherwise 302 * 303 * Side Effects: 304 * none 305 *----------------------------------------------------------------------- 306 */ 307Boolean | 193static int DirPrintWord(void *, void *); 194static int DirPrintDir(void *, void *); 195 196/*- 197 *----------------------------------------------------------------------- 198 * Dir_Init -- 199 * initialize things for this module 200 * --- 96 unchanged lines hidden (view full) --- 297 * Results: 298 * returns TRUE if the word should be expanded, FALSE otherwise 299 * 300 * Side Effects: 301 * none 302 *----------------------------------------------------------------------- 303 */ 304Boolean |
308Dir_HasWildcards(char *name) | 305Dir_HasWildcards(const char *name) |
309{ | 306{ |
310 char *cp; | 307 const char *cp; |
311 int wild = 0, brace = 0, bracket = 0; 312 313 for (cp = name; *cp; cp++) { 314 switch (*cp) { 315 case '{': 316 brace++; 317 wild = 1; 318 break; --- 31 unchanged lines hidden (view full) --- 350 * Always returns 0 351 * 352 * Side Effects: 353 * File names are added to the expansions lst. The directory will be 354 * fully hashed when this is done. 355 *----------------------------------------------------------------------- 356 */ 357static int | 308 int wild = 0, brace = 0, bracket = 0; 309 310 for (cp = name; *cp; cp++) { 311 switch (*cp) { 312 case '{': 313 brace++; 314 wild = 1; 315 break; --- 31 unchanged lines hidden (view full) --- 347 * Always returns 0 348 * 349 * Side Effects: 350 * File names are added to the expansions lst. The directory will be 351 * fully hashed when this is done. 352 *----------------------------------------------------------------------- 353 */ 354static int |
358DirMatchFiles(char *pattern, Path *p, Lst expansions) | 355DirMatchFiles(const char *pattern, const Path *p, Lst expansions) |
359{ 360 Hash_Search search; /* Index into the directory's table */ 361 Hash_Entry *entry; /* Current entry in the table */ 362 Boolean isDot; /* TRUE if the directory being searched is . */ 363 364 isDot = (*p->name == '.' && p->name[1] == '\0'); 365 366 for (entry = Hash_EnumFirst(&p->files, &search); --- 31 unchanged lines hidden (view full) --- 398 * None. 399 * 400 * Side Effects: 401 * The given list is filled with the expansions... 402 * 403 *----------------------------------------------------------------------- 404 */ 405static void | 356{ 357 Hash_Search search; /* Index into the directory's table */ 358 Hash_Entry *entry; /* Current entry in the table */ 359 Boolean isDot; /* TRUE if the directory being searched is . */ 360 361 isDot = (*p->name == '.' && p->name[1] == '\0'); 362 363 for (entry = Hash_EnumFirst(&p->files, &search); --- 31 unchanged lines hidden (view full) --- 395 * None. 396 * 397 * Side Effects: 398 * The given list is filled with the expansions... 399 * 400 *----------------------------------------------------------------------- 401 */ 402static void |
406DirExpandCurly(char *word, char *brace, Lst path, Lst expansions) | 403DirExpandCurly(const char *word, const char *brace, Lst path, Lst expansions) |
407{ | 404{ |
408 char *end; /* Character after the closing brace */ 409 char *cp; /* Current position in brace clause */ 410 char *start; /* Start of current piece of brace clause */ | 405 const char *end; /* Character after the closing brace */ 406 const char *cp; /* Current position in brace clause */ 407 const char *start; /* Start of current piece of brace clause */ |
411 int bracelevel; /* Number of braces we've seen. If we see a right brace 412 * when this is 0, we've hit the end of the clause. */ 413 char *file; /* Current expansion */ 414 int otherLen; /* The length of the other pieces of the expansion 415 * (chars before and after the clause in 'word') */ 416 char *cp2; /* Pointer for checking for wildcards in 417 * expansion before calling Dir_Expand */ 418 --- 66 unchanged lines hidden (view full) --- 485 } else { 486 next: 487 free(file); 488 } 489 start = cp + 1; 490 } 491} 492 | 408 int bracelevel; /* Number of braces we've seen. If we see a right brace 409 * when this is 0, we've hit the end of the clause. */ 410 char *file; /* Current expansion */ 411 int otherLen; /* The length of the other pieces of the expansion 412 * (chars before and after the clause in 'word') */ 413 char *cp2; /* Pointer for checking for wildcards in 414 * expansion before calling Dir_Expand */ 415 --- 66 unchanged lines hidden (view full) --- 482 } else { 483 next: 484 free(file); 485 } 486 start = cp + 1; 487 } 488} 489 |
493 | |
494/*- 495 *----------------------------------------------------------------------- 496 * DirExpandInt -- 497 * Internal expand routine. Passes through the directories in the 498 * path one by one, calling DirMatchFiles for each. NOTE: This still 499 * doesn't handle patterns in directories... Works given a word to 500 * expand, a path to look in, and a list to store expansions in. 501 * 502 * Results: 503 * None. 504 * 505 * Side Effects: 506 * Things are added to the expansions list. 507 * 508 *----------------------------------------------------------------------- 509 */ 510static void | 490/*- 491 *----------------------------------------------------------------------- 492 * DirExpandInt -- 493 * Internal expand routine. Passes through the directories in the 494 * path one by one, calling DirMatchFiles for each. NOTE: This still 495 * doesn't handle patterns in directories... Works given a word to 496 * expand, a path to look in, and a list to store expansions in. 497 * 498 * Results: 499 * None. 500 * 501 * Side Effects: 502 * Things are added to the expansions list. 503 * 504 *----------------------------------------------------------------------- 505 */ 506static void |
511DirExpandInt(char *word, Lst path, Lst expansions) | 507DirExpandInt(const char *word, Lst path, Lst expansions) |
512{ 513 LstNode ln; /* Current node */ 514 Path *p; /* Directory in the node */ 515 516 if (Lst_Open(path) == SUCCESS) { 517 while ((ln = Lst_Next(path)) != NULL) { 518 p = Lst_Datum(ln); 519 DirMatchFiles(word, p, expansions); --- 746 unchanged lines hidden --- | 508{ 509 LstNode ln; /* Current node */ 510 Path *p; /* Directory in the node */ 511 512 if (Lst_Open(path) == SUCCESS) { 513 while ((ln = Lst_Next(path)) != NULL) { 514 p = Lst_Datum(ln); 515 DirMatchFiles(word, p, expansions); --- 746 unchanged lines hidden --- |