LCOV - code coverage report
Current view: top level - libreoffice/rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-12-17 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             : /****************** 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           0 : void RscFileInst::Init()
      34             : {
      35           0 :     nLineNo = 0;
      36           0 :     nLineBufLen = 256;
      37           0 :     pLine = (char *)rtl_allocateMemory( nLineBufLen );
      38           0 :     *pLine = '\0';
      39           0 :     nScanPos = 0;
      40           0 :     cLastChar = '\0';
      41           0 :     bEof = sal_False;
      42           0 : };
      43             : 
      44             : /*************************************************************************
      45             : |*
      46             : |*    RscFileInst::RscFileInst()
      47             : |*
      48             : *************************************************************************/
      49           0 : RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
      50           0 :                           sal_uLong lFIndex, FILE * fFile )
      51             : {
      52           0 :     pTypCont = pTC;
      53           0 :     Init();
      54             : 
      55           0 :     lFileIndex = lFIndex;
      56           0 :     lSrcIndex = lIndexSrc;
      57           0 :     fInputFile = fFile;
      58             : 
      59             :     //Status: Zeiger am Ende des Lesepuffers
      60           0 :     nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
      61           0 :     pInput    = (char *)rtl_allocateMemory( nInputBufLen );
      62           0 : }
      63             : 
      64             : /*************************************************************************
      65             : |*
      66             : |*    RscFileInst::~RscFileInst()
      67             : |*
      68             : *************************************************************************/
      69           0 : RscFileInst::~RscFileInst(){
      70           0 :     if( pInput )
      71           0 :         rtl_freeMemory( pInput );
      72           0 :     if( pLine )
      73           0 :         rtl_freeMemory( pLine );
      74           0 : }
      75             : 
      76             : /*************************************************************************
      77             : |*
      78             : |*    RscFileInst::GetChar()
      79             : |*
      80             : *************************************************************************/
      81           0 : int RscFileInst::GetChar()
      82             : {
      83           0 :     if( pLine[ nScanPos ] )
      84           0 :         return( pLine[ nScanPos++ ] );
      85           0 :     else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
      86             :     {
      87             :         // Dateiende
      88           0 :         bEof = sal_True;
      89           0 :         return 0;
      90             :     }
      91             :     else
      92             :     {
      93           0 :         GetNewLine();
      94           0 :         return( '\n' );
      95             :     }
      96             : }
      97             : 
      98             : /*************************************************************************
      99             : |*
     100             : |*    RscFileInst::GetNewLine()
     101             : |*
     102             : *************************************************************************/
     103           0 : void RscFileInst::GetNewLine()
     104             : {
     105           0 :     nLineNo++;
     106           0 :     nScanPos = 0;
     107             : 
     108             :     //laeuft bis Dateiende
     109           0 :     sal_uInt32 nLen = 0;
     110           0 :     while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
     111             :     {
     112           0 :         if( (nInputPos >= nInputEndPos) && fInputFile )
     113             :         {
     114           0 :             nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
     115           0 :             nInputPos = 0;
     116             :         }
     117             : 
     118           0 :         while( nInputPos < nInputEndPos )
     119             :         {
     120             :             //immer eine Zeile lesen
     121           0 :             if( nLen >= nLineBufLen )
     122             :             {
     123           0 :                 nLineBufLen += 256;
     124             :                 // einen dazu fuer '\0'
     125           0 :                 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
     126             :             }
     127             : 
     128             :             // cr lf, lf cr, lf oder cr wird '\0'
     129           0 :             if( pInput[ nInputPos ] == '\n' ){
     130           0 :                 nInputPos++;
     131           0 :                 if( cLastChar != '\r' ){
     132           0 :                     cLastChar = '\n';
     133           0 :                     pLine[ nLen++ ] = '\0';
     134           0 :                     goto END;
     135             :                 }
     136             :             }
     137           0 :             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           0 :                 pLine[ nLen++ ] = pInput[ nInputPos++ ];
     148           0 :                 if( nLen > 2 )
     149             :                 {
     150           0 :                     if( (unsigned char)pLine[nLen-3] == 0xef &&
     151           0 :                         (unsigned char)pLine[nLen-2] == 0xbb &&
     152           0 :                         (unsigned char)pLine[nLen-1] == 0xbf )
     153             :                     {
     154           0 :                         nLen -= 3;
     155             :                     }
     156             :                 }
     157             :             }
     158             :         };
     159             :     };
     160             : 
     161             :     // Abbruch ueber EOF
     162           0 :     pLine[ nLen ] = '\0';
     163             : 
     164             : END:
     165           0 :     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           0 : }
     174             : 
     175             : /*************************************************************************
     176             : |*
     177             : |*    RscFileInst::SetError()
     178             : |*
     179             : *************************************************************************/
     180           0 : void RscFileInst::SetError( ERRTYPE aError )
     181             : {
     182           0 :     if( aError.IsOk() )
     183             :     {
     184           0 :         aFirstError = aError;
     185           0 :         nErrorLine  = GetLineNo();
     186           0 :         nErrorPos   = GetScanPos() -1;
     187             :     };
     188           0 : };
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10