-/* $Id: libmdocml.c,v 1.8 2008/11/24 08:50:33 kristaps Exp $ */
+/* $Id: libmdocml.c,v 1.16 2008/11/30 21:41:35 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <assert.h>
+#include <ctype.h>
#include <fcntl.h>
#include <err.h>
#include <stdio.h>
}
-static int
-md_buf_flush(struct md_mbuf *buf)
+static int md_buf_flush(struct md_mbuf *buf)
{
ssize_t sz;
int
md_buf_putchar(struct md_mbuf *buf, char c)
{
+
+ assert(buf);
return(md_buf_puts(buf, &c, 1));
}
int
md_buf_putstring(struct md_mbuf *buf, const char *p)
{
+
+ assert(buf);
return(md_buf_puts(buf, p, strlen(p)));
}
/* Run exiters. */
switch (args->type) {
case (MD_HTML4_STRICT):
- if ( ! md_exit_html4_strict(args, mbuf, rbuf, c, data))
- return(-1);
- break;
- case (MD_DUMMY):
+ if ( ! md_exit_html4_strict(data, -1 == c ? 0 : 1))
+ c = -1;
break;
default:
- abort();
+ if ( ! md_exit_xml(data, -1 == c ? 0 : 1))
+ c = -1;
+ break;
}
/* Make final flush of buffer. */
fp = md_line_html4_strict;
break;
default:
- fp = md_line_dummy;
+ fp = md_line_xml;
break;
}
return(md_run_leave(args, mbuf, rbuf, 0, p));
for (i = 0; i < sz; i++) {
+ /*
+ if ( ! isascii(rbuf->buf[i])) {
+ warnx("%s: non-ascii char (line %zu, col %zu)",
+ rbuf->name, rbuf->line, pos);
+ return(md_run_leave(args, mbuf, rbuf, -1, p));
+ }
+ */
if ('\n' != rbuf->buf[i]) {
if (pos < BUFFER_LINE) {
/* LINTED */
return(md_run_leave(args, mbuf, rbuf, -1, p));
}
- line[pos] = 0;
- if ( ! (*fp)(args, mbuf, rbuf, line, pos, p))
+ line[(int)pos] = 0;
+ if ( ! (*fp)(p, line))
return(md_run_leave(args, mbuf, rbuf, -1, p));
rbuf->line++;
pos = 0;
mbuf.pos = 0;
rbuf.line = 1;
- data = NULL;
/* Run initialisers. */
switch (args->type) {
case (MD_HTML4_STRICT):
- if ( ! md_init_html4_strict(args, &mbuf, &rbuf, &data))
- return(-1);
- break;
- case (MD_DUMMY):
+ data = md_init_html4_strict
+ (args, &mbuf, &rbuf);
break;
default:
- abort();
+ data = md_init_xml(args, &mbuf, &rbuf);
+ break;
}
/* Go into mainline. */