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

Generated by: LCOV version 1.10