1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
*** rman.c.original Tue Jul 16 21:19:49 1996
--- rman.c Tue Aug 27 15:59:38 1996
***************
*** 1,5 ****
--- 1,9 ----
static char rcsid[] = "$Header: /home/ajax/dri-backup/xc/xc/extras/rman/contrib/bennett.txt,v 1.1.8.3 2000/11/27 04:08:20 gareth Exp $";
+ /* ELS: SearchDirs by "Edward L. Sutter" <els@sage.sage.att.com> */
+ /* AB: HTMLHeader and HTMLFooter by Anne Bennett <anne@alcor.concordia.ca> */
+ /* AB: SearchDirsPrefix by Anne Bennett <anne@alcor.concordia.ca> */
+
/*
RosettaMan
***************
*** 265,271 ****
--- 269,278 ----
/*** utility functions ***/
+ /* 1996/08/26 Anne Bennett patched */
+ int HrefSearch(char *manname, char *section);
+
/* case insensitive versions of strcmp and strncmp */
int
***************
*** 1338,1343 ****
--- 1345,1355 ----
char *manTitle = MANTITLEPRINTF;
char *manRef = MANREFPRINTF;
int fmanRef=1; /* valid man ref? */
+ /* 1996/08/26 Anne Bennett patched */
+ char *SearchDirs=0; /* ELS: added for smarter external reference generator. */
+ char *SearchDirsPrefix=0; /* AB: added for HREF prefix to manpage path. */
+ char *HTMLHeader=0; /* AB: added for HTML header and footer files. */
+ char *HTMLFooter=0; /* AB: added for HTML header and footer files. */
/*
* HTML
***************
*** 1349,1354 ****
--- 1361,1373 ----
int i,j;
int lasttoc;
char *p, *p0;
+ /* 1996/08/26 Anne Bennett patched */
+ /* AB: To support HTMLHeader and HTMLFooter */
+ #define SUB_MANNAME "@@MANPAGE_NAME@@"
+ #define SUB_MANSECT "@@MANPAGE_SECTION@@"
+ #define STRING_SIZE 1024
+ char line[STRING_SIZE];
+ FILE *fp;
/* always respond to these signals */
switch (cmd) {
***************
*** 1397,1402 ****
--- 1416,1474 ----
/* better title possible? */
printf("<TITLE>"); printf(manTitle, manName, manSect); printf("</TITLE>\n");
printf("</HEAD>\n<BODY>\n");
+ /* 1996/08/26 Anne Bennett patched */
+ /* AB: added HTMLHeader file, if -H option is set */
+ if (HTMLHeader) {
+ if ((fp = fopen(HTMLHeader,"r")) == NULL) {
+ fprintf(stderr,"Could not open HTMLHeader file\n");
+ }
+ else {
+ /* Output the header file, replacing strings as needed */
+ while (fgets(line, STRING_SIZE, fp) != (char *)NULL) {
+ char *walker, *found;
+ int i;
+
+ /* replace man section */
+ walker = line;
+ while ( ( found = strstr(walker, SUB_MANSECT) ) != NULL ) {
+ if ( ( strlen(line) + strlen(manSect)
+ - strlen (SUB_MANSECT) ) > sizeof(line) ) {
+ fprintf(stderr,"Cannot substitute %s for %s; "
+ "line would be too long:\n "
+ "%s\n", manSect, SUB_MANSECT, line);
+ walker = found + strlen(SUB_MANSECT);
+ }
+ else {
+ (void) memmove(found+strlen(manSect),
+ found+strlen(SUB_MANSECT),
+ strlen(found+strlen(SUB_MANSECT))+1);
+ memcpy(found, manSect, strlen(manSect));
+ walker = found + strlen(manSect);
+ }
+ }
+ /* replace man name */
+ walker = line;
+ while ( ( found = strstr(walker, SUB_MANNAME) ) != NULL ) {
+ if ( ( strlen(line) + strlen(manName)
+ - strlen (SUB_MANNAME) ) > sizeof(line) ) {
+ fprintf(stderr,"Cannot substitute %s for %s; "
+ "line would be too long:\n "
+ "%s\n", manName, SUB_MANNAME, line);
+ walker = found + strlen(SUB_MANNAME);
+ }
+ else {
+ (void) memmove(found+strlen(manName),
+ found+strlen(SUB_MANNAME),
+ strlen(found+strlen(SUB_MANNAME))+1);
+ memcpy(found, manName, strlen(manName));
+ walker = found + strlen(manName);
+ }
+ }
+ printf("%s", line);
+ }
+ fclose(fp);
+ }
+ }
printf("<A HREF=\"#toc\">%s</A><P>\n", TABLEOFCONTENTS);
I=0;
break;
***************
*** 1424,1429 ****
--- 1496,1514 ----
if (lasttoc==BEGINSUBSECTION) printf("</UL>");
printf("</UL>\n");
}
+ /* 1996/08/26 Anne Bennett patched */
+ /* AB: added HTMLFooter file, if -F option is set */
+ if (HTMLFooter) {
+ if ((fp = fopen(HTMLFooter,"r")) == NULL) {
+ fprintf(stderr,"Could not open HTMLFooter file\n");
+ }
+ else {
+ /* Output the footer file */
+ while (fgets(line, STRING_SIZE, fp) != (char *)NULL)
+ printf("%s", line);
+ fclose(fp);
+ }
+ }
printf("</BODY></HTML>\n");
break;
case BEGINBODY: break;
***************
*** 1500,1510 ****
*p++='\0'; p0=p;
for (; *p && *p!=')'; p++) /* empty */;
*p='\0';
! if (fmanRef) { printf("<A HREF=\""); printf(manRef, hitxt, p0); printf("\">"); }
else printf("<I>");
break;
case ENDMANREF:
! if (fmanRef) printf("</A>"); else printf("</I>");
break;
case BEGINSC: case ENDSC:
--- 1585,1604 ----
*p++='\0'; p0=p;
for (; *p && *p!=')'; p++) /* empty */;
*p='\0';
! /* 1996/08/26 Anne Bennett patched */
! /* ELS: added a call to HrefSearch() if the -S option is set.. */
! if (SearchDirs)
! HrefSearch(hitxt,p0);
! else if (fmanRef) {
! printf("<A HREF=\"");
! printf(manRef, hitxt, p0);
! printf("\">");
! }
else printf("<I>");
break;
case ENDMANREF:
! /* 1996/08/26 Anne Bennett patched */
! if (fmanRef || SearchDirs) printf("</A>"); else printf("</I>");
break;
case BEGINSC: case ENDSC:
***************
*** 2744,2754 ****
--- 2838,2856 ----
extern char *optarg;
extern int optind, opterr;
+ /* 1996/08/26 Anne Bennett patched */
+ /* ELS: added the -S option: */
+ /* AB: added the -H and -F options */
+ /* AB: added the -P option */
char strgetopt[80];
/* options with an arg must have a '<' in the description */
struct { char letter; int arg; char *longnames; char *desc; } option[] = {
{ 'f', 1, "filter", " <ASCII|roff|TkMan|Tk|Ensemble|Sections|HTML|SGML|MIME|LaTeX|LaTeX2e|RTF|pod>" },
{ 'r', 1, "reference:manref:ref", " <man reference printf string>" },
+ { 'S', 1, "searchdirs", " <man reference search directories>" },
+ { 'P', 1, "prefix", " <prefix for manpage paths in -S>" },
+ { 'H', 1, "header", " <HTML header file>" },
+ { 'F', 1, "footer", " <HTML footer file>" },
{ 'l', 1, "title", " <title printf string>" },
{ 'b', 0, "subsections:sub", " (show subsections)" },
{ 'n', 1, "name", "(ame of man page) <string>" },
***************
*** 2830,2835 ****
--- 2932,2953 ----
case 'r': manRef = optarg;
if (strlen(manRef)==0 || strcmp(manRef,"-")==0 || strcmp(manRef,"off")==0) fmanRef=0;
break;
+ /* 1996/08/26 Anne Bennett patched */
+ /* ELS: added the -S option: */
+ /* AB: added the -H and -F options */
+ /* AB: added the -P option */
+ case 'S': SearchDirs = optarg;
+ if (strlen(SearchDirs)==0 ) SearchDirs=0;
+ break;
+ case 'P': SearchDirsPrefix = optarg;
+ if (strlen(SearchDirsPrefix)==0 ) SearchDirsPrefix=0;
+ break;
+ case 'H': HTMLHeader = optarg;
+ if (strlen(HTMLHeader)==0 ) HTMLHeader=0;
+ break;
+ case 'F': HTMLFooter = optarg;
+ if (strlen(HTMLFooter)==0 ) HTMLFooter=0;
+ break;
case 't': TabStops=atoi(optarg); break;
case 'm': fMan=0; break;
case 'T': fTable=1; break;
***************
*** 2904,2906 ****
--- 3022,3126 ----
filter();
return 0;
}
+
+
+ /* 1996/08/26 Anne Bennett patched */
+ /* ELS...
+ HrefSearch():
+ Active only with command line option -S...
+ Called when rman -fHTML has determined that it is going to add a
+ hypertext link. The user tells rman where to search for the hypertext
+ links (local machine search only) and if HrefSearch() finds the file
+
+ SRCHDIR/manname.section
+
+ where
+ SRCHDIR is one of the colon-delimited paths specified with
+ the -S option;
+ manname is the text that rman found preceding a "manname(##)"
+ detection;
+ section is the string within the parens of the manname spec;
+
+
+ then it will use that path to build the HREF line. If not found,
+ then <A> is all that is inserted.
+ This is generally only helpful when you are simply attempting to
+ turn a man directory into an html directory.
+
+ Note that if the first char of SearchDirs is a colon, then if
+ HrefSearch does not find the reference, it defaults to what rman
+ used to do (use manRef, -r option); otherwise, it will not add
+ a hypertext link at all.
+ */
+ int HrefSearch(char *manname, char *section)
+ {
+ char *dir, *colon, tmp;
+ int DefaultToManRef;
+ FILE *fp;
+ static char path[256];
+
+ tmp = 0;
+
+ again:
+ if (SearchDirs[0] == ':') {
+ dir = &SearchDirs[1];
+ DefaultToManRef = 1;
+ }
+ else {
+ dir = SearchDirs;
+ DefaultToManRef = 0;
+ }
+
+ /* Make 2 passes on all search directories... */
+ /* First pass is with the path dir/manname.section */
+ /* Second pass is with the path dir/manname.section[0] */
+ /* This allows the spec manname(3x) to be found as manname.3 */
+ /* just in cast manname.3x doesn't exist. */
+ /* Note that the second pass is only necessary if the section */
+ /* string is more than one character in length. */
+ while(1) {
+ colon = strchr(dir,':');
+ if (colon) *colon = 0;
+ sprintf(path,"%s/%s.%s.html",dir,manname,section);
+ /* 1996/08/26 Anne: read-only, not rw, please. */
+ if ((fp = fopen(path,"r")) != NULL) {
+ printf("<A HREF=\"");
+ /* AB: Put in the manpage location prefix */
+ if (SearchDirsPrefix)
+ printf("%s",SearchDirsPrefix);
+ printf("%s",path);
+ printf("\">");
+ fclose(fp);
+ if (colon) *colon = ':';
+ fprintf(stderr,"HREF @ %s\n",path);
+ return(1);
+ }
+ if (colon) {
+ *colon = ':';
+ dir = colon+1;
+ }
+ else
+ break;
+ }
+ if (section[1]) {
+ tmp = section[1];
+ section[1] = 0;
+ dir = SearchDirs;
+ goto again;
+ }
+ if (tmp)
+ section[1] = tmp;
+
+ /* 1996/08/27 Anne Bennett: use manRef only if set */
+ if (DefaultToManRef && manRef) {
+ printf("<A HREF=\"");
+ printf(manRef, manname, section);
+ printf("\">");
+ }
+ else
+ printf("<A>");
+ return(1);
+ }
+
+ /* End ELS additions. */
+
*** rman.1.original Tue Jul 16 21:19:49 1996
--- rman.1 Tue Aug 27 15:16:29 1996
***************
*** 75,80 ****
--- 75,109 ----
or `off', then man page references will not be HREFs, just set
in italics.
.TP 15
+ -S|--searchDirs \fIcolon-separated-directories \fR
+ Valid only with \fI-fHTML \fR, this option modifies the behaviour of
+ rman when inserting a hyperlink to a referenced manpage.
+ The directories indicate where to look
+ for a pre-HTMLized version of the referenced manpage under the name
+ " \fIname \fR. \fIsection \fR. \fIhtml \fR". If the file is not
+ found, no hypertext link is added, except if the first character of
+ the directories list is a colon, in which case a link is added using
+ manRef, ( \fI-r \fR option).
+ .TP 15
+ -P|--prefix \fIstring \fR
+ Valid only with \fI-S \fR, the string indicates what prefix to add to
+ the path when constructing the hyperlink for a referenced manpage.
+ The string will usually be
+ similar to that given with \fI-r \fR, except that there will be no
+ printf-style escapes, for example "http://localhost/manpages".
+ .TP 15
+ -H|--header \fIfilename \fR
+ Valid only with \fI-fHTML \fR, the filename refers to a file
+ containing an HTML "header", which might consist of, for example, a
+ company logo, or body color specifications. If the strings
+ "@@MANPAGE_NAME@@" or "@@MANPAGE_SECTION@@" are found in this file,
+ they are replaced by the appropriate manpage name and section.
+ .TP 15
+ -F|--footer \fIfilename \fR
+ Valid only with \fI-fHTML \fR, the filename refers to a file
+ containing an HTML "footer", which might consist of, for example, a
+ link back to the site's home page.
+ .TP 15
-s|section \fI# \fR
Set volume (aka section) number of man page (used in roff format).
.TP 15
|