auth-source.el (auth-source-debug): Enable by default and don't mention the obsolete...
[emacs.git] / oldXMenu / XMakeAssoc.c
blob3626eb01f5245c0332454b1549df6d69e13b57a2
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 void
30 XMakeAssoc(register Display *dpy, register XAssocTable *table, register XID x_id, register caddr_t data)
32 int hash;
33 register XAssoc *bucket;
34 register XAssoc *Entry;
35 register XAssoc *new_entry;
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;
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;
65 /* We found an association with the right */
66 /* id but the wrong display! */
67 continue;
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;
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. */
80 new_entry = (XAssoc *) malloc(sizeof(XAssoc));
81 new_entry->display = dpy;
82 new_entry->x_id = x_id;
83 new_entry->data = data;
85 /* Insert the new entry. */
86 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev);