From d133c59fefbdcdf4e8fca8710a3fcd32436715ea Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 25 Jun 2009 23:32:13 +0000 Subject: Documentation and context restoration on error svn path=/trunk/libcss/; revision=8002 --- src/parse/properties/table.c | 81 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 72 insertions(+), 9 deletions(-) (limited to 'src/parse/properties') diff --git a/src/parse/properties/table.c b/src/parse/properties/table.c index 43a8a58..0e5e270 100644 --- a/src/parse/properties/table.c +++ b/src/parse/properties/table.c @@ -12,10 +12,25 @@ #include "parse/properties/properties.h" #include "parse/properties/utils.h" +/** + * Parse caption-side + * + * \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_caption_side(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; @@ -24,8 +39,10 @@ css_error parse_caption_side(css_language *c, /* IDENT (top, bottom, 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; @@ -33,15 +50,19 @@ css_error parse_caption_side(css_language *c, value = CAPTION_SIDE_TOP; } else if (ident->ilower == c->strings[BOTTOM]) { value = CAPTION_SIDE_BOTTOM; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_CAPTION_SIDE, 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)); @@ -49,10 +70,25 @@ css_error parse_caption_side(css_language *c, return CSS_OK; } +/** + * Parse empty-cells + * + * \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_empty_cells(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; @@ -61,8 +97,10 @@ css_error parse_empty_cells(css_language *c, /* IDENT (show, hide, 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; @@ -70,15 +108,19 @@ css_error parse_empty_cells(css_language *c, value = EMPTY_CELLS_SHOW; } else if (ident->ilower == c->strings[HIDE]) { value = EMPTY_CELLS_HIDE; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_EMPTY_CELLS, 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)); @@ -86,10 +128,25 @@ css_error parse_empty_cells(css_language *c, return CSS_OK; } +/** + * Parse table-layout + * + * \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_table_layout(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; @@ -98,8 +155,10 @@ css_error parse_table_layout(css_language *c, /* IDENT (auto, fixed, 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; @@ -107,15 +166,19 @@ css_error parse_table_layout(css_language *c, value = TABLE_LAYOUT_AUTO; } else if (ident->ilower == c->strings[FIXED]) { value = TABLE_LAYOUT_FIXED; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_TABLE_LAYOUT, 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)); -- cgit v1.2.3