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