cmark

My personal build of CMark ✏️

Commit
abc95bdfa1fd4f4ffb5b0727aec34791a6e472e5
Parent
7f0d1a80c7871a97dcf6495fba9f0e3c8d86be81
Author
John MacFarlane <jgm@berkeley.edu>
Date

Renamed c program and library stmd -> cmark.

Also renamed internal library functions accordingly.

Diffstat

18 files changed, 219 insertions, 218 deletions

Status File Name N° Changes Insertions Deletions
Modified Makefile 8 4 4
Modified README.md 9 5 4
Modified man/Makefile 2 1 1
Added man/cmark.1.md 36 36 0
Added man/man1/cmark.1 32 32 0
Deleted man/man1/stmd.1 32 0 32
Deleted man/stmd.1.md 36 0 36
Modified narrative.md 6 3 3
Modified src/blocks.c 10 5 5
Added src/cmark.h 115 115 0
Modified src/html/html.c 4 2 2
Modified src/inlines.c 2 1 1
Modified src/main.c 18 9 9
Modified src/print.c 4 2 2
Modified src/references.c 2 1 1
Modified src/scanners.h 2 1 1
Deleted src/stmd.h 115 0 115
Modified src/utf8.h 4 2 2
diff --git a/Makefile b/Makefile
@@ -3,7 +3,7 @@ LDFLAGS?=-g -O3 -Wall -Werror
 SRCDIR?=src
 DATADIR?=data
 BENCHINP?=bench.md
