LCOV - code coverage report
Current view: top level - rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 66 76 86.8 %
Date: 2014-11-03 Functions: 6 6 100.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         475 : void RscFileInst::Init()
      25             : {
      26         475 :     nLineNo = 0;
      27         475 :     nLineBufLen = 256;
      28         475 :     pLine = (char *)rtl_allocateMemory( nLineBufLen );
      29         475 :     *pLine = '\0';
      30         475 :     nScanPos = 0;
      31         475 :     cLastChar = '\0';
      32         475 :     bEof = false;
      33         475 : }
      34             : 
      35         475 : RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
      36             :                           sal_uLong lFIndex, FILE * fFile )
      37             :     : nErrorLine(0)
      38         475 :     , nErrorPos(0)
      39             : {
      40         475 :     pTypCont = pTC;
      41         475 :     Init();
      42             : 
      43         475 :     lFileIndex = lFIndex;
      44         475 :     lSrcIndex = lIndexSrc;
      45         475 :     fInputFile = fFile;
      46             : 
      47             :     //Status: Zeiger am Ende des Lesepuffers
      48         475 :     nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
      49         475 :     pInput    = (char *)rtl_allocateMemory( nInputBufLen );
      50         475 : }
      51             : 
      52         475 : RscFileInst::~RscFileInst()
      53             : {
      54         475 :     if( pInput )
      55         475 :         rtl_freeMemory( pInput );
      56         475 :     if( pLine )
      57         475 :         rtl_freeMemory( pLine );
      58         475 : }
      59             : 
      60      208146 : int RscFileInst::GetChar()
      61             : {
      62      208146 :     if( pLine[ nScanPos ] )
      63           0 :         return pLine[ nScanPos++ ];
      64      208146 :     else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
      65             :     {
      66             :         // Dateiende
      67         838 :         bEof = true;
      68         838 :         return 0;
      69             :     }
      70             :     else
      71             :     {
      72      207308 :         GetNewLine();
      73      207308 :         return '\n';
      74             :     }
      75             : }
      76             : 
      77      207308 : void RscFileInst::GetNewLine()
      78             : {
      79      207308 :     nLineNo++;
      80      207308 :     nScanPos = 0;
      81             : 
      82             :     //laeuft bis Dateiende
      83      207308 :     sal_uInt32 nLen = 0;
      84      427710 :     while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
      85             :     {
      86      220401 :         if( (nInputPos >= nInputEndPos) && fInputFile )
      87             :         {
      88       14336 :             nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
      89       14336 :             nInputPos = 0;
      90             :         }
      91             : 
      92     3838152 :         while( nInputPos < nInputEndPos )
      93             :         {
      94             :             //immer eine Zeile lesen
      95     3604657 :             if( nLen >= nLineBufLen )
      96             :             {
      97          64 :                 nLineBufLen += 256;
      98             :                 // einen dazu fuer '\0'
      99          64 :                 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
     100             :             }
     101             : 
     102             :             // cr lf, lf cr, lf oder cr wird '\0'
     103     3604657 :             if( pInput[ nInputPos ] == '\n' )
     104             :             {
     105      207307 :                 nInputPos++;
     106      207307 :                 if( cLastChar != '\r' )
     107             :                 {
     108      207307 :                     cLastChar = '\n';
     109      207307 :                     pLine[ nLen++ ] = '\0';
     110      207307 :                     goto END;
     111             :                 }
     112             :             }
     113     3397350 :             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     3397350 :                 pLine[ nLen++ ] = pInput[ nInputPos++ ];
     126     3397350 :                 if( nLen > 2 )
     127             :                 {
     128     3024322 :                     if( (unsigned char)pLine[nLen-3] == 0xef &&
     129         838 :                         (unsigned char)pLine[nLen-2] == 0xbb &&
     130         419 :                         (unsigned char)pLine[nLen-1] == 0xbf )
     131             :                     {
     132         419 :                         nLen -= 3;
     133             :                     }
     134             :                 }
     135             :             }
     136             :         }
     137             :     }
     138             : 
     139             :     // Abbruch ueber EOF
     140           1 :     pLine[ nLen ] = '\0';
     141             : 
     142             : END:
     143      207308 :     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      207308 : }
     153             : 
     154         419 : void RscFileInst::SetError( ERRTYPE aError )
     155             : {
     156         419 :     if( aError.IsOk() )
     157             :     {
     158         419 :         aFirstError = aError;
     159         419 :         nErrorLine  = GetLineNo();
     160         419 :         nErrorPos   = GetScanPos() -1;
     161             :     }
     162         419 : };
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10