More cleanup and API coalescing
This commit is contained in:
parent
7c69ce64e3
commit
2c95da1d7a
13 changed files with 212 additions and 214 deletions
4
Makefile
4
Makefile
|
@ -1,7 +1,5 @@
|
|||
CFLAGS = -c -g -O3 -Wall -Werror -Wsign-compare -Isrc
|
||||
LDFLAGS = -g -O3 -Wall -Werror
|
||||
CFLAGS = -c -g -O3 -Wall -Wextra -Wno-unused-parameter -Isrc
|
||||
|
||||
# MingW/Cygwin
|
||||
ifneq ($(OS),Windows_NT)
|
||||
CFLAGS += -fPIC
|
||||
endif
|
||||
|
|
|
@ -51,8 +51,8 @@ main(int argc, char **argv)
|
|||
(void)fwrite(ob->data, 1, ob->size, stdout);
|
||||
|
||||
/* cleanup */
|
||||
hoedown_buffer_release(ib);
|
||||
hoedown_buffer_release(ob);
|
||||
hoedown_buffer_free(ib);
|
||||
hoedown_buffer_free(ob);
|
||||
|
||||
return ferror(stdout);
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ main(int argc, char **argv)
|
|||
(void)fwrite(ob->data, 1, ob->size, stdout);
|
||||
|
||||
/* cleanup */
|
||||
hoedown_buffer_release(ib);
|
||||
hoedown_buffer_release(ob);
|
||||
hoedown_buffer_free(ib);
|
||||
hoedown_buffer_free(ob);
|
||||
|
||||
return ferror(stdout);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ EXPORTS
|
|||
hoedown_buffer_put
|
||||
hoedown_buffer_puts
|
||||
hoedown_buffer_putc
|
||||
hoedown_buffer_release
|
||||
hoedown_buffer_free
|
||||
hoedown_buffer_reset
|
||||
hoedown_buffer_slurp
|
||||
hoedown_buffer_printf
|
||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
enum {
|
||||
HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0),
|
||||
HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0)
|
||||
};
|
||||
|
||||
int
|
||||
|
|
194
src/buffer.c
194
src/buffer.c
|
@ -1,4 +1,4 @@
|
|||
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb
|
||||
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) /* 16mb */
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
|
@ -14,21 +14,42 @@
|
|||
# define _buf_vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
int
|
||||
hoedown_buffer_prefix(const struct hoedown_buffer *buf, const char *prefix)
|
||||
/* hoedown_buffer_new: allocation of a new buffer */
|
||||
struct hoedown_buffer *
|
||||
hoedown_buffer_new(size_t unit)
|
||||
{
|
||||
size_t i;
|
||||
assert(buf && buf->unit);
|
||||
struct hoedown_buffer *ret;
|
||||
ret = malloc(sizeof (struct hoedown_buffer));
|
||||
|
||||
for (i = 0; i < buf->size; ++i) {
|
||||
if (prefix[i] == 0)
|
||||
return 0;
|
||||
|
||||
if (buf->data[i] != prefix[i])
|
||||
return buf->data[i] - prefix[i];
|
||||
if (ret) {
|
||||
ret->data = 0;
|
||||
ret->size = ret->asize = 0;
|
||||
ret->unit = unit;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* hoedown_buffer_free: decrease the reference count and free the buffer if needed */
|
||||
void
|
||||
hoedown_buffer_free(struct hoedown_buffer *buf)
|
||||
{
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
free(buf->data);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
/* hoedown_buffer_reset: frees internal data of the buffer */
|
||||
void
|
||||
hoedown_buffer_reset(struct hoedown_buffer *buf)
|
||||
{
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
free(buf->data);
|
||||
buf->data = NULL;
|
||||
buf->size = buf->asize = 0;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_grow: increasing the allocated size to the given value */
|
||||
|
@ -59,23 +80,73 @@ hoedown_buffer_grow(struct hoedown_buffer *buf, size_t neosz)
|
|||
return HOEDOWN_BUF_OK;
|
||||
}
|
||||
|
||||
|
||||
/* hoedown_buffer_new: allocation of a new buffer */
|
||||
struct hoedown_buffer *
|
||||
hoedown_buffer_new(size_t unit)
|
||||
/* hoedown_buffer_put: appends raw data to a buffer */
|
||||
void
|
||||
hoedown_buffer_put(struct hoedown_buffer *buf, const void *data, size_t len)
|
||||
{
|
||||
struct hoedown_buffer *ret;
|
||||
ret = malloc(sizeof (struct hoedown_buffer));
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (ret) {
|
||||
ret->data = 0;
|
||||
ret->size = ret->asize = 0;
|
||||
ret->unit = unit;
|
||||
}
|
||||
return ret;
|
||||
if (buf->size + len > buf->asize && hoedown_buffer_grow(buf, buf->size + len) < 0)
|
||||
return;
|
||||
|
||||
memcpy(buf->data + buf->size, data, len);
|
||||
buf->size += len;
|
||||
}
|
||||
|
||||
/* bufnullterm: NULL-termination of the string array */
|
||||
/* hoedown_buffer_puts: appends a NUL-terminated string to a buffer */
|
||||
void
|
||||
hoedown_buffer_puts(struct hoedown_buffer *buf, const char *str)
|
||||
{
|
||||
hoedown_buffer_put(buf, str, strlen(str));
|
||||
}
|
||||
|
||||
|
||||
/* hoedown_buffer_putc: appends a single uint8_t to a buffer */
|
||||
void
|
||||
hoedown_buffer_putc(struct hoedown_buffer *buf, int c)
|
||||
{
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (buf->size + 1 > buf->asize && hoedown_buffer_grow(buf, buf->size + 1) < 0)
|
||||
return;
|
||||
|
||||
buf->data[buf->size] = c;
|
||||
buf->size += 1;
|
||||
}
|
||||
|
||||
int
|
||||
hoedown_buffer_prefix(const struct hoedown_buffer *buf, const char *prefix)
|
||||
{
|
||||
size_t i;
|
||||
assert(buf && buf->unit);
|
||||
|
||||
for (i = 0; i < buf->size; ++i) {
|
||||
if (prefix[i] == 0)
|
||||
return 0;
|
||||
|
||||
if (buf->data[i] != prefix[i])
|
||||
return buf->data[i] - prefix[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_slurp: removes a given number of bytes from the head of the array */
|
||||
void
|
||||
hoedown_buffer_slurp(struct hoedown_buffer *buf, size_t len)
|
||||
{
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (len >= buf->size) {
|
||||
buf->size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
buf->size -= len;
|
||||
memmove(buf->data, buf->data + len, buf->size);
|
||||
}
|
||||
|
||||
/* hoedown_buffer_cstr: NULL-termination of the string array */
|
||||
const char *
|
||||
hoedown_buffer_cstr(struct hoedown_buffer *buf)
|
||||
{
|
||||
|
@ -132,76 +203,3 @@ hoedown_buffer_printf(struct hoedown_buffer *buf, const char *fmt, ...)
|
|||
|
||||
buf->size += n;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_put: appends raw data to a buffer */
|
||||
void
|
||||
hoedown_buffer_put(struct hoedown_buffer *buf, const void *data, size_t len)
|
||||
{
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (buf->size + len > buf->asize && hoedown_buffer_grow(buf, buf->size + len) < 0)
|
||||
return;
|
||||
|
||||
memcpy(buf->data + buf->size, data, len);
|
||||
buf->size += len;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_puts: appends a NUL-terminated string to a buffer */
|
||||
void
|
||||
hoedown_buffer_puts(struct hoedown_buffer *buf, const char *str)
|
||||
{
|
||||
hoedown_buffer_put(buf, str, strlen(str));
|
||||
}
|
||||
|
||||
|
||||
/* hoedown_buffer_putc: appends a single uint8_t to a buffer */
|
||||
void
|
||||
hoedown_buffer_putc(struct hoedown_buffer *buf, int c)
|
||||
{
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (buf->size + 1 > buf->asize && hoedown_buffer_grow(buf, buf->size + 1) < 0)
|
||||
return;
|
||||
|
||||
buf->data[buf->size] = c;
|
||||
buf->size += 1;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_release: decrease the reference count and free the buffer if needed */
|
||||
void
|
||||
hoedown_buffer_release(struct hoedown_buffer *buf)
|
||||
{
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
free(buf->data);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
|
||||
/* hoedown_buffer_reset: frees internal data of the buffer */
|
||||
void
|
||||
hoedown_buffer_reset(struct hoedown_buffer *buf)
|
||||
{
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
free(buf->data);
|
||||
buf->data = NULL;
|
||||
buf->size = buf->asize = 0;
|
||||
}
|
||||
|
||||
/* hoedown_buffer_slurp: removes a given number of bytes from the head of the array */
|
||||
void
|
||||
hoedown_buffer_slurp(struct hoedown_buffer *buf, size_t len)
|
||||
{
|
||||
assert(buf && buf->unit);
|
||||
|
||||
if (len >= buf->size) {
|
||||
buf->size = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
buf->size -= len;
|
||||
memmove(buf->data, buf->data + len, buf->size);
|
||||
}
|
||||
|
|
26
src/buffer.h
26
src/buffer.h
|
@ -18,7 +18,7 @@ extern "C" {
|
|||
|
||||
typedef enum {
|
||||
HOEDOWN_BUF_OK = 0,
|
||||
HOEDOWN_BUF_ENOMEM = -1,
|
||||
HOEDOWN_BUF_ENOMEM = -1
|
||||
} hoedown_buferror_t;
|
||||
|
||||
/* struct hoedown_buffer: character array buffer */
|
||||
|
@ -33,17 +33,17 @@ struct hoedown_buffer {
|
|||
#define BUFPUTSL(output, literal) \
|
||||
hoedown_buffer_put(output, literal, sizeof(literal) - 1)
|
||||
|
||||
/* hoedown_buffer_grow: increasing the allocated size to the given value */
|
||||
int hoedown_buffer_grow(struct hoedown_buffer *, size_t);
|
||||
|
||||
/* hoedown_buffer_new: allocation of a new buffer */
|
||||
struct hoedown_buffer *hoedown_buffer_new(size_t) __attribute__ ((malloc));
|
||||
|
||||
/* bufnullterm: NUL-termination of the string array (making a C-string) */
|
||||
const char *hoedown_buffer_cstr(struct hoedown_buffer *);
|
||||
/* hoedown_buffer_free: decrease the reference count and free the buffer if needed */
|
||||
void hoedown_buffer_free(struct hoedown_buffer *);
|
||||
|
||||
/* hoedown_buffer_prefix: compare the beginning of a buffer with a string */
|
||||
int hoedown_buffer_prefix(const struct hoedown_buffer *buf, const char *prefix);
|
||||
/* hoedown_buffer_reset: frees internal data of the buffer */
|
||||
void hoedown_buffer_reset(struct hoedown_buffer *);
|
||||
|
||||
/* hoedown_buffer_grow: increasing the allocated size to the given value */
|
||||
int hoedown_buffer_grow(struct hoedown_buffer *, size_t);
|
||||
|
||||
/* hoedown_buffer_put: appends raw data to a buffer */
|
||||
void hoedown_buffer_put(struct hoedown_buffer *, const void *, size_t);
|
||||
|
@ -54,15 +54,15 @@ void hoedown_buffer_puts(struct hoedown_buffer *, const char *);
|
|||
/* hoedown_buffer_putc: appends a single char to a buffer */
|
||||
void hoedown_buffer_putc(struct hoedown_buffer *, int);
|
||||
|
||||
/* hoedown_buffer_release: decrease the reference count and free the buffer if needed */
|
||||
void hoedown_buffer_release(struct hoedown_buffer *);
|
||||
|
||||
/* hoedown_buffer_reset: frees internal data of the buffer */
|
||||
void hoedown_buffer_reset(struct hoedown_buffer *);
|
||||
/* hoedown_buffer_prefix: compare the beginning of a buffer with a string */
|
||||
int hoedown_buffer_prefix(const struct hoedown_buffer *buf, const char *prefix);
|
||||
|
||||
/* hoedown_buffer_slurp: removes a given number of bytes from the head of the array */
|
||||
void hoedown_buffer_slurp(struct hoedown_buffer *, size_t);
|
||||
|
||||
/* hoedown_buffer_cstr: NUL-termination of the string array (making a C-string) */
|
||||
const char *hoedown_buffer_cstr(struct hoedown_buffer *);
|
||||
|
||||
/* hoedown_buffer_printf: formatted printing to a buffer */
|
||||
void hoedown_buffer_printf(struct hoedown_buffer *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
|
|
40
src/html.h
40
src/html.h
|
@ -11,6 +11,26 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
HOEDOWN_HTML_SKIP_HTML = (1 << 0),
|
||||
HOEDOWN_HTML_SKIP_STYLE = (1 << 1),
|
||||
HOEDOWN_HTML_SKIP_IMAGES = (1 << 2),
|
||||
HOEDOWN_HTML_SKIP_LINKS = (1 << 3),
|
||||
HOEDOWN_HTML_EXPAND_TABS = (1 << 4),
|
||||
HOEDOWN_HTML_SAFELINK = (1 << 5),
|
||||
HOEDOWN_HTML_TOC = (1 << 6),
|
||||
HOEDOWN_HTML_HARD_WRAP = (1 << 7),
|
||||
HOEDOWN_HTML_USE_XHTML = (1 << 8),
|
||||
HOEDOWN_HTML_ESCAPE = (1 << 9),
|
||||
HOEDOWN_HTML_PRETTIFY = (1 << 10)
|
||||
} hoedown_html_render_mode;
|
||||
|
||||
typedef enum {
|
||||
HOEDOWN_HTML_TAG_NONE = 0,
|
||||
HOEDOWN_HTML_TAG_OPEN,
|
||||
HOEDOWN_HTML_TAG_CLOSE
|
||||
} hoedown_html_tag;
|
||||
|
||||
struct hoedown_html_renderopt {
|
||||
struct {
|
||||
int header_count;
|
||||
|
@ -25,26 +45,6 @@ struct hoedown_html_renderopt {
|
|||
void (*link_attributes)(struct hoedown_buffer *ob, const struct hoedown_buffer *url, void *self);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
HOEDOWN_HTML_SKIP_HTML = (1 << 0),
|
||||
HOEDOWN_HTML_SKIP_STYLE = (1 << 1),
|
||||
HOEDOWN_HTML_SKIP_IMAGES = (1 << 2),
|
||||
HOEDOWN_HTML_SKIP_LINKS = (1 << 3),
|
||||
HOEDOWN_HTML_EXPAND_TABS = (1 << 4),
|
||||
HOEDOWN_HTML_SAFELINK = (1 << 5),
|
||||
HOEDOWN_HTML_TOC = (1 << 6),
|
||||
HOEDOWN_HTML_HARD_WRAP = (1 << 7),
|
||||
HOEDOWN_HTML_USE_XHTML = (1 << 8),
|
||||
HOEDOWN_HTML_ESCAPE = (1 << 9),
|
||||
HOEDOWN_HTML_PRETTIFY = (1 << 10),
|
||||
} hoedown_html_render_mode;
|
||||
|
||||
typedef enum {
|
||||
HOEDOWN_HTML_TAG_NONE = 0,
|
||||
HOEDOWN_HTML_TAG_OPEN,
|
||||
HOEDOWN_HTML_TAG_CLOSE,
|
||||
} hoedown_html_tag;
|
||||
|
||||
int
|
||||
hoedown_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname);
|
||||
|
||||
|
|
|
@ -66,9 +66,11 @@ word_boundary(uint8_t c)
|
|||
return c == 0 || isspace(c) || ispunct(c);
|
||||
}
|
||||
|
||||
// If 'text' begins with any kind of single quote (e.g. "'" or "'" etc.),
|
||||
// returns the length of the sequence of characters that makes up the single-
|
||||
// quote. Otherwise, returns zero.
|
||||
/*
|
||||
If 'text' begins with any kind of single quote (e.g. "'" or "'" etc.),
|
||||
returns the length of the sequence of characters that makes up the single-
|
||||
quote. Otherwise, returns zero.
|
||||
*/
|
||||
static size_t
|
||||
squote_len(const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -85,7 +87,7 @@ squote_len(const uint8_t *text, size_t size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts " or ' at very beginning or end of a word to left or right quote
|
||||
/* Converts " or ' at very beginning or end of a word to left or right quote */
|
||||
static int
|
||||
smartypants_quotes(struct hoedown_buffer *ob, uint8_t previous_char, uint8_t next_char, uint8_t quote, int *is_open)
|
||||
{
|
||||
|
@ -103,10 +105,12 @@ smartypants_quotes(struct hoedown_buffer *ob, uint8_t previous_char, uint8_t nex
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Converts ' to left or right single quote; but the initial ' might be in
|
||||
// different forms, e.g. ' or ' or '.
|
||||
// 'squote_text' points to the original single quote, and 'squote_size' is its length.
|
||||
// 'text' points at the last character of the single-quote, e.g. ' or ;
|
||||
/*
|
||||
Converts ' to left or right single quote; but the initial ' might be in
|
||||
different forms, e.g. ' or ' or '.
|
||||
'squote_text' points to the original single quote, and 'squote_size' is its length.
|
||||
'text' points at the last character of the single-quote, e.g. ' or ;
|
||||
*/
|
||||
static size_t
|
||||
smartypants_squote(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size,
|
||||
const uint8_t *squote_text, size_t squote_size)
|
||||
|
@ -115,21 +119,21 @@ smartypants_squote(struct hoedown_buffer *ob, struct smartypants_data *smrt, uin
|
|||
uint8_t t1 = tolower(text[1]);
|
||||
size_t next_squote_len = squote_len(text+1, size-1);
|
||||
|
||||
// convert '' to “ or ”
|
||||
/* convert '' to “ or ” */
|
||||
if (next_squote_len > 0) {
|
||||
uint8_t next_char = (size > 1+next_squote_len) ? text[1+next_squote_len] : 0;
|
||||
if (smartypants_quotes(ob, previous_char, next_char, 'd', &smrt->in_dquote))
|
||||
return next_squote_len;
|
||||
}
|
||||
|
||||
// Tom's, isn't, I'm, I'd
|
||||
/* Tom's, isn't, I'm, I'd */
|
||||
if ((t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd') &&
|
||||
(size == 3 || word_boundary(text[2]))) {
|
||||
BUFPUTSL(ob, "’");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// you're, you'll, you've
|
||||
/* you're, you'll, you've */
|
||||
if (size >= 3) {
|
||||
uint8_t t2 = tolower(text[2]);
|
||||
|
||||
|
@ -150,14 +154,14 @@ smartypants_squote(struct hoedown_buffer *ob, struct smartypants_data *smrt, uin
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts ' to left or right single quote.
|
||||
/* Converts ' to left or right single quote. */
|
||||
static size_t
|
||||
smartypants_cb__squote(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
return smartypants_squote(ob, smrt, previous_char, text, size, text, 1);
|
||||
}
|
||||
|
||||
// Converts (c), (r), (tm)
|
||||
/* Converts (c), (r), (tm) */
|
||||
static size_t
|
||||
smartypants_cb__parens(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -185,7 +189,7 @@ smartypants_cb__parens(struct hoedown_buffer *ob, struct smartypants_data *smrt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts "--" to em-dash, etc.
|
||||
/* Converts "--" to em-dash, etc. */
|
||||
static size_t
|
||||
smartypants_cb__dash(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -203,7 +207,7 @@ smartypants_cb__dash(struct hoedown_buffer *ob, struct smartypants_data *smrt, u
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts " etc.
|
||||
/* Converts " etc. */
|
||||
static size_t
|
||||
smartypants_cb__amp(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -225,7 +229,7 @@ smartypants_cb__amp(struct hoedown_buffer *ob, struct smartypants_data *smrt, ui
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts "..." to ellipsis
|
||||
/* Converts "..." to ellipsis */
|
||||
static size_t
|
||||
smartypants_cb__period(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -243,7 +247,7 @@ smartypants_cb__period(struct hoedown_buffer *ob, struct smartypants_data *smrt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts `` to opening double quote
|
||||
/* Converts `` to opening double quote */
|
||||
static size_t
|
||||
smartypants_cb__backtick(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -256,7 +260,7 @@ smartypants_cb__backtick(struct hoedown_buffer *ob, struct smartypants_data *smr
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts 1/2, 1/4, 3/4
|
||||
/* Converts 1/2, 1/4, 3/4 */
|
||||
static size_t
|
||||
smartypants_cb__number(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
@ -289,7 +293,7 @@ smartypants_cb__number(struct hoedown_buffer *ob, struct smartypants_data *smrt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
// Converts " to left or right double quote
|
||||
/* Converts " to left or right double quote */
|
||||
static size_t
|
||||
smartypants_cb__dquote(struct hoedown_buffer *ob, struct smartypants_data *smrt, uint8_t previous_char, const uint8_t *text, size_t size)
|
||||
{
|
||||
|
|
|
@ -234,8 +234,8 @@ free_link_refs(struct link_ref **references)
|
|||
|
||||
while (r) {
|
||||
next = r->next;
|
||||
hoedown_buffer_release(r->link);
|
||||
hoedown_buffer_release(r->title);
|
||||
hoedown_buffer_free(r->link);
|
||||
hoedown_buffer_free(r->title);
|
||||
free(r);
|
||||
r = next;
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ find_footnote_ref(struct footnote_list *list, uint8_t *name, size_t length)
|
|||
static void
|
||||
free_footnote_ref(struct footnote_ref *ref)
|
||||
{
|
||||
hoedown_buffer_release(ref->contents);
|
||||
hoedown_buffer_free(ref->contents);
|
||||
free(ref);
|
||||
}
|
||||
|
||||
|
@ -2771,7 +2771,7 @@ hoedown_markdown_new(
|
|||
void
|
||||
hoedown_markdown_render(struct hoedown_buffer *ob, const uint8_t *document, size_t doc_size, struct hoedown_markdown *md)
|
||||
{
|
||||
static const char UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
|
||||
static const uint8_t UTF8_BOM[] = {0xEF, 0xBB, 0xBF};
|
||||
|
||||
struct hoedown_buffer *text;
|
||||
size_t beg, end;
|
||||
|
@ -2851,7 +2851,7 @@ hoedown_markdown_render(struct hoedown_buffer *ob, const uint8_t *document, size
|
|||
md->cb.doc_footer(ob, md->opaque);
|
||||
|
||||
/* clean-up */
|
||||
hoedown_buffer_release(text);
|
||||
hoedown_buffer_free(text);
|
||||
free_link_refs(md->refs);
|
||||
if (footnotes_enabled) {
|
||||
free_footnote_list(&md->footnotes_found, 1);
|
||||
|
@ -2868,10 +2868,10 @@ hoedown_markdown_free(struct hoedown_markdown *md)
|
|||
size_t i;
|
||||
|
||||
for (i = 0; i < (size_t)md->work_bufs[BUFFER_SPAN].asize; ++i)
|
||||
hoedown_buffer_release(md->work_bufs[BUFFER_SPAN].item[i]);
|
||||
hoedown_buffer_free(md->work_bufs[BUFFER_SPAN].item[i]);
|
||||
|
||||
for (i = 0; i < (size_t)md->work_bufs[BUFFER_BLOCK].asize; ++i)
|
||||
hoedown_buffer_release(md->work_bufs[BUFFER_BLOCK].item[i]);
|
||||
hoedown_buffer_free(md->work_bufs[BUFFER_BLOCK].item[i]);
|
||||
|
||||
hoedown_stack_free(&md->work_bufs[BUFFER_SPAN]);
|
||||
hoedown_stack_free(&md->work_bufs[BUFFER_BLOCK]);
|
||||
|
@ -2882,7 +2882,7 @@ hoedown_markdown_free(struct hoedown_markdown *md)
|
|||
void
|
||||
hoedown_version(int *ver_major, int *ver_minor, int *ver_revision)
|
||||
{
|
||||
*ver_major = HOEDOWN_VER_MAJOR;
|
||||
*ver_minor = HOEDOWN_VER_MINOR;
|
||||
*ver_revision = HOEDOWN_VER_REVISION;
|
||||
*ver_major = HOEDOWN_VERSION_MAJOR;
|
||||
*ver_minor = HOEDOWN_VERSION_MINOR;
|
||||
*ver_revision = HOEDOWN_VERSION_REVISION;
|
||||
}
|
||||
|
|
|
@ -11,9 +11,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define HOEDOWN_VERSION "0.0.1"
|
||||
#define HOEDOWN_VER_MAJOR 0
|
||||
#define HOEDOWN_VER_MINOR 0
|
||||
#define HOEDOWN_VER_REVISION 1
|
||||
#define HOEDOWN_VERSION_MAJOR 0
|
||||
#define HOEDOWN_VERSION_MINOR 0
|
||||
#define HOEDOWN_VERSION_REVISION 1
|
||||
|
||||
/********************
|
||||
* TYPE DEFINITIONS *
|
||||
|
@ -21,9 +21,9 @@ extern "C" {
|
|||
|
||||
/* hoedown_autolink - type of autolink */
|
||||
enum hoedown_autolink {
|
||||
HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/
|
||||
HOEDOWN_AUTOLINK_NORMAL, /* normal http/http/ftp/mailto/etc link */
|
||||
HOEDOWN_AUTOLINK_EMAIL, /* e-mail link without explit mailto: */
|
||||
HOEDOWN_AUTOLINK_NONE, /* used internally when it is not an autolink*/
|
||||
HOEDOWN_AUTOLINK_NORMAL, /* normal http/http/ftp/mailto/etc link */
|
||||
HOEDOWN_AUTOLINK_EMAIL /* e-mail link without explit mailto: */
|
||||
};
|
||||
|
||||
enum hoedown_tableflags {
|
||||
|
@ -101,7 +101,7 @@ struct hoedown_markdown;
|
|||
|
||||
/* list/listitem flags */
|
||||
#define HOEDOWN_LIST_ORDERED 1
|
||||
#define HOEDOWN_LI_BLOCK 2 /* <li> containing block data */
|
||||
#define HOEDOWN_LI_BLOCK 2 /* <li> containing block data */
|
||||
|
||||
/**********************
|
||||
* EXPORTED FUNCTIONS *
|
||||
|
|
70
src/stack.c
70
src/stack.c
|
@ -2,6 +2,32 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
hoedown_stack_new(struct hoedown_stack *st, size_t initial_size)
|
||||
{
|
||||
st->item = NULL;
|
||||
st->size = 0;
|
||||
st->asize = 0;
|
||||
|
||||
if (!initial_size)
|
||||
initial_size = 8;
|
||||
|
||||
return hoedown_stack_grow(st, initial_size);
|
||||
}
|
||||
|
||||
void
|
||||
hoedown_stack_free(struct hoedown_stack *st)
|
||||
{
|
||||
if (!st)
|
||||
return;
|
||||
|
||||
free(st->item);
|
||||
|
||||
st->item = NULL;
|
||||
st->size = 0;
|
||||
st->asize = 0;
|
||||
}
|
||||
|
||||
int
|
||||
hoedown_stack_grow(struct hoedown_stack *st, size_t new_size)
|
||||
{
|
||||
|
@ -26,41 +52,6 @@ hoedown_stack_grow(struct hoedown_stack *st, size_t new_size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
hoedown_stack_free(struct hoedown_stack *st)
|
||||
{
|
||||
if (!st)
|
||||
return;
|
||||
|
||||
free(st->item);
|
||||
|
||||
st->item = NULL;
|
||||
st->size = 0;
|
||||
st->asize = 0;
|
||||
}
|
||||
|
||||
int
|
||||
hoedown_stack_new(struct hoedown_stack *st, size_t initial_size)
|
||||
{
|
||||
st->item = NULL;
|
||||
st->size = 0;
|
||||
st->asize = 0;
|
||||
|
||||
if (!initial_size)
|
||||
initial_size = 8;
|
||||
|
||||
return hoedown_stack_grow(st, initial_size);
|
||||
}
|
||||
|
||||
void *
|
||||
hoedown_stack_pop(struct hoedown_stack *st)
|
||||
{
|
||||
if (!st->size)
|
||||
return NULL;
|
||||
|
||||
return st->item[--st->size];
|
||||
}
|
||||
|
||||
int
|
||||
hoedown_stack_push(struct hoedown_stack *st, void *item)
|
||||
{
|
||||
|
@ -71,6 +62,15 @@ hoedown_stack_push(struct hoedown_stack *st, void *item)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
hoedown_stack_pop(struct hoedown_stack *st)
|
||||
{
|
||||
if (!st->size)
|
||||
return NULL;
|
||||
|
||||
return st->item[--st->size];
|
||||
}
|
||||
|
||||
void *
|
||||
hoedown_stack_top(struct hoedown_stack *st)
|
||||
{
|
||||
|
|
|
@ -15,12 +15,10 @@ struct hoedown_stack {
|
|||
size_t asize;
|
||||
};
|
||||
|
||||
int hoedown_stack_new(struct hoedown_stack *, size_t);
|
||||
void hoedown_stack_free(struct hoedown_stack *);
|
||||
int hoedown_stack_grow(struct hoedown_stack *, size_t);
|
||||
int hoedown_stack_new(struct hoedown_stack *, size_t);
|
||||
|
||||
int hoedown_stack_push(struct hoedown_stack *, void *);
|
||||
|
||||
void *hoedown_stack_pop(struct hoedown_stack *);
|
||||
void *hoedown_stack_top(struct hoedown_stack *);
|
||||
|
||||
|
|
Loading…
Reference in a new issue