forked from hamano/man2html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgibase.c
163 lines (139 loc) · 3.81 KB
/
cgibase.c
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
/*
* 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:/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:<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 '/' */
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;
}
void
set_current_html_links(void) {
current_html_style = 1;
}
/* 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/man-pages-zh/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 now;
timebuf[0] = 0;
#ifdef TIMEFORMAT
sprintf(timebuf, "Time: ");
now=time(NULL);
timetm=gmtime(&now);
strftime(timebuf+6, TIMEBUFSZ-6, TIMEFORMAT, timetm);
timebuf[TIMEBUFSZ-1] = 0;
#endif
//printf(signature, cgibase, man2htmlpath, timebuf);
printf(signature, timebuf);
}
void
include_file_html(char *g) {
printf("<a href=\"file:///usr/include/%s\">%s</a>>", g,g);
}
void
man_page_html(char *sec, char *h) {
if (current_html_style) {
if (!h)
printf("<a href=\"./\">"
"Return to Main Contents</a>");
else
printf("<a href=\"./%s.html\">%s</a>",
h, h);
} else if (relat_html_style) {
if (!h)
printf("<a href=\"../index.html\">"
"Return to Main Contents</a>");
else
printf("<a href=\"../man%s/%s.%s.html\">%s</a>",
sec, h, sec, h);
} else {
if (!h)
printf("<a href=\"%s%s\">Return to Main Contents</a>",
cgibase, man2htmlpath);
else if (!sec)
printf("<a href=\"%s%s%c%s\">%s</a>",
cgibase, man2htmlpath, sep, h, h);
else
printf("<a href=\"%s%s%c%s+%s\">%s</a>",
cgibase, man2htmlpath, sep, sec, h, h);
}
}
void
ftp_html(char *f) {
printf("<a href=\"ftp://%s\">%s</a>", f, f);
}
void
www_html(char *f) {
printf("<a href=\"http://%s\">%s</a>", f, f);
}
void
mailto_html(char *g) {
printf("<a href=\"mailto:%s\">%s</a>", g, g);
}
void
url_html(char *g) {
printf("<a href=\"%s\">%s</a>", g, g);
}
/* vim: set ts=8 sw=4 tw=0 et :*/