#include "globals.h"
#ifndef ZERO
#include <X11/Xaw/Cardinals.h>
#endif
#if !defined(lint) && !defined(SABER) && 0
static char version[] = XMAN_VERSION;
#endif
static void ArgError(int argc, char ** argv);
static void AdjustDefResources(void);
#define Offset(field) (XtOffsetOf(Xman_Resources , field))
static XtResource my_resources[] = {
{"directoryFontNormal", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
Offset(fonts.directory), XtRString, DIRECTORY_NORMAL},
{"bothShown", XtCBoolean, XtRBoolean, sizeof(Boolean),
Offset(both_shown_initial), XtRString, "False"},
{"directoryHeight", "DirectoryHeight", XtRInt, sizeof(int),
Offset(directory_height), XtRString, "150"},
{"topCursor", XtCCursor, XtRCursor, sizeof(Cursor),
Offset(cursors.top), XtRString, XMAN_CURSOR},
{"helpCursor", XtCCursor, XtRCursor, sizeof(Cursor),
Offset(cursors.help), XtRString, HELP_CURSOR},
{"manpageCursor", XtCCursor, XtRCursor, sizeof(Cursor),
Offset(cursors.manpage), XtRString, MANPAGE_CURSOR},
{"searchEntryCursor", XtCCursor, XtRCursor, sizeof(Cursor),
Offset(cursors.search_entry), XtRString, SEARCH_ENTRY_CURSOR},
{"pointerColor", XtCForeground, XtRPixel, sizeof(Pixel),
Offset(cursors.fg_color), XtRString, "XtDefaultForeground"},
{"pointerColorBackground", XtCBackground, XtRPixel, sizeof(Pixel),
Offset(cursors.bg_color), XtRString, "XtDefaultBackground"},
{"help", XtCBoolean, XtRBoolean, sizeof(Boolean),
Offset(show_help_syntax), XtRImmediate, FALSE},
{"helpFile", XtCFile, XtRString, sizeof(char *),
Offset(help_file), XtRString, HELPFILE},
{"topBox", XtCBoolean, XtRBoolean, sizeof(Boolean),
Offset(top_box_active), XtRString, "True"},
{"clearSearchString", "ClearSearchString", XtRBoolean, sizeof(Boolean),
Offset(clear_search_string), XtRImmediate, (caddr_t) TRUE},
{"title", XtCString, XtRString, sizeof(char *),
Offset(title), XtRString, "xman"},
{"iconic", XtCBoolean, XtRBoolean, sizeof(Boolean),
Offset(iconic), XtRString, "False"},
};
#undef Offset
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,
};
static XrmOptionDescRec xman_options[] = {
{"-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"},
};
XtActionsRec xman_actions[] = {
{"GotoPage", GotoPage},
{"Quit", Quit},
{"Search", Search},
{"PopupHelp", PopupHelp},
{"PopupSearch", PopupSearch},
{"CreateNewManpage", CreateNewManpage},
{"RemoveThisManpage", RemoveThisManpage},
{"SaveFormattedPage", SaveFormattedPage},
{"ShowVersion", ShowVersion},
};
char **saved_argv;
int saved_argc;
Atom wm_delete_window;
int main(int argc, char ** argv)
{
XtAppContext app_con;
saved_argc = argc;
saved_argv = (char **)XtMalloc(argc * sizeof(char *));
bcopy(argv, saved_argv, argc * sizeof(char *));
XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
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);
manglobals_context = XStringToContext(MANNAME);
AdjustDefResources();
XtGetApplicationResources( initial_widget, (caddr_t) &resources,
my_resources, XtNumber(my_resources),
NULL, (Cardinal) 0);
if ( (argc != 1) || (resources.show_help_syntax) ) {
ArgError(argc, argv);
exit(1);
}
XtAppAddActions(app_con, xman_actions, XtNumber(xman_actions));
if (!resources.fonts.directory)
PrintError("Failed to get the directory font.");
#ifdef DEBUG
printf("debugging mode\n");
#endif
default_width = DEFAULT_WIDTH;
default_height=DisplayHeight(XtDisplay(initial_widget),
DefaultScreen(XtDisplay(initial_widget)));
default_height *= 3;
default_height /= 4;
if ( (sections = Man()) == 0 )
PrintError("There are no manual sections to display, check your MANPATH.");
if (resources.top_box_active)
MakeTopBox();
else
(void) CreateManpage(NULL);
man_pages_shown = 1;
XtAppMainLoop(app_con);
exit(0);
}
static void
ArgError(int argc, char ** argv)
{
int i;
static 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.",
"-geometery <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;
}
}
static void
AdjustDefResources(void)
{
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")) {
if (!(my_resources[i].default_addr =
malloc(strlen(xwinhome) + sizeof("/lib/X11/xman.help")))) {
fprintf(stderr, "malloc failure\n");
exit(1);
}
sprintf(my_resources[i].default_addr, "%s/lib/X11/xman.help", xwinhome);
}
}
}