(toggle-gdb-use-inferior-io-buffer):
[bpt/emacs.git] / oldXMenu / XMakeAssoc.c
CommitLineData
e745ede7
DL
1/* Copyright Massachusetts Institute of Technology 1985 */
2
3/*
4Permission to use, copy, modify, distribute, and sell this software and its
5documentation for any purpose is hereby granted without fee, provided that
6the above copyright notice appear in all copies and that both that
7copyright notice and this permission notice appear in supporting
8documentation, and that the name of M.I.T. not be used in advertising or
9publicity pertaining to distribution of the software without specific,
10written prior permission. M.I.T. makes no representations about the
11suitability of this software for any purpose. It is provided "as is"
12without express or implied warranty.
13*/
14
15#include <config.h>
16#include <X11/Xlib.h>
17#include <X11/Xresource.h>
18#include "X10.h"
19#include <errno.h>
20
21#ifndef NULL
22#define NULL 0
23#endif
24
25extern int errno;
26
27void emacs_insque();
28struct qelem {
29 struct qelem *q_forw;
30 struct qelem *q_back;
31 char q_data[1];
32};
33/*
34 * XMakeAssoc - Insert data into an XAssocTable keyed on an XId.
35 * Data is inserted into the table only once. Redundant inserts are
36 * meaningless (but cause no problems). The queue in each association
37 * bucket is sorted (lowest XId to highest XId).
38 */
39XMakeAssoc(dpy, table, x_id, data)
40 register Display *dpy;
41 register XAssocTable *table;
42 register XID x_id;
43 register caddr_t data;
44{
45 int hash;
46 register XAssoc *bucket;
47 register XAssoc *Entry;
48 register XAssoc *new_entry;
177c0ea7 49
e745ede7
DL
50 /* Hash the XId to get the bucket number. */
51 hash = x_id & (table->size - 1);
52 /* Look up the bucket to get the entries in that bucket. */
53 bucket = &table->buckets[hash];
54 /* Get the first entry in the bucket. */
55 Entry = bucket->next;
56
57 /* If (Entry != bucket), the bucket is empty so make */
58 /* the new entry the first entry in the bucket. */
59 /* if (Entry == bucket), the we have to search the */
60 /* bucket. */
61 if (Entry != bucket) {
62 /* The bucket isn't empty, begin searching. */
63 /* If we leave the for loop then we have either passed */
64 /* where the entry should be or hit the end of the bucket. */
65 /* In either case we should then insert the new entry */
66 /* before the current value of "Entry". */
67 for (; Entry != bucket; Entry = Entry->next) {
68 if (Entry->x_id == x_id) {
69 /* Entry has the same XId... */
70 if (Entry->display == dpy) {
71 /* Entry has the same Display... */
72 /* Therefore there is already an */
73 /* entry with this XId and Display, */
74 /* reset its data value and return. */
75 Entry->data = data;
76 return;
77 }
78 /* We found an association with the right */
79 /* id but the wrong display! */
80 continue;
81 }
82 /* If the current entry's XId is greater than the */
83 /* XId of the entry to be inserted then we have */
84 /* passed the location where the new XId should */
85 /* be inserted. */
86 if (Entry->x_id > x_id) break;
87 }
88 }
89
90 /* If we are here then the new entry should be inserted just */
91 /* before the current value of "Entry". */
92 /* Create a new XAssoc and load it with new provided data. */
93 new_entry = (XAssoc *) xmalloc(sizeof(XAssoc));
94 new_entry->display = dpy;
95 new_entry->x_id = x_id;
96 new_entry->data = data;
97
98 /* Insert the new entry. */
99 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev);
100}
101
ab5796a9
MB
102/* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49
103 (do not change this comment) */