1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995,1997, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 typedef struct _cap_mapping cap_mapping
;
28 unsigned_cell external
;
35 cap_mapping
*mappings
;
40 cap_create(const char *key
)
49 cap_mapping
*current_map
= db
->mappings
;
50 if (current_map
!= NULL
) {
51 db
->nr_mappings
= db
->mappings
->external
;
52 /* verify that the mappings that were not removed are in sequence
54 while (current_map
->next
!= NULL
) {
55 if (current_map
->external
!= current_map
->next
->external
+ 1)
56 error("cap: cap database possibly corrupt");
57 current_map
= current_map
->next
;
59 ASSERT(current_map
->next
== NULL
);
60 if (current_map
->external
!= 1)
61 error("cap: cap database possibly currupt");
73 cap_mapping
*current_map
= db
->mappings
;
74 while (current_map
!= NULL
) {
75 if (current_map
->external
== external
)
76 return current_map
->internal
;
77 current_map
= current_map
->next
;
87 cap_mapping
*current_map
= db
->mappings
;
88 while (current_map
!= NULL
) {
89 if (current_map
->internal
== internal
)
90 return current_map
->external
;
91 current_map
= current_map
->next
;
101 if (cap_external(db
, internal
) != 0) {
102 error("cap: attempting to add an object already in the data base");
105 /* insert at the front making things in decending order */
106 cap_mapping
*new_map
= ZALLOC(cap_mapping
);
107 new_map
->next
= db
->mappings
;
108 new_map
->internal
= internal
;
109 db
->nr_mappings
+= 1;
110 new_map
->external
= db
->nr_mappings
;
111 db
->mappings
= new_map
;
120 cap_mapping
**current_map
= &db
->mappings
;
121 while (*current_map
!= NULL
) {
122 if ((*current_map
)->internal
== internal
) {
123 cap_mapping
*delete = *current_map
;
124 *current_map
= delete->next
;
128 current_map
= &(*current_map
)->next
;
130 error("cap: attempt to remove nonexistant internal object");