Wed Aug 26 22:55:46 2020 UTC ()
make(1): add stricter variants for remaining Lst functions

In most cases the Lst functions are only called when the arguments are
indeed valid.  It's not guaranteed though, therefore each function call
needs to be analyzed and converted individually.

While here, remove a few statements that were only useful when the Lst
functions handled circular lists.


(rillig)
diff -r1.96 -r1.97 src/usr.bin/make/arch.c
diff -r1.110 -r1.111 src/usr.bin/make/dir.c
diff -r1.41 -r1.42 src/usr.bin/make/lst.c
diff -r1.43 -r1.44 src/usr.bin/make/lst.h
diff -r1.313 -r1.314 src/usr.bin/make/main.c
diff -r1.123 -r1.124 src/usr.bin/make/make.c
diff -r1.99 -r1.100 src/usr.bin/make/meta.c
diff -r1.262 -r1.263 src/usr.bin/make/parse.c
diff -r1.115 -r1.116 src/usr.bin/make/suff.c
diff -r1.72 -r1.73 src/usr.bin/make/targ.c

cvs diff -r1.96 -r1.97 src/usr.bin/make/arch.c (expand / switch to unified diff)

--- src/usr.bin/make/arch.c 2020/08/23 18:59:01 1.96
+++ src/usr.bin/make/arch.c 2020/08/26 22:55:46 1.97
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $ */ 1/* $NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $"; 72static char rcsid[] = "$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94"; 77static char sccsid[] = "@(#)arch.c 8.2 (Berkeley) 1/2/94";
78#else 78#else
79__RCSID("$NetBSD: arch.c,v 1.96 2020/08/23 18:59:01 rillig Exp $"); 79__RCSID("$NetBSD: arch.c,v 1.97 2020/08/26 22:55:46 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * arch.c -- 85 * arch.c --
86 * Functions to manipulate libraries, archives and their members. 86 * Functions to manipulate libraries, archives and their members.
87 * 87 *
88 * Once again, cacheing/hashing comes into play in the manipulation 88 * Once again, cacheing/hashing comes into play in the manipulation
89 * of archives. The first time an archive is referenced, all of its members' 89 * of archives. The first time an archive is referenced, all of its members'
90 * headers are read and hashed and the archive closed again. All hashed 90 * headers are read and hashed and the archive closed again. All hashed
91 * archives are kept on a list which is searched each time an archive member 91 * archives are kept on a list which is searched each time an archive member
92 * is referenced. 92 * is referenced.
@@ -381,27 +381,27 @@ Arch_ParseArchive(char **linePtr, Lst no @@ -381,27 +381,27 @@ Arch_ParseArchive(char **linePtr, Lst no
381 } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) { 381 } else if (Arch_ParseArchive(&sacrifice, nodeLst, ctxt)!=SUCCESS) {
382 /* 382 /*
383 * Error in nested call -- free buffer and return FAILURE 383 * Error in nested call -- free buffer and return FAILURE
384 * ourselves. 384 * ourselves.
385 */ 385 */
386 free(buf); 386 free(buf);
387 return FAILURE; 387 return FAILURE;
388 } 388 }
389 /* 389 /*
390 * Free buffer and continue with our work. 390 * Free buffer and continue with our work.
391 */ 391 */
392 free(buf); 392 free(buf);
393 } else if (Dir_HasWildcards(memName)) { 393 } else if (Dir_HasWildcards(memName)) {
394 Lst members = Lst_Init(); 394 Lst members = Lst_Init();
395 Buffer nameBuf; 395 Buffer nameBuf;
396 396
397 Buf_Init(&nameBuf, 0); 397 Buf_Init(&nameBuf, 0);
398 Dir_Expand(memName, dirSearchPath, members); 398 Dir_Expand(memName, dirSearchPath, members);
399 while (!Lst_IsEmpty(members)) { 399 while (!Lst_IsEmpty(members)) {
400 char *member = Lst_DequeueS(members); 400 char *member = Lst_DequeueS(members);
401 401
402 Buf_Empty(&nameBuf); 402 Buf_Empty(&nameBuf);
403 Buf_AddStr(&nameBuf, libName); 403 Buf_AddStr(&nameBuf, libName);
404 Buf_AddStr(&nameBuf, "("); 404 Buf_AddStr(&nameBuf, "(");
405 Buf_AddStr(&nameBuf, member); 405 Buf_AddStr(&nameBuf, member);
406 Buf_AddStr(&nameBuf, ")"); 406 Buf_AddStr(&nameBuf, ")");
407 free(member); 407 free(member);
@@ -412,27 +412,27 @@ Arch_ParseArchive(char **linePtr, Lst no @@ -412,27 +412,27 @@ Arch_ParseArchive(char **linePtr, Lst no
412 return FAILURE; 412 return FAILURE;
413 } else { 413 } else {
414 /* 414 /*
415 * We've found the node, but have to make sure the rest of 415 * We've found the node, but have to make sure the rest of
416 * the world knows it's an archive member, without having 416 * the world knows it's an archive member, without having
417 * to constantly check for parentheses, so we type the 417 * to constantly check for parentheses, so we type the
418 * thing with the OP_ARCHV bit before we place it on the 418 * thing with the OP_ARCHV bit before we place it on the
419 * end of the provided list. 419 * end of the provided list.
420 */ 420 */
421 gn->type |= OP_ARCHV; 421 gn->type |= OP_ARCHV;
422 Lst_AppendS(nodeLst, gn); 422 Lst_AppendS(nodeLst, gn);
423 } 423 }
424 } 424 }
425 Lst_Destroy(members, NULL); 425 Lst_FreeS(members);
426 Buf_Destroy(&nameBuf, TRUE); 426 Buf_Destroy(&nameBuf, TRUE);
427 } else { 427 } else {
428 Buffer nameBuf; 428 Buffer nameBuf;
429 429
430 Buf_Init(&nameBuf, 0); 430 Buf_Init(&nameBuf, 0);
431 Buf_AddStr(&nameBuf, libName); 431 Buf_AddStr(&nameBuf, libName);
432 Buf_AddStr(&nameBuf, "("); 432 Buf_AddStr(&nameBuf, "(");
433 Buf_AddStr(&nameBuf, memName); 433 Buf_AddStr(&nameBuf, memName);
434 Buf_AddStr(&nameBuf, ")"); 434 Buf_AddStr(&nameBuf, ")");
435 435
436 gn = Targ_FindNode(Buf_GetAll(&nameBuf, NULL), TARG_CREATE); 436 gn = Targ_FindNode(Buf_GetAll(&nameBuf, NULL), TARG_CREATE);
437 Buf_Destroy(&nameBuf, TRUE); 437 Buf_Destroy(&nameBuf, TRUE);
438 if (gn == NULL) { 438 if (gn == NULL) {
@@ -1278,65 +1278,39 @@ Arch_LibOODate(GNode *gn) @@ -1278,65 +1278,39 @@ Arch_LibOODate(GNode *gn)
1278 */ 1278 */
1279 if (DEBUG(ARCH) || DEBUG(MAKE)) { 1279 if (DEBUG(ARCH) || DEBUG(MAKE)) {
1280 fprintf(debug_file, "No t.o.c...."); 1280 fprintf(debug_file, "No t.o.c....");
1281 } 1281 }
1282 oodate = TRUE; 1282 oodate = TRUE;
1283 } 1283 }
1284#else 1284#else
1285 oodate = FALSE; 1285 oodate = FALSE;
1286#endif 1286#endif
1287 } 1287 }
1288 return oodate; 1288 return oodate;
1289} 1289}
1290 1290
1291/*- 1291/* Initialize things for this module. */
1292 *----------------------------------------------------------------------- 
1293 * Arch_Init -- 
1294 * Initialize things for this module. 
1295 * 
1296 * Results: 
1297 * None. 
1298 * 
1299 * Side Effects: 
1300 * The 'archives' list is initialized. 
1301 * 
1302 *----------------------------------------------------------------------- 
1303 */ 
1304void 1292void
1305Arch_Init(void) 1293Arch_Init(void)
1306{ 1294{
1307 archives = Lst_Init(); 1295 archives = Lst_Init();
1308} 1296}
1309 1297
1310 1298/* Clean up things for this module. */
1311 
1312/*- 
1313 *----------------------------------------------------------------------- 
1314 * Arch_End -- 
1315 * Cleanup things for this module. 
1316 * 
1317 * Results: 
1318 * None. 
1319 * 
1320 * Side Effects: 
1321 * The 'archives' list is freed 
1322 * 
1323 *----------------------------------------------------------------------- 
1324 */ 
1325void 1299void
1326Arch_End(void) 1300Arch_End(void)
1327{ 1301{
1328#ifdef CLEANUP 1302#ifdef CLEANUP
1329 Lst_Destroy(archives, ArchFree); 1303 Lst_DestroyS(archives, ArchFree);
1330#endif 1304#endif
1331} 1305}
1332 1306
1333/*- 1307/*-
1334 *----------------------------------------------------------------------- 1308 *-----------------------------------------------------------------------
1335 * Arch_IsLib -- 1309 * Arch_IsLib --
1336 * Check if the node is a library 1310 * Check if the node is a library
1337 * 1311 *
1338 * Results: 1312 * Results:
1339 * True or False. 1313 * True or False.
1340 * 1314 *
1341 * Side Effects: 1315 * Side Effects:
1342 * None. 1316 * None.

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

--- src/usr.bin/make/dir.c 2020/08/23 16:58:02 1.110
+++ src/usr.bin/make/dir.c 2020/08/26 22:55:46 1.111
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir.c,v 1.110 2020/08/23 16:58:02 rillig Exp $ */ 1/* $NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $"; 73static char rcsid[] = "$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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.110 2020/08/23 16:58:02 rillig Exp $"); 80__RCSID("$NetBSD: dir.c,v 1.111 2020/08/26 22:55:46 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 *
@@ -451,29 +451,29 @@ Dir_InitDot(void) @@ -451,29 +451,29 @@ Dir_InitDot(void)
451void 451void
452Dir_End(void) 452Dir_End(void)
453{ 453{
454#ifdef CLEANUP 454#ifdef CLEANUP
455 if (cur) { 455 if (cur) {
456 cur->refCount -= 1; 456 cur->refCount -= 1;
457 Dir_Destroy(cur); 457 Dir_Destroy(cur);
458 } 458 }
459 dot->refCount -= 1; 459 dot->refCount -= 1;
460 dotLast->refCount -= 1; 460 dotLast->refCount -= 1;
461 Dir_Destroy(dotLast); 461 Dir_Destroy(dotLast);
462 Dir_Destroy(dot); 462 Dir_Destroy(dot);
463 Dir_ClearPath(dirSearchPath); 463 Dir_ClearPath(dirSearchPath);
464 Lst_Destroy(dirSearchPath, NULL); 464 Lst_FreeS(dirSearchPath);
465 Dir_ClearPath(openDirectories); 465 Dir_ClearPath(openDirectories);
466 Lst_Destroy(openDirectories, NULL); 466 Lst_FreeS(openDirectories);
467 Hash_DeleteTable(&mtimes); 467 Hash_DeleteTable(&mtimes);
468#endif 468#endif
469} 469}
470 470
471/* 471/*
472 * We want ${.PATH} to indicate the order in which we will actually 472 * We want ${.PATH} to indicate the order in which we will actually
473 * search, so we rebuild it after any .PATH: target. 473 * search, so we rebuild it after any .PATH: target.
474 * This is the simplest way to deal with the effect of .DOTLAST. 474 * This is the simplest way to deal with the effect of .DOTLAST.
475 */ 475 */
476void 476void
477Dir_SetPATH(void) 477Dir_SetPATH(void)
478{ 478{
479 LstNode ln; /* a list element */ 479 LstNode ln; /* a list element */
@@ -885,27 +885,27 @@ Dir_Expand(const char *word, Lst path, L @@ -885,27 +885,27 @@ Dir_Expand(const char *word, Lst path, L
885 * dirpath is null if can't find the leading component 885 * dirpath is null if can't find the leading component
886 * XXX: Dir_FindFile won't find internal components. 886 * XXX: Dir_FindFile won't find internal components.
887 * i.e. if the path contains ../Etc/Object and we're 887 * i.e. if the path contains ../Etc/Object and we're
888 * looking for Etc, it won't be found. Ah well. 888 * looking for Etc, it won't be found. Ah well.
889 * Probably not important. 889 * Probably not important.
890 */ 890 */
891 if (dirpath != NULL) { 891 if (dirpath != NULL) {
892 char *dp = &dirpath[strlen(dirpath) - 1]; 892 char *dp = &dirpath[strlen(dirpath) - 1];
893 if (*dp == '/') 893 if (*dp == '/')
894 *dp = '\0'; 894 *dp = '\0';
895 path = Lst_Init(); 895 path = Lst_Init();
896 (void)Dir_AddDir(path, dirpath); 896 (void)Dir_AddDir(path, dirpath);
897 DirExpandInt(cp + 1, path, expansions); 897 DirExpandInt(cp + 1, path, expansions);
898 Lst_Destroy(path, NULL); 898 Lst_FreeS(path);
899 } 899 }
900 } else { 900 } else {
901 /* 901 /*
902 * Start the search from the local directory 902 * Start the search from the local directory
903 */ 903 */
904 DirExpandInt(word, path, expansions); 904 DirExpandInt(word, path, expansions);
905 } 905 }
906 } else { 906 } else {
907 /* 907 /*
908 * Return the file -- this should never happen. 908 * Return the file -- this should never happen.
909 */ 909 */
910 DirExpandInt(word, path, expansions); 910 DirExpandInt(word, path, expansions);
911 } 911 }

cvs diff -r1.41 -r1.42 src/usr.bin/make/lst.c (expand / switch to unified diff)

