xenocara/app/xman/main.c

299 lines
10 KiB
C
Raw Normal View History

2006-11-25 13:07:29 -07:00
/*
Copyright (c) 1987, 1988 X Consortium
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the X Consortium.
*/
/*
* xman - X window system manual page display program.
* Author: Chris D. Peterson, MIT Project Athena
* Created: October 22, 1987
*/
#include "globals.h"
#ifndef ZERO
#include <X11/Xaw/Cardinals.h>
#endif /* ZERO */
2013-09-28 10:22:59 -06:00
static void ArgError(int argc, char **argv);
2006-11-25 13:07:29 -07:00
static void AdjustDefResources(void);
#define Offset(field) (XtOffsetOf(Xman_Resources , field))
static XtResource my_resources[] = {
2013-09-28 10:22:59 -06:00
{"directoryFontNormal", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
2006-11-25 13:07:29 -07:00
Offset(fonts.directory), XtRString, DIRECTORY_NORMAL},
2013-09-28 10:22:59 -06:00
{"bothShown", XtCBoolean, XtRBoolean, sizeof(Boolean),
2006-11-25 13:07:29 -07:00
Offset(both_shown_initial), XtRString, "False"},
2013-09-28 10:22:59 -06:00
{"directoryHeight", "DirectoryHeight", XtRInt, sizeof(int),
Offset(directory_height), XtRString, "150"},
{"topCursor", XtCCursor, XtRCursor, sizeof(Cursor),
2006-11-25 13:07:29 -07:00
Offset(cursors.top), XtRString, XMAN_CURSOR},
2013-09-28 10:22:59 -06:00
{"helpCursor", XtCCursor, XtRCursor, sizeof(Cursor),
2006-11-25 13:07:29 -07:00
Offset(cursors.help), XtRString, HELP_CURSOR},
2013-09-28 10:22:59 -06:00
{"manpageCursor", XtCCursor, XtRCursor, sizeof(Cursor),
2006-11-25 13:07:29 -07:00
Offset(cursors.manpage), XtRString, MANPAGE_CURSOR},
2013-09-28 10:22:59 -06:00
{"searchEntryCursor", XtCCursor, XtRCursor, sizeof(Cursor),
2006-11-25 13:07:29 -07:00
Offset(cursors.search_entry), XtRString, SEARCH_ENTRY_CURSOR},
2013-09-28 10:22:59 -06:00
{"pointerColor", XtCForeground, XtRPixel, sizeof(Pixel),
2006-11-25 13:07:29 -07:00
Offset(cursors.fg_color), XtRString, "XtDefaultForeground"},
2013-09-28 10:22:59 -06:00
{"pointerColorBackground", XtCBackground, XtRPixel, sizeof(Pixel),
2006-11-25 13:07:29 -07:00
Offset(cursors.bg_color), XtRString, "XtDefaultBackground"},
2013-09-28 10:22:59 -06:00
{"help", XtCBoolean, XtRBoolean, sizeof(Boolean),
2009-10-24 09:00:51 -06:00
Offset(show_help_syntax), XtRImmediate, NULL},
2013-09-28 10:22:59 -06:00
{"helpFile", XtCFile, XtRString, sizeof(char *),
2006-11-25 13:07:29 -07:00
Offset(help_file), XtRString, HELPFILE},
2013-09-28 10:22:59 -06:00
{"topBox", XtCBoolean, XtRBoolean, sizeof(Boolean),
2006-11-25 13:07:29 -07:00
Offset(top_box_active), XtRString, "True"},
2013-09-28 10:22:59 -06:00
{"clearSearchString", "ClearSearchString", XtRBoolean, sizeof(Boolean),
2006-11-25 13:07:29 -07:00
Offset(clear_search_string), XtRImmediate, (caddr_t) TRUE},
2013-09-28 10:22:59 -06:00
{"title", XtCString, XtRString, sizeof(char *),
2006-11-25 13:07:29 -07:00
Offset(title), XtRString, "xman"},
2013-09-28 10:22:59 -06:00
{"iconic", XtCBoolean, XtRBoolean, sizeof(Boolean),
2006-11-25 13:07:29 -07:00
Offset(iconic), XtRString, "False"},
};
#undef Offset
/*
* The resource that we absolutely need.
*/
2013-09-28 10:22:59 -06:00
static char *fallback_resources[] = {
"Xman*quitButton.translations: #override \\n <Btn1Up>: Quit() reset()",
"Xman*helpButton.sensitive: FALSE",
"Xman*manpageButton.sensitive: FALSE",
"Xman*helpButton.Label: Help",
"Xman*quitButton.Label: Quit",
"Xman*manpageButton.Label: Manual Page",
"Xman*topLabel.label: No App-Defaults File",
NULL,
2006-11-25 13:07:29 -07:00
};
/*
* This is necessary to keep all TopLevel shells from becoming
* the size that is specified on the command line.
*/
static XrmOptionDescRec xman_options[] = {
2013-09-28 10:22:59 -06:00
{"-geometry", "*topBox.geometry", XrmoptionSepArg, (caddr_t) NULL},
{"-help", "help", XrmoptionNoArg, (caddr_t) "True"},
{"=", "*topBox.geometry", XrmoptionIsArg, (caddr_t) NULL},
{"-pagesize", "*manualBrowser.geometry", XrmoptionSepArg, (caddr_t) NULL},
{"-notopbox", "topBox", XrmoptionNoArg, (caddr_t) "False"},
{"-helpfile", "helpFile", XrmoptionSepArg, (caddr_t) NULL},
{"-bothshown", "bothShown", XrmoptionNoArg, (caddr_t) "True"},
{"-title", "title", XrmoptionSepArg, (caddr_t) "xman"},
{"-iconic", "iconic", XrmoptionNoArg, (caddr_t) "True"},
2006-11-25 13:07:29 -07:00
};
2009-10-24 09:00:51 -06:00
static XtActionsRec xman_actions[] = {
2013-09-28 10:22:59 -06:00
{"GotoPage", GotoPage},
{"Quit", Quit},
{"Search", Search},
{"PopupHelp", PopupHelp},
{"PopupSearch", PopupSearch},
{"CreateNewManpage", CreateNewManpage},
{"RemoveThisManpage", RemoveThisManpage},
{"SaveFormattedPage", SaveFormattedPage},
2006-11-25 13:07:29 -07:00
#ifdef INCLUDE_XPRINT_SUPPORT
2013-09-28 10:22:59 -06:00
{"PrintThisManpage", PrintThisManpage},
#endif /* INCLUDE_XPRINT_SUPPORT */
{"ShowVersion", ShowVersion},
2006-11-25 13:07:29 -07:00
};
char **saved_argv;
int saved_argc;
/*
* This atom is used to make the application ICCCM compliant.
*/
Atom wm_delete_window;
/* Function Name: main
* Description: This is the main driver for Xman.
* Arguments: argc, argv - the command line arguments.
* Returns: return, what return.
*/
2013-09-28 10:22:59 -06:00
int
main(int argc, char **argv)
2006-11-25 13:07:29 -07:00
{
2013-09-28 10:22:59 -06:00
XtAppContext app_con;
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
saved_argc = argc;
saved_argv = (char **) XtMalloc(argc * sizeof(char *));
bcopy(argv, saved_argv, argc * sizeof(char *));
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
initial_widget = XtAppInitialize(&app_con, "Xman", xman_options,
XtNumber(xman_options), &argc, argv,
fallback_resources, NULL, ZERO);
wm_delete_window =
XInternAtom(XtDisplay(initial_widget), "WM_DELETE_WINDOW", False);
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
manglobals_context = XStringToContext(MANNAME);
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
AdjustDefResources();
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
XtGetApplicationResources(initial_widget, (caddr_t) & resources,
my_resources, XtNumber(my_resources),
NULL, (Cardinal) 0);
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
if ((argc != 1) || (resources.show_help_syntax)) {
ArgError(argc, argv);
return EXIT_FAILURE;
}
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
XtAppAddActions(app_con, xman_actions, XtNumber(xman_actions));
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
if (!resources.fonts.directory)
PrintError("Failed to get the directory font.");
2006-11-25 13:07:29 -07:00
#ifdef DEBUG
2013-09-28 10:22:59 -06:00
printf("debugging mode\n");
2006-11-25 13:07:29 -07:00
#endif
/*
* Set the default width and height.
* I am not real happy with this method, but it will usually do something
* reasonable, if not the "right" thing. It is not a real big issue since
* it is easy to change the values with resources or command line options.
* NOTE: if you are in a 100 dpi display you will lose.
*/
2013-09-28 10:22:59 -06:00
default_width = DEFAULT_WIDTH;
default_height = DisplayHeight(XtDisplay(initial_widget),
DefaultScreen(XtDisplay(initial_widget)));
default_height *= 3;
default_height /= 4;
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
if ((sections = Man()) == 0)
PrintError
("There are no manual sections to display, check your MANPATH.");
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
if (resources.top_box_active)
MakeTopBox();
else
(void) CreateManpage(NULL);
2006-11-25 13:07:29 -07:00
/*
* We need to keep track of the number of manual pages that are shown on
2015-05-10 04:21:18 -06:00
* the screen so that if this user does not have a top box then when they
* remove all their manual pages we can kill off the xman process.
2006-11-25 13:07:29 -07:00
* To make things easier we will consider the top box a shown manual page
* here, but since you cannot remove it, man_page_shown only goes to zero when
* no top box is present.
*/
2013-09-28 10:22:59 -06:00
man_pages_shown = 1;
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
XtAppMainLoop(app_con);
2006-11-25 13:07:29 -07:00
2013-09-28 10:22:59 -06:00
return EXIT_SUCCESS;
2006-11-25 13:07:29 -07:00
}
/* Function Name: ArgError
2013-09-28 10:22:59 -06:00
* Description: Prints error message about unknown arguments.
2006-11-25 13:07:29 -07:00
* Arguments: argc, argv - args not understood.
* Returns: none.
*/
2013-09-28 10:22:59 -06:00
static void
ArgError(int argc, char **argv)
2006-11-25 13:07:29 -07:00
{
2013-09-28 10:22:59 -06:00
int i;
static const char **syntax, *syntax_def[] = {
"-help", "Print this message",
"-helpfile <filename>", "Specifies the helpfile to use.",
"-bothshown", "Show both the directory and manpage at once.",
"-notopbox", "Starts with manpage rather than topbox.",
"-geometry <geom>", "Specifies the geometry of the top box.",
"=<geom>", "Specifies the geometry of the top box.",
"-pagesize <geom>", "Specifies the geometry of the manual page.",
"-bw <pixels>", "Width of all window borders.",
"-borderwidth <pixels>", "Width of all window borders.",
"-bd <color>", "Color of all window borders.",
"-bordercolor <color>", "Color of all window borders.",
"-fg <color>", "Foreground color for the application.",
"-foreground <color>", "Foreground color for the application.",
"-bg <color>", "Background color for the application.",
"-background <color>", "Background color for the application.",
"-display <display name>", "Specify a display that is not the default",
"-fn <font>", "Font to be used for button and label text.",
"-font <font>", "Font to be used for button and label text.",
"-name <name>", "Change the name used for retrieving resources.",
"-title <name>", "Change the name without affecting resources.",
"-xrm <resource>", "Specifies a resource on the command line.",
NULL, NULL,
};
syntax = syntax_def;
for (i = 1; i < argc; i++)
(void) printf("This argument is unknown to Xman: %s\n", argv[i]);
(void) printf("\nKnown arguments are:\n");
while (*syntax != NULL) {
printf("%-30s - %s\n", syntax[0], syntax[1]);
syntax += 2;
}
2006-11-25 13:07:29 -07:00
}
/* Function Name: AdjustDefResources
* Description: Changes default resources which contain paths when
* XWINHOME is set
* Arguments: none
* Returns: nothing
*/
static void
AdjustDefResources(void)
{
2013-09-28 10:22:59 -06:00
char *xwinhome = NULL;
int i;
if (!(xwinhome = getenv("XWINHOME")))
return;
for (i = 0; i < sizeof(my_resources) / sizeof(XtResource); i++) {
if (!strcmp(my_resources[i].resource_name, "helpFile")) {
char filename[PATH_MAX];
snprintf(filename, sizeof(filename), "%s/lib/X11/xman.help",
xwinhome);
if (!(my_resources[i].default_addr = strdup(filename))) {
fprintf(stderr, "malloc failure\n");
exit(EXIT_FAILURE);
}
}
2006-11-25 13:07:29 -07:00
}
}