16c321187Smrg/*
20cc2eac3Smrg
36c321187SmrgCopyright 1989, 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
270cc2eac3Smrg/*
286c321187Smrg * Author:  Jim Fulton, MIT X Consortium
296c321187Smrg */
306c321187Smrg
316c321187Smrg#ifdef HAVE_CONFIG_H
326c321187Smrg#include <config.h>
336c321187Smrg#endif
346c321187Smrg#include <stdio.h>
356c321187Smrg#include <X11/Xlib.h>
366c321187Smrg#include <X11/Xos.h>
376c321187Smrg#include <X11/Xmu/CvtCache.h>
386c321187Smrg#include <stdlib.h>
396c321187Smrg
406c321187Smrg/*
416c321187Smrg * Prototypes
426c321187Smrg */
436c321187Smrgstatic int _CloseDisplay(XmuDisplayQueue*, XmuDisplayQueueEntry*);
446c321187Smrgstatic int _FreeCCDQ(XmuDisplayQueue*);
456c321187Smrgstatic void _InitializeCvtCache(XmuCvtCache*);
466c321187Smrg
476c321187Smrg/*
486c321187Smrg * Initialization
496c321187Smrg */
506c321187Smrgstatic XmuDisplayQueue *dq = NULL;
516c321187Smrg
526c321187Smrg
536c321187Smrg/*
546c321187Smrg * internal utility callbacks
556c321187Smrg */
566c321187Smrg
576c321187Smrgstatic int
586c321187Smrg_FreeCCDQ(XmuDisplayQueue *q)
596c321187Smrg{
606c321187Smrg    XmuDQDestroy (dq, False);
616c321187Smrg    dq = NULL;
626c321187Smrg    return (0);
636c321187Smrg}
646c321187Smrg
656c321187Smrg
666c321187Smrgstatic int
676c321187Smrg_CloseDisplay(XmuDisplayQueue *q, XmuDisplayQueueEntry *e)
686c321187Smrg{
696c321187Smrg    XmuCvtCache *c;
706c321187Smrg
716c321187Smrg    if (e && (c = (XmuCvtCache *)(e->data))) {
726c321187Smrg	_XmuStringToBitmapFreeCache (c);
736c321187Smrg	/* insert calls to free any cached memory */
746c321187Smrg
756c321187Smrg    }
766c321187Smrg    return 0;
776c321187Smrg}
786c321187Smrg
796c321187Smrgstatic void
806c321187Smrg_InitializeCvtCache(register XmuCvtCache *c)
816c321187Smrg{
826c321187Smrg    _XmuStringToBitmapInitCache (c);
836c321187Smrg    /* insert calls to init any cached memory */
846c321187Smrg}
856c321187Smrg
866c321187Smrg
876c321187Smrg/*
886c321187Smrg * XmuCCLookupDisplay - return the cache entry for the indicated display;
896c321187Smrg * initialize the cache if necessary
906c321187Smrg */
916c321187SmrgXmuCvtCache *
926c321187Smrg_XmuCCLookupDisplay(Display *dpy)
936c321187Smrg{
946c321187Smrg    XmuDisplayQueueEntry *e;
956c321187Smrg
966c321187Smrg    /*
976c321187Smrg     * If no displays have been added before this, create the display queue.
986c321187Smrg     */
996c321187Smrg    if (!dq) {
1006c321187Smrg	dq = XmuDQCreate (_CloseDisplay, _FreeCCDQ, NULL);
1016c321187Smrg	if (!dq) return NULL;
1026c321187Smrg    }
1030cc2eac3Smrg
1046c321187Smrg    /*
1056c321187Smrg     * See if the display is already there
1066c321187Smrg     */
1076c321187Smrg    e = XmuDQLookupDisplay (dq, dpy);	/* see if it's there */
1086c321187Smrg    if (!e) {				/* else create it */
1099dedec0cSmrg	XmuCvtCache *c = malloc (sizeof (XmuCvtCache));
1106c321187Smrg	if (!c) return NULL;
1116c321187Smrg
1126c321187Smrg	/*
1136c321187Smrg	 * Add the display to the queue
1146c321187Smrg	 */
1156c321187Smrg	e = XmuDQAddDisplay (dq, dpy, (XPointer) c);
1166c321187Smrg	if (!e) {
1179dedec0cSmrg	    free (c);
1186c321187Smrg	    return NULL;
1196c321187Smrg	}
1206c321187Smrg
1216c321187Smrg	/*
1226c321187Smrg	 * initialize fields in cache
1236c321187Smrg	 */
1246c321187Smrg	_InitializeCvtCache (c);
1256c321187Smrg    }
1266c321187Smrg
1276c321187Smrg    /*
1286c321187Smrg     * got it
1296c321187Smrg     */
1306c321187Smrg    return (XmuCvtCache *)(e->data);
1316c321187Smrg}
1326c321187Smrg
1336c321187Smrg
134