fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / rsc / source / parser / rscpar.cxx
blob088fce877d6f62592aa48eb7f76bd219061df751
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string.h>
21 #include <rscpar.hxx>
22 #include <rscdb.hxx>
24 void RscFileInst::Init()
26 nLineNo = 0;
27 nLineBufLen = 256;
28 pLine = static_cast<char *>(rtl_allocateMemory( nLineBufLen ));
29 *pLine = '\0';
30 nScanPos = 0;
31 cLastChar = '\0';
32 bEof = false;
35 RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
36 sal_uLong lFIndex, FILE * fFile )
37 : nErrorLine(0)
38 , nErrorPos(0)
40 pTypCont = pTC;
41 Init();
43 lFileIndex = lFIndex;
44 lSrcIndex = lIndexSrc;
45 fInputFile = fFile;
47 //Status: Zeiger am Ende des Lesepuffers
48 nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
49 pInput = static_cast<char *>(rtl_allocateMemory( nInputBufLen ));
52 RscFileInst::~RscFileInst()
54 if( pInput )
55 rtl_freeMemory( pInput );
56 if( pLine )
57 rtl_freeMemory( pLine );
60 int RscFileInst::GetChar()
62 if( pLine[ nScanPos ] )
63 return pLine[ nScanPos++ ];
64 else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
66 // Dateiende
67 bEof = true;
68 return 0;
70 else
72 GetNewLine();
73 return '\n';
77 void RscFileInst::GetNewLine()
79 nLineNo++;
80 nScanPos = 0;
82 //laeuft bis Dateiende
83 sal_uInt32 nLen = 0;
84 while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
86 if( (nInputPos >= nInputEndPos) && fInputFile )
88 nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
89 nInputPos = 0;
92 while( nInputPos < nInputEndPos )
94 //immer eine Zeile lesen
95 if( nLen >= nLineBufLen )
97 nLineBufLen += 256;
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' )
105 nInputPos++;
106 if( cLastChar != '\r' )
108 cLastChar = '\n';
109 pLine[ nLen++ ] = '\0';
110 goto END;
113 else if( pInput[ nInputPos ] == '\r' )
115 nInputPos++;
116 if( cLastChar != '\n' )
118 cLastChar = '\r';
119 pLine[ nLen++ ] = '\0';
120 goto END;
123 else
125 pLine[ nLen++ ] = pInput[ nInputPos++ ];
126 if( nLen > 2 )
128 if( (unsigned char)pLine[nLen-3] == 0xef &&
129 (unsigned char)pLine[nLen-2] == 0xbb &&
130 (unsigned char)pLine[nLen-1] == 0xbf )
132 nLen -= 3;
139 // Abbruch ueber EOF
140 pLine[ nLen ] = '\0';
142 END:
143 if( pTypCont->pEH->GetListFile() )
145 char buf[ 10 ];
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 )
156 if( aError.IsOk() )
158 aFirstError = aError;
159 nErrorLine = GetLineNo();
160 nErrorPos = GetScanPos() -1;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */