1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "sal/main.h" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <codemaker/typemanager.hxx> 36*cdf0e10cSrcweir #include <codemaker/dependency.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "cunooptions.hxx" 39*cdf0e10cSrcweir #include "cunotype.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace rtl; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir sal_Bool produceAllTypes(const OString& typeName, 44*cdf0e10cSrcweir TypeManager& typeMgr, 45*cdf0e10cSrcweir TypeDependency& typeDependencies, 46*cdf0e10cSrcweir CunoOptions* pOptions, 47*cdf0e10cSrcweir sal_Bool bFullScope) 48*cdf0e10cSrcweir throw( CannotDumpException ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir if (!produceType(typeName, typeMgr, typeDependencies, pOptions)) 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 53*cdf0e10cSrcweir pOptions->getProgramName().getStr(), 54*cdf0e10cSrcweir OString("cannot dump Type '" + typeName + "'").getStr()); 55*cdf0e10cSrcweir exit(99); 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir RegistryKey typeKey = typeMgr.getTypeKey(typeName); 59*cdf0e10cSrcweir RegistryKeyNames subKeys; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir if (typeKey.getKeyNames(OUString(), subKeys)) 62*cdf0e10cSrcweir return sal_False; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir OString tmpName; 65*cdf0e10cSrcweir for (sal_uInt32 i=0; i < subKeys.getLength(); i++) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir tmpName = OUStringToOString(subKeys.getElement(i), RTL_TEXTENCODING_UTF8); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir if (pOptions->isValid("-B")) 70*cdf0e10cSrcweir tmpName = tmpName.copy(tmpName.indexOf('/', 1) + 1); 71*cdf0e10cSrcweir else 72*cdf0e10cSrcweir tmpName = tmpName.copy(1); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir if (bFullScope) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if (!produceAllTypes(tmpName, typeMgr, typeDependencies, pOptions, sal_True)) 77*cdf0e10cSrcweir return sal_False; 78*cdf0e10cSrcweir } else 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir if (!produceType(tmpName, typeMgr, typeDependencies, pOptions)) 81*cdf0e10cSrcweir return sal_False; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir return sal_True; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir CunoOptions options; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir try 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir if (!options.initOptions(argc, argv)) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir exit(1); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir catch( IllegalArgument& e) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); 102*cdf0e10cSrcweir exit(99); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir RegistryTypeManager typeMgr; 106*cdf0e10cSrcweir TypeDependency typeDependencies; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if (!typeMgr.init(!options.isValid("-T"), options.getInputFiles())) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); 111*cdf0e10cSrcweir exit(99); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir if (options.isValid("-B")) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir typeMgr.setBase(options.getOption("-B")); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir try 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir if (options.isValid("-T")) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir OString tOption(options.getOption("-T")); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir OString typeName, tmpName; 126*cdf0e10cSrcweir sal_Bool ret = sal_False; 127*cdf0e10cSrcweir sal_Int32 nIndex = 0; 128*cdf0e10cSrcweir do 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir typeName = tOption.getToken(0, ';', nIndex); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir sal_Int32 nPos = typeName.lastIndexOf( '.' ); 133*cdf0e10cSrcweir tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); 134*cdf0e10cSrcweir if (tmpName == "*") 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir // produce this type and his scope, but the scope is not recursively generated. 137*cdf0e10cSrcweir if (typeName.equals("*")) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir tmpName = "/"; 140*cdf0e10cSrcweir } else 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); 143*cdf0e10cSrcweir if (tmpName.getLength() == 0) 144*cdf0e10cSrcweir tmpName = "/"; 145*cdf0e10cSrcweir else 146*cdf0e10cSrcweir tmpName.replace('.', '/'); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir ret = produceAllTypes(tmpName, typeMgr, typeDependencies, &options, sal_False); 149*cdf0e10cSrcweir } else 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir // produce only this type 152*cdf0e10cSrcweir ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, &options); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if (!ret) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 158*cdf0e10cSrcweir options.getProgramName().getStr(), 159*cdf0e10cSrcweir OString("cannot dump Type '" + typeName + "'").getStr()); 160*cdf0e10cSrcweir exit(99); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } while( nIndex != -1 ); 163*cdf0e10cSrcweir } else 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // produce all types 166*cdf0e10cSrcweir if (!produceAllTypes("/", typeMgr, typeDependencies, &options, sal_True)) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 169*cdf0e10cSrcweir options.getProgramName().getStr(), 170*cdf0e10cSrcweir "an error occurs while dumping all types."); 171*cdf0e10cSrcweir exit(99); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir catch( CannotDumpException& e) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir fprintf(stderr, "%s ERROR: %s\n", 178*cdf0e10cSrcweir options.getProgramName().getStr(), 179*cdf0e10cSrcweir e.m_message.getStr()); 180*cdf0e10cSrcweir exit(99); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir return 0; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir 187