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 1993-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/param.h>
35 #include "proto_list.h"
42 init_list(elem_list
*list
, int hsize
)
47 list
->list
= (elem
**)malloc(sizeof (elem
*) * hsize
);
48 list
->num_of_buckets
= hsize
;
49 for (i
= 0; i
< list
->num_of_buckets
; i
++)
55 examine_list(elem_list
*list
)
61 for (i
= 0; i
< list
->num_of_buckets
; i
++) {
63 for (cur
= list
->list
[i
]; cur
; cur
= cur
->next
)
65 (void) printf("bucket[%4d] contains %5d entries\n",
72 * print all elements of a list
77 print_list(elem_list
*list
)
82 for (i
= 0; i
< list
->num_of_buckets
; i
++) {
83 for (cur
= list
->list
[i
]; cur
; cur
= cur
->next
)
84 print_elem(stdout
, cur
);
90 * print all elements of a list of type 'file_type'
95 print_type_list(elem_list
*list
, char file_type
)
100 for (i
= 0; i
< list
->num_of_buckets
; i
++) {
101 for (cur
= list
->list
[i
]; cur
; cur
= cur
->next
) {
102 if (cur
->file_type
== file_type
)
103 print_elem(stdout
, cur
);
110 hash(const char *str
)
114 for (i
= 0; *str
!= '\0'; )
121 name_compare(elem
*i
, elem
*j
)
125 if ((n
= strncmp(i
->name
, j
->name
, MAXNAME
)) != 0)
128 return (j
->arch
- i
->arch
);
135 * possible values for flag.
137 * flag = NO_FOLLOW_LINK
140 find_elem(elem_list
*list
, elem
*key
, int flag
)
144 for (e
= list
->list
[hash(key
->name
) % list
->num_of_buckets
]; e
;
146 if (!name_compare(e
, key
))
147 if (e
->link_parent
&& flag
== FOLLOW_LINK
)
148 return (e
->link_parent
);
160 * flags - same as find_elem()
163 find_elem_isa(elem_list
*list
, elem
*key
, int flag
)
168 orig_arch
= key
->arch
;
170 e
= find_elem(list
, key
, flag
);
171 key
->arch
= orig_arch
;
178 * flags - same as find_elem()
181 find_elem_mach(elem_list
*list
, elem
*key
, int flag
)
185 for (e
= list
->list
[hash(key
->name
) % list
->num_of_buckets
]; e
;
187 if ((e
->arch
!= P_ISA
) && (strcmp(key
->name
, e
->name
) == 0))
188 if (e
->link_parent
&& flag
== FOLLOW_LINK
)
189 return (e
->link_parent
);
198 add_pkg(pkg_list
*head
, const char *pkgname
)
200 pkg_list
*cur
, *prev
= NULL
;
201 static pkg_list
*new = NULL
;
204 new = (pkg_list
*)malloc(sizeof (pkg_list
));
206 (void) strcpy(new->pkg_name
, pkgname
);
208 for (cur
= head
; cur
; cur
= cur
->next
) {
209 if (strcmp(cur
->pkg_name
, pkgname
) >= 0)
228 if (strcmp(cur
->pkg_name
, pkgname
) == 0) /* a duplicate */
245 add_elem(elem_list
*list
, elem
*e
)
252 bucket
= hash(e
->name
) % list
->num_of_buckets
;
253 if (list
->list
[bucket
]) {
254 for (cur
= list
->list
[bucket
]; cur
; cur
= cur
->next
) {
256 if (strcmp(cur
->name
, e
->name
) > 0)
262 if (depth
> max_list_depth
)
263 max_list_depth
= depth
;
271 * insert at head of list
273 e
->next
= list
->list
[bucket
];
274 list
->list
[bucket
] = e
;
275 if (depth
> max_list_depth
)
276 max_list_depth
= depth
;