daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | /****************************************************************************\ |
| 7 | Copyright (c) 2002, NVIDIA Corporation. |
| 8 | |
| 9 | NVIDIA Corporation("NVIDIA") supplies this software to you in |
| 10 | consideration of your agreement to the following terms, and your use, |
| 11 | installation, modification or redistribution of this NVIDIA software |
| 12 | constitutes acceptance of these terms. If you do not agree with these |
| 13 | terms, please do not use, install, modify or redistribute this NVIDIA |
| 14 | software. |
| 15 | |
| 16 | In consideration of your agreement to abide by the following terms, and |
| 17 | subject to these terms, NVIDIA grants you a personal, non-exclusive |
| 18 | license, under NVIDIA's copyrights in this original NVIDIA software (the |
| 19 | "NVIDIA Software"), to use, reproduce, modify and redistribute the |
| 20 | NVIDIA Software, with or without modifications, in source and/or binary |
| 21 | forms; provided that if you redistribute the NVIDIA Software, you must |
| 22 | retain the copyright notice of NVIDIA, this notice and the following |
| 23 | text and disclaimers in all such redistributions of the NVIDIA Software. |
| 24 | Neither the name, trademarks, service marks nor logos of NVIDIA |
| 25 | Corporation may be used to endorse or promote products derived from the |
| 26 | NVIDIA Software without specific prior written permission from NVIDIA. |
| 27 | Except as expressly stated in this notice, no other rights or licenses |
| 28 | express or implied, are granted by NVIDIA herein, including but not |
| 29 | limited to any patent rights that may be infringed by your derivative |
| 30 | works or by other works in which the NVIDIA Software may be |
| 31 | incorporated. No hardware is licensed hereunder. |
| 32 | |
| 33 | THE NVIDIA SOFTWARE IS BEING PROVIDED ON AN "AS IS" BASIS, WITHOUT |
| 34 | WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 35 | INCLUDING WITHOUT LIMITATION, WARRANTIES OR CONDITIONS OF TITLE, |
| 36 | NON-INFRINGEMENT, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
| 37 | ITS USE AND OPERATION EITHER ALONE OR IN COMBINATION WITH OTHER |
| 38 | PRODUCTS. |
| 39 | |
| 40 | IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, |
| 41 | INCIDENTAL, EXEMPLARY, CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 42 | TO, LOST PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
| 43 | USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR ARISING IN ANY WAY |
| 44 | OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE |
| 45 | NVIDIA SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, |
| 46 | TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF |
| 47 | NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | \****************************************************************************/ |
| 49 | // |
| 50 | // cppstruct.c |
| 51 | // |
| 52 | |
| 53 | #include <stdio.h> |
| 54 | #include <stdlib.h> |
| 55 | |
| 56 | #include "slglobals.h" |
| 57 | |
| 58 | CPPStruct *cpp = NULL; |
| 59 | static int refCount = 0; |
| 60 | |
| 61 | int InitPreprocessor(void); |
| 62 | int ResetPreprocessor(void); |
| 63 | int FreeCPPStruct(void); |
| 64 | int FinalizePreprocessor(void); |
| 65 | |
| 66 | /* |
| 67 | * InitCPPStruct() - Initilaize the CPP structure. |
| 68 | * |
| 69 | */ |
| 70 | |
| 71 | int InitCPPStruct(void) |
| 72 | { |
| 73 | int len; |
| 74 | char *p; |
| 75 | |
| 76 | cpp = (CPPStruct *) malloc(sizeof(CPPStruct)); |
| 77 | if (cpp == NULL) |
| 78 | return 0; |
| 79 | |
| 80 | refCount++; |
| 81 | |
| 82 | // Initialize public members: |
| 83 | cpp->pLastSourceLoc = &cpp->lastSourceLoc; |
| 84 | |
| 85 | p = (char *) &cpp->options; |
| 86 | len = sizeof(cpp->options); |
| 87 | while (--len >= 0) |
| 88 | p[len] = 0; |
| 89 | |
| 90 | ResetPreprocessor(); |
| 91 | return 1; |
| 92 | } // InitCPPStruct |
| 93 | |
| 94 | int ResetPreprocessor(void) |
| 95 | { |
| 96 | // Initialize private members: |
| 97 | |
| 98 | cpp->lastSourceLoc.file = 0; |
| 99 | cpp->lastSourceLoc.line = 0; |
| 100 | cpp->pC=0; |
| 101 | cpp->CompileError=0; |
| 102 | cpp->ifdepth=0; |
| 103 | for(cpp->elsetracker=0; cpp->elsetracker<64; cpp->elsetracker++) |
| 104 | cpp->elsedepth[cpp->elsetracker]=0; |
| 105 | cpp->elsetracker=0; |
| 106 | cpp->tokensBeforeEOF = 0; |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | //Intializing the Preprocessor. |
| 111 | |
| 112 | int InitPreprocessor(void) |
| 113 | { |
| 114 | # define CPP_STUFF true |
| 115 | # ifdef CPP_STUFF |
| 116 | FreeCPPStruct(); |
| 117 | InitCPPStruct(); |
| 118 | cpp->options.Quiet = 1; |
| 119 | cpp->options.profileString = "generic"; |
| 120 | if (!InitAtomTable(atable, 0)) |
| 121 | return 1; |
| 122 | if (!InitScanner(cpp)) |
| 123 | return 1; |
| 124 | # endif |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | //FreeCPPStruct() - Free the CPP structure. |
| 129 | |
| 130 | int FreeCPPStruct(void) |
| 131 | { |
| 132 | if (refCount) |
| 133 | { |
| 134 | free(cpp); |
| 135 | refCount--; |
| 136 | } |
| 137 | |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | //Finalizing the Preprocessor. |
| 142 | |
| 143 | int FinalizePreprocessor(void) |
| 144 | { |
| 145 | # define CPP_STUFF true |
| 146 | # ifdef CPP_STUFF |
| 147 | FreeAtomTable(atable); |
| 148 | FreeCPPStruct(); |
| 149 | FreeScanner(); |
| 150 | # endif |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 156 | ////////////////////////////////////// End of cppstruct.c ////////////////////////////////////// |
| 157 | /////////////////////////////////////////////////////////////////////////////////////////////// |