summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:49:23 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 16:49:23 +0000
commit36fca7804971e1b209138fcf82aee2d74cb2583e (patch)
tree5359a5d57d4193ee2954f56eb780f0f6da312344
Initial revisionXORG-STABLE
-rw-r--r--ScrollByL.c1219
-rw-r--r--ScrollByL.h73
-rw-r--r--ScrollByLP.h98
-rw-r--r--buttons.c739
-rw-r--r--defs.h139
-rw-r--r--globals.c54
-rw-r--r--globals.h56
-rw-r--r--handler.c607
-rw-r--r--help.c110
-rw-r--r--icon_help.h50
-rw-r--r--icon_open.h50
-rw-r--r--iconclosed.h47
-rw-r--r--main.c296
-rw-r--r--man.c1160
-rw-r--r--man.h256
-rw-r--r--misc.c1054
-rw-r--r--search.c395
-rw-r--r--tkfuncs.c99
-rw-r--r--vendor.c318
-rw-r--r--vendor.h235
-rw-r--r--version.h32
-rw-r--r--xman.help228
-rw-r--r--xman.man387
23 files changed, 7702 insertions, 0 deletions
diff --git a/ScrollByL.c b/ScrollByL.c
new file mode 100644
index 0000000..b312128
--- /dev/null
+++ b/ScrollByL.c
@@ -0,0 +1,1219 @@
+/* $XConsortium: ScrollByL.c,v 1.30 94/04/17 20:43:46 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/ScrollByL.c,v 1.6 2001/10/28 03:34:36 tsi Exp $ */
+
+#if !defined(lint) && !defined(SABER) && 0
+ static char rcs_version[] = "$Athena: ScrollByL.c,v 4.5 88/12/19 13:46:04 kit Exp $";
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+#include <X11/Xos.h>
+#include <stdlib.h>
+
+#include <X11/IntrinsicP.h>
+#include <sys/stat.h> /* depends on IntrinsicP.h */
+#include <X11/StringDefs.h>
+
+#include <X11/Xaw/Scrollbar.h>
+#include <X11/Xmu/Misc.h>
+
+#include "ScrollByLP.h"
+
+/* Default Translation Table */
+
+static char defaultTranslations[] =
+ "<Key>f: Page(Forward) \n\
+ <Key>b: Page(Back) \n\
+ <Key>1: Page(Line, 1) \n\
+ <Key>2: Page(Line, 2) \n\
+ <Key>3: Page(Line, 3) \n\
+ <Key>4: Page(Line, 4) \n\
+ <Key>\\ : Page(Forward)";
+
+
+/****************************************************************
+ *
+ * ScrollByLine Resources
+ *
+ ****************************************************************/
+
+#define Offset(field) XtOffset(ScrollByLineWidget, scroll.field)
+#define CoreOffset(field) XtOffset(ScrollByLineWidget, core.field)
+
+static XtResource resources[] = {
+ {XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
+ CoreOffset(width), XtRImmediate, (caddr_t) 500},
+ {XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
+ CoreOffset(height), XtRImmediate, (caddr_t) 700},
+
+ {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
+ Offset(foreground), XtRString, "XtDefaultForeground"},
+ {XtNforceVert, XtCBoolean, XtRBoolean, sizeof(Boolean),
+ Offset(force_vert), XtRImmediate, (caddr_t) FALSE},
+ {XtNindent, XtCIndent, XtRDimension, sizeof(Dimension),
+ Offset(indent), XtRImmediate, (caddr_t) 15},
+ {XtNuseRight, XtCBoolean, XtRBoolean, sizeof(Boolean),
+ Offset(use_right), XtRImmediate, (caddr_t) FALSE},
+ {XtNmanualFontNormal, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
+ Offset(normal_font), XtRString, MANPAGE_NORMAL},
+ {XtNmanualFontBold, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
+ Offset(bold_font), XtRString, MANPAGE_BOLD},
+ {XtNmanualFontItalic, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
+ Offset(italic_font), XtRString, MANPAGE_ITALIC},
+ {XtNmanualFontSymbol, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
+ Offset(symbol_font), XtRString, MANPAGE_SYMBOL},
+ {XtNfile, XtCFile, XtRFile, sizeof(FILE *),
+ Offset(file), XtRImmediate, (caddr_t) NULL},
+};
+
+#undef Offset
+#undef CoreOffset
+
+/****************************************************************
+ *
+ * Full class record constant
+ *
+ ****************************************************************/
+
+static Boolean ScrollVerticalText(Widget w, int new_line, Boolean force_redisp);
+static void Layout(Widget w);
+static void LoadFile(Widget w);
+static void MoveAndClearText(Widget w, int old_y, int height, int new_y);
+static void PaintText(Widget w, int y_loc, int height);
+static void PrintText(Widget w, int start_line, int num_lines, int location);
+static void SetThumbHeight(Widget w);
+static void VerticalJump(Widget w, XtPointer junk, XtPointer percent_ptr);
+static void VerticalScroll(Widget w, XtPointer client_data, XtPointer call_data);
+
+/* semi - public functions. */
+
+static void Realize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes);
+static void Initialize(Widget req, Widget new, ArgList args, Cardinal *num_args);
+static void Destroy(Widget w);
+static void Redisplay(Widget w, XEvent *event, Region region);
+static void Page(Widget w, XEvent * event, String * params, Cardinal *num_params);
+static Boolean SetValuesHook(Widget w, ArgList args, Cardinal *num_args);
+
+static XtActionsRec actions[] = {
+ { "Page", Page},
+};
+
+#define superclass (&simpleClassRec)
+#define SuperClass simpleWidgetClass
+
+ScrollByLineClassRec scrollByLineClassRec = {
+ {
+/* core_class fields */
+ /* superclass */ (WidgetClass) superclass,
+ /* class_name */ "ScrollByLine",
+ /* widget_size */ sizeof(ScrollByLineRec),
+ /* class_initialize */ NULL,
+ /* class_part_init */ NULL,
+ /* class_inited */ FALSE,
+ /* initialize */ Initialize,
+ /* initialize_hook */ NULL,
+ /* realize */ Realize,
+ /* actions */ actions,
+ /* num_actions */ XtNumber(actions),
+ /* resources */ resources,
+ /* num_resources */ XtNumber(resources),
+ /* xrm_class */ NULLQUARK,
+ /* compress_motion */ TRUE,
+ /* compress_exposure */ FALSE,
+ /* compress_enterleave*/ TRUE,
+ /* visible_interest */ FALSE,
+ /* destroy */ Destroy,
+ /* resize */ Layout,
+ /* expose */ Redisplay,
+ /* set_values */ NULL,
+ /* set_values_hook */ SetValuesHook,
+ /* set_values_almost */ XtInheritSetValuesAlmost,
+ /* get_values_hook */ NULL,
+ /* accept_focus */ NULL,
+ /* version */ XtVersion,
+ /* callback_private */ NULL,
+ /* tm_table */ defaultTranslations,
+ /* query_geometry */ XtInheritQueryGeometry,
+ /* display_accelerator*/ XtInheritDisplayAccelerator,
+ /* extension */ NULL,
+ },
+ { /* simple fields */
+ /* change_sensitive */ XtInheritChangeSensitive
+ }
+};
+
+WidgetClass scrollByLineWidgetClass =
+ (WidgetClass) &scrollByLineClassRec;
+
+
+/****************************************************************
+ *
+ * Private Routines
+ *
+ ****************************************************************/
+
+/* Function Name: Layout
+ * Description: This function lays out the scroll widget.
+ * Arguments: w - the scroll widget.
+ * key - a boolean: if true then resize the widget to the child
+ * if false the resize children to fit widget.
+ * Returns: TRUE if successful.
+ */
+
+static void
+Layout(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ Dimension width, height;
+ Widget bar;
+ Position bar_bw;
+
+/*
+ * For now always show the bar.
+ */
+
+ bar = sblw->scroll.bar;
+ height = sblw->core.height;
+ width = sblw->core.width;
+ bar_bw = bar->core.border_width;
+
+ /* Move child and v_bar to correct location. */
+
+ if (sblw->scroll.use_right) {
+ XtMoveWidget(bar, width - (bar->core.width + bar_bw), - bar_bw);
+ sblw->scroll.offset = 0;
+ }
+ else {
+ XtMoveWidget(bar, - bar_bw, - bar_bw);
+ sblw->scroll.offset = bar->core.width + bar_bw;
+ }
+
+ /* resize the scrollbar to be the correct height or width. */
+
+ XtResizeWidget(bar, bar->core.width, height, bar->core.border_width);
+
+ SetThumbHeight(w);
+}
+
+/* ARGSUSED */
+static void
+GExpose(Widget w, XtPointer junk, XEvent *event, Boolean *cont)
+{
+
+/*
+ * Graphics exposure events are not currently sent to exposure proc.
+ */
+
+ if (event->type == GraphicsExpose)
+ Redisplay(w, event, NULL);
+
+} /* ChildExpose */
+
+/*
+ * Repaint the widget's child Window Widget.
+ */
+
+/* ARGSUSED */
+static void
+Redisplay(Widget w, XEvent *event, Region region)
+{
+ int top, height; /* the locations of the top and height
+ of the region that needs to be repainted. */
+
+/*
+ * This routine tells the client which sections of the window to
+ * repaint in his callback function which does the actual repainting.
+ */
+
+ if (event->type == Expose) {
+ top = event->xexpose.y;
+ height = event->xexpose.height;
+ }
+ else {
+ top = event->xgraphicsexpose.y;
+ height = event->xgraphicsexpose.height;
+ }
+
+ PaintText(w, top, height);
+} /* redisplay (expose) */
+
+/* Function Name: PaintText
+ * Description: paints the text at the give location for a given height.
+ * Arguments: w - the sbl widget.
+ * y_loc, height - location and size of area to paint.
+ * Returns: none
+ */
+
+static void
+PaintText(Widget w, int y_loc, int height)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ int start_line, num_lines, location;
+
+ start_line = y_loc / sblw->scroll.font_height + sblw->scroll.line_pointer;
+
+ if (start_line >= sblw->scroll.lines)
+ return;
+
+ num_lines = height / sblw->scroll.font_height + 1;
+
+/*
+ * Only integer arithmetic makes this possible.
+ */
+
+ location = y_loc / sblw->scroll.font_height * sblw->scroll.font_height;
+
+ PrintText(w, start_line, num_lines, location);
+}
+
+/* Function Name: Page
+ * Description: This function pages the widget, by the amount it recieves
+ * from the translation Manager.
+ * Arguments: w - the ScrollByLineWidget.
+ * event - the event that caused this return.
+ * params - the parameters passed to it.
+ * num_params - the number of parameters.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+Page(Widget w, XEvent * event, String * params, Cardinal *num_params)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ Widget bar = sblw->scroll.bar;
+
+ if (*num_params < 1)
+ return;
+/*
+ * If no scroll bar is visible then do not page, as the entire window is shown,
+ * of scrolling has been turned off.
+ */
+
+ if (bar == (Widget) NULL)
+ return;
+
+ switch ( params[0][0] ) {
+ case 'f':
+ case 'F':
+ /* move one page forward */
+ VerticalScroll(bar, NULL, (XtPointer)((long) bar->core.height));
+ break;
+ case 'b':
+ case 'B':
+ /* move one page backward */
+ VerticalScroll(bar, NULL, (XtPointer)(- (long) bar->core.height));
+ break;
+ case 'L':
+ case 'l':
+ /* move one line forward */
+ VerticalScroll(bar, NULL,
+ (XtPointer)((long) atoi(params[1]) * sblw->scroll.font_height));
+ break;
+ default:
+ return;
+ }
+}
+
+/* Function Name: CreateScrollbar
+ * Description: createst the scrollbar for us.
+ * Arguments: w - sblw widget.
+ * Returns: none.
+ */
+
+static void
+CreateScrollbar(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ Arg args[5];
+ Cardinal num_args = 0;
+
+ if (sblw->scroll.bar != NULL)
+ return;
+
+ XtSetArg(args[num_args], XtNorientation, XtorientVertical); num_args++;
+
+ sblw->scroll.bar = XtCreateWidget("scrollbar", scrollbarWidgetClass, w,
+ args, num_args);
+ XtAddCallback(sblw->scroll.bar, XtNscrollProc, VerticalScroll, NULL);
+ XtAddCallback(sblw->scroll.bar, XtNjumpProc, VerticalJump, NULL);
+}
+
+/* Function Name: ScrollVerticalText
+ * Description: This accomplished the actual movement of the text.
+ * Arguments: w - the ScrollByLine Widget.
+ * new_line - the new location for the line pointer
+ * force_redisplay - should we force this window to get
+ * redisplayed?
+ * Returns: True if the thumb needs to be moved.
+ */
+
+static Boolean
+ScrollVerticalText(
+Widget w,
+int new_line,
+Boolean force_redisp)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ int num_lines = (int)w->core.height / sblw->scroll.font_height + 1;
+ int max_lines, old_line;
+ Boolean move_thumb = FALSE;
+
+/*
+ * Do not let the window extend out of bounds.
+ */
+
+ if ( new_line < 0) {
+ new_line = 0;
+ move_thumb = TRUE;
+ }
+ else {
+ max_lines = sblw->scroll.lines - (int)w->core.height / sblw->scroll.font_height;
+ AssignMax(max_lines, 0);
+
+ if ( new_line > max_lines ) {
+ new_line = max_lines;
+ move_thumb = TRUE;
+ }
+ }
+
+/*
+ * If forced to redisplay then do a full redisplay and return.
+ */
+
+ old_line = sblw->scroll.line_pointer;
+ sblw->scroll.line_pointer = new_line; /* Set current top of page. */
+
+ if (force_redisp)
+ MoveAndClearText(w, 0, /* cause a full redisplay */ 0, 0);
+
+ if (new_line == old_line)
+ return(move_thumb);
+
+/*
+ * Scroll forward.
+ */
+
+ else if (new_line < old_line) {
+ int lines_to_scroll = old_line - new_line;
+ MoveAndClearText(w, 0, num_lines - lines_to_scroll, lines_to_scroll);
+ }
+
+/*
+ * Scroll back.
+ */
+
+ else {
+ int lines_to_scroll = new_line - old_line;
+ MoveAndClearText(w, lines_to_scroll, num_lines - lines_to_scroll, 0);
+ }
+
+ return(move_thumb);
+}
+
+/* Function Name: MoveAndClearText
+ * Description: Blits as much text as it can and clear the
+ * remaining area with generate exposures TRUE.
+ * Arguments: w - the sbl widget.
+ * old_y - the old y position.
+ * height - height of area to move.
+ * new_y - new y position.
+ * Returns: none
+ */
+
+static void
+MoveAndClearText(Widget w, int old_y, int height, int new_y)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ int from_left = sblw->scroll.indent + sblw->scroll.offset - 1;
+ int y_clear;
+
+ old_y *= sblw->scroll.font_height;
+ new_y *= sblw->scroll.font_height;
+ height *= sblw->scroll.font_height;
+
+/*
+ * If we are already at the right location then do nothing.
+ * (height == 0).
+ *
+ * If we have scrolled more than a screen height then just clear
+ * the window.
+ */
+
+ if (height <= sblw->scroll.font_height) { /* avoid rounding errors. */
+ XClearArea( XtDisplay(w), XtWindow(w), from_left, 0,
+ (unsigned int) 0, (unsigned int) 0, FALSE);
+ PaintText(w, 0, (int) sblw->core.height);
+ return;
+ }
+
+ if ((int)height + (int)old_y > (int)w->core.height)
+ height = w->core.height - old_y;
+
+ XCopyArea(XtDisplay(w), XtWindow(w), XtWindow(w), sblw->scroll.move_gc,
+ from_left, old_y,
+ (unsigned int) w->core.width - from_left, (unsigned int) height,
+ from_left, new_y);
+
+ if (old_y > new_y)
+ height -= sblw->scroll.font_height/2; /* clear 1/2 font of extra space,
+ to make sure we don't lose or
+ gain decenders. */
+ else
+ height -= sblw->scroll.font_height; /* clear 1 font of extra space,
+ to make sure we don't overwrite
+ with a last line in buffer. */
+
+ if (old_y > new_y)
+ y_clear = height;
+ else
+ y_clear = 0;
+
+/*
+ * We cannot use generate exposures, since that may allow another move and
+ * clear before the area get repainted, this would be bad.
+ */
+
+ XClearArea( XtDisplay(w), XtWindow(w), from_left, y_clear,
+ (unsigned int) 0, (unsigned int) (w->core.height - height),
+ FALSE);
+ PaintText(w, (int) y_clear, (int) (w->core.height - height));
+}
+
+/* Function Name: SetThumbHeight
+ * Description: Set the height of the thumb.
+ * Arguments: w - the sblw widget.
+ * Returns: none
+ */
+
+static void
+SetThumbHeight(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ float shown;
+
+ if (sblw->scroll.bar == NULL)
+ return;
+
+ if (sblw->scroll.lines == 0)
+ shown = 1.0;
+ else
+ shown = (float) w->core.height / (float) (sblw->scroll.lines *
+ sblw->scroll.font_height);
+ if (shown > 1.0)
+ shown = 1.0;
+
+ XawScrollbarSetThumb( sblw->scroll.bar, (float) -1, shown );
+}
+
+/* Function Name: SetThumb
+ * Description: Set the thumb location.
+ * Arguments: w - the sblw.
+ * Returns: none
+ */
+
+static void
+SetThumb(Widget w)
+{
+ float location;
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ if ( (sblw->scroll.lines == 0) || (sblw->scroll.bar == NULL) )
+ return;
+
+ location = (float) sblw->scroll.line_pointer / (float) sblw->scroll.lines;
+ XawScrollbarSetThumb( sblw->scroll.bar, location , (float) -1 );
+}
+
+/* Function Name: VerticalJump.
+ * Description: This function moves the test
+ * as the vertical scroll bar is moved.
+ * Arguments: w - the scrollbar widget.
+ * junk - not used.
+ * percent - the position of the scrollbar.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+VerticalJump(Widget w, XtPointer junk, XtPointer percent_ptr)
+{
+ float percent = *((float *) percent_ptr);
+ int new_line; /* The new location for the line pointer. */
+ ScrollByLineWidget sblw = (ScrollByLineWidget) XtParent(w);
+
+ new_line = (int) ((float) sblw->scroll.lines * percent);
+ if (ScrollVerticalText( (Widget) sblw, new_line, FALSE))
+ SetThumb((Widget) sblw);
+}
+
+/* Function Name: VerticalScroll
+ * Description: This function moves the postition of the interior window
+ * as the vertical scroll bar is moved.
+ * Arguments: w - the scrollbar widget.
+ * junk - not used.
+ * pos - the position of the cursor.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+VerticalScroll(Widget w, XtPointer client_data, XtPointer call_data)
+{
+ int pos = (int)(long) call_data;
+ int new_line; /* The new location for the line pointer. */
+ ScrollByLineWidget sblw = (ScrollByLineWidget) XtParent(w);
+
+ new_line = sblw->scroll.line_pointer + (pos / sblw->scroll.font_height);
+ (void) ScrollVerticalText( (Widget) sblw, new_line, FALSE);
+ SetThumb( (Widget) sblw);
+}
+
+int h_width; /* main font width */
+
+/* ARGSUSED */
+static void
+Initialize(Widget req, Widget new, ArgList args, Cardinal *num_args)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) new;
+ unsigned long figWidth;
+ Atom atomNum;
+
+ sblw->scroll.top_line = NULL;
+ sblw->scroll.line_pointer = 0;
+ LoadFile(new);
+ sblw->scroll.bar = (Widget) NULL;
+
+ sblw->scroll.font_height = (sblw->scroll.normal_font->max_bounds.ascent +
+ sblw->scroll.normal_font->max_bounds.descent);
+
+ atomNum = XInternAtom(XtDisplay(req), "FIGURE_WIDTH", False);
+
+ if (XGetFontProperty(sblw->scroll.normal_font, atomNum, &figWidth))
+ h_width = figWidth;
+ else
+ h_width = XTextWidth(sblw->scroll.normal_font, "$", 1);
+
+
+
+} /* Initialize. */
+
+/* Function Name: CreateGCs
+ * Description: Creates the graphics contexts that we need.
+ * Arguments: w - the sblw.
+ * Returns: none
+ */
+
+static void
+CreateGCs(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ XtGCMask mask;
+ XGCValues values;
+
+ values.graphics_exposures = TRUE;
+ sblw->scroll.move_gc = XtGetGC(w, GCGraphicsExposures, &values);
+
+ mask = GCForeground | GCFont;
+ values.foreground = sblw->scroll.foreground;
+
+ values.font = sblw->scroll.normal_font->fid;
+ sblw->scroll.normal_gc = XtGetGC(w, mask, &values);
+
+ values.font = sblw->scroll.italic_font->fid;
+ sblw->scroll.italic_gc = XtGetGC(w, mask, &values);
+
+ values.font = sblw->scroll.bold_font->fid;
+ sblw->scroll.bold_gc = XtGetGC(w, mask, &values);
+
+ values.font = sblw->scroll.symbol_font->fid;
+ sblw->scroll.symbol_gc = XtGetGC(w, mask, &values);
+}
+
+/* Function Name: DestroyGCs
+ * Description: removes all gcs for this widget.
+ * Arguments: w - the widget.
+ * Returns: none
+ */
+
+static void
+DestroyGCs(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ XtReleaseGC(w, sblw->scroll.normal_gc);
+ XtReleaseGC(w, sblw->scroll.bold_gc);
+ XtReleaseGC(w, sblw->scroll.italic_gc);
+ XtReleaseGC(w, sblw->scroll.move_gc);
+}
+
+static void
+Realize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ CreateScrollbar(w);
+ CreateGCs(w);
+ Layout(w);
+ (*SuperClass->core_class.realize) (w, valueMask, attributes);
+ XtRealizeWidget(sblw->scroll.bar); /* realize scrollbar. */
+ XtMapWidget(sblw->scroll.bar); /* map scrollbar. */
+
+ XtAddEventHandler(w, 0, TRUE, GExpose, NULL); /* Get Graphics Exposures */
+} /* Realize */
+
+/* Function Name: Destroy
+ * Description: Cleans up when we are killed.
+ * Arguments: w - the widget.
+ * Returns: none
+ */
+
+static void
+Destroy(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ if (sblw->scroll.bar != NULL)
+ XtDestroyWidget(sblw->scroll.bar); /* Destroy scrollbar. */
+ if (sblw->scroll.file != NULL)
+ fclose(sblw->scroll.file);
+ DestroyGCs(w);
+}
+
+/*
+ *
+ * Set Values
+ *
+ */
+
+/* ARGSUSED */
+static Boolean
+SetValuesHook(Widget w, ArgList args, Cardinal *num_args)
+{
+ Boolean ret = TRUE;
+ int i;
+
+ for (i = 0; i < *num_args; i++) {
+ if (strcmp(XtNfile, args[i].name) == 0) {
+ LoadFile(w);
+ ret = TRUE;
+ }
+ }
+
+/*
+ * Changing anthing else will have strange effects, I don't need it so
+ * I didn't code it.
+ */
+
+ return(ret);
+
+} /* Set Values */
+
+/*
+ * A little design philosophy is probabally wise to include at this point.
+ *
+ * One of the things that I has hoped to achieve with xman is to make the
+ * viewing of manpage not only easy for the nieve user, but also fast for
+ * the experienced user, I wanted to be able to use it too. To achieve this
+ * I end up sacrificing a bit of start up time for the manual data structure.
+ * As well as, the overhead of reading the entire file before putting it up
+ * on the display. This is actually hardly even noticeable since most manual
+ * pages are shots, one to two pages - the notable exception is of course csh,
+ * but then that should be broken up anyway.
+ *
+ * METHOD:
+ *
+ * I allocate a chunk of space that is the size of the file, plus a null for
+ * debugging. Then copiesthe file into this chunk of memory. I then allocate
+ * an array of char*'s that are assigned to the beginning of each line. Yes,
+ * this means that I have to read the file twice, and could probabally be more
+ * clever about it, but once it is in memory the second read is damn fast.
+ * There are a few obsucrities here about guessing the number of lines and
+ * reallocing if I guess wrong, but other than that it is pretty straight
+ * forward.
+ *
+ * Chris Peterson
+ * 1/27/88
+ */
+
+#define ADD_MORE_MEM 100 /* first guesses for allocations. */
+#define CHAR_PER_LINE 40
+
+/* Function Name: LoadFile
+ * Description: Loads the current file into the internal memory.
+ * Arguments: w - the sblw.
+ * Returns: none
+ */
+
+static void
+LoadFile(Widget w)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ FILE * file = sblw->scroll.file;
+
+ char *page;
+ char **line_pointer,**top_line; /* pointers to beginnings of the
+ lines of the file. */
+ int nlines; /* the current number of allocated lines. */
+ struct stat fileinfo; /* file information from fstat. */
+
+ if ( sblw->scroll.top_line != NULL) {
+ XtFree(*(sblw->scroll.top_line)); /* free characters. */
+ XtFree((char *)(sblw->scroll.top_line)); /* free lines. */
+ }
+ sblw->scroll.top_line = NULL;
+
+ if (file == NULL)
+ return;
+
+/*
+ * Get file size and allocate a chunk of memory for the file to be
+ * copied into.
+ */
+
+ if (fstat(fileno(file), &fileinfo))
+ XtAppError(XtWidgetToApplicationContext(w),
+ "SBLW LoadFile: Failure in fstat.");
+
+/*
+ * Allocate a space for a list of pointer to the beginning of each line.
+ */
+
+ if ( (nlines = fileinfo.st_size/CHAR_PER_LINE) == 0)
+ return;
+
+ page = XtMalloc(fileinfo.st_size + 1); /* leave space for the NULL */
+ top_line = line_pointer = (char**) XtMalloc( nlines * sizeof(char *) );
+
+/*
+ * Copy the file into memory.
+ */
+
+ if (fread(page, sizeof(char), fileinfo.st_size, file) == 0)
+ XtAppError(XtWidgetToApplicationContext(w),
+ "SBLW LoadFile: Failure in fread.");
+
+
+/* put NULL at end of buffer. */
+
+ *(page + fileinfo.st_size) = '\0';
+
+/*
+ * Go through the file setting a line pointer to the character after each
+ * new line. If we run out of line pointer space then realloc that space
+ * with space for more lines.
+ */
+
+ *line_pointer++ = page; /* first line points to first char in buffer.*/
+ while (*page != '\0') {
+
+ if ( *page == '\n' ) {
+ *line_pointer++ = page + 1;
+
+ if (line_pointer >= top_line + nlines) {
+ top_line = (char **) XtRealloc( (char *)top_line, (nlines +
+ ADD_MORE_MEM) * sizeof(char *) );
+ line_pointer = top_line + nlines;
+ nlines += ADD_MORE_MEM;
+ }
+ }
+ page++;
+ }
+
+/*
+ * Realloc the line pointer space to take only the minimum amount of memory
+ */
+
+ sblw->scroll.lines = nlines = line_pointer - top_line - 1;
+ top_line = (char **) XtRealloc((char *)top_line, nlines * sizeof(char *));
+
+/*
+ * Store the memory pointers
+ */
+
+ sblw->scroll.top_line = top_line;
+ sblw->scroll.line_pointer = 0;
+ SetThumbHeight(w);
+ SetThumb(w);
+}
+
+#define NLINES 66 /* This is the number of lines to wait until
+ we boldify the line again, this allows
+ me to bold the first line of each page.*/
+#define BACKSPACE 010 /* I doubt you would want to change this. */
+
+#define NORMAL 0
+#define BOLD 1
+#define ITALIC 2
+#define SYMBOL 3
+#define WHICH(italic, bold) ((bold) ? BOLD : ((italic) ? ITALIC : NORMAL))
+ /* Choose BOLD over ITALICS. If neither */
+ /* is chosen, use NORMAL. */
+
+static int DumpText(Widget w, int x_loc, int y_loc, char * buf, int len, int format);
+static Boolean Boldify(char *);
+
+/* Function Name: PrintText
+ * Description: This function actually prints the text.
+ * Arguments: w - the ScrollByLine widget.
+ * start_line - line to start printing,
+ * num_lines - the number of lines to print.
+ * location - the location to print the text.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+
+static void
+PrintText(Widget w, int start_line, int num_lines, int location)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+
+ register char *bufp, *c; /* Generic char pointers */
+ int current_line; /* the number of the currrent line */
+ char buf[BUFSIZ]; /* Misc. characters */
+ int width; /* Width of a tab stop. */
+ Boolean italicflag = FALSE; /* Print text in italics?? */
+ Boolean first = TRUE; /* First line of a manual page??? */
+ int x_loc, y_loc; /* x and y location of text. */
+
+/*
+ * For table hack
+ * To get columns to line up reasonably in most cases, make the
+ * assumption that they were lined up using lots of spaces, where
+ * lots is greater than two. Use a space width of 70% of the
+ * widest character in the font.
+ */
+ XFontStruct * h_font;
+ int h_col, h_fix;
+ char * h_c;
+
+ h_font = sblw->scroll.normal_font;
+
+/*
+ * Nothing loaded, take no action.
+ */
+
+ if (sblw->scroll.top_line == NULL || num_lines == 0)
+ return;
+
+ current_line = start_line;
+
+/* Set the first character to print at the first line. */
+
+ c = *(sblw->scroll.top_line + start_line);
+
+ /* Width of a tab stop. */
+ width = 8 * h_width;
+
+/*
+ * Because XDrawString uses the bottom of the text as a position
+ * reference, add the height from the top of the font to the baseline
+ * to the ScollByLine position reference.
+ */
+
+ y_loc = location + sblw->scroll.normal_font->max_bounds.ascent;
+
+/*
+ * Ok, here's the more than mildly heuristic man page formatter.
+ * We put chars into buf until either a font change or newline
+ * occurs (at which time we flush it to the screen.)
+ */
+
+
+ bufp = buf;
+ x_loc = sblw->scroll.offset + sblw->scroll.indent;
+ h_col = 0;
+
+/*
+ * A fix:
+ * Assume that we are always starting to print on or before the
+ * first line of a page, and then prove it if we aren't.
+ */
+ for (h_fix = 1; h_fix <= (start_line % NLINES); h_fix++)
+ if (**(sblw->scroll.top_line + start_line - h_fix) != '\n')
+ {
+ first = FALSE;
+ break;
+ }
+
+ while(TRUE) {
+ if (current_line % NLINES == 0)
+ first = TRUE;
+
+/*
+ * Lets make sure that we do not run out of space in our buffer, making full
+ * use of it is not critical since no window will be wide enough to display
+ * nearly BUFSIZ characters.
+ */
+
+ if ( (bufp - buf) > (BUFSIZ - 10) )
+ /* Toss everything until we find a <CR> or the end of the buffer. */
+ while ( (*c != '\n') && (*c != '\0') ) c++;
+
+ switch(*c) {
+
+ case '\0': /* If we reach the end of the file then return */
+ DumpText(w, x_loc, y_loc, buf, bufp - buf, WHICH(italicflag, first));
+ return;
+
+ case '\n':
+ if (bufp != buf) {
+ Boolean bold;
+ *bufp = '\0'; /* for Boldify. */
+ bold = ( (first) || ((x_loc == (sblw->scroll.offset +
+ sblw->scroll.indent)) && Boldify(buf)) );
+
+ (void) DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, bold));
+
+ if (bold)
+ first = FALSE;
+ }
+
+/*
+ * If we have painted the required number of lines then we should now return.
+ */
+ if (++current_line == start_line + num_lines )
+ return;
+
+ bufp = buf;
+ italicflag = FALSE;
+ x_loc = sblw->scroll.offset + sblw->scroll.indent;
+ h_col = 0;
+ y_loc += sblw->scroll.font_height;
+ break;
+
+/*
+ * This tab handling code is not very clever it moves the cursor over
+ * to the next boundry of eight (8) spaces, as calculated in width just
+ * before the printing loop started.
+ */
+
+ case '\t': /* TAB */
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, first));
+ h_col += bufp - buf;
+ bufp = buf;
+ italicflag = FALSE;
+ x_loc = sblw->scroll.offset + sblw->scroll.indent;
+ h_col = h_col + 8 - (h_col%8);
+ x_loc += h_width * h_col;
+ break;
+
+ case ' ':
+ h_c = c + 1;
+ while (*h_c == ' ') h_c++;
+
+ if (h_c - c < 4)
+ {
+ *bufp++ = *c;
+ break;
+ }
+
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, first));
+ h_col += bufp - buf;
+ bufp = buf;
+ italicflag = FALSE;
+
+ x_loc = sblw->scroll.offset + sblw->scroll.indent;
+ h_col += (h_c - c);
+ x_loc += h_width * h_col;
+ c = h_c - 1;
+ break;
+
+ case '\033': /* ignore esc sequences for now */
+ c++; /* should always be esc-x */
+ break;
+
+/*
+ * Overstrike code supplied by: cs.utexas.edu!ut-emx!clyde@rutgers.edu
+ * Since my manual pages do not have overstrike I couldn't test this.
+ */
+
+ case BACKSPACE: /* Backspacing for nroff bolding */
+ if (c[-1] == c[1] && c[1] != BACKSPACE) { /* overstriking one char */
+ if (bufp > buf) {
+ bufp--; /* Zap 1st instance of char to bolden */
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, FALSE));
+ h_col += bufp - buf;
+ }
+ bufp = buf;
+ *bufp++ = c[1];
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, BOLD);
+ h_col += bufp - buf;
+ bufp = buf;
+ first = FALSE;
+
+ /*
+ * Nroff bolding looks like:
+ * C\bC\bC\bCN...
+ * c points to ----^ ^
+ * it needs to point to --^
+ */
+ while (*c == BACKSPACE && c[-1] == c[1])
+ c += 2;
+ c--; /* Back up to previous char */
+ }
+ else {
+ if ((c[-1] == 'o' && c[1] == '+') /* Nroff bullet */
+ || (c[-1] == '+' && c[1] == 'o')) { /* Nroff bullet */
+ /* If we run into a bullet, print out */
+ /* everything that's accumulated to this */
+ /* point, then the bullet, then resume. */
+ if (bufp>buf) {
+ bufp--;
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, FALSE));
+ h_col += bufp - buf;
+ }
+ bufp = buf;
+ *bufp = (char)183;
+ x_loc = DumpText(w, x_loc, y_loc, buf, 1, SYMBOL);
+ h_col++;
+ c++;
+ }
+ else { /* 'real' backspace - back up output ptr */
+ if (bufp>buf)
+ bufp--;
+ }
+ }
+ break;
+
+/* End of contributed overstrike code. */
+
+ case '_': /* look for underlining [italicize] */
+ if(*(c + 1) == BACKSPACE) {
+ if(!italicflag) { /* font change? */
+ if (bufp != buf) {
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf, NORMAL);
+ h_col += bufp - buf;
+ bufp = buf;
+ }
+ italicflag = TRUE;
+ }
+ c += 2;
+ *bufp++ = *c;
+ break;
+ }
+ /* else fall through to default, because this was a real underscore. */
+
+ default:
+ if(italicflag) { /* font change? */
+ if (bufp != buf) {
+ x_loc = DumpText(w, x_loc, y_loc, buf, bufp - buf,
+ WHICH(italicflag, FALSE));
+ h_col += bufp - buf;
+ bufp = buf;
+ }
+ italicflag = FALSE;
+ }
+ *bufp++ = *c;
+ break;
+ }
+ c++;
+ }
+}
+
+/* Function Name: DumpText
+ * Description: Dumps text to the screen.
+ * Arguments: w - the widget.
+ * x_loc - to dump text at.
+ * y_loc - the y_location to draw_text.
+ * buf - buffer to dump.
+ * italic, bold, boolean that tells us which gc to use.
+ * Returns: x_location of the end of the text.
+ */
+
+static int
+DumpText(Widget w, int x_loc, int y_loc, char * buf, int len, int format)
+{
+ ScrollByLineWidget sblw = (ScrollByLineWidget) w;
+ GC gc;
+ XFontStruct * font;
+
+ switch(format) {
+
+ case ITALIC:
+ gc = sblw->scroll.italic_gc;
+ font = sblw->scroll.italic_font;
+ break;
+
+ case BOLD:
+ gc = sblw->scroll.bold_gc;
+ font = sblw->scroll.bold_font;
+ break;
+
+ case SYMBOL:
+ gc = sblw->scroll.symbol_gc;
+ font = sblw->scroll.symbol_font;
+ break;
+
+ default:
+ gc = sblw->scroll.normal_gc;
+ font = sblw->scroll.normal_font;
+ break;
+ }
+
+ XDrawString(XtDisplay(w), XtWindow(w), gc, x_loc, y_loc, buf, len);
+ return(x_loc + XTextWidth(font, buf, len));
+}
+
+/* Function Name: Boldify
+ * Description: look for keyword.
+ * Arguments: sp - string pointer.
+ * Returns: 1 if keyword else 0.
+ */
+
+static Boolean
+Boldify(register char *sp)
+{
+ register char *sp_pointer;
+ int length,count;
+
+/*
+ * If there are not lower case letters in the line the assume it is a
+ * keyword and boldify it in PrintManpage.
+ */
+
+ length = strlen(sp);
+ for (sp_pointer = sp, count = 0; count < length; sp_pointer++,count++)
+ if ( !isupper(*sp_pointer) && !isspace(*sp_pointer) )
+ return(0);
+ return(1);
+}
+
+#undef superclass
+#undef SuperClass
diff --git a/ScrollByL.h b/ScrollByL.h
new file mode 100644
index 0000000..cdf8e2e
--- /dev/null
+++ b/ScrollByL.h
@@ -0,0 +1,73 @@
+/* $XConsortium: ScrollByL.h,v 1.7 94/04/17 20:43:48 dave Exp $ */
+/*
+
+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.
+
+*/
+
+#ifndef _XtScrollByLine_h
+#define _XtScrollByLine_h
+
+/***********************************************************************
+ *
+ * ScrollByLine Widget (subclass of Simple)
+ *
+ ***********************************************************************/
+
+/*
+ * The default fonts.
+ */
+
+#ifdef ATHENA
+#define MANPAGE_NORMAL "fixed"
+#define MANPAGE_BOLD "helvetica-bold12"
+#define MANPAGE_ITALIC "helvetica-boldoblique12"
+#define MANPAGE_SYMBOL "symbol-medium12"
+#else
+#define MANPAGE_NORMAL "*-new century schoolbook-medium-r-normal--*-120-*"
+#define MANPAGE_BOLD "*-new century schoolbook-bold-r-normal--*-120-*"
+#define MANPAGE_ITALIC "*-new century schoolbook-bold-i-normal--*-120-*"
+#define MANPAGE_SYMBOL "*-symbol-medium-r-normal--*-120-*"
+#endif /* ATHENA */
+
+#define XtNindent "indent"
+#define XtNforceVert "forceVert"
+#define XtNmanualFontNormal "manualFontNormal"
+#define XtNmanualFontBold "manualFontBold"
+#define XtNmanualFontItalic "manualFontItalic"
+#define XtNmanualFontSymbol "manualFontSymbol"
+
+#define XtCIndent "Indent"
+
+/* Class record constants */
+
+extern WidgetClass scrollByLineWidgetClass;
+
+typedef struct _ScrollByLineClassRec *ScrollByLineWidgetClass;
+typedef struct _ScrollByLineRec *ScrollByLineWidget;
+
+#endif /* _XtScrollByLine_h --- DON'T ADD STUFF AFTER THIS LINE */
diff --git a/ScrollByLP.h b/ScrollByLP.h
new file mode 100644
index 0000000..0947707
--- /dev/null
+++ b/ScrollByLP.h
@@ -0,0 +1,98 @@
+/* $XConsortium: ScrollByLP.h,v 1.9 94/04/17 20:43:49 keith Exp $ */
+/*
+
+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.
+
+*/
+
+
+#ifndef _XtScrollByLinePrivate_h
+#define _XtScrollByLinePrivate_h
+
+#include <X11/Xaw/SimpleP.h>
+
+#include "ScrollByL.h"
+
+/***********************************************************************
+ *
+ * ScrollByLine Widget Private Data
+ *
+ ***********************************************************************/
+
+/* New fields for the ScrollByLine widget class record */
+typedef struct {
+ int mumble; /* No new procedures */
+} ScrollByLineClassPart;
+
+/* Full class record declaration */
+typedef struct _ScrollByLineClassRec {
+ CoreClassPart core_class;
+ SimpleClassPart simple_class;
+ ScrollByLineClassPart scrolled_widget_class;
+} ScrollByLineClassRec;
+
+extern ScrollByLineClassRec scrollByLineClassRec;
+
+/* New fields for the ScrollByLine widget record */
+typedef struct _ScrollByLinePart {
+ Pixel foreground; /* The color for the forground of the text. */
+ Boolean force_vert, /* Must have scrollbar visable */
+ use_right; /* put scroll bar on right side of window. */
+ FILE * file; /* The file to display. */
+ Dimension indent; /* amount to indent the file. */
+ XFontStruct * bold_font, /* The four fonts. */
+ * normal_font,
+ * italic_font,
+ * symbol_font;
+
+/* variables not in resource list. */
+
+ Widget bar; /* The scrollbar. */
+ int font_height; /* the height of the font. */
+ int line_pointer; /* The line that currently is at the top
+ of the window being displayed. */
+ Dimension offset; /* Drawing offset because of scrollbar. */
+ GC move_gc; /* GC to use when moving the text. */
+ GC bold_gc, normal_gc, italic_gc, symbol_gc; /* gc for drawing. */
+
+ char ** top_line; /* The top line of the file. */
+ int lines; /* number of line in the file. */
+} ScrollByLinePart;
+
+/****************************************************************
+ *
+ * Full instance record declaration
+ *
+ ****************************************************************/
+
+typedef struct _ScrollByLineRec {
+ CorePart core;
+ SimplePart simple;
+ ScrollByLinePart scroll;
+} ScrollByLineRec;
+
+#endif /* _XtScrollByLinePrivate_h --- DON'T ADD STUFF AFTER THIS LINE */
diff --git a/buttons.c b/buttons.c
new file mode 100644
index 0000000..5779280
--- /dev/null
+++ b/buttons.c
@@ -0,0 +1,739 @@
+/* $XConsortium: buttons.c,v 1.33 94/04/17 20:43:50 dave Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/buttons.c,v 1.4 2003/01/19 04:44:45 paulo Exp $ */
+
+/*
+ * xman - X window system manual page display program.
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: October 27, 1987
+ */
+
+#include "globals.h"
+#include "vendor.h"
+
+/* The files with the icon bits in them. */
+
+#include "icon_open.h"
+#include "icon_help.h"
+#include "iconclosed.h"
+
+static void CreateOptionMenu(ManpageGlobals * man_globals, Widget parent);
+static void CreateSectionMenu(ManpageGlobals * man_globals, Widget parent);
+static void StartManpage(ManpageGlobals * man_globals, Boolean help, Boolean page);
+static Widget * ConvertNamesToWidgets(Widget parent, char ** names);
+
+/* Function Name: MakeTopBox
+ * Description: This funtion creates the top menu, in a shell widget.
+ * Arguments: none.
+ * Returns: the top level widget
+ */
+
+#define TOPARGS 5
+
+extern Atom wm_delete_window; /* in main.c */
+
+Widget top; /* needed in PopupWarning, misc.c */
+
+void
+MakeTopBox(void)
+{
+ Widget form, command, label; /* widgets. */
+ Arg arglist[TOPARGS]; /* An argument list */
+ Cardinal num_args = 0; /* The number of arguments. */
+ ManpageGlobals * man_globals;
+ static char * full_size[] = {
+ "topLabel", MANPAGE_BUTTON, NULL
+ };
+ static char * half_size[] = {
+ HELP_BUTTON, QUIT_BUTTON, NULL
+ };
+
+/* create the top icon. */
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNiconPixmap,
+ XCreateBitmapFromData( XtDisplay(initial_widget),
+ XtScreen(initial_widget)->root,
+ (char *)iconclosed_bits, iconclosed_width,
+ iconclosed_height));
+ num_args++;
+ XtSetArg(arglist[num_args], XtNtitle, resources.title);
+ num_args++;
+ XtSetArg(arglist[num_args], XtNiconic, resources.iconic);
+ num_args++;
+ top = XtCreatePopupShell(TOPBOXNAME, topLevelShellWidgetClass,
+ initial_widget, arglist, num_args);
+
+ form = XtCreateManagedWidget("form", formWidgetClass, top,
+ NULL, (Cardinal) 0);
+
+ label = XtCreateManagedWidget("topLabel", labelWidgetClass, form,
+ NULL, (Cardinal) 0);
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNfromVert, label); num_args++;
+ command = XtCreateManagedWidget(HELP_BUTTON, commandWidgetClass, form,
+ arglist, num_args);
+
+ /* use same vertical as help widget. */
+ XtSetArg(arglist[num_args], XtNfromHoriz, command); num_args++;
+ command = XtCreateManagedWidget(QUIT_BUTTON, commandWidgetClass, form,
+ arglist, num_args);
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNfromVert, command); num_args++;
+ command = XtCreateManagedWidget(MANPAGE_BUTTON, commandWidgetClass, form,
+ arglist, num_args);
+
+ help_widget = NULL; /* We have not seen the help yet. */
+
+ FormUpWidgets(form, full_size, half_size);
+
+ XtRealizeWidget(top);
+ /* add WM_COMMAND property */
+ XSetCommand(XtDisplay(top), XtWindow(top), saved_argv, saved_argc);
+
+ man_globals = (ManpageGlobals*) XtMalloc( (Cardinal) sizeof(ManpageGlobals));
+ man_globals->label = NULL;
+ man_globals->search_widget = NULL;
+ man_globals->manpagewidgets.directory = NULL;
+ man_globals->manpagewidgets.manpage = NULL;
+ man_globals->manpagewidgets.box = NULL;
+ man_globals->current_directory = 0;
+ MakeSearchWidget(man_globals, top);
+ MakeSaveWidgets(man_globals, top);
+
+ SaveGlobals( (man_globals->This_Manpage = top), man_globals);
+ XtMapWidget(top);
+ AddCursor(top, resources.cursors.top);
+
+/*
+ * Set up ICCCM delete window.
+ */
+ XtOverrideTranslations
+ (top, XtParseTranslationTable ("<Message>WM_PROTOCOLS: Quit()"));
+ (void) XSetWMProtocols (XtDisplay(top), XtWindow(top),
+ &wm_delete_window, 1);
+
+
+}
+
+/* Function Name: CreateManpage
+ * Description: Creates a new manpage.
+ * Arguments: none.
+ * Returns: none.
+ */
+
+Widget
+CreateManpage(FILE * file)
+{
+ ManpageGlobals * man_globals; /* The psuedo global structure. */
+
+ man_globals = InitPsuedoGlobals();
+ CreateManpageWidget(man_globals, MANNAME, TRUE);
+
+ if (file == NULL)
+ StartManpage( man_globals, OpenHelpfile(man_globals), FALSE );
+ else {
+ OpenFile(man_globals, file);
+ StartManpage( man_globals, FALSE, TRUE);
+ }
+ return(man_globals->This_Manpage);
+}
+
+/* Function Name: InitPsuedoGlobals
+ * Description: Initializes the psuedo global variables.
+ * Arguments: none.
+ * Returns: a pointer to a new pseudo globals structure.
+ */
+
+ManpageGlobals *
+InitPsuedoGlobals(void)
+{
+ ManpageGlobals * man_globals;
+
+ /*
+ * Allocate necessary memory.
+ */
+
+ man_globals = (ManpageGlobals *)
+ XtMalloc( (Cardinal) sizeof(ManpageGlobals));
+
+ man_globals->search_widget = NULL;
+ man_globals->section_name = (char **) XtMalloc( (Cardinal) (sections *
+ sizeof(char *)));
+ man_globals->manpagewidgets.box = (Widget *) XtCalloc( (Cardinal) sections,
+ (Cardinal) sizeof(Widget));
+
+ /* Initialize the number of screens that will be shown */
+
+ man_globals->both_shown = resources.both_shown_initial;
+
+ return(man_globals);
+}
+
+/* Function Name: CreateManpageWidget
+ * Description: Creates a new manual page widget.
+ * Arguments: man_globals - a new man_globals structure.
+ * name - name of this shell widget instance.
+ * full_instance - if true then create a full manpage,
+ * otherwise create stripped down version
+ * used for help.
+ * Returns: none
+ */
+
+#define MANPAGEARGS 10
+
+void
+CreateManpageWidget(
+ManpageGlobals * man_globals,
+char * name,
+Boolean full_instance)
+{
+ Arg arglist[MANPAGEARGS]; /* An argument list for widget creation */
+ Cardinal num_args; /* The number of arguments in the list. */
+ Widget mytop, pane, hpane, mysections; /* Widgets */
+ ManPageWidgets * mpw = &(man_globals->manpagewidgets);
+
+ num_args = (Cardinal) 0;
+ XtSetArg(arglist[num_args], XtNwidth, default_width);
+ num_args++;
+ XtSetArg(arglist[num_args], XtNheight, default_height);
+ num_args++;
+
+ mytop = XtCreatePopupShell(name, topLevelShellWidgetClass, initial_widget,
+ arglist, num_args);
+
+ man_globals->This_Manpage = mytop; /* pointer to root widget of Manualpage. */
+ num_args = 0;
+ if (full_instance)
+ XtSetArg(arglist[num_args], XtNiconPixmap,
+ XCreateBitmapFromData( XtDisplay(mytop), XtScreen(mytop)->root,
+ (char *)icon_open_bits, icon_open_width,
+ icon_open_height));
+ else
+ XtSetArg(arglist[num_args], XtNiconPixmap,
+ XCreateBitmapFromData( XtDisplay(mytop), XtScreen(mytop)->root,
+ (char *)icon_help_bits, icon_help_width,
+ icon_help_height));
+ num_args++;
+ XtSetValues(mytop, arglist, num_args);
+
+ pane = XtCreateManagedWidget("vertPane", panedWidgetClass, mytop, NULL,
+ (Cardinal) 0);
+
+/* Create menu bar. */
+
+ hpane = XtCreateManagedWidget("horizPane", panedWidgetClass,
+ pane, NULL, (Cardinal) 0);
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNmenuName, OPTION_MENU); num_args++;
+ (void) XtCreateManagedWidget("options", menuButtonWidgetClass,
+ hpane, arglist, num_args);
+
+ CreateOptionMenu(man_globals, mytop);
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNmenuName, SECTION_MENU); num_args++;
+ mysections = XtCreateManagedWidget("sections", menuButtonWidgetClass,
+ hpane, arglist, num_args);
+
+ XtSetArg(arglist[0], XtNlabel, SHOW_BOTH);
+ XtSetValues(man_globals->both_screens_entry, arglist, (Cardinal) 1);
+
+ if (full_instance) {
+ MakeSearchWidget(man_globals, mytop);
+ CreateSectionMenu(man_globals, mytop);
+ MakeSaveWidgets(man_globals, mytop);
+ } else {
+ XtSetSensitive(mysections, FALSE);
+ XtSetArg(arglist[0], XtNsensitive, FALSE);
+ XtSetValues(man_globals->dir_entry, arglist, ONE);
+ XtSetValues(man_globals->manpage_entry, arglist, ONE);
+ XtSetValues(man_globals->help_entry, arglist, ONE);
+ XtSetValues(man_globals->search_entry, arglist, ONE);
+ XtSetValues(man_globals->both_screens_entry, arglist, ONE);
+ }
+
+ man_globals->label = XtCreateManagedWidget("manualTitle", labelWidgetClass,
+ hpane, NULL, (Cardinal) 0);
+
+/* Create Directory */
+
+ if (full_instance) {
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNallowVert, TRUE);
+ num_args++;
+
+ mpw->directory = XtCreateWidget(DIRECTORY_NAME, viewportWidgetClass,
+ pane, arglist, num_args);
+
+ man_globals->current_directory = INITIAL_DIR;
+ MakeDirectoryBox(man_globals, mpw->directory,
+ mpw->box + man_globals->current_directory,
+ man_globals->current_directory );
+ XtManageChild(mpw->box[man_globals->current_directory]);
+ }
+
+/* Create Manpage */
+
+ mpw->manpage = XtCreateWidget(MANUALPAGE, scrollByLineWidgetClass,
+ pane, NULL, (Cardinal) 0);
+
+}
+
+/* Function Name: StartManpage
+ * Description: Starts up a new manpage.
+ * Arguments: man_globals - the psuedo globals variable.
+ * help - is this a help file?
+ * page - Is there a page to display?
+ * Returns: none.
+ */
+
+static void
+StartManpage(ManpageGlobals * man_globals, Boolean help, Boolean page)
+{
+ Widget dir = man_globals->manpagewidgets.directory;
+ Widget manpage = man_globals->manpagewidgets.manpage;
+ Widget label = man_globals->label;
+ Arg arglist[1];
+
+/*
+ * If there is a helpfile then put up both screens if both_show is set.
+ */
+
+ if (page || help) {
+ if (help)
+ strcpy(man_globals->manpage_title, "Xman Help");
+
+ if (man_globals->both_shown) {
+ XtManageChild(dir);
+ man_globals->dir_shown = TRUE;
+
+ XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height);
+ XtSetValues(dir, arglist, (Cardinal) 1);
+
+ XtSetArg(arglist[0], XtNsensitive, FALSE);
+ XtSetValues(man_globals->manpage_entry, arglist, ONE);
+ XtSetValues(man_globals->dir_entry, arglist, ONE);
+
+ XtSetArg(arglist[0], XtNlabel, SHOW_ONE);
+ XtSetValues(man_globals->both_screens_entry, arglist, ONE);
+ ChangeLabel(label,
+ man_globals->section_name[man_globals->current_directory]);
+ }
+ else {
+ ChangeLabel(label,man_globals->manpage_title);
+ }
+ XtManageChild(manpage);
+ man_globals->dir_shown = FALSE;
+ }
+/*
+ * Since There is file to display, put up directory and do not allow change
+ * to manpage, show both, or help.
+ */
+ else {
+ XtManageChild(dir);
+ man_globals->dir_shown = TRUE;
+ XtSetArg(arglist[0], XtNsensitive, FALSE);
+ XtSetValues(man_globals->manpage_entry, arglist, ONE);
+ XtSetValues(man_globals->help_entry, arglist, ONE);
+ XtSetValues(man_globals->both_screens_entry, arglist, ONE);
+ man_globals->both_shown = FALSE;
+ ChangeLabel(label,
+ man_globals->section_name[man_globals->current_directory]);
+ }
+
+/*
+ * Start 'er up, and change the cursor.
+ */
+
+ XtRealizeWidget( man_globals->This_Manpage );
+ SaveGlobals( man_globals->This_Manpage, man_globals);
+ XtMapWidget( man_globals->This_Manpage );
+ AddCursor( man_globals->This_Manpage, resources.cursors.manpage);
+ XtSetArg(arglist[0], XtNtransientFor, man_globals->This_Manpage);
+ XtSetValues(XtParent(man_globals->standby), arglist, (Cardinal)1);
+ XtSetValues(XtParent(man_globals->save), arglist, (Cardinal) 1);
+ XtRealizeWidget(XtParent(man_globals->standby));
+ XtRealizeWidget(XtParent(man_globals->save));
+ AddCursor( XtParent(man_globals->standby), resources.cursors.top);
+ AddCursor( XtParent(man_globals->save), resources.cursors.top);
+
+/*
+ * Set up ICCCM delete window.
+ */
+ XtOverrideTranslations
+ (man_globals->This_Manpage,
+ XtParseTranslationTable ("<Message>WM_PROTOCOLS: RemoveThisManpage()"));
+ (void) XSetWMProtocols (XtDisplay(man_globals->This_Manpage),
+ XtWindow(man_globals->This_Manpage),
+ &wm_delete_window, 1);
+
+}
+
+/* Function Name: MenuDestroy
+ * Description: free's data associated with menu when it is destroyed.
+ * Arguments: w - menu widget.
+ * free_me - data to free.
+ * junk - not used.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+static void
+MenuDestroy(Widget w, XtPointer free_me, XtPointer junk)
+{
+ XtFree( (char *) free_me);
+}
+
+/* Function Name: CreateOptionMenu
+ * Description: Create the option menu.
+ * Arguments: man_globals - the manual page globals.
+ * parent - the button that activates the menu.
+ * Returns: none.
+ */
+
+static void
+CreateOptionMenu(ManpageGlobals * man_globals, Widget parent)
+{
+ Widget menu, entry;
+ int i;
+ static char * option_names[] = { /* Names of the buttons. */
+ DIRECTORY,
+ MANPAGE,
+ HELP,
+ SEARCH,
+ BOTH_SCREENS,
+ REMOVE_MANPAGE,
+ OPEN_MANPAGE,
+ SHOW_VERSION,
+ QUIT
+ };
+
+ menu = XtCreatePopupShell(OPTION_MENU, simpleMenuWidgetClass, parent,
+ NULL, (Cardinal) 0);
+ man_globals->option_menu = menu;
+
+ for (i = 0 ; i < NUM_OPTIONS ; i++) {
+ entry = XtCreateManagedWidget(option_names[i], smeBSBObjectClass,
+ menu, NULL, ZERO);
+ XtAddCallback(entry, XtNcallback, OptionCallback, (caddr_t) man_globals);
+ switch (i) {
+ case 0:
+ man_globals->dir_entry = entry;
+ break;
+ case 1:
+ man_globals->manpage_entry = entry;
+ break;
+ case 2:
+ man_globals->help_entry = entry;
+ break;
+ case 3:
+ man_globals->search_entry = entry;
+ break;
+ case 4:
+ man_globals->both_screens_entry = entry;
+ break;
+ case 5:
+ man_globals->remove_entry = entry;
+ break;
+ case 6:
+ man_globals->open_entry = entry;
+ break;
+ case 7:
+ man_globals->version_entry = entry;
+ break;
+ case 8:
+ man_globals->quit_entry = entry;
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+/* Function Name: CreateSectionMenu
+ * Description: Create the Section menu.
+ * Arguments: man_globals - the manual page globals.
+ * parent - the button that activates the menu.
+ * Returns: none.
+ */
+
+static void
+CreateSectionMenu(ManpageGlobals * man_globals, Widget parent)
+{
+ Widget menu, entry;
+ int i;
+ MenuStruct * menu_struct;
+ Arg args[1];
+ Cardinal num_args;
+ char entry_name[BUFSIZ];
+
+ menu = XtCreatePopupShell(SECTION_MENU, simpleMenuWidgetClass, parent,
+ NULL, (Cardinal) 0);
+
+ for (i = 0 ; i < sections ; i ++) {
+ num_args = 0;
+ XtSetArg(args[num_args], XtNlabel, manual[i].blabel); num_args++;
+ sprintf(entry_name, "section%d", i);
+
+ entry = XtCreateManagedWidget(entry_name, smeBSBObjectClass,
+ menu, args, num_args);
+ menu_struct = (MenuStruct *) XtMalloc(sizeof(MenuStruct));
+ menu_struct->data = (caddr_t) man_globals;
+ menu_struct->number = i;
+ XtAddCallback(entry, XtNcallback, DirPopupCallback, (caddr_t) menu_struct);
+ XtAddCallback(entry, XtNdestroyCallback,MenuDestroy, (caddr_t)menu_struct);
+
+ }
+}
+
+/* Function Name: CreateList
+ * Description: this function prints a label in the directory list
+ * Arguments: section - the manual section.
+ * Returns: none
+ */
+
+static char **
+CreateList(int section)
+{
+ char ** ret_list, **current;
+ int count;
+
+ ret_list = (char **) XtMalloc( (manual[section].nentries + 1) *
+ sizeof (char *));
+
+ for (current = ret_list, count = 0 ; count < manual[section].nentries ;
+ count++, current++)
+ *current = CreateManpageName(manual[section].entries[count], section,
+ manual[section].flags);
+
+ *current = NULL; /* NULL terminate the list. */
+ return(ret_list);
+}
+
+/* Function Name: MakeDirectoryBox
+ * Description: make a directory box.
+ * Arguments: man_globals - the psuedo global structure for each manpage.
+ * parent - this guys parent widget.
+ * dir_disp - the directory display widget.
+ * section - the section number.
+ * Returns: none.
+ */
+
+void
+MakeDirectoryBox(ManpageGlobals *man_globals, Widget parent, Widget *dir_disp, int section)
+{
+ Arg arglist[10];
+ Cardinal num_args;
+ char * name, label_name[BUFSIZ];
+
+ if (*dir_disp != NULL) /* If we have one, don't make another. */
+ return;
+
+ name = manual[section].blabel; /* Set the section name */
+ sprintf(label_name,"Directory of: %s",name);
+ man_globals->section_name[section] = StrAlloc(label_name);
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNlist, CreateList(section));
+ num_args++;
+ XtSetArg(arglist[num_args], XtNfont, resources.fonts.directory);
+ num_args++;
+
+ *dir_disp = XtCreateWidget(DIRECTORY_NAME, listWidgetClass, parent,
+ arglist, num_args);
+
+ XtAddCallback(*dir_disp, XtNcallback,
+ DirectoryHandler, (caddr_t) man_globals);
+}
+
+/* Function Name: MakeSaveWidgets.
+ * Description: This functions creates two popup widgets, the please
+ * standby widget and the would you like to save widget.
+ * Arguments: man_globals - the psuedo globals structure for each man page
+ * parent - the realized parent for both popups.
+ * Returns: none.
+ */
+
+void
+MakeSaveWidgets(ManpageGlobals *man_globals, Widget parent)
+{
+ Widget shell, dialog; /* misc. widgets. */
+ Arg warg[1];
+ Cardinal n = 0;
+
+/* make the please stand by popup widget. */
+ if (XtIsRealized(parent)) {
+ XtSetArg(warg[0], XtNtransientFor, parent); n++;
+ }
+ shell = XtCreatePopupShell( "pleaseStandBy", transientShellWidgetClass,
+ parent, warg, (Cardinal) n);
+
+ man_globals->standby = XtCreateManagedWidget("label", labelWidgetClass,
+ shell, NULL, (Cardinal) 0);
+
+ man_globals->save = XtCreatePopupShell("likeToSave",
+ transientShellWidgetClass,
+ parent, warg, n);
+
+ dialog = XtCreateManagedWidget("dialog", dialogWidgetClass,
+ man_globals->save, NULL, (Cardinal) 0);
+
+ XawDialogAddButton(dialog, FILE_SAVE, NULL, NULL);
+ XawDialogAddButton(dialog, CANCEL_FILE_SAVE, NULL, NULL);
+
+ if (XtIsRealized(parent)) {
+ XtRealizeWidget(shell);
+ AddCursor(shell,resources.cursors.top);
+ XtRealizeWidget(man_globals->save);
+ AddCursor(man_globals->save, resources.cursors.top);
+ }
+}
+
+/* Function Name: FormUpWidgets
+ * Description: Sizes widgets to look nice.
+ * Arguments: parent - the common parent of all the widgets.
+ * full_size - array of widget names that will he full size.
+ * half_size - array of widget names that will he half size.
+ * Returns: none
+ */
+
+void
+FormUpWidgets(Widget parent, char ** full_size, char ** half_size)
+{
+ Widget * full_widgets, * half_widgets, *temp, long_widget;
+ Dimension longest, length, b_width;
+ int interior_dist;
+ Arg arglist[2];
+
+ full_widgets = ConvertNamesToWidgets(parent, full_size);
+ half_widgets = ConvertNamesToWidgets(parent, half_size);
+
+ long_widget = NULL;
+ longest = 0;
+ XtSetArg(arglist[0], XtNwidth, &length);
+ XtSetArg(arglist[1], XtNborderWidth, &b_width);
+
+/*
+ * Find Longest widget.
+ */
+
+ for ( temp = full_widgets ; *temp != (Widget) NULL ; temp++) {
+ XtGetValues(*temp, arglist, (Cardinal) 2);
+ length += 2 * b_width;
+ if (length > longest) {
+ longest = length;
+ long_widget = *temp;
+ }
+ }
+
+ if (long_widget == (Widget) NULL) { /* Make sure we found one. */
+ PopupWarning(GetGlobals(parent),
+ "Could not find longest widget, aborting...");
+ XtFree((char *)full_widgets);
+ XtFree((char *)half_widgets);
+ return;
+ }
+
+/*
+ * Set all other full_widgets to this length.
+ */
+
+ for ( temp = full_widgets ; *temp != (Widget) NULL ; temp++ )
+ if ( long_widget != *temp) {
+ Dimension width, border_width;
+
+ XtSetArg(arglist[0], XtNborderWidth, &border_width);
+ XtGetValues(*temp, arglist, (Cardinal) 1);
+
+ width = longest - 2 * border_width;
+ XtSetArg(arglist[0], XtNwidth, width);
+ XtSetValues(*temp, arglist, (Cardinal) 1);
+ }
+
+/*
+ * Set all the half widgets to the right length.
+ */
+
+ XtSetArg(arglist[0], XtNdefaultDistance, &interior_dist);
+ XtGetValues(parent, arglist, (Cardinal) 1);
+
+ for ( temp = half_widgets ; *temp != (Widget) NULL ; temp++) {
+ Dimension width, border_width;
+
+ XtSetArg(arglist[0], XtNborderWidth, &border_width);
+ XtGetValues(*temp, arglist, (Cardinal) 1);
+
+ width = (int)(longest - interior_dist)/2 - 2 * border_width;
+ XtSetArg(arglist[0], XtNwidth, width);
+ XtSetValues(*temp, arglist, (Cardinal) 1);
+ }
+
+ XtFree((char *)full_widgets);
+ XtFree((char *)half_widgets);
+}
+
+/* Function Name: ConvertNamesToWidgets
+ * Description: Convers a list of names into a list of widgets.
+ * Arguments: parent - the common parent of these widgets.
+ * names - an array of widget names.
+ * Returns: an array of widget id's.
+ */
+
+static Widget *
+ConvertNamesToWidgets(Widget parent, char ** names)
+{
+ char ** temp;
+ Widget * ids, * temp_ids;
+ int count;
+
+ for (count = 0, temp = names; *temp != NULL ; count++, temp++);
+
+ ids = (Widget *) XtMalloc( (count + 1) * sizeof(Widget));
+
+
+ for ( temp_ids = ids; *names != NULL ; names++, temp_ids++) {
+ *temp_ids = XtNameToWidget(parent, *names);
+ if (*temp_ids == NULL) {
+ char error_buf[BUFSIZ];
+
+ sprintf(error_buf, "Could not find widget named '%s'", *names);
+ PrintError(error_buf);
+ XtFree((char *)ids);
+ return(NULL);
+ }
+ }
+
+ *temp_ids = (Widget) NULL;
+ return(ids);
+}
diff --git a/defs.h b/defs.h
new file mode 100644
index 0000000..1f40e50
--- /dev/null
+++ b/defs.h
@@ -0,0 +1,139 @@
+/* $XConsortium: defs.h,v 1.25 94/04/17 20:43:50 converse Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/defs.h,v 1.3 2001/04/19 19:54:51 dawes Exp $ */
+
+/*
+ * xman - X window system manual page display program.
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: October 22, 1987
+ */
+
+#ifndef HELPFILE
+#define HELPFILE "/usr/lib/X11/xman.help" /* name of the default helpfile. */
+#endif
+
+/* The default cursors */
+
+#define XMAN_CURSOR "left_ptr" /* Top level cursor. */
+#define HELP_CURSOR "left_ptr" /* The help cursor. */
+#define MANPAGE_CURSOR "left_ptr" /* The manpage cursor. */
+#define SEARCH_ENTRY_CURSOR "question_arrow" /* The search text widget
+ cursor. */
+#define DIRECTORY_NORMAL "fixed" /* The default dir font */
+
+#define OPTION_MENU "optionMenu" /* Name of the Option Menu. */
+#define SECTION_MENU "sectionMenu" /* Name of the Section Menu. */
+
+#define HELP_BUTTON "helpButton" /* Name of top help button */
+#define QUIT_BUTTON "quitButton" /* Name of top quit button */
+#define MANPAGE_BUTTON "manpageButton" /* Name of top manpage button */
+
+#define TOPBOXNAME "topBox" /* Name of the Top Box. */
+#define MANNAME "manualBrowser" /* name for each manual page widget. */
+#define SEARCHNAME "search" /* The name for the search widget. */
+#define HELPNAME "help" /* The name of the help widget. */
+#define DIRECTORY_NAME "directory" /* name of the directory widget. */
+#define MANUALPAGE "manualPage" /* name of the Scrollbyline widget that
+ contains the man page. */
+#define DIALOG "dialog"
+
+/* Names of the menu buttons */
+
+#define NUM_OPTIONS 9 /* Number of menu options. */
+
+#define DIRECTORY "displayDirectory"
+#define MANPAGE "displayManualPage"
+#define HELP "help"
+#define SEARCH "search"
+#define BOTH_SCREENS "showBothScreens"
+#define REMOVE_MANPAGE "removeThisManpage"
+#define OPEN_MANPAGE "openNewManpage"
+#define SHOW_VERSION "showVersion"
+#define QUIT "quit"
+
+/* definitions of string to use for show both and show one. */
+
+#define SHOW_BOTH "Show Both Screens"
+#define SHOW_ONE "Show One Screen"
+
+/*
+ * Things will not look right if you change these names to make
+ * MANUALSEARCH longer APROPOSSEARCH, see search.c for details.
+ */
+
+#define MANUALSEARCH "manualPage"
+#define APROPOSSEARCH "apropos"
+#define CANCEL "cancel"
+
+#define MANUAL 0
+#define APROPOS 1
+
+#define NO_SECTION_DEFAULTS ("no default sections")
+
+/*
+ * Define HANDLE_ROFFSEQ to enable parsing of '\" <string>
+ * sequences in source files to set the format pipeline.
+ * This is necessary because the default pipeline causes incorrect
+ * display of ascii(7) on Linux.
+ * This depends on GNU roff.
+ */
+#ifdef HAS_GROFF
+#define HANDLE_ROFFSEQ
+#endif
+
+#define DEFAULT_WIDTH 500 /* The default width of xman. */
+#define SECTALLOC 8 /* The number of entries allocated
+ at a time for the manual structures. */
+#define ENTRYALLOC 100 /* The number of entries allocated
+ at a time for a section. */
+
+#define INITIAL_DIR 0 /* The Initial Directory displayed. */
+
+#define COPY "cp" /* copy command */
+#define CHMOD_MODE 00666 /* permissions set on saved formatted files */
+#define MANDESC "mandesc" /* name of the mandesc files */
+
+#define INDENT 15
+#define TYP20STR "MMMMMMMMMMMMMMMMMMMM"
+
+#define FILE_SAVE "yes"
+#define CANCEL_FILE_SAVE "no"
+#define MANTEMP "/tmp/xmanXXXXXX"
+
+/*
+ * Macro Definitions.
+ */
+
+#define streq(a, b) ( strcmp((a), (b)) == 0 )
+
+/*
+ * Function definitions moved to man.h
+ */
diff --git a/globals.c b/globals.c
new file mode 100644
index 0000000..e880953
--- /dev/null
+++ b/globals.c
@@ -0,0 +1,54 @@
+/* $XConsortium: globals.c,v 1.9 94/04/17 20:43:51 rws Exp $ */
+/*
+
+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.
+
+*/
+
+
+#include "man.h"
+
+Xman_Resources resources; /* Resource manager sets these. */
+
+/* bookkeeping global variables. */
+
+Widget help_widget; /* The help widget. */
+
+int default_height,default_width; /* Approximately the default with and
+ height, of the manpage when shown,
+ the the top level manual page
+ window */
+
+Manual * manual; /* The manual structure. */
+int sections; /* The number of manual sections. */
+
+int man_pages_shown; /* The current number of manual
+ pages being shown, if 0 we exit. */
+
+Widget initial_widget; /* The initial widget, never realized. */
+
+XContext manglobals_context; /* The context for man_globals. */
diff --git a/globals.h b/globals.h
new file mode 100644
index 0000000..f6ab862
--- /dev/null
+++ b/globals.h
@@ -0,0 +1,56 @@
+/* $XConsortium: globals.h,v 1.9 94/04/17 20:43:51 dave Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/globals.h,v 1.3 2000/03/03 23:16:26 dawes Exp $ */
+
+#include "man.h"
+
+extern Xman_Resources resources; /* Resource manager sets these. */
+
+/* bookkeeping global variables. */
+
+extern Widget help_widget; /* The help widget. */
+
+extern int default_height,default_width; /* Approximately the default with and
+ height, of the manpage when shown,
+ the the top level manual page
+ window */
+extern int man_pages_shown; /* The current number of manual
+ pages being shown, if 0 we exit. */
+
+extern Manual * manual; /* The manual structure. */
+extern int sections; /* The number of manual sections. */
+
+extern XContext manglobals_context; /* The context for man_globals. */
+
+extern Widget initial_widget; /* The initial widget, never realized. */
+
+extern char **saved_argv;
+extern int saved_argc;
diff --git a/handler.c b/handler.c
new file mode 100644
index 0000000..da1fd08
--- /dev/null
+++ b/handler.c
@@ -0,0 +1,607 @@
+/* $XConsortium: handler.c,v 1.22 94/12/16 21:36:53 gildea Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/handler.c,v 1.6 2003/01/19 04:44:45 paulo Exp $ */
+
+/*
+ * xman - X window system manual page display program.
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: October 29, 1987
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "globals.h"
+#include "vendor.h"
+
+static void PutUpManpage(ManpageGlobals * man_globals, FILE * file);
+static void ToggleBothShownState(ManpageGlobals * man_globals);
+
+/* Function Name: OptionCallback
+ * Description: This is the callback function for the callback menu.
+ * Arguments: w - the widget we are calling back from.
+ * globals_pointer - a pointer to the psuedo globals structure
+ * for this manpage.
+ * junk - (call data) not used.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+OptionCallback(Widget w, XtPointer pointer, XtPointer junk)
+{
+ ManpageGlobals * man_globals = (ManpageGlobals *) pointer;
+ String params;
+ Cardinal num_params = 1;
+
+ if ( w == man_globals->search_entry )
+ PopupSearch(XtParent(w), NULL, NULL, NULL);
+ else if (w == man_globals->dir_entry) { /* Put Up Directory */
+ params = "Directory";
+ GotoPage(XtParent(w), NULL, &params, &num_params);
+ }
+ else if (w == man_globals->manpage_entry ) { /* Put Up Man Page */
+ params = "ManualPage";
+ GotoPage(XtParent(w), NULL, &params, &num_params);
+ }
+ else if ( w == man_globals->help_entry ) /* Help */
+ PopupHelp(XtParent(w), NULL, NULL, NULL);
+ else if ( w == man_globals->both_screens_entry ) /*Toggle Both_Shown State.*/
+ ToggleBothShownState(man_globals);
+ else if ( w == man_globals->remove_entry) /* Kill the manpage */
+ RemoveThisManpage(XtParent(w), NULL, NULL, NULL);
+ else if ( w == man_globals->open_entry) /* Open new manpage */
+ CreateNewManpage(XtParent(w), NULL, NULL, NULL);
+ else if ( w == man_globals->version_entry) /* Get version */
+ ShowVersion(XtParent(w), NULL, NULL, NULL);
+ else if ( w == man_globals->quit_entry) /* Quit. */
+ Quit(XtParent(w), NULL, NULL, NULL);
+}
+
+/* Function Name: ToggleBothShownState;
+ * Description: toggles the state of the both shown feature.
+ * Arguments: man_globals - the man globals structure.
+ * Returns: none.
+ */
+
+/*
+ * I did not have a two state widget, which is the way this
+ * should really be done. 1/22/88 - CDP.
+ */
+
+static void
+ToggleBothShownState(ManpageGlobals * man_globals)
+{
+ char * label_str;
+ Arg arglist[1];
+
+ if (man_globals->both_shown == TRUE) {
+ label_str = SHOW_BOTH;
+ if (man_globals->dir_shown)
+ XtUnmanageChild(man_globals->manpagewidgets.manpage);
+ else
+ XtUnmanageChild(man_globals->manpagewidgets.directory);
+ }
+ else {
+ Widget manpage = man_globals->manpagewidgets.manpage;
+ Widget dir = man_globals->manpagewidgets.directory;
+
+ label_str = SHOW_ONE;
+
+ XtSetArg(arglist[0], XtNpreferredPaneSize, resources.directory_height);
+ XtSetValues(dir, arglist, (Cardinal) 1);
+
+ if (!man_globals->dir_shown) {
+ XtUnmanageChild(manpage);
+ XtManageChild(dir);
+ }
+ XtManageChild(manpage);
+ }
+ man_globals->both_shown = !man_globals->both_shown;
+
+ if (man_globals->dir_shown)
+ ChangeLabel(man_globals->label,
+ man_globals->section_name[man_globals->current_directory]);
+ else
+ ChangeLabel(man_globals->label, man_globals->manpage_title);
+
+ XtSetArg(arglist[0], XtNlabel, label_str);
+ XtSetValues(man_globals->both_screens_entry, arglist, ONE);
+
+ /* if both are shown there is no need to switch between the two. */
+
+ XtSetArg(arglist[0], XtNsensitive, !man_globals->both_shown);
+ XtSetValues(man_globals->manpage_entry, arglist, ONE);
+ XtSetValues(man_globals->dir_entry, arglist, ONE);
+}
+
+/* Function Name: Popup
+ * Description: This function pops up the given widget under the cursor.
+ * Arguments: w - the widget to popup.
+ * grab_kind - the kind of grab to register.
+ * Returns: none
+ */
+
+/* How far off the top of the widget to have the initial cursor postion. */
+
+#define OFF_OF_TOP 25
+
+void
+Popup(Widget w, XtGrabKind grab_kind)
+{
+ int x_root,y_root,y_pos,garbage;
+ unsigned int mask;
+ Window junk_window;
+
+ XQueryPointer(XtDisplay(w), XtWindow(w), &junk_window, &junk_window,
+ &x_root, &y_root, &garbage, &garbage, &mask);
+
+ y_pos = OFF_OF_TOP - Height(w)/2 - BorderWidth(w);
+ PositionCenter(w, x_root, y_root, y_pos, 0, 2, 2);
+ XtPopup(w, grab_kind);
+}
+
+/* Function Name: PutUpManpage
+ * Description: Puts the manpage on the display.
+ * Arguments: man_globals - a pointer to the psuedo globals structure
+ * for this manpage.
+ * file - the file to display.
+ * Returns: none.
+ */
+
+static void
+PutUpManpage(ManpageGlobals * man_globals, FILE * file)
+{
+ String params = "ManualPage";
+ Cardinal num_params = 1;
+
+ if (file == NULL)
+ return;
+
+ OpenFile(man_globals, file);
+
+ if (!man_globals->both_shown) {
+ Arg arglist[1];
+ XtSetArg(arglist[0], XtNsensitive, TRUE);
+ XtSetValues(man_globals->manpage_entry, arglist, ONE);
+ XtSetValues(man_globals->both_screens_entry, arglist, ONE);
+ }
+ GotoPage(man_globals->manpagewidgets.manpage, NULL, &params, &num_params);
+}
+
+/* Function Name: DirectoryHandler
+ * Description: This is the callback function for the directory listings.
+ * Arguments: w - the widget we are calling back from.
+ * global_pointer - the pointer to the psuedo global structure
+ * associated with this manpage.
+ * ret_val - return value from the list widget.
+ * Returns: none.
+ */
+
+void
+DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val)
+{
+ FILE * file; /* The manpage file. */
+ ManpageGlobals * man_globals = (ManpageGlobals *) global_pointer;
+ XawListReturnStruct * ret_struct = (XawListReturnStruct *) ret_val;
+
+ file = FindManualFile(man_globals, man_globals->current_directory,
+ ret_struct->list_index);
+ PutUpManpage(man_globals, file);
+}
+
+/* Function Name: DirPopupCallback
+ * Description: This is the callback function for the callback menu.
+ * Arguments: w - the widget we are calling back from.
+ * pointer - a pointer to the psuedo globals structure
+ * for this manpage.
+ * junk - (call data) not used.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+DirPopupCallback(Widget w, XtPointer pointer, XtPointer junk)
+{
+ ManpageGlobals * man_globals;
+ MenuStruct * menu_struct;
+ Widget parent;
+ int number;
+ int current_box;
+
+ menu_struct = (MenuStruct *) pointer;
+ man_globals = (ManpageGlobals *) menu_struct->data;
+
+ number = menu_struct->number;
+ current_box = man_globals->current_directory;
+
+ /* We have used this guy, pop down the menu. */
+
+ if (number != current_box) {
+ /* This is the only one that we know has a parent. */
+ parent = XtParent(man_globals->manpagewidgets.box[INITIAL_DIR]);
+
+ MakeDirectoryBox(man_globals, parent,
+ man_globals->manpagewidgets.box + number, number);
+ XtUnmanageChild(man_globals->manpagewidgets.box[current_box]);
+ XtManageChild(man_globals->manpagewidgets.box[number]);
+
+ XawListUnhighlight(man_globals->manpagewidgets.box[current_box]);
+ ChangeLabel(man_globals->label, man_globals->section_name[number]);
+ man_globals->current_directory = number;
+ }
+
+ /* put up directory. */
+ if (!man_globals->both_shown) {
+ XtUnmanageChild(man_globals->manpagewidgets.manpage);
+ XtManageChild(man_globals->manpagewidgets.directory);
+ }
+}
+
+/************************************************************
+ *
+ * Action Routines.
+ *
+ ************************************************************/
+
+/* Function Name: SaveFormattedPage
+ * Description: This is the action routine may save the manpage.
+ * Arguments: w - any widget in the widget tree.
+ * event - NOT USED.
+ * params, num_params - the parameters paseed to the action
+ * routine, can be either Manpage or
+ * Directory.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+SaveFormattedPage(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals;
+ char cmdbuf[BUFSIZ], error_buf[BUFSIZ];
+
+ if (*num_params != 1) {
+ XtAppWarning(XtWidgetToApplicationContext(w),
+ "Xman - SaveFormattedPage: This action routine requires one argument.");
+ return;
+ }
+
+ man_globals = GetGlobals(w);
+
+/*
+ * If we are not active then take no action.
+ */
+
+ if (man_globals->tempfile == '\0') return;
+
+ switch (params[0][0]) {
+ case 'S':
+ case 's':
+
+#ifndef NO_COMPRESS
+ if (!man_globals->compress)
+#endif
+
+ sprintf(cmdbuf, "%s %s %s", COPY, man_globals->tempfile,
+ man_globals->save_file);
+
+#ifndef NO_COMPRESS
+ else
+ if (man_globals->gzip)
+ sprintf(cmdbuf, "%s < %s > %s", GZIP_COMPRESS, man_globals->tempfile,
+ man_globals->save_file);
+ else
+ sprintf(cmdbuf, "%s < %s > %s", COMPRESS, man_globals->tempfile,
+ man_globals->save_file);
+#endif
+
+ if(! system(cmdbuf)) {
+ /* make sure the formatted man page is fully accessible by the world */
+ if (chmod(man_globals->save_file, CHMOD_MODE) != 0) {
+ sprintf(error_buf,
+ "Couldn't set permissions on formatted man page '%s'.\n",
+ man_globals->save_file);
+ PopupWarning( man_globals, error_buf);
+ }
+ } else {
+ sprintf(error_buf, "Error while executing the command '%s'.\n",
+ cmdbuf);
+ PopupWarning( man_globals, error_buf);
+ }
+ break;
+ case 'C':
+ case 'c':
+ break;
+ default:
+ sprintf(error_buf,"%s %s", "Xman - SaveFormattedPagee:",
+ "Unknown argument must be either 'Save' or 'Cancel'.");
+ PopupWarning(man_globals, error_buf);
+ return;
+ }
+
+/*
+ * We do not need the filename anymore, and have the fd open.
+ * We will unlink it.
+ */
+
+ unlink(man_globals->tempfile);
+ XtPopdown( XtParent(XtParent(w)) );
+}
+
+/* Function Name: GotoPage
+ * Description: The Action routine that switches over to the manpage
+ * or directory.
+ * Arguments: w - any widget in the widget tree.
+ * event - NOT USED.
+ * params, num_params - the parameters paseed to the action
+ * routine, can be either Manpage or
+ * Directory.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+GotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals;
+ char error_buf[BUFSIZ];
+ Arg arglist[1];
+ Boolean sensitive;
+
+ if (*num_params != 1) {
+ XtAppWarning(XtWidgetToApplicationContext(w),
+ "Xman - GotoPage: This action routine requires one argument.");
+ return;
+ }
+
+ man_globals = GetGlobals(w);
+
+ if (man_globals->both_shown) {
+ ChangeLabel(man_globals->label,
+ man_globals->section_name[man_globals->current_directory]);
+ return;
+ }
+
+ switch (params[0][0]) {
+ case 'M':
+ case 'm':
+ XtSetArg(arglist[0], XtNsensitive, &sensitive);
+ XtGetValues(man_globals->manpage_entry, arglist, ONE);
+ if (sensitive) {
+ ChangeLabel(man_globals->label,man_globals->manpage_title);
+ XtUnmanageChild(man_globals->manpagewidgets.directory);
+ XtManageChild(man_globals->manpagewidgets.manpage);
+ man_globals->dir_shown = FALSE;
+ }
+ break;
+ case 'D':
+ case 'd':
+ ChangeLabel(man_globals->label,
+ man_globals->section_name[man_globals->current_directory]);
+ XtUnmanageChild(man_globals->manpagewidgets.manpage);
+ XtManageChild(man_globals->manpagewidgets.directory);
+ man_globals->dir_shown = TRUE;
+ break;
+ default:
+ sprintf(error_buf,"%s %s", "Xman - GotoPage: Unknown argument must be",
+ "either Manpage or Directory.");
+ XtAppWarning(XtWidgetToApplicationContext(w), error_buf);
+ return;
+ }
+}
+
+/* Function Name: Quit.
+ * Description: Quits Xman.
+ * Arguments: w - any widget.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+Quit(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ XCloseDisplay(XtDisplay(w));
+ exit(0);
+}
+
+/* Function Name: PopupHelp
+ * Description: Pops up xman's help.
+ * Arguments: w - NOT USED.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+PopupHelp(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ if (MakeHelpWidget())
+ XtPopup(help_widget,XtGrabNone);
+}
+
+/* Function Name: PopupSearch
+ * Description: Pops up this manual pages search widget.
+ * Arguments: w - any widget in this manpage.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+PopupSearch(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals = GetGlobals(w);
+
+ if (man_globals->search_widget) {
+ if (!XtIsRealized(man_globals->search_widget)) {
+ XtRealizeWidget(man_globals->search_widget);
+ AddCursor(man_globals->search_widget, resources.cursors.search_entry);
+ }
+ Popup(man_globals->search_widget, XtGrabNone);
+ }
+}
+
+/* Function Name: CreateNewManpage
+ * Description: Creates A New Manual Page.
+ * Arguments: w - NOT USED.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+CreateNewManpage(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ (void) CreateManpage(NULL);
+ man_pages_shown++;
+}
+
+/* Function Name: RemoveThisManpage
+ * Description: Removes a manual page.
+ * Arguments: w - any widget in the manpage.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+RemoveThisManpage(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals = GetGlobals(w);
+
+ if (man_globals->This_Manpage != help_widget) {
+ RemoveGlobals(man_globals->This_Manpage);
+ XtDestroyWidget(man_globals->This_Manpage);
+
+ XtFree( (char *) man_globals->section_name);
+ XtFree( (char *) man_globals->manpagewidgets.box);
+ XtFree( (char *) man_globals);
+
+ if ( (--man_pages_shown) == 0)
+ Quit(w, NULL, NULL, NULL);
+ }
+ else
+ XtPopdown(help_widget);
+}
+
+/* Function Name: Search
+ * Description: Actually performs a search.
+ * Arguments: w - any widget in the manpage.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+Search(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals = GetGlobals(w);
+ FILE * file;
+
+ XtPopdown( XtParent(XtParent(w)) ); /* popdown the search widget */
+
+ if ( (*num_params < 1) || (*num_params > 2) ) {
+ XtAppWarning(XtWidgetToApplicationContext(w),
+ "Xman - Search: This action routine requires one or two arguments.");
+ return;
+ }
+
+ switch(params[0][0]) {
+ case 'a':
+ case 'A':
+ file = DoSearch(man_globals,APROPOS);
+ break;
+ case 'm':
+ case 'M':
+ file = DoSearch(man_globals,MANUAL);
+ break;
+ case 'c':
+ case 'C':
+ file = NULL;
+ break;
+ default:
+ XtAppWarning(XtWidgetToApplicationContext(w),
+ "Xman - Search: First parameter unknown.");
+ file = NULL;
+ break;
+ }
+
+ if ( *num_params == 2 )
+ switch (params[1][0]) {
+ case 'O':
+ case 'o':
+ if (file != NULL) {
+ Widget w;
+ char * label;
+
+ w = CreateManpage(file);
+ man_pages_shown++;
+
+ /* Put title into new manual page. */
+
+ label = man_globals->manpage_title;
+ man_globals = GetGlobals(w);
+ strcpy(man_globals->manpage_title, label);
+ ChangeLabel(man_globals->label, label);
+ }
+ break;
+ default:
+ XtAppWarning(XtWidgetToApplicationContext(w),
+ "Xman - Search: Second parameter unknown.");
+ break;
+ }
+ else {
+ PutUpManpage(man_globals, file);
+ }
+}
+
+/* Function Name: ShowVersion
+ * Description: Show current version.
+ * Arguments: w - any widget in the manpage.
+ * event - NOT USED.
+ * params, num_params - NOT USED.
+ * Returns: none.
+ */
+
+/*ARGSUSED*/
+void
+ShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params)
+{
+ ManpageGlobals * man_globals = GetGlobals(w);
+ ChangeLabel(man_globals->label, XMAN_VERSION);
+}
diff --git a/help.c b/help.c
new file mode 100644
index 0000000..5abea46
--- /dev/null
+++ b/help.c
@@ -0,0 +1,110 @@
+/* $XConsortium: help.c,v 1.10 94/04/17 20:43:53 dave Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/help.c,v 1.3 2000/03/03 23:16:27 dawes Exp $ */
+
+/*
+ * xman - X window system manual page display program.
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: January 19, 1988
+ */
+
+#include "globals.h"
+
+extern Atom wm_delete_window; /* in main.c */
+
+/* Function Name: MakeHelpWidget.
+ * Description: This function creates the help widget so that it will be
+ * ready to be displayed.
+ * Arguments: none.
+ * Returns: none.
+ */
+
+Boolean
+MakeHelpWidget(void)
+{
+
+ ManpageGlobals * man_globals; /* The psuedo global structure. */
+
+ if (help_widget != NULL) /* If we already have a help widget.
+ then do not create one. */
+ return(TRUE);
+
+ man_globals = InitPsuedoGlobals();
+
+ CreateManpageWidget(man_globals, HELPNAME, FALSE);
+ help_widget = man_globals->This_Manpage;
+
+ if (OpenHelpfile(man_globals) == FALSE) {
+ XtDestroyWidget(help_widget);
+ help_widget = NULL;
+ return(FALSE);
+ }
+
+ ChangeLabel(man_globals->label, "Xman Help");
+
+ XtManageChild( man_globals->manpagewidgets.manpage );
+ XtRealizeWidget( help_widget );
+ SaveGlobals( man_globals->This_Manpage, man_globals );
+ AddCursor( help_widget, resources.cursors.manpage);
+
+/*
+ * Set up ICCCM delete window.
+ */
+ XtOverrideTranslations
+ (man_globals->This_Manpage,
+ XtParseTranslationTable ("<Message>WM_PROTOCOLS: RemoveThisManpage()"));
+ (void) XSetWMProtocols (XtDisplay(man_globals->This_Manpage),
+ XtWindow(man_globals->This_Manpage),
+ &wm_delete_window, 1);
+
+ return(TRUE);
+}
+
+/* Function Name: OpenHelpfile
+ * Description: opens the helpfile.
+ * Arguments: man_globals - the psuedo globals structure.
+ * Returns: False if no helpfile was found.
+ */
+
+Boolean
+OpenHelpfile(ManpageGlobals * man_globals)
+{
+ FILE * help_file_ptr;
+
+ if( (help_file_ptr = fopen(resources.help_file, "r")) == NULL ) {
+ PopupWarning(man_globals,
+ "Could not open help file, NO HELP WILL BE AVALIABLE.");
+ return(FALSE);
+ }
+
+ OpenFile(man_globals, help_file_ptr);
+ return(TRUE);
+}
diff --git a/icon_help.h b/icon_help.h
new file mode 100644
index 0000000..228c3c7
--- /dev/null
+++ b/icon_help.h
@@ -0,0 +1,50 @@
+/* $XConsortium: icon_help.h,v 1.5 94/04/17 20:43:54 rws Exp $ */
+/*
+
+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: August 15, 1988
+ */
+
+#define icon_help_width 30
+#define icon_help_height 30
+static unsigned char icon_help_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x00, 0xf8, 0xdf, 0xfe, 0x07,
+ 0x3e, 0xfc, 0x0f, 0x1f, 0x06, 0x00, 0x00, 0x18, 0x06, 0x00, 0x00, 0x18,
+ 0x06, 0xe0, 0x03, 0x18, 0x06, 0xf0, 0x07, 0x18, 0x06, 0x18, 0x0c, 0x18,
+ 0x06, 0x0c, 0x18, 0x18, 0x06, 0x0c, 0x18, 0x18, 0x06, 0x0c, 0x18, 0x18,
+ 0x06, 0x00, 0x18, 0x18, 0x06, 0x00, 0x18, 0x18, 0x06, 0x00, 0x0c, 0x18,
+ 0x06, 0x80, 0x07, 0x18, 0x06, 0xc0, 0x03, 0x18, 0x06, 0xc0, 0x00, 0x18,
+ 0x06, 0xc0, 0x00, 0x18, 0x06, 0xc0, 0x00, 0x18, 0x06, 0xc0, 0x00, 0x18,
+ 0x06, 0x00, 0x00, 0x18, 0x06, 0x00, 0x00, 0x18, 0x06, 0xc0, 0x00, 0x18,
+ 0x06, 0xc0, 0x00, 0x18, 0xc6, 0x03, 0xf0, 0x18, 0xfe, 0x1f, 0xfe, 0x1f,
+ 0x3e, 0xfc, 0x0f, 0x1f, 0x06, 0xc0, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00};
diff --git a/icon_open.h b/icon_open.h
new file mode 100644
index 0000000..b47b1d1
--- /dev/null
+++ b/icon_open.h
@@ -0,0 +1,50 @@
+/* $XConsortium: icon_open.h,v 1.5 94/04/17 20:43:54 rws Exp $ */
+/*
+
+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: January 29, 1988
+ */
+
+#define icon_open_width 30
+#define icon_open_height 30
+static unsigned char icon_open_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xf0, 0x00, 0xf8, 0xdf, 0xfe, 0x07,
+ 0x3e, 0xfc, 0x0f, 0x1f, 0x06, 0x00, 0x00, 0x18, 0x06, 0x30, 0x03, 0x18,
+ 0xc6, 0x31, 0xe3, 0x18, 0x36, 0x32, 0x13, 0x1b, 0x06, 0x30, 0x03, 0x18,
+ 0xc6, 0xf1, 0xe3, 0x18, 0x36, 0xe2, 0x11, 0x1b, 0x06, 0x00, 0x00, 0x18,
+ 0xc6, 0xf1, 0xe3, 0x18, 0x36, 0x32, 0x13, 0x1b, 0x06, 0x30, 0x03, 0x18,
+ 0xc6, 0xf1, 0xe3, 0x18, 0x36, 0x32, 0x10, 0x1b, 0x06, 0x30, 0x00, 0x18,
+ 0xc6, 0x01, 0xe0, 0x18, 0x36, 0x3a, 0x17, 0x1b, 0x06, 0xf8, 0x07, 0x18,
+ 0xc6, 0xd9, 0xe6, 0x18, 0x36, 0xda, 0x16, 0x1b, 0x06, 0x18, 0x06, 0x18,
+ 0x06, 0x18, 0x06, 0x18, 0xc6, 0x03, 0xf0, 0x18, 0xfe, 0x1f, 0xfe, 0x1f,
+ 0x3e, 0xfc, 0x0f, 0x1f, 0x06, 0xc0, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00};
diff --git a/iconclosed.h b/iconclosed.h
new file mode 100644
index 0000000..106068c
--- /dev/null
+++ b/iconclosed.h
@@ -0,0 +1,47 @@
+/* $XConsortium: iconclosed.h,v 1.5 94/04/17 20:43:55 rws Exp $ */
+/*
+
+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.
+
+*/
+
+/*
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: January 29, 1988
+ */
+
+#define iconclosed_width 20
+#define iconclosed_height 30
+static unsigned char iconclosed_bits[] = {
+ 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x0e, 0xf8, 0x07, 0x06, 0x00, 0x05,
+ 0xfe, 0xff, 0x04, 0xbe, 0xfb, 0x04, 0xbe, 0xfb, 0x04, 0xbe, 0xfb, 0x04,
+ 0xbe, 0xfb, 0x04, 0xbe, 0xfb, 0x04, 0x3e, 0xf8, 0x04, 0xfe, 0xff, 0x04,
+ 0xfe, 0xff, 0x04, 0x3e, 0xf8, 0x04, 0xbe, 0xfb, 0x04, 0xbe, 0xfb, 0x04,
+ 0x3e, 0xf8, 0x04, 0xbe, 0xff, 0x04, 0xbe, 0xff, 0x04, 0xfe, 0xff, 0x04,
+ 0xfe, 0xff, 0x04, 0x3e, 0xf9, 0x04, 0x3e, 0xf9, 0x04, 0xbe, 0xfa, 0x04,
+ 0xbe, 0xfa, 0x04, 0xbe, 0xfb, 0x06, 0xbe, 0xfb, 0x05, 0xfe, 0xff, 0x00,
+ 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00};
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..fb30b5a
--- /dev/null
+++ b/main.c
@@ -0,0 +1,296 @@
+/* $XConsortium: main.c,v 1.23 94/04/17 20:43:55 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/main.c,v 1.4 2001/10/28 03:34:36 tsi Exp $ */
+
+/*
+ * 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 */
+
+#if !defined(lint) && !defined(SABER) && 0
+ static char version[] = XMAN_VERSION; /* via strings. */
+#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
+
+/*
+ * The resource that we absolutely need.
+ */
+
+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,
+};
+
+/*
+ * This is necessary to keep all TopLevel shells from becoming
+ * the size that is specified on the command line.
+ */
+
+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;
+
+/*
+ * 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.
+ */
+
+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
+
+/*
+ * 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.
+ */
+
+ 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);
+
+/*
+ * We need to keep track of the number of manual pages that are shown on
+ * the screen so that if this user does not have a top box then when he
+ * removes all his manual pages we can kill off the xman process.
+ * 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.
+ */
+
+ man_pages_shown = 1;
+
+ XtAppMainLoop(app_con);
+
+ exit(0);
+}
+
+/* Function Name: ArgError
+ * Description: Prints error message about unknow arguments.
+ * Arguments: argc, argv - args not understood.
+ * Returns: none.
+ */
+
+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;
+ }
+}
+
+/* Function Name: AdjustDefResources
+ * Description: Changes default resources which contain paths when
+ * XWINHOME is set
+ * Arguments: none
+ * Returns: nothing
+ */
+
+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);
+ }
+ }
+}
diff --git a/man.c b/man.c
new file mode 100644
index 0000000..5b1627d
--- /dev/null
+++ b/man.c
@@ -0,0 +1,1160 @@
+/* $XConsortium: man.c,v 1.30 94/04/17 20:43:56 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/man.c,v 1.7 2002/08/05 01:47:34 torrey Exp $ */
+
+
+#include "globals.h"
+#include "vendor.h" /* vendor-specific defines and data */
+
+#ifndef X_NOT_POSIX
+#include <dirent.h>
+#else
+#ifdef SYSV
+#include <dirent.h>
+#else
+#ifdef USG
+#include <dirent.h>
+#else
+#include <sys/dir.h>
+#ifndef dirent
+#define dirent direct
+#endif
+#endif
+#endif
+#endif
+
+#ifdef DEBUG
+static char error_buf[BUFSIZ]; /* The buffer for error messages. */
+#endif /* DEBUG */
+
+static void AddToCurrentSection(Manual * local_manual, char * path);
+static void InitManual(Manual * l_manual, char * label);
+static void ReadCurrentSection(Manual * local_manual, char * path);
+static void ReadMandescFile(SectionList ** section_list, char * path);
+static void SortAndRemove(Manual *man, int number);
+static void SortList(SectionList ** list);
+
+#define SECT_ERROR -1
+
+#ifndef Byte
+#define Byte unsigned char
+#endif
+
+#ifndef reg
+#define reg register
+#endif
+
+static void sortstrs (Byte *data[], int size, Byte *otherdata[]);
+static void sortstrs_block (Byte **, Byte **, int, Byte, Byte **, Byte **);
+static void sortstrs_block_oo (Byte **, Byte **, int, Byte, int *, int *, Byte **, Byte **);
+
+/* Function Name: Man
+ * Description: Builds a list of all manual directories and files.
+ * Arguments: none.
+ * Returns: the number of manual sections.
+ */
+
+int
+Man(void)
+{
+ SectionList *list = NULL;
+ char *ptr, *lang = 0, manpath[BUFSIZ], buf[BUFSIZ], *path, *current_label;
+ int sect, num_alloced;
+
+/*
+ * Get the environment variable MANPATH, and if it doesn't exist then use
+ * SYSMANPATH and LOCALMANPATH.
+ */
+
+ /* if MANPATH variable ends in ':'. So, should extend it's value to the
+ * default search path.
+ */
+
+ *manpath = '\0';
+ if ((ptr = getenv("MANPATH")) != NULL)
+ strcpy(manpath, ptr);
+ if (ptr == NULL || streq(ptr , "") || ptr[strlen(ptr) - 1] == ':') {
+ lang = getenv("LANG");
+#ifdef MANCONF
+ if (!ReadManConfig(manpath + strlen(manpath)))
+#endif
+ {
+#ifdef MANCONF
+ if (manpath[strlen(manpath) - 1] != ':')
+ strcat(manpath, ":");
+#endif
+ strcat(manpath, SYSMANPATH);
+#ifdef LOCALMANPATH
+ strcat(manpath, ":");
+ strcat(manpath, LOCALMANPATH);
+#endif
+ }
+ }
+
+/*
+ * Get the list of manual directories in the users MANPATH that we should
+ * open to look for manual pages. The ``mandesc'' file is read here.
+ */
+
+ for ( path = manpath ; (ptr = index(path , ':')) != NULL ; path = ++ptr) {
+ *ptr = '\0';
+ if (lang != 0) {
+ strcpy(buf, path);
+ strcat(buf, "/");
+ strncat(buf, lang, sizeof(buf) - strlen(path) + 1);
+ buf[sizeof(buf) - strlen(path) + 1] = '\0';
+ ReadMandescFile(&list, buf);
+ }
+ ReadMandescFile(&list, path);
+ }
+ if (lang != 0) {
+ strcpy(buf, path);
+ strcat(buf, "/");
+ strncat(buf, lang, sizeof(buf) - strlen(path) + 1);
+ buf[sizeof(buf) - strlen(path) + 1] = '\0';
+ ReadMandescFile(&list, buf);
+ }
+ ReadMandescFile(&list, path);
+
+ SortList(&list);
+
+ sect = 0;
+ num_alloced = SECTALLOC;
+ manual = (Manual *) XtMalloc( sizeof(Manual) * num_alloced );
+ InitManual( manual, list->label );
+ manual[sect].flags = list->flags;
+ current_label = NULL;
+
+ while ( list != NULL ) {
+ SectionList * old_list;
+
+ if ( current_label == NULL || streq(list->label, current_label) )
+ AddToCurrentSection( manual + sect, list->directory);
+ else {
+ if (manual[sect].nentries == 0) { /* empty section, re-use it. */
+ XtFree(manual[sect].blabel);
+ manual[sect].blabel = list->label;
+ manual[sect].flags = list->flags;
+ }
+ else {
+ if ( ++sect >= num_alloced ) {
+ num_alloced += SECTALLOC;
+ manual = (Manual *) XtRealloc ( (char *) manual,
+ (sizeof(Manual) * num_alloced));
+ if (manual == NULL)
+ PrintError("Could not allocate memory for manual sections.");
+ }
+ InitManual( manual + sect, list->label );
+ manual[sect].flags = list->flags;
+ }
+ AddToCurrentSection( manual + sect, list->directory);
+ }
+ /* Save label to see if it matches next entry. */
+ current_label = list->label;
+ old_list = list;
+ list = list->next;
+ XtFree((char *) old_list); /* free what you allocate. */
+ }
+ if (manual[sect].nentries != 0)
+ sect++; /* don't forget that last section. */
+
+ SortAndRemove(manual, sect);
+
+#ifdef notdef /* dump info. */
+ DumpManual(sect);
+#endif
+
+/*
+ * realloc manual to be minimum space necessary.
+ */
+
+ if (sect == 0)
+ PrintError("No manual pages found.");
+ manual = (Manual *) XtRealloc( (char *) manual, (sizeof(Manual) * sect));
+ if (manual == NULL)
+ PrintError("Could not allocate memory for manual sections.");
+
+ return(sect); /* return the number of man sections. */
+}
+
+/* Function Name: SortList
+ * Description: Sorts the list of sections to search.
+ * Arguments: list - a pointer to the list to sort.
+ * Returns: a sorted list.
+ *
+ * This is the most complicated part of the entire operation.
+ * all sections with the same label must by right next to each other,
+ * but the sections that are in the standard list have to come first.
+ */
+
+static void
+SortList(SectionList ** list)
+{
+ SectionList * local;
+ SectionList *head, *last, *inner, *old;
+
+ if (*list == NULL)
+ PrintError("No manual sections to read, exiting.");
+
+/*
+ * First step
+ *
+ * Look for standard list items, and more them to the top of the list.
+ */
+
+ last = NULL; /* keep Saber happy. */
+ for ( local = *list ; local->next != NULL ; local = local->next) {
+ if ( local->flags ) {
+ if ( local == *list ) /* top element is already standard. */
+ break;
+ head = local;
+
+ /* Find end of standard block */
+ for (old = 0 ; (local->next != NULL) && (local->flags)
+ ; old = local, local = local->next);
+
+ if (old != 0) {
+ last->next = old->next; /* Move the block. */
+ old->next = *list;
+ *list = head;
+ }
+
+ break; /* First step accomplished. */
+ }
+ last = local;
+ }
+
+/*
+ * Second step
+ *
+ * Move items with duplicate labels right next to each other.
+ *
+ * Changed to keep the order of the list entries unchanged.
+ */
+
+ for (local = *list; local->next != NULL; local = local->next) {
+ head = local;
+ old = inner = local->next;
+ while (inner != NULL) {
+ if (streq(inner->label, local->label)) {
+ if (old != inner) {
+ old->next = inner->next;
+ last = inner->next;
+ inner->next = head->next;
+ head->next = inner;
+ head = inner;
+ old = inner = last;
+ continue;
+ }
+ else
+ head = inner;
+ }
+ old = inner;
+ inner = inner->next;
+ }
+ }
+}
+
+/* Function Name: ReadMandescFile
+ * Description: Reads the mandesc file, and adds more sections as
+ * nescessary.
+ * Arguments: path - path name if the current search directory.
+ * section_list - pointer to the list of sections.
+ * Returns: TRUE in we should use default sections
+ */
+
+static void
+ReadMandescFile(SectionList ** section_list, char * path)
+{
+ char mandesc_file[BUFSIZ]; /* full path to the mandesc file. */
+ FILE * descfile;
+ char string[BUFSIZ], local_file[BUFSIZ];
+ Boolean use_defaults = TRUE;
+ char *cp;
+
+ sprintf(mandesc_file, "%s/%s", path, MANDESC);
+ if ( (descfile = fopen(mandesc_file, "r")) != NULL) {
+ while ( fgets(string, BUFSIZ, descfile) != NULL) {
+ string[strlen(string)-1] = '\0'; /* Strip off the CR. */
+
+ if ( streq(string, NO_SECTION_DEFAULTS) ) {
+ use_defaults = FALSE;
+ continue;
+ }
+
+ if ((cp = index(string,'\t')) != NULL) {
+ char *s;
+ *cp++ = '\0';
+ strcpy(local_file, MAN);
+ strcat(local_file, string);
+ if ((s = index(cp,'\t')) != NULL) {
+ *s++ = '\0';
+ if (streq(s, SUFFIX))
+ AddNewSection(section_list, path, local_file, cp, MSUFFIX);
+ else if (streq(s, FOLD))
+ AddNewSection(section_list, path, local_file, cp, MFOLD);
+ else if (streq(s, FOLDSUFFIX))
+ AddNewSection(section_list, path, local_file, cp, MFOLDSUFFIX);
+ else
+ AddNewSection(section_list, path, local_file, cp, MNULL);
+ } else
+ AddNewSection(section_list, path, local_file, cp, MNULL);
+ } else {
+ sprintf(local_file, "%s%c", MAN, string[0]);
+ AddNewSection(section_list, path, local_file, (string + 1), FALSE );
+#ifdef SEARCHOTHER
+ sprintf(local_file, "%s%c", SEARCHOTHER, string[0]);
+ AddNewSection(section_list, path, local_file, (string + 1), FALSE);
+#endif
+ }
+ }
+
+ fclose(descfile);
+ }
+ if (use_defaults)
+ AddStandardSections(section_list, path);
+}
+
+/* Function Name: AddNewSection
+ * Description: Adds the new section onto the current section list.
+ * Arguments: list - pointer to the section list.
+ * path - the path to the current manual section.
+ * file - the file to save.
+ * label - the current section label.
+ * flags = 1 - add a suffix
+ * = 2 - fold to lower case
+ * Returns: none.
+ */
+
+void
+AddNewSection(
+SectionList **list,
+char * path, char * file, char * label,
+int flags)
+{
+ SectionList * local_list, * end;
+ char full_path[BUFSIZ];
+
+/* Allocate a new list element */
+
+ local_list = (SectionList *) XtMalloc(sizeof(SectionList));
+
+ if (*list != NULL) {
+ for ( end = *list ; end->next != NULL ; end = end->next );
+ end->next = local_list;
+ }
+ else
+ *list = local_list;
+
+ local_list->next = NULL;
+ local_list->label = StrAlloc(label);
+ sprintf(full_path, "%s/%s", path, file);
+ local_list->directory = StrAlloc(full_path);
+ local_list->flags = flags;
+}
+
+/* Function Name: AddToCurrentSection
+ * Description: This function gets the names of the manual page
+ * directories, then closes the directory.
+ * Arguments: local_manual - a pointer to a manual pages structure.
+ * path - the path to this directory.
+ * Returns: none.
+ */
+
+static void
+AddToCurrentSection(Manual * local_manual, char * path)
+{
+ char temp_path[BUFSIZ];
+
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ sprintf(temp_path, "%s/%s", path, MACHINE);
+ ReadCurrentSection(local_manual, temp_path);
+#endif
+ ReadCurrentSection(local_manual, path);
+ sprintf(temp_path, "%s.%s", path, COMPRESSION_EXTENSION);
+ ReadCurrentSection(local_manual, temp_path);
+}
+
+/* Function Name: ReadCurrentSection
+ * Description: Actually does the work of adding entries to the
+ * new section
+ * Arguments: local_manual - a pointer to a manual pages structure.
+ * path - the path to this directory.
+ * compressed - Is this a compressed directory?
+ * Returns: TRUE if any entries are found.
+ */
+
+static void
+ReadCurrentSection(Manual * local_manual, char * path)
+{
+ DIR * dir;
+
+ register struct dirent *dp;
+
+ register int nentries;
+ register int nalloc;
+ char full_name[BUFSIZ], *ptr;
+
+ if((dir = opendir(path)) == NULL) {
+#ifdef DEBUG
+ sprintf(error_buf,"Can't open directory %s", path);
+ PopupWarning(NULL, error_buf);
+#endif /* DEBUG */
+ return;
+ }
+
+/*
+ * Remove the compression extension from the path name.
+ */
+
+ if ( (ptr = rindex(path, '.')) != NULL) {
+#if !defined(SCO) && !defined(ISC)
+ if (streq(ptr + 1, COMPRESSION_EXTENSION))
+#else
+ if (strpbrk(ptr + 1, COMPRESSION_EXTENSIONS) != NULL)
+#endif
+ *ptr = '\0';
+#ifdef GZIP_EXTENSION
+ else if (streq(ptr + 1, GZIP_EXTENSION))
+ *ptr = '\0';
+#endif
+ }
+
+ nentries = local_manual->nentries;
+ nalloc = local_manual->nalloc;
+
+ while( (dp = readdir(dir)) != NULL ) {
+ char * name = dp->d_name;
+ if (name[0] == '.')
+ continue;
+#ifndef CRAY
+ if (index(name, '.') == NULL)
+ continue;
+#endif
+ if( nentries >= nalloc ) {
+ nalloc += ENTRYALLOC;
+ local_manual->entries =(char **) XtRealloc((char *)local_manual->entries,
+ nalloc * sizeof(char *));
+ local_manual->entries_less_paths =
+ (char **) XtRealloc((char *)local_manual->entries_less_paths,
+ nalloc * sizeof(char *));
+ }
+
+ sprintf(full_name, "%s/%s", path, name);
+/*
+ * Remove the compression extension from the entry name.
+ */
+
+ if ( (ptr = rindex(full_name, '.')) != NULL) {
+#if !defined(SCO) && !defined(ISC)
+ if (streq(ptr + 1, COMPRESSION_EXTENSION))
+#else
+ if (strpbrk(ptr + 1, COMPRESSION_EXTENSIONS) != NULL)
+#endif
+ *ptr = '\0';
+#ifdef GZIP_EXTENSION
+ else if (streq(ptr + 1, GZIP_EXTENSION))
+ *ptr = '\0';
+#endif
+ }
+ local_manual->entries[nentries] = StrAlloc(full_name);
+ local_manual->entries_less_paths[nentries] =
+ rindex(local_manual->entries[nentries], '/');
+ if ( local_manual->entries_less_paths[nentries] == NULL )
+ PrintError("Internal error while cataloging manual pages.");
+ ++ nentries;
+ }
+
+ local_manual->nentries = nentries;
+ local_manual->nalloc = nalloc;
+
+ closedir(dir);
+}
+
+/* Function Name: SortAndRemove
+ * Description: This function sorts all the entry names and
+ * then removes all the duplicate entries.
+ * Arguments: man - a pointer to the manual structure.
+ * number - the number of manual sections.
+ * Returns: an improved manual stucure
+ */
+
+static void
+SortAndRemove(Manual *man, int number)
+{
+ int i;
+ char *l1, *l2, **s1;
+
+ for ( i = 0; i < number; man++, i++) { /* sort each section */
+ register int i2 = 0;
+
+#ifdef DEBUG
+ printf("sorting section %d - %s\n", i, man->blabel);
+#endif /* DEBUG */
+
+ s1 = (char **)malloc(man->nentries * sizeof(char *));
+
+ /* temporarily remove suffixes of entries, preventing them from */
+ /* being used in alpabetic comparison ie sccs-delta.1 vs sccs.1 */
+ for (i2=0; i2<man->nentries; i2++)
+ if ((s1[i2] = rindex(man->entries_less_paths[i2], '.')) != NULL)
+ *s1[i2] = '\0';
+
+ sortstrs ( (Byte **)man->entries_less_paths, man->nentries, (Byte **)man->entries );
+
+ /* put back suffixes */
+ for (i2=0; i2<man->nentries; i2++)
+ if (s1[i2] != NULL) *s1[i2] = '.';
+
+ free(s1);
+
+#ifdef DEBUG
+ printf("removing from section %d.\n", i);
+#endif /* DEBUG */
+
+ {
+ register int j, k, nent, nentm1;
+ int j2;
+ nent = man -> nentries;
+ nentm1 = nent - 1;
+ j = 0;
+ l2 = man->entries_less_paths[j++];
+ if ( l2 == NULL )
+ PrintError("Internal error while removing duplicate manual pages.");
+ while ( j < nentm1 )
+ {
+ l1 = l2;
+ l2 = man->entries_less_paths[j++];
+ if ( l2 == NULL )
+ PrintError("Internal error while removing duplicate manual pages."
+ );
+ if ( streq(l1,l2) )
+ {
+ j2 = j-1;
+ k = j2;
+ while ( j < nent )
+ {
+ man -> entries_less_paths[k] = man -> entries_less_paths[j];
+ man -> entries[k++] = man -> entries[j++];
+ }
+ j = j2;
+ -- man -> nentries;
+ -- nent;
+ -- nentm1;
+ }
+ }
+ }
+ }
+}
+
+ /*
+ ******* Replacement for qsort to keep
+ ******* identical entries in order
+
+ A somewhat ugly hack of something that was once simpler...
+ */
+ /*
+ Sort an array of pointers to strings, keeping it
+ in ascending order by (1) string comparison and
+ (2) original entry order in the pointer array.
+
+ This is a modified radix exchange algorithm.
+
+ In case there's insufficient memory for a temporary copy
+ of the pointer array, the original order of identical strings
+ isn't preserved.
+ */
+
+static void
+sortstrs (Byte *data[], int size, Byte *otherdata[])
+{
+ Byte **sp, **ep;
+ Byte **othersp, **otherep;
+ int *origorder;
+
+ origorder = (int *) calloc (size, sizeof(int));
+ if ( origorder )
+ {
+ reg int i;
+
+ for ( i=0; i < size; ++i )
+ origorder[i] = i;
+ }
+
+ sp = data;
+ ep = &data[size-1];
+ othersp = otherdata;
+ otherep = &otherdata[size-1];
+ if ( origorder )
+ {
+ sortstrs_block_oo ( sp, ep, 0, 0x80, origorder, &origorder[size-1],
+ othersp, otherep );
+ free (origorder);
+ }
+ else
+ sortstrs_block ( sp, ep, 0, 0x80, othersp, otherep );
+}
+
+
+
+ /*---------------------------------*/
+ /* Sort 1 block of data on 1 bit */
+ /*---------------------------------*/
+
+static void
+sortstrs_block (
+ Byte **start,
+ Byte **end,
+ int offset,
+ Byte mask,
+ Byte **otherstart,
+ Byte **otherend)
+
+{
+ reg Byte **sp, **ep;
+ reg Byte m;
+ reg int off;
+ reg Byte *t;
+ reg int curstrlen;
+ int maxstrlen;
+ Byte **othersp, **otherep;
+
+
+#define newstring(ptr) \
+ { \
+ t = *ptr; \
+ curstrlen = 0; \
+ while ( *t++ ) ++ curstrlen; \
+ if ( curstrlen > maxstrlen ) maxstrlen = curstrlen; \
+ t = *ptr; \
+ }
+
+
+ maxstrlen = 0;
+ sp = start;
+ ep = end;
+ off = offset;
+ m = mask;
+ othersp = otherstart;
+ otherep = otherend;
+
+ while (1)
+ {
+ newstring(sp)
+ while (((sp != ep) && ((curstrlen < off) || ((t[off] & m) == 0))))
+ {
+ ++ sp;
+ ++ othersp;
+ newstring(sp)
+ }
+ if ( sp == ep )
+ break;
+
+ newstring(ep);
+ while (((sp != ep) && (curstrlen >= off) && ((t[off] & m) != 0)))
+ {
+ -- ep;
+ -- otherep;
+ newstring(ep)
+ }
+ if ( sp == ep )
+ break;
+
+ t = *sp;
+ *sp = *ep;
+ *ep = t;
+
+ t = *othersp;
+ *othersp = *otherep;
+ *otherep = t;
+ }
+
+ t = *sp;
+ if ((curstrlen < off) || ((t[off] & m) == 0))
+ {
+ if ( ep != end )
+ {
+ ++ ep;
+ ++ otherep;
+ }
+ }
+ else
+ {
+ if ( sp != start )
+ {
+ -- sp;
+ -- othersp;
+ }
+ }
+
+ m >>= 1;
+ if ( m == 0 )
+ {
+ m = 0x80;
+ if ( ++off >= maxstrlen )
+ return;
+ }
+
+
+ if ( sp != start )
+ sortstrs_block ( start, sp, off, m, otherstart, othersp );
+ if ( ep != end )
+ sortstrs_block ( ep, end, off, m, otherep, otherend );
+}
+
+
+
+ /*-----------------------------------------------------------------*/
+ /* Sort 1 block of data on 1 bit; check for out-of-order entries */
+ /*-----------------------------------------------------------------*/
+
+static void
+ sortstrs_block_oo (
+ Byte **start,
+ Byte **end,
+ int offset,
+ Byte mask,
+ int *ostart,
+ int *oend,
+ Byte **otherstart,
+ Byte **otherend)
+
+{
+ reg Byte **sp, **ep;
+ reg int *osp, *oep;
+ reg Byte m;
+ reg int off;
+ reg Byte *t;
+ reg int u;
+ reg int curstrlen;
+ int maxstrlen;
+ Byte **othersp, **otherep;
+
+
+#define newstring(ptr) \
+ { \
+ t = *ptr; \
+ curstrlen = 0; \
+ while ( *t++ ) ++ curstrlen; \
+ if ( curstrlen > maxstrlen ) maxstrlen = curstrlen; \
+ t = *ptr; \
+ }
+
+
+ maxstrlen = 0;
+ sp = start;
+ ep = end;
+ osp = ostart;
+ oep = oend;
+ off = offset;
+ m = mask;
+ othersp = otherstart;
+ otherep = otherend;
+
+ while (1)
+ {
+ newstring(sp)
+ while (((sp != ep) && ((curstrlen < off) || ((t[off] & m) == 0))))
+ {
+ ++ sp;
+ ++ osp;
+ ++ othersp;
+ newstring(sp)
+ }
+ if ( sp == ep )
+ break;
+
+ newstring(ep);
+ while (((sp != ep) && (curstrlen >= off) && ((t[off] & m) != 0)))
+ {
+ -- ep;
+ -- oep;
+ -- otherep;
+ newstring(ep)
+ }
+ if ( sp == ep )
+ break;
+
+ t = *sp;
+ *sp = *ep;
+ *ep = t;
+
+ t = *othersp;
+ *othersp = *otherep;
+ *otherep = t;
+
+ u = *osp;
+ *osp = *oep;
+ *oep = u;
+ }
+
+ t = *sp;
+ if ((curstrlen < off) || ((t[off] & m) == 0))
+ {
+ if ( ep != end )
+ {
+ ++ ep;
+ ++ oep;
+ ++ otherep;
+ }
+ }
+ else
+ {
+ if ( sp != start )
+ {
+ -- sp;
+ -- osp;
+ -- othersp;
+ }
+ }
+
+ m >>= 1;
+ if ( m == 0 )
+ {
+ m = 0x80;
+ if ( ++off >= maxstrlen ) /* Finished sorting block of strings: */
+ { /* Restore duplicates to
+riginal order */
+ reg Byte **cp;
+ reg int *ocp;
+ Byte **othercp;
+
+
+ if ( sp != start )
+ {
+ cp = start;
+ ocp = ostart;
+ othercp = otherstart;
+ while ( cp != sp )
+ {
+ if ( *ocp > *(ocp+1) )
+ {
+ t = *(cp+1);
+ *(cp+1) = *cp;
+ *cp = t;
+
+ t = *(othercp+1);
+ *(othercp+1) = *othercp;
+ *othercp = t;
+
+ u = *(ocp+1);
+ *(ocp+1) = *ocp;
+ *ocp = u;
+
+ if ( cp != start )
+ {
+ -- cp;
+ -- ocp;
+ -- othercp;
+ continue;
+ }
+ }
+ ++ cp;
+ ++ ocp;
+ ++ othercp;
+ }
+ }
+ if ( ep != end )
+ {
+ cp = ep;
+ ocp = oep;
+ othercp = otherep;
+ while ( cp != end )
+ {
+ if ( *ocp > *(ocp+1) )
+ {
+ t = *(cp+1);
+ *(cp+1) = *cp;
+ *cp = t;
+
+ t = *(othercp+1);
+ *(othercp+1) = *othercp;
+ *othercp = t;
+
+ u = *(ocp+1);
+ *(ocp+1) = *ocp;
+ *ocp = u;
+
+ if ( cp != ep )
+ {
+ -- cp;
+ -- ocp;
+ -- othercp;
+ continue;
+ }
+ }
+ ++ cp;
+ ++ ocp;
+ ++ othercp;
+ }
+ }
+ return;
+ }
+ }
+
+
+ if ( sp != start )
+ sortstrs_block_oo ( start, sp, off, m, ostart, osp, otherstart, othersp );
+ if ( ep != end )
+ sortstrs_block_oo ( ep, end, off, m, oep, oend, otherep, otherend );
+}
+
+
+/* Function Name: InitManual
+ * Description: Initializes this manual section.
+ * Arguments: l_manual - local copy of the manual structure.
+ * label - the button label for this section.
+ * Returns: none.
+ */
+
+static void
+InitManual(Manual * l_manual, char * label)
+{
+ bzero( l_manual, sizeof(Manual) ); /* clear it. */
+ l_manual->blabel = label; /* set label. */
+}
+
+#if defined(DEBUG)
+
+/* Function Name: DumpManual
+ * Description: Debugging function that dumps the entire manual page
+ * structure.
+ * Arguments: number - the number of sections.
+ * Returns: none.
+ */
+
+void
+DumpManual(int number)
+{
+ register int i,j;
+
+ for ( i = 0; i < number; i++) {
+ printf("label: %s\n", manual[i].blabel);
+ for (j = 0; j < manual[i].nentries; j++)
+ printf("%s\n", manual[i].entries[j]);
+ }
+}
+
+#endif /* DEBUG */
+
+
+
+#ifdef MANCONF
+
+#if defined(MANCONFIGSTYLE_FreeBSD)
+
+/* Function Name: ReadManConfig
+ * Description: Reads man.conf file used by FreeBSD man
+ * Argument: manpath - char array to return path in.
+ * Returns: TRUE if read was successful.
+ */
+
+Bool
+ReadManConfig(char manpath[])
+{
+ FILE *fp;
+ char line[BUFSIZ];
+ char *path;
+ Bool firstpath = TRUE;
+
+ if (!(fp = fopen(MANCONF, "r")))
+ return(FALSE);
+
+ while (fgets(line, sizeof(line), fp)) {
+ path = strtok(line, " \t\n");
+ if (!path || *path == '#')
+ continue;
+ if (strcmp(path, "MANPATH_MAP") == 0)
+ path = strtok((char *)NULL, " \t\n");
+ else if (strcmp(path, "MANDATORY_MANPATH") != 0 &&
+ strcmp(path, "OPTIONAL_MANPATH") != 0)
+ return(FALSE);
+ path = strtok((char *)NULL, " \t\n");
+ if (!path || *path == '#')
+ return FALSE;
+ if (firstpath) {
+ strcpy(manpath, path);
+ firstpath = FALSE;
+ }
+ else if (!strstr(manpath,path)) {
+ strcat(manpath, ":");
+ strcat(manpath, path);
+ }
+ }
+ fclose(fp);
+ return(!firstpath);
+}
+
+
+#elif defined(MANCONFIGSTYLE_Linux) /* not FreeBSD */
+
+/* Function Name: ReadManConfig
+ * Description: Reads man.conf file used by Linux man
+ * Argument: manpath - char array to return path in.
+ * Returns: TRUE if read was successful.
+ */
+
+
+Bool
+ReadManConfig(char manpath[])
+{
+ FILE *fp;
+ char line[BUFSIZ];
+ char *path;
+ Bool firstpath = TRUE;
+
+ if (!(fp = fopen(MANCONF, "r")))
+ return(FALSE);
+
+ while (fgets(line, sizeof(line), fp)) {
+ path = strtok(line, " \t\n");
+ if (!path || *path == '#' || (strcmp(path, "MANPATH") != 0))
+ continue;
+ path = strtok((char *)NULL, " \t\n");
+ if (!path || *path == '#')
+ return FALSE;
+ if (firstpath) {
+ strcpy(manpath, path);
+ firstpath = FALSE;
+ }
+ else {
+ strcat(manpath, ":");
+ strcat(manpath, path);
+ }
+ }
+ fclose(fp);
+ return(!firstpath);
+}
+
+#elif defined(MANCONFIGSTYLE_OpenBSD) /* not FreeBSD or Linux */
+
+/* Function Name: ReadManConfig
+ * Description: Reads man.conf file used by Open/NetBSD
+ * Argument: manpath - char array to return path in.
+ * Returns: TRUE if read was successful.
+ *
+ * This version expands the glob pattern that can be found
+ * in man.conf
+ */
+#include <glob.h>
+
+Bool
+ReadManConfig(char manpath[])
+{
+ FILE *fp;
+ char line[BUFSIZ];
+ char *path;
+ Bool firstpath = TRUE;
+ glob_t gs;
+ int i;
+
+ if (!(fp = fopen(MANCONF, "r")))
+ return(FALSE);
+
+ while (fgets(line, sizeof(line), fp)) {
+ path = strtok(line, " \t\n");
+ if (!path || *path == '#')
+ continue;
+ if (strcmp(path, "_default")) {
+ /* for now */
+ continue;
+ }
+ memset(&gs, 0, sizeof(glob_t));
+ while ((path = strtok((char *)NULL, " \t\n"))) {
+ if (glob(path, GLOB_BRACE, NULL, &gs) < 0) {
+ return FALSE;
+ }
+ } /* while */
+ for (i = 0; i < gs.gl_pathc; i++) {
+
+ if (firstpath) {
+ strcpy(manpath, gs.gl_pathv[i]);
+ firstpath = FALSE;
+ }
+ else {
+ strcat(manpath, ":");
+ strcat(manpath, gs.gl_pathv[i]);
+ }
+ } /* for */
+ globfree(&gs);
+ }
+ fclose(fp);
+ return(!firstpath);
+}
+
+#elif defined(MANCONFIGSTYLE_BSD) /* not FreeBSD, Linux, or OpenBSD */
+
+/* Function Name: ReadManConfig
+ * Description: Reads man.conf file used by BSD 4.4
+ * Argument: manpath - char array to return path in.
+ * Returns: TRUE if read was successful.
+ */
+
+Bool
+ReadManConfig(manpath)
+
+char manpath[];
+
+{
+ FILE *fp;
+ char line[BUFSIZ];
+ char *path;
+ Bool firstpath = TRUE;
+
+ if (!(fp = fopen(MANCONF, "r")))
+ return(FALSE);
+
+ while (fgets(line, sizeof(line), fp)) {
+ path = strtok(line, " \t\n");
+ if (!path || *path == '#' || strcmp(path, "_default"))
+ continue;
+ while ((path = strtok((char *)NULL, " \t\n"))) {
+ if (firstpath) {
+ strcpy(manpath, path);
+ firstpath = FALSE;
+ }
+ else {
+ strcat(manpath, ":");
+ strcat(manpath, path);
+ }
+ }
+ }
+ fclose(fp);
+ return(!firstpath);
+}
+
+#else /* not BSD */
+
+#error "MANCONF defined (in vendor.h) for unknown operating system."
+
+#endif /* MANCONFIGSTYLE == FreeBSD ... BSD */
+
+#endif /* MANCONF */
diff --git a/man.h b/man.h
new file mode 100644
index 0000000..b189473
--- /dev/null
+++ b/man.h
@@ -0,0 +1,256 @@
+/* $XConsortium: man.h,v 1.31 94/12/16 21:36:53 gildea Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/man.h,v 1.4 2001/07/25 15:05:27 dawes Exp $ */
+
+
+/* X toolkit header files */
+
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/Shell.h>
+
+#include <X11/Xaw/Cardinals.h>
+
+/* Std system and C header files */
+
+#include <stdio.h>
+
+#include <X11/Xfuncs.h>
+#include <X11/Xos.h>
+
+/* X include files */
+
+#include <X11/Xatom.h>
+
+/* Widget header files. */
+
+#include <X11/Xaw/AsciiText.h>
+#include <X11/Xaw/SmeBSB.h>
+#include <X11/Xaw/Box.h>
+#include <X11/Xaw/Command.h>
+#include <X11/Xaw/Dialog.h>
+#include <X11/Xaw/Label.h>
+#include <X11/Xaw/List.h>
+#include <X11/Xaw/MenuButton.h>
+#include <X11/Xaw/SimpleMenu.h>
+#include <X11/Xaw/Paned.h>
+#include <X11/Xaw/Viewport.h>
+
+/* program specific header files. */
+
+#include "ScrollByL.h"
+
+#include "version.h"
+#include "defs.h"
+
+/*
+ * Assigning values here allows the user of Bitwise Or.
+ */
+
+typedef struct _XmanFonts {
+ XFontStruct * directory; /* The font for the directory. */
+} XmanFonts;
+
+typedef struct _XmanCursors {
+ Cursor top, /* The top Cursor, default for xman. */
+ help, /* The top cursor for the help menu. */
+ manpage, /* The cursor for the Manpage. */
+ search_entry; /* The cursor for the text widget in the
+ search box.*/
+ Pixel fg_color; /* foreground color of cursors. */
+ Pixel bg_color; /* background color of cursors. */
+} XmanCursors;
+
+typedef struct _ManPageWidgets {
+ Widget manpage, /* The manual page window (scrolled) */
+ directory, /* The widget in which all directories will
+ appear. */
+ *box; /* The boxes containing the sections. */
+} ManPageWidgets;
+
+typedef struct _MenuStruct {
+ caddr_t data;
+ int number;
+ XrmQuark quark;
+} MenuStruct;
+
+/*
+ * The manual sections and entries
+ */
+
+typedef struct tManual {
+ char * blabel; /* The button label. */
+ char ** entries; /* The individual man page file names. */
+ char ** entries_less_paths; /* Entry names only */
+ int nentries; /* how many (TOTAL)*/
+ int nalloc; /* how much space allocated */
+ int flags; /* suffix, fold */
+} Manual;
+
+/* psuedo Globals that are specific to each manpage created. */
+
+typedef struct _ManpageGlobals{
+ int current_directory; /* The directory currently being shown
+ on this manpage. */
+ Boolean dir_shown, /* True if the directory is then current
+ visable screen */
+ both_shown; /* If true then both the manpage and
+ the directory are to be shown.*/
+ Widget label, /* The label widget at the top of the page. */
+ standby, /* The please standby widget. */
+ save, /* The "would you like to save?" widget. */
+ search_widget, /* The search widget popup. */
+ help_button, /* The help button. */
+ option_menu, /* The option menu. */
+ text_widget; /* text widget containing search string. */
+
+ /* Widgets (Objects really) for the command menu entries. */
+
+ Widget dir_entry, manpage_entry, help_entry,
+ search_entry, both_screens_entry, remove_entry, open_entry,
+ version_entry, quit_entry;
+
+ char manpage_title[80]; /* The label to use for the current manpage. */
+
+ char save_file[80]; /* the name of the file to save fomatted
+ page into. */
+ char tempfile[80]; /* the name of the file to copy the formatted
+ page from. */
+ Boolean compress; /* Compress file on save? */
+ Boolean gzip; /* Gzip file on save? */
+ char ** section_name; /* The name of each of the sections */
+
+ ManPageWidgets manpagewidgets; /* The manpage widgets. */
+
+ /* Things to remember when cleaning up whne killing manpage. */
+
+ Widget This_Manpage; /* a pointer to the root of
+ this manpage. */
+
+} ManpageGlobals;
+
+
+/* Resource manager sets these. */
+
+typedef struct _Xman_Resources {
+ XmanFonts fonts; /* The fonts used for the man pages. */
+ XmanCursors cursors; /* The cursors for xman. */
+ Boolean show_help_syntax; /* True of syntax message should be dumped to
+ stdout. */
+ Boolean both_shown_initial; /* The initial state of the manual pages
+ show two screens or only one. */
+ Boolean top_box_active; /* Put up the Top Box. */
+ Boolean clear_search_string; /* clear the search string each time it
+ is popped down? */
+ int directory_height; /* The default height of directory in
+ both_shown mode. */
+ char * help_file; /* The name of the help file. */
+ char * title; /* The title for topBox */
+ Boolean iconic; /* Should topBox come up in an iconic state */
+} Xman_Resources;
+
+/************************************************************
+ *
+ * Function Defintions
+ *
+ ************************************************************/
+
+/*
+ * This is easier than trying to find all calls to StrAlloc().
+ */
+
+#define StrAlloc(ptr) XtNewString(ptr)
+
+/* Standard library function definitions. */
+#include <stdlib.h>
+
+/* buttons.c */
+
+ManpageGlobals * InitPsuedoGlobals(void);
+Widget CreateManpage(FILE * file);
+void CreateManpageWidget(ManpageGlobals * man_globals, char * name, Boolean full_instance);
+void FormUpWidgets(Widget parent, char ** full_size, char ** half_size);
+void MakeDirectoryBox(ManpageGlobals *man_globals, Widget parent, Widget *dir_disp, int section);
+void MakeSaveWidgets(ManpageGlobals *man_globals, Widget parent);
+void MakeTopBox(void);
+
+/* handler.c */
+
+void DirPopupCallback(Widget w, XtPointer pointer, XtPointer junk);
+void DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val);
+void OptionCallback(Widget w, XtPointer pointer, XtPointer junk);
+void Popup(Widget w, XtGrabKind grab_kind);
+
+/* Action Routines. */
+
+void CreateNewManpage(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void GotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void PopupHelp(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void PopupSearch(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void Quit(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void RemoveThisManpage(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void SaveFormattedPage(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void Search(Widget w, XEvent * event, String * params, Cardinal * num_params);
+void ShowVersion(Widget w, XEvent * event, String * params, Cardinal * num_params);
+
+/* help.c */
+
+Boolean MakeHelpWidget(void);
+Boolean OpenHelpfile(ManpageGlobals * man_globals);
+
+/* man.c */
+Bool ReadManConfig(char manpath[]);
+int Man(void);
+
+/* misc.c */
+FILE * DoSearch(ManpageGlobals * man_globals, int type);
+FILE * FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num);
+ManpageGlobals * GetGlobals(Widget w);
+void AddCursor(Widget w, Cursor cursor);
+void ChangeLabel(Widget w, char * str);
+void OpenFile(ManpageGlobals * man_globals, FILE * file);
+void PopupWarning(ManpageGlobals * man_globals, char * string);
+void PositionCenter(Widget widget, int x, int y, int above, int left, int v_space, int h_space);
+void PrintError(char * string);
+void RemoveGlobals(Widget w);
+void SaveGlobals(Widget w, ManpageGlobals * globals);
+void ParseEntry(char *entry, char *path, char *sect, char *page);
+FILE * Format(ManpageGlobals * man_globals, char * entry);
+
+/* search */
+void MakeSearchWidget(ManpageGlobals * man_globals, Widget parent);
+
+/* tkfunctions.c */
+
+int Width(Widget);
+int Height(Widget);
+int BorderWidth(Widget);
+char * Name(Widget);
diff --git a/misc.c b/misc.c
new file mode 100644
index 0000000..b1d039d
--- /dev/null
+++ b/misc.c
@@ -0,0 +1,1054 @@
+/* $XConsortium: misc.c,v 1.31 94/12/16 21:36:53 gildea Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/misc.c,v 1.7 2001/12/28 17:09:08 dawes Exp $ */
+
+/*
+ * xman - X window system manual page display program.
+ * Author: Chris D. Peterson, MIT Project Athena
+ * Created: October 27, 1987
+ */
+
+#include "globals.h"
+#include "vendor.h"
+#include <X11/Xos.h> /* sys/types.h and unistd.h included in here */
+#include <sys/stat.h>
+#include <errno.h>
+#include <X11/Xaw/Dialog.h>
+#include <X11/Shell.h>
+
+#ifndef HAS_SNPRINTF
+#undef SCOPE
+#define SCOPE static
+#include "snprintf.c"
+#endif
+
+static FILE * Uncompress(ManpageGlobals * man_globals, char * filename);
+#ifndef HAS_MKSTEMP
+static Boolean UncompressNamed(ManpageGlobals * man_globals, char * filename,
+ char * output);
+static Boolean UncompressUnformatted(ManpageGlobals * man_globals,
+ char * entry, char * filename);
+#else
+static Boolean UncompressNamed(ManpageGlobals * man_globals, char * filename,
+ char * output, FILE ** output_fd);
+static Boolean UncompressUnformatted(ManpageGlobals * man_globals,
+ char * entry, char * filename,
+ FILE **file);
+#endif
+#ifdef HANDLE_ROFFSEQ
+static Boolean ConstructCommand(char * cmdbuf, char * path, char * filename, char * tempfile);
+#endif
+
+#if defined(ISC) || defined(SCO)
+static char *uncompress_format = NULL;
+static char *uncompress_formats[] =
+ { UNCOMPRESS_FORMAT_1,
+ UNCOMPRESS_FORMAT_2,
+ UNCOMPRESS_FORMAT_3
+ };
+#endif
+
+/* Function Name: PopupWarning
+ * Description: This function pops upa warning message.
+ * Arguments: string - the specific warning string.
+ * Returns: none
+ */
+
+extern Widget top;
+static Widget warnShell, warnDialog;
+
+static void
+PopdownWarning(Widget w, XtPointer client, XtPointer call)
+{
+ XtPopdown((Widget)client);
+}
+
+void
+PopupWarning(ManpageGlobals * man_globals, char * string)
+{
+ int n;
+ Arg wargs[3];
+ Dimension topX, topY;
+ char buffer[BUFSIZ];
+ Widget positionto;
+ Boolean hasPosition;
+
+ sprintf( buffer, "Xman Warning: %s", string);
+ hasPosition = FALSE;
+ if (man_globals->This_Manpage)
+ positionto = man_globals->This_Manpage;
+ else
+ positionto = top;
+ if (top)
+ {
+ n=0;
+ XtSetArg(wargs[n], XtNx, &topX); n++;
+ XtSetArg(wargs[n], XtNy, &topY); n++;
+ XtGetValues(top, wargs, n);
+ hasPosition = TRUE;
+ }
+
+ if (man_globals != NULL)
+ ChangeLabel(man_globals->label, buffer);
+ if (man_globals->label == NULL) {
+ n=0;
+ if (hasPosition)
+ {
+ XtSetArg(wargs[n], XtNx, topX); n++;
+ XtSetArg(wargs[n], XtNy, topY); n++;
+ }
+ XtSetArg(wargs[n], XtNtransientFor, top); n++;
+ warnShell = XtCreatePopupShell("warnShell", transientShellWidgetClass,
+ initial_widget, wargs, n);
+ XtSetArg(wargs[0], XtNlabel, buffer);
+ warnDialog = XtCreateManagedWidget("warnDialog", dialogWidgetClass,
+ warnShell, wargs, 1);
+ XawDialogAddButton(warnDialog, "dismiss", PopdownWarning,
+ (XtPointer)warnShell);
+ XtRealizeWidget(warnShell);
+ Popup(warnShell, XtGrabNone);
+ }
+}
+
+/* Function Name: PrintError
+ * Description: This Function prints an error message and exits.
+ * Arguments: string - the specific message.
+ * Returns: none. - exits tho.
+ */
+
+void
+PrintError(char * string)
+{
+ fprintf(stderr,"Xman Error: %s\n",string);
+ exit(1);
+}
+
+/* Function Name: OpenFile
+ * Description: Assignes a file to the manpage.
+ * Arguments: man_globals - global structure.
+ * file - the file pointer.
+ * Returns: none
+ */
+
+void
+OpenFile(ManpageGlobals * man_globals, FILE * file)
+{
+ Arg arglist[1];
+ Cardinal num_args = 0;
+
+ XtSetArg(arglist[num_args], XtNfile, file); num_args++;
+ XtSetValues(man_globals->manpagewidgets.manpage, arglist, num_args);
+}
+
+
+/* Function Name: FindManualFile
+ * Description: Opens the manual page file given the entry information.
+ * Arguments: man_globals - the globals info for this manpage.
+ * section_num - section number of the man page.
+ * entry_num - entry number of the man page.
+ * Returns: fp - the file pointer
+ *
+ * NOTES:
+ *
+ * If there is a uncompressed section it will look there for uncompresed
+ * manual pages first and then for individually comressed file in the
+ * uncompressed section.
+ *
+ * If there is a compressed directory then it will also look there for
+ * the manual pages.
+ *
+ * If both of these fail then it will attempt to format the manual page.
+ */
+
+FILE *
+FindManualFile(ManpageGlobals * man_globals, int section_num, int entry_num)
+{
+ FILE * file;
+ char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], *temp;
+ char filename[BUFSIZ];
+ char * entry = manual[section_num].entries[entry_num];
+ int len_cat = strlen(CAT);
+#if defined(ISC) || defined(SCO)
+ int i;
+#endif
+
+ temp = CreateManpageName(entry, 0, 0);
+ sprintf(man_globals->manpage_title, "The current manual page is: %s.", temp);
+ XtFree(temp);
+
+ ParseEntry(entry, path, section, page);
+
+/*
+ * Look for uncompressed files first.
+ */
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ /* look in machine subdir first */
+ sprintf(filename, "%s/%s%s/%s/%s", path, CAT,
+ section + len_cat, MACHINE, page);
+ if ( (file = fopen(filename,"r")) != NULL)
+ return(file);
+#endif
+
+ sprintf(filename, "%s/%s%s/%s", path, CAT, section + len_cat, page);
+ if ( (file = fopen(filename,"r")) != NULL)
+ return(file);
+
+/*
+ * Then for compressed files in an uncompressed directory.
+ */
+
+#if !defined(ISC) && !defined(SCO)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ /* look in machine subdir first */
+ sprintf(filename, "%s/%s%s/%s/%s.%s", path, CAT,
+ section + len_cat, MACHINE, page, COMPRESSION_EXTENSION);
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+#endif
+ sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
+ section + len_cat, page, COMPRESSION_EXTENSION);
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+#ifdef GZIP_EXTENSION
+ else {
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ /* look in machine subdir first */
+ sprintf(filename, "%s/%s%s/%s/%s.%s", path, CAT,
+ section + len_cat, MACHINE, page, GZIP_EXTENSION);
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+#endif
+ sprintf(filename, "%s/%s%s/%s.%s", path, CAT,
+ section + len_cat, page, GZIP_EXTENSION);
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+ }
+#endif
+#else
+ for(i = 0; i < strlen(COMPRESSION_EXTENSIONS); i++) {
+ sprintf(filename, "%s/%s%s/%s.%c", path, CAT,
+ section + len_cat, page, COMPRESSION_EXTENSIONS[i]);
+ uncompress_format = uncompress_formats[i];
+#ifdef DEBUG
+ printf("Trying .%c ...\n", COMPRESSION_EXTENSIONS[i]);
+#endif
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+ }
+#endif
+
+/*
+ * And lastly files in a compressed directory.
+ *
+ * The directory is not actually compressed it is just named man#.Z
+ * and all files in it are compressed without the .Z extension.
+ * HP does it this way (really :-).
+ */
+
+ sprintf(filename, "%s/%s%s.%s/%s", path, CAT, section + len_cat,
+ COMPRESSION_EXTENSION, page);
+ if ( (file = Uncompress(man_globals, filename)) != NULL)
+ return(file);
+/*
+ * We did not find any preformatted manual pages, try to format it.
+ */
+
+ return(Format(man_globals, entry));
+}
+
+/* Function Namecompress
+ * Description: This function will attempt to find a compressed man
+ * page and uncompress it.
+ * Arguments: man_globals - the psuedo global info.
+ * filename - name of file to uncompress.
+ * Returns:; a pointer to the file or NULL.
+ */
+
+static FILE *
+Uncompress(ManpageGlobals * man_globals, char * filename)
+{
+ char tmp_file[BUFSIZ], error_buf[BUFSIZ];
+ FILE * file;
+
+#ifndef HAS_MKSTEMP
+ if ( !UncompressNamed(man_globals, filename, tmp_file) )
+ return(NULL);
+
+ else if ((file = fopen(tmp_file, "r")) == NULL) {
+ sprintf(error_buf, "Something went wrong in retrieving the %s",
+ "uncompressed manual page try cleaning up /tmp.");
+ PopupWarning(man_globals, error_buf);
+ }
+#else
+ if (!UncompressNamed(man_globals, filename, tmp_file, &file)) {
+ sprintf(error_buf, "Something went wrong in retrieving the %s",
+ "uncompressed manual page try cleaning up /tmp.");
+ PopupWarning(man_globals, error_buf);
+ return(NULL);
+ }
+#endif
+
+ unlink(tmp_file); /* remove name in tree, it will remain
+ until we close the fd, however. */
+ return(file);
+}
+
+/* Function Name: UncompressNamed
+ * Description: This function will attempt to find a compressed man
+ * page and uncompress it.
+ * Arguments: man_globals - the psuedo global info.
+ * filename - name of file to uncompress.
+ * RETURNED output - the file name output (must be an allocated string).
+ * Returns:; TRUE if the file was found.
+ */
+
+#ifndef HAS_MKSTEMP
+static Boolean
+UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output)
+#else
+static Boolean
+UncompressNamed(ManpageGlobals * man_globals, char * filename, char * output,
+ FILE ** output_fd)
+#endif
+{
+ char tmp[BUFSIZ], cmdbuf[BUFSIZ], error_buf[BUFSIZ];
+ struct stat junk;
+#ifdef HAS_MKSTEMP
+ int fd;
+#endif
+
+ if (stat(filename, &junk) != 0) { /* Check for existance of the file. */
+ if (errno != ENOENT) {
+ sprintf(error_buf, "Error while stating file %s, errno = %d",
+ filename, errno);
+ PopupWarning(man_globals, error_buf);
+ }
+ return(FALSE);
+ }
+
+/*
+ * Using stdin is necessary to fool zcat since we cannot guarentee
+ * the .Z extension.
+ */
+
+ strcpy(tmp, MANTEMP); /* get a temp file. */
+#ifndef HAS_MKSTEMP
+ (void) mktemp(tmp);
+#else
+ fd = mkstemp(tmp);
+ if (fd < 0) {
+ PopupWarning(man_globals, "Error creating a temp file");
+ return FALSE;
+ }
+ *output_fd = fdopen(fd, "r");
+#endif
+ strcpy(output, tmp);
+
+#ifdef GZIP_EXTENSION
+ if (streq(filename + strlen(filename) - strlen(GZIP_EXTENSION),
+ GZIP_EXTENSION))
+ sprintf(cmdbuf, GUNZIP_FORMAT, filename, output);
+ else
+#endif
+ sprintf(cmdbuf, UNCOMPRESS_FORMAT, filename, output);
+ if(system(cmdbuf) == 0) /* execute search. */
+ return(TRUE);
+
+ sprintf(error_buf, "Error while uncompressing, command was: %s", cmdbuf);
+ PopupWarning(man_globals, error_buf);
+ return(FALSE);
+}
+
+/* Function Name: Format
+ * Description: This funtion formats the manual pages and interfaces
+ * with the user.
+ * Arguments: man_globals - the psuedo globals
+ * file - the file pointer to use and return
+ * entry - the current entry struct.
+ * current_box - The current directory being displayed.
+ * Returns: none.
+ */
+
+/* ARGSUSED */
+
+FILE *
+Format(ManpageGlobals * man_globals, char * entry)
+{
+ FILE * file = NULL;
+#ifdef HAS_MKSTEMP
+ int fd;
+#endif
+ Widget manpage = man_globals->manpagewidgets.manpage;
+ char cmdbuf[BUFSIZ], tmp[BUFSIZ], filename[BUFSIZ], error_buf[BUFSIZ];
+ char path[BUFSIZ];
+ XEvent event;
+ Position x,y; /* location to pop up the
+ "would you like to save" widget. */
+
+#ifndef HAS_MKSTEMP
+ if ( !UncompressUnformatted(man_globals, entry, filename) ) {
+#else
+ if ( !UncompressUnformatted(man_globals, entry, filename, &file) ) {
+#endif
+ /* We Really could not find it, this should never happen, yea right. */
+ sprintf(error_buf, "Could not open manual page, %s", entry);
+ PopupWarning(man_globals, error_buf);
+ XtPopdown( XtParent(man_globals->standby) );
+ return(NULL);
+ }
+
+#ifndef HAS_MKSTEMP
+ if ((file = fopen(filename, "r")) != NULL) {
+#else
+ if (file != NULL) {
+#endif
+ char line[BUFSIZ];
+
+ if (fgets(line, sizeof(line), file) != NULL) {
+ if (strncmp(line, ".so ", 4) == 0) {
+ line[strlen(line) - 1] = '\0';
+ fclose(file);
+ unlink(filename);
+ if (line[4] != '/') {
+ char *ptr = NULL;
+
+ strcpy(tmp, entry);
+ if ((ptr = rindex(tmp, '/')) != NULL) {
+ *ptr = '\0';
+ if ((ptr = rindex(tmp, '/')) != NULL)
+ ptr[1] = '\0';
+ }
+ }
+ else
+ *tmp = '\0';
+ sprintf(filename, "%s%s", tmp, line + 4);
+
+ return (Format(man_globals, filename));
+ }
+ }
+ fclose(file);
+ }
+
+ Popup(XtParent(man_globals->standby), XtGrabExclusive);
+ while ( !XCheckTypedWindowEvent(XtDisplay(man_globals->standby),
+ XtWindow(man_globals->standby),
+ Expose, &event) );
+ XtDispatchEvent( &event );
+ XFlush(XtDisplay(man_globals->standby));
+
+ strcpy(tmp,MANTEMP); /* Get a temp file. */
+#ifndef HAS_MKSTEMP
+ (void) mktemp(tmp);
+#else
+ fd = mkstemp(tmp);
+ file = fdopen(fd, "r");
+#endif
+ strcpy(man_globals->tempfile, tmp);
+
+ ParseEntry(entry, path, NULL, NULL);
+
+#ifndef HANDLE_ROFFSEQ
+#ifndef HAS_MKSTEMP
+ sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL,
+ filename, FORMAT, man_globals->tempfile, "2> /dev/null");
+#else
+ sprintf(cmdbuf,"cd %s ; %s %s %s >> %s %s", path, TBL,
+ filename, FORMAT, man_globals->tempfile, "2> /dev/null");
+#endif
+#else
+ /* Handle more flexible way of specifying the formatting pipeline */
+ if (! ConstructCommand(cmdbuf, path, filename, man_globals->tempfile)) {
+ sprintf(error_buf, "Constructed command was too long!");
+ PopupWarning(man_globals, error_buf);
+ file = NULL;
+ }
+ else
+#endif /* HANDLE_ROFFSEQ */
+
+ if(system(cmdbuf) != 0) { /* execute search. */
+ sprintf(error_buf,
+ "Something went wrong trying to run the command: %s", cmdbuf);
+ PopupWarning(man_globals, error_buf);
+ file = NULL;
+ }
+ else {
+#ifndef HAS_MKSTEMP
+ if ((file = fopen(man_globals->tempfile,"r")) == NULL) {
+ sprintf(error_buf, "Something went wrong in retrieving the %s",
+ "temp file, try cleaning up /tmp");
+ PopupWarning(man_globals, error_buf);
+ }
+ else {
+#endif
+
+ XtPopdown( XtParent(man_globals->standby) );
+
+ if ( (man_globals->save == NULL) ||
+ (man_globals->manpagewidgets.manpage == NULL) )
+ unlink(man_globals->tempfile);
+ else {
+ char * ptr, catdir[BUFSIZ];
+
+ /*
+ * If the catdir is writeable then ask the user if he/she wants to
+ * write the man page to it.
+ */
+
+ strcpy(catdir, man_globals->save_file);
+ if ( (ptr = rindex(catdir, '/')) != NULL) {
+ *ptr = '\0';
+
+ if ( access(catdir, W_OK) != 0 )
+ unlink(man_globals->tempfile);
+ else {
+ x = (Position) Width(man_globals->manpagewidgets.manpage)/2;
+ y = (Position) Height(man_globals->manpagewidgets.manpage)/2;
+ XtTranslateCoords(manpage, x, y, &x, &y);
+ PositionCenter( man_globals->save, (int) x, (int) y, 0, 0, 0, 0);
+ XtPopup( man_globals->save, XtGrabExclusive);
+ }
+ }
+ else
+ unlink(man_globals->tempfile);
+ }
+#ifndef HAS_MKSTEMP
+ }
+#endif
+ }
+
+ if (man_globals->compress || man_globals->gzip) /* If the original
+ was compressed
+ then this is a tempory
+ file. */
+ unlink(filename);
+
+ return(file);
+}
+
+#ifdef HANDLE_ROFFSEQ
+/* Function Name: ConstructCommand
+ * Description: Constructs the pipeline of commands necessary to format
+ * a manual page.
+ * Arguments: cmdbuf - the buffer into which to write the command
+ * path - the directory in which the original man page resides
+ * filename - the (uncompressed) manpage source file
+ * tempfile - the name of a temporary file to direct the final
+ * output of the pipeline into
+ * Returns: TRUE if the command fit into the buffer, FALSE if it would
+ * be too long (more than BUFSIZ characters)
+ */
+static Boolean
+ConstructCommand(cmdbuf, path, filename, tempfile)
+ char *cmdbuf, *path, *filename, *tempfile;
+{
+ /* The original code did the following to produce a command line:
+ * sprintf(cmdbuf,"cd %s ; %s %s %s > %s %s", path, TBL,
+ * filename, FORMAT, man_globals->tempfile, "2> /dev/null");
+ * We are more flexible and follow more or less the algorithm used
+ * by the Linux man command:
+ * + Obtain a string of letters from the following sources in order
+ * of preference:
+ * + a command line option (not implemented in xman; it's probably not
+ * useful)
+ * + the first line of the manpage source, if it is of the form:
+ * '\" <string>
+ * + the MANROFFSEQ environment variable
+ * + a default string; this is "".
+ * + Interpret the string as a pipeline of filters:
+ * + e = eqn g = grap p = pic t = tbl v = vgrind r = refer
+ * + zsoelim is always run as the first preprocessor in any case.
+ *
+ * Strictly speaking we should save a catpage iff the string comes
+ * from the file or is the default.
+ *
+ * You'll notice that we format a man page into ASCII text output and then
+ * attempt to interpret things like L^HL as bold and so forth. This
+ * is so obviously the Wrong Thing it's untrue.
+ */
+ char *c = cmdbuf; /* current posn in buffer */
+ int left = BUFSIZ; /* space left in buffer */
+ int used;
+ char *fmt;
+ FILE *file;
+ char fmtbuf[128];
+ int gotfmt = 0; /* set to 1 if we got a directive from source */
+ char *fname = NULL;
+
+ fmt = NULL;
+ /* If you have a command line option that gives a setting for fmt,
+ set it here. */
+
+ if (!fmt) {
+ /* This is the tricky bit: extract a format string from the source file
+ * Annoyingly, filename might be relative or absolute. We cheat and
+ * use system to get the thing to a known absoute filename.
+ */
+ if (filename[0] == '/') {
+ fname = filename;
+ } else {
+ fname = malloc(strlen(path) + 1 + strlen(filename) + 1);
+ if (!fname)
+ return FALSE;
+ sprintf(fname, "%s/%s", path, filename);
+ }
+ if ((file = fopen(fname, "r")) &&
+ (fgets(fmtbuf, sizeof(fmtbuf), file)) &&
+ (!memcmp(fmtbuf, "'\\\" ", 4))) {
+ /* that's squote-backslash-dquote-space */
+ int len;
+ fmt = fmtbuf + 3;
+ len = strlen(fmt);
+ if (len && (fmt[len-1] == '\n')) {
+ fmt[len-1] = 0;
+ gotfmt++;
+ }
+ }
+ if (fname && fname != filename)
+ free(fname);
+ if (!gotfmt) /* not there or some error */
+ {
+ fmt = getenv("MANROFFSEQ");
+ }
+ }
+
+ if (!fmt)
+ {
+ fmt = DEFAULT_MANROFFSEQ;
+ }
+
+
+ /* Start with the first fixed part of the command line */
+ used = snprintf(c, left, "cd %s; %s %s ", path, ZSOELIM, filename);
+ left -= used;
+ c += used;
+ if (left <= 1)
+ return (FALSE);
+
+ /* Now add preprocessors of the form '| processor' */
+ for ( ; *fmt; fmt++)
+ {
+ char *filter;
+ switch (*fmt)
+ {
+ case 'e':
+ filter = EQN;
+ break;
+ case 'g':
+ filter = GRAP;
+ break;
+ case 'p':
+ filter = PIC;
+ break;
+ case 't':
+ filter = TBL;
+ break;
+ case 'v':
+ filter = VGRIND;
+ break;
+ case 'r':
+ filter = REFER;
+ break;
+ default:
+ filter = NULL;
+ break;
+ }
+ if (filter)
+ {
+ used = snprintf(c, left, " | %s ", filter);
+ left -= used;
+ c += used;
+ if (left <= 1)
+ return (FALSE);
+ }
+ }
+
+ /* Now add the fixed trailing part 'formatprog > tempfile 2> /dev/null' */
+#ifndef HAS_MKSTEMP
+ used = snprintf(c, left, " | %s > %s 2>/dev/null", FORMAT, tempfile);
+#else
+ used = snprintf(c, left, " | %s >> %s 2>/dev/null", FORMAT, tempfile);
+#endif
+ left -= used;
+ if (left <= 1)
+ return (FALSE);
+
+ return (TRUE);
+}
+#endif /* HANDLE_ROFFSEQ */
+
+/* Function Name: UncompressUnformatted
+ * Description: Finds an uncompressed unformatted manual page.
+ * Arguments: man_globals - the psuedo global structure.
+ * entry - the manual page entry.
+ * RETURNED filename - location to put the name of the file.
+ * Returns: TRUE if the file was found.
+ */
+
+static Boolean
+#ifndef HAS_MKSTEMP
+UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
+ char * filename)
+#else
+UncompressUnformatted(ManpageGlobals * man_globals, char * entry,
+ char * filename, FILE **file)
+#endif
+{
+ char path[BUFSIZ], page[BUFSIZ], section[BUFSIZ], input[BUFSIZ];
+ int len_cat = strlen(CAT), len_man = strlen(MAN);
+
+ ParseEntry(entry, path, section, page);
+
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ /*
+ * look for uncomressed file in machine subdir first
+ */
+ sprintf(filename, "%s/%s%s/%s/%s", path, MAN,
+ section + len_cat, MACHINE, page);
+ if ( access( filename, R_OK ) == 0 ) {
+ man_globals->compress = FALSE;
+ man_globals->gzip = FALSE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s/%s", path,
+ CAT, section + len_cat, MACHINE, page);
+ return(TRUE);
+ }
+ /*
+ * Then for compressed files in an uncompressed directory.
+ */
+ sprintf(input, "%s.%s", filename, COMPRESSION_EXTENSION);
+#ifndef HAS_MKSTEMP
+ if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+ if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+ man_globals->compress = TRUE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+ CAT, section + len_cat, page, COMPRESSION_EXTENSION);
+ return(TRUE);
+ }
+#ifdef GZIP_EXTENSION
+ else {
+ sprintf(input, "%s.%s", filename, GZIP_EXTENSION);
+#ifndef HAS_MKSTEMP
+ if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+ if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+ man_globals->compress = TRUE;
+ man_globals->gzip = TRUE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+ CAT, section + len_cat, page, GZIP_EXTENSION);
+ return(TRUE);
+ }
+ }
+#endif /* GZIP_EXTENSION */
+#endif /* __OpenBSD__ || __NetBSD__ */
+/*
+ * Look for uncompressed file first.
+ */
+
+ sprintf(filename, "%s/%s%s/%s", path, MAN, section + len_man, page);
+ if ( access( filename, R_OK ) == 0 ) {
+ man_globals->compress = FALSE;
+ man_globals->gzip = FALSE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s", path,
+ CAT, section + len_cat, page);
+ return(TRUE);
+ }
+
+/*
+ * Then for compressed files in an uncompressed directory.
+ */
+
+ sprintf(input, "%s.%s", filename, COMPRESSION_EXTENSION);
+#ifndef HAS_MKSTEMP
+ if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+ if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+ man_globals->compress = TRUE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+ CAT, section + len_cat, page, COMPRESSION_EXTENSION);
+ return(TRUE);
+ }
+#ifdef GZIP_EXTENSION
+ else {
+ sprintf(input, "%s.%s", filename, GZIP_EXTENSION);
+#ifndef HAS_MKSTEMP
+ if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+ if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+ man_globals->compress = TRUE;
+ man_globals->gzip = TRUE;
+ sprintf(man_globals->save_file, "%s/%s%s/%s.%s", path,
+ CAT, section + len_cat, page, GZIP_EXTENSION);
+ return(TRUE);
+ }
+ }
+#endif
+/*
+ * And lastly files in a compressed directory.
+ */
+
+ sprintf(input, "%s/%s%s.%s/%s", path,
+ MAN, section + len_man, COMPRESSION_EXTENSION, page);
+#ifndef HAS_MKSTEMP
+ if ( UncompressNamed(man_globals, input, filename) ) {
+#else
+ if ( UncompressNamed(man_globals, input, filename, file) ) {
+#endif
+ man_globals->compress = TRUE;
+ sprintf(man_globals->save_file, "%s/%s%s.%s/%s", path,
+ CAT, section + len_cat, COMPRESSION_EXTENSION, page);
+ return(TRUE);
+ }
+ return(FALSE);
+}
+
+/* Function Name: AddCursor
+ * Description: This function adds the cursor to the window.
+ * Arguments: w - the widget to add the cursor to.
+ * cursor - the cursor to add to this widget.
+ * Returns: none
+ */
+
+void
+AddCursor(Widget w, Cursor cursor)
+{
+ XColor colors[2];
+ Arg args[10];
+ Cardinal num_args = 0;
+ Colormap c_map;
+
+ if (!XtIsRealized(w)) {
+ PopupWarning(NULL, "Widget is not realized, no cursor added.\n");
+ return;
+ }
+
+ XtSetArg( args[num_args], XtNcolormap, &c_map); num_args++;
+ XtGetValues( w, args, num_args);
+
+ colors[0].pixel = resources.cursors.fg_color;
+ colors[1].pixel = resources.cursors.bg_color;
+
+ XQueryColors (XtDisplay(w), c_map, colors, 2);
+ XRecolorCursor(XtDisplay(w), cursor, colors, colors+1);
+ XDefineCursor(XtDisplay(w),XtWindow(w),cursor);
+}
+
+/* Function Name: ChangeLabel
+ * Description: This function changes the label field of the
+ * given widget to the string in str.
+ * Arguments: w - the widget.
+ * str - the string to change the label to.
+ * Returns: none
+ */
+
+void
+ChangeLabel(Widget w, char * str)
+{
+ Arg arglist[3]; /* An argument list. */
+
+ if (w == NULL) return;
+
+ XtSetArg(arglist[0], XtNlabel, str);
+
+/* shouldn't really have to do this. */
+ XtSetArg(arglist[1], XtNwidth, 0);
+ XtSetArg(arglist[2], XtNheight, 0);
+
+ XtSetValues(w, arglist, (Cardinal) 1);
+}
+
+/*
+ * In an ideal world this would be part of the XToolkit, and I would not
+ * have to do it, but such is life sometimes. Perhaps in X11R3.
+ */
+
+/* Function Name: PositionCenter
+ * Description: This fuction positions the given widgets center
+ * in the following location.
+ * Arguments: widget - the widget widget to postion
+ * x,y - The location for the center of the widget
+ * above - number of pixels above center to locate this widget
+ * left - number of pixels left of center to locate this widget
+ * h_space, v_space - how close to get to the edges of the
+ * parent window.
+ * Returns: none
+ * Note: This should only be used with a popup widget that has override
+ * redirect set.
+ */
+
+void
+PositionCenter(Widget widget, int x, int y, int above, int left, int v_space, int h_space)
+{
+ Arg wargs[2];
+ int x_temp,y_temp; /* location of the new window. */
+ int parent_height,parent_width; /* Height and width of the parent widget or
+ the root window if it has no parent. */
+
+ x_temp = x - left - Width(widget) / 2 + BorderWidth(widget);
+ y_temp = y - above - Height(widget) / 2 + BorderWidth(widget);
+
+ parent_height = HeightOfScreen(XtScreen(widget));
+ parent_width = WidthOfScreen(XtScreen(widget));
+
+/*
+ * Check to make sure that all edges are within the viewable part of the
+ * root window, and if not then force them to be.
+ */
+
+ if (x_temp < h_space)
+ x_temp = v_space;
+ if (y_temp < v_space)
+ (y_temp = 2);
+
+ if ( y_temp + Height(widget) + v_space > parent_height )
+ y_temp = parent_height - Height(widget) - v_space;
+
+ if ( x_temp + Width(widget) + h_space > parent_width )
+ x_temp = parent_width - Width(widget) - h_space;
+
+ XtSetArg(wargs[0], XtNx, x_temp);
+ XtSetArg(wargs[1], XtNy, y_temp);
+ XtSetValues(widget, wargs, 2);
+}
+
+/* Function Name: ParseEntry(entry, path, sect, page)
+ * Description: Parses the manual pages entry filenames.
+ * Arguments: str - the full path name.
+ * path - the path name. RETURNED
+ * sect - the section name. RETURNED
+ * page - the page name. RETURNED
+ * Returns: none.
+ */
+
+void
+ParseEntry(char *entry, char *path, char *sect, char *page)
+{
+ char *c, temp[BUFSIZ];
+
+ strcpy(temp, entry);
+
+ c = rindex(temp, '/');
+ if (c == NULL)
+ PrintError("index failure in ParseEntry.");
+ *c++ = '\0';
+ if (page != NULL)
+ strcpy(page, c);
+
+ c = rindex(temp, '/');
+ if (c == NULL)
+ PrintError("index failure in ParseEntry.");
+ *c++ = '\0';
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ /* Skip machine subdirectory if present */
+ if (strcmp(c, MACHINE) == 0) {
+ c = rindex(temp, '/');
+ if (c == NULL)
+ PrintError("index failure in ParseEntry.");
+ *c++ = '\0';
+ }
+#endif
+ if (sect != NULL)
+ strcpy(sect, c);
+
+ if (path != NULL)
+ strcpy(path, temp);
+}
+
+/* Function Name: GetGlobals
+ * Description: Gets the psuedo globals associated with the
+ * manpage associated with this widget.
+ * Arguments: w - a widget in the manpage.
+ * Returns: the psuedo globals.
+ * Notes: initial_widget is a globals variable.
+ * manglobals_context is a global variable.
+ */
+
+ManpageGlobals *
+GetGlobals(Widget w)
+{
+ Widget temp;
+ caddr_t data;
+
+ while ( (temp = XtParent(w)) != initial_widget && (temp != NULL))
+ w = temp;
+
+ if (temp == NULL)
+ XtAppError(XtWidgetToApplicationContext(w),
+ "Xman: Could not locate widget in tree, exiting");
+
+ if (XFindContext(XtDisplay(w), XtWindow(w),
+ manglobals_context, &data) != XCSUCCESS)
+ XtAppError(XtWidgetToApplicationContext(w),
+ "Xman: Could not find global data, exiting");
+
+ return( (ManpageGlobals *) data);
+}
+
+/* Function Name: SaveGlobals
+ * Description: Saves the psuedo globals on the widget passed
+ * to this function, although GetGlobals assumes that
+ * the data is associated with the popup child of topBox.
+ * Arguments: w - the widget to associate the data with.
+ * globals - data to associate with this widget.
+ * Returns: none.
+ * Notes: WIDGET MUST BE REALIZED.
+ * manglobals_context is a global variable.
+ */
+
+void
+SaveGlobals(Widget w, ManpageGlobals * globals)
+{
+ if (XSaveContext(XtDisplay(w), XtWindow(w), manglobals_context,
+ (caddr_t) globals) != XCSUCCESS)
+ XtAppError(XtWidgetToApplicationContext(w),
+ "Xman: Could not save global data, are you out of memory?");
+}
+
+/* Function Name: RemoveGlobals
+ * Description: Removes the psuedo globals from the widget passed
+ * to this function.
+ * Arguments: w - the widget to remove the data from.
+ * Returns: none.
+ * Notes: WIDGET MUST BE REALIZED.
+ * manglobals_context is a global variable.
+ */
+
+void
+RemoveGlobals(Widget w)
+{
+ if (XDeleteContext(XtDisplay(w), XtWindow(w),
+ manglobals_context) != XCSUCCESS)
+ XtAppError(XtWidgetToApplicationContext(w),
+ "Xman: Could not remove global data?");
+}
diff --git a/search.c b/search.c
new file mode 100644
index 0000000..052dae0
--- /dev/null
+++ b/search.c
@@ -0,0 +1,395 @@
+/* $XConsortium: search.c,v 1.21 94/04/17 20:43:58 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/search.c,v 1.5 2001/01/27 17:24:27 herrb Exp $ */
+
+
+#include "globals.h"
+#include "vendor.h"
+
+/* Map <CR> and control-M to goto begining of file. */
+
+#define SEARCHARGS 10
+
+FILE * DoManualSearch(ManpageGlobals *man_globals, char * string);
+static int BEntrySearch(char * string, char ** first, int number);
+
+/* Function Name: MakeSearchWidget
+ * Description: This Function Creates the Search Widget.
+ * Arguments: man_globals - the pseudo globas for this manpage.
+ * w - the widgets parent
+ * Returns: the search widget.
+ */
+
+void
+MakeSearchWidget(ManpageGlobals * man_globals, Widget parent)
+{
+ Widget dialog, command, text, cancel;
+ Arg arglist[2];
+ Cardinal num_args = 0;
+
+ XtSetArg(arglist[0], XtNtransientFor, parent);
+ man_globals->search_widget = XtCreatePopupShell(SEARCHNAME,
+ transientShellWidgetClass,
+ parent,
+ arglist, 1);
+
+ if (resources.clear_search_string) {
+ XtSetArg(arglist[0], XtNvalue, ""); num_args++;
+ }
+
+ dialog = XtCreateManagedWidget(DIALOG, dialogWidgetClass,
+ man_globals->search_widget,
+ arglist, num_args);
+
+ if ( (text = XtNameToWidget(dialog, "value")) == (Widget) NULL)
+ PopupWarning(NULL, "Could not find text widget in MakeSearchWidget.");
+ else
+ XtSetKeyboardFocus(dialog, text);
+
+ XawDialogAddButton(dialog, MANUALSEARCH, NULL, NULL);
+ XawDialogAddButton(dialog, APROPOSSEARCH, NULL, NULL);
+ XawDialogAddButton(dialog, CANCEL, NULL, NULL);
+
+/*
+ * This is a bit gross, but it get the cancel button underneath the
+ * others, and forms them up to the right size..
+ */
+
+ if ( ((command = XtNameToWidget(dialog, MANUALSEARCH)) == (Widget) NULL) ||
+ ((cancel = XtNameToWidget(dialog, CANCEL)) == (Widget) NULL) )
+ PopupWarning(NULL,
+ "Could not find manual search widget in MakeSearchWidget.");
+ else {
+ static char * half_size[] = {
+ MANUALSEARCH, APROPOSSEARCH, NULL
+ };
+ static char * full_size[] = {
+ "label", "value", CANCEL, NULL
+ };
+
+ num_args = 0;
+ XtSetArg(arglist[num_args], XtNfromVert, command); num_args++;
+ XtSetArg(arglist[num_args], XtNfromHoriz, NULL); num_args++;
+ XtSetValues(cancel, arglist, num_args);
+ FormUpWidgets(dialog, full_size, half_size);
+ }
+
+}
+
+/* Function Name: SearchString
+ * Description: Returns the search string.
+ * Arguments: man_globals - the globals.
+ * Returns: the search string.
+ */
+
+static char *
+SearchString(
+ManpageGlobals * man_globals)
+{
+ Widget dialog;
+
+ dialog = XtNameToWidget(man_globals->search_widget, DIALOG);
+ if (dialog != NULL)
+ return(XawDialogGetValueString(dialog));
+
+ PopupWarning(man_globals,
+ "Could not get the search string, no search will be preformed.");
+ return(NULL);
+}
+
+
+/* Function Name: DoSearch
+ * Description: This function performs a search for a man page or apropos
+ * search upon search string.
+ * Arguments: man_globals - the pseudo globas for this manpage.
+ * type - the type of search.
+ * Returns: none.
+ */
+
+#define LOOKLINES 6
+
+/*
+ * Manual searches look through the list of manual pages for the right one
+ * with a binary search.
+ *
+ * Apropos searches still exec man -k.
+ *
+ * If nothing is found then I send a warning message to the user, and do
+ * nothing.
+ */
+
+FILE *
+DoSearch(ManpageGlobals * man_globals, int type)
+{
+ char cmdbuf[BUFSIZ],*mantmp, *manpath;
+ char tmp[BUFSIZ],path[BUFSIZ];
+ char string_buf[BUFSIZ], cmp_str[BUFSIZ], error_buf[BUFSIZ];
+ char * search_string = SearchString(man_globals);
+ FILE * file;
+#ifdef HAS_MKSTEMP
+ int fd;
+#endif
+ int count;
+ Boolean flag;
+
+ if (search_string == NULL) return(NULL);
+
+ /* If the string is empty or starts with a space then do not search */
+
+ if ( streq(search_string,"") ) {
+ PopupWarning(man_globals, "Search string is empty.");
+ return(NULL);
+ }
+
+ if (search_string[0] == ' ') {
+ PopupWarning(man_globals, "First character cannot be a space.");
+ return(NULL);
+ }
+
+ if (type == APROPOS) {
+ char label[BUFSIZ];
+
+ strcpy(tmp, MANTEMP); /* get a temp file. */
+#ifdef HAS_MKSTEMP
+ fd = mkstemp(tmp);
+ if (fd < 0) {
+ PopupWarning(man_globals, "Cant create temp file");
+ return NULL;
+ }
+#else
+ (void)mktemp(tmp);
+#endif
+ mantmp = tmp;
+
+ manpath=getenv("MANPATH");
+ if (manpath == NULL || streq(manpath,"") ) {
+#ifdef MANCONF
+ if (!ReadManConfig(path))
+#endif
+ {
+ strcpy(path,SYSMANPATH);
+#ifdef LOCALMANPATH
+ strcat(path,":");
+ strcat(path,LOCALMANPATH);
+#endif
+ }
+ } else {
+ strcpy(path,manpath);
+ }
+
+ sprintf(label,"Results of apropos search on: %s", search_string);
+
+#ifdef NO_MANPATH_SUPPORT /* not quite correct, but the best I can do. */
+ sprintf(cmdbuf, APROPOS_FORMAT, search_string, mantmp);
+#else
+ sprintf(cmdbuf, APROPOS_FORMAT, path, search_string, mantmp);
+#endif
+
+ if(system(cmdbuf) != 0) { /* execute search. */
+ sprintf(error_buf,"Something went wrong trying to run %s\n",cmdbuf);
+ PopupWarning(man_globals, error_buf);
+ }
+
+#ifdef HAS_MKSTEMP
+ if ((file = fdopen(fd, "r")) == NULL)
+#else
+ if((file = fopen(mantmp,"r")) == NULL)
+#endif
+ PrintError("lost temp file? out of temp space?");
+
+/*
+ * Since we keep the FD open we can unlink the file safely, this
+ * will keep extra files out of /tmp.
+ */
+
+ unlink(mantmp);
+
+ sprintf(string_buf,"%s: nothing appropriate", search_string);
+
+ /*
+ * Check first LOOKLINES lines for "nothing appropriate".
+ */
+
+ count = 0;
+ flag = FALSE;
+ while ( (fgets(cmp_str, BUFSIZ, file) != NULL) && (count < LOOKLINES) ) {
+ if ( cmp_str[strlen(cmp_str) - 1] == '\n') /* strip off the '\n' */
+ cmp_str[strlen(cmp_str) - 1] = '\0';
+
+ if (streq(cmp_str, string_buf)) {
+ flag = TRUE;
+ break;
+ }
+ count++;
+ }
+
+ /*
+ * If the file is less than this number of lines then assume that there is
+ * nothing apropriate found. This does not confuse the apropos filter.
+ */
+
+ if (flag) {
+ fclose(file);
+ file = NULL;
+ ChangeLabel(man_globals->label,string_buf);
+ return(NULL);
+ }
+
+ strcpy(man_globals->manpage_title,label);
+ ChangeLabel(man_globals->label,label);
+ fseek(file, 0L, 0); /* reset file to point at top. */
+ }
+ else { /* MANUAL SEACH */
+ file = DoManualSearch(man_globals, search_string);
+ if (file == NULL) {
+ sprintf(string_buf,"No manual entry for %s.", search_string);
+ ChangeLabel(man_globals->label, string_buf);
+ if (man_globals->label == NULL)
+ PopupWarning(man_globals, string_buf);
+ return(NULL);
+ }
+ }
+
+ if (resources.clear_search_string) {
+ Arg arglist[1];
+ Widget dialog;
+
+ dialog = XtNameToWidget(man_globals->search_widget, DIALOG);
+ if (dialog == NULL)
+ PopupWarning(man_globals, "Could not clear the search string.");
+
+ XtSetArg(arglist[0], XtNvalue, "");
+ XtSetValues(dialog, arglist, (Cardinal) 1);
+ }
+
+ return(file);
+}
+
+/* Function Name: DoManualSearch
+ * Description: performs a manual search.
+ * Arguments: man_globals - the manual page specific globals.
+ * Returns: the filename of the man page.
+ */
+
+#define NO_ENTRY -100
+
+FILE *
+DoManualSearch(ManpageGlobals *man_globals, char * string)
+{
+ int e_num = NO_ENTRY;
+ int i;
+
+/* search current section first. */
+
+ i = man_globals->current_directory;
+ e_num = BEntrySearch(string, manual[i].entries, manual[i].nentries);
+
+/* search other sections. */
+
+ if (e_num == NO_ENTRY) {
+ i = 0; /* At the exit of the loop i needs to
+ be the one we used. */
+ while ( TRUE ) {
+ if (i == man_globals->current_directory)
+ if (++i >= sections) return(NULL);
+ e_num = BEntrySearch(string, manual[i].entries, manual[i].nentries);
+ if (e_num != NO_ENTRY) break;
+ if (++i >= sections) return(NULL);
+ }
+
+/*
+ * Manual page found in some other section, unhighlight the current one.
+ */
+ if ( man_globals->manpagewidgets.box != NULL)
+ XawListUnhighlight(
+ man_globals->manpagewidgets.box[man_globals->current_directory]);
+ }
+ else {
+ /*
+ * Highlight the element we are searching for if it is in the directory
+ * listing currently being shown.
+ */
+ if ( man_globals->manpagewidgets.box != NULL)
+ XawListHighlight(man_globals->manpagewidgets.box[i], e_num);
+ }
+ return(FindManualFile(man_globals, i, e_num));
+}
+
+/* Function Name: BEntrySearch
+ * Description: binary search through entries.
+ * Arguments: string - the string to match.
+ * first - the first entry in the list.
+ * number - the number of entries.
+ * Returns: a pointer to the entry found.
+ */
+
+static int
+BEntrySearch(
+char * string,
+char ** first,
+int number)
+{
+ int check, cmp, len_cmp, global_number;
+ char *head, *tail;
+
+ global_number = 0;
+ while (TRUE) {
+
+ if (number == 0) {
+ return(NO_ENTRY); /* didn't find it. */
+ }
+
+ check = number/2;
+
+ head = rindex(first[ global_number + check ], '/');
+ if (head == NULL)
+ PrintError("index failure in BEntrySearch");
+ head++;
+
+ tail = rindex(head, '.');
+ if (tail == NULL)
+ /* not an error, some systems (e.g. sgi) have only a .z suffix */
+ tail = head + strlen(head);
+
+ cmp = strncmp(string, head, (tail - head));
+ len_cmp = strlen(string) - (int) (tail - head);
+
+ if ( cmp == 0 && len_cmp == 0) {
+ return(global_number + check);
+ }
+ else if ( cmp < 0 || ((cmp == 0) && (len_cmp < 0)) )
+ number = check;
+ else /* cmp > 0 || ((cmp == 0) && (len_cmp > 0)) */ {
+ global_number += (check + 1);
+ number -= ( check + 1 );
+ }
+ }
+}
diff --git a/tkfuncs.c b/tkfuncs.c
new file mode 100644
index 0000000..2471352
--- /dev/null
+++ b/tkfuncs.c
@@ -0,0 +1,99 @@
+/* $XConsortium: tkfuncs.c,v 1.6 94/04/17 20:43:59 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/tkfuncs.c,v 1.3 2000/03/03 23:16:28 dawes Exp $ */
+
+#include <X11/X.h>
+#include <X11/Xos.h>
+#include <X11/Xlib.h>
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+#include <X11/IntrinsicP.h>
+
+#include "globals.h"
+
+/*
+ * I am doing the "wrong" thing here by looking in the core field for the
+ * widget to get this info, the "right" thing to do is to do a XtGetValues
+ * to get this information.
+ */
+
+/* Function Name: Width
+ * Description: finds the width of a widget.
+ * Arguments: w - the widget.
+ * Returns: the width of that widget.
+ */
+
+int
+Width(Widget w)
+{
+ return( (int) w->core.width );
+}
+
+/* Function Name: Height
+ * Description: finds the height of a widget.
+ * Arguments: w - the widget.
+ * Returns: the height of that widget.
+ */
+
+int
+Height(Widget w)
+{
+ return( (int) w->core.height );
+}
+
+/* Function Name: BorderWidth
+ * Description: finds the BorderWidth of a widget.
+ * Arguments: w - the widget.
+ * Returns: the BorderWidth of that widget.
+ */
+
+int
+BorderWidth(Widget w)
+{
+ return( (int) w->core.border_width );
+}
+
+/*
+ * These functions have got to be able to get at the widget tree, I don't see
+ * any way around this one.
+ */
+
+/* Function Name: Name
+ * Description: This function returns the correct popup child
+ * Arguments: w - widget
+ * Returns: the popup child.
+ */
+
+char *
+Name(Widget w)
+{
+ return( w->core.name);
+}
diff --git a/vendor.c b/vendor.c
new file mode 100644
index 0000000..e91b7a9
--- /dev/null
+++ b/vendor.c
@@ -0,0 +1,318 @@
+/* $XConsortium: vendor.c,v 1.10 94/04/17 20:43:59 rws Exp $ */
+/*
+
+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.
+
+*/
+/* $XFree86: xc/programs/xman/vendor.c,v 1.3 2000/03/03 23:16:28 dawes Exp $ */
+
+/* Vendor-specific data structures and operations */
+
+#include "globals.h"
+#include "vendor.h"
+
+typedef struct sectionName {
+ char * name;
+ char * suffix;
+} SectionNameRec;
+
+#if defined(SYSV) || defined(__osf__) || defined(SVR4) && !defined(sun)
+
+static SectionNameRec SectionNames[] = {
+ {"(1) User Commands", "1"},
+ {"(1m) Sys, Administration", "1m"},
+ {"(2) System Calls", "2"},
+ {"(3) Subroutines", "3"},
+ {"(4) File Formats", "4"},
+ {"(5) Miscellaneous", "5"},
+ {"(6) Games", "6"},
+ {"(7) Devices", "7"},
+ {"(8) Sys. Administration", "8"},
+ {"(l) Local", "l"},
+ {"(n) New", "n"},
+ {"(o) Old", "o"}
+#ifdef SCO
+ ,
+ { "(ADM) System Administration", "ADM" },
+ { "(ADMN) Network Administration", "ADMN" },
+ { "(ADMP) Protocol Administration", "ADMP" },
+ { "(C) Commands", "C" },
+ { "(CMD) DOS Commands", "CMD" },
+ { "(CP) Programming Commands", "CP" },
+ { "(DOS) DOS Subroutines and Libraries", "DOS" },
+ { "(F) File Formats", "F" },
+ { "(HW) Hardware Dependant", "HW" },
+ { "(K) Kernel Subroutines", "K" },
+ { "(LOCAL) Local utilities for your system", "LOCAL" },
+ { "(M) Miscellaneous", "M" },
+ { "(NADM) NFS Administration", "NADM" },
+ { "(NC) Network Commands", "NC" },
+ { "(NF) Network File Formats", "NF" },
+ { "(NS) Network Subroutines", "NS" },
+ { "(NSL) Network Services", "NSL" },
+ { "(S) Subroutines and Libraries", "S" },
+ { "(SCO) Product Engineering Toolkit", "SCO" },
+ { "(SFF) Socket File Formats", "SFF" },
+ { "(STR) Streams", "STR" },
+ { "(TC) Transport Layer Commands", "TC" },
+ { "(X) X Man pages", "X" },
+ { "(XNX) Xenix Subroutines, Commands and Libs", "XNX" },
+ { "(XS) X11 Subroutines and Libraries", "XS" },
+ { "(Xm) Motif Commands and Subroutines", "Xm" },
+ { "(Xt) X Intrinsics", "Xt" }
+#endif
+};
+
+#else
+
+#if defined(sun) && defined(SVR4)
+/* losing man.cf is useless because it has no section names */
+
+static SectionNameRec SectionNames[] = {
+ {"(1) User Commands", "1"},
+ {"(1b) SunOS/BSD Compatibility Commands", "1b"},
+ {"(1c) Communication Commands", "1c"},
+ {"(1f) FMLI Commands", "1f"},
+ {"(1m) Maintenance Commands", "1m"},
+ {"(1s) SunOS Specific Commands", "1s"},
+ {"(2) System Calls", "2"},
+ {"(3) C Library Functions", "3"},
+ {"(3b) SunOS/BSD Compatibility Functions", "3b"},
+ {"(3c) C Library Functions", "3c"},
+ {"(3e) ELF Library Functions", "3e"},
+ {"(3g) C Library Functions", "3g"},
+ {"(3i) Wid Character Functions", "3i"},
+ {"(3k) Kernel VM Library Functions", "3k"},
+ {"(3m) Mathematical Library", "3m"},
+ {"(3n) Network Functions", "3n"},
+ {"(3r) RPC Services Library", "3r"},
+ {"(3s) Standard I/O Functions", "3s"},
+#if OSMINORVERSION == 5
+ {"(3t) Threads Library", "3t"},
+#endif
+ {"(3x) Miscellaneous Library Functions", "3x"},
+ {"(4) File Formats", "4"},
+ {"(4b) Misc. Reference Manual Pages", "4b"},
+ {"(5) Environments, Tables, and TROFF Macros", "5"},
+ {"(6) Games and Demos", "6"},
+ {"(7) Special Files", "7"},
+#if OSMINORVERSION == 5
+ {"(7d) Devices", "7d"},
+ {"(7fs) File Systems", "7fs"},
+ {"(7i) Ioctl Requests", "7i"},
+ {"(7m) STREAMS Modules", "7m"},
+ {"(7p) Protocols", "7p"},
+#endif
+ {"(9) Device Driver Information", "9"},
+ {"(9e) DDI and DKI Driver Entry Points", "9e"},
+ {"(9f) DDI and DKI Kernel Functions", "9f"},
+ {"(9s) DDI and DKI Data Structures", "9s"},
+ {"(l) Local", "l"},
+ {"(n) New", "n"},
+};
+
+#else
+
+static SectionNameRec SectionNames[] = {
+ {"(1) User Commands", "1"},
+ {"(2) System Calls", "2"},
+ {"(3) Subroutines", "3"},
+ {"(4) Devices", "4"},
+ {"(5) File Formats", "5"},
+ {"(6) Games", "6"},
+ {"(7) Miscellaneous", "7"},
+ {"(8) Sys. Administration", "8"},
+#ifdef Lynx
+ {"(9) Device driver service calls", "9"},
+#endif
+#if defined(__OpenBSD__) || defined(__NetBSD__)
+ {"(9) Kernel Manual", "9"},
+#endif
+#if defined(__FreeBSD__)
+ {"(9) Kernel Interfaces", "9"},
+#endif
+ {"(l) Local", "l"},
+ {"(n) New", "n"},
+ {"(o) Old", "o"},
+#ifdef sony
+ {"(p) Public Domain", "p"},
+ {"(s) Sony Specific", "s"},
+#endif
+};
+
+#endif
+#endif
+
+/* Function Name: AddStandardSections
+ * Description: Adds all the standard sections to the list for this path.
+ * Arguments: list - a pointer to the section list.
+ * path - the path to these standard sections.
+ * Returns: none.
+ */
+
+void AddStandardSections(
+SectionList **list,
+char * path)
+{
+#ifdef CRAY
+ AddStandardCraySections(list, path);
+ return;
+#else
+ register int i;
+ char file[BUFSIZ];
+ int numSections = sizeof(SectionNames) / sizeof(SectionNames[0]);
+
+ for (i=0; i < numSections; i++) {
+ sprintf(file, "%s%s", SEARCHDIR, SectionNames[i].suffix);
+ AddNewSection(list, path, file, SectionNames[i].name, TRUE);
+#ifdef SEARCHOTHER
+ sprintf(file, "%s%s", SEARCHOTHER, SectionNames[i].suffix);
+ AddNewSection(list, path, file, SectionNames[i].name, TRUE);
+#endif
+ }
+#endif
+}
+
+#ifdef CRAY
+/* Function Name: AddStandardCraySections
+ * Description: Add sections specific to the Cray.
+ * Arguments: list - a pointer to the section list.
+ * path - the path to these standard sections.
+ * names - standard section names.
+ * Returns: none.
+ */
+
+void AddStandardCraySections(
+SectionList **list,
+char *path)
+{
+ char file[BUFSIZ];
+ int i;
+#define NoSuf (char *)0
+#define Suffix (char *)1
+#define Fold (char *)2
+#define FoldSuffix (char *)3
+ static char *cname[] = {
+ "(1) User Commands", Suffix, "1", "1bsd", NULL,
+ "(1) User Commands (instant)", NoSuf, "1r", "1rb", NULL,
+ "(1m) System Administration", NoSuf, "1m", NULL,
+ "(2) System Calls", Suffix, "2", NULL,
+ "(3) Subroutines", FoldSuffix, "3", "3bsd", "3c", "3m", "3mt", "3s", "3sl", "3z", NULL,
+ "(3) Subroutines (FORTRAN)", Fold, "3f", NULL,
+ "(3) Subroutines (I/O)", Fold, "3io", NULL,
+ "(3) Subroutines (X11)", NoSuf, "3X11", NULL,
+ "(3) Subroutines (Xt)", NoSuf, "3Xt", NULL,
+ "(3) Subroutines (misc.)", Suffix, "3q", NULL,
+ "(3) Subroutines (misc.)", Fold, "3x", NULL,
+ "(3) Subroutines (networking)", Suffix, "3n", "3rpc", "3svc", "3w", "3yp", NULL,
+ "(3) Subroutines (scientific)", Fold, "3sci", NULL,
+ "(3) Subroutines (utilities)", FoldSuffix, "3db", "3u", NULL,
+ "(4) Devices", Suffix, "4", "4d", "4f", "4n", "4p", "4s", NULL,
+ "(5) File Formats", Suffix, "5", NULL,
+ "(6) Games", Suffix, "6", NULL,
+ "(7) Miscellaneous", Suffix, "7", NULL,
+ "(8) Sys. Administration", NoSuf, "8", NULL,
+ "(l) Local", Suffix, "l", NULL,
+ "(n) New", Suffix, "n", NULL,
+ "(o) Old", Suffix, "o", NULL,
+ "(info) Information", NoSuf, "info", NULL,
+ "(osi) Miscellaneous", NoSuf, "osi", NULL,
+ "(sl) Miscellaneous", NoSuf, "sl", NULL,
+ "(ultra) Miscellaneous", NoSuf, "ultra", NULL,
+ NULL
+ };
+ char **p = cname;
+
+ while (*p != NULL) {
+ char *message = *p++;
+ int flags = (int) *p++;
+ while (*p != NULL) {
+ sprintf(file, "%s%s", SEARCHDIR, *p++);
+ AddNewSection(list, path, file, message, flags);
+ }
+ p++;
+ }
+}
+#endif /* CRAY */
+
+
+/* Function Name: CreateManpageName
+ * Description: Creates the manual page name for a given item.
+ * Arguments: entry - the entry to convert.
+ * Returns: the manual page properly allocated.
+ */
+
+/*
+ * If the filename is foo.3 - Create an entry of the form: foo
+ * If the filename is foo.3X11 - Create an entry of the form: foo(X11)
+ * IF the filename is a.out.1 - Create an entry of the form: a.out
+ */
+
+char *
+CreateManpageName(
+char * entry,
+int section, /* FIXME: unused */
+int flags)
+{
+ char * cp;
+ char page[BUFSIZ];
+ char sect[BUFSIZ];
+
+ ParseEntry(entry, NULL, sect, page);
+
+#ifndef CRAY
+ if ( (cp = rindex(page, '.')) != NULL) {
+ if ( (int)strlen(cp) > 2 ) {
+ *cp++ = '(';
+ while( (cp[1] != '\0') ) {
+ *cp = *(cp + 1);
+ cp++;
+ }
+ *cp++ = ')';
+ *cp = '\0';
+ }
+ else
+ *cp = '\0';
+ }
+
+#else /* CRAY - pick up the Cray name from the section */
+
+ if ( (cp = rindex(page, '.')) == NULL)
+ cp = page + strlen(page);
+ if ((flags & MSUFFIX) && strlen(sect) > 4) {
+ char *p = sect + 4;
+ *cp++ = '(';
+ while (*p)
+ *cp++ = *p++;
+ *cp++ = ')';
+ }
+ *cp = '\0';
+
+#endif /* CRAY */
+
+ return(StrAlloc(page));
+}
diff --git a/vendor.h b/vendor.h
new file mode 100644
index 0000000..43d28c9
--- /dev/null
+++ b/vendor.h
@@ -0,0 +1,235 @@
+/* $XConsortium: vendor.h,v 1.12 94/04/17 20:44:00 rws Exp $ */
+/*
+
+Copyright (c) 1991 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.
+
+*/
+/* $XFree86: xc/programs/xman/vendor.h,v 1.11 2002/09/21 02:38:25 dawes Exp $ */
+
+/* Vendor-specific definitions */
+
+#ifdef CSRG_BASED
+#include <sys/param.h>
+#endif
+
+#define SUFFIX "suffix"
+#define FOLD "fold"
+#define FOLDSUFFIX "foldsuffix"
+#define MNULL 0
+#define MSUFFIX 1
+#define MFOLD 2
+#define MFOLDSUFFIX 3
+
+/*
+ * The directories to search. Assume that the manual directories are more
+ * complete than the cat directories.
+ */
+
+#if ( defined(UTEK) || defined(apollo) || defined(Lynx) )
+# define SEARCHDIR CAT
+#else
+# define SEARCHDIR MAN
+#endif
+
+#if ( defined(sgi) || (defined(i386) && (defined(SYSV) || defined(SVR4))) || (defined(BSD) && (BSD >= 199103)) || defined(linux) )
+# define SEARCHOTHER CAT
+#endif
+
+/*
+ * The default manual page directory.
+ *
+ * The MANPATH enviornment variable will override this.
+ */
+
+#ifndef SYSMANPATH
+
+#if defined(macII)
+# define SYSMANPATH "/usr/catman/u_man:/usr/catman/a_man"
+#elif defined(__bsdi__)
+# define SYSMANPATH "/usr/share/man:/usr/contrib/man:/usr/contrib/isode/man:/usr/local/man"
+#elif defined(__OpenBSD__) || defined(__DARWIN__)
+# define SYSMANPATH "/usr/share/man:/usr/local/man:/usr/X11R6/man"
+#elif defined(SVR4) || defined(__osf__) || (defined(BSD) && (BSD >= 199103))
+# define SYSMANPATH "/usr/share/man"
+#elif defined(hcx)
+# define SYSMANPATH "/usr/catman/local_man:/usr/catman/u_man:/usr/catman/a_man:/usr/catman/p_man:/usr/catman/ada_man"
+#elif defined(SYSV) && defined(i386) && !defined(SCO)
+# define SYSMANPATH "/usr/catman/u_man:/usr/catman/p_man"
+#elif defined(sgi)
+# define SYSMANPATH "/usr/catman/a_man:/usr/catman/g_man:/usr/catman/p_man:/usr/catman/u_man:/usr/man/p_man:/usr/man/u_man:/usr/man"
+#endif
+
+#ifndef SYSMANPATH
+# define SYSMANPATH "/usr/man"
+#endif
+
+#endif
+
+/*
+ * Compression Definitions.
+ */
+
+#if defined( macII ) || defined( hcx ) || \
+ (defined(SYSV) && defined(i386) && !defined(ISC) && !defined(SCO)) || \
+ defined(sgi)
+# define COMPRESSION_EXTENSION "z"
+# define UNCOMPRESS_FORMAT "pcat %s > %s"
+# define NO_COMPRESS /* mac can't handle using pack as a filter and
+ xman needs it to be done that way. */
+#elif defined(UTEK)
+# define COMPRESSION_EXTENSION "C"
+# define UNCOMPRESS_FORMAT "ccat < %s > %s"
+# define COMPRESS "compact"
+#elif defined (ISC) || defined(SCO)
+# define COMPRESSION_EXTENSION "Z" /* dummy */
+# ifndef SCO
+# define COMPRESSION_EXTENSIONS "zZF" /* pack, compress, freeze */
+# else
+# define COMPRESSION_EXTENSIONS "zZ" /* pack, compress */
+# endif
+# define UNCOMPRESS_FORMAT uncompress_format
+# define UNCOMPRESS_FORMAT_1 "pcat %s > %s"
+# define UNCOMPRESS_FORMAT_2 "zcat < %s > %s"
+# define UNCOMPRESS_FORMAT_3 "fcat < %s > %s"
+# define NO_COMPRESS
+#else
+# define COMPRESSION_EXTENSION "Z"
+# ifndef HAS_MKSTEMP
+# define UNCOMPRESS_FORMAT "zcat < %s > %s"
+# else
+# define UNCOMPRESS_FORMAT "zcat < %s >> %s"
+# endif
+# define COMPRESS "compress"
+# define GZIP_EXTENSION "gz"
+# ifndef HAS_MKSTEMP
+# define GUNZIP_FORMAT "gzip -c -d < %s > %s"
+# else
+# define GUNZIP_FORMAT "gzip -c -d < %s >> %s"
+# endif
+# define GZIP_COMPRESS "gzip"
+#endif
+
+
+
+/*
+ * The command filters for the manual and apropos searches.
+ */
+
+#if (defined(hpux) || defined(macII) || defined(CRAY) || defined(ultrix) || \
+ defined(hcx) )
+# define NO_MANPATH_SUPPORT
+#endif
+
+#ifndef HAS_MKSTEMP
+# ifdef NO_MANPATH_SUPPORT
+# define APROPOS_FORMAT ("man -k %s | pr -h Apropos > %s")
+# else
+# define APROPOS_FORMAT ("man -M %s -k %s | pr -h Apropos > %s")
+# endif
+#else
+/* with mkstemp the temp output file is already created */
+# ifdef NO_MANPATH_SUPPORT
+# define APROPOS_FORMAT ("man -k %s | pr -h Apropos >> %s")
+# else
+# define APROPOS_FORMAT ("man -M %s -k %s | pr -h Apropos >> %s")
+# endif
+#endif
+
+#ifndef HANDLE_ROFFSEQ
+# if defined(ultrix)
+# define FORMAT "| nroff -man" /* The format command. */
+# elif defined(CSRG_BASED)
+# define FORMAT "| eqn | tbl | nroff -mandoc"
+# elif defined(BSD) && (BSD >= 199103)
+# define FORMAT "| eqn | tbl | nroff -man"
+# elif defined(linux)
+# define FORMAT "| geqn | gtbl | groff -Tlatin1 -mandoc"
+# else
+# define FORMAT "| neqn | nroff -man" /* The format command. */
+# endif
+# if defined(linux)
+# define TBL "gtbl"
+# else
+# define TBL "tbl"
+# endif
+#else /* HANDLE_ROFFSEQ */
+# if defined(linux)
+# define ZSOELIM "zsoelim"
+# define EQN "geqn"
+# define TBL "gtbl"
+# else
+# define ZSOELIM "soelim"
+# define EQN "eqn"
+# define TBL "tbl"
+#endif
+# define GRAP "grap"
+# define PIC "pic"
+# define VGRIND "vgrind"
+# define REFER "refer"
+# if defined(CSRG_BASED)
+# define FORMAT "nroff -mandoc"
+# elif defined(linux)
+# define FORMAT "groff -Tlatin1 -mandoc"
+# else
+# define FORMAT "groff -man"
+# endif
+# define DEFAULT_MANROFFSEQ "et"
+#endif /*HANDLE_ROFFSEQ */
+
+/*
+ * Names of the man and cat dirs.
+ */
+
+#ifdef __bsdi__
+#define MAN "cat"
+#else
+#define MAN "man"
+#endif
+
+/*
+ * The Apple, Cray,, SYSV386, and HCX folks put the preformatted pages in the
+ * "man" directories.
+ */
+#if (defined(macII) || defined(CRAY) || defined(hcx) || \
+ (defined(SYSV) && defined(i386))) && !defined(SCO)
+# define CAT MAN
+#elif defined(SCO)
+# define CAT "cat."
+#else
+# define CAT "cat"
+#endif
+
+typedef struct _SectionList {
+ struct _SectionList * next;
+ char * label; /* section label */
+ char * directory; /* section directory */
+ int flags;
+} SectionList;
+
+extern char * CreateManpageName(char * entry, int section, int flags);
+extern void AddStandardSections(SectionList **list, char * path);
+extern void AddNewSection(SectionList **list, char * path, char * file, char * label, int flags);
diff --git a/version.h b/version.h
new file mode 100644
index 0000000..ff3ade8
--- /dev/null
+++ b/version.h
@@ -0,0 +1,32 @@
+/* $XConsortium: version.h,v 1.11 94/04/17 20:44:00 gildea Exp $ */
+/*
+
+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.
+
+*/
+
+#define XMAN_VERSION "Xman Version 3.1.6 - X11R6."
diff --git a/xman.help b/xman.help
new file mode 100644
index 0000000..247ed7c
--- /dev/null
+++ b/xman.help
@@ -0,0 +1,228 @@
+
+
+XMAN is an X Window System manual browsing tool.
+
+
+
+GETTING STARTED
+
+By default, xman starts by creating a small window that contains three
+"buttons" (places on which to click a pointer button). Two of these
+buttons, Help and Quit, are self-explanatory. The third, Manual Page,
+creates a new manual page browser window; you may use this button to
+open a new manual page any time xman is running.
+
+A new manual page starts up displaying this help information. The
+manual page contains three sections. In the upper left corner are two
+menu buttons. When the mouse is clicked on either of these buttons a
+menu is popped up. The contents of these menus is described below.
+Directly to the right of the menu buttons is an informational display.
+This display usually contains the name of the directory or manual page
+being displayed. It is also used to display warning messages and the
+current version of xman. The last and largest section is the
+information display. This section of the application contains either a
+list of manual pages to choose from or the text of a manual page.
+
+To use xman pull down the Sections menu to select a manual section.
+When the section is displayed, click the left pointer button on the name
+of the manual page that you would like to see. Xman will replace the
+directory listing with the manual page you selected.
+
+That should be enough to get you started. Once you understand the
+basics of how to use xman, take a look at the rest of this file to see
+the advanced features that are available to make using xman fast and
+efficient.
+
+
+SCROLLING TEXT
+
+The scroll bars are similar to xterm and xmh scroll bars; clicking the
+left or right pointer button with the pointer at the bottom of the
+scroll bar will scroll the text down or up one page, respectively.
+Clicking with the pointer farther up the scroll bar scrolls
+proportionally less than one page. Clicking the middle button a portion
+of the way down the scroll bar will move the text window that portion of
+the way down the text. Holding the middle button and moving the pointer
+up and down allows the text to be scrolled dynamically.
+
+You may also type 'f' or <space bar> to scroll down one page, and 'b' to
+scroll up one page.
+
+
+RESIZING WINDOWS
+
+You can resize any of the windows in xman with your window manager, and
+xman will do the best it can to resize everything internally into a
+useful configuration. The only control over the internal arrangement
+that you have is moving the border between the manual page and directory
+when both are displayed. This is done by clicking and holding the any
+pointer button when the cursor is over the small square (grip) on the
+right side of the screen. The grip is located on the horizontal line
+which separates the panes. The grip may be moved up and down to resize
+the panes of the screen, and when the pointer button is released xman
+will move the pane boundary to the newly specified location.
+
+
+MENU COMMANDS
+
+There are two ways to activate the menus. The first is to click any
+pointer button in the menu button corresponding to the menu you want to
+activate. The second method is to hold down the "Control" key and click
+the left pointer button for the Options menu or the middle pointer
+button for the Sections menu. Reguardless of how the menu was
+activated, selecting items is the same.
+
+Once a menu is activated, continue to hold down the pointer button and
+drag the pointer cursor over the item that you would like to activate.
+Once the item that you want to select is highlighted, select it by
+releasing the pointer button. To avoid making a menu selection, move
+the pointer cursor outside the menu and release the button.
+
+Selecting one of the items in the Sections menu will display the named
+directory.
+
+The following commands are available through the Options menu:
+
+Display Directory Show the current section directory.
+
+Display Manual Page Show the current manual page.
+
+Help Create a help window with this text displayed.
+
+Search Pop up a dialogue box that allows the entire
+ tree of manual pages to be searched for a
+ specific name. A keyword (apropos) search is
+ also available through this dialogue box.
+
+Show Both Screens Split the manual page display window to display
+ both the current manual page and the directory.
+Show One Screen Return to a single screen display of either a
+ manual page or directory listing.
+
+Remove This Man Page Remove this manual page, do not quit.
+
+Open New Man Page Pop up a new manual page browser window.
+
+Show Version Print the current version of xman to the
+ information display window. Please include the
+ version number when reporting bugs.
+
+Quit Close all xman windows and quit xman.
+
+
+SUMMARY OF BASIC ACTIONS
+
+In a menu button:
+
+ CLICK: Pop up a menu
+
+In a directory, manual page, or scroll bar:
+
+ <CONTROL> CLICK LEFT: Pop up the Options menu.
+ <CONTROL> CLICK MIDDLE: Pop up the Sections menu.
+
+In a directory:
+
+ CLICK LEFT: Bring up named manual page
+ <SHIFT> CLICK MIDDLE: Go to manual page previously chosen.
+
+In a manual page or apropos listing:
+
+ <SHIFT> CLICK MIDDLE: Go to directory of manual pages.
+
+In scroll bars:
+
+ CLICK LEFT: Move down - more if pointer is near bottom
+ of window, less if at top.
+ CLICK MIDDLE: Move top of page to current pointer position.
+ CLICK RIGHT: Move up - more if pointer is near bottom
+ of window, less if at top.
+
+SEARCHING
+
+Xman has a built-in searching utility that allows the user to search the
+entire manual page tree for a specific topic (manual page search) or a
+keyword (apropos search). The search dialogue box can be activated from
+the Options menu, or by the key Control-s. If the search is started
+from the small initial topbox xman will open a new manual page if the
+search was successful, and fail silently if the search was unsuccessful.
+
+Manual page searches are performed starting in the currently displayed
+section. If no match is found then the remaining sections are searched
+in the order that the sections appear in the Sections menu, starting at
+the top. The current version of xman immediately displays the first
+manual page that it finds. If the manual page cannot be found that fact
+is noted in the informational display.
+
+An apropos search will search a list of short descriptions for all
+manual pages on the system and return a list of all descriptions which
+contain the keyword specified.
+
+
+KEYBOARD ACCELERATORS
+
+Xman contains a set of preinstalled keyboard accelerators. These are a
+set of key bindings that perform many of the same operations as the menu
+items. Since it is not necessary to pull down the menu, these actions
+can be performed more quickly, hence the name accelerators.
+
+The default key bindings for xman are:
+
+Anywhere:
+
+ Control - c Exit xman
+ Control - h Create the help window
+ Control - n Create a new man page
+ Control - q Exit xman
+ Control - s Create a search popup
+
+In a manual page, directory, or help window:
+
+ Control - r Remove this manual page or help display
+ Control - v Show the current version of xman
+
+In a manual page or directory:
+
+ Control - d Display Directory
+ Control - m Display Man Page
+
+In a manual page only:
+
+ b Page Back
+ f Page forward
+ <Space> Page forward
+ 1 One line forward
+ 2 Two lines forward
+ 3 Three lines forward
+ 4 Four lines forward
+
+Note: Control-s does not have any effect in the help window.
+
+
+FURTHER INFORMATION
+
+Xman is highly customizable. Through the X resource database a user can
+customize the look and feel of this application so that it meets a
+preferred style of interaction. Almost any configuration that is
+available dynamically can be specified through resources. This includes
+changing the size, color, and fonts, starting with no topbox, showing
+both screens, and rebinding the keyboard accelerators.
+
+The information on customizing xman is contained in the xman manual
+page, I will leave it to you to figure out how to find and display that
+information :-)
+
+
+ Chris D. Peterson MIT X
+ Consortium
+
+CREDITS
+
+Version: Use 'Show Version' menu item.
+Written By: Chris D. Peterson - formerly MIT X Consortium
+Based Upon: Xman for X10 by Barry Shein - Boston University
+
+Copyright 1988, 1989 X Consortium
+Edited by Donna Converse and Dave Sternlicht
+
+
diff --git a/xman.man b/xman.man
new file mode 100644
index 0000000..2eab384
--- /dev/null
+++ b/xman.man
@@ -0,0 +1,387 @@
+.\" $XConsortium: xman.man,v 1.23 94/04/17 20:44:02 matt Exp $
+.\"
+.\" $XFree86: xc/programs/xman/xman.man,v 1.4 2002/10/12 16:06:48 herrb Exp $
+.\"
+.TH XMAN 1 __xorgversion__
+.SH NAME
+xman \- Manual page display program for the X Window System
+.SH SYNOPSIS
+.B xman
+[
+.I \-options
+\&.\|.\|. ]
+.SH DESCRIPTION
+.I Xman
+is a manual page browser. The default size of the initial \fIxman\fP
+window is small so that you can leave it running throughout your entire login
+session. In the initial window there are three options:
+\fIHelp\fP will pop up a window with on-line help, \fIQuit\fP will
+exit, and \fIManual Page\fP will pop up a window with a manual page
+browser in it.
+Typing Control-S will pop up a window prompting for a specific manual
+page to display.
+You may display more than one manual page browser window at a time
+from a single execution of \fIxman\fP.
+.PP
+For further information on using \fIxman\fP, please read the on-line
+help information. Most of this manual will discuss
+customization of \fIxman\fP.
+.SH "OPTIONS"
+.PP
+Xman supports all standard Toolkit command line arguments (see
+\fIX\fP(1)). The following additional arguments are supported.
+.sp
+.IP "\fB\-helpfile\fP \fIfilename\fP"
+Specifies a helpfile to use other than the default.
+.IP \fB\-bothshown\fP
+Allows both the manual page and manual directory to be on the screen at
+the same time.
+.IP \fB\-notopbox\fP
+Starts without the Top Menu with the three buttons in it.
+.IP "\fB\-geometry\fP \fIWxH+X+Y\fP"
+Sets the size and location of the Top Menu with the three buttons in it.
+.IP "\fB\-pagesize\fP \fIWxH+X+Y\fP"
+Sets the size and location of all the Manual Pages.
+.SH "CUSTOMIZING XMAN"
+.PP
+.I Xman
+allows customization of both the directories to be searched for manual pages,
+and the name that each directory will map to in the \fISections\fP
+menu. Xman determines which directories it will
+search by reading the \fIMANPATH\fP environment variable. If no
+\fIMANPATH\fP is found then the directory is /usr/man is searched on
+POSIX systems. This environment
+is expected to be a colon-separated list of directories for xman to search.
+.sp
+.nf
+setenv MANPATH /mit/kit/man:/usr/man
+.fi
+.PP
+By default,
+.I xman
+will search each of the following directories (in each of the directories
+specified in the users MANPATH) for manual pages. If manual pages exist
+in that directory then they are added to list of manual pages for
+the corresponding menu item.
+A menu item is only displayed for those sections that actually contain
+manual pages.
+.ta 1.5i
+.nf
+
+Directory Section Name
+--------- ------------
+man1 (1) User Commands
+man2 (2) System Calls
+man3 (3) Subroutines
+man4 (4) Devices
+man5 (5) File Formats
+man6 (6) Games
+man7 (7) Miscellaneous
+man8 (8) Sys. Administration
+manl (l) Local
+mann (n) New
+mano (o) Old
+
+.fi
+For instance, a user has three directories in her manual path and each
+contain a directory called \fIman3\fP. All these manual pages will appear
+alphabetically sorted when the user selects the menu item called
+\fI(3) Subroutines\fP. If there is no directory called \fImano\fP in
+any of the directories in her MANPATH, or there are no manual pages
+in any of the directories called \fImano\fP then no menu item will be
+displayed for the section called \fI(o) Old\fP.
+.SH "BSD AND LINUX SYSTEMS"
+.PP
+In newer BSD and Linux systems, \fIXman\fP will search for a file named
+\fI/etc/man.conf\fP which will contain the list of directories containing
+manual pages. See \fIman.conf\fP(5) for a complete description of the file
+format.
+.SH "THE MANDESC FILE"
+.PP
+By using the \fImandesc\fP file a user or system manager is able to
+more closely control which manual pages will appear in each of the sections
+represented by menu items in the \fISections\fP menu. This
+functionality is only available on a section by section basis, and individual
+manual pages may not be handled in this manner.
+(Although generous use of
+symbolic links \(em see \fIln\fP(1) \(em will allow
+almost any configuration you can imagine.)
+.PP
+The format of the mandesc file is a character followed by a label. The
+character determines which of the sections will be added under this label.
+For instance suppose that you would like to create an extra menu item that
+contains all programmer subroutines. This label should contain all manual
+pages in both sections two and three. The \fImandesc\fP file
+would look like this:
+.nf
+
+2Programmer Subroutines
+3Programmer Subroutines
+
+.fi
+This will add a menu item to the \fISections\fP menu that would
+bring up a listing of all manual pages in sections two and three of
+the Programmers Manual. Since the label names are \fIexactly\fP the
+same they will be added to the same section. Note, however, that the
+original sections still exist.
+.PP
+If you want to completely ignore the default sections in a manual directory
+then add the line:
+.nf
+
+no default sections
+
+.fi
+anywhere in your mandesc file. This keeps xman from searching
+the default manual sections \fIIn that directory only\fP. As an example,
+suppose you want to do the same thing as above, but you don't think that
+it is useful to have the \fISystem Calls\fP or \fISubroutines\fP sections
+any longer. You would need to duplicate the default entries, as well as
+adding your new one.
+.nf
+
+no default sections
+1(1) User Commands
+2Programmer Subroutines
+3Programmer Subroutines
+4(4) Devices
+5(5) File Formats
+6(6) Games
+7(7) Miscellaneous
+8(8) Sys. Administration
+l(l) Local
+n(n) New
+o(o) Old
+
+.fi
+Xman will read any section that is of the from \fIman<character>\fP, where
+<character> is an upper or lower case letter (they are treated distinctly) or
+a numeral (0-9). Be warned, however, that man(1) and catman(8) will
+not search directories that are non-standard.
+.SH WIDGETS
+In order to specify resources, it is useful to know the hierarchy of
+the widgets which compose \fIxman\fR. In the notation below,
+indentation indicates hierarchical structure. The widget class name
+is given first, followed by the widget instance name.
+.sp
+.nf
+.ta .5i 1.0i 1.5i 2.0i 2.5i 3.0i 3.5i
+Xman xman \fI(This widget is never used)\fP
+ TopLevelShell topBox
+ Form form
+ Label topLabel
+ Command helpButton
+ Command quitButton
+ Command manpageButton
+ TransientShell search
+ DialogWidgetClass dialog
+ Label label
+ Text value
+ Command manualPage
+ Command apropos
+ Command cancel
+ TransientShell pleaseStandBy
+ Label label
+ TopLevelShell manualBrowser
+ Paned Manpage_Vpane
+ Paned horizPane
+ MenuButton options
+ MenuButton sections
+ Label manualBrowser
+ Viewport directory
+ List directory
+ List directory
+ .
+ . (one for each section,
+ . created on the fly)
+ .
+ ScrollByLine manualPage
+ SimpleMenu optionMenu
+ SmeBSB displayDirectory
+ SmeBSB displayManualPage
+ SmeBSB help
+ SmeBSB search
+ SmeBSB showBothScreens
+ SmeBSB removeThisManpage
+ SmeBSB openNewManpage
+ SmeBSB showVersion
+ SmeBSB quit
+ SimpleMenu sectionMenu
+ SmeBSB <name of section>
+ .
+ . (one for each section)
+ .
+ TransientShell search
+ DialogWidgetClass dialog
+ Label label
+ Text value
+ Command manualPage
+ Command apropos
+ Command cancel
+ TransientShell pleaseStandBy
+ Label label
+ TransientShell likeToSave
+ Dialog dialog
+ Label label
+ Text value
+ Command yes
+ Command no
+ TopLevelShell help
+ Paned Manpage_Vpane
+ Paned horizPane
+ MenuButton options
+ MenuButton sections
+ Label manualBrowser
+ ScrollByLine manualPage
+ SimpleMenu optionMenu
+ SmeBSB displayDirectory
+ SmeBSB displayManualPage
+ SmeBSB help
+ SmeBSB search
+ SmeBSB showBothScreens
+ SmeBSB removeThisManpage
+ SmeBSB openNewManpage
+ SmeBSB showVersion
+ SmeBSB quit
+
+.fi
+.SH "APPLICATION RESOURCES"
+\fIxman\fP has the following application-specific resources which allow
+customizations unique to \fIxman\fP.
+.PP
+.TP 18
+\fBmanualFontNormal\fP (Class \fBFont\fP)
+The font to use for normal text in the manual pages.
+.TP 18
+\fBmanualFontBold\fP (Class \fBFont\fP)
+The font to use for bold text in the manual pages.
+.TP 18
+\fBmanualFontItalic\fP (Class \fBFont\fP)
+The font to use for italic text in the manual pages.
+.TP 18
+\fBdirectoryFontNormal\fP (Class \fBFont\fP)
+The font to use for the directory text.
+.TP 18
+\fBbothShown\fP (Class \fBBoolean\fP)
+Either `true' or `false,' specifies whether or not you want both the
+directory and the manual page shown at start up.
+.TP 18
+\fBdirectoryHeight\fP (Class \fBDirectoryHeight\fP)
+The height in pixels of the directory, when the directory and the manual page
+are shown simultaneously.
+.TP 18
+\fBtopCursor\fP (Class \fBCursor\fP)
+The cursor to use in the top box.
+.TP 18
+\fBhelpCursor\fP (Class \fBCursor\fP)
+The cursor to use in the help window.
+.TP 18
+\fBmanpageCursor\fP (Class \fBCursor\fP)
+The cursor to use in the manual page window.
+.TP 18
+\fBsearchEntryCursor\fP (Class \fBCursor\fP)
+The cursor to use in the search entry text widget.
+.TP 18
+\fBpointerColor\fP (Class \fBForeground\fP)
+This is the color of all the cursors (pointers) specified above. The
+name was chosen to be compatible with xterm.
+.TP 18
+\fBhelpFile\fP (Class \fBFile\fP)
+Use this rather than the system default helpfile.
+.TP 18
+\fBtopBox\fP (Class \fBBoolean\fP)
+Either `true' or `false,' determines whether the top box (containing
+the help, quit and manual page buttons) or a manual page is put on the screen
+at start-up. The default is true.
+.TP 18
+\fBverticalList\fP (Class \fBBoolean\fP)
+Either `true' or `false,' determines whether the directory listing is
+vertically or horizontally organized. The default is horizontal (false).
+.SH "GLOBAL ACTIONS"
+\fIXman\fP defines all user interaction through global actions. This allows
+the user to modify the translation table of any widget, and bind any event
+to the new user action. The list of actions supported by \fIxman\fP are:
+.TP 1.5i
+.B GotoPage(\fIpage\fB)
+When used in a manual page display window this will allow the user to
+move between a directory and manual page display. The \fIpage\fP argument can
+be either \fBDirectory\fP or \fBManualPage\fP.
+.TP 1.5i
+.B Quit()
+This action may be used anywhere, and will exit xman.
+.TP 1.5i
+.B Search(\fItype\fB, \fIaction\fB)
+Only useful when used in a search popup, this action will cause the search
+widget to perform the named search type on the string in the search popup's
+value widget. This action will also pop down the search widget. The
+\fItype\fP argument can be either \fBApropos\fP, \fBManpage\fP or
+\fBCancel\fP. If an \fIaction\fP of \fBOpen\fP is specified then xman
+will open a new manual page to display the results of the search, otherwise
+xman will attempt to display the results in the parent of the search popup.
+.TP 1.5i
+.B PopupHelp()
+This action may be used anywhere, and will popup the help widget.
+.TP 1.5i
+.B PopupSearch()
+This action may be used anywhere except in a help window. It will cause
+the search popup to become active and visible on the screen, allowing
+the user search for a manual page.
+.TP 1.5i
+.B CreateNewManpage()
+This action may be used anywhere, and will create a new manual page
+display window.
+.TP 1.5i
+.B RemoveThisManpage()
+This action may be used in any manual page or help display window. When
+called it will remove the window, and clean up all resources
+associated with it.
+.TP 1.5i
+.B SaveFormattedPage(\fIaction\fP)
+This action can only be used in the \fBlikeToSave\fP popup widget, and
+tells xman whether to \fBSave\fP or \fBCancel\fP a save of the
+manual page that has just been formatted.
+.TP 1.5i
+.B ShowVersion()
+This action may be called from any manual page or help display window, and
+will cause the informational display line to show the current version
+of xman.
+.SH FILES
+.IP "\fI<manpath directory>\fP/man<\fIcharacter\fP>" 2.5i
+.IP "\fI<manpath directory>\fP/cat<\fIcharacter\fP>"
+.IP "\fI<manpath directory>\fP/mandesc"
+.IP __apploaddir__/Xman
+specifies required resources.
+.IP /tmp
+.I Xman
+creates temporary files in /tmp for all unformatted man pages and all apropos
+searches.
+.SH "SEE ALSO"
+.IR X (__miscmansuffix__),
+.IR man (1),
+.IR apropos (1),
+.IR catman (8),
+.I "Athena Widget Set"
+.SH ENVIRONMENT
+.TP 1.5i
+.B DISPLAY
+the default host and display to use.
+.TP 1.5i
+.B MANPATH
+the search path for manual pages. Directories are separated by
+colons (e.g. /usr/man:/mit/kit/man:/foo/bar/man).
+.TP 1.5i
+.B XENVIRONMENT
+to get the name of a resource file that overrides the global resources
+stored in the RESOURCE_MANAGER property.
+.TP 1.5i
+.B XAPPLRESDIR
+A string that will have ``Xman'' appended to it. This string will be
+the full path name of a user app-defaults file to be merged into the
+resource database after the system app-defaults file, and before
+the resources that are attached to the display.
+.br
+See \fIX(__miscmansuffix__)\fP for a full statement of rights and permissions.
+.SH AUTHORS
+Chris Peterson, MIT X Consortium from the V10 version written by Barry
+Shein formerly of Boston University.
+Bug fixes and Linux support by Carlos A M dos Santos, The XFree86 Project.