Print this page
9718 update mandoc to 1.14.4
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mandoc/mdoc_state.c
+++ new/usr/src/cmd/mandoc/mdoc_state.c
1 -/* $Id: mdoc_state.c,v 1.8 2017/05/05 15:17:32 schwarze Exp $ */
1 +/* $Id: mdoc_state.c,v 1.9 2017/11/29 20:05:33 schwarze Exp $ */
2 2 /*
3 3 * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
4 4 *
5 5 * Permission to use, copy, modify, and distribute this software for any
6 6 * purpose with or without fee is hereby granted, provided that the above
7 7 * copyright notice and this permission notice appear in all copies.
8 8 *
9 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16 */
17 17 #include <sys/types.h>
18 18
19 19 #include <assert.h>
20 20 #include <stdlib.h>
21 21 #include <string.h>
22 22
23 23 #include "mandoc.h"
24 24 #include "roff.h"
25 25 #include "mdoc.h"
26 26 #include "libmandoc.h"
27 27 #include "libmdoc.h"
28 28
29 29 #define STATE_ARGS struct roff_man *mdoc, struct roff_node *n
30 30
31 31 typedef void (*state_handler)(STATE_ARGS);
32 32
33 33 static void state_bd(STATE_ARGS);
34 34 static void state_bl(STATE_ARGS);
35 35 static void state_dl(STATE_ARGS);
36 36 static void state_sh(STATE_ARGS);
37 37 static void state_sm(STATE_ARGS);
38 38
39 39 static const state_handler __state_handlers[MDOC_MAX - MDOC_Dd] = {
40 40 NULL, /* Dd */
41 41 NULL, /* Dt */
42 42 NULL, /* Os */
43 43 state_sh, /* Sh */
44 44 NULL, /* Ss */
45 45 NULL, /* Pp */
46 46 NULL, /* D1 */
47 47 state_dl, /* Dl */
48 48 state_bd, /* Bd */
49 49 NULL, /* Ed */
50 50 state_bl, /* Bl */
51 51 NULL, /* El */
52 52 NULL, /* It */
53 53 NULL, /* Ad */
54 54 NULL, /* An */
55 55 NULL, /* Ap */
56 56 NULL, /* Ar */
57 57 NULL, /* Cd */
58 58 NULL, /* Cm */
59 59 NULL, /* Dv */
60 60 NULL, /* Er */
61 61 NULL, /* Ev */
62 62 NULL, /* Ex */
63 63 NULL, /* Fa */
64 64 NULL, /* Fd */
65 65 NULL, /* Fl */
66 66 NULL, /* Fn */
67 67 NULL, /* Ft */
68 68 NULL, /* Ic */
69 69 NULL, /* In */
70 70 NULL, /* Li */
71 71 NULL, /* Nd */
72 72 NULL, /* Nm */
73 73 NULL, /* Op */
74 74 NULL, /* Ot */
75 75 NULL, /* Pa */
76 76 NULL, /* Rv */
77 77 NULL, /* St */
78 78 NULL, /* Va */
79 79 NULL, /* Vt */
80 80 NULL, /* Xr */
81 81 NULL, /* %A */
82 82 NULL, /* %B */
83 83 NULL, /* %D */
84 84 NULL, /* %I */
85 85 NULL, /* %J */
86 86 NULL, /* %N */
87 87 NULL, /* %O */
88 88 NULL, /* %P */
89 89 NULL, /* %R */
90 90 NULL, /* %T */
91 91 NULL, /* %V */
92 92 NULL, /* Ac */
93 93 NULL, /* Ao */
94 94 NULL, /* Aq */
95 95 NULL, /* At */
96 96 NULL, /* Bc */
97 97 NULL, /* Bf */
98 98 NULL, /* Bo */
99 99 NULL, /* Bq */
100 100 NULL, /* Bsx */
101 101 NULL, /* Bx */
102 102 NULL, /* Db */
103 103 NULL, /* Dc */
104 104 NULL, /* Do */
105 105 NULL, /* Dq */
106 106 NULL, /* Ec */
107 107 NULL, /* Ef */
108 108 NULL, /* Em */
109 109 NULL, /* Eo */
110 110 NULL, /* Fx */
111 111 NULL, /* Ms */
112 112 NULL, /* No */
113 113 NULL, /* Ns */
114 114 NULL, /* Nx */
115 115 NULL, /* Ox */
116 116 NULL, /* Pc */
117 117 NULL, /* Pf */
118 118 NULL, /* Po */
119 119 NULL, /* Pq */
120 120 NULL, /* Qc */
121 121 NULL, /* Ql */
122 122 NULL, /* Qo */
123 123 NULL, /* Qq */
124 124 NULL, /* Re */
125 125 NULL, /* Rs */
126 126 NULL, /* Sc */
127 127 NULL, /* So */
128 128 NULL, /* Sq */
129 129 state_sm, /* Sm */
130 130 NULL, /* Sx */
131 131 NULL, /* Sy */
132 132 NULL, /* Tn */
133 133 NULL, /* Ux */
134 134 NULL, /* Xc */
135 135 NULL, /* Xo */
136 136 NULL, /* Fo */
137 137 NULL, /* Fc */
138 138 NULL, /* Oo */
139 139 NULL, /* Oc */
140 140 NULL, /* Bk */
141 141 NULL, /* Ek */
142 142 NULL, /* Bt */
143 143 NULL, /* Hf */
144 144 NULL, /* Fr */
145 145 NULL, /* Ud */
146 146 NULL, /* Lb */
147 147 NULL, /* Lp */
148 148 NULL, /* Lk */
149 149 NULL, /* Mt */
150 150 NULL, /* Brq */
151 151 NULL, /* Bro */
152 152 NULL, /* Brc */
153 153 NULL, /* %C */
154 154 NULL, /* Es */
155 155 NULL, /* En */
156 156 NULL, /* Dx */
157 157 NULL, /* %Q */
158 158 NULL, /* %U */
159 159 NULL, /* Ta */
160 160 };
161 161 static const state_handler *const state_handlers = __state_handlers - MDOC_Dd;
162 162
163 163
164 164 void
165 165 mdoc_state(struct roff_man *mdoc, struct roff_node *n)
166 166 {
167 167 state_handler handler;
168 168
169 169 if (n->tok == TOKEN_NONE || n->tok < ROFF_MAX)
170 170 return;
171 171
172 172 assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
173 173 if ( ! (mdoc_macros[n->tok].flags & MDOC_PROLOGUE))
174 174 mdoc->flags |= MDOC_PBODY;
175 175
176 176 handler = state_handlers[n->tok];
177 177 if (*handler)
178 178 (*handler)(mdoc, n);
179 179 }
180 180
181 181 void
182 182 mdoc_state_reset(struct roff_man *mdoc)
183 183 {
184 184
185 185 roff_setreg(mdoc->roff, "nS", 0, '=');
186 186 mdoc->flags = 0;
187 187 }
188 188
189 189 static void
190 190 state_bd(STATE_ARGS)
191 191 {
192 192 enum mdocargt arg;
193 193
194 194 if (n->type != ROFFT_HEAD &&
195 195 (n->type != ROFFT_BODY || n->end != ENDBODY_NOT))
196 196 return;
197 197
198 198 if (n->parent->args == NULL)
199 199 return;
200 200
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
201 201 arg = n->parent->args->argv[0].arg;
202 202 if (arg != MDOC_Literal && arg != MDOC_Unfilled)
203 203 return;
204 204
205 205 state_dl(mdoc, n);
206 206 }
207 207
208 208 static void
209 209 state_bl(STATE_ARGS)
210 210 {
211 + struct mdoc_arg *args;
212 + size_t i;
211 213
212 214 if (n->type != ROFFT_HEAD || n->parent->args == NULL)
213 215 return;
214 216
215 - switch(n->parent->args->argv[0].arg) {
216 - case MDOC_Diag:
217 - n->norm->Bl.type = LIST_diag;
218 - break;
219 - case MDOC_Column:
220 - n->norm->Bl.type = LIST_column;
221 - break;
222 - default:
223 - break;
217 + args = n->parent->args;
218 + for (i = 0; i < args->argc; i++) {
219 + switch(args->argv[i].arg) {
220 + case MDOC_Diag:
221 + n->norm->Bl.type = LIST_diag;
222 + return;
223 + case MDOC_Column:
224 + n->norm->Bl.type = LIST_column;
225 + return;
226 + default:
227 + break;
228 + }
224 229 }
225 230 }
226 231
227 232 static void
228 233 state_dl(STATE_ARGS)
229 234 {
230 235
231 236 switch (n->type) {
232 237 case ROFFT_HEAD:
233 238 mdoc->flags |= MDOC_LITERAL;
234 239 break;
235 240 case ROFFT_BODY:
236 241 mdoc->flags &= ~MDOC_LITERAL;
237 242 break;
238 243 default:
239 244 break;
240 245 }
241 246 }
242 247
243 248 static void
244 249 state_sh(STATE_ARGS)
245 250 {
246 251 struct roff_node *nch;
247 252 char *secname;
248 253
249 254 if (n->type != ROFFT_HEAD)
250 255 return;
251 256
252 257 if ( ! (n->flags & NODE_VALID)) {
253 258 secname = NULL;
254 259 deroff(&secname, n);
255 260
256 261 /*
257 262 * Set the section attribute for the BLOCK, HEAD,
258 263 * and HEAD children; the latter can only be TEXT
259 264 * nodes, so no recursion is needed. For other
260 265 * nodes, including the .Sh BODY, this is done
261 266 * when allocating the node data structures, but
262 267 * for .Sh BLOCK and HEAD, the section is still
263 268 * unknown at that time.
264 269 */
265 270
266 271 n->sec = n->parent->sec = secname == NULL ?
267 272 SEC_CUSTOM : mdoc_a2sec(secname);
268 273 for (nch = n->child; nch != NULL; nch = nch->next)
269 274 nch->sec = n->sec;
270 275 free(secname);
271 276 }
272 277
273 278 if ((mdoc->lastsec = n->sec) == SEC_SYNOPSIS) {
274 279 roff_setreg(mdoc->roff, "nS", 1, '=');
275 280 mdoc->flags |= MDOC_SYNOPSIS;
276 281 } else {
277 282 roff_setreg(mdoc->roff, "nS", 0, '=');
278 283 mdoc->flags &= ~MDOC_SYNOPSIS;
279 284 }
280 285 }
281 286
282 287 static void
283 288 state_sm(STATE_ARGS)
284 289 {
285 290
286 291 if (n->child == NULL)
287 292 mdoc->flags ^= MDOC_SMOFF;
288 293 else if ( ! strcmp(n->child->string, "on"))
289 294 mdoc->flags &= ~MDOC_SMOFF;
290 295 else if ( ! strcmp(n->child->string, "off"))
291 296 mdoc->flags |= MDOC_SMOFF;
292 297 }
↓ open down ↓ |
59 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX