summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse/Makefile2
-rw-r--r--src/parse/css21.c96
-rw-r--r--src/parse/css21.h25
-rw-r--r--src/parse/parse.c10
-rw-r--r--src/parse/parse.h5
5 files changed, 128 insertions, 10 deletions
diff --git a/src/parse/Makefile b/src/parse/Makefile
index 9e1c6dd..fc27e8e 100644
--- a/src/parse/Makefile
+++ b/src/parse/Makefile
@@ -35,7 +35,7 @@ d := $(DIR)
CFLAGS := $(CFLAGS) -I$(d)
# Sources
-SRCS_$(d) := parse.c
+SRCS_$(d) := parse.c css21.c
# Append to sources for component
SOURCES += $(addprefix $(d), $(SRCS_$(d)))
diff --git a/src/parse/css21.c b/src/parse/css21.c
new file mode 100644
index 0000000..63e8df7
--- /dev/null
+++ b/src/parse/css21.c
@@ -0,0 +1,96 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#include "parse/css21.h"
+#include "parse/parse.h"
+
+#include "utils/utils.h"
+
+/**
+ * Context for a CSS 2.1 parser
+ */
+struct css_css21 {
+ css_stylesheet *sheet; /**< The stylesheet to parse for */
+ css_parser *parser; /**< The underlying core parser */
+
+ css_alloc alloc; /**< Memory (de)allocation function */
+ void *pw; /**< Client's private data */
+};
+
+static bool css21_handle_event(css_parser_event type,
+ const parserutils_vector *tokens, void *pw);
+
+/**
+ * Create a CSS 2.1 parser
+ *
+ * \param sheet The stylesheet object to parse for
+ * \param parser The core parser object to use
+ * \param alloc Memory (de)allocation function
+ * \param pw Pointer to client-specific private data
+ * \return Pointer to parser object, or NULL on failure
+ */
+css_css21 *css_css21_create(css_stylesheet *sheet, css_parser *parser,
+ css_alloc alloc, void *pw)
+{
+ css_css21 *css21;
+ css_parser_optparams params;
+ css_error error;
+
+ if (sheet == NULL || parser == NULL || alloc == NULL)
+ return NULL;
+
+ css21 = alloc(NULL, sizeof(css_css21), pw);
+ if (css21 == NULL)
+ return NULL;
+
+ params.event_handler.handler = css21_handle_event;
+ params.event_handler.pw = css21;
+ error = css_parser_setopt(parser, CSS_PARSER_EVENT_HANDLER, &params);
+ if (error != CSS_OK) {
+ alloc(css21, 0, pw);
+ return NULL;
+ }
+
+ css21->sheet = sheet;
+ css21->parser = parser;
+ css21->alloc = alloc;
+ css21->pw = pw;
+
+ return css21;
+}
+
+/**
+ * Destroy a CSS 2.1 parser
+ *
+ * \param css21 The parser to destroy
+ */
+void css_css21_destroy(css_css21 *css21)
+{
+ if (css21 == NULL)
+ return;
+
+ css21->alloc(css21, 0, css21->pw);
+}
+
+/**
+ * Handler for core parser events
+ *
+ * \param type The event type
+ * \param tokens Vector of tokens read since last event, or NULL
+ * \param pw Pointer to handler context
+ * \return False to signal parse error, true otherwise
+ */
+bool css21_handle_event(css_parser_event type, const parserutils_vector *tokens,
+ void *pw)
+{
+ UNUSED(type);
+ UNUSED(tokens);
+ UNUSED(pw);
+
+ return true;
+}
+
diff --git a/src/parse/css21.h b/src/parse/css21.h
new file mode 100644
index 0000000..c1b1fda
--- /dev/null
+++ b/src/parse/css21.h
@@ -0,0 +1,25 @@
+/*
+ * This file is part of LibCSS.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
+ */
+
+#ifndef css_parse_css21_h_
+#define css_parse_css21_h_
+
+#include <parserutils/utils/vector.h>
+
+#include <libcss/functypes.h>
+#include <libcss/types.h>
+
+#include "parse/parse.h"
+
+typedef struct css_css21 css_css21;
+
+css_css21 *css_css21_create(css_stylesheet *sheet, css_parser *parser,
+ css_alloc alloc, void *pw);
+void css_css21_destroy(css_css21 *css21);
+
+#endif
+
diff --git a/src/parse/parse.c b/src/parse/parse.c
index dedccae..e19bd15 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -78,8 +78,6 @@ typedef struct parser_state
*/
struct css_parser
{
- css_stylesheet *sheet; /**< The sheet we're parsing */
-
parserutils_inputstream *stream; /**< The inputstream */
css_lexer *lexer; /**< The lexer to use */
@@ -171,21 +169,20 @@ static css_error (*parseFuncs[])(css_parser *parser) = {
/**
* Create a CSS parser
*
- * \param sheet The sheet to parse data for
* \param charset Charset of data, if known, or NULL
* \param cs_source Source of charset information, or CSS_CHARSET_DEFAULT
* \param alloc Memory (de)allocation function
* \param pw Pointer to client-specific private data
* \return Pointer to parser instance, or NULL on memory exhaustion
*/
-css_parser *css_parser_create(css_stylesheet *sheet, const char *charset,
- css_charset_source cs_source, css_alloc alloc, void *pw)
+css_parser *css_parser_create(const char *charset, css_charset_source cs_source,
+ css_alloc alloc, void *pw)
{
css_parser *parser;
parser_state initial = { sStart, 0 };
parserutils_error perror;
- if (sheet == NULL || alloc == NULL)
+ if (alloc == NULL)
return NULL;
parser = alloc(NULL, sizeof(css_parser), pw);
@@ -259,7 +256,6 @@ css_parser *css_parser_create(css_stylesheet *sheet, const char *charset,
return NULL;
}
- parser->sheet = sheet;
parser->quirks = false;
parser->pushback = NULL;
parser->parseError = false;
diff --git a/src/parse/parse.h b/src/parse/parse.h
index c1b6830..4137c65 100644
--- a/src/parse/parse.h
+++ b/src/parse/parse.h
@@ -10,6 +10,7 @@
#include <parserutils/utils/vector.h>
+#include <libcss/errors.h>
#include <libcss/functypes.h>
#include <libcss/types.h>
@@ -55,8 +56,8 @@ typedef union css_parser_optparams {
} event_handler;
} css_parser_optparams;
-css_parser *css_parser_create(css_stylesheet *sheet, const char *charset,
- css_charset_source cs_source, css_alloc alloc, void *pw);
+css_parser *css_parser_create(const char *charset, css_charset_source cs_source,
+ css_alloc alloc, void *pw);
void css_parser_destroy(css_parser *parser);
css_error css_parser_setopt(css_parser *parser, css_parser_opttype type,