add man2html program

git-svn-id: svn://kolibrios.org@9278 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
navichok26 2021-11-16 09:37:50 +00:00
parent 8a5c16a53a
commit 2ce4f2ee4d
9 changed files with 3753 additions and 0 deletions

BIN
data/common/utils/MAN2HTML Normal file

Binary file not shown.

View File

@ -0,0 +1,13 @@
CC = gcc
NAME = man2html
CFLAGS = -DNOCGI
SRC = man2html.c cgibase.c abbrev.c strdefs.c
$(NAME): $(SRC)
$(CC) $(SRC) -o $(NAME)
clean:
rm -f $(NAME)

View File

@ -0,0 +1,15 @@
TCC = /kolibrios/develop/tcc/tcc
NAME = man2html
SRC = man2html.c cgibase.c abbrev.c strdefs.c
CFLAGS = -D_KOLIBRI -DNOCGI
LIBS = -ltcc -lc.obj
all:
$(KTCC) $(CFLAGS) $(SRC) $(LIBS) -o $(NAME)
clean:
rm $(NAME)

View File

@ -0,0 +1,91 @@
This directory contains the following.
1. man2html
This is a pure manroff -> html converter.
No manpath search etc.
Call: man2html [-l | -H host.domain:port] [filename]
The contents of FILENAME (or STDIN, in case FILENAME is "-" or absent)
are converted from man-style nroff to html, and printed on STDOUT.
With "-l" URLs of the form "lynxcgi:/home/httpd/cgi-bin/..." are generated.
With "-H host" we make URLs of the form "http://host/cgi-bin/...".
The default is "http://localhost/cgi-bin/...".
2. A collection of scripts
This part is not installed by "make install" of the global Makefile.
There are security considerations: it is very unlikely that these
scripts (still in alpha) are secure, so for the time being they
should only be used where security is not a major concern.
If you are not afraid, or are not running a httpd, do
"make install-scripts" in this directory.
This does three things: install man stuff, install glimpse stuff,
and install user interface stuff.
2A. man stuff
This first part (that can be done separately with "make install-man-scripts")
puts various scripts under /home/httpd/cgi-bin and /home/httpd/cgi-aux
in a subdirectory man.
It will create a directory /var/man2html to hold the indices.
(This directory should be writable by the cgi scripts;
probably that means that the owner should be nobody.
Choose a group and add all non-httpd users that should be
able to write this directory to that group.)
Structure of the collection of scripts:
man2html is the main script.
It uses man.aux when called without arguments.
It uses manwhatis when asked for an index of manpages+descriptions.
It uses mansec when asked for a compact index of manpages.
It uses mansearch when asked for a glimpse search.
In its turn mansearch uses mansearch.aux when called
without arguments. It uses mansearchhelp (which uses
mansearchhelp.aux) when asked for help.
2B. glimpse stuff
The second part (that can be done separately with
"make install-glimpse-stuff") installs .glimpse_filters
in /var/man2html, in order to tell glimpse what decompressors to use.
2C. user interface stuff
The third part (that can be done separately with "make install-hman")
installs a user interface to these scripts in /usr/bin/hman.
Now people can say
alias man=/usr/bin/hman
and have a man that uses a html browser.
The browser is chosen via environment variables - look at the script.
3. Glimpse.
For the glimpse part, I quote Michael Hamilton:
----------------------------------------------------------------------
To use the Glimpse full text searching, you will need to install
glimpse in /usr/bin. Redhat rpm users can get glimpse from
ftp://ftp.redhat.com/pub/contrib/i386/glimpse-4.0-6.i386.rpm
The glimpse home ftp site is cs.arizona.edu. N.B. glimpse is not
freely redistributable for commercial use, I'd be very interested in a
more liberal alternative. Having installed glimpse, you will need to
build a glimpse index in /var/man2html. This doesn't take too long -
about 3 minutes on my 486DX2/66 16MB machine. As root do:
/usr/bin/glimpseindex -z -H /var/man2html /usr/man/man* /usr/X11R6/man/man* \
/usr/local/man/man* /opt/man/man*
chmod ugo+r /var/man2html/.glimpse*
The -z option causes glimpse to apply any filters (for decompression etc)
specified in /var/man2html/.glimpse_filters.
This could be set up as a cron job in /etc/crontab, e.g. (the following
must be all on one line):
21 04 * * 1 root /usr/bin/glimpseindex -z -H /var/man2html /usr/man/man*
/usr/X11R6/man/man* /usr/local/man/man* /opt/man/man* ;
chmod +r /var/man2html/.glimpse*
--------------------------------------------------------------------------

