xbiff.c revision c19de146
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
33c19de146Smrg#include <stdio.h>
34c19de146Smrg#include <stdlib.h>
35c19de146Smrg#include <X11/Xatom.h>
36c19de146Smrg#include <X11/Intrinsic.h>
37c19de146Smrg#include <X11/StringDefs.h>
38c19de146Smrg#include "Mailbox.h"
39c19de146Smrg#include <X11/Xaw/Cardinals.h>
40c19de146Smrg
41c19de146Smrgconst char *ProgramName;
42c19de146Smrg
43c19de146Smrgstatic XrmOptionDescRec options[] = {
44c19de146Smrg{ "-update", "*mailbox.update", XrmoptionSepArg, (caddr_t) NULL },
45c19de146Smrg{ "-file",   "*mailbox.file", XrmoptionSepArg, (caddr_t) NULL },
46c19de146Smrg{ "-volume", "*mailbox.volume", XrmoptionSepArg, (caddr_t) NULL },
47c19de146Smrg{ "-shape",  "*mailbox.shapeWindow", XrmoptionNoArg, (caddr_t) "on" },
48c19de146Smrg};
49c19de146Smrg
50c19de146Smrgstatic Atom wm_delete_window;
51c19de146Smrg
52c19de146Smrgstatic void quit (w, event, params, num_params)
53c19de146Smrg    Widget w;
54c19de146Smrg    XEvent *event;
55c19de146Smrg    String *params;
56c19de146Smrg    Cardinal *num_params;
57c19de146Smrg{
58c19de146Smrg    if (event->type == ClientMessage &&
59c19de146Smrg        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
71c19de146Smrgstatic void Usage ()
72c19de146Smrg{
73c19de146Smrg    static const char *help_message[] = {
74c19de146Smrg"where options include:",
75c19de146Smrg"    -display host:dpy              X server to contact",
76c19de146Smrg"    -geometry geom                 size of mailbox",
77c19de146Smrg"    -file file                     file to watch",
78c19de146Smrg"    -update seconds                how often to check for mail",
79c19de146Smrg"    -volume percentage             how loud to ring the bell",
80c19de146Smrg"    -bg color                      background color",
81c19de146Smrg"    -fg color                      foreground color",
82c19de146Smrg"    -rv                            reverse video",
83c19de146Smrg"    -shape                         shape the window",
84c19de146SmrgNULL};
85c19de146Smrg    const char **cpp;
86c19de146Smrg
87c19de146Smrg    fprintf (stderr, "usage:  %s [-options ...]\n", ProgramName);
88c19de146Smrg    for (cpp = help_message; *cpp; cpp++)
89c19de146Smrg	fprintf (stderr, "%s\n", *cpp);
90c19de146Smrg    fprintf (stderr, "\n");
91c19de146Smrg    exit (1);
92c19de146Smrg}
93c19de146Smrg
94c19de146Smrg
95c19de146Smrgint
96c19de146Smrgmain (argc, argv)
97c19de146Smrg    int argc;
98c19de146Smrg    char **argv;
99c19de146Smrg{
100c19de146Smrg    XtAppContext xtcontext;
101c19de146Smrg    Widget toplevel;
102c19de146Smrg
103c19de146Smrg    ProgramName = argv[0];
104c19de146Smrg
105c19de146Smrg    XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
106c19de146Smrg
107c19de146Smrg    toplevel = XtAppInitialize(&xtcontext, "XBiff", options, XtNumber (options),
108c19de146Smrg			       &argc, argv, NULL, NULL, 0);
109c19de146Smrg    if (argc != 1) Usage ();
110c19de146Smrg
111c19de146Smrg    /*
112c19de146Smrg     * This is a hack so that f.delete will do something useful in this
113c19de146Smrg     * single-window application.
114c19de146Smrg     */
115c19de146Smrg    wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
116c19de146Smrg                                    False);
117c19de146Smrg    XtAppAddActions (xtcontext, xbiff_actions, XtNumber(xbiff_actions));
118c19de146Smrg    XtOverrideTranslations(toplevel,
119c19de146Smrg		   XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
120c19de146Smrg
121c19de146Smrg    (void) XtCreateManagedWidget ("mailbox", mailboxWidgetClass, toplevel,
122c19de146Smrg				  NULL, 0);
123c19de146Smrg    XtRealizeWidget (toplevel);
124c19de146Smrg    (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
125c19de146Smrg                            &wm_delete_window, 1);
126c19de146Smrg    XtAppMainLoop (xtcontext);
127c19de146Smrg
128c19de146Smrg    return 0;
129c19de146Smrg}
130