Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3584 | sourcerer | 1 | /* |
2 | * This file is part of LibCSS. |
||
3 | * Licensed under the MIT License, |
||
4 | * http://www.opensource.org/licenses/mit-license.php |
||
5 | * Copyright 2009 John-Mark Bell |
||
6 | */ |
||
7 | |||
8 | #include |
||
9 | |||
10 | #include "bytecode/bytecode.h" |
||
11 | #include "bytecode/opcodes.h" |
||
12 | #include "parse/properties/properties.h" |
||
13 | #include "parse/properties/utils.h" |
||
14 | |||
15 | /** |
||
16 | * Parse cursor |
||
17 | * |
||
18 | * \param c Parsing context |
||
19 | * \param vector Vector of tokens to process |
||
20 | * \param ctx Pointer to vector iteration context |
||
21 | * \param result Pointer to location to receive resulting style |
||
22 | * \return CSS_OK on success, |
||
23 | * CSS_NOMEM on memory exhaustion, |
||
24 | * CSS_INVALID if the input is not valid |
||
25 | * |
||
26 | * Post condition: \a *ctx is updated with the next token to process |
||
27 | * If the input is invalid, then \a *ctx remains unchanged. |
||
28 | */ |
||
29 | css_error css__parse_cursor(css_language *c, |
||
30 | const parserutils_vector *vector, int *ctx, |
||
31 | css_style *result) |
||
32 | { |
||
33 | int orig_ctx = *ctx; |
||
34 | css_error error = CSS_OK; |
||
35 | const css_token *token; |
||
36 | bool match; |
||
37 | |||
38 | /* [ (URI ',')* IDENT(auto, crosshair, default, pointer, move, e-resize, |
||
39 | * ne-resize, nw-resize, n-resize, se-resize, sw-resize, |
||
40 | * s-resize, w-resize, text, wait, help, progress) ] |
||
41 | * | IDENT(inherit) |
||
42 | */ |
||
43 | token = parserutils_vector_iterate(vector, ctx); |
||
44 | if ((token == NULL) || |
||
45 | (token->type != CSS_TOKEN_IDENT && |
||
46 | token->type != CSS_TOKEN_URI)) { |
||
47 | *ctx = orig_ctx; |
||
48 | return CSS_INVALID; |
||
49 | } |
||
50 | |||
51 | if ((token->type == CSS_TOKEN_IDENT) && |
||
52 | (lwc_string_caseless_isequal(token->idata, |
||
53 | c->strings[INHERIT], |
||
54 | &match) == lwc_error_ok && match)) { |
||
55 | error = css_stylesheet_style_inherit(result, CSS_PROP_CURSOR); |
||
56 | } else { |
||
57 | bool first = true; |
||
58 | |||
59 | /* Macro to output the value marker, awkward because we need to check |
||
60 | * first to determine how the value is constructed. |
||
61 | */ |
||
62 | #define CSS_APPEND(CSSVAL) css__stylesheet_style_append(result, first?buildOPV(CSS_PROP_CURSOR, 0, CSSVAL):CSSVAL) |
||
63 | |||
64 | |||
65 | /* URI* */ |
||
66 | while (token != NULL && token->type == CSS_TOKEN_URI) { |
||
67 | lwc_string *uri; |
||
68 | uint32_t uri_snumber; |
||
69 | |||
70 | error = c->sheet->resolve(c->sheet->resolve_pw, |
||
71 | c->sheet->url, |
||
72 | token->idata, &uri); |
||
73 | if (error != CSS_OK) { |
||
74 | *ctx = orig_ctx; |
||
75 | return error; |
||
76 | } |
||
77 | |||
78 | error = css__stylesheet_string_add(c->sheet, |
||
79 | uri, |
||
80 | &uri_snumber); |
||
81 | if (error != CSS_OK) { |
||
82 | *ctx = orig_ctx; |
||
83 | return error; |
||
84 | } |
||
85 | |||
86 | error = CSS_APPEND(CURSOR_URI); |
||
87 | if (error != CSS_OK) { |
||
88 | *ctx = orig_ctx; |
||
89 | return error; |
||
90 | } |
||
91 | |||
92 | error = css__stylesheet_style_append(result, uri_snumber); |
||
93 | if (error != CSS_OK) { |
||
94 | *ctx = orig_ctx; |
||
95 | return error; |
||
96 | } |
||
97 | |||
98 | consumeWhitespace(vector, ctx); |
||
99 | |||
100 | /* Expect ',' */ |
||
101 | token = parserutils_vector_iterate(vector, ctx); |
||
102 | if (token == NULL || tokenIsChar(token, ',') == false) { |
||
103 | *ctx = orig_ctx; |
||
104 | return CSS_INVALID; |
||
105 | } |
||
106 | |||
107 | consumeWhitespace(vector, ctx); |
||
108 | |||
109 | /* Expect either URI or IDENT */ |
||
110 | token = parserutils_vector_iterate(vector, ctx); |
||
111 | if (token == NULL || (token->type != CSS_TOKEN_IDENT && |
||
112 | token->type != CSS_TOKEN_URI)) { |
||
113 | *ctx = orig_ctx; |
||
114 | return CSS_INVALID; |
||
115 | } |
||
116 | |||
117 | first = false; |
||
118 | } |
||
119 | |||
120 | /* IDENT */ |
||
121 | if (token != NULL && token->type == CSS_TOKEN_IDENT) { |
||
122 | if ((lwc_string_caseless_isequal( |
||
123 | token->idata, c->strings[AUTO], |
||
124 | &match) == lwc_error_ok && match)) { |
||
125 | error=CSS_APPEND(CURSOR_AUTO); |
||
126 | } else if ((lwc_string_caseless_isequal( |
||
127 | token->idata, c->strings[CROSSHAIR], |
||
128 | &match) == lwc_error_ok && match)) { |
||
129 | error=CSS_APPEND(CURSOR_CROSSHAIR); |
||
130 | } else if ((lwc_string_caseless_isequal( |
||
131 | token->idata, c->strings[DEFAULT], |
||
132 | &match) == lwc_error_ok && match)) { |
||
133 | error=CSS_APPEND(CURSOR_DEFAULT); |
||
134 | } else if ((lwc_string_caseless_isequal( |
||
135 | token->idata, c->strings[POINTER], |
||
136 | &match) == lwc_error_ok && match)) { |
||
137 | error=CSS_APPEND(CURSOR_POINTER); |
||
138 | } else if ((lwc_string_caseless_isequal( |
||
139 | token->idata, c->strings[MOVE], |
||
140 | &match) == lwc_error_ok && match)) { |
||
141 | error=CSS_APPEND(CURSOR_MOVE); |
||
142 | } else if ((lwc_string_caseless_isequal( |
||
143 | token->idata, c->strings[E_RESIZE], |
||
144 | &match) == lwc_error_ok && match)) { |
||
145 | error=CSS_APPEND(CURSOR_E_RESIZE); |
||
146 | } else if ((lwc_string_caseless_isequal( |
||
147 | token->idata, c->strings[NE_RESIZE], |
||
148 | &match) == lwc_error_ok && match)) { |
||
149 | error=CSS_APPEND(CURSOR_NE_RESIZE); |
||
150 | } else if ((lwc_string_caseless_isequal( |
||
151 | token->idata, c->strings[NW_RESIZE], |
||
152 | &match) == lwc_error_ok && match)) { |
||
153 | error=CSS_APPEND(CURSOR_NW_RESIZE); |
||
154 | } else if ((lwc_string_caseless_isequal( |
||
155 | token->idata, c->strings[N_RESIZE], |
||
156 | &match) == lwc_error_ok && match)) { |
||
157 | error=CSS_APPEND(CURSOR_N_RESIZE); |
||
158 | } else if ((lwc_string_caseless_isequal( |
||
159 | token->idata, c->strings[SE_RESIZE], |
||
160 | &match) == lwc_error_ok && match)) { |
||
161 | error=CSS_APPEND(CURSOR_SE_RESIZE); |
||
162 | } else if ((lwc_string_caseless_isequal( |
||
163 | token->idata, c->strings[SW_RESIZE], |
||
164 | &match) == lwc_error_ok && match)) { |
||
165 | error=CSS_APPEND(CURSOR_SW_RESIZE); |
||
166 | } else if ((lwc_string_caseless_isequal( |
||
167 | token->idata, c->strings[S_RESIZE], |
||
168 | &match) == lwc_error_ok && match)) { |
||
169 | error=CSS_APPEND(CURSOR_S_RESIZE); |
||
170 | } else if ((lwc_string_caseless_isequal( |
||
171 | token->idata, c->strings[W_RESIZE], |
||
172 | &match) == lwc_error_ok && match)) { |
||
173 | error=CSS_APPEND(CURSOR_W_RESIZE); |
||
174 | } else if ((lwc_string_caseless_isequal( |
||
175 | token->idata, c->strings[LIBCSS_TEXT], |
||
176 | &match) == lwc_error_ok && match)) { |
||
177 | error=CSS_APPEND(CURSOR_TEXT); |
||
178 | } else if ((lwc_string_caseless_isequal( |
||
179 | token->idata, c->strings[WAIT], |
||
180 | &match) == lwc_error_ok && match)) { |
||
181 | error=CSS_APPEND(CURSOR_WAIT); |
||
182 | } else if ((lwc_string_caseless_isequal( |
||
183 | token->idata, c->strings[HELP], |
||
184 | &match) == lwc_error_ok && match)) { |
||
185 | error=CSS_APPEND(CURSOR_HELP); |
||
186 | } else if ((lwc_string_caseless_isequal( |
||
187 | token->idata, c->strings[PROGRESS], |
||
188 | &match) == lwc_error_ok && match)) { |
||
189 | error=CSS_APPEND(CURSOR_PROGRESS); |
||
190 | } else { |
||
191 | error = CSS_INVALID; |
||
192 | } |
||
193 | } |
||
194 | |||
195 | } |
||
196 | |||
197 | if (error != CSS_OK) |
||
198 | *ctx = orig_ctx; |
||
199 | |||
200 | return error; |
||
201 | } |
||
202 |