Mercurial > emacs
annotate oldXMenu/XMakeAssoc.c @ 61538:1ba2007fb029
TUTORIAL.sk updated header.
author | Marcelo Toledo <marcelo@gnu.org> |
---|---|
date | Wed, 13 Apr 2005 22:08:50 +0000 |
parents | e8824c4f5f7e |
children | 3861ff8f4bf1 |
rev | line source |
---|---|
25858 | 1 /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | |
3 /* | |
4 Permission to use, copy, modify, distribute, and sell this software and its | |
5 documentation for any purpose is hereby granted without fee, provided that | |
6 the above copyright notice appear in all copies and that both that | |
7 copyright notice and this permission notice appear in supporting | |
8 documentation, and that the name of M.I.T. not be used in advertising or | |
9 publicity pertaining to distribution of the software without specific, | |
10 written prior permission. M.I.T. makes no representations about the | |
11 suitability of this software for any purpose. It is provided "as is" | |
12 without 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 | |
25 extern int errno; | |
26 | |
27 void emacs_insque(); | |
28 struct 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 */ | |
39 XMakeAssoc(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; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
25858
diff
changeset
|
49 |
25858 | 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 | |
52401 | 102 /* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49 |
103 (do not change this comment) */ |