1/* 2 * Here are the routines of man2html that output a HREF string. 3 */ 4 5#include <stdlib.h> 6#include <stdio.h> 7#include <time.h> 8#include <ctype.h> /* tolower() */ 9#include <string.h> /* strlen() */ 10#include "defs.h" 11 12/* 13 * The default is to use cgibase. With relative html style 14 * we generate URLs of the form "../manX/page.html". 15 */ 16static int relat_html_style = 0; 17 18/* 19 * Either the user is non-local (or local, but using httpd), 20 * in which case we use http:/cgi-bin, or the user is local 21 * and uses lynx, and we use lynxcgi:/home/httpd/cgi-bin. 22 */ 23 24static char *man2htmlpath = "/cgi-bin/man/man2html"; /* default */ 25static char *cgibase_format = "http://%s"; /* host.domain:port */ 26static char *cgibase_ll_format = "lynxcgi:%s"; /* directory */ 27static char *cgibase = "http://localhost"; /* default */ 28 29/* 30 * Separator between URL and argument string. 31 * 32 * With http:<path to script>/a/b?c+d+e the script is called 33 * with PATH_INFO=/a/b and QUERY_STRING=c+d+e and args $1=c, $2=d, $3=e. 34 * With lynxcgi:<full path to script>?c+d+e no PATH_INFO is possible. 35 */ 36static char sep = '?'; /* or '/' */ 37 38void 39set_separator(char s) { 40 sep = s; 41} 42 43void 44set_lynxcgibase(char *s) { 45 int n = strlen(cgibase_ll_format) + strlen(s); 46 char *t = (char *) xmalloc(n); 47 48 sprintf(t, cgibase_ll_format, s); 49 cgibase = t; 50} 51 52void 53set_cgibase(char *s) { 54 int n = strlen(cgibase_format) + strlen(s); 55 char *t = (char *) xmalloc(n); 56 57 sprintf(t, cgibase_format, s); 58 cgibase = t; 59} 60 61void 62set_man2htmlpath(char *s) { 63 man2htmlpath = xstrdup(s); 64} 65 66void 67set_relative_html_links(void) { 68 relat_html_style = 1; 69} 70 71/* What shall we say in case of relat_html_style? */ 72static char *signature = "<HR>\n" 73"This document was created by\n" 74"<A HREF=\"%s%s\">man2html</A>,\n" 75"using the manual pages.<BR>\n" 76"%s\n"; 77 78#define TIMEFORMAT "%T GMT, %B %d, %Y" 79#define TIMEBUFSZ 500 80 81void print_sig() 82{ 83 char timebuf[TIMEBUFSZ]; 84 struct tm *timetm; 85 time_t clock; 86 87 timebuf[0] = 0; 88#ifdef TIMEFORMAT 89 sprintf(timebuf, "Time: "); 90 clock=time(NULL); 91 timetm=gmtime(&clock); 92 strftime(timebuf+6, TIMEBUFSZ-6, TIMEFORMAT, timetm); 93 timebuf[TIMEBUFSZ-1] = 0; 94#endif 95 printf(signature, cgibase, man2htmlpath, timebuf); 96} 97 98void 99include_file_html(char *g) { 100 printf("<A HREF=\"file:/usr/include/%s\">%s</A>>", g,g); 101} 102 103void 104man_page_html(char *sec, char *h) { 105 if (relat_html_style) { 106 if (!h) 107 printf("<A HREF=\"../index.html\">" 108 "Return to Main Contents</A>"); 109 else 110 printf("<A HREF=\"../man%s/%s.%s.html\">%s</A>", 111 sec, h, sec, h); 112 } else { 113 if (!h) 114 printf("<A HREF=\"%s%s\">Return to Main Contents</A>", 115 cgibase, man2htmlpath); 116 else if (!sec) 117 printf("<A HREF=\"%s%s%c%s\">%s</A>", 118 cgibase, man2htmlpath, sep, h, h); 119 else 120 printf("<A HREF=\"%s%s%c%s+%s\">%s</A>", 121 cgibase, man2htmlpath, sep, sec, h, h); 122 } 123} 124 125void 126ftp_html(char *f) { 127 printf("<A HREF=\"ftp://%s\">%s</A>", f, f); 128} 129 130void 131www_html(char *f) { 132 printf("<A HREF=\"http://%s\">%s</A>", f, f); 133} 134 135void 136mailto_html(char *g) { 137 printf("<A HREF=\"mailto:%s\">%s</A>", g, g); 138} 139 140void 141url_html(char *g) { 142 printf("<A HREF=\"%s\">%s</A>", g, g); 143} 144