glsl/apps: remove unused vars
[mesa.git] / src / glsl / pp / sl_pp_version.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <stdlib.h>
29 #include <string.h>
30 #include "sl_pp_public.h"
31 #include "sl_pp_context.h"
32
33
34 int
35 sl_pp_version(struct sl_pp_context *context,
36 const struct sl_pp_token_info *input,
37 unsigned int *version,
38 unsigned int *tokens_eaten)
39 {
40 unsigned int i = 0;
41 unsigned int line = context->line;
42
43 /* Default values if `#version' is not present. */
44 *version = 110;
45 *tokens_eaten = 0;
46
47 /* There can be multiple `#version' directives present.
48 * Accept the value of the last one.
49 */
50 for (;;) {
51 int found_hash = 0;
52 int found_version = 0;
53 int found_number = 0;
54 int found_end = 0;
55
56 /* Skip whitespace and newlines and seek for hash. */
57 while (!found_hash) {
58 switch (input[i].token) {
59 case SL_PP_NEWLINE:
60 line++;
61 /* pass thru */
62 case SL_PP_WHITESPACE:
63 i++;
64 break;
65
66 case SL_PP_HASH:
67 i++;
68 found_hash = 1;
69 break;
70
71 default:
72 return 0;
73 }
74 }
75
76 /* Skip whitespace and seek for `version'. */
77 while (!found_version) {
78 switch (input[i].token) {
79 case SL_PP_WHITESPACE:
80 i++;
81 break;
82
83 case SL_PP_IDENTIFIER:
84 if (input[i].data.identifier != context->dict.version) {
85 return 0;
86 }
87 i++;
88 found_version = 1;
89 break;
90
91 default:
92 return 0;
93 }
94 }
95
96 /* Skip whitespace and seek for version number. */
97 while (!found_number) {
98 switch (input[i].token) {
99 case SL_PP_WHITESPACE:
100 i++;
101 break;
102
103 case SL_PP_UINT:
104 *version = atoi(sl_pp_context_cstr(context, input[i].data._uint));
105 i++;
106 found_number = 1;
107 break;
108
109 default:
110 strcpy(context->error_msg, "expected version number after `#version'");
111 return -1;
112 }
113 }
114
115 /* Skip whitespace and seek for either newline or eof. */
116 while (!found_end) {
117 switch (input[i].token) {
118 case SL_PP_WHITESPACE:
119 i++;
120 break;
121
122 case SL_PP_NEWLINE:
123 line++;
124 /* pass thru */
125 case SL_PP_EOF:
126 i++;
127 *tokens_eaten = i;
128 context->line = line;
129 found_end = 1;
130 break;
131
132 default:
133 strcpy(context->error_msg, "expected end of line after version number");
134 return -1;
135 }
136 }
137 }
138
139 /* Should not get here. */
140 }