1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <codemaker/global.hxx>
22 #include <codemaker/typemanager.hxx>
24 #include <rtl/process.h>
25 #include <options.hxx>
26 #include <unoidl/unoidl.hxx>
28 #include "skeletonjava.hxx"
29 #include "skeletoncpp.hxx"
31 using namespace ::skeletonmaker
;
32 using namespace ::unodevtools
;
36 const char usageText
[] =
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 component\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"
52 " -a, --all list all interface methods, not only the direct\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"
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"
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 a 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";
102 void printUsageAndExit(const char* programname
, const char* version
)
105 << "\n using: " << programname
<< "\n"
106 " dump [<options>] -t <type> ...\n"
107 " " << programname
<< "\n"
108 " component [<options>] -n <name> -t <type> ...\n"
109 " " << programname
<< "\n"
110 " calc-add-in [<options>] -n <name> -t <add-in_service>\n"
111 " " << programname
<< "\n"
112 " add-on [<options>] -n <name> -p <protocol_name:command,...>\n"
113 " " << programname
<< " -V, --version\n"
114 " " << programname
<< " -h, --help\n"
116 << programname
<< " Version " << version
<< "\n\n";
123 const char* const version
= "0.4";
124 const char* const programname
= "uno-skeletonmaker";
126 sal_uInt32 nCount
= rtl_getAppCommandArgCount();
128 printUsageAndExit(programname
, version
);
132 ProgramOptions options
;
133 std::vector
< OString
> registries
;
134 std::vector
< OString
> types
;
140 OUString arg
, sOption
;
143 rtl_getAppCommandArg(nPos
++, &arg
.pData
);
144 if ( arg
== "dump" ) {
146 } else if ( arg
== "component" ) {
147 options
.dump
= false;
148 options
.shortnames
= true;
149 } else if ( arg
== "calc-add-in" ) {
150 options
.dump
= false;
151 options
.shortnames
= true;
152 options
.componenttype
= 2;
153 } else if ( arg
== "add-on" ) {
154 options
.dump
= false;
155 options
.shortnames
= true;
156 options
.componenttype
= 3;
157 } else if ( readOption( "h", &nPos
, arg
) ||
158 readOption( "help", &nPos
, arg
) ) {
159 printUsageAndExit(programname
, version
);
161 } else if ( readOption( "V", &nPos
, arg
) ||
162 readOption( "version", &nPos
, arg
) ) {
163 std::cerr
<< "\n Sun Microsystems (R) " << programname
164 << " Version " << version
<< "\n\n";
167 std::cerr
<< "ERROR: unexpected command \"" << arg
<< "\"!\n";
168 printUsageAndExit(programname
, version
);
172 // read up to arguments
173 while ( nPos
< nCount
)
175 rtl_getAppCommandArg(nPos
, &arg
.pData
);
177 if ( readOption( "a", &nPos
, arg
) ||
178 readOption( "all", &nPos
, arg
) ) {
182 if ( readOption( "java4", &nPos
, arg
) ) {
184 "\nError: Java 1.4 is no longer supported, use --java5 instead\n";
186 if ( readOption( "java5", &nPos
, arg
) ) {
187 options
.language
= 1;
190 if ( readOption( "cpp", &nPos
, arg
) ) {
191 options
.language
= 2;
194 if ( readOption( "sn", &nPos
, arg
) ||
195 readOption( "shortnames", &nPos
, arg
) ) {
196 options
.shortnames
= true;
199 if ( readOption( "lh", &nPos
, arg
) ||
200 readOption( "licenseheader", &nPos
, arg
) ) {
201 options
.license
= true;
204 if ( readOption( "bc", &nPos
, arg
) ||
205 readOption( "backward-compatible", &nPos
, arg
) ) {
206 options
.backwardcompatible
= true;
209 if ( readOption( "propertysetmixin", &nPos
, arg
) ) {
210 options
.supportpropertysetmixin
= true;
213 if ( readOption( &sOption
, "d", &nPos
, arg
) ) {
214 delegate
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
217 if ( readOption( &sOption
, "n", &nPos
, arg
) ) {
218 options
.implname
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
221 if ( readOption( &sOption
, "o", &nPos
, arg
) ) {
222 options
.outputpath
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
225 if ( readOption( &sOption
, "l", &nPos
, arg
) ) {
226 registries
.push_back(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
229 if ( readOption( &sOption
, "t", &nPos
, arg
) ) {
230 types
.push_back(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
233 if ( readOption( &sOption
, "p", &nPos
, arg
) ) {
234 OString
sTmp(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
235 sal_Int32 nIndex
{ sTmp
.indexOf(':')+1 };
236 const OString sPrt
= sTmp
.copy(0, nIndex
);
237 std::vector
< OString
> vCmds
;
239 vCmds
.push_back(sTmp
.getToken( 0, ',', nIndex
));
240 options
.protocolCmdMap
.emplace(sPrt
, vCmds
);
245 // else illegal argument
246 throw CannotDumpException("unexpected parameter \"" + arg
+ "\"!");
249 if ( types
.empty() && options
.componenttype
!= 3) {
251 << "\nError: no type is specified, use the -T option at least once\n";
252 printUsageAndExit(programname
, version
);
256 rtl::Reference
< TypeManager
> manager(new TypeManager
);
257 for (const auto& rRegistry
: registries
)
259 manager
->loadProvider(convertToFileUrl(rRegistry
), true);
262 if ( options
.dump
) {
263 for (const auto& rType
: types
) {
264 std::cout
<< "\n/***************************************************"
265 "*****************************/\n";
266 switch (options
.language
)
269 java::generateDocumentation(std::cout
, options
, manager
,
273 cpp::generateDocumentation(std::cout
, options
, manager
,
282 switch ( options
.language
)
285 java::generateSkeleton(options
, manager
, types
);
288 cpp::generateSkeleton(options
, manager
, types
);
296 } catch (CannotDumpException
& e
) {
297 std::cerr
<< "ERROR: " << e
.getMessage() << '\n';
299 } catch (unoidl::NoSuchFileException
& e
) {
300 std::cerr
<< "ERROR: No such file <" << e
.getUri() << ">\n";
302 } catch (unoidl::FileFormatException
& e
) {
304 << "ERROR: Bad format of <" << e
.getUri() << ">, \""
305 << e
.getDetail() << "\"\n";
307 } catch (std::exception
& e
) {
308 std::cerr
<< "ERROR: " << e
.what() << "\n";
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */