1c19de146Smrg/* $XConsortium: xbiff.c,v 1.19 94/04/17 20:43:28 rws Exp $ */ 2c19de146Smrg/* 3c19de146Smrg 4c19de146SmrgCopyright (c) 1988 X Consortium 5c19de146Smrg 6c19de146SmrgPermission is hereby granted, free of charge, to any person obtaining 7c19de146Smrga copy of this software and associated documentation files (the 8c19de146Smrg"Software"), to deal in the Software without restriction, including 9c19de146Smrgwithout limitation the rights to use, copy, modify, merge, publish, 10c19de146Smrgdistribute, sublicense, and/or sell copies of the Software, and to 11c19de146Smrgpermit persons to whom the Software is furnished to do so, subject to 12c19de146Smrgthe following conditions: 13c19de146Smrg 14c19de146SmrgThe above copyright notice and this permission notice shall be included 15c19de146Smrgin all copies or substantial portions of the Software. 16c19de146Smrg 17c19de146SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18c19de146SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19c19de146SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20c19de146SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 21c19de146SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22c19de146SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23c19de146SmrgOTHER DEALINGS IN THE SOFTWARE. 24c19de146Smrg 25c19de146SmrgExcept as contained in this notice, the name of the X Consortium shall 26c19de146Smrgnot be used in advertising or otherwise to promote the sale, use or 27c19de146Smrgother dealings in this Software without prior written authorization 28c19de146Smrgfrom the X Consortium. 29c19de146Smrg 30c19de146Smrg*/ 31c19de146Smrg/* $XFree86: xc/programs/xbiff/xbiff.c,v 1.3tsi Exp $ */ 32c19de146Smrg 333b83913fSmrg#ifdef HAVE_CONFIG_H 343b83913fSmrg#include "config.h" 353b83913fSmrg#endif 363b83913fSmrg 37c19de146Smrg#include <stdio.h> 38c19de146Smrg#include <stdlib.h> 39c19de146Smrg#include <X11/Xatom.h> 40c19de146Smrg#include <X11/Intrinsic.h> 41c19de146Smrg#include <X11/StringDefs.h> 42c19de146Smrg#include "Mailbox.h" 43c19de146Smrg#include <X11/Xaw/Cardinals.h> 44c19de146Smrg 459ef7378bSmrgstatic const char *ProgramName; 46c19de146Smrg 47c19de146Smrgstatic XrmOptionDescRec options[] = { 48c19de146Smrg{ "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL }, 49c19de146Smrg{ "-file", "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL }, 50c19de146Smrg{ "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL }, 51c19de146Smrg{ "-shape", "*mailbox.shapeWindow", XrmoptionNoArg, (caddr_t) "on" }, 52c19de146Smrg}; 53c19de146Smrg 54c19de146Smrgstatic Atom wm_delete_window; 55c19de146Smrg 569ef7378bSmrgstatic void quit (Widget w, XEvent *event, String *params, Cardinal *num_params) 57c19de146Smrg{ 58c19de146Smrg if (event->type == ClientMessage && 59a39bb051Smrg ((Atom) event->xclient.data.l[0]) != wm_delete_window) { 60c19de146Smrg XBell (XtDisplay(w), 0); 61c19de146Smrg return; 62c19de146Smrg } 63c19de146Smrg XCloseDisplay (XtDisplay(w)); 64c19de146Smrg exit (0); 65c19de146Smrg} 66c19de146Smrg 67c19de146Smrgstatic XtActionsRec xbiff_actions[] = { 68c19de146Smrg { "quit", quit }, 69c19de146Smrg}; 70c19de146Smrg 713b83913fSmrgstatic void _X_NORETURN _X_COLD 723b83913fSmrgUsage (int exitval) 73c19de146Smrg{ 743b83913fSmrg const char *help_message = 753b83913fSmrg"where options include:\n" 763b83913fSmrg" -display host:dpy X server to contact\n" 773b83913fSmrg" -geometry geom size of mailbox\n" 783b83913fSmrg" -file file file to watch\n" 793b83913fSmrg" -update seconds how often to check for mail\n" 803b83913fSmrg" -volume percentage how loud to ring the bell\n" 813b83913fSmrg" -bg color background color\n" 823b83913fSmrg" -fg color foreground color\n" 833b83913fSmrg" -rv reverse video\n" 843b83913fSmrg" -shape shape the window\n" 853b83913fSmrg" -help print usage info and exit\n" 863b83913fSmrg" -version print version info and exit\n"; 87c19de146Smrg 88c19de146Smrg fprintf (stderr, "usage: %s [-options ...]\n", ProgramName); 893b83913fSmrg fprintf (stderr, "%s\n", help_message); 903b83913fSmrg exit (exitval); 91c19de146Smrg} 92c19de146Smrg 93c19de146Smrg 94c19de146Smrgint 959ef7378bSmrgmain (int argc, char **argv) 96c19de146Smrg{ 97c19de146Smrg XtAppContext xtcontext; 98c19de146Smrg Widget toplevel; 99c19de146Smrg 100c19de146Smrg ProgramName = argv[0]; 101c19de146Smrg 102c19de146Smrg XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); 103c19de146Smrg 1043b83913fSmrg /* Handle args that don't require opening a display */ 1053b83913fSmrg for (int n = 1; n < argc; n++) { 1063b83913fSmrg const char *argn = argv[n]; 1073b83913fSmrg /* accept single or double dash for -help & -version */ 1083b83913fSmrg if (argn[0] == '-' && argn[1] == '-') { 1093b83913fSmrg argn++; 1103b83913fSmrg } 1113b83913fSmrg if (strcmp(argn, "-help") == 0) { 1123b83913fSmrg Usage(0); 1133b83913fSmrg } 1143b83913fSmrg if (strcmp(argn, "-version") == 0) { 1153b83913fSmrg puts(PACKAGE_STRING); 1163b83913fSmrg exit(0); 1173b83913fSmrg } 1183b83913fSmrg } 1193b83913fSmrg 120c19de146Smrg toplevel = XtAppInitialize(&xtcontext, "XBiff", options, XtNumber (options), 121c19de146Smrg &argc, argv, NULL, NULL, 0); 1223b83913fSmrg if (argc != 1) { 1233b83913fSmrg fputs("Unknown argument(s):", stderr); 1243b83913fSmrg for (int n = 1; n < argc; n++) { 1253b83913fSmrg fprintf(stderr, " %s", argv[n]); 1263b83913fSmrg } 1273b83913fSmrg fputs("\n\n", stderr); 1283b83913fSmrg Usage(1); 1293b83913fSmrg } 130c19de146Smrg 131c19de146Smrg /* 132c19de146Smrg * This is a hack so that f.delete will do something useful in this 133c19de146Smrg * single-window application. 134c19de146Smrg */ 135c19de146Smrg wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW", 136c19de146Smrg False); 137c19de146Smrg XtAppAddActions (xtcontext, xbiff_actions, XtNumber(xbiff_actions)); 138c19de146Smrg XtOverrideTranslations(toplevel, 139c19de146Smrg XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()")); 140c19de146Smrg 141c19de146Smrg (void) XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel, 142c19de146Smrg NULL, 0); 143c19de146Smrg XtRealizeWidget (toplevel); 144c19de146Smrg (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel), 145c19de146Smrg &wm_delete_window, 1); 146c19de146Smrg XtAppMainLoop (xtcontext); 147c19de146Smrg 148c19de146Smrg return 0; 149c19de146Smrg} 150