From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: New function pnode_alloc() to reduce code duplication.
Date: Thu, 11 Apr 2019 23:39:54 -0500 (EST) [thread overview]
Message-ID: <e3fdaecd7e42ab3b@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2019-04-12 4:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fdaecd7e42ab3b@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).