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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
/*
* Permission is granted to distribute this software freely
* for any purpose.
*/
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include "FvwmIconMan.h"
#include "readconfig.h"
#include "x.h"
#include "xmanager.h"
#include "../../fvwm/module.h"
static int fd_width;
static volatile sig_atomic_t isTerminated = False;
static char *IM_VERSION = "1.3";
static char const rcsid[] =
"$Id: FvwmIconMan.c,v 1.1.1.1 2006/11/26 10:53:49 matthieu Exp $";
static RETSIGTYPE TerminateHandler(int);
char *copy_string (char **target, char *src)
{
int len = strlen (src);
ConsoleDebug (CORE, "copy_string: 1: 0x%lx\n", (unsigned long)*target);
if (*target)
Free (*target);
ConsoleDebug (CORE, "copy_string: 2\n");
*target = (char *)safemalloc ((len + 1) * sizeof (char));
strcpy (*target, src);
ConsoleDebug (CORE, "copy_string: 3\n");
return *target;
}
#ifdef TRACE_MEMUSE
long MemUsed = 0;
void Free (void *p)
{
struct malloc_header *head = (struct malloc_header *)p;
if (p != NULL) {
head--;
if (head->magic != MALLOC_MAGIC) {
fprintf (stderr, "Corrupted memory found in Free\n");
abort();
return;
}
if (head->len > MemUsed) {
fprintf (stderr, "Free block too big\n");
return;
}
MemUsed -= head->len;
free (head);
}
}
void PrintMemuse (void)
{
ConsoleDebug (CORE, "Memory used: %d\n", MemUsed);
}
#else
void Free (void *p)
{
if (p != NULL)
free (p);
}
void PrintMemuse (void)
{
}
#endif
static RETSIGTYPE
TerminateHandler(int sig)
{
isTerminated = True;
}
void ShutMeDown (int flag)
{
ConsoleDebug (CORE, "Bye Bye\n");
exit (flag);
}
void DeadPipe (int nothing)
{
ShutMeDown(0);
}
void SendFvwmPipe (char *message,unsigned long window)
{
char *hold,*temp,*temp_msg;
hold=message;
while(1) {
temp=strchr(hold,',');
if (temp!=NULL) {
temp_msg= (char *)safemalloc(temp-hold+1);
strncpy(temp_msg,hold,(temp-hold));
temp_msg[(temp-hold)]='\0';
hold=temp+1;
} else temp_msg=hold;
SendText(Fvwm_fd, temp_msg, window);
if(temp_msg!=hold) Free(temp_msg);
else break;
}
}
static void main_loop (void)
{
fd_set readset, saveset;
FD_ZERO (&saveset);
FD_SET (Fvwm_fd[1], &saveset);
FD_SET (x_fd, &saveset);
while( !isTerminated ) {
/* Check the pipes for anything to read, and block if
* there is nothing there yet ...
*/
readset = saveset;
if (select(fd_width,&readset,NULL,NULL,NULL) < 0) {
ConsoleMessage ("Internal error with select: errno=%d\n",errno);
}
else {
if (FD_ISSET (x_fd, &readset) || XPending (theDisplay)) {
xevent_loop();
}
if (FD_ISSET(Fvwm_fd[1],&readset)) {
ReadFvwmPipe();
}
}
} /* while */
}
int main (int argc, char **argv)
{
char *temp, *s;
int i;
#ifdef ELECTRIC_FENCE
extern int EF_PROTECT_BELOW, EF_PROTECT_FREE;
EF_PROTECT_BELOW = 1;
EF_PROTECT_FREE = 1;
#endif
#ifdef DEBUG_ATTACH
{
char buf[256];
sprintf (buf, "%d", getpid());
if (fork() == 0) {
chdir ("/home/bradym/src/FvwmIconMan");
execl ("/usr/local/bin/ddd", "/usr/local/bin/ddd", "FvwmIconMan",
buf, NULL);
}
else {
int i, done = 0;
for (i = 0; i < (1 << 27) && !done; i++) ;
}
}
#endif
OpenConsole(OUTPUT_FILE);
#if 0
ConsoleMessage ("PID = %d\n", getpid());
ConsoleMessage ("Waiting for GDB to attach\n");
sleep (10);
#endif
init_globals();
init_winlists();
temp = argv[0];
s = strrchr (argv[0], '/');
if (s != NULL)
temp = s + 1;
if((argc != 6) && (argc != 7)) {
fprintf(stderr,"%s Version %s should only be executed by fvwm!\n",Module,
IM_VERSION);
ShutMeDown (1);
}
if (argc == 7 && !strcasecmp (argv[6], "Transient"))
globals.transient = 1;
Fvwm_fd[0] = atoi(argv[1]);
Fvwm_fd[1] = atoi(argv[2]);
init_display();
init_boxes();
#ifdef HAVE_SIGACTION
{
struct sigaction sigact;
sigemptyset(&sigact.sa_mask);
# ifdef SA_INTERRUPT
sigact.sa_flags = SA_INTERRUPT;
# else
sigact.sa_flags = 0;
# endif
sigact.sa_handler = TerminateHandler;
sigaction(SIGPIPE, &sigact, NULL);
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGHUP, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
}
#else
/* We don't have sigaction(), so fall back to less robust methods. */
signal(SIGPIPE, TerminateHandler);
signal(SIGINT, TerminateHandler);
signal(SIGHUP, TerminateHandler);
signal(SIGTERM, TerminateHandler);
signal(SIGQUIT, TerminateHandler);
#endif
read_in_resources (argv[3]);
for (i = 0; i < globals.num_managers; i++) {
X_init_manager (i);
}
assert (globals.managers);
fd_width = GetFdWidth();
SetMessageMask(Fvwm_fd,M_CONFIGURE_WINDOW | M_RES_CLASS | M_RES_NAME |
M_ADD_WINDOW | M_DESTROY_WINDOW | M_ICON_NAME |
M_DEICONIFY | M_ICONIFY | M_END_WINDOWLIST |
M_NEW_DESK | M_NEW_PAGE | M_FOCUS_CHANGE | M_WINDOW_NAME |
#ifdef MINI_ICONS
M_MINI_ICON |
#endif
M_STRING);
SendInfo (Fvwm_fd, "Send_WindowList", 0);
main_loop();
return 0;
}
|