Debian Codegraph @

gui/GraphLib/libsrc/uimxR5/src/XpmRdFToI.c

raw
1 /* Copyright 1990,91 GROUPE BULL -- See licence conditions in file COPYRIGHT */
2 /*****************************************************************************\
3 * XpmRdFToI.c: *
4 * *
5 * XPM library *
6 * Parse an XPM file and create the image and possibly its mask *
7 * *
8 * Developed by Arnaud Le Hors *
9
10 .VERSION
11 090818 last modif
12
13 \*****************************************************************************/
14
15 #include "xpmP.h"
16
17 xpmDataType xpmDataTypes[] =
18 {
19 {"", "!", "\n", '\0', '\n', "", "", "", ""}, /* Natural type */
20
21 {"C", "/*", "*/", '"', '"', ",\n", "static char *", "[] = {\n", "};\n"},
22
23 {"Lisp", ";", "\n", '"', '"', "\n", "(setq ", " '(\n", "))\n"},
24
25 #ifdef VMS
26 NULL
27 #else
28 {(char *)0, (char *)0, (char *)0, '\0', '\0', (char *)0, (char *)0,
29 (char *)0, (char *)0}
30 /* was: NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL */
31 #endif
32 };
33
34 int
35 XpmReadFileToImage(display, filename, image_return,
36 shapeimage_return, attributes)
37 Display *display;
38 char *filename;
39 XImage **image_return;
40 XImage **shapeimage_return;
41 XpmAttributes *attributes;
42 {
43 xpmData mdata;
44 char buf[BUFSIZ];
45 int l, n = 0;
46 int ErrorStatus;
47 xpmInternAttrib attrib;
48
49 /*
50 * initialize return values
51 */
52 if (image_return)
53 *image_return = NULL;
54 if (shapeimage_return)
55 *shapeimage_return = NULL;
56
57 if ((ErrorStatus = xpmReadFile(filename, &mdata)) != XpmSuccess)
58 return (ErrorStatus);
59
60 xpmInitInternAttrib(&attrib);
61
62 /*
63 * parse the header file
64 */
65 mdata.Bos = '\0';
66 mdata.Eos = '\n';
67 mdata.Bcmt = mdata.Ecmt = NULL;
68 xpmNextWord(&mdata, buf); /* skip the first word */
69 l = xpmNextWord(&mdata, buf); /* then get the second word */
70 if ((l == 3 && !strncmp("XPM", buf, 3)) ||
71 (l == 4 && !strncmp("XPM2", buf, 4))) {
72 if (l == 3)
73 n = 1; /* handle XPM as XPM2 C */
74 else {
75 l = xpmNextWord(&mdata, buf); /* get the type key word */
76
77 /*
78 * get infos about this type
79 */
80 while (xpmDataTypes[n].type
81 && strncmp(xpmDataTypes[n].type, buf, l))
82 n++;
83 }
84 if (xpmDataTypes[n].type) {
85 if (n == 0) { /* natural type */
86 mdata.Bcmt = xpmDataTypes[n].Bcmt;
87 mdata.Ecmt = xpmDataTypes[n].Ecmt;
88 xpmNextString(&mdata); /* skip the end of headerline */
89 mdata.Bos = xpmDataTypes[n].Bos;
90 } else {
91 xpmNextString(&mdata); /* skip the end of headerline */
92 mdata.Bcmt = xpmDataTypes[n].Bcmt;
93 mdata.Ecmt = xpmDataTypes[n].Ecmt;
94 mdata.Bos = xpmDataTypes[n].Bos;
95 mdata.Eos = '\0';
96 xpmNextString(&mdata); /* skip the assignment line */
97 }
98 mdata.Eos = xpmDataTypes[n].Eos;
99
100 ErrorStatus = xpmParseData(&mdata, &attrib, attributes);
101
102 if (ErrorStatus == XpmSuccess)
103 ErrorStatus = xpmCreateImage(display, &attrib, image_return,
104 shapeimage_return, attributes);
105 } else
106 ErrorStatus = XpmFileInvalid;
107 } else
108 ErrorStatus = XpmFileInvalid;
109
110 if (ErrorStatus >= 0)
111 xpmSetAttributes(&attrib, attributes);
112 else if (attributes)
113 XpmFreeAttributes(attributes);
114
115 xpmFreeInternAttrib(&attrib);
116 XpmDataClose(&mdata);
117
118 return (ErrorStatus);
119 }