xref: /freebsd/contrib/mandoc/libmdoc.h (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1 /*	$Id: libmdoc.h,v 1.117 2018/12/31 04:55:46 schwarze Exp $ */
2 /*
3  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2013,2014,2015,2017,2018 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 struct	mdoc_arg;
22 
23 #define	MACRO_PROT_ARGS	struct roff_man *mdoc, \
24 			enum roff_tok tok, \
25 			int line, \
26 			int ppos, \
27 			int *pos, \
28 			char *buf
29 
30 struct	mdoc_macro {
31 	void		(*fp)(MACRO_PROT_ARGS);
32 	int		  flags;
33 #define	MDOC_CALLABLE	 (1 << 0)
34 #define	MDOC_PARSED	 (1 << 1)
35 #define	MDOC_EXPLICIT	 (1 << 2)
36 #define	MDOC_PROLOGUE	 (1 << 3)
37 #define	MDOC_IGNDELIM	 (1 << 4)
38 #define	MDOC_JOIN	 (1 << 5)
39 };
40 
41 enum	margserr {
42 	ARGS_ERROR,
43 	ARGS_EOLN, /* end-of-line */
44 	ARGS_WORD, /* normal word */
45 	ARGS_ALLOC, /* normal word from roff_getarg() */
46 	ARGS_PUNCT, /* series of punctuation */
47 	ARGS_PHRASE /* Bl -column phrase */
48 };
49 
50 /*
51  * A punctuation delimiter is opening, closing, or "middle mark"
52  * punctuation.  These govern spacing.
53  * Opening punctuation (e.g., the opening parenthesis) suppresses the
54  * following space; closing punctuation (e.g., the closing parenthesis)
55  * suppresses the leading space; middle punctuation (e.g., the vertical
56  * bar) can do either.  The middle punctuation delimiter bends the rules
57  * depending on usage.
58  */
59 enum	mdelim {
60 	DELIM_NONE = 0,
61 	DELIM_OPEN,
62 	DELIM_MIDDLE,
63 	DELIM_CLOSE,
64 	DELIM_MAX
65 };
66 
67 const struct mdoc_macro *mdoc_macro(enum roff_tok);
68 
69 void		  mdoc_elem_alloc(struct roff_man *, int, int,
70 			enum roff_tok, struct mdoc_arg *);
71 struct roff_node *mdoc_block_alloc(struct roff_man *, int, int,
72 			enum roff_tok, struct mdoc_arg *);
73 void		  mdoc_tail_alloc(struct roff_man *, int, int,
74 			enum roff_tok);
75 struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int,
76 			enum roff_tok, struct roff_node *);
77 void		  mdoc_state(struct roff_man *, struct roff_node *);
78 const char	 *mdoc_a2arch(const char *);
79 const char	 *mdoc_a2att(const char *);
80 const char	 *mdoc_a2lib(const char *);
81 enum roff_sec	  mdoc_a2sec(const char *);
82 const char	 *mdoc_a2st(const char *);
83 void		  mdoc_argv(struct roff_man *, int, enum roff_tok,
84 			struct mdoc_arg **, int *, char *);
85 enum margserr	  mdoc_args(struct roff_man *, int,
86 			int *, char *, enum roff_tok, char **);
87 enum mdelim	  mdoc_isdelim(const char *);
88