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/dependency.hxx> 37 38 #include "cunooptions.hxx" 39 #include "cunotype.hxx" 40 41 using namespace rtl; 42 43 sal_Bool produceAllTypes(const OString& typeName, 44 TypeManager& typeMgr, 45 TypeDependency& typeDependencies, 46 CunoOptions* pOptions, 47 sal_Bool bFullScope) 48 throw( CannotDumpException ) 49 { 50 if (!produceType(typeName, typeMgr, typeDependencies, pOptions)) 51 { 52 fprintf(stderr, "%s ERROR: %s\n", 53 pOptions->getProgramName().getStr(), 54 OString("cannot dump Type '" + typeName + "'").getStr()); 55 exit(99); 56 } 57 58 RegistryKey typeKey = typeMgr.getTypeKey(typeName); 59 RegistryKeyNames subKeys; 60 61 if (typeKey.getKeyNames(OUString(), subKeys)) 62 return sal_False; 63 64 OString tmpName; 65 for (sal_uInt32 i=0; i < subKeys.getLength(); i++) 66 { 67 tmpName = OUStringToOString(subKeys.getElement(i), RTL_TEXTENCODING_UTF8); 68 69 if (pOptions->isValid("-B")) 70 tmpName = tmpName.copy(tmpName.indexOf('/', 1) + 1); 71 else 72 tmpName = tmpName.copy(1); 73 74 if (bFullScope) 75 { 76 if (!produceAllTypes(tmpName, typeMgr, typeDependencies, pOptions, sal_True)) 77 return sal_False; 78 } else 79 { 80 if (!produceType(tmpName, typeMgr, typeDependencies, pOptions)) 81 return sal_False; 82 } 83 } 84 85 return sal_True; 86 } 87 88 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) 89 { 90 CunoOptions options; 91 92 try 93 { 94 if (!options.initOptions(argc, argv)) 95 { 96 exit(1); 97 } 98 } 99 catch( IllegalArgument& e) 100 { 101 fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr()); 102 exit(99); 103 } 104 105 RegistryTypeManager typeMgr; 106 TypeDependency typeDependencies; 107 108 if (!typeMgr.init(!options.isValid("-T"), options.getInputFiles())) 109 { 110 fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr()); 111 exit(99); 112 } 113 114 if (options.isValid("-B")) 115 { 116 typeMgr.setBase(options.getOption("-B")); 117 } 118 119 try 120 { 121 if (options.isValid("-T")) 122 { 123 OString tOption(options.getOption("-T")); 124 125 OString typeName, tmpName; 126 sal_Bool ret = sal_False; 127 sal_Int32 nIndex = 0; 128 do 129 { 130 typeName = tOption.getToken(0, ';', nIndex); 131 132 sal_Int32 nPos = typeName.lastIndexOf( '.' ); 133 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 ); 134 if (tmpName == "*") 135 { 136 // produce this type and his scope, but the scope is not recursively generated. 137 if (typeName.equals("*")) 138 { 139 tmpName = "/"; 140 } else 141 { 142 tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/'); 143 if (tmpName.getLength() == 0) 144 tmpName = "/"; 145 else 146 tmpName.replace('.', '/'); 147 } 148 ret = produceAllTypes(tmpName, typeMgr, typeDependencies, &options, sal_False); 149 } else 150 { 151 // produce only this type 152 ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, &options); 153 } 154 155 if (!ret) 156 { 157 fprintf(stderr, "%s ERROR: %s\n", 158 options.getProgramName().getStr(), 159 OString("cannot dump Type '" + typeName + "'").getStr()); 160 exit(99); 161 } 162 } while( nIndex != -1 ); 163 } else 164 { 165 // produce all types 166 if (!produceAllTypes("/", typeMgr, typeDependencies, &options, sal_True)) 167 { 168 fprintf(stderr, "%s ERROR: %s\n", 169 options.getProgramName().getStr(), 170 "an error occurs while dumping all types."); 171 exit(99); 172 } 173 } 174 } 175 catch( CannotDumpException& e) 176 { 177 fprintf(stderr, "%s ERROR: %s\n", 178 options.getProgramName().getStr(), 179 e.m_message.getStr()); 180 exit(99); 181 } 182 183 return 0; 184 } 185 186 187