1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 void RscFileInst::Init()
28 pLine
= static_cast<char *>(rtl_allocateMemory( nLineBufLen
));
35 RscFileInst::RscFileInst( RscTypCont
* pTC
, sal_uLong lIndexSrc
,
36 sal_uLong lFIndex
, FILE * fFile
)
44 lSrcIndex
= lIndexSrc
;
47 //Status: Zeiger am Ende des Lesepuffers
48 nInputPos
= nInputEndPos
= nInputBufLen
= READBUFFER_MAX
;
49 pInput
= static_cast<char *>(rtl_allocateMemory( nInputBufLen
));
52 RscFileInst::~RscFileInst()
55 rtl_freeMemory( pInput
);
57 rtl_freeMemory( pLine
);
60 int RscFileInst::GetChar()
62 if( pLine
[ nScanPos
] )
63 return pLine
[ nScanPos
++ ];
64 else if( nInputPos
>= nInputEndPos
&& nInputEndPos
!= nInputBufLen
)
77 void RscFileInst::GetNewLine()
82 //laeuft bis Dateiende
84 while( (nInputPos
< nInputEndPos
) || (nInputEndPos
== nInputBufLen
) )
86 if( (nInputPos
>= nInputEndPos
) && fInputFile
)
88 nInputEndPos
= fread( pInput
, 1, nInputBufLen
, fInputFile
);
92 while( nInputPos
< nInputEndPos
)
94 //immer eine Zeile lesen
95 if( nLen
>= nLineBufLen
)
98 // einen dazu fuer '\0'
99 pLine
= static_cast<char*>(rtl_reallocateMemory( pLine
, nLineBufLen
+1 ));
102 // cr lf, lf cr, lf oder cr wird '\0'
103 if( pInput
[ nInputPos
] == '\n' )
106 if( cLastChar
!= '\r' )
109 pLine
[ nLen
++ ] = '\0';
113 else if( pInput
[ nInputPos
] == '\r' )
116 if( cLastChar
!= '\n' )
119 pLine
[ nLen
++ ] = '\0';
125 pLine
[ nLen
++ ] = pInput
[ nInputPos
++ ];
128 if( (unsigned char)pLine
[nLen
-3] == 0xef &&
129 (unsigned char)pLine
[nLen
-2] == 0xbb &&
130 (unsigned char)pLine
[nLen
-1] == 0xbf )
140 pLine
[ nLen
] = '\0';
143 if( pTypCont
->pEH
->GetListFile() )
147 sprintf( buf
, "%5d ", (int)GetLineNo() );
148 pTypCont
->pEH
->LstOut( buf
);
149 pTypCont
->pEH
->LstOut( GetLine() );
150 pTypCont
->pEH
->LstOut( "\n" );
154 void RscFileInst::SetError( ERRTYPE aError
)
158 aFirstError
= aError
;
159 nErrorLine
= GetLineNo();
160 nErrorPos
= GetScanPos() -1;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */