aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-06-18 20:46:19 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-06-18 20:46:19 +0000
commit65dc168510767708e266ed70c10c9e2a646424fa (patch)
tree893ef034f49f88a19a1a3a753e0d514227aaa6ce
parent5a58b9c46f195b91a6e97db9ae3778de5e5bae2f (diff)
downloadmandoc-65dc168510767708e266ed70c10c9e2a646424fa.tar.gz
mandoc-65dc168510767708e266ed70c10c9e2a646424fa.tar.zst
mandoc-65dc168510767708e266ed70c10c9e2a646424fa.zip
Added nchild decrement in libman (not used, but better in than forgotten).
Added nchild to libmdoc, deprecated count() functions in validator.
-rw-r--r--man.c5
-rw-r--r--man_term.c3
-rw-r--r--mdoc.c7
-rw-r--r--mdoc.h3
-rw-r--r--mdoc_action.c12
-rw-r--r--mdoc_validate.c21
6 files changed, 23 insertions, 28 deletions
diff --git a/man.c b/man.c
index 350498fd..8067153c 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/* $Id: man.c,v 1.23 2009/06/18 10:53:58 kristaps Exp $ */
+/* $Id: man.c,v 1.24 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -252,6 +252,8 @@ man_node_free(struct man_node *p)
if (p->string)
free(p->string);
+ if (p->parent)
+ p->parent->nchild--;
free(p);
}
@@ -265,6 +267,7 @@ man_node_freelist(struct man_node *p)
if (p->next)
man_node_freelist(p->next);
+ assert(0 == p->nchild);
man_node_free(p);
}
diff --git a/man_term.c b/man_term.c
index d416069b..8b1c6236 100644
--- a/man_term.c
+++ b/man_term.c
@@ -1,4 +1,4 @@
-/* $Id: man_term.c,v 1.15 2009/06/18 19:54:04 kristaps Exp $ */
+/* $Id: man_term.c,v 1.16 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -325,6 +325,7 @@ pre_TP(DECL_ARGS)
size_t offs;
term_vspace(p);
+
p->offset = INDENT;
if (NULL == (nn = n->child))
diff --git a/mdoc.c b/mdoc.c
index aec797d0..ac75b38f 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.85 2009/06/17 10:53:32 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.86 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -442,6 +442,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
/* NOTREACHED */
}
+ p->parent->nchild++;
+
if ( ! mdoc_valid_pre(mdoc, p))
return(0);
if ( ! mdoc_action_pre(mdoc, p))
@@ -597,6 +599,8 @@ void
mdoc_node_free(struct mdoc_node *p)
{
+ if (p->parent)
+ p->parent->nchild--;
if (p->string)
free(p->string);
if (p->args)
@@ -614,6 +618,7 @@ mdoc_node_freelist(struct mdoc_node *p)
if (p->next)
mdoc_node_freelist(p->next);
+ assert(0 == p->nchild);
mdoc_node_free(p);
}
diff --git a/mdoc.h b/mdoc.h
index dc4d108b..bd139d6c 100644
--- a/mdoc.h
+++ b/mdoc.h
@@ -1,4 +1,4 @@
-/* $Id: mdoc.h,v 1.60 2009/06/17 10:53:32 kristaps Exp $ */
+/* $Id: mdoc.h,v 1.61 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -252,6 +252,7 @@ struct mdoc_node {
struct mdoc_node *child;
struct mdoc_node *next;
struct mdoc_node *prev;
+ int nchild;
int line;
int pos;
int tok;
diff --git a/mdoc_action.c b/mdoc_action.c
index 56ff7565..13ce974c 100644
--- a/mdoc_action.c
+++ b/mdoc_action.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_action.c,v 1.16 2009/06/17 14:14:51 kristaps Exp $ */
+/* $Id: mdoc_action.c,v 1.17 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -663,11 +663,9 @@ post_bl_head(POST_ARGS)
* column field. Then, delete the head children.
*/
- for (i = 0, nn = m->last->child; nn; nn = nn->next, i++)
- /* Count children. */;
-
- n->args->argv[c].sz = (size_t)i;
- n->args->argv[c].value = malloc((size_t)i * sizeof(char *));
+ n->args->argv[c].sz = (size_t)m->last->nchild;
+ n->args->argv[c].value = malloc
+ ((size_t)m->last->nchild * sizeof(char *));
for (i = 0, nn = m->last->child; nn; i++) {
n->args->argv[c].value[i] = nn->string;
@@ -677,7 +675,9 @@ post_bl_head(POST_ARGS)
mdoc_node_free(nnp);
}
+ m->last->nchild = 0;
m->last->child = NULL;
+
return(1);
}
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 71b9ff27..48751d87 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.15 2009/06/17 14:10:09 kristaps Exp $ */
+/* $Id: mdoc_validate.c,v 1.16 2009/06/18 20:46:19 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -99,7 +99,6 @@ static int err_child_gt(struct mdoc *, const char *, int);
static int warn_child_gt(struct mdoc *, const char *, int);
static int err_child_eq(struct mdoc *, const char *, int);
static int warn_child_eq(struct mdoc *, const char *, int);
-static int count_child(struct mdoc *);
static int warn_print(struct mdoc *, int, int);
static int warn_count(struct mdoc *, const char *,
int, const char *, int);
@@ -553,19 +552,6 @@ err_count(struct mdoc *m, const char *k,
}
-static inline int
-count_child(struct mdoc *mdoc)
-{
- int i;
- struct mdoc_node *n;
-
- for (i = 0, n = mdoc->last->child; n; n = n->next, i++)
- /* Do nothing */ ;
-
- return(i);
-}
-
-
/*
* Build these up with macros because they're basically the same check
* for different inequalities. Yes, this could be done with functions,
@@ -576,10 +562,9 @@ count_child(struct mdoc *mdoc)
static int \
lvl##_child_##name(struct mdoc *mdoc, const char *p, int sz) \
{ \
- int i; \
- if ((i = count_child(mdoc)) ineq sz) \
+ if (mdoc->last->nchild ineq sz) \
return(1); \
- return(lvl##_count(mdoc, #ineq, sz, p, i)); \
+ return(lvl##_count(mdoc, #ineq, sz, p, mdoc->last->nchild)); \
}
#define CHECK_BODY_DEFN(name, lvl, func, num) \