summaryrefslogtreecommitdiffstats
path: root/src/glsl/pp
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-06-15 09:50:48 +0200
committerMichal Krol <[email protected]>2009-09-07 10:11:38 +0200
commitb4e92367f33c8bdd14337ced63abe82685f08cb3 (patch)
tree9bc9003db66106f164f1de6407bfd3e96beb5814 /src/glsl/pp
parent55f75c13f05ea6373b95f0777078fcdec226672a (diff)
glsl: Allow for multiple version statements.
Diffstat (limited to 'src/glsl/pp')
-rw-r--r--src/glsl/pp/sl_pp_version.c144
1 files changed, 76 insertions, 68 deletions
diff --git a/src/glsl/pp/sl_pp_version.c b/src/glsl/pp/sl_pp_version.c
index f4b4b829d1e..e743a098417 100644
--- a/src/glsl/pp/sl_pp_version.c
+++ b/src/glsl/pp/sl_pp_version.c
@@ -59,90 +59,98 @@ sl_pp_version(const struct sl_pp_token_info *input,
unsigned int *tokens_eaten)
{
unsigned int i = 0;
- int found_hash = 0;
- int found_version = 0;
- int found_number = 0;
/* Default values if `#version' is not present. */
*version = 110;
*tokens_eaten = 0;
- /* Skip whitespace and newlines and seek for hash. */
- while (!found_hash) {
- switch (input[i].token) {
- case SL_PP_WHITESPACE:
- case SL_PP_NEWLINE:
- i++;
- break;
-
- case SL_PP_HASH:
- i++;
- found_hash = 1;
- break;
-
- default:
- return 0;
+ /* There can be multiple `#version' directives present.
+ * Accept the value of the last one.
+ */
+ for (;;) {
+ int found_hash = 0;
+ int found_version = 0;
+ int found_number = 0;
+ int found_end = 0;
+
+ /* Skip whitespace and newlines and seek for hash. */
+ while (!found_hash) {
+ switch (input[i].token) {
+ case SL_PP_WHITESPACE:
+ case SL_PP_NEWLINE:
+ i++;
+ break;
+
+ case SL_PP_HASH:
+ i++;
+ found_hash = 1;
+ break;
+
+ default:
+ return 0;
+ }
}
- }
- /* Skip whitespace and seek for `version'. */
- while (!found_version) {
- switch (input[i].token) {
- case SL_PP_WHITESPACE:
- i++;
- break;
-
- case SL_PP_IDENTIFIER:
- if (strcmp(input[i].data.identifier, "version")) {
+ /* Skip whitespace and seek for `version'. */
+ while (!found_version) {
+ switch (input[i].token) {
+ case SL_PP_WHITESPACE:
+ i++;
+ break;
+
+ case SL_PP_IDENTIFIER:
+ if (strcmp(input[i].data.identifier, "version")) {
+ return 0;
+ }
+ i++;
+ found_version = 1;
+ break;
+
+ default:
return 0;
}
- i++;
- found_version = 1;
- break;
-
- default:
- return 0;
}
- }
-
- /* Skip whitespace and seek for version number. */
- while (!found_number) {
- switch (input[i].token) {
- case SL_PP_WHITESPACE:
- i++;
- break;
- case SL_PP_NUMBER:
- if (_parse_integer(input[i].data.number, version)) {
+ /* Skip whitespace and seek for version number. */
+ while (!found_number) {
+ switch (input[i].token) {
+ case SL_PP_WHITESPACE:
+ i++;
+ break;
+
+ case SL_PP_NUMBER:
+ if (_parse_integer(input[i].data.number, version)) {
+ /* Expected version number. */
+ return -1;
+ }
+ i++;
+ found_number = 1;
+ break;
+
+ default:
/* Expected version number. */
return -1;
}
- i++;
- found_number = 1;
- break;
-
- default:
- /* Expected version number. */
- return -1;
}
- }
- /* Skip whitespace and seek for either newline or eof. */
- for (;;) {
- switch (input[i].token) {
- case SL_PP_WHITESPACE:
- i++;
- break;
-
- case SL_PP_NEWLINE:
- case SL_PP_EOF:
- i++;
- *tokens_eaten = i;
- return 0;
-
- default:
- /* Expected end of line. */
- return -1;
+ /* Skip whitespace and seek for either newline or eof. */
+ while (!found_end) {
+ switch (input[i].token) {
+ case SL_PP_WHITESPACE:
+ i++;
+ break;
+
+ case SL_PP_NEWLINE:
+ case SL_PP_EOF:
+ i++;
+ *tokens_eaten = i;
+ found_end = 1;
+ break;
+
+ default:
+ /* Expected end of line. */
+ return -1;
+ }
}
}