LCOV - code coverage report
Current view: top level - unodevtools/source/skeletonmaker - skeletonmaker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 148 0.0 %
Date: 2014-11-03 Functions: 0 5 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             : #include <iostream>
      20             : 
      21             : #include "codemaker/global.hxx"
      22             : #include "codemaker/typemanager.hxx"
      23             : #include "sal/main.h"
      24             : #include "rtl/process.h"
      25             : #include "unodevtools/options.hxx"
      26             : #include "unoidl/unoidl.hxx"
      27             : 
      28             : #include "skeletonjava.hxx"
      29             : #include "skeletoncpp.hxx"
      30             : 
      31             : using namespace ::skeletonmaker;
      32             : using namespace ::unodevtools;
      33             : 
      34             : namespace {
      35             : 
      36             : static const char usageText[] =
      37             : "\n sub-commands:\n"
      38             : "    dump        dump declarations on stdout (e.g. constructors, methods, type\n"
      39             : "                mapping for properties) or complete method bodies with\n"
      40             : "                method forwarding.\n"
      41             : "    component   generates language specific code skeleton files using the\n"
      42             : "                implementation name as the file and class name\n"
      43             : "    calc-add-in generates a language specific code skeleton for a calc add-in\n"
      44             : "                using the implementation name as the file and class name. A \n"
      45             : "                service type is necessary, referencing an interface which defines\n"
      46             : "                the new add-in functions.\n"
      47             : "    add-on      generates a language specific code skeleton for an add-on compnent\n"
      48             : "                using the implementation name as the file and class name. The protocol\n"
      49             : "                name(s) and the corresponding command(s) have to be specified with the\n"
      50             : "                '-p' option.\n"
      51             : "\n options:\n"
      52             : "    -a, --all              list all interface methods, not only the direct\n"
      53             : "                           ones\n"
      54             : "    --(java5|cpp)          select the target language\n"
      55             : "                           --java5 generate output for Java 1.5 or later (is \n"
      56             : "                                   currently the default)\n"
      57             : "                           --cpp   generate output for C++\n"
      58             : "    -sn, --shortnames      using namespace abbreviation 'css:': for\n"
      59             : "                           '::com::sun::star::', only valid for sub-command\n"
      60             : "                           'dump' and target language 'cpp'. It is default for the\n"
      61             : "                           sub-command 'component'.\n"
      62             : "    --propertysetmixin     the generated skeleton implements the cppu::PropertySetMixin\n"
      63             : "                           helper if a referenced new style service specifies an\n"
      64             : "                           interface which provides attributes (directly or inherited).\n"
      65             : "    -lh --licenseheader    generates a default LibreOffice MPL license\n"
      66             : "                           header at the beginning of a component source file.\n"
      67             : "                           This option is taken into account in 'component' mode\n"
      68             : "                           only and if -o is unequal 'stdout'.\n"
      69             : "    -bc                    specifies that the generated calc add-in is backward\n"
      70             : "    --backward-compatible  compatible to older office versions and implement the\n"
      71             : "                           former required add-in interfaces where the implementation\n"
      72             : "                           is mapped on the new add-in configuration. In this case\n"
      73             : "                           the config schema needs to be bundled with the extension\n"
      74             : "                           add-in as well. Default is a minimal add-in component\n"
      75             : "                           skeleton based on the configuration coming with the\n"
      76             : "                           office since OO.org 2.0.4.\n"
      77             : "    -o <path>              path specifies an existing directory where the\n"
      78             : "                           output files are generated to, only valid for\n"
      79             : "                           sub-command 'component'. If path=stdout the generated\n"
      80             : "                           code is generated on standard out instead of a file.\n"
      81             : "    -l <file>              specifies a binary type library (can be used more\n"
      82             : "                           than once).\n"
      83             : "    -n <name>              specifies an implementation name for the component\n"
      84             : "                           (used as classname, filename and package|namespace\n"
      85             : "                           name). In 'dump' mode it is used as classname (e.g.\n"
      86             : "                           \"MyBase::\", C++ only) to generate method bodies not\n"
      87             : "                           inline.\n"
      88             : "    -d <name>              specifies a base classname or a delegator.\n"
      89             : "                           In 'dump' mode it is used as a delegator to forward\n"
      90             : "                           methods. It can be used as '<name>::' for base\n"
      91             : "                           forwarding, or '<name>->|.' for composition.\n"
      92             : "                           Using \"_\" means that a default bodies with default\n"
      93             : "                           return values are dumped.\n"
      94             : "    -t <name>              specifies an UNOIDL type name, e.g.\n"
      95             : "                           com.sun.star.text.XText (can be used more than once)\n"
      96             : "    -p <protocol:cmd(s)>   specifies an add-on protocol name and the corresponding\n"
      97             : "                           command names, where the commands are a ',' separated list\n"
      98             : "                           of unique commands. This option is only valid for add-ons.\n"
      99             : "    -V, --version          print version number and exit\n"
     100             : "    -h, --help             print this help and exit\n\n";
     101             : 
     102           0 : void printUsageAndExit(const char* programname, const char* version)
     103             : {
     104             :     std::cerr
     105           0 :         << "\n using: " << programname << "\n"
     106             :            "            dump [<options>] -t <type> ...\n"
     107           0 :            "        " << programname << "\n"
     108             :            "            component [<options>] -n <name> -t <type> ...\n"
     109           0 :            "        " << programname << "\n"
     110             :            "            calc-add-in [<options>] -n <name> -t <add-in_service>\n"
     111           0 :            "        " << programname << "\n"
     112             :            "            add-on [<options>] -n <name> -p <protocol_name:command,...>\n"
     113           0 :            "        " << programname << " -V, --version\n"
     114           0 :            "        " << programname << " -h, --help\n"
     115           0 :         << usageText
     116           0 :         << programname << " Version " << version << "\n\n";
     117           0 : }
     118             : 
     119             : }
     120             : 
     121           0 : SAL_IMPLEMENT_MAIN()
     122             : {
     123           0 :     const char* version = "0.4";
     124           0 :     const char* programname = "uno-skeletonmaker";
     125             : 
     126           0 :     sal_uInt32 nCount = rtl_getAppCommandArgCount();
     127           0 :     if ( nCount == 0 ) {
     128           0 :         printUsageAndExit(programname, version);
     129           0 :         exit(EXIT_FAILURE);
     130             :     }
     131             : 
     132           0 :     ProgramOptions options;
     133           0 :     std::vector< OString > registries;
     134           0 :     std::vector< OString > types;
     135           0 :     OString delegate;
     136             : 
     137             :     try {
     138             : 
     139           0 :     sal_uInt32 nPos = 0;
     140           0 :     OUString arg, sOption;
     141           0 :     sal_Bool bOption=sal_False;
     142             : 
     143             :     // check command
     144           0 :     rtl_getAppCommandArg(nPos++, &arg.pData);
     145           0 :     if ( arg == "dump" ) {
     146           0 :         options.dump = true;
     147           0 :     } else if ( arg == "component" ) {
     148           0 :         options.dump = false;
     149           0 :         options.shortnames = true;
     150           0 :     } else if ( arg == "calc-add-in" ) {
     151           0 :         options.dump = false;
     152           0 :         options.shortnames = true;
     153           0 :         options.componenttype = 2;
     154           0 :     } else if ( arg == "add-on" ) {
     155           0 :         options.dump = false;
     156           0 :         options.shortnames = true;
     157           0 :         options.componenttype = 3;
     158           0 :     } else if ( readOption( &bOption, "h", &nPos, arg) ||
     159           0 :                 readOption( &bOption, "help", &nPos, arg) ) {
     160           0 :         printUsageAndExit(programname, version);
     161           0 :         exit(EXIT_SUCCESS);
     162           0 :     } else if ( readOption( &bOption, "V", &nPos, arg) ||
     163           0 :                 readOption( &bOption, "version", &nPos, arg) ) {
     164           0 :         std::cerr << "\n Sun Microsystems (R) " << programname
     165           0 :                   << " Version " << version << "\n\n";
     166           0 :         exit(EXIT_SUCCESS);
     167             :     } else {
     168             :         std::cerr
     169           0 :             << "ERROR: unexpected command \""
     170           0 :             << OUStringToOString(arg, RTL_TEXTENCODING_UTF8).getStr()
     171           0 :             << "\"!\n";
     172           0 :         printUsageAndExit(programname, version);
     173           0 :         exit(EXIT_FAILURE);
     174             :     }
     175             : 
     176             :     // read up to arguments
     177           0 :     while ( nPos < nCount )
     178             :     {
     179           0 :         rtl_getAppCommandArg(nPos, &arg.pData);
     180             : 
     181           0 :         if ( readOption( &bOption, "a", &nPos, arg) ||
     182           0 :              readOption( &bOption, "all", &nPos, arg) ) {
     183           0 :             options.all = true;
     184           0 :             continue;
     185             :         }
     186           0 :         if ( readOption( &bOption, "java4", &nPos, arg) ) {
     187             :             std::cerr <<
     188           0 :               "\nError: Java 1.4 is no longer supported, use --java5 instead\n";
     189             :         }
     190           0 :         if ( readOption( &bOption, "java5", &nPos, arg) ) {
     191           0 :             options.language = 1;
     192           0 :             continue;
     193             :         }
     194           0 :         if ( readOption( &bOption, "cpp", &nPos, arg) ) {
     195           0 :             options.language = 2;
     196           0 :             continue;
     197             :         }
     198           0 :         if ( readOption( &bOption, "sn", &nPos, arg) ||
     199           0 :              readOption( &bOption, "shortnames", &nPos, arg) ) {
     200           0 :             options.shortnames = true;
     201           0 :             continue;
     202             :         }
     203           0 :         if ( readOption( &bOption, "lh", &nPos, arg) ||
     204           0 :              readOption( &bOption, "licenseheader", &nPos, arg) ) {
     205           0 :             options.license = true;
     206           0 :             continue;
     207             :         }
     208           0 :         if ( readOption( &bOption, "bc", &nPos, arg) ||
     209           0 :              readOption( &bOption, "backward-compatible", &nPos, arg) ) {
     210           0 :             options.backwardcompatible = true;
     211           0 :             continue;
     212             :         }
     213           0 :         if ( readOption( &bOption, "propertysetmixin", &nPos, arg) ) {
     214           0 :             options.supportpropertysetmixin = true;
     215           0 :             continue;
     216             :         }
     217           0 :         if ( readOption( &sOption, "d", &nPos, arg) ) {
     218           0 :             delegate = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8);
     219           0 :             continue;
     220             :         }
     221           0 :         if ( readOption( &sOption, "n", &nPos, arg) ) {
     222           0 :             options.implname = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8);
     223           0 :             continue;
     224             :         }
     225           0 :         if ( readOption( &sOption, "o", &nPos, arg) ) {
     226           0 :             options.outputpath = OUStringToOString(sOption, RTL_TEXTENCODING_UTF8);
     227           0 :             continue;
     228             :         }
     229           0 :         if ( readOption( &sOption, "l", &nPos, arg) ) {
     230           0 :             registries.push_back(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8));
     231           0 :             continue;
     232             :         }
     233           0 :         if ( readOption( &sOption, "t", &nPos, arg) ) {
     234           0 :             types.push_back(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8));
     235           0 :             continue;
     236             :         }
     237           0 :         if ( readOption( &sOption, "p", &nPos, arg) ) {
     238           0 :             OString sTmp(OUStringToOString(sOption, RTL_TEXTENCODING_UTF8));
     239           0 :             sal_Int32 nIndex= sTmp.indexOf(':');
     240           0 :             OString sPrt = sTmp.copy(0, nIndex+1);
     241           0 :             OString sCmds = sTmp.copy(nIndex+1);
     242             : 
     243           0 :             nIndex = 0;
     244           0 :             std::vector< OString > vCmds;
     245           0 :             do {
     246           0 :                 OString sCmd = sCmds.getToken( 0, ',', nIndex );
     247           0 :                 vCmds.push_back(sCmd);
     248           0 :             } while ( nIndex >= 0 );
     249             : 
     250           0 :             options.protocolCmdMap.insert(ProtocolCmdMap::value_type(sPrt, vCmds));
     251           0 :             continue;
     252             :         }
     253             : 
     254             : 
     255             :         // else illegal argument
     256           0 :         throw CannotDumpException("unexpected parameter \"" + arg + "\"!");
     257             :     }
     258             : 
     259           0 :     if ( types.empty() && options.componenttype != 3) {
     260             :         std::cerr
     261           0 :             << ("\nError: no type is specified, use the -T option at least once\n");
     262           0 :         printUsageAndExit(programname, version);
     263           0 :         exit(EXIT_FAILURE);
     264             :     }
     265             : 
     266           0 :     rtl::Reference< TypeManager > manager(new TypeManager);
     267           0 :     for (std::vector< OString >::const_iterator i(registries.begin());
     268           0 :          i != registries.end(); ++i)
     269             :     {
     270           0 :         manager->loadProvider(convertToFileUrl(*i), true);
     271             :     }
     272             : 
     273           0 :     if ( options.dump ) {
     274           0 :         std::vector< OString >::const_iterator iter = types.begin();
     275           0 :         while (iter != types.end()) {
     276             :             std::cout << "\n/***************************************************"
     277           0 :                 "*****************************/\n";
     278           0 :             switch (options.language )
     279             :             {
     280             :             case 1: //Java
     281             :                 java::generateDocumentation(std::cout, options, manager,
     282           0 :                                             *iter, delegate);
     283           0 :                 break;
     284             :             case 2: //C++
     285             :                 cpp::generateDocumentation(std::cout, options, manager,
     286           0 :                                            *iter, delegate);
     287           0 :                 break;
     288             :             default:
     289             :                 OSL_ASSERT(false);
     290           0 :                 break;
     291             :             }
     292           0 :             ++iter;
     293             :         }
     294             :     } else {
     295           0 :         switch ( options.language )
     296             :         {
     297             :         case 1: //Java
     298           0 :             java::generateSkeleton(options, manager, types);
     299           0 :             break;
     300             :         case 2: //C++
     301           0 :             cpp::generateSkeleton(options, manager, types);
     302           0 :             break;
     303             :         default:
     304             :             OSL_ASSERT(false);
     305           0 :             break;
     306             :         }
     307           0 :     }
     308             : 
     309           0 :     } catch (CannotDumpException & e) {
     310           0 :         std::cerr << "ERROR: " << e.getMessage() << '\n';
     311           0 :         return EXIT_FAILURE;
     312           0 :     } catch (unoidl::NoSuchFileException & e) {
     313           0 :         std::cerr << "ERROR: No such file <" << e.getUri() << ">\n";
     314           0 :         return EXIT_FAILURE;
     315           0 :     } catch (unoidl::FileFormatException & e) {
     316             :         std::cerr
     317           0 :             << "ERROR: Bad format of <" << e.getUri() << ">, \""
     318           0 :             << e.getDetail() << "\"\n";
     319           0 :         return EXIT_FAILURE;
     320             :     }
     321             : 
     322           0 :     return 0;
     323           0 : }
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10