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