LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 76 86.8 %
Date: 2013-07-09 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         687 : void RscFileInst::Init()
      25             : {
      26         687 :     nLineNo = 0;
      27         687 :     nLineBufLen = 256;
      28         687 :     pLine = (char *)rtl_allocateMemory( nLineBufLen );
      29         687 :     *pLine = '\0';
      30         687 :     nScanPos = 0;
      31         687 :     cLastChar = '\0';
      32         687 :     bEof = false;
      33         687 : }
      34             : 
      35         687 : RscFileInst::RscFileInst( RscTypCont * pTC, sal_uLong lIndexSrc,
      36         687 :                           sal_uLong lFIndex, FILE * fFile )
      37             : {
      38         687 :     pTypCont = pTC;
      39         687 :     Init();
      40             : 
      41         687 :     lFileIndex = lFIndex;
      42         687 :     lSrcIndex = lIndexSrc;
      43         687 :     fInputFile = fFile;
      44             : 
      45             :     //Status: Zeiger am Ende des Lesepuffers
      46         687 :     nInputPos = nInputEndPos = nInputBufLen = READBUFFER_MAX;
      47         687 :     pInput    = (char *)rtl_allocateMemory( nInputBufLen );
      48         687 : }
      49             : 
      50         687 : RscFileInst::~RscFileInst()
      51             : {
      52         687 :     if( pInput )
      53         687 :         rtl_freeMemory( pInput );
      54         687 :     if( pLine )
      55         687 :         rtl_freeMemory( pLine );
      56         687 : }
      57             : 
      58      305859 : int RscFileInst::GetChar()
      59             : {
      60      305859 :     if( pLine[ nScanPos ] )
      61           0 :         return pLine[ nScanPos++ ];
      62      305859 :     else if( nInputPos >= nInputEndPos && nInputEndPos != nInputBufLen )
      63             :     {
      64             :         // Dateiende
      65        1254 :         bEof = true;
      66        1254 :         return 0;
      67             :     }
      68             :     else
      69             :     {
      70      304605 :         GetNewLine();
      71      304605 :         return '\n';
      72             :     }
      73             : }
      74             : 
      75      304605 : void RscFileInst::GetNewLine()
      76             : {
      77      304605 :     nLineNo++;
      78      304605 :     nScanPos = 0;
      79             : 
      80             :     //laeuft bis Dateiende
      81      304605 :     sal_uInt32 nLen = 0;
      82      629880 :     while( (nInputPos < nInputEndPos) || (nInputEndPos == nInputBufLen) )
      83             :     {
      84      325272 :         if( (nInputPos >= nInputEndPos) && fInputFile )
      85             :         {
      86       22575 :             nInputEndPos = fread( pInput, 1, nInputBufLen, fInputFile );
      87       22575 :             nInputPos = 0;
      88             :         }
      89             : 
      90     6028321 :         while( nInputPos < nInputEndPos )
      91             :         {
      92             :             //immer eine Zeile lesen
      93     5682379 :             if( nLen >= nLineBufLen )
      94             :             {
      95         210 :                 nLineBufLen += 256;
      96             :                 // einen dazu fuer '\0'
      97         210 :                 pLine = (char*)rtl_reallocateMemory( pLine, nLineBufLen +1 );
      98             :             }
      99             : 
     100             :             // cr lf, lf cr, lf oder cr wird '\0'
     101     5682379 :             if( pInput[ nInputPos ] == '\n' )
     102             :             {
     103      304602 :                 nInputPos++;
     104      304602 :                 if( cLastChar != '\r' )
     105             :                 {
     106      304602 :                     cLastChar = '\n';
     107      304602 :                     pLine[ nLen++ ] = '\0';
     108      304602 :                     goto END;
     109             :                 }
     110             :             }
     111     5377777 :             else if( pInput[ nInputPos ] == '\r' )
     112             :             {
     113           0 :                 nInputPos++;
     114           0 :                 if( cLastChar != '\n' )
     115             :                 {
     116           0 :                     cLastChar = '\r';
     117           0 :                     pLine[ nLen++ ] = '\0';
     118           0 :                     goto END;
     119             :                 }
     120             :             }
     121             :             else
     122             :             {
     123     5377777 :                 pLine[ nLen++ ] = pInput[ nInputPos++ ];
     124     5377777 :                 if( nLen > 2 )
     125             :                 {
     126     4821060 :                     if( (unsigned char)pLine[nLen-3] == 0xef &&
     127        1254 :                         (unsigned char)pLine[nLen-2] == 0xbb &&
     128         627 :                         (unsigned char)pLine[nLen-1] == 0xbf )
     129             :                     {
     130         627 :                         nLen -= 3;
     131             :                     }
     132             :                 }
     133             :             }
     134             :         };
     135             :     };
     136             : 
     137             :     // Abbruch ueber EOF
     138           3 :     pLine[ nLen ] = '\0';
     139             : 
     140             : END:
     141      304605 :     if( pTypCont->pEH->GetListFile() )
     142             :     {
     143             :         char buf[ 10 ];
     144             : 
     145           0 :         sprintf( buf, "%5d ", (int)GetLineNo() );
     146           0 :         pTypCont->pEH->LstOut( buf );
     147           0 :         pTypCont->pEH->LstOut( GetLine() );
     148           0 :         pTypCont->pEH->LstOut( "\n" );
     149             :     }
     150      304605 : }
     151             : 
     152         627 : void RscFileInst::SetError( ERRTYPE aError )
     153             : {
     154         627 :     if( aError.IsOk() )
     155             :     {
     156         627 :         aFirstError = aError;
     157         627 :         nErrorLine  = GetLineNo();
     158         627 :         nErrorPos   = GetScanPos() -1;
     159             :     };
     160         627 : };
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10