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