xref: /openbsd/usr.bin/mandoc/roff_int.h (revision 9784ce3e)
1 /* $OpenBSD: roff_int.h,v 1.20 2022/06/02 11:28:16 schwarze Exp $	*/
2 /*
3  * Copyright (c) 2013-2015, 2017-2022 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 	char	 	 *os_r;    /* Operating system name at run time. */
39 	struct roff_node *last;    /* The last node parsed. */
40 	struct roff_node *last_es; /* The most recent Es node. */
41 	int		  quick;   /* Abort parse early. */
42 	int		  flags;   /* Parse flags. */
43 #define	ROFF_NOFILL	 (1 << 1)  /* Fill mode switched off. */
44 #define	MDOC_PBODY	 (1 << 2)  /* In the document body. */
45 #define	MDOC_NEWLINE	 (1 << 3)  /* First macro/text in a line. */
46 #define	MDOC_PHRASE	 (1 << 4)  /* In a Bl -column phrase. */
47 #define	MDOC_PHRASELIT	 (1 << 5)  /* Literal within a phrase. */
48 #define	MDOC_FREECOL	 (1 << 6)  /* `It' invocation should close. */
49 #define	MDOC_SYNOPSIS	 (1 << 7)  /* SYNOPSIS-style formatting. */
50 #define	MDOC_KEEP	 (1 << 8)  /* In a word keep. */
51 #define	MDOC_SMOFF	 (1 << 9)  /* Spacing is off. */
52 #define	MDOC_NODELIMC	 (1 << 10) /* Disable closing delimiter handling. */
53 #define	MAN_ELINE	 (1 << 11) /* Next-line element scope. */
54 #define	MAN_BLINE	 (1 << 12) /* Next-line block scope. */
55 #define	MDOC_PHRASEQF	 (1 << 13) /* Quote first word encountered. */
56 #define	MDOC_PHRASEQL	 (1 << 14) /* Quote last word of this phrase. */
57 #define	MDOC_PHRASEQN	 (1 << 15) /* Quote first word of the next phrase. */
58 #define	ROFF_NONOFILL	 (1 << 16) /* Temporarily suspend no-fill mode. */
59 #define	MAN_NEWLINE	  MDOC_NEWLINE
60 	enum roff_sec	  lastsec; /* Last section seen. */
61 	enum roff_sec	  lastnamed; /* Last standard section seen. */
62 	enum roff_next	  next;    /* Where to put the next node. */
63 	char		  filesec; /* Section digit in the file name. */
64 };
65 
66 
67 struct roff_node *roff_node_alloc(struct roff_man *, int, int,
68 			enum roff_type, int);
69 void		  roff_node_append(struct roff_man *, struct roff_node *);
70 void		  roff_word_alloc(struct roff_man *, int, int, const char *);
71 void		  roff_word_append(struct roff_man *, const char *);
72 void		  roff_elem_alloc(struct roff_man *, int, int, int);
73 struct roff_node *roff_block_alloc(struct roff_man *, int, int, int);
74 struct roff_node *roff_head_alloc(struct roff_man *, int, int, int);
75 struct roff_node *roff_body_alloc(struct roff_man *, int, int, int);
76 void		  roff_node_unlink(struct roff_man *, struct roff_node *);
77 void		  roff_node_relink(struct roff_man *, struct roff_node *);
78 void		  roff_node_free(struct roff_node *);
79 void		  roff_node_delete(struct roff_man *, struct roff_node *);
80 
81 struct ohash	 *roffhash_alloc(enum roff_tok, enum roff_tok);
82 enum roff_tok	  roffhash_find(struct ohash *, const char *, size_t);
83 void		  roffhash_free(struct ohash *);
84 
85 enum mandoc_esc	  roff_escape(const char *, const int, const int,
86 			int *, int *, int *, int *, int *);
87 void		  roff_state_reset(struct roff_man *);
88 void		  roff_validate(struct roff_man *);
89 
90 /*
91  * Functions called from roff.c need to be declared here,
92  * not in libmdoc.h or libman.h, even if they are specific
93  * to either the mdoc(7) or the man(7) parser.
94  */
95 
96 void		  man_breakscope(struct roff_man *, int);
97 void		  mdoc_argv_free(struct mdoc_arg *);
98