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

Generated by: LCOV version 1.10