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 static 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 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";
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";
168 << "ERROR: unexpected command \""
169 << OUStringToOString(arg
, RTL_TEXTENCODING_UTF8
).getStr()
171 printUsageAndExit(programname
, version
);
175 // read up to arguments
176 while ( nPos
< nCount
)
178 rtl_getAppCommandArg(nPos
, &arg
.pData
);
180 if ( readOption( "a", &nPos
, arg
) ||
181 readOption( "all", &nPos
, arg
) ) {
185 if ( readOption( "java4", &nPos
, arg
) ) {
187 "\nError: Java 1.4 is no longer supported, use --java5 instead\n";
189 if ( readOption( "java5", &nPos
, arg
) ) {
190 options
.language
= 1;
193 if ( readOption( "cpp", &nPos
, arg
) ) {
194 options
.language
= 2;
197 if ( readOption( "sn", &nPos
, arg
) ||
198 readOption( "shortnames", &nPos
, arg
) ) {
199 options
.shortnames
= true;
202 if ( readOption( "lh", &nPos
, arg
) ||
203 readOption( "licenseheader", &nPos
, arg
) ) {
204 options
.license
= true;
207 if ( readOption( "bc", &nPos
, arg
) ||
208 readOption( "backward-compatible", &nPos
, arg
) ) {
209 options
.backwardcompatible
= true;
212 if ( readOption( "propertysetmixin", &nPos
, arg
) ) {
213 options
.supportpropertysetmixin
= true;
216 if ( readOption( &sOption
, "d", &nPos
, arg
) ) {
217 delegate
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
220 if ( readOption( &sOption
, "n", &nPos
, arg
) ) {
221 options
.implname
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
224 if ( readOption( &sOption
, "o", &nPos
, arg
) ) {
225 options
.outputpath
= OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
);
228 if ( readOption( &sOption
, "l", &nPos
, arg
) ) {
229 registries
.push_back(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
232 if ( readOption( &sOption
, "t", &nPos
, arg
) ) {
233 types
.push_back(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
236 if ( readOption( &sOption
, "p", &nPos
, arg
) ) {
237 OString
sTmp(OUStringToOString(sOption
, RTL_TEXTENCODING_UTF8
));
238 sal_Int32 nIndex
= sTmp
.indexOf(':');
239 OString sPrt
= sTmp
.copy(0, nIndex
+1);
240 OString sCmds
= sTmp
.copy(nIndex
+1);
243 std::vector
< OString
> vCmds
;
245 OString sCmd
= sCmds
.getToken( 0, ',', nIndex
);
246 vCmds
.push_back(sCmd
);
247 } while ( nIndex
>= 0 );
249 options
.protocolCmdMap
.insert(ProtocolCmdMap::value_type(sPrt
, vCmds
));
254 // else illegal argument
255 throw CannotDumpException("unexpected parameter \"" + arg
+ "\"!");
258 if ( types
.empty() && options
.componenttype
!= 3) {
260 << ("\nError: no type is specified, use the -T option at least once\n");
261 printUsageAndExit(programname
, version
);
265 rtl::Reference
< TypeManager
> manager(new TypeManager
);
266 for (std::vector
< OString
>::const_iterator
i(registries
.begin());
267 i
!= registries
.end(); ++i
)
269 manager
->loadProvider(convertToFileUrl(*i
), true);
272 if ( options
.dump
) {
273 std::vector
< OString
>::const_iterator iter
= types
.begin();
274 while (iter
!= types
.end()) {
275 std::cout
<< "\n/***************************************************"
276 "*****************************/\n";
277 switch (options
.language
)
280 java::generateDocumentation(std::cout
, options
, manager
,
284 cpp::generateDocumentation(std::cout
, options
, manager
,
294 switch ( options
.language
)
297 java::generateSkeleton(options
, manager
, types
);
300 cpp::generateSkeleton(options
, manager
, types
);
308 } catch (CannotDumpException
& e
) {
309 std::cerr
<< "ERROR: " << e
.getMessage() << '\n';
311 } catch (unoidl::NoSuchFileException
& e
) {
312 std::cerr
<< "ERROR: No such file <" << e
.getUri() << ">\n";
314 } catch (unoidl::FileFormatException
& e
) {
316 << "ERROR: Bad format of <" << e
.getUri() << ">, \""
317 << e
.getDetail() << "\"\n";
319 } catch (std::exception
& e
) {
320 std::cerr
<< "ERROR: " << e
.what() << "\n";
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */