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