wmbiff: Fix global notification
[dockapps.git] / wmbiff-0.4.27 / wmbiff / wmbiff.c
blobcc6b947fc06e64b6a2f7180b61b073f7b00e1b11
1 /* $Id: wmbiff.c,v 1.70 2005/10/07 03:07:58 bluehal Exp $ */
3 // typedef int gcry_error_t;
5 #ifdef HAVE_CONFIG_H
6 #include <config.h>
7 #endif
9 #include <time.h>
10 #include <ctype.h>
12 #ifdef HAVE_POLL
13 #include <poll.h>
14 #else
15 #include <sys/time.h>
16 #endif
18 #include <sys/wait.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <signal.h>
23 #include <X11/Xlib.h>
24 #include <X11/xpm.h>
25 #include <X11/cursorfont.h>
26 #include <X11/keysym.h>
28 #include <errno.h>
29 #include <string.h>
31 #include "../wmgeneral/wmgeneral.h"
32 #include "../wmgeneral/misc.h"
34 #include "Client.h"
35 #include "charutil.h"
36 #include "MessageList.h"
38 #ifdef USE_DMALLOC
39 #include <dmalloc.h>
40 #endif
43 #include "wmbiff-master-led.xpm"
44 static char wmbiff_mask_bits[64 * 64];
45 static const int wmbiff_mask_width = 64;
46 // const int wmbiff_mask_height = 64;
48 #define CHAR_WIDTH 5
49 #define CHAR_HEIGHT 7
51 #define BLINK_TIMES 8
52 #define DEFAULT_SLEEP_INTERVAL 5000
53 #define BLINK_SLEEP_INTERVAL 200
54 #define DEFAULT_LOOP 5
56 #define MAX_NUM_MAILBOXES 40
57 static mbox_t mbox[MAX_NUM_MAILBOXES];
59 /* this is the normal pixmap. */
60 static const char *skin_filename = "wmbiff-master-led.xpm";
61 /* global notify action taken (if globalnotify option is set) */
62 /*@null@*/
63 static const char *globalnotify = NULL;
64 /* path to search for pixmaps */
65 /* /usr/share/wmbiff should have the default pixmap. */
66 /* /usr/local/share/wmbiff if compiled locally. */
67 /* / is there in case a user wants to specify a complete path */
68 /* . is there for development. */
69 static const char *skin_search_path = DEFAULT_SKIN_PATH;
70 /* for gnutls */
71 /*@null@*/
72 const char *certificate_filename = NULL;
74 /* it could be argued that a better default exists. */
75 #define DEFAULT_FONT "-*-fixed-*-r-*-*-10-*-*-*-*-*-*-*"
76 /*@null@*/
77 static const char *font = NULL;
79 int debug_default = DEBUG_ERROR;
81 /* color from wmbiff's xpm, down to 24 bits. */
82 const char *foreground = "#21B3AF"; /* foreground cyan */
83 const char *background = "#202020"; /* background gray */
84 static const char *highlight = "yellow";
85 int SkipCertificateCheck = 0;
86 int Relax = 0; /* be not paranoid */
87 static int notWithdrawn = 0;
89 static unsigned int num_mailboxes = 1;
90 static const int x_origin = 5;
91 static const int y_origin = 5;
92 static int forever = 1; /* keep running. */
94 extern Window win;
95 extern Window iconwin;
97 Cursor busy_cursor, ready_cursor;
99 static __inline /*@out@ */ void *
100 malloc_ordie(size_t len)
102 void *ret = malloc(len);
103 if (ret == NULL) {
104 fprintf(stderr, "unable to allocate %d bytes\n", (int) len);
105 abort();
107 return (ret);
110 /* where vertically the mailbox sits for blitting characters. */
111 static int mbox_y(unsigned int mboxnum)
113 return ((11 * mboxnum) + y_origin);
116 /* special shortcuts for longer shell client commands */
117 static int gicuCreate( /*@notnull@ */ Pop3 pc, const char *path)
119 char buf[255];
120 if (isdigit(path[5])) {
121 sprintf(buf,
122 "shell:::echo `gnomeicu-client -u%s msgcount` new",
123 path + 5);
124 } else {
125 sprintf(buf, "shell:::echo `gnomeicu-client msgcount` new");
127 return (shellCreate(pc, buf));
130 static int fingerCreate( /*@notnull@ */ Pop3 pc, const char *path)
132 char buf[255];
133 sprintf(buf, "shell:::finger -lm %s | "
134 "perl -ne '(/^new mail/i && print \"new\");' "
135 "-e '(/^mail last read/i && print \"old\");' "
136 "-e '(/^no( unread)? mail/i && print \"no\");'", path + 7);
137 return (shellCreate(pc, buf));
140 /* Read a line from a file to obtain a pair setting=value
141 skips # and leading spaces
142 NOTE: if setting finish with 0, 1, 2, 3 or 4 last char are deleted and
143 index takes its value... if not index will get -1
144 Returns -1 if no setting=value
146 static int ReadLine(FILE * fp, /*@out@ */ char *setting,
147 /*@out@ */ char *value, /*@out@ */ int *mbox_index)
149 char buf[BUF_SIZE];
150 char *p, *q;
151 int len;
153 *setting = '\0';
154 *value = '\0';
155 *mbox_index = -1;
157 if (!fp || feof(fp))
158 return -1;
160 if (!fgets(buf, BUF_SIZE - 1, fp))
161 return -1;
163 len = strlen(buf);
165 if (buf[len - 1] == '\n') {
166 buf[len - 1] = '\0'; /* strip linefeed */
169 StripComment(buf);
171 if (!(p = strtok(buf, "=")))
172 return -1;
173 if (!(q = strtok(NULL, "\n")))
174 return -1;
176 /* Chg - Mark Hurley
177 * Date: May 8, 2001
178 * Removed for loop (which removed leading spaces)
179 * Leading & Trailing spaces need to be removed
180 * to Fix Debian bug #95849
182 FullTrim(p);
183 FullTrim(q);
185 /* strcpy(setting, p); nspring replaced with sscanf dec 2002 */
186 strcpy(value, q);
188 if (sscanf(p, "%[_a-z.]%d", setting, mbox_index) == 2) {
189 /* mailbox-specific configuration, ends in a digit */
190 if (*mbox_index < 0 || *mbox_index >= MAX_NUM_MAILBOXES) {
191 DMA(DEBUG_ERROR, "invalid mailbox number %d\n", *mbox_index);
192 exit(EXIT_FAILURE);
194 } else if (sscanf(p, "%[a-z]", setting) == 1) {
195 /* global configuration, all text. */
196 *mbox_index = -1;
197 } else {
198 /* we found an uncommented line that has an equals,
199 but is non-alphabetic. */
200 DMA(DEBUG_INFO, "unparsed setting %s\n", p);
201 return -1;
204 DMA(DEBUG_INFO, "@%s.%d=%s@\n", setting, *mbox_index, value);
205 return 1;
208 struct path_demultiplexer {
209 const char *id; /* followed by a colon */
210 int (*creator) ( /*@notnull@ */ Pop3 pc, const char *path);
213 static struct path_demultiplexer paths[] = {
214 {"pop3:", pop3Create},
215 {"pop3s:", pop3Create},
216 {"shell:", shellCreate},
217 {"gicu:", gicuCreate},
218 {"licq:", licqCreate},
219 {"finger:", fingerCreate},
220 {"imap:", imap4Create},
221 {"imaps:", imap4Create},
222 {"sslimap:", imap4Create},
223 {"maildir:", maildirCreate},
224 {"mbox:", mboxCreate},
225 {NULL, NULL}
229 static void parse_mbox_path(unsigned int item)
231 int i;
232 /* find the creator */
233 for (i = 0;
234 paths[i].id != NULL
235 && strncasecmp(mbox[item].path, paths[i].id, strlen(paths[i].id));
236 i++);
237 /* if found, execute */
238 if (paths[i].id != NULL) {
239 if (paths[i].creator((&mbox[item]), mbox[item].path) != 0) {
240 DMA(DEBUG_ERROR, "creator for mailbox %u returned failure\n",
241 item);
243 } else {
244 /* default are mbox */
245 mboxCreate((&mbox[item]), mbox[item].path);
249 static int Read_Config_File(char *filename, int *loopinterval)
251 FILE *fp;
252 char setting[BUF_SMALL], value[BUF_SIZE];
253 int mbox_index;
254 unsigned int i;
256 if (!(fp = fopen(filename, "r"))) {
257 DMA(DEBUG_ERROR, "Unable to open %s, no settings read: %s\n",
258 filename, strerror(errno));
259 return 0;
261 while (!feof(fp)) {
262 /* skanky: -1 can represent an unparsed line
263 or an error */
264 if (ReadLine(fp, setting, value, &mbox_index) == -1)
265 continue;
267 /* settings that can be global go here. */
268 if (!strcmp(setting, "interval")) {
269 *loopinterval = atoi(value);
270 continue;
271 } else if (!strcmp(setting, "askpass")) {
272 const char *askpass = strdup_ordie(value);
273 if (mbox_index == -1) {
274 DMA(DEBUG_INFO, "setting all to askpass %s\n", askpass);
275 for (i = 0; i < MAX_NUM_MAILBOXES; i++)
276 mbox[i].askpass = askpass;
277 } else {
278 mbox[mbox_index].askpass = askpass;
280 continue;
281 } else if (!strcmp(setting, "skinfile")) {
282 skin_filename = strdup_ordie(value);
283 continue;
284 } else if (!strcmp(setting, "certfile")) { /* not yet supported */
285 certificate_filename = strdup_ordie(value);
286 continue;
287 } else if (!strcmp(setting, "globalnotify")) {
288 globalnotify = strdup_ordie(value);
289 continue;
290 } else if (mbox_index == -1) {
291 DMA(DEBUG_INFO, "Unknown global setting '%s'\n", setting);
292 continue; /* Didn't read any setting.[0-5] value */
295 if (mbox_index >= MAX_NUM_MAILBOXES) {
296 DMA(DEBUG_ERROR, "Don't have %d mailboxes.\n", mbox_index);
297 continue;
300 if (1U + mbox_index > num_mailboxes
301 && mbox_index + 1 <= MAX_NUM_MAILBOXES) {
302 num_mailboxes = 1U + mbox_index;
305 /* now only local settings */
306 if (!strcmp(setting, "label.")) {
307 if (strlen(value) + 1 > BUF_SMALL) {
308 DMA(DEBUG_ERROR,
309 "Mailbox %i label string '%s' is too long.\n",
310 mbox_index, value);
311 continue;
312 } else {
313 strncpy(mbox[mbox_index].label, value, BUF_SMALL - 1);
315 } else if (!strcmp(setting, "path.")) {
316 if (strlen(value) + 1 > BUF_BIG) {
317 DMA(DEBUG_ERROR,
318 "Mailbox %i path string '%s' is too long.\n",
319 mbox_index, value);
320 continue;
321 } else {
322 strncpy(mbox[mbox_index].path, value, BUF_BIG - 1);
324 } else if (!strcmp(setting, "notify.")) {
325 if (strlen(value) + 1 > BUF_BIG) {
326 DMA(DEBUG_ERROR,
327 "Mailbox %i notify string '%s' is too long.\n",
328 mbox_index, value);
329 continue;
330 } else {
331 strncpy(mbox[mbox_index].notify, value, BUF_BIG - 1);
333 } else if (!strcmp(setting, "action.")) {
334 if (strlen(value) + 1 > BUF_BIG) {
335 DMA(DEBUG_ERROR,
336 "Mailbox %i action string '%s' is too long.\n",
337 mbox_index, value);
338 continue;
339 } else {
340 strncpy(mbox[mbox_index].action, value, BUF_BIG - 1);
342 } else if (!strcmp(setting, "action_disconnected.")) {
343 if (strlen(value) + 1 > BUF_BIG) {
344 DMA(DEBUG_ERROR,
345 "Mailbox %i action_disconnected string '%s' is too long.\n",
346 mbox_index, value);
347 continue;
348 } else {
349 strncpy(mbox[mbox_index].actiondc, value, BUF_BIG - 1);
351 } else if (!strcmp(setting, "action_new_mail.")) {
352 if (strlen(value) + 1 > BUF_BIG) {
353 DMA(DEBUG_ERROR,
354 "Mailbox %i action_new_mail string '%s' is too long.\n",
355 mbox_index, value);
356 continue;
357 } else {
358 strncpy(mbox[mbox_index].actionnew, value, BUF_BIG - 1);
360 } else if (!strcmp(setting, "action_no_new_mail.")) {
361 if (strlen(value) + 1 > BUF_BIG) {
362 DMA(DEBUG_ERROR,
363 "Mailbox %i action_no_new_mail string '%s' is too long.\n",
364 mbox_index, value);
365 continue;
366 } else {
367 strncpy(mbox[mbox_index].actionnonew, value, BUF_BIG - 1);
369 } else if (!strcmp(setting, "interval.")) {
370 mbox[mbox_index].loopinterval = atoi(value);
371 } else if (!strcmp(setting, "buttontwo.")) {
372 if (strlen(value) + 1 > BUF_BIG) {
373 DMA(DEBUG_ERROR,
374 "Mailbox %i buttontwo string '%s' is too long.\n",
375 mbox_index, value);
376 continue;
377 } else {
378 strncpy(mbox[mbox_index].button2, value, BUF_BIG - 1);
380 } else if (!strcmp(setting, "fetchcmd.")) {
381 if (strlen(value) + 1 > BUF_BIG) {
382 DMA(DEBUG_ERROR,
383 "Mailbox %i fetchcmd string '%s' is too long.\n",
384 mbox_index, value);
385 continue;
386 } else {
387 strncpy(mbox[mbox_index].fetchcmd, value, BUF_BIG - 1);
389 } else if (!strcmp(setting, "fetchinterval.")) {
390 mbox[mbox_index].fetchinterval = atoi(value);
391 } else if (!strcmp(setting, "debug.")) {
392 int debug_value = debug_default;
393 if (strcasecmp(value, "all") == 0) {
394 debug_value = DEBUG_ALL;
396 /* could disable debugging, but I want the command
397 line argument to provide all information
398 possible. */
399 mbox[mbox_index].debug = debug_value;
400 } else {
401 DMA(DEBUG_INFO, "Unknown setting '%s'\n", setting);
404 (void) fclose(fp);
405 for (i = 0; i < num_mailboxes; i++)
406 if (mbox[i].label[0] != '\0')
407 parse_mbox_path(i);
408 return 1;
412 static void init_biff(char *config_file)
414 #ifdef HAVE_GCRYPT_H
415 gcry_error_t rc;
416 #endif
417 int loopinterval = DEFAULT_LOOP;
418 unsigned int i;
420 for (i = 0; i < MAX_NUM_MAILBOXES; i++) {
421 memset(mbox[i].label, 0, BUF_SMALL);
422 memset(mbox[i].path, 0, BUF_BIG);
423 memset(mbox[i].notify, 0, BUF_BIG);
424 memset(mbox[i].action, 0, BUF_BIG);
425 memset(mbox[i].actiondc, 0, BUF_BIG);
426 memset(mbox[i].actionnew, 0, BUF_BIG);
427 memset(mbox[i].actionnonew, 0, BUF_BIG);
428 memset(mbox[i].button2, 0, BUF_BIG);
429 memset(mbox[i].fetchcmd, 0, BUF_BIG);
430 mbox[i].loopinterval = 0;
431 mbox[i].getHeaders = NULL;
432 mbox[i].releaseHeaders = NULL;
433 mbox[i].debug = debug_default;
434 mbox[i].askpass = DEFAULT_ASKPASS;
437 #ifdef HAVE_GCRYPT_H
438 /* gcrypt is a little strange, in that it doesn't
439 * seem to initialize its memory pool by itself.
440 * I believe we *expect* "Warning: using insecure memory!"
442 /* gcryctl_disable_secmem gets called before check_version -- in a message on
443 gcrypt-devel august 17 2004. */
444 if ((rc = gcry_control(GCRYCTL_DISABLE_SECMEM, 0)) != 0) {
445 DMA(DEBUG_ERROR,
446 "Error: tried to disable gcrypt warning and failed: %d\n"
447 " Message: %s\n" " libgcrypt version: %s\n", rc,
448 gcry_strerror(rc), gcry_check_version(NULL));
451 /* recently made a requirement, section 2.4 of gcrypt manual */
452 if (gcry_check_version("1.1.42") == NULL) {
453 DMA(DEBUG_ERROR, "Error: incompatible gcrypt version.\n");
457 if ((rc = gcry_control(GCRYCTL_INIT_SECMEM, 16384, 0)) != 0) {
458 DMA(DEBUG_ERROR,
459 "Error: gcry_control() to initialize secure memory returned non-zero: %d\n"
460 " Message: %s\n"
461 " libgcrypt version: %s\n"
462 " recovering: will fail later if using CRAM-MD5 or APOP authentication.\n",
463 rc, gcry_strerror(rc), gcry_check_version(NULL));
466 #endif
468 DMA(DEBUG_INFO, "config_file = %s.\n", config_file);
469 if (!Read_Config_File(config_file, &loopinterval)) {
470 char *m;
471 /* setup defaults if there's no config */
472 if ((m = getenv("MAIL")) != NULL) {
473 /* we are using MAIL environment var. type mbox */
474 if (strlen(m) + 1 > BUF_BIG) {
475 DMA(DEBUG_ERROR,
476 "MAIL environment var '%s' is too long.\n", m);
477 } else {
478 DMA(DEBUG_INFO, "Using MAIL environment var '%s'.\n", m);
479 strncpy(mbox[0].path, m, BUF_BIG - 1);
481 } else if ((m = getenv("USER")) != NULL) {
482 /* we will use the USER env var to find an mbox name */
483 if (strlen(m) + 10 + 1 > BUF_BIG) {
484 DMA(DEBUG_ERROR,
485 "USER environment var '%s' is too long.\n", m);
486 } else {
487 DMA(DEBUG_INFO, "Using /var/mail/%s.\n", m);
488 strcpy(mbox[0].path, "/var/mail/");
489 strncat(mbox[0].path, m, BUF_BIG - 1 - 10);
490 if (mbox[0].path[9] != '/') {
491 DMA(DEBUG_ERROR,
492 "Unexpected failure to construct /var/mail/username, please "
493 "report this with your operating system info and the version of wmbiff.");
496 } else {
497 DMA(DEBUG_ERROR, "Cannot open config file '%s' nor use the "
498 "MAIL environment var.\n", config_file);
499 exit(EXIT_FAILURE);
501 if (!exists(mbox[0].path)) {
502 DMA(DEBUG_ERROR, "Cannot open config file '%s', and the "
503 "default %s doesn't exist.\n", config_file, mbox[0].path);
504 exit(EXIT_FAILURE);
506 strcpy(mbox[0].label, "Spool");
507 mboxCreate((&mbox[0]), mbox[0].path);
510 /* Make labels look right */
511 for (i = 0; i < num_mailboxes; i++) {
512 if (mbox[i].label[0] != '\0') {
513 /* append a colon, but skip if we're using fonts. */
514 if (font == NULL) {
515 int j = strlen(mbox[i].label);
516 if (j < 5) {
517 memset(mbox[i].label + j, ' ', 5 - j);
519 mbox[i].label[5] = ':';
521 /* but always end after 5 characters */
522 mbox[i].label[6] = '\0';
523 /* set global loopinterval to boxes with 0 loop */
524 if (!mbox[i].loopinterval) {
525 mbox[i].loopinterval = loopinterval;
531 static char **LoadXPM(const char *pixmap_filename)
533 char **xpm;
534 int success;
535 success = XpmReadFileToData((char *) pixmap_filename, &xpm);
536 switch (success) {
537 case XpmOpenFailed:
538 DMA(DEBUG_ERROR, "Unable to open %s\n", pixmap_filename);
539 break;
540 case XpmFileInvalid:
541 DMA(DEBUG_ERROR, "%s is not a valid pixmap\n", pixmap_filename);
542 break;
543 case XpmNoMemory:
544 DMA(DEBUG_ERROR, "Insufficient memory to read %s\n",
545 pixmap_filename);
546 break;
547 default:
548 break;
550 return (xpm);
553 /* tests as "test -f" would */
554 int exists(const char *filename)
556 struct stat st_buf;
557 DMA(DEBUG_INFO, "looking for %s\n", filename);
558 if (stat(filename, &st_buf) == 0 && S_ISREG(st_buf.st_mode)) {
559 DMA(DEBUG_INFO, "found %s\n", filename);
560 return (1);
562 return (0);
565 /* acts like execvp, with code inspired by it */
566 /* mustfree */
567 static char *search_path(const char *path, /*@notnull@ */
568 const char *find_me)
570 char *buf;
571 const char *p;
572 int len, pathlen;
573 if (strchr(find_me, '/') != NULL) {
574 return (strdup_ordie(find_me));
576 pathlen = strlen(path);
577 len = strlen(find_me) + 1;
578 buf = malloc_ordie(pathlen + len + 1);
579 memcpy(buf + pathlen + 1, find_me, len);
580 buf[pathlen] = '/';
582 for (p = path; p != NULL; path = p, path++) {
583 char *startp;
584 p = strchr(path, ':');
585 if (p == NULL) {
586 /* not found; p should point to the null char at the end */
587 startp =
588 memcpy(buf + pathlen - strlen(path), path, strlen(path));
589 } else if (p == path) {
590 /* double colon in a path apparently means try here */
591 startp = &buf[pathlen + 1];
592 } else {
593 /* copy the part between the colons to the buffer */
594 startp = memcpy(buf + pathlen - (p - path), path, p - path);
596 if (exists(startp) != 0) {
597 char *ret = strdup_ordie(startp);
598 free(buf);
599 return (ret);
602 free(buf);
603 return (NULL);
606 /* verifies that .wmbiffrc, is a file, is owned by the user,
607 is not world writeable, and is not world readable. This
608 is just to help keep passwords secure */
609 static int wmbiffrc_permissions_check(const char *wmbiffrc_fname)
611 struct stat st;
612 if (stat(wmbiffrc_fname, &st) != 0) {
613 DMA(DEBUG_ERROR, "Can't stat wmbiffrc: '%s'\n", wmbiffrc_fname);
614 return (1); /* well, it's not a bad permission
615 problem: if you can't find it,
616 neither can the bad guys.. */
618 if ((st.st_mode & S_IFDIR) != 0) {
619 DMA(DEBUG_ERROR, ".wmbiffrc '%s' is a directory!\n"
620 "exiting. don't do that.", wmbiffrc_fname);
621 exit(EXIT_FAILURE);
623 if (st.st_uid != getuid()) {
624 char *user = getenv("USER");
625 DMA(DEBUG_ERROR,
626 ".wmbiffrc '%s' isn't owned by you.\n"
627 "Verify its contents, then 'chown %s %s'\n",
628 wmbiffrc_fname, ((user != NULL) ? user : "(your username)"),
629 wmbiffrc_fname);
630 return (0);
632 if ((st.st_mode & S_IWOTH) != 0) {
633 DMA(DEBUG_ERROR, ".wmbiffrc '%s' is world writable.\n"
634 "Verify its contents, then 'chmod 0600 %s'\n",
635 wmbiffrc_fname, wmbiffrc_fname);
636 return (0);
638 if ((st.st_mode & S_IROTH) != 0) {
639 DMA(DEBUG_ERROR, ".wmbiffrc '%s' is world readable.\n"
640 "Please run 'chmod 0600 %s' and consider changing your passwords.\n",
641 wmbiffrc_fname, wmbiffrc_fname);
642 return (0);
644 return (1);
647 static void ClearDigits(unsigned int i)
649 if (font) {
650 eraseRect(39, mbox_y(i), 58, mbox_y(i + 1) - 1, background);
651 } else {
652 /* overwrite the colon */
653 copyXPMArea((10 * (CHAR_WIDTH + 1)), 64, (CHAR_WIDTH + 1),
654 (CHAR_HEIGHT + 1), 35, mbox_y(i));
655 /* blank out the number fields. */
656 copyXPMArea(39, 84, (3 * (CHAR_WIDTH + 1)), (CHAR_HEIGHT + 1), 39,
657 mbox_y(i));
661 /* Blits a string at given co-ordinates. If a ``new''
662 parameter is nonzero, all digits will be yellow */
663 static void BlitString(const char *name, int x, int y, int new)
665 if (font != NULL) {
666 /* an alternate behavior - draw the string using a font
667 instead of the pixmap. should allow pretty colors */
668 drawString(x, y + CHAR_HEIGHT + 1, name,
669 new ? highlight : foreground, background, 0);
670 } else {
671 /* normal, LED-like behavior. */
672 int i, c, k = x;
673 for (i = 0; name[i] != '\0'; i++) {
674 c = toupper(name[i]);
675 if (c >= 'A' && c <= 'Z') { /* it's a letter */
676 c -= 'A';
677 copyXPMArea(c * (CHAR_WIDTH + 1), (new ? 95 : 74),
678 (CHAR_WIDTH + 1), (CHAR_HEIGHT + 1), k, y);
679 k += (CHAR_WIDTH + 1);
680 } else { /* it's a number or symbol */
681 c -= '0';
682 if (new) {
683 copyXPMArea((c * (CHAR_WIDTH + 1)) + 65, 0,
684 (CHAR_WIDTH + 1), (CHAR_HEIGHT + 1), k, y);
685 } else {
686 copyXPMArea((c * (CHAR_WIDTH + 1)), 64,
687 (CHAR_WIDTH + 1), (CHAR_HEIGHT + 1), k, y);
689 k += (CHAR_WIDTH + 1);
696 /* Blits number to give coordinates.. two 0's, right justified */
697 static void BlitNum(int num, int x, int y, int new)
699 char buf[32];
701 sprintf(buf, "%02i", num);
703 if (font != NULL) {
704 const char *color = (new) ? highlight : foreground;
705 drawString(x + (CHAR_WIDTH * 2 + 4), y + CHAR_HEIGHT + 1, buf,
706 color, background, 1);
707 } else {
708 int newx = x;
710 if (num > 99)
711 newx -= (CHAR_WIDTH + 1);
712 if (num > 999)
713 newx -= (CHAR_WIDTH + 1);
715 BlitString(buf, newx, y, new);
719 /* helper function for displayMsgCounters, which has outgrown its name */
720 static void blitMsgCounters(unsigned int i)
722 int y_row = mbox_y(i); /* constant for each mailbox */
723 ClearDigits(i); /* Clear digits */
724 if ((mbox[i].blink_stat & 0x01) == 0) {
725 int newmail = (mbox[i].UnreadMsgs > 0) ? 1 : 0;
726 if (mbox[i].TextStatus[0] != '\0') {
727 BlitString(mbox[i].TextStatus, 39, y_row, newmail);
728 } else {
729 int mailcount =
730 (newmail) ? mbox[i].UnreadMsgs : 0;
731 BlitNum(mailcount, 45, y_row, newmail);
737 * void execnotify(1) : runs notify command, if given (not null)
739 static void execnotify( /*@null@ */ const char *notifycmd)
741 if (notifycmd != NULL) { /* need to call notify() ? */
742 if (!strcasecmp(notifycmd, "true")) {
743 /* Yes, nothing */
744 } else {
745 /* Else call external notifyer, ignoring the pid */
746 (void) execCommand(notifycmd);
752 static void
753 displayMsgCounters(unsigned int i, int mail_stat, int *Blink_Mode)
755 switch (mail_stat) {
756 case 2: /* New mail has arrived */
757 /* Enter blink-mode for digits */
758 mbox[i].blink_stat = BLINK_TIMES * 2;
759 *Blink_Mode |= (1 << i); /* Global blink flag set for this mailbox */
760 blitMsgCounters(i);
761 execnotify(mbox[i].notify);
762 break;
763 case 1: /* mailbox has been rescanned/changed */
764 blitMsgCounters(i);
765 break;
766 case 0:
767 break;
768 case -1: /* Error was detected */
769 ClearDigits(i); /* Clear digits */
770 BlitString("XX", 45, mbox_y(i), 0);
771 break;
775 /** counts mail in spool-file
776 Returned value:
777 -1 : Error was encountered
778 0 : mailbox status wasn't changed
779 1 : mailbox was changed (NO new mail)
780 2 : mailbox was changed AND new mail has arrived
782 static int count_mail(unsigned int item)
784 int rc = 0;
786 if (!mbox[item].checkMail) {
787 return -1;
790 if (mbox[item].checkMail(&(mbox[item])) < 0) {
791 /* we failed to obtain any numbers therefore set
792 * them to -1's ensuring the next pass (even if
793 * zero) will be captured correctly
795 mbox[item].TotalMsgs = -1;
796 mbox[item].UnreadMsgs = -1;
797 mbox[item].OldMsgs = -1;
798 mbox[item].OldUnreadMsgs = -1;
799 return -1;
802 if (mbox[item].UnreadMsgs > mbox[item].OldUnreadMsgs &&
803 mbox[item].UnreadMsgs > 0) {
804 rc = 2; /* New mail detected */
805 } else if (mbox[item].UnreadMsgs < mbox[item].OldUnreadMsgs ||
806 mbox[item].TotalMsgs != mbox[item].OldMsgs) {
807 rc = 1; /* mailbox was changed - NO new mail */
808 } else {
809 rc = 0; /* mailbox wasn't changed */
811 mbox[item].OldMsgs = mbox[item].TotalMsgs;
812 mbox[item].OldUnreadMsgs = mbox[item].UnreadMsgs;
813 return rc;
816 static int periodic_mail_check(void)
818 int NeedRedraw = 0;
819 static int Blink_Mode = 0; /* Bit mask, digits are in blinking
820 mode or not. Each bit for separate
821 mailbox */
822 int Sleep_Interval; /* either DEFAULT_SLEEP_INTERVAL or
823 BLINK_SLEEP_INTERVAL */
824 int NewMail = 0; /* flag for global notify */
825 unsigned int i;
826 time_t curtime = time(0);
827 for (i = 0; i < num_mailboxes; i++) {
828 if (mbox[i].label[0] != '\0') {
829 if (curtime >= mbox[i].prevtime + mbox[i].loopinterval) {
830 int mailstat = 0;
831 NeedRedraw = 1;
832 DM(&mbox[i], DEBUG_INFO,
833 "working on [%u].label=>%s< [%u].path=>%s<\n", i,
834 mbox[i].label, i, mbox[i].path);
835 DM(&mbox[i], DEBUG_INFO,
836 "curtime=%d, prevtime=%d, interval=%d\n",
837 (int) curtime, (int) mbox[i].prevtime,
838 mbox[i].loopinterval);
839 mbox[i].prevtime = curtime;
841 XDefineCursor(display, iconwin, busy_cursor);
842 RedrawWindow();
844 mailstat = count_mail(i);
846 XUndefineCursor(display, iconwin);
848 /* Global notify */
849 if (mailstat == 2)
850 NewMail = 1;
852 displayMsgCounters(i, mailstat, &Blink_Mode);
853 /* update our idea of current time, as it
854 may have changed as we check. */
855 curtime = time(0);
857 if (mbox[i].blink_stat > 0) {
858 if (--mbox[i].blink_stat <= 0) {
859 Blink_Mode &= ~(1 << i);
860 mbox[i].blink_stat = 0;
862 displayMsgCounters(i, 1, &Blink_Mode);
863 NeedRedraw = 1;
865 if (mbox[i].fetchinterval > 0 && mbox[i].fetchcmd[0] != '\0'
866 && curtime >=
867 mbox[i].prevfetch_time + mbox[i].fetchinterval) {
869 XDefineCursor(display, iconwin, busy_cursor);
870 RedrawWindow();
872 (void) execCommand(mbox[i].fetchcmd);
874 XUndefineCursor(display, iconwin);
876 mbox[i].prevfetch_time = curtime;
881 /* exec globalnotify if there was any new mail */
882 if (NewMail == 1) {
883 execnotify(globalnotify);
886 if (Blink_Mode == 0) {
887 for (i = 0; i < num_mailboxes; i++) {
888 mbox[i].blink_stat = 0;
890 Sleep_Interval = DEFAULT_SLEEP_INTERVAL;
891 } else {
892 Sleep_Interval = BLINK_SLEEP_INTERVAL;
895 if (NeedRedraw) {
896 NeedRedraw = 0;
897 RedrawWindow();
900 return Sleep_Interval;
903 static int findTopOfMasterXPM(const char **skin_xpm)
905 int i;
906 for (i = 0; skin_xpm[i] != NULL; i++) {
907 if (strstr(skin_xpm[i], "++++++++") != NULL)
908 return i;
910 DMA(DEBUG_ERROR,
911 "couldn't find the top of the xpm file using the simple method\n");
912 exit(EXIT_FAILURE);
915 static char **CreateBackingXPM(int width, int height,
916 const char **skin_xpm)
918 char **ret = malloc_ordie(sizeof(char *) * (height + 6)
919 + sizeof(void *) /* trailing null space */ );
920 const int colors = 5;
921 const int base = colors + 1;
922 const int margin = 4;
923 int i;
924 int top = findTopOfMasterXPM(skin_xpm);
925 ret[0] = malloc_ordie(30);
926 sprintf(ret[0], "%d %d %d %d", width, height, colors, 1);
927 ret[1] = (char *) " \tc #0000FF"; /* no color */
928 ret[2] = (char *) ".\tc #202020"; /* background gray */
929 ret[2] = malloc_ordie(30);
930 sprintf(ret[2], ".\tc %s", background);
931 ret[3] = (char *) "+\tc #000000"; /* shadowed */
932 ret[4] = (char *) "@\tc #C7C3C7"; /* highlight */
933 ret[5] = (char *) ":\tc #004941"; /* led off */
934 for (i = base; i < base + height; i++) {
935 ret[i] = malloc_ordie(width);
937 for (i = base; i < base + margin; i++) {
938 memset(ret[i], ' ', width);
940 for (i = base + margin; i < height + base - margin; i++) {
941 memset(ret[i], ' ', margin);
943 if (i == base + margin) {
944 memset(ret[i] + margin, '+', width - margin - margin);
945 } else if (i == base + height - margin - 1) {
946 memset(ret[i] + margin, '@', width - margin - margin);
947 } else {
948 // " +..:::...:::...:::...:::...:::.......:::...:::...:::...@ "
949 // " +.:...:.:...:.:...:.:...:.:...:..:..:...:.:...:.:...:..@ " ",
950 ret[i][margin] = '+';
951 memset(ret[i] + margin + 1, '.', width - margin - margin - 1);
952 ret[i][width - margin - 1] = '@';
953 memcpy(ret[i],
954 skin_xpm[((i - (base + margin) - 1) % 11) + top + 1],
955 width);
958 memset(ret[i] + width - margin, ' ', margin);
960 for (i = base + height - margin; i < height + base; i++) {
961 memset(ret[i], ' ', width);
963 ret[height + base] = NULL; /* not sure if this is necessary, it just
964 seemed like a good idea */
965 return (ret);
969 * NOTE: this function assumes that the ConnectionNumber() macro
970 * will return the file descriptor of the Display struct
971 * (it does under XFree86 and solaris' openwin X)
973 static void XSleep(int millisec)
975 #ifdef HAVE_POLL
976 struct pollfd timeout;
978 timeout.fd = ConnectionNumber(display);
979 timeout.events = POLLIN;
981 poll(&timeout, 1, millisec);
982 #else
983 struct timeval to;
984 struct timeval *timeout = NULL;
985 fd_set readfds;
986 int max_fd;
988 if (millisec >= 0) {
989 timeout = &to;
990 to.tv_sec = millisec / 1000;
991 to.tv_usec = (millisec % 1000) * 1000;
993 FD_ZERO(&readfds);
994 FD_SET(ConnectionNumber(display), &readfds);
995 max_fd = ConnectionNumber(display);
997 select(max_fd + 1, &readfds, NULL, NULL, timeout);
998 #endif
1001 const char **restart_args;
1003 static void restart_wmbiff(int sig
1004 #ifdef HAVE___ATTRIBUTE__
1005 __attribute__ ((unused))
1006 #endif
1009 DMA(DEBUG_ERROR, "exec()'ing %s\n", restart_args[0]);
1010 sleep(1);
1011 execvp(restart_args[0], (char *const *) restart_args);
1012 DMA(DEBUG_ERROR, "exec of %s failed: %s\n",
1013 restart_args[0], strerror(errno));
1014 exit(EXIT_FAILURE);
1017 extern int x_socket(void)
1019 return ConnectionNumber(display);
1021 extern void ProcessPendingEvents(void)
1023 static int but_pressed_region = -1; /* static so click can be determined */
1024 int but_released_region = -1;
1025 /* X Events */
1026 while (XPending(display)) {
1027 XEvent Event;
1028 const char *press_action;
1030 XNextEvent(display, &Event);
1032 switch (Event.type) {
1033 case Expose:
1034 if (Event.xany.window != win && Event.xany.window != iconwin) {
1035 msglst_redraw();
1036 } else {
1037 RedrawWindow();
1039 break;
1040 case DestroyNotify:
1041 XCloseDisplay(display);
1042 exit(EXIT_SUCCESS);
1043 break;
1044 case ButtonPress:
1045 but_pressed_region =
1046 CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1047 switch (Event.xbutton.button) {
1048 case 1:
1049 press_action = mbox[but_pressed_region].action;
1050 break;
1051 case 2:
1052 press_action = mbox[but_pressed_region].button2;
1053 break;
1054 case 3:
1055 press_action = mbox[but_pressed_region].fetchcmd;
1056 break;
1057 default:
1058 press_action = NULL;
1059 break;
1062 if (press_action && strcmp(press_action, "msglst") == 0) {
1063 msglst_show(&mbox[but_pressed_region],
1064 Event.xbutton.x_root, Event.xbutton.y_root);
1066 break;
1067 case ButtonRelease:
1068 but_released_region =
1069 CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1070 if (but_released_region == but_pressed_region
1071 && but_released_region >= 0) {
1072 const char *click_action, *extra_click_action = NULL;
1074 switch (Event.xbutton.button) {
1075 case 1: /* Left mouse-click */
1076 /* C-S-left will restart wmbiff. */
1077 if ((Event.xbutton.state & ControlMask) &&
1078 (Event.xbutton.state & ShiftMask)) {
1079 restart_wmbiff(0);
1081 /* do we need to run an extra action? */
1082 if (mbox[but_released_region].UnreadMsgs == -1) {
1083 extra_click_action =
1084 mbox[but_released_region].actiondc;
1085 } else if (mbox[but_released_region].UnreadMsgs > 0) {
1086 extra_click_action =
1087 mbox[but_released_region].actionnew;
1088 } else {
1089 extra_click_action =
1090 mbox[but_released_region].actionnonew;
1092 click_action = mbox[but_released_region].action;
1093 break;
1094 case 2: /* Middle mouse-click */
1095 click_action = mbox[but_released_region].button2;
1096 break;
1097 case 3: /* Right mouse-click */
1098 click_action = mbox[but_released_region].fetchcmd;
1099 break;
1100 default:
1101 click_action = NULL;
1102 break;
1104 if (extra_click_action != NULL
1105 && extra_click_action[0] != 0
1106 && strcmp(extra_click_action, "msglst")) {
1107 DM(&mbox[but_released_region], DEBUG_INFO,
1108 "runing: %s", extra_click_action);
1109 (void) execCommand(extra_click_action);
1111 if (click_action != NULL
1112 && click_action[0] != '\0'
1113 && strcmp(click_action, "msglst")) {
1114 DM(&mbox[but_released_region], DEBUG_INFO,
1115 "running: %s", click_action);
1116 (void) execCommand(click_action);
1120 /* a button was released, hide the message list if open */
1121 msglst_hide();
1123 but_pressed_region = -1;
1124 /* RedrawWindow(); */
1125 break;
1126 case MotionNotify:
1127 break;
1128 case KeyPress:{
1129 XKeyPressedEvent *xkpe = (XKeyPressedEvent *) & Event;
1130 KeySym ks = XKeycodeToKeysym(display, xkpe->keycode, 0);
1131 if (ks > XK_0 && ks < XK_0 + min(9U, num_mailboxes)) {
1132 const char *click_action = mbox[ks - XK_1].action;
1133 if (click_action != NULL
1134 && click_action[0] != '\0'
1135 && strcmp(click_action, "msglst")) {
1136 DM(&mbox[but_released_region], DEBUG_INFO,
1137 "running: %s", click_action);
1138 (void) execCommand(click_action);
1143 break;
1144 default:
1145 break;
1150 static void do_biff(int argc, const char **argv)
1152 unsigned int i;
1153 time_t curtime;
1154 int Sleep_Interval;
1155 const char **skin_xpm = NULL;
1156 const char **bkg_xpm = NULL;
1157 char *skin_file_path = search_path(skin_search_path, skin_filename);
1158 int wmbiff_mask_height = mbox_y(num_mailboxes) + 4;
1160 DMA(DEBUG_INFO, "running %u mailboxes w %d h %d\n", num_mailboxes,
1161 wmbiff_mask_width, wmbiff_mask_height);
1163 if (skin_file_path != NULL) {
1164 skin_xpm = (const char **) LoadXPM(skin_file_path);
1165 free(skin_file_path);
1167 if (skin_xpm == NULL) {
1168 DMA(DEBUG_ERROR, "using built-in xpm; %s wasn't found in %s\n",
1169 skin_filename, skin_search_path);
1170 skin_xpm = wmbiff_master_xpm;
1173 bkg_xpm = (const char **) CreateBackingXPM(wmbiff_mask_width,
1174 wmbiff_mask_height,
1175 skin_xpm);
1177 createXBMfromXPM(wmbiff_mask_bits, bkg_xpm,
1178 wmbiff_mask_width, wmbiff_mask_height);
1180 openXwindow(argc, argv, bkg_xpm, skin_xpm, wmbiff_mask_bits,
1181 wmbiff_mask_width, wmbiff_mask_height, notWithdrawn);
1183 /* now that display is set, we can create the cursors
1184 (mouse pointer shapes) */
1185 busy_cursor = XCreateFontCursor(display, XC_watch);
1186 ready_cursor = XCreateFontCursor(display, XC_left_ptr);
1188 if (font != NULL) {
1189 if (loadFont(font) < 0) {
1190 DMA(DEBUG_ERROR, "unable to load font. exiting.\n");
1191 exit(EXIT_FAILURE);
1193 /* make the whole background black */
1194 // removed; seems unnecessary with CreateBackingXPM
1195 // eraseRect(x_origin, y_origin,
1196 // wmbiff_mask_width - 6, wmbiff_mask_height - 6,
1197 // background);
1200 /* First time setup of button regions and labels */
1201 curtime = time(0);
1202 for (i = 0; i < num_mailboxes; i++) {
1203 /* make it easy to recover the mbox index from a mouse click */
1204 AddMouseRegion(i, x_origin, mbox_y(i), 58, mbox_y(i + 1) - 1);
1205 if (mbox[i].label[0] != '\0') {
1206 mbox[i].prevtime = mbox[i].prevfetch_time = 0;
1207 BlitString(mbox[i].label, x_origin, mbox_y(i), 0);
1211 do {
1212 /* waitpid(0, NULL, WNOHANG); */
1214 Sleep_Interval = periodic_mail_check();
1216 ProcessPendingEvents();
1218 XSleep(Sleep_Interval);
1220 while (forever); /* forever is usually true,
1221 but not when debugging with -exit */
1222 if (skin_xpm != NULL && skin_xpm != wmbiff_master_xpm) {
1223 free(skin_xpm); // added 3 jul 02, appeasing valgrind
1225 if (bkg_xpm != NULL) {
1226 free(bkg_xpm);
1230 static void sigchld_handler(int sig
1231 #ifdef HAVE___ATTRIBUTE__
1232 __attribute__ ((unused))
1233 #endif
1236 while (waitpid(0, NULL, WNOHANG) > 0);
1237 signal(SIGCHLD, sigchld_handler);
1240 static void usage(void)
1242 printf("\nwmBiff v%s"
1243 " - incoming mail checker\n"
1244 "Gennady Belyakov and others (see the README file)\n"
1245 "Please report bugs to %s\n"
1246 "\n"
1247 "usage:\n"
1248 " -bg <color> background color\n"
1249 " -c <filename> use specified config file\n"
1250 " -debug enable debugging\n"
1251 " -display <display name> use specified X display\n"
1252 " -fg <color> foreground color\n"
1253 " -font <font> font instead of LED\n"
1254 " -geometry +XPOS+YPOS initial window position\n"
1255 " -h this help screen\n"
1256 " -hi <color> highlight color for new mail\n"
1257 #ifdef USE_GNUTLS
1258 " -skip-certificate-check using TLS, don't validate the\n"
1259 " server's certificate\n"
1260 #endif
1261 " -relax assume the configuration is \n"
1262 " correct, parse it without paranoia, \n"
1263 " and assume hostnames are okay.\n"
1264 " -v print the version number\n"
1265 " +w not withdrawn: run as a window\n"
1266 "\n", PACKAGE_VERSION, PACKAGE_BUGREPORT);
1269 static void printversion(void)
1271 printf("wmbiff v%s\n", PACKAGE_VERSION);
1275 static void parse_cmd(int argc, const char **argv, /*@out@ */
1276 char *config_file)
1278 int i;
1280 config_file[0] = '\0';
1282 /* Parse Command Line */
1284 for (i = 1; i < argc; i++) {
1285 const char *arg = argv[i];
1287 if (*arg == '-') {
1288 switch (arg[1]) {
1289 case 'b':
1290 if (strcmp(arg + 1, "bg") == 0) {
1291 if (argc > (i + 1)) {
1292 background = strdup_ordie(argv[i + 1]);
1293 DMA(DEBUG_INFO, "new background: %s", foreground);
1294 i++;
1295 if (font == NULL)
1296 font = DEFAULT_FONT;
1299 break;
1300 case 'd':
1301 if (strcmp(arg + 1, "debug") == 0) {
1302 debug_default = DEBUG_ALL;
1303 } else if (strcmp(arg + 1, "display") == 0) {
1304 /* passed to X's command line parser */
1305 } else {
1306 usage();
1307 exit(EXIT_FAILURE);
1309 break;
1310 case 'f':
1311 if (strcmp(arg + 1, "fg") == 0) {
1312 if (argc > (i + 1)) {
1313 foreground = strdup_ordie(argv[i + 1]);
1314 DMA(DEBUG_INFO, "new foreground: %s", foreground);
1315 i++;
1316 if (font == NULL)
1317 font = DEFAULT_FONT;
1319 } else if (strcmp(arg + 1, "font") == 0) {
1320 if (argc > (i + 1)) {
1321 if (strcmp(argv[i + 1], "default") == 0) {
1322 font = DEFAULT_FONT;
1323 } else {
1324 font = strdup_ordie(argv[i + 1]);
1326 DMA(DEBUG_INFO, "new font: %s", font);
1327 i++;
1329 } else {
1330 usage();
1331 exit(EXIT_FAILURE);
1333 break;
1334 case 'g':
1335 if (strcmp(arg + 1, "geometry") != 0) {
1336 usage();
1337 exit(EXIT_FAILURE);
1338 } else {
1339 i++; /* gobble the argument */
1340 if (i >= argc) { /* fail if there's nothing to gobble */
1341 usage();
1342 exit(EXIT_FAILURE);
1345 break;
1346 case 'h':
1347 if (strcmp(arg + 1, "hi") == 0) {
1348 if (argc > (i + 1)) {
1349 highlight = strdup_ordie(argv[i + 1]);
1350 DMA(DEBUG_INFO, "new highlight: %s", highlight);
1351 i++;
1352 if (font == NULL)
1353 font = DEFAULT_FONT;
1355 } else if (strcmp(arg + 1, "h") == 0) {
1356 usage();
1357 exit(EXIT_SUCCESS);
1359 break;
1360 case 'v':
1361 printversion();
1362 exit(EXIT_SUCCESS);
1363 break;
1364 case 's':
1365 if (strcmp(arg + 1, "skip-certificate-check") == 0) {
1366 SkipCertificateCheck = 1;
1367 } else {
1368 usage();
1369 exit(EXIT_SUCCESS);
1372 break;
1373 case 'r':
1374 if (strcmp(arg + 1, "relax") == 0) {
1375 Relax = 1;
1376 } else {
1377 usage();
1378 exit(EXIT_SUCCESS);
1381 break;
1382 case 'c':
1383 if (argc > (i + 1)) {
1384 strncpy(config_file, argv[i + 1], 255);
1385 i++;
1387 break;
1388 case 'e': /* undocumented for debugging */
1389 if (strcmp(arg + 1, "exit") == 0) {
1390 forever = 0;
1392 break;
1393 default:
1394 usage();
1395 exit(EXIT_SUCCESS);
1396 break;
1398 } else if (*arg == '+') {
1399 switch (arg[1]) {
1400 case 'w':
1401 notWithdrawn = 1;
1402 break;
1403 default:
1404 usage();
1405 exit(EXIT_SUCCESS);
1406 break;
1412 int main(int argc, const char *argv[])
1414 char uconfig_file[256];
1416 /* hold on to the arguments we were started with; we
1417 will need them if we have to restart on sigusr1 */
1418 restart_args =
1419 (const char **) malloc((argc + 1) * sizeof(const char *));
1420 memcpy(restart_args, argv, (argc) * sizeof(const char *));
1421 restart_args[argc] = NULL;
1423 parse_cmd(argc, argv, uconfig_file);
1425 /* decide what the config file is */
1426 if (uconfig_file[0] != '\0') { /* user-specified config file */
1427 DMA(DEBUG_INFO, "Using user-specified config file '%s'.\n",
1428 uconfig_file);
1429 } else {
1430 const char *home = getenv("HOME");
1431 if (home == NULL) {
1432 DMA(DEBUG_ERROR,
1433 "$HOME undefined. Use the -c option to specify a wmbiffrc\n");
1434 exit(EXIT_FAILURE);
1436 sprintf(uconfig_file, "%s/.wmbiffrc", home);
1439 if (wmbiffrc_permissions_check(uconfig_file) == 0) {
1440 DMA(DEBUG_ERROR,
1441 "WARNING: In future versions of WMBiff, .wmbiffrc MUST be\n"
1442 "owned by the user, and not readable or writable by others.\n\n");
1444 init_biff(uconfig_file);
1445 signal(SIGCHLD, sigchld_handler);
1446 signal(SIGUSR1, restart_wmbiff);
1447 signal(SIGPIPE, SIG_IGN); /* write() may fail */
1449 do_biff(argc, argv);
1450 return 0;
1453 /* vim:set ts=4: */
1455 * Local Variables:
1456 * tab-width: 4
1457 * c-indent-level: 4
1458 * c-basic-offset: 4
1459 * End: