]>
git.cameronkatri.com Git - mandoc.git/blob - action.c
81d38ba179c37a836a2fa3b3b7c23b659bd1362a
1 /* $Id: action.c,v 1.3 2009/01/07 15:53:00 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
24 typedef int (*a_act
)(struct mdoc
*, int, int);
32 static int action_sh(struct mdoc
*, int, int);
35 const struct actions mdoc_actions
[MDOC_MAX
] = {
40 { action_sh
}, /* Sh */
146 action_sh(struct mdoc
*mdoc
, int tok
, int pos
)
151 char *args
[MDOC_LINEARG_MAX
];
153 if (MDOC_HEAD
!= mdoc
->last
->type
)
156 n
= mdoc
->last
->child
;
159 for (i
= 0; n
&& i
< MDOC_LINEARG_MAX
; n
= n
->next
, i
++) {
160 assert(MDOC_TEXT
== n
->type
);
161 assert(NULL
== n
->child
);
162 assert(n
->data
.text
.string
);
163 args
[i
] = n
->data
.text
.string
;
166 sec
= mdoc_atosec((size_t)i
, (const char **)args
);
167 if (SEC_CUSTOM
!= sec
)
168 mdoc
->sec_lastn
= sec
;
169 mdoc
->sec_last
= sec
;
176 mdoc_action(struct mdoc
*mdoc
, int pos
)
180 switch (mdoc
->last
->type
) {
182 t
= mdoc
->last
->data
.body
.tok
;
185 t
= mdoc
->last
->data
.elem
.tok
;
188 t
= mdoc
->last
->data
.block
.tok
;
191 t
= mdoc
->last
->data
.head
.tok
;
197 if (NULL
== mdoc_actions
[t
].action
)
199 /* TODO: MDOC_Nm... ? */
200 return((*mdoc_actions
[t
].action
)(mdoc
, t
, pos
));