Sat Aug 29 12:39:32 2020 UTC ()
make(1): clean up comments in dir.c


(rillig)
diff -r1.123 -r1.124 src/usr.bin/make/dir.c

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

--- src/usr.bin/make/dir.c 2020/08/29 10:41:12 1.123
+++ src/usr.bin/make/dir.c 2020/08/29 12:39:32 1.124
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir.c,v 1.123 2020/08/29 10:41:12 rillig Exp $ */ 1/* $NetBSD: dir.c,v 1.124 2020/08/29 12:39:32 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.
@@ -60,34 +60,34 @@ @@ -60,34 +60,34 @@
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE. 69 * SUCH DAMAGE.
70 */ 70 */
71 71
72#ifndef MAKE_NATIVE 72#ifndef MAKE_NATIVE
73static char rcsid[] = "$NetBSD: dir.c,v 1.123 2020/08/29 10:41:12 rillig Exp $"; 73static char rcsid[] = "$NetBSD: dir.c,v 1.124 2020/08/29 12:39:32 rillig Exp $";
74#else 74#else
75#include <sys/cdefs.h> 75#include <sys/cdefs.h>
76#ifndef lint 76#ifndef lint
77#if 0 77#if 0
78static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94"; 78static char sccsid[] = "@(#)dir.c 8.2 (Berkeley) 1/2/94";
79#else 79#else
80__RCSID("$NetBSD: dir.c,v 1.123 2020/08/29 10:41:12 rillig Exp $"); 80__RCSID("$NetBSD: dir.c,v 1.124 2020/08/29 12:39:32 rillig Exp $");
81#endif 81#endif
82#endif /* not lint */ 82#endif /* not lint */
83#endif 83#endif
84 84
85/*- 85/*-
86 * dir.c -- 86 * dir.c --
87 * Directory searching using wildcards and/or normal names... 87 * Directory searching using wildcards and/or normal names...
88 * Used both for source wildcarding in the Makefile and for finding 88 * Used both for source wildcarding in the Makefile and for finding
89 * implicit sources. 89 * implicit sources.
90 * 90 *
91 * The interface for this module is: 91 * The interface for this module is:
92 * Dir_Init Initialize the module. 92 * Dir_Init Initialize the module.
93 * 93 *
@@ -387,76 +387,55 @@ Dir_InitCur(const char *cdname) @@ -387,76 +387,55 @@ Dir_InitCur(const char *cdname)
387 p->refCount += 1; 387 p->refCount += 1;
388 if (cur && cur != p) { 388 if (cur && cur != p) {
389 /* 389 /*
390 * We've been here before, cleanup. 390 * We've been here before, cleanup.
391 */ 391 */
392 cur->refCount -= 1; 392 cur->refCount -= 1;
393 Dir_Destroy(cur); 393 Dir_Destroy(cur);
394 } 394 }
395 cur = p; 395 cur = p;
396 } 396 }
397 } 397 }
398} 398}
399 399
400/*- 400/* (Re)initialize "dot" (current/object directory) path hash.
401 *----------------------------------------------------------------------- 401 * Some directories may be opened. */
402 * Dir_InitDot -- 
403 * (re)initialize "dot" (current/object directory) path hash 
404 * 
405 * Results: 
406 * none 
407 * 
408 * Side Effects: 
409 * some directories may be opened. 
410 *----------------------------------------------------------------------- 
411 */ 
412void 402void
413Dir_InitDot(void) 403Dir_InitDot(void)
414{ 404{
415 if (dot != NULL) { 405 if (dot != NULL) {
416 LstNode ln; 406 LstNode ln;
417 407
418 /* Remove old entry from openDirectories, but do not destroy. */ 408 /* Remove old entry from openDirectories, but do not destroy. */
419 ln = Lst_Member(openDirectories, dot); 409 ln = Lst_Member(openDirectories, dot);
420 Lst_Remove(openDirectories, ln); 410 Lst_Remove(openDirectories, ln);
421 } 411 }
422 412
423 dot = Dir_AddDir(NULL, "."); 413 dot = Dir_AddDir(NULL, ".");
424 414
425 if (dot == NULL) { 415 if (dot == NULL) {
426 Error("Cannot open `.' (%s)", strerror(errno)); 416 Error("Cannot open `.' (%s)", strerror(errno));
427 exit(1); 417 exit(1);
428 } 418 }
429 419
430 /* 420 /*
431 * We always need to have dot around, so we increment its reference count 421 * We always need to have dot around, so we increment its reference count
432 * to make sure it's not destroyed. 422 * to make sure it's not destroyed.
433 */ 423 */
434 dot->refCount += 1; 424 dot->refCount += 1;
435 Dir_SetPATH(); /* initialize */ 425 Dir_SetPATH(); /* initialize */
436} 426}
437 427
438/*- 428/* Clean up things for this module. */
439 *----------------------------------------------------------------------- 
440 * Dir_End -- 
441 * cleanup things for this module 
442 * 
443 * Results: 
444 * none 
445 * 
446 * Side Effects: 
447 * none 
448 *----------------------------------------------------------------------- 
449 */ 
450void 429void
451Dir_End(void) 430Dir_End(void)
452{ 431{
453#ifdef CLEANUP 432#ifdef CLEANUP
454 if (cur) { 433 if (cur) {
455 cur->refCount -= 1; 434 cur->refCount -= 1;
456 Dir_Destroy(cur); 435 Dir_Destroy(cur);
457 } 436 }
458 dot->refCount -= 1; 437 dot->refCount -= 1;
459 dotLast->refCount -= 1; 438 dotLast->refCount -= 1;
460 Dir_Destroy(dotLast); 439 Dir_Destroy(dotLast);
461 Dir_Destroy(dot); 440 Dir_Destroy(dot);
462 Dir_ClearPath(dirSearchPath); 441 Dir_ClearPath(dirSearchPath);
@@ -514,45 +493,38 @@ Dir_SetPATH(void) @@ -514,45 +493,38 @@ Dir_SetPATH(void)
514 } 493 }
515 Lst_Close(dirSearchPath); 494 Lst_Close(dirSearchPath);
516} 495}
517 496
518/* See if the Path structure describes the same directory as the 497/* See if the Path structure describes the same directory as the
519 * given one by comparing their names. Called from Dir_AddDir via 498 * given one by comparing their names. Called from Dir_AddDir via
520 * Lst_Find when searching the list of open directories. */ 499 * Lst_Find when searching the list of open directories. */
521static Boolean 500static Boolean
522DirFindName(const void *p, const void *desiredName) 501DirFindName(const void *p, const void *desiredName)
523{ 502{
524 return strcmp(((const Path *)p)->name, desiredName) == 0; 503 return strcmp(((const Path *)p)->name, desiredName) == 0;
525} 504}
526 505
527/*- 506/* See if the given name has any wildcard characters in it. Be careful not to
528 *----------------------------------------------------------------------- 507 * expand unmatching brackets or braces.
529 * Dir_HasWildcards -- 508 *
530 * see if the given name has any wildcard characters in it 509 * XXX: This code is not 100% correct ([^]] fails etc.). I really don't think
531 * be careful not to expand unmatching brackets or braces. 510 * that make(1) should be expanding patterns, because then you have to set a
532 * XXX: This code is not 100% correct. ([^]] fails etc.) 511 * mechanism for escaping the expansion!
533 * I really don't think that make(1) should be expanding 
534 * patterns, because then you have to set a mechanism for 
535 * escaping the expansion! 
536 * 512 *
537 * Input: 513 * Input:
538 * name name to check 514 * name name to check
539 * 515 *
540 * Results: 516 * Results:
541 * returns TRUE if the word should be expanded, FALSE otherwise 517 * returns TRUE if the word should be expanded, FALSE otherwise
542 * 
543 * Side Effects: 
544 * none 
545 *----------------------------------------------------------------------- 
546 */ 518 */
547Boolean 519Boolean
548Dir_HasWildcards(char *name) 520Dir_HasWildcards(char *name)
549{ 521{
550 char *cp; 522 char *cp;
551 int wild = 0, brace = 0, bracket = 0; 523 int wild = 0, brace = 0, bracket = 0;
552 524
553 for (cp = name; *cp; cp++) { 525 for (cp = name; *cp; cp++) {
554 switch (*cp) { 526 switch (*cp) {
555 case '{': 527 case '{':
556 brace++; 528 brace++;
557 wild = 1; 529 wild = 1;
558 break; 530 break;