cmark

My personal build of CMark ✏️

Commit
84d48648f0a203befd666aa0c7dad32fa1a22710
Parent
3f4d605546fc82a3cdce8056790f1bb140a62903
Author
John MacFarlane <jgm@berkeley.edu>
Date

Merge pull request #289 from nwellnhof/user_data

Add field for user data to node

Diffstat

5 files changed, 63 insertions, 1 deletion

Status File Name N° Changes Insertions Deletions
Modified man/man3/cmark.3 21 20 1
Modified src/cmark.h 17 17 0
Modified src/iterator.c 6 6 0
Modified src/node.c 18 18 0
Modified src/node.h 2 2 0
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
@@ -1,4 +1,4 @@
-.TH cmark 3 "January 11, 2015" "LOCAL" "Library Functions Manual"
+.TH cmark 3 "January 20, 2015" "LOCAL" "Library Functions Manual"
 .SH
 NAME
 .PP
@@ -172,6 +172,12 @@ Returns the current node.
 Returns the current event type.
 
 .PP
+\fIcmark_node*\f[] \fBcmark_iter_get_root\f[](\fIcmark_iter *iter\f[])
+
+.PP
+Returns the root node.
+
+.PP
 \fIvoid\f[] \fBcmark_iter_reset\f[](\fIcmark_iter *iter\f[], \fIcmark_node *current\f[], \fIcmark_event_type event_type\f[])
 
 .PP
@@ -183,6 +189,19 @@ descendant of the root node or the root node itself.
 Accessors
 
 .PP
+\fIvoid*\f[] \fBcmark_node_get_user_data\f[](\fIcmark_node *node\f[])
+
+.PP
+Returns the user data of \f[I]node\f[]\&.
+
+.PP
+\fIint\f[] \fBcmark_node_set_user_data\f[](\fIcmark_node *node\f[], \fIvoid *user_data\f[])
+
+.PP
+Sets arbitrary user data for \f[I]node\f[]\&.  Returns 1 on success,
+0 on failure.
+
+.PP
 \fIcmark_node_type\f[] \fBcmark_node_get_type\f[](\fIcmark_node *node\f[])
 
 .PP
diff --git a/src/cmark.h b/src/cmark.h
@@ -213,6 +213,12 @@ CMARK_EXPORT
 cmark_event_type
 cmark_iter_get_event_type(cmark_iter *iter);
 
+/** Returns the root node.
+ */
+CMARK_EXPORT
+cmark_node*
+cmark_iter_get_root(cmark_iter *iter);
+
 /** Resets the iterator so that the current node is 'current' and
  * the event type is 'event_type'.  The new current node must be a
  * descendant of the root node or the root node itself.
@@ -226,6 +232,17 @@ cmark_iter_reset(cmark_iter *iter, cmark_node *current,
  * ## Accessors
  */
 
+/** Returns the user data of 'node'.
+ */
+CMARK_EXPORT void*
+cmark_node_get_user_data(cmark_node *node);
+
+/** Sets arbitrary user data for 'node'.  Returns 1 on success,
+ * 0 on failure.
+ */
+CMARK_EXPORT int
+cmark_node_set_user_data(cmark_node *node, void *user_data);
+
 /** Returns the type of 'node', or `CMARK_NODE_NONE` on error.
  */
 CMARK_EXPORT cmark_node_type
diff --git a/src/iterator.c b/src/iterator.c
@@ -108,6 +108,12 @@ cmark_iter_get_event_type(cmark_iter *iter)
 	return iter->cur.ev_type;
 }
 
+cmark_node*
+cmark_iter_get_root(cmark_iter *iter)
+{
+	return iter->root;
+}
+
 
 void cmark_consolidate_text_nodes(cmark_node *root)
 {
diff --git a/src/node.c b/src/node.c
@@ -189,6 +189,24 @@ cmark_node_last_child(cmark_node *node)
 	}
 }
 
+void*
+cmark_node_get_user_data(cmark_node *node) {
+	if (node == NULL) {
+		return NULL;
+	} else {
+		return node->user_data;
+	}
+}
+
+int
+cmark_node_set_user_data(cmark_node *node, void *user_data) {
+	if (node == NULL) {
+		return 0;
+	}
+	node->user_data = user_data;
+	return 1;
+}
+
 static char*
 S_strdup(const char *str)
 {
diff --git a/src/node.h b/src/node.h
@@ -49,6 +49,8 @@ struct cmark_node {
 	struct cmark_node *first_child;
 	struct cmark_node *last_child;
 
+	void *user_data;
+
 	int start_line;
 	int start_column;
 	int end_line;