diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/select/Makefile | 2 | ||||
-rw-r--r-- | src/select/dispatch.c | 2 | ||||
-rw-r--r-- | src/select/properties/properties.c (renamed from src/select/properties.c) | 2 | ||||
-rw-r--r-- | src/select/properties/properties.h (renamed from src/select/properties.h) | 0 | ||||
-rw-r--r-- | src/stylesheet.c | 85 | ||||
-rw-r--r-- | src/stylesheet.h | 8 |
6 files changed, 96 insertions, 3 deletions
diff --git a/src/select/Makefile b/src/select/Makefile index 0fe1a5e..db1c4e6 100644 --- a/src/select/Makefile +++ b/src/select/Makefile @@ -1,4 +1,4 @@ # Sources -DIR_SOURCES := computed.c dispatch.c hash.c properties.c select.c +DIR_SOURCES := computed.c dispatch.c hash.c select.c include build/makefiles/Makefile.subdir diff --git a/src/select/dispatch.c b/src/select/dispatch.c index a0ac4aa..aee6175 100644 --- a/src/select/dispatch.c +++ b/src/select/dispatch.c @@ -6,7 +6,7 @@ */ #include "select/dispatch.h" -#include "select/properties.h" +#include "select/properties/properties.h" /** * Dispatch table for properties, indexed by opcode diff --git a/src/select/properties.c b/src/select/properties/properties.c index 58d94aa..a0d1a18 100644 --- a/src/select/properties.c +++ b/src/select/properties/properties.c @@ -9,7 +9,7 @@ #include "bytecode/bytecode.h" #include "bytecode/opcodes.h" -#include "select/properties.h" +#include "select/properties/properties.h" #include "select/propget.h" #include "select/propset.h" #include "utils/utils.h" diff --git a/src/select/properties.h b/src/select/properties/properties.h index 0d9cd72..0d9cd72 100644 --- a/src/select/properties.h +++ b/src/select/properties/properties.h diff --git a/src/stylesheet.c b/src/stylesheet.c index f2bb81a..406288e 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -20,6 +20,82 @@ static css_error _remove_selectors(css_stylesheet *sheet, css_rule *rule); static size_t _rule_size(const css_rule *rule); /** + * Add a string to a stylesheets string vector. + * + * \param sheet The stylesheet to add string to. + * \param string The string to add. + * \param string_number Pointer to location to recive string number. + * \return CSS_OK on success, + * CSS_BADPARM on bad parameters, + * CSS_NOMEM on memory exhaustion + * + */ +css_error css_stylesheet_string_add(css_stylesheet *sheet, lwc_string *string, uint32_t *string_number) +{ + uint32_t new_string_number; /* The string number count */ + + /* search for the string in the existing vector */ + for (new_string_number = 0; + new_string_number < sheet->string_vector_c; + new_string_number++) { + lwc_error res; + bool isequal; + res = lwc_string_isequal(string, + sheet->string_vector[new_string_number], + &isequal); + if (isequal) { + lwc_string_unref(string); + *string_number = new_string_number; + return CSS_OK; + } + + } + + /* string does not exist in current vector, add a new one */ + + if (sheet->string_vector_c >= sheet->string_vector_l) { + /* additional storage must be allocated to deal with + * this request. + */ + lwc_string **new_vector; + uint32_t new_vector_len; + + new_vector_len = sheet->string_vector_l + 256; + new_vector = sheet->alloc(sheet->string_vector, new_vector_len * sizeof(lwc_string *), sheet->pw); + + if (new_vector == NULL) { + return CSS_NOMEM; + } + sheet->string_vector = new_vector; + sheet->string_vector_l = new_vector_len; + } + + sheet->string_vector_c++; + sheet->string_vector[new_string_number] = string; + *string_number = new_string_number; + return CSS_OK; +} + +/** + * Get a string from a stylesheets string vector. + * + * \param sheet The stylesheet to retrive string from. + * \param string_number The string number to retrive. + * \param string Pointer to location to recive string. + * \return CSS_OK on success, + * CSS_BADPARM on bad parameters, + */ +css_error css_stylesheet_string_get(css_stylesheet *sheet, uint32_t string_number, lwc_string **string) +{ + if (string_number > sheet->string_vector_c) { + return CSS_BADPARM; + } + + *string = sheet->string_vector[string_number]; + return CSS_OK; +} + +/** * Create a stylesheet * * \param level The language level of the stylesheet @@ -161,6 +237,7 @@ css_error css_stylesheet_create(css_language_level level, */ css_error css_stylesheet_destroy(css_stylesheet *sheet) { + uint32_t string_index; uint32_t bucket; css_rule *r, *s; @@ -203,6 +280,14 @@ css_error css_stylesheet_destroy(css_stylesheet *sheet) if (sheet->parser != NULL) css_parser_destroy(sheet->parser); + /* destroy string vector */ + for (string_index = 0; + string_index < sheet->string_vector_c; + string_index++) { + lwc_string_unref(sheet->string_vector[string_index]); + } + sheet->alloc(sheet->string_vector, 0, sheet->pw); + sheet->alloc(sheet, 0, sheet->pw); return CSS_OK; diff --git a/src/stylesheet.h b/src/stylesheet.h index fbd76b0..e8feea9 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -178,6 +178,10 @@ struct css_stylesheet { css_allocator_fn alloc; /**< Allocation function */ void *pw; /**< Private word */ + + lwc_string **string_vector; /**< Bytecode string vector */ + uint32_t string_vector_l; /**< The string vector allocated length in entries */ + uint32_t string_vector_c; /**< The number of string vector entries used */ }; css_error css_stylesheet_style_create(css_stylesheet *sheet, uint32_t len, @@ -227,5 +231,9 @@ css_error css_stylesheet_add_rule(css_stylesheet *sheet, css_rule *rule, css_rule *parent); css_error css_stylesheet_remove_rule(css_stylesheet *sheet, css_rule *rule); +css_error css_stylesheet_string_get(css_stylesheet *sheet, uint32_t string_number, lwc_string **string); + +css_error css_stylesheet_string_add(css_stylesheet *sheet, lwc_string *string, uint32_t *string_number); + #endif |