| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: suff.c,v 1.121 2020/08/27 19:15:35 rillig Exp $ */ | | 1 | /* $NetBSD: suff.c,v 1.122 2020/08/28 03:35:45 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.121 2020/08/27 19:15:35 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: suff.c,v 1.122 2020/08/28 03:35:45 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.121 2020/08/27 19:15:35 rillig Exp $"); | | 79 | __RCSID("$NetBSD: suff.c,v 1.122 2020/08/28 03:35:45 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 |
| @@ -141,34 +141,38 @@ __RCSID("$NetBSD: suff.c,v 1.121 2020/08 | | | @@ -141,34 +141,38 @@ __RCSID("$NetBSD: suff.c,v 1.121 2020/08 |
141 | static Lst sufflist; /* Lst of suffixes */ | | 141 | static Lst sufflist; /* Lst of suffixes */ |
142 | #ifdef CLEANUP | | 142 | #ifdef CLEANUP |
143 | static Lst suffClean; /* Lst of suffixes to be cleaned */ | | 143 | static Lst suffClean; /* Lst of suffixes to be cleaned */ |
144 | #endif | | 144 | #endif |
145 | static Lst srclist; /* Lst of sources */ | | 145 | static Lst srclist; /* Lst of sources */ |
146 | static Lst transforms; /* Lst of transformation rules */ | | 146 | static Lst transforms; /* Lst of transformation rules */ |
147 | | | 147 | |
148 | static int sNum = 0; /* Counter for assigning suffix numbers */ | | 148 | static int sNum = 0; /* Counter for assigning suffix numbers */ |
149 | | | 149 | |
150 | typedef enum { | | 150 | typedef enum { |
151 | SUFF_INCLUDE = 0x01, /* One which is #include'd */ | | 151 | SUFF_INCLUDE = 0x01, /* One which is #include'd */ |
152 | SUFF_LIBRARY = 0x02, /* One which contains a library */ | | 152 | SUFF_LIBRARY = 0x02, /* One which contains a library */ |
153 | SUFF_NULL = 0x04 /* The empty suffix */ | | 153 | SUFF_NULL = 0x04 /* The empty suffix */ |
| | | 154 | /* XXX: Why is SUFF_NULL needed? Wouldn't nameLen == 0 mean the same? */ |
154 | } SuffFlags; | | 155 | } SuffFlags; |
155 | | | 156 | |
| | | 157 | ENUM_FLAGS_RTTI_3(SuffFlags, |
| | | 158 | SUFF_INCLUDE, SUFF_LIBRARY, SUFF_NULL); |
| | | 159 | |
156 | /* | | 160 | /* |
157 | * Structure describing an individual suffix. | | 161 | * Structure describing an individual suffix. |
158 | */ | | 162 | */ |
159 | typedef struct Suff { | | 163 | typedef struct Suff { |
160 | char *name; /* The suffix itself */ | | 164 | char *name; /* The suffix itself, such as ".c" */ |
161 | int nameLen; /* Length of the suffix */ | | 165 | int nameLen; /* Length of the name, to avoid strlen calls */ |
162 | SuffFlags flags; /* Type of suffix */ | | 166 | SuffFlags flags; /* Type of suffix */ |
163 | Lst searchPath; /* The path along which files of this suffix | | 167 | Lst searchPath; /* The path along which files of this suffix |
164 | * may be found */ | | 168 | * may be found */ |
165 | int sNum; /* The suffix number */ | | 169 | int sNum; /* The suffix number */ |
166 | int refCount; /* Reference count of list membership */ | | 170 | int refCount; /* Reference count of list membership */ |
167 | Lst parents; /* Suffixes we have a transformation to */ | | 171 | Lst parents; /* Suffixes we have a transformation to */ |
168 | Lst children; /* Suffixes we have a transformation from */ | | 172 | Lst children; /* Suffixes we have a transformation from */ |
169 | Lst ref; /* List of lists this suffix is referenced */ | | 173 | Lst ref; /* List of lists this suffix is referenced */ |
170 | } Suff; | | 174 | } Suff; |
171 | | | 175 | |
172 | /* | | 176 | /* |
173 | * for SuffSuffIsSuffix | | 177 | * for SuffSuffIsSuffix |
174 | */ | | 178 | */ |
| @@ -2592,50 +2596,35 @@ Suff_End(void) | | | @@ -2592,50 +2596,35 @@ Suff_End(void) |
2592 | /********************* DEBUGGING FUNCTIONS **********************/ | | 2596 | /********************* DEBUGGING FUNCTIONS **********************/ |
2593 | | | 2597 | |
2594 | static int SuffPrintName(void *s, void *dummy MAKE_ATTR_UNUSED) | | 2598 | static int SuffPrintName(void *s, void *dummy MAKE_ATTR_UNUSED) |
2595 | { | | 2599 | { |
2596 | | | 2600 | |
2597 | fprintf(debug_file, "%s ", ((Suff *)s)->name); | | 2601 | fprintf(debug_file, "%s ", ((Suff *)s)->name); |
2598 | return 0; | | 2602 | return 0; |
2599 | } | | 2603 | } |
2600 | | | 2604 | |
2601 | static int | | 2605 | static int |
2602 | SuffPrintSuff(void *sp, void *dummy MAKE_ATTR_UNUSED) | | 2606 | SuffPrintSuff(void *sp, void *dummy MAKE_ATTR_UNUSED) |
2603 | { | | 2607 | { |
2604 | Suff *s = (Suff *)sp; | | 2608 | Suff *s = (Suff *)sp; |
2605 | int flags; | | | |
2606 | int flag; | | | |
2607 | | | 2609 | |
2608 | fprintf(debug_file, "# `%s' [%d] ", s->name, s->refCount); | | 2610 | fprintf(debug_file, "# `%s' [%d] ", s->name, s->refCount); |
2609 | | | 2611 | |
2610 | flags = s->flags; | | 2612 | if (s->flags != 0) { |
2611 | if (flags) { | | 2613 | char flags_buf[SuffFlags_ToStringSize]; |
2612 | fputs(" (", debug_file); | | 2614 | |
2613 | while (flags) { | | 2615 | fprintf(debug_file, " (%s)", |
2614 | flag = 1 << (ffs(flags) - 1); | | 2616 | Enum_FlagsToString(flags_buf, sizeof flags_buf, |
2615 | flags &= ~flag; | | 2617 | s->flags, SuffFlags_ToStringSpecs)); |
2616 | switch (flag) { | | | |
2617 | case SUFF_NULL: | | | |
2618 | fprintf(debug_file, "NULL"); | | | |
2619 | break; | | | |
2620 | case SUFF_INCLUDE: | | | |
2621 | fprintf(debug_file, "INCLUDE"); | | | |
2622 | break; | | | |
2623 | case SUFF_LIBRARY: | | | |
2624 | fprintf(debug_file, "LIBRARY"); | | | |
2625 | break; | | | |
2626 | } | | | |
2627 | fputc(flags ? '|' : ')', debug_file); | | | |
2628 | } | | | |
2629 | } | | 2618 | } |
2630 | fputc('\n', debug_file); | | 2619 | fputc('\n', debug_file); |
2631 | fprintf(debug_file, "#\tTo: "); | | 2620 | fprintf(debug_file, "#\tTo: "); |
2632 | Lst_ForEachS(s->parents, SuffPrintName, NULL); | | 2621 | Lst_ForEachS(s->parents, SuffPrintName, NULL); |
2633 | fputc('\n', debug_file); | | 2622 | fputc('\n', debug_file); |
2634 | fprintf(debug_file, "#\tFrom: "); | | 2623 | fprintf(debug_file, "#\tFrom: "); |
2635 | Lst_ForEachS(s->children, SuffPrintName, NULL); | | 2624 | Lst_ForEachS(s->children, SuffPrintName, NULL); |
2636 | fputc('\n', debug_file); | | 2625 | fputc('\n', debug_file); |
2637 | fprintf(debug_file, "#\tSearch Path: "); | | 2626 | fprintf(debug_file, "#\tSearch Path: "); |
2638 | Dir_PrintPath(s->searchPath); | | 2627 | Dir_PrintPath(s->searchPath); |
2639 | fputc('\n', debug_file); | | 2628 | fputc('\n', debug_file); |
2640 | return 0; | | 2629 | return 0; |
2641 | } | | 2630 | } |