xref: /freebsd/contrib/mandoc/mdoc.h (revision 5ab1c5846ff41be24b1f6beb0317bf8258cd4409)
1 /*	$Id: mdoc.h,v 1.146 2018/12/30 00:49:55 schwarze Exp $ */
2 /*
3  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4  * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
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 
19 struct	roff_node;
20 struct	roff_man;
21 
22 enum	mdocargt {
23 	MDOC_Split, /* -split */
24 	MDOC_Nosplit, /* -nospli */
25 	MDOC_Ragged, /* -ragged */
26 	MDOC_Unfilled, /* -unfilled */
27 	MDOC_Literal, /* -literal */
28 	MDOC_File, /* -file */
29 	MDOC_Offset, /* -offset */
30 	MDOC_Bullet, /* -bullet */
31 	MDOC_Dash, /* -dash */
32 	MDOC_Hyphen, /* -hyphen */
33 	MDOC_Item, /* -item */
34 	MDOC_Enum, /* -enum */
35 	MDOC_Tag, /* -tag */
36 	MDOC_Diag, /* -diag */
37 	MDOC_Hang, /* -hang */
38 	MDOC_Ohang, /* -ohang */
39 	MDOC_Inset, /* -inset */
40 	MDOC_Column, /* -column */
41 	MDOC_Width, /* -width */
42 	MDOC_Compact, /* -compact */
43 	MDOC_Std, /* -std */
44 	MDOC_Filled, /* -filled */
45 	MDOC_Words, /* -words */
46 	MDOC_Emphasis, /* -emphasis */
47 	MDOC_Symbolic, /* -symbolic */
48 	MDOC_Nested, /* -nested */
49 	MDOC_Centred, /* -centered */
50 	MDOC_ARG_MAX
51 };
52 
53 /*
54  * An argument to a macro (multiple values = `-column xxx yyy').
55  */
56 struct	mdoc_argv {
57 	enum mdocargt	  arg; /* type of argument */
58 	int		  line;
59 	int		  pos;
60 	size_t		  sz; /* elements in "value" */
61 	char		**value; /* argument strings */
62 };
63 
64 /*
65  * Reference-counted macro arguments.  These are refcounted because
66  * blocks have multiple instances of the same arguments spread across
67  * the HEAD, BODY, TAIL, and BLOCK node types.
68  */
69 struct	mdoc_arg {
70 	size_t		  argc;
71 	struct mdoc_argv *argv;
72 	unsigned int	  refcnt;
73 };
74 
75 enum	mdoc_list {
76 	LIST__NONE = 0,
77 	LIST_bullet, /* -bullet */
78 	LIST_column, /* -column */
79 	LIST_dash, /* -dash */
80 	LIST_diag, /* -diag */
81 	LIST_enum, /* -enum */
82 	LIST_hang, /* -hang */
83 	LIST_hyphen, /* -hyphen */
84 	LIST_inset, /* -inset */
85 	LIST_item, /* -item */
86 	LIST_ohang, /* -ohang */
87 	LIST_tag, /* -tag */
88 	LIST_MAX
89 };
90 
91 enum	mdoc_disp {
92 	DISP__NONE = 0,
93 	DISP_centered, /* -centered */
94 	DISP_ragged, /* -ragged */
95 	DISP_unfilled, /* -unfilled */
96 	DISP_filled, /* -filled */
97 	DISP_literal /* -literal */
98 };
99 
100 enum	mdoc_auth {
101 	AUTH__NONE = 0,
102 	AUTH_split, /* -split */
103 	AUTH_nosplit /* -nosplit */
104 };
105 
106 enum	mdoc_font {
107 	FONT__NONE = 0,
108 	FONT_Em, /* Em, -emphasis */
109 	FONT_Li, /* Li, -literal */
110 	FONT_Sy /* Sy, -symbolic */
111 };
112 
113 struct	mdoc_bd {
114 	const char	 *offs; /* -offset */
115 	enum mdoc_disp	  type; /* -ragged, etc. */
116 	int		  comp; /* -compact */
117 };
118 
119 struct	mdoc_bl {
120 	const char	 *width; /* -width */
121 	const char	 *offs; /* -offset */
122 	enum mdoc_list	  type; /* -tag, -enum, etc. */
123 	int		  comp; /* -compact */
124 	size_t		  ncols; /* -column arg count */
125 	const char	**cols; /* -column val ptr */
126 	int		  count; /* -enum counter */
127 };
128 
129 struct	mdoc_bf {
130 	enum mdoc_font	  font; /* font */
131 };
132 
133 struct	mdoc_an {
134 	enum mdoc_auth	  auth; /* -split, etc. */
135 };
136 
137 struct	mdoc_rs {
138 	int		  quote_T; /* whether to quote %T */
139 };
140 
141 /*
142  * Consists of normalised node arguments.  These should be used instead
143  * of iterating through the mdoc_arg pointers of a node: defaults are
144  * provided, etc.
145  */
146 union	mdoc_data {
147 	struct mdoc_an	  An;
148 	struct mdoc_bd	  Bd;
149 	struct mdoc_bf	  Bf;
150 	struct mdoc_bl	  Bl;
151 	struct roff_node *Es;
152 	struct mdoc_rs	  Rs;
153 };
154 
155 /* Names of macro args.  Index is enum mdocargt. */
156 extern	const char *const *mdoc_argnames;
157 
158 void		 mdoc_validate(struct roff_man *);
159