| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: suff.c,v 1.125 2020/08/28 04:48:57 rillig Exp $ */ | | 1 | /* $NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 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.125 2020/08/28 04:48:57 rillig Exp $"; | | 72 | static char rcsid[] = "$NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 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.125 2020/08/28 04:48:57 rillig Exp $"); | | 79 | __RCSID("$NetBSD: suff.c,v 1.126 2020/08/28 06:37:21 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 |
| @@ -614,28 +614,30 @@ SuffParseTransform(char *str, Suff **src | | | @@ -614,28 +614,30 @@ SuffParseTransform(char *str, Suff **src |
614 | srcLn = NULL; | | 614 | srcLn = NULL; |
615 | singleLn = NULL; | | 615 | singleLn = NULL; |
616 | | | 616 | |
617 | /* | | 617 | /* |
618 | * Loop looking first for a suffix that matches the start of the | | 618 | * Loop looking first for a suffix that matches the start of the |
619 | * string and then for one that exactly matches the rest of it. If | | 619 | * string and then for one that exactly matches the rest of it. If |
620 | * we can find two that meet these criteria, we've successfully | | 620 | * we can find two that meet these criteria, we've successfully |
621 | * parsed the string. | | 621 | * parsed the string. |
622 | */ | | 622 | */ |
623 | for (;;) { | | 623 | for (;;) { |
624 | if (srcLn == NULL) { | | 624 | if (srcLn == NULL) { |
625 | srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str); | | 625 | srcLn = Lst_Find(sufflist, SuffSuffIsPrefix, str); |
626 | } else { | | 626 | } else { |
627 | srcLn = Lst_FindFrom(sufflist, Lst_Succ(srcLn), | | 627 | LstNode succ = Lst_Succ(srcLn); |
628 | SuffSuffIsPrefix, str); | | 628 | srcLn = succ != NULL |
| | | 629 | ? Lst_FindFrom(sufflist, succ, SuffSuffIsPrefix, str) |
| | | 630 | : NULL; |
629 | } | | 631 | } |
630 | if (srcLn == NULL) { | | 632 | if (srcLn == NULL) { |
631 | /* | | 633 | /* |
632 | * Ran out of source suffixes -- no such rule | | 634 | * Ran out of source suffixes -- no such rule |
633 | */ | | 635 | */ |
634 | if (singleLn != NULL) { | | 636 | if (singleLn != NULL) { |
635 | /* | | 637 | /* |
636 | * Not so fast Mr. Smith! There was a suffix that encompassed | | 638 | * Not so fast Mr. Smith! There was a suffix that encompassed |
637 | * the entire string, so we assume it was a transformation | | 639 | * the entire string, so we assume it was a transformation |
638 | * to the null suffix (thank you POSIX). We still prefer to | | 640 | * to the null suffix (thank you POSIX). We still prefer to |
639 | * find a double rule over a singleton, hence we leave this | | 641 | * find a double rule over a singleton, hence we leave this |
640 | * check until the end. | | 642 | * check until the end. |
641 | * | | 643 | * |