diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-06-25 23:24:58 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-06-25 23:24:58 +0000 |
commit | 887bbbed68b8a496a1c2b3d085540ce8b4da3263 (patch) | |
tree | 34115a0edde4e4712668e36f50457a96702ee1a9 /src/parse | |
parent | 2bc03416cd99fa9a4b8f8b7122ebe9907c21dc9b (diff) | |
download | libcss-887bbbed68b8a496a1c2b3d085540ce8b4da3263.tar.gz libcss-887bbbed68b8a496a1c2b3d085540ce8b4da3263.tar.bz2 |
Documentation and context recovery on error
svn path=/trunk/libcss/; revision=8000
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/properties/page.c | 151 |
1 files changed, 132 insertions, 19 deletions
diff --git a/src/parse/properties/page.c b/src/parse/properties/page.c index 49031cf..e2fdcf2 100644 --- a/src/parse/properties/page.c +++ b/src/parse/properties/page.c @@ -12,10 +12,25 @@ #include "parse/properties/properties.h" #include "parse/properties/utils.h" +/** + * Parse orphans + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not valid + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_orphans(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *token; uint8_t flags = 0; @@ -27,8 +42,10 @@ css_error parse_orphans(css_language *c, /* <integer> | IDENT (inherit) */ token = parserutils_vector_iterate(vector, ctx); if (token == NULL || (token->type != CSS_TOKEN_IDENT && - token->type != CSS_TOKEN_NUMBER)) + token->type != CSS_TOKEN_NUMBER)) { + *ctx = orig_ctx; return CSS_INVALID; + } if (token->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -36,16 +53,22 @@ css_error parse_orphans(css_language *c, size_t consumed = 0; num = number_from_lwc_string(token->ilower, true, &consumed); /* Invalid if there are trailing characters */ - if (consumed != lwc_string_length(token->ilower)) + if (consumed != lwc_string_length(token->ilower)) { + *ctx = orig_ctx; return CSS_INVALID; + } /* Negative values are nonsensical */ - if (num < 0) + if (num < 0) { + *ctx = orig_ctx; return CSS_INVALID; + } value = ORPHANS_SET; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_ORPHANS, flags, value); @@ -55,8 +78,10 @@ css_error parse_orphans(css_language *c, /* Allocate result */ error = css_stylesheet_style_create(c->sheet, required_size, result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); @@ -68,10 +93,25 @@ css_error parse_orphans(css_language *c, return CSS_OK; } +/** + * Parse page-break-after + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not valid + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_page_break_after(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *ident; uint8_t flags = 0; @@ -80,8 +120,10 @@ css_error parse_page_break_after(css_language *c, /* IDENT (auto, always, avoid, left, right, inherit) */ ident = parserutils_vector_iterate(vector, ctx); - if (ident == NULL || ident->type != CSS_TOKEN_IDENT) + if (ident == NULL || ident->type != CSS_TOKEN_IDENT) { + *ctx = orig_ctx; return CSS_INVALID; + } if (ident->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -95,15 +137,19 @@ css_error parse_page_break_after(css_language *c, value = PAGE_BREAK_AFTER_LEFT; } else if (ident->ilower == c->strings[RIGHT]) { value = PAGE_BREAK_AFTER_RIGHT; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_PAGE_BREAK_AFTER, flags, value); /* Allocate result */ error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); @@ -111,10 +157,25 @@ css_error parse_page_break_after(css_language *c, return CSS_OK; } +/** + * Parse page-break-before + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not valid + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_page_break_before(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *ident; uint8_t flags = 0; @@ -123,8 +184,10 @@ css_error parse_page_break_before(css_language *c, /* IDENT (auto, always, avoid, left, right, inherit) */ ident = parserutils_vector_iterate(vector, ctx); - if (ident == NULL || ident->type != CSS_TOKEN_IDENT) + if (ident == NULL || ident->type != CSS_TOKEN_IDENT) { + *ctx = orig_ctx; return CSS_INVALID; + } if (ident->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -138,15 +201,19 @@ css_error parse_page_break_before(css_language *c, value = PAGE_BREAK_BEFORE_LEFT; } else if (ident->ilower == c->strings[RIGHT]) { value = PAGE_BREAK_BEFORE_RIGHT; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_PAGE_BREAK_BEFORE, flags, value); /* Allocate result */ error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); @@ -154,10 +221,25 @@ css_error parse_page_break_before(css_language *c, return CSS_OK; } +/** + * Parse page-break-inside + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not valid + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_page_break_inside(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *ident; uint8_t flags = 0; @@ -166,8 +248,10 @@ css_error parse_page_break_inside(css_language *c, /* IDENT (auto, avoid, inherit) */ ident = parserutils_vector_iterate(vector, ctx); - if (ident == NULL || ident->type != CSS_TOKEN_IDENT) + if (ident == NULL || ident->type != CSS_TOKEN_IDENT) { + *ctx = orig_ctx; return CSS_INVALID; + } if (ident->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -175,15 +259,19 @@ css_error parse_page_break_inside(css_language *c, value = PAGE_BREAK_INSIDE_AUTO; } else if (ident->ilower == c->strings[AVOID]) { value = PAGE_BREAK_INSIDE_AVOID; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_PAGE_BREAK_INSIDE, flags, value); /* Allocate result */ error = css_stylesheet_style_create(c->sheet, sizeof(opv), result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); @@ -191,10 +279,25 @@ css_error parse_page_break_inside(css_language *c, return CSS_OK; } +/** + * Parse widows + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param result Pointer to location to receive resulting style + * \return CSS_OK on success, + * CSS_NOMEM on memory exhaustion, + * CSS_INVALID if the input is not valid + * + * Post condition: \a *ctx is updated with the next token to process + * If the input is invalid, then \a *ctx remains unchanged. + */ css_error parse_widows(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *token; uint8_t flags = 0; @@ -206,8 +309,10 @@ css_error parse_widows(css_language *c, /* <integer> | IDENT (inherit) */ token = parserutils_vector_iterate(vector, ctx); if (token == NULL || (token->type != CSS_TOKEN_IDENT && - token->type != CSS_TOKEN_NUMBER)) + token->type != CSS_TOKEN_NUMBER)) { + *ctx = orig_ctx; return CSS_INVALID; + } if (token->ilower == c->strings[INHERIT]) { flags |= FLAG_INHERIT; @@ -215,16 +320,22 @@ css_error parse_widows(css_language *c, size_t consumed = 0; num = number_from_lwc_string(token->ilower, true, &consumed); /* Invalid if there are trailing characters */ - if (consumed != lwc_string_length(token->ilower)) + if (consumed != lwc_string_length(token->ilower)) { + *ctx = orig_ctx; return CSS_INVALID; + } /* Negative values are nonsensical */ - if (num < 0) + if (num < 0) { + *ctx = orig_ctx; return CSS_INVALID; + } value = WIDOWS_SET; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_WIDOWS, flags, value); @@ -234,8 +345,10 @@ css_error parse_widows(css_language *c, /* Allocate result */ error = css_stylesheet_style_create(c->sheet, required_size, result); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } /* Copy the bytecode to it */ memcpy((*result)->bytecode, &opv, sizeof(opv)); |