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

Generated by: LCOV version 1.11