View File

@ -0,0 +1,62 @@
#include <string.h>
#include "defs.h"
/*
* lookup_abbrev() is used for TX macros - is that
* something SUN-specific?
*/
char *abbrev_list[] = {
"GSBG", "Getting Started ",
"SUBG", "Customizing SunOS",
"SHBG", "Basic Troubleshooting",
"SVBG", "SunView User's Guide",
"MMBG", "Mail and Messages",
"DMBG", "Doing More with SunOS",
"UNBG", "Using the Network",
"GDBG", "Games, Demos &amp; Other Pursuits",
"CHANGE", "SunOS 4.1 Release Manual",
"INSTALL", "Installing SunOS 4.1",
"ADMIN", "System and Network Administration",
"SECUR", "Security Features Guide",
"PROM", "PROM User's Manual",
"DIAG", "Sun System Diagnostics",
"SUNDIAG", "Sundiag User's Guide",
"MANPAGES", "SunOS Reference Manual",
"REFMAN", "SunOS Reference Manual",
"SSI", "Sun System Introduction",
"SSO", "System Services Overview",
"TEXT", "Editing Text Files",
"DOCS", "Formatting Documents",
"TROFF", "Using <B>nroff</B> and <B>troff</B>",
"INDEX", "Global Index",
"CPG", "C Programmer's Guide",
"CREF", "C Reference Manual",
"ASSY", "Assembly Language Reference",
"PUL", "Programming Utilities and Libraries",
"DEBUG", "Debugging Tools",
"NETP", "Network Programming",
"DRIVER", "Writing Device Drivers",
"STREAMS", "STREAMS Programming",
"SBDK", "SBus Developer's Kit",
"WDDS", "Writing Device Drivers for the SBus",
"FPOINT", "Floating-Point Programmer's Guide",
"SVPG", "SunView 1 Programmer's Guide",
"SVSPG", "SunView 1 System Programmer's Guide",
"PIXRCT", "Pixrect Reference Manual",
"CGI", "SunCGI Reference Manual",
"CORE", "SunCore Reference Manual",
"4ASSY", "Sun-4 Assembly Language Reference",
"SARCH", "<FONT SIZE=\"-1\">SPARC</FONT> Architecture Manual",
"KR", "The C Programming Language",
0, 0 };
char *lookup_abbrev (char *s)
{
int i=0;
if (!s)
return "";
while (abbrev_list[i] && strcmp(s, abbrev_list[i]))
i = i+2;
return abbrev_list[i] ? abbrev_list[i+1] : s;
}

View File

