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,94 @@
|
|
|
1
|
+
/* $OpenBSD: roff_int.h,v 1.16 2019/01/05 00:36:46 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
|
|
4
|
+
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
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
|
+
* Parser internals shared by multiple parsers.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
struct ohash;
|
|
22
|
+
struct roff_node;
|
|
23
|
+
struct roff_meta;
|
|
24
|
+
struct roff;
|
|
25
|
+
struct mdoc_arg;
|
|
26
|
+
|
|
27
|
+
enum roff_next {
|
|
28
|
+
ROFF_NEXT_SIBLING = 0,
|
|
29
|
+
ROFF_NEXT_CHILD
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
struct roff_man {
|
|
33
|
+
struct roff_meta meta; /* Public parse results. */
|
|
34
|
+
struct roff *roff; /* Roff parser state data. */
|
|
35
|
+
struct ohash *mdocmac; /* Mdoc macro lookup table. */
|
|
36
|
+
struct ohash *manmac; /* Man macro lookup table. */
|
|
37
|
+
const char *os_s; /* Default operating system. */
|
|
38
|
+
struct roff_node *last; /* The last node parsed. */
|
|
39
|
+
struct roff_node *last_es; /* The most recent Es node. */
|
|
40
|
+
int quick; /* Abort parse early. */
|
|
41
|
+
int flags; /* Parse flags. */
|
|
42
|
+
#define ROFF_NOFILL (1 << 1) /* Fill mode switched off. */
|
|
43
|
+
#define MDOC_PBODY (1 << 2) /* In the document body. */
|
|
44
|
+
#define MDOC_NEWLINE (1 << 3) /* First macro/text in a line. */
|
|
45
|
+
#define MDOC_PHRASE (1 << 4) /* In a Bl -column phrase. */
|
|
46
|
+
#define MDOC_PHRASELIT (1 << 5) /* Literal within a phrase. */
|
|
47
|
+
#define MDOC_FREECOL (1 << 6) /* `It' invocation should close. */
|
|
48
|
+
#define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting. */
|
|
49
|
+
#define MDOC_KEEP (1 << 8) /* In a word keep. */
|
|
50
|
+
#define MDOC_SMOFF (1 << 9) /* Spacing is off. */
|
|
51
|
+
#define MDOC_NODELIMC (1 << 10) /* Disable closing delimiter handling. */
|
|
52
|
+
#define MAN_ELINE (1 << 11) /* Next-line element scope. */
|
|
53
|
+
#define MAN_BLINE (1 << 12) /* Next-line block scope. */
|
|
54
|
+
#define MDOC_PHRASEQF (1 << 13) /* Quote first word encountered. */
|
|
55
|
+
#define MDOC_PHRASEQL (1 << 14) /* Quote last word of this phrase. */
|
|
56
|
+
#define MDOC_PHRASEQN (1 << 15) /* Quote first word of the next phrase. */
|
|
57
|
+
#define ROFF_NONOFILL (1 << 16) /* Temporarily suspend no-fill mode. */
|
|
58
|
+
#define MAN_NEWLINE MDOC_NEWLINE
|
|
59
|
+
enum roff_sec lastsec; /* Last section seen. */
|
|
60
|
+
enum roff_sec lastnamed; /* Last standard section seen. */
|
|
61
|
+
enum roff_next next; /* Where to put the next node. */
|
|
62
|
+
char filesec; /* Section digit in the file name. */
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
struct roff_node *roff_node_alloc(struct roff_man *, int, int,
|
|
67
|
+
enum roff_type, int);
|
|
68
|
+
void roff_node_append(struct roff_man *, struct roff_node *);
|
|
69
|
+
void roff_word_alloc(struct roff_man *, int, int, const char *);
|
|
70
|
+
void roff_word_append(struct roff_man *, const char *);
|
|
71
|
+
void roff_elem_alloc(struct roff_man *, int, int, int);
|
|
72
|
+
struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
|
|
73
|
+
struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
|
|
74
|
+
struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
|
|
75
|
+
void roff_node_unlink(struct roff_man *, struct roff_node *);
|
|
76
|
+
void roff_node_relink(struct roff_man *, struct roff_node *);
|
|
77
|
+
void roff_node_free(struct roff_node *);
|
|
78
|
+
void roff_node_delete(struct roff_man *, struct roff_node *);
|
|
79
|
+
|
|
80
|
+
struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok);
|
|
81
|
+
enum roff_tok roffhash_find(struct ohash *, const char *, size_t);
|
|
82
|
+
void roffhash_free(struct ohash *);
|
|
83
|
+
|
|
84
|
+
void roff_state_reset(struct roff_man *);
|
|
85
|
+
void roff_validate(struct roff_man *);
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* Functions called from roff.c need to be declared here,
|
|
89
|
+
* not in libmdoc.h or libman.h, even if they are specific
|
|
90
|
+
* to either the mdoc(7) or the man(7) parser.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
void man_breakscope(struct roff_man *, int);
|
|
94
|
+
void mdoc_argv_free(struct mdoc_arg *);
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/* $OpenBSD: roff_term.c,v 1.20 2020/09/03 17:37:06 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2010,2014,2015,2017-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
|
+
#include "config.h"
|
|
18
|
+
|
|
19
|
+
#include <sys/types.h>
|
|
20
|
+
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
#include <stdio.h>
|
|
23
|
+
#include <string.h>
|
|
24
|
+
|
|
25
|
+
#include "mandoc.h"
|
|
26
|
+
#include "roff.h"
|
|
27
|
+
#include "out.h"
|
|
28
|
+
#include "term.h"
|
|
29
|
+
|
|
30
|
+
#define ROFF_TERM_ARGS struct termp *p, const struct roff_node *n
|
|
31
|
+
|
|
32
|
+
typedef void (*roff_term_pre_fp)(ROFF_TERM_ARGS);
|
|
33
|
+
|
|
34
|
+
static void roff_term_pre_br(ROFF_TERM_ARGS);
|
|
35
|
+
static void roff_term_pre_ce(ROFF_TERM_ARGS);
|
|
36
|
+
static void roff_term_pre_ft(ROFF_TERM_ARGS);
|
|
37
|
+
static void roff_term_pre_ll(ROFF_TERM_ARGS);
|
|
38
|
+
static void roff_term_pre_mc(ROFF_TERM_ARGS);
|
|
39
|
+
static void roff_term_pre_po(ROFF_TERM_ARGS);
|
|
40
|
+
static void roff_term_pre_sp(ROFF_TERM_ARGS);
|
|
41
|
+
static void roff_term_pre_ta(ROFF_TERM_ARGS);
|
|
42
|
+
static void roff_term_pre_ti(ROFF_TERM_ARGS);
|
|
43
|
+
|
|
44
|
+
static const roff_term_pre_fp roff_term_pre_acts[ROFF_MAX] = {
|
|
45
|
+
roff_term_pre_br, /* br */
|
|
46
|
+
roff_term_pre_ce, /* ce */
|
|
47
|
+
roff_term_pre_br, /* fi */
|
|
48
|
+
roff_term_pre_ft, /* ft */
|
|
49
|
+
roff_term_pre_ll, /* ll */
|
|
50
|
+
roff_term_pre_mc, /* mc */
|
|
51
|
+
roff_term_pre_br, /* nf */
|
|
52
|
+
roff_term_pre_po, /* po */
|
|
53
|
+
roff_term_pre_ce, /* rj */
|
|
54
|
+
roff_term_pre_sp, /* sp */
|
|
55
|
+
roff_term_pre_ta, /* ta */
|
|
56
|
+
roff_term_pre_ti, /* ti */
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
void
|
|
61
|
+
roff_term_pre(struct termp *p, const struct roff_node *n)
|
|
62
|
+
{
|
|
63
|
+
assert(n->tok < ROFF_MAX);
|
|
64
|
+
(*roff_term_pre_acts[n->tok])(p, n);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void
|
|
68
|
+
roff_term_pre_br(ROFF_TERM_ARGS)
|
|
69
|
+
{
|
|
70
|
+
term_newln(p);
|
|
71
|
+
if (p->flags & TERMP_BRIND) {
|
|
72
|
+
p->tcol->offset = p->tcol->rmargin;
|
|
73
|
+
p->tcol->rmargin = p->maxrmargin;
|
|
74
|
+
p->trailspace = 0;
|
|
75
|
+
p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND);
|
|
76
|
+
p->flags |= TERMP_NOSPACE;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static void
|
|
81
|
+
roff_term_pre_ce(ROFF_TERM_ARGS)
|
|
82
|
+
{
|
|
83
|
+
const struct roff_node *nc1, *nc2;
|
|
84
|
+
|
|
85
|
+
roff_term_pre_br(p, n);
|
|
86
|
+
p->flags |= n->tok == ROFF_ce ? TERMP_CENTER : TERMP_RIGHT;
|
|
87
|
+
nc1 = n->child->next;
|
|
88
|
+
while (nc1 != NULL) {
|
|
89
|
+
nc2 = nc1;
|
|
90
|
+
do {
|
|
91
|
+
nc2 = nc2->next;
|
|
92
|
+
} while (nc2 != NULL && (nc2->type != ROFFT_TEXT ||
|
|
93
|
+
(nc2->flags & NODE_LINE) == 0));
|
|
94
|
+
while (nc1 != nc2) {
|
|
95
|
+
if (nc1->type == ROFFT_TEXT)
|
|
96
|
+
term_word(p, nc1->string);
|
|
97
|
+
else
|
|
98
|
+
roff_term_pre(p, nc1);
|
|
99
|
+
nc1 = nc1->next;
|
|
100
|
+
}
|
|
101
|
+
p->flags |= TERMP_NOSPACE;
|
|
102
|
+
term_flushln(p);
|
|
103
|
+
}
|
|
104
|
+
p->flags &= ~(TERMP_CENTER | TERMP_RIGHT);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void
|
|
108
|
+
roff_term_pre_ft(ROFF_TERM_ARGS)
|
|
109
|
+
{
|
|
110
|
+
const char *cp;
|
|
111
|
+
|
|
112
|
+
cp = n->child->string;
|
|
113
|
+
switch (mandoc_font(cp, (int)strlen(cp))) {
|
|
114
|
+
case ESCAPE_FONTBOLD:
|
|
115
|
+
case ESCAPE_FONTCB:
|
|
116
|
+
term_fontrepl(p, TERMFONT_BOLD);
|
|
117
|
+
break;
|
|
118
|
+
case ESCAPE_FONTITALIC:
|
|
119
|
+
case ESCAPE_FONTCI:
|
|
120
|
+
term_fontrepl(p, TERMFONT_UNDER);
|
|
121
|
+
break;
|
|
122
|
+
case ESCAPE_FONTBI:
|
|
123
|
+
term_fontrepl(p, TERMFONT_BI);
|
|
124
|
+
break;
|
|
125
|
+
case ESCAPE_FONTPREV:
|
|
126
|
+
term_fontlast(p);
|
|
127
|
+
break;
|
|
128
|
+
case ESCAPE_FONTROMAN:
|
|
129
|
+
case ESCAPE_FONTCR:
|
|
130
|
+
term_fontrepl(p, TERMFONT_NONE);
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static void
|
|
138
|
+
roff_term_pre_ll(ROFF_TERM_ARGS)
|
|
139
|
+
{
|
|
140
|
+
term_setwidth(p, n->child != NULL ? n->child->string : NULL);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static void
|
|
144
|
+
roff_term_pre_mc(ROFF_TERM_ARGS)
|
|
145
|
+
{
|
|
146
|
+
if (p->col) {
|
|
147
|
+
p->flags |= TERMP_NOBREAK;
|
|
148
|
+
term_flushln(p);
|
|
149
|
+
p->flags &= ~(TERMP_NOBREAK | TERMP_NOSPACE);
|
|
150
|
+
}
|
|
151
|
+
if (n->child != NULL) {
|
|
152
|
+
p->mc = n->child->string;
|
|
153
|
+
p->flags |= TERMP_NEWMC;
|
|
154
|
+
} else
|
|
155
|
+
p->flags |= TERMP_ENDMC;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static void
|
|
159
|
+
roff_term_pre_po(ROFF_TERM_ARGS)
|
|
160
|
+
{
|
|
161
|
+
struct roffsu su;
|
|
162
|
+
static int po, pouse, polast;
|
|
163
|
+
int ponew;
|
|
164
|
+
|
|
165
|
+
/* Revert the currently active page offset. */
|
|
166
|
+
p->tcol->offset -= pouse;
|
|
167
|
+
|
|
168
|
+
/* Determine the requested page offset. */
|
|
169
|
+
if (n->child != NULL &&
|
|
170
|
+
a2roffsu(n->child->string, &su, SCALE_EM) != NULL) {
|
|
171
|
+
ponew = term_hen(p, &su);
|
|
172
|
+
if (*n->child->string == '+' ||
|
|
173
|
+
*n->child->string == '-')
|
|
174
|
+
ponew += po;
|
|
175
|
+
} else
|
|
176
|
+
ponew = polast;
|
|
177
|
+
|
|
178
|
+
/* Remeber both the previous and the newly requested offset. */
|
|
179
|
+
polast = po;
|
|
180
|
+
po = ponew;
|
|
181
|
+
|
|
182
|
+
/* Truncate to the range [-offset, 60], remember, and apply it. */
|
|
183
|
+
pouse = po >= 60 ? 60 :
|
|
184
|
+
po < -(int)p->tcol->offset ? -(int)p->tcol->offset : po;
|
|
185
|
+
p->tcol->offset += pouse;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static void
|
|
189
|
+
roff_term_pre_sp(ROFF_TERM_ARGS)
|
|
190
|
+
{
|
|
191
|
+
struct roffsu su;
|
|
192
|
+
int len;
|
|
193
|
+
|
|
194
|
+
if (n->child != NULL) {
|
|
195
|
+
if (a2roffsu(n->child->string, &su, SCALE_VS) == NULL)
|
|
196
|
+
su.scale = 1.0;
|
|
197
|
+
len = term_vspan(p, &su);
|
|
198
|
+
} else
|
|
199
|
+
len = 1;
|
|
200
|
+
|
|
201
|
+
if (len < 0)
|
|
202
|
+
p->skipvsp -= len;
|
|
203
|
+
else
|
|
204
|
+
while (len--)
|
|
205
|
+
term_vspace(p);
|
|
206
|
+
|
|
207
|
+
roff_term_pre_br(p, n);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
static void
|
|
211
|
+
roff_term_pre_ta(ROFF_TERM_ARGS)
|
|
212
|
+
{
|
|
213
|
+
term_tab_set(p, NULL);
|
|
214
|
+
for (n = n->child; n != NULL; n = n->next)
|
|
215
|
+
term_tab_set(p, n->string);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static void
|
|
219
|
+
roff_term_pre_ti(ROFF_TERM_ARGS)
|
|
220
|
+
{
|
|
221
|
+
struct roffsu su;
|
|
222
|
+
const char *cp;
|
|
223
|
+
const size_t maxoff = 72;
|
|
224
|
+
int len, sign;
|
|
225
|
+
|
|
226
|
+
roff_term_pre_br(p, n);
|
|
227
|
+
|
|
228
|
+
if (n->child == NULL)
|
|
229
|
+
return;
|
|
230
|
+
cp = n->child->string;
|
|
231
|
+
if (*cp == '+') {
|
|
232
|
+
sign = 1;
|
|
233
|
+
cp++;
|
|
234
|
+
} else if (*cp == '-') {
|
|
235
|
+
sign = -1;
|
|
236
|
+
cp++;
|
|
237
|
+
} else
|
|
238
|
+
sign = 0;
|
|
239
|
+
|
|
240
|
+
if (a2roffsu(cp, &su, SCALE_EM) == NULL)
|
|
241
|
+
return;
|
|
242
|
+
len = term_hen(p, &su);
|
|
243
|
+
|
|
244
|
+
switch (sign) {
|
|
245
|
+
case 1:
|
|
246
|
+
if (p->tcol->offset + len <= maxoff)
|
|
247
|
+
p->ti = len;
|
|
248
|
+
else if (p->tcol->offset < maxoff)
|
|
249
|
+
p->ti = maxoff - p->tcol->offset;
|
|
250
|
+
else
|
|
251
|
+
p->ti = 0;
|
|
252
|
+
break;
|
|
253
|
+
case -1:
|
|
254
|
+
if ((size_t)len < p->tcol->offset)
|
|
255
|
+
p->ti = -len;
|
|
256
|
+
else
|
|
257
|
+
p->ti = -p->tcol->offset;
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
if ((size_t)len > maxoff)
|
|
261
|
+
len = maxoff;
|
|
262
|
+
p->ti = len - p->tcol->offset;
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
p->tcol->offset += p->ti;
|
|
266
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* $Id: roff_validate.c,v 1.20 2020/06/22 19:20:40 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2010, 2017, 2018, 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
|
+
#include "config.h"
|
|
18
|
+
|
|
19
|
+
#include <sys/types.h>
|
|
20
|
+
|
|
21
|
+
#include <assert.h>
|
|
22
|
+
#include <stdio.h>
|
|
23
|
+
#include <string.h>
|
|
24
|
+
|
|
25
|
+
#include "mandoc.h"
|
|
26
|
+
#include "roff.h"
|
|
27
|
+
#include "libmandoc.h"
|
|
28
|
+
#include "roff_int.h"
|
|
29
|
+
|
|
30
|
+
#define ROFF_VALID_ARGS struct roff_man *man, struct roff_node *n
|
|
31
|
+
|
|
32
|
+
typedef void (*roff_valid_fp)(ROFF_VALID_ARGS);
|
|
33
|
+
|
|
34
|
+
static void roff_valid_br(ROFF_VALID_ARGS);
|
|
35
|
+
static void roff_valid_fi(ROFF_VALID_ARGS);
|
|
36
|
+
static void roff_valid_ft(ROFF_VALID_ARGS);
|
|
37
|
+
static void roff_valid_nf(ROFF_VALID_ARGS);
|
|
38
|
+
static void roff_valid_sp(ROFF_VALID_ARGS);
|
|
39
|
+
|
|
40
|
+
static const roff_valid_fp roff_valids[ROFF_MAX] = {
|
|
41
|
+
roff_valid_br, /* br */
|
|
42
|
+
NULL, /* ce */
|
|
43
|
+
roff_valid_fi, /* fi */
|
|
44
|
+
roff_valid_ft, /* ft */
|
|
45
|
+
NULL, /* ll */
|
|
46
|
+
NULL, /* mc */
|
|
47
|
+
roff_valid_nf, /* nf */
|
|
48
|
+
NULL, /* po */
|
|
49
|
+
NULL, /* rj */
|
|
50
|
+
roff_valid_sp, /* sp */
|
|
51
|
+
NULL, /* ta */
|
|
52
|
+
NULL, /* ti */
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
void
|
|
57
|
+
roff_validate(struct roff_man *man)
|
|
58
|
+
{
|
|
59
|
+
struct roff_node *n;
|
|
60
|
+
|
|
61
|
+
n = man->last;
|
|
62
|
+
assert(n->tok < ROFF_MAX);
|
|
63
|
+
if (roff_valids[n->tok] != NULL)
|
|
64
|
+
(*roff_valids[n->tok])(man, n);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void
|
|
68
|
+
roff_valid_br(ROFF_VALID_ARGS)
|
|
69
|
+
{
|
|
70
|
+
struct roff_node *np;
|
|
71
|
+
|
|
72
|
+
if (n->next != NULL && n->next->type == ROFFT_TEXT &&
|
|
73
|
+
*n->next->string == ' ') {
|
|
74
|
+
mandoc_msg(MANDOCERR_PAR_SKIP, n->line, n->pos,
|
|
75
|
+
"br before text line with leading blank");
|
|
76
|
+
roff_node_delete(man, n);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ((np = roff_node_prev(n)) == NULL)
|
|
81
|
+
return;
|
|
82
|
+
|
|
83
|
+
switch (np->tok) {
|
|
84
|
+
case ROFF_br:
|
|
85
|
+
case ROFF_sp:
|
|
86
|
+
case MDOC_Pp:
|
|
87
|
+
mandoc_msg(MANDOCERR_PAR_SKIP,
|
|
88
|
+
n->line, n->pos, "br after %s", roff_name[np->tok]);
|
|
89
|
+
roff_node_delete(man, n);
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static void
|
|
97
|
+
roff_valid_fi(ROFF_VALID_ARGS)
|
|
98
|
+
{
|
|
99
|
+
if ((n->flags & NODE_NOFILL) == 0)
|
|
100
|
+
mandoc_msg(MANDOCERR_FI_SKIP, n->line, n->pos, "fi");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static void
|
|
104
|
+
roff_valid_ft(ROFF_VALID_ARGS)
|
|
105
|
+
{
|
|
106
|
+
const char *cp;
|
|
107
|
+
|
|
108
|
+
if (n->child == NULL) {
|
|
109
|
+
man->next = ROFF_NEXT_CHILD;
|
|
110
|
+
roff_word_alloc(man, n->line, n->pos, "P");
|
|
111
|
+
man->last = n;
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cp = n->child->string;
|
|
116
|
+
if (mandoc_font(cp, (int)strlen(cp)) != ESCAPE_ERROR)
|
|
117
|
+
return;
|
|
118
|
+
mandoc_msg(MANDOCERR_FT_BAD, n->line, n->pos, "ft %s", cp);
|
|
119
|
+
roff_node_delete(man, n);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static void
|
|
123
|
+
roff_valid_nf(ROFF_VALID_ARGS)
|
|
124
|
+
{
|
|
125
|
+
if (n->flags & NODE_NOFILL)
|
|
126
|
+
mandoc_msg(MANDOCERR_NF_SKIP, n->line, n->pos, "nf");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static void
|
|
130
|
+
roff_valid_sp(ROFF_VALID_ARGS)
|
|
131
|
+
{
|
|
132
|
+
struct roff_node *np;
|
|
133
|
+
|
|
134
|
+
if ((np = roff_node_prev(n)) == NULL)
|
|
135
|
+
return;
|
|
136
|
+
|
|
137
|
+
switch (np->tok) {
|
|
138
|
+
case ROFF_br:
|
|
139
|
+
mandoc_msg(MANDOCERR_PAR_SKIP,
|
|
140
|
+
np->line, np->pos, "br before sp");
|
|
141
|
+
roff_node_delete(man, np);
|
|
142
|
+
break;
|
|
143
|
+
case MDOC_Pp:
|
|
144
|
+
mandoc_msg(MANDOCERR_PAR_SKIP,
|
|
145
|
+
n->line, n->pos, "sp after Pp");
|
|
146
|
+
roff_node_delete(man, n);
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/* $Id: soelim.c,v 1.6 2021/09/19 18:14:24 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
|
7
|
+
* modification, are permitted provided that the following conditions
|
|
8
|
+
* are met:
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer
|
|
11
|
+
* in this position and unchanged.
|
|
12
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
13
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
14
|
+
* documentation and/or other materials provided with the distribution.
|
|
15
|
+
*
|
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
17
|
+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
18
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
20
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
21
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
22
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
23
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
24
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
25
|
+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
#include "config.h"
|
|
28
|
+
|
|
29
|
+
#include <sys/types.h>
|
|
30
|
+
|
|
31
|
+
#include <ctype.h>
|
|
32
|
+
#if HAVE_ERR
|
|
33
|
+
#include <err.h>
|
|
34
|
+
#endif
|
|
35
|
+
#include <limits.h>
|
|
36
|
+
#include <stdio.h>
|
|
37
|
+
#include <stdlib.h>
|
|
38
|
+
#include <string.h>
|
|
39
|
+
#if HAVE_STRINGLIST
|
|
40
|
+
#include <stringlist.h>
|
|
41
|
+
#else
|
|
42
|
+
#include "compat_stringlist.h"
|
|
43
|
+
#endif
|
|
44
|
+
#include <unistd.h>
|
|
45
|
+
|
|
46
|
+
#define C_OPTION 0x1
|
|
47
|
+
|
|
48
|
+
static StringList *includes;
|
|
49
|
+
|
|
50
|
+
static void
|
|
51
|
+
usage(void)
|
|
52
|
+
{
|
|
53
|
+
|
|
54
|
+
fprintf(stderr, "usage: soelim [-Crtv] [-I dir] [files]\n");
|
|
55
|
+
|
|
56
|
+
exit(EXIT_FAILURE);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static FILE *
|
|
60
|
+
soelim_fopen(const char *name)
|
|
61
|
+
{
|
|
62
|
+
FILE *f;
|
|
63
|
+
char path[PATH_MAX];
|
|
64
|
+
size_t i;
|
|
65
|
+
|
|
66
|
+
if (strcmp(name, "-") == 0)
|
|
67
|
+
return (stdin);
|
|
68
|
+
|
|
69
|
+
if ((f = fopen(name, "r")) != NULL)
|
|
70
|
+
return (f);
|
|
71
|
+
|
|
72
|
+
if (*name == '/') {
|
|
73
|
+
warn("can't open '%s'", name);
|
|
74
|
+
return (NULL);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (i = 0; i < includes->sl_cur; i++) {
|
|
78
|
+
snprintf(path, sizeof(path), "%s/%s", includes->sl_str[i],
|
|
79
|
+
name);
|
|
80
|
+
if ((f = fopen(path, "r")) != NULL)
|
|
81
|
+
return (f);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
warn("can't open '%s'", name);
|
|
85
|
+
|
|
86
|
+
return (f);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static int
|
|
90
|
+
soelim_file(FILE *f, int flag)
|
|
91
|
+
{
|
|
92
|
+
char *line = NULL;
|
|
93
|
+
char *walk, *cp;
|
|
94
|
+
size_t linecap = 0;
|
|
95
|
+
ssize_t linelen;
|
|
96
|
+
|
|
97
|
+
if (f == NULL)
|
|
98
|
+
return (1);
|
|
99
|
+
|
|
100
|
+
while ((linelen = getline(&line, &linecap, f)) > 0) {
|
|
101
|
+
if (strncmp(line, ".so", 3) != 0) {
|
|
102
|
+
printf("%s", line);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
walk = line + 3;
|
|
107
|
+
if (!isspace((unsigned char)*walk) && (flag & C_OPTION) == 0) {
|
|
108
|
+
printf("%s", line);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
while (isspace((unsigned char)*walk))
|
|
113
|
+
walk++;
|
|
114
|
+
|
|
115
|
+
cp = walk;
|
|
116
|
+
while (*cp != '\0' && !isspace((unsigned char)*cp))
|
|
117
|
+
cp++;
|
|
118
|
+
*cp = 0;
|
|
119
|
+
if (cp < line + linelen)
|
|
120
|
+
cp++;
|
|
121
|
+
|
|
122
|
+
if (*walk == '\0') {
|
|
123
|
+
printf("%s", line);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (soelim_file(soelim_fopen(walk), flag) == 1) {
|
|
127
|
+
free(line);
|
|
128
|
+
return (1);
|
|
129
|
+
}
|
|
130
|
+
if (*cp != '\0')
|
|
131
|
+
printf("%s", cp);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
free(line);
|
|
135
|
+
fclose(f);
|
|
136
|
+
|
|
137
|
+
return (0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
int
|
|
141
|
+
main(int argc, char **argv)
|
|
142
|
+
{
|
|
143
|
+
int ch, i;
|
|
144
|
+
int ret = 0;
|
|
145
|
+
int flags = 0;
|
|
146
|
+
|
|
147
|
+
includes = sl_init();
|
|
148
|
+
if (includes == NULL)
|
|
149
|
+
err(EXIT_FAILURE, "sl_init()");
|
|
150
|
+
|
|
151
|
+
while ((ch = getopt(argc, argv, "CrtvI:")) != -1) {
|
|
152
|
+
switch (ch) {
|
|
153
|
+
case 'C':
|
|
154
|
+
flags |= C_OPTION;
|
|
155
|
+
break;
|
|
156
|
+
case 'r':
|
|
157
|
+
case 'v':
|
|
158
|
+
case 't':
|
|
159
|
+
/* stub compatibility with groff's soelim */
|
|
160
|
+
break;
|
|
161
|
+
case 'I':
|
|
162
|
+
sl_add(includes, optarg);
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
sl_free(includes, 0);
|
|
166
|
+
usage();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
argc -= optind;
|
|
171
|
+
argv += optind;
|
|
172
|
+
|
|
173
|
+
if (argc == 0)
|
|
174
|
+
ret = soelim_file(stdin, flags);
|
|
175
|
+
|
|
176
|
+
for (i = 0; i < argc; i++)
|
|
177
|
+
ret = soelim_file(soelim_fopen(argv[i]), flags);
|
|
178
|
+
|
|
179
|
+
sl_free(includes, 0);
|
|
180
|
+
|
|
181
|
+
return (ret);
|
|
182
|
+
}
|