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
data/mandoc-1.14.6/st.c
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* $Id: st.c,v 1.16 2018/12/14 01:18:26 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
#include "config.h"
|
|
18
|
+
|
|
19
|
+
#include <sys/types.h>
|
|
20
|
+
|
|
21
|
+
#include <stdio.h>
|
|
22
|
+
#include <string.h>
|
|
23
|
+
|
|
24
|
+
#include "mandoc.h"
|
|
25
|
+
#include "roff.h"
|
|
26
|
+
#include "libmdoc.h"
|
|
27
|
+
|
|
28
|
+
#define LINE(x, y) \
|
|
29
|
+
if (0 == strcmp(p, x)) return(y);
|
|
30
|
+
|
|
31
|
+
const char *
|
|
32
|
+
mdoc_a2st(const char *p)
|
|
33
|
+
{
|
|
34
|
+
LINE("-p1003.1-88", "IEEE Std 1003.1-1988 (\\(lqPOSIX.1\\(rq)")
|
|
35
|
+
LINE("-p1003.1-90", "IEEE Std 1003.1-1990 (\\(lqPOSIX.1\\(rq)")
|
|
36
|
+
LINE("-p1003.1-96", "ISO/IEC 9945-1:1996 (\\(lqPOSIX.1\\(rq)")
|
|
37
|
+
LINE("-p1003.1-2001", "IEEE Std 1003.1-2001 (\\(lqPOSIX.1\\(rq)")
|
|
38
|
+
LINE("-p1003.1-2004", "IEEE Std 1003.1-2004 (\\(lqPOSIX.1\\(rq)")
|
|
39
|
+
LINE("-p1003.1-2008", "IEEE Std 1003.1-2008 (\\(lqPOSIX.1\\(rq)")
|
|
40
|
+
LINE("-p1003.1", "IEEE Std 1003.1 (\\(lqPOSIX.1\\(rq)")
|
|
41
|
+
LINE("-p1003.1b", "IEEE Std 1003.1b (\\(lqPOSIX.1b\\(rq)")
|
|
42
|
+
LINE("-p1003.1b-93", "IEEE Std 1003.1b-1993 (\\(lqPOSIX.1b\\(rq)")
|
|
43
|
+
LINE("-p1003.1c-95", "IEEE Std 1003.1c-1995 (\\(lqPOSIX.1c\\(rq)")
|
|
44
|
+
LINE("-p1003.1g-2000", "IEEE Std 1003.1g-2000 (\\(lqPOSIX.1g\\(rq)")
|
|
45
|
+
LINE("-p1003.1i-95", "IEEE Std 1003.1i-1995 (\\(lqPOSIX.1i\\(rq)")
|
|
46
|
+
LINE("-p1003.2", "IEEE Std 1003.2 (\\(lqPOSIX.2\\(rq)")
|
|
47
|
+
LINE("-p1003.2-92", "IEEE Std 1003.2-1992 (\\(lqPOSIX.2\\(rq)")
|
|
48
|
+
LINE("-p1003.2a-92", "IEEE Std 1003.2a-1992 (\\(lqPOSIX.2\\(rq)")
|
|
49
|
+
LINE("-isoC", "ISO/IEC 9899:1990 (\\(lqISO\\~C90\\(rq)")
|
|
50
|
+
LINE("-isoC-90", "ISO/IEC 9899:1990 (\\(lqISO\\~C90\\(rq)")
|
|
51
|
+
LINE("-isoC-amd1", "ISO/IEC 9899/AMD1:1995 (\\(lqISO\\~C90, Amendment 1\\(rq)")
|
|
52
|
+
LINE("-isoC-tcor1", "ISO/IEC 9899/TCOR1:1994 (\\(lqISO\\~C90, Technical Corrigendum 1\\(rq)")
|
|
53
|
+
LINE("-isoC-tcor2", "ISO/IEC 9899/TCOR2:1995 (\\(lqISO\\~C90, Technical Corrigendum 2\\(rq)")
|
|
54
|
+
LINE("-isoC-99", "ISO/IEC 9899:1999 (\\(lqISO\\~C99\\(rq)")
|
|
55
|
+
LINE("-isoC-2011", "ISO/IEC 9899:2011 (\\(lqISO\\~C11\\(rq)")
|
|
56
|
+
LINE("-iso9945-1-90", "ISO/IEC 9945-1:1990 (\\(lqPOSIX.1\\(rq)")
|
|
57
|
+
LINE("-iso9945-1-96", "ISO/IEC 9945-1:1996 (\\(lqPOSIX.1\\(rq)")
|
|
58
|
+
LINE("-iso9945-2-93", "ISO/IEC 9945-2:1993 (\\(lqPOSIX.2\\(rq)")
|
|
59
|
+
LINE("-ansiC", "ANSI X3.159-1989 (\\(lqANSI\\~C89\\(rq)")
|
|
60
|
+
LINE("-ansiC-89", "ANSI X3.159-1989 (\\(lqANSI\\~C89\\(rq)")
|
|
61
|
+
LINE("-ieee754", "IEEE Std 754-1985")
|
|
62
|
+
LINE("-iso8802-3", "ISO 8802-3: 1989")
|
|
63
|
+
LINE("-iso8601", "ISO 8601")
|
|
64
|
+
LINE("-ieee1275-94", "IEEE Std 1275-1994 (\\(lqOpen Firmware\\(rq)")
|
|
65
|
+
LINE("-xpg3", "X/Open Portability Guide Issue\\~3 (\\(lqXPG3\\(rq)")
|
|
66
|
+
LINE("-xpg4", "X/Open Portability Guide Issue\\~4 (\\(lqXPG4\\(rq)")
|
|
67
|
+
LINE("-xpg4.2", "X/Open Portability Guide Issue\\~4, Version\\~2 (\\(lqXPG4.2\\(rq)")
|
|
68
|
+
LINE("-xbd5", "X/Open Base Definitions Issue\\~5 (\\(lqXBD5\\(rq)")
|
|
69
|
+
LINE("-xcu5", "X/Open Commands and Utilities Issue\\~5 (\\(lqXCU5\\(rq)")
|
|
70
|
+
LINE("-xsh4.2", "X/Open System Interfaces and Headers Issue\\~4, Version\\~2 (\\(lqXSH4.2\\(rq)")
|
|
71
|
+
LINE("-xsh5", "X/Open System Interfaces and Headers Issue\\~5 (\\(lqXSH5\\(rq)")
|
|
72
|
+
LINE("-xns5", "X/Open Networking Services Issue\\~5 (\\(lqXNS5\\(rq)")
|
|
73
|
+
LINE("-xns5.2", "X/Open Networking Services Issue\\~5.2 (\\(lqXNS5.2\\(rq)")
|
|
74
|
+
LINE("-xcurses4.2", "X/Open Curses Issue\\~4, Version\\~2 (\\(lqXCURSES4.2\\(rq)")
|
|
75
|
+
LINE("-susv1", "Version\\~1 of the Single UNIX Specification (\\(lqSUSv1\\(rq)")
|
|
76
|
+
LINE("-susv2", "Version\\~2 of the Single UNIX Specification (\\(lqSUSv2\\(rq)")
|
|
77
|
+
LINE("-susv3", "Version\\~3 of the Single UNIX Specification (\\(lqSUSv3\\(rq)")
|
|
78
|
+
LINE("-susv4", "Version\\~4 of the Single UNIX Specification (\\(lqSUSv4\\(rq)")
|
|
79
|
+
LINE("-svid4", "System\\~V Interface Definition, Fourth Edition (\\(lqSVID4\\(rq)")
|
|
80
|
+
|
|
81
|
+
return NULL;
|
|
82
|
+
}
|
data/mandoc-1.14.6/tag.c
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* $Id: tag.c,v 1.36 2020/04/19 16:36:16 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*
|
|
17
|
+
* Functions to tag syntax tree nodes.
|
|
18
|
+
* For internal use by mandoc(1) validation modules only.
|
|
19
|
+
*/
|
|
20
|
+
#include "config.h"
|
|
21
|
+
|
|
22
|
+
#include <sys/types.h>
|
|
23
|
+
|
|
24
|
+
#include <assert.h>
|
|
25
|
+
#include <limits.h>
|
|
26
|
+
#include <stddef.h>
|
|
27
|
+
#include <stdint.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <string.h>
|
|
30
|
+
|
|
31
|
+
#include "mandoc_aux.h"
|
|
32
|
+
#include "mandoc_ohash.h"
|
|
33
|
+
#include "roff.h"
|
|
34
|
+
#include "mdoc.h"
|
|
35
|
+
#include "roff_int.h"
|
|
36
|
+
#include "tag.h"
|
|
37
|
+
|
|
38
|
+
struct tag_entry {
|
|
39
|
+
struct roff_node **nodes;
|
|
40
|
+
size_t maxnodes;
|
|
41
|
+
size_t nnodes;
|
|
42
|
+
int prio;
|
|
43
|
+
char s[];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static void tag_move_href(struct roff_man *,
|
|
47
|
+
struct roff_node *, const char *);
|
|
48
|
+
static void tag_move_id(struct roff_node *);
|
|
49
|
+
|
|
50
|
+
static struct ohash tag_data;
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Set up the ohash table to collect nodes
|
|
55
|
+
* where various marked-up terms are documented.
|
|
56
|
+
*/
|
|
57
|
+
void
|
|
58
|
+
tag_alloc(void)
|
|
59
|
+
{
|
|
60
|
+
mandoc_ohash_init(&tag_data, 4, offsetof(struct tag_entry, s));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void
|
|
64
|
+
tag_free(void)
|
|
65
|
+
{
|
|
66
|
+
struct tag_entry *entry;
|
|
67
|
+
unsigned int slot;
|
|
68
|
+
|
|
69
|
+
if (tag_data.info.free == NULL)
|
|
70
|
+
return;
|
|
71
|
+
entry = ohash_first(&tag_data, &slot);
|
|
72
|
+
while (entry != NULL) {
|
|
73
|
+
free(entry->nodes);
|
|
74
|
+
free(entry);
|
|
75
|
+
entry = ohash_next(&tag_data, &slot);
|
|
76
|
+
}
|
|
77
|
+
ohash_delete(&tag_data);
|
|
78
|
+
tag_data.info.free = NULL;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Set a node where a term is defined,
|
|
83
|
+
* unless it is already defined at a lower priority.
|
|
84
|
+
*/
|
|
85
|
+
void
|
|
86
|
+
tag_put(const char *s, int prio, struct roff_node *n)
|
|
87
|
+
{
|
|
88
|
+
struct tag_entry *entry;
|
|
89
|
+
struct roff_node *nold;
|
|
90
|
+
const char *se;
|
|
91
|
+
size_t len;
|
|
92
|
+
unsigned int slot;
|
|
93
|
+
|
|
94
|
+
assert(prio <= TAG_FALLBACK);
|
|
95
|
+
|
|
96
|
+
if (s == NULL) {
|
|
97
|
+
if (n->child == NULL || n->child->type != ROFFT_TEXT)
|
|
98
|
+
return;
|
|
99
|
+
s = n->child->string;
|
|
100
|
+
switch (s[0]) {
|
|
101
|
+
case '-':
|
|
102
|
+
s++;
|
|
103
|
+
break;
|
|
104
|
+
case '\\':
|
|
105
|
+
switch (s[1]) {
|
|
106
|
+
case '&':
|
|
107
|
+
case '-':
|
|
108
|
+
case 'e':
|
|
109
|
+
s += 2;
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/*
|
|
121
|
+
* Skip whitespace and escapes and whatever follows,
|
|
122
|
+
* and if there is any, downgrade the priority.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
len = strcspn(s, " \t\\");
|
|
126
|
+
if (len == 0)
|
|
127
|
+
return;
|
|
128
|
+
|
|
129
|
+
se = s + len;
|
|
130
|
+
if (*se != '\0' && prio < TAG_WEAK)
|
|
131
|
+
prio = TAG_WEAK;
|
|
132
|
+
|
|
133
|
+
slot = ohash_qlookupi(&tag_data, s, &se);
|
|
134
|
+
entry = ohash_find(&tag_data, slot);
|
|
135
|
+
|
|
136
|
+
/* Build a new entry. */
|
|
137
|
+
|
|
138
|
+
if (entry == NULL) {
|
|
139
|
+
entry = mandoc_malloc(sizeof(*entry) + len + 1);
|
|
140
|
+
memcpy(entry->s, s, len);
|
|
141
|
+
entry->s[len] = '\0';
|
|
142
|
+
entry->nodes = NULL;
|
|
143
|
+
entry->maxnodes = entry->nnodes = 0;
|
|
144
|
+
ohash_insert(&tag_data, slot, entry);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* Lower priority numbers take precedence.
|
|
149
|
+
* If a better entry is already present, ignore the new one.
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
else if (entry->prio < prio)
|
|
153
|
+
return;
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
* If the existing entry is worse, clear it.
|
|
157
|
+
* In addition, a tag with priority TAG_FALLBACK
|
|
158
|
+
* is only used if the tag occurs exactly once.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
else if (entry->prio > prio || prio == TAG_FALLBACK) {
|
|
162
|
+
while (entry->nnodes > 0) {
|
|
163
|
+
nold = entry->nodes[--entry->nnodes];
|
|
164
|
+
nold->flags &= ~NODE_ID;
|
|
165
|
+
free(nold->tag);
|
|
166
|
+
nold->tag = NULL;
|
|
167
|
+
}
|
|
168
|
+
if (prio == TAG_FALLBACK) {
|
|
169
|
+
entry->prio = TAG_DELETE;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/* Remember the new node. */
|
|
175
|
+
|
|
176
|
+
if (entry->maxnodes == entry->nnodes) {
|
|
177
|
+
entry->maxnodes += 4;
|
|
178
|
+
entry->nodes = mandoc_reallocarray(entry->nodes,
|
|
179
|
+
entry->maxnodes, sizeof(*entry->nodes));
|
|
180
|
+
}
|
|
181
|
+
entry->nodes[entry->nnodes++] = n;
|
|
182
|
+
entry->prio = prio;
|
|
183
|
+
n->flags |= NODE_ID;
|
|
184
|
+
if (n->child == NULL || n->child->string != s || *se != '\0') {
|
|
185
|
+
assert(n->tag == NULL);
|
|
186
|
+
n->tag = mandoc_strndup(s, len);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
int
|
|
191
|
+
tag_exists(const char *tag)
|
|
192
|
+
{
|
|
193
|
+
return ohash_find(&tag_data, ohash_qlookup(&tag_data, tag)) != NULL;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/*
|
|
197
|
+
* For in-line elements, move the link target
|
|
198
|
+
* to the enclosing paragraph when appropriate.
|
|
199
|
+
*/
|
|
200
|
+
static void
|
|
201
|
+
tag_move_id(struct roff_node *n)
|
|
202
|
+
{
|
|
203
|
+
struct roff_node *np;
|
|
204
|
+
|
|
205
|
+
np = n;
|
|
206
|
+
for (;;) {
|
|
207
|
+
if (np->prev != NULL)
|
|
208
|
+
np = np->prev;
|
|
209
|
+
else if ((np = np->parent) == NULL)
|
|
210
|
+
return;
|
|
211
|
+
switch (np->tok) {
|
|
212
|
+
case MDOC_It:
|
|
213
|
+
switch (np->parent->parent->norm->Bl.type) {
|
|
214
|
+
case LIST_column:
|
|
215
|
+
/* Target the ROFFT_BLOCK = <tr>. */
|
|
216
|
+
np = np->parent;
|
|
217
|
+
break;
|
|
218
|
+
case LIST_diag:
|
|
219
|
+
case LIST_hang:
|
|
220
|
+
case LIST_inset:
|
|
221
|
+
case LIST_ohang:
|
|
222
|
+
case LIST_tag:
|
|
223
|
+
/* Target the ROFFT_HEAD = <dt>. */
|
|
224
|
+
np = np->parent->head;
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
/* Target the ROFF_BODY = <li>. */
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
/* FALLTHROUGH */
|
|
231
|
+
case MDOC_Pp: /* Target the ROFFT_ELEM = <p>. */
|
|
232
|
+
if (np->tag == NULL) {
|
|
233
|
+
np->tag = mandoc_strdup(n->tag == NULL ?
|
|
234
|
+
n->child->string : n->tag);
|
|
235
|
+
np->flags |= NODE_ID;
|
|
236
|
+
n->flags &= ~NODE_ID;
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
case MDOC_Sh:
|
|
240
|
+
case MDOC_Ss:
|
|
241
|
+
case MDOC_Bd:
|
|
242
|
+
case MDOC_Bl:
|
|
243
|
+
case MDOC_D1:
|
|
244
|
+
case MDOC_Dl:
|
|
245
|
+
case MDOC_Rs:
|
|
246
|
+
/* Do not move past major blocks. */
|
|
247
|
+
return;
|
|
248
|
+
default:
|
|
249
|
+
/*
|
|
250
|
+
* Move past in-line content and partial
|
|
251
|
+
* blocks, for example .It Xo or .It Bq Er.
|
|
252
|
+
*/
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/*
|
|
259
|
+
* When a paragraph is tagged and starts with text,
|
|
260
|
+
* move the permalink to the first few words.
|
|
261
|
+
*/
|
|
262
|
+
static void
|
|
263
|
+
tag_move_href(struct roff_man *man, struct roff_node *n, const char *tag)
|
|
264
|
+
{
|
|
265
|
+
char *cp;
|
|
266
|
+
|
|
267
|
+
if (n == NULL || n->type != ROFFT_TEXT ||
|
|
268
|
+
*n->string == '\0' || *n->string == ' ')
|
|
269
|
+
return;
|
|
270
|
+
|
|
271
|
+
cp = n->string;
|
|
272
|
+
while (cp != NULL && cp - n->string < 5)
|
|
273
|
+
cp = strchr(cp + 1, ' ');
|
|
274
|
+
|
|
275
|
+
/* If the first text node is longer, split it. */
|
|
276
|
+
|
|
277
|
+
if (cp != NULL && cp[1] != '\0') {
|
|
278
|
+
man->last = n;
|
|
279
|
+
man->next = ROFF_NEXT_SIBLING;
|
|
280
|
+
roff_word_alloc(man, n->line,
|
|
281
|
+
n->pos + (cp - n->string), cp + 1);
|
|
282
|
+
man->last->flags = n->flags & ~NODE_LINE;
|
|
283
|
+
*cp = '\0';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
assert(n->tag == NULL);
|
|
287
|
+
n->tag = mandoc_strdup(tag);
|
|
288
|
+
n->flags |= NODE_HREF;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/*
|
|
292
|
+
* When all tags have been set, decide where to put
|
|
293
|
+
* the associated permalinks, and maybe move some tags
|
|
294
|
+
* to the beginning of the respective paragraphs.
|
|
295
|
+
*/
|
|
296
|
+
void
|
|
297
|
+
tag_postprocess(struct roff_man *man, struct roff_node *n)
|
|
298
|
+
{
|
|
299
|
+
if (n->flags & NODE_ID) {
|
|
300
|
+
switch (n->tok) {
|
|
301
|
+
case MDOC_Pp:
|
|
302
|
+
tag_move_href(man, n->next, n->tag);
|
|
303
|
+
break;
|
|
304
|
+
case MDOC_Bd:
|
|
305
|
+
case MDOC_D1:
|
|
306
|
+
case MDOC_Dl:
|
|
307
|
+
tag_move_href(man, n->child, n->tag);
|
|
308
|
+
break;
|
|
309
|
+
case MDOC_Bl:
|
|
310
|
+
/* XXX No permalink for now. */
|
|
311
|
+
break;
|
|
312
|
+
default:
|
|
313
|
+
if (n->type == ROFFT_ELEM || n->tok == MDOC_Fo)
|
|
314
|
+
tag_move_id(n);
|
|
315
|
+
if (n->tok != MDOC_Tg)
|
|
316
|
+
n->flags |= NODE_HREF;
|
|
317
|
+
else if ((n->flags & NODE_ID) == 0) {
|
|
318
|
+
n->flags |= NODE_NOPRT;
|
|
319
|
+
free(n->tag);
|
|
320
|
+
n->tag = NULL;
|
|
321
|
+
}
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
for (n = n->child; n != NULL; n = n->next)
|
|
326
|
+
tag_postprocess(man, n);
|
|
327
|
+
}
|
data/mandoc-1.14.6/tag.h
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* $Id: tag.h,v 1.14 2020/04/18 20:40:10 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org>
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*
|
|
17
|
+
* Internal interfaces to tag syntax tree nodes.
|
|
18
|
+
* For use by mandoc(1) validation modules only.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* Tagging priorities.
|
|
23
|
+
* Lower numbers indicate higher importance.
|
|
24
|
+
*/
|
|
25
|
+
#define TAG_MANUAL 1 /* Set with a .Tg macro. */
|
|
26
|
+
#define TAG_STRONG 2 /* Good automatic tagging. */
|
|
27
|
+
#define TAG_WEAK (INT_MAX - 2) /* Dubious automatic tagging. */
|
|
28
|
+
#define TAG_FALLBACK (INT_MAX - 1) /* Tag only used if unique. */
|
|
29
|
+
#define TAG_DELETE (INT_MAX) /* Tag not used at all. */
|
|
30
|
+
|
|
31
|
+
void tag_alloc(void);
|
|
32
|
+
int tag_exists(const char *);
|
|
33
|
+
void tag_put(const char *, int, struct roff_node *);
|
|
34
|
+
void tag_postprocess(struct roff_man *, struct roff_node *);
|
|
35
|
+
void tag_free(void);
|
data/mandoc-1.14.6/tbl.c
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* $Id: tbl.c,v 1.46 2018/12/14 06:33:14 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2011, 2015 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 <stdlib.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
#include <time.h>
|
|
27
|
+
|
|
28
|
+
#include "mandoc_aux.h"
|
|
29
|
+
#include "mandoc.h"
|
|
30
|
+
#include "tbl.h"
|
|
31
|
+
#include "libmandoc.h"
|
|
32
|
+
#include "tbl_parse.h"
|
|
33
|
+
#include "tbl_int.h"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
void
|
|
37
|
+
tbl_read(struct tbl_node *tbl, int ln, const char *p, int pos)
|
|
38
|
+
{
|
|
39
|
+
const char *cp;
|
|
40
|
+
int active;
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* In the options section, proceed to the layout section
|
|
44
|
+
* after a semicolon, or right away if there is no semicolon.
|
|
45
|
+
* Ignore semicolons in arguments.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
if (tbl->part == TBL_PART_OPTS) {
|
|
49
|
+
tbl->part = TBL_PART_LAYOUT;
|
|
50
|
+
active = 1;
|
|
51
|
+
for (cp = p + pos; *cp != '\0'; cp++) {
|
|
52
|
+
switch (*cp) {
|
|
53
|
+
case '(':
|
|
54
|
+
active = 0;
|
|
55
|
+
continue;
|
|
56
|
+
case ')':
|
|
57
|
+
active = 1;
|
|
58
|
+
continue;
|
|
59
|
+
case ';':
|
|
60
|
+
if (active)
|
|
61
|
+
break;
|
|
62
|
+
continue;
|
|
63
|
+
default:
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
if (*cp == ';') {
|
|
69
|
+
tbl_option(tbl, ln, p, &pos);
|
|
70
|
+
if (p[pos] == '\0')
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Process the other section types. */
|
|
76
|
+
|
|
77
|
+
switch (tbl->part) {
|
|
78
|
+
case TBL_PART_LAYOUT:
|
|
79
|
+
tbl_layout(tbl, ln, p, pos);
|
|
80
|
+
break;
|
|
81
|
+
case TBL_PART_CDATA:
|
|
82
|
+
tbl_cdata(tbl, ln, p, pos);
|
|
83
|
+
break;
|
|
84
|
+
default:
|
|
85
|
+
tbl_data(tbl, ln, p, pos);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
struct tbl_node *
|
|
91
|
+
tbl_alloc(int pos, int line, struct tbl_node *last_tbl)
|
|
92
|
+
{
|
|
93
|
+
struct tbl_node *tbl;
|
|
94
|
+
|
|
95
|
+
tbl = mandoc_calloc(1, sizeof(*tbl));
|
|
96
|
+
if (last_tbl != NULL)
|
|
97
|
+
last_tbl->next = tbl;
|
|
98
|
+
tbl->line = line;
|
|
99
|
+
tbl->pos = pos;
|
|
100
|
+
tbl->part = TBL_PART_OPTS;
|
|
101
|
+
tbl->opts.tab = '\t';
|
|
102
|
+
tbl->opts.decimal = '.';
|
|
103
|
+
return tbl;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void
|
|
107
|
+
tbl_free(struct tbl_node *tbl)
|
|
108
|
+
{
|
|
109
|
+
struct tbl_node *old_tbl;
|
|
110
|
+
struct tbl_row *rp;
|
|
111
|
+
struct tbl_cell *cp;
|
|
112
|
+
struct tbl_span *sp;
|
|
113
|
+
struct tbl_dat *dp;
|
|
114
|
+
|
|
115
|
+
while (tbl != NULL) {
|
|
116
|
+
while ((rp = tbl->first_row) != NULL) {
|
|
117
|
+
tbl->first_row = rp->next;
|
|
118
|
+
while (rp->first != NULL) {
|
|
119
|
+
cp = rp->first;
|
|
120
|
+
rp->first = cp->next;
|
|
121
|
+
free(cp->wstr);
|
|
122
|
+
free(cp);
|
|
123
|
+
}
|
|
124
|
+
free(rp);
|
|
125
|
+
}
|
|
126
|
+
while ((sp = tbl->first_span) != NULL) {
|
|
127
|
+
tbl->first_span = sp->next;
|
|
128
|
+
while (sp->first != NULL) {
|
|
129
|
+
dp = sp->first;
|
|
130
|
+
sp->first = dp->next;
|
|
131
|
+
free(dp->string);
|
|
132
|
+
free(dp);
|
|
133
|
+
}
|
|
134
|
+
free(sp);
|
|
135
|
+
}
|
|
136
|
+
old_tbl = tbl;
|
|
137
|
+
tbl = tbl->next;
|
|
138
|
+
free(old_tbl);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
void
|
|
143
|
+
tbl_restart(int line, int pos, struct tbl_node *tbl)
|
|
144
|
+
{
|
|
145
|
+
if (tbl->part == TBL_PART_CDATA)
|
|
146
|
+
mandoc_msg(MANDOCERR_TBLDATA_BLK, line, pos, "T&");
|
|
147
|
+
|
|
148
|
+
tbl->part = TBL_PART_LAYOUT;
|
|
149
|
+
tbl->line = line;
|
|
150
|
+
tbl->pos = pos;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
struct tbl_span *
|
|
154
|
+
tbl_span(struct tbl_node *tbl)
|
|
155
|
+
{
|
|
156
|
+
struct tbl_span *span;
|
|
157
|
+
|
|
158
|
+
span = tbl->current_span ? tbl->current_span->next
|
|
159
|
+
: tbl->first_span;
|
|
160
|
+
if (span != NULL)
|
|
161
|
+
tbl->current_span = span;
|
|
162
|
+
return span;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
int
|
|
166
|
+
tbl_end(struct tbl_node *tbl, int still_open)
|
|
167
|
+
{
|
|
168
|
+
struct tbl_span *sp;
|
|
169
|
+
|
|
170
|
+
if (still_open)
|
|
171
|
+
mandoc_msg(MANDOCERR_BLK_NOEND, tbl->line, tbl->pos, "TS");
|
|
172
|
+
else if (tbl->part == TBL_PART_CDATA)
|
|
173
|
+
mandoc_msg(MANDOCERR_TBLDATA_BLK, tbl->line, tbl->pos, "TE");
|
|
174
|
+
|
|
175
|
+
sp = tbl->first_span;
|
|
176
|
+
while (sp != NULL && sp->first == NULL)
|
|
177
|
+
sp = sp->next;
|
|
178
|
+
if (sp == NULL) {
|
|
179
|
+
mandoc_msg(MANDOCERR_TBLDATA_NONE, tbl->line, tbl->pos, NULL);
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
return 1;
|
|
183
|
+
}
|