Skip to content

Commit

Permalink
Overhaul how metadata is handled. Instead of extracting metadata duri…
Browse files Browse the repository at this point in the history
…ng parse

and needing to separately escape and smartypants it, have the renderer fill in
a queue of metadata when it renders.  This considerably simplifies areas of the
code.  The smartypants code now doesn't need separate considerations for buffers,
as the metadata values are just normal text nodes.

In doing so, the existing smartypants mechanism can be completely unhooked.

While here, extensively simplify the renderers with regard to superfluous
checks for whether buffers are NULL or empty (they're never NULL), left-over
integer return values, and style(9).
  • Loading branch information
kristapsdz committed Jan 22, 2020
1 parent bf0e1cb commit 524f94c
Show file tree
Hide file tree
Showing 14 changed files with 807 additions and 888 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ OBJS = autolink.o \
entity.o \
html.o \
html_escape.o \
html_smartypants.o \
library.o \
libdiff.o \
log.o \
nroff.o \
nroff_escape.o \
nroff_smartypants.o \
smartypants.o \
term.o \
tree.o \
Expand Down
25 changes: 23 additions & 2 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ hbuf_truncate(hbuf *buf)
buf->size = 0;
}

int
hbuf_streq(const hbuf *buf1, const char *buf2)
{
size_t sz;

sz = strlen(buf2);
return buf1->size == sz &&
memcmp(buf1->data, buf2, sz) == 0;
}

int
hbuf_eq(const hbuf *buf1, const hbuf *buf2)
{

return(buf1->size == buf2->size &&
0 == memcmp(buf1->data, buf2->data, buf1->size));
return buf1->size == buf2->size &&
memcmp(buf1->data, buf2->data, buf1->size) == 0;
}

/*
Expand Down Expand Up @@ -140,6 +150,14 @@ hbuf_grow(hbuf *buf, size_t neosz)
buf->asize = neoasz;
}

void
hbuf_putb(hbuf *buf, const hbuf *b)
{

if (b != NULL)
hbuf_put(buf, b->data, b->size);
}

/*
* Append raw data to a buffer.
* May not be NULL.
Expand All @@ -150,6 +168,9 @@ hbuf_put(hbuf *buf, const char *data, size_t size)
{
assert(buf && buf->unit);

if (data == NULL || size == 0)
return;

if (buf->size + size > buf->asize)
hbuf_grow(buf, buf->size + size);

Expand Down
18 changes: 4 additions & 14 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static const char *const names[LOWDOWN__MAX] = {
"LOWDOWN_ENTITY", /* LOWDOWN_ENTITY */
"LOWDOWN_NORMAL_TEXT", /* LOWDOWN_NORMAL_TEXT */
"LOWDOWN_DOC_HEADER", /* LOWDOWN_DOC_HEADER */
"LOWDOWN_META", /* LOWDOWN_META */
"LOWDOWN_DOC_FOOTER", /* LOWDOWN_DOC_FOOTER */
};
#endif
Expand Down Expand Up @@ -601,20 +602,9 @@ node_clone(const struct lowdown_node *v, size_t id)
n->id = id;

switch (n->type) {
case LOWDOWN_DOC_HEADER:
n->rndr_doc_header.msz =
v->rndr_doc_header.msz;
if (0 == n->rndr_doc_header.msz)
break;
n->rndr_doc_header.m = xcalloc
(v->rndr_doc_header.msz,
sizeof(struct lowdown_meta));
for (i = 0; i < n->rndr_doc_header.msz; i++) {
n->rndr_doc_header.m[i].key = xstrdup
(v->rndr_doc_header.m[i].key);
n->rndr_doc_header.m[i].value = xstrdup
(v->rndr_doc_header.m[i].value);
}
case LOWDOWN_META:
hbuf_clone(&v->rndr_meta.key,
&n->rndr_meta.key);
break;
case LOWDOWN_LIST:
n->rndr_list.flags = v->rndr_list.flags;
Expand Down
Loading

0 comments on commit 524f94c

Please sign in to comment.