4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 /* Copyright (c) 1988 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
39 #pragma ident "%Z%%M% %I% %E% SMI"
42 *************************************************************************
44 *************************************************************************
45 * This software is copyright(C) 1982 by Pavel Curtis *
47 * Permission is granted to reproduce and distribute *
48 * this file by any means so long as no fee is charged *
49 * above a nominal handling fee and so long as this *
50 * notice is always included in the copies. *
52 * Other rights are reserved except as explicitly granted *
53 * by written permission of the author. *
55 * Computer Science Dept. *
57 * Cornell University *
60 * Ph- (607) 256-4934 *
62 * Pavel.Cornell@Udel-Relay(ARPAnet) *
63 * decvax!cornell!pavel(UUCPnet) *
64 *********************************************************************** */
67 * comp_hash.c --- Routines to deal with the hashtable of capability
70 * $Log: RCS/comp_hash.v $
71 * Revision 2.1 82/10/25 14:45:34 pavel
72 * Added Copyright Notice
74 * Revision 2.0 82/10/24 15:16:34 pavel
75 * Beta-one Test Release
77 * Revision 1.3 82/08/23 22:29:33 pavel
78 * The REAL Alpha-one Release Version
80 * Revision 1.2 82/08/19 19:09:46 pavel
81 * Alpha Test Release One
83 * Revision 1.1 82/08/12 18:36:23 pavel
90 #include "curses_inc.h"
93 static void make_nte(void);
94 static int hash_function(char *);
99 * Takes the entries in cap_table[] and hashes them into cap_hash_table[]
100 * by name. There are Captabsize entries in cap_table[] and Hashtabsize
101 * slots in cap_hash_table[].
113 for (i
= 0; i
< Captabsize
; i
++) {
114 hashvalue
= hash_function(cap_table
[i
].nte_name
);
115 DEBUG(9, "%d\n", hashvalue
);
117 if (cap_hash_table
[hashvalue
] != (struct name_table_entry
*) 0)
120 cap_table
[i
].nte_link
= cap_hash_table
[hashvalue
];
121 cap_hash_table
[hashvalue
] = &cap_table
[i
];
124 DEBUG(3, "Hash table complete\n%d collisions ", collisions
);
125 DEBUG(3, "out of %d entries\n", Captabsize
);
130 * Make the name_table_entry from the capnames.c set of tables.
136 extern char *boolnames
[], *numnames
[], *strnames
[];
140 for (i
= 0; boolnames
[i
]; i
++) {
141 cap_table
[n
].nte_link
= NULL
;
142 cap_table
[n
].nte_name
= boolnames
[i
];
143 cap_table
[n
].nte_type
= BOOLEAN
;
144 cap_table
[n
].nte_index
= i
;
149 for (i
= 0; numnames
[i
]; i
++) {
150 cap_table
[n
].nte_link
= NULL
;
151 cap_table
[n
].nte_name
= numnames
[i
];
152 cap_table
[n
].nte_type
= NUMBER
;
153 cap_table
[n
].nte_index
= i
;
158 for (i
= 0; strnames
[i
]; i
++) {
159 cap_table
[n
].nte_link
= NULL
;
160 cap_table
[n
].nte_name
= strnames
[i
];
161 cap_table
[n
].nte_type
= STRING
;
162 cap_table
[n
].nte_index
= i
;
172 * int hash_function(string)
174 * Computes the hashing function on the given string.
176 * The current hash function is the sum of each consectutive pair
177 * of characters, taken as two-byte integers, mod Hashtabsize.
182 hash_function(char *string
)
187 sum
+= *string
+ (*(string
+ 1) << 8);
191 return (sum
% Hashtabsize
);
197 * struct name_table_entry *
200 * Finds the entry for the given string in the hash table if present.
201 * Returns a pointer to the entry in the table or 0 if not found.
205 struct name_table_entry
*
206 find_entry(char *string
)
209 struct name_table_entry
*ptr
;
211 hashvalue
= hash_function(string
);
213 ptr
= cap_hash_table
[hashvalue
];
215 while (ptr
!= (struct name_table_entry
*) 0 &&
216 strcmp(ptr
->nte_name
, string
) != 0)