summaryrefslogtreecommitdiff
path: root/src/parse/properties/cursor.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-01-19 23:12:37 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-01-19 23:12:37 +0000
commit6a50bef84ae6a0a67e03ac1356f8d85d15fe09d6 (patch)
tree01f78f04b22517899f603787f6005f70b359271e /src/parse/properties/cursor.c
parent63c21aca7c77b1d37cb64ad2b1fa76d6b0b92f48 (diff)
downloadlibcss-6a50bef84ae6a0a67e03ac1356f8d85d15fe09d6.tar.gz
libcss-6a50bef84ae6a0a67e03ac1356f8d85d15fe09d6.tar.bz2
Merge parser autogeneration and string handling refactor branch r=jmb,kinnison,vince
svn path=/trunk/libcss/; revision=11408
Diffstat (limited to 'src/parse/properties/cursor.c')
-rw-r--r--src/parse/properties/cursor.c281
1 files changed, 55 insertions, 226 deletions
diff --git a/src/parse/properties/cursor.c b/src/parse/properties/cursor.c
index 725e7b7..e063a9b 100644
--- a/src/parse/properties/cursor.c
+++ b/src/parse/properties/cursor.c
@@ -28,17 +28,11 @@
*/
css_error parse_cursor(css_language *c,
const parserutils_vector *vector, int *ctx,
- css_style **result)
+ css_style *result)
{
int orig_ctx = *ctx;
css_error error;
const css_token *token;
- uint8_t flags = 0;
- uint16_t value = 0;
- uint32_t opv;
- uint32_t required_size = sizeof(opv);
- int temp_ctx = *ctx;
- uint8_t *ptr;
bool match;
/* [ (URI ',')* IDENT(auto, crosshair, default, pointer, move, e-resize,
@@ -46,224 +40,61 @@ css_error parse_cursor(css_language *c,
* s-resize, w-resize, text, wait, help, progress) ]
* | IDENT(inherit)
*/
-
- /* Pass 1: validate input and calculate bytecode size */
- token = parserutils_vector_iterate(vector, &temp_ctx);
- if (token == NULL || (token->type != CSS_TOKEN_IDENT &&
- token->type != CSS_TOKEN_URI)) {
+ token = parserutils_vector_iterate(vector, ctx);
+ if ((token == NULL) ||
+ (token->type != CSS_TOKEN_IDENT &&
+ token->type != CSS_TOKEN_URI)) {
*ctx = orig_ctx;
return CSS_INVALID;
}
- if (token->type == CSS_TOKEN_IDENT &&
- (lwc_string_caseless_isequal(
- token->idata, c->strings[INHERIT],
- &match) == lwc_error_ok && match)) {
- flags = FLAG_INHERIT;
+ if ((token->type == CSS_TOKEN_IDENT) &&
+ (lwc_string_caseless_isequal(token->idata,
+ c->strings[INHERIT],
+ &match) == lwc_error_ok && match)) {
+ error = css_stylesheet_style_inherit(result, CSS_PROP_CURSOR);
} else {
bool first = true;
- /* URI* */
- while (token != NULL && token->type == CSS_TOKEN_URI) {
- lwc_string *uri = token->idata;
+/* Macro to output the value marker, awkward because we need to check
+ * first to determine how the value is constructed.
+ */
+#define CSS_APPEND(CSSVAL) css_stylesheet_style_append(result, first?buildOPV(CSS_PROP_CURSOR, 0, CSSVAL):CSSVAL)
- if (first == false) {
- required_size += sizeof(opv);
- } else {
- value = CURSOR_URI;
- }
- required_size += sizeof(uri);
- consumeWhitespace(vector, &temp_ctx);
+ /* URI* */
+ while (token != NULL && token->type == CSS_TOKEN_URI) {
+ lwc_string *uri;
+ uint32_t uri_snumber;
- /* Expect ',' */
- token = parserutils_vector_iterate(vector, &temp_ctx);
- if (token == NULL || tokenIsChar(token, ',') == false) {
+ error = c->sheet->resolve(c->sheet->resolve_pw,
+ c->sheet->url,
+ token->idata, &uri);
+ if (error != CSS_OK) {
*ctx = orig_ctx;
- return CSS_INVALID;
+ return error;
}
- consumeWhitespace(vector, &temp_ctx);
-
- /* Expect either URI or IDENT */
- token = parserutils_vector_iterate(vector, &temp_ctx);
- if (token == NULL || (token->type != CSS_TOKEN_IDENT &&
- token->type != CSS_TOKEN_URI)) {
+ error = css_stylesheet_string_add(c->sheet,
+ uri,
+ &uri_snumber);
+ if (error != CSS_OK) {
*ctx = orig_ctx;
- return CSS_INVALID;
+ return error;
}
- first = false;
- }
-
- /* IDENT */
- if (token != NULL && token->type == CSS_TOKEN_IDENT) {
- if ((lwc_string_caseless_isequal(
- token->idata, c->strings[AUTO],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_AUTO;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[CROSSHAIR],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_CROSSHAIR;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[DEFAULT],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_DEFAULT;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[POINTER],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_POINTER;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[MOVE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_MOVE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[E_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_E_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[NE_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_NE_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[NW_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_NW_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[N_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_N_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[SE_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_SE_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[SW_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_SW_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[S_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_S_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[W_RESIZE],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_W_RESIZE;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[LIBCSS_TEXT],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_TEXT;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[WAIT],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_WAIT;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[HELP],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_HELP;
- }
- } else if ((lwc_string_caseless_isequal(
- token->idata, c->strings[PROGRESS],
- &match) == lwc_error_ok && match)) {
- if (first) {
- value = CURSOR_PROGRESS;
- }
- } else {
+ error = CSS_APPEND(CURSOR_URI);
+ if (error != CSS_OK) {
*ctx = orig_ctx;
- return CSS_INVALID;
- }
-
- if (first == false) {
- required_size += sizeof(opv);
+ return error;
}
- }
- }
- opv = buildOPV(CSS_PROP_CURSOR, flags, value);
-
- /* Allocate result */
- error = css_stylesheet_style_create(c->sheet, required_size, result);
- if (error != CSS_OK) {
- *ctx = orig_ctx;
- return error;
- }
-
- /* Copy OPV to bytecode */
- ptr = (*result)->bytecode;
- memcpy(ptr, &opv, sizeof(opv));
- ptr += sizeof(opv);
-
- /* Pass 2: construct bytecode */
- token = parserutils_vector_iterate(vector, ctx);
- if (token == NULL || (token->type != CSS_TOKEN_IDENT &&
- token->type != CSS_TOKEN_URI)) {
- *ctx = orig_ctx;
- return CSS_INVALID;
- }
-
- if (token->type == CSS_TOKEN_IDENT &&
- (lwc_string_caseless_isequal(
- token->idata, c->strings[INHERIT],
- &match) == lwc_error_ok && match)) {
- /* Nothing to do */
- } else {
- bool first = true;
-
- /* URI* */
- while (token != NULL && token->type == CSS_TOKEN_URI) {
- lwc_string *uri;
-
- error = c->sheet->resolve(c->sheet->resolve_pw,
- c->sheet->url,
- token->idata, &uri);
+ error = css_stylesheet_style_append(result, uri_snumber);
if (error != CSS_OK) {
*ctx = orig_ctx;
return error;
}
- if (first == false) {
- opv = CURSOR_URI;
- memcpy(ptr, &opv, sizeof(opv));
- ptr += sizeof(opv);
- }
-
- /* Don't ref URI -- we want to pass ownership to the
- * bytecode */
- memcpy(ptr, &uri, sizeof(uri));
- ptr += sizeof(uri);
-
consumeWhitespace(vector, ctx);
/* Expect ',' */
@@ -291,83 +122,81 @@ css_error parse_cursor(css_language *c,
if ((lwc_string_caseless_isequal(
token->idata, c->strings[AUTO],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_AUTO;
+ error=CSS_APPEND(CURSOR_AUTO);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[CROSSHAIR],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_CROSSHAIR;
+ error=CSS_APPEND(CURSOR_CROSSHAIR);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[DEFAULT],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_DEFAULT;
+ error=CSS_APPEND(CURSOR_DEFAULT);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[POINTER],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_POINTER;
+ error=CSS_APPEND(CURSOR_POINTER);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[MOVE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_MOVE;
+ error=CSS_APPEND(CURSOR_MOVE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[E_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_E_RESIZE;
+ error=CSS_APPEND(CURSOR_E_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[NE_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_NE_RESIZE;
+ error=CSS_APPEND(CURSOR_NE_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[NW_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_NW_RESIZE;
+ error=CSS_APPEND(CURSOR_NW_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[N_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_N_RESIZE;
+ error=CSS_APPEND(CURSOR_N_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[SE_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_SE_RESIZE;
+ error=CSS_APPEND(CURSOR_SE_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[SW_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_SW_RESIZE;
+ error=CSS_APPEND(CURSOR_SW_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[S_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_S_RESIZE;
+ error=CSS_APPEND(CURSOR_S_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[W_RESIZE],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_W_RESIZE;
+ error=CSS_APPEND(CURSOR_W_RESIZE);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[LIBCSS_TEXT],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_TEXT;
+ error=CSS_APPEND(CURSOR_TEXT);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[WAIT],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_WAIT;
+ error=CSS_APPEND(CURSOR_WAIT);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[HELP],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_HELP;
+ error=CSS_APPEND(CURSOR_HELP);
} else if ((lwc_string_caseless_isequal(
token->idata, c->strings[PROGRESS],
&match) == lwc_error_ok && match)) {
- opv = CURSOR_PROGRESS;
+ error=CSS_APPEND(CURSOR_PROGRESS);
} else {
- *ctx = orig_ctx;
- return CSS_INVALID;
- }
-
- if (first == false) {
- memcpy(ptr, &opv, sizeof(opv));
- ptr += sizeof(opv);
+ error = CSS_INVALID;
}
}
+
}
- return CSS_OK;
+ if (error != CSS_OK)
+ *ctx = orig_ctx;
+
+ return error;
}