xref: /openbsd-src/usr.bin/mandoc/libman.h (revision 5ad04d351680822078003e2b066cfc9680d6157d)
1 /*	$Id: libman.h,v 1.34 2014/04/20 16:44:44 schwarze Exp $ */
2 /*
3  * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 #ifndef LIBMAN_H
18 #define LIBMAN_H
19 
20 enum	man_next {
21 	MAN_NEXT_SIBLING = 0,
22 	MAN_NEXT_CHILD
23 };
24 
25 struct	man {
26 	struct mparse	*parse; /* parse pointer */
27 	int		 quick; /* abort parse early */
28 	int		 flags; /* parse flags */
29 #define	MAN_HALT	(1 << 0) /* badness happened: die */
30 #define	MAN_ELINE	(1 << 1) /* Next-line element scope. */
31 #define	MAN_BLINE	(1 << 2) /* Next-line block scope. */
32 #define	MAN_ILINE	(1 << 3) /* Ignored in next-line scope. */
33 #define	MAN_LITERAL	(1 << 4) /* Literal input. */
34 #define	MAN_BPLINE	(1 << 5)
35 #define	MAN_NEWLINE	(1 << 6) /* first macro/text in a line */
36 	enum man_next	 next; /* where to put the next node */
37 	struct man_node	*last; /* the last parsed node */
38 	struct man_node	*first; /* the first parsed node */
39 	struct man_meta	 meta; /* document meta-data */
40 	struct roff	*roff;
41 };
42 
43 #define	MACRO_PROT_ARGS	  struct man *man, \
44 			  enum mant tok, \
45 			  int line, \
46 			  int ppos, \
47 			  int *pos, \
48 			  char *buf
49 
50 struct	man_macro {
51 	int		(*fp)(MACRO_PROT_ARGS);
52 	int		  flags;
53 #define	MAN_SCOPED	 (1 << 0)
54 #define	MAN_EXPLICIT	 (1 << 1)	/* See blk_imp(). */
55 #define	MAN_FSCOPED	 (1 << 2)	/* See blk_imp(). */
56 #define	MAN_NSCOPED	 (1 << 3)	/* See in_line_eoln(). */
57 #define	MAN_NOCLOSE	 (1 << 4)	/* See blk_exp(). */
58 #define	MAN_BSCOPE	 (1 << 5)	/* Break BLINE scope. */
59 };
60 
61 extern	const struct man_macro *const man_macros;
62 
63 __BEGIN_DECLS
64 
65 #define		  man_pmsg(man, l, p, t) \
66 		  mandoc_msg((t), (man)->parse, (l), (p), NULL)
67 #define		  man_nmsg(man, n, t) \
68 		  mandoc_msg((t), (man)->parse, (n)->line, (n)->pos, NULL)
69 int		  man_word_alloc(struct man *, int, int, const char *);
70 int		  man_block_alloc(struct man *, int, int, enum mant);
71 int		  man_head_alloc(struct man *, int, int, enum mant);
72 int		  man_tail_alloc(struct man *, int, int, enum mant);
73 int		  man_body_alloc(struct man *, int, int, enum mant);
74 int		  man_elem_alloc(struct man *, int, int, enum mant);
75 void		  man_node_delete(struct man *, struct man_node *);
76 void		  man_hash_init(void);
77 enum mant	  man_hash_find(const char *);
78 int		  man_macroend(struct man *);
79 int		  man_valid_post(struct man *);
80 int		  man_valid_pre(struct man *, struct man_node *);
81 int		  man_unscope(struct man *, const struct man_node *,
82 			enum mandocerr);
83 
84 __END_DECLS
85 
86 #endif /*!LIBMAN_H*/
87