Blame src/CvtCache.c

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