/*
* Here are the routines of man2html that output a HREF string.
*/
#include
#include
#include
#include /* tolower() */
#include /* strlen() */
#include "defs.h"
#include
#include
/*
* 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;
/*
* 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:/usr/lib/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 = ""; /* default */
/*
* Separator between URL and argument string.
*
* With http:/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:?c+d+e no PATH_INFO is possible.
*/
static char sep = '?'; /* or '/' */
void
set_separator(char s) {
sep = s;
}
void
set_lynxcgibase(char *s) {
int n = strlen(cgibase_ll_format) + strlen(s);
char *t = (char *) xmalloc(n);
sprintf(t, cgibase_ll_format, s);
cgibase = t;
}
void
set_cgibase(char *s) {
int n = strlen(cgibase_format) + strlen(s);
char *t = (char *) xmalloc(n);
sprintf(t, cgibase_format, s);
cgibase = t;
}
void
set_man2htmlpath(char *s) {
man2htmlpath = xstrdup(s);
}
void
set_relative_html_links(void) {
relat_html_style = 1;
}
/* What shall we say in case of relat_html_style? */
static char *signature = "
\n"
"This document was created by\n"
"man2html,\n"
"using the manual pages.
\n"
"%s\n";
#define TIMEFORMAT "%T GMT, %B %d, %Y"
#define TIMEBUFSZ 500
void print_sig()
{
char timebuf[TIMEBUFSZ];
struct tm *timetm;
time_t now;
char *source_date_epoch;
unsigned long long epoch;
char *endptr;
timebuf[0] = 0;
#ifdef TIMEFORMAT
sprintf(timebuf, "Time: ");
source_date_epoch = getenv("SOURCE_DATE_EPOCH");
if (source_date_epoch) {
errno = 0;
epoch = strtoull(source_date_epoch, &endptr, 10);
if ((errno == ERANGE && (epoch == ULLONG_MAX || epoch == 0))
|| (errno != 0 && epoch == 0)) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: strtoull: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
if (endptr == source_date_epoch) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: No digits were found: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (*endptr != '\0') {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: Trailing garbage: %s\n", endptr);
exit(EXIT_FAILURE);
}
if (epoch > ULONG_MAX) {
fprintf(stderr, "Environment variable $SOURCE_DATE_EPOCH: value must be smaller than or equal to: %lu but was found to be: %llu \n", ULONG_MAX ,epoch);
exit(EXIT_FAILURE);
}
now=epoch;
}
else {
now=time(NULL);
}
timetm=gmtime(&now);
strftime(timebuf+6, TIMEBUFSZ-6, TIMEFORMAT, timetm);
timebuf[TIMEBUFSZ-1] = 0;
#endif
printf(signature, cgibase, man2htmlpath, timebuf);
}
void
include_file_html(char *g) {
printf("%s>", g,g);
}
void
man_page_html(char *sec, char *h) {
if (relat_html_style) {
if (!h)
printf(""
"Return to Main Contents");
else
printf("%s",
sec, h, sec, h);
} else {
if (!h)
printf("Return to Main Contents",
cgibase, man2htmlpath);
else if (!sec)
printf("%s",
cgibase, man2htmlpath, sep, h, h);
else
printf("%s",
cgibase, man2htmlpath, sep, sec, h, h);
}
}
void
ftp_html(char *f) {
printf("%s", f, f);
}
void
www_html(char *f) {
printf("%s", f, f);
}
void
mailto_html(char *g) {
printf("%s", g, g);
}
void
url_html(char *g) {
printf("%s", g, g);
}