| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: tyname.c,v 1.25 2021/01/24 11:55:57 rillig Exp $ */ | | 1 | /* $NetBSD: tyname.c,v 1.26 2021/01/26 18:38:57 rillig Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2005 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2005 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
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. |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #if HAVE_NBTOOL_CONFIG_H | | 32 | #if HAVE_NBTOOL_CONFIG_H |
33 | #include "nbtool_config.h" | | 33 | #include "nbtool_config.h" |
34 | #endif | | 34 | #endif |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | #if defined(__RCSID) && !defined(lint) | | 37 | #if defined(__RCSID) && !defined(lint) |
38 | __RCSID("$NetBSD: tyname.c,v 1.25 2021/01/24 11:55:57 rillig Exp $"); | | 38 | __RCSID("$NetBSD: tyname.c,v 1.26 2021/01/26 18:38:57 rillig Exp $"); |
39 | #endif | | 39 | #endif |
40 | | | 40 | |
41 | #include <limits.h> | | 41 | #include <limits.h> |
42 | #include <string.h> | | 42 | #include <string.h> |
43 | #include <stdlib.h> | | 43 | #include <stdlib.h> |
44 | #include <err.h> | | 44 | #include <err.h> |
45 | | | 45 | |
46 | #include PASS | | 46 | #include PASS |
47 | | | 47 | |
48 | #ifndef LERROR | | 48 | #ifndef LERROR |
49 | #define LERROR(fmt, args...) \ | | 49 | #define LERROR(fmt, args...) \ |
50 | do { \ | | 50 | do { \ |
51 | (void)warnx("%s, %d: " fmt, __FILE__, __LINE__, ##args); \ | | 51 | (void)warnx("%s, %d: " fmt, __FILE__, __LINE__, ##args); \ |
| @@ -72,27 +72,27 @@ static name_tree_node *type_names; | | | @@ -72,27 +72,27 @@ static name_tree_node *type_names; |
72 | static name_tree_node * | | 72 | static name_tree_node * |
73 | new_name_tree_node(const char *name) | | 73 | new_name_tree_node(const char *name) |
74 | { | | 74 | { |
75 | name_tree_node *n; | | 75 | name_tree_node *n; |
76 | | | 76 | |
77 | n = xmalloc(sizeof(*n)); | | 77 | n = xmalloc(sizeof(*n)); |
78 | n->ntn_name = xstrdup(name); | | 78 | n->ntn_name = xstrdup(name); |
79 | n->ntn_less = NULL; | | 79 | n->ntn_less = NULL; |
80 | n->ntn_greater = NULL; | | 80 | n->ntn_greater = NULL; |
81 | return n; | | 81 | return n; |
82 | } | | 82 | } |
83 | | | 83 | |
84 | /* Return the canonical instance of the string, with unlimited life time. */ | | 84 | /* Return the canonical instance of the string, with unlimited life time. */ |
85 | static const char * __noinline | | 85 | static const char * |
86 | intern(const char *name) | | 86 | intern(const char *name) |
87 | { | | 87 | { |
88 | name_tree_node *n = type_names, **next; | | 88 | name_tree_node *n = type_names, **next; |
89 | int cmp; | | 89 | int cmp; |
90 | | | 90 | |
91 | if (n == NULL) { | | 91 | if (n == NULL) { |
92 | n = new_name_tree_node(name); | | 92 | n = new_name_tree_node(name); |
93 | type_names = n; | | 93 | type_names = n; |
94 | return n->ntn_name; | | 94 | return n->ntn_name; |
95 | } | | 95 | } |
96 | | | 96 | |
97 | while ((cmp = strcmp(name, n->ntn_name)) != 0) { | | 97 | while ((cmp = strcmp(name, n->ntn_name)) != 0) { |
98 | next = cmp < 0 ? &n->ntn_less : &n->ntn_greater; | | 98 | next = cmp < 0 ? &n->ntn_less : &n->ntn_greater; |