@ -0,0 +1,123 @@
/*
* Here are the routines of man2html that output a HREF string.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h> /* tolower() */
#include <string.h> /* strlen() */
#include "defs.h"
/*
* The default is to use cgibase. With relative html style
* we generate URLs of the form "../manX/page.html".
*/
static int relat_html_style = 0;
/*
* The default is to use cgibase. With current html style
* we generate URLs of the form "./page.html".
*/
static int current_html_style = 0;
/*
* Either the user is non-local (or local, but using httpd),
* in which case we use http:/cgi-bin, or the user is local
* and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin.
*/
static char *man2htmlpath = "/cgi-bin/man/man2html"; /* default */
static char *cgibase_format = "http://%s"; /* host.domain:port */
static char *cgibase_ll_format = "lynxcgi:%s"; /* directory */
static char *cgibase = "http://localhost"; /* default */
/*
* Separator between URL and argument string.
*
* With http:<path to script>/a/b?c+d+e the script is called
* with PATH_INFO=/a/b and QUERY_STRING=c+d+e and args $1=c, $2=d, $3=e.
* With lynxcgi:<full path to script>?c+d+e no PATH_INFO is possible.
*/
static char sep = '?'; /* or '/' */
/* What shall we say in case of relat_html_style? */
static char *signature = "<HR>\n"
"This document was created by\n"
"<A HREF=\"http://github.com/hamano/man2html/\">man2html</A>,\n"
"using the manual pages.<BR>\n"
"%s\n";
#define TIMEFORMAT "%T GMT, %B %d, %Y"
#define TIMEBUFSZ 500
void print_sig()
{
char timebuf[TIMEBUFSZ];
struct tm *timetm;
time_t clock;
timebuf[0] = 0;
#ifdef TIMEFORMAT
sprintf(timebuf, "Time: ");
clock=time(NULL);
timetm=localtime(&clock);
snprintf(timebuf, TIMEBUFSZ, "%s%s", timebuf, asctime(timetm));
timebuf[TIMEBUFSZ-1] = 0;
#endif
fprintf(out, signature, timebuf);
}
void
include_file_html(char *g) {
fprintf(out, "<A HREF=\"file:/usr/include/%s\">%s</A>&gt;", g,g);
}
void
man_page_html(char *sec, char *h) {
if (current_html_style) {
if (!h)
fprintf(out, "<A HREF=\"./\">"
"Return to Main Contents</A>");
else
fprintf(out, "<A HREF=\"./%s.html\">%s</A>",
h, h);
} else if (relat_html_style) {
if (!h)
fprintf(out, "<A HREF=\"../index.html\">"
"Return to Main Contents</A>");
else
fprintf(out, "<A HREF=\"../man%s/%s.%s.html\">%s</A>",
sec, h, sec, h);
} else {
if (!h)
fprintf(out, "<A HREF=\"%s%s\">Return to Main Contents</A>",
cgibase, man2htmlpath);
else if (!sec)
fprintf(out, "<A HREF=\"%s%s%c%s\">%s</A>",
cgibase, man2htmlpath, sep, h, h);
else
fprintf(out, "<A HREF=\"%s%s%c%s+%s\">%s</A>",
cgibase, man2htmlpath, sep, sec, h, h);
}
}
void
ftp_html(char *f) {
fprintf(out, "<A HREF=\"ftp://%s\">%s</A>", f, f);
}
void
www_html(char *f) {
fprintf(out, "<A HREF=\"http://%s\">%s</A>", f, f);
}
void
mailto_html(char *g) {
fprintf(out, "<A HREF=\"mailto:%s\">%s</A>", g, g);
}
void
url_html(char *g) {
fprintf(out, "<A HREF=\"%s\">%s</A>", g, g);
}

View File

