LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/idxf - dxfgrprd.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 175 0.0 %
Date: 2014-04-11 Functions: 0 12 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             : 
      21             : #include <string.h>
      22             : #include <stdlib.h>
      23             : #include <rtl/strbuf.hxx>
      24             : #include <tools/stream.hxx>
      25             : #include "dxfgrprd.hxx"
      26             : 
      27             : 
      28             : 
      29             : // we use an own ReadLine function, because Stream::ReadLine stops if
      30             : // a 0-sign occurs; this functions converts 0-signs to blanks and reads
      31             : // a complete line until a cr/lf is found
      32             : 
      33           0 : OString DXFReadLine(SvStream& rIStm)
      34             : {
      35             :     char  buf[256 + 1];
      36           0 :     sal_Bool  bEnd = sal_False;
      37           0 :     sal_uLong nOldFilePos = rIStm.Tell();
      38           0 :     char  c = 0;
      39             : 
      40           0 :     OStringBuffer aBuf;
      41             : 
      42           0 :     while( !bEnd && !rIStm.GetError() )   // !!! do not check for EOF
      43             :                                           // !!! because we read blockwise
      44             :     {
      45           0 :         sal_uInt16 nLen = (sal_uInt16)rIStm.Read( buf, sizeof(buf)-1 );
      46           0 :         if( !nLen )
      47             :         {
      48           0 :             if( aBuf.isEmpty() )
      49           0 :                 return OString();
      50             :             else
      51           0 :                 break;
      52             :         }
      53             : 
      54           0 :         for( sal_uInt16 n = 0; n < nLen ; n++ )
      55             :         {
      56           0 :             c = buf[n];
      57           0 :             if( c != '\n' && c != '\r' )
      58             :             {
      59           0 :                 if( !c )
      60           0 :                     c = ' ';
      61           0 :                 aBuf.append(c);
      62             :             }
      63             :             else
      64             :             {
      65           0 :                 bEnd = sal_True;
      66           0 :                 break;
      67             :             }
      68             :         }
      69             :     }
      70             : 
      71           0 :     if( !bEnd && !rIStm.GetError() && !aBuf.isEmpty() )
      72           0 :         bEnd = sal_True;
      73             : 
      74           0 :     nOldFilePos += aBuf.getLength();
      75           0 :     if( rIStm.Tell() > nOldFilePos )
      76           0 :         nOldFilePos++;
      77           0 :     rIStm.Seek( nOldFilePos );  // seek because of BlockRead above!
      78             : 
      79           0 :     if( bEnd && (c=='\r' || c=='\n'))  // special treatment of DOS files
      80             :     {
      81           0 :         char cTemp(0);
      82           0 :         rIStm.Read(&cTemp, 1);
      83           0 :         if( cTemp == c || (cTemp != '\n' && cTemp != '\r') )
      84           0 :             rIStm.Seek( nOldFilePos );
      85             :     }
      86             : 
      87           0 :     return aBuf.makeStringAndClear();
      88             : }
      89             : 
      90             : 
      91             : 
      92           0 : DXFGroupReader::DXFGroupReader(SvStream & rIStream, sal_uInt16 nminpercent, sal_uInt16 nmaxpercent ) :
      93           0 :     rIS(rIStream)
      94             : {
      95             :     sal_uInt16 i;
      96             : 
      97           0 :     nIBuffPos=0;
      98           0 :     nIBuffSize=0;
      99           0 :     bStatus=sal_True;
     100           0 :     nLastG=0;
     101           0 :     nGCount=0;
     102             : 
     103           0 :     nMinPercent=(sal_uLong)nminpercent;
     104           0 :     nMaxPercent=(sal_uLong)nmaxpercent;
     105           0 :     nLastPercent=nMinPercent;
     106             : 
     107           0 :     rIS.Seek(STREAM_SEEK_TO_END);
     108           0 :     nFileSize=rIS.Tell();
     109           0 :     rIS.Seek(0);
     110             : 
     111           0 :     for (i=0; i<10; i++) S0_9[i][0]=0;
     112           0 :     S100[ 0 ] = S102[ 0 ] = 0;
     113           0 :     for (i=0; i<50; i++) F10_59[i]=0.0;
     114           0 :     for (i=0; i<20; i++) I60_79[i]=0;
     115           0 :     for (i=0; i<10; i++) I90_99[i]=0;
     116           0 :     for (i=0; i< 8; i++) F140_147[i]=0.0;
     117           0 :     for (i=0; i< 6; i++) I170_175[i]=0;
     118           0 :     for (i=0; i<30; i++) F210_239[i]=0.0;
     119           0 :     for (i=0; i<11; i++) S999_1009[i][0]=0;
     120           0 :     for (i=0; i<50; i++) F1010_1059[i]=0.0;
     121           0 :     for (i=0; i<20; i++) I1060_1079[i]=0;
     122             : 
     123           0 : }
     124             : 
     125             : 
     126           0 : sal_uInt16 DXFGroupReader::Read()
     127             : {
     128           0 :     sal_uInt16 nG = 0;
     129           0 :     if ( bStatus )
     130             :     {
     131           0 :         nGCount++;
     132           0 :         nG = (sal_uInt16)ReadI();
     133           0 :         if ( bStatus )
     134             :         {
     135             :             char aTmp[ DXF_MAX_STRING_LEN + 1 ];
     136             : 
     137           0 :             if      (nG<  10) ReadS(S0_9[nG]);
     138           0 :             else if (nG<  60) F10_59[nG-10]=ReadF();
     139           0 :             else if (nG<  80) I60_79[nG-60]=ReadI();
     140           0 :             else if (nG<  90) ReadS( aTmp );
     141           0 :             else if (nG<  99) I90_99[nG-90]=ReadI();
     142           0 :             else if (nG==100) ReadS(S100);
     143           0 :             else if (nG==102) ReadS(S102);
     144           0 :             else if (nG==105) ReadS( aTmp );
     145           0 :             else if (nG< 140) ReadS( aTmp );
     146           0 :             else if (nG< 148) F140_147[nG-140]=ReadF();
     147           0 :             else if (nG< 170) ReadS( aTmp );
     148           0 :             else if (nG< 176) I170_175[nG-175]=ReadI();
     149           0 :             else if (nG< 180) ReadI();
     150           0 :             else if (nG< 210) ReadS( aTmp );
     151           0 :             else if (nG< 240) F210_239[nG-210]=ReadF();
     152           0 :             else if (nG<=369) ReadS( aTmp );
     153           0 :             else if (nG< 999) ReadS( aTmp );
     154           0 :             else if (nG<1010) ReadS(S999_1009[nG-999]);
     155           0 :             else if (nG<1060) F1010_1059[nG-1010]=ReadF();
     156           0 :             else if (nG<1080) I1060_1079[nG-1060]=ReadI();
     157           0 :             else bStatus = sal_False;
     158             :         }
     159             :     }
     160           0 :     if ( bStatus )
     161           0 :         nLastG = nG;
     162             :     else
     163             :     {
     164           0 :         nG = 0;
     165           0 :         SetS();
     166           0 :         if ( nGCount != 0xffffffff )
     167             :         {
     168             :             // InfoBox(NULL,String("Fehler ab Gruppe Nr ")+String(nGCount)).Execute();
     169           0 :             nGCount=0xffffffff;
     170             :         }
     171             :     }
     172           0 :     nLastG = nG;
     173           0 :     return nG;
     174             : }
     175             : 
     176             : 
     177           0 : long DXFGroupReader::GetI(sal_uInt16 nG) const
     178             : {
     179           0 :     sal_Int32 nRetValue = 0;
     180           0 :     if ( ( nG >= 60 ) && ( nG <= 79 ) )
     181           0 :         nRetValue = I60_79[ nG - 60 ];
     182           0 :     else if ( ( nG >= 90 ) && ( nG <= 99 ) )
     183           0 :         nRetValue = I90_99[ nG - 90 ];
     184           0 :     else if ( ( nG >= 170 ) && ( nG <= 175 ) )
     185           0 :         nRetValue = I170_175[ nG - 170 ];
     186           0 :     else if ( ( nG >= 1060 ) && ( nG <= 1079 ) )
     187           0 :         nRetValue = I1060_1079[ nG - 1060 ];
     188           0 :     return nRetValue;
     189             : }
     190             : 
     191           0 : double DXFGroupReader::GetF(sal_uInt16 nG) const
     192             : {
     193           0 :     nG-=10;
     194           0 :     if (nG<50) return F10_59[nG];
     195             :     else {
     196           0 :         nG-=130;
     197           0 :         if (nG<8) return F140_147[nG];
     198             :         else {
     199           0 :             nG-=70;
     200           0 :             if (nG<30) return F210_239[nG];
     201             :             else {
     202           0 :                 nG-=800;
     203           0 :                 if (nG<50) return F1010_1059[nG];
     204           0 :                 else return 0;
     205             :             }
     206             :         }
     207             :     }
     208             : }
     209             : 
     210           0 : const char * DXFGroupReader::GetS(sal_uInt16 nG) const
     211             : {
     212           0 :     if (nG<10) return S0_9[nG];
     213           0 :     else if ( nG == 100 )
     214           0 :         return S100;
     215           0 :     else if ( nG == 102 )
     216           0 :         return S102;
     217             :     else
     218             :     {
     219           0 :         nG-=999;
     220           0 :         if (nG<11) return S999_1009[nG];
     221           0 :         else return NULL;
     222             :     }
     223             : }
     224             : 
     225           0 : void DXFGroupReader::SetF(sal_uInt16 nG, double fF)
     226             : {
     227           0 :     nG-=10;
     228           0 :     if (nG<50) F10_59[nG]=fF;
     229             :     else {
     230           0 :         nG-=130;
     231           0 :         if (nG<8) F140_147[nG]=fF;
     232             :         else {
     233           0 :             nG-=70;
     234           0 :             if (nG<30) F210_239[nG]=fF;
     235             :             else {
     236           0 :                 nG-=800;
     237           0 :                 if (nG<50) F1010_1059[nG]=fF;
     238             :             }
     239             :         }
     240             :     }
     241           0 : }
     242             : 
     243             : 
     244           0 : void DXFGroupReader::SetS()
     245             : {
     246           0 :     strncpy(S0_9[0], "EOF", DXF_MAX_STRING_LEN);
     247           0 :     S0_9[0][DXF_MAX_STRING_LEN] = 0;
     248           0 : }
     249             : 
     250             : 
     251           0 : void DXFGroupReader::ReadLine(char * ptgt)
     252             : {
     253           0 :     OString aStr = DXFReadLine(rIS);
     254             : 
     255           0 :     size_t nLen = aStr.getLength();
     256           0 :     if ( nLen > DXF_MAX_STRING_LEN )
     257           0 :         nLen = DXF_MAX_STRING_LEN;
     258             : 
     259           0 :     memcpy( ptgt, aStr.getStr(), nLen );
     260           0 :     ptgt[ nLen ] = 0x00;
     261           0 : }
     262             : 
     263             : 
     264           0 : long DXFGroupReader::ReadI()
     265             : {
     266             :     char sl[DXF_MAX_STRING_LEN+1],*p;
     267             :     long res,nv;
     268             : 
     269           0 :     ReadLine(sl);
     270             : 
     271           0 :     p=sl;
     272             : 
     273           0 :     while(*p==0x20) p++;
     274             : 
     275           0 :     if ((*p<'0' || *p>'9') && *p!='-') {
     276           0 :         bStatus=sal_False;
     277           0 :         return 0;
     278             :     }
     279             : 
     280           0 :     if (*p=='-') {
     281           0 :         nv=-1;
     282           0 :         p++;
     283             :     }
     284           0 :     else nv=1;
     285             : 
     286           0 :     res=0;
     287           0 :     do {
     288           0 :         res=res*10+(long)(*p-'0');
     289           0 :         p++;
     290           0 :     } while (*p>='0' && *p<='9');
     291             : 
     292           0 :     while (*p==0x20) p++;
     293           0 :     if (*p!=0) {
     294           0 :         bStatus=sal_False;
     295           0 :         return 0;
     296             :     }
     297             : 
     298           0 :     return res*nv;
     299             : }
     300             : 
     301             : 
     302           0 : double DXFGroupReader::ReadF()
     303             : {
     304             :     char sl[DXF_MAX_STRING_LEN+1],*p;
     305             : 
     306           0 :     ReadLine(sl);
     307           0 :     p=sl;
     308           0 :     while(*p==0x20) p++;
     309           0 :     if ((*p<'0' || *p>'9') && *p!='.' && *p!='-') {
     310           0 :         bStatus=sal_False;
     311           0 :         return 0.0;
     312             :     }
     313           0 :     return atof(p);
     314             : }
     315             : 
     316             : 
     317           0 : void DXFGroupReader::ReadS(char * ptgt)
     318             : {
     319           0 :     ReadLine(ptgt);
     320           0 : }
     321             : 
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10