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

Generated by: LCOV version 1.10