LCOV - code coverage report
Current view: top level - rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 76 0.0 %
Date: 2014-04-14 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <string.h>
      21             : #include <rscpar.hxx>
      22             : #include <rscdb.hxx>
      23             : 
      24           0 : void RscFileInst::Init()
      25             : {
      26           0 :     nLineNo = 0;
      27           0 :     nLineBufLen = 256;
      28           0 :     pLine = (char *)rtl_allocateMemory( nLineBufLen );
      29           0 :     *pLine = '\0';
      30           0 :     nScanPos = 0;
      31           0 :     cLastChar = '\0';
      32           0 :     bEof = false;
      33           0 : }
      34             : 
      35           0 : RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
      36             :                           sal_uLong lFIndex, FILE * fFile )
      37             :     : nErrorLine(0)
      38           0 :     , nErrorPos(0)
      39             : {
      40           0 :     pTypCont = pTC;
      41           0 :     Init();
      42             : 
      43           0 :     lFileIndex = lFIndex;
      44           0 :     lSrcIndex = lIndexSrc;
      45           0 :     fInputFile = fFile;
      46             : 
      47             :     //Status: Zeiger am Ende des Lesepuffers
      48           0 :     nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
      49           0 :     pInput    = (char *)rtl_allocateMemory( nInputBufLen );
      50           0 : }
      51             : 
      52           0 : RscFileInst::~RscFileInst()
      53             : {
      54           0 :     if( pInput )
      55           0 :         rtl_freeMemory( pInput );
      56           0 :     if( pLine )
      57           0 :         rtl_freeMemory( pLine );
      58           0 : }
      59             : 
      60           0 : int RscFileInst::GetChar()
      61             : {
      62           0 :     if( pLine[ nScanPos ] )
      63           0 :         return pLine[ nScanPos++ ];
      64           0 :     else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
      65             :     {
      66             :         // Dateiende
      67           0 :         bEof = true;
      68           0 :         return 0;
      69             :     }
      70             :     else
      71             :     {
      72           0 :         GetNewLine();
      73           0 :         return '\n';
      74             :     }
      75             : }
      76             : 
      77           0 : void RscFileInst::GetNewLine()
      78             : {
      79           0 :     nLineNo++;
      80           0 :     nScanPos = 0;
      81             : 
      82             :     //laeuft bis Dateiende
      83           0 :     sal_uInt32 nLen = 0;
      84           0 :     while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
      85             :     {
      86           0 :         if( (nInputPos >= nInputEndPos) && fInputFile )
      87             :         {
      88           0 :             nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
      89           0 :             nInputPos = 0;
      90             :         }
      91             : 
      92           0 :         while( nInputPos < nInputEndPos )
      93             :         {
      94             :             //immer eine Zeile lesen
      95           0 :             if( nLen >= nLineBufLen )
      96             :             {
      97           0 :                 nLineBufLen += 256;
      98             :                 // einen dazu fuer '\0'
      99           0 :                 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
     100             :             }
     101             : 
     102             :             // cr lf, lf cr, lf oder cr wird '\0'
     103           0 :             if( pInput[ nInputPos ] == '\n' )
     104             :             {
     105           0 :                 nInputPos++;
     106           0 :                 if( cLastChar != '\r' )
     107             :                 {
     108           0 :                     cLastChar = '\n';
     109           0 :                     pLine[ nLen++ ] = '\0';
     110           0 :                     goto END;
     111             :                 }
     112             :             }
     113           0 :             else if( pInput[ nInputPos ] == '\r' )
     114             :             {
     115           0 :                 nInputPos++;
     116           0 :                 if( cLastChar != '\n' )
     117             :                 {
     118           0 :                     cLastChar = '\r';
     119           0 :                     pLine[ nLen++ ] = '\0';
     120           0 :                     goto END;
     121             :                 }
     122             :             }
     123             :             else
     124             :             {
     125           0 :                 pLine[ nLen++ ] = pInput[ nInputPos++ ];
     126           0 :                 if( nLen > 2 )
     127             :                 {
     128           0 :                     if( (unsigned char)pLine[nLen-3] == 0xef &&
     129           0 :                         (unsigned char)pLine[nLen-2] == 0xbb &&
     130           0 :                         (unsigned char)pLine[nLen-1] == 0xbf )
     131             :                     {
     132           0 :                         nLen -= 3;
     133             :                     }
     134             :                 }
     135             :             }
     136             :         };
     137             :     };
     138             : 
     139             :     // Abbruch ueber EOF
     140           0 :     pLine[ nLen ] = '\0';
     141             : 
     142             : END:
     143           0 :     if( pTypCont->pEH->GetListFile() )
     144             :     {
     145             :         char buf[ 10 ];
     146             : 
     147           0 :         sprintf( buf, "%5d ", (int)GetLineNo() );
     148           0 :         pTypCont->pEH->LstOut( buf );
     149           0 :         pTypCont->pEH->LstOut( GetLine() );
     150           0 :         pTypCont->pEH->LstOut( "\n" );
     151             :     }
     152           0 : }
     153             : 
     154           0 : void RscFileInst::SetError( ERRTYPE aError )
     155             : {
     156           0 :     if( aError.IsOk() )
     157             :     {
     158           0 :         aFirstError = aError;
     159           0 :         nErrorLine  = GetLineNo();
     160           0 :         nErrorPos   = GetScanPos() -1;
     161             :     };
     162           0 : };
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10