1*ff7655f0SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ff7655f0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ff7655f0SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ff7655f0SAndrew Rist * distributed with this work for additional information 6*ff7655f0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ff7655f0SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ff7655f0SAndrew Rist * "License"); you may not use this file except in compliance 9*ff7655f0SAndrew Rist * with the License. You may obtain a copy of the License at 10*ff7655f0SAndrew Rist * 11*ff7655f0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ff7655f0SAndrew Rist * 13*ff7655f0SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ff7655f0SAndrew Rist * software distributed under the License is distributed on an 15*ff7655f0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ff7655f0SAndrew Rist * KIND, either express or implied. See the License for the 17*ff7655f0SAndrew Rist * specific language governing permissions and limitations 18*ff7655f0SAndrew Rist * under the License. 19*ff7655f0SAndrew Rist * 20*ff7655f0SAndrew Rist *************************************************************/ 21*ff7655f0SAndrew Rist 22*ff7655f0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_codemaker.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <stdio.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "sal/main.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "codemaker/typemanager.hxx" 32cdf0e10cSrcweir #include "codemaker/generatedtypeset.hxx" 33cdf0e10cSrcweir #include "javaoptions.hxx" 34cdf0e10cSrcweir #include "javatype.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace rtl; 37cdf0e10cSrcweir 38cdf0e10cSrcweir sal_Bool produceAllTypes(RegistryKey& rTypeKey, sal_Bool bIsExtraType, 39cdf0e10cSrcweir TypeManager const & typeMgr, 40cdf0e10cSrcweir codemaker::GeneratedTypeSet & generated, 41cdf0e10cSrcweir JavaOptions* pOptions, 42cdf0e10cSrcweir sal_Bool bFullScope) 43cdf0e10cSrcweir throw( CannotDumpException ) 44cdf0e10cSrcweir { 45cdf0e10cSrcweir OString typeName = typeMgr.getTypeName(rTypeKey); 46cdf0e10cSrcweir 47cdf0e10cSrcweir if (!produceType(rTypeKey, bIsExtraType, typeMgr, generated, pOptions)) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 50cdf0e10cSrcweir pOptions->getProgramName().getStr(), 51cdf0e10cSrcweir OString("cannot dump Type '" + typeName + "'").getStr()); 52cdf0e10cSrcweir exit(99); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName); 56cdf0e10cSrcweir RegistryKeyList::const_iterator iter = typeKeys.begin(); 57cdf0e10cSrcweir RegistryKey key, subKey; 58cdf0e10cSrcweir RegistryKeyArray subKeys; 59cdf0e10cSrcweir 60cdf0e10cSrcweir while (iter != typeKeys.end()) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir key = (*iter).first; 63cdf0e10cSrcweir 64cdf0e10cSrcweir if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir subKey = subKeys.getElement(i); 69cdf0e10cSrcweir if (bFullScope) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir if (!produceAllTypes( 72cdf0e10cSrcweir subKey, (*iter).second, 73cdf0e10cSrcweir typeMgr, generated, pOptions, sal_True)) 74cdf0e10cSrcweir return sal_False; 75cdf0e10cSrcweir } else 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if (!produceType(subKey, (*iter).second, 78cdf0e10cSrcweir typeMgr, generated, pOptions)) 79cdf0e10cSrcweir return sal_False; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir ++iter; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir return sal_True; 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir sal_Bool produceAllTypes(const OString& typeName, 91cdf0e10cSrcweir TypeManager const & typeMgr, 92cdf0e10cSrcweir codemaker::GeneratedTypeSet & generated, 93cdf0e10cSrcweir JavaOptions* pOptions, 94cdf0e10cSrcweir sal_Bool bFullScope) 95cdf0e10cSrcweir throw( CannotDumpException ) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir if (!produceType(typeName, typeMgr, generated, pOptions)) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 100cdf0e10cSrcweir pOptions->getProgramName().getStr(), 101cdf0e10cSrcweir OString("cannot dump Type '" + typeName + "'").getStr()); 102cdf0e10cSrcweir exit(99); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir RegistryKeyList typeKeys = typeMgr.getTypeKeys(typeName); 106cdf0e10cSrcweir RegistryKeyList::const_iterator iter = typeKeys.begin(); 107cdf0e10cSrcweir RegistryKey key, subKey; 108cdf0e10cSrcweir RegistryKeyArray subKeys; 109cdf0e10cSrcweir 110cdf0e10cSrcweir while (iter != typeKeys.end()) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir key = (*iter).first; 113cdf0e10cSrcweir if (!(*iter).second && !key.openSubKeys(OUString(), subKeys)) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir for (sal_uInt32 i = 0; i < subKeys.getLength(); i++) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir subKey = subKeys.getElement(i); 118cdf0e10cSrcweir if (bFullScope) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir if (!produceAllTypes( 121cdf0e10cSrcweir subKey, (*iter).second, 122cdf0e10cSrcweir typeMgr, generated, pOptions, sal_True)) 123cdf0e10cSrcweir return sal_False; 124cdf0e10cSrcweir } else 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if (!produceType(subKey, (*iter).second, 127cdf0e10cSrcweir typeMgr, generated, pOptions)) 128cdf0e10cSrcweir return sal_False; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir ++iter; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir return sal_True; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir JavaOptions options; 142cdf0e10cSrcweir 143cdf0e10cSrcweir try 144cdf0e10cSrcweir { 145cdf0e10cSrcweir if (!options.initOptions(argc, argv)) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir exit(1); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir catch( IllegalArgument& e) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); 153cdf0e10cSrcweir exit(99); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir RegistryTypeManager typeMgr; 157cdf0e10cSrcweir 158cdf0e10cSrcweir if (!typeMgr.init(options.getInputFiles(), options.getExtraInputFiles())) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); 161cdf0e10cSrcweir exit(99); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir if (options.isValid("-B")) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir typeMgr.setBase(options.getOption("-B")); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir try 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if (options.isValid("-T")) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir OString tOption(options.getOption("-T")); 174cdf0e10cSrcweir sal_Int32 nIndex = 0; 175cdf0e10cSrcweir 176cdf0e10cSrcweir codemaker::GeneratedTypeSet generated; 177cdf0e10cSrcweir OString typeName, tmpName; 178cdf0e10cSrcweir sal_Bool ret = sal_False; 179cdf0e10cSrcweir do 180cdf0e10cSrcweir { 181cdf0e10cSrcweir typeName = tOption.getToken(0, ';', nIndex); 182cdf0e10cSrcweir 183cdf0e10cSrcweir sal_Int32 nPos = typeName.lastIndexOf( '.' ); 184cdf0e10cSrcweir tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); 185cdf0e10cSrcweir if (tmpName == "*") 186cdf0e10cSrcweir { 187cdf0e10cSrcweir // produce this type and his scope. 188cdf0e10cSrcweir if (typeName.equals("*")) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir tmpName = "/"; 191cdf0e10cSrcweir } else 192cdf0e10cSrcweir { 193cdf0e10cSrcweir tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); 194cdf0e10cSrcweir if (tmpName.getLength() == 0) 195cdf0e10cSrcweir tmpName = "/"; 196cdf0e10cSrcweir else 197cdf0e10cSrcweir tmpName.replace('.', '/'); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir // related to task #116780# the scope is recursively 200cdf0e10cSrcweir // generated. bFullScope = true 201cdf0e10cSrcweir ret = produceAllTypes( 202cdf0e10cSrcweir tmpName, typeMgr, generated, &options, sal_True); 203cdf0e10cSrcweir } else 204cdf0e10cSrcweir { 205cdf0e10cSrcweir // produce only this type 206cdf0e10cSrcweir ret = produceType( 207cdf0e10cSrcweir typeName.replace('.', '/'), typeMgr, generated, 208cdf0e10cSrcweir &options); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir if (!ret) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 214cdf0e10cSrcweir options.getProgramName().getStr(), 215cdf0e10cSrcweir OString("cannot dump Type '" + typeName + "'").getStr()); 216cdf0e10cSrcweir exit(99); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } while( nIndex != -1 ); 219cdf0e10cSrcweir } else 220cdf0e10cSrcweir { 221cdf0e10cSrcweir // produce all types 222cdf0e10cSrcweir codemaker::GeneratedTypeSet generated; 223cdf0e10cSrcweir if (!produceAllTypes("/", typeMgr, generated, &options, sal_True)) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 226cdf0e10cSrcweir options.getProgramName().getStr(), 227cdf0e10cSrcweir "an error occurs while dumping all types."); 228cdf0e10cSrcweir exit(99); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir } 232cdf0e10cSrcweir catch( CannotDumpException& e) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 235cdf0e10cSrcweir options.getProgramName().getStr(), 236cdf0e10cSrcweir e.m_message.getStr()); 237cdf0e10cSrcweir exit(99); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir return 0; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir 244