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