| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $ */ | | 1 | /* $NetBSD: suff.c,v 1.117 2020/08/26 23:08:26 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 |
72 | static char rcsid[] = "$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: suff.c,v 1.117 2020/08/26 23:08:26 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 |
77 | static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; | | 77 | static char sccsid[] = "@(#)suff.c 8.4 (Berkeley) 3/21/94"; |
78 | #else | | 78 | #else |
79 | __RCSID("$NetBSD: suff.c,v 1.116 2020/08/26 22:55:46 rillig Exp $"); | | 79 | __RCSID("$NetBSD: suff.c,v 1.117 2020/08/26 23:08:26 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 |
| @@ -517,26 +517,44 @@ SuffInsert(Lst l, Suff *s) | | | @@ -517,26 +517,44 @@ SuffInsert(Lst l, Suff *s) |
517 | Lst_AppendS(s->ref, l); | | 517 | Lst_AppendS(s->ref, l); |
518 | } else if (s2->sNum != s->sNum) { | | 518 | } else if (s2->sNum != s->sNum) { |
519 | if (DEBUG(SUFF)) { | | 519 | if (DEBUG(SUFF)) { |
520 | fprintf(debug_file, "before %s(%d)\n", s2->name, s2->sNum); | | 520 | fprintf(debug_file, "before %s(%d)\n", s2->name, s2->sNum); |
521 | } | | 521 | } |
522 | Lst_InsertBeforeS(l, ln, s); | | 522 | Lst_InsertBeforeS(l, ln, s); |
523 | s->refCount++; | | 523 | s->refCount++; |
524 | Lst_AppendS(s->ref, l); | | 524 | Lst_AppendS(s->ref, l); |
525 | } else if (DEBUG(SUFF)) { | | 525 | } else if (DEBUG(SUFF)) { |
526 | fprintf(debug_file, "already there\n"); | | 526 | fprintf(debug_file, "already there\n"); |
527 | } | | 527 | } |
528 | } | | 528 | } |
529 | | | 529 | |
| | | 530 | static Suff * |
| | | 531 | SuffNew(const char *name) |
| | | 532 | { |
| | | 533 | Suff *s = bmake_malloc(sizeof(Suff)); |
| | | 534 | |
| | | 535 | s->name = bmake_strdup(name); |
| | | 536 | s->nameLen = strlen(s->name); |
| | | 537 | s->searchPath = Lst_Init(); |
| | | 538 | s->children = Lst_Init(); |
| | | 539 | s->parents = Lst_Init(); |
| | | 540 | s->ref = Lst_Init(); |
| | | 541 | s->sNum = sNum++; |
| | | 542 | s->flags = 0; |
| | | 543 | s->refCount = 1; |
| | | 544 | |
| | | 545 | return s; |
| | | 546 | } |
| | | 547 | |
530 | /*- | | 548 | /*- |
531 | *----------------------------------------------------------------------- | | 549 | *----------------------------------------------------------------------- |
532 | * Suff_ClearSuffixes -- | | 550 | * Suff_ClearSuffixes -- |
533 | * This is gross. Nuke the list of suffixes but keep all transformation | | 551 | * This is gross. Nuke the list of suffixes but keep all transformation |
534 | * rules around. The transformation graph is destroyed in this process, | | 552 | * rules around. The transformation graph is destroyed in this process, |
535 | * but we leave the list of rules so when a new graph is formed the rules | | 553 | * but we leave the list of rules so when a new graph is formed the rules |
536 | * will remain. | | 554 | * will remain. |
537 | * This function is called from the parse module when a | | 555 | * This function is called from the parse module when a |
538 | * .SUFFIXES:\n line is encountered. | | 556 | * .SUFFIXES:\n line is encountered. |
539 | * | | 557 | * |
540 | * Results: | | 558 | * Results: |
541 | * none | | 559 | * none |
542 | * | | 560 | * |
| @@ -544,38 +562,30 @@ SuffInsert(Lst l, Suff *s) | | | @@ -544,38 +562,30 @@ SuffInsert(Lst l, Suff *s) |
544 | * the sufflist and its graph nodes are destroyed | | 562 | * the sufflist and its graph nodes are destroyed |
545 | *----------------------------------------------------------------------- | | 563 | *----------------------------------------------------------------------- |
546 | */ | | 564 | */ |
547 | void | | 565 | void |
548 | Suff_ClearSuffixes(void) | | 566 | Suff_ClearSuffixes(void) |
549 | { | | 567 | { |
550 | #ifdef CLEANUP | | 568 | #ifdef CLEANUP |
551 | Lst_MoveAllS(suffClean, sufflist); | | 569 | Lst_MoveAllS(suffClean, sufflist); |
552 | #endif | | 570 | #endif |
553 | sufflist = Lst_Init(); | | 571 | sufflist = Lst_Init(); |
554 | sNum = 0; | | 572 | sNum = 0; |
555 | if (suffNull) | | 573 | if (suffNull) |
556 | SuffFree(suffNull); | | 574 | SuffFree(suffNull); |
557 | emptySuff = suffNull = bmake_malloc(sizeof(Suff)); | | 575 | emptySuff = suffNull = SuffNew(""); |
558 | | | 576 | |
559 | suffNull->name = bmake_strdup(""); | | | |
560 | suffNull->nameLen = 0; | | | |
561 | suffNull->searchPath = Lst_Init(); | | | |
562 | Dir_Concat(suffNull->searchPath, dirSearchPath); | | 577 | Dir_Concat(suffNull->searchPath, dirSearchPath); |
563 | suffNull->children = Lst_Init(); | | | |
564 | suffNull->parents = Lst_Init(); | | | |
565 | suffNull->ref = Lst_Init(); | | | |
566 | suffNull->sNum = sNum++; | | | |
567 | suffNull->flags = SUFF_NULL; | | 578 | suffNull->flags = SUFF_NULL; |
568 | suffNull->refCount = 1; | | | |
569 | } | | 579 | } |
570 | | | 580 | |
571 | /*- | | 581 | /*- |
572 | *----------------------------------------------------------------------- | | 582 | *----------------------------------------------------------------------- |
573 | * SuffParseTransform -- | | 583 | * SuffParseTransform -- |
574 | * Parse a transformation string to find its two component suffixes. | | 584 | * Parse a transformation string to find its two component suffixes. |
575 | * | | 585 | * |
576 | * Input: | | 586 | * Input: |
577 | * str String being parsed | | 587 | * str String being parsed |
578 | * srcPtr Place to store source of trans. | | 588 | * srcPtr Place to store source of trans. |
579 | * targPtr Place to store target of trans. | | 589 | * targPtr Place to store target of trans. |
580 | * | | 590 | * |
581 | * Results: | | 591 | * Results: |
| @@ -968,37 +978,27 @@ SuffScanTargets(void *targetp, void *gsp | | | @@ -968,37 +978,27 @@ SuffScanTargets(void *targetp, void *gsp |
968 | * The mainNode passed can be modified if a target mutated into a | | 978 | * The mainNode passed can be modified if a target mutated into a |
969 | * transform and that target happened to be the main target. | | 979 | * transform and that target happened to be the main target. |
970 | *----------------------------------------------------------------------- | | 980 | *----------------------------------------------------------------------- |
971 | */ | | 981 | */ |
972 | void | | 982 | void |
973 | Suff_AddSuffix(char *str, GNode **gn) | | 983 | Suff_AddSuffix(char *str, GNode **gn) |
974 | { | | 984 | { |
975 | Suff *s; /* new suffix descriptor */ | | 985 | Suff *s; /* new suffix descriptor */ |
976 | LstNode ln; | | 986 | LstNode ln; |
977 | GNodeSuff gs; | | 987 | GNodeSuff gs; |
978 | | | 988 | |
979 | ln = Lst_FindS(sufflist, SuffSuffHasNameP, str); | | 989 | ln = Lst_FindS(sufflist, SuffSuffHasNameP, str); |
980 | if (ln == NULL) { | | 990 | if (ln == NULL) { |
981 | s = bmake_malloc(sizeof(Suff)); | | 991 | s = SuffNew(str); |
982 | | | | |
983 | s->name = bmake_strdup(str); | | | |
984 | s->nameLen = strlen(s->name); | | | |
985 | s->searchPath = Lst_Init(); | | | |
986 | s->children = Lst_Init(); | | | |
987 | s->parents = Lst_Init(); | | | |
988 | s->ref = Lst_Init(); | | | |
989 | s->sNum = sNum++; | | | |
990 | s->flags = 0; | | | |
991 | s->refCount = 1; | | | |
992 | | | 992 | |
993 | Lst_AppendS(sufflist, s); | | 993 | Lst_AppendS(sufflist, s); |
994 | /* | | 994 | /* |
995 | * We also look at our existing targets list to see if adding | | 995 | * We also look at our existing targets list to see if adding |
996 | * this suffix will make one of our current targets mutate into | | 996 | * this suffix will make one of our current targets mutate into |
997 | * a suffix rule. This is ugly, but other makes treat all targets | | 997 | * a suffix rule. This is ugly, but other makes treat all targets |
998 | * that start with a . as suffix rules. | | 998 | * that start with a . as suffix rules. |
999 | */ | | 999 | */ |
1000 | gs.gn = gn; | | 1000 | gs.gn = gn; |
1001 | gs.s = s; | | 1001 | gs.s = s; |
1002 | gs.r = FALSE; | | 1002 | gs.r = FALSE; |
1003 | Lst_ForEach(Targ_List(), SuffScanTargets, &gs); | | 1003 | Lst_ForEach(Targ_List(), SuffScanTargets, &gs); |
1004 | /* | | 1004 | /* |