xref: /illumos-gate/usr/src/cmd/mandoc/roff_int.h (revision 4d131170)
1 /* $OpenBSD: roff_int.h,v 1.16 2019/01/05 00:36:46 schwarze Exp $	*/
2 /*
3  * Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
4  * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * Parser internals shared by multiple parsers.
19  */
20 
21 struct	ohash;
22 struct	roff_node;
23 struct	roff_meta;
24 struct	roff;
25 struct	mdoc_arg;
26 
27 enum	roff_next {
28 	ROFF_NEXT_SIBLING = 0,
29 	ROFF_NEXT_CHILD
30 };
31 
32 struct	roff_man {
33 	struct roff_meta  meta;    /* Public parse results. */
34 	struct roff	 *roff;    /* Roff parser state data. */
35 	struct ohash	 *mdocmac; /* Mdoc macro lookup table. */
36 	struct ohash	 *manmac;  /* Man macro lookup table. */
37 	const char	 *os_s;    /* Default operating system. */
38 	struct roff_node *last;    /* The last node parsed. */
39 	struct roff_node *last_es; /* The most recent Es node. */
40 	int		  quick;   /* Abort parse early. */
41 	int		  flags;   /* Parse flags. */
42 #define	ROFF_NOFILL	 (1 << 1)  /* Fill mode switched off. */
43 #define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
44 #define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
45 #define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
46 #define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
47 #define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
48 #define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
49 #define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
50 #define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
51 #define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
52 #define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
53 #define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
54 #define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
55 #define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
56 #define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
57 #define	ROFF_NONOFILL	 (1 << 16) /* Temporarily suspend no-fill mode. */
58 #define	MAN_NEWLINE	  MDOC_NEWLINE
59 	enum roff_sec	  lastsec; /* Last section seen. */
60 	enum roff_sec	  lastnamed; /* Last standard section seen. */
61 	enum roff_next	  next;    /* Where to put the next node. */
62 	char		  filesec; /* Section digit in the file name. */
63 };
64 
65 
66 struct roff_node *roff_node_alloc(struct roff_man *, int, int,
67 			enum roff_type, int);
68 void		  roff_node_append(struct roff_man *, struct roff_node *);
69 void		  roff_word_alloc(struct roff_man *, int, int, const char *);
70 void		  roff_word_append(struct roff_man *, const char *);
71 void		  roff_elem_alloc(struct roff_man *, int, int, int);
72 struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
73 struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
74 struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
75 void		  roff_node_unlink(struct roff_man *, struct roff_node *);
76 void		  roff_node_relink(struct roff_man *, struct roff_node *);
77 void		  roff_node_free(struct roff_node *);
78 void		  roff_node_delete(struct roff_man *, struct roff_node *);
79 
80 struct ohash	 *roffhash_alloc(enum roff_tok, enum roff_tok);
81 enum roff_tok	  roffhash_find(struct ohash *, const char *, size_t);
82 void		  roffhash_free(struct ohash *);
83 
84 void		  roff_state_reset(struct roff_man *);
85 void		  roff_validate(struct roff_man *);
86 
87 /*
88  * Functions called from roff.c need to be declared here,
89  * not in libmdoc.h or libman.h, even if they are specific
90  * to either the mdoc(7) or the man(7) parser.
91  */
92 
93 void		  man_breakscope(struct roff_man *, int);
94 void		  mdoc_argv_free(struct mdoc_arg *);
95