11abf7346Smrg/* 21abf7346Smrg 31abf7346SmrgCopyright (c) 1987, 1988 X Consortium 41abf7346Smrg 51abf7346SmrgPermission is hereby granted, free of charge, to any person obtaining 61abf7346Smrga copy of this software and associated documentation files (the 71abf7346Smrg"Software"), to deal in the Software without restriction, including 81abf7346Smrgwithout limitation the rights to use, copy, modify, merge, publish, 91abf7346Smrgdistribute, sublicense, and/or sell copies of the Software, and to 101abf7346Smrgpermit persons to whom the Software is furnished to do so, subject to 111abf7346Smrgthe following conditions: 121abf7346Smrg 131abf7346SmrgThe above copyright notice and this permission notice shall be included 141abf7346Smrgin all copies or substantial portions of the Software. 151abf7346Smrg 161abf7346SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 171abf7346SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 181abf7346SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 191abf7346SmrgIN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 201abf7346SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 211abf7346SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 221abf7346SmrgOTHER DEALINGS IN THE SOFTWARE. 231abf7346Smrg 241abf7346SmrgExcept as contained in this notice, the name of the X Consortium shall 251abf7346Smrgnot be used in advertising or otherwise to promote the sale, use or 261abf7346Smrgother dealings in this Software without prior written authorization 271abf7346Smrgfrom the X Consortium. 281abf7346Smrg 291abf7346Smrg*/ 301abf7346Smrg 316d36ef34Smrg#ifdef HAVE_CONFIG_H 326d36ef34Smrg# include "config.h" 336d36ef34Smrg#endif 341abf7346Smrg 351abf7346Smrg/* X toolkit header files */ 361abf7346Smrg 371abf7346Smrg#include <X11/Intrinsic.h> 381abf7346Smrg#include <X11/StringDefs.h> 391abf7346Smrg#include <X11/Shell.h> 401abf7346Smrg 411abf7346Smrg#include <X11/Xaw/Cardinals.h> 421abf7346Smrg 431abf7346Smrg/* Std system and C header files */ 441abf7346Smrg 451abf7346Smrg#include <stdio.h> 461abf7346Smrg#include <limits.h> 471abf7346Smrg 481abf7346Smrg#include <X11/Xfuncs.h> 491abf7346Smrg#include <X11/Xos.h> 501abf7346Smrg 511abf7346Smrg/* X include files */ 521abf7346Smrg 531abf7346Smrg#include <X11/Xatom.h> 541abf7346Smrg 551abf7346Smrg/* Widget header files. */ 561abf7346Smrg 571abf7346Smrg#include <X11/Xaw/AsciiText.h> 581abf7346Smrg#include <X11/Xaw/SmeBSB.h> 591abf7346Smrg#include <X11/Xaw/Box.h> 601abf7346Smrg#include <X11/Xaw/Command.h> 611abf7346Smrg#include <X11/Xaw/Dialog.h> 621abf7346Smrg#include <X11/Xaw/Label.h> 631abf7346Smrg#include <X11/Xaw/List.h> 641abf7346Smrg#include <X11/Xaw/MenuButton.h> 651abf7346Smrg#include <X11/Xaw/SimpleMenu.h> 661abf7346Smrg#include <X11/Xaw/Paned.h> 671abf7346Smrg#include <X11/Xaw/Viewport.h> 681abf7346Smrg 691abf7346Smrg/* program specific header files. */ 701abf7346Smrg 711abf7346Smrg#include "ScrollByL.h" 721abf7346Smrg 731abf7346Smrg#include "defs.h" 741abf7346Smrg 751abf7346Smrg#define Error(x) { printf x ; exit(EXIT_FAILURE); } 761abf7346Smrg#define Assertion(expr, msg) { if (!(expr)) { Error msg } } 771abf7346Smrg#ifdef DEBUG 781abf7346Smrg# define Log(x) { if(True) printf x; } 791abf7346Smrg#else 801abf7346Smrg# define Log(x) { if(False) printf x; } 811abf7346Smrg#endif /* DEBUG */ 821abf7346Smrg 836d36ef34Smrg/* 841abf7346Smrg * Assigning values here allows the user of Bitwise Or. 851abf7346Smrg */ 861abf7346Smrg 871abf7346Smrgtypedef struct _XmanFonts { 886d36ef34Smrg XFontStruct *directory; /* The font for the directory. */ 891abf7346Smrg} XmanFonts; 901abf7346Smrg 911abf7346Smrgtypedef struct _XmanCursors { 926d36ef34Smrg Cursor top, /* The top Cursor, default for xman. */ 936d36ef34Smrg help, /* The top cursor for the help menu. */ 946d36ef34Smrg manpage, /* The cursor for the Manpage. */ 956d36ef34Smrg search_entry; /* The cursor for the text widget in the 966d36ef34Smrg search box. */ 976d36ef34Smrg Pixel fg_color; /* foreground color of cursors. */ 986d36ef34Smrg Pixel bg_color; /* background color of cursors. */ 991abf7346Smrg} XmanCursors; 1001abf7346Smrg 1011abf7346Smrgtypedef struct _ManPageWidgets { 1026d36ef34Smrg Widget manpage, /* The manual page window (scrolled) */ 1036d36ef34Smrg directory, /* The widget in which all directories will 1046d36ef34Smrg appear. */ 1056d36ef34Smrg *box; /* The boxes containing the sections. */ 1061abf7346Smrg} ManPageWidgets; 1071abf7346Smrg 1081abf7346Smrgtypedef struct _MenuStruct { 1096d36ef34Smrg caddr_t data; 1106d36ef34Smrg int number; 1116d36ef34Smrg XrmQuark quark; 1121abf7346Smrg} MenuStruct; 1131abf7346Smrg 1141abf7346Smrg/* 1151abf7346Smrg * The manual sections and entries 1161abf7346Smrg */ 1171abf7346Smrg 1181abf7346Smrgtypedef struct tManual { 1196d36ef34Smrg char *blabel; /* The button label. */ 1206d36ef34Smrg char **entries; /* The individual man page file names. */ 1216d36ef34Smrg char **entries_less_paths; /* Entry names only */ 1226d36ef34Smrg int nentries; /* how many (TOTAL) */ 1236d36ef34Smrg int nalloc; /* how much space allocated */ 1246d36ef34Smrg int flags; /* suffix, fold */ 1251abf7346Smrg} Manual; 1266d36ef34Smrg 1276d36ef34Smrg/* pseudo Globals that are specific to each manpage created. */ 1286d36ef34Smrg 1296d36ef34Smrgtypedef struct _ManpageGlobals { 1306d36ef34Smrg int current_directory; /* The directory currently being shown 1316d36ef34Smrg on this manpage. */ 1326d36ef34Smrg Boolean dir_shown, /* True if the directory is then current 1336d36ef34Smrg visible screen */ 1346d36ef34Smrg both_shown; /* If true then both the manpage and 1356d36ef34Smrg the directory are to be shown. */ 1366d36ef34Smrg Widget label, /* The label widget at the top of the page. */ 1376d36ef34Smrg standby, /* The please standby widget. */ 1386d36ef34Smrg save, /* The "would you like to save?" widget. */ 1396d36ef34Smrg search_widget, /* The search widget popup. */ 1406d36ef34Smrg help_button, /* The help button. */ 1416d36ef34Smrg option_menu, /* The option menu. */ 1426d36ef34Smrg text_widget; /* text widget containing search string. */ 1436d36ef34Smrg 1446d36ef34Smrg /* Widgets (Objects really) for the command menu entries. */ 1456d36ef34Smrg 1466d36ef34Smrg Widget dir_entry, manpage_entry, help_entry, 1476d36ef34Smrg search_entry, both_screens_entry, remove_entry, 1486d36ef34Smrg open_entry, print_entry, version_entry, quit_entry; 1496d36ef34Smrg 1506d36ef34Smrg /* Misc. */ 1511abf7346Smrg 1526d36ef34Smrg char manpage_title[80]; /* The label to use for the current manpage. */ 1531abf7346Smrg 1546d36ef34Smrg char save_file[80]; /* the name of the file to save formatted 1556d36ef34Smrg page into. */ 1566d36ef34Smrg char tempfile[80]; /* the name of the file to copy the formatted 1576d36ef34Smrg page from. */ 1586d36ef34Smrg Boolean compress; /* Compress file on save? */ 1596d36ef34Smrg Boolean gzip; /* Gzip file on save? */ 1606d36ef34Smrg Boolean bzip2; /* Bzip2 file on save? */ 1616d36ef34Smrg Boolean lzma; 1626d36ef34Smrg Boolean deletetempfile; /* Need to delete tempfile when done? */ 1636d36ef34Smrg char **section_name; /* The name of each of the sections */ 1641abf7346Smrg 1656d36ef34Smrg ManPageWidgets manpagewidgets; /* The manpage widgets. */ 1661abf7346Smrg 1676d36ef34Smrg /* Things to remember when cleaning up when killing manpage. */ 1681abf7346Smrg 1696d36ef34Smrg Widget This_Manpage; /* a pointer to the root of 1706d36ef34Smrg this manpage. */ 1711abf7346Smrg 1726d36ef34Smrg FILE *curr_file; /* Current file shown in manpage widget */ 1731abf7346Smrg} ManpageGlobals; 1741abf7346Smrg 1751abf7346Smrg 1761abf7346Smrg/* Resource manager sets these. */ 1771abf7346Smrg 1781abf7346Smrgtypedef struct _Xman_Resources { 1796d36ef34Smrg XmanFonts fonts; /* The fonts used for the man pages. */ 1806d36ef34Smrg XmanCursors cursors; /* The cursors for xman. */ 1816d36ef34Smrg Boolean show_help_syntax; /* True if syntax message should be dumped to 1826d36ef34Smrg stdout. */ 1836d36ef34Smrg Boolean both_shown_initial; /* The initial state of the manual pages 1846d36ef34Smrg show two screens or only one. */ 1856d36ef34Smrg Boolean top_box_active; /* Put up the Top Box. */ 1866d36ef34Smrg Boolean clear_search_string; /* clear the search string each time it 1876d36ef34Smrg is popped down? */ 1886d36ef34Smrg int directory_height; /* The default height of directory in 1896d36ef34Smrg both_shown mode. */ 1906d36ef34Smrg char *help_file; /* The name of the help file. */ 1916d36ef34Smrg char *title; /* The title for topBox */ 1926d36ef34Smrg Boolean iconic; /* Should topBox come up in an iconic state */ 1931abf7346Smrg} Xman_Resources; 1941abf7346Smrg 1951abf7346Smrg/************************************************************ 1961abf7346Smrg * 1976d36ef34Smrg * Function Definitions 1986d36ef34Smrg * 1991abf7346Smrg ************************************************************/ 2001abf7346Smrg 2011abf7346Smrg/* Standard library function definitions. */ 2021abf7346Smrg#include <stdlib.h> 2031abf7346Smrg 2041abf7346Smrg/* buttons.c */ 2051abf7346Smrg 2066d36ef34SmrgManpageGlobals *InitPsuedoGlobals(void); 2071abf7346SmrgWidget CreateManpage(FILE * file); 208ae5a67adSmrgvoid CreateManpageWidget(ManpageGlobals * man_globals, String name, 2096d36ef34Smrg Boolean full_instance); 2106d36ef34Smrgvoid FormUpWidgets(Widget parent, 2116d36ef34Smrg const char **full_size, const char **half_size); 2126d36ef34Smrgvoid MakeDirectoryBox(ManpageGlobals * man_globals, Widget parent, 2136d36ef34Smrg Widget * dir_disp, int section); 2146d36ef34Smrgvoid MakeSaveWidgets(ManpageGlobals * man_globals, Widget parent); 2151abf7346Smrgvoid MakeTopBox(void); 2161abf7346Smrg 2171abf7346Smrg/* handler.c */ 2181abf7346Smrg 2191abf7346Smrgvoid DirPopupCallback(Widget w, XtPointer pointer, XtPointer junk); 2201abf7346Smrgvoid DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val); 2211abf7346Smrgvoid OptionCallback(Widget w, XtPointer pointer, XtPointer junk); 2221abf7346Smrgvoid Popup(Widget w, XtGrabKind grab_kind); 2231abf7346Smrg 2241abf7346Smrg/* Action Routines. */ 2251abf7346Smrg 2266d36ef34Smrgvoid CreateNewManpage(Widget w, XEvent * event, String * params, 2276d36ef34Smrg Cardinal * num_params); 2281abf7346Smrgvoid GotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params); 2296d36ef34Smrgvoid PopupHelp(Widget w, XEvent * event, String * params, 2306d36ef34Smrg Cardinal * num_params); 2316d36ef34Smrgvoid PopupSearch(Widget w, XEvent * event, String * params, 2326d36ef34Smrg Cardinal * num_params); 233a5a2a776Smrgvoid RemoveSearch(Widget w, XEvent * event, String * params, 234a5a2a776Smrg Cardinal * num_params); 2351abf7346Smrgvoid Quit(Widget w, XEvent * event, String * params, Cardinal * num_params); 2366d36ef34Smrgvoid RemoveThisManpage(Widget w, XEvent * event, String * params, 2376d36ef34Smrg Cardinal * num_params); 2386d36ef34Smrgvoid SaveFormattedPage(Widget w, XEvent * event, String * params, 2396d36ef34Smrg Cardinal * num_params); 2401abf7346Smrgvoid Search(Widget w, XEvent * event, String * params, Cardinal * num_params); 2416d36ef34Smrg 2426d36ef34Smrgvoid ShowVersion(Widget w, XEvent * event, String * params, 2436d36ef34Smrg Cardinal * num_params); 2441abf7346Smrg 2451abf7346Smrg/* help.c */ 2461abf7346Smrg 2471abf7346SmrgBoolean MakeHelpWidget(void); 2481abf7346SmrgBoolean OpenHelpfile(ManpageGlobals * man_globals); 2491abf7346Smrg 2501abf7346Smrg/* man.c */ 2511abf7346SmrgBool ReadManConfig(char manpath[]); 2521abf7346Smrgint Man(void); 2531abf7346Smrg 2541abf7346Smrg/* misc.c */ 2556d36ef34Smrg#ifndef HAVE_MKSTEMP 2566d36ef34Smrg_X_HIDDEN int Xmkstemp (char *template); 2576d36ef34Smrg# define mkstemp Xmkstemp 2586d36ef34Smrg#endif 2596d36ef34Smrg 2606d36ef34SmrgFILE *FindManualFile(ManpageGlobals * man_globals, int section_num, 2616d36ef34Smrg int entry_num); 2626d36ef34SmrgManpageGlobals *GetGlobals(Widget w); 2636d36ef34Smrg 2641abf7346Smrgvoid AddCursor(Widget w, Cursor cursor); 2656d36ef34Smrgvoid ChangeLabel(Widget w, const char *str); 2661abf7346Smrgvoid OpenFile(ManpageGlobals * man_globals, FILE * file); 2676d36ef34Smrgvoid PopupWarning(ManpageGlobals * man_globals, const char *string); 2686d36ef34Smrgvoid PositionCenter(Widget widget, int x, int y, int above, int left, 2696d36ef34Smrg int v_space, int h_space); 2706d36ef34Smrgvoid PrintError(const char *string) _X_NORETURN; 2711abf7346Smrgvoid RemoveGlobals(Widget w); 2721abf7346Smrgvoid SaveGlobals(Widget w, ManpageGlobals * globals); 2736d36ef34Smrgvoid ParseEntry(const char *entry, char *path, char *sect, char *page); 2746d36ef34SmrgFILE *Format(ManpageGlobals * man_globals, const char *entry); 2751abf7346Smrg 2761abf7346Smrg/* search */ 2776d36ef34SmrgFILE *DoSearch(ManpageGlobals * man_globals, int type); 2781abf7346Smrgvoid MakeSearchWidget(ManpageGlobals * man_globals, Widget parent); 2791abf7346Smrg 2801abf7346Smrg/* tkfunctions.c */ 2811abf7346Smrg 2821abf7346Smrgint Width(Widget); 2831abf7346Smrgint Height(Widget); 2841abf7346Smrgint BorderWidth(Widget); 285