Commit | Line | Data |
---|---|---|
e745ede7 DL |
1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | ||
0ff3f435 GM |
3 | #include "copyright.h" |
4 | ||
47a6e6df | 5 | #include <config.h> |
e745ede7 DL |
6 | #include <X11/Xlib.h> |
7 | #include <X11/Xresource.h> | |
8 | #include "X10.h" | |
9 | ||
10 | #ifndef NULL | |
11 | #define NULL 0 | |
12 | #endif | |
13 | ||
177c0ea7 | 14 | /* |
e745ede7 DL |
15 | * XLookUpAssoc - Retrieve the data stored in an XAssocTable by its XId. |
16 | * If an appropriately matching XId can be found in the table the routine will | |
17 | * return apointer to the data associated with it. If the XId can not be found | |
18 | * in the table the routine will return a NULL pointer. All XId's are relative | |
19 | * to the currently active Display. | |
20 | */ | |
47a6e6df PE |
21 | caddr_t XLookUpAssoc(Display *dpy, |
22 | XAssocTable *table, /* XAssocTable to search in. */ | |
23 | XID x_id) /* XId to search for. */ | |
e745ede7 DL |
24 | { |
25 | int hash; | |
26 | register XAssoc *bucket; | |
27 | register XAssoc *Entry; | |
28 | ||
29 | /* Hash the XId to get the bucket number. */ | |
30 | hash = x_id & (table->size - 1); | |
31 | /* Look up the bucket to get the entries in that bucket. */ | |
32 | bucket = &table->buckets[hash]; | |
33 | /* Get the first entry in the bucket. */ | |
34 | Entry = bucket->next; | |
35 | ||
36 | /* Scan through the entries in the bucket for the right XId. */ | |
37 | for (; Entry != bucket; Entry = Entry->next) { | |
38 | if (Entry->x_id == x_id) { | |
39 | /* We have the right XId. */ | |
40 | if (Entry->display == dpy) { | |
41 | /* We have the right display. */ | |
42 | /* We have the right entry! */ | |
43 | return(Entry->data); | |
44 | } | |
45 | /* Oops, identical XId's on different displays! */ | |
46 | continue; | |
47 | } | |
48 | if (Entry->x_id > x_id) { | |
49 | /* We have gone past where it should be. */ | |
50 | /* It is apparently not in the table. */ | |
51 | return(NULL); | |
52 | } | |
53 | } | |
54 | /* It is apparently not in the table. */ | |
55 | return(NULL); | |
56 | } |