xref: /netbsd-src/external/bsd/mdocml/dist/libmandoc.h (revision 6167eca2d062f3691f8b22e3b8ea212d6dde852a)
1*6167eca2Schristos /*	Id: libmandoc.h,v 1.77 2018/12/21 17:15:18 schwarze Exp  */
24154958bSjoerg /*
3603fc4ebSjoerg  * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
4*6167eca2Schristos  * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
54154958bSjoerg  *
64154958bSjoerg  * Permission to use, copy, modify, and distribute this software for any
74154958bSjoerg  * purpose with or without fee is hereby granted, provided that the above
84154958bSjoerg  * copyright notice and this permission notice appear in all copies.
94154958bSjoerg  *
10f47368cfSchristos  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
114154958bSjoerg  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12f47368cfSchristos  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
134154958bSjoerg  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
144154958bSjoerg  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
154154958bSjoerg  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
164154958bSjoerg  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
174154958bSjoerg  */
184154958bSjoerg 
19*6167eca2Schristos /*
20*6167eca2Schristos  * Return codes passed from the roff parser to the main parser.
21*6167eca2Schristos  */
22*6167eca2Schristos 
23*6167eca2Schristos /* Main instruction: what to do with the returned line. */
24*6167eca2Schristos #define	ROFF_IGN	0x000	/* Don't do anything with it. */
25*6167eca2Schristos #define	ROFF_CONT	0x001	/* Give it to the high-level parser. */
26*6167eca2Schristos #define	ROFF_RERUN	0x002	/* Re-run the roff parser with an offset. */
27*6167eca2Schristos #define	ROFF_REPARSE	0x004	/* Recursively run the main parser on it. */
28*6167eca2Schristos #define	ROFF_SO		0x008	/* Include the named file. */
29*6167eca2Schristos #define	ROFF_MASK	0x00f	/* Only one of these bits should be set. */
30*6167eca2Schristos 
31*6167eca2Schristos /* Options for further parsing, to be OR'ed with the above. */
32*6167eca2Schristos #define	ROFF_APPEND	0x010	/* Append the next line to this one. */
33*6167eca2Schristos #define	ROFF_USERCALL	0x020	/* Start execution of a new macro. */
34*6167eca2Schristos #define	ROFF_USERRET	0x040	/* Abort execution of the current macro. */
35*6167eca2Schristos #define	ROFF_WHILE	0x100	/* Start a new .while loop. */
36*6167eca2Schristos #define	ROFF_LOOPCONT	0x200	/* Iterate the current .while loop. */
37*6167eca2Schristos #define	ROFF_LOOPEXIT	0x400	/* Exit the current .while loop. */
38*6167eca2Schristos #define	ROFF_LOOPMASK	0xf00
39*6167eca2Schristos 
405c413d0cSchristos 
415c413d0cSchristos struct	buf {
425c413d0cSchristos 	char		*buf;
435c413d0cSchristos 	size_t		 sz;
44*6167eca2Schristos 	struct buf	*next;
4548741257Sjoerg };
4648741257Sjoerg 
474154958bSjoerg 
4848741257Sjoerg struct	roff;
49f47368cfSchristos struct	roff_man;
50f47368cfSchristos enum	mandocerr;
5148741257Sjoerg 
5214e7489eSchristos char		*mandoc_normdate(struct roff_man *, char *, int, int);
53603fc4ebSjoerg int		 mandoc_eos(const char *, size_t);
54c5f73b34Sjoerg int		 mandoc_strntoi(const char *, size_t, int);
55cf816816Sjoerg const char	*mandoc_a2msec(const char*);
5648741257Sjoerg 
57f47368cfSchristos int		 mdoc_parseln(struct roff_man *, int, char *, int);
58f47368cfSchristos void		 mdoc_endparse(struct roff_man *);
5948741257Sjoerg 
60f47368cfSchristos int		 man_parseln(struct roff_man *, int, char *, int);
61f47368cfSchristos void		 man_endparse(struct roff_man *);
625c413d0cSchristos 
635c413d0cSchristos int		 preconv_cue(const struct buf *, size_t);
64755c0a52Schristos int		 preconv_encode(const struct buf *, size_t *,
655c413d0cSchristos 			struct buf *, size_t *, int *);
6648741257Sjoerg 
6748741257Sjoerg void		 roff_free(struct roff *);
68*6167eca2Schristos struct roff	*roff_alloc(int);
6948741257Sjoerg void		 roff_reset(struct roff *);
70f47368cfSchristos void		 roff_man_free(struct roff_man *);
71*6167eca2Schristos struct roff_man	*roff_man_alloc(struct roff *, const char *, int);
72f47368cfSchristos void		 roff_man_reset(struct roff_man *);
73*6167eca2Schristos int		 roff_parseln(struct roff *, int, struct buf *, int *);
74*6167eca2Schristos void		 roff_userret(struct roff *);
7548741257Sjoerg void		 roff_endparse(struct roff *);
76603fc4ebSjoerg void		 roff_setreg(struct roff *, const char *, int, char sign);
7714e7489eSchristos int		 roff_getreg(struct roff *, const char *);
78c5f73b34Sjoerg char		*roff_strdup(const struct roff *, const char *);
79*6167eca2Schristos char		*roff_getarg(struct roff *, char **, int, int *);
80603fc4ebSjoerg int		 roff_getcontrol(const struct roff *,
81603fc4ebSjoerg 			const char *, int *);
825c413d0cSchristos int		 roff_getformat(const struct roff *);
83