summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-01-05 14:14:04 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-01-05 14:14:04 +0000
commitdffebd8f3a78d88f60b2dc8706c4b9227071f1de (patch)
tree01c98a966b94e2e57de520a5b6a995f317c2d733
parent6eb782b58c4ba0e676d14d922231664e884957bf (diff)
downloadmandoc-dffebd8f3a78d88f60b2dc8706c4b9227071f1de.tar.gz
mandoc-dffebd8f3a78d88f60b2dc8706c4b9227071f1de.tar.zst
mandoc-dffebd8f3a78d88f60b2dc8706c4b9227071f1de.zip
Actions and validations properly added.
-rw-r--r--Makefile18
-rw-r--r--action.c164
-rw-r--r--macro.c66
-rw-r--r--mdoc.c39
-rw-r--r--private.h3
-rw-r--r--validate.c19
6 files changed, 217 insertions, 92 deletions
diff --git a/Makefile b/Makefile
index 73636879..0233ecc3 100644
--- a/Makefile
+++ b/Makefile
@@ -2,15 +2,15 @@ VERSION = 1.1.0
CFLAGS += -W -Wall -Wno-unused-parameter -g
-LNS = macro.ln mdoc.ln mdocml.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln
+LNS = macro.ln mdoc.ln mdocml.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln action.ln
LLNS = llib-llibmdoc.ln llib-lmdocml.ln
LIBS = libmdoc.a
-OBJS = macro.o mdoc.o mdocml.o hash.o strings.o xstd.o argv.o validate.o prologue.o
+OBJS = macro.o mdoc.o mdocml.o hash.o strings.o xstd.o argv.o validate.o prologue.o action.o
-SRCS = macro.c mdoc.c mdocml.c hash.c strings.c xstd.c argv.c validate.c prologue.c
+SRCS = macro.c mdoc.c mdocml.c hash.c strings.c xstd.c argv.c validate.c prologue.c action.c
HEADS = mdoc.h
@@ -28,8 +28,8 @@ mdocml: mdocml.o libmdoc.a
clean:
rm -f $(CLEAN)
-llib-llibmdoc.ln: macro.ln mdoc.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln
- $(LINT) $(LINTFLAGS) -Clibmdoc mdoc.ln macro.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln
+llib-llibmdoc.ln: macro.ln mdoc.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln action.ln
+ $(LINT) $(LINTFLAGS) -Clibmdoc mdoc.ln macro.ln hash.ln strings.ln xstd.ln argv.ln validate.ln prologue.ln action.ln
llib-lmdocml.ln: mdocml.ln llib-llibmdoc.ln
$(LINT) $(LINTFLAGS) -Cmdocml mdocml.ln llib-llibmdoc.ln
@@ -70,8 +70,12 @@ prologue.ln: prologue.c private.h
prologue.o: prologue.c private.h
+action.ln: action.c private.h
+
+action.o: action.c private.h
+
private.h: mdoc.h
-libmdoc.a: macro.o mdoc.o hash.o strings.o xstd.o argv.o validate.o prologue.o
- $(AR) rs $@ macro.o mdoc.o hash.o strings.o xstd.o argv.o validate.o prologue.o
+libmdoc.a: macro.o mdoc.o hash.o strings.o xstd.o argv.o validate.o prologue.o action.o
+ $(AR) rs $@ macro.o mdoc.o hash.o strings.o xstd.o argv.o validate.o prologue.o action.o
diff --git a/action.c b/action.c
new file mode 100644
index 00000000..c099803a
--- /dev/null
+++ b/action.c
@@ -0,0 +1,164 @@
+/* $Id: action.c,v 1.1 2009/01/05 14:14:04 kristaps Exp $ */
+/*
+ * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <assert.h>
+#include <stdlib.h>
+
+#include "private.h"
+
+typedef int (*a_act)(struct mdoc *, int, int,
+ int, const char *[],
+ int, const struct mdoc_arg *);
+
+
+struct actions {
+ a_act action;
+};
+
+
+const struct actions mdoc_actions[MDOC_MAX] = {
+ { NULL }, /* \" */
+ { NULL }, /* Dd */
+ { NULL }, /* Dt */
+ { NULL }, /* Os */
+ { NULL }, /* Sh */
+ { NULL }, /* Ss */
+ { NULL }, /* Pp */
+ { NULL }, /* D1 */
+ { NULL }, /* Dl */
+ { NULL }, /* Bd */
+ { NULL }, /* Ed */
+ { NULL }, /* Bl */
+ { NULL }, /* El */
+ { NULL }, /* It */
+ { NULL }, /* Ad */
+ { NULL }, /* An */
+ { NULL }, /* Ar */
+ { NULL }, /* Cd */
+ { NULL }, /* Cm */
+ { NULL }, /* Dv */
+ { NULL }, /* Er */
+ { NULL }, /* Ev */
+ { NULL }, /* Ex */
+ { NULL }, /* Fa */
+ { NULL }, /* Fd */
+ { NULL }, /* Fl */
+ { NULL }, /* Fn */
+ { NULL }, /* Ft */
+ { NULL }, /* Ic */
+ { NULL }, /* In */
+ { NULL }, /* Li */
+ { NULL }, /* Nd */
+ { NULL }, /* Nm */
+ { NULL }, /* Op */
+ { NULL }, /* Ot */
+ { NULL }, /* Pa */
+ { NULL }, /* Rv */
+ { NULL }, /* St */
+ { NULL }, /* Va */
+ { NULL }, /* Vt */
+ { NULL }, /* Xr */
+ { NULL }, /* %A */
+ { NULL }, /* %B */
+ { NULL }, /* %D */
+ { NULL }, /* %I */
+ { NULL }, /* %J */
+ { NULL }, /* %N */
+ { NULL }, /* %O */
+ { NULL }, /* %P */
+ { NULL }, /* %R */
+ { NULL }, /* %T */
+ { NULL }, /* %V */
+ { NULL }, /* Ac */
+ { NULL }, /* Ao */
+ { NULL }, /* Aq */
+ { NULL }, /* At */
+ { NULL }, /* Bc */
+ { NULL }, /* Bf */
+ { NULL }, /* Bo */
+ { NULL }, /* Bq */
+ { NULL }, /* Bsx */
+ { NULL }, /* Bx */
+ { NULL }, /* Db */
+ { NULL }, /* Dc */
+ { NULL }, /* Do */
+ { NULL }, /* Dq */
+ { NULL }, /* Ec */
+ { NULL }, /* Ef */
+ { NULL }, /* Em */
+ { NULL }, /* Eo */
+ { NULL }, /* Fx */
+ { NULL }, /* Ms */
+ { NULL }, /* No */
+ { NULL }, /* Ns */
+ { NULL }, /* Nx */
+ { NULL }, /* Ox */
+ { NULL }, /* Pc */
+ { NULL }, /* Pf */
+ { NULL }, /* Po */
+ { NULL }, /* Pq */
+ { NULL }, /* Qc */
+ { NULL }, /* Ql */
+ { NULL }, /* Qo */
+ { NULL }, /* Qq */
+ { NULL }, /* Re */
+ { NULL }, /* Rs */
+ { NULL }, /* Sc */
+ { NULL }, /* So */
+ { NULL }, /* Sq */
+ { NULL }, /* Sm */
+ { NULL }, /* Sx */
+ { NULL }, /* Sy */
+ { NULL }, /* Tn */
+ { NULL }, /* Ux */
+ { NULL }, /* Xc */
+ { NULL }, /* Xo */
+ { NULL }, /* Fo */
+ { NULL }, /* Fc */
+ { NULL }, /* Oo */
+ { NULL }, /* Oc */
+ { NULL }, /* Bk */
+ { NULL }, /* Ek */
+ { NULL }, /* Bt */
+ { NULL }, /* Hf */
+ { NULL }, /* Fr */
+ { NULL }, /* Ud */
+};
+
+
+int
+mdoc_action(struct mdoc *mdoc, int tok, int pos)
+{
+
+ 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;
+ break;
+ default:
+ break;
+ }
+#endif
+
diff --git a/macro.c b/macro.c
index a53cf4ab..d5ad4331 100644
--- a/macro.c
+++ b/macro.c
@@ -1,4 +1,4 @@
-/* $Id: macro.c,v 1.20 2009/01/05 12:23:17 kristaps Exp $ */
+/* $Id: macro.c,v 1.21 2009/01/05 14:14:04 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -49,7 +49,9 @@ rewind_elem(struct mdoc *mdoc, int ppos, int tok)
mdoc->last = n;
mdoc->next = MDOC_NEXT_SIBLING;
- return(mdoc_valid_post(mdoc, tok, ppos));
+ if ( ! mdoc_valid_post(mdoc, tok, ppos))
+ return(0);
+ return(mdoc_action(mdoc, tok, ppos));
}
@@ -72,6 +74,7 @@ rewind_line(struct mdoc *mdoc, int ppos, int tok)
mdoc->last = n ? n : mdoc->last;
mdoc->next = MDOC_NEXT_SIBLING;
+ /* XXX - no validation, we do this only for blocks/elements. */
return(1);
}
@@ -96,7 +99,36 @@ rewind_exp(struct mdoc *mdoc, int ppos, int tok, int tt)
return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_NOCTX));
mdoc->next = MDOC_NEXT_SIBLING;
- return(mdoc_valid_post(mdoc, tok, ppos));
+ if ( ! mdoc_valid_post(mdoc, tok, ppos))
+ return(0);
+ return(mdoc_action(mdoc, tok, ppos));
+}
+
+
+static int
+rewind_imp(struct mdoc *mdoc, int ppos, int tok)
+{
+ struct mdoc_node *n;
+ int t;
+
+ n = mdoc->last ? mdoc->last->parent : NULL;
+
+ /* LINTED */
+ for ( ; n; n = n->parent) {
+ if (MDOC_BLOCK != n->type)
+ continue;
+ if (tok == (t = n->data.block.tok))
+ break;
+ if ( ! (MDOC_EXPLICIT & mdoc_macros[t].flags))
+ continue;
+ return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_BREAK));
+ }
+
+ mdoc->last = n ? n : mdoc->last;
+ mdoc->next = MDOC_NEXT_SIBLING;
+ if ( ! mdoc_valid_post(mdoc, tok, ppos))
+ return(0);
+ return(mdoc_action(mdoc, tok, ppos));
}
@@ -131,32 +163,6 @@ macro_close_explicit(MACRO_PROT_ARGS)
static int
-rewind_imp(struct mdoc *mdoc, int ppos, int tok)
-{
- struct mdoc_node *n;
- int t;
-
- n = mdoc->last ? mdoc->last->parent : NULL;
-
- /* LINTED */
- for ( ; n; n = n->parent) {
- if (MDOC_BLOCK != n->type)
- continue;
- if (tok == (t = n->data.block.tok))
- break;
- if ( ! (MDOC_EXPLICIT & mdoc_macros[t].flags))
- continue;
- return(mdoc_err(mdoc, tok, ppos, ERR_SCOPE_BREAK));
- }
-
- mdoc->last = n ? n : mdoc->last;
- mdoc->next = MDOC_NEXT_SIBLING;
- return(1);
- /*return(mdoc_valid_post(mdoc, tok, ppos));*/
-}
-
-
-static int
append_delims(struct mdoc *mdoc, int tok, int *pos, char *buf)
{
int c, lastarg;
@@ -542,7 +548,7 @@ macro_constant(MACRO_PROT_ARGS)
break;
mdoc_word_alloc(mdoc, lastarg, p);
- mdoc->next = MDOC_NEXT_CHILD;
+ mdoc->next = MDOC_NEXT_SIBLING;
}
if (MDOC_LINEARG_MAX == sz + argc)
diff --git a/mdoc.c b/mdoc.c
index 21382807..fe175850 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.15 2009/01/03 22:10:22 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.16 2009/01/05 14:14:04 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -141,7 +141,7 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
{ macro_scoped_line, MDOC_CALLABLE }, /* Aq */
{ macro_constant, 0 }, /* At */
{ NULL, 0 }, /* Bc */
- { macro_scoped, 0 }, /* Bf */
+ { macro_scoped, MDOC_EXPLICIT }, /* Bf */
{ NULL, 0 }, /* Bo */
{ macro_scoped_line, MDOC_CALLABLE }, /* Bq */
{ macro_constant_delimited, 0 }, /* Bsx */
@@ -201,8 +201,6 @@ static struct mdoc_arg *argdup(size_t, const struct mdoc_arg *);
static void argfree(size_t, struct mdoc_arg *);
static void argcpy(struct mdoc_arg *,
const struct mdoc_arg *);
-static char **paramdup(size_t, const char **);
-static void paramfree(size_t, char **);
static void mdoc_node_freelist(struct mdoc_node *);
static void mdoc_node_append(struct mdoc *, int,
@@ -544,7 +542,6 @@ static void
mdoc_elem_free(struct mdoc_elem *p)
{
- paramfree(p->sz, p->args);
argfree(p->argc, p->argv);
}
@@ -639,35 +636,3 @@ argdup(size_t argsz, const struct mdoc_arg *args)
return(pp);
}
-
-static void
-paramfree(size_t sz, char **p)
-{
- int i;
-
- if (0 == sz)
- return;
-
- assert(p);
- /* LINTED */
- for (i = 0; i < (int)sz; i++)
- free(p[i]);
- free(p);
-}
-
-
-static char **
-paramdup(size_t sz, const char **p)
-{
- char **pp;
- int i;
-
- if (0 == sz)
- return(NULL);
-
- pp = xcalloc(sz, sizeof(char *));
- for (i = 0; i < (int)sz; i++)
- pp[i] = xstrdup(p[i]);
-
- return(pp);
-}
diff --git a/private.h b/private.h
index 974ab24c..b78dcdb6 100644
--- a/private.h
+++ b/private.h
@@ -1,4 +1,4 @@
-/* $Id: private.h,v 1.53 2009/01/03 22:10:22 kristaps Exp $ */
+/* $Id: private.h,v 1.54 2009/01/05 14:14:04 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -85,6 +85,7 @@ time_t mdoc_atotime(const char *);
int mdoc_valid_pre(struct mdoc *, int, int,
int, const struct mdoc_arg *);
int mdoc_valid_post(struct mdoc *, int, int);
+int mdoc_action(struct mdoc *, int, int);
int mdoc_argv(struct mdoc *, int,
struct mdoc_arg *, int *, char *);
diff --git a/validate.c b/validate.c
index fbc725a1..728672e0 100644
--- a/validate.c
+++ b/validate.c
@@ -1,4 +1,4 @@
-/* $Id: validate.c,v 1.15 2009/01/03 22:10:22 kristaps Exp $ */
+/* $Id: validate.c,v 1.16 2009/01/05 14:14:04 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -322,7 +322,6 @@ args_an(struct mdoc *mdoc, int tok, int pos,
int argc, const struct mdoc_arg *argv)
{
- printf("argc=%d, sz=%d\n", argc, sz);
if (0 != argc && 0 != sz)
return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_EQ0));
return(1);
@@ -449,28 +448,14 @@ mdoc_valid_pre(struct mdoc *mdoc, int tok, int pos,
int argc, const struct mdoc_arg *argv)
{
- assert(tok < MDOC_MAX);
- if (mdoc_valids[tok].sz)
- if ( ! (*mdoc_valids[tok].sz)(mdoc, tok, pos, sz))
- return(0);
- if (mdoc_valids[tok].args)
- if ( ! (*mdoc_valids[tok].args)(mdoc, tok, pos,
- sz, args, argc, argv))
- return(0);
- if (mdoc_valids[tok].tree_pre)
- if ( ! (*mdoc_valids[tok].tree_pre)(mdoc, tok, pos))
- return(0);
return(1);
}
int
-mdoc_valid_post(struct mdoc *mdoc, int tok, int pos,
- int argc, const struct mdoc_arg *argv)
+mdoc_valid_post(struct mdoc *mdoc, int tok, int pos)
{
- if (mdoc_valids[tok].tree_post)
- return((*mdoc_valids[tok].tree_post)(mdoc, tok, pos));
return(1);
}