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 **************************************************************************/
31 #include "../pp/sl_pp_context.h"
32 #include "../pp/sl_pp_purify.h"
33 #include "../pp/sl_pp_token.h"
43 struct sl_pp_purify_options options
;
45 struct sl_pp_context context
;
46 struct sl_pp_token_info
*tokens
;
54 in
= fopen(argv
[1], "rb");
59 fseek(in
, 0, SEEK_END
);
61 fseek(in
, 0, SEEK_SET
);
63 inbuf
= malloc(size
+ 1);
69 if (fread(inbuf
, 1, size
, in
) != size
) {
78 memset(&options
, 0, sizeof(options
));
80 if (sl_pp_purify(inbuf
, &options
, &outbuf
)) {
87 if (sl_pp_context_init(&context
)) {
92 if (sl_pp_tokenise(&context
, outbuf
, &tokens
)) {
93 sl_pp_context_destroy(&context
);
100 out
= fopen(argv
[2], "wb");
102 sl_pp_context_destroy(&context
);
107 for (i
= 0; tokens
[i
].token
!= SL_PP_EOF
; i
++) {
108 switch (tokens
[i
].token
) {
109 case SL_PP_WHITESPACE
:
124 case SL_PP_SEMICOLON
:
156 case SL_PP_INCREMENT
:
160 case SL_PP_ADDASSIGN
:
168 case SL_PP_DECREMENT
:
172 case SL_PP_SUBASSIGN
:
192 case SL_PP_MULASSIGN
:
200 case SL_PP_DIVASSIGN
:
208 case SL_PP_MODASSIGN
:
216 case SL_PP_LSHIFTASSIGN
:
217 fprintf(out
, "<<= ");
224 case SL_PP_LESSEQUAL
:
232 case SL_PP_RSHIFTASSIGN
:
233 fprintf(out
, ">>= ");
240 case SL_PP_GREATEREQUAL
:
260 case SL_PP_BITANDASSIGN
:
272 case SL_PP_BITXORASSIGN
:
284 case SL_PP_BITORASSIGN
:
300 case SL_PP_IDENTIFIER
:
301 fprintf(out
, "%s ", sl_pp_context_cstr(&context
, tokens
[i
].data
.identifier
));
305 fprintf(out
, "(%s) ", sl_pp_context_cstr(&context
, tokens
[i
].data
.number
));
309 if (tokens
[i
].data
.other
== '\'') {
310 fprintf(out
, "'\\'' ");
312 fprintf(out
, "'%c' ", tokens
[i
].data
.other
);
321 sl_pp_context_destroy(&context
);