-PROG?=./stmd
+PROG?=./cmark
 JSMODULES=$(wildcard js/lib/*.js)
 
 .PHONY: all test spec benchjs testjs
@@ -46,10 +46,10 @@ benchjs:
 
 HTML_OBJ=$(SRCDIR)/html/html.o $(SRCDIR)/html/houdini_href_e.o $(SRCDIR)/html/houdini_html_e.o $(SRCDIR)/html/houdini_html_u.o
 
-STMD_OBJ=$(SRCDIR)/inlines.o $(SRCDIR)/buffer.o $(SRCDIR)/blocks.o $(SRCDIR)/scanners.c $(SRCDIR)/print.o $(SRCDIR)/utf8.o $(SRCDIR)/references.c
+CMARK_OBJ=$(SRCDIR)/inlines.o $(SRCDIR)/buffer.o $(SRCDIR)/blocks.o $(SRCDIR)/scanners.c $(SRCDIR)/print.o $(SRCDIR)/utf8.o $(SRCDIR)/references.c
 
-$(PROG): $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc $(HTML_OBJ) $(STMD_OBJ) $(SRCDIR)/main.c
-	$(CC) $(LDFLAGS) -o $@ $(HTML_OBJ) $(STMD_OBJ) $(SRCDIR)/main.c
+$(PROG): $(SRCDIR)/html/html_unescape.h $(SRCDIR)/case_fold_switch.inc $(HTML_OBJ) $(CMARK_OBJ) $(SRCDIR)/main.c
+	$(CC) $(LDFLAGS) -o $@ $(HTML_OBJ) $(CMARK_OBJ) $(SRCDIR)/main.c
 
 $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
 	re2c --case-insensitive -bis $< > $@ || (rm $@ && false)
diff --git a/README.md b/README.md
@@ -2,20 +2,21 @@ CommonMark
 ==========
 
 CommonMark is a [specification of Markdown syntax][the spec],
-together with BSD3-licensed implementations (`stmd`) in C and JavaScript.
+together with BSD3-licensed implementations (`cmark`) in C and
+JavaScript.
 
 The implementations
 -------------------
 
 The C implementation provides both a library and a standalone program
-`stmd` that converts Markdown to HTML.  It is written in standard C99
+`cmark` that converts Markdown to HTML.  It is written in standard C99
 and has no library dependencies.  (However, if you check it out from the
 repository, you'll need [`re2c`](http://re2c.org) to generate
 `scanners.c` from `scanners.re`.  This is only a build dependency for
 developers, since `scanners.c` can be provided in a released source
 tarball.)
 
-    Usage:   stmd [FILE*]
+    Usage:   cmark [FILE*]
     Options: --help, -h    Print usage information
              --ast         Print AST instead of HTML
              --version     Print version
@@ -37,7 +38,7 @@ sanitizer to protect against
 [XSS attacks](http://en.wikipedia.org/wiki/Cross-site_scripting).
 
 [The spec] contains over 450 embedded examples which serve as conformance
-tests.  To run the tests for `stmd`, do `make test`.  To run them for
+tests.  To run the tests for `cmark`, do `make test`.  To run them for
 another Markdown program, say `myprog`, do `make test PROG=myprog`.  To
 run the tests for `stmd.js`, do `make testjs`.
 
diff --git a/man/Makefile b/man/Makefile
@@ -1,4 +1,4 @@
-ALL=man1/stmd.1
+ALL=man1/cmark.1
 
 .PHONY: all
 
diff --git a/man/cmark.1.md b/man/cmark.1.md
@@ -0,0 +1,36 @@
+---
+title: cmark
+section: 1
+footer: cmark manual
+date: October 22, 2014
+...
+
+# NAME
+
+cmark - convert CommonMark formatted text to HTML
+
+# SYNOPSIS
+
+cmark [*options*] [file\*]
+
+# DESCRIPTION
+
+`cmark` acts as a pipe, reading from stdin or from the specified
+files and writing to stdout.  It converts Markdown formatted plain
+text to HTML, using the conventions described in the CommonMark
+spec.
+
+# OPTIONS
+
+`--ast`
+:   Print an abstract syntax tree instead of HTML.
+
+`--help`
+:   Print usage information.
+
+`--version`
+:   Print version.
+
+# AUTHORS
+
+John MacFarlane
diff --git a/man/man1/cmark.1 b/man/man1/cmark.1
@@ -0,0 +1,32 @@
+.TH "cmark" "1" "October 22, 2014" "cmark manual" ""
+.SH NAME
+.PP
+cmark \- convert CommonMark formatted text to HTML
+.SH SYNOPSIS
+.PP
+cmark [\f[I]options\f[]] [file*]
+.SH DESCRIPTION
+.PP
+\f[C]cmark\f[] acts as a pipe, reading from stdin or from the specified
+files and writing to stdout.
+It converts Markdown formatted plain text to HTML, using the conventions
+described in the CommonMark spec.
+.SH OPTIONS
+.TP
+.B \f[C]\-\-ast\f[]
+Print an abstract syntax tree instead of HTML.
+.RS
+.RE
+.TP
+.B \f[C]\-\-help\f[]
+Print usage information.
+.RS
+.RE
+.TP
+.B \f[C]\-\-version\f[]
+Print version.
+.RS
+.RE
+.SH AUTHORS
+.PP
+John MacFarlane
diff --git a/man/man1/stmd.1 b/man/man1/stmd.1
@@ -1,32 +0,0 @@
-.TH "stmd" "1" "August 12, 2014" "stmd manual" ""
-.SH NAME
-.PP
-stmd \- convert markdown formatted text to HTML
-.SH SYNOPSIS
-.PP
-stmd [\f[I]options\f[]] [file*]
-.SH DESCRIPTION
-.PP
-\f[C]stmd\f[] acts as a pipe, reading from stdin or from the specified
-files and writing to stdout.
-It converts markdown formatted plain text to HTML, using the conventions
-described in the CommonMark spec.
-.SH OPTIONS
-.TP
-.B \f[C]\-\-ast\f[]
-Print an abstract syntax tree instead of HTML.
-.RS
-.RE
-.TP
-.B \f[C]\-\-help\f[]
-Print usage information.
-.RS
-.RE
-.TP
-.B \f[C]\-\-version\f[]
-Print version.
-.RS
-.RE
-.SH AUTHORS
-.PP
-John MacFarlane
diff --git a/man/stmd.1.md b/man/stmd.1.md
@@ -1,36 +0,0 @@
----
-title: stmd
-section: 1
-footer: stmd manual
-date: August 12, 2014
-...
-
-# NAME
-
-stmd - convert markdown formatted text to HTML
-
-# SYNOPSIS
-
-stmd [*options*] [file\*]
-
-# DESCRIPTION
-
-`stmd` acts as a pipe, reading from stdin or from the specified
-files and writing to stdout.  It converts markdown formatted plain
-text to HTML, using the conventions described in the CommonMark
-spec.
-
-# OPTIONS
-
-`--ast`
-:   Print an abstract syntax tree instead of HTML.
-
-`--help`
-:   Print usage information.
-
-`--version`
-:   Print version.
-
-# AUTHORS
-
-John MacFarlane
diff --git a/narrative.md b/narrative.md
@@ -4,13 +4,13 @@ title: CommonMark
 
 CommonMark is a [specification of Markdown
 syntax](http://jgm.github.io/stmd/spec.html), together with
-BSD3-licensed implementations (`stmd`) in C and JavaScript. The source
+BSD3-licensed implementations (`cmark`) in C and JavaScript. The source
 for the spec and the two implementations can be found in [this
 repository](http://github.com/jgm/stmd).
 
 The C implementation provides both a library and a standalone program
-`stmd` that converts Markdown to HTML. It is written in standard C99 and
-has no library dependencies.
+`cmark` that converts Markdown to HTML. It is written in standard C99
+and has no library dependencies.
 
 The JavaScript implementation is a single JavaScript file, with no
 dependencies. [Try it now!](http://jgm.github.io/stmd/js/)
diff --git a/src/blocks.c b/src/blocks.c
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <ctype.h>
 
-#include "stmd.h"
+#include "cmark.h"
 #include "utf8.h"
 #include "scanners.h"
 #include "inlines.h"
@@ -253,7 +253,7 @@ static node_block* add_child(node_block* parent,
 }
 
 // Free a node_block list and any children.
-void stmd_free_nodes(node_block *e)
+void cmark_free_nodes(node_block *e)
 {
 	node_block * next;
 	while (e != NULL) {
@@ -265,7 +265,7 @@ void stmd_free_nodes(node_block *e)
 		} else if (e->tag == BLOCK_DOCUMENT) {
 			reference_map_free(e->as.document.refmap);
 		}
-		stmd_free_nodes(e->children);
+		cmark_free_nodes(e->children);
 		free(e);
 		e = next;
 	}
@@ -380,7 +380,7 @@ static node_block *finalize_document(node_block *document, int linenum)
 	return document;
 }
 
-extern node_block *stmd_parse_file(FILE *f)
+extern node_block *cmark_parse_file(FILE *f)
 {
 	strbuf line = GH_BUF_INIT;
 	unsigned char buffer[4096];
@@ -398,7 +398,7 @@ extern node_block *stmd_parse_file(FILE *f)
 	return finalize_document(document, linenum);
 }
 
-extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len)
+extern node_block *cmark_parse_document(const unsigned char *buffer, size_t len)
 {
 	strbuf line = GH_BUF_INIT;
 	int linenum = 1;
diff --git a/src/cmark.h b/src/cmark.h
@@ -0,0 +1,115 @@
+#ifndef _STDMD_H_
+#define _STDMD_H_
+
+#include <stdbool.h>
+#include <stdio.h>
+#include "buffer.h"
+#include "chunk.h"
+#include "references.h"
+
+#define VERSION "0.1"
+#define CODE_INDENT 4
+
+struct node_inl {
+	enum {
+		INL_STRING,
+		INL_SOFTBREAK,
+		INL_LINEBREAK,
+		INL_CODE,
+		INL_RAW_HTML,
+		INL_EMPH,
+		INL_STRONG,
+		INL_LINK,
+		INL_IMAGE
+	} tag;
+	union {
+		chunk literal;
+		struct node_inl *inlines;
+		struct {
+			struct node_inl *label;
+			unsigned char *url;
+			unsigned char *title;
+		} linkable;
+	} content;
+	struct node_inl *next;
+};
+
+typedef struct node_inl node_inl;
+
+// Types for blocks
+struct ListData {
+	enum {
+		bullet,
+		ordered
+	}  list_type;
+	int               marker_offset;
+	int               padding;
+	int               start;
+	enum {
+		period,
+		parens
+	} delimiter;
+	unsigned char     bullet_char;
+	bool              tight;
+};
+
+struct FencedCodeData {
+	int               fence_length;
+	int               fence_offset;
+	unsigned char     fence_char;
+	strbuf            info;
+};
+
+struct node_block {
+	enum {
+		BLOCK_DOCUMENT,
+		BLOCK_BQUOTE,
+		BLOCK_LIST,
+		BLOCK_LIST_ITEM,
+		BLOCK_FENCED_CODE,
+		BLOCK_INDENTED_CODE,
+		BLOCK_HTML,
+		BLOCK_PARAGRAPH,
+		BLOCK_ATX_HEADER,
+		BLOCK_SETEXT_HEADER,
+		BLOCK_HRULE,
+		BLOCK_REFERENCE_DEF
+	} tag;
+	int start_line;
+	int start_column;
+	int end_line;
+	bool open;
+	bool last_line_blank;
+	struct node_block* children;
+	struct node_block* last_child;
+	struct node_block* parent;
+	struct node_block* top;
+	strbuf string_content;
+	node_inl* inline_content;
+
+	union  {
+		struct ListData list;
+		struct FencedCodeData code;
+		struct {
+			int level;
+		} header;
+		struct {
+			reference_map *refmap;
+		} document;
+	} as;
+
+	struct node_block *next;
+	struct node_block *prev;
+};
+
+typedef struct node_block node_block;
+
+node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
+node_block *cmark_parse_file(FILE *f);
+
+void cmark_free_nodes(node_block *e);
+
+void cmark_debug_print(node_block *root);
+void cmark_render_html(strbuf *html, node_block *root);
+
+#endif
diff --git a/src/html/html.c b/src/html/html.c
@@ -4,7 +4,7 @@
 #include <string.h>
 #include <assert.h>
 
-#include "stmd.h"
+#include "cmark.h"
 #include "debug.h"
 #include "html/houdini.h"
 
@@ -222,7 +222,7 @@ static void blocks_to_html(strbuf *html, node_block *b, bool tight)
 	}
 }
 
-void stmd_render_html(strbuf *html, node_block *root)
+void cmark_render_html(strbuf *html, node_block *root)
 {
 	blocks_to_html(html, root, false);
 }
diff --git a/src/inlines.c b/src/inlines.c
@@ -4,7 +4,7 @@
 #include <stdbool.h>
 #include <ctype.h>
 
-#include "stmd.h"
+#include "cmark.h"
 #include "html/houdini.h"
 #include "utf8.h"
 #include "scanners.h"
diff --git a/src/main.c b/src/main.c
@@ -1,12 +1,12 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "stmd.h"
+#include "cmark.h"
 #include "debug.h"
 
 void print_usage()
 {
-	printf("Usage:   stmd [FILE*]\n");
+	printf("Usage:   cmark [FILE*]\n");
 	printf("Options: --help, -h    Print usage information\n");
 	printf("         --ast         Print AST instead of HTML\n");
 	printf("         --version     Print version\n");
@@ -17,9 +17,9 @@ static void print_document(node_block *document, bool ast)
 	strbuf html = GH_BUF_INIT;
 
 	if (ast) {
-		stmd_debug_print(document);
+		cmark_debug_print(document);
 	} else {
-		stmd_render_html(&html, document);
+		cmark_render_html(&html, document);
 		printf("%s", html.ptr);
 		strbuf_free(&html);
 	}
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
 
 	for (i = 1; i < argc; i++) {
 		if (strcmp(argv[i], "--version") == 0) {
-			printf("stmd %s", VERSION);
+			printf("cmark %s", VERSION);
 			printf(" - CommonMark converter (c) 2014 John MacFarlane\n");
 			exit(0);
 		} else if ((strcmp(argv[i], "--help") == 0) ||
@@ -52,9 +52,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (numfps == 0) {
-		document = stmd_parse_file(stdin);
+		document = cmark_parse_file(stdin);
 		print_document(document, ast);
-		stmd_free_nodes(document);
+		cmark_free_nodes(document);
 	} else {
 		for (i = 0; i < numfps; i++) {
 			FILE *fp = fopen(argv[files[i]], "r");
@@ -65,9 +65,9 @@ int main(int argc, char *argv[])
 				exit(1);
 			}
 
-			document = stmd_parse_file(fp);
+			document = cmark_parse_file(fp);
 			print_document(document, ast);
-			stmd_free_nodes(document);
+			cmark_free_nodes(document);
 			fclose(fp);
 		}
 	}
diff --git a/src/print.c b/src/print.c
@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include "stmd.h"
+#include "cmark.h"
 #include "debug.h"
 
 static void print_str(const unsigned char *s, int len)
@@ -170,7 +170,7 @@ static void print_blocks(node_block* b, int indent)
 	}
 }
 
-void stmd_debug_print(node_block *root)
+void cmark_debug_print(node_block *root)
 {
 	print_blocks(root, 0);
 }
diff --git a/src/references.c b/src/references.c
@@ -1,4 +1,4 @@
-#include "stmd.h"
+#include "cmark.h"
 #include "utf8.h"
 #include "references.h"
 #include "inlines.h"
diff --git a/src/scanners.h b/src/scanners.h
@@ -1,4 +1,4 @@
-#include "stmd.h"
+#include "cmark.h"
 
 extern int _scan_autolink_uri(const unsigned char *p);
 extern int _scan_autolink_email(const unsigned char *p);
diff --git a/src/stmd.h b/src/stmd.h
@@ -1,115 +0,0 @@
-#ifndef _STDMD_H_
-#define _STDMD_H_
-
-#include <stdbool.h>
-#include <stdio.h>
-#include "buffer.h"
-#include "chunk.h"
-#include "references.h"
-
-#define VERSION "0.1"
-#define CODE_INDENT 4
-
-struct node_inl {
-	enum {
-		INL_STRING,
-		INL_SOFTBREAK,
-		INL_LINEBREAK,
-		INL_CODE,
-		INL_RAW_HTML,
-		INL_EMPH,
-		INL_STRONG,
-		INL_LINK,
-		INL_IMAGE
-	} tag;
-	union {
-		chunk literal;
-		struct node_inl *inlines;
-		struct {
-			struct node_inl *label;
-			unsigned char *url;
-			unsigned char *title;
-		} linkable;
-	} content;
-	struct node_inl *next;
-};
-
-typedef struct node_inl node_inl;
-
-// Types for blocks
-struct ListData {
-	enum {
-		bullet,
-		ordered
-	}  list_type;
-	int               marker_offset;
-	int               padding;
-	int               start;
-	enum {
-		period,
-		parens
-	} delimiter;
-	unsigned char     bullet_char;
-	bool              tight;
-};
-
-struct FencedCodeData {
-	int               fence_length;
-	int               fence_offset;
-	unsigned char     fence_char;
-	strbuf            info;
-};
-
-struct node_block {
-	enum {
-		BLOCK_DOCUMENT,
-		BLOCK_BQUOTE,
-		BLOCK_LIST,
-		BLOCK_LIST_ITEM,
-		BLOCK_FENCED_CODE,
-		BLOCK_INDENTED_CODE,
-		BLOCK_HTML,
-		BLOCK_PARAGRAPH,
-		BLOCK_ATX_HEADER,
-		BLOCK_SETEXT_HEADER,
-		BLOCK_HRULE,
-		BLOCK_REFERENCE_DEF
-	} tag;
-	int start_line;
-	int start_column;
-	int end_line;
-	bool open;
-	bool last_line_blank;
-	struct node_block* children;
-	struct node_block* last_child;
-	struct node_block* parent;
-	struct node_block* top;
-	strbuf string_content;
-	node_inl* inline_content;
-
-	union  {
-		struct ListData list;
-		struct FencedCodeData code;
-		struct {
-			int level;
-		} header;
-		struct {
-			reference_map *refmap;
-		} document;
-	} as;
-
-	struct node_block *next;
-	struct node_block *prev;
-};
-
-typedef struct node_block node_block;
-
-node_block *stmd_parse_document(const unsigned char *buffer, size_t len);
-node_block *stmd_parse_file(FILE *f);
-
-void stmd_free_nodes(node_block *e);
-
-void stmd_debug_print(node_block *root);
-void stmd_render_html(strbuf *html, node_block *root);
-
-#endif
diff --git a/src/utf8.h b/src/utf8.h
@@ -1,5 +1,5 @@
-#ifndef _H_STMD_UTF8_
-#define _H_STMD_UTF8_
+#ifndef _H_cmark_UTF8_
+#define _H_cmark_UTF8_
 
 #include <stdint.h>
 #include "buffer.h"