diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-04-11 09:27:11 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-04-11 09:29:44 +0200 |
commit | fc02ae8f825b9325c3f3d6b690a1bffeb0520253 (patch) | |
tree | ce1d8a59480232a0e6cc35f1ce60056b0f87e63e /codemaker/source/javamaker/javamaker.cxx | |
parent | Minor terminology clean-up (diff) | |
download | core-fc02ae8f825b9325c3f3d6b690a1bffeb0520253.tar.gz core-fc02ae8f825b9325c3f3d6b690a1bffeb0520253.zip |
[API CHANGE] WIP: Experimental new binary type.rdb format
Make javamaker work on top of unoidl/ instead of registry/.
API CHANGE: javamaker no longer supports the -B switch, as that is meaningless
with the new format. When reading from an old-format .rdb file, /UCR is hard-
coded as the prefix now.
Change-Id: I8cca39f8ebacd0476934f7bd493d206928d063a9
Diffstat (limited to 'codemaker/source/javamaker/javamaker.cxx')
-rw-r--r-- | codemaker/source/javamaker/javamaker.cxx | 269 |
1 files changed, 61 insertions, 208 deletions
diff --git a/codemaker/source/javamaker/javamaker.cxx b/codemaker/source/javamaker/javamaker.cxx index c10406bcaf79..9250153be6fd 100644 --- a/codemaker/source/javamaker/javamaker.cxx +++ b/codemaker/source/javamaker/javamaker.cxx @@ -17,234 +17,87 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include "sal/config.h" -#include <stdio.h> +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <vector> +#include "codemaker/generatedtypeset.hxx" +#include "codemaker/typemanager.hxx" #include "rtl/ref.hxx" +#include "rtl/string.hxx" +#include "rtl/ustring.hxx" #include "sal/main.h" +#include "sal/types.h" +#include "unoidl/unoidl.hxx" -#include "codemaker/typemanager.hxx" -#include "codemaker/generatedtypeset.hxx" #include "javaoptions.hxx" #include "javatype.hxx" -using ::rtl::OUString; -using ::rtl::OString; -sal_Bool produceAllTypes(RegistryKey& rTypeKey, sal_Bool bIsExtraType, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - JavaOptions* pOptions, - sal_Bool bFullScope) -{ - OString typeName = typeMgr->getTypeName(rTypeKey); - - if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, pOptions)) - { - fprintf(stderr, "%s ERROR: %s\n", - pOptions->getProgramName().getStr(), - OString("cannot dump Type '" + typeName + "'").getStr()); - exit(99); - } - - RegistryKeyList typeKeys = typeMgr->getTypeKeys(typeName); - RegistryKeyList::const_iterator iter = typeKeys.begin(); - RegistryKey key, subKey; - RegistryKeyArray subKeys; - - while (iter != typeKeys.end()) - { - key = (*iter).first; - - if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) - { - for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) - { - subKey = subKeys.getElement(i); - if (bFullScope) - { - if (!produceAllTypes( - subKey, (*iter).second, - typeMgr, generated, pOptions, sal_True)) - return sal_False; - } else - { - if (!produceType(subKey, (*iter).second, - typeMgr, generated, pOptions)) - return sal_False; - } - } +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) { + JavaOptions options; + try { + if (!options.initOptions(argc, argv)) { + return EXIT_FAILURE; } - - ++iter; - } - - return sal_True; -} - -sal_Bool produceAllTypes(const OString& typeName, - rtl::Reference< TypeManager > const & typeMgr, - codemaker::GeneratedTypeSet & generated, - JavaOptions* pOptions, - sal_Bool bFullScope) -{ - if (!produceType(typeName, typeMgr, generated, pOptions)) - { - fprintf(stderr, "%s ERROR: %s\n", - pOptions->getProgramName().getStr(), - OString("cannot dump Type '" + typeName + "'").getStr()); - exit(99); + } catch (IllegalArgument & e) { + std::cerr << "Illegal option " << e.m_message << '\n'; + return EXIT_FAILURE; } - - RegistryKeyList typeKeys = typeMgr->getTypeKeys(typeName); - RegistryKeyList::const_iterator iter = typeKeys.begin(); - RegistryKey key, subKey; - RegistryKeyArray subKeys; - - while (iter != typeKeys.end()) - { - key = (*iter).first; - if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) + try { + rtl::Reference< TypeManager > typeMgr(new TypeManager); + if (!typeMgr->init( + options.getInputFiles(), options.getExtraInputFiles())) { - for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) - { - subKey = subKeys.getElement(i); - if (bFullScope) - { - if (!produceAllTypes( - subKey, (*iter).second, - typeMgr, generated, pOptions, sal_True)) - return sal_False; - } else - { - if (!produceType(subKey, (*iter).second, - typeMgr, generated, pOptions)) - return sal_False; - } - } + std::cerr << "Initialization of registries failed\n"; + return EXIT_FAILURE; } - - ++iter; - } - - return sal_True; -} - -SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) -{ - JavaOptions options; - - try - { - if (!options.initOptions(argc, argv)) + for (std::vector< rtl::OString >::const_iterator i( + options.getExtraInputFiles().begin()); + i != options.getExtraInputFiles().end(); ++i) { - exit(1); + typeMgr->loadProvider(b2u(*i), false); } - } - catch( IllegalArgument& e) - { - fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); - exit(99); - } - - rtl::Reference< TypeManager > typeMgr(new TypeManager); - - if (!typeMgr->init(options.getInputFiles(), options.getExtraInputFiles())) - { - fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); - exit(99); - } - - if (options.isValid("-B")) - { - typeMgr->setBase(options.getOption("-B")); - } - - for (std::vector< rtl::OString >::const_iterator i( - options.getExtraInputFiles().begin()); - i != options.getExtraInputFiles().end(); ++i) - { - typeMgr->loadProvider(b2u(*i), false); - } - for (std::vector< rtl::OString >::const_iterator i( - options.getInputFiles().begin()); - i != options.getInputFiles().end(); ++i) - { - typeMgr->loadProvider(b2u(*i), true); - } - - try - { - if (options.isValid("-T")) + for (std::vector< rtl::OString >::const_iterator i( + options.getInputFiles().begin()); + i != options.getInputFiles().end(); ++i) { - OString tOption(options.getOption("-T")); - sal_Int32 nIndex = 0; - - codemaker::GeneratedTypeSet generated; - OString typeName, tmpName; - sal_Bool ret = sal_False; - do - { - typeName = tOption.getToken(0, ';', nIndex); - - sal_Int32 nPos = typeName.lastIndexOf( '.' ); - tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); - if (tmpName == "*") - { - // produce this type and his scope. - if (typeName == "*") - { - tmpName = "/"; - } else - { - tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); - if (tmpName.isEmpty()) - tmpName = "/"; - else - tmpName = tmpName.replace('.', '/'); - } - // related to task #116780# the scope is recursively - // generated. bFullScope = true - ret = produceAllTypes( - tmpName, typeMgr, generated, &options, sal_True); - } else - { - // produce only this type - ret = produceType( - typeName.replace('.', '/'), typeMgr, generated, - &options); - } - - if (!ret) - { - fprintf(stderr, "%s ERROR: %s\n", - options.getProgramName().getStr(), - OString("cannot dump Type '" + typeName + "'").getStr()); - exit(99); + typeMgr->loadProvider(b2u(*i), true); + } + codemaker::GeneratedTypeSet generated; + if (options.isValid("-T")) { + OUString names(b2u(options.getOption("-T"))); + for (sal_Int32 i = 0; i != -1;) { + OUString name(names.getToken(0, ';', i)); + if (!name.isEmpty()) { + produce( + (name == "*" + ? "" + : name.endsWith(".*") + ? name.copy(0, name.getLength() - std::strlen(".*")) + : name), + typeMgr, generated, options); } - } while( nIndex != -1 ); - } else - { - // produce all types - codemaker::GeneratedTypeSet generated; - if (!produceAllTypes("/", typeMgr, generated, &options, sal_True)) - { - fprintf(stderr, "%s ERROR: %s\n", - options.getProgramName().getStr(), - "an error occurs while dumping all types."); - exit(99); } + } else { + produce("", typeMgr, generated, options); } } - catch( CannotDumpException& e) - { - fprintf(stderr, "%s ERROR: %s\n", - options.getProgramName().getStr(), - u2b(e.getMessage()).getStr()); - exit(99); + catch (CannotDumpException & e) { + std::cerr << "ERROR: " << e.getMessage() << '\n'; + return EXIT_FAILURE; + } catch (unoidl::NoSuchFileException & e) { + std::cerr << "ERROR: No such file <" << e.getUri() << ">\n"; + return EXIT_FAILURE; + } catch (unoidl::FileFormatException & e) { + std::cerr + << "ERROR: Bad format of <" << e.getUri() << ">, \"" + << e.getDetail() << "\"\n"; + return EXIT_FAILURE; } - - return 0; + return EXIT_SUCCESS; } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |