source: trunk/third/xmh/init.c @ 9658

Revision 9658, 16.8 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9657, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 * $XConsortium: init.c,v 2.71 91/07/23 17:42:19 converse Exp $
3 *
4 *
5 *                      COPYRIGHT 1987, 1989
6 *                 DIGITAL EQUIPMENT CORPORATION
7 *                     MAYNARD, MASSACHUSETTS
8 *                      ALL RIGHTS RESERVED.
9 *
10 * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
11 * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
12 * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR
13 * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
14 *
15 * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
16 * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
17 * ADDITION TO THAT SET FORTH ABOVE.
18 *
19 * Permission to use, copy, modify, and distribute this software and its
20 * documentation for any purpose and without fee is hereby granted, provided
21 * that the above copyright notice appear in all copies and that both that
22 * copyright notice and this permission notice appear in supporting
23 * documentation, and that the name of Digital Equipment Corporation not be
24 * used in advertising or publicity pertaining to distribution of the software
25 * without specific, written prior permission.
26 *
27 */
28
29/* Init.c - Handle start-up initialization. */
30
31#include "xmh.h"
32#include "actions.h"
33#include <errno.h>
34
35#define MIN_APP_DEFAULTS_VERSION 1
36#define xmhCkpDefault "%d.CKP"
37
38static String FallbackResources[] = {
39"*folderButton.label: Close",
40"*folderButton.borderWidth: 4",
41"*folderButton.translations: #override <Btn1Down>: XmhClose()",
42NULL
43};
44
45static Boolean static_variable;  /* whose address is not a widget ID */
46
47/* This is for the check mark in the Options menu */
48#define check_width 9
49#define check_height 8
50static unsigned char check_bits[] = {
51   0x00, 0x01, 0x80, 0x01, 0xc0, 0x00, 0x60, 0x00,
52   0x31, 0x00, 0x1b, 0x00, 0x0e, 0x00, 0x04, 0x00
53};
54
55#define Offset(field) XtOffsetOf(struct _resources, field)
56
57/* Xmh application resources. */
58
59static XtResource resources[] = {
60    {"debug", "Debug", XtRBoolean, sizeof(Boolean),
61         Offset(debug), XtRImmediate, (XtPointer)False},
62
63    {"tempDir", "TempDir", XtRString, sizeof(char *),
64         Offset(temp_dir), XtRString, "/tmp"},
65    {"mhPath", "MhPath", XtRString, sizeof(char *),
66         Offset(mh_path), XtRString, "/usr/local/mh6"},
67    {"mailPath", "MailPath", XtRString, sizeof(char *),
68         Offset(mail_path), XtRString, NULL},
69    {"initialFolder", "InitialFolder", XtRString, sizeof(char *),
70         Offset(initial_folder_name), XtRString, "inbox"},
71    {"initialIncFile", "InitialIncFile", XtRString, sizeof(char *),
72         Offset(initial_inc_file), XtRString, NULL},
73    {"replyInsertFilter", "ReplyInsertFilter", XtRString, sizeof(char *),
74         Offset(insert_filter), XtRString, NULL},
75    {"draftsFolder", "DraftsFolder", XtRString, sizeof(char *),
76         Offset(drafts_folder_name), XtRString, "drafts"},
77    {"printCommand", "PrintCommand", XtRString, sizeof(char *),
78         Offset(print_command), XtRString,
79         "enscript > /dev/null 2>/dev/null"},
80
81    {"sendWidth", "SendWidth", XtRInt, sizeof(int),
82         Offset(send_line_width), XtRImmediate, (XtPointer)72},
83    {"sendBreakWidth", "SendBreakWidth", XtRInt, sizeof(int),
84         Offset(break_send_line_width), XtRImmediate, (XtPointer)85},
85    {"tocWidth", "TocWidth", XtRInt, sizeof(int),
86         Offset(toc_width), XtRImmediate, (XtPointer)100},
87    {"skipDeleted", "SkipDeleted", XtRBoolean, sizeof(Boolean),
88         Offset(skip_deleted), XtRImmediate, (XtPointer)True},
89    {"skipMoved", "SkipMoved", XtRBoolean, sizeof(Boolean),
90         Offset(skip_moved), XtRImmediate, (XtPointer)True},
91    {"skipCopied", "SkipCopied", XtRBoolean, sizeof(Boolean),
92         Offset(skip_copied), XtRImmediate, (XtPointer)False},
93    {"hideBoringHeaders", "HideBoringHeaders", XtRBoolean, sizeof(Boolean),
94         Offset(hide_boring_headers), XtRImmediate, (XtPointer)True},
95
96    {"geometry", "Geometry", XtRString, sizeof(char *),
97         Offset(geometry), XtRString, NULL},
98    {"tocGeometry", "TocGeometry", XtRString, sizeof(char *),
99         Offset(toc_geometry), XtRString, NULL},
100    {"viewGeometry", "ViewGeometry", XtRString, sizeof(char *),
101         Offset(view_geometry), XtRString, NULL},
102    {"compGeometry", "CompGeometry", XtRString, sizeof(char *),
103         Offset(comp_geometry), XtRString, NULL},
104    {"pickGeometry", "PickGeometry", XtRString, sizeof(char *),
105         Offset(pick_geometry), XtRString, NULL},
106    {"tocPercentage", "TocPercentage", XtRInt, sizeof(int),
107         Offset(toc_percentage), XtRImmediate, (XtPointer)33},
108
109    {"checkNewMail", "CheckNewMail", XtRBoolean, sizeof(Boolean),
110         Offset(new_mail_check), XtRImmediate, (XtPointer)True},
111    {"mailInterval", "Interval", XtRInt, sizeof(int),
112         Offset(mail_interval), XtRImmediate, (XtPointer)-1},
113    {"makeCheckpoints", "MakeCheckpoints", XtRBoolean, sizeof(Boolean),
114         Offset(make_checkpoints), XtRImmediate, (XtPointer)False},
115    {"checkpointInterval", "Interval", XtRInt, sizeof(int),
116         Offset(checkpoint_interval), XtRImmediate, (XtPointer)-1},
117    {"checkpointNameFormat", "CheckpointNameFormat",
118         XtRString, sizeof(char *),
119         Offset(checkpoint_name_format), XtRString, xmhCkpDefault},
120    {"rescanInterval", "Interval", XtRInt, sizeof(int),
121         Offset(rescan_interval), XtRImmediate, (XtPointer)-1},
122    {"checkFrequency", "CheckFrequency", XtRInt, sizeof(int),
123         Offset(check_frequency), XtRImmediate, (XtPointer)1},
124    {"mailWaitingFlag", "MailWaitingFlag", XtRBoolean, sizeof(Boolean),
125         Offset(mail_waiting_flag), XtRImmediate, (XtPointer)False},
126    {"newMailIconBitmap", "NewMailBitmap", XtRBitmap, sizeof(Pixmap),
127         Offset(new_mail_icon), XtRString, (XtPointer)"flagup"},
128    {"noMailIconBitmap", "NoMailBitmap", XtRBitmap, sizeof(Pixmap),
129         Offset(no_mail_icon), XtRString, (XtPointer)"flagdown"},
130    {"newMailBitmap", "NewMailBitmap", XtRBitmap, sizeof(Pixmap),
131         Offset(flag_up), XtRString, (XtPointer)"black6"},
132    {"noMailBitmap", "NoMailBitmap", XtRBitmap, sizeof(Pixmap),
133         Offset(flag_down), XtRString, (XtPointer)"box6"},
134
135    {"cursor", "Cursor", XtRCursor, sizeof(Cursor),
136         Offset(cursor), XtRString, "left_ptr"},
137    {"pointerColor", "PointerColor", XtRPixel, sizeof(Pixel),
138         Offset(pointer_color), XtRString, XtDefaultForeground},
139    {"showOnInc", "ShowOnInc", XtRBoolean, sizeof(Boolean),
140         Offset(show_on_inc), XtRImmediate, (XtPointer)True},
141    {"stickyMenu", "StickyMenu", XtRBoolean, sizeof(Boolean),   
142         Offset(sticky_menu), XtRImmediate, (XtPointer)False},
143    {"prefixWmAndIconName", "PrefixWmAndIconName", XtRBoolean, sizeof(Boolean),
144         Offset(prefix_wm_and_icon_name), XtRImmediate, (XtPointer)True},
145    {"reverseReadOrder", "ReverseReadOrder", XtRBoolean, sizeof(Boolean),
146         Offset(reverse_read_order), XtRImmediate, (XtPointer)False},
147    {"blockEventsOnBusy", "BlockEventsOnBusy", XtRBoolean, sizeof(Boolean),
148         Offset(block_events_on_busy), XtRImmediate, (XtPointer)True},
149    {"busyCursor", "BusyCursor", XtRCursor, sizeof(Cursor),
150         Offset(busy_cursor), XtRString, "watch"},
151    {"busyPointerColor", "BusyPointerColor", XtRPixel, sizeof(Pixel),
152         Offset(busy_pointer_color), XtRString, XtDefaultForeground},
153    {"commandButtonCount", "CommandButtonCount", XtRInt, sizeof(int),
154         Offset(command_button_count), XtRImmediate, (XtPointer)0},
155    {"appDefaultsVersion", "AppDefaultsVersion", XtRInt, sizeof(int),
156         Offset(app_defaults_version), XtRImmediate, (XtPointer)0},
157    {"banner", "Banner", XtRString, sizeof(char *),
158         Offset(banner), XtRString, "xmh    MIT X Consortium    R5"},
159    {"wmProtocolsTranslations", "WMProtocolsTranslations",
160         XtRTranslationTable, sizeof(XtTranslations),
161         Offset(wm_protocols_translations), XtRString,
162         "<Message>WM_PROTOCOLS: XmhWMProtocols()\n"}
163};
164
165#undef Offset
166
167static XrmOptionDescRec table[] = {
168    {"-debug",  "debug",                XrmoptionNoArg, "on"},
169    {"-flag",   "mailWaitingFlag",      XrmoptionNoArg, "on"},
170    {"-initial","initialFolder",        XrmoptionSepArg, NULL},
171    {"-path",   "mailPath",             XrmoptionSepArg, NULL},
172};
173
174/* Tell the user how to use this program. */
175Syntax(call)
176    char *call;
177{
178    (void) fprintf(stderr, "usage: %s [-path <path>] [-initial <folder>]\n",
179                   call);
180    exit(2);
181}
182
183
184static char *FixUpGeometry(geo, defwidth, defheight)
185char *geo;
186Dimension defwidth, defheight;
187{
188    int gbits;
189    int x, y;
190    unsigned int width, height;
191    if (geo == NULL) geo = app_resources.geometry;
192    x = y = 0;
193    gbits = XParseGeometry(geo, &x, &y, &width, &height);
194    if (!(gbits & WidthValue)) {
195        width = defwidth;
196        gbits |= WidthValue;
197    }
198    if (!(gbits & HeightValue)) {
199        height = defheight;
200        gbits |= HeightValue;
201    }
202    return CreateGeometry(gbits, x, y, (int) width, (int) height);
203}
204
205
206static _IOErrorHandler(dpy)
207    Display *dpy;
208{
209    extern char* SysErrMsg();
210    (void) fprintf (stderr,
211             "%s:\tfatal IO error after %lu requests (%lu known processed)\n",
212                    progName,
213                    NextRequest(dpy) - 1, LastKnownRequestProcessed(dpy));
214    (void) fprintf (stderr, "\t%d unprocessed events remaining.\r\n",
215                    QLength(dpy));
216
217    if (errno == EPIPE) {
218        (void) fprintf (stderr,
219     "\tThe connection was probably broken by a server shutdown or KillClient.\r\n");
220    }
221
222    Punt("Cannot continue from server error.");
223}
224
225/*ARGSUSED*/
226static void PopupAppDefaultsWarning(w, closure, event, cont)
227    Widget w;
228    XtPointer closure;
229    XEvent *event;
230    Boolean *cont;
231{
232    if (event->type == MapNotify) {
233        PopupError(w,
234"The minimum application default resources\n\
235were not properly installed; many features\n\
236will not work properly, if at all.  See the\n\
237xmh man page for further information."
238                   );
239        XtRemoveEventHandler(w, XtAllEvents, True,
240                             PopupAppDefaultsWarning, closure);
241    }
242}
243
244
245/* All the start-up initialization goes here. */
246
247InitializeWorld(argc, argv)
248int argc;
249char **argv;
250{
251    int l;
252    FILEPTR fid;
253    char str[500], str2[500], *ptr;
254    Scrn scrn;
255    XtAppContext app;
256    static XtActionsRec actions[] = {
257
258        /* general Xmh action procedures */
259
260        {"XmhClose",                    XmhClose},
261        {"XmhComposeMessage",           XmhComposeMessage},
262        {"XmhWMProtocols",              XmhWMProtocols},
263
264        /* actions upon folders */
265
266        {"XmhOpenFolder",               XmhOpenFolder},
267        {"XmhOpenFolderInNewWindow",    XmhOpenFolderInNewWindow},
268        {"XmhCreateFolder",             XmhCreateFolder},
269        {"XmhDeleteFolder",             XmhDeleteFolder},
270
271        /* actions to support easier folder manipulation */
272
273        {"XmhPushFolder",               XmhPushFolder},
274        {"XmhPopFolder",                XmhPopFolder},
275        {"XmhPopupFolderMenu",          XmhPopupFolderMenu},
276        {"XmhSetCurrentFolder",         XmhSetCurrentFolder},
277        {"XmhLeaveFolderButton",        XmhLeaveFolderButton},
278        {"XmhCheckForNewMail",          XmhCheckForNewMail},
279
280        /* actions upon the Table of Contents */
281
282        {"XmhIncorporateNewMail",       XmhIncorporateNewMail},
283        {"XmhCommitChanges",            XmhCommitChanges},
284        {"XmhPackFolder",               XmhPackFolder},
285        {"XmhSortFolder",               XmhSortFolder},
286        {"XmhForceRescan",              XmhForceRescan},
287        {"XmhReloadSeqLists",           XmhReloadSeqLists},
288
289        /* actions upon the currently selected message(s) */
290
291        {"XmhViewNextMessage",          XmhViewNextMessage},
292        {"XmhViewPreviousMessage",      XmhViewPreviousMessage},
293        {"XmhMarkDelete",               XmhMarkDelete},
294        {"XmhMarkMove",                 XmhMarkMove},
295        {"XmhMarkCopy",                 XmhMarkCopy},
296        {"XmhUnmark",                   XmhUnmark},
297        {"XmhViewInNewWindow",          XmhViewInNewWindow},
298        {"XmhReply",                    XmhReply},
299        {"XmhForward",                  XmhForward},
300        {"XmhUseAsComposition",         XmhUseAsComposition},
301        {"XmhPrint",                    XmhPrint},
302        {"XmhShellCommand",             XmhShellCommand},
303
304        /* actions upon sequences */
305
306        {"XmhPickMessages",             XmhPickMessages},
307        {"XmhOpenSequence",             XmhOpenSequence},
308        {"XmhAddToSequence",            XmhAddToSequence},
309        {"XmhRemoveFromSequence",       XmhRemoveFromSequence},
310        {"XmhDeleteSequence",           XmhDeleteSequence},
311
312        /* actions to support easier sequence manipulation */
313
314        {"XmhPushSequence",             XmhPushSequence},
315        {"XmhPopSequence",              XmhPopSequence},
316
317        /* actions upon the currently viewed message */
318
319        {"XmhCloseView",                XmhCloseView},
320        {"XmhViewReply",                XmhViewReply},
321        {"XmhViewForward",              XmhViewForward},
322        {"XmhViewUseAsComposition",     XmhViewUseAsComposition},
323        {"XmhEditView",                 XmhEditView},
324        {"XmhSaveView",                 XmhSaveView},
325        {"XmhPrintView",                XmhPrintView},
326        {"XmhViewMarkDelete",           XmhViewMarkDelete},
327
328        /* actions upon a composition, reply, or forward */
329
330        /* Close button                 XmhCloseView      (see above) */
331        {"XmhResetCompose",             XmhResetCompose},
332        /* Compose button               XmhComposeMessage (see above) */
333        {"XmhSave",                     XmhSave},
334        {"XmhSend",                     XmhSend},
335        {"XmhInsert",                   XmhInsert},
336
337        /* popup dialog box button action procedures */
338
339        {"XmhPromptOkayAction",         XmhPromptOkayAction},
340
341        /* retained for backward compatibility with user resources */
342       
343        {"XmhCancelPick",               XmhWMProtocols}
344    };
345
346    static Arg shell_args[] = {
347        {XtNinput, (XtArgVal)True},
348    };
349
350    ptr = rindex(argv[0], '/');
351    if (ptr) progName = ptr + 1;
352    else progName = argv[0];
353
354    toplevel = XtAppInitialize(&app, "Xmh", table, XtNumber(table),
355                               &argc, argv, FallbackResources,
356                               NULL, (Cardinal)0);
357    if (argc > 1) Syntax(progName);
358
359    XSetIOErrorHandler(_IOErrorHandler);
360
361    XtSetValues(toplevel, shell_args, XtNumber(shell_args));
362
363    theDisplay = XtDisplay(toplevel);
364
365    homeDir = XtNewString(getenv("HOME"));
366
367    XtGetApplicationResources( toplevel, (XtPointer)&app_resources,
368                               resources, XtNumber(resources),
369                               NULL, (Cardinal)0 );
370
371    if (app_resources.app_defaults_version < MIN_APP_DEFAULTS_VERSION)
372        XtAddEventHandler(toplevel, StructureNotifyMask, False,
373                          PopupAppDefaultsWarning, NULL);
374
375    if (app_resources.mail_waiting_flag) app_resources.new_mail_check = True;
376    if (app_resources.mail_interval == -1)
377        app_resources.mail_interval = app_resources.check_frequency;
378    if (app_resources.checkpoint_interval == -1)
379        app_resources.checkpoint_interval = 5 * app_resources.check_frequency;
380    if (app_resources.rescan_interval == -1)
381        app_resources.rescan_interval = 5 * app_resources.check_frequency;
382    ptr = strchr(app_resources.checkpoint_name_format, '%');
383    while (ptr && *(++ptr) != 'd')
384        ptr = strchr(app_resources.checkpoint_name_format, '%');
385    if (!ptr || strlen(app_resources.checkpoint_name_format) == 2)
386        app_resources.checkpoint_name_format = xmhCkpDefault;
387
388    ptr = getenv("MH");
389    if (!ptr) {
390        (void) sprintf(str, "%s/.mh_profile", homeDir);
391        ptr = str;
392    }
393    fid = myfopen(ptr, "r");
394    if (fid) {
395        while (ptr = ReadLine(fid)) {
396            char *cp;
397
398            (void) strncpy(str2, ptr, 5);
399            str2[5] = '\0';
400            for (cp = str2; *cp; cp++) {
401                if ('A' <= *cp && *cp <= 'Z')
402                    *cp = *cp - 'A' + 'a';
403            }
404            if (strcmp(str2, "path:") == 0) {
405                ptr += 5;
406                while (*ptr == ' ' || *ptr == '\t')
407                    ptr++;
408                (void) strcpy(str, ptr);
409            }
410        }
411        (void) myfclose(fid);
412    } else {
413        (void) strcpy(str, "Mail");
414    }
415    for (l=strlen(str) - 1; l>=0 && (str[l] == ' ' || str[l] == '\t'); l--)
416        str[l] = 0;
417    if (str[0] == '/')
418        (void) strcpy(str2, str);
419    else
420        (void) sprintf(str2, "%s/%s", homeDir, str);
421
422    (void) sprintf(str, "%s/draft", str2);
423    draftFile = XtNewString(str);
424    (void) sprintf(str, "%s/xmhdraft", str2);
425    xmhDraftFile = XtNewString(str);
426
427    if (app_resources.mail_path == NULL)
428        app_resources.mail_path = XtNewString(str2);
429
430    NullSource = (Widget) NULL;
431
432    l = strlen(app_resources.mh_path) - 1;
433    if (l > 0 && app_resources.mh_path[l] == '/')
434        app_resources.mh_path[l] = 0;
435
436    rootwidth = WidthOfScreen(XtScreen(toplevel));
437    rootheight = HeightOfScreen(XtScreen(toplevel));
438
439    app_resources.toc_geometry =
440        FixUpGeometry(app_resources.toc_geometry,
441                      (unsigned)rootwidth / 2, 3 * (unsigned)rootheight / 4);
442    app_resources.view_geometry =
443        FixUpGeometry(app_resources.view_geometry,
444                      (unsigned)rootwidth / 2, (unsigned)rootheight / 2);
445    app_resources.comp_geometry =
446        FixUpGeometry(app_resources.comp_geometry,
447                      (unsigned)rootwidth / 2, (unsigned)rootheight / 2);
448    app_resources.pick_geometry =
449        FixUpGeometry(app_resources.pick_geometry,
450                      (unsigned)rootwidth / 2, (unsigned)rootheight / 2);
451
452    numScrns = 0;
453    scrnList = (Scrn *) NULL;
454    NoMenuForButton = (Widget) &static_variable;
455    LastMenuButtonPressed = (Widget) NULL;
456
457    TocInit();
458    InitPick();
459    BBoxInit();
460
461    XtAppAddActions(app, actions, XtNumber(actions));
462    XtRegisterGrabAction(XmhPopupFolderMenu, True,
463                         ButtonPressMask | ButtonReleaseMask,
464                         GrabModeAsync, GrabModeAsync);
465    wm_protocols = XInternAtom(XtDisplay(toplevel), "WM_PROTOCOLS", False);
466    protocolList[0] = wm_delete_window =
467        XInternAtom(XtDisplay(toplevel), "WM_DELETE_WINDOW", False);
468    protocolList[1] = wm_save_yourself =
469        XInternAtom(XtDisplay(toplevel), "WM_SAVE_YOURSELF", False);
470
471    MenuItemBitmap =
472        XCreateBitmapFromData( XtDisplay(toplevel),
473                              RootWindowOfScreen( XtScreen(toplevel)),
474                              (char *)check_bits, check_width, check_height);
475
476    DEBUG("Making screen ... ")
477
478    scrn = CreateNewScrn(STtocAndView);
479
480    SetCursorColor(scrn->parent, app_resources.cursor,
481                   app_resources.pointer_color);
482    if (app_resources.block_events_on_busy)
483        SetCursorColor(scrn->parent, app_resources.busy_cursor,
484                       app_resources.busy_pointer_color);
485
486    DEBUG(" setting toc ... ")
487
488    TocSetScrn(InitialFolder, scrn);
489
490    DEBUG("done.\n");
491
492    MapScrn(scrn);
493}
Note: See TracBrowser for help on using the repository browser.