11abf7346Smrg/*
21abf7346Smrg
31abf7346SmrgCopyright (c) 1987, 1988  X Consortium
41abf7346Smrg
51abf7346SmrgPermission is hereby granted, free of charge, to any person obtaining
61abf7346Smrga copy of this software and associated documentation files (the
71abf7346Smrg"Software"), to deal in the Software without restriction, including
81abf7346Smrgwithout limitation the rights to use, copy, modify, merge, publish,
91abf7346Smrgdistribute, sublicense, and/or sell copies of the Software, and to
101abf7346Smrgpermit persons to whom the Software is furnished to do so, subject to
111abf7346Smrgthe following conditions:
121abf7346Smrg
131abf7346SmrgThe above copyright notice and this permission notice shall be included
141abf7346Smrgin all copies or substantial portions of the Software.
151abf7346Smrg
161abf7346SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
171abf7346SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
181abf7346SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
191abf7346SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
201abf7346SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
211abf7346SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
221abf7346SmrgOTHER DEALINGS IN THE SOFTWARE.
231abf7346Smrg
241abf7346SmrgExcept as contained in this notice, the name of the X Consortium shall
251abf7346Smrgnot be used in advertising or otherwise to promote the sale, use or
261abf7346Smrgother dealings in this Software without prior written authorization
271abf7346Smrgfrom the X Consortium.
281abf7346Smrg
291abf7346Smrg*/
301abf7346Smrg
311abf7346Smrg/*
321abf7346Smrg * xman - X window system manual page display program.
331abf7346Smrg * Author:    Chris D. Peterson, MIT Project Athena
341abf7346Smrg * Created:   October 29, 1987
351abf7346Smrg */
3623a8d56dSmrg#ifdef HAVE_CONFIG_H
3723a8d56dSmrg# include "config.h"
3823a8d56dSmrg#endif
391abf7346Smrg
401abf7346Smrg#include <sys/types.h>
411abf7346Smrg#include <sys/stat.h>
421abf7346Smrg#include "globals.h"
431abf7346Smrg#include "vendor.h"
441abf7346Smrg
4523a8d56dSmrg#ifdef RELEASE_VERSION
4623a8d56dSmrg#define XMAN_VERSION "Xman Version " PACKAGE_VERSION " - X11R" RELEASE_VERSION
4723a8d56dSmrg#else
4823a8d56dSmrg#define XMAN_VERSION "Xman Version " PACKAGE_VERSION
4923a8d56dSmrg#endif
5023a8d56dSmrg
511abf7346Smrgstatic void PutUpManpage(ManpageGlobals * man_globals, FILE * file);
521abf7346Smrgstatic void ToggleBothShownState(ManpageGlobals * man_globals);
531abf7346Smrg
541abf7346Smrg/*	Function Name: OptionCallback
551abf7346Smrg *	Description: This is the callback function for the callback menu.
5636ffeb23Smrg *	Arguments: w - the widget we are calling back from.
5736ffeb23Smrg *                 globals_pointer - a pointer to the pseudo globals structure
581abf7346Smrg *                                  for this manpage.
591abf7346Smrg *                 junk - (call data) not used.
601abf7346Smrg *	Returns: none.
611abf7346Smrg */
621abf7346Smrg
631abf7346Smrg/*ARGSUSED*/
641abf7346Smrgvoid
651abf7346SmrgOptionCallback(Widget w, XtPointer pointer, XtPointer junk)
661abf7346Smrg{
6736ffeb23Smrg    ManpageGlobals *man_globals = (ManpageGlobals *) pointer;
6836ffeb23Smrg    String params;
6936ffeb23Smrg    Cardinal num_params = 1;
7036ffeb23Smrg
7136ffeb23Smrg    if (w == man_globals->search_entry)
7236ffeb23Smrg        PopupSearch(XtParent(w), NULL, NULL, NULL);
7336ffeb23Smrg    else if (w == man_globals->dir_entry) {     /* Put Up Directory */
7436ffeb23Smrg        params = "Directory";
7536ffeb23Smrg        GotoPage(XtParent(w), NULL, &params, &num_params);
7636ffeb23Smrg    }
7736ffeb23Smrg    else if (w == man_globals->manpage_entry) { /* Put Up Man Page */
7836ffeb23Smrg        params = "ManualPage";
7936ffeb23Smrg        GotoPage(XtParent(w), NULL, &params, &num_params);
8036ffeb23Smrg    }
8136ffeb23Smrg    else if (w == man_globals->help_entry)      /* Help */
8236ffeb23Smrg        PopupHelp(XtParent(w), NULL, NULL, NULL);
8336ffeb23Smrg    else if (w == man_globals->both_screens_entry)      /*Toggle Both_Shown State. */
8436ffeb23Smrg        ToggleBothShownState(man_globals);
8536ffeb23Smrg    else if (w == man_globals->remove_entry)    /* Kill the manpage */
8636ffeb23Smrg        RemoveThisManpage(XtParent(w), NULL, NULL, NULL);
8736ffeb23Smrg    else if (w == man_globals->open_entry)      /* Open new manpage */
8836ffeb23Smrg        CreateNewManpage(XtParent(w), NULL, NULL, NULL);
8936ffeb23Smrg    else if (w == man_globals->version_entry)   /* Get version */
9036ffeb23Smrg        ShowVersion(XtParent(w), NULL, NULL, NULL);
9136ffeb23Smrg    else if (w == man_globals->quit_entry)      /* Quit. */
9236ffeb23Smrg        Quit(XtParent(w), NULL, NULL, NULL);
931abf7346Smrg}
941abf7346Smrg
951abf7346Smrg/*      Function Name: ToggleBothShownState;
961abf7346Smrg *      Description: toggles the state of the both shown feature.
971abf7346Smrg *      Arguments: man_globals - the man globals structure.
981abf7346Smrg *      Returns: none.
991abf7346Smrg */
1001abf7346Smrg
1011abf7346Smrg/*
1021abf7346Smrg * I did not have a two state widget, which is the way this
1031abf7346Smrg * should really be done.  1/22/88 - CDP.
1041abf7346Smrg */
1051abf7346Smrg
1061abf7346Smrgstatic void
1071abf7346SmrgToggleBothShownState(ManpageGlobals * man_globals)
1081abf7346Smrg{
10936ffeb23Smrg    const char *label_str;
11036ffeb23Smrg    Arg arglist[1];
11136ffeb23Smrg
11236ffeb23Smrg    if (man_globals->both_shown == TRUE) {
11336ffeb23Smrg        label_str = SHOW_BOTH;
11436ffeb23Smrg        if (man_globals->dir_shown)
11536ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.manpage);
11636ffeb23Smrg        else
11736ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.directory);
11836ffeb23Smrg    }
11936ffeb23Smrg    else {
12036ffeb23Smrg        Widget manpage = man_globals->manpagewidgets.manpage;
12136ffeb23Smrg        Widget dir = man_globals->manpagewidgets.directory;
12236ffeb23Smrg
12336ffeb23Smrg        label_str = SHOW_ONE;
12436ffeb23Smrg
12536ffeb23Smrg        XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height);
12636ffeb23Smrg        XtSetValues(dir, arglist, (Cardinal) 1);
12736ffeb23Smrg
12836ffeb23Smrg        if (!man_globals->dir_shown) {
12936ffeb23Smrg            XtUnmanageChild(manpage);
13036ffeb23Smrg            XtManageChild(dir);
13136ffeb23Smrg        }
13236ffeb23Smrg        XtManageChild(manpage);
13336ffeb23Smrg    }
13436ffeb23Smrg    man_globals->both_shown = !man_globals->both_shown;
1351abf7346Smrg
1361abf7346Smrg    if (man_globals->dir_shown)
13736ffeb23Smrg        ChangeLabel(man_globals->label,
13836ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
1391abf7346Smrg    else
14036ffeb23Smrg        ChangeLabel(man_globals->label, man_globals->manpage_title);
14136ffeb23Smrg
14236ffeb23Smrg    XtSetArg(arglist[0], XtNlabel, label_str);
14336ffeb23Smrg    XtSetValues(man_globals->both_screens_entry, arglist, ONE);
14436ffeb23Smrg
14536ffeb23Smrg    /* if both are shown there is no need to switch between the two. */
14636ffeb23Smrg
14736ffeb23Smrg    XtSetArg(arglist[0], XtNsensitive, !man_globals->both_shown);
14836ffeb23Smrg    XtSetValues(man_globals->manpage_entry, arglist, ONE);
14936ffeb23Smrg    XtSetValues(man_globals->dir_entry, arglist, ONE);
1501abf7346Smrg}
1511abf7346Smrg
1521abf7346Smrg/*	Function Name: Popup
1531abf7346Smrg *	Description: This function pops up the given widget under the cursor.
1541abf7346Smrg *	Arguments: w - the widget to popup.
1551abf7346Smrg *                 grab_kind - the kind of grab to register.
1561abf7346Smrg *	Returns: none
1571abf7346Smrg */
1581abf7346Smrg
15936ffeb23Smrg/* How far off the top of the widget to have the initial cursor position. */
1601abf7346Smrg
1611abf7346Smrg#define OFF_OF_TOP 25
1621abf7346Smrg
1631abf7346Smrgvoid
1641abf7346SmrgPopup(Widget w, XtGrabKind grab_kind)
1651abf7346Smrg{
16636ffeb23Smrg    int x_root, y_root, y_pos, garbage;
16736ffeb23Smrg    unsigned int mask;
16836ffeb23Smrg    Window junk_window;
1691abf7346Smrg
17036ffeb23Smrg    XQueryPointer(XtDisplay(w), XtWindow(w), &junk_window, &junk_window,
17136ffeb23Smrg                  &x_root, &y_root, &garbage, &garbage, &mask);
1721abf7346Smrg
17336ffeb23Smrg    y_pos = OFF_OF_TOP - Height(w) / 2 - BorderWidth(w);
17436ffeb23Smrg    PositionCenter(w, x_root, y_root, y_pos, 0, 2, 2);
17536ffeb23Smrg    XtPopup(w, grab_kind);
1761abf7346Smrg}
1771abf7346Smrg
1781abf7346Smrg/*	Function Name: PutUpManpage
1791abf7346Smrg *	Description: Puts the manpage on the display.
18036ffeb23Smrg *	Arguments: man_globals - a pointer to the pseudo globals structure
1811abf7346Smrg *                                  for this manpage.
1821abf7346Smrg *                 file - the file to display.
1831abf7346Smrg *	Returns: none.
1841abf7346Smrg */
1851abf7346Smrg
1861abf7346Smrgstatic void
1871abf7346SmrgPutUpManpage(ManpageGlobals * man_globals, FILE * file)
1881abf7346Smrg{
18936ffeb23Smrg    String params = "ManualPage";
19036ffeb23Smrg    Cardinal num_params = 1;
1911abf7346Smrg
19236ffeb23Smrg    if (file == NULL)
19336ffeb23Smrg        return;
1941abf7346Smrg
19536ffeb23Smrg    OpenFile(man_globals, file);
19636ffeb23Smrg
19736ffeb23Smrg    if (!man_globals->both_shown) {
19836ffeb23Smrg        Arg arglist[1];
19936ffeb23Smrg
20036ffeb23Smrg        XtSetArg(arglist[0], XtNsensitive, TRUE);
20136ffeb23Smrg        XtSetValues(man_globals->manpage_entry, arglist, ONE);
20236ffeb23Smrg        XtSetValues(man_globals->both_screens_entry, arglist, ONE);
20336ffeb23Smrg    }
20436ffeb23Smrg    GotoPage(man_globals->manpagewidgets.manpage, NULL, &params, &num_params);
2051abf7346Smrg}
2061abf7346Smrg
2071abf7346Smrg/*	Function Name: DirectoryHandler
2081abf7346Smrg *	Description: This is the callback function for the directory listings.
20936ffeb23Smrg *	Arguments: w - the widget we are calling back from.
21036ffeb23Smrg *                 global_pointer - the pointer to the pseudo global structure
2111abf7346Smrg *                                  associated with this manpage.
2121abf7346Smrg *                 ret_val - return value from the list widget.
2131abf7346Smrg *	Returns: none.
2141abf7346Smrg */
2151abf7346Smrg
2161abf7346Smrgvoid
2171abf7346SmrgDirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val)
2181abf7346Smrg{
21936ffeb23Smrg    FILE *file;                 /* The manpage file. */
22036ffeb23Smrg    ManpageGlobals *man_globals = (ManpageGlobals *) global_pointer;
22136ffeb23Smrg    XawListReturnStruct *ret_struct = (XawListReturnStruct *) ret_val;
22236ffeb23Smrg
22336ffeb23Smrg    file = FindManualFile(man_globals, man_globals->current_directory,
22436ffeb23Smrg                          ret_struct->list_index);
22536ffeb23Smrg    PutUpManpage(man_globals, file);
22636ffeb23Smrg    if ((file != NULL) && (file != man_globals->curr_file)) {
22736ffeb23Smrg        fclose(file);
22836ffeb23Smrg    }
2291abf7346Smrg}
2301abf7346Smrg
2311abf7346Smrg/*	Function Name: DirPopupCallback
2321abf7346Smrg *	Description: This is the callback function for the callback menu.
23336ffeb23Smrg *	Arguments: w - the widget we are calling back from.
23436ffeb23Smrg *                 pointer - a pointer to the pseudo globals structure
2351abf7346Smrg *                                  for this manpage.
2361abf7346Smrg *                 junk - (call data) not used.
2371abf7346Smrg *	Returns: none.
2381abf7346Smrg */
2391abf7346Smrg
2401abf7346Smrg/*ARGSUSED*/
2411abf7346Smrgvoid
2421abf7346SmrgDirPopupCallback(Widget w, XtPointer pointer, XtPointer junk)
2431abf7346Smrg{
24436ffeb23Smrg    ManpageGlobals *man_globals;
24536ffeb23Smrg    MenuStruct *menu_struct;
24636ffeb23Smrg    Widget parent;
24736ffeb23Smrg    int number;
24836ffeb23Smrg    int current_box;
24936ffeb23Smrg
25036ffeb23Smrg    menu_struct = (MenuStruct *) pointer;
25136ffeb23Smrg    man_globals = (ManpageGlobals *) menu_struct->data;
25236ffeb23Smrg
25336ffeb23Smrg    number = menu_struct->number;
25436ffeb23Smrg    current_box = man_globals->current_directory;
25536ffeb23Smrg
25636ffeb23Smrg    /* We have used this guy, pop down the menu. */
25736ffeb23Smrg
25836ffeb23Smrg    if (number != current_box) {
25936ffeb23Smrg        /* This is the only one that we know has a parent. */
26036ffeb23Smrg        parent = XtParent(man_globals->manpagewidgets.box[INITIAL_DIR]);
26136ffeb23Smrg
26236ffeb23Smrg        MakeDirectoryBox(man_globals, parent,
26336ffeb23Smrg                         man_globals->manpagewidgets.box + number, number);
26436ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.box[current_box]);
26536ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.box[number]);
26636ffeb23Smrg
26736ffeb23Smrg        XawListUnhighlight(man_globals->manpagewidgets.box[current_box]);
26836ffeb23Smrg        ChangeLabel(man_globals->label, man_globals->section_name[number]);
26936ffeb23Smrg        man_globals->current_directory = number;
27036ffeb23Smrg    }
27136ffeb23Smrg
27236ffeb23Smrg    /* put up directory. */
27336ffeb23Smrg    if (!man_globals->both_shown) {
27436ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.manpage);
27536ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.directory);
27636ffeb23Smrg    }
2771abf7346Smrg}
27836ffeb23Smrg
2791abf7346Smrg/************************************************************
2801abf7346Smrg *
2811abf7346Smrg * Action Routines.
2821abf7346Smrg *
2831abf7346Smrg ************************************************************/
2841abf7346Smrg
2851abf7346Smrg/*	Function Name: SaveFormattedPage
2861abf7346Smrg *	Description: This is the action routine may save the manpage.
2871abf7346Smrg *      Arguments: w - any widget in the widget tree.
2881abf7346Smrg *                 event - NOT USED.
28936ffeb23Smrg *                 params, num_params - the parameters passed to the action
2901abf7346Smrg *                                      routine, can be either Manpage or
2911abf7346Smrg *                                      Directory.
2921abf7346Smrg *      Returns: none.
2931abf7346Smrg */
2941abf7346Smrg
2951abf7346Smrg/*ARGSUSED*/
2961abf7346Smrgvoid
29736ffeb23SmrgSaveFormattedPage(Widget w, XEvent * event, String * params,
29836ffeb23Smrg                  Cardinal * num_params)
2991abf7346Smrg{
30036ffeb23Smrg    ManpageGlobals *man_globals;
30136ffeb23Smrg    char cmdbuf[BUFSIZ], error_buf[BUFSIZ];
3021abf7346Smrg
30336ffeb23Smrg    if (*num_params != 1) {
30436ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
30536ffeb23Smrg                     "Xman - SaveFormattedPage: This action routine requires one argument.");
30636ffeb23Smrg        return;
30736ffeb23Smrg    }
3081abf7346Smrg
30936ffeb23Smrg    man_globals = GetGlobals(w);
3101abf7346Smrg
3111abf7346Smrg/*
3121abf7346Smrg * If we are not active then take no action.
3131abf7346Smrg */
3141abf7346Smrg
315b096d6f4Swiz    if (man_globals->tempfile[0] == '\0')
31636ffeb23Smrg        return;
31736ffeb23Smrg
31836ffeb23Smrg    switch (params[0][0]) {
31936ffeb23Smrg    case 'S':
32036ffeb23Smrg    case 's':
3211abf7346Smrg
32236ffeb23Smrg        if (!man_globals->compress)
32336ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s %s %s", COPY,
32436ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
32536ffeb23Smrg        else if (man_globals->gzip)
32636ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s < %s > %s", GZIP_COMPRESS,
32736ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
32836ffeb23Smrg        else
32936ffeb23Smrg            snprintf(cmdbuf, sizeof(cmdbuf), "%s < %s > %s", COMPRESS,
33036ffeb23Smrg                     man_globals->tempfile, man_globals->save_file);
3311abf7346Smrg
33236ffeb23Smrg        if (!system(cmdbuf)) {
33336ffeb23Smrg            /* make sure the formatted man page is fully accessible by the world */
33436ffeb23Smrg            if (chmod(man_globals->save_file, CHMOD_MODE) != 0) {
33536ffeb23Smrg                snprintf(error_buf, sizeof(error_buf),
33636ffeb23Smrg                         "Couldn't set permissions on formatted man page '%s'.\n",
33736ffeb23Smrg                         man_globals->save_file);
33836ffeb23Smrg                PopupWarning(man_globals, error_buf);
33936ffeb23Smrg            }
34036ffeb23Smrg        }
34136ffeb23Smrg        else {
34236ffeb23Smrg            snprintf(error_buf, sizeof(error_buf),
34336ffeb23Smrg                     "Error while executing the command '%s'.\n", cmdbuf);
34436ffeb23Smrg            PopupWarning(man_globals, error_buf);
34536ffeb23Smrg        }
34636ffeb23Smrg        break;
34736ffeb23Smrg    case 'C':
34836ffeb23Smrg    case 'c':
34936ffeb23Smrg        break;
35036ffeb23Smrg    default:
35136ffeb23Smrg        PopupWarning(man_globals, "Xman - SaveFormattedPage: "
35236ffeb23Smrg                     "Unknown argument must be either 'Save' or 'Cancel'.");
35336ffeb23Smrg        return;
3541abf7346Smrg    }
35536ffeb23Smrg
3561abf7346Smrg/*
3571abf7346Smrg * We do not need the filename anymore, and have the fd open.
35836ffeb23Smrg * We will remove it.
3591abf7346Smrg */
3601abf7346Smrg
36136ffeb23Smrg    remove(man_globals->tempfile);
36236ffeb23Smrg    XtPopdown(XtParent(XtParent(w)));
3631abf7346Smrg}
3641abf7346Smrg
3651abf7346Smrg/*      Function Name: GotoPage
3661abf7346Smrg *      Description: The Action routine that switches over to the manpage
3671abf7346Smrg *                   or directory.
3681abf7346Smrg *      Arguments: w - any widget in the widget tree.
3691abf7346Smrg *                 event - NOT USED.
37036ffeb23Smrg *                 params, num_params - the parameters passed to the action
3711abf7346Smrg *                                      routine, can be either Manpage or
3721abf7346Smrg *                                      Directory.
3731abf7346Smrg *      Returns: none.
3741abf7346Smrg */
3751abf7346Smrg
3761abf7346Smrg/*ARGSUSED*/
3771abf7346Smrgvoid
3781abf7346SmrgGotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params)
3791abf7346Smrg{
38036ffeb23Smrg    ManpageGlobals *man_globals;
38136ffeb23Smrg    Arg arglist[1];
38236ffeb23Smrg    Boolean sensitive;
38336ffeb23Smrg
38436ffeb23Smrg    if (*num_params != 1) {
38536ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
38636ffeb23Smrg                     "Xman - GotoPage: This action routine requires one argument.");
38736ffeb23Smrg        return;
38836ffeb23Smrg    }
38936ffeb23Smrg
39036ffeb23Smrg    man_globals = GetGlobals(w);
39136ffeb23Smrg
39236ffeb23Smrg    if (man_globals->both_shown) {
39336ffeb23Smrg        ChangeLabel(man_globals->label,
39436ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
39536ffeb23Smrg        return;
39636ffeb23Smrg    }
39736ffeb23Smrg
39836ffeb23Smrg    switch (params[0][0]) {
39936ffeb23Smrg    case 'M':
40036ffeb23Smrg    case 'm':
40136ffeb23Smrg        XtSetArg(arglist[0], XtNsensitive, &sensitive);
40236ffeb23Smrg        XtGetValues(man_globals->manpage_entry, arglist, ONE);
40336ffeb23Smrg        if (sensitive) {
40436ffeb23Smrg            ChangeLabel(man_globals->label, man_globals->manpage_title);
40536ffeb23Smrg            XtUnmanageChild(man_globals->manpagewidgets.directory);
40636ffeb23Smrg            XtManageChild(man_globals->manpagewidgets.manpage);
40736ffeb23Smrg            man_globals->dir_shown = FALSE;
40836ffeb23Smrg        }
40936ffeb23Smrg        break;
41036ffeb23Smrg    case 'D':
41136ffeb23Smrg    case 'd':
41236ffeb23Smrg        ChangeLabel(man_globals->label,
41336ffeb23Smrg                    man_globals->section_name[man_globals->current_directory]);
41436ffeb23Smrg        XtUnmanageChild(man_globals->manpagewidgets.manpage);
41536ffeb23Smrg        XtManageChild(man_globals->manpagewidgets.directory);
41636ffeb23Smrg        man_globals->dir_shown = TRUE;
41736ffeb23Smrg        break;
41836ffeb23Smrg    default:
41936ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
42036ffeb23Smrg                     "Xman - GotoPage: Unknown argument must be "
42136ffeb23Smrg                     "either Manpage or Directory.");
42236ffeb23Smrg        return;
4231abf7346Smrg    }
4241abf7346Smrg}
4251abf7346Smrg
4261abf7346Smrg/*      Function Name: Quit.
4271abf7346Smrg *      Description: Quits Xman.
4281abf7346Smrg *      Arguments: w - any widget.
4291abf7346Smrg *                 event - NOT USED.
4301abf7346Smrg *                 params, num_params - NOT USED.
4311abf7346Smrg *      Returns: none.
4321abf7346Smrg */
4331abf7346Smrg
4341abf7346Smrg/*ARGSUSED*/
43536ffeb23Smrgvoid
4361abf7346SmrgQuit(Widget w, XEvent * event, String * params, Cardinal * num_params)
4371abf7346Smrg{
43836ffeb23Smrg    XtAppSetExitFlag(XtWidgetToApplicationContext(w));
4391abf7346Smrg}
4401abf7346Smrg
4411abf7346Smrg/*      Function Name: PopupHelp
4421abf7346Smrg *      Description: Pops up xman's help.
4431abf7346Smrg *      Arguments: w - NOT USED.
4441abf7346Smrg *                 event - NOT USED.
4451abf7346Smrg *                 params, num_params - NOT USED.
4461abf7346Smrg *      Returns: none.
4471abf7346Smrg */
4481abf7346Smrg
4491abf7346Smrg/*ARGSUSED*/
45036ffeb23Smrgvoid
4511abf7346SmrgPopupHelp(Widget w, XEvent * event, String * params, Cardinal * num_params)
4521abf7346Smrg{
45336ffeb23Smrg    if (MakeHelpWidget())
45436ffeb23Smrg        XtPopup(help_widget, XtGrabNone);
4551abf7346Smrg}
4561abf7346Smrg
4571abf7346Smrg/*      Function Name: PopupSearch
4581abf7346Smrg *      Description: Pops up this manual pages search widget.
4591abf7346Smrg *      Arguments: w - any widget in this manpage.
4601abf7346Smrg *                 event - NOT USED.
4611abf7346Smrg *                 params, num_params - NOT USED.
4621abf7346Smrg *      Returns: none.
4631abf7346Smrg */
4641abf7346Smrg
4651abf7346Smrg/*ARGSUSED*/
46636ffeb23Smrgvoid
4671abf7346SmrgPopupSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
4681abf7346Smrg{
46936ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
47036ffeb23Smrg
47136ffeb23Smrg    if (man_globals->search_widget) {
47236ffeb23Smrg        if (!XtIsRealized(man_globals->search_widget)) {
47336ffeb23Smrg            XtRealizeWidget(man_globals->search_widget);
47436ffeb23Smrg            AddCursor(man_globals->search_widget,
47536ffeb23Smrg                      resources.cursors.search_entry);
4766448b35cSmrg/*
4776448b35cSmrg * Set up ICCCM delete window.
4786448b35cSmrg */
4796448b35cSmrg            XtOverrideTranslations(man_globals->search_widget,
4806448b35cSmrg              XtParseTranslationTable("<Message>WM_PROTOCOLS: RemoveSearch()"));
4816448b35cSmrg            XSetWMProtocols(XtDisplay(man_globals->search_widget),
4826448b35cSmrg                            XtWindow(man_globals->search_widget),
4836448b35cSmrg                            &wm_delete_window, 1);
48436ffeb23Smrg        }
48536ffeb23Smrg        Popup(man_globals->search_widget, XtGrabNone);
4861abf7346Smrg    }
4871abf7346Smrg}
4881abf7346Smrg
4896448b35cSmrg/*      Function Name: RemoveSearch
4906448b35cSmrg *      Description: Removes this search widget.
4916448b35cSmrg *      Arguments: w - search widget
4926448b35cSmrg *                 event - NOT USED.
4936448b35cSmrg *                 params, num_params - NOT USED.
4946448b35cSmrg *      Returns: none.
4956448b35cSmrg */
4966448b35cSmrg
4976448b35cSmrg/*ARGSUSED*/
4986448b35cSmrgvoid
4996448b35cSmrgRemoveSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
5006448b35cSmrg{
5016448b35cSmrg    XtPopdown(w);
5026448b35cSmrg}
5036448b35cSmrg
5041abf7346Smrg/*      Function Name: CreateNewManpage
5051abf7346Smrg *      Description: Creates A New Manual Page.
5061abf7346Smrg *      Arguments: w - NOT USED.
5071abf7346Smrg *                 event - NOT USED.
5081abf7346Smrg *                 params, num_params - NOT USED.
5091abf7346Smrg *      Returns: none.
5101abf7346Smrg */
5111abf7346Smrg
5121abf7346Smrg/*ARGSUSED*/
51336ffeb23Smrgvoid
51436ffeb23SmrgCreateNewManpage(Widget w, XEvent * event, String * params,
51536ffeb23Smrg                 Cardinal * num_params)
5161abf7346Smrg{
51736ffeb23Smrg    if (CreateManpage(NULL))
51836ffeb23Smrg        man_pages_shown++;
5191abf7346Smrg}
5201abf7346Smrg
5211abf7346Smrg/*      Function Name: RemoveThisManpage
5221abf7346Smrg *      Description: Removes a manual page.
5231abf7346Smrg *      Arguments: w - any widget in the manpage.
5241abf7346Smrg *                 event - NOT USED.
5251abf7346Smrg *                 params, num_params - NOT USED.
5261abf7346Smrg *      Returns: none.
5271abf7346Smrg */
5281abf7346Smrg
5291abf7346Smrg/*ARGSUSED*/
53036ffeb23Smrgvoid
53136ffeb23SmrgRemoveThisManpage(Widget w, XEvent * event, String * params,
53236ffeb23Smrg                  Cardinal * num_params)
5331abf7346Smrg{
53436ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
53536ffeb23Smrg
53636ffeb23Smrg    if (man_globals->This_Manpage != help_widget) {
53736ffeb23Smrg        RemoveGlobals(man_globals->This_Manpage);
53836ffeb23Smrg        XtDestroyWidget(man_globals->This_Manpage);
53936ffeb23Smrg
54036ffeb23Smrg        XtFree((char *) man_globals->section_name);
54136ffeb23Smrg        XtFree((char *) man_globals->manpagewidgets.box);
54236ffeb23Smrg        XtFree((char *) man_globals);
54336ffeb23Smrg
54436ffeb23Smrg        if ((--man_pages_shown) == 0)
54536ffeb23Smrg            Quit(w, NULL, NULL, NULL);
54636ffeb23Smrg    }
54736ffeb23Smrg    else
54836ffeb23Smrg        XtPopdown(help_widget);
5491abf7346Smrg}
5501abf7346Smrg
5511abf7346Smrg/*      Function Name: Search
5521abf7346Smrg *      Description: Actually performs a search.
5531abf7346Smrg *      Arguments: w - any widget in the manpage.
5541abf7346Smrg *                 event - NOT USED.
5551abf7346Smrg *                 params, num_params - NOT USED.
5561abf7346Smrg *      Returns: none.
5571abf7346Smrg */
5581abf7346Smrg
5591abf7346Smrg/*ARGSUSED*/
56036ffeb23Smrgvoid
5611abf7346SmrgSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
5621abf7346Smrg{
56336ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
56436ffeb23Smrg    FILE *file = NULL;
56536ffeb23Smrg
56636ffeb23Smrg    XtPopdown(XtParent(XtParent(w)));   /* popdown the search widget */
56736ffeb23Smrg
56836ffeb23Smrg    if ((*num_params < 1) || (*num_params > 2)) {
56936ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
57036ffeb23Smrg                     "Xman - Search: This action routine requires one or two arguments.");
57136ffeb23Smrg        return;
57236ffeb23Smrg    }
57336ffeb23Smrg
57436ffeb23Smrg    switch (params[0][0]) {
57536ffeb23Smrg    case 'a':
57636ffeb23Smrg    case 'A':
57736ffeb23Smrg        file = DoSearch(man_globals, APROPOS);
57836ffeb23Smrg        break;
57936ffeb23Smrg    case 'm':
58036ffeb23Smrg    case 'M':
58136ffeb23Smrg        file = DoSearch(man_globals, MANUAL);
58236ffeb23Smrg        break;
58336ffeb23Smrg    case 'c':
58436ffeb23Smrg    case 'C':
58536ffeb23Smrg        file = NULL;
58636ffeb23Smrg        break;
5871abf7346Smrg    default:
58836ffeb23Smrg        XtAppWarning(XtWidgetToApplicationContext(w),
58936ffeb23Smrg                     "Xman - Search: First parameter unknown.");
59036ffeb23Smrg        file = NULL;
59136ffeb23Smrg        break;
59236ffeb23Smrg    }
59336ffeb23Smrg
59436ffeb23Smrg    if (*num_params == 2)
59536ffeb23Smrg        switch (params[1][0]) {
59636ffeb23Smrg        case 'O':
59736ffeb23Smrg        case 'o':
59836ffeb23Smrg            if (file != NULL) {
5993653852eSmrg                Widget w2;
60036ffeb23Smrg                char *label;
60136ffeb23Smrg
6023653852eSmrg                w2 = CreateManpage(file);
6033653852eSmrg                if (w2) {
60436ffeb23Smrg                    man_pages_shown++;
60536ffeb23Smrg
60636ffeb23Smrg                    /* Put title into new manual page. */
60736ffeb23Smrg
60836ffeb23Smrg                    label = man_globals->manpage_title;
6093653852eSmrg                    man_globals = GetGlobals(w2);
61036ffeb23Smrg                    strcpy(man_globals->manpage_title, label);
61136ffeb23Smrg                    ChangeLabel(man_globals->label, label);
61236ffeb23Smrg                }
61336ffeb23Smrg            }
61436ffeb23Smrg            break;
61536ffeb23Smrg        default:
61636ffeb23Smrg            XtAppWarning(XtWidgetToApplicationContext(w),
61736ffeb23Smrg                         "Xman - Search: Second parameter unknown.");
61836ffeb23Smrg            break;
61936ffeb23Smrg        }
62036ffeb23Smrg    else {
62136ffeb23Smrg        PutUpManpage(man_globals, file);
62236ffeb23Smrg    }
62336ffeb23Smrg    if ((file != NULL) && (file != man_globals->curr_file)) {
62436ffeb23Smrg        fclose(file);
6251abf7346Smrg    }
6261abf7346Smrg}
6271abf7346Smrg
6281abf7346Smrg
6291abf7346Smrg/*      Function Name: ShowVersion
6301abf7346Smrg *      Description: Show current version.
6311abf7346Smrg *      Arguments: w - any widget in the manpage.
6321abf7346Smrg *                 event - NOT USED.
6331abf7346Smrg *                 params, num_params - NOT USED.
6341abf7346Smrg *      Returns: none.
6351abf7346Smrg */
6361abf7346Smrg
6371abf7346Smrg/*ARGSUSED*/
63836ffeb23Smrgvoid
6391abf7346SmrgShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params)
6401abf7346Smrg{
64136ffeb23Smrg    ManpageGlobals *man_globals = GetGlobals(w);
64236ffeb23Smrg
64336ffeb23Smrg    ChangeLabel(man_globals->label, XMAN_VERSION);
6441abf7346Smrg}
645