LCOV - code coverage report
Current view: top level - libreoffice/rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 76 86.8 %
Date: 2012-12-27 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             : /****************** I N C L U D E S **************************************/
      21             : // C and C++ Includes.
      22             : #include <string.h>
      23             : #include <rscpar.hxx>
      24             : #include <rscdb.hxx>
      25             : 
      26             : /****************** R s c F i l e I n s t ********************************/
      27             : /****************** C O D E **********************************************/
      28             : /*************************************************************************
      29             : |*
      30             : |*    RscFileInst::Init()
      31             : |*
      32             : *************************************************************************/
      33         754 : void RscFileInst::Init()
      34             : {
      35         754 :     nLineNo = 0;
      36         754 :     nLineBufLen = 256;
      37         754 :     pLine = (char *)rtl_allocateMemory( nLineBufLen );
      38         754 :     *pLine = '\0';
      39         754 :     nScanPos = 0;
      40         754 :     cLastChar = '\0';
      41         754 :     bEof = sal_False;
      42         754 : };
      43             : 
      44             : /*************************************************************************
      45             : |*
      46             : |*    RscFileInst::RscFileInst()
      47             : |*
      48             : *************************************************************************/
      49         754 : RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
      50         754 :                           sal_uLong lFIndex, FILE * fFile )
      51             : {
      52         754 :     pTypCont = pTC;
      53         754 :     Init();
      54             : 
      55         754 :     lFileIndex = lFIndex;
      56         754 :     lSrcIndex = lIndexSrc;
      57         754 :     fInputFile = fFile;
      58             : 
      59             :     //Status: Zeiger am Ende des Lesepuffers
      60         754 :     nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
      61         754 :     pInput    = (char *)rtl_allocateMemory( nInputBufLen );
      62         754 : }
      63             : 
      64             : /*************************************************************************
      65             : |*
      66             : |*    RscFileInst::~RscFileInst()
      67             : |*
      68             : *************************************************************************/
      69         754 : RscFileInst::~RscFileInst(){
      70         754 :     if( pInput )
      71         754 :         rtl_freeMemory( pInput );
      72         754 :     if( pLine )
      73         754 :         rtl_freeMemory( pLine );
      74         754 : }
      75             : 
      76             : /*************************************************************************
      77             : |*
      78             : |*    RscFileInst::GetChar()
      79             : |*
      80             : *************************************************************************/
      81      345406 : int RscFileInst::GetChar()
      82             : {
      83      345406 :     if( pLine[ nScanPos ] )
      84           0 :         return( pLine[ nScanPos++ ] );
      85      345406 :     else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
      86             :     {
      87             :         // Dateiende
      88        1384 :         bEof = sal_True;
      89        1384 :         return 0;
      90             :     }
      91             :     else
      92             :     {
      93      344022 :         GetNewLine();
      94      344022 :         return( '\n' );
      95             :     }
      96             : }
      97             : 
      98             : /*************************************************************************
      99             : |*
     100             : |*    RscFileInst::GetNewLine()
     101             : |*
     102             : *************************************************************************/
     103      344022 : void RscFileInst::GetNewLine()
     104             : {
     105      344022 :     nLineNo++;
     106      344022 :     nScanPos = 0;
     107             : 
     108             :     //laeuft bis Dateiende
     109      344022 :     sal_uInt32 nLen = 0;
     110      711815 :     while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
     111             :     {
     112      367788 :         if( (nInputPos >= nInputEndPos) && fInputFile )
     113             :         {
     114       25852 :             nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
     115       25852 :             nInputPos = 0;
     116             :         }
     117             : 
     118     6903790 :         while( nInputPos < nInputEndPos )
     119             :         {
     120             :             //immer eine Zeile lesen
     121     6512231 :             if( nLen >= nLineBufLen )
     122             :             {
     123         228 :                 nLineBufLen += 256;
     124             :                 // einen dazu fuer '\0'
     125         228 :                 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
     126             :             }
     127             : 
     128             :             // cr lf, lf cr, lf oder cr wird '\0'
     129     6512231 :             if( pInput[ nInputPos ] == '\n' ){
     130      344017 :                 nInputPos++;
     131      344017 :                 if( cLastChar != '\r' ){
     132      344017 :                     cLastChar = '\n';
     133      344017 :                     pLine[ nLen++ ] = '\0';
     134      344017 :                     goto END;
     135             :                 }
     136             :             }
     137     6168214 :             else if( pInput[ nInputPos ] == '\r' ){
     138           0 :                 nInputPos++;
     139           0 :                 if( cLastChar != '\n' ){
     140           0 :                     cLastChar = '\r';
     141           0 :                     pLine[ nLen++ ] = '\0';
     142           0 :                     goto END;
     143             :                 }
     144             :             }
     145             :             else
     146             :             {
     147     6168214 :                 pLine[ nLen++ ] = pInput[ nInputPos++ ];
     148     6168214 :                 if( nLen > 2 )
     149             :                 {
     150     5536545 :                     if( (unsigned char)pLine[nLen-3] == 0xef &&
     151         692 :                         (unsigned char)pLine[nLen-2] == 0xbb &&
     152         692 :                         (unsigned char)pLine[nLen-1] == 0xbf )
     153             :                     {
     154         692 :                         nLen -= 3;
     155             :                     }
     156             :                 }
     157             :             }
     158             :         };
     159             :     };
     160             : 
     161             :     // Abbruch ueber EOF
     162           5 :     pLine[ nLen ] = '\0';
     163             : 
     164             : END:
     165      344022 :     if( pTypCont->pEH->GetListFile() ){
     166             :         char buf[ 10 ];
     167             : 
     168           0 :         sprintf( buf, "%5d ", (int)GetLineNo() );
     169           0 :         pTypCont->pEH->LstOut( buf );
     170           0 :         pTypCont->pEH->LstOut( GetLine() );
     171           0 :         pTypCont->pEH->LstOut( "\n" );
     172             :     }
     173      344022 : }
     174             : 
     175             : /*************************************************************************
     176             : |*
     177             : |*    RscFileInst::SetError()
     178             : |*
     179             : *************************************************************************/
     180         692 : void RscFileInst::SetError( ERRTYPE aError )
     181             : {
     182         692 :     if( aError.IsOk() )
     183             :     {
     184         692 :         aFirstError = aError;
     185         692 :         nErrorLine  = GetLineNo();
     186         692 :         nErrorPos   = GetScanPos() -1;
     187             :     };
     188         692 : };
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10