Commit | Line | Data |
---|---|---|
e745ede7 DL |
1 | /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | ||
0ff3f435 GM |
3 | #include "copyright.h" |
4 | ||
e745ede7 DL |
5 | |
6 | #include <config.h> | |
7 | #include <X11/Xlib.h> | |
8 | #include <X11/Xresource.h> | |
9 | #include "X10.h" | |
10 | #include <errno.h> | |
11 | ||
12 | #ifndef NULL | |
13 | #define NULL 0 | |
14 | #endif | |
15 | ||
e745ede7 DL |
16 | struct qelem { |
17 | struct qelem *q_forw; | |
18 | struct qelem *q_back; | |
19 | char q_data[1]; | |
20 | }; | |
b782e2d7 DN |
21 | void emacs_insque (struct qelem *elem, struct qelem *prev); |
22 | ||
e745ede7 DL |
23 | /* |
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). | |
28 | */ | |
76320384 | 29 | void |
b782e2d7 | 30 | XMakeAssoc(register Display *dpy, register XAssocTable *table, register XID x_id, register caddr_t data) |
e745ede7 DL |
31 | { |
32 | int hash; | |
33 | register XAssoc *bucket; | |
34 | register XAssoc *Entry; | |
35 | register XAssoc *new_entry; | |
177c0ea7 | 36 | |
e745ede7 DL |
37 | /* Hash the XId to get the bucket number. */ |
38 | hash = x_id & (table->size - 1); | |
39 | /* Look up the bucket to get the entries in that bucket. */ | |
40 | bucket = &table->buckets[hash]; | |
41 | /* Get the first entry in the bucket. */ | |
42 | Entry = bucket->next; | |
43 | ||
44 | /* If (Entry != bucket), the bucket is empty so make */ | |
45 | /* the new entry the first entry in the bucket. */ | |
46 | /* if (Entry == bucket), the we have to search the */ | |
47 | /* bucket. */ | |
48 | if (Entry != bucket) { | |
49 | /* The bucket isn't empty, begin searching. */ | |
50 | /* If we leave the for loop then we have either passed */ | |
51 | /* where the entry should be or hit the end of the bucket. */ | |
52 | /* In either case we should then insert the new entry */ | |
53 | /* before the current value of "Entry". */ | |
54 | for (; Entry != bucket; Entry = Entry->next) { | |
55 | if (Entry->x_id == x_id) { | |
56 | /* Entry has the same XId... */ | |
57 | if (Entry->display == dpy) { | |
58 | /* Entry has the same Display... */ | |
59 | /* Therefore there is already an */ | |
60 | /* entry with this XId and Display, */ | |
61 | /* reset its data value and return. */ | |
62 | Entry->data = data; | |
63 | return; | |
64 | } | |
65 | /* We found an association with the right */ | |
66 | /* id but the wrong display! */ | |
67 | continue; | |
68 | } | |
69 | /* If the current entry's XId is greater than the */ | |
70 | /* XId of the entry to be inserted then we have */ | |
71 | /* passed the location where the new XId should */ | |
72 | /* be inserted. */ | |
73 | if (Entry->x_id > x_id) break; | |
74 | } | |
75 | } | |
76 | ||
77 | /* If we are here then the new entry should be inserted just */ | |
78 | /* before the current value of "Entry". */ | |
79 | /* Create a new XAssoc and load it with new provided data. */ | |
bdf41b96 | 80 | new_entry = (XAssoc *) malloc(sizeof(XAssoc)); |
e745ede7 DL |
81 | new_entry->display = dpy; |
82 | new_entry->x_id = x_id; | |
83 | new_entry->data = data; | |
84 | ||
85 | /* Insert the new entry. */ | |
86 | emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev); | |
87 | } | |
88 |