File: images.c

package info (click to toggle)
fookb 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 568 kB
  • sloc: sh: 1,241; ansic: 416; makefile: 15
file content (181 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * images.c
 *
 * (c) 1998-2004 Alexey Vyskubov <alexey@mawhrin.net>
 */

#include <stdio.h>		/* puts() */
#include <stdlib.h>
#include <string.h>

/* Xpm fun */
#include <X11/xpm.h>

//#include "fookb.h"
#include "params.h"
#include "images.h"

/* Let us make lint happy! */
#define lputs(x) (void)(puts(x))

static int w = 0;
static int h = 0;

static XImage *stupid_picture[5];	/* Icons for fookb */

int get_width() {
	return w;
}

int get_height() {
	return h;
}

static int get_one_image(char *name, int index, Display *dpy)
{
	int foo;

	foo = XpmReadFileToImage(dpy, name, &stupid_picture[index],
				 NULL, NULL);

	if (foo < 0)
		return foo;

	if (0 == w) {
		w = stupid_picture[index]->width;
		if (0 == w) {
			lputs("FATAL: Icon1 has zero width!");
			exit(EXIT_FAILURE);
		}
		if (w > 64) {
			lputs("Warning: Icon width is more than 64. Strange things may happen if using Window Maker.");
		}
	}

	if (0 == h) {
		h = stupid_picture[index]->height;
		if (0 == h) {
			lputs("FATAL: Icon1 had zero height!");
			exit(EXIT_FAILURE);
		}
		if (h > 64) {
			lputs("Warning: Icon height is more than 64. Strange things may happen if using Window Maker.");
		}
	}

	if (w != stupid_picture[index]->width) {
		lputs("FATAL: Not all icons are of the same width!");
		exit(EXIT_FAILURE);
	}

	if (h != stupid_picture[index]->height) {
		lputs("FATAL: Not all iconse are of the same height!");
		exit(EXIT_FAILURE);
	}
	return (foo);
}

void read_images(Display *dpy)
{
	int i;
	int res;
	int status = 0;

	for (i = 0; i < 5; i++) {

		switch (i) {
		case 0:
			res = get_one_image(read_param("Icon1"), 0, dpy);
			break;
		case 1:
			res = get_one_image(read_param("Icon2"), 1, dpy);
			break;
		case 2:
			res = get_one_image(read_param("Icon3"), 2, dpy);
			break;
		case 3:
			res = get_one_image(read_param("Icon4"), 3, dpy);
			break;
		default:
			res = get_one_image(read_param("IconBoom"), 4, dpy);
			break;
		}

		switch (res) {
		case XpmOpenFailed:
			lputs("Xpm file open failed:");
			status = 1 << 5;
			break;
		case XpmFileInvalid:
			lputs("Xpm file is invalid:");
			status = 1 << 6;
			break;
		case XpmNoMemory:
			lputs("No memory for open xpm file:");
			status = 1 << 7;
			break;
		default:
			break;
		}

		if (!(status == 0)) {
			status += 1 << i;
			switch (i) {
			case 0:
				lputs(read_param("Icon1"));
				break;
			case 1:
				lputs(read_param("Icon2"));
				break;
			case 2:
				lputs(read_param("Icon3"));
				break;
			case 3:
				lputs(read_param("Icon4"));
				break;
			case 4:
				lputs(read_param("IconBoom"));
				break;
			default:
				lputs("UNKNOWN ERROR! PLEASE REPORT!!!");
				exit(-2);
			}
			exit(status);
		}
	}

}

void update_window(Drawable win, GC gc, unsigned int whattodo, Display *dpy)
{
	int err;

	err = XPutImage(dpy, win, gc, stupid_picture[whattodo],
			0, 0, 0, 0, w, h);

	if (0 == err) return;

	switch (err) {
		case BadDrawable:
			lputs("Fatal error, XPutImage returns BadDrawable. "
					"Please report!");
			break;
		case BadGC:
			lputs("Fatal error, XPutImage returns BadGC. "
					"Please report!");
			break;
		case BadMatch:
			lputs("Fatal error, XPutImage returns BadMatch. "
					"Please report!");
			break;
		case BadValue:
			lputs("Fatal error, XPutImage returns BadValue. "
					"Please report!");
			break;
		default:
			lputs("Fatal error, XPutImage returns unknown error. "
					"Please report, but probably "
					"it is a bug in X.");
			break;
	}
}