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,118 @@
|
|
|
1
|
+
/* $Id: mansearch.h,v 1.30 2019/04/30 18:51:57 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2013, 2014, 2016, 2017 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
|
+
|
|
19
|
+
#define MANDOC_DB "mandoc.db"
|
|
20
|
+
#define MANDOCDB_MAGIC 0x3a7d0cdb
|
|
21
|
+
#define MANDOCDB_VERSION 1
|
|
22
|
+
|
|
23
|
+
#define MACRO_MAX 36
|
|
24
|
+
#define KEY_arch 0
|
|
25
|
+
#define KEY_sec 1
|
|
26
|
+
#define KEY_Nm 38
|
|
27
|
+
#define KEY_Nd 39
|
|
28
|
+
#define KEY_MAX 40
|
|
29
|
+
|
|
30
|
+
#define TYPE_arch 0x0000000000000001ULL
|
|
31
|
+
#define TYPE_sec 0x0000000000000002ULL
|
|
32
|
+
#define TYPE_Xr 0x0000000000000004ULL
|
|
33
|
+
#define TYPE_Ar 0x0000000000000008ULL
|
|
34
|
+
#define TYPE_Fa 0x0000000000000010ULL
|
|
35
|
+
#define TYPE_Fl 0x0000000000000020ULL
|
|
36
|
+
#define TYPE_Dv 0x0000000000000040ULL
|
|
37
|
+
#define TYPE_Fn 0x0000000000000080ULL
|
|
38
|
+
#define TYPE_Ic 0x0000000000000100ULL
|
|
39
|
+
#define TYPE_Pa 0x0000000000000200ULL
|
|
40
|
+
#define TYPE_Cm 0x0000000000000400ULL
|
|
41
|
+
#define TYPE_Li 0x0000000000000800ULL
|
|
42
|
+
#define TYPE_Em 0x0000000000001000ULL
|
|
43
|
+
#define TYPE_Cd 0x0000000000002000ULL
|
|
44
|
+
#define TYPE_Va 0x0000000000004000ULL
|
|
45
|
+
#define TYPE_Ft 0x0000000000008000ULL
|
|
46
|
+
#define TYPE_Tn 0x0000000000010000ULL
|
|
47
|
+
#define TYPE_Er 0x0000000000020000ULL
|
|
48
|
+
#define TYPE_Ev 0x0000000000040000ULL
|
|
49
|
+
#define TYPE_Sy 0x0000000000080000ULL
|
|
50
|
+
#define TYPE_Sh 0x0000000000100000ULL
|
|
51
|
+
#define TYPE_In 0x0000000000200000ULL
|
|
52
|
+
#define TYPE_Ss 0x0000000000400000ULL
|
|
53
|
+
#define TYPE_Ox 0x0000000000800000ULL
|
|
54
|
+
#define TYPE_An 0x0000000001000000ULL
|
|
55
|
+
#define TYPE_Mt 0x0000000002000000ULL
|
|
56
|
+
#define TYPE_St 0x0000000004000000ULL
|
|
57
|
+
#define TYPE_Bx 0x0000000008000000ULL
|
|
58
|
+
#define TYPE_At 0x0000000010000000ULL
|
|
59
|
+
#define TYPE_Nx 0x0000000020000000ULL
|
|
60
|
+
#define TYPE_Fx 0x0000000040000000ULL
|
|
61
|
+
#define TYPE_Lk 0x0000000080000000ULL
|
|
62
|
+
#define TYPE_Ms 0x0000000100000000ULL
|
|
63
|
+
#define TYPE_Bsx 0x0000000200000000ULL
|
|
64
|
+
#define TYPE_Dx 0x0000000400000000ULL
|
|
65
|
+
#define TYPE_Rs 0x0000000800000000ULL
|
|
66
|
+
#define TYPE_Vt 0x0000001000000000ULL
|
|
67
|
+
#define TYPE_Lb 0x0000002000000000ULL
|
|
68
|
+
#define TYPE_Nm 0x0000004000000000ULL
|
|
69
|
+
#define TYPE_Nd 0x0000008000000000ULL
|
|
70
|
+
|
|
71
|
+
#define NAME_SYN 0x0000004000000001ULL
|
|
72
|
+
#define NAME_FIRST 0x0000004000000004ULL
|
|
73
|
+
#define NAME_TITLE 0x0000004000000006ULL
|
|
74
|
+
#define NAME_HEAD 0x0000004000000008ULL
|
|
75
|
+
#define NAME_FILE 0x0000004000000010ULL
|
|
76
|
+
#define NAME_MASK 0x000000000000001fULL
|
|
77
|
+
|
|
78
|
+
enum form {
|
|
79
|
+
FORM_SRC = 1, /* Format is mdoc(7) or man(7). */
|
|
80
|
+
FORM_CAT, /* Manual page is preformatted. */
|
|
81
|
+
FORM_NONE /* Format is unknown. */
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
enum argmode {
|
|
85
|
+
ARG_FILE = 0,
|
|
86
|
+
ARG_NAME,
|
|
87
|
+
ARG_WORD,
|
|
88
|
+
ARG_EXPR
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
struct manpage {
|
|
92
|
+
char *file; /* to be prefixed by manpath */
|
|
93
|
+
char *names; /* a list of names with sections */
|
|
94
|
+
char *output; /* user-defined additional output */
|
|
95
|
+
uint64_t bits; /* name type mask */
|
|
96
|
+
size_t ipath; /* number of the manpath */
|
|
97
|
+
int sec; /* section number, 10 means invalid */
|
|
98
|
+
enum form form;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
struct mansearch {
|
|
102
|
+
const char *arch; /* architecture/NULL */
|
|
103
|
+
const char *sec; /* mansection/NULL */
|
|
104
|
+
const char *outkey; /* show content of this macro */
|
|
105
|
+
enum argmode argmode; /* interpretation of arguments */
|
|
106
|
+
int firstmatch; /* first matching database only */
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
struct manpaths;
|
|
111
|
+
|
|
112
|
+
int mansearch(const struct mansearch *cfg, /* options */
|
|
113
|
+
const struct manpaths *paths, /* manpaths */
|
|
114
|
+
int argc, /* size of argv */
|
|
115
|
+
char *argv[], /* search terms */
|
|
116
|
+
struct manpage **res, /* results */
|
|
117
|
+
size_t *ressz); /* results returned */
|
|
118
|
+
void mansearch_free(struct manpage *, size_t);
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/* $Id: mdoc.c,v 1.275 2020/04/06 10:16:17 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2010, 2012-2018, 2020 Ingo Schwarze <schwarze@openbsd.org>
|
|
4
|
+
* Copyright (c) 2008, 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
|
+
* Top level and utility functions of the mdoc(7) parser for mandoc(1).
|
|
19
|
+
*/
|
|
20
|
+
#include "config.h"
|
|
21
|
+
|
|
22
|
+
#include <sys/types.h>
|
|
23
|
+
|
|
24
|
+
#include <assert.h>
|
|
25
|
+
#include <ctype.h>
|
|
26
|
+
#include <stdarg.h>
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <string.h>
|
|
30
|
+
#include <time.h>
|
|
31
|
+
|
|
32
|
+
#include "mandoc_aux.h"
|
|
33
|
+
#include "mandoc.h"
|
|
34
|
+
#include "roff.h"
|
|
35
|
+
#include "mdoc.h"
|
|
36
|
+
#include "libmandoc.h"
|
|
37
|
+
#include "roff_int.h"
|
|
38
|
+
#include "libmdoc.h"
|
|
39
|
+
|
|
40
|
+
const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
|
|
41
|
+
"split", "nosplit", "ragged",
|
|
42
|
+
"unfilled", "literal", "file",
|
|
43
|
+
"offset", "bullet", "dash",
|
|
44
|
+
"hyphen", "item", "enum",
|
|
45
|
+
"tag", "diag", "hang",
|
|
46
|
+
"ohang", "inset", "column",
|
|
47
|
+
"width", "compact", "std",
|
|
48
|
+
"filled", "words", "emphasis",
|
|
49
|
+
"symbolic", "nested", "centered"
|
|
50
|
+
};
|
|
51
|
+
const char * const *mdoc_argnames = __mdoc_argnames;
|
|
52
|
+
|
|
53
|
+
static int mdoc_ptext(struct roff_man *, int, char *, int);
|
|
54
|
+
static int mdoc_pmacro(struct roff_man *, int, char *, int);
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/*
|
|
58
|
+
* Main parse routine. Parses a single line -- really just hands off to
|
|
59
|
+
* the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
|
|
60
|
+
*/
|
|
61
|
+
int
|
|
62
|
+
mdoc_parseln(struct roff_man *mdoc, int ln, char *buf, int offs)
|
|
63
|
+
{
|
|
64
|
+
|
|
65
|
+
if (mdoc->last->type != ROFFT_EQN || ln > mdoc->last->line)
|
|
66
|
+
mdoc->flags |= MDOC_NEWLINE;
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* Let the roff nS register switch SYNOPSIS mode early,
|
|
70
|
+
* such that the parser knows at all times
|
|
71
|
+
* whether this mode is on or off.
|
|
72
|
+
* Note that this mode is also switched by the Sh macro.
|
|
73
|
+
*/
|
|
74
|
+
if (roff_getreg(mdoc->roff, "nS"))
|
|
75
|
+
mdoc->flags |= MDOC_SYNOPSIS;
|
|
76
|
+
else
|
|
77
|
+
mdoc->flags &= ~MDOC_SYNOPSIS;
|
|
78
|
+
|
|
79
|
+
return roff_getcontrol(mdoc->roff, buf, &offs) ?
|
|
80
|
+
mdoc_pmacro(mdoc, ln, buf, offs) :
|
|
81
|
+
mdoc_ptext(mdoc, ln, buf, offs);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void
|
|
85
|
+
mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, enum roff_tok tok)
|
|
86
|
+
{
|
|
87
|
+
struct roff_node *p;
|
|
88
|
+
|
|
89
|
+
p = roff_node_alloc(mdoc, line, pos, ROFFT_TAIL, tok);
|
|
90
|
+
roff_node_append(mdoc, p);
|
|
91
|
+
mdoc->next = ROFF_NEXT_CHILD;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
struct roff_node *
|
|
95
|
+
mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos,
|
|
96
|
+
enum roff_tok tok, struct roff_node *body)
|
|
97
|
+
{
|
|
98
|
+
struct roff_node *p;
|
|
99
|
+
|
|
100
|
+
body->flags |= NODE_ENDED;
|
|
101
|
+
body->parent->flags |= NODE_ENDED;
|
|
102
|
+
p = roff_node_alloc(mdoc, line, pos, ROFFT_BODY, tok);
|
|
103
|
+
p->body = body;
|
|
104
|
+
p->norm = body->norm;
|
|
105
|
+
p->end = ENDBODY_SPACE;
|
|
106
|
+
roff_node_append(mdoc, p);
|
|
107
|
+
mdoc->next = ROFF_NEXT_SIBLING;
|
|
108
|
+
return p;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
struct roff_node *
|
|
112
|
+
mdoc_block_alloc(struct roff_man *mdoc, int line, int pos,
|
|
113
|
+
enum roff_tok tok, struct mdoc_arg *args)
|
|
114
|
+
{
|
|
115
|
+
struct roff_node *p;
|
|
116
|
+
|
|
117
|
+
p = roff_node_alloc(mdoc, line, pos, ROFFT_BLOCK, tok);
|
|
118
|
+
p->args = args;
|
|
119
|
+
if (p->args)
|
|
120
|
+
(args->refcnt)++;
|
|
121
|
+
|
|
122
|
+
switch (tok) {
|
|
123
|
+
case MDOC_Bd:
|
|
124
|
+
case MDOC_Bf:
|
|
125
|
+
case MDOC_Bl:
|
|
126
|
+
case MDOC_En:
|
|
127
|
+
case MDOC_Rs:
|
|
128
|
+
p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
roff_node_append(mdoc, p);
|
|
134
|
+
mdoc->next = ROFF_NEXT_CHILD;
|
|
135
|
+
return p;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void
|
|
139
|
+
mdoc_elem_alloc(struct roff_man *mdoc, int line, int pos,
|
|
140
|
+
enum roff_tok tok, struct mdoc_arg *args)
|
|
141
|
+
{
|
|
142
|
+
struct roff_node *p;
|
|
143
|
+
|
|
144
|
+
p = roff_node_alloc(mdoc, line, pos, ROFFT_ELEM, tok);
|
|
145
|
+
p->args = args;
|
|
146
|
+
if (p->args)
|
|
147
|
+
(args->refcnt)++;
|
|
148
|
+
|
|
149
|
+
switch (tok) {
|
|
150
|
+
case MDOC_An:
|
|
151
|
+
p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
roff_node_append(mdoc, p);
|
|
157
|
+
mdoc->next = ROFF_NEXT_CHILD;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* Parse free-form text, that is, a line that does not begin with the
|
|
162
|
+
* control character.
|
|
163
|
+
*/
|
|
164
|
+
static int
|
|
165
|
+
mdoc_ptext(struct roff_man *mdoc, int line, char *buf, int offs)
|
|
166
|
+
{
|
|
167
|
+
struct roff_node *n;
|
|
168
|
+
const char *cp, *sp;
|
|
169
|
+
char *c, *ws, *end;
|
|
170
|
+
|
|
171
|
+
n = mdoc->last;
|
|
172
|
+
|
|
173
|
+
/*
|
|
174
|
+
* If a column list contains plain text, assume an implicit item
|
|
175
|
+
* macro. This can happen one or more times at the beginning
|
|
176
|
+
* of such a list, intermixed with non-It mdoc macros and with
|
|
177
|
+
* nodes generated on the roff level, for example by tbl.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY &&
|
|
181
|
+
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) ||
|
|
182
|
+
(n->parent != NULL && n->parent->tok == MDOC_Bl &&
|
|
183
|
+
n->parent->norm->Bl.type == LIST_column)) {
|
|
184
|
+
mdoc->flags |= MDOC_FREECOL;
|
|
185
|
+
(*mdoc_macro(MDOC_It)->fp)(mdoc, MDOC_It,
|
|
186
|
+
line, offs, &offs, buf);
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/*
|
|
191
|
+
* Search for the beginning of unescaped trailing whitespace (ws)
|
|
192
|
+
* and for the first character not to be output (end).
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
/* FIXME: replace with strcspn(). */
|
|
196
|
+
ws = NULL;
|
|
197
|
+
for (c = end = buf + offs; *c; c++) {
|
|
198
|
+
switch (*c) {
|
|
199
|
+
case ' ':
|
|
200
|
+
if (NULL == ws)
|
|
201
|
+
ws = c;
|
|
202
|
+
continue;
|
|
203
|
+
case '\t':
|
|
204
|
+
/*
|
|
205
|
+
* Always warn about trailing tabs,
|
|
206
|
+
* even outside literal context,
|
|
207
|
+
* where they should be put on the next line.
|
|
208
|
+
*/
|
|
209
|
+
if (NULL == ws)
|
|
210
|
+
ws = c;
|
|
211
|
+
/*
|
|
212
|
+
* Strip trailing tabs in literal context only;
|
|
213
|
+
* outside, they affect the next line.
|
|
214
|
+
*/
|
|
215
|
+
if (mdoc->flags & ROFF_NOFILL)
|
|
216
|
+
continue;
|
|
217
|
+
break;
|
|
218
|
+
case '\\':
|
|
219
|
+
/* Skip the escaped character, too, if any. */
|
|
220
|
+
if (c[1])
|
|
221
|
+
c++;
|
|
222
|
+
/* FALLTHROUGH */
|
|
223
|
+
default:
|
|
224
|
+
ws = NULL;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
end = c + 1;
|
|
228
|
+
}
|
|
229
|
+
*end = '\0';
|
|
230
|
+
|
|
231
|
+
if (ws)
|
|
232
|
+
mandoc_msg(MANDOCERR_SPACE_EOL, line, (int)(ws - buf), NULL);
|
|
233
|
+
|
|
234
|
+
/*
|
|
235
|
+
* Blank lines are allowed in no-fill mode
|
|
236
|
+
* and cancel preceding \c,
|
|
237
|
+
* but add a single vertical space elsewhere.
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
if (buf[offs] == '\0' && (mdoc->flags & ROFF_NOFILL) == 0) {
|
|
241
|
+
switch (mdoc->last->type) {
|
|
242
|
+
case ROFFT_TEXT:
|
|
243
|
+
sp = mdoc->last->string;
|
|
244
|
+
cp = end = strchr(sp, '\0') - 2;
|
|
245
|
+
if (cp < sp || cp[0] != '\\' || cp[1] != 'c')
|
|
246
|
+
break;
|
|
247
|
+
while (cp > sp && cp[-1] == '\\')
|
|
248
|
+
cp--;
|
|
249
|
+
if ((end - cp) % 2)
|
|
250
|
+
break;
|
|
251
|
+
*end = '\0';
|
|
252
|
+
return 1;
|
|
253
|
+
default:
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
mandoc_msg(MANDOCERR_FI_BLANK, line, (int)(c - buf), NULL);
|
|
257
|
+
roff_elem_alloc(mdoc, line, offs, ROFF_sp);
|
|
258
|
+
mdoc->last->flags |= NODE_VALID | NODE_ENDED;
|
|
259
|
+
mdoc->next = ROFF_NEXT_SIBLING;
|
|
260
|
+
return 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
roff_word_alloc(mdoc, line, offs, buf+offs);
|
|
264
|
+
|
|
265
|
+
if (mdoc->flags & ROFF_NOFILL)
|
|
266
|
+
return 1;
|
|
267
|
+
|
|
268
|
+
/*
|
|
269
|
+
* End-of-sentence check. If the last character is an unescaped
|
|
270
|
+
* EOS character, then flag the node as being the end of a
|
|
271
|
+
* sentence. The front-end will know how to interpret this.
|
|
272
|
+
*/
|
|
273
|
+
|
|
274
|
+
assert(buf < end);
|
|
275
|
+
|
|
276
|
+
if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
|
|
277
|
+
mdoc->last->flags |= NODE_EOS;
|
|
278
|
+
|
|
279
|
+
for (c = buf + offs; c != NULL; c = strchr(c + 1, '.')) {
|
|
280
|
+
if (c - buf < offs + 2)
|
|
281
|
+
continue;
|
|
282
|
+
if (end - c < 3)
|
|
283
|
+
break;
|
|
284
|
+
if (c[1] != ' ' ||
|
|
285
|
+
isalnum((unsigned char)c[-2]) == 0 ||
|
|
286
|
+
isalnum((unsigned char)c[-1]) == 0 ||
|
|
287
|
+
(c[-2] == 'n' && c[-1] == 'c') ||
|
|
288
|
+
(c[-2] == 'v' && c[-1] == 's'))
|
|
289
|
+
continue;
|
|
290
|
+
c += 2;
|
|
291
|
+
if (*c == ' ')
|
|
292
|
+
c++;
|
|
293
|
+
if (*c == ' ')
|
|
294
|
+
c++;
|
|
295
|
+
if (isupper((unsigned char)(*c)))
|
|
296
|
+
mandoc_msg(MANDOCERR_EOS, line, (int)(c - buf), NULL);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return 1;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/*
|
|
303
|
+
* Parse a macro line, that is, a line beginning with the control
|
|
304
|
+
* character.
|
|
305
|
+
*/
|
|
306
|
+
static int
|
|
307
|
+
mdoc_pmacro(struct roff_man *mdoc, int ln, char *buf, int offs)
|
|
308
|
+
{
|
|
309
|
+
struct roff_node *n;
|
|
310
|
+
const char *cp;
|
|
311
|
+
size_t sz;
|
|
312
|
+
enum roff_tok tok;
|
|
313
|
+
int sv;
|
|
314
|
+
|
|
315
|
+
/* Determine the line macro. */
|
|
316
|
+
|
|
317
|
+
sv = offs;
|
|
318
|
+
tok = TOKEN_NONE;
|
|
319
|
+
for (sz = 0; sz < 4 && strchr(" \t\\", buf[offs]) == NULL; sz++)
|
|
320
|
+
offs++;
|
|
321
|
+
if (sz == 2 || sz == 3)
|
|
322
|
+
tok = roffhash_find(mdoc->mdocmac, buf + sv, sz);
|
|
323
|
+
if (tok == TOKEN_NONE) {
|
|
324
|
+
mandoc_msg(MANDOCERR_MACRO, ln, sv, "%s", buf + sv - 1);
|
|
325
|
+
return 1;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* Skip a leading escape sequence or tab. */
|
|
329
|
+
|
|
330
|
+
switch (buf[offs]) {
|
|
331
|
+
case '\\':
|
|
332
|
+
cp = buf + offs + 1;
|
|
333
|
+
mandoc_escape(&cp, NULL, NULL);
|
|
334
|
+
offs = cp - buf;
|
|
335
|
+
break;
|
|
336
|
+
case '\t':
|
|
337
|
+
offs++;
|
|
338
|
+
break;
|
|
339
|
+
default:
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* Jump to the next non-whitespace word. */
|
|
344
|
+
|
|
345
|
+
while (buf[offs] == ' ')
|
|
346
|
+
offs++;
|
|
347
|
+
|
|
348
|
+
/*
|
|
349
|
+
* Trailing whitespace. Note that tabs are allowed to be passed
|
|
350
|
+
* into the parser as "text", so we only warn about spaces here.
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
if ('\0' == buf[offs] && ' ' == buf[offs - 1])
|
|
354
|
+
mandoc_msg(MANDOCERR_SPACE_EOL, ln, offs - 1, NULL);
|
|
355
|
+
|
|
356
|
+
/*
|
|
357
|
+
* If an initial or transparent macro or a list invocation,
|
|
358
|
+
* divert directly into macro processing.
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
n = mdoc->last;
|
|
362
|
+
if (n == NULL || tok == MDOC_It || tok == MDOC_El ||
|
|
363
|
+
roff_tok_transparent(tok)) {
|
|
364
|
+
(*mdoc_macro(tok)->fp)(mdoc, tok, ln, sv, &offs, buf);
|
|
365
|
+
return 1;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/*
|
|
369
|
+
* If a column list contains a non-It macro, assume an implicit
|
|
370
|
+
* item macro. This can happen one or more times at the
|
|
371
|
+
* beginning of such a list, intermixed with text lines and
|
|
372
|
+
* with nodes generated on the roff level, for example by tbl.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
if ((n->tok == MDOC_Bl && n->type == ROFFT_BODY &&
|
|
376
|
+
n->end == ENDBODY_NOT && n->norm->Bl.type == LIST_column) ||
|
|
377
|
+
(n->parent != NULL && n->parent->tok == MDOC_Bl &&
|
|
378
|
+
n->parent->norm->Bl.type == LIST_column)) {
|
|
379
|
+
mdoc->flags |= MDOC_FREECOL;
|
|
380
|
+
(*mdoc_macro(MDOC_It)->fp)(mdoc, MDOC_It, ln, sv, &sv, buf);
|
|
381
|
+
return 1;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/* Normal processing of a macro. */
|
|
385
|
+
|
|
386
|
+
(*mdoc_macro(tok)->fp)(mdoc, tok, ln, sv, &offs, buf);
|
|
387
|
+
|
|
388
|
+
/* In quick mode (for mandocdb), abort after the NAME section. */
|
|
389
|
+
|
|
390
|
+
if (mdoc->quick && MDOC_Sh == tok &&
|
|
391
|
+
SEC_NAME != mdoc->last->sec)
|
|
392
|
+
return 2;
|
|
393
|
+
|
|
394
|
+
return 1;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
enum mdelim
|
|
398
|
+
mdoc_isdelim(const char *p)
|
|
399
|
+
{
|
|
400
|
+
|
|
401
|
+
if ('\0' == p[0])
|
|
402
|
+
return DELIM_NONE;
|
|
403
|
+
|
|
404
|
+
if ('\0' == p[1])
|
|
405
|
+
switch (p[0]) {
|
|
406
|
+
case '(':
|
|
407
|
+
case '[':
|
|
408
|
+
return DELIM_OPEN;
|
|
409
|
+
case '|':
|
|
410
|
+
return DELIM_MIDDLE;
|
|
411
|
+
case '.':
|
|
412
|
+
case ',':
|
|
413
|
+
case ';':
|
|
414
|
+
case ':':
|
|
415
|
+
case '?':
|
|
416
|
+
case '!':
|
|
417
|
+
case ')':
|
|
418
|
+
case ']':
|
|
419
|
+
return DELIM_CLOSE;
|
|
420
|
+
default:
|
|
421
|
+
return DELIM_NONE;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if ('\\' != p[0])
|
|
425
|
+
return DELIM_NONE;
|
|
426
|
+
|
|
427
|
+
if (0 == strcmp(p + 1, "."))
|
|
428
|
+
return DELIM_CLOSE;
|
|
429
|
+
if (0 == strcmp(p + 1, "fR|\\fP"))
|
|
430
|
+
return DELIM_MIDDLE;
|
|
431
|
+
|
|
432
|
+
return DELIM_NONE;
|
|
433
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* $Id: mdoc.h,v 1.146 2018/12/30 00:49:55 schwarze Exp $ */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
4
|
+
* Copyright (c) 2014, 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 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
|
+
|
|
19
|
+
struct roff_node;
|
|
20
|
+
struct roff_man;
|
|
21
|
+
|
|
22
|
+
enum mdocargt {
|
|
23
|
+
MDOC_Split, /* -split */
|
|
24
|
+
MDOC_Nosplit, /* -nospli */
|
|
25
|
+
MDOC_Ragged, /* -ragged */
|
|
26
|
+
MDOC_Unfilled, /* -unfilled */
|
|
27
|
+
MDOC_Literal, /* -literal */
|
|
28
|
+
MDOC_File, /* -file */
|
|
29
|
+
MDOC_Offset, /* -offset */
|
|
30
|
+
MDOC_Bullet, /* -bullet */
|
|
31
|
+
MDOC_Dash, /* -dash */
|
|
32
|
+
MDOC_Hyphen, /* -hyphen */
|
|
33
|
+
MDOC_Item, /* -item */
|
|
34
|
+
MDOC_Enum, /* -enum */
|
|
35
|
+
MDOC_Tag, /* -tag */
|
|
36
|
+
MDOC_Diag, /* -diag */
|
|
37
|
+
MDOC_Hang, /* -hang */
|
|
38
|
+
MDOC_Ohang, /* -ohang */
|
|
39
|
+
MDOC_Inset, /* -inset */
|
|
40
|
+
MDOC_Column, /* -column */
|
|
41
|
+
MDOC_Width, /* -width */
|
|
42
|
+
MDOC_Compact, /* -compact */
|
|
43
|
+
MDOC_Std, /* -std */
|
|
44
|
+
MDOC_Filled, /* -filled */
|
|
45
|
+
MDOC_Words, /* -words */
|
|
46
|
+
MDOC_Emphasis, /* -emphasis */
|
|
47
|
+
MDOC_Symbolic, /* -symbolic */
|
|
48
|
+
MDOC_Nested, /* -nested */
|
|
49
|
+
MDOC_Centred, /* -centered */
|
|
50
|
+
MDOC_ARG_MAX
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* An argument to a macro (multiple values = `-column xxx yyy').
|
|
55
|
+
*/
|
|
56
|
+
struct mdoc_argv {
|
|
57
|
+
enum mdocargt arg; /* type of argument */
|
|
58
|
+
int line;
|
|
59
|
+
int pos;
|
|
60
|
+
size_t sz; /* elements in "value" */
|
|
61
|
+
char **value; /* argument strings */
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* Reference-counted macro arguments. These are refcounted because
|
|
66
|
+
* blocks have multiple instances of the same arguments spread across
|
|
67
|
+
* the HEAD, BODY, TAIL, and BLOCK node types.
|
|
68
|
+
*/
|
|
69
|
+
struct mdoc_arg {
|
|
70
|
+
size_t argc;
|
|
71
|
+
struct mdoc_argv *argv;
|
|
72
|
+
unsigned int refcnt;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
enum mdoc_list {
|
|
76
|
+
LIST__NONE = 0,
|
|
77
|
+
LIST_bullet, /* -bullet */
|
|
78
|
+
LIST_column, /* -column */
|
|
79
|
+
LIST_dash, /* -dash */
|
|
80
|
+
LIST_diag, /* -diag */
|
|
81
|
+
LIST_enum, /* -enum */
|
|
82
|
+
LIST_hang, /* -hang */
|
|
83
|
+
LIST_hyphen, /* -hyphen */
|
|
84
|
+
LIST_inset, /* -inset */
|
|
85
|
+
LIST_item, /* -item */
|
|
86
|
+
LIST_ohang, /* -ohang */
|
|
87
|
+
LIST_tag, /* -tag */
|
|
88
|
+
LIST_MAX
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
enum mdoc_disp {
|
|
92
|
+
DISP__NONE = 0,
|
|
93
|
+
DISP_centered, /* -centered */
|
|
94
|
+
DISP_ragged, /* -ragged */
|
|
95
|
+
DISP_unfilled, /* -unfilled */
|
|
96
|
+
DISP_filled, /* -filled */
|
|
97
|
+
DISP_literal /* -literal */
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
enum mdoc_auth {
|
|
101
|
+
AUTH__NONE = 0,
|
|
102
|
+
AUTH_split, /* -split */
|
|
103
|
+
AUTH_nosplit /* -nosplit */
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
enum mdoc_font {
|
|
107
|
+
FONT__NONE = 0,
|
|
108
|
+
FONT_Em, /* Em, -emphasis */
|
|
109
|
+
FONT_Li, /* Li, -literal */
|
|
110
|
+
FONT_Sy /* Sy, -symbolic */
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
struct mdoc_bd {
|
|
114
|
+
const char *offs; /* -offset */
|
|
115
|
+
enum mdoc_disp type; /* -ragged, etc. */
|
|
116
|
+
int comp; /* -compact */
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
struct mdoc_bl {
|
|
120
|
+
const char *width; /* -width */
|
|
121
|
+
const char *offs; /* -offset */
|
|
122
|
+
enum mdoc_list type; /* -tag, -enum, etc. */
|
|
123
|
+
int comp; /* -compact */
|
|
124
|
+
size_t ncols; /* -column arg count */
|
|
125
|
+
const char **cols; /* -column val ptr */
|
|
126
|
+
int count; /* -enum counter */
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
struct mdoc_bf {
|
|
130
|
+
enum mdoc_font font; /* font */
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
struct mdoc_an {
|
|
134
|
+
enum mdoc_auth auth; /* -split, etc. */
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
struct mdoc_rs {
|
|
138
|
+
int quote_T; /* whether to quote %T */
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* Consists of normalised node arguments. These should be used instead
|
|
143
|
+
* of iterating through the mdoc_arg pointers of a node: defaults are
|
|
144
|
+
* provided, etc.
|
|
145
|
+
*/
|
|
146
|
+
union mdoc_data {
|
|
147
|
+
struct mdoc_an An;
|
|
148
|
+
struct mdoc_bd Bd;
|
|
149
|
+
struct mdoc_bf Bf;
|
|
150
|
+
struct mdoc_bl Bl;
|
|
151
|
+
struct roff_node *Es;
|
|
152
|
+
struct mdoc_rs Rs;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/* Names of macro args. Index is enum mdocargt. */
|
|
156
|
+
extern const char *const *mdoc_argnames;
|
|
157
|
+
|
|
158
|
+
void mdoc_validate(struct roff_man *);
|