source: trunk/athena/lib/Xj/StrToPixmap.c @ 12350

Revision 12350, 2.0 KB checked in by ghudson, 26 years ago (diff)
Some RCS ID cleanup: delete $Log$ and replace other RCS keywords with $Id$.
Line 
1/*
2 * $Id: StrToPixmap.c,v 1.2 1999-01-22 23:17:00 ghudson Exp $
3 *
4 * Copyright 1990, 1991 by the Massachusetts Institute of Technology.
5 *
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
8 *
9 */
10
11#if  (!defined(lint))  &&  (!defined(SABER))
12static char *rcsid =
13"$Id: StrToPixmap.c,v 1.2 1999-01-22 23:17:00 ghudson Exp $";
14#endif
15
16#include "mit-copyright.h"
17#include "Jets.h"
18
19#ifndef BITMAPDIR
20#define BITMAPDIR "/usr/lib/X11/bitmaps"
21#endif
22static char *bitmapdir = BITMAPDIR;
23
24/*
25 * String to Pixmap conversion
26 */
27int StrToPixmap(display, window, where, resource, type, address)
28     Display *display;
29     Window window;
30     caddr_t where;
31     XjResource *resource;
32     char *type;
33     caddr_t address;
34{
35  XjPixmap *newPixmap = NULL;
36  XjPixmap p;
37  char errtext[100];
38  char *error = "error reading bitmap %s%s";
39  char *no_mem = ", no memory";
40  char *ptr = (char *) address;
41  int status = 1;
42
43  if (ptr == NULL)
44    {
45      *((XjPixmap **)((char *)where + resource->resource_offset)) = NULL;
46      return 0;
47    }
48
49  switch(XReadBitmapFile(display, window,
50                         ptr, &p.width, &p.height,
51                         &p.pixmap, &p.hot_x, &p.hot_y))
52    {
53    case BitmapOpenFailed:
54    case BitmapFileInvalid:
55      if (ptr[0] != '/')
56        {
57          char *new_ptr;
58          int ret;
59
60          new_ptr = (char *) XjMalloc(strlen(ptr)
61                                      + strlen(bitmapdir) + 2);
62          sprintf(new_ptr, "%s/%s", bitmapdir, ptr);
63          ret = StrToPixmap(display, window, where, resource, type, new_ptr);
64          XjFree(new_ptr);
65          if (!ret)
66            return 0;
67        }
68      sprintf(errtext, error, ptr, "");
69      XjWarning(errtext);
70      break;
71
72    case BitmapNoMemory:
73      sprintf(errtext, error, ptr, no_mem);
74      XjWarning(errtext);
75      break;
76
77    case BitmapSuccess:
78      newPixmap = (XjPixmap *)XjMalloc((unsigned) sizeof(XjPixmap));
79      memcpy(newPixmap, &p, sizeof(XjPixmap));
80      status = 0;
81      break;
82    }
83
84  *((XjPixmap **)((char *)where + resource->resource_offset)) = newPixmap;
85
86  return status;
87}
Note: See TracBrowser for help on using the repository browser.