@ -0,0 +1,43 @@
#ifndef DEFS_H
#define DEFS_H
#include <stddef.h>
#include <stdio.h>
extern FILE *out;
extern int nroff;
extern int local_lynx;
typedef struct STRDEF STRDEF;
struct STRDEF {
int nr,slen;
char *st;
STRDEF *next;
};
typedef struct INTDEF INTDEF;
struct INTDEF {
int nr;
int val;
int incr;
INTDEF *next;
};
extern STRDEF *chardef, *strdef, *defdef;
extern INTDEF *intdef;
#define V(A,B) ((A)*256+(B))
extern void stdinit(void);
extern void print_sig(void);
extern char *lookup_abbrev(char *);
extern void include_file_html(char *);
extern void man_page_html(char*, char *);
extern void ftp_html(char *);
extern void www_html(char *);
extern void mailto_html(char *);
extern void url_html(char *);
extern void *xmalloc(size_t size);
extern void *xrealloc(void *ptr, size_t size);
extern char *xstrdup(const char *s);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,176 @@
#include "defs.h"
#ifndef NULL
#define NULL ((void *) 0)
#endif
int nroff = 1;
#define NROFF (-666)
#define TROFF (-667)
STRDEF *chardef, *strdef, *defdef;
INTDEF *intdef;
static INTDEF standardint[] = {
{ V('n',' '), NROFF, 0, NULL },
{ V('t',' '), TROFF, 0, NULL },
{ V('o',' '), 1, 0, NULL },
{ V('e',' '), 0, 0, NULL },
{ V('.','l'), 70, 0, NULL },
{ V('.','$'), 0, 0, NULL },
{ V('.','A'), NROFF, 0, NULL },
{ V('.','T'), TROFF, 0, NULL },
{ V('.','V'), 1, 0, NULL }, /* the me package tests for this */
{ 0, 0, 0, NULL } };
static STRDEF standardstring[] = {
{ V('R',' '), 1, "&#174;", NULL },
{ V('l','q'), 2, "``", NULL },
{ V('r','q'), 2, "''", NULL },
{ 0, 0, NULL, NULL}
};
static STRDEF standardchar[] = {
{ V('*','*'), 1, "*", NULL }, /* math star */
{ V('*','A'), 1, "A", NULL },
{ V('*','B'), 1, "B", NULL },
{ V('*','C'), 2, "Xi", NULL },
{ V('*','D'), 5, "Delta", NULL },
{ V('*','E'), 1, "E", NULL },
{ V('*','F'), 3, "Phi", NULL },
{ V('*','G'), 5, "Gamma", NULL },
{ V('*','H'), 5, "Theta", NULL },
{ V('*','I'), 1, "I", NULL },
{ V('*','K'), 1, "K", NULL },
{ V('*','L'), 6, "Lambda", NULL },
{ V('*','M'), 1, "M", NULL },
{ V('*','N'), 1, "N", NULL },
{ V('*','O'), 1, "O", NULL },
{ V('*','P'), 2, "Pi", NULL },
{ V('*','Q'), 3, "Psi", NULL },
{ V('*','R'), 1, "P", NULL },
{ V('*','S'), 5, "Sigma", NULL },
{ V('*','T'), 1, "T", NULL },
{ V('*','U'), 1, "Y", NULL },
{ V('*','W'), 5, "Omega", NULL },
{ V('*','X'), 1, "X", NULL },
{ V('*','Y'), 1, "H", NULL },
{ V('*','Z'), 1, "Z", NULL },
{ V('*','a'), 5, "alpha", NULL },
{ V('*','b'), 4, "beta", NULL },
{ V('*','c'), 2, "xi", NULL },
{ V('*','d'), 5, "delta", NULL },
{ V('*','e'), 7, "epsilon", NULL },
{ V('*','f'), 3, "phi", NULL },
{ V('*','g'), 5, "gamma", NULL },
{ V('*','h'), 5, "theta", NULL },
{ V('*','i'), 4, "iota", NULL },
{ V('*','k'), 5, "kappa", NULL },
{ V('*','l'), 6, "lambda", NULL },
{ V('*','m'), 1, "&#181;", NULL },
{ V('*','n'), 2, "nu", NULL },
{ V('*','o'), 1, "o", NULL },
{ V('*','p'), 2, "pi", NULL },
{ V('*','q'), 3, "psi", NULL },
{ V('*','r'), 3, "rho", NULL },
{ V('*','s'), 5, "sigma", NULL },
{ V('*','t'), 3, "tau", NULL },
{ V('*','u'), 7, "upsilon", NULL },
{ V('*','w'), 5, "omega", NULL },
{ V('*','x'), 3, "chi", NULL },
{ V('*','y'), 3, "eta", NULL },
{ V('*','z'), 4, "zeta", NULL },
{ V('+','-'), 1, "&#177;", NULL },
{ V('1','2'), 1, "&#189;", NULL },
{ V('1','4'), 1, "&#188;", NULL },
{ V('3','4'), 1, "&#190;", NULL },
{ V('F','i'), 3, "ffi", NULL },
{ V('F','l'), 3, "ffl", NULL },
{ V('a','a'), 1, "&#180;", NULL },
{ V('a','p'), 1, "~", NULL },
{ V('b','r'), 1, "|", NULL },
{ V('b','u'), 1, "*", NULL }, /* bullet */
{ V('b','v'), 1, "|", NULL },
{ V('c','i'), 1, "o", NULL }, /* circle */
{ V('c','o'), 1, "&#169;", NULL },
{ V('c','t'), 1, "&#162;", NULL },
{ V('d','e'), 1, "&#176;", NULL },
{ V('d','g'), 1, "+", NULL }, /* dagger */
{ V('d','i'), 1, "&#247;", NULL },
{ V('e','m'), 3, "---", NULL }, /* em dash */
{ V('e','n'), 1, "-", NULL }, /* en dash */
{ V('e','q'), 1, "=", NULL },
{ V('e','s'), 1, "&#216;", NULL },
{ V('f','f'), 2, "ff", NULL },
{ V('f','i'), 2, "fi", NULL },
{ V('f','l'), 2, "fl", NULL },
{ V('f','m'), 1, "&#180;", NULL },
{ V('g','a'), 1, "`", NULL },
{ V('h','y'), 1, "-", NULL },
{ V('l','c'), 2, "|&#175;", NULL },
{ V('i','f'), 8, "Infinity", NULL }, /* infinity sign */
{ V('i','s'), 8, "Integral", NULL }, /* integral sign */
{ V('l','f'), 2, "|_", NULL },
{ V('l','k'), 1, "<FONT SIZE=\"+2\">{</FONT>", NULL },
{ V('m','i'), 1, "-", NULL },
{ V('m','u'), 1, "&#215;", NULL },
{ V('n','o'), 1, "&#172;", NULL },
{ V('o','r'), 1, "|", NULL },
{ V('p','d'), 1, "d", NULL }, /* partial derivative */
{ V('p','l'), 1, "+", NULL },
{ V('r','c'), 2, "&#175;|", NULL },
{ V('r','f'), 2, "_|", NULL },
{ V('r','g'), 1, "&#174;", NULL },
{ V('r','k'), 1, "<FONT SIZE=\"+2\">}</FONT>", NULL },
{ V('r','n'), 1, "&#175;", NULL },
{ V('r','u'), 1, "_", NULL },
{ V('s','c'), 1, "&#167;", NULL },
{ V('s','l'), 1, "/", NULL },
{ V('s','q'), 2, "[]", NULL },
{ V('t','s'), 1, "s", NULL }, /* should be terminal sigma */
{ V('u','l'), 1, "_", NULL },
{ V('>','='), 1, "&gt;", NULL },
{ V('<','='), 1, "&lt;", NULL },
{ 0, 0, NULL, NULL }
};
void stdinit(void) {
STRDEF *stdf;
int i;
stdf = &standardchar[0];
i = 0;
while (stdf->nr) {
if (stdf->st) stdf->st = xstrdup(stdf->st);
stdf->next = &standardchar[i];
stdf = stdf->next;
i++;
}
chardef=&standardchar[0];
stdf=&standardstring[0];
i=0;
while (stdf->nr) {
/* waste a little memory, and make a copy, to avoid
the segfault when we free non-malloced memory */
if (stdf->st) stdf->st = xstrdup(stdf->st);
stdf->next = &standardstring[i];
stdf = stdf->next;
i++;
}
strdef=&standardstring[0];
intdef=&standardint[0];
i=0;
while (intdef->nr) {
if (intdef->nr == NROFF) intdef->nr = nroff; else
if (intdef->nr == TROFF) intdef->nr = !nroff;
intdef->next = &standardint[i];
intdef = intdef->next;
i++;
}
intdef = &standardint[0];
defdef = NULL;
}