Debian Codegraph @

rplayd/xhash.c

raw symbols ◀ ▶ SCIP
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 /* Make sure MAXPATHLEN is defined. */
40 #ifndef MAXPATHLEN
41 #define MAXPATHLEN 4096
42 #endif
43
44 static struct hash_control *htable;
45
46 #ifdef DEBUG
47 static void
48 xhash_stats()
49 {
50 int statbuf[HASH_STATLENGTH];
51 hash_say(htable, statbuf, HASH_STATLENGTH);
52 printf(" %d size, %d read, %d write, %d collisions, %d used\n",
53 statbuf[1], statbuf[2], statbuf[3], statbuf[4], statbuf[5]);
54 }
55 #endif
56
57 #ifdef __STDC__
58 void
59 xhash_init(int hash_table_size)
60 #else
61 void
62 xhash_init(hash_table_size)
63 int hash_table_size;
64 #endif
65 {
66 htable = hash_new();
67 }
68
69 #ifdef __STDC__
70 char *
71 xhash_get(char *hash_key)
72 #else
73 char *
74 xhash_get(hash_key)
75 char *hash_key;
76 #endif
77 {
78 return (char *) hash_find(htable, hash_key);
79 }
80
81 #ifdef __STDC__
82 void
83 xhash_put(char *hash_key, char *data)
84 #else
85 void
86 xhash_put(hash_key, data)
87 char *hash_key;
88 char *data;
89 #endif
90 {
91 hash_insert(htable, hash_key, data);
92 }
93
94 #ifdef __STDC__
95 void
96 xhash_replace(char *hash_key, char *data)
97 #else
98 void
99 xhash_replace(hash_key, data)
100 char *hash_key;
101 char *data;
102 #endif
103 {
104 hash_replace(htable, hash_key, data);
105 }
106
107 #ifdef __STDC__
108 void
109 xhash_delete(char *hash_key)
110 #else
111 void
112 xhash_delete(hash_key)
113 char *hash_key;
114 #endif
115 {
116 hash_delete(htable, hash_key);
117 }
118
119 /*
120 * create a hash key name for the given sound
121 */
122 #ifdef __STDC__
123 char *
124 xhash_name(char *pathname)
125 #else
126 char *
127 xhash_name(pathname)
128 char *pathname;
129 #endif
130 {
131 static char name[MAXPATHLEN];
132 char *extension;
133
134 if (pathname[0] == '/')
135 {
136 pathname = strrchr(pathname, '/') + 1;
137 }
138
139 strncpy(name, pathname, sizeof(name));
140 extension = strrchr(name, '.');
141 if (extension)
142 {
143 *extension = '\0';
144 }
145
146 return name;
147 }
148
149 #ifdef __STDC__
150 void
•151 xhash_apply(char *(*func) (const char *str, PTR val))
152 #else
153 void
154 xhash_apply(func)
155 char *(*func) ();
156 #endif
157 {
158 hash_apply(htable, func);
159 }
160
161 void
162 xhash_die()
163 {
164 hash_die(htable);
165 }