Mercurial > emacs
annotate oldXMenu/XMakeAssoc.c @ 75256:64d67dc1e67a
Add 2007 and sync two Copyrights.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 16 Jan 2007 09:01:24 +0000 |
parents | ce127a46b1ca |
children | 3d45362f1d38 6588c6259dfb |
rev | line source |
---|---|
25858 | 1 /* Copyright Massachusetts Institute of Technology 1985 */ |
74548 | 2 /* Copyright (C) 2001, 2002, 2003, 2004, 2005, |
68640
e8a3fb527b77
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65000
diff
changeset
|
3 2006 Free Software Foundation, Inc. */ |
25858 | 4 |
5 /* | |
6 Permission to use, copy, modify, distribute, and sell this software and its | |
7 documentation for any purpose is hereby granted without fee, provided that | |
8 the above copyright notice appear in all copies and that both that | |
9 copyright notice and this permission notice appear in supporting | |
10 documentation, and that the name of M.I.T. not be used in advertising or | |
11 publicity pertaining to distribution of the software without specific, | |
12 written prior permission. M.I.T. makes no representations about the | |
13 suitability of this software for any purpose. It is provided "as is" | |
14 without express or implied warranty. | |
15 */ | |
16 | |
17 #include <config.h> | |
18 #include <X11/Xlib.h> | |
19 #include <X11/Xresource.h> | |
20 #include "X10.h" | |
21 #include <errno.h> | |
22 | |
23 #ifndef NULL | |
24 #define NULL 0 | |
25 #endif | |
26 | |
27 extern int errno; | |
28 | |
29 void emacs_insque(); | |
30 struct qelem { | |
31 struct qelem *q_forw; | |
32 struct qelem *q_back; | |
33 char q_data[1]; | |
34 }; | |
35 /* | |
36 * XMakeAssoc - Insert data into an XAssocTable keyed on an XId. | |
37 * Data is inserted into the table only once. Redundant inserts are | |
38 * meaningless (but cause no problems). The queue in each association | |
39 * bucket is sorted (lowest XId to highest XId). | |
40 */ | |
41 XMakeAssoc(dpy, table, x_id, data) | |
42 register Display *dpy; | |
43 register XAssocTable *table; | |
44 register XID x_id; | |
45 register caddr_t data; | |
46 { | |
47 int hash; | |
48 register XAssoc *bucket; | |
49 register XAssoc *Entry; | |
50 register XAssoc *new_entry; | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
25858
diff
changeset
|
51 |
25858 | 52 /* Hash the XId to get the bucket number. */ |
53 hash = x_id & (table->size - 1); | |
54 /* Look up the bucket to get the entries in that bucket. */ | |
55 bucket = &table->buckets[hash]; | |
56 /* Get the first entry in the bucket. */ | |
57 Entry = bucket->next; | |
58 | |
59 /* If (Entry != bucket), the bucket is empty so make */ | |
60 /* the new entry the first entry in the bucket. */ | |
61 /* if (Entry == bucket), the we have to search the */ | |
62 /* bucket. */ | |
63 if (Entry != bucket) { | |
64 /* The bucket isn't empty, begin searching. */ | |
65 /* If we leave the for loop then we have either passed */ | |
66 /* where the entry should be or hit the end of the bucket. */ | |
67 /* In either case we should then insert the new entry */ | |
68 /* before the current value of "Entry". */ | |
69 for (; Entry != bucket; Entry = Entry->next) { | |
70 if (Entry->x_id == x_id) { | |
71 /* Entry has the same XId... */ | |
72 if (Entry->display == dpy) { | |
73 /* Entry has the same Display... */ | |
74 /* Therefore there is already an */ | |
75 /* entry with this XId and Display, */ | |
76 /* reset its data value and return. */ | |
77 Entry->data = data; | |
78 return; | |
79 } | |
80 /* We found an association with the right */ | |
81 /* id but the wrong display! */ | |
82 continue; | |
83 } | |
84 /* If the current entry's XId is greater than the */ | |
85 /* XId of the entry to be inserted then we have */ | |
86 /* passed the location where the new XId should */ | |
87 /* be inserted. */ | |
88 if (Entry->x_id > x_id) break; | |
89 } | |
90 } | |
91 | |
92 /* If we are here then the new entry should be inserted just */ | |
93 /* before the current value of "Entry". */ | |
94 /* Create a new XAssoc and load it with new provided data. */ | |
95 new_entry = (XAssoc *) xmalloc(sizeof(XAssoc)); | |
96 new_entry->display = dpy; | |
97 new_entry->x_id = x_id; | |
98 new_entry->data = data; | |
99 | |
100 /* Insert the new entry. */ | |
101 emacs_insque((struct qelem *)new_entry, (struct qelem *)Entry->prev); | |
102 } | |
103 | |
52401 | 104 /* arch-tag: d7e3fb8a-f3b3-4c5d-a307-75ca67ec1b49 |
105 (do not change this comment) */ |