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 **************************************************************************/
28 #include "sl_pp_version.h"
32 _parse_integer(const char *input
,
37 while (*input
>= '0' && *input
<= '9') {
43 n
= n
* 10 + (*input
++ - '0');
47 /* Invalid decimal number. */
57 sl_pp_version(struct sl_pp_context
*context
,
58 const struct sl_pp_token_info
*input
,
59 unsigned int *version
,
60 unsigned int *tokens_eaten
)
63 unsigned int line
= context
->line
;
65 /* Default values if `#version' is not present. */
69 /* There can be multiple `#version' directives present.
70 * Accept the value of the last one.
74 int found_version
= 0;
78 /* Skip whitespace and newlines and seek for hash. */
80 switch (input
[i
].token
) {
84 case SL_PP_WHITESPACE
:
98 /* Skip whitespace and seek for `version'. */
99 while (!found_version
) {
100 switch (input
[i
].token
) {
101 case SL_PP_WHITESPACE
:
105 case SL_PP_IDENTIFIER
:
107 const char *id
= sl_pp_context_cstr(context
, input
[i
].data
.identifier
);
112 if (strcmp(id
, "version")) {
125 /* Skip whitespace and seek for version number. */
126 while (!found_number
) {
127 switch (input
[i
].token
) {
128 case SL_PP_WHITESPACE
:
134 const char *num
= sl_pp_context_cstr(context
, input
[i
].data
.number
);
139 if (_parse_integer(num
, version
)) {
140 strcpy(context
->error_msg
, "expected version number after `#version'");
149 strcpy(context
->error_msg
, "expected version number after `#version'");
154 /* Skip whitespace and seek for either newline or eof. */
156 switch (input
[i
].token
) {
157 case SL_PP_WHITESPACE
:
167 context
->line
= line
;
172 strcpy(context
->error_msg
, "expected end of line after version number");
178 /* Should not get here. */