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: rscpar.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 ************************************************************************/
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.
39 /****************** R s c F i l e I n s t ********************************/
40 /****************** C O D E **********************************************/
41 /*************************************************************************
43 |* RscFileInst::Init()
46 |* Ersterstellung MM 05.11.91
47 |* Letzte Aenderung MM 17.02.93
49 *************************************************************************/
50 void RscFileInst::Init()
54 pLine
= (char *)rtl_allocateMemory( nLineBufLen
);
61 /*************************************************************************
63 |* RscFileInst::RscFileInst()
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
)
77 lSrcIndex
= lIndexSrc
;
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
)
91 lSrcIndex
= lIndexSrc
;
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()
107 |* Ersterstellung MM 06.06.91
108 |* Letzte Aenderung MM 06.06.91
110 *************************************************************************/
111 RscFileInst::~RscFileInst(){
113 rtl_freeMemory( pInput
);
115 rtl_freeMemory( pLine
);
118 /*************************************************************************
120 |* RscFileInst::GetChar()
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
)
144 /*************************************************************************
146 |* RscFileInst::GetNewLine()
149 |* Ersterstellung MM 06.06.91
150 |* Letzte Aenderung MM 06.06.91
152 *************************************************************************/
153 void RscFileInst::GetNewLine()
158 //laeuft bis Dateiende
160 while( (nInputPos
< nInputEndPos
) || (nInputEndPos
== nInputBufLen
) )
162 if( (nInputPos
>= nInputEndPos
) && fInputFile
)
164 nInputEndPos
= fread( pInput
, 1, nInputBufLen
, fInputFile
);
168 while( nInputPos
< nInputEndPos
)
170 //immer eine Zeile lesen
171 if( nLen
>= nLineBufLen
)
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' ){
181 if( cLastChar
!= '\r' ){
183 pLine
[ nLen
++ ] = '\0';
187 else if( pInput
[ nInputPos
] == '\r' ){
189 if( cLastChar
!= '\n' ){
191 pLine
[ nLen
++ ] = '\0';
197 pLine
[ nLen
++ ] = pInput
[ nInputPos
++ ];
200 if( (unsigned char)pLine
[nLen
-3] == 0xef &&
201 (unsigned char)pLine
[nLen
-2] == 0xbb &&
202 (unsigned char)pLine
[nLen
-1] == 0xbf )
212 pLine
[ nLen
] = '\0';
215 if( pTypCont
->pEH
->GetListFile() ){
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()
230 |* Ersterstellung MM 05.11.91
231 |* Letzte Aenderung MM 05.11.91
233 *************************************************************************/
234 void RscFileInst::SetError( ERRTYPE aError
)
238 aFirstError
= aError
;
239 nErrorLine
= GetLineNo();
240 nErrorPos
= GetScanPos() -1;