--- src/usr.bin/make/lst.c 2020/08/23 16:58:02 1.41
+++ src/usr.bin/make/lst.c 2020/08/26 22:55:46 1.42
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $ */ 1/* $NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -27,31 +27,31 @@ @@ -27,31 +27,31 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include <stdint.h> 35#include <stdint.h>
36 36
37#include "make.h" 37#include "make.h"
38 38
39#ifndef MAKE_NATIVE 39#ifndef MAKE_NATIVE
40static char rcsid[] = "$NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $"; 40static char rcsid[] = "$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $";
41#else 41#else
42#include <sys/cdefs.h> 42#include <sys/cdefs.h>
43#ifndef lint 43#ifndef lint
44__RCSID("$NetBSD: lst.c,v 1.41 2020/08/23 16:58:02 rillig Exp $"); 44__RCSID("$NetBSD: lst.c,v 1.42 2020/08/26 22:55:46 rillig Exp $");
45#endif /* not lint */ 45#endif /* not lint */
46#endif 46#endif
47 47
48struct ListNode { 48struct ListNode {
49 struct ListNode *prev; /* previous element in list */ 49 struct ListNode *prev; /* previous element in list */
50 struct ListNode *next; /* next in list */ 50 struct ListNode *next; /* next in list */
51 uint8_t useCount; /* Count of functions using the node. 51 uint8_t useCount; /* Count of functions using the node.
52 * node may not be deleted until count 52 * node may not be deleted until count
53 * goes to 0 */ 53 * goes to 0 */
54 Boolean deleted; /* List node should be removed when done */ 54 Boolean deleted; /* List node should be removed when done */
55 union { 55 union {
56 void *datum; /* datum associated with this element */ 56 void *datum; /* datum associated with this element */
57 const GNode *gnode; /* alias, just for debugging */ 57 const GNode *gnode; /* alias, just for debugging */
@@ -132,56 +132,58 @@ Lst_CopyS(Lst list, LstCopyProc copyProc @@ -132,56 +132,58 @@ Lst_CopyS(Lst list, LstCopyProc copyProc
132 132
133 assert(LstIsValid(list)); 133 assert(LstIsValid(list));
134 134
135 newList = Lst_Init(); 135 newList = Lst_Init();
136 136
137 for (node = list->first; node != NULL; node = node->next) { 137 for (node = list->first; node != NULL; node = node->next) {
138 void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum; 138 void *datum = copyProc != NULL ? copyProc(node->datum) : node->datum;
139 Lst_AppendS(newList, datum); 139 Lst_AppendS(newList, datum);
140 } 140 }
141 141
142 return newList; 142 return newList;
143} 143}
144 144
 145/* Free a list and all its nodes. The list data itself are not freed though. */
 146void
 147Lst_FreeS(Lst list)
 148{
 149 LstNode node;
 150 LstNode next;
 151
 152 assert(LstIsValid(list));
 153
 154 for (node = list->first; node != NULL; node = next) {
 155 next = node->next;
 156 free(node);
 157 }
 158
 159 free(list);
 160}
 161
145/* Destroy a list and free all its resources. If the freeProc is given, it is 162/* Destroy a list and free all its resources. If the freeProc is given, it is
146 * called with the datum from each node in turn before the node is freed. */ 163 * called with the datum from each node in turn before the node is freed. */
147void 164void
148Lst_Destroy(Lst list, LstFreeProc freeProc) 165Lst_DestroyS(Lst list, LstFreeProc freeProc)
149{ 166{
150 LstNode node; 167 LstNode node;
151 LstNode next = NULL; 168 LstNode next;
152 169
153 if (list == NULL) 170 assert(LstIsValid(list));
154 return; 171 assert(freeProc != NULL);
155 172
156 /* To ease scanning */ 173 for (node = list->first; node != NULL; node = next) {
157 if (list->last != NULL) 174 next = node->next;
158 list->last->next = NULL; 175 freeProc(node->datum);
159 else { 176 free(node);
160 free(list); 
161 return; 
162 } 
163 
164 if (freeProc) { 
165 for (node = list->first; node != NULL; node = next) { 
166 next = node->next; 
167 freeProc(node->datum); 
168 free(node); 
169 } 
170 } else { 
171 for (node = list->first; node != NULL; node = next) { 
172 next = node->next; 
173 free(node); 
174 } 
175 } 177 }
176 178
177 free(list); 179 free(list);
178} 180}
179 181
180/* 182/*
181 * Functions to modify a list 183 * Functions to modify a list
182 */ 184 */
183 185
184/* Insert a new node with the given piece of data before the given node in the 186/* Insert a new node with the given piece of data before the given node in the
185 * given list. */ 187 * given list. */
186void 188void
187Lst_InsertBeforeS(Lst list, LstNode node, void *datum) 189Lst_InsertBeforeS(Lst list, LstNode node, void *datum)
@@ -330,49 +332,76 @@ LstNode_SetNullS(LstNode node) @@ -330,49 +332,76 @@ LstNode_SetNullS(LstNode node)
330 332
331/* Return the first node from the given list, or NULL if the list is empty or 333/* Return the first node from the given list, or NULL if the list is empty or
332 * invalid. */ 334 * invalid. */
333LstNode 335LstNode
334Lst_First(Lst list) 336Lst_First(Lst list)
335{ 337{
336 if (!LstIsValid(list) || LstIsEmpty(list)) { 338 if (!LstIsValid(list) || LstIsEmpty(list)) {
337 return NULL; 339 return NULL;
338 } else { 340 } else {
339 return list->first; 341 return list->first;
340 } 342 }
341} 343}
342 344
 345/* Return the first node from the given list, or NULL if the list is empty. */
 346LstNode
 347Lst_FirstS(Lst list)
 348{
 349 assert(LstIsValid(list));
 350
 351 return list->first;
 352}
 353
343/* Return the last node from the given list, or NULL if the list is empty or 354/* Return the last node from the given list, or NULL if the list is empty or
344 * invalid. */ 355 * invalid. */
345LstNode 356LstNode
346Lst_Last(Lst list) 357Lst_Last(Lst list)
347{ 358{
348 if (!LstIsValid(list) || LstIsEmpty(list)) { 359 if (!LstIsValid(list) || LstIsEmpty(list)) {
349 return NULL; 360 return NULL;
350 } else { 361 } else {
351 return list->last; 362 return list->last;
352 } 363 }
353} 364}
354 365
 366/* Return the last node from the given list, or NULL if the list is empty. */
 367LstNode
 368Lst_LastS(Lst list)
 369{
 370 assert(LstIsValid(list));
 371
 372 return list->last;
 373}
 374
355/* Return the successor to the given node on its list, or NULL. */ 375/* Return the successor to the given node on its list, or NULL. */
356LstNode 376LstNode
357Lst_Succ(LstNode node) 377Lst_Succ(LstNode node)
358{ 378{
359 if (node == NULL) { 379 if (node == NULL) {
360 return NULL; 380 return NULL;
361 } else { 381 } else {
362 return node->next; 382 return node->next;
363 } 383 }
364} 384}
365 385
 386/* Return the successor to the given node on its list, or NULL. */
 387LstNode
 388Lst_SuccS(LstNode node)
 389{
 390 assert(LstNodeIsValid(node));
 391
 392 return node->next;
 393}
 394
366/* Return the predecessor to the given node on its list, or NULL. */ 395/* Return the predecessor to the given node on its list, or NULL. */
367LstNode 396LstNode
368Lst_PrevS(LstNode node) 397Lst_PrevS(LstNode node)
369{ 398{
370 assert(LstNodeIsValid(node)); 399 assert(LstNodeIsValid(node));
371 return node->prev; 400 return node->prev;
372} 401}
373 402
374/* Return the datum stored in the given node. */ 403/* Return the datum stored in the given node. */
375void * 404void *
376Lst_DatumS(LstNode node) 405Lst_DatumS(LstNode node)
377{ 406{
378 assert(LstNodeIsValid(node)); 407 assert(LstNodeIsValid(node));
@@ -381,101 +410,153 @@ Lst_DatumS(LstNode node) @@ -381,101 +410,153 @@ Lst_DatumS(LstNode node)
381 410
382 411
383/* 412/*
384 * Functions for entire lists 413 * Functions for entire lists
385 */ 414 */
386 415
387/* Return TRUE if the given list is empty or invalid. */ 416/* Return TRUE if the given list is empty or invalid. */
388Boolean 417Boolean
389Lst_IsEmpty(Lst list) 418Lst_IsEmpty(Lst list)
390{ 419{
391 return !LstIsValid(list) || LstIsEmpty(list); 420 return !LstIsValid(list) || LstIsEmpty(list);
392} 421}
393 422
 423/* Return TRUE if the given list is empty. */
 424Boolean
 425Lst_IsEmptyS(Lst list)
 426{
 427 assert(LstIsValid(list));
 428
 429 return LstIsEmpty(list);
 430}
 431
394/* Return the first node from the given list for which the given comparison 432/* Return the first node from the given list for which the given comparison
395 * function returns 0, or NULL if none of the nodes matches. */ 433 * function returns 0, or NULL if none of the nodes matches. */
396LstNode 434LstNode
397Lst_Find(Lst list, LstFindProc cmp, const void *cmpData) 435Lst_Find(Lst list, LstFindProc cmp, const void *cmpData)
398{ 436{
399 return Lst_FindFrom(list, Lst_First(list), cmp, cmpData); 437 return Lst_FindFrom(list, Lst_First(list), cmp, cmpData);
400} 438}
401 439
 440/* Return the first node from the given list for which the given comparison
 441 * function returns 0, or NULL if none of the nodes matches. */
 442LstNode
 443Lst_FindS(Lst list, LstFindProc cmp, const void *cmpData)
 444{
 445 if (LstIsEmpty(list))
 446 return NULL;
 447 return Lst_FindFromS(list, Lst_FirstS(list), cmp, cmpData);
 448}
 449
402/* Return the first node from the given list, starting at the given node, for 450/* Return the first node from the given list, starting at the given node, for
403 * which the given comparison function returns 0, or NULL if none of the nodes 451 * which the given comparison function returns 0, or NULL if none of the nodes
404 * matches. */ 452 * matches. */
405LstNode 453LstNode
406Lst_FindFrom(Lst list, LstNode node, LstFindProc cmp, const void *cmpData) 454Lst_FindFrom(Lst list, LstNode node, LstFindProc cmp, const void *cmpData)
407{ 455{
408 LstNode tln; 
409 
410 assert(cmp != NULL); 
411 
412 if (!LstIsValid(list) || LstIsEmpty(list) || !LstNodeIsValid(node)) { 456 if (!LstIsValid(list) || LstIsEmpty(list) || !LstNodeIsValid(node)) {
413 return NULL; 457 return NULL;
414 } 458 }
415 459
416 tln = node; 460 return Lst_FindFromS(list, node, cmp, cmpData);
 461}
417 462
418 do { 463/* Return the first node from the given list, starting at the given node, for
 464 * which the given comparison function returns 0, or NULL if none of the nodes
 465 * matches. */
 466LstNode
 467Lst_FindFromS(Lst list, LstNode node, LstFindProc cmp, const void *cmpData)
 468{
 469 LstNode tln;
 470
 471 assert(LstIsValid(list));
 472 assert(LstNodeIsValid(node));
 473 assert(cmp != NULL);
 474
 475 for (tln = node; tln != NULL; tln = tln->next) {
419 if (cmp(tln->datum, cmpData) == 0) 476 if (cmp(tln->datum, cmpData) == 0)
420 return tln; 477 return tln;
421 tln = tln->next; 478 }
422 } while (tln != node && tln != NULL); 
423 479
424 return NULL; 480 return NULL;
425} 481}
426 482
427/* Return the first node that contains the given datum, or NULL. */ 483/* Return the first node that contains the given datum, or NULL. */
428LstNode 484LstNode
429Lst_MemberS(Lst list, void *datum) 485Lst_MemberS(Lst list, void *datum)
430{ 486{
431 LstNode node; 487 LstNode node;
432 488
433 assert(LstIsValid(list)); 489 assert(LstIsValid(list));
434 assert(datum != NULL); 490 assert(datum != NULL);
435 491
436 for (node = list->first; node != NULL; node = node->next) { 492 for (node = list->first; node != NULL; node = node->next) {
437 if (node->datum == datum) { 493 if (node->datum == datum) {
438 return node; 494 return node;
439 } 495 }
440 } 496 }
441 497
442 return NULL; 498 return NULL;
443} 499}
444 500
445/* Apply the given function to each element of the given list. The function 501/* Apply the given function to each element of the given list. The function
446 * should return 0 if traversal should continue and non-zero if it should 502 * should return 0 if traversal should continue and non-zero if it should
447 * abort. */ 503 * abort. */
448int 504int
449Lst_ForEach(Lst list, int (*proc)(void *, void *), void *procData) 505Lst_ForEach(Lst list, LstActionProc proc, void *procData)
450{ 506{
451 return Lst_ForEachFrom(list, Lst_First(list), proc, procData); 507 return Lst_ForEachFrom(list, Lst_First(list), proc, procData);
452} 508}
453 509
 510/* Apply the given function to each element of the given list. The function
 511 * should return 0 if traversal should continue and non-zero if it should
 512 * abort. */
 513int
 514Lst_ForEachS(Lst list, LstActionProc proc, void *procData)
 515{
 516 if (LstIsEmpty(list))
 517 return 0; /* XXX: Document what this value means. */
 518 return Lst_ForEachFromS(list, Lst_First(list), proc, procData);
 519}
 520
454/* Apply the given function to each element of the given list, starting from 521/* Apply the given function to each element of the given list, starting from
455 * the given node. The function should return 0 if traversal should continue, 522 * the given node. The function should return 0 if traversal should continue,
456 * and non-zero if it should abort. */ 523 * and non-zero if it should abort. */
457int 524int
458Lst_ForEachFrom(Lst list, LstNode node, 525Lst_ForEachFrom(Lst list, LstNode node,
459 int (*proc)(void *, void *), void *procData) 526 LstActionProc proc, void *procData)
 527{
 528 if (!LstIsValid(list) || LstIsEmpty(list)) {
 529 return 0;
 530 }
 531
 532 return Lst_ForEachFromS(list, node, proc, procData);
 533}
 534
 535/* Apply the given function to each element of the given list, starting from
 536 * the given node. The function should return 0 if traversal should continue,
 537 * and non-zero if it should abort. */
 538int
 539Lst_ForEachFromS(Lst list, LstNode node,
 540 LstActionProc proc, void *procData)
460{ 541{
461 LstNode tln = node; 542 LstNode tln = node;
462 LstNode next; 543 LstNode next;
463 Boolean done; 544 Boolean done;
464 int result; 545 int result;
465 546
466 if (!LstIsValid(list) || LstIsEmpty(list)) { 547 assert(LstIsValid(list));
467 return 0; 548 assert(LstNodeIsValid(node));
468 } 549 assert(proc != NULL);
469 550
470 do { 551 do {
471 /* 552 /*
472 * Take care of having the current element deleted out from under 553 * Take care of having the current element deleted out from under
473 * us. 554 * us.
474 */ 555 */
475 556
476 next = tln->next; 557 next = tln->next;
477 558
478 /* 559 /*
479 * We're done with the traversal if 560 * We're done with the traversal if
480 * - the next node to examine doesn't exist and 561 * - the next node to examine doesn't exist and
481 * - nothing's been added after the current node (check this 562 * - nothing's been added after the current node (check this

cvs diff -r1.43 -r1.44 src/usr.bin/make/lst.h (expand / switch to unified diff)

--- src/usr.bin/make/lst.h 2020/08/23 17:04:21 1.43
+++ src/usr.bin/make/lst.h 2020/08/26 22:55:46 1.44
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lst.h,v 1.43 2020/08/23 17:04:21 rillig Exp $ */ 1/* $NetBSD: lst.h,v 1.44 2020/08/26 22:55:46 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.
@@ -95,78 +95,88 @@ typedef struct ListNode *LstNode; @@ -95,78 +95,88 @@ typedef struct ListNode *LstNode;
95typedef void *LstCopyProc(void *); 95typedef void *LstCopyProc(void *);
96typedef void LstFreeProc(void *); 96typedef void LstFreeProc(void *);
97typedef int LstFindProc(const void *, const void *); 97typedef int LstFindProc(const void *, const void *);
98typedef int LstActionProc(void *, void *); 98typedef int LstActionProc(void *, void *);
99 99
100/* 100/*
101 * Creation/destruction functions 101 * Creation/destruction functions
102 */ 102 */
103/* Create a new list */ 103/* Create a new list */
104Lst Lst_Init(void); 104Lst Lst_Init(void);
105/* Duplicate an existing list */ 105/* Duplicate an existing list */
106Lst Lst_CopyS(Lst, LstCopyProc); 106Lst Lst_CopyS(Lst, LstCopyProc);
107/* Destroy an old one */ 107/* Destroy an old one */
108void Lst_Destroy(Lst, LstFreeProc); 108void Lst_FreeS(Lst);
 109void Lst_DestroyS(Lst, LstFreeProc);
109/* True if list is empty */ 110/* True if list is empty */
110Boolean Lst_IsEmpty(Lst); 111Boolean Lst_IsEmpty(Lst);
 112Boolean Lst_IsEmptyS(Lst);
111 113
112/* 114/*
113 * Functions to modify a list 115 * Functions to modify a list
114 */ 116 */
115/* Insert an element before another */ 117/* Insert an element before another */
116void Lst_InsertBeforeS(Lst, LstNode, void *); 118void Lst_InsertBeforeS(Lst, LstNode, void *);
117/* Place an element at the front of a lst. */ 119/* Place an element at the front of a lst. */
118void Lst_PrependS(Lst, void *); 120void Lst_PrependS(Lst, void *);
119/* Place an element at the end of a lst. */ 121/* Place an element at the end of a lst. */
120void Lst_AppendS(Lst, void *); 122void Lst_AppendS(Lst, void *);
121/* Remove an element */ 123/* Remove an element */
122void Lst_RemoveS(Lst, LstNode); 124void Lst_RemoveS(Lst, LstNode);
123/* Replace a node with a new value */ 125/* Replace a node with a new value */
124void LstNode_SetS(LstNode, void *); 126void LstNode_SetS(LstNode, void *);
125void LstNode_SetNullS(LstNode); 127void LstNode_SetNullS(LstNode);
 128
126void Lst_PrependAllS(Lst, Lst); 129void Lst_PrependAllS(Lst, Lst);
127void Lst_AppendAllS(Lst, Lst); 130void Lst_AppendAllS(Lst, Lst);
128void Lst_MoveAllS(Lst, Lst); 131void Lst_MoveAllS(Lst, Lst);
129 132
130/* 133/*
131 * Node-specific functions 134 * Node-specific functions
132 */ 135 */
133/* Return first element in list */ 136/* Return first element in list */
134LstNode Lst_First(Lst); 137LstNode Lst_First(Lst);
 138LstNode Lst_FirstS(Lst);
135/* Return last element in list */ 139/* Return last element in list */
136LstNode Lst_Last(Lst); 140LstNode Lst_Last(Lst);
 141LstNode Lst_LastS(Lst);
137/* Return successor to given element */ 142/* Return successor to given element */
138LstNode Lst_Succ(LstNode); 143LstNode Lst_Succ(LstNode);
 144LstNode Lst_SuccS(LstNode);
139/* Return predecessor to given element */ 145/* Return predecessor to given element */
140LstNode Lst_PrevS(LstNode); 146LstNode Lst_PrevS(LstNode);
141/* Get datum from LstNode */ 147/* Get datum from LstNode */
142void *Lst_DatumS(LstNode); 148void *Lst_DatumS(LstNode);
143 149
144/* 150/*
145 * Functions for entire lists 151 * Functions for entire lists
146 */ 152 */
147/* Find an element in a list */ 153/* Find an element in a list */
148LstNode Lst_Find(Lst, LstFindProc, const void *); 154LstNode Lst_Find(Lst, LstFindProc, const void *);
 155LstNode Lst_FindS(Lst, LstFindProc, const void *);
149/* Find an element starting from somewhere */ 156/* Find an element starting from somewhere */
150LstNode Lst_FindFrom(Lst, LstNode, LstFindProc, const void *); 157LstNode Lst_FindFrom(Lst, LstNode, LstFindProc, const void *);
 158LstNode Lst_FindFromS(Lst, LstNode, LstFindProc, const void *);
151/* 159/*
152 * See if the given datum is on the list. Returns the LstNode containing 160 * See if the given datum is on the list. Returns the LstNode containing
153 * the datum 161 * the datum
154 */ 162 */
155LstNode Lst_MemberS(Lst, void *); 163LstNode Lst_MemberS(Lst, void *);
156/* Apply a function to all elements of a lst */ 164/* Apply a function to all elements of a lst */
157int Lst_ForEach(Lst, LstActionProc, void *); 165int Lst_ForEach(Lst, LstActionProc, void *);
 166int Lst_ForEachS(Lst, LstActionProc, void *);
158/* Apply a function to all elements of a lst starting from a certain point. */ 167/* Apply a function to all elements of a lst starting from a certain point. */
159int Lst_ForEachFrom(Lst, LstNode, LstActionProc, void *); 168int Lst_ForEachFrom(Lst, LstNode, LstActionProc, void *);
 169int Lst_ForEachFromS(Lst, LstNode, LstActionProc, void *);
160/* 170/*
161 * these functions are for dealing with a list as a table, of sorts. 171 * these functions are for dealing with a list as a table, of sorts.
162 * An idea of the "current element" is kept and used by all the functions 172 * An idea of the "current element" is kept and used by all the functions
163 * between Lst_Open() and Lst_Close(). 173 * between Lst_Open() and Lst_Close().
164 */ 174 */
165/* Open the list */ 175/* Open the list */
166ReturnStatus Lst_Open(Lst); 176ReturnStatus Lst_Open(Lst);
167void Lst_OpenS(Lst); 177void Lst_OpenS(Lst);
168/* Next element please, or NULL */ 178/* Next element please, or NULL */
169LstNode Lst_NextS(Lst); 179LstNode Lst_NextS(Lst);
170/* Finish table access */ 180/* Finish table access */
171void Lst_CloseS(Lst); 181void Lst_CloseS(Lst);
172 182

cvs diff -r1.313 -r1.314 src/usr.bin/make/main.c (expand / switch to unified diff)

--- src/usr.bin/make/main.c 2020/08/25 16:50:02 1.313
+++ src/usr.bin/make/main.c 2020/08/26 22:55:46 1.314
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $ */ 1/* $NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,39 +59,39 @@ @@ -59,39 +59,39 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $"; 72static char rcsid[] = "$NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\ 76__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\
77 The Regents of the University of California. All rights reserved."); 77 The Regents of the University of California. All rights reserved.");
78#endif /* not lint */ 78#endif /* not lint */
79 79
80#ifndef lint 80#ifndef lint
81#if 0 81#if 0
82static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; 82static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
83#else 83#else
84__RCSID("$NetBSD: main.c,v 1.313 2020/08/25 16:50:02 rillig Exp $"); 84__RCSID("$NetBSD: main.c,v 1.314 2020/08/26 22:55:46 rillig Exp $");
85#endif 85#endif
86#endif /* not lint */ 86#endif /* not lint */
87#endif 87#endif
88 88
89/*- 89/*-
90 * main.c -- 90 * main.c --
91 * The main file for this entire program. Exit routines etc 91 * The main file for this entire program. Exit routines etc
92 * reside here. 92 * reside here.
93 * 93 *
94 * Utility functions defined in this file: 94 * Utility functions defined in this file:
95 * Main_ParseArgLine Takes a line of arguments, breaks them and 95 * Main_ParseArgLine Takes a line of arguments, breaks them and
96 * treats them as if they were given when first 96 * treats them as if they were given when first
97 * invoked. Used by the parse module to implement 97 * invoked. Used by the parse module to implement
@@ -895,27 +895,27 @@ doPrintVars(void) @@ -895,27 +895,27 @@ doPrintVars(void)
895 895
896static Boolean 896static Boolean
897runTargets(void) 897runTargets(void)
898{ 898{
899 Lst targs; /* target nodes to create -- passed to Make_Init */ 899 Lst targs; /* target nodes to create -- passed to Make_Init */
900 Boolean outOfDate; /* FALSE if all targets up to date */ 900 Boolean outOfDate; /* FALSE if all targets up to date */
901 901
902 /* 902 /*
903 * Have now read the entire graph and need to make a list of 903 * Have now read the entire graph and need to make a list of
904 * targets to create. If none was given on the command line, 904 * targets to create. If none was given on the command line,
905 * we consult the parsing module to find the main target(s) 905 * we consult the parsing module to find the main target(s)
906 * to create. 906 * to create.
907 */ 907 */
908 if (Lst_IsEmpty(create)) 908 if (Lst_IsEmptyS(create))
909 targs = Parse_MainName(); 909 targs = Parse_MainName();
910 else 910 else
911 targs = Targ_FindList(create, TARG_CREATE); 911 targs = Targ_FindList(create, TARG_CREATE);
912 912
913 if (!compatMake) { 913 if (!compatMake) {
914 /* 914 /*
915 * Initialize job module before traversing the graph 915 * Initialize job module before traversing the graph
916 * now that any .BEGIN and .END targets have been read. 916 * now that any .BEGIN and .END targets have been read.
917 * This is done only if the -q flag wasn't given 917 * This is done only if the -q flag wasn't given
918 * (to prevent the .BEGIN from being executed should 918 * (to prevent the .BEGIN from being executed should
919 * it exist). 919 * it exist).
920 */ 920 */
921 if (!queryFlag) { 921 if (!queryFlag) {
@@ -923,27 +923,27 @@ runTargets(void) @@ -923,27 +923,27 @@ runTargets(void)
923 jobsRunning = TRUE; 923 jobsRunning = TRUE;
924 } 924 }
925 925
926 /* Traverse the graph, checking on all the targets */ 926 /* Traverse the graph, checking on all the targets */
927 outOfDate = Make_Run(targs); 927 outOfDate = Make_Run(targs);
928 } else { 928 } else {
929 /* 929 /*
930 * Compat_Init will take care of creating all the 930 * Compat_Init will take care of creating all the
931 * targets as well as initializing the module. 931 * targets as well as initializing the module.
932 */ 932 */
933 Compat_Run(targs); 933 Compat_Run(targs);
934 outOfDate = FALSE; 934 outOfDate = FALSE;
935 } 935 }
936 Lst_Destroy(targs, NULL); 936 Lst_FreeS(targs);
937 return outOfDate; 937 return outOfDate;
938} 938}
939 939
940/*- 940/*-
941 * main -- 941 * main --
942 * The main function, for obvious reasons. Initializes variables 942 * The main function, for obvious reasons. Initializes variables
943 * and a few modules, then parses the arguments give it in the 943 * and a few modules, then parses the arguments give it in the
944 * environment and on the command line. Reads the system makefile 944 * environment and on the command line. Reads the system makefile
945 * followed by either Makefile, makefile or the file given by the 945 * followed by either Makefile, makefile or the file given by the
946 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the 946 * -f argument. Sets the .MAKEFLAGS PMake variable based on all the
947 * flags it has received by then uses either the Make or the Compat 947 * flags it has received by then uses either the Make or the Compat
948 * module to create the initial list of targets. 948 * module to create the initial list of targets.
949 * 949 *
@@ -1457,29 +1457,29 @@ main(int argc, char **argv) @@ -1457,29 +1457,29 @@ main(int argc, char **argv)
1457 /* print the initial graph, if the user requested it */ 1457 /* print the initial graph, if the user requested it */
1458 if (DEBUG(GRAPH1)) 1458 if (DEBUG(GRAPH1))
1459 Targ_PrintGraph(1); 1459 Targ_PrintGraph(1);
1460 1460
1461 /* print the values of any variables requested by the user */ 1461 /* print the values of any variables requested by the user */
1462 if (printVars) { 1462 if (printVars) {
1463 doPrintVars(); 1463 doPrintVars();
1464 outOfDate = FALSE; 1464 outOfDate = FALSE;
1465 } else { 1465 } else {
1466 outOfDate = runTargets(); 1466 outOfDate = runTargets();
1467 } 1467 }
1468 1468
1469#ifdef CLEANUP 1469#ifdef CLEANUP
1470 Lst_Destroy(variables, NULL); 1470 Lst_FreeS(variables);
1471 Lst_Destroy(makefiles, NULL); 1471 Lst_FreeS(makefiles);
1472 Lst_Destroy(create, free); 1472 Lst_DestroyS(create, free);
1473#endif 1473#endif
1474 1474
1475 /* print the graph now it's been processed if the user requested it */ 1475 /* print the graph now it's been processed if the user requested it */
1476 if (DEBUG(GRAPH2)) 1476 if (DEBUG(GRAPH2))
1477 Targ_PrintGraph(2); 1477 Targ_PrintGraph(2);
1478 1478
1479 Trace_Log(MAKEEND, 0); 1479 Trace_Log(MAKEEND, 0);
1480 1480
1481 if (enterFlagObj) 1481 if (enterFlagObj)
1482 printf("%s: Leaving directory `%s'\n", progname, objdir); 1482 printf("%s: Leaving directory `%s'\n", progname, objdir);
1483 if (enterFlag) 1483 if (enterFlag)
1484 printf("%s: Leaving directory `%s'\n", progname, curdir); 1484 printf("%s: Leaving directory `%s'\n", progname, curdir);
1485 1485

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

--- src/usr.bin/make/make.c 2020/08/25 16:27:24 1.123
+++ src/usr.bin/make/make.c 2020/08/26 22:55:46 1.124
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make.c,v 1.123 2020/08/25 16:27:24 rillig Exp $ */ 1/* $NetBSD: make.c,v 1.124 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: make.c,v 1.123 2020/08/25 16:27:24 rillig Exp $"; 72static char rcsid[] = "$NetBSD: make.c,v 1.124 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93"; 77static char sccsid[] = "@(#)make.c 8.1 (Berkeley) 6/6/93";
78#else 78#else
79__RCSID("$NetBSD: make.c,v 1.123 2020/08/25 16:27:24 rillig Exp $"); 79__RCSID("$NetBSD: make.c,v 1.124 2020/08/26 22:55:46 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * make.c -- 85 * make.c --
86 * The functions which perform the examination of targets and 86 * The functions which perform the examination of targets and
87 * their suitability for creation 87 * their suitability for creation
88 * 88 *
89 * Interface: 89 * Interface:
90 * Make_Run Initialize things for the module and recreate 90 * Make_Run Initialize things for the module and recreate
91 * whatever needs recreating. Returns TRUE if 91 * whatever needs recreating. Returns TRUE if
92 * work was (or would have been) done and FALSE 92 * work was (or would have been) done and FALSE
@@ -1296,27 +1296,27 @@ Make_ExpandUse(Lst targs) @@ -1296,27 +1296,27 @@ Make_ExpandUse(Lst targs)
1296 GNode *gn; /* a temporary pointer */ 1296 GNode *gn; /* a temporary pointer */
1297 Lst examine; /* List of targets to examine */ 1297 Lst examine; /* List of targets to examine */
1298 1298
1299 examine = Lst_CopyS(targs, NULL); 1299 examine = Lst_CopyS(targs, NULL);
1300 1300
1301 /* 1301 /*
1302 * Make an initial downward pass over the graph, marking nodes to be made 1302 * Make an initial downward pass over the graph, marking nodes to be made
1303 * as we go down. We call Suff_FindDeps to find where a node is and 1303 * as we go down. We call Suff_FindDeps to find where a node is and
1304 * to get some children for it if it has none and also has no commands. 1304 * to get some children for it if it has none and also has no commands.
1305 * If the node is a leaf, we stick it on the toBeMade queue to 1305 * If the node is a leaf, we stick it on the toBeMade queue to
1306 * be looked at in a minute, otherwise we add its children to our queue 1306 * be looked at in a minute, otherwise we add its children to our queue
1307 * and go on about our business. 1307 * and go on about our business.
1308 */ 1308 */
1309 while (!Lst_IsEmpty(examine)) { 1309 while (!Lst_IsEmptyS(examine)) {
1310 gn = Lst_DequeueS(examine); 1310 gn = Lst_DequeueS(examine);
1311 1311
1312 if (gn->flags & REMAKE) 1312 if (gn->flags & REMAKE)
1313 /* We've looked at this one already */ 1313 /* We've looked at this one already */
1314 continue; 1314 continue;
1315 gn->flags |= REMAKE; 1315 gn->flags |= REMAKE;
1316 if (DEBUG(MAKE)) 1316 if (DEBUG(MAKE))
1317 fprintf(debug_file, "Make_ExpandUse: examine %s%s\n", 1317 fprintf(debug_file, "Make_ExpandUse: examine %s%s\n",
1318 gn->name, gn->cohort_num); 1318 gn->name, gn->cohort_num);
1319 1319
1320 if (gn->type & OP_DOUBLEDEP) 1320 if (gn->type & OP_DOUBLEDEP)
1321 Lst_PrependAllS(examine, gn->cohorts); 1321 Lst_PrependAllS(examine, gn->cohorts);
1322 1322
@@ -1349,27 +1349,27 @@ Make_ExpandUse(Lst targs) @@ -1349,27 +1349,27 @@ Make_ExpandUse(Lst targs)
1349 Suff_FindDeps(gn); 1349 Suff_FindDeps(gn);
1350 else { 1350 else {
1351 /* Pretend we made all this node's children */ 1351 /* Pretend we made all this node's children */
1352 Lst_ForEach(gn->children, MakeFindChild, gn); 1352 Lst_ForEach(gn->children, MakeFindChild, gn);
1353 if (gn->unmade != 0) 1353 if (gn->unmade != 0)
1354 printf("Warning: %s%s still has %d unmade children\n", 1354 printf("Warning: %s%s still has %d unmade children\n",
1355 gn->name, gn->cohort_num, gn->unmade); 1355 gn->name, gn->cohort_num, gn->unmade);
1356 } 1356 }
1357 1357
1358 if (gn->unmade != 0) 1358 if (gn->unmade != 0)
1359 Lst_ForEach(gn->children, MakeAddChild, examine); 1359 Lst_ForEach(gn->children, MakeAddChild, examine);
1360 } 1360 }
1361 1361
1362 Lst_Destroy(examine, NULL); 1362 Lst_FreeS(examine);
1363} 1363}
1364 1364
1365/*- 1365/*-
1366 *----------------------------------------------------------------------- 1366 *-----------------------------------------------------------------------
1367 * Make_ProcessWait -- 1367 * Make_ProcessWait --
1368 * Convert .WAIT nodes into dependencies 1368 * Convert .WAIT nodes into dependencies
1369 * 1369 *
1370 * Input: 1370 * Input:
1371 * targs the initial list of targets 1371 * targs the initial list of targets
1372 * 1372 *
1373 *----------------------------------------------------------------------- 1373 *-----------------------------------------------------------------------
1374 */ 1374 */
1375 1375
@@ -1455,27 +1455,27 @@ Make_ProcessWait(Lst targs) @@ -1455,27 +1455,27 @@ Make_ProcessWait(Lst targs)
1455 for (; (ln = Lst_NextS(pgn->children)) != NULL; ) { 1455 for (; (ln = Lst_NextS(pgn->children)) != NULL; ) {
1456 cgn = Lst_DatumS(ln); 1456 cgn = Lst_DatumS(ln);
1457 if (cgn->type & OP_WAIT) { 1457 if (cgn->type & OP_WAIT) {
1458 /* Make the .WAIT node depend on the previous children */ 1458 /* Make the .WAIT node depend on the previous children */
1459 Lst_ForEachFrom(pgn->children, owln, add_wait_dep, cgn); 1459 Lst_ForEachFrom(pgn->children, owln, add_wait_dep, cgn);
1460 owln = ln; 1460 owln = ln;
1461 } else { 1461 } else {
1462 Lst_AppendS(examine, cgn); 1462 Lst_AppendS(examine, cgn);
1463 } 1463 }
1464 } 1464 }
1465 Lst_CloseS(pgn->children); 1465 Lst_CloseS(pgn->children);
1466 } 1466 }
1467 1467
1468 Lst_Destroy(examine, NULL); 1468 Lst_FreeS(examine);
1469} 1469}
1470 1470
1471/*- 1471/*-
1472 *----------------------------------------------------------------------- 1472 *-----------------------------------------------------------------------
1473 * Make_Run -- 1473 * Make_Run --
1474 * Initialize the nodes to remake and the list of nodes which are 1474 * Initialize the nodes to remake and the list of nodes which are
1475 * ready to be made by doing a breadth-first traversal of the graph 1475 * ready to be made by doing a breadth-first traversal of the graph
1476 * starting from the nodes in the given list. Once this traversal 1476 * starting from the nodes in the given list. Once this traversal
1477 * is finished, all the 'leaves' of the graph are in the toBeMade 1477 * is finished, all the 'leaves' of the graph are in the toBeMade
1478 * queue. 1478 * queue.
1479 * Using this queue and the Job module, work back up the graph, 1479 * Using this queue and the Job module, work back up the graph,
1480 * calling on MakeStartJobs to keep the job table as full as 1480 * calling on MakeStartJobs to keep the job table as full as
1481 * possible. 1481 * possible.

cvs diff -r1.99 -r1.100 src/usr.bin/make/meta.c (expand / switch to unified diff)

--- src/usr.bin/make/meta.c 2020/08/23 16:58:02 1.99
+++ src/usr.bin/make/meta.c 2020/08/26 22:55:46 1.100
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: meta.c,v 1.99 2020/08/23 16:58:02 rillig Exp $ */ 1/* $NetBSD: meta.c,v 1.100 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Implement 'meta' mode. 4 * Implement 'meta' mode.
5 * Adapted from John Birrell's patches to FreeBSD make. 5 * Adapted from John Birrell's patches to FreeBSD make.
6 * --sjg 6 * --sjg
7 */ 7 */
8/* 8/*
9 * Copyright (c) 2009-2016, Juniper Networks, Inc. 9 * Copyright (c) 2009-2016, Juniper Networks, Inc.
10 * Portions Copyright (c) 2009, John Birrell. 10 * Portions Copyright (c) 2009, John Birrell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -879,29 +879,31 @@ meta_job_finish(Job *job) @@ -879,29 +879,31 @@ meta_job_finish(Job *job)
879 error = meta_cmd_finish(pbm); 879 error = meta_cmd_finish(pbm);
880 x = fclose(pbm->mfp); 880 x = fclose(pbm->mfp);
881 if (error == 0 && x != 0) 881 if (error == 0 && x != 0)
882 error = errno; 882 error = errno;
883 pbm->mfp = NULL; 883 pbm->mfp = NULL;
884 pbm->meta_fname[0] = '\0'; 884 pbm->meta_fname[0] = '\0';
885 } 885 }
886 return error; 886 return error;
887} 887}
888 888
889void 889void
890meta_finish(void) 890meta_finish(void)
891{ 891{
892 Lst_Destroy(metaBailiwick, NULL); 892 if (metaBailiwick != NULL)
 893 Lst_FreeS(metaBailiwick);
893 free(metaBailiwickStr); 894 free(metaBailiwickStr);
894 Lst_Destroy(metaIgnorePaths, NULL); 895 if (metaIgnorePaths != NULL)
 896 Lst_FreeS(metaIgnorePaths);
895 free(metaIgnorePathsStr); 897 free(metaIgnorePathsStr);
896} 898}
897 899
898/* 900/*
899 * Fetch a full line from fp - growing bufp if needed 901 * Fetch a full line from fp - growing bufp if needed
900 * Return length in bufp. 902 * Return length in bufp.
901 */ 903 */
902static int 904static int
903fgetLine(char **bufp, size_t *szp, int o, FILE *fp) 905fgetLine(char **bufp, size_t *szp, int o, FILE *fp)
904{ 906{
905 char *buf = *bufp; 907 char *buf = *bufp;
906 size_t bufsz = *szp; 908 size_t bufsz = *szp;
907 struct stat fs; 909 struct stat fs;
@@ -1613,27 +1615,27 @@ meta_oodate(GNode *gn, Boolean oodate) @@ -1613,27 +1615,27 @@ meta_oodate(GNode *gn, Boolean oodate)
1613 if (strncmp(curdir, gn->path, (cp - gn->path)) != 0) { 1615 if (strncmp(curdir, gn->path, (cp - gn->path)) != 0) {
1614 cp = NULL; /* not in .CURDIR */ 1616 cp = NULL; /* not in .CURDIR */
1615 } 1617 }
1616 } 1618 }
1617 if (!cp) { 1619 if (!cp) {
1618 if (DEBUG(META)) 1620 if (DEBUG(META))
1619 fprintf(debug_file, "%s: required but missing\n", fname); 1621 fprintf(debug_file, "%s: required but missing\n", fname);
1620 oodate = TRUE; 1622 oodate = TRUE;
1621 needOODATE = TRUE; /* assume the worst */ 1623 needOODATE = TRUE; /* assume the worst */
1622 } 1624 }
1623 } 1625 }
1624 } 1626 }
1625 1627
1626 Lst_Destroy(missingFiles, free); 1628 Lst_DestroyS(missingFiles, free);
1627 1629
1628 if (oodate && needOODATE) { 1630 if (oodate && needOODATE) {
1629 /* 1631 /*
1630 * Target uses .OODATE which is empty; or we wouldn't be here. 1632 * Target uses .OODATE which is empty; or we wouldn't be here.
1631 * We have decided it is oodate, so .OODATE needs to be set. 1633 * We have decided it is oodate, so .OODATE needs to be set.
1632 * All we can sanely do is set it to .ALLSRC. 1634 * All we can sanely do is set it to .ALLSRC.
1633 */ 1635 */
1634 Var_Delete(OODATE, gn); 1636 Var_Delete(OODATE, gn);
1635 Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn); 1637 Var_Set(OODATE, Var_Value(ALLSRC, gn, &cp), gn);
1636 bmake_free(cp); 1638 bmake_free(cp);
1637 } 1639 }
1638 1640
1639 oodate_out: 1641 oodate_out:

