*** empty log message ***
[emacs.git] / oldXMenu / XLookAssoc.c
blobf80952a63459fe92c44e62c74fb33b730c7ab103
1 /* $XConsortium: XLookAssoc.c,v 10.16 91/01/06 12:09:24 rws Exp $ */
2 /* Copyright Massachusetts Institute of Technology 1985 */
4 /*
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation, and that the name of M.I.T. not be used in advertising or
10 publicity pertaining to distribution of the software without specific,
11 written prior permission. M.I.T. makes no representations about the
12 suitability of this software for any purpose. It is provided "as is"
13 without express or implied warranty.
16 #include <X11/Xlib.h>
17 #include <X11/Xresource.h>
18 #include "X10.h"
20 #ifndef NULL
21 #define NULL 0
22 #endif
24 /*
25 * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId.
26 * If an appropriately matching XId can be found in the table the routine will
27 * return apointer to the data associated with it. If the XId can not be found
28 * in the table the routine will return a NULL pointer. All XId's are relative
29 * to the currently active Display.
31 caddr_t XLookUpAssoc(dpy, table, x_id)
32 register Display *dpy;
33 register XAssocTable *table; /* XAssocTable to search in. */
34 register XID x_id; /* XId to search for. */
36 int hash;
37 register XAssoc *bucket;
38 register XAssoc *Entry;
40 /* Hash the XId to get the bucket number. */
41 hash = x_id & (table->size - 1);
42 /* Look up the bucket to get the entries in that bucket. */
43 bucket = &table->buckets[hash];
44 /* Get the first entry in the bucket. */
45 Entry = bucket->next;
47 /* Scan through the entries in the bucket for the right XId. */
48 for (; Entry != bucket; Entry = Entry->next) {
49 if (Entry->x_id == x_id) {
50 /* We have the right XId. */
51 if (Entry->display == dpy) {
52 /* We have the right display. */
53 /* We have the right entry! */
54 return(Entry->data);
56 /* Oops, identical XId's on different displays! */
57 continue;
59 if (Entry->x_id > x_id) {
60 /* We have gone past where it should be. */
61 /* It is apparently not in the table. */
62 return(NULL);
65 /* It is apparently not in the table. */
66 return(NULL);