1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 #include "sl_pp_public.h"
31 #include "sl_pp_context.h"
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
)
41 unsigned int line
= context
->line
;
43 /* Default values if `#version' is not present. */
47 /* There can be multiple `#version' directives present.
48 * Accept the value of the last one.
52 int found_version
= 0;
56 /* Skip whitespace and newlines and seek for hash. */
58 switch (input
[i
].token
) {
62 case SL_PP_WHITESPACE
:
76 /* Skip whitespace and seek for `version'. */
77 while (!found_version
) {
78 switch (input
[i
].token
) {
79 case SL_PP_WHITESPACE
:
83 case SL_PP_IDENTIFIER
:
84 if (input
[i
].data
.identifier
!= context
->dict
.version
) {
96 /* Skip whitespace and seek for version number. */
97 while (!found_number
) {
98 switch (input
[i
].token
) {
99 case SL_PP_WHITESPACE
:
104 *version
= atoi(sl_pp_context_cstr(context
, input
[i
].data
._uint
));
110 strcpy(context
->error_msg
, "expected version number after `#version'");
115 /* Skip whitespace and seek for either newline or eof. */
117 switch (input
[i
].token
) {
118 case SL_PP_WHITESPACE
:
128 context
->line
= line
;
133 strcpy(context
->error_msg
, "expected end of line after version number");
139 /* Should not get here. */