home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / sim / ppc / cap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-19  |  2.2 KB  |  95 lines

  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. #include "cap.h"
  26.  
  27. typedef struct _cap_mapping cap_mapping;
  28. struct _cap_mapping {
  29.   unsigned32 external;
  30.   void *internal;
  31.   cap_mapping *next;
  32. };
  33.  
  34. struct _cap {
  35.   int nr_mappings;
  36.   cap_mapping *mappings;
  37. };
  38.  
  39. INLINE_CAP\
  40. (cap *)
  41. cap_create(const char *key)
  42. {
  43.   return ZALLOC(cap);
  44. }
  45.  
  46. INLINE_CAP\
  47. (void)
  48. cap_init(cap *map)
  49. {
  50.   cap_mapping *current_mapping = map->mappings;
  51.   while (current_mapping != NULL) {
  52.     cap_mapping *tbd = current_mapping;
  53.     current_mapping = tbd->next;
  54.     zfree(tbd);
  55.   }
  56.   map->nr_mappings = 0;
  57.   map->mappings = (cap_mapping*)0;
  58. }
  59.  
  60. INLINE_CAP\
  61. (void *)
  62. cap_internal(cap *db,
  63.          signed32 external)
  64. {
  65.   cap_mapping *current_map = db->mappings;
  66.   while (current_map != NULL) {
  67.     if (current_map->external == external)
  68.       return current_map->internal;
  69.     current_map = current_map->next;
  70.   }
  71.   return (void*)0;
  72. }
  73.  
  74. INLINE_CAP\
  75. (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
  95.