From 4c68d0928a4c43adbdfcad86af6f8e3bd113f7ae Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 25 Jun 2009 23:29:44 +0000 Subject: Documentation and context restoration on error svn path=/trunk/libcss/; revision=8001 --- src/parse/properties/positioning.c | 200 +++++++++++++++++++++++++++++++++---- 1 file changed, 183 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/parse/properties/positioning.c b/src/parse/properties/positioning.c index c280f4b..71b4bab 100644 --- a/src/parse/properties/positioning.c +++ b/src/parse/properties/positioning.c @@ -16,6 +16,20 @@ static css_error parse_side(css_language *c, const parserutils_vector *vector, int *ctx, uint16_t op, css_style **result); +/** + * Parse bottom + * + * \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_bottom(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) @@ -23,6 +37,20 @@ css_error parse_bottom(css_language *c, return parse_side(c, vector, ctx, CSS_PROP_BOTTOM, result); } +/** + * Parse left + * + * \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_left(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) @@ -30,6 +58,20 @@ css_error parse_left(css_language *c, return parse_side(c, vector, ctx, CSS_PROP_LEFT, result); } +/** + * Parse right + * + * \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_right(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) @@ -37,6 +79,20 @@ css_error parse_right(css_language *c, return parse_side(c, vector, ctx, CSS_PROP_RIGHT, result); } +/** + * Parse top + * + * \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_top(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) @@ -44,10 +100,25 @@ css_error parse_top(css_language *c, return parse_side(c, vector, ctx, CSS_PROP_TOP, result); } +/** + * Parse position + * + * \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_position(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; @@ -56,8 +127,10 @@ css_error parse_position(css_language *c, /* IDENT (static, relative, absolute, 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; @@ -69,15 +142,19 @@ css_error parse_position(css_language *c, value = POSITION_ABSOLUTE; } else if (ident->ilower == c->strings[FIXED]) { value = POSITION_FIXED; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_POSITION, 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)); @@ -85,10 +162,25 @@ css_error parse_position(css_language *c, return CSS_OK; } +/** + * Parse clear + * + * \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_clear(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; @@ -97,8 +189,10 @@ css_error parse_clear(css_language *c, /* IDENT (left, right, both, none, 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; @@ -110,15 +204,19 @@ css_error parse_clear(css_language *c, value = CLEAR_BOTH; } else if (ident->ilower == c->strings[NONE]) { value = CLEAR_NONE; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_CLEAR, 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)); @@ -126,10 +224,25 @@ css_error parse_clear(css_language *c, return CSS_OK; } +/** + * Parse float + * + * \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_float(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; @@ -138,8 +251,10 @@ css_error parse_float(css_language *c, /* IDENT (left, right, none, 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; @@ -149,15 +264,19 @@ css_error parse_float(css_language *c, value = FLOAT_RIGHT; } else if (ident->ilower == c->strings[NONE]) { value = FLOAT_NONE; - } else + } else { + *ctx = orig_ctx; return CSS_INVALID; + } opv = buildOPV(CSS_PROP_FLOAT, 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)); @@ -165,10 +284,25 @@ css_error parse_float(css_language *c, return CSS_OK; } +/** + * Parse vertical-align + * + * \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_vertical_align(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; @@ -182,8 +316,10 @@ css_error parse_vertical_align(css_language *c, * middle, bottom, text-bottom, inherit) */ token = parserutils_vector_peek(vector, *ctx); - if (token == NULL) + if (token == NULL) { + *ctx = orig_ctx; return CSS_INVALID; + } if (token->type == CSS_TOKEN_IDENT && token->ilower == c->strings[INHERIT]) { @@ -224,11 +360,15 @@ css_error parse_vertical_align(css_language *c, } else { error = parse_unit_specifier(c, vector, ctx, UNIT_PX, &length, &unit); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } - if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) + if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) { + *ctx = orig_ctx; return CSS_INVALID; + } value = VERTICAL_ALIGN_SET; } @@ -241,8 +381,10 @@ css_error parse_vertical_align(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)); @@ -256,10 +398,26 @@ css_error parse_vertical_align(css_language *c, return CSS_OK; } +/** + * Parse {top,right,bottom,left} + * + * \param c Parsing context + * \param vector Vector of tokens to process + * \param ctx Pointer to vector iteration context + * \param op Opcode to parse for + * \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_side(css_language *c, const parserutils_vector *vector, int *ctx, uint16_t op, css_style **result) { + int orig_ctx = *ctx; css_error error; const css_token *token; uint8_t flags = 0; @@ -271,8 +429,10 @@ css_error parse_side(css_language *c, /* length | percentage | IDENT(auto, inherit) */ token = parserutils_vector_peek(vector, *ctx); - if (token == NULL) + if (token == NULL) { + *ctx = orig_ctx; return CSS_INVALID; + } if (token->type == CSS_TOKEN_IDENT && token->ilower == c->strings[INHERIT]) { @@ -285,11 +445,15 @@ css_error parse_side(css_language *c, } else { error = parse_unit_specifier(c, vector, ctx, UNIT_PX, &length, &unit); - if (error != CSS_OK) + if (error != CSS_OK) { + *ctx = orig_ctx; return error; + } - if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) + if (unit & UNIT_ANGLE || unit & UNIT_TIME || unit & UNIT_FREQ) { + *ctx = orig_ctx; return CSS_INVALID; + } value = BOTTOM_SET; } @@ -302,8 +466,10 @@ css_error parse_side(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)); -- cgit v1.2.3