1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_codemaker.hxx" 30 31 #include <stdio.h> 32 33 #include "sal/main.h" 34 35 #include "codemaker/typemanager.hxx" 36 #include "codemaker/generatedtypeset.hxx" 37 38 #include "cppuoptions.hxx" 39 #include "cpputype.hxx" 40 41 using namespace rtl; 42 43 namespace { 44 45 void failed(rtl::OString const & typeName, CppuOptions * options) { 46 fprintf(stderr, "%s ERROR: %s\n", options->getProgramName().getStr(), 47 rtl::OString("cannot dump Type '" + typeName + "'").getStr()); 48 exit(99); 49 } 50 51 void produce( 52 RegistryKey& rTypeKey, bool bIsExtraType, TypeManager const & typeMgr, 53 codemaker::GeneratedTypeSet & generated, CppuOptions * options) 54 { 55 if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, options)) { 56 OString typeName = typeMgr.getTypeName(rTypeKey); 57 failed(typeName, options); 58 } 59 } 60 61 void produce( 62 rtl::OString const & typeName, TypeManager const & typeMgr, 63 codemaker::GeneratedTypeSet & generated, CppuOptions * options) 64 { 65 if (!produceType(typeName, typeMgr, generated, options)) { 66 failed(typeName, options); 67 } 68 } 69 70 void produceAllTypes(RegistryKey& rTypeKey, bool bIsExtraType, 71 TypeManager const & typeMgr, 72 codemaker::GeneratedTypeSet & generated, 73 CppuOptions* pOptions, 74 sal_Bool bFullScope) 75 throw( CannotDumpException ) 76 { 77 OString typeName = typeMgr.getTypeName(rTypeKey); 78 79 produce(rTypeKey, bIsExtraType, typeMgr, generated, pOptions); 80 81 RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName); 82 RegistryKeyList::const_iterator iter = typeKeys.begin(); 83 RegistryKey key, subKey; 84 RegistryKeyArray subKeys; 85 86 while (iter != typeKeys.end()) 87 { 88 key = (*iter).first; 89 90 if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) 91 { 92 for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) 93 { 94 subKey = subKeys.getElement(i); 95 if (bFullScope) 96 { 97 produceAllTypes(subKey, (*iter).second, typeMgr, 98 generated, pOptions, true); 99 } else 100 { 101 produce(subKey, (*iter).second, 102 typeMgr, generated, pOptions); 103 } 104 } 105 } 106 107 ++iter; 108 } 109 } 110 111 void produceAllTypes(const OString& typeName, 112 TypeManager const & typeMgr, 113 codemaker::GeneratedTypeSet & generated, 114 CppuOptions* pOptions, 115 sal_Bool bFullScope) 116 throw( CannotDumpException ) 117 { 118 produce(typeName, typeMgr, generated, pOptions); 119 120 RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName); 121 RegistryKeyList::const_iterator iter = typeKeys.begin(); 122 RegistryKey key, subKey; 123 RegistryKeyArray subKeys; 124 125 while (iter != typeKeys.end()) 126 { 127 key = (*iter).first; 128 if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) 129 { 130 for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) 131 { 132 subKey = subKeys.getElement(i); 133 if (bFullScope) 134 { 135 produceAllTypes(subKey, (*iter).second, typeMgr, 136 generated, pOptions, true); 137 } else 138 { 139 produce(subKey, (*iter).second, 140 typeMgr, generated, pOptions); 141 } 142 } 143 } 144 145 ++iter; 146 } 147 } 148 149 } 150 151 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) 152 { 153 CppuOptions options; 154 155 try 156 { 157 if (!options.initOptions(argc, argv)) 158 { 159 exit(1); 160 } 161 } 162 catch( IllegalArgument& e) 163 { 164 fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); 165 exit(99); 166 } 167 168 RegistryTypeManager typeMgr; 169 170 if (!typeMgr.init(options.getInputFiles(), options.getExtraInputFiles())) 171 { 172 fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); 173 exit(99); 174 } 175 176 if (options.isValid("-B")) 177 { 178 typeMgr.setBase(options.getOption("-B")); 179 } 180 181 codemaker::GeneratedTypeSet generated; 182 try 183 { 184 if (options.isValid("-T")) 185 { 186 OString tOption(options.getOption("-T")); 187 188 OString typeName, tmpName; 189 sal_Int32 nIndex = 0; 190 do 191 { 192 typeName = tOption.getToken(0, ';', nIndex); 193 194 sal_Int32 nPos = typeName.lastIndexOf( '.' ); 195 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); 196 if (tmpName == "*") 197 { 198 // produce this type and his scope 199 if (typeName.equals("*")) 200 { 201 tmpName = "/"; 202 } else 203 { 204 tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); 205 if (tmpName.getLength() == 0) 206 tmpName = "/"; 207 else 208 tmpName.replace('.', '/'); 209 } 210 // related to task #116780# the scope is recursively 211 // generated. bFullScope = true 212 produceAllTypes( 213 tmpName, typeMgr, generated, &options, true); 214 } else 215 { 216 // produce only this type 217 produce( 218 typeName.replace('.', '/'), typeMgr, generated, &options); 219 } 220 } while( nIndex != -1 ); 221 } else 222 { 223 // produce all types 224 produceAllTypes("/", typeMgr, generated, &options, true); 225 } 226 // C++ header files generated for the following UNO types are included 227 // in header files in cppu/inc/com/sun/star/uno (Any.hxx, Reference.hxx, 228 // Type.h), so it seems best to always generate those C++ header files: 229 produce("com/sun/star/uno/RuntimeException", typeMgr, generated, &options); 230 produce("com/sun/star/uno/TypeClass", typeMgr, generated, &options); 231 produce("com/sun/star/uno/XInterface", typeMgr, generated, &options); 232 } 233 catch( CannotDumpException& e) 234 { 235 fprintf(stderr, "%s ERROR: %s\n", 236 options.getProgramName().getStr(), 237 e.m_message.getStr()); 238 exit(99); 239 } 240 241 return 0; 242 } 243 244 245