1 /* $Id: mdoc_state.c,v 1.4 2017/01/10 13:47:00 schwarze Exp $ */
3 * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
17 #include <sys/types.h>
25 #include "libmandoc.h"
28 #define STATE_ARGS struct roff_man *mdoc, struct roff_node *n
30 typedef void (*state_handler)(STATE_ARGS);
32 static void state_bd(STATE_ARGS);
33 static void state_bl(STATE_ARGS);
34 static void state_dl(STATE_ARGS);
35 static void state_sh(STATE_ARGS);
36 static void state_sm(STATE_ARGS);
38 static const state_handler state_handlers[MDOC_MAX] = {
166 mdoc_state(struct roff_man *mdoc, struct roff_node *n)
168 state_handler handler;
170 if (n->tok == TOKEN_NONE)
173 if ( ! (mdoc_macros[n->tok].flags & MDOC_PROLOGUE))
174 mdoc->flags |= MDOC_PBODY;
176 handler = state_handlers[n->tok];
182 mdoc_state_reset(struct roff_man *mdoc)
185 roff_setreg(mdoc->roff, "nS", 0, '=');
194 if (n->type != ROFFT_HEAD &&
195 (n->type != ROFFT_BODY || n->end != ENDBODY_NOT))
198 if (n->parent->args == NULL)
201 arg = n->parent->args->argv[0].arg;
202 if (arg != MDOC_Literal && arg != MDOC_Unfilled)
212 if (n->type != ROFFT_HEAD || n->parent->args == NULL)
215 switch(n->parent->args->argv[0].arg) {
217 n->norm->Bl.type = LIST_diag;
220 n->norm->Bl.type = LIST_column;
233 mdoc->flags |= MDOC_LITERAL;
236 mdoc->flags &= ~MDOC_LITERAL;
246 struct roff_node *nch;
249 if (n->type != ROFFT_HEAD)
252 if ( ! (n->flags & NODE_VALID)) {
257 * Set the section attribute for the BLOCK, HEAD,
258 * and HEAD children; the latter can only be TEXT
259 * nodes, so no recursion is needed. For other
260 * nodes, including the .Sh BODY, this is done
261 * when allocating the node data structures, but
262 * for .Sh BLOCK and HEAD, the section is still
263 * unknown at that time.
266 n->sec = n->parent->sec = secname == NULL ?
267 SEC_CUSTOM : mdoc_a2sec(secname);
268 for (nch = n->child; nch != NULL; nch = nch->next)
273 if ((mdoc->lastsec = n->sec) == SEC_SYNOPSIS) {
274 roff_setreg(mdoc->roff, "nS", 1, '=');
275 mdoc->flags |= MDOC_SYNOPSIS;
277 roff_setreg(mdoc->roff, "nS", 0, '=');
278 mdoc->flags &= ~MDOC_SYNOPSIS;
286 if (n->child == NULL)
287 mdoc->flags ^= MDOC_SMOFF;
288 else if ( ! strcmp(n->child->string, "on"))
289 mdoc->flags &= ~MDOC_SMOFF;
290 else if ( ! strcmp(n->child->string, "off"))
291 mdoc->flags |= MDOC_SMOFF;