mandoc 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/COPYING +674 -0
- data/README.md +117 -0
- data/ext/mandoc/extconf.rb +59 -0
- data/ext/mandoc/rb_mandoc.c +548 -0
- data/ext/mandoc/rb_mandoc.h +22 -0
- data/lib/mandoc/version.rb +19 -0
- data/lib/mandoc.rb +26 -0
- data/mandoc-1.14.6/LICENSE +55 -0
- data/mandoc-1.14.6/arch.c +54 -0
- data/mandoc-1.14.6/att.c +49 -0
- data/mandoc-1.14.6/catman.c +260 -0
- data/mandoc-1.14.6/cgi.c +1279 -0
- data/mandoc-1.14.6/chars.c +507 -0
- data/mandoc-1.14.6/compat_err.c +103 -0
- data/mandoc-1.14.6/compat_fts.c +696 -0
- data/mandoc-1.14.6/compat_fts.h +106 -0
- data/mandoc-1.14.6/compat_getline.c +59 -0
- data/mandoc-1.14.6/compat_getsubopt.c +87 -0
- data/mandoc-1.14.6/compat_isblank.c +23 -0
- data/mandoc-1.14.6/compat_mkdtemp.c +50 -0
- data/mandoc-1.14.6/compat_mkstemps.c +63 -0
- data/mandoc-1.14.6/compat_ohash.c +330 -0
- data/mandoc-1.14.6/compat_ohash.h +72 -0
- data/mandoc-1.14.6/compat_progname.c +31 -0
- data/mandoc-1.14.6/compat_reallocarray.c +40 -0
- data/mandoc-1.14.6/compat_recallocarray.c +99 -0
- data/mandoc-1.14.6/compat_strcasestr.c +64 -0
- data/mandoc-1.14.6/compat_stringlist.c +135 -0
- data/mandoc-1.14.6/compat_stringlist.h +48 -0
- data/mandoc-1.14.6/compat_strlcat.c +57 -0
- data/mandoc-1.14.6/compat_strlcpy.c +52 -0
- data/mandoc-1.14.6/compat_strndup.c +42 -0
- data/mandoc-1.14.6/compat_strsep.c +70 -0
- data/mandoc-1.14.6/compat_strtonum.c +67 -0
- data/mandoc-1.14.6/compat_vasprintf.c +47 -0
- data/mandoc-1.14.6/config.h +52 -0
- data/mandoc-1.14.6/dba.c +508 -0
- data/mandoc-1.14.6/dba.h +50 -0
- data/mandoc-1.14.6/dba_array.c +190 -0
- data/mandoc-1.14.6/dba_array.h +47 -0
- data/mandoc-1.14.6/dba_read.c +74 -0
- data/mandoc-1.14.6/dba_write.c +127 -0
- data/mandoc-1.14.6/dba_write.h +30 -0
- data/mandoc-1.14.6/dbm.c +480 -0
- data/mandoc-1.14.6/dbm.h +68 -0
- data/mandoc-1.14.6/dbm_map.c +194 -0
- data/mandoc-1.14.6/dbm_map.h +29 -0
- data/mandoc-1.14.6/demandoc.c +260 -0
- data/mandoc-1.14.6/eqn.c +1132 -0
- data/mandoc-1.14.6/eqn.h +72 -0
- data/mandoc-1.14.6/eqn_html.c +246 -0
- data/mandoc-1.14.6/eqn_parse.h +48 -0
- data/mandoc-1.14.6/eqn_term.c +174 -0
- data/mandoc-1.14.6/html.c +1102 -0
- data/mandoc-1.14.6/html.h +142 -0
- data/mandoc-1.14.6/lib.c +35 -0
- data/mandoc-1.14.6/libman.h +42 -0
- data/mandoc-1.14.6/libmandoc.h +85 -0
- data/mandoc-1.14.6/libmdoc.h +87 -0
- data/mandoc-1.14.6/main.c +1375 -0
- data/mandoc-1.14.6/main.h +53 -0
- data/mandoc-1.14.6/man.c +345 -0
- data/mandoc-1.14.6/man.h +21 -0
- data/mandoc-1.14.6/man_html.c +640 -0
- data/mandoc-1.14.6/man_macro.c +470 -0
- data/mandoc-1.14.6/man_term.c +1143 -0
- data/mandoc-1.14.6/man_validate.c +660 -0
- data/mandoc-1.14.6/manconf.h +58 -0
- data/mandoc-1.14.6/mandoc.c +669 -0
- data/mandoc-1.14.6/mandoc.h +329 -0
- data/mandoc-1.14.6/mandoc_aux.c +118 -0
- data/mandoc-1.14.6/mandoc_aux.h +27 -0
- data/mandoc-1.14.6/mandoc_msg.c +375 -0
- data/mandoc-1.14.6/mandoc_ohash.c +65 -0
- data/mandoc-1.14.6/mandoc_ohash.h +23 -0
- data/mandoc-1.14.6/mandoc_parse.h +44 -0
- data/mandoc-1.14.6/mandoc_xr.c +123 -0
- data/mandoc-1.14.6/mandoc_xr.h +31 -0
- data/mandoc-1.14.6/mandocd.c +282 -0
- data/mandoc-1.14.6/mandocdb.c +2448 -0
- data/mandoc-1.14.6/manpath.c +363 -0
- data/mandoc-1.14.6/mansearch.c +851 -0
- data/mandoc-1.14.6/mansearch.h +118 -0
- data/mandoc-1.14.6/mdoc.c +433 -0
- data/mandoc-1.14.6/mdoc.h +158 -0
- data/mandoc-1.14.6/mdoc_argv.c +682 -0
- data/mandoc-1.14.6/mdoc_html.c +1762 -0
- data/mandoc-1.14.6/mdoc_macro.c +1600 -0
- data/mandoc-1.14.6/mdoc_man.c +1850 -0
- data/mandoc-1.14.6/mdoc_markdown.c +1610 -0
- data/mandoc-1.14.6/mdoc_state.c +256 -0
- data/mandoc-1.14.6/mdoc_term.c +1964 -0
- data/mandoc-1.14.6/mdoc_validate.c +3062 -0
- data/mandoc-1.14.6/msec.c +37 -0
- data/mandoc-1.14.6/out.c +544 -0
- data/mandoc-1.14.6/out.h +70 -0
- data/mandoc-1.14.6/preconv.c +179 -0
- data/mandoc-1.14.6/read.c +732 -0
- data/mandoc-1.14.6/roff.c +4390 -0
- data/mandoc-1.14.6/roff.h +561 -0
- data/mandoc-1.14.6/roff_html.c +119 -0
- data/mandoc-1.14.6/roff_int.h +94 -0
- data/mandoc-1.14.6/roff_term.c +266 -0
- data/mandoc-1.14.6/roff_validate.c +151 -0
- data/mandoc-1.14.6/soelim.c +182 -0
- data/mandoc-1.14.6/st.c +82 -0
- data/mandoc-1.14.6/tag.c +327 -0
- data/mandoc-1.14.6/tag.h +35 -0
- data/mandoc-1.14.6/tbl.c +183 -0
- data/mandoc-1.14.6/tbl.h +121 -0
- data/mandoc-1.14.6/tbl_data.c +323 -0
- data/mandoc-1.14.6/tbl_html.c +293 -0
- data/mandoc-1.14.6/tbl_int.h +47 -0
- data/mandoc-1.14.6/tbl_layout.c +376 -0
- data/mandoc-1.14.6/tbl_opts.c +173 -0
- data/mandoc-1.14.6/tbl_parse.h +30 -0
- data/mandoc-1.14.6/tbl_term.c +948 -0
- data/mandoc-1.14.6/term.c +1113 -0
- data/mandoc-1.14.6/term.h +158 -0
- data/mandoc-1.14.6/term_ascii.c +424 -0
- data/mandoc-1.14.6/term_ps.c +1362 -0
- data/mandoc-1.14.6/term_tab.c +130 -0
- data/mandoc-1.14.6/term_tag.c +227 -0
- data/mandoc-1.14.6/term_tag.h +34 -0
- data/mandoc-1.14.6/tree.c +536 -0
- metadata +170 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/* $Id: mandocd.c,v 1.12 2020/06/14 23:40:31 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org>
|
|
4
|
+
* Copyright (c) 2017, 2019 Ingo Schwarze <schwarze@openbsd.org>
|
|
5
|
+
*
|
|
6
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
7
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
8
|
+
* copyright notice and this permission notice appear in all copies.
|
|
9
|
+
*
|
|
10
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
|
11
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
|
13
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
14
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
15
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
16
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
+
*/
|
|
18
|
+
#include "config.h"
|
|
19
|
+
|
|
20
|
+
#if NEED_XPG4_2
|
|
21
|
+
#define _XPG4_2
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
#include <sys/types.h>
|
|
25
|
+
#include <sys/socket.h>
|
|
26
|
+
|
|
27
|
+
#if HAVE_ERR
|
|
28
|
+
#include <err.h>
|
|
29
|
+
#endif
|
|
30
|
+
#include <limits.h>
|
|
31
|
+
#include <stdint.h>
|
|
32
|
+
#include <stdio.h>
|
|
33
|
+
#include <stdlib.h>
|
|
34
|
+
#include <string.h>
|
|
35
|
+
#include <unistd.h>
|
|
36
|
+
|
|
37
|
+
#include "mandoc.h"
|
|
38
|
+
#include "roff.h"
|
|
39
|
+
#include "mdoc.h"
|
|
40
|
+
#include "man.h"
|
|
41
|
+
#include "mandoc_parse.h"
|
|
42
|
+
#include "main.h"
|
|
43
|
+
#include "manconf.h"
|
|
44
|
+
|
|
45
|
+
enum outt {
|
|
46
|
+
OUTT_ASCII = 0,
|
|
47
|
+
OUTT_UTF8,
|
|
48
|
+
OUTT_HTML
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
static void process(struct mparse *, enum outt, void *);
|
|
52
|
+
static int read_fds(int, int *);
|
|
53
|
+
static void usage(void) __attribute__((__noreturn__));
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
#define NUM_FDS 3
|
|
57
|
+
static int
|
|
58
|
+
read_fds(int clientfd, int *fds)
|
|
59
|
+
{
|
|
60
|
+
struct msghdr msg;
|
|
61
|
+
struct iovec iov[1];
|
|
62
|
+
unsigned char dummy[1];
|
|
63
|
+
struct cmsghdr *cmsg;
|
|
64
|
+
int *walk;
|
|
65
|
+
int cnt;
|
|
66
|
+
|
|
67
|
+
/* Union used for alignment. */
|
|
68
|
+
union {
|
|
69
|
+
uint8_t controlbuf[CMSG_SPACE(NUM_FDS * sizeof(int))];
|
|
70
|
+
struct cmsghdr align;
|
|
71
|
+
} u;
|
|
72
|
+
|
|
73
|
+
memset(&msg, '\0', sizeof(msg));
|
|
74
|
+
msg.msg_control = u.controlbuf;
|
|
75
|
+
msg.msg_controllen = sizeof(u.controlbuf);
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
* Read a dummy byte - sendmsg cannot send an empty message,
|
|
79
|
+
* even if we are only interested in the OOB data.
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
iov[0].iov_base = dummy;
|
|
83
|
+
iov[0].iov_len = sizeof(dummy);
|
|
84
|
+
msg.msg_iov = iov;
|
|
85
|
+
msg.msg_iovlen = 1;
|
|
86
|
+
|
|
87
|
+
switch (recvmsg(clientfd, &msg, 0)) {
|
|
88
|
+
case -1:
|
|
89
|
+
warn("recvmsg");
|
|
90
|
+
return -1;
|
|
91
|
+
case 0:
|
|
92
|
+
return 0;
|
|
93
|
+
default:
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if ((cmsg = CMSG_FIRSTHDR(&msg)) == NULL) {
|
|
98
|
+
warnx("CMSG_FIRSTHDR: missing control message");
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (cmsg->cmsg_level != SOL_SOCKET ||
|
|
103
|
+
cmsg->cmsg_type != SCM_RIGHTS ||
|
|
104
|
+
cmsg->cmsg_len != CMSG_LEN(NUM_FDS * sizeof(int))) {
|
|
105
|
+
warnx("CMSG_FIRSTHDR: invalid control message");
|
|
106
|
+
return -1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
walk = (int *)CMSG_DATA(cmsg);
|
|
110
|
+
for (cnt = 0; cnt < NUM_FDS; cnt++)
|
|
111
|
+
fds[cnt] = *walk++;
|
|
112
|
+
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
int
|
|
117
|
+
main(int argc, char *argv[])
|
|
118
|
+
{
|
|
119
|
+
struct manoutput options;
|
|
120
|
+
struct mparse *parser;
|
|
121
|
+
void *formatter;
|
|
122
|
+
const char *defos;
|
|
123
|
+
const char *errstr;
|
|
124
|
+
int clientfd;
|
|
125
|
+
int old_stdin;
|
|
126
|
+
int old_stdout;
|
|
127
|
+
int old_stderr;
|
|
128
|
+
int fds[3];
|
|
129
|
+
int state, opt;
|
|
130
|
+
enum outt outtype;
|
|
131
|
+
|
|
132
|
+
defos = NULL;
|
|
133
|
+
outtype = OUTT_ASCII;
|
|
134
|
+
while ((opt = getopt(argc, argv, "I:T:")) != -1) {
|
|
135
|
+
switch (opt) {
|
|
136
|
+
case 'I':
|
|
137
|
+
if (strncmp(optarg, "os=", 3) == 0)
|
|
138
|
+
defos = optarg + 3;
|
|
139
|
+
else {
|
|
140
|
+
warnx("-I %s: Bad argument", optarg);
|
|
141
|
+
usage();
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case 'T':
|
|
145
|
+
if (strcmp(optarg, "ascii") == 0)
|
|
146
|
+
outtype = OUTT_ASCII;
|
|
147
|
+
else if (strcmp(optarg, "utf8") == 0)
|
|
148
|
+
outtype = OUTT_UTF8;
|
|
149
|
+
else if (strcmp(optarg, "html") == 0)
|
|
150
|
+
outtype = OUTT_HTML;
|
|
151
|
+
else {
|
|
152
|
+
warnx("-T %s: Bad argument", optarg);
|
|
153
|
+
usage();
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
default:
|
|
157
|
+
usage();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (argc > 0) {
|
|
162
|
+
argc -= optind;
|
|
163
|
+
argv += optind;
|
|
164
|
+
}
|
|
165
|
+
if (argc != 1)
|
|
166
|
+
usage();
|
|
167
|
+
|
|
168
|
+
errstr = NULL;
|
|
169
|
+
clientfd = strtonum(argv[0], 3, INT_MAX, &errstr);
|
|
170
|
+
if (errstr)
|
|
171
|
+
errx(1, "file descriptor %s %s", argv[1], errstr);
|
|
172
|
+
|
|
173
|
+
mchars_alloc();
|
|
174
|
+
parser = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 |
|
|
175
|
+
MPARSE_VALIDATE, MANDOC_OS_OTHER, defos);
|
|
176
|
+
|
|
177
|
+
memset(&options, 0, sizeof(options));
|
|
178
|
+
switch (outtype) {
|
|
179
|
+
case OUTT_ASCII:
|
|
180
|
+
formatter = ascii_alloc(&options);
|
|
181
|
+
break;
|
|
182
|
+
case OUTT_UTF8:
|
|
183
|
+
formatter = utf8_alloc(&options);
|
|
184
|
+
break;
|
|
185
|
+
case OUTT_HTML:
|
|
186
|
+
options.fragment = 1;
|
|
187
|
+
formatter = html_alloc(&options);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
state = 1; /* work to do */
|
|
192
|
+
fflush(stdout);
|
|
193
|
+
fflush(stderr);
|
|
194
|
+
if ((old_stdin = dup(STDIN_FILENO)) == -1 ||
|
|
195
|
+
(old_stdout = dup(STDOUT_FILENO)) == -1 ||
|
|
196
|
+
(old_stderr = dup(STDERR_FILENO)) == -1) {
|
|
197
|
+
warn("dup");
|
|
198
|
+
state = -1; /* error */
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
while (state == 1 && (state = read_fds(clientfd, fds)) == 1) {
|
|
202
|
+
if (dup2(fds[0], STDIN_FILENO) == -1 ||
|
|
203
|
+
dup2(fds[1], STDOUT_FILENO) == -1 ||
|
|
204
|
+
dup2(fds[2], STDERR_FILENO) == -1) {
|
|
205
|
+
warn("dup2");
|
|
206
|
+
state = -1;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
close(fds[0]);
|
|
211
|
+
close(fds[1]);
|
|
212
|
+
close(fds[2]);
|
|
213
|
+
|
|
214
|
+
process(parser, outtype, formatter);
|
|
215
|
+
mparse_reset(parser);
|
|
216
|
+
if (outtype == OUTT_HTML)
|
|
217
|
+
html_reset(formatter);
|
|
218
|
+
|
|
219
|
+
fflush(stdout);
|
|
220
|
+
fflush(stderr);
|
|
221
|
+
/* Close file descriptors by restoring the old ones. */
|
|
222
|
+
if (dup2(old_stderr, STDERR_FILENO) == -1 ||
|
|
223
|
+
dup2(old_stdout, STDOUT_FILENO) == -1 ||
|
|
224
|
+
dup2(old_stdin, STDIN_FILENO) == -1) {
|
|
225
|
+
warn("dup2");
|
|
226
|
+
state = -1;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
close(clientfd);
|
|
232
|
+
switch (outtype) {
|
|
233
|
+
case OUTT_ASCII:
|
|
234
|
+
case OUTT_UTF8:
|
|
235
|
+
ascii_free(formatter);
|
|
236
|
+
break;
|
|
237
|
+
case OUTT_HTML:
|
|
238
|
+
html_free(formatter);
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
mparse_free(parser);
|
|
242
|
+
mchars_free();
|
|
243
|
+
return state == -1 ? 1 : 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
static void
|
|
247
|
+
process(struct mparse *parser, enum outt outtype, void *formatter)
|
|
248
|
+
{
|
|
249
|
+
struct roff_meta *meta;
|
|
250
|
+
|
|
251
|
+
mparse_readfd(parser, STDIN_FILENO, "<unixfd>");
|
|
252
|
+
meta = mparse_result(parser);
|
|
253
|
+
if (meta->macroset == MACROSET_MDOC) {
|
|
254
|
+
switch (outtype) {
|
|
255
|
+
case OUTT_ASCII:
|
|
256
|
+
case OUTT_UTF8:
|
|
257
|
+
terminal_mdoc(formatter, meta);
|
|
258
|
+
break;
|
|
259
|
+
case OUTT_HTML:
|
|
260
|
+
html_mdoc(formatter, meta);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (meta->macroset == MACROSET_MAN) {
|
|
265
|
+
switch (outtype) {
|
|
266
|
+
case OUTT_ASCII:
|
|
267
|
+
case OUTT_UTF8:
|
|
268
|
+
terminal_man(formatter, meta);
|
|
269
|
+
break;
|
|
270
|
+
case OUTT_HTML:
|
|
271
|
+
html_man(formatter, meta);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
void
|
|
278
|
+
usage(void)
|
|
279
|
+
{
|
|
280
|
+
fprintf(stderr, "usage: mandocd [-I os=name] [-T output] socket_fd\n");
|
|
281
|
+
exit(1);
|
|
282
|
+
}
|