Debian Codegraph @

rplayd/xhash.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 /* $Id: xhash.c,v 1.4 1999/03/10 07:58:05 boyns Exp $ */
2
3 /*
4 * Copyright (C) 1993-99 Mark R. Boyns <[email protected]>
5 *
6 * This file is part of rplay.
7 *
8 * rplay is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * rplay is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with rplay; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <stdio.h>
32 #ifdef HAVE_STRING_H
33 #include <string.h>
34 #endif
35 #include "xhash.h"
36 #include "hash.h"
37 #include "rplayd.h"
38
39 static struct hash_control *htable;
40
41 #ifdef DEBUG
42 static void
43 xhash_stats()
44 {
45 int statbuf[HASH_STATLENGTH];
46 hash_say(htable, statbuf, HASH_STATLENGTH);
47 printf(" %d size, %d read, %d write, %d collisions, %d used\n",
48 statbuf[1], statbuf[2], statbuf[3], statbuf[4], statbuf[5]);
49 }
50 #endif
51
52 #ifdef __STDC__
53 void
54 xhash_init(int hash_table_size)
55 #else
56 void
57 xhash_init(hash_table_size)
58 int hash_table_size;
59 #endif
60 {
61 htable = hash_new();
62 }
63
64 #ifdef __STDC__
65 char *
66 xhash_get(char *hash_key)
67 #else
68 char *
69 xhash_get(hash_key)
70 char *hash_key;
71 #endif
72 {
73 return (char *) hash_find(htable, hash_key);
74 }
75
76 #ifdef __STDC__
77 void
78 xhash_put(char *hash_key, char *data)
79 #else
80 void
81 xhash_put(hash_key, data)
82 char *hash_key;
83 char *data;
84 #endif
85 {
86 hash_insert(htable, hash_key, data);
87 }
88
89 #ifdef __STDC__
90 void
91 xhash_replace(char *hash_key, char *data)
92 #else
93 void
94 xhash_replace(hash_key, data)
95 char *hash_key;
96 char *data;
97 #endif
98 {
99 hash_replace(htable, hash_key, data);
100 }
101
102 #ifdef __STDC__
103 void
104 xhash_delete(char *hash_key)
105 #else
106 void
107 xhash_delete(hash_key)
108 char *hash_key;
109 #endif
110 {
111 hash_delete(htable, hash_key);
112 }
113
114 /*
115 * create a hash key name for the given sound
116 */
117 #ifdef __STDC__
118 char *
119 xhash_name(char *pathname)
120 #else
121 char *
122 xhash_name(pathname)
123 char *pathname;
124 #endif
125 {
126 static char name[MAXPATHLEN];
127 char *extension;
128
129 if (pathname[0] == '/')
130 {
131 pathname = strrchr(pathname, '/') + 1;
132 }
133
134 strncpy(name, pathname, sizeof(name));
135 extension = strrchr(name, '.');
136 if (extension)
137 {
138 *extension = '\0';
139 }
140
141 return name;
142 }
143
144 #ifdef __STDC__
145 void
146 xhash_apply(char *(*func) ())
147 #else
148 void
149 xhash_apply(func)
150 char *(*func) ();
151 #endif
152 {
153 hash_apply(htable, func);
154 }
155
156 void
157 xhash_die()
158 {
159 hash_die(htable);
160 }