LocBitmap.c File Reference

#include <X11/Xlib.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include <X11/Xmu/CvtCache.h>
#include <X11/Xmu/Drawing.h>
#include <X11/Xmu/SysUtil.h>
#include <limits.h>
#include <sys/param.h>

Include dependency graph for LocBitmap.c:

Go to the source code of this file.

Defines

#define PATH_MAX   1024
#define BITMAPDIR   "/usr/include/X11/bitmaps"

Functions

static char ** split_path_string (char *)
Pixmap XmuLocateBitmapFile (Screen *screen, _Xconst char *name, char *srcname, int srcnamelen, int *widthp, int *heightp, int *xhotp, int *yhotp)
Pixmap XmuLocatePixmapFile (Screen *screen, _Xconst char *name, unsigned long fore, unsigned long back, unsigned int depth, char *srcname, int srcnamelen, int *widthp, int *heightp, int *xhotp, int *yhotp)
static char ** split_path_string (register char *src)
void _XmuStringToBitmapInitCache (register XmuCvtCache *c)
void _XmuStringToBitmapFreeCache (register XmuCvtCache *c)


Define Documentation

#define BITMAPDIR   "/usr/include/X11/bitmaps"

Referenced by XmuLocatePixmapFile().

#define PATH_MAX   1024

Definition at line 62 of file LocBitmap.c.


Function Documentation

void _XmuStringToBitmapFreeCache ( register XmuCvtCache c  ) 

Definition at line 262 of file LocBitmap.c.

References free().

00263 {
00264     if (c->string_to_bitmap.bitmapFilePath) {
00265         if (c->string_to_bitmap.bitmapFilePath[0]) 
00266           free (c->string_to_bitmap.bitmapFilePath[0]);
00267         free ((char *) (c->string_to_bitmap.bitmapFilePath));
00268     }
00269 }

Here is the call graph for this function:

void _XmuStringToBitmapInitCache ( register XmuCvtCache c  ) 

Definition at line 256 of file LocBitmap.c.

References NULL.

00257 {
00258     c->string_to_bitmap.bitmapFilePath = NULL;
00259 }

static char** split_path_string ( register char *  src  )  [static]

Definition at line 222 of file LocBitmap.c.

References calloc(), free(), malloc(), and NULL.

00223 {
00224     int nelems = 1;
00225     register char *dst;
00226     char **elemlist, **elem;
00227 
00228     /* count the number of elements */
00229     for (dst = src; *dst; dst++) if (*dst == ':') nelems++;
00230 
00231     /* get memory for everything */
00232     dst = (char *) malloc (dst - src + 1);
00233     if (!dst) return NULL;
00234     elemlist = (char **) calloc ((nelems + 1), sizeof (char *));
00235     if (!elemlist) {
00236         free (dst);
00237         return NULL;
00238     }
00239 
00240     /* copy to new list and walk up nulling colons and setting list pointers */
00241     strcpy (dst, src);
00242     for (elem = elemlist, src = dst; *src; src++) {
00243         if (*src == ':') {
00244             *elem++ = dst;
00245             *src = '\0';
00246             dst = src + 1;
00247         }
00248     }
00249     *elem = dst;
00250 
00251     return elemlist;
00252 }

Here is the call graph for this function:

static char** split_path_string ( char *   )  [static]

Referenced by XmuLocatePixmapFile().

Here is the caller graph for this function:

Pixmap XmuLocateBitmapFile ( Screen *  screen,
_Xconst char *  name,
char *  srcname,
int  srcnamelen,
int widthp,
int heightp,
int xhotp,
int yhotp 
)

Definition at line 77 of file LocBitmap.c.

References XmuLocatePixmapFile().

Referenced by XmuCvtStringToBitmap().

00080 {
00081     return XmuLocatePixmapFile (screen, name, 
00082                                 (unsigned long) 1, (unsigned long) 0,
00083                                 (unsigned int) 1, srcname, srcnamelen,
00084                                 widthp, heightp, xhotp, yhotp);
00085 }

Here is the call graph for this function:

Here is the caller graph for this function:

Pixmap XmuLocatePixmapFile ( Screen *  screen,
_Xconst char *  name,
unsigned long  fore,
unsigned long  back,
unsigned int  depth,
char *  srcname,
int  srcnamelen,
int widthp,
int heightp,
int xhotp,
int yhotp 
)

Definition at line 92 of file LocBitmap.c.

References _XmuCCLookupDisplay(), BITMAPDIR, _XmuCvtCache::bitmapFilePath, data, dpy, filename, height, i, int, NULL, PATH_MAX, root, split_path_string(), _XmuCvtCache::string_to_bitmap, value, void(), width, XmuReadBitmapDataFromFile(), and XmuSnprintf().

