xref: /illumos-gate/usr/src/cmd/mandoc/libmandoc.h (revision 4d131170e62381276a07ffc0aeb1b62e527d940c)
1*4d131170SRobert Mustacchi /* $Id: libmandoc.h,v 1.80 2021/06/27 17:57:54 schwarze Exp $ */
295c635efSGarrett D'Amore /*
3*4d131170SRobert Mustacchi  * Copyright (c) 2013-2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org>
4698f87a4SGarrett D'Amore  * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
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.
17*4d131170SRobert Mustacchi  *
18*4d131170SRobert Mustacchi  * Internal interfaces for parser utilities needed by multiple parsers
19*4d131170SRobert Mustacchi  * and the top-level functions to call the mdoc, man, and roff parsers.
2095c635efSGarrett D'Amore  */
2195c635efSGarrett D'Amore 
22cec8643bSMichal Nowak /*
23cec8643bSMichal Nowak  * Return codes passed from the roff parser to the main parser.
24cec8643bSMichal Nowak  */
25cec8643bSMichal Nowak 
26cec8643bSMichal Nowak /* Main instruction: what to do with the returned line. */
27cec8643bSMichal Nowak #define	ROFF_IGN	0x000	/* Don't do anything with it. */
28cec8643bSMichal Nowak #define	ROFF_CONT	0x001	/* Give it to the high-level parser. */
29cec8643bSMichal Nowak #define	ROFF_RERUN	0x002	/* Re-run the roff parser with an offset. */
30cec8643bSMichal Nowak #define	ROFF_REPARSE	0x004	/* Recursively run the main parser on it. */
31cec8643bSMichal Nowak #define	ROFF_SO		0x008	/* Include the named file. */
32cec8643bSMichal Nowak #define	ROFF_MASK	0x00f	/* Only one of these bits should be set. */
33cec8643bSMichal Nowak 
34cec8643bSMichal Nowak /* Options for further parsing, to be OR'ed with the above. */
35cec8643bSMichal Nowak #define	ROFF_APPEND	0x010	/* Append the next line to this one. */
36cec8643bSMichal Nowak #define	ROFF_USERCALL	0x020	/* Start execution of a new macro. */
37cec8643bSMichal Nowak #define	ROFF_USERRET	0x040	/* Abort execution of the current macro. */
38cec8643bSMichal Nowak #define	ROFF_WHILE	0x100	/* Start a new .while loop. */
39cec8643bSMichal Nowak #define	ROFF_LOOPCONT	0x200	/* Iterate the current .while loop. */
40cec8643bSMichal Nowak #define	ROFF_LOOPEXIT	0x400	/* Exit the current .while loop. */
41cec8643bSMichal Nowak #define	ROFF_LOOPMASK	0xf00
42cec8643bSMichal Nowak 
43260e9a87SYuri Pankov 
44260e9a87SYuri Pankov struct	buf {
45260e9a87SYuri Pankov 	char		*buf;
46260e9a87SYuri Pankov 	size_t		 sz;
47cec8643bSMichal Nowak 	struct buf	*next;
4895c635efSGarrett D'Amore };
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore 
5195c635efSGarrett D'Amore struct	roff;
52371584c2SYuri Pankov struct	roff_man;
53*4d131170SRobert Mustacchi struct	roff_node;
5495c635efSGarrett D'Amore 
55*4d131170SRobert Mustacchi char		*mandoc_normdate(struct roff_node *, struct roff_node *);
56260e9a87SYuri Pankov int		 mandoc_eos(const char *, size_t);
5795c635efSGarrett D'Amore int		 mandoc_strntoi(const char *, size_t, int);
5895c635efSGarrett D'Amore const char	*mandoc_a2msec(const char*);
5995c635efSGarrett D'Amore 
60371584c2SYuri Pankov int		 mdoc_parseln(struct roff_man *, int, char *, int);
61371584c2SYuri Pankov void		 mdoc_endparse(struct roff_man *);
6295c635efSGarrett D'Amore 
63371584c2SYuri Pankov int		 man_parseln(struct roff_man *, int, char *, int);
64371584c2SYuri Pankov void		 man_endparse(struct roff_man *);
65260e9a87SYuri Pankov 
66260e9a87SYuri Pankov int		 preconv_cue(const struct buf *, size_t);
67a40ea1a7SYuri Pankov int		 preconv_encode(const struct buf *, size_t *,
68260e9a87SYuri Pankov 			struct buf *, size_t *, int *);
6995c635efSGarrett D'Amore 
7095c635efSGarrett D'Amore void		 roff_free(struct roff *);
71cec8643bSMichal Nowak struct roff	*roff_alloc(int);
7295c635efSGarrett D'Amore void		 roff_reset(struct roff *);
73371584c2SYuri Pankov void		 roff_man_free(struct roff_man *);
74cec8643bSMichal Nowak struct roff_man	*roff_man_alloc(struct roff *, const char *, int);
75371584c2SYuri Pankov void		 roff_man_reset(struct roff_man *);
76*4d131170SRobert Mustacchi int		 roff_parseln(struct roff *, int, struct buf *, int *, size_t);
77cec8643bSMichal Nowak void		 roff_userret(struct roff *);
7895c635efSGarrett D'Amore void		 roff_endparse(struct roff *);
79*4d131170SRobert Mustacchi void		 roff_setreg(struct roff *, const char *, int, char);
806640c13bSYuri Pankov int		 roff_getreg(struct roff *, const char *);
8195c635efSGarrett D'Amore char		*roff_strdup(const struct roff *, const char *);
82cec8643bSMichal Nowak char		*roff_getarg(struct roff *, char **, int, int *);
83698f87a4SGarrett D'Amore int		 roff_getcontrol(const struct roff *,
84698f87a4SGarrett D'Amore 			const char *, int *);
85260e9a87SYuri Pankov int		 roff_getformat(const struct roff *);
86