Commit | Line | Data |
---|---|---|
93fac324 MM |
1 | /* This file is part of the program psim. |
2 | ||
3 | Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au> | |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | */ | |
20 | ||
21 | ||
22 | #ifndef _CAP_C_ | |
23 | #define _CAP_C_ | |
24 | ||
25 | #ifndef STATIC_INLINE_CAP | |
26 | #define STATIC_INLINE_CAP STATIC_INLINE | |
27 | #endif | |
28 | ||
29 | #include "cap.h" | |
30 | ||
31 | typedef struct _cap_mapping cap_mapping; | |
32 | struct _cap_mapping { | |
33 | unsigned32 external; | |
34 | void *internal; | |
35 | cap_mapping *next; | |
36 | }; | |
37 | ||
38 | struct _cap { | |
39 | int nr_mappings; | |
40 | cap_mapping *mappings; | |
41 | }; | |
42 | ||
43 | INLINE_CAP cap * | |
44 | cap_create(const char *key) | |
45 | { | |
46 | return ZALLOC(cap); | |
47 | } | |
48 | ||
49 | INLINE_CAP void | |
50 | cap_init(cap *map) | |
51 | { | |
52 | cap_mapping *current_mapping = map->mappings; | |
53 | while (current_mapping != NULL) { | |
54 | cap_mapping *tbd = current_mapping; | |
55 | current_mapping = tbd->next; | |
56 | zfree(tbd); | |
57 | } | |
58 | map->nr_mappings = 0; | |
59 | map->mappings = (cap_mapping*)0; | |
60 | } | |
61 | ||
62 | INLINE_CAP void * | |
63 | cap_internal(cap *db, | |
64 | signed32 external) | |
65 | { | |
66 | cap_mapping *current_map = db->mappings; | |
67 | while (current_map != NULL) { | |
68 | if (current_map->external == external) | |
69 | return current_map->internal; | |
70 | current_map = current_map->next; | |
71 | } | |
72 | return (void*)0; | |
73 | } | |
74 | ||
75 | INLINE_CAP signed32 | |
76 | cap_external(cap *db, | |
77 | void *internal) | |
78 | { | |
79 | cap_mapping *current_map = db->mappings; | |
80 | while (current_map != NULL) { | |
81 | if (current_map->internal == internal) | |
82 | return current_map->external; | |
83 | current_map = current_map->next; | |
84 | } | |
85 | current_map = ZALLOC(cap_mapping); | |
86 | current_map->next = db->mappings; | |
87 | current_map->internal = internal; | |
88 | db->nr_mappings += 1; | |
89 | current_map->external = db->nr_mappings; | |
90 | db->mappings = current_map; | |
91 | return current_map->external; | |
92 | } | |
93 | ||
94 | #endif |