Mercurial > emacs
annotate oldXMenu/XMakeAssoc.c @ 76170:365a8de87f1f
Add GPL for FSF copyright. Adjust FSF copyright years based on
changelogs.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 27 Feb 2007 02:56:08 +0000 |
parents | 995b45abe69d |
children | fec5e03aaf59 dd7c098af727 |
rev | line source |
---|---|
25858 | 1 /* Copyright Massachusetts Institute of Technology 1985 */ |
74548 | 2 /* Copyright (C) 2001, 2002, 2003, 2004, 2005, |
75348 | 3 2006, 2007 Free Software Foundation, Inc. */ |
25858 | 4 |
76133
995b45abe69d
Remove license text in favour of including copyright.h, as was done in
Glenn Morris <rgm@gnu.org>
parents:
75348
diff
changeset
|
5 #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
|
6 |
25858 | 7 |
8 #include <config.h> | |
9 #include <X11/Xlib.h> | |
10 #include <X11/Xresource.h> | |
11 #include "X10.h" | |
12 #include <errno.h> | |
13 | |
14 #ifndef NULL | |
15 #define NULL 0 | |
16 #endif | |
17 | |
18 extern int errno; | |
19 | |
20 void emacs_insque(); | |
21 struct qelem { | |
22 struct qelem *q_forw; | |
23 struct qelem *q_back; | |
24 char q_data[1]; | |
25 }; | |
26 /* | |
27 * XMakeAssoc - Insert data into an XAssocTable keyed on an XId. | |
28 * Data is inserted into the table only once. Redundant inserts are | |
29 * meaningless (but cause no problems). The queue in each association | |
30 * bucket is sorted (lowest XId to highest XId). | |
31 */ | |
32 XMakeAssoc(dpy, table, x_id, data) | |
33 register Display *dpy; | |
34 register XAssocTable *table; | |
35 register XID x_id; | |
36 register caddr_t data; | |
37 { | |
38 int hash; | |
39 register XAssoc *bucket; | |
40 register XAssoc *Entry; | |
41 register XAssoc *new_entry; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
25858
diff
changeset
|
42 |
25858 | 43 /* Hash the XId to get the bucket number. */ |
44 hash = x_id & (table->size - 1); | |
45 /* Look up the bucket to get the entries in that bucket. */ | |
46 bucket = &table->buckets[hash]; | |
47 /* Get the first entry in the bucket. */ | |
48 Entry = bucket->next; | |
49 | |
50 /* If (Entry != bucket), the bucket is empty so make */ | |
51 /* the new entry the first entry in the bucket. */ | |
52 /* if (Entry == bucket), the we have to search the */ | |
53 /* bucket. */ | |
54 if (Entry != bucket) { | |
55 /* The bucket isn't empty, begin searching. */ | |
56 /* If we leave the for loop then we have either passed */ | |
57 /* where the entry should be or hit the end of the bucket. */ | |
58 /* In either case we should then insert the new entry */ | |
59 /* before the current value of "Entry". */ | |
60 for (; Entry != bucket; Entry = Entry->next) { | |
61 if (Entry->x_id == x_id) { | |
62 /* Entry has the same XId... */ | |
63 if (Entry->display == dpy) { | |
64 /* Entry has the same Display... */ | |
65 /* Therefore there is already an */ | |
66 /* entry with this XId and Display, */ | |
67 /* reset its data value and return. */ | |
68 Entry->data = data; | |
69 return; | |
70 } | |
71 /* We found an association with the right */ | |
72 /* id but the wrong display! */ | |
73 continue; | |
74 } | |
75 /* If the current entry's XId is greater than the */ | |
76 /* XId of the entry to be inserted then we have */ | |
77 /* passed the location where the new XId should */ | |
78 /* be inserted. */ | |
79 if (Entry->x_id > x_id) break; | |
80 } | |
81 } | |
82 | |
83 /* If we are here then the new entry should be inserted just */ | |
84 /* before the current value of "Entry". */ | |
85 /* Create a new XAssoc and load it with new provided data. */ | |
86 new_entry = (XAssoc *) xmalloc(sizeof(XAssoc)); | |
87 new_entry->display = dpy; | |
88 new_entry->x_id = x_id; | |
89 new_entry->data = data; | |
90 | |
91 /* Insert the new entry. */ | |
92 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev); | |
93 } | |
94 | |
52401 | 95 /* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49 |
96 (do not change this comment) */ |