1/* $XConsortium: xbiff.c,v 1.19 94/04/17 20:43:28 rws Exp $ */ 2/* 3 4Copyright (c) 1988 X Consortium 5 6Permission is hereby granted, free of charge, to any person obtaining 7a copy of this software and associated documentation files (the 8"Software"), to deal in the Software without restriction, including 9without limitation the rights to use, copy, modify, merge, publish, 10distribute, sublicense, and/or sell copies of the Software, and to 11permit persons to whom the Software is furnished to do so, subject to 12the following conditions: 13 14The above copyright notice and this permission notice shall be included 15in all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 21OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of the X Consortium shall 26not be used in advertising or otherwise to promote the sale, use or 27other dealings in this Software without prior written authorization 28from the X Consortium. 29 30*/ 31/* $XFree86: xc/programs/xbiff/xbiff.c,v 1.3tsi Exp $ */ 32 33#ifdef HAVE_CONFIG_H 34#include "config.h" 35#endif 36 37#include <stdio.h> 38#include <stdlib.h> 39#include <X11/Xatom.h> 40#include <X11/Intrinsic.h> 41#include <X11/StringDefs.h> 42#include "Mailbox.h" 43#include <X11/Xaw/Cardinals.h> 44 45static const char *ProgramName; 46 47static XrmOptionDescRec options[] = { 48{ "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL }, 49{ "-file", "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL }, 50{ "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL }, 51{ "-shape", "*mailbox.shapeWindow", XrmoptionNoArg, (caddr_t) "on" }, 52}; 53 54static Atom wm_delete_window; 55 56static void quit (Widget w, XEvent *event, String *params, Cardinal *num_params) 57{ 58 if (event->type == ClientMessage && 59 ((Atom) event->xclient.data.l[0]) != wm_delete_window) { 60 XBell (XtDisplay(w), 0); 61 return; 62 } 63 XCloseDisplay (XtDisplay(w)); 64 exit (0); 65} 66 67static XtActionsRec xbiff_actions[] = { 68 { "quit", quit }, 69}; 70 71static void _X_NORETURN _X_COLD 72Usage (int exitval) 73{ 74 const char *help_message = 75"where options include:\n" 76" -display host:dpy X server to contact\n" 77" -geometry geom size of mailbox\n" 78" -file file file to watch\n" 79" -update seconds how often to check for mail\n" 80" -volume percentage how loud to ring the bell\n" 81" -bg color background color\n" 82" -fg color foreground color\n" 83" -rv reverse video\n" 84" -shape shape the window\n" 85" -help print usage info and exit\n" 86" -version print version info and exit\n"; 87 88 fprintf (stderr, "usage: %s [-options ...]\n", ProgramName); 89 fprintf (stderr, "%s\n", help_message); 90 exit (exitval); 91} 92 93 94int 95main (int argc, char **argv) 96{ 97 XtAppContext xtcontext; 98 Widget toplevel; 99 100 ProgramName = argv[0]; 101 102 XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); 103 104 /* Handle args that don't require opening a display */ 105 for (int n = 1; n < argc; n++) { 106 const char *argn = argv[n]; 107 /* accept single or double dash for -help & -version */ 108 if (argn[0] == '-' && argn[1] == '-') { 109 argn++; 110 } 111 if (strcmp(argn, "-help") == 0) { 112 Usage(0); 113 } 114 if (strcmp(argn, "-version") == 0) { 115 puts(PACKAGE_STRING); 116 exit(0); 117 } 118 } 119 120 toplevel = XtAppInitialize(&xtcontext, "XBiff", options, XtNumber (options), 121 &argc, argv, NULL, NULL, 0); 122 if (argc != 1) { 123 fputs("Unknown argument(s):", stderr); 124 for (int n = 1; n < argc; n++) { 125 fprintf(stderr, " %s", argv[n]); 126 } 127 fputs("\n\n", stderr); 128 Usage(1); 129 } 130 131 /* 132 * This is a hack so that f.delete will do something useful in this 133 * single-window application. 134 */ 135 wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW", 136 False); 137 XtAppAddActions (xtcontext, xbiff_actions, XtNumber(xbiff_actions)); 138 XtOverrideTranslations(toplevel, 139 XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 140 141 (void) XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel, 142 NULL, 0); 143 XtRealizeWidget (toplevel); 144 (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 145 &wm_delete_window, 1); 146 XtAppMainLoop (xtcontext); 147 148 return 0; 149} 150