summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-07-30 23:53:26 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-07-30 23:53:26 +0000
commite3afbca5b4a25d07d3cd32b16ecb0f7401c46109 (patch)
tree0d780e13075007acdc20306a6d79ea07080b01f3 /test
parent8e5933fc5491f95160e7a2417d575d12186c59a1 (diff)
downloadlibcss-e3afbca5b4a25d07d3cd32b16ecb0f7401c46109.tar.gz
libcss-e3afbca5b4a25d07d3cd32b16ecb0f7401c46109.tar.bz2
Generate and emit events
svn path=/trunk/libcss/; revision=4828
Diffstat (limited to 'test')
-rw-r--r--test/parse.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parse.c b/test/parse.c
index f24aa76..567c8c4 100644
--- a/test/parse.c
+++ b/test/parse.c
@@ -6,6 +6,7 @@
#include "charset/detect.h"
#include "utils/utils.h"
+#include "lex/lex.h"
#include "parse/parse.h"
#include "testutils.h"
@@ -17,8 +18,40 @@ static void *myrealloc(void *ptr, size_t len, void *pw)
return realloc(ptr, len);
}
+static bool event_handler(css_parser_event type,
+ const parserutils_vector *tokens, void *pw)
+{
+ int32_t ctx = 0;
+ const css_token *token;
+
+ UNUSED(pw);
+
+ printf("%s%d", tokens != NULL ? " " : "", type);
+
+ if (tokens == NULL) {
+ printf("\n");
+ return true;
+ }
+
+ do {
+ token = parserutils_vector_iterate(tokens, &ctx);
+ if (token == NULL)
+ break;
+
+ printf("\n %d", token->type);
+
+ if (token->data.ptr != NULL)
+ printf(" %.*s", token->data.len, token->data.ptr);
+ } while (token != NULL);
+
+ printf("\n");
+
+ return true;
+}
+
int main(int argc, char **argv)
{
+ css_parser_optparams params;
css_parser *parser;
FILE *fp;
size_t len, origlen;
@@ -38,6 +71,11 @@ int main(int argc, char **argv)
"UTF-8", CSS_CHARSET_DICTATED, myrealloc, NULL);
assert(parser != NULL);
+ params.event_handler.handler = event_handler;
+ params.event_handler.pw = NULL;
+ assert(css_parser_setopt(parser, CSS_PARSER_EVENT_HANDLER,
+ &params) == CSS_OK);
+
fp = fopen(argv[2], "rb");
if (fp == NULL) {
printf("Failed opening %s\n", argv[2]);