Sat Oct 24 09:18:09 2020 UTC ()
make(1): inline DirFindName


(rillig)
diff -r1.172 -r1.173 src/usr.bin/make/dir.c

cvs diff -r1.172 -r1.173 src/usr.bin/make/dir.c (expand / switch to unified diff)

--- src/usr.bin/make/dir.c 2020/10/22 05:50:02 1.172
+++ src/usr.bin/make/dir.c 2020/10/24 09:18:09 1.173
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir.c,v 1.172 2020/10/22 05:50:02 rillig Exp $ */ 1/* $NetBSD: dir.c,v 1.173 2020/10/24 09:18:09 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor. 8 * Adam de Boor.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -125,27 +125,27 @@ @@ -125,27 +125,27 @@
125 */ 125 */
126 126
127#include <sys/types.h> 127#include <sys/types.h>
128#include <sys/stat.h> 128#include <sys/stat.h>
129 129
130#include <dirent.h> 130#include <dirent.h>
131#include <errno.h> 131#include <errno.h>
132 132
133#include "make.h" 133#include "make.h"
134#include "dir.h" 134#include "dir.h"
135#include "job.h" 135#include "job.h"
136 136
137/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */ 137/* "@(#)dir.c 8.2 (Berkeley) 1/2/94" */
138MAKE_RCSID("$NetBSD: dir.c,v 1.172 2020/10/22 05:50:02 rillig Exp $"); 138MAKE_RCSID("$NetBSD: dir.c,v 1.173 2020/10/24 09:18:09 rillig Exp $");
139 139
140#define DIR_DEBUG0(text) DEBUG0(DIR, text) 140#define DIR_DEBUG0(text) DEBUG0(DIR, text)
141#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1) 141#define DIR_DEBUG1(fmt, arg1) DEBUG1(DIR, fmt, arg1)
142#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2) 142#define DIR_DEBUG2(fmt, arg1, arg2) DEBUG2(DIR, fmt, arg1, arg2)
143 143
144/* 144/*
145 * A search path consists of a list of CachedDir structures. A CachedDir 145 * A search path consists of a list of CachedDir structures. A CachedDir
146 * has in it the name of the directory and a hash table of all the files 146 * has in it the name of the directory and a hash table of all the files
147 * in the directory. This is used to cut down on the number of system 147 * in the directory. This is used to cut down on the number of system
148 * calls necessary to find implicit dependents and their like. Since 148 * calls necessary to find implicit dependents and their like. Since
149 * these searches are made before any actions are taken, we need not 149 * these searches are made before any actions are taken, we need not
150 * worry about the directory changing due to creation commands. If this 150 * worry about the directory changing due to creation commands. If this
151 * hampers the style of some makefiles, they must be changed. 151 * hampers the style of some makefiles, they must be changed.
@@ -517,36 +517,26 @@ Dir_SetPATH(void) @@ -517,36 +517,26 @@ Dir_SetPATH(void)
517 if (dir == dot && hasLastDot) 517 if (dir == dot && hasLastDot)
518 continue; 518 continue;
519 Var_Append(".PATH", dir->name, VAR_GLOBAL); 519 Var_Append(".PATH", dir->name, VAR_GLOBAL);
520 } 520 }
521 521
522 if (hasLastDot) { 522 if (hasLastDot) {
523 if (dot) 523 if (dot)
524 Var_Append(".PATH", dot->name, VAR_GLOBAL); 524 Var_Append(".PATH", dot->name, VAR_GLOBAL);
525 if (cur) 525 if (cur)
526 Var_Append(".PATH", cur->name, VAR_GLOBAL); 526 Var_Append(".PATH", cur->name, VAR_GLOBAL);
527 } 527 }
528} 528}
529 529
530/* See if the CachedDir structure describes the same directory as the 
531 * given one by comparing their names. Called from Dir_AddDir via 
532 * Lst_Find when searching the list of open directories. */ 
533static Boolean 
534DirFindName(const void *p, const void *desiredName) 
535{ 
536 const CachedDir *dir = p; 
537 return strcmp(dir->name, desiredName) == 0; 
538} 
539 
540/* See if the given name has any wildcard characters in it. Be careful not to 530/* See if the given name has any wildcard characters in it. Be careful not to
541 * expand unmatching brackets or braces. 531 * expand unmatching brackets or braces.
542 * 532 *
543 * XXX: This code is not 100% correct ([^]] fails etc.). I really don't think 533 * XXX: This code is not 100% correct ([^]] fails etc.). I really don't think
544 * that make(1) should be expanding patterns, because then you have to set a 534 * that make(1) should be expanding patterns, because then you have to set a
545 * mechanism for escaping the expansion! 535 * mechanism for escaping the expansion!
546 * 536 *
547 * Input: 537 * Input:
548 * name name to check 538 * name name to check
549 * 539 *
550 * Results: 540 * Results:
551 * returns TRUE if the word should be expanded, FALSE otherwise 541 * returns TRUE if the word should be expanded, FALSE otherwise
552 */ 542 */
@@ -1498,29 +1488,33 @@ Dir_MTime(GNode *gn, Boolean recheck) @@ -1498,29 +1488,33 @@ Dir_MTime(GNode *gn, Boolean recheck)
1498 * added, or NULL to only add the directory to 1488 * added, or NULL to only add the directory to
1499 * openDirectories 1489 * openDirectories
1500 * name The name of the directory to add. 1490 * name The name of the directory to add.
1501 * The name is not normalized in any way. 1491 * The name is not normalized in any way.
1502 */ 1492 */
1503CachedDir * 1493CachedDir *
1504Dir_AddDir(SearchPath *path, const char *name) 1494Dir_AddDir(SearchPath *path, const char *name)
1505{ 1495{
1506 CachedDir *dir = NULL; /* the added directory */ 1496 CachedDir *dir = NULL; /* the added directory */
1507 DIR *d; 1497 DIR *d;
1508 struct dirent *dp; 1498 struct dirent *dp;
1509 1499
1510 if (path != NULL && strcmp(name, ".DOTLAST") == 0) { 1500 if (path != NULL && strcmp(name, ".DOTLAST") == 0) {
1511 SearchPathNode *ln = Lst_Find(path, DirFindName, name); 1501 SearchPathNode *ln;
1512 if (ln != NULL) 1502
1513 return ln->datum; 1503 for (ln = path->first; ln != NULL; ln = ln->next) {
 1504 CachedDir *pathDir = ln->datum;
 1505 if (strcmp(pathDir->name, name) == 0)
 1506 return pathDir;
 1507 }
1514 1508
1515 dotLast->refCount++; 1509 dotLast->refCount++;
1516 Lst_Prepend(path, dotLast); 1510 Lst_Prepend(path, dotLast);
1517 } 1511 }
1518 1512
1519 if (path != NULL) 1513 if (path != NULL)
1520 dir = OpenDirs_Find(&openDirs, name); 1514 dir = OpenDirs_Find(&openDirs, name);
1521 if (dir != NULL) { 1515 if (dir != NULL) {
1522 if (Lst_FindDatum(path, dir) == NULL) { 1516 if (Lst_FindDatum(path, dir) == NULL) {
1523 dir->refCount++; 1517 dir->refCount++;
1524 Lst_Append(path, dir); 1518 Lst_Append(path, dir);
1525 } 1519 }
1526 return dir; 1520 return dir;