LCOV - code coverage report
Current view: top level - idlc/source - idlcmain.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 74 60.8 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 61 170 35.9 %

           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 "idlc/idlc.hxx"
      22                 :            : #include "sal/main.h"
      23                 :            : 
      24                 :            : #include <string.h>
      25                 :            : 
      26                 :            : using namespace ::rtl;
      27                 :            : 
      28                 :        166 : SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
      29                 :            : {
      30         [ +  - ]:        166 :     std::vector< std::string > args;
      31         [ +  + ]:        336 :     for (int i = 1; i < argc; i++)
      32                 :            :     {
      33 [ +  - ][ -  + ]:        170 :         if (!Options::checkArgument (args, argv[i], strlen(argv[i])))
      34                 :          0 :             return (1);
      35                 :            :     }
      36                 :            : 
      37         [ +  - ]:        166 :     Options options(argv[0]);
      38                 :            :     try
      39                 :            :     {
      40 [ +  - ][ -  + ]:        166 :         if (!options.initOptions(args))
      41                 :          0 :            return (0);
      42                 :            :     }
      43   [ #  #  #  # ]:          0 :     catch(const IllegalArgument& e)
      44                 :            :     {
      45                 :            :         fprintf(stderr, "Illegal argument: %s\n%s",
      46                 :            :             e.m_message.getStr(),
      47   [ #  #  #  # ]:          0 :             options.prepareVersion().getStr());
      48                 :          0 :         return (99);
      49                 :            :     }
      50                 :            : 
      51         [ +  - ]:        166 :     setIdlc(&options);
      52                 :            : 
      53                 :        166 :     sal_Int32 nErrors = 0;
      54         [ -  + ]:        166 :     if (options.readStdin()) {
      55         [ #  # ]:          0 :         if ( !options.quiet() )
      56                 :            :             fprintf(
      57                 :            :                 stdout, "%s: Compiling stdin\n",
      58 [ #  # ][ #  # ]:          0 :                 options.getProgramName().getStr());
      59         [ #  # ]:          0 :         nErrors = compileFile(0);
      60 [ #  # ][ #  # ]:          0 :         if ( ( idlc()->getWarningCount() > 0 ) && !options.quiet() ) {
         [ #  # ][ #  # ]
      61                 :            :             fprintf(
      62                 :            :                 stdout, "%s: detected %lu warnings compiling stdin\n",
      63         [ #  # ]:          0 :                 options.getProgramName().getStr(),
      64                 :            :                 sal::static_int_cast< unsigned long >(
      65 [ #  # ][ #  # ]:          0 :                     idlc()->getWarningCount()));
      66                 :            :         }
      67                 :          0 :         OString outputUrl;
      68 [ #  # ][ #  # ]:          0 :         if (options.isValid("-O")) {
      69 [ #  # ][ #  # ]:          0 :             outputUrl = convertToFileUrl(options.getOption("-O"));
      70         [ #  # ]:          0 :             if (outputUrl[outputUrl.getLength() - 1] != '/') {
      71                 :          0 :                 outputUrl += "/";
      72                 :            :             }
      73                 :          0 :             outputUrl += "stdin.urd";
      74                 :            :         } else {
      75         [ #  # ]:          0 :             outputUrl = convertToFileUrl("stdin.urd");
      76                 :            :         }
      77         [ #  # ]:          0 :         if (nErrors > 0) {
      78         [ #  # ]:          0 :             removeIfExists(outputUrl);
      79                 :            :         } else {
      80         [ #  # ]:          0 :             nErrors = produceFile(outputUrl, 0);
      81                 :            :         }
      82 [ #  # ][ #  # ]:          0 :         idlc()->reset();
      83                 :            :     }
      84                 :        166 :     StringVector const & files = options.getInputFiles();
      85         [ +  + ]:        166 :     if ( options.verbose() )
      86                 :            :     {
      87                 :            :         fprintf( stdout, "%s: compiling %i source files ... \n",
      88 [ +  - ][ +  - ]:        165 :             options.getProgramName().getStr(), (int)files.size() );
      89         [ +  - ]:        165 :         fflush( stdout );
      90                 :            :     }
      91 [ +  + ][ +  - ]:      18432 :     for (StringVector::const_iterator i(files.begin());
                 [ +  + ]
      92 [ +  - ][ +  - ]:      12288 :          i != files.end() && nErrors == 0; ++i)
                 [ #  # ]
      93                 :            :     {
      94         [ +  - ]:       5978 :         OString sysFileName( convertToAbsoluteSystemPath(*i) );
      95                 :            : 
      96         [ +  - ]:       5978 :         if ( !options.quiet() )
      97                 :            :             fprintf(stdout, "Compiling: %s\n",
      98         [ +  - ]:       5978 :                 (*i).getStr());
      99         [ +  - ]:       5978 :         nErrors = compileFile(&sysFileName);
     100                 :            : 
     101 [ +  - ][ +  + ]:       5978 :         if ( idlc()->getWarningCount() && !options.quiet() )
         [ +  - ][ +  + ]
     102                 :            :             fprintf(stdout, "%s: detected %lu warnings compiling file '%s'\n",
     103         [ +  - ]:         76 :                     options.getProgramName().getStr(),
     104                 :            :                     sal::static_int_cast< unsigned long >(
     105                 :            :                         idlc()->getWarningCount()),
     106 [ +  - ][ +  - ]:        152 :                     (*i).getStr());
     107                 :            : 
     108                 :            :         // prepare output file name
     109                 :            :         OString const strippedFileName(
     110                 :       5978 :                 sysFileName.copy(sysFileName.lastIndexOf(SEPARATOR) + 1));
     111                 :       5978 :         OString outputFile;
     112 [ +  - ][ +  - ]:       5978 :         if ( options.isValid("-O") )
     113                 :            :         {
     114         [ +  - ]:       5978 :             outputFile = (options.getOption("-O"));
     115         [ +  + ]:       5978 :             if ('/' != outputFile.getStr()[outputFile.getLength()-1]) {
     116                 :          1 :                 outputFile += OString::valueOf('/');
     117                 :            :             }
     118                 :            :             outputFile += strippedFileName.replaceAt(
     119                 :       5978 :                     strippedFileName.getLength() -3 , 3, "urd");
     120                 :            :         } else {
     121                 :            :             outputFile =
     122                 :          0 :                 sysFileName.replaceAt(sysFileName.getLength() -3 , 3, "urd");
     123                 :            :         }
     124         [ +  - ]:       5978 :         OString const outputFileUrl = convertToFileUrl(outputFile);
     125                 :            : 
     126                 :       5978 :         ::rtl::OString depFileUrl;
     127 [ +  + ][ +  - ]:       5978 :         if (options.isValid("-M")) {
     128 [ +  - ][ +  - ]:       5977 :             depFileUrl = convertToFileUrl(options.getOption("-M"));
     129         [ -  + ]:       5977 :             if ('/' != depFileUrl.getStr()[depFileUrl.getLength()-1]) {
     130                 :          0 :                 depFileUrl += OString::valueOf('/');
     131                 :            :             }
     132                 :            :             depFileUrl += strippedFileName.replaceAt(
     133                 :       5977 :                     strippedFileName.getLength() -3 , 3, "d");
     134                 :            :         }
     135                 :            : 
     136         [ -  + ]:       5978 :         if ( nErrors ) {
     137 [ #  # ][ #  # ]:          0 :             if (options.isValid("-M")) {
     138         [ #  # ]:          0 :                 removeIfExists(depFileUrl);
     139                 :            :             }
     140         [ #  # ]:          0 :             removeIfExists(outputFileUrl);
     141                 :            :         } else {
     142                 :       5978 :             sPair_t const pair(depFileUrl, outputFile);
     143                 :            :             nErrors = produceFile(outputFileUrl,
     144 [ +  + ][ +  - ]:       5978 :                         (options.isValid("-M")) ? &pair : 0);
                 [ +  - ]
     145                 :            :         }
     146                 :            : 
     147 [ +  - ][ +  - ]:       5978 :         idlc()->reset();
     148                 :       5978 :     }
     149                 :            : 
     150         [ -  + ]:        166 :     if ( nErrors > 0 )
     151                 :            :     {
     152                 :            :         fprintf(stderr, "%s: detected %ld errors%s",
     153         [ #  # ]:          0 :             options.getProgramName().getStr(),
     154                 :            :             sal::static_int_cast< long >(nErrors),
     155 [ #  # ][ #  # ]:          0 :             options.prepareVersion().getStr());
     156                 :            :     } else
     157                 :            :     {
     158         [ +  + ]:        166 :         if ( options.verbose() )
     159                 :            :             fprintf(stdout, "%s: returned successful%s",
     160         [ +  - ]:        165 :                 options.getProgramName().getStr(),
     161 [ +  - ][ +  - ]:        330 :                 options.prepareVersion().getStr());
     162                 :            :     }
     163         [ +  - ]:        166 :     return nErrors;
     164                 :            : }
     165                 :            : 
     166                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10