home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / xsokoban-31 / resources.c < prev    next >
C/C++ Source or Header  |  1994-03-05  |  2KB  |  84 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "externs.h"
  5. #include "globals.h"
  6. #include "defaults.h"
  7.  
  8. /* rewritten slightly from the xantfarm code by Jef Poskanzer */
  9.  
  10. /* get a resource from the specified db.  This helps support the -display
  11.  * code, but could be used to get a resource that should only be specified
  12.  * in a given place (ie either only command line, or only Xresource db)
  13.  */
  14. char *GetDatabaseResource(XrmDatabase db, char *res)
  15. {
  16.   char name[500];
  17.   char class[500];
  18.   char *type;
  19.   XrmValue value;
  20.  
  21.   (void)sprintf(name, "%s.%s", progname, res);
  22.   (void)sprintf(class, "%s.%s", CLASSNAME, res);
  23.  
  24.   if(XrmGetResource(db, name, class, &type, &value) == True)
  25.     if(strcmp(type, "String") == 0)
  26.       return (char *)value.addr;
  27.   return (char *)0;
  28. }
  29.  
  30. /* just calls the above routine with the general combined db */
  31. char *GetResource(char *res)
  32. {
  33.   return GetDatabaseResource(rdb, res);
  34. }
  35.  
  36. /* returns the color pixel for the given resource */
  37. Boolean GetColorResource(char *res, unsigned long *cP)
  38. {
  39.   XColor color;
  40.   char *rval = GetResource(res);
  41.  
  42.   if(rval == (char *)0)
  43.     return _false_;
  44.   if(XParseColor(dpy, cmap, rval, &color) != True)
  45.     return _false_;
  46.   if(XAllocColor(dpy, cmap, &color) != True)
  47.     return _false_;
  48.   *cP = color.pixel;
  49.   return _true_;
  50. }
  51.  
  52. XFontStruct *GetFontResource(char *font)
  53. {
  54.     char *rval = GetResource(font);
  55.     XFontStruct *finfo;
  56.     if (!rval) rval = DEF_FONT;
  57.     finfo = XLoadQueryFont(dpy, rval);
  58.     if (!finfo) {
  59.     finfo = XLoadQueryFont(dpy, "fixed");
  60.     }
  61.     return finfo;
  62. }
  63.  
  64. char *boolopts[] = {
  65.   "true",
  66.   "True",
  67.   "on",
  68.   "On",
  69.   "yes",
  70.   "Yes",
  71.   "1"
  72. };
  73.  
  74. /* convert a string to the 'boolean' type (I defined my own, thanks) */
  75. Boolean StringToBoolean(char *str)
  76. {
  77.   int nboolopts = sizeof(boolopts)/sizeof(*boolopts), i;
  78.  
  79.   for(i = 0; i < nboolopts; i++)
  80.     if(strcmp(str, boolopts[i]) == 0)
  81.       return _true_;
  82.   return _false_;
  83. }
  84.