cvs diff -r1.262 -r1.263 src/usr.bin/make/parse.c (expand / switch to unified diff)

--- src/usr.bin/make/parse.c 2020/08/25 16:50:02 1.262
+++ src/usr.bin/make/parse.c 2020/08/26 22:55:46 1.263
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: parse.c,v 1.262 2020/08/25 16:50:02 rillig Exp $ */ 1/* $NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: parse.c,v 1.262 2020/08/25 16:50:02 rillig Exp $"; 72static char rcsid[] = "$NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)parse.c 8.3 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: parse.c,v 1.262 2020/08/25 16:50:02 rillig Exp $"); 79__RCSID("$NetBSD: parse.c,v 1.263 2020/08/26 22:55:46 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * parse.c -- 85 * parse.c --
86 * Functions to parse a makefile. 86 * Functions to parse a makefile.
87 * 87 *
88 * One function, Parse_Init, must be called before any functions 88 * One function, Parse_Init, must be called before any functions
89 * in this module are used. After that, the function Parse_File is the 89 * in this module are used. After that, the function Parse_File is the
90 * main entry point and controls most of the other functions in this 90 * main entry point and controls most of the other functions in this
91 * module. 91 * module.
92 * 92 *
@@ -843,27 +843,27 @@ ParseMessage(char *line) @@ -843,27 +843,27 @@ ParseMessage(char *line)
843 * Side Effects: 843 * Side Effects:
844 * New elements are added to the parents list of cgn and the 844 * New elements are added to the parents list of cgn and the
845 * children list of cgn. the unmade field of pgn is updated 845 * children list of cgn. the unmade field of pgn is updated
846 * to reflect the additional child. 846 * to reflect the additional child.
847 *--------------------------------------------------------------------- 847 *---------------------------------------------------------------------
848 */ 848 */
849static int 849static int
850ParseLinkSrc(void *pgnp, void *cgnp) 850ParseLinkSrc(void *pgnp, void *cgnp)
851{ 851{
852 GNode *pgn = (GNode *)pgnp; 852 GNode *pgn = (GNode *)pgnp;
853 GNode *cgn = (GNode *)cgnp; 853 GNode *cgn = (GNode *)cgnp;
854 854
855 if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts)) 855 if ((pgn->type & OP_DOUBLEDEP) && !Lst_IsEmpty(pgn->cohorts))
856 pgn = Lst_DatumS(Lst_Last(pgn->cohorts)); 856 pgn = Lst_DatumS(Lst_LastS(pgn->cohorts));
857 Lst_AppendS(pgn->children, cgn); 857 Lst_AppendS(pgn->children, cgn);
858 if (specType == Not) 858 if (specType == Not)
859 Lst_AppendS(cgn->parents, pgn); 859 Lst_AppendS(cgn->parents, pgn);
860 pgn->unmade += 1; 860 pgn->unmade += 1;
861 if (DEBUG(PARSE)) { 861 if (DEBUG(PARSE)) {
862 fprintf(debug_file, "# %s: added child %s - %s\n", __func__, 862 fprintf(debug_file, "# %s: added child %s - %s\n", __func__,
863 pgn->name, cgn->name); 863 pgn->name, cgn->name);
864 Targ_PrintNode(pgn, 0); 864 Targ_PrintNode(pgn, 0);
865 Targ_PrintNode(cgn, 0); 865 Targ_PrintNode(cgn, 0);
866 } 866 }
867 return 0; 867 return 0;
868} 868}
869 869
@@ -1423,27 +1423,27 @@ ParseDoDependency(char *line) @@ -1423,27 +1423,27 @@ ParseDoDependency(char *line)
1423 */ 1423 */
1424 if (specType == Not && *line != '\0') { 1424 if (specType == Not && *line != '\0') {
1425 if (Dir_HasWildcards(line)) { 1425 if (Dir_HasWildcards(line)) {
1426 /* 1426 /*
1427 * Targets are to be sought only in the current directory, 1427 * Targets are to be sought only in the current directory,
1428 * so create an empty path for the thing. Note we need to 1428 * so create an empty path for the thing. Note we need to
1429 * use Dir_Destroy in the destruction of the path as the 1429 * use Dir_Destroy in the destruction of the path as the
1430 * Dir module could have added a directory to the path... 1430 * Dir module could have added a directory to the path...
1431 */ 1431 */
1432 Lst emptyPath = Lst_Init(); 1432 Lst emptyPath = Lst_Init();
1433 1433
1434 Dir_Expand(line, emptyPath, curTargs); 1434 Dir_Expand(line, emptyPath, curTargs);
1435 1435
1436 Lst_Destroy(emptyPath, Dir_Destroy); 1436 Lst_DestroyS(emptyPath, Dir_Destroy);
1437 } else { 1437 } else {
1438 /* 1438 /*
1439 * No wildcards, but we want to avoid code duplication, 1439 * No wildcards, but we want to avoid code duplication,
1440 * so create a list with the word on it. 1440 * so create a list with the word on it.
1441 */ 1441 */
1442 Lst_AppendS(curTargs, line); 1442 Lst_AppendS(curTargs, line);
1443 } 1443 }
1444 1444
1445 /* Apply the targets. */ 1445 /* Apply the targets. */
1446 1446
1447 while(!Lst_IsEmpty(curTargs)) { 1447 while(!Lst_IsEmpty(curTargs)) {
1448 char *targName = Lst_DequeueS(curTargs); 1448 char *targName = Lst_DequeueS(curTargs);
1449 1449
@@ -1484,27 +1484,27 @@ ParseDoDependency(char *line) @@ -1484,27 +1484,27 @@ ParseDoDependency(char *line)
1484 } 1484 }
1485 } else { 1485 } else {
1486 while (*cp && isspace ((unsigned char)*cp)) { 1486 while (*cp && isspace ((unsigned char)*cp)) {
1487 cp++; 1487 cp++;
1488 } 1488 }
1489 } 1489 }
1490 line = cp; 1490 line = cp;
1491 } while (*line && (ParseIsEscaped(lstart, line) || 1491 } while (*line && (ParseIsEscaped(lstart, line) ||
1492 (*line != '!' && *line != ':'))); 1492 (*line != '!' && *line != ':')));
1493 1493
1494 /* 1494 /*
1495 * Don't need the list of target names anymore... 1495 * Don't need the list of target names anymore...
1496 */ 1496 */
1497 Lst_Destroy(curTargs, NULL); 1497 Lst_FreeS(curTargs);
1498 curTargs = NULL; 1498 curTargs = NULL;
1499 1499
1500 if (!Lst_IsEmpty(targets)) { 1500 if (!Lst_IsEmpty(targets)) {
1501 switch(specType) { 1501 switch(specType) {
1502 default: 1502 default:
1503 Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored"); 1503 Parse_Error(PARSE_WARNING, "Special and mundane targets don't mix. Mundane ones ignored");
1504 break; 1504 break;
1505 case Default: 1505 case Default:
1506 case Stale: 1506 case Stale:
1507 case Begin: 1507 case Begin:
1508 case End: 1508 case End:
1509 case dotError: 1509 case dotError:
1510 case Interrupt: 1510 case Interrupt:
@@ -1676,27 +1676,27 @@ ParseDoDependency(char *line) @@ -1676,27 +1676,27 @@ ParseDoDependency(char *line)
1676 default: 1676 default:
1677 break; 1677 break;
1678 } 1678 }
1679 *cp = savec; 1679 *cp = savec;
1680 if (savec != '\0') { 1680 if (savec != '\0') {
1681 cp++; 1681 cp++;
1682 } 1682 }
1683 while (*cp && isspace ((unsigned char)*cp)) { 1683 while (*cp && isspace ((unsigned char)*cp)) {
1684 cp++; 1684 cp++;
1685 } 1685 }
1686 line = cp; 1686 line = cp;
1687 } 1687 }
1688 if (paths) { 1688 if (paths) {
1689 Lst_Destroy(paths, NULL); 1689 Lst_FreeS(paths);
1690 paths = NULL; 1690 paths = NULL;
1691 } 1691 }
1692 if (specType == ExPath) 1692 if (specType == ExPath)
1693 Dir_SetPATH(); 1693 Dir_SetPATH();
1694 } else { 1694 } else {
1695 assert(paths == NULL); 1695 assert(paths == NULL);
1696 while (*line) { 1696 while (*line) {
1697 /* 1697 /*
1698 * The targets take real sources, so we must beware of archive 1698 * The targets take real sources, so we must beware of archive
1699 * specifications (i.e. things with left parentheses in them) 1699 * specifications (i.e. things with left parentheses in them)
1700 * and handle them accordingly. 1700 * and handle them accordingly.
1701 */ 1701 */
1702 for (; *cp && !isspace ((unsigned char)*cp); cp++) { 1702 for (; *cp && !isspace ((unsigned char)*cp); cp++) {
@@ -1713,27 +1713,27 @@ ParseDoDependency(char *line) @@ -1713,27 +1713,27 @@ ParseDoDependency(char *line)
1713 1713
1714 if (*cp == LPAREN) { 1714 if (*cp == LPAREN) {
1715 sources = Lst_Init(); 1715 sources = Lst_Init();
1716 if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) { 1716 if (Arch_ParseArchive(&line, sources, VAR_CMD) != SUCCESS) {
1717 Parse_Error(PARSE_FATAL, 1717 Parse_Error(PARSE_FATAL,
1718 "Error in source archive spec \"%s\"", line); 1718 "Error in source archive spec \"%s\"", line);
1719 goto out; 1719 goto out;
1720 } 1720 }
1721 1721
1722 while (!Lst_IsEmpty(sources)) { 1722 while (!Lst_IsEmpty(sources)) {
1723 gn = Lst_DequeueS(sources); 1723 gn = Lst_DequeueS(sources);
1724 ParseDoSrc(tOp, gn->name); 1724 ParseDoSrc(tOp, gn->name);
1725 } 1725 }
1726 Lst_Destroy(sources, NULL); 1726 Lst_FreeS(sources);
1727 cp = line; 1727 cp = line;
1728 } else { 1728 } else {
1729 if (*cp) { 1729 if (*cp) {
1730 *cp = '\0'; 1730 *cp = '\0';
1731 cp += 1; 1731 cp += 1;
1732 } 1732 }
1733 1733
1734 ParseDoSrc(tOp, line); 1734 ParseDoSrc(tOp, line);
1735 } 1735 }
1736 while (*cp && isspace ((unsigned char)*cp)) { 1736 while (*cp && isspace ((unsigned char)*cp)) {
1737 cp++; 1737 cp++;
1738 } 1738 }
1739 line = cp; 1739 line = cp;
@@ -1741,30 +1741,30 @@ ParseDoDependency(char *line) @@ -1741,30 +1741,30 @@ ParseDoDependency(char *line)
1741 } 1741 }
1742 1742
1743 if (mainNode == NULL) { 1743 if (mainNode == NULL) {
1744 /* 1744 /*
1745 * If we have yet to decide on a main target to make, in the 1745 * If we have yet to decide on a main target to make, in the
1746 * absence of any user input, we want the first target on 1746 * absence of any user input, we want the first target on
1747 * the first dependency line that is actually a real target 1747 * the first dependency line that is actually a real target
1748 * (i.e. isn't a .USE or .EXEC rule) to be made. 1748 * (i.e. isn't a .USE or .EXEC rule) to be made.
1749 */ 1749 */
1750 Lst_ForEach(targets, ParseFindMain, NULL); 1750 Lst_ForEach(targets, ParseFindMain, NULL);
1751 } 1751 }
1752 1752
1753out: 1753out:
1754 if (paths) 1754 if (paths != NULL)
1755 Lst_Destroy(paths, NULL); 1755 Lst_FreeS(paths);
1756 if (curTargs) 1756 if (curTargs != NULL)
1757 Lst_Destroy(curTargs, NULL); 1757 Lst_FreeS(curTargs);
1758} 1758}
1759 1759
1760/*- 1760/*-
1761 *--------------------------------------------------------------------- 1761 *---------------------------------------------------------------------
1762 * Parse_IsVar -- 1762 * Parse_IsVar --
1763 * Return TRUE if the passed line is a variable assignment. A variable 1763 * Return TRUE if the passed line is a variable assignment. A variable
1764 * assignment consists of a single word followed by optional whitespace 1764 * assignment consists of a single word followed by optional whitespace
1765 * followed by either a += or an = operator. 1765 * followed by either a += or an = operator.
1766 * This function is used both by the Parse_File function and main when 1766 * This function is used both by the Parse_File function and main when
1767 * parsing the command-line arguments. 1767 * parsing the command-line arguments.
1768 * 1768 *
1769 * Input: 1769 * Input:
1770 * line the line to check 1770 * line the line to check
@@ -3008,28 +3008,30 @@ ParseReadLine(void) @@ -3008,28 +3008,30 @@ ParseReadLine(void)
3008 * 3008 *
3009 * Results: 3009 * Results:
3010 * Nothing. 3010 * Nothing.
3011 * 3011 *
3012 * Side Effects: 3012 * Side Effects:
3013 * inLine set FALSE. 'targets' list destroyed. 3013 * inLine set FALSE. 'targets' list destroyed.
3014 * 3014 *
3015 *----------------------------------------------------------------------- 3015 *-----------------------------------------------------------------------
3016 */ 3016 */
3017static void 3017static void
3018ParseFinishLine(void) 3018ParseFinishLine(void)
3019{ 3019{
3020 if (inLine) { 3020 if (inLine) {
3021 Lst_ForEach(targets, Suff_EndTransform, NULL); 3021 if (targets != NULL) {
3022 Lst_Destroy(targets, ParseHasCommands); 3022 Lst_ForEach(targets, Suff_EndTransform, NULL);
 3023 Lst_DestroyS(targets, ParseHasCommands);
 3024 }
3023 targets = NULL; 3025 targets = NULL;
3024 inLine = FALSE; 3026 inLine = FALSE;
3025 } 3027 }
3026} 3028}
3027 3029
3028 3030
3029/*- 3031/*-
3030 *--------------------------------------------------------------------- 3032 *---------------------------------------------------------------------
3031 * Parse_File -- 3033 * Parse_File --
3032 * Parse a file into its component parts, incorporating it into the 3034 * Parse a file into its component parts, incorporating it into the
3033 * current dependency graph. This is the main function and controls 3035 * current dependency graph. This is the main function and controls
3034 * almost every other function in this module 3036 * almost every other function in this module
3035 * 3037 *
@@ -3227,28 +3229,28 @@ Parse_File(const char *name, int fd) @@ -3227,28 +3229,28 @@ Parse_File(const char *name, int fd)
3227 else 3229 else
3228 cp = NULL; 3230 cp = NULL;
3229 3231
3230 /* 3232 /*
3231 * We now know it's a dependency line so it needs to have all 3233 * We now know it's a dependency line so it needs to have all
3232 * variables expanded before being parsed. Tell the variable 3234 * variables expanded before being parsed. Tell the variable
3233 * module to complain if some variable is undefined... 3235 * module to complain if some variable is undefined...
3234 */ 3236 */
3235 line = Var_Subst(line, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES); 3237 line = Var_Subst(line, VAR_CMD, VARE_UNDEFERR|VARE_WANTRES);
3236 3238
3237 /* 3239 /*
3238 * Need a non-circular list for the target nodes 3240 * Need a non-circular list for the target nodes
3239 */ 3241 */
3240 if (targets) 3242 if (targets != NULL)
3241 Lst_Destroy(targets, NULL); 3243 Lst_FreeS(targets);
3242 3244
3243 targets = Lst_Init(); 3245 targets = Lst_Init();
3244 inLine = TRUE; 3246 inLine = TRUE;
3245 3247
3246 ParseDoDependency(line); 3248 ParseDoDependency(line);
3247 free(line); 3249 free(line);
3248 3250
3249 /* If there were commands after a ';', add them now */ 3251 /* If there were commands after a ';', add them now */
3250 if (cp != NULL) { 3252 if (cp != NULL) {
3251 goto shellCommand; 3253 goto shellCommand;
3252 } 3254 }
3253 } 3255 }
3254 /* 3256 /*
@@ -3285,33 +3287,33 @@ Parse_Init(void) @@ -3285,33 +3287,33 @@ Parse_Init(void)
3285 parseIncPath = Lst_Init(); 3287 parseIncPath = Lst_Init();
3286 sysIncPath = Lst_Init(); 3288 sysIncPath = Lst_Init();
3287 defIncPath = Lst_Init(); 3289 defIncPath = Lst_Init();
3288 includes = Lst_Init(); 3290 includes = Lst_Init();
3289#ifdef CLEANUP 3291#ifdef CLEANUP
3290 targCmds = Lst_Init(); 3292 targCmds = Lst_Init();
3291#endif 3293#endif
3292} 3294}
3293 3295
3294void 3296void
3295Parse_End(void) 3297Parse_End(void)
3296{ 3298{
3297#ifdef CLEANUP 3299#ifdef CLEANUP
3298 Lst_Destroy(targCmds, free); 3300 Lst_DestroyS(targCmds, free);
3299 if (targets) 3301 if (targets)
3300 Lst_Destroy(targets, NULL); 3302 Lst_FreeS(targets);
3301 Lst_Destroy(defIncPath, Dir_Destroy); 3303 Lst_DestroyS(defIncPath, Dir_Destroy);
3302 Lst_Destroy(sysIncPath, Dir_Destroy); 3304 Lst_DestroyS(sysIncPath, Dir_Destroy);
3303 Lst_Destroy(parseIncPath, Dir_Destroy); 3305 Lst_DestroyS(parseIncPath, Dir_Destroy);
3304 Lst_Destroy(includes, NULL); /* Should be empty now */ 3306 Lst_FreeS(includes); /* Should be empty now */
3305#endif 3307#endif
3306} 3308}
3307 3309
3308 3310
3309/*- 3311/*-
3310 *----------------------------------------------------------------------- 3312 *-----------------------------------------------------------------------
3311 * Parse_MainName -- 3313 * Parse_MainName --
3312 * Return a Lst of the main target to create for main()'s sake. If 3314 * Return a Lst of the main target to create for main()'s sake. If
3313 * no such target exists, we Punt with an obnoxious error message. 3315 * no such target exists, we Punt with an obnoxious error message.
3314 * 3316 *
3315 * Results: 3317 * Results:
3316 * A Lst of the single node to create. 3318 * A Lst of the single node to create.
3317 * 3319 *

cvs diff -r1.115 -r1.116 src/usr.bin/make/suff.c (expand / switch to unified diff)

--- src/usr.bin/make/suff.c 2020/08/25 16:50:02 1.115
+++ src/usr.bin/make/suff.c 2020/08/26 22:55:46 1.116
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: suff.c,v 1.115 2020/08/25 16:50:02 rillig Exp $ */ 1/* $NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: suff.c,v 1.115 2020/08/25 16:50:02 rillig Exp $"; 72static char rcsid[] = "$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; 77static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94";
78#else 78#else
79__RCSID("$NetBSD: suff.c,v 1.115 2020/08/25 16:50:02 rillig Exp $"); 79__RCSID("$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * suff.c -- 85 * suff.c --
86 * Functions to maintain suffix lists and find implicit dependents 86 * Functions to maintain suffix lists and find implicit dependents
87 * using suffix transformation rules 87 * using suffix transformation rules
88 * 88 *
89 * Interface: 89 * Interface:
90 * Suff_Init Initialize all things to do with suffixes. 90 * Suff_Init Initialize all things to do with suffixes.
91 * 91 *
92 * Suff_End Cleanup the module 92 * Suff_End Cleanup the module
@@ -431,30 +431,30 @@ SuffFree(void *sp) @@ -431,30 +431,30 @@ SuffFree(void *sp)
431 if (s == suffNull) 431 if (s == suffNull)
432 suffNull = NULL; 432 suffNull = NULL;
433 433
434 if (s == emptySuff) 434 if (s == emptySuff)
435 emptySuff = NULL; 435 emptySuff = NULL;
436 436
437#ifdef notdef 437#ifdef notdef
438 /* We don't delete suffixes in order, so we cannot use this */ 438 /* We don't delete suffixes in order, so we cannot use this */
439 if (s->refCount) 439 if (s->refCount)
440 Punt("Internal error deleting suffix `%s' with refcount = %d", s->name, 440 Punt("Internal error deleting suffix `%s' with refcount = %d", s->name,
441 s->refCount); 441 s->refCount);
442#endif 442#endif
443 443
444 Lst_Destroy(s->ref, NULL); 444 Lst_FreeS(s->ref);
445 Lst_Destroy(s->children, NULL); 445 Lst_FreeS(s->children);
446 Lst_Destroy(s->parents, NULL); 446 Lst_FreeS(s->parents);
447 Lst_Destroy(s->searchPath, Dir_Destroy); 447 Lst_DestroyS(s->searchPath, Dir_Destroy);
448 448
449 free(s->name); 449 free(s->name);
450 free(s); 450 free(s);
451} 451}
452 452
453/*- 453/*-
454 *----------------------------------------------------------------------- 454 *-----------------------------------------------------------------------
455 * SuffRemove -- 455 * SuffRemove --
456 * Remove the suffix into the list 456 * Remove the suffix into the list
457 * 457 *
458 * Results: 458 * Results:
459 * None 459 * None
460 * 460 *
@@ -599,27 +599,27 @@ SuffParseTransform(char *str, Suff **src @@ -599,27 +599,27 @@ SuffParseTransform(char *str, Suff **src
599 * null suffix */ 599 * null suffix */
600 600
601 srcLn = NULL; 601 srcLn = NULL;
602 singleLn = NULL; 602 singleLn = NULL;
603 603
604 /* 604 /*
605 * Loop looking first for a suffix that matches the start of the 605 * Loop looking first for a suffix that matches the start of the
606 * string and then for one that exactly matches the rest of it. If 606 * string and then for one that exactly matches the rest of it. If
607 * we can find two that meet these criteria, we've successfully 607 * we can find two that meet these criteria, we've successfully
608 * parsed the string. 608 * parsed the string.
609 */ 609 */
610 for (;;) { 610 for (;;) {
611 if (srcLn == NULL) { 611 if (srcLn == NULL) {
612 srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str); 612 srcLn = Lst_FindS(sufflist, SuffSuffIsPrefix, str);
613 } else { 613 } else {
614 srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), 614 srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn),
615 SuffSuffIsPrefix, str); 615 SuffSuffIsPrefix, str);
616 } 616 }
617 if (srcLn == NULL) { 617 if (srcLn == NULL) {
618 /* 618 /*
619 * Ran out of source suffixes -- no such rule 619 * Ran out of source suffixes -- no such rule
620 */ 620 */
621 if (singleLn != NULL) { 621 if (singleLn != NULL) {
622 /* 622 /*
623 * Not so fast Mr. Smith! There was a suffix that encompassed 623 * Not so fast Mr. Smith! There was a suffix that encompassed
624 * the entire string, so we assume it was a transformation 624 * the entire string, so we assume it was a transformation
625 * to the null suffix (thank you POSIX). We still prefer to 625 * to the null suffix (thank you POSIX). We still prefer to
@@ -630,27 +630,27 @@ SuffParseTransform(char *str, Suff **src @@ -630,27 +630,27 @@ SuffParseTransform(char *str, Suff **src
630 */ 630 */
631 *srcPtr = single; 631 *srcPtr = single;
632 *targPtr = suffNull; 632 *targPtr = suffNull;
633 return TRUE; 633 return TRUE;
634 } 634 }
635 return FALSE; 635 return FALSE;
636 } 636 }
637 src = Lst_DatumS(srcLn); 637 src = Lst_DatumS(srcLn);
638 str2 = str + src->nameLen; 638 str2 = str + src->nameLen;
639 if (*str2 == '\0') { 639 if (*str2 == '\0') {
640 single = src; 640 single = src;
641 singleLn = srcLn; 641 singleLn = srcLn;
642 } else { 642 } else {
643 targLn = Lst_Find(sufflist, SuffSuffHasNameP, str2); 643 targLn = Lst_FindS(sufflist, SuffSuffHasNameP, str2);
644 if (targLn != NULL) { 644 if (targLn != NULL) {
645 *srcPtr = src; 645 *srcPtr = src;
646 *targPtr = Lst_DatumS(targLn); 646 *targPtr = Lst_DatumS(targLn);
647 return TRUE; 647 return TRUE;
648 } 648 }
649 } 649 }
650 } 650 }
651} 651}
652 652
653/*- 653/*-
654 *----------------------------------------------------------------------- 654 *-----------------------------------------------------------------------
655 * Suff_IsTransform -- 655 * Suff_IsTransform --
656 * Return TRUE if the given string is a transformation rule 656 * Return TRUE if the given string is a transformation rule
@@ -706,28 +706,28 @@ Suff_AddTransform(char *line) @@ -706,28 +706,28 @@ Suff_AddTransform(char *line)
706 * Make a new graph node for the transformation. It will be filled in 706 * Make a new graph node for the transformation. It will be filled in
707 * by the Parse module. 707 * by the Parse module.
708 */ 708 */
709 gn = Targ_NewGN(line); 709 gn = Targ_NewGN(line);
710 Lst_AppendS(transforms, gn); 710 Lst_AppendS(transforms, gn);
711 } else { 711 } else {
712 /* 712 /*
713 * New specification for transformation rule. Just nuke the old list 713 * New specification for transformation rule. Just nuke the old list
714 * of commands so they can be filled in again... We don't actually 714 * of commands so they can be filled in again... We don't actually
715 * free the commands themselves, because a given command can be 715 * free the commands themselves, because a given command can be
716 * attached to several different transformations. 716 * attached to several different transformations.
717 */ 717 */
718 gn = Lst_DatumS(ln); 718 gn = Lst_DatumS(ln);
719 Lst_Destroy(gn->commands, NULL); 719 Lst_FreeS(gn->commands);
720 Lst_Destroy(gn->children, NULL); 720 Lst_FreeS(gn->children);
721 gn->commands = Lst_Init(); 721 gn->commands = Lst_Init();
722 gn->children = Lst_Init(); 722 gn->children = Lst_Init();
723 } 723 }
724 724
725 gn->type = OP_TRANSFORM; 725 gn->type = OP_TRANSFORM;
726 726
727 (void)SuffParseTransform(line, &s, &t); 727 (void)SuffParseTransform(line, &s, &t);
728 728
729 /* 729 /*
730 * link the two together in the proper relationship and order 730 * link the two together in the proper relationship and order
731 */ 731 */
732 if (DEBUG(SUFF)) { 732 if (DEBUG(SUFF)) {
733 fprintf(debug_file, "defining transformation from `%s' to `%s'\n", 733 fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
@@ -839,51 +839,51 @@ SuffRebuildGraph(void *transformp, void  @@ -839,51 +839,51 @@ SuffRebuildGraph(void *transformp, void
839{ 839{
840 GNode *transform = (GNode *)transformp; 840 GNode *transform = (GNode *)transformp;
841 Suff *s = (Suff *)sp; 841 Suff *s = (Suff *)sp;
842 char *cp; 842 char *cp;
843 LstNode ln; 843 LstNode ln;
844 Suff *s2; 844 Suff *s2;
845 SuffixCmpData sd; 845 SuffixCmpData sd;
846 846
847 /* 847 /*
848 * First see if it is a transformation from this suffix. 848 * First see if it is a transformation from this suffix.
849 */ 849 */
850 cp = UNCONST(SuffStrIsPrefix(s->name, transform->name)); 850 cp = UNCONST(SuffStrIsPrefix(s->name, transform->name));
851 if (cp != NULL) { 851 if (cp != NULL) {
852 ln = Lst_Find(sufflist, SuffSuffHasNameP, cp); 852 ln = Lst_FindS(sufflist, SuffSuffHasNameP, cp);
853 if (ln != NULL) { 853 if (ln != NULL) {
854 /* 854 /*
855 * Found target. Link in and return, since it can't be anything 855 * Found target. Link in and return, since it can't be anything
856 * else. 856 * else.
857 */ 857 */
858 s2 = Lst_DatumS(ln); 858 s2 = Lst_DatumS(ln);
859 SuffInsert(s2->children, s); 859 SuffInsert(s2->children, s);
860 SuffInsert(s->parents, s2); 860 SuffInsert(s->parents, s2);
861 return 0; 861 return 0;
862 } 862 }
863 } 863 }
864 864
865 /* 865 /*
866 * Not from, maybe to? 866 * Not from, maybe to?
867 */ 867 */
868 sd.len = strlen(transform->name); 868 sd.len = strlen(transform->name);
869 sd.ename = transform->name + sd.len; 869 sd.ename = transform->name + sd.len;
870 cp = SuffSuffIsSuffix(s, &sd); 870 cp = SuffSuffIsSuffix(s, &sd);
871 if (cp != NULL) { 871 if (cp != NULL) {
872 /* 872 /*
873 * Null-terminate the source suffix in order to find it. 873 * Null-terminate the source suffix in order to find it.
874 */ 874 */
875 cp[1] = '\0'; 875 cp[1] = '\0';
876 ln = Lst_Find(sufflist, SuffSuffHasNameP, transform->name); 876 ln = Lst_FindS(sufflist, SuffSuffHasNameP, transform->name);
877 /* 877 /*
878 * Replace the start of the target suffix 878 * Replace the start of the target suffix
879 */ 879 */
880 cp[1] = s->name[0]; 880 cp[1] = s->name[0];
881 if (ln != NULL) { 881 if (ln != NULL) {
882 /* 882 /*
883 * Found it -- establish the proper relationship 883 * Found it -- establish the proper relationship
884 */ 884 */
885 s2 = Lst_DatumS(ln); 885 s2 = Lst_DatumS(ln);
886 SuffInsert(s->children, s2); 886 SuffInsert(s->children, s2);
887 SuffInsert(s2->parents, s); 887 SuffInsert(s2->parents, s);
888 } 888 }
889 } 889 }
@@ -924,27 +924,27 @@ SuffScanTargets(void *targetp, void *gsp @@ -924,27 +924,27 @@ SuffScanTargets(void *targetp, void *gsp
924 if (target->type == OP_TRANSFORM) 924 if (target->type == OP_TRANSFORM)
925 return 0; 925 return 0;
926 926
927 if ((ptr = strstr(target->name, gs->s->name)) == NULL || 927 if ((ptr = strstr(target->name, gs->s->name)) == NULL ||
928 ptr == target->name) 928 ptr == target->name)
929 return 0; 929 return 0;
930 930
931 if (SuffParseTransform(target->name, &s, &t)) { 931 if (SuffParseTransform(target->name, &s, &t)) {
932 if (*gs->gn == target) { 932 if (*gs->gn == target) {
933 gs->r = TRUE; 933 gs->r = TRUE;
934 *gs->gn = NULL; 934 *gs->gn = NULL;
935 Targ_SetMain(NULL); 935 Targ_SetMain(NULL);
936 } 936 }
937 Lst_Destroy(target->children, NULL); 937 Lst_FreeS(target->children);
938 target->children = Lst_Init(); 938 target->children = Lst_Init();
939 target->type = OP_TRANSFORM; 939 target->type = OP_TRANSFORM;
940 /* 940 /*
941 * link the two together in the proper relationship and order 941 * link the two together in the proper relationship and order
942 */ 942 */
943 if (DEBUG(SUFF)) { 943 if (DEBUG(SUFF)) {
944 fprintf(debug_file, "defining transformation from `%s' to `%s'\n", 944 fprintf(debug_file, "defining transformation from `%s' to `%s'\n",
945 s->name, t->name); 945 s->name, t->name);
946 } 946 }
947 SuffInsert(t->children, s); 947 SuffInsert(t->children, s);
948 SuffInsert(s->parents, t); 948 SuffInsert(s->parents, t);
949 } 949 }
950 return 0; 950 return 0;
@@ -966,27 +966,27 @@ SuffScanTargets(void *targetp, void *gsp @@ -966,27 +966,27 @@ SuffScanTargets(void *targetp, void *gsp
966 * A GNode is created for the suffix and a Suff structure is created and 966 * A GNode is created for the suffix and a Suff structure is created and
967 * added to the suffixes list unless the suffix was already known. 967 * added to the suffixes list unless the suffix was already known.
968 * The mainNode passed can be modified if a target mutated into a 968 * The mainNode passed can be modified if a target mutated into a
969 * transform and that target happened to be the main target. 969 * transform and that target happened to be the main target.
970 *----------------------------------------------------------------------- 970 *-----------------------------------------------------------------------
971 */ 971 */
972void 972void
973Suff_AddSuffix(char *str, GNode **gn) 973Suff_AddSuffix(char *str, GNode **gn)
974{ 974{
975 Suff *s; /* new suffix descriptor */ 975 Suff *s; /* new suffix descriptor */
976 LstNode ln; 976 LstNode ln;
977 GNodeSuff gs; 977 GNodeSuff gs;
978 978
979 ln = Lst_Find(sufflist, SuffSuffHasNameP, str); 979 ln = Lst_FindS(sufflist, SuffSuffHasNameP, str);
980 if (ln == NULL) { 980 if (ln == NULL) {
981 s = bmake_malloc(sizeof(Suff)); 981 s = bmake_malloc(sizeof(Suff));
982 982
983 s->name = bmake_strdup(str); 983 s->name = bmake_strdup(str);
984 s->nameLen = strlen(s->name); 984 s->nameLen = strlen(s->name);
985 s->searchPath = Lst_Init(); 985 s->searchPath = Lst_Init();
986 s->children = Lst_Init(); 986 s->children = Lst_Init();
987 s->parents = Lst_Init(); 987 s->parents = Lst_Init();
988 s->ref = Lst_Init(); 988 s->ref = Lst_Init();
989 s->sNum = sNum++; 989 s->sNum = sNum++;
990 s->flags = 0; 990 s->flags = 0;
991 s->refCount = 1; 991 s->refCount = 1;
992 992
@@ -1018,27 +1018,27 @@ Suff_AddSuffix(char *str, GNode **gn) @@ -1018,27 +1018,27 @@ Suff_AddSuffix(char *str, GNode **gn)
1018 * The searchPath for the desired suffix or NULL if the suffix isn't 1018 * The searchPath for the desired suffix or NULL if the suffix isn't
1019 * defined. 1019 * defined.
1020 * 1020 *
1021 * Side Effects: 1021 * Side Effects:
1022 * None 1022 * None
1023 *----------------------------------------------------------------------- 1023 *-----------------------------------------------------------------------
1024 */ 1024 */
1025Lst 1025Lst
1026Suff_GetPath(char *sname) 1026Suff_GetPath(char *sname)
1027{ 1027{
1028 LstNode ln; 1028 LstNode ln;
1029 Suff *s; 1029 Suff *s;
1030 1030
1031 ln = Lst_Find(sufflist, SuffSuffHasNameP, sname); 1031 ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
1032 if (ln == NULL) { 1032 if (ln == NULL) {
1033 return NULL; 1033 return NULL;
1034 } else { 1034 } else {
1035 s = Lst_DatumS(ln); 1035 s = Lst_DatumS(ln);
1036 return s->searchPath; 1036 return s->searchPath;
1037 } 1037 }
1038} 1038}
1039 1039
1040/*- 1040/*-
1041 *----------------------------------------------------------------------- 1041 *-----------------------------------------------------------------------
1042 * Suff_DoPaths -- 1042 * Suff_DoPaths --
1043 * Extend the search paths for all suffixes to include the default 1043 * Extend the search paths for all suffixes to include the default
1044 * search path. 1044 * search path.
@@ -1074,66 +1074,66 @@ Suff_DoPaths(void) @@ -1074,66 +1074,66 @@ Suff_DoPaths(void)
1074 if (!Lst_IsEmpty (s->searchPath)) { 1074 if (!Lst_IsEmpty (s->searchPath)) {
1075#ifdef INCLUDES 1075#ifdef INCLUDES
1076 if (s->flags & SUFF_INCLUDE) { 1076 if (s->flags & SUFF_INCLUDE) {
1077 Dir_Concat(inIncludes, s->searchPath); 1077 Dir_Concat(inIncludes, s->searchPath);
1078 } 1078 }
1079#endif /* INCLUDES */ 1079#endif /* INCLUDES */
1080#ifdef LIBRARIES 1080#ifdef LIBRARIES
1081 if (s->flags & SUFF_LIBRARY) { 1081 if (s->flags & SUFF_LIBRARY) {
1082 Dir_Concat(inLibs, s->searchPath); 1082 Dir_Concat(inLibs, s->searchPath);
1083 } 1083 }
1084#endif /* LIBRARIES */ 1084#endif /* LIBRARIES */
1085 Dir_Concat(s->searchPath, dirSearchPath); 1085 Dir_Concat(s->searchPath, dirSearchPath);
1086 } else { 1086 } else {
1087 Lst_Destroy(s->searchPath, Dir_Destroy); 1087 Lst_DestroyS(s->searchPath, Dir_Destroy);
1088 s->searchPath = Lst_CopyS(dirSearchPath, Dir_CopyDir); 1088 s->searchPath = Lst_CopyS(dirSearchPath, Dir_CopyDir);
1089 } 1089 }
1090 } 1090 }
1091 Lst_CloseS(sufflist); 1091 Lst_CloseS(sufflist);
1092 1092
1093 Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL); 1093 Var_Set(".INCLUDES", ptr = Dir_MakeFlags("-I", inIncludes), VAR_GLOBAL);
1094 free(ptr); 1094 free(ptr);
1095 Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL); 1095 Var_Set(".LIBS", ptr = Dir_MakeFlags("-L", inLibs), VAR_GLOBAL);
1096 free(ptr); 1096 free(ptr);
1097 1097
1098 Lst_Destroy(inIncludes, Dir_Destroy); 1098 Lst_DestroyS(inIncludes, Dir_Destroy);
1099 Lst_Destroy(inLibs, Dir_Destroy); 1099 Lst_DestroyS(inLibs, Dir_Destroy);
1100} 1100}
1101 1101
1102/*- 1102/*-
1103 *----------------------------------------------------------------------- 1103 *-----------------------------------------------------------------------
1104 * Suff_AddInclude -- 1104 * Suff_AddInclude --
1105 * Add the given suffix as a type of file which gets included. 1105 * Add the given suffix as a type of file which gets included.
1106 * Called from the parse module when a .INCLUDES line is parsed. 1106 * Called from the parse module when a .INCLUDES line is parsed.
1107 * The suffix must have already been defined. 1107 * The suffix must have already been defined.
1108 * 1108 *
1109 * Input: 1109 * Input:
1110 * sname Name of the suffix to mark 1110 * sname Name of the suffix to mark
1111 * 1111 *
1112 * Results: 1112 * Results:
1113 * None. 1113 * None.
1114 * 1114 *
1115 * Side Effects: 1115 * Side Effects:
1116 * The SUFF_INCLUDE bit is set in the suffix's flags field 1116 * The SUFF_INCLUDE bit is set in the suffix's flags field
1117 * 1117 *
1118 *----------------------------------------------------------------------- 1118 *-----------------------------------------------------------------------
1119 */ 1119 */
1120void 1120void
1121Suff_AddInclude(char *sname) 1121Suff_AddInclude(char *sname)
1122{ 1122{
1123 LstNode ln; 1123 LstNode ln;
1124 Suff *s; 1124 Suff *s;
1125 1125
1126 ln = Lst_Find(sufflist, SuffSuffHasNameP, sname); 1126 ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
1127 if (ln != NULL) { 1127 if (ln != NULL) {
1128 s = Lst_DatumS(ln); 1128 s = Lst_DatumS(ln);
1129 s->flags |= SUFF_INCLUDE; 1129 s->flags |= SUFF_INCLUDE;
1130 } 1130 }
1131} 1131}
1132 1132
1133/*- 1133/*-
1134 *----------------------------------------------------------------------- 1134 *-----------------------------------------------------------------------
1135 * Suff_AddLib -- 1135 * Suff_AddLib --
1136 * Add the given suffix as a type of file which is a library. 1136 * Add the given suffix as a type of file which is a library.
1137 * Called from the parse module when parsing a .LIBS line. The 1137 * Called from the parse module when parsing a .LIBS line. The
1138 * suffix must have been defined via .SUFFIXES before this is 1138 * suffix must have been defined via .SUFFIXES before this is
1139 * called. 1139 * called.
@@ -1145,27 +1145,27 @@ Suff_AddInclude(char *sname) @@ -1145,27 +1145,27 @@ Suff_AddInclude(char *sname)
1145 * None. 1145 * None.
1146 * 1146 *
1147 * Side Effects: 1147 * Side Effects:
1148 * The SUFF_LIBRARY bit is set in the suffix's flags field 1148 * The SUFF_LIBRARY bit is set in the suffix's flags field
1149 * 1149 *
1150 *----------------------------------------------------------------------- 1150 *-----------------------------------------------------------------------
1151 */ 1151 */
1152void 1152void
1153Suff_AddLib(char *sname) 1153Suff_AddLib(char *sname)
1154{ 1154{
1155 LstNode ln; 1155 LstNode ln;
1156 Suff *s; 1156 Suff *s;
1157 1157
1158 ln = Lst_Find(sufflist, SuffSuffHasNameP, sname); 1158 ln = Lst_FindS(sufflist, SuffSuffHasNameP, sname);
1159 if (ln != NULL) { 1159 if (ln != NULL) {
1160 s = Lst_DatumS(ln); 1160 s = Lst_DatumS(ln);
1161 s->flags |= SUFF_LIBRARY; 1161 s->flags |= SUFF_LIBRARY;
1162 } 1162 }
1163} 1163}
1164 1164
1165 /********** Implicit Source Search Functions *********/ 1165 /********** Implicit Source Search Functions *********/
1166 1166
1167/*- 1167/*-
1168 *----------------------------------------------------------------------- 1168 *-----------------------------------------------------------------------
1169 * SuffAddSrc -- 1169 * SuffAddSrc --
1170 * Add a suffix as a Src structure to the given list with its parent 1170 * Add a suffix as a Src structure to the given list with its parent
1171 * being the given Src structure. If the suffix is the null suffix, 1171 * being the given Src structure. If the suffix is the null suffix,
@@ -1298,27 +1298,27 @@ SuffRemoveSrc(Lst l) @@ -1298,27 +1298,27 @@ SuffRemoveSrc(Lst l)
1298 free(s->file); 1298 free(s->file);
1299 if (!s->parent) 1299 if (!s->parent)
1300 free(s->pref); 1300 free(s->pref);
1301 else { 1301 else {
1302#ifdef DEBUG_SRC 1302#ifdef DEBUG_SRC
1303 LstNode ln2 = Lst_MemberS(s->parent->cp, s); 1303 LstNode ln2 = Lst_MemberS(s->parent->cp, s);
1304 if (ln2 != NULL) 1304 if (ln2 != NULL)
1305 Lst_RemoveS(s->parent->cp, ln2); 1305 Lst_RemoveS(s->parent->cp, ln2);
1306#endif 1306#endif
1307 --s->parent->children; 1307 --s->parent->children;
1308 } 1308 }
1309#ifdef DEBUG_SRC 1309#ifdef DEBUG_SRC
1310 fprintf(debug_file, "free: [l=%p] p=%p %d\n", l, s, s->children); 1310 fprintf(debug_file, "free: [l=%p] p=%p %d\n", l, s, s->children);
1311 Lst_Destroy(s->cp, NULL); 1311 Lst_FreeS(s->cp);
1312#endif 1312#endif
1313 Lst_RemoveS(l, ln); 1313 Lst_RemoveS(l, ln);
1314 free(s); 1314 free(s);
1315 t |= 1; 1315 t |= 1;
1316 Lst_CloseS(l); 1316 Lst_CloseS(l);
1317 return TRUE; 1317 return TRUE;
1318 } 1318 }
1319#ifdef DEBUG_SRC 1319#ifdef DEBUG_SRC
1320 else { 1320 else {
1321 fprintf(debug_file, "keep: [l=%p] p=%p %d: ", l, s, s->children); 1321 fprintf(debug_file, "keep: [l=%p] p=%p %d: ", l, s, s->children);
1322 Lst_ForEach(s->cp, PrintAddr, NULL); 1322 Lst_ForEach(s->cp, PrintAddr, NULL);
1323 fprintf(debug_file, "\n"); 1323 fprintf(debug_file, "\n");
1324 } 1324 }
@@ -1450,27 +1450,27 @@ SuffFindCmds(Src *targ, Lst slst) @@ -1450,27 +1450,27 @@ SuffFindCmds(Src *targ, Lst slst)
1450 1450
1451 cp = strrchr(s->name, '/'); 1451 cp = strrchr(s->name, '/');
1452 if (cp == NULL) { 1452 if (cp == NULL) {
1453 cp = s->name; 1453 cp = s->name;
1454 } else { 1454 } else {
1455 cp++; 1455 cp++;
1456 } 1456 }
1457 if (strncmp(cp, targ->pref, prefLen) != 0) 1457 if (strncmp(cp, targ->pref, prefLen) != 0)
1458 continue; 1458 continue;
1459 /* 1459 /*
1460 * The node matches the prefix ok, see if it has a known 1460 * The node matches the prefix ok, see if it has a known
1461 * suffix. 1461 * suffix.
1462 */ 1462 */
1463 ln = Lst_Find(sufflist, SuffSuffHasNameP, &cp[prefLen]); 1463 ln = Lst_FindS(sufflist, SuffSuffHasNameP, &cp[prefLen]);
1464 if (ln == NULL) 1464 if (ln == NULL)
1465 continue; 1465 continue;
1466 /* 1466 /*
1467 * It even has a known suffix, see if there's a transformation 1467 * It even has a known suffix, see if there's a transformation
1468 * defined between the node's suffix and the target's suffix. 1468 * defined between the node's suffix and the target's suffix.
1469 * 1469 *
1470 * XXX: Handle multi-stage transformations here, too. 1470 * XXX: Handle multi-stage transformations here, too.
1471 */ 1471 */
1472 suff = Lst_DatumS(ln); 1472 suff = Lst_DatumS(ln);
1473 1473
1474 /* XXX: Can targ->suff be NULL here? */ 1474 /* XXX: Can targ->suff be NULL here? */
1475 if (targ->suff != NULL && 1475 if (targ->suff != NULL &&
1476 Lst_MemberS(suff->parents, targ->suff) != NULL) 1476 Lst_MemberS(suff->parents, targ->suff) != NULL)
@@ -1641,27 +1641,27 @@ SuffExpandChildren(LstNode cln, GNode *p @@ -1641,27 +1641,27 @@ SuffExpandChildren(LstNode cln, GNode *p
1641 while(!Lst_IsEmpty(members)) { 1641 while(!Lst_IsEmpty(members)) {
1642 gn = Lst_DequeueS(members); 1642 gn = Lst_DequeueS(members);
1643 1643
1644 if (DEBUG(SUFF)) { 1644 if (DEBUG(SUFF)) {
1645 fprintf(debug_file, "%s...", gn->name); 1645 fprintf(debug_file, "%s...", gn->name);
1646 } 1646 }
1647 /* Add gn to the parents child list before the original child */ 1647 /* Add gn to the parents child list before the original child */
1648 Lst_InsertBeforeS(pgn->children, cln, gn); 1648 Lst_InsertBeforeS(pgn->children, cln, gn);
1649 Lst_AppendS(gn->parents, pgn); 1649 Lst_AppendS(gn->parents, pgn);
1650 pgn->unmade++; 1650 pgn->unmade++;
1651 /* Expand wildcards on new node */ 1651 /* Expand wildcards on new node */
1652 SuffExpandWildcards(Lst_PrevS(cln), pgn); 1652 SuffExpandWildcards(Lst_PrevS(cln), pgn);
1653 } 1653 }
1654 Lst_Destroy(members, NULL); 1654 Lst_FreeS(members);
1655 1655
1656 /* 1656 /*
1657 * Free the result 1657 * Free the result
1658 */ 1658 */
1659 free(cp); 1659 free(cp);
1660 } 1660 }
1661 if (DEBUG(SUFF)) { 1661 if (DEBUG(SUFF)) {
1662 fprintf(debug_file, "\n"); 1662 fprintf(debug_file, "\n");
1663 } 1663 }
1664 1664
1665 /* 1665 /*
1666 * Now the source is expanded, remove it from the list of children to 1666 * Now the source is expanded, remove it from the list of children to
1667 * keep it from being processed. 1667 * keep it from being processed.
@@ -1695,30 +1695,27 @@ SuffExpandWildcards(LstNode cln, GNode * @@ -1695,30 +1695,27 @@ SuffExpandWildcards(LstNode cln, GNode *
1695 cp = Lst_DequeueS(explist); 1695 cp = Lst_DequeueS(explist);
1696 1696
1697 if (DEBUG(SUFF)) { 1697 if (DEBUG(SUFF)) {
1698 fprintf(debug_file, "%s...", cp); 1698 fprintf(debug_file, "%s...", cp);
1699 } 1699 }
1700 gn = Targ_FindNode(cp, TARG_CREATE); 1700 gn = Targ_FindNode(cp, TARG_CREATE);
1701 1701
1702 /* Add gn to the parents child list before the original child */ 1702 /* Add gn to the parents child list before the original child */
1703 Lst_InsertBeforeS(pgn->children, cln, gn); 1703 Lst_InsertBeforeS(pgn->children, cln, gn);
1704 Lst_AppendS(gn->parents, pgn); 1704 Lst_AppendS(gn->parents, pgn);
1705 pgn->unmade++; 1705 pgn->unmade++;
1706 } 1706 }
1707 1707
1708 /* 1708 Lst_FreeS(explist);
1709 * Nuke what's left of the list 
1710 */ 
1711 Lst_Destroy(explist, NULL); 
1712 1709
1713 if (DEBUG(SUFF)) { 1710 if (DEBUG(SUFF)) {
1714 fprintf(debug_file, "\n"); 1711 fprintf(debug_file, "\n");
1715 } 1712 }
1716 1713
1717 /* 1714 /*
1718 * Now the source is expanded, remove it from the list of children to 1715 * Now the source is expanded, remove it from the list of children to
1719 * keep it from being processed. 1716 * keep it from being processed.
1720 */ 1717 */
1721 pgn->unmade--; 1718 pgn->unmade--;
1722 Lst_RemoveS(pgn->children, cln); 1719 Lst_RemoveS(pgn->children, cln);
1723 Lst_RemoveS(cgn->parents, Lst_MemberS(cgn->parents, pgn)); 1720 Lst_RemoveS(cgn->parents, Lst_MemberS(cgn->parents, pgn));
1724} 1721}
@@ -1743,27 +1740,27 @@ SuffExpandWildcards(LstNode cln, GNode * @@ -1743,27 +1740,27 @@ SuffExpandWildcards(LstNode cln, GNode *
1743 * 1740 *
1744 *----------------------------------------------------------------------- 1741 *-----------------------------------------------------------------------
1745 */ 1742 */
1746Lst 1743Lst
1747Suff_FindPath(GNode* gn) 1744Suff_FindPath(GNode* gn)
1748{ 1745{
1749 Suff *suff = gn->suffix; 1746 Suff *suff = gn->suffix;
1750 1747
1751 if (suff == NULL) { 1748 if (suff == NULL) {
1752 SuffixCmpData sd; /* Search string data */ 1749 SuffixCmpData sd; /* Search string data */
1753 LstNode ln; 1750 LstNode ln;
1754 sd.len = strlen(gn->name); 1751 sd.len = strlen(gn->name);
1755 sd.ename = gn->name + sd.len; 1752 sd.ename = gn->name + sd.len;
1756 ln = Lst_Find(sufflist, SuffSuffIsSuffixP, &sd); 1753 ln = Lst_FindS(sufflist, SuffSuffIsSuffixP, &sd);
1757 1754
1758 if (DEBUG(SUFF)) { 1755 if (DEBUG(SUFF)) {
1759 fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name); 1756 fprintf(debug_file, "Wildcard expanding \"%s\"...", gn->name);
1760 } 1757 }
1761 if (ln != NULL) 1758 if (ln != NULL)
1762 suff = Lst_DatumS(ln); 1759 suff = Lst_DatumS(ln);
1763 /* XXX: Here we can save the suffix so we don't have to do this again */ 1760 /* XXX: Here we can save the suffix so we don't have to do this again */
1764 } 1761 }
1765 1762
1766 if (suff != NULL) { 1763 if (suff != NULL) {
1767 if (DEBUG(SUFF)) { 1764 if (DEBUG(SUFF)) {
1768 fprintf(debug_file, "suffix is \"%s\"...", suff->name); 1765 fprintf(debug_file, "suffix is \"%s\"...", suff->name);
1769 } 1766 }
@@ -1954,28 +1951,28 @@ SuffFindArchiveDeps(GNode *gn, Lst slst) @@ -1954,28 +1951,28 @@ SuffFindArchiveDeps(GNode *gn, Lst slst)
1954 */ 1951 */
1955 Var_Set(MEMBER, name, gn); 1952 Var_Set(MEMBER, name, gn);
1956 Var_Set(ARCHIVE, gn->name, gn); 1953 Var_Set(ARCHIVE, gn->name, gn);
1957 1954
1958 /* 1955 /*
1959 * Set $@ for compatibility with other makes 1956 * Set $@ for compatibility with other makes
1960 */ 1957 */
1961 Var_Set(TARGET, gn->name, gn); 1958 Var_Set(TARGET, gn->name, gn);
1962 1959
1963 /* 1960 /*
1964 * Now we've got the important local variables set, expand any sources 1961 * Now we've got the important local variables set, expand any sources
1965 * that still contain variables or wildcards in their names. 1962 * that still contain variables or wildcards in their names.
1966 */ 1963 */
1967 for (ln = Lst_First(gn->children); ln != NULL; ln = nln) { 1964 for (ln = Lst_FirstS(gn->children); ln != NULL; ln = nln) {
1968 nln = Lst_Succ(ln); 1965 nln = Lst_SuccS(ln);
1969 SuffExpandChildren(ln, gn); 1966 SuffExpandChildren(ln, gn);
1970 } 1967 }
1971 1968
1972 if (ms != NULL) { 1969 if (ms != NULL) {
1973 /* 1970 /*
1974 * Member has a known suffix, so look for a transformation rule from 1971 * Member has a known suffix, so look for a transformation rule from
1975 * it to a possible suffix of the archive. Rather than searching 1972 * it to a possible suffix of the archive. Rather than searching
1976 * through the entire list, we just look at suffixes to which the 1973 * through the entire list, we just look at suffixes to which the
1977 * member's suffix may be transformed... 1974 * member's suffix may be transformed...
1978 */ 1975 */
1979 SuffixCmpData sd; /* Search string data */ 1976 SuffixCmpData sd; /* Search string data */
1980 1977
1981 /* 1978 /*
@@ -2460,27 +2457,27 @@ SuffFindDeps(GNode *gn, Lst slst) @@ -2460,27 +2457,27 @@ SuffFindDeps(GNode *gn, Lst slst)
2460 SuffFindArchiveDeps(gn, slst); 2457 SuffFindArchiveDeps(gn, slst);
2461 } else if (gn->type & OP_LIB) { 2458 } else if (gn->type & OP_LIB) {
2462 /* 2459 /*
2463 * If the node is a library, it is the arch module's job to find it 2460 * If the node is a library, it is the arch module's job to find it
2464 * and set the TARGET variable accordingly. We merely provide the 2461 * and set the TARGET variable accordingly. We merely provide the
2465 * search path, assuming all libraries end in ".a" (if the suffix 2462 * search path, assuming all libraries end in ".a" (if the suffix
2466 * hasn't been defined, there's nothing we can do for it, so we just 2463 * hasn't been defined, there's nothing we can do for it, so we just
2467 * set the TARGET variable to the node's name in order to give it a 2464 * set the TARGET variable to the node's name in order to give it a
2468 * value). 2465 * value).
2469 */ 2466 */
2470 LstNode ln; 2467 LstNode ln;
2471 Suff *s; 2468 Suff *s;
2472 2469
2473 ln = Lst_Find(sufflist, SuffSuffHasNameP, LIBSUFF); 2470 ln = Lst_FindS(sufflist, SuffSuffHasNameP, LIBSUFF);
2474 if (gn->suffix) 2471 if (gn->suffix)
2475 gn->suffix->refCount--; 2472 gn->suffix->refCount--;
2476 if (ln != NULL) { 2473 if (ln != NULL) {
2477 gn->suffix = s = Lst_DatumS(ln); 2474 gn->suffix = s = Lst_DatumS(ln);
2478 gn->suffix->refCount++; 2475 gn->suffix->refCount++;
2479 Arch_FindLib(gn, s->searchPath); 2476 Arch_FindLib(gn, s->searchPath);
2480 } else { 2477 } else {
2481 gn->suffix = NULL; 2478 gn->suffix = NULL;
2482 Var_Set(TARGET, gn->name, gn); 2479 Var_Set(TARGET, gn->name, gn);
2483 } 2480 }
2484 /* 2481 /*
2485 * Because a library (-lfoo) target doesn't follow the standard 2482 * Because a library (-lfoo) target doesn't follow the standard
2486 * filesystem conventions, we don't set the regular variables for 2483 * filesystem conventions, we don't set the regular variables for
@@ -2508,27 +2505,27 @@ SuffFindDeps(GNode *gn, Lst slst) @@ -2508,27 +2505,27 @@ SuffFindDeps(GNode *gn, Lst slst)
2508 * 2505 *
2509 * Notes: 2506 * Notes:
2510 * Need to handle the changing of the null suffix gracefully so the 2507 * Need to handle the changing of the null suffix gracefully so the
2511 * old transformation rules don't just go away. 2508 * old transformation rules don't just go away.
2512 * 2509 *
2513 *----------------------------------------------------------------------- 2510 *-----------------------------------------------------------------------
2514 */ 2511 */
2515void 2512void
2516Suff_SetNull(char *name) 2513Suff_SetNull(char *name)
2517{ 2514{
2518 Suff *s; 2515 Suff *s;
2519 LstNode ln; 2516 LstNode ln;
2520 2517
2521 ln = Lst_Find(sufflist, SuffSuffHasNameP, name); 2518 ln = Lst_FindS(sufflist, SuffSuffHasNameP, name);
2522 if (ln != NULL) { 2519 if (ln != NULL) {
2523 s = Lst_DatumS(ln); 2520 s = Lst_DatumS(ln);
2524 if (suffNull != NULL) { 2521 if (suffNull != NULL) {
2525 suffNull->flags &= ~SUFF_NULL; 2522 suffNull->flags &= ~SUFF_NULL;
2526 } 2523 }
2527 s->flags |= SUFF_NULL; 2524 s->flags |= SUFF_NULL;
2528 /* 2525 /*
2529 * XXX: Here's where the transformation mangling would take place 2526 * XXX: Here's where the transformation mangling would take place
2530 */ 2527 */
2531 suffNull = s; 2528 suffNull = s;
2532 } else { 2529 } else {
2533 Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.", 2530 Parse_Error(PARSE_WARNING, "Desired null suffix %s not defined.",
2534 name); 2531 name);
@@ -2573,32 +2570,32 @@ Suff_Init(void) @@ -2573,32 +2570,32 @@ Suff_Init(void)
2573 * 2570 *
2574 * Results: 2571 * Results:
2575 * None 2572 * None
2576 * 2573 *
2577 * Side Effects: 2574 * Side Effects:
2578 * The memory is free'd. 2575 * The memory is free'd.
2579 *---------------------------------------------------------------------- 2576 *----------------------------------------------------------------------
2580 */ 2577 */
2581 2578
2582void 2579void
2583Suff_End(void) 2580Suff_End(void)
2584{ 2581{
2585#ifdef CLEANUP 2582#ifdef CLEANUP
2586 Lst_Destroy(sufflist, SuffFree); 2583 Lst_DestroyS(sufflist, SuffFree);
2587 Lst_Destroy(suffClean, SuffFree); 2584 Lst_DestroyS(suffClean, SuffFree);
2588 if (suffNull) 2585 if (suffNull)
2589 SuffFree(suffNull); 2586 SuffFree(suffNull);
2590 Lst_Destroy(srclist, NULL); 2587 Lst_FreeS(srclist);
2591 Lst_Destroy(transforms, NULL); 2588 Lst_FreeS(transforms);
2592#endif 2589#endif
2593} 2590}
2594 2591
2595 2592
2596/********************* DEBUGGING FUNCTIONS **********************/ 2593/********************* DEBUGGING FUNCTIONS **********************/
2597 2594
2598static int SuffPrintName(void *s, void *dummy MAKE_ATTR_UNUSED) 2595static int SuffPrintName(void *s, void *dummy MAKE_ATTR_UNUSED)
2599{ 2596{
2600 2597
2601 fprintf(debug_file, "%s ", ((Suff *)s)->name); 2598 fprintf(debug_file, "%s ", ((Suff *)s)->name);
2602 return 0; 2599 return 0;
2603} 2600}
2604 2601
@@ -2623,30 +2620,30 @@ SuffPrintSuff(void *sp, void *dummy MAKE @@ -2623,30 +2620,30 @@ SuffPrintSuff(void *sp, void *dummy MAKE
2623 break; 2620 break;
2624 case SUFF_INCLUDE: 2621 case SUFF_INCLUDE:
2625 fprintf(debug_file, "INCLUDE"); 2622 fprintf(debug_file, "INCLUDE");
2626 break; 2623 break;
2627 case SUFF_LIBRARY: 2624 case SUFF_LIBRARY:
2628 fprintf(debug_file, "LIBRARY"); 2625 fprintf(debug_file, "LIBRARY");
2629 break; 2626 break;
2630 } 2627 }
2631 fputc(flags ? '|' : ')', debug_file); 2628 fputc(flags ? '|' : ')', debug_file);
2632 } 2629 }
2633 } 2630 }
2634 fputc('\n', debug_file); 2631 fputc('\n', debug_file);
2635 fprintf(debug_file, "#\tTo: "); 2632 fprintf(debug_file, "#\tTo: ");
2636 Lst_ForEach(s->parents, SuffPrintName, NULL); 2633 Lst_ForEachS(s->parents, SuffPrintName, NULL);
2637 fputc('\n', debug_file); 2634 fputc('\n', debug_file);
2638 fprintf(debug_file, "#\tFrom: "); 2635 fprintf(debug_file, "#\tFrom: ");
2639 Lst_ForEach(s->children, SuffPrintName, NULL); 2636 Lst_ForEachS(s->children, SuffPrintName, NULL);
2640 fputc('\n', debug_file); 2637 fputc('\n', debug_file);
2641 fprintf(debug_file, "#\tSearch Path: "); 2638 fprintf(debug_file, "#\tSearch Path: ");
2642 Dir_PrintPath(s->searchPath); 2639 Dir_PrintPath(s->searchPath);
2643 fputc('\n', debug_file); 2640 fputc('\n', debug_file);
2644 return 0; 2641 return 0;
2645} 2642}
2646 2643
2647static int 2644static int
2648SuffPrintTrans(void *tp, void *dummy MAKE_ATTR_UNUSED) 2645SuffPrintTrans(void *tp, void *dummy MAKE_ATTR_UNUSED)
2649{ 2646{
2650 GNode *t = (GNode *)tp; 2647 GNode *t = (GNode *)tp;
2651 2648
2652 fprintf(debug_file, "%-16s: ", t->name); 2649 fprintf(debug_file, "%-16s: ", t->name);

cvs diff -r1.72 -r1.73 src/usr.bin/make/targ.c (expand / switch to unified diff)

--- src/usr.bin/make/targ.c 2020/08/24 20:15:51 1.72
+++ src/usr.bin/make/targ.c 2020/08/26 22:55:46 1.73
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $ */ 1/* $NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988, 1989, 1990, 1993 4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. 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.
@@ -59,34 +59,34 @@ @@ -59,34 +59,34 @@
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#ifndef MAKE_NATIVE 71#ifndef MAKE_NATIVE
72static char rcsid[] = "$NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $"; 72static char rcsid[] = "$NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $";
73#else 73#else
74#include <sys/cdefs.h> 74#include <sys/cdefs.h>
75#ifndef lint 75#ifndef lint
76#if 0 76#if 0
77static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94"; 77static char sccsid[] = "@(#)targ.c 8.2 (Berkeley) 3/19/94";
78#else 78#else
79__RCSID("$NetBSD: targ.c,v 1.72 2020/08/24 20:15:51 rillig Exp $"); 79__RCSID("$NetBSD: targ.c,v 1.73 2020/08/26 22:55:46 rillig Exp $");
80#endif 80#endif
81#endif /* not lint */ 81#endif /* not lint */
82#endif 82#endif
83 83
84/*- 84/*-
85 * targ.c -- 85 * targ.c --
86 * Functions for maintaining the Lst allTargets. Target nodes are 86 * Functions for maintaining the Lst allTargets. Target nodes are
87 * kept in two structures: a Lst, maintained by the list library, and a 87 * kept in two structures: a Lst, maintained by the list library, and a
88 * hash table, maintained by the hash library. 88 * hash table, maintained by the hash library.
89 * 89 *
90 * Interface: 90 * Interface:
91 * Targ_Init Initialization procedure. 91 * Targ_Init Initialization procedure.
92 * 92 *
@@ -178,29 +178,29 @@ Targ_Init(void) @@ -178,29 +178,29 @@ Targ_Init(void)
178 * 178 *
179 * Results: 179 * Results:
180 * None 180 * None
181 * 181 *
182 * Side Effects: 182 * Side Effects:
183 * All lists and gnodes are cleared 183 * All lists and gnodes are cleared
184 *----------------------------------------------------------------------- 184 *-----------------------------------------------------------------------
185 */ 185 */
186void 186void
187Targ_End(void) 187Targ_End(void)
188{ 188{
189 Targ_Stats(); 189 Targ_Stats();
190#ifdef CLEANUP 190#ifdef CLEANUP
191 Lst_Destroy(allTargets, NULL); 191 Lst_FreeS(allTargets);
192 if (allGNs) 192 if (allGNs != NULL)
193 Lst_Destroy(allGNs, TargFreeGN); 193 Lst_DestroyS(allGNs, TargFreeGN);
194 Hash_DeleteTable(&targets); 194 Hash_DeleteTable(&targets);
195#endif 195#endif
196} 196}
197 197
198void 198void
199Targ_Stats(void) 199Targ_Stats(void)
200{ 200{
201 Hash_DebugStats(&targets, "targets"); 201 Hash_DebugStats(&targets, "targets");
202} 202}
203 203
204/*- 204/*-
205 *----------------------------------------------------------------------- 205 *-----------------------------------------------------------------------
206 * Targ_List -- 206 * Targ_List --
@@ -293,34 +293,34 @@ Targ_NewGN(const char *name) @@ -293,34 +293,34 @@ Targ_NewGN(const char *name)
293 *----------------------------------------------------------------------- 293 *-----------------------------------------------------------------------
294 */ 294 */
295static void 295static void
296TargFreeGN(void *gnp) 296TargFreeGN(void *gnp)
297{ 297{
298 GNode *gn = (GNode *)gnp; 298 GNode *gn = (GNode *)gnp;
299 299
300 300
301 free(gn->name); 301 free(gn->name);
302 free(gn->uname); 302 free(gn->uname);
303 free(gn->path); 303 free(gn->path);
304 /* gn->fname points to name allocated when file was opened, don't free */ 304 /* gn->fname points to name allocated when file was opened, don't free */
305 305
306 Lst_Destroy(gn->iParents, NULL); 306 Lst_FreeS(gn->iParents);
307 Lst_Destroy(gn->cohorts, NULL); 307 Lst_FreeS(gn->cohorts);
308 Lst_Destroy(gn->parents, NULL); 308 Lst_FreeS(gn->parents);
309 Lst_Destroy(gn->children, NULL); 309 Lst_FreeS(gn->children);
310 Lst_Destroy(gn->order_succ, NULL); 310 Lst_FreeS(gn->order_succ);
311 Lst_Destroy(gn->order_pred, NULL); 311 Lst_FreeS(gn->order_pred);
312 Hash_DeleteTable(&gn->context); 312 Hash_DeleteTable(&gn->context);
313 Lst_Destroy(gn->commands, NULL); 313 Lst_FreeS(gn->commands);
314 free(gn); 314 free(gn);
315} 315}
316#endif 316#endif
317 317
318 318
319/*- 319/*-
320 *----------------------------------------------------------------------- 320 *-----------------------------------------------------------------------
321 * Targ_FindNode -- 321 * Targ_FindNode --
322 * Find a node in the list using the given name for matching 322 * Find a node in the list using the given name for matching
323 * 323 *
324 * Input: 324 * Input:
325 * name the name to find 325 * name the name to find
326 * flags flags governing events when target not 326 * flags flags governing events when target not