From e219764e7fff79f53c25ef9d7d9c3bb94c5a2fee Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 18 Sep 2014 19:44:23 -0700 Subject: Implementing M2 register and .M2SS extension. Updating date of the man page and documenting extensions. Changing .ab request to exit unsuccessfully. Index generation needed to be trivially extended to handle more than two levels. --- man2html/man2html.1 | 16 +++++++++++++++- man2html/man2html.c | 54 ++++++++++++++++++++++++++++++++++++++++++++--------- man2html/strdefs.c | 1 + 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/man2html/man2html.1 b/man2html/man2html.1 index c1c25b3..089edf4 100644 --- a/man2html/man2html.1 +++ b/man2html/man2html.1 @@ -1,8 +1,9 @@ '\" t .\" Man page for man2html .\" aeb, 980101 +.\" kk, 140918 .\" -.TH man2html 1 "1 January 1998" +.TH man2html 1 "September 2014" .LO 1 .SH NAME man2html \- format a manual page in html @@ -135,6 +136,19 @@ man2html -H $SERVER_NAME if the variable SERVER_NAME is set. This would allow your machine to act as a server and export man pages. +.SH EXTENSIONS +To test whether troff code is being processed by +.BR man2html , +use the register \f[CO]\en[M2]\f[P]. This is defined and has a nonzero +value. + +The request ".M2SS level tag datum" can be used to emit a custom +section header which is indexed, where level is the index level of +the section, tag is the HTML tag without the angle brackets, for instance H4. +The datum is the heading to be indexed and emitted into the HTML output. +The standard .SH and .SS requests use levels 0 and 1, respectively, +and HTML tags H2 and H3, respectively. + .SH BUGS There are many heuristics. The output will not always be perfect. The lynxcgi method will not work if lynx was compiled without diff --git a/man2html/man2html.c b/man2html/man2html.c index c5f22dc..7a7ef56 100644 --- a/man2html/man2html.c +++ b/man2html/man2html.c @@ -1571,17 +1571,19 @@ add_to_index(int level, char *item) label[2]++; } - if (level != subs) { - manidx_need(6); - if (subs) { - strcpy(manidx+mip, "\n"); - mip += 6; - } else { + while (level != subs) { + if (level > subs) { + manidx_need(5); strcpy(manidx+mip, "
\n"); mip += 5; + subs++; + } else { + manidx_need(6); + strcpy(manidx+mip, "
\n"); + mip += 6; + subs--; } } - subs = level; scan_troff(item, 1, &c); manidx_need(100 + strlen(c)); @@ -1654,7 +1656,7 @@ scan_request(char *c) { printf("%s\n", buffer); } fprintf(stderr, "%s\n", c+2); /* XXX */ - exit(0); + exit(1); break; case V('d','i'): { @@ -2218,6 +2220,40 @@ scan_request(char *c) { else out_html("\n"); curpos=0; break; + case V4('M','2','S','S'): + { + char *h = NULL, *p; + c=c+j; + c = fill_words(c, wordlist, SIZE(wordlist), &words, 0); + if (words<3) + abort(); + p = strchr(wordlist[2], '\n'); + if (p) *p = 0; + out_html(change_to_font(0)); + out_html(change_to_size(0)); + (void) scan_expression(wordlist[0], &i); + add_to_index(i, wordlist[2]); + if (mandoc_command) + scan_troff_mandoc(wordlist[1],1,&h); + else + scan_troff(wordlist[1],1,&h); + wordlist[1] = h; + h = NULL; + if (mandoc_command) + scan_troff_mandoc(wordlist[2],1,&h); + else + scan_troff(wordlist[2],1,&h); + wordlist[2] = h; + out_html(" \n<"); + out_html(wordlist[1]); out_html(">"); + out_html(wordlist[2]); out_html("\n"); + free(wordlist[1]); + free(wordlist[2]); + } + break; case V('T','S'): c=scan_table(c); break; @@ -3351,7 +3387,7 @@ main(int argc, char **argv) { manidx[mip]=0; printf("%s", manidx); } - if (subs) printf("\n"); + while (subs--) printf("\n"); printf("\n"); print_sig(); printf("\n\n"); diff --git a/man2html/strdefs.c b/man2html/strdefs.c index 03f4012..25ab6bb 100644 --- a/man2html/strdefs.c +++ b/man2html/strdefs.c @@ -23,6 +23,7 @@ static INTDEF standardint[] = { { V('.','A'), NROFF, 0, NULL }, { V('.','T'), TROFF, 0, NULL }, { V('.','V'), 1, 0, NULL }, /* the me package tests for this */ + { V('M','2'), 1, 0, NULL }, /* \n[M2] indicates man2html */ { 0, 0, 0, NULL } }; static STRDEF standardstring[] = { -- cgit v1.2.3