|
|
1.1 root 1: #include "copyright.h"
2:
3: /* $Header: XMakeAssoc.c,v 10.16 87/09/11 07:56:43 toddb Exp $ */
4: /* Copyright Massachusetts Institute of Technology 1985 */
5:
6: #include "Xlibint.h"
7: #include "X10.h"
8:
9: void insque();
10: struct qelem {
11: struct qelem *q_forw;
12: struct qelem *q_back;
13: char q_data[1];
14: };
15: /*
16: * XMakeAssoc - Insert data into an XAssocTable keyed on an XId.
17: * Data is inserted into the table only once. Redundant inserts are
18: * meaningless (but cause no problems). The queue in each association
19: * bucket is sorted (lowest XId to highest XId).
20: */
21: XMakeAssoc(dpy, table, x_id, data)
22: register Display *dpy;
23: register XAssocTable *table;
24: register XID x_id;
25: register caddr_t data;
26: {
27: int hash;
28: register XAssoc *bucket;
29: register XAssoc *Entry;
30: register XAssoc *new_entry;
31:
32: /* Hash the XId to get the bucket number. */
33: hash = x_id & (table->size - 1);
34: /* Look up the bucket to get the entries in that bucket. */
35: bucket = &table->buckets[hash];
36: /* Get the first entry in the bucket. */
37: Entry = bucket->next;
38:
39: /* If (Entry != bucket), the bucket is empty so make */
40: /* the new entry the first entry in the bucket. */
41: /* if (Entry == bucket), the we have to search the */
42: /* bucket. */
43: if (Entry != bucket) {
44: /* The bucket isn't empty, begin searching. */
45: /* If we leave the for loop then we have either passed */
46: /* where the entry should be or hit the end of the bucket. */
47: /* In either case we should then insert the new entry */
48: /* before the current value of "Entry". */
49: for (; Entry != bucket; Entry = Entry->next) {
50: if (Entry->x_id == x_id) {
51: /* Entry has the same XId... */
52: if (Entry->display == dpy) {
53: /* Entry has the same Display... */
54: /* Therefore there is already an */
55: /* entry with this XId and Display, */
56: /* reset its data value and return. */
57: Entry->data = data;
58: return;
59: }
60: /* We found an association with the right */
61: /* id but the wrong display! */
62: continue;
63: }
64: /* If the current entry's XId is greater than the */
65: /* XId of the entry to be inserted then we have */
66: /* passed the location where the new XId should */
67: /* be inserted. */
68: if (Entry->x_id > x_id) break;
69: }
70: }
71:
72: /* If we are here then the new entry should be inserted just */
73: /* before the current value of "Entry". */
74: /* Create a new XAssoc and load it with new provided data. */
75: new_entry = (XAssoc *)Xmalloc(sizeof(XAssoc));
76: if (new_entry == NULL) {
77: /* Malloc failed! */
78: errno = ENOMEM;
79: (*_XIOErrorFunction)(dpy);
80: }
81: new_entry->display = dpy;
82: new_entry->x_id = x_id;
83: new_entry->data = data;
84:
85: /* Insert the new entry. */
86: insque((struct qelem *)new_entry, (struct qelem *)Entry->prev);
87: }
88:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.