Referenced by XmuLocateBitmapFile().

00097 {
00098 
00099 #ifndef BITMAPDIR
00100 #define BITMAPDIR "/usr/include/X11/bitmaps"
00101 #endif
00102 
00103     Display *dpy = DisplayOfScreen (screen);
00104     Window root = RootWindowOfScreen (screen);
00105     Bool try_plain_name = True;
00106     XmuCvtCache *cache = _XmuCCLookupDisplay (dpy);
00107     char **file_paths = (char **) NULL;
00108     char filename[PATH_MAX];
00109 #if 0
00110     char* bitmapdir = BITMAPDIR;
00111 #endif
00112     unsigned int width, height;
00113     int xhot, yhot;
00114     int i;
00115 
00116     /*
00117      * look in cache for bitmap path
00118      */
00119     if (cache) {
00120         if (!cache->string_to_bitmap.bitmapFilePath) {
00121             XrmName xrm_name[2];
00122             XrmClass xrm_class[2];
00123             XrmRepresentation rep_type;
00124             XrmValue value;
00125 
00126             xrm_name[0] = XrmPermStringToQuark ("bitmapFilePath");
00127             xrm_name[1] = NULLQUARK;
00128             xrm_class[0] = XrmPermStringToQuark ("BitmapFilePath");
00129             xrm_class[1] = NULLQUARK;
00130             if (!XrmGetDatabase(dpy)) {
00131                 /* what a hack; need to initialize it */
00132                 (void) XGetDefault (dpy, "", "");
00133             }
00134             if (XrmQGetResource (XrmGetDatabase(dpy), xrm_name, xrm_class, 
00135                                  &rep_type, &value) &&
00136                 rep_type == XrmPermStringToQuark("String")) {
00137                 cache->string_to_bitmap.bitmapFilePath = 
00138                   split_path_string (value.addr);
00139             }
00140         }
00141         file_paths = cache->string_to_bitmap.bitmapFilePath;
00142     }
00143 
00144     /*
00145      * Search order:
00146      *    1.  name if it begins with / or ./
00147      *    2.  "each prefix in file_paths"/name
00148      *    3.  BITMAPDIR/name
00149      *    4.  name if didn't begin with / or .
00150      */
00151 
00152     for (i = 1; i <= 4; i++) {
00153         char *fn = filename;
00154         Pixmap pixmap;
00155         unsigned char *data;
00156 
00157         switch (i) {
00158           case 1:
00159 #ifndef __UNIXOS2__
00160             if (!(name[0] == '/' || ((name[0] == '.') && name[1] == '/')))
00161 #else
00162             if (!(name[0] == '/' || (name[0] == '.' && name[1] == '/') ||
00163                   (isalpha(name[0]) && name[1] == ':')))
00164 #endif
00165               continue;
00166             fn = (char *) name;
00167             try_plain_name = False;
00168             break;
00169           case 2:
00170             if (file_paths && *file_paths) {
00171                 XmuSnprintf(filename, sizeof(filename),
00172                             "%s/%s", *file_paths, name);
00173                 file_paths++;
00174                 i--;
00175                 break;
00176             }
00177             continue;
00178           case 3:
00179             XmuSnprintf(filename, sizeof(filename), "%s/%s", BITMAPDIR, name);
00180             break;
00181           case 4:
00182             if (!try_plain_name) continue;
00183             fn = (char *) name;
00184             break;
00185         }
00186 
00187         data = NULL;
00188         pixmap = None;
00189 #ifdef __UNIXOS2__
00190         fn = (char*)__XOS2RedirRoot(fn);
00191 #endif
00192         if (XmuReadBitmapDataFromFile (fn, &width, &height, &data,
00193                                        &xhot, &yhot) == BitmapSuccess) {
00194             pixmap = XCreatePixmapFromBitmapData (dpy, root, (char *) data,
00195                                                   width, height,
00196                                                   fore, back, depth);
00197             XFree ((char *)data);
00198         }
00199 
00200         if (pixmap) {
00201             if (widthp) *widthp = (int)width;
00202             if (heightp) *heightp = (int)height;
00203             if (xhotp) *xhotp = xhot;
00204             if (yhotp) *yhotp = yhot;
00205             if (srcname && srcnamelen > 0) {
00206                 strncpy (srcname, fn, srcnamelen - 1);
00207                 srcname[srcnamelen - 1] = '\0';
00208             }
00209             return pixmap;
00210         }
00211     }
00212 
00213     return None;
00214 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Mar 4 16:04:12 2007 for Scilab [trunk] by  doxygen 1.5.1