xref: /illumos-gate/usr/src/cmd/mandoc/libmdoc.h (revision cec8643b)
1*cec8643bSMichal Nowak /*	$Id: libmdoc.h,v 1.117 2018/12/31 04:55:46 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*cec8643bSMichal Nowak  * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
595c635efSGarrett D'Amore  *
695c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
795c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
895c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
995c635efSGarrett D'Amore  *
10371584c2SYuri Pankov  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12371584c2SYuri Pankov  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1395c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1495c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1595c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1695c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1795c635efSGarrett D'Amore  */
1895c635efSGarrett D'Amore 
19*cec8643bSMichal Nowak struct	roff_node;
20*cec8643bSMichal Nowak struct	roff_man;
21*cec8643bSMichal Nowak struct	mdoc_arg;
22*cec8643bSMichal Nowak 
23371584c2SYuri Pankov #define	MACRO_PROT_ARGS	struct roff_man *mdoc, \
24c66b8046SYuri Pankov 			enum roff_tok tok, \
2595c635efSGarrett D'Amore 			int line, \
2695c635efSGarrett D'Amore 			int ppos, \
2795c635efSGarrett D'Amore 			int *pos, \
2895c635efSGarrett D'Amore 			char *buf
2995c635efSGarrett D'Amore 
3095c635efSGarrett D'Amore struct	mdoc_macro {
31260e9a87SYuri Pankov 	void		(*fp)(MACRO_PROT_ARGS);
3295c635efSGarrett D'Amore 	int		  flags;
3395c635efSGarrett D'Amore #define	MDOC_CALLABLE	 (1 << 0)
3495c635efSGarrett D'Amore #define	MDOC_PARSED	 (1 << 1)
3595c635efSGarrett D'Amore #define	MDOC_EXPLICIT	 (1 << 2)
3695c635efSGarrett D'Amore #define	MDOC_PROLOGUE	 (1 << 3)
37698f87a4SGarrett D'Amore #define	MDOC_IGNDELIM	 (1 << 4)
38698f87a4SGarrett D'Amore #define	MDOC_JOIN	 (1 << 5)
3995c635efSGarrett D'Amore };
4095c635efSGarrett D'Amore 
4195c635efSGarrett D'Amore enum	margserr {
4295c635efSGarrett D'Amore 	ARGS_ERROR,
4395c635efSGarrett D'Amore 	ARGS_EOLN, /* end-of-line */
4495c635efSGarrett D'Amore 	ARGS_WORD, /* normal word */
45*cec8643bSMichal Nowak 	ARGS_ALLOC, /* normal word from roff_getarg() */
4695c635efSGarrett D'Amore 	ARGS_PUNCT, /* series of punctuation */
47371584c2SYuri Pankov 	ARGS_PHRASE /* Bl -column phrase */
4895c635efSGarrett D'Amore };
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore /*
5195c635efSGarrett D'Amore  * A punctuation delimiter is opening, closing, or "middle mark"
5295c635efSGarrett D'Amore  * punctuation.  These govern spacing.
5395c635efSGarrett D'Amore  * Opening punctuation (e.g., the opening parenthesis) suppresses the
5495c635efSGarrett D'Amore  * following space; closing punctuation (e.g., the closing parenthesis)
5595c635efSGarrett D'Amore  * suppresses the leading space; middle punctuation (e.g., the vertical
5695c635efSGarrett D'Amore  * bar) can do either.  The middle punctuation delimiter bends the rules
5795c635efSGarrett D'Amore  * depending on usage.
5895c635efSGarrett D'Amore  */
5995c635efSGarrett D'Amore enum	mdelim {
6095c635efSGarrett D'Amore 	DELIM_NONE = 0,
6195c635efSGarrett D'Amore 	DELIM_OPEN,
6295c635efSGarrett D'Amore 	DELIM_MIDDLE,
6395c635efSGarrett D'Amore 	DELIM_CLOSE,
6495c635efSGarrett D'Amore 	DELIM_MAX
6595c635efSGarrett D'Amore };
6695c635efSGarrett D'Amore 
67*cec8643bSMichal Nowak const struct mdoc_macro *mdoc_macro(enum roff_tok);
6895c635efSGarrett D'Amore 
69371584c2SYuri Pankov void		  mdoc_elem_alloc(struct roff_man *, int, int,
70c66b8046SYuri Pankov 			enum roff_tok, struct mdoc_arg *);
71371584c2SYuri Pankov struct roff_node *mdoc_block_alloc(struct roff_man *, int, int,
72c66b8046SYuri Pankov 			enum roff_tok, struct mdoc_arg *);
73c66b8046SYuri Pankov void		  mdoc_tail_alloc(struct roff_man *, int, int,
74c66b8046SYuri Pankov 			enum roff_tok);
75c66b8046SYuri Pankov struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int,
76c66b8046SYuri Pankov 			enum roff_tok, struct roff_node *);
77371584c2SYuri Pankov void		  mdoc_state(struct roff_man *, struct roff_node *);
78371584c2SYuri Pankov const char	 *mdoc_a2arch(const char *);
7995c635efSGarrett D'Amore const char	 *mdoc_a2att(const char *);
8095c635efSGarrett D'Amore const char	 *mdoc_a2lib(const char *);
81371584c2SYuri Pankov enum roff_sec	  mdoc_a2sec(const char *);
8295c635efSGarrett D'Amore const char	 *mdoc_a2st(const char *);
83c66b8046SYuri Pankov void		  mdoc_argv(struct roff_man *, int, enum roff_tok,
8495c635efSGarrett D'Amore 			struct mdoc_arg **, int *, char *);
85371584c2SYuri Pankov enum margserr	  mdoc_args(struct roff_man *, int,
86c66b8046SYuri Pankov 			int *, char *, enum roff_tok, char **);
8795c635efSGarrett D'Amore enum mdelim	  mdoc_isdelim(const char *);
88