xref: /freebsd/contrib/mandoc/libmandoc.h (revision 6d38604fc532a3fc060788e3ce40464b46047eaf)
1*6d38604fSBaptiste Daroussin /* $Id: libmandoc.h,v 1.80 2021/06/27 17:57:54 schwarze Exp $ */
261d06d6bSBaptiste Daroussin /*
3*6d38604fSBaptiste Daroussin  * Copyright (c) 2013-2015,2017,2018,2020 Ingo Schwarze <schwarze@openbsd.org>
461d06d6bSBaptiste Daroussin  * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
561d06d6bSBaptiste Daroussin  *
661d06d6bSBaptiste Daroussin  * Permission to use, copy, modify, and distribute this software for any
761d06d6bSBaptiste Daroussin  * purpose with or without fee is hereby granted, provided that the above
861d06d6bSBaptiste Daroussin  * copyright notice and this permission notice appear in all copies.
961d06d6bSBaptiste Daroussin  *
1061d06d6bSBaptiste Daroussin  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1161d06d6bSBaptiste Daroussin  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1261d06d6bSBaptiste Daroussin  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1361d06d6bSBaptiste Daroussin  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1461d06d6bSBaptiste Daroussin  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1561d06d6bSBaptiste Daroussin  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1661d06d6bSBaptiste Daroussin  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*6d38604fSBaptiste Daroussin  *
18*6d38604fSBaptiste Daroussin  * Internal interfaces for parser utilities needed by multiple parsers
19*6d38604fSBaptiste Daroussin  * and the top-level functions to call the mdoc, man, and roff parsers.
2061d06d6bSBaptiste Daroussin  */
2161d06d6bSBaptiste Daroussin 
227295610fSBaptiste Daroussin /*
237295610fSBaptiste Daroussin  * Return codes passed from the roff parser to the main parser.
247295610fSBaptiste Daroussin  */
257295610fSBaptiste Daroussin 
267295610fSBaptiste Daroussin /* Main instruction: what to do with the returned line. */
277295610fSBaptiste Daroussin #define	ROFF_IGN	0x000	/* Don't do anything with it. */
287295610fSBaptiste Daroussin #define	ROFF_CONT	0x001	/* Give it to the high-level parser. */
297295610fSBaptiste Daroussin #define	ROFF_RERUN	0x002	/* Re-run the roff parser with an offset. */
307295610fSBaptiste Daroussin #define	ROFF_REPARSE	0x004	/* Recursively run the main parser on it. */
317295610fSBaptiste Daroussin #define	ROFF_SO		0x008	/* Include the named file. */
327295610fSBaptiste Daroussin #define	ROFF_MASK	0x00f	/* Only one of these bits should be set. */
337295610fSBaptiste Daroussin 
347295610fSBaptiste Daroussin /* Options for further parsing, to be OR'ed with the above. */
357295610fSBaptiste Daroussin #define	ROFF_APPEND	0x010	/* Append the next line to this one. */
367295610fSBaptiste Daroussin #define	ROFF_USERCALL	0x020	/* Start execution of a new macro. */
377295610fSBaptiste Daroussin #define	ROFF_USERRET	0x040	/* Abort execution of the current macro. */
387295610fSBaptiste Daroussin #define	ROFF_WHILE	0x100	/* Start a new .while loop. */
397295610fSBaptiste Daroussin #define	ROFF_LOOPCONT	0x200	/* Iterate the current .while loop. */
407295610fSBaptiste Daroussin #define	ROFF_LOOPEXIT	0x400	/* Exit the current .while loop. */
417295610fSBaptiste Daroussin #define	ROFF_LOOPMASK	0xf00
427295610fSBaptiste Daroussin 
4361d06d6bSBaptiste Daroussin 
4461d06d6bSBaptiste Daroussin struct	buf {
4561d06d6bSBaptiste Daroussin 	char		*buf;
4661d06d6bSBaptiste Daroussin 	size_t		 sz;
477295610fSBaptiste Daroussin 	struct buf	*next;
4861d06d6bSBaptiste Daroussin };
4961d06d6bSBaptiste Daroussin 
5061d06d6bSBaptiste Daroussin 
5161d06d6bSBaptiste Daroussin struct	roff;
5261d06d6bSBaptiste Daroussin struct	roff_man;
53*6d38604fSBaptiste Daroussin struct	roff_node;
5461d06d6bSBaptiste Daroussin 
55*6d38604fSBaptiste Daroussin char		*mandoc_normdate(struct roff_node *, struct roff_node *);
5661d06d6bSBaptiste Daroussin int		 mandoc_eos(const char *, size_t);
5761d06d6bSBaptiste Daroussin int		 mandoc_strntoi(const char *, size_t, int);
5861d06d6bSBaptiste Daroussin const char	*mandoc_a2msec(const char*);
5961d06d6bSBaptiste Daroussin 
6061d06d6bSBaptiste Daroussin int		 mdoc_parseln(struct roff_man *, int, char *, int);
6161d06d6bSBaptiste Daroussin void		 mdoc_endparse(struct roff_man *);
6261d06d6bSBaptiste Daroussin 
6361d06d6bSBaptiste Daroussin int		 man_parseln(struct roff_man *, int, char *, int);
6461d06d6bSBaptiste Daroussin void		 man_endparse(struct roff_man *);
6561d06d6bSBaptiste Daroussin 
6661d06d6bSBaptiste Daroussin int		 preconv_cue(const struct buf *, size_t);
6761d06d6bSBaptiste Daroussin int		 preconv_encode(const struct buf *, size_t *,
6861d06d6bSBaptiste Daroussin 			struct buf *, size_t *, int *);
6961d06d6bSBaptiste Daroussin 
7061d06d6bSBaptiste Daroussin void		 roff_free(struct roff *);
717295610fSBaptiste Daroussin struct roff	*roff_alloc(int);
7261d06d6bSBaptiste Daroussin void		 roff_reset(struct roff *);
7361d06d6bSBaptiste Daroussin void		 roff_man_free(struct roff_man *);
747295610fSBaptiste Daroussin struct roff_man	*roff_man_alloc(struct roff *, const char *, int);
7561d06d6bSBaptiste Daroussin void		 roff_man_reset(struct roff_man *);
76*6d38604fSBaptiste Daroussin int		 roff_parseln(struct roff *, int, struct buf *, int *, size_t);
777295610fSBaptiste Daroussin void		 roff_userret(struct roff *);
7861d06d6bSBaptiste Daroussin void		 roff_endparse(struct roff *);
79*6d38604fSBaptiste Daroussin void		 roff_setreg(struct roff *, const char *, int, char);
8061d06d6bSBaptiste Daroussin int		 roff_getreg(struct roff *, const char *);
8161d06d6bSBaptiste Daroussin char		*roff_strdup(const struct roff *, const char *);
827295610fSBaptiste Daroussin char		*roff_getarg(struct roff *, char **, int, int *);
8361d06d6bSBaptiste Daroussin int		 roff_getcontrol(const struct roff *,
8461d06d6bSBaptiste Daroussin 			const char *, int *);
8561d06d6bSBaptiste Daroussin int		 roff_getformat(const struct roff *);
86