nnir.el (nnir-run-swish-e): Remove hyrex support.
[emacs.git] / oldXMenu / XMakeAssoc.c
blob84157399b43923eb777e80ff4665ad28fbc18d7c
1 /* Copyright Massachusetts Institute of Technology 1985 */
3 #include "copyright.h"
6 #include <config.h>
7 #include <X11/Xlib.h>
8 #include <X11/Xresource.h>
9 #include "X10.h"
10 #include <errno.h>
12 #ifndef NULL
13 #define NULL 0
14 #endif
16 struct qelem {
17 struct qelem *q_forw;
18 struct qelem *q_back;
19 char q_data[1];
21 void emacs_insque (struct qelem *elem, struct qelem *prev);
24 * XMakeAssoc - Insert data into an XAssocTable keyed on an XId.
25 * Data is inserted into the table only once. Redundant inserts are
26 * meaningless (but cause no problems). The queue in each association
27 * bucket is sorted (lowest XId to highest XId).
29 XMakeAssoc(register Display *dpy, register XAssocTable *table, register XID x_id, register caddr_t data)
31 int hash;
32 register XAssoc *bucket;
33 register XAssoc *Entry;
34 register XAssoc *new_entry;
36 /* Hash the XId to get the bucket number. */
37 hash = x_id & (table->size - 1);
38 /* Look up the bucket to get the entries in that bucket. */
39 bucket = &table->buckets[hash];
40 /* Get the first entry in the bucket. */
41 Entry = bucket->next;
43 /* If (Entry != bucket), the bucket is empty so make */
44 /* the new entry the first entry in the bucket. */
45 /* if (Entry == bucket), the we have to search the */
46 /* bucket. */
47 if (Entry != bucket) {
48 /* The bucket isn't empty, begin searching. */
49 /* If we leave the for loop then we have either passed */
50 /* where the entry should be or hit the end of the bucket. */
51 /* In either case we should then insert the new entry */
52 /* before the current value of "Entry". */
53 for (; Entry != bucket; Entry = Entry->next) {
54 if (Entry->x_id == x_id) {
55 /* Entry has the same XId... */
56 if (Entry->display == dpy) {
57 /* Entry has the same Display... */
58 /* Therefore there is already an */
59 /* entry with this XId and Display, */
60 /* reset its data value and return. */
61 Entry->data = data;
62 return;
64 /* We found an association with the right */
65 /* id but the wrong display! */
66 continue;
68 /* If the current entry's XId is greater than the */
69 /* XId of the entry to be inserted then we have */
70 /* passed the location where the new XId should */
71 /* be inserted. */
72 if (Entry->x_id > x_id) break;
76 /* If we are here then the new entry should be inserted just */
77 /* before the current value of "Entry". */
78 /* Create a new XAssoc and load it with new provided data. */
79 new_entry = (XAssoc *) malloc(sizeof(XAssoc));
80 new_entry->display = dpy;
81 new_entry->x_id = x_id;
82 new_entry->data = data;
84 /* Insert the new entry. */
85 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev);
88 /* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49
89 (do not change this comment) */