merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / parser / tokens / tkpstama.cxx
bloba67eb40e2d8a104dd50e36db37012df939ffb3ba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tkpstama.cxx,v $
10 * $Revision: 1.9 $
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 ************************************************************************/
31 #include <precomp.h>
32 #include <tokens/tkpstama.hxx>
34 // NOT FULLY DECLARED SERVICES
35 // #include <srcfind.hxx>
36 #include <tokens/stmstarr.hxx>
37 //#include <parseinc.hxx>
38 #include <tools/tkpchars.hxx>
41 const intt C_nStatuslistResizeValue = 32;
42 const intt C_nTopStatus = 0;
44 StateMachine::StateMachine( intt in_nStatusSize,
45 intt in_nInitial_StatusListSize )
46 : pStati(new StmStatus*[in_nInitial_StatusListSize]),
47 nCurrentStatus(C_nTopStatus),
48 nPeekedStatus(C_nTopStatus),
49 nStatusSize(in_nStatusSize),
50 nNrofStati(0),
51 nStatiSpace(in_nInitial_StatusListSize)
53 csv_assert(in_nStatusSize > 0);
54 csv_assert(in_nInitial_StatusListSize > 0);
56 memset(pStati, 0, sizeof(StmStatus*) * nStatiSpace);
59 intt
60 StateMachine::AddStatus(StmStatus * let_dpStatus)
62 if (nNrofStati == nStatiSpace)
64 ResizeStati();
66 pStati[nNrofStati] = let_dpStatus;
67 return nNrofStati++;
70 void
71 StateMachine::AddToken( const char * in_sToken,
72 TextToken::F_CRTOK in_fTokenCreateFunction,
73 const INT16 * in_aBranches,
74 INT16 in_nBoundsStatus )
76 if (csv::no_str(in_sToken))
77 return;
79 // Durch existierende Stati durchhangeln:
80 nCurrentStatus = 0;
81 nPeekedStatus = 0;
83 for ( const char * pChar = in_sToken;
84 *pChar != NULCH;
85 ++pChar )
87 Peek(*pChar);
88 StmStatus & rPst = Status(nPeekedStatus);
89 if ( rPst.IsADefault() OR rPst.AsBounds() != 0 )
91 nPeekedStatus = AddStatus( new StmArrayStatus(nStatusSize, in_aBranches, 0, false ) );
92 CurrentStatus().SetBranch( *pChar, nPeekedStatus );
94 nCurrentStatus = nPeekedStatus;
95 } // end for
96 StmArrayStatus & rLastStatus = CurrentStatus();
97 rLastStatus.SetTokenCreateFunction(in_fTokenCreateFunction);
98 for (intt i = 0; i < nStatusSize; i++)
100 if (Status(rLastStatus.NextBy(i)).AsBounds() != 0)
101 rLastStatus.SetBranch(i,in_nBoundsStatus);
102 } // end for
105 StateMachine::~StateMachine()
107 for (intt i = 0; i < nNrofStati; i++)
109 delete pStati[i];
111 delete [] pStati;
114 StmBoundsStatus &
115 StateMachine::GetCharChain( TextToken::F_CRTOK & o_nTokenCreateFunction,
116 CharacterSource & io_rText )
118 nCurrentStatus = C_nTopStatus;
120 Peek(io_rText.CurChar());
121 while (BoundsStatus() == 0)
123 nCurrentStatus = nPeekedStatus;
124 Peek(io_rText.MoveOn());
126 o_nTokenCreateFunction = CurrentStatus().TokenCreateFunction();
128 return *BoundsStatus();
131 void
132 StateMachine::ResizeStati()
134 intt nNewSize = nStatiSpace + C_nStatuslistResizeValue;
135 intt i = 0;
136 StatusList pNewStati = new StmStatus*[nNewSize];
138 for ( ; i < nNrofStati; i++)
140 pNewStati[i] = pStati[i];
142 memset( pNewStati+i,
144 (nNewSize-i) * sizeof(StmStatus*) );
146 delete [] pStati;
147 pStati = pNewStati;
148 nStatiSpace = nNewSize;
151 StmStatus &
152 StateMachine::Status(intt in_nStatusNr) const
154 csv_assert( csv::in_range(intt(0), in_nStatusNr, intt(nNrofStati)) );
155 return *pStati[in_nStatusNr];
158 StmArrayStatus &
159 StateMachine::CurrentStatus() const
161 StmArrayStatus * pCurSt = Status(nCurrentStatus).AsArray();
163 csv_assert(pCurSt != 0);
164 // if(pCurSt == 0)
165 // csv_assert(false);
166 return *pCurSt;
169 StmBoundsStatus *
170 StateMachine::BoundsStatus() const
172 return Status(nPeekedStatus).AsBounds();
175 void
176 StateMachine::Peek(intt in_nBranch)
178 StmArrayStatus & rSt = CurrentStatus();
179 nPeekedStatus = rSt.NextBy(in_nBranch);