summaryrefslogtreecommitdiff
path: root/src/scanners.h
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-09-29 22:59:46 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-09-29 22:59:46 -0700
commitd9f7581443bd786e7d17532f6678efd2ee77c26f (patch)
tree831a33dc8990e3b85ea068b361750702f8e3f40a /src/scanners.h
parentde1e28217f0da80b928bca0ca09541c0401314ee (diff)
parentc006aececef112f61dd44cad43f0596221f29700 (diff)
Merge branch 'master' into newemphasis
Conflicts: Makefile js/stmd.js
Diffstat (limited to 'src/scanners.h')
-rw-r--r--src/scanners.h57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/scanners.h b/src/scanners.h
index 71e0520..785d424 100644
--- a/src/scanners.h
+++ b/src/scanners.h
@@ -1,15 +1,42 @@
-#include "bstrlib.h"
-
-int scan_autolink_uri(bstring s, int pos);
-int scan_autolink_email(bstring s, int pos);
-int scan_html_tag(bstring s, int pos);
-int scan_html_block_tag(bstring s, int pos);
-int scan_link_url(bstring s, int pos);
-int scan_link_title(bstring s, int pos);
-int scan_spacechars(bstring s, int pos);
-int scan_atx_header_start(bstring s, int pos);
-int scan_setext_header_line(bstring s, int pos);
-int scan_hrule(bstring s, int pos);
-int scan_open_code_fence(bstring s, int pos);
-int scan_close_code_fence(bstring s, int pos, int len);
-int scan_entity(bstring s, int pos);
+#include "stmd.h"
+
+extern int _scan_autolink_uri(const unsigned char *p);
+extern int _scan_autolink_email(const unsigned char *p);
+extern int _scan_html_tag(const unsigned char *p);
+extern int _scan_html_block_tag(const unsigned char *p);
+extern int _scan_link_url(const unsigned char *p);
+extern int _scan_link_title(const unsigned char *p);
+extern int _scan_spacechars(const unsigned char *p);
+extern int _scan_atx_header_start(const unsigned char *p);
+extern int _scan_setext_header_line(const unsigned char *p);
+extern int _scan_hrule(const unsigned char *p);
+extern int _scan_open_code_fence(const unsigned char *p);
+extern int _scan_close_code_fence(const unsigned char *p);
+extern int _scan_entity(const unsigned char *p);
+
+static int scan_at(int (*scanner)(const unsigned char *), chunk *c, int offset)
+{
+ int res;
+ unsigned char *ptr = (unsigned char *)c->data;
+ unsigned char lim = ptr[c->len];
+
+ ptr[c->len] = '\0';
+ res = scanner(ptr + offset);
+ ptr[c->len] = lim;
+
+ return res;
+}
+
+#define scan_autolink_uri(c, n) scan_at(&_scan_autolink_uri, c, n)
+#define scan_autolink_email(c, n) scan_at(&_scan_autolink_email, c, n)
+#define scan_html_tag(c, n) scan_at(&_scan_html_tag, c, n)
+#define scan_html_block_tag(c, n) scan_at(&_scan_html_block_tag, c, n)
+#define scan_link_url(c, n) scan_at(&_scan_link_url, c, n)
+#define scan_link_title(c, n) scan_at(&_scan_link_title, c, n)
+#define scan_spacechars(c, n) scan_at(&_scan_spacechars, c, n)
+#define scan_atx_header_start(c, n) scan_at(&_scan_atx_header_start, c, n)
+#define scan_setext_header_line(c, n) scan_at(&_scan_setext_header_line, c, n)
+#define scan_hrule(c, n) scan_at(&_scan_hrule, c, n)
+#define scan_open_code_fence(c, n) scan_at(&_scan_open_code_fence, c, n)
+#define scan_close_code_fence(c, n) scan_at(&_scan_close_code_fence, c, n)
+#define scan_entity(c, n) scan_at(&_scan_entity, c, n)