1/* 2 3Copyright (c) 1987, 1988 X Consortium 4 5Permission is hereby granted, free of charge, to any person obtaining 6a copy of this software and associated documentation files (the 7"Software"), to deal in the Software without restriction, including 8without limitation the rights to use, copy, modify, merge, publish, 9distribute, sublicense, and/or sell copies of the Software, and to 10permit persons to whom the Software is furnished to do so, subject to 11the following conditions: 12 13The above copyright notice and this permission notice shall be included 14in all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR 20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22OTHER DEALINGS IN THE SOFTWARE. 23 24Except as contained in this notice, the name of the X Consortium shall 25not be used in advertising or otherwise to promote the sale, use or 26other dealings in this Software without prior written authorization 27from the X Consortium. 28 29*/ 30 31#ifdef HAVE_CONFIG_H 32# include "config.h" 33#endif 34 35/* X toolkit header files */ 36 37#include <X11/Intrinsic.h> 38#include <X11/StringDefs.h> 39#include <X11/Shell.h> 40 41#include <X11/Xaw/Cardinals.h> 42 43/* Std system and C header files */ 44 45#include <stdio.h> 46#include <limits.h> 47 48#include <X11/Xfuncs.h> 49#include <X11/Xos.h> 50 51/* X include files */ 52 53#include <X11/Xatom.h> 54 55/* Widget header files. */ 56 57#include <X11/Xaw/AsciiText.h> 58#include <X11/Xaw/SmeBSB.h> 59#include <X11/Xaw/Box.h> 60#include <X11/Xaw/Command.h> 61#include <X11/Xaw/Dialog.h> 62#include <X11/Xaw/Label.h> 63#include <X11/Xaw/List.h> 64#include <X11/Xaw/MenuButton.h> 65#include <X11/Xaw/SimpleMenu.h> 66#include <X11/Xaw/Paned.h> 67#include <X11/Xaw/Viewport.h> 68 69/* program specific header files. */ 70 71#include "ScrollByL.h" 72 73#include "defs.h" 74 75#define Error(x) { printf x ; exit(EXIT_FAILURE); } 76#define Assertion(expr, msg) { if (!(expr)) { Error msg } } 77#ifdef DEBUG 78# define Log(x) { if(True) printf x; } 79#else 80# define Log(x) { if(False) printf x; } 81#endif /* DEBUG */ 82 83/* 84 * Assigning values here allows the user of Bitwise Or. 85 */ 86 87typedef struct _XmanFonts { 88 XFontStruct *directory; /* The font for the directory. */ 89} XmanFonts; 90 91typedef struct _XmanCursors { 92 Cursor top, /* The top Cursor, default for xman. */ 93 help, /* The top cursor for the help menu. */ 94 manpage, /* The cursor for the Manpage. */ 95 search_entry; /* The cursor for the text widget in the 96 search box. */ 97 Pixel fg_color; /* foreground color of cursors. */ 98 Pixel bg_color; /* background color of cursors. */ 99} XmanCursors; 100 101typedef struct _ManPageWidgets { 102 Widget manpage, /* The manual page window (scrolled) */ 103 directory, /* The widget in which all directories will 104 appear. */ 105 *box; /* The boxes containing the sections. */ 106} ManPageWidgets; 107 108typedef struct _MenuStruct { 109 caddr_t data; 110 int number; 111 XrmQuark quark; 112} MenuStruct; 113 114/* 115 * The manual sections and entries 116 */ 117 118typedef struct tManual { 119 char *blabel; /* The button label. */ 120 char **entries; /* The individual man page file names. */ 121 char **entries_less_paths; /* Entry names only */ 122 int nentries; /* how many (TOTAL) */ 123 int nalloc; /* how much space allocated */ 124 int flags; /* suffix, fold */ 125} Manual; 126 127/* pseudo Globals that are specific to each manpage created. */ 128 129typedef struct _ManpageGlobals { 130 int current_directory; /* The directory currently being shown 131 on this manpage. */ 132 Boolean dir_shown, /* True if the directory is then current 133 visible screen */ 134 both_shown; /* If true then both the manpage and 135 the directory are to be shown. */ 136 Widget label, /* The label widget at the top of the page. */ 137 standby, /* The please standby widget. */ 138 save, /* The "would you like to save?" widget. */ 139 search_widget, /* The search widget popup. */ 140 help_button, /* The help button. */ 141 option_menu, /* The option menu. */ 142 text_widget; /* text widget containing search string. */ 143 144 /* Widgets (Objects really) for the command menu entries. */ 145 146 Widget dir_entry, manpage_entry, help_entry, 147 search_entry, both_screens_entry, remove_entry, 148 open_entry, print_entry, version_entry, quit_entry; 149 150 /* Misc. */ 151 152 char manpage_title[80]; /* The label to use for the current manpage. */ 153 154 char save_file[80]; /* the name of the file to save formatted 155 page into. */ 156 char tempfile[80]; /* the name of the file to copy the formatted 157 page from. */ 158 Boolean compress; /* Compress file on save? */ 159 Boolean gzip; /* Gzip file on save? */ 160 Boolean bzip2; /* Bzip2 file on save? */ 161 Boolean lzma; 162 Boolean deletetempfile; /* Need to delete tempfile when done? */ 163 char **section_name; /* The name of each of the sections */ 164 165 ManPageWidgets manpagewidgets; /* The manpage widgets. */ 166 167 /* Things to remember when cleaning up when killing manpage. */ 168 169 Widget This_Manpage; /* a pointer to the root of 170 this manpage. */ 171 172 FILE *curr_file; /* Current file shown in manpage widget */ 173} ManpageGlobals; 174 175 176/* Resource manager sets these. */ 177 178typedef struct _Xman_Resources { 179 XmanFonts fonts; /* The fonts used for the man pages. */ 180 XmanCursors cursors; /* The cursors for xman. */ 181 Boolean show_help_syntax; /* True if syntax message should be dumped to 182 stdout. */ 183 Boolean both_shown_initial; /* The initial state of the manual pages 184 show two screens or only one. */ 185 Boolean top_box_active; /* Put up the Top Box. */ 186 Boolean clear_search_string; /* clear the search string each time it 187 is popped down? */ 188 int directory_height; /* The default height of directory in 189 both_shown mode. */ 190 char *help_file; /* The name of the help file. */ 191 char *title; /* The title for topBox */ 192 Boolean iconic; /* Should topBox come up in an iconic state */ 193} Xman_Resources; 194 195/************************************************************ 196 * 197 * Function Definitions 198 * 199 ************************************************************/ 200 201/* Standard library function definitions. */ 202#include <stdlib.h> 203 204/* buttons.c */ 205 206ManpageGlobals *InitPsuedoGlobals(void); 207Widget CreateManpage(FILE * file); 208void CreateManpageWidget(ManpageGlobals * man_globals, String name, 209 Boolean full_instance); 210void FormUpWidgets(Widget parent, 211 const char **full_size, const char **half_size); 212void MakeDirectoryBox(ManpageGlobals * man_globals, Widget parent, 213 Widget * dir_disp, int section); 214void MakeSaveWidgets(ManpageGlobals * man_globals, Widget parent); 215void MakeTopBox(void); 216 217/* handler.c */ 218 219void DirPopupCallback(Widget w, XtPointer pointer, XtPointer junk); 220void DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val); 221void OptionCallback(Widget w, XtPointer pointer, XtPointer junk); 222void Popup(Widget w, XtGrabKind grab_kind); 223 224/* Action Routines. */ 225 226void CreateNewManpage(Widget w, XEvent * event, String * params, 227 Cardinal * num_params); 228void GotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params); 229void PopupHelp(Widget w, XEvent * event, String * params, 230 Cardinal * num_params); 231void PopupSearch(Widget w, XEvent * event, String * params, 232 Cardinal * num_params); 233void RemoveSearch(Widget w, XEvent * event, String * params, 234 Cardinal * num_params); 235void Quit(Widget w, XEvent * event, String * params, Cardinal * num_params); 236void RemoveThisManpage(Widget w, XEvent * event, String * params, 237 Cardinal * num_params); 238void SaveFormattedPage(Widget w, XEvent * event, String * params, 239 Cardinal * num_params); 240void Search(Widget w, XEvent * event, String * params, Cardinal * num_params); 241 242void ShowVersion(Widget w, XEvent * event, String * params, 243 Cardinal * num_params); 244 245/* help.c */ 246 247Boolean MakeHelpWidget(void); 248Boolean OpenHelpfile(ManpageGlobals * man_globals); 249 250/* man.c */ 251Bool ReadManConfig(char manpath[]); 252int Man(void); 253 254/* misc.c */ 255#ifndef HAVE_MKSTEMP 256_X_HIDDEN int Xmkstemp (char *template); 257# define mkstemp Xmkstemp 258#endif 259 260FILE *FindManualFile(ManpageGlobals * man_globals, int section_num, 261 int entry_num); 262ManpageGlobals *GetGlobals(Widget w); 263 264void AddCursor(Widget w, Cursor cursor); 265void ChangeLabel(Widget w, const char *str); 266void OpenFile(ManpageGlobals * man_globals, FILE * file); 267void PopupWarning(ManpageGlobals * man_globals, const char *string); 268void PositionCenter(Widget widget, int x, int y, int above, int left, 269 int v_space, int h_space); 270void PrintError(const char *string) _X_NORETURN; 271void RemoveGlobals(Widget w); 272void SaveGlobals(Widget w, ManpageGlobals * globals); 273void ParseEntry(const char *entry, char *path, char *sect, char *page); 274FILE *Format(ManpageGlobals * man_globals, const char *entry); 275 276/* search */ 277FILE *DoSearch(ManpageGlobals * man_globals, int type); 278void MakeSearchWidget(ManpageGlobals * man_globals, Widget parent); 279 280/* tkfunctions.c */ 281 282int Width(Widget); 283int Height(Widget); 284int BorderWidth(Widget); 285