summaryrefslogtreecommitdiffstatshomepage
path: root/action.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-07 15:53:00 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-07 15:53:00 +0000
commit9dd355694618bcd06487072ef69080b1afa3dead (patch)
tree014ccffd5ebbb334c255c29e64f5bdc54d10050d /action.c
parent1c8d0e7cfcdbd3d64368314aed6b31f07872e336 (diff)
downloadmandoc-9dd355694618bcd06487072ef69080b1afa3dead.tar.gz
mandoc-9dd355694618bcd06487072ef69080b1afa3dead.tar.zst
mandoc-9dd355694618bcd06487072ef69080b1afa3dead.zip
*** empty log message ***
Diffstat (limited to 'action.c')
-rw-r--r--action.c72
1 files changed, 54 insertions, 18 deletions
diff --git a/action.c b/action.c
index c7f27266..81d38ba1 100644
--- a/action.c
+++ b/action.c
@@ -1,4 +1,4 @@
-/* $Id: action.c,v 1.2 2009/01/05 16:11:14 kristaps Exp $ */
+/* $Id: action.c,v 1.3 2009/01/07 15:53:00 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -21,9 +21,7 @@
#include "private.h"
-typedef int (*a_act)(struct mdoc *, int, int,
- int, const char *[],
- int, const struct mdoc_arg *);
+typedef int (*a_act)(struct mdoc *, int, int);
struct actions {
@@ -31,12 +29,15 @@ struct actions {
};
+static int action_sh(struct mdoc *, int, int);
+
+
const struct actions mdoc_actions[MDOC_MAX] = {
{ NULL }, /* \" */
{ NULL }, /* Dd */
{ NULL }, /* Dt */
{ NULL }, /* Os */
- { NULL }, /* Sh */
+ { action_sh }, /* Sh */
{ NULL }, /* Ss */
{ NULL }, /* Pp */
{ NULL }, /* D1 */
@@ -141,26 +142,61 @@ const struct actions mdoc_actions[MDOC_MAX] = {
};
-int
-mdoc_action(struct mdoc *mdoc, int tok, int pos)
+static int
+action_sh(struct mdoc *mdoc, int tok, int pos)
{
+ enum mdoc_sec sec;
+ int i;
+ struct mdoc_node *n;
+ char *args[MDOC_LINEARG_MAX];
+
+ if (MDOC_HEAD != mdoc->last->type)
+ return(1);
+
+ n = mdoc->last->child;
+ assert(n);
+
+ for (i = 0; n && i < MDOC_LINEARG_MAX; n = n->next, i++) {
+ assert(MDOC_TEXT == n->type);
+ assert(NULL == n->child);
+ assert(n->data.text.string);
+ args[i] = n->data.text.string;
+ }
+
+ sec = mdoc_atosec((size_t)i, (const char **)args);
+ if (SEC_CUSTOM != sec)
+ mdoc->sec_lastn = sec;
+ mdoc->sec_last = sec;
return(1);
}
-#if 0
- /* Post-processing. */
- switch (tok) {
- case (MDOC_Sh):
- sec = mdoc_atosec((size_t)sz, _CC(args));
- if (SEC_CUSTOM != sec)
- mdoc->sec_lastn = sec;
- mdoc->sec_last = sec;
+
+int
+mdoc_action(struct mdoc *mdoc, int pos)
+{
+ int t;
+
+ switch (mdoc->last->type) {
+ case (MDOC_BODY):
+ t = mdoc->last->data.body.tok;
break;
- default:
+ case (MDOC_ELEM):
+ t = mdoc->last->data.elem.tok;
break;
+ case (MDOC_BLOCK):
+ t = mdoc->last->data.block.tok;
+ break;
+ case (MDOC_HEAD):
+ t = mdoc->last->data.head.tok;
+ break;
+ default:
+ return(1);
}
- MDOC_Nm... ?
-#endif
+ if (NULL == mdoc_actions[t].action)
+ return(1);
+ /* TODO: MDOC_Nm... ? */
+ return((*mdoc_actions[t].action)(mdoc, t, pos));
+}