Mercurial > emacs
annotate oldXMenu/XMakeAssoc.c @ 110964:388aaaced495
* lisp/subr.el (last): Make it faster.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 12 Oct 2010 20:30:36 -0700 |
parents | 5cc91198ffb2 |
children | 132f2dfd549f |
rev | line source |
---|---|
25858 | 1 /* Copyright Massachusetts Institute of Technology 1985 */ |
2 | |
76133
995b45abe69d
Remove license text in favour of including copyright.h, as was done in
Glenn Morris <rgm@gnu.org>
parents:
75348
diff
changeset
|
3 #include "copyright.h" |
995b45abe69d
Remove license text in favour of including copyright.h, as was done in
Glenn Morris <rgm@gnu.org>
parents:
75348
diff
changeset
|
4 |
25858 | 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 | |
16 struct qelem { | |
17 struct qelem *q_forw; | |
18 struct qelem *q_back; | |
19 char q_data[1]; | |
20 }; | |
109124
5cc91198ffb2
Convert function definitions in oldXMenu to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
77837
diff
changeset
|
21 void emacs_insque (struct qelem *elem, struct qelem *prev); |
5cc91198ffb2
Convert function definitions in oldXMenu to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
77837
diff
changeset
|
22 |
25858 | 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 */ | |
109124
5cc91198ffb2
Convert function definitions in oldXMenu to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
77837
diff
changeset
|
29 XMakeAssoc(register Display *dpy, register XAssocTable *table, register XID x_id, register caddr_t data) |
25858 | 30 { |
31 int hash; | |
32 register XAssoc *bucket; | |
33 register XAssoc *Entry; | |
34 register XAssoc *new_entry; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
25858
diff
changeset
|
35 |
25858 | 36 /* Hash the XId to get the bucket number. */ |
37 hash = x_id & (table->size - 1); | |
38 /* Look up the bucket to get the entries in that bucket. */ | |
39 bucket = &table->buckets[hash]; | |
40 /* Get the first entry in the bucket. */ | |
41 Entry = bucket->next; | |
42 | |
43 /* If (Entry != bucket), the bucket is empty so make */ | |
44 /* the new entry the first entry in the bucket. */ | |
45 /* if (Entry == bucket), the we have to search the */ | |
46 /* bucket. */ | |
47 if (Entry != bucket) { | |
48 /* The bucket isn't empty, begin searching. */ | |
49 /* If we leave the for loop then we have either passed */ | |
50 /* where the entry should be or hit the end of the bucket. */ | |
51 /* In either case we should then insert the new entry */ | |
52 /* before the current value of "Entry". */ | |
53 for (; Entry != bucket; Entry = Entry->next) { | |
54 if (Entry->x_id == x_id) { | |
55 /* Entry has the same XId... */ | |
56 if (Entry->display == dpy) { | |
57 /* Entry has the same Display... */ | |
58 /* Therefore there is already an */ | |
59 /* entry with this XId and Display, */ | |
60 /* reset its data value and return. */ | |
61 Entry->data = data; | |
62 return; | |
63 } | |
64 /* We found an association with the right */ | |
65 /* id but the wrong display! */ | |
66 continue; | |
67 } | |
68 /* If the current entry's XId is greater than the */ | |
69 /* XId of the entry to be inserted then we have */ | |
70 /* passed the location where the new XId should */ | |
71 /* be inserted. */ | |
72 if (Entry->x_id > x_id) break; | |
73 } | |
74 } | |
75 | |
76 /* If we are here then the new entry should be inserted just */ | |
77 /* before the current value of "Entry". */ | |
78 /* Create a new XAssoc and load it with new provided data. */ | |
77837
77b2ab19bece
Ulrich Mueller <ulm at gentoo.org> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
76174
diff
changeset
|
79 new_entry = (XAssoc *) malloc(sizeof(XAssoc)); |
25858 | 80 new_entry->display = dpy; |
81 new_entry->x_id = x_id; | |
82 new_entry->data = data; | |
83 | |
84 /* Insert the new entry. */ | |
85 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev); | |
86 } | |
87 | |
52401 | 88 /* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49 |
89 (do not change this comment) */ |