From e216094e2192c05ddbd0988458eb8c0012e7baf8 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Tue, 2 Sep 2014 01:10:54 +0200 Subject: lol --- src/stmd.h | 76 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'src/stmd.h') diff --git a/src/stmd.h b/src/stmd.h index 5e34399..eb1b989 100644 --- a/src/stmd.h +++ b/src/stmd.h @@ -1,38 +1,38 @@ #include -#include "bstrlib.h" +#include "buffer.h" #include "uthash.h" #define VERSION "0.1" #define CODE_INDENT 4 +typedef struct { + const unsigned char *data; + int len; + int alloc; +} chunk; + typedef struct Inline { - enum { str, softbreak, linebreak, code, raw_html, entity, - emph, strong, link, image } tag; - union { - bstring literal; - struct Inline* inlines; - struct { struct Inline* label; - bstring url; - bstring title; - } linkable; - } content; - struct Inline* next; + enum { str, softbreak, linebreak, code, raw_html, entity, + emph, strong, link, image } tag; + union { + chunk literal; + struct Inline *inlines; + struct { + struct Inline *label; + unsigned char *url; + unsigned char *title; + } linkable; + } content; + struct Inline *next; } inl; typedef struct Reference { - bstring label; - bstring url; - bstring title; + unsigned char *label; + unsigned char *url; + unsigned char *title; UT_hash_handle hh; // used by uthash } reference; -typedef struct Subject { - bstring buffer; - int pos; - reference** reference_map; - int label_nestlevel; -} subject; - // Types for blocks struct ListData { @@ -51,7 +51,7 @@ struct FencedCodeData { int fence_length; int fence_offset; char fence_char; - bstring info; + gh_buf info; }; typedef struct Block { @@ -77,7 +77,8 @@ typedef struct Block { struct Block* last_child; struct Block* parent; struct Block* top; - bstring string_content; + gh_buf string_content; + int string_pos; inl* inline_content; union { struct ListData list_data; @@ -89,33 +90,34 @@ typedef struct Block { struct Block * prev; } block; -int parse_inline(subject* subj, inl ** last); -inl* parse_inlines(bstring input, reference** refmap); -inl* parse_inlines_while(subject* subj, int (*f)(subject*)); +inl* parse_inlines(gh_buf *input, int input_pos, reference** refmap); void free_inlines(inl* e); -int parse_reference(bstring input, reference** refmap); + +int parse_reference(gh_buf *input, int input_pos, reference** refmap); void free_reference(reference *ref); void free_reference_map(reference **refmap); -reference* make_reference(bstring label, bstring url, bstring title); -reference* lookup_reference(reference** refmap, bstring label); + void add_reference(reference** refmap, reference* ref); -int unescape(bstring s); +void unescape_buffer(gh_buf *buf); extern block* make_document(); extern block* add_child(block* parent, int block_type, int start_line, int start_column); void free_blocks(block* e); +block *stmd_parse_document(const char *buffer, size_t len); + // FOR NOW: -int process_inlines(block* cur, reference** refmap); -int incorporate_line(bstring ln, int line_number, block** curptr); -int finalize(block* b, int line_number); +void process_inlines(block* cur, reference** refmap); +void incorporate_line(gh_buf *ln, int line_number, block** curptr); +void finalize(block* b, int line_number); void print_inlines(inl* ils, int indent); void print_blocks(block* blk, int indent); -int blocks_to_html(block* b, bstring* result, bool tight); -int inlines_to_html(inl* b, bstring* result); +/* TODO */ +// int blocks_to_html(block* b, bstring* result, bool tight); +// int inlines_to_html(inl* b, bstring* result); -int bdetab(bstring s, int utf8); +void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len); -- cgit v1.2.3