From 72c39e3522c5781d1e7dc8abad77d96141c5d49b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 1 May 2008 16:36:27 +0000 Subject: Import beginnings of a CSS parsing library. Currently comprises a lexer. svn path=/trunk/libcss/; revision=4112 --- include/libcss/errors.h | 31 +++++++++++++++++++++++++++++++ include/libcss/functypes.h | 27 +++++++++++++++++++++++++++ include/libcss/libcss.h | 23 +++++++++++++++++++++++ include/libcss/types.h | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 include/libcss/errors.h create mode 100644 include/libcss/functypes.h create mode 100644 include/libcss/libcss.h create mode 100644 include/libcss/types.h (limited to 'include') diff --git a/include/libcss/errors.h b/include/libcss/errors.h new file mode 100644 index 0000000..f7eeba2 --- /dev/null +++ b/include/libcss/errors.h @@ -0,0 +1,31 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2007 John-Mark Bell + */ + +#ifndef css_errors_h_ +#define css_errors_h_ + +#include + +typedef enum css_error { + CSS_OK = 0, + + CSS_NOMEM = 1, + CSS_BADPARM = 2, + CSS_INVALID = 3, + CSS_FILENOTFOUND = 4, + CSS_NEEDDATA = 5, + CSS_BADCHARSET = 6, + CSS_EOF = 7, +} css_error; + +/* Convert a libcss error value to a string */ +const char *css_error_to_string(css_error error); +/* Convert a string to a libcss error value */ +css_error css_error_from_string(const char *str, size_t len); + +#endif + diff --git a/include/libcss/functypes.h b/include/libcss/functypes.h new file mode 100644 index 0000000..22a48bf --- /dev/null +++ b/include/libcss/functypes.h @@ -0,0 +1,27 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2007-8 John-Mark Bell + */ + +#ifndef css_functypes_h_ +#define css_functypes_h_ + +#include +#include +#include + +#include + +/* Type of allocation function for libcss */ +typedef void *(*css_alloc)(void *ptr, size_t size, void *pw); + +/** + * Type of parse error handling function + */ +typedef void (*css_error_handler)(uint32_t line, uint32_t col, + const char *message, void *pw); + +#endif + diff --git a/include/libcss/libcss.h b/include/libcss/libcss.h new file mode 100644 index 0000000..364a3eb --- /dev/null +++ b/include/libcss/libcss.h @@ -0,0 +1,23 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2007 John-Mark Bell + */ + +#ifndef css_h_ +#define css_h_ + +#include +#include +#include + +/* Initialise the CSS library for use */ +css_error css_initialise(const char *aliases_file, + css_alloc alloc, void *pw); + +/* Clean up after LibCSS */ +css_error css_finalise(css_alloc alloc, void *pw); + +#endif + diff --git a/include/libcss/types.h b/include/libcss/types.h new file mode 100644 index 0000000..b3e18dc --- /dev/null +++ b/include/libcss/types.h @@ -0,0 +1,33 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2007 John-Mark Bell + */ + +#ifndef css_types_h_ +#define css_types_h_ + +#include +#include + +/** Source of charset information, in order of importance + * A client-dictated charset will override all others. + * A document-specified charset will override autodetection or the default */ +typedef enum css_charset_source { + CSS_CHARSET_DEFAULT = 0, /**< Default setting */ + CSS_CHARSET_REFERRED = 1, /**< From referring document */ + CSS_CHARSET_METADATA = 2, /**< From linking metadata */ + CSS_CHARSET_DOCUMENT = 3, /**< Defined in document */ + CSS_CHARSET_DICTATED = 4, /**< Dictated by client */ +} css_charset_source; + +/** + * String type + */ +typedef struct css_string { + uint8_t *ptr; /**< Pointer to data */ + size_t len; /**< Byte length of string */ +} css_string; + +#endif -- cgit v1.2.3