LCOV - code coverage report
Current view: top level - rsc/source/parser - rscpar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 66 76 86.8 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 50 64.0 %

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

Generated by: LCOV version 1.10