LCOV - code coverage report
Current view: top level - xml2cmp/source/xcd - main.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 105 50.5 %
Date: 2012-08-25 Functions: 7 9 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 56 238 23.5 %

           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                 :            : #include <iostream>
      21                 :            : #include <fstream>
      22                 :            : #include <stdio.h>
      23                 :            : 
      24                 :            : 
      25                 :            : #include <string.h>
      26                 :            : #include "../support/cmdline.hxx"
      27                 :            : #include "cr_metho.hxx"
      28                 :            : #include "cr_html.hxx"
      29                 :            : #include "xmlelem.hxx"
      30                 :            : #include "xmltree.hxx"
      31                 :            : #include "parse.hxx"
      32                 :            : #include "../support/syshelp.hxx"
      33                 :            : #include "../support/heap.hxx"
      34                 :            : #include "dependy.hxx"
      35                 :            : 
      36                 :            : 
      37                 :            : 
      38                 :          2 : void StreamOut_TypeInfo( std::ostream& o_rOut, ModuleDescription& i_rData,
      39                 :            :                          const char* i_sSeparator )
      40                 :            : {
      41         [ +  - ]:          2 :     Heap    aTypesHeap(12);
      42                 :            : 
      43                 :            :     // Gather types:
      44         [ +  - ]:          2 :     List< const MultipleTextElement * > aTypes;
      45         [ +  - ]:          2 :     i_rData.Get_Types(aTypes);
      46                 :            : 
      47         [ +  + ]:         22 :     for ( unsigned t = 0; t < aTypes.size(); ++t )
      48                 :            :     {
      49 [ +  - ][ +  - ]:         20 :         unsigned i_max = aTypes[t]->Size();
      50         [ +  + ]:        426 :         for ( unsigned  i = 0; i < i_max; ++i )
      51                 :            :         {
      52 [ +  - ][ +  - ]:        406 :             aTypesHeap.InsertValue( aTypes[t]->Data(i), "" );
                 [ +  - ]
      53                 :            :         }  // end for
      54                 :            :     }
      55                 :            : 
      56                 :            :     // Write types:
      57                 :          2 :     HeapItem * pLastHeapTop = 0;
      58 [ +  - ][ +  - ]:        408 :     for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() )
                 [ +  + ]
      59                 :            :     {
      60         [ +  + ]:        406 :         if (pLastHeapTop != 0)
      61                 :            :         {
      62 [ +  - ][ +  - ]:        404 :             if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) )
                 [ +  + ]
      63                 :        274 :                 continue;
      64 [ +  - ][ +  - ]:        130 :             delete pLastHeapTop;
      65                 :            :         }
      66                 :        132 :         pLastHeapTop = pHeapTop;
      67                 :            : 
      68         [ +  - ]:        132 :         WriteStr( o_rOut, i_sSeparator );
      69                 :            : 
      70         [ +  - ]:        132 :         const char * sEnd = strchr( pHeapTop->Key(), ' ' );
      71         [ +  - ]:        132 :         if (sEnd != 0)
      72                 :            :         {
      73         [ +  - ]:        132 :             const char * sQuali = strrchr( pHeapTop->Key(), ' ' ) + 1;
      74         [ +  - ]:        132 :             WriteStr( o_rOut, sQuali );
      75         [ +  - ]:        132 :             WriteStr( o_rOut, "." );
      76 [ +  - ][ +  - ]:        132 :             o_rOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() );
                 [ +  - ]
      77                 :            :         }
      78                 :            :         else
      79                 :            :         {
      80 [ #  # ][ #  # ]:          0 :             WriteStr( o_rOut, pHeapTop->Key() );
      81                 :            :         }
      82                 :            :     }   // end for
      83                 :            : 
      84         [ +  - ]:          2 :     if (pLastHeapTop != 0)
      85                 :            :     {
      86 [ +  - ][ +  - ]:          2 :         delete pLastHeapTop;
      87                 :          2 :         pLastHeapTop = 0;
      88         [ +  - ]:          2 :     }
      89                 :          2 : }
      90                 :            : 
      91                 :          2 : void Put2StdOut_TypeInfo( ModuleDescription& i_rData )
      92                 :            : {
      93                 :          2 :     StreamOut_TypeInfo(std::cout, i_rData, " ");
      94                 :          2 : }
      95                 :            : 
      96                 :          0 : void Put2File_TypeInfo( const char* i_sOutputFile, ModuleDescription& i_rData )
      97                 :            : {
      98                 :            :     std::ofstream aOut(i_sOutputFile, std::ios::out
      99                 :            : #if defined(WNT)
     100                 :            :                                                | std::ios::binary
     101                 :            : #endif
     102         [ #  # ]:          0 :     );
     103 [ #  # ][ #  # ]:          0 :     if ( !aOut )
     104                 :            :     {
     105 [ #  # ][ #  # ]:          0 :         std::cerr << "Error: " << i_sOutputFile << " could not be created." << std::endl;
         [ #  # ][ #  # ]
     106                 :          0 :         return;
     107                 :            :     }
     108                 :            : 
     109 [ #  # ][ #  # ]:          0 :     Simstr  sLibPrefix = i_rData.ModuleName();
     110         [ #  # ]:          0 :     WriteStr( aOut, sLibPrefix );
     111         [ #  # ]:          0 :     WriteStr( aOut, "_XML2CMPTYPES= ");
     112                 :            : 
     113         [ #  # ]:          0 :     StreamOut_TypeInfo(aOut, i_rData, "\t\\\n\t\t");
     114                 :            : 
     115 [ #  # ][ #  # ]:          0 :     aOut.close();
         [ #  # ][ #  # ]
     116                 :            : }
     117                 :            : 
     118                 :          2 : void Create_TypeInfo( const char* o_sOutputFile, ModuleDescription& i_rData )
     119                 :            : {
     120         [ +  - ]:          2 :     if ( strcmp(o_sOutputFile, "stdout") == 0 )
     121                 :            :     {
     122                 :          2 :         Put2StdOut_TypeInfo(i_rData);
     123                 :            :     }
     124                 :            :     else
     125                 :            :     {
     126                 :          0 :         Put2File_TypeInfo(o_sOutputFile,i_rData);
     127                 :            :     }
     128                 :          2 : }
     129                 :            : 
     130                 :          0 : int Do_DepCommandLine(const CommandLine & i_rCommandLine)
     131                 :            : {
     132         [ #  # ]:          0 :     DependencyFinder aDependencies;
     133                 :            : 
     134         [ #  # ]:          0 :     aDependencies.GatherData(i_rCommandLine.DepPath());
     135                 :          0 :     char sInput[500] = "";
     136         [ #  # ]:          0 :     std::vector<Simstr>  aLibs;
     137         [ #  # ]:          0 :     std::vector<Simstr>  aServs;
     138                 :            : 
     139                 :            : 
     140                 :            :     std::cout
     141         [ #  # ]:          0 :          << "\nNow you can start to put in Service names.\n"
     142         [ #  # ]:          0 :          << "Please use correct case, but don't use namespaces.\n"
     143         [ #  # ]:          0 :          << "Just the Service's own name.\n\n"
     144         [ #  # ]:          0 :          << "To stop the program, put in a hashmark \"#\" + ENTER.\n"
     145         [ #  # ]:          0 :          << std::endl;
     146                 :            : 
     147         [ #  # ]:          0 :     do
     148                 :            :     {
     149                 :          0 :         sInput[0] = 0;
     150         [ #  # ]:          0 :         std::cin >> sInput;
     151         [ #  # ]:          0 :         Simstr sImplService(sInput);
     152         [ #  # ]:          0 :         if (*sInput != '#')
     153                 :            :         {
     154         [ #  # ]:          0 :             aLibs.erase( aLibs.begin(), aLibs.end() );
     155         [ #  # ]:          0 :             aServs.erase( aServs.begin(), aServs.end() );
     156                 :            : 
     157         [ #  # ]:          0 :             aDependencies.FindNeededServices( aLibs, aServs, sImplService );
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :             std::cout << "\n\n\nNeeded libraries: " << std::endl;
     160         [ #  # ]:          0 :             for ( unsigned i = 0; i < aLibs.size(); ++i )
     161                 :            :             {
     162 [ #  # ][ #  # ]:          0 :                 std::cout << "    " << aLibs[i].str() << std::endl;
                 [ #  # ]
     163                 :            :             }
     164 [ #  # ][ #  # ]:          0 :             std::cout << "\nNeeded services: " << std::endl;
     165         [ #  # ]:          0 :             for ( unsigned s= 0; s < aServs.size(); ++s )
     166                 :            :             {
     167 [ #  # ][ #  # ]:          0 :                 std::cout << "    " << aServs[s].str() << std::endl;
                 [ #  # ]
     168                 :            :             }
     169 [ #  # ][ #  # ]:          0 :             std::cout << "\n\n" << std::endl;
     170         [ #  # ]:          0 :         }
     171                 :            :     }
     172                 :            :     while (*sInput != '#');
     173                 :            : 
     174         [ #  # ]:          0 :     return 0;
     175                 :            : 
     176                 :            : }
     177                 :            : 
     178                 :          2 : int Do_SingleFileCommandLine(const CommandLine & i_rCommandLine)
     179                 :            : {
     180         [ +  - ]:          2 :     ModuleDescription   aDescr;
     181         [ +  - ]:          2 :     X2CParser           aParser(aDescr);
     182                 :            : 
     183                 :            :     // Load file and create Function-file
     184         [ +  - ]:          2 :     bool bLoadResult = aParser.LoadFile(i_rCommandLine.XmlSrcFile());
     185         [ -  + ]:          2 :     if (! bLoadResult)
     186                 :            :     {
     187 [ #  # ][ #  # ]:          0 :         std::cerr << "Error: File " << i_rCommandLine.XmlSrcFile() << " could not be loaded." << std::endl;
         [ #  # ][ #  # ]
     188                 :          0 :         return 1;
     189                 :            :     }
     190                 :            : 
     191         [ -  + ]:          2 :     if ( strlen(i_rCommandLine.FuncFile()) > 0 )
     192                 :            :     {
     193         [ #  # ]:          0 :         Create_AccessMethod( i_rCommandLine.FuncFile(), aParser.PureText() );
     194                 :            : 
     195         [ #  # ]:          0 :         std::cout << "File "
     196         [ #  # ]:          0 :              << i_rCommandLine.FuncFile()
     197         [ #  # ]:          0 :              << " with component_getDescriptionFunc() is created now."
     198         [ #  # ]:          0 :              << std::endl;
     199                 :            :     }
     200                 :            : 
     201                 :            :     // Parse
     202         [ +  - ]:          2 :     aParser.Parse();
     203                 :            : 
     204                 :            :     // Produce output
     205         [ -  + ]:          2 :     if ( strlen(i_rCommandLine.HtmlFile()) > 0 )
     206                 :            :     {
     207                 :            :         HtmlCreator aHtmlCreator( i_rCommandLine.HtmlFile(),
     208                 :            :                                   aDescr,
     209 [ #  # ][ #  # ]:          0 :                                   i_rCommandLine.IdlRootPath() );
                 [ #  # ]
     210 [ #  # ][ #  # ]:          0 :         aHtmlCreator.Run();
     211                 :            :     }
     212                 :            : 
     213         [ +  - ]:          2 :     if (strlen(i_rCommandLine.TypeInfoFile()) > 0)
     214                 :            :     {
     215         [ +  - ]:          2 :         Create_TypeInfo( i_rCommandLine.TypeInfoFile(), aDescr );
     216                 :            :     }
     217                 :            : 
     218 [ +  - ][ +  - ]:          2 :     return 0;
     219                 :            : };
     220                 :            : 
     221                 :            : int
     222                 :            : #ifdef WNT
     223                 :            : _cdecl
     224                 :            : #endif
     225                 :          2 : main( int argc, char* argv[] )
     226                 :            : {
     227                 :            :     // Variables
     228         [ +  - ]:          2 :     CommandLine             aCommandLine(argc, argv);
     229                 :          2 :     int ret = 0;
     230                 :            : 
     231         [ -  + ]:          2 :     if (! aCommandLine.IsOk())
     232                 :            :     {
     233 [ #  # ][ #  # ]:          0 :         std::cerr <<  aCommandLine.ErrorText() << std::endl ;
                 [ #  # ]
     234                 :          0 :         return 1;
     235                 :            :     }
     236                 :            : 
     237         [ -  + ]:          2 :     if ( aCommandLine.IsDepCommand() )
     238                 :            :     {
     239         [ #  # ]:          0 :         ret = Do_DepCommandLine(aCommandLine);
     240                 :            :     }
     241                 :            :     else
     242                 :            :     {
     243         [ +  - ]:          2 :         ret = Do_SingleFileCommandLine(aCommandLine);
     244                 :            :     }
     245         [ +  - ]:          2 :     return ret;
     246 [ +  - ][ +  - ]:          6 : }
     247                 :            : 
     248                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10