Print this page
*** NO COMMENTS ***
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ypcmd/revnetgroup/table.c
+++ new/usr/src/cmd/ypcmd/revnetgroup/table.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright (c) 1994, by Sun Microsystems, Inc.
24 24 * All rights reserved.
25 + *
26 + * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
25 27 */
26 -
27 -#ident "%Z%%M% %I% %E% SMI" /* SMI4.1 1.4 */
28 28
29 +#include <stdlib.h>
30 +#include <strings.h>
29 31 #include <ctype.h>
30 32 #include "util.h"
31 33 #include "table.h"
32 34
33 35
34 36
35 37 /*
36 38 * Hash table manager. Store/lookup strings, keyed by string
37 39 */
38 40
39 41 /*
40 42 * Generate the key into the table using the first two letters
41 43 * of "str". The table is alphabetized, with no distinction between
42 44 * upper and lower case. Non-letters are given least significance.
43 45 */
44 46 int
45 47 tablekey(str)
46 48 register char *str;
47 49 {
48 50 #define TOLOWER(c) (islower(c) ? c : \
49 51 (isupper(c) ? tolower(c) : ('a'+NUMLETTERS-1)))
50 52
51 53 register int c1, c2;
52 54
53 55 c1 = *str++;
54 56 c2 = *str;
55 57 if (c1 == EOS) {
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
56 58 c2 = EOS; /* just in case */
57 59 }
58 60 c1 = TOLOWER(c1) - 'a';
59 61 c2 = TOLOWER(c2) - 'a';
60 62 return (c1*NUMLETTERS + c2);
61 63 }
62 64
63 65
64 66 void
65 67 store(table, key, datum)
66 - stringtable table;
68 + tablelist *table;
67 69 char *key;
68 70 char *datum;
69 71 {
70 72 int index;
71 73 tablelist cur, new;
72 74
73 75 index = tablekey(key);
74 76 cur = table[index];
75 77
76 78 new = MALLOC(tablenode);
77 79 new->key = key;
78 80 new->datum = datum;
79 81 new->next = cur;
80 82 table[index] = new;
81 83 }
82 84
83 85
84 86 char *
85 87 lookup(table, key)
86 - stringtable table;
88 + tablelist *table;
87 89 char *key;
88 90 {
89 91 tablelist cur;
90 92
91 93 cur = table[tablekey(key)];
92 94 while (cur && strcmp(cur->key, key)) {
93 95 cur = cur->next;
94 96 }
95 97 if (cur) {
96 98 return (cur->datum);
97 99 } else {
98 100 return (NULL);
99 101 }
100 102 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX