1 /*
2 
3 Copyright (c) 1987, 1988  X Consortium
4 
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
12 
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
23 
24 Except as contained in this notice, the name of the X Consortium shall
25 not be used in advertising or otherwise to promote the sale, use or
26 other dealings in this Software without prior written authorization
27 from 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 
87 typedef struct _XmanFonts {
88     XFontStruct *directory;     /* The font for the directory.  */
89 } XmanFonts;
90 
91 typedef 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 
101 typedef 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 
108 typedef struct _MenuStruct {
109     caddr_t data;
110     int number;
111     XrmQuark quark;
112 } MenuStruct;
113 
114 /*
115  * The manual sections and entries
116  */
117 
118 typedef 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 
129 typedef 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 #ifdef INCLUDE_XPRINT_SUPPORT
151     /* Print objects and data */
152     Widget printdialog_shell;   /* Shell for the print dialog */
153     Widget printdialog;         /* Print dialog */
154 #endif                          /*INCLUDE_XPRINT_SUPPORT */
155     /* Misc. */
156 
157     char manpage_title[80];     /* The label to use for the current manpage. */
158 
159     char save_file[80];         /* the name of the file to save formatted
160                                    page into. */
161     char tempfile[80];          /* the name of the file to copy the formatted
162                                    page from. */
163     Boolean compress;           /* Compress file on save? */
164     Boolean gzip;               /* Gzip file on save? */
165     Boolean bzip2;              /* Bzip2 file on save? */
166     Boolean lzma;
167     Boolean deletetempfile;     /* Need to delete tempfile when done? */
168     char **section_name;        /* The name of each of the sections */
169 
170     ManPageWidgets manpagewidgets;      /* The manpage widgets. */
171 
172     /* Things to remember when cleaning up when killing manpage. */
173 
174     Widget This_Manpage;        /* a pointer to the root of
175                                    this manpage. */
176 
177     FILE *curr_file;            /* Current file shown in manpage widget */
178 } ManpageGlobals;
179 
180 
181 /* Resource manager sets these. */
182 
183 typedef struct _Xman_Resources {
184     XmanFonts fonts;            /* The fonts used for the man pages. */
185     XmanCursors cursors;        /* The cursors for xman. */
186     Boolean show_help_syntax;   /* True if syntax message should be dumped to
187                                    stdout. */
188     Boolean both_shown_initial; /* The initial state of the manual pages
189                                    show two screens or only one. */
190     Boolean top_box_active;     /* Put up the Top Box. */
191     Boolean clear_search_string;        /* clear the search string each time it
192                                            is popped down? */
193     int directory_height;       /* The default height of directory in
194                                    both_shown mode. */
195     char *help_file;            /* The name of the help file. */
196     char *title;                /* The title for topBox */
197     Boolean iconic;             /* Should topBox come up in an iconic state */
198 } Xman_Resources;
199 
200 /************************************************************
201  *
202  * Function Definitions
203  *
204  ************************************************************/
205 
206 /* Standard library function definitions. */
207 #include <stdlib.h>
208 
209 /* buttons.c */
210 
211 ManpageGlobals *InitPsuedoGlobals(void);
212 Widget CreateManpage(FILE * file);
213 void CreateManpageWidget(ManpageGlobals * man_globals, String name,
214                          Boolean full_instance);
215 void FormUpWidgets(Widget parent,
216                    const char **full_size, const char **half_size);
217 void MakeDirectoryBox(ManpageGlobals * man_globals, Widget parent,
218                       Widget * dir_disp, int section);
219 void MakeSaveWidgets(ManpageGlobals * man_globals, Widget parent);
220 void MakeTopBox(void);
221 
222 /* handler.c */
223 
224 void DirPopupCallback(Widget w, XtPointer pointer, XtPointer junk);
225 void DirectoryHandler(Widget w, XtPointer global_pointer, XtPointer ret_val);
226 void OptionCallback(Widget w, XtPointer pointer, XtPointer junk);
227 void Popup(Widget w, XtGrabKind grab_kind);
228 
229 /* Action Routines. */
230 
231 void CreateNewManpage(Widget w, XEvent * event, String * params,
232                       Cardinal * num_params);
233 void GotoPage(Widget w, XEvent * event, String * params, Cardinal * num_params);
234 void PopupHelp(Widget w, XEvent * event, String * params,
235                Cardinal * num_params);
236 void PopupSearch(Widget w, XEvent * event, String * params,
237                  Cardinal * num_params);
238 void Quit(Widget w, XEvent * event, String * params, Cardinal * num_params);
239 void RemoveThisManpage(Widget w, XEvent * event, String * params,
240                        Cardinal * num_params);
241 void SaveFormattedPage(Widget w, XEvent * event, String * params,
242                        Cardinal * num_params);
243 void Search(Widget w, XEvent * event, String * params, Cardinal * num_params);
244 
245 #ifdef INCLUDE_XPRINT_SUPPORT
246 void PrintThisManpage(Widget w, XEvent * event, String * params,
247                       Cardinal * num_params);
248 #endif /* INCLUDE_XPRINT_SUPPORT */
249 void ShowVersion(Widget w, XEvent * event, String * params,
250                  Cardinal * num_params);
251 
252 /* help.c */
253 
254 Boolean MakeHelpWidget(void);
255 Boolean OpenHelpfile(ManpageGlobals * man_globals);
256 
257 /* man.c */
258 Bool ReadManConfig(char manpath[]);
259 int Man(void);
260 
261 /* misc.c */
262 #ifndef HAVE_MKSTEMP
263 _X_HIDDEN int Xmkstemp (char *template);
264 # define mkstemp Xmkstemp
265 #endif
266 
267 FILE *FindManualFile(ManpageGlobals * man_globals, int section_num,
268                      int entry_num);
269 ManpageGlobals *GetGlobals(Widget w);
270 
271 void AddCursor(Widget w, Cursor cursor);
272 void ChangeLabel(Widget w, const char *str);
273 void OpenFile(ManpageGlobals * man_globals, FILE * file);
274 void PopupWarning(ManpageGlobals * man_globals, const char *string);
275 void PositionCenter(Widget widget, int x, int y, int above, int left,
276                     int v_space, int h_space);
277 void PrintError(const char *string) _X_NORETURN;
278 void RemoveGlobals(Widget w);
279 void SaveGlobals(Widget w, ManpageGlobals * globals);
280 void ParseEntry(const char *entry, char *path, char *sect, char *page);
281 FILE *Format(ManpageGlobals * man_globals, const char *entry);
282 
283 /* search */
284 FILE *DoSearch(ManpageGlobals * man_globals, int type);
285 void MakeSearchWidget(ManpageGlobals * man_globals, Widget parent);
286 
287 /* tkfunctions.c */
288 
289 int Width(Widget);
290 int Height(Widget);
291 int BorderWidth(Widget);
292