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,179 @@
|
|
|
1
|
+
/* $Id: preconv.c,v 1.17 2018/12/13 11:55:47 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2014 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 AUTHOR DISCLAIMS ALL WARRANTIES
|
|
11
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
12
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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
|
+
#include <sys/types.h>
|
|
21
|
+
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
#include <stdio.h>
|
|
24
|
+
#include <string.h>
|
|
25
|
+
|
|
26
|
+
#include "mandoc.h"
|
|
27
|
+
#include "roff.h"
|
|
28
|
+
#include "mandoc_parse.h"
|
|
29
|
+
#include "libmandoc.h"
|
|
30
|
+
|
|
31
|
+
int
|
|
32
|
+
preconv_encode(const struct buf *ib, size_t *ii, struct buf *ob, size_t *oi,
|
|
33
|
+
int *filenc)
|
|
34
|
+
{
|
|
35
|
+
const unsigned char *cu;
|
|
36
|
+
int nby;
|
|
37
|
+
unsigned int accum;
|
|
38
|
+
|
|
39
|
+
cu = (const unsigned char *)ib->buf + *ii;
|
|
40
|
+
assert(*cu & 0x80);
|
|
41
|
+
|
|
42
|
+
if ( ! (*filenc & MPARSE_UTF8))
|
|
43
|
+
goto latin;
|
|
44
|
+
|
|
45
|
+
nby = 1;
|
|
46
|
+
while (nby < 5 && *cu & (1 << (7 - nby)))
|
|
47
|
+
nby++;
|
|
48
|
+
|
|
49
|
+
switch (nby) {
|
|
50
|
+
case 2:
|
|
51
|
+
accum = *cu & 0x1f;
|
|
52
|
+
if (accum < 0x02) /* Obfuscated ASCII. */
|
|
53
|
+
goto latin;
|
|
54
|
+
break;
|
|
55
|
+
case 3:
|
|
56
|
+
accum = *cu & 0x0f;
|
|
57
|
+
break;
|
|
58
|
+
case 4:
|
|
59
|
+
accum = *cu & 0x07;
|
|
60
|
+
if (accum > 0x04) /* Beyond Unicode. */
|
|
61
|
+
goto latin;
|
|
62
|
+
break;
|
|
63
|
+
default: /* Bad sequence header. */
|
|
64
|
+
goto latin;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
cu++;
|
|
68
|
+
switch (nby) {
|
|
69
|
+
case 3:
|
|
70
|
+
if ((accum == 0x00 && ! (*cu & 0x20)) || /* Use 2-byte. */
|
|
71
|
+
(accum == 0x0d && *cu & 0x20)) /* Surrogates. */
|
|
72
|
+
goto latin;
|
|
73
|
+
break;
|
|
74
|
+
case 4:
|
|
75
|
+
if ((accum == 0x00 && ! (*cu & 0x30)) || /* Use 3-byte. */
|
|
76
|
+
(accum == 0x04 && *cu & 0x30)) /* Beyond Unicode. */
|
|
77
|
+
goto latin;
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
while (--nby) {
|
|
84
|
+
if ((*cu & 0xc0) != 0x80) /* Invalid continuation. */
|
|
85
|
+
goto latin;
|
|
86
|
+
accum <<= 6;
|
|
87
|
+
accum += *cu & 0x3f;
|
|
88
|
+
cu++;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
assert(accum > 0x7f);
|
|
92
|
+
assert(accum < 0x110000);
|
|
93
|
+
assert(accum < 0xd800 || accum > 0xdfff);
|
|
94
|
+
|
|
95
|
+
*oi += snprintf(ob->buf + *oi, 11, "\\[u%.4X]", accum);
|
|
96
|
+
*ii = (const char *)cu - ib->buf;
|
|
97
|
+
*filenc &= ~MPARSE_LATIN1;
|
|
98
|
+
return 1;
|
|
99
|
+
|
|
100
|
+
latin:
|
|
101
|
+
if ( ! (*filenc & MPARSE_LATIN1))
|
|
102
|
+
return 0;
|
|
103
|
+
|
|
104
|
+
*oi += snprintf(ob->buf + *oi, 11,
|
|
105
|
+
"\\[u%.4X]", (unsigned char)ib->buf[(*ii)++]);
|
|
106
|
+
|
|
107
|
+
*filenc &= ~MPARSE_UTF8;
|
|
108
|
+
return 1;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
int
|
|
112
|
+
preconv_cue(const struct buf *b, size_t offset)
|
|
113
|
+
{
|
|
114
|
+
const char *ln, *eoln, *eoph;
|
|
115
|
+
size_t sz, phsz;
|
|
116
|
+
|
|
117
|
+
ln = b->buf + offset;
|
|
118
|
+
sz = b->sz - offset;
|
|
119
|
+
|
|
120
|
+
/* Look for the end-of-line. */
|
|
121
|
+
|
|
122
|
+
if (NULL == (eoln = memchr(ln, '\n', sz)))
|
|
123
|
+
eoln = ln + sz;
|
|
124
|
+
|
|
125
|
+
/* Check if we have the correct header/trailer. */
|
|
126
|
+
|
|
127
|
+
if ((sz = (size_t)(eoln - ln)) < 10 ||
|
|
128
|
+
memcmp(ln, ".\\\" -*-", 7) || memcmp(eoln - 3, "-*-", 3))
|
|
129
|
+
return MPARSE_UTF8 | MPARSE_LATIN1;
|
|
130
|
+
|
|
131
|
+
/* Move after the header and adjust for the trailer. */
|
|
132
|
+
|
|
133
|
+
ln += 7;
|
|
134
|
+
sz -= 10;
|
|
135
|
+
|
|
136
|
+
while (sz > 0) {
|
|
137
|
+
while (sz > 0 && ' ' == *ln) {
|
|
138
|
+
ln++;
|
|
139
|
+
sz--;
|
|
140
|
+
}
|
|
141
|
+
if (0 == sz)
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
/* Find the end-of-phrase marker (or eoln). */
|
|
145
|
+
|
|
146
|
+
if (NULL == (eoph = memchr(ln, ';', sz)))
|
|
147
|
+
eoph = eoln - 3;
|
|
148
|
+
else
|
|
149
|
+
eoph++;
|
|
150
|
+
|
|
151
|
+
/* Only account for the "coding" phrase. */
|
|
152
|
+
|
|
153
|
+
if ((phsz = eoph - ln) < 7 ||
|
|
154
|
+
strncasecmp(ln, "coding:", 7)) {
|
|
155
|
+
sz -= phsz;
|
|
156
|
+
ln += phsz;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
sz -= 7;
|
|
161
|
+
ln += 7;
|
|
162
|
+
|
|
163
|
+
while (sz > 0 && ' ' == *ln) {
|
|
164
|
+
ln++;
|
|
165
|
+
sz--;
|
|
166
|
+
}
|
|
167
|
+
if (0 == sz)
|
|
168
|
+
return 0;
|
|
169
|
+
|
|
170
|
+
/* Check us against known encodings. */
|
|
171
|
+
|
|
172
|
+
if (phsz > 4 && !strncasecmp(ln, "utf-8", 5))
|
|
173
|
+
return MPARSE_UTF8;
|
|
174
|
+
if (phsz > 10 && !strncasecmp(ln, "iso-latin-1", 11))
|
|
175
|
+
return MPARSE_LATIN1;
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
return MPARSE_UTF8 | MPARSE_LATIN1;
|
|
179
|
+
}
|