]> cvs.zerfleddert.de Git - micropolis/blob - src/tk/tkatom.c
Fixes for compilation with gcc 15
[micropolis] / src / tk / tkatom.c
1 /*
2 * tkAtom.c --
3 *
4 * This file manages a cache of X Atoms in order to avoid
5 * interactions with the X server. It's much like the Xmu
6 * routines, except it has a cleaner interface (caller
7 * doesn't have to provide permanent storage for atom names,
8 * for example).
9 *
10 * Copyright 1990 Regents of the University of California.
11 * Permission to use, copy, modify, and distribute this
12 * software and its documentation for any purpose and without
13 * fee is hereby granted, provided that the above copyright
14 * notice appear in all copies. The University of California
15 * makes no representations about the suitability of this
16 * software for any purpose. It is provided "as is" without
17 * express or implied warranty.
18 */
19
20 #ifndef lint
21 static char rcsid[] = "$Header: /user6/ouster/wish/RCS/tkAtom.c,v 1.6 92/05/07 09:51:06 ouster Exp $ SPRITE (Berkeley)";
22 #endif
23
24 #include "tkconfig.h"
25 #include "tkint.h"
26
27 /*
28 * Forward references to procedures defined in this file:
29 */
30
31 static void AtomInit _ANSI_ARGS_((TkDisplay *dispPtr));
32 \f
33 /*
34 *--------------------------------------------------------------
35 *
36 * Tk_InternAtom --
37 *
38 * Given a string, produce the equivalent X atom. This
39 * procedure is equivalent to XInternAtom, except that it
40 * keeps a local cache of atoms. Once a name is known,
41 * the server need not be contacted again for that name.
42 *
43 * Results:
44 * The return value is the Atom corresponding to name.
45 *
46 * Side effects:
47 * A new entry may be added to the local atom cache.
48 *
49 *--------------------------------------------------------------
50 */
51
52 Atom
53 Tk_InternAtom (
54 Tk_Window tkwin, /* Window token; map name to atom
55 * for this window's display. */
56 char *name /* Name to turn into atom. */
57 )
58 {
59 register TkDisplay *dispPtr;
60 register Tcl_HashEntry *hPtr;
61 int new;
62
63 dispPtr = ((TkWindow *) tkwin)->dispPtr;
64 if (!dispPtr->atomInit) {
65 AtomInit(dispPtr);
66 }
67
68 hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &new);
69 if (new) {
70 Tcl_HashEntry *hPtr2;
71 Atom atom;
72
73 atom = XInternAtom(dispPtr->display, name, False);
74 Tcl_SetHashValue(hPtr, atom);
75 hPtr2 = Tcl_CreateHashEntry(&dispPtr->atomTable, (char *) atom,
76 &new);
77 Tcl_SetHashValue(hPtr2, Tcl_GetHashKey(&dispPtr->nameTable, hPtr));
78 }
79 return (Atom) Tcl_GetHashValue(hPtr);
80 }
81 \f
82 /*
83 *--------------------------------------------------------------
84 *
85 * Tk_GetAtomName --
86 *
87 * This procedure is equivalent to XGetAtomName except that
88 * it uses the local atom cache to avoid contacting the
89 * server.
90 *
91 * Results:
92 * The return value is a character string corresponding to
93 * the atom given by "atom". This string's storage space
94 * is static: it need not be freed by the caller, and should
95 * not be modified by the caller. If "atom" doesn't exist
96 * on tkwin's display, then the string "?bad atom?" is returned.
97 *
98 * Side effects:
99 * None.
100 *
101 *--------------------------------------------------------------
102 */
103
104 char *
105 Tk_GetAtomName (
106 Tk_Window tkwin, /* Window token; map atom to name
107 * relative to this window's
108 * display. */
109 Atom atom /* Atom whose name is wanted. */
110 )
111 {
112 register TkDisplay *dispPtr;
113 register Tcl_HashEntry *hPtr;
114
115 dispPtr = ((TkWindow *) tkwin)->dispPtr;
116 if (!dispPtr->atomInit) {
117 AtomInit(dispPtr);
118 }
119
120 hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, (char *) atom);
121 if (hPtr == NULL) {
122 char *name;
123 Tk_ErrorHandler handler;
124 int new;
125
126 handler= Tk_CreateErrorHandler(dispPtr->display, BadAtom,
127 -1, -1, (int (*)(int *, XErrorEvent *)) NULL, (ClientData) NULL);
128 name = XGetAtomName(dispPtr->display, atom);
129 if (name == NULL) {
130 name = "?bad atom?";
131 }
132 Tk_DeleteErrorHandler(handler);
133 hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, (char *) name,
134 &new);
135 Tcl_SetHashValue(hPtr, atom);
136 name = Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
137 hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, (char *) atom,
138 &new);
139 Tcl_SetHashValue(hPtr, name);
140 }
141 return (char *) Tcl_GetHashValue(hPtr);
142 }
143 \f
144 /*
145 *--------------------------------------------------------------
146 *
147 * AtomInit --
148 *
149 * Initialize atom-related information for a display.
150 *
151 * Results:
152 * None.
153 *
154 * Side effects:
155 * Tables get initialized, etc. etc..
156 *
157 *--------------------------------------------------------------
158 */
159
160 static void
161 AtomInit (
162 register TkDisplay *dispPtr /* Display to initialize. */
163 )
164 {
165 dispPtr->atomInit = 1;
166 Tcl_InitHashTable(&dispPtr->nameTable, TCL_STRING_KEYS);
167 Tcl_InitHashTable(&dispPtr->atomTable, TCL_ONE_WORD_KEYS);
168 }
Impressum, Datenschutz