home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / CvtCache.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-19  |  3.0 KB  |  122 lines

  1. /*
  2.  * $XConsortium: CvtCache.c,v 1.6 90/12/19 18:21:33 converse Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  * 
  23.  * Author:  Jim Fulton, MIT X Consortium
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <X11/Xlib.h>
  28. #include <X11/Xos.h>
  29. #include <X11/Xmu/CvtCache.h>
  30.  
  31. extern char *malloc();
  32.  
  33. static XmuDisplayQueue *dq = NULL;
  34. static int _CloseDisplay(), _FreeCCDQ();
  35.  
  36.  
  37.  
  38. /*
  39.  * internal utility callbacks
  40.  */
  41.  
  42. static int _FreeCCDQ (q)
  43.     XmuDisplayQueue *q;
  44. {
  45.     XmuDQDestroy (dq, False);
  46.     dq = NULL;
  47. }
  48.  
  49.  
  50. static int _CloseDisplay (q, e)
  51.     XmuDisplayQueue *q;
  52.     XmuDisplayQueueEntry *e;
  53. {
  54.     XmuCvtCache *c;
  55.     extern void _XmuStringToBitmapFreeCache();
  56.  
  57.     if (e && (c = (XmuCvtCache *)(e->data))) {
  58.     _XmuStringToBitmapFreeCache (c);
  59.     /* insert calls to free any cached memory */
  60.  
  61.     }
  62.     return 0;
  63. }
  64.  
  65. static void _InitializeCvtCache (c)
  66.     register XmuCvtCache *c;
  67. {
  68.     extern void _XmuStringToBitmapInitCache();
  69.  
  70.     _XmuStringToBitmapInitCache (c);
  71.     /* insert calls to init any cached memory */
  72. }
  73.  
  74.  
  75. /*
  76.  * XmuCCLookupDisplay - return the cache entry for the indicated display;
  77.  * initialize the cache if necessary
  78.  */
  79. XmuCvtCache *_XmuCCLookupDisplay (dpy)
  80.     Display *dpy;
  81. {
  82.     XmuDisplayQueueEntry *e;
  83.  
  84.     /*
  85.      * If no displays have been added before this, create the display queue.
  86.      */
  87.     if (!dq) {
  88.     dq = XmuDQCreate (_CloseDisplay, _FreeCCDQ, NULL);
  89.     if (!dq) return NULL;
  90.     }
  91.     
  92.     /*
  93.      * See if the display is already there
  94.      */
  95.     e = XmuDQLookupDisplay (dq, dpy);    /* see if it's there */
  96.     if (!e) {                /* else create it */
  97.     XmuCvtCache *c = (XmuCvtCache *) malloc (sizeof (XmuCvtCache));
  98.     if (!c) return NULL;
  99.  
  100.     /*
  101.      * Add the display to the queue
  102.      */
  103.     e = XmuDQAddDisplay (dq, dpy, (caddr_t) c);
  104.     if (!e) {
  105.         free ((char *) c);
  106.         return NULL;
  107.     }
  108.  
  109.     /*
  110.      * initialize fields in cache
  111.      */
  112.     _InitializeCvtCache (c);
  113.     }
  114.  
  115.     /*
  116.      * got it
  117.      */
  118.     return (XmuCvtCache *)(e->data);
  119. }
  120.  
  121.  
  122.