10cc2eac3Smrg/*
26c321187Smrg
36c321187SmrgCopyright 1988, 1998  The Open Group
46c321187Smrg
56c321187SmrgPermission to use, copy, modify, distribute, and sell this software and its
66c321187Smrgdocumentation for any purpose is hereby granted without fee, provided that
76c321187Smrgthe above copyright notice appear in all copies and that both that
86c321187Smrgcopyright notice and this permission notice appear in supporting
96c321187Smrgdocumentation.
106c321187Smrg
116c321187SmrgThe above copyright notice and this permission notice shall be included in
126c321187Smrgall copies or substantial portions of the Software.
136c321187Smrg
146c321187SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
156c321187SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
166c321187SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
176c321187SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
186c321187SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
196c321187SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
206c321187Smrg
216c321187SmrgExcept as contained in this notice, the name of The Open Group shall not be
226c321187Smrgused in advertising or otherwise to promote the sale, use or other dealings
236c321187Smrgin this Software without prior written authorization from The Open Group.
246c321187Smrg
256c321187Smrg*/
266c321187Smrg
276c321187Smrg/*
286c321187Smrg * This file contains routines to cache atoms, avoiding multiple
296c321187Smrg * server round-trips.  Not so useful now that Xlib caches them.
306c321187Smrg *
316c321187Smrg * Public entry points:
326c321187Smrg *
336c321187Smrg *	XmuMakeAtom		creates & initializes an opaque AtomRec
346c321187Smrg *	XmuInternAtom		fetches an Atom from cache or Display
356c321187Smrg *	XmuInternStrings	fetches multiple Atoms as strings
366c321187Smrg *	XmuGetAtomName		returns name of an Atom
376c321187Smrg *	XmuNameOfAtom		returns name from an AtomPtr
386c321187Smrg */
396c321187Smrg
406c321187Smrg#ifdef HAVE_CONFIG_H
416c321187Smrg#include <config.h>
426c321187Smrg#endif
436c321187Smrg#include <X11/Intrinsic.h>
446c321187Smrg#include "Atoms.h"
456c321187Smrg
466c321187Smrgtypedef struct _DisplayRec {
476c321187Smrg    struct _DisplayRec* next;
486c321187Smrg    Display *dpy;
496c321187Smrg    Atom atom;
506c321187Smrg} DisplayRec;
516c321187Smrg
526c321187Smrgstruct _AtomRec {
530cc2eac3Smrg    _Xconst char *name;
546c321187Smrg    DisplayRec* head;
556c321187Smrg};
566c321187Smrg
576c321187Smrg#define DeclareAtom(atom,text) \
58198e4c3cSmrgstatic struct _AtomRec __##atom = { text, NULL }; \
596c321187SmrgAtomPtr _##atom = &__##atom;
606c321187Smrg
616c321187SmrgDeclareAtom(XA_ATOM_PAIR,		"ATOM_PAIR"		)
626c321187SmrgDeclareAtom(XA_CHARACTER_POSITION,	"CHARACTER_POSITION"	)
636c321187SmrgDeclareAtom(XA_CLASS,			"CLASS"			)
646c321187SmrgDeclareAtom(XA_CLIENT_WINDOW,		"CLIENT_WINDOW"		)
656c321187SmrgDeclareAtom(XA_CLIPBOARD,		"CLIPBOARD"		)
666c321187SmrgDeclareAtom(XA_COMPOUND_TEXT,		"COMPOUND_TEXT"		)
676c321187SmrgDeclareAtom(XA_DECNET_ADDRESS,		"DECNET_ADDRESS"	)
686c321187SmrgDeclareAtom(XA_DELETE,			"DELETE"		)
696c321187SmrgDeclareAtom(XA_FILENAME,		"FILENAME"		)
706c321187SmrgDeclareAtom(XA_HOSTNAME,		"HOSTNAME"		)
716c321187SmrgDeclareAtom(XA_IP_ADDRESS,		"IP_ADDRESS"		)
726c321187SmrgDeclareAtom(XA_LENGTH,			"LENGTH"		)
736c321187SmrgDeclareAtom(XA_LIST_LENGTH,		"LIST_LENGTH"		)
746c321187SmrgDeclareAtom(XA_NAME,			"NAME"			)
756c321187SmrgDeclareAtom(XA_NET_ADDRESS,		"NET_ADDRESS"		)
766c321187SmrgDeclareAtom(XA_NULL,			"NULL"			)
776c321187SmrgDeclareAtom(XA_OWNER_OS,		"OWNER_OS"		)
786c321187SmrgDeclareAtom(XA_SPAN,			"SPAN"			)
796c321187SmrgDeclareAtom(XA_TARGETS,			"TARGETS"		)
806c321187SmrgDeclareAtom(XA_TEXT,			"TEXT"			)
816c321187SmrgDeclareAtom(XA_TIMESTAMP,		"TIMESTAMP"		)
826c321187SmrgDeclareAtom(XA_USER,			"USER"			)
836c321187SmrgDeclareAtom(XA_UTF8_STRING,		"UTF8_STRING"		)
846c321187Smrg
856c321187Smrg/******************************************************************
866c321187Smrg
876c321187Smrg  Public procedures
886c321187Smrg
896c321187Smrg ******************************************************************/
906c321187Smrg
916c321187Smrg
926c321187SmrgAtomPtr
936c321187SmrgXmuMakeAtom(_Xconst char *name)
946c321187Smrg{
956c321187Smrg    AtomPtr ptr = XtNew(struct _AtomRec);
960cc2eac3Smrg    ptr->name = name;
976c321187Smrg    ptr->head = NULL;
986c321187Smrg    return ptr;
996c321187Smrg}
1006c321187Smrg
1016c321187Smrgchar *
1026c321187SmrgXmuNameOfAtom(AtomPtr atom_ptr)
1036c321187Smrg{
1040cc2eac3Smrg    return (char *) atom_ptr->name;
1056c321187Smrg}
1066c321187Smrg
1076c321187Smrg
1086c321187SmrgAtom
1096c321187SmrgXmuInternAtom(Display *d, AtomPtr atom_ptr)
1106c321187Smrg{
1116c321187Smrg    DisplayRec* display_rec;
1126c321187Smrg    for (display_rec = atom_ptr->head; display_rec != NULL;
1136c321187Smrg	 display_rec = display_rec->next) {
1146c321187Smrg	if (display_rec->dpy == d)
1156c321187Smrg	    return display_rec->atom;
1166c321187Smrg    }
1176c321187Smrg    display_rec = XtNew(DisplayRec);
1186c321187Smrg    display_rec->next = atom_ptr->head;
1196c321187Smrg    atom_ptr->head = display_rec;
1206c321187Smrg    display_rec->dpy = d;
1216c321187Smrg    display_rec->atom = XInternAtom(d, atom_ptr->name, False);
1226c321187Smrg    return display_rec->atom;
1236c321187Smrg}
1246c321187Smrg
1256c321187Smrg
1266c321187Smrgchar *
1276c321187SmrgXmuGetAtomName(Display *d, Atom atom)
1286c321187Smrg{
1296c321187Smrg    if (atom == 0) return (NULL);
1306c321187Smrg    return XGetAtomName(d, atom);
1316c321187Smrg}
1326c321187Smrg
1336c321187Smrg/* convert (names, count) to a list of atoms. Caller allocates list */
1346c321187Smrgvoid
1356c321187SmrgXmuInternStrings(Display *d, register String *names,
1366c321187Smrg		 register Cardinal count, register Atom *atoms)
1376c321187Smrg{
1386c321187Smrg    (void) XInternAtoms(d, (char**)names, (int)count, FALSE, atoms);
1396c321187Smrg}
140