LCOV - code coverage report
Current view: top level - xml2cmp/source/support - syshelp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 104 3.8 %
Date: 2012-08-25 Functions: 3 7 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 142 1.4 %

           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                 :            : 
      21                 :            : #include <syshelp.hxx>
      22                 :            : 
      23                 :            : 
      24                 :            : // NOT FULLY DEFINED SERVICES
      25                 :            : #include <string.h>
      26                 :            : #include "sistr.hxx"
      27                 :            : #include "list.hxx"
      28                 :            : 
      29                 :            : #ifdef WNT
      30                 :            : #include <io.h>
      31                 :            : #elif defined(UNX)
      32                 :            : #include <sys/types.h>
      33                 :            : #include <sys/stat.h>
      34                 :            : #include <dirent.h>
      35                 :            : #define stricmp strcasecmp
      36                 :            : #else
      37                 :            : #error Must run under unix or windows, please define UNX or WNT.
      38                 :            : #endif
      39                 :            : 
      40                 :            : 
      41                 :            : char C_sSpaceInName[] = "&nbsp;&nbsp;&nbsp;";
      42                 :            : 
      43                 :            : void
      44                 :          0 : WriteName( std::ostream &       o_rFile,
      45                 :            :            const Simstr &   i_rIdlDocuBaseDir,
      46                 :            :            const Simstr &   i_rName,
      47                 :            :            E_LinkType       i_eLinkType )
      48                 :            : {
      49         [ #  # ]:          0 :     if (i_rName.l() == 0)
      50                 :          0 :         return;
      51                 :            : 
      52                 :            : 
      53                 :          0 :     const char * pNameEnd = strstr( i_rName.str(), " in " );
      54                 :            : 
      55                 :            :     // No link:
      56         [ #  # ]:          0 :     if ( i_eLinkType == lt_nolink )
      57                 :            :     {
      58         [ #  # ]:          0 :         if ( pNameEnd != 0 )
      59                 :            :         {
      60                 :          0 :             const char * pStart = i_rName.str();
      61                 :          0 :             o_rFile.write( pStart, pNameEnd - pStart );
      62                 :          0 :             WriteStr( o_rFile, C_sSpaceInName );
      63                 :          0 :             WriteStr( o_rFile, pNameEnd );
      64                 :            :         }
      65                 :            :         else
      66                 :            :         {
      67                 :          0 :             WriteStr( o_rFile, i_rName );
      68                 :            :         }
      69                 :          0 :         return;
      70                 :            :     }
      71                 :            : 
      72         [ #  # ]:          0 :     if ( i_eLinkType == lt_idl )
      73                 :            :     {
      74         [ #  # ]:          0 :         Simstr sPath(i_rName);
      75         [ #  # ]:          0 :         sPath.replace_all('.','/');
      76         [ #  # ]:          0 :         int nNameEnd = sPath.pos_first(' ');
      77         [ #  # ]:          0 :         int nPathStart = sPath.pos_last(' ');
      78         [ #  # ]:          0 :         WriteStr( o_rFile, "<A HREF=\"" );
      79                 :            : 
      80         [ #  # ]:          0 :         if ( nNameEnd > -1 )
      81                 :            :         {
      82         [ #  # ]:          0 :             WriteStr( o_rFile, "file:///" );
      83         [ #  # ]:          0 :             WriteStr( o_rFile, i_rIdlDocuBaseDir );
      84         [ #  # ]:          0 :             WriteStr( o_rFile, "/" );
      85         [ #  # ]:          0 :             WriteStr( o_rFile, sPath.str() + 1 + nPathStart );
      86         [ #  # ]:          0 :             WriteStr( o_rFile, "/" );
      87         [ #  # ]:          0 :             o_rFile.write( sPath.str(), nNameEnd );
      88         [ #  # ]:          0 :             WriteStr( o_rFile, ".html\">" );
      89                 :            :         }
      90                 :            :         else
      91                 :            :         {   // Should not be reached:
      92         [ #  # ]:          0 :             WriteStr(o_rFile, i_rName);
      93                 :            :             return;
      94 [ #  # ][ #  # ]:          0 :         }
      95                 :            :     }
      96         [ #  # ]:          0 :     else if ( i_eLinkType == lt_html )
      97                 :            :     {
      98                 :          0 :         int nKomma = i_rName.pos_first(',');
      99                 :          0 :         int nEnd = i_rName.pos_first(' ');
     100         [ #  # ]:          0 :         if ( nKomma > -1 )
     101                 :            :         {
     102                 :          0 :             o_rFile.write( i_rName.str(), nKomma );
     103                 :          0 :             WriteStr( o_rFile, ": " );
     104                 :            : 
     105                 :          0 :             WriteStr( o_rFile, "<A HREF=\"" );
     106                 :            : 
     107                 :          0 :             o_rFile.write( i_rName.str(), nKomma );
     108                 :          0 :             WriteStr( o_rFile, ".html#" );
     109         [ #  # ]:          0 :             if ( nEnd > -1 )
     110                 :          0 :                 o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
     111                 :            :             else
     112                 :          0 :                 WriteStr( o_rFile, i_rName.str() + nKomma + 1 );
     113                 :          0 :             WriteStr( o_rFile, "\">" );
     114                 :            : 
     115                 :          0 :             o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma );
     116                 :            :         }
     117                 :            :         else
     118                 :            :         {
     119                 :          0 :             WriteStr( o_rFile, "<A HREF=\"" );
     120                 :          0 :             WriteStr( o_rFile, i_rName );
     121                 :          0 :             WriteStr( o_rFile, ".html\">" );
     122                 :            : 
     123                 :          0 :             WriteStr( o_rFile, i_rName );
     124                 :            :         }
     125                 :          0 :         WriteStr( o_rFile, "</A>" );
     126                 :          0 :         return;
     127                 :            :     }
     128                 :            : 
     129         [ #  # ]:          0 :     if ( pNameEnd != 0 )
     130                 :            :     {
     131                 :          0 :         const char * pStart = i_rName.str();
     132         [ #  # ]:          0 :         if ( pNameEnd > pStart )
     133                 :          0 :             o_rFile.write( pStart, pNameEnd - pStart );
     134                 :          0 :         WriteStr( o_rFile, "</A>" );
     135                 :            : 
     136                 :          0 :         WriteStr( o_rFile, C_sSpaceInName );
     137                 :          0 :         WriteStr( o_rFile, pNameEnd );
     138                 :            :     }
     139                 :            :     else
     140                 :            :     {
     141                 :          0 :         WriteStr( o_rFile, i_rName );
     142                 :          0 :         WriteStr( o_rFile, "</A>" );
     143                 :            :     }
     144                 :            : }
     145                 :            : 
     146                 :            : 
     147                 :            : void
     148                 :        396 : WriteStr( std::ostream &    o_rFile,
     149                 :            :           const char *      i_sStr )
     150                 :            : {
     151                 :        396 :     o_rFile.write( i_sStr, (int) strlen(i_sStr) );
     152                 :        396 : }
     153                 :            : 
     154                 :            : void
     155                 :          0 : WriteStr( std::ostream &      o_rFile,
     156                 :            :           const Simstr &      i_sStr )
     157                 :            : {
     158                 :          0 :     o_rFile.write( i_sStr.str(), i_sStr.l() );
     159                 :          0 : }
     160                 :            : 
     161                 :            : 
     162                 :            : const char C_sXML_END[] = "\\*.xml";
     163                 :            : 
     164                 :            : void
     165                 :          0 : GatherFileNames( List<Simstr> &     o_sFiles,
     166                 :            :                  const char *       i_sSrcDirectory )
     167                 :            : {
     168                 :            :     static int   nAliveCounter = 0;
     169                 :            : 
     170                 :          0 :     char *       sNextDir = 0;
     171         [ #  # ]:          0 :     Simstr       sNew = 0;
     172                 :            : 
     173                 :            : #ifdef WNT
     174                 :            :     struct _finddata_t aEntry;
     175                 :            :     long hFile = 0;
     176                 :            :     int bFindMore = 0;
     177                 :            :     char * sFilter = new char[ strlen(i_sSrcDirectory) + sizeof C_sXML_END ];
     178                 :            : 
     179                 :            :     // Stayingalive sign
     180                 :            :     if (++nAliveCounter % 100 == 1)
     181                 :            :         std::cout << "." << std::flush;
     182                 :            : 
     183                 :            :     strcpy(sFilter, i_sSrcDirectory);       // STRCPY SAFE HERE
     184                 :            :     strcat(sFilter,C_sXML_END);             // STRCAT SAFE HERE
     185                 :            : 
     186                 :            :     hFile = _findfirst( sFilter, &aEntry );
     187                 :            :     for ( bFindMore = hFile == -1;
     188                 :            :           bFindMore == 0;
     189                 :            :           bFindMore = _findnext( hFile, &aEntry ) )
     190                 :            :     {
     191                 :            :         sNew = i_sSrcDirectory;
     192                 :            :         sNew += "\\";
     193                 :            :         sNew += aEntry.name;
     194                 :            :         o_sFiles.push_back(sNew);
     195                 :            :     }   // end for
     196                 :            : 
     197                 :            :     _findclose(hFile);
     198                 :            :     delete [] sFilter;
     199                 :            : #elif defined(UNX)
     200         [ #  # ]:          0 :     DIR * pDir = opendir( i_sSrcDirectory );
     201                 :          0 :     dirent * pEntry = 0;
     202                 :            :     char * sEnding;
     203                 :            : 
     204                 :            :     // Stayingalive sign
     205         [ #  # ]:          0 :     if (++nAliveCounter % 100 == 1)
     206 [ #  # ][ #  # ]:          0 :         std::cout << "." << std::flush;
     207                 :            : 
     208 [ #  # ][ #  # ]:          0 :     while ( (pEntry = readdir(pDir)) != 0 )
     209                 :            :     {
     210                 :          0 :         sEnding = strrchr(pEntry->d_name,'.');
     211 [ #  # ][ #  # ]:          0 :         if (sEnding != 0 ? stricmp(sEnding,".xml") == 0 : 0 )
     212                 :            :         {
     213 [ #  # ][ #  # ]:          0 :             sNew = i_sSrcDirectory;
                 [ #  # ]
     214 [ #  # ][ #  # ]:          0 :             sNew += "/";
                 [ #  # ]
     215 [ #  # ][ #  # ]:          0 :             sNew += pEntry->d_name;
                 [ #  # ]
     216         [ #  # ]:          0 :             o_sFiles.push_back(sNew);
     217                 :            :         }
     218                 :            :     }   // end while
     219                 :            : 
     220         [ #  # ]:          0 :     closedir( pDir );
     221                 :            : #else
     222                 :            : #error Must run on unix or windows, please define UNX or WNT.
     223                 :            : #endif
     224                 :            : 
     225                 :            :     //  gathering from subdirectories:
     226         [ #  # ]:          0 :     List<Simstr> aSubDirectories;
     227         [ #  # ]:          0 :     GatherSubDirectories( aSubDirectories, i_sSrcDirectory );
     228                 :            : 
     229                 :          0 :     unsigned d_max = aSubDirectories.size();
     230         [ #  # ]:          0 :     for ( unsigned d = 0; d < d_max; ++d )
     231                 :            :     {
     232 [ #  # ][ #  # ]:          0 :         sNextDir = new char[ strlen(i_sSrcDirectory) + 2 + aSubDirectories[d].l() ];
     233                 :            : 
     234                 :          0 :         strcpy(sNextDir, i_sSrcDirectory);
     235                 :          0 :         strcat(sNextDir, C_sSLASH);
     236         [ #  # ]:          0 :         strcat(sNextDir, aSubDirectories[d].str());
     237         [ #  # ]:          0 :         GatherFileNames(o_sFiles, sNextDir);
     238                 :            : 
     239         [ #  # ]:          0 :         delete [] sNextDir;
     240 [ #  # ][ #  # ]:          0 :     }
     241                 :          0 : }
     242                 :            : 
     243                 :            : 
     244                 :            : const char * C_sANYDIR = "\\*.*";
     245                 :            : 
     246                 :            : void
     247                 :          0 : GatherSubDirectories( List<Simstr> &    o_sSubDirectories,
     248                 :            :                       const char *      i_sParentdDirectory )
     249                 :            : {
     250         [ #  # ]:          0 :     Simstr sNew;
     251                 :            : 
     252                 :            : #ifdef WNT
     253                 :            :     struct _finddata_t aEntry;
     254                 :            :     long hFile = 0;
     255                 :            :     int bFindMore = 0;
     256                 :            :     char * sFilter = new char[strlen(i_sParentdDirectory) + sizeof C_sANYDIR];
     257                 :            : 
     258                 :            :     strcpy(sFilter, i_sParentdDirectory);
     259                 :            :     strcat(sFilter,C_sANYDIR);
     260                 :            : 
     261                 :            :     hFile = _findfirst( sFilter, &aEntry );
     262                 :            :     for ( bFindMore = hFile == -1;
     263                 :            :           bFindMore == 0;
     264                 :            :           bFindMore = _findnext( hFile, &aEntry ) )
     265                 :            :     {
     266                 :            :         if (aEntry.attrib == _A_SUBDIR)
     267                 :            :         {
     268                 :            :             // Do not gather . .. and outputtree directories
     269                 :            :             if ( strchr(aEntry.name,'.') == 0
     270                 :            :                  && strncmp(aEntry.name, "wnt", 3) != 0
     271                 :            :                  && strncmp(aEntry.name, "unx", 3) != 0 )
     272                 :            :             {
     273                 :            :                 sNew = aEntry.name;
     274                 :            :                 o_sSubDirectories.push_back(sNew);
     275                 :            :             }
     276                 :            :         }   // endif (aEntry.attrib == _A_SUBDIR)
     277                 :            :     }   // end for
     278                 :            :     _findclose(hFile);
     279                 :            :     delete [] sFilter;
     280                 :            : 
     281                 :            : #elif defined(UNX)
     282         [ #  # ]:          0 :     DIR * pDir = opendir( i_sParentdDirectory );
     283                 :          0 :     dirent * pEntry = 0;
     284                 :            :     struct stat     aEntryStatus;
     285                 :            : 
     286 [ #  # ][ #  # ]:          0 :     while ( ( pEntry = readdir(pDir) ) != 0 )
     287                 :            :     {
     288                 :          0 :         stat(pEntry->d_name, &aEntryStatus);
     289         [ #  # ]:          0 :         if ( ( aEntryStatus.st_mode & S_IFDIR ) == S_IFDIR )
     290                 :            :         {
     291                 :            :             // Do not gather . .. and outputtree directories
     292 [ #  # ][ #  # ]:          0 :             if ( strchr(pEntry->d_name,'.') == 0
                 [ #  # ]
     293                 :          0 :                  && strncmp(pEntry->d_name, "wnt", 3) != 0
     294                 :          0 :                  && strncmp(pEntry->d_name, "unx", 3) != 0 )
     295                 :            :             {
     296 [ #  # ][ #  # ]:          0 :                 sNew = pEntry->d_name;
                 [ #  # ]
     297         [ #  # ]:          0 :                 o_sSubDirectories.push_back(sNew);
     298                 :            :             }
     299                 :            :         }   // endif (aEntry.attrib == _A_SUBDIR)
     300                 :            :     }   // end while
     301 [ #  # ][ #  # ]:          0 :     closedir( pDir );
     302                 :            : #else
     303                 :            : #error Must run on unix or windows, please define UNX or WNT.
     304                 :            : #endif
     305 [ +  - ][ +  - ]:          6 : }
     306                 :            : 
     307                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10