No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / sim / ppc / cap.c
bloba3be304c81fb0dec2b1cb7bcbd55c30a88d855a7
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 2 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, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _CAP_C_
23 #define _CAP_C_
25 #include "cap.h"
27 typedef struct _cap_mapping cap_mapping;
28 struct _cap_mapping {
29 unsigned_cell external;
30 void *internal;
31 cap_mapping *next;
34 struct _cap {
35 int nr_mappings;
36 cap_mapping *mappings;
39 INLINE_CAP\
40 (cap *)
41 cap_create(const char *key)
43 return ZALLOC(cap);
46 INLINE_CAP\
47 (void)
48 cap_init(cap *db)
50 cap_mapping *current_map = db->mappings;
51 if (current_map != NULL) {
52 db->nr_mappings = db->mappings->external;
53 /* verify that the mappings that were not removed are in sequence
54 down to nr 1 */
55 while (current_map->next != NULL) {
56 if (current_map->external != current_map->next->external + 1)
57 error("cap: cap database possibly corrupt");
58 current_map = current_map->next;
60 ASSERT(current_map->next == NULL);
61 if (current_map->external != 1)
62 error("cap: cap database possibly currupt");
64 else {
65 db->nr_mappings = 0;
69 INLINE_CAP\
70 (void *)
71 cap_internal(cap *db,
72 signed_cell external)
74 cap_mapping *current_map = db->mappings;
75 while (current_map != NULL) {
76 if (current_map->external == external)
77 return current_map->internal;
78 current_map = current_map->next;
80 return (void*)0;
83 INLINE_CAP\
84 (signed_cell)
85 cap_external(cap *db,
86 void *internal)
88 cap_mapping *current_map = db->mappings;
89 while (current_map != NULL) {
90 if (current_map->internal == internal)
91 return current_map->external;
92 current_map = current_map->next;
94 return 0;
97 INLINE_CAP\
98 (void)
99 cap_add(cap *db,
100 void *internal)
102 if (cap_external(db, internal) != 0) {
103 error("cap: attempting to add an object already in the data base");
105 else {
106 /* insert at the front making things in decending order */
107 cap_mapping *new_map = ZALLOC(cap_mapping);
108 new_map->next = db->mappings;
109 new_map->internal = internal;
110 db->nr_mappings += 1;
111 new_map->external = db->nr_mappings;
112 db->mappings = new_map;
116 INLINE_CAP\
117 (void)
118 cap_remove(cap *db,
119 void *internal)
121 cap_mapping **current_map = &db->mappings;
122 while (*current_map != NULL) {
123 if ((*current_map)->internal == internal) {
124 cap_mapping *delete = *current_map;
125 *current_map = delete->next;
126 zfree(delete);
127 return;
129 current_map = &(*current_map)->next;
131 error("cap: attempt to remove nonexistant internal object");
134 #endif