Atoms.c revision 6c321187
1/* $Xorg: Atoms.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */ 2 3/* 4 5Copyright 1988, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27*/ 28/* $XFree86: xc/lib/Xmu/Atoms.c,v 3.7 2001/07/25 15:04:50 dawes Exp $ */ 29 30/* 31 * This file contains routines to cache atoms, avoiding multiple 32 * server round-trips. Not so useful now that Xlib caches them. 33 * 34 * Public entry points: 35 * 36 * XmuMakeAtom creates & initializes an opaque AtomRec 37 * XmuInternAtom fetches an Atom from cache or Display 38 * XmuInternStrings fetches multiple Atoms as strings 39 * XmuGetAtomName returns name of an Atom 40 * XmuNameOfAtom returns name from an AtomPtr 41 */ 42 43#ifdef HAVE_CONFIG_H 44#include <config.h> 45#endif 46#include <X11/Intrinsic.h> 47#include "Atoms.h" 48 49typedef struct _DisplayRec { 50 struct _DisplayRec* next; 51 Display *dpy; 52 Atom atom; 53} DisplayRec; 54 55struct _AtomRec { 56 char *name; 57 DisplayRec* head; 58}; 59 60#ifdef SUNSHLIB 61#define STATIC 62#else 63#define STATIC static 64#endif 65 66#if !defined(UNIXCPP) || defined(ANSICPP) 67#define DeclareAtom(atom,text) \ 68STATIC struct _AtomRec __##atom = { text, NULL }; \ 69AtomPtr _##atom = &__##atom; 70#else 71#define DeclareAtom(atom,text) \ 72STATIC struct _AtomRec __/**/atom = { text, NULL }; \ 73AtomPtr _/**/atom = &__/**/atom; 74#endif 75 76DeclareAtom(XA_ATOM_PAIR, "ATOM_PAIR" ) 77DeclareAtom(XA_CHARACTER_POSITION, "CHARACTER_POSITION" ) 78DeclareAtom(XA_CLASS, "CLASS" ) 79DeclareAtom(XA_CLIENT_WINDOW, "CLIENT_WINDOW" ) 80DeclareAtom(XA_CLIPBOARD, "CLIPBOARD" ) 81DeclareAtom(XA_COMPOUND_TEXT, "COMPOUND_TEXT" ) 82DeclareAtom(XA_DECNET_ADDRESS, "DECNET_ADDRESS" ) 83DeclareAtom(XA_DELETE, "DELETE" ) 84DeclareAtom(XA_FILENAME, "FILENAME" ) 85DeclareAtom(XA_HOSTNAME, "HOSTNAME" ) 86DeclareAtom(XA_IP_ADDRESS, "IP_ADDRESS" ) 87DeclareAtom(XA_LENGTH, "LENGTH" ) 88DeclareAtom(XA_LIST_LENGTH, "LIST_LENGTH" ) 89DeclareAtom(XA_NAME, "NAME" ) 90DeclareAtom(XA_NET_ADDRESS, "NET_ADDRESS" ) 91DeclareAtom(XA_NULL, "NULL" ) 92DeclareAtom(XA_OWNER_OS, "OWNER_OS" ) 93DeclareAtom(XA_SPAN, "SPAN" ) 94DeclareAtom(XA_TARGETS, "TARGETS" ) 95DeclareAtom(XA_TEXT, "TEXT" ) 96DeclareAtom(XA_TIMESTAMP, "TIMESTAMP" ) 97DeclareAtom(XA_USER, "USER" ) 98DeclareAtom(XA_UTF8_STRING, "UTF8_STRING" ) 99 100/****************************************************************** 101 102 Public procedures 103 104 ******************************************************************/ 105 106 107AtomPtr 108XmuMakeAtom(_Xconst char *name) 109{ 110 AtomPtr ptr = XtNew(struct _AtomRec); 111 ptr->name = (char *) name; 112 ptr->head = NULL; 113 return ptr; 114} 115 116char * 117XmuNameOfAtom(AtomPtr atom_ptr) 118{ 119 return atom_ptr->name; 120} 121 122 123Atom 124XmuInternAtom(Display *d, AtomPtr atom_ptr) 125{ 126 DisplayRec* display_rec; 127 for (display_rec = atom_ptr->head; display_rec != NULL; 128 display_rec = display_rec->next) { 129 if (display_rec->dpy == d) 130 return display_rec->atom; 131 } 132 display_rec = XtNew(DisplayRec); 133 display_rec->next = atom_ptr->head; 134 atom_ptr->head = display_rec; 135 display_rec->dpy = d; 136 display_rec->atom = XInternAtom(d, atom_ptr->name, False); 137 return display_rec->atom; 138} 139 140 141char * 142XmuGetAtomName(Display *d, Atom atom) 143{ 144 if (atom == 0) return (NULL); 145 return XGetAtomName(d, atom); 146} 147 148/* convert (names, count) to a list of atoms. Caller allocates list */ 149void 150XmuInternStrings(Display *d, register String *names, 151 register Cardinal count, register Atom *atoms) 152{ 153 (void) XInternAtoms(d, (char**)names, (int)count, FALSE, atoms); 154} 155