1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <precomp.h> 29 #include "cx_c_pp.hxx" 30 31 32 33 // NOT FULLY DECLARED SERVICES 34 #include "c_dealer.hxx" 35 #include <tokens/parseinc.hxx> 36 #include <x_parse.hxx> 37 #include "all_toks.hxx" 38 39 40 namespace cpp 41 { 42 43 Context_Preprocessor::Context_Preprocessor( TkpContext & i_rFollowUpContext ) 44 : Cx_Base(&i_rFollowUpContext), 45 pContext_Parent(&i_rFollowUpContext), 46 pContext_PP_MacroParams( 0 ), 47 pContext_PP_Definition( new Context_PP_Definition(i_rFollowUpContext) ) 48 { 49 pContext_PP_MacroParams = new Context_PP_MacroParams(*pContext_PP_Definition); 50 } 51 52 void 53 Context_Preprocessor::ReadCharChain( CharacterSource & io_rText ) 54 { 55 jumpOverWhite( io_rText ); 56 jumpToWhite( io_rText ); 57 const char * sPP_Keyword = io_rText.CutToken(); 58 if ( strcmp(sPP_Keyword, "define") == 0 ) 59 ReadDefine(io_rText); 60 else 61 ReadDefault(io_rText); 62 } 63 64 void 65 Context_Preprocessor::AssignDealer( Distributor & o_rDealer ) 66 { 67 Cx_Base::AssignDealer(o_rDealer); 68 pContext_PP_MacroParams->AssignDealer(o_rDealer); 69 pContext_PP_Definition->AssignDealer(o_rDealer); 70 } 71 72 void 73 Context_Preprocessor::ReadDefault( CharacterSource & io_rText ) 74 { 75 int o_rCount_BackslashedLineBreaks = 0; 76 jumpToEol(io_rText,o_rCount_BackslashedLineBreaks); 77 for ( ; o_rCount_BackslashedLineBreaks > 0; --o_rCount_BackslashedLineBreaks ) 78 Dealer().Deal_Eol(); 79 80 if (io_rText.CurChar() != NULCH) 81 jumpOverEol(io_rText); 82 io_rText.CutToken(); 83 Dealer().Deal_Eol(); 84 SetNewToken(0); 85 SetFollowUpContext( pContext_Parent ); 86 } 87 88 void 89 Context_Preprocessor::ReadDefine( CharacterSource & io_rText ) 90 { 91 jumpOverWhite( io_rText ); 92 io_rText.CutToken(); 93 94 char cNext = '\0'; 95 for ( cNext = io_rText.CurChar(); 96 static_cast<UINT8>(cNext) > 32 AND cNext != '('; 97 cNext = io_rText.MoveOn() ) 98 { } 99 100 bool bMacro = cNext == '('; 101 102 if ( NOT bMacro ) 103 { 104 SetNewToken( new Tok_DefineName(io_rText.CutToken()) ); 105 SetFollowUpContext( pContext_PP_Definition.Ptr() ); 106 } 107 else 108 { 109 SetNewToken( new Tok_MacroName(io_rText.CutToken()) ); 110 io_rText.MoveOn(); 111 io_rText.CutToken(); 112 SetFollowUpContext( pContext_PP_MacroParams.Ptr() ); 113 } 114 } 115 116 117 Context_PP_MacroParams::Context_PP_MacroParams( Cx_Base & i_rFollowUpContext ) 118 : Cx_Base(&i_rFollowUpContext), 119 pContext_PP_Definition(&i_rFollowUpContext) 120 { 121 } 122 123 void 124 Context_PP_MacroParams::ReadCharChain( CharacterSource & io_rText ) 125 { 126 uintt nLen; 127 128 jumpOverWhite( io_rText ); 129 // KORR_FUTURE Handling line breaks within macro parameters: 130 char cSeparator = jumpTo( io_rText, ',', ')' ); 131 csv_assert( cSeparator != 0 ); 132 133 static char cBuf[500]; 134 // KORR_FUTURE, make it still safer, here: 135 strcpy( cBuf, io_rText.CutToken() ); // SAFE STRCPY (#100211# - checked) 136 for ( nLen = strlen(cBuf); 137 nLen > 0 AND cBuf[nLen-1] < 33; 138 --nLen ) 139 { } 140 cBuf[nLen] = '\0'; 141 SetNewToken( new Tok_MacroParameter(cBuf) ); 142 143 io_rText.MoveOn(); 144 io_rText.CutToken(); 145 if ( cSeparator == ',') 146 SetFollowUpContext( this ); 147 else // Must be ')' 148 SetFollowUpContext( pContext_PP_Definition ); 149 } 150 151 Context_PP_Definition::Context_PP_Definition( TkpContext & i_rFollowUpContext ) 152 : Cx_Base(&i_rFollowUpContext), 153 pContext_Parent(&i_rFollowUpContext) 154 { 155 } 156 157 void 158 Context_PP_Definition::ReadCharChain( CharacterSource & io_rText ) 159 { 160 int o_rCount_BackslashedLineBreaks = 0; 161 jumpToEol(io_rText,o_rCount_BackslashedLineBreaks); 162 for ( ; o_rCount_BackslashedLineBreaks > 0; --o_rCount_BackslashedLineBreaks ) 163 Dealer().Deal_Eol(); 164 SetNewToken( new Tok_PreProDefinition(io_rText.CutToken()) ); 165 if (io_rText.CurChar() != NULCH) 166 jumpOverEol(io_rText); 167 Dealer().Deal_Eol(); 168 } 169 170 171 } // namespace cpp 172 173 174 175 176 177 178 179 180 181