From abc95bdfa1fd4f4ffb5b0727aec34791a6e472e5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 24 Oct 2014 20:22:05 -0700 Subject: Renamed c program and library stmd -> cmark. Also renamed internal library functions accordingly. --- src/blocks.c | 10 ++--- src/cmark.h | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/html/html.c | 4 +- src/inlines.c | 2 +- src/main.c | 18 ++++----- src/print.c | 4 +- src/references.c | 2 +- src/scanners.h | 2 +- src/stmd.h | 115 ------------------------------------------------------- src/utf8.h | 4 +- 10 files changed, 138 insertions(+), 138 deletions(-) create mode 100644 src/cmark.h delete mode 100644 src/stmd.h (limited to 'src') diff --git a/src/blocks.c b/src/blocks.c index bcec27a..ae106d2 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -4,7 +4,7 @@ #include #include -#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 new file mode 100644 index 0000000..ff2f9a2 --- /dev/null +++ b/src/cmark.h @@ -0,0 +1,115 @@ +#ifndef _STDMD_H_ +#define _STDMD_H_ + +#include +#include +#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 index ab6fc35..fde1cb4 100644 --- a/src/html/html.c +++ b/src/html/html.c @@ -4,7 +4,7 @@ #include #include -#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 index 4744312..7a7f08a 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -4,7 +4,7 @@ #include #include -#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 index 99d14f8..b2404f6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,12 +1,12 @@ #include #include #include -#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 index f3bd8e5..be3bced 100644 --- a/src/print.c +++ b/src/print.c @@ -1,7 +1,7 @@ #include #include #include -#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 index 6759c2c..04b9025 100644 --- 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 index 785d424..86dbcf5 100644 --- 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 deleted file mode 100644 index 552e60e..0000000 --- a/src/stmd.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef _STDMD_H_ -#define _STDMD_H_ - -#include -#include -#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 index c971250..496eae9 100644 --- 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 #include "buffer.h" -- cgit v1.2.3