source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: New function pnode_alloc() to reduce code duplication.
@ 2019-04-12  4:39 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-04-12  4:39 UTC (permalink / raw)
  To: source

Log Message:
-----------
New function pnode_alloc() to reduce code duplication.
No functional change.

Modified Files:
--------------
    docbook2mdoc:
        node.c
        node.h
        parse.c

Revision Data
-------------
Index: node.h
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -Lnode.h -Lnode.h -u -p -r1.16 -r1.17
--- node.h
+++ node.h
@@ -229,6 +229,7 @@ struct	ptree {
 
 enum attrkey	 attrkey_parse(const char *);
 enum attrval	 attrval_parse(const char *);
+struct pnode	*pnode_alloc(struct pnode *);
 void		 pnode_unlink(struct pnode *);
 void		 pnode_unlinksub(struct pnode *);
 enum attrval	 pnode_getattr(struct pnode *, enum attrkey);
Index: parse.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/parse.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -Lparse.c -Lparse.c -u -p -r1.33 -r1.34
--- parse.c
+++ parse.c
@@ -337,14 +337,10 @@ xml_char(struct parse *p, const char *wo
 	}
 
 	if (n->node != NODE_TEXT) {
-		if ((n = calloc(1, sizeof(*n))) == NULL)
+		if ((n = pnode_alloc(p->cur)) == NULL)
 			fatal(p);
 		n->node = NODE_TEXT;
 		n->spc = (p->flags & PFLAG_SPC) != 0;
-		n->parent = p->cur;
-		TAILQ_INIT(&n->childq);
-		TAILQ_INIT(&n->attrq);
-		TAILQ_INSERT_TAIL(&p->cur->childq, n, child);
 		p->cur = n;
 	}
 
@@ -440,15 +436,11 @@ xml_entity(struct parse *p, const char *
 	}
 
 	/* Create, append, and close out an entity node. */
-	if ((n = calloc(1, sizeof(*n))) == NULL ||
+	if ((n = pnode_alloc(p->cur)) == NULL ||
 	    (n->b = strdup(entity->roff)) == NULL)
 		fatal(p);
 	n->node = NODE_ESCAPE;
 	n->spc = (p->flags & PFLAG_SPC) != 0;
-	n->parent = p->cur;
-	TAILQ_INIT(&n->childq);
-	TAILQ_INIT(&n->attrq);
-	TAILQ_INSERT_TAIL(&p->cur->childq, n, child);
 	p->flags &= ~PFLAG_SPC;
 }
 
@@ -504,7 +496,7 @@ xml_elem_start(struct parse *p, const ch
 	if (p->tree->flags & TREE_CLOSED && p->cur->parent == NULL)
 		warn_msg(p, "element after end of document: <%s>", name);
 
-	if ((n = calloc(1, sizeof(*n))) == NULL)
+	if ((n = pnode_alloc(p->cur)) == NULL)
 		fatal(p);
 
 	/*
@@ -556,13 +548,6 @@ xml_elem_start(struct parse *p, const ch
 		n->spc = (p->flags & PFLAG_SPC) != 0;
 		break;
 	}
-	n->parent = p->cur;
-	TAILQ_INIT(&n->childq);
-	TAILQ_INIT(&n->attrq);
-
-	if (p->cur != NULL)
-		TAILQ_INSERT_TAIL(&p->cur->childq, n, child);
-
 	p->cur = n;
 	if (n->node == NODE_DOCTYPE) {
 		if (p->doctype == NULL)
Index: node.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/node.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lnode.c -Lnode.c -u -p -r1.8 -r1.9
--- node.c
+++ node.c
@@ -74,6 +74,20 @@ attrval_parse(const char *name)
 	return val;
 }
 
+struct pnode *
+pnode_alloc(struct pnode *np)
+{
+	struct pnode	*n;
+
+	if ((n = calloc(1, sizeof(*n))) != NULL) {
+		TAILQ_INIT(&n->childq);
+		TAILQ_INIT(&n->attrq);
+		if ((n->parent = np) != NULL)
+			TAILQ_INSERT_TAIL(&np->childq, n, child);
+	}
+	return n;
+}
+
 /*
  * Recursively free a node (NULL is ok).
  */
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-04-12  4:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-12  4:39 docbook2mdoc: New function pnode_alloc() to reduce code duplication schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).