1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cx_c_pp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include "cx_c_pp.hxx"
36 // NOT FULLY DECLARED SERVICES
37 #include "c_dealer.hxx"
38 #include <tokens/parseinc.hxx>
39 #include <x_parse.hxx>
40 #include "all_toks.hxx"
46 Context_Preprocessor::Context_Preprocessor( TkpContext
& i_rFollowUpContext
)
47 : Cx_Base(&i_rFollowUpContext
),
48 pContext_Parent(&i_rFollowUpContext
),
49 pContext_PP_MacroParams( 0 ),
50 pContext_PP_Definition( new Context_PP_Definition(i_rFollowUpContext
) )
52 pContext_PP_MacroParams
= new Context_PP_MacroParams(*pContext_PP_Definition
);
56 Context_Preprocessor::ReadCharChain( CharacterSource
& io_rText
)
58 jumpOverWhite( io_rText
);
59 jumpToWhite( io_rText
);
60 const char * sPP_Keyword
= io_rText
.CutToken();
61 if ( strcmp(sPP_Keyword
, "define") == 0 )
64 ReadDefault(io_rText
);
68 Context_Preprocessor::AssignDealer( Distributor
& o_rDealer
)
70 Cx_Base::AssignDealer(o_rDealer
);
71 pContext_PP_MacroParams
->AssignDealer(o_rDealer
);
72 pContext_PP_Definition
->AssignDealer(o_rDealer
);
76 Context_Preprocessor::ReadDefault( CharacterSource
& io_rText
)
78 int o_rCount_BackslashedLineBreaks
= 0;
79 jumpToEol(io_rText
,o_rCount_BackslashedLineBreaks
);
80 for ( ; o_rCount_BackslashedLineBreaks
> 0; --o_rCount_BackslashedLineBreaks
)
83 if (io_rText
.CurChar() != NULCH
)
84 jumpOverEol(io_rText
);
88 SetFollowUpContext( pContext_Parent
);
92 Context_Preprocessor::ReadDefine( CharacterSource
& io_rText
)
94 jumpOverWhite( io_rText
);
98 for ( cNext
= io_rText
.CurChar();
99 static_cast<UINT8
>(cNext
) > 32 AND cNext
!= '(';
100 cNext
= io_rText
.MoveOn() )
103 bool bMacro
= cNext
== '(';
107 SetNewToken( new Tok_DefineName(io_rText
.CutToken()) );
108 SetFollowUpContext( pContext_PP_Definition
.Ptr() );
112 SetNewToken( new Tok_MacroName(io_rText
.CutToken()) );
115 SetFollowUpContext( pContext_PP_MacroParams
.Ptr() );
120 Context_PP_MacroParams::Context_PP_MacroParams( Cx_Base
& i_rFollowUpContext
)
121 : Cx_Base(&i_rFollowUpContext
),
122 pContext_PP_Definition(&i_rFollowUpContext
)
127 Context_PP_MacroParams::ReadCharChain( CharacterSource
& io_rText
)
131 jumpOverWhite( io_rText
);
132 // KORR_FUTURE Handling line breaks within macro parameters:
133 char cSeparator
= jumpTo( io_rText
, ',', ')' );
134 csv_assert( cSeparator
!= 0 );
136 static char cBuf
[500];
137 // KORR_FUTURE, make it still safer, here:
138 strcpy( cBuf
, io_rText
.CutToken() ); // SAFE STRCPY (#100211# - checked)
139 for ( nLen
= strlen(cBuf
);
140 nLen
> 0 AND cBuf
[nLen
-1] < 33;
144 SetNewToken( new Tok_MacroParameter(cBuf
) );
148 if ( cSeparator
== ',')
149 SetFollowUpContext( this );
151 SetFollowUpContext( pContext_PP_Definition
);
154 Context_PP_Definition::Context_PP_Definition( TkpContext
& i_rFollowUpContext
)
155 : Cx_Base(&i_rFollowUpContext
),
156 pContext_Parent(&i_rFollowUpContext
)
161 Context_PP_Definition::ReadCharChain( CharacterSource
& io_rText
)
163 int o_rCount_BackslashedLineBreaks
= 0;
164 jumpToEol(io_rText
,o_rCount_BackslashedLineBreaks
);
165 for ( ; o_rCount_BackslashedLineBreaks
> 0; --o_rCount_BackslashedLineBreaks
)
167 SetNewToken( new Tok_PreProDefinition(io_rText
.CutToken()) );
168 if (io_rText
.CurChar() != NULCH
)
169 jumpOverEol(io_rText
);