Blame src/CvtCache.c

Packit cd2a55
/*
Packit cd2a55
Packit cd2a55
Copyright 1989, 1998  The Open Group
Packit cd2a55
Packit cd2a55
Permission to use, copy, modify, distribute, and sell this software and its
Packit cd2a55
documentation for any purpose is hereby granted without fee, provided that
Packit cd2a55
the above copyright notice appear in all copies and that both that
Packit cd2a55
copyright notice and this permission notice appear in supporting
Packit cd2a55
documentation.
Packit cd2a55
Packit cd2a55
The above copyright notice and this permission notice shall be included in
Packit cd2a55
all copies or substantial portions of the Software.
Packit cd2a55
Packit cd2a55
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit cd2a55
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit cd2a55
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit cd2a55
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit cd2a55
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit cd2a55
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit cd2a55
Packit cd2a55
Except as contained in this notice, the name of The Open Group shall not be
Packit cd2a55
used in advertising or otherwise to promote the sale, use or other dealings
Packit cd2a55
in this Software without prior written authorization from The Open Group.
Packit cd2a55
Packit cd2a55
*/
Packit cd2a55
Packit cd2a55
/*
Packit cd2a55
 * Author:  Jim Fulton, MIT X Consortium
Packit cd2a55
 */
Packit cd2a55
Packit cd2a55
#ifdef HAVE_CONFIG_H
Packit cd2a55
#include <config.h>
Packit cd2a55
#endif
Packit cd2a55
#include <stdio.h>
Packit cd2a55
#include <X11/Xlib.h>
Packit cd2a55
#include <X11/Xos.h>
Packit cd2a55
#include <X11/Xmu/CvtCache.h>
Packit cd2a55
#include <stdlib.h>
Packit cd2a55
Packit cd2a55
/*
Packit cd2a55
 * Prototypes
Packit cd2a55
 */
Packit cd2a55
static int _CloseDisplay(XmuDisplayQueue*, XmuDisplayQueueEntry*);
Packit cd2a55
static int _FreeCCDQ(XmuDisplayQueue*);
Packit cd2a55
static void _InitializeCvtCache(XmuCvtCache*);
Packit cd2a55
Packit cd2a55
/*
Packit cd2a55
 * Initialization
Packit cd2a55
 */
Packit cd2a55
static XmuDisplayQueue *dq = NULL;
Packit cd2a55
Packit cd2a55
Packit cd2a55
/*
Packit cd2a55
 * internal utility callbacks
Packit cd2a55
 */
Packit cd2a55
Packit cd2a55
static int
Packit cd2a55
_FreeCCDQ(XmuDisplayQueue *q)
Packit cd2a55
{
Packit cd2a55
    XmuDQDestroy (dq, False);
Packit cd2a55
    dq = NULL;
Packit cd2a55
    return (0);
Packit cd2a55
}
Packit cd2a55
Packit cd2a55
Packit cd2a55
static int
Packit cd2a55
_CloseDisplay(XmuDisplayQueue *q, XmuDisplayQueueEntry *e)
Packit cd2a55
{
Packit cd2a55
    XmuCvtCache *c;
Packit cd2a55
Packit cd2a55
    if (e && (c = (XmuCvtCache *)(e->data))) {
Packit cd2a55
	_XmuStringToBitmapFreeCache (c);
Packit cd2a55
	/* insert calls to free any cached memory */
Packit cd2a55
Packit cd2a55
    }
Packit cd2a55
    return 0;
Packit cd2a55
}
Packit cd2a55
Packit cd2a55
static void
Packit cd2a55
_InitializeCvtCache(register XmuCvtCache *c)
Packit cd2a55
{
Packit cd2a55
    _XmuStringToBitmapInitCache (c);
Packit cd2a55
    /* insert calls to init any cached memory */
Packit cd2a55
}
Packit cd2a55
Packit cd2a55
Packit cd2a55
/*
Packit cd2a55
 * XmuCCLookupDisplay - return the cache entry for the indicated display;
Packit cd2a55
 * initialize the cache if necessary
Packit cd2a55
 */
Packit cd2a55
XmuCvtCache *
Packit cd2a55
_XmuCCLookupDisplay(Display *dpy)
Packit cd2a55
{
Packit cd2a55
    XmuDisplayQueueEntry *e;
Packit cd2a55
Packit cd2a55
    /*
Packit cd2a55
     * If no displays have been added before this, create the display queue.
Packit cd2a55
     */
Packit cd2a55
    if (!dq) {
Packit cd2a55
	dq = XmuDQCreate (_CloseDisplay, _FreeCCDQ, NULL);
Packit cd2a55
	if (!dq) return NULL;
Packit cd2a55
    }
Packit cd2a55
Packit cd2a55
    /*
Packit cd2a55
     * See if the display is already there
Packit cd2a55
     */
Packit cd2a55
    e = XmuDQLookupDisplay (dq, dpy);	/* see if it's there */
Packit cd2a55
    if (!e) {				/* else create it */
Packit cd2a55
	XmuCvtCache *c = (XmuCvtCache *) malloc (sizeof (XmuCvtCache));
Packit cd2a55
	if (!c) return NULL;
Packit cd2a55
Packit cd2a55
	/*
Packit cd2a55
	 * Add the display to the queue
Packit cd2a55
	 */
Packit cd2a55
	e = XmuDQAddDisplay (dq, dpy, (XPointer) c);
Packit cd2a55
	if (!e) {
Packit cd2a55
	    free ((char *) c);
Packit cd2a55
	    return NULL;
Packit cd2a55
	}
Packit cd2a55
Packit cd2a55
	/*
Packit cd2a55
	 * initialize fields in cache
Packit cd2a55
	 */
Packit cd2a55
	_InitializeCvtCache (c);
Packit cd2a55
    }
Packit cd2a55
Packit cd2a55
    /*
Packit cd2a55
     * got it
Packit cd2a55
     */
Packit cd2a55
    return (XmuCvtCache *)(e->data);
Packit cd2a55
}
Packit cd2a55
Packit cd2a55