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