merge the formfield patch from ooo-build
[ooovba.git] / rsc / source / parser / rscpar.cxx
blob9b2461b8f6e0d20f4e7a1102a7df5ee2d1aaf4cd
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: rscpar.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_rsc.hxx"
33 /****************** I N C L U D E S **************************************/
34 // C and C++ Includes.
35 #include <string.h>
36 #include <rscpar.hxx>
37 #include <rscdb.hxx>
39 /****************** R s c F i l e I n s t ********************************/
40 /****************** C O D E **********************************************/
41 /*************************************************************************
43 |* RscFileInst::Init()
45 |* Beschreibung
46 |* Ersterstellung MM 05.11.91
47 |* Letzte Aenderung MM 17.02.93
49 *************************************************************************/
50 void RscFileInst::Init()
52 nLineNo = 0;
53 nLineBufLen = 256;
54 pLine = (char *)rtl_allocateMemory( nLineBufLen );
55 *pLine = '\0';
56 nScanPos = 0;
57 cLastChar = '\0';
58 bEof = FALSE;
61 /*************************************************************************
63 |* RscFileInst::RscFileInst()
65 |* Beschreibung
66 |* Ersterstellung MM 06.06.91
67 |* Letzte Aenderung MM 06.06.91
69 *************************************************************************/
70 RscFileInst::RscFileInst( RscTypCont * pTC, ULONG lIndexSrc,
71 ULONG lFIndex, FILE * fFile )
73 pTypCont = pTC;
74 Init();
76 lFileIndex = lFIndex;
77 lSrcIndex = lIndexSrc;
78 fInputFile = fFile;
80 //Status: Zeiger am Ende des Lesepuffers
81 nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
82 pInput = (char *)rtl_allocateMemory( nInputBufLen );
85 RscFileInst::RscFileInst( RscTypCont * pTC, ULONG lIndexSrc,
86 ULONG lFIndex, const ByteString& rBuf )
88 pTypCont = pTC;
89 Init();
90 lFileIndex = lFIndex;
91 lSrcIndex = lIndexSrc;
92 fInputFile = NULL;
93 nInputPos = 0;
94 nInputEndPos = rBuf.Len();
96 // Muss groesser sein wegen Eingabeende bei nInputBufLen < nInputEndPos
97 nInputBufLen = nInputEndPos +1;
98 pInput = (char *)rtl_allocateMemory( nInputBufLen +100 );
99 memcpy( pInput, rBuf.GetBuffer(), nInputEndPos );
102 /*************************************************************************
104 |* RscFileInst::~RscFileInst()
106 |* Beschreibung
107 |* Ersterstellung MM 06.06.91
108 |* Letzte Aenderung MM 06.06.91
110 *************************************************************************/
111 RscFileInst::~RscFileInst(){
112 if( pInput )
113 rtl_freeMemory( pInput );
114 if( pLine )
115 rtl_freeMemory( pLine );
118 /*************************************************************************
120 |* RscFileInst::GetChar()
122 |* Beschreibung
123 |* Ersterstellung MM 01.06.91
124 |* Letzte Aenderung MM 09.08.91
126 *************************************************************************/
127 int RscFileInst::GetChar()
129 if( pLine[ nScanPos ] )
130 return( pLine[ nScanPos++ ] );
131 else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
133 // Dateiende
134 bEof = TRUE;
135 return 0;
137 else
139 GetNewLine();
140 return( '\n' );
144 /*************************************************************************
146 |* RscFileInst::GetNewLine()
148 |* Beschreibung
149 |* Ersterstellung MM 06.06.91
150 |* Letzte Aenderung MM 06.06.91
152 *************************************************************************/
153 void RscFileInst::GetNewLine()
155 nLineNo++;
156 nScanPos = 0;
158 //laeuft bis Dateiende
159 sal_uInt32 nLen = 0;
160 while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
162 if( (nInputPos >= nInputEndPos) && fInputFile )
164 nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
165 nInputPos = 0;
168 while( nInputPos < nInputEndPos )
170 //immer eine Zeile lesen
171 if( nLen >= nLineBufLen )
173 nLineBufLen += 256;
174 // einen dazu fuer '\0'
175 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
178 // cr lf, lf cr, lf oder cr wird '\0'
179 if( pInput[ nInputPos ] == '\n' ){
180 nInputPos++;
181 if( cLastChar != '\r' ){
182 cLastChar = '\n';
183 pLine[ nLen++ ] = '\0';
184 goto END;
187 else if( pInput[ nInputPos ] == '\r' ){
188 nInputPos++;
189 if( cLastChar != '\n' ){
190 cLastChar = '\r';
191 pLine[ nLen++ ] = '\0';
192 goto END;
195 else
197 pLine[ nLen++ ] = pInput[ nInputPos++ ];
198 if( nLen > 2 )
200 if( (unsigned char)pLine[nLen-3] == 0xef &&
201 (unsigned char)pLine[nLen-2] == 0xbb &&
202 (unsigned char)pLine[nLen-1] == 0xbf )
204 nLen -= 3;
211 // Abbruch ueber EOF
212 pLine[ nLen ] = '\0';
214 END:
215 if( pTypCont->pEH->GetListFile() ){
216 char buf[ 10 ];
218 sprintf( buf, "%5d ", (int)GetLineNo() );
219 pTypCont->pEH->LstOut( buf );
220 pTypCont->pEH->LstOut( GetLine() );
221 pTypCont->pEH->LstOut( "\n" );
225 /*************************************************************************
227 |* RscFileInst::SetError()
229 |* Beschreibung
230 |* Ersterstellung MM 05.11.91
231 |* Letzte Aenderung MM 05.11.91
233 *************************************************************************/
234 void RscFileInst::SetError( ERRTYPE aError )
236 if( aError.IsOk() )
238 aFirstError = aError;
239 nErrorLine = GetLineNo();
240 nErrorPos = GetScanPos() -1;