summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/blocks.c100
-rw-r--r--src/html/html.c6
-rw-r--r--src/main.c4
-rw-r--r--src/print.c4
-rw-r--r--src/stmd.h57
5 files changed, 87 insertions, 84 deletions
diff --git a/src/blocks.c b/src/blocks.c
index 9faccd9..d74ceb2 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -10,13 +10,13 @@
#define peek_at(i, n) (i)->data[n]
-static void incorporate_line(strbuf *ln, int line_number, block** curptr);
-static void finalize(block* b, int line_number);
+static void incorporate_line(strbuf *ln, int line_number, node_block** curptr);
+static void finalize(node_block* b, int line_number);
-static block* make_block(int tag, int start_line, int start_column)
+static node_block* make_block(int tag, int start_line, int start_column)
{
- block* e;
- e = (block*) malloc(sizeof(block));
+ node_block* e;
+ e = (node_block*) malloc(sizeof(node_block));
e->tag = tag;
e->open = true;
e->last_line_blank = false;
@@ -35,10 +35,10 @@ static block* make_block(int tag, int start_line, int start_column)
return e;
}
-// Create a root document block.
-extern block* make_document()
+// Create a root document node_block.
+extern node_block* make_document()
{
- block * e = make_block(document, 1, 1);
+ node_block * e = make_block(document, 1, 1);
reference * map = NULL;
reference ** refmap;
refmap = (reference**) malloc(sizeof(reference*));
@@ -82,10 +82,10 @@ static inline bool accepts_lines(int block_type)
block_type == fenced_code);
}
-static void add_line(block* block, chunk *ch, int offset)
+static void add_line(node_block* node_block, chunk *ch, int offset)
{
- assert(block->open);
- strbuf_put(&block->string_content, ch->data + offset, ch->len - offset);
+ assert(node_block->open);
+ strbuf_put(&node_block->string_content, ch->data + offset, ch->len - offset);
}
static void remove_trailing_blank_lines(strbuf *ln)
@@ -109,25 +109,25 @@ static void remove_trailing_blank_lines(strbuf *ln)
strbuf_truncate(ln, i);
}
-// Check to see if a block ends with a blank line, descending
+// Check to see if a node_block ends with a blank line, descending
// if needed into lists and sublists.
-static bool ends_with_blank_line(block* block)
+static bool ends_with_blank_line(node_block* node_block)
{
- if (block->last_line_blank) {
+ if (node_block->last_line_blank) {
return true;
}
- if ((block->tag == list || block->tag == list_item) && block->last_child) {
- return ends_with_blank_line(block->last_child);
+ if ((node_block->tag == list || node_block->tag == list_item) && node_block->last_child) {
+ return ends_with_blank_line(node_block->last_child);
} else {
return false;
}
}
// Break out of all containing lists
-static int break_out_of_lists(block ** bptr, int line_number)
+static int break_out_of_lists(node_block ** bptr, int line_number)
{
- block * container = *bptr;
- block * b = container->top;
+ node_block * container = *bptr;
+ node_block * b = container->top;
// find first containing list:
while (b && b->tag != list) {
b = b->last_child;
@@ -144,15 +144,15 @@ static int break_out_of_lists(block ** bptr, int line_number)
}
-static void finalize(block* b, int line_number)
+static void finalize(node_block* b, int line_number)
{
int firstlinelen;
int pos;
- block* item;
- block* subitem;
+ node_block* item;
+ node_block* subitem;
if (!b->open)
- return; // don't do anything if the block is already closed
+ return; // don't do anything if the node_block is already closed
b->open = false;
if (line_number > b->start_line) {
@@ -230,20 +230,20 @@ static void finalize(block* b, int line_number)
}
}
-// Add a block as child of another. Return pointer to child.
-extern block* add_child(block* parent,
+// Add a node_block as child of another. Return pointer to child.
+extern node_block* add_child(node_block* parent,
int block_type, int start_line, int start_column)
{
assert(parent);
- // if 'parent' isn't the kind of block that can accept this child,
- // then back up til we hit a block that can.
+ // if 'parent' isn't the kind of node_block that can accept this child,
+ // then back up til we hit a node_block that can.
while (!can_contain(parent->tag, block_type)) {
finalize(parent, start_line);
parent = parent->parent;
}
- block* child = make_block(block_type, start_line, start_column);
+ node_block* child = make_block(block_type, start_line, start_column);
child->parent = parent;
child->top = parent->top;
@@ -258,10 +258,10 @@ extern block* add_child(block* parent,
return child;
}
-// Free a block list and any children.
-extern void free_blocks(block* e)
+// Free a node_block list and any children.
+extern void free_blocks(node_block* e)
{
- block * next;
+ node_block * next;
while (e != NULL) {
next = e->next;
free_inlines(e->inline_content);
@@ -277,9 +277,9 @@ extern void free_blocks(block* e)
}
}
-// Walk through block and all children, recursively, parsing
+// Walk through node_block and all children, recursively, parsing
// string content into inline content where appropriate.
-void process_inlines(block* cur, reference** refmap)
+void process_inlines(node_block* cur, reference** refmap)
{
switch (cur->tag) {
case paragraph:
@@ -294,7 +294,7 @@ void process_inlines(block* cur, reference** refmap)
break;
}
- block *child = cur->children;
+ node_block *child = cur->children;
while (child != NULL) {
process_inlines(child, refmap);
child = child->next;
@@ -394,7 +394,7 @@ static void expand_tabs(strbuf *ob, const unsigned char *line, size_t size)
}
}
-static block *finalize_document(block *document, int linenum)
+static node_block *finalize_document(node_block *document, int linenum)
{
while (document != document->top) {
finalize(document, linenum);
@@ -407,12 +407,12 @@ static block *finalize_document(block *document, int linenum)
return document;
}
-extern block *stmd_parse_file(FILE *f)
+extern node_block *stmd_parse_file(FILE *f)
{
strbuf line = GH_BUF_INIT;
unsigned char buffer[4096];
int linenum = 1;
- block *document = make_document();
+ node_block *document = make_document();
while (fgets((char *)buffer, sizeof(buffer), f)) {
expand_tabs(&line, buffer, strlen((char *)buffer));
@@ -425,12 +425,12 @@ extern block *stmd_parse_file(FILE *f)
return finalize_document(document, linenum);
}
-extern block *stmd_parse_document(const unsigned char *buffer, size_t len)
+extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len)
{
strbuf line = GH_BUF_INIT;
int linenum = 1;
const unsigned char *end = buffer + len;
- block *document = make_document();
+ node_block *document = make_document();
while (buffer < end) {
const unsigned char *eol = memchr(buffer, '\n', end - buffer);
@@ -470,18 +470,18 @@ static void chop_trailing_hashtags(chunk *ch)
ch->len = n + 1;
}
-// Process one line at a time, modifying a block.
-static void incorporate_line(strbuf *line, int line_number, block** curptr)
+// Process one line at a time, modifying a node_block.
+static void incorporate_line(strbuf *line, int line_number, node_block** curptr)
{
- block* last_matched_container;
+ node_block* last_matched_container;
int offset = 0;
int matched = 0;
int lev = 0;
int i;
struct ListData * data = NULL;
bool all_matched = true;
- block* container;
- block* cur = *curptr;
+ node_block* container;
+ node_block* cur = *curptr;
bool blank = false;
int first_nonspace;
int indent;
@@ -493,8 +493,8 @@ static void incorporate_line(strbuf *line, int line_number, block** curptr)
// container starts at the document root.
container = cur->top;
- // for each containing block, try to parse the associated line start.
- // bail out on failure: container will point to the last matching block.
+ // for each containing node_block, try to parse the associated line start.
+ // bail out on failure: container will point to the last matching node_block.
while (container->last_child && container->last_child->open) {
container = container->last_child;
@@ -570,7 +570,7 @@ static void incorporate_line(strbuf *line, int line_number, block** curptr)
}
if (!all_matched) {
- container = container->parent; // back up to last matching block
+ container = container->parent; // back up to last matching node_block
break;
}
}
@@ -582,7 +582,7 @@ static void incorporate_line(strbuf *line, int line_number, block** curptr)
break_out_of_lists(&container, line_number);
}
- // unless last matched container is code block, try new container starts:
+ // unless last matched container is code node_block, try new container starts:
while (container->tag != fenced_code && container->tag != indented_code &&
container->tag != html_block) {
@@ -713,7 +713,7 @@ static void incorporate_line(strbuf *line, int line_number, block** curptr)
indent = first_nonspace - offset;
blank = peek_at(&input, first_nonspace) == '\n';
- // block quote lines are never blank as they start with >
+ // node_block quote lines are never blank as they start with >
// and we don't count blanks in fenced code for purposes of tight/loose
// lists or breaking out of lists. we also don't set last_line_blank
// on an empty list item.
@@ -724,7 +724,7 @@ static void incorporate_line(strbuf *line, int line_number, block** curptr)
container->children == NULL &&
container->start_line == line_number));
- block *cont = container;
+ node_block *cont = container;
while (cont->parent) {
cont->parent->last_line_blank = false;
cont = cont->parent;
diff --git a/src/html/html.c b/src/html/html.c
index a7bb21a..6041fde 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -8,7 +8,7 @@
#include "debug.h"
#include "html/houdini.h"
-// Functions to convert block and inline lists to HTML strings.
+// Functions to convert node_block and inline lists to HTML strings.
static void escape_html(strbuf *dest, const unsigned char *source, int length)
{
@@ -32,8 +32,8 @@ static inline void cr(strbuf *html)
strbuf_putc(html, '\n');
}
-// Convert a block list to HTML. Returns 0 on success, and sets result.
-void blocks_to_html(strbuf *html, block *b, bool tight)
+// Convert a node_block list to HTML. Returns 0 on success, and sets result.
+void blocks_to_html(strbuf *html, node_block *b, bool tight)
{
struct ListData *data;
diff --git a/src/main.c b/src/main.c
index 7cf67e2..90bb16d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -12,7 +12,7 @@ void print_usage()
printf(" --version Print version\n");
}
-static void print_document(block *document, bool ast)
+static void print_document(node_block *document, bool ast)
{
strbuf html = GH_BUF_INIT;
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
int i, numfps = 0;
bool ast = false;
int files[argc];
- block *document = NULL;
+ node_block *document = NULL;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "--version") == 0) {
diff --git a/src/print.c b/src/print.c
index 01e9136..069d299 100644
--- a/src/print.c
+++ b/src/print.c
@@ -32,9 +32,9 @@ static void print_str(const unsigned char *s, int len)
putchar('"');
}
-// Functions to pretty-print inline and block lists, for debugging.
+// Functions to pretty-print inline and node_block lists, for debugging.
// Prettyprint an inline list, for debugging.
-extern void print_blocks(block* b, int indent)
+extern void print_blocks(node_block* b, int indent)
{
struct ListData *data;
diff --git a/src/stmd.h b/src/stmd.h
index dbc8c8c..957ab03 100644
--- a/src/stmd.h
+++ b/src/stmd.h
@@ -67,29 +67,30 @@ struct FencedCodeData {
strbuf info;
};
-typedef struct Block {
- enum { document,
- block_quote,
- list,
- list_item,
- fenced_code,
- indented_code,
- html_block,
- paragraph,
- atx_header,
- setext_header,
- hrule,
- reference_def
+struct node_block {
+ enum {
+ document,
+ block_quote,
+ list,
+ list_item,
+ fenced_code,
+ indented_code,
+ html_block,
+ paragraph,
+ atx_header,
+ setext_header,
+ hrule,
+ reference_def
} tag;
int start_line;
int start_column;
int end_line;
bool open;
bool last_line_blank;
- struct Block* children;
- struct Block* last_child;
- struct Block* parent;
- struct Block* top;
+ 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 {
@@ -98,9 +99,11 @@ typedef struct Block {
int header_level;
reference** refmap;
} attributes;
- struct Block * next;
- struct Block * prev;
-} block;
+ struct node_block * next;
+ struct node_block * prev;
+};
+
+typedef struct node_block node_block;
node_inl* parse_inlines(strbuf *input, reference** refmap);
void free_inlines(node_inl* e);
@@ -112,18 +115,18 @@ void free_reference_map(reference **refmap);
void add_reference(reference** refmap, reference* ref);
void unescape_buffer(strbuf *buf);
-extern block* make_document();
-extern block* add_child(block* parent,
+extern node_block* make_document();
+extern node_block* add_child(node_block* parent,
int block_type, int start_line, int start_column);
-void free_blocks(block* e);
+void free_blocks(node_block* e);
-extern block *stmd_parse_document(const unsigned char *buffer, size_t len);
-extern block *stmd_parse_file(FILE *f);
+extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len);
+extern node_block *stmd_parse_file(FILE *f);
void print_inlines(node_inl* ils, int indent);
-void print_blocks(block* blk, int indent);
+void print_blocks(node_block* blk, int indent);
-void blocks_to_html(strbuf *html, block *b, bool tight);
+void blocks_to_html(strbuf *html, node_block *b, bool tight);
void inlines_to_html(strbuf *html, node_inl *b);
void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len);