Atoms.c

Go to the documentation of this file.
00001 /* $Xorg: Atoms.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
00002  
00003 /* 
00004 
00005 Copyright 1988, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/Atoms.c,v 3.7 2001/07/25 15:04:50 dawes Exp $ */
00029 
00030 /*
00031  * This file contains routines to cache atoms, avoiding multiple
00032  * server round-trips.  Not so useful now that Xlib caches them.
00033  *
00034  * Public entry points:
00035  *
00036  *      XmuMakeAtom             creates & initializes an opaque AtomRec
00037  *      XmuInternAtom           fetches an Atom from cache or Display
00038  *      XmuInternStrings        fetches multiple Atoms as strings
00039  *      XmuGetAtomName          returns name of an Atom
00040  *      XmuNameOfAtom           returns name from an AtomPtr
00041  */
00042 
00043 #include <X11/Intrinsic.h>
00044 #include "Atoms.h"
00045 
00046 typedef struct _DisplayRec {
00047     struct _DisplayRec* next;
00048     Display *dpy;
00049     Atom atom;
00050 } DisplayRec;
00051 
00052 struct _AtomRec {
00053     char *name;
00054     DisplayRec* head;
00055 };
00056 
00057 #ifdef SUNSHLIB
00058 #define STATIC
00059 #else
00060 #define STATIC static
00061 #endif
00062 
00063 #if !defined(UNIXCPP) || defined(ANSICPP)
00064 #define DeclareAtom(atom,text) \
00065 STATIC struct _AtomRec __##atom = { text, NULL }; \
00066 AtomPtr _##atom = &__##atom;
00067 #else
00068 #define DeclareAtom(atom,text) \
00069 STATIC struct _AtomRec __atom = { text, NULL }; \
00070 AtomPtr _atom = &__atom;
00071 #endif
00072 
00073 DeclareAtom(XA_ATOM_PAIR,               "ATOM_PAIR"             )
00074 DeclareAtom(XA_CHARACTER_POSITION,      "CHARACTER_POSITION"    )
00075 DeclareAtom(XA_CLASS,                   "CLASS"                 )
00076 DeclareAtom(XA_CLIENT_WINDOW,           "CLIENT_WINDOW"         )
00077 DeclareAtom(XA_CLIPBOARD,               "CLIPBOARD"             )
00078 DeclareAtom(XA_COMPOUND_TEXT,           "COMPOUND_TEXT"         )
00079 DeclareAtom(XA_DECNET_ADDRESS,          "DECNET_ADDRESS"        )
00080 DeclareAtom(XA_DELETE,                  "DELETE"                )
00081 DeclareAtom(XA_FILENAME,                "FILENAME"              )
00082 DeclareAtom(XA_HOSTNAME,                "HOSTNAME"              )
00083 DeclareAtom(XA_IP_ADDRESS,              "IP_ADDRESS"            )
00084 DeclareAtom(XA_LENGTH,                  "LENGTH"                )
00085 DeclareAtom(XA_LIST_LENGTH,             "LIST_LENGTH"           )
00086 DeclareAtom(XA_NAME,                    "NAME"                  )
00087 DeclareAtom(XA_NET_ADDRESS,             "NET_ADDRESS"           )
00088 DeclareAtom(XA_NULL,                    "NULL"                  )
00089 DeclareAtom(XA_OWNER_OS,                "OWNER_OS"              )
00090 DeclareAtom(XA_SPAN,                    "SPAN"                  )
00091 DeclareAtom(XA_TARGETS,                 "TARGETS"               )
00092 DeclareAtom(XA_TEXT,                    "TEXT"                  )
00093 DeclareAtom(XA_TIMESTAMP,               "TIMESTAMP"             )
00094 DeclareAtom(XA_USER,                    "USER"                  )
00095 DeclareAtom(XA_UTF8_STRING,             "UTF8_STRING"           )
00096 
00097 /******************************************************************
00098 
00099   Public procedures
00100 
00101  ******************************************************************/
00102 
00103 
00104 AtomPtr
00105 XmuMakeAtom(_Xconst char *name)
00106 {
00107     AtomPtr ptr = XtNew(struct _AtomRec);
00108     ptr->name = (char *) name;
00109     ptr->head = NULL;
00110     return ptr;
00111 }
00112 
00113 char *
00114 XmuNameOfAtom(AtomPtr atom_ptr)
00115 {
00116     return atom_ptr->name;
00117 }
00118 
00119 
00120 Atom
00121 XmuInternAtom(Display *d, AtomPtr atom_ptr)
00122 {
00123     DisplayRec* display_rec;
00124     for (display_rec = atom_ptr->head; display_rec != NULL;
00125          display_rec = display_rec->next) {
00126         if (display_rec->dpy == d)
00127             return display_rec->atom;
00128     }
00129     display_rec = XtNew(DisplayRec);
00130     display_rec->next = atom_ptr->head;
00131     atom_ptr->head = display_rec;
00132     display_rec->dpy = d;
00133     display_rec->atom = XInternAtom(d, atom_ptr->name, False);
00134     return display_rec->atom;
00135 }
00136 
00137 
00138 char *
00139 XmuGetAtomName(Display *d, Atom atom)
00140 {
00141     if (atom == 0) return (NULL);
00142     return XGetAtomName(d, atom);
00143 }
00144 
00145 /* convert (names, count) to a list of atoms. Caller allocates list */
00146 void
00147 XmuInternStrings(Display *d, register String *names,
00148                  register Cardinal count, register Atom *atoms)
00149 {
00150     (void) XInternAtoms(d, (char**)names, (int)count, FALSE, atoms);
00151 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1