1 /* $Id: mdoc_state.c,v 1.18 2022/04/14 16:43:44 schwarze Exp $ */
3 * Copyright (c) 2014, 2015, 2017, 2021 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.
19 #include <sys/types.h>
27 #include "mandoc_dbg.h"
32 #include "libmandoc.h"
36 #define STATE_ARGS struct roff_man *mdoc, struct roff_node *n
38 typedef void (*state_handler
)(STATE_ARGS
);
40 static void state_bl(STATE_ARGS
);
41 static void state_sh(STATE_ARGS
);
42 static void state_sm(STATE_ARGS
);
44 static const state_handler state_handlers
[MDOC_MAX
- MDOC_Dd
] = {
170 mdoc_state(struct roff_man
*mdoc
, struct roff_node
*n
)
172 state_handler handler
;
174 if (n
->tok
== TOKEN_NONE
|| n
->tok
< ROFF_MAX
)
177 assert(n
->tok
>= MDOC_Dd
&& n
->tok
< MDOC_MAX
);
178 if ((mdoc_macro(n
->tok
)->flags
& MDOC_PROLOGUE
) == 0)
179 mdoc
->flags
|= MDOC_PBODY
;
181 handler
= state_handlers
[n
->tok
- MDOC_Dd
];
189 struct mdoc_arg
*args
;
192 if (n
->type
!= ROFFT_HEAD
|| n
->parent
->args
== NULL
)
195 args
= n
->parent
->args
;
196 for (i
= 0; i
< args
->argc
; i
++) {
197 switch(args
->argv
[i
].arg
) {
199 n
->norm
->Bl
.type
= LIST_diag
;
202 n
->norm
->Bl
.type
= LIST_column
;
213 struct roff_node
*nch
;
216 if (n
->type
!= ROFFT_HEAD
)
219 if ( ! (n
->flags
& NODE_VALID
)) {
224 * Set the section attribute for the BLOCK, HEAD,
225 * and HEAD children; the latter can only be TEXT
226 * nodes, so no recursion is needed. For other
227 * nodes, including the .Sh BODY, this is done
228 * when allocating the node data structures, but
229 * for .Sh BLOCK and HEAD, the section is still
230 * unknown at that time.
233 n
->sec
= n
->parent
->sec
= secname
== NULL
?
234 SEC_CUSTOM
: mdoc_a2sec(secname
);
235 for (nch
= n
->child
; nch
!= NULL
; nch
= nch
->next
)
240 if ((mdoc
->lastsec
= n
->sec
) == SEC_SYNOPSIS
) {
241 roff_setreg(mdoc
->roff
, "nS", 1, '=');
242 mdoc
->flags
|= MDOC_SYNOPSIS
;
244 roff_setreg(mdoc
->roff
, "nS", 0, '=');
245 mdoc
->flags
&= ~MDOC_SYNOPSIS
;
253 if (n
->child
== NULL
)
254 mdoc
->flags
^= MDOC_SMOFF
;
255 else if ( ! strcmp(n
->child
->string
, "on"))
256 mdoc
->flags
&= ~MDOC_SMOFF
;
257 else if ( ! strcmp(n
->child
->string
, "off"))
258 mdoc
->flags
|= MDOC_SMOFF
;