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 #include <stdio.h>
25 #include	<rtl/alloc.h>
26 #include	<rtl/ustring.hxx>
27 #include	<rtl/strbuf.hxx>
28 
29 #include	"rdbtype.hxx"
30 #include	"rdboptions.hxx"
31 
32 using namespace rtl;
33 
isBaseType(const OString & type)34 sal_Bool isBaseType(const OString& type)
35 {
36 	if ( type.equals("long") ||
37  		 type.equals("short") ||
38  		 type.equals("hyper") ||
39  		 type.equals("string") ||
40  		 type.equals("boolean") ||
41  		 type.equals("char") ||
42  		 type.equals("byte") ||
43  		 type.equals("any") ||
44  		 type.equals("type") ||
45  		 type.equals("float") ||
46  		 type.equals("double") ||
47  		 type.equals("octet") ||
48  		 type.equals("void") ||
49  		 type.equals("unsigned long") ||
50  		 type.equals("unsigned short") ||
51  		 type.equals("unsigned hyper") )
52 		return sal_True;
53 
54 	return sal_False;
55 }
56 
produceDependedTypes(const OString & typeName,TypeManager & typeMgr,TypeDependency & typeDependencies,RdbOptions * pOptions,FileStream & o,RegistryKey & regKey,StringSet & filterTypes)57 sal_Bool produceDependedTypes(const OString& typeName,
58 							  TypeManager& typeMgr,
59 							  TypeDependency& typeDependencies,
60 							  RdbOptions* pOptions,
61 							  FileStream& o,
62 							  RegistryKey& regKey,
63 							  StringSet& filterTypes)
64 	throw( CannotDumpException )
65 {
66 	sal_Bool ret = sal_True;
67 
68 	TypeUsingSet usingSet(typeDependencies.getDependencies(typeName));
69 
70 	TypeUsingSet::const_iterator iter = usingSet.begin();
71 	OString sTypeName;
72 	sal_Int32 index = 0;
73 	while (iter != usingSet.end())
74 	{
75 		sTypeName = (*iter).m_type;
76 		if ((index = sTypeName.lastIndexOf(']')) > 0)
77 			sTypeName = sTypeName.copy(index + 1);
78 
79 		if ( !isBaseType(sTypeName) )
80 		{
81 			if (!produceType(sTypeName,
82 						   	 typeMgr,
83 							 typeDependencies,
84 							 pOptions,
85 							 o, regKey,
86 							 filterTypes,
87                              sal_True))
88 			{
89 				fprintf(stderr, "%s ERROR: %s\n",
90 						pOptions->getProgramName().getStr(),
91 						OString("cannot dump Type '" + sTypeName + "'").getStr());
92 				cleanUp(sal_True);
93 				exit(99);
94 			}
95 		}
96 		iter++;
97 	}
98 
99 	return ret;
100 }
101 
102 //*************************************************************************
103 // produceType
104 //*************************************************************************
produceType(const OString & typeName,TypeManager & typeMgr,TypeDependency & typeDependencies,RdbOptions * pOptions,FileStream & o,RegistryKey & regKey,StringSet & filterTypes,sal_Bool bDepend)105 sal_Bool produceType(const OString& typeName,
106 					 TypeManager& typeMgr,
107 					 TypeDependency& typeDependencies,
108 					 RdbOptions* pOptions,
109 					 FileStream& o,
110 					 RegistryKey& regKey,
111 					 StringSet& filterTypes,
112                      sal_Bool bDepend)
113 	throw( CannotDumpException )
114 {
115 	if (typeDependencies.isGenerated(typeName) )
116 		return sal_True;
117 /*
118 	RegistryKey		typeKey = typeMgr.getTypeKey(typeName);
119 
120 	if (!typeKey.isValid())
121 		return sal_False;
122 */
123 	if( !checkTypeDependencies(typeMgr, typeDependencies, typeName, bDepend))
124 		return sal_False;
125 
126 	if ( !checkFilterTypes(typeName) )
127 	{
128 		if ( pOptions->generateTypeList() )
129 		{
130 			o << typeName.getStr() << "\n";
131 		} else
132 		{
133 /*
134 			RegValueType 	valueType;
135 			sal_uInt32		valueSize;
136 
137 			if (typeKey.getValueInfo(OUString(), &valueType, &valueSize))
138 			{
139 				if (typeName.equals("/"))
140 					return sal_True;
141 				else
142 					return sal_False;
143 			}
144 
145 			sal_uInt8* pBuffer = (sal_uInt8*)rtl_allocateMemory(valueSize);
146 
147 			if (typeKey.getValue(OUString(), pBuffer))
148 			{
149 				rtl_freeMemory(pBuffer);
150 				return sal_False;
151 			}
152 */
153 			TypeReader reader = typeMgr.getTypeReader(typeName);
154 
155 			if (!reader.isValid())
156 			{
157 				if (typeName.equals("/"))
158 				{
159 					return sal_True;
160 				} else
161 				{
162 					return sal_False;
163 				}
164 			}
165 			RegistryKey typeKey;
166 			if ( regKey.createKey( OStringToOUString(typeName, RTL_TEXTENCODING_UTF8), typeKey) )
167 			{
168 //				rtl_freeMemory(pBuffer);
169 				return sal_False;
170 			}
171 
172 			if ( typeKey.setValue(OUString(), RG_VALUETYPE_BINARY, (void*)reader.getBlop(), reader.getBlopSize()) )
173 //			if ( typeKey.setValue(OUString(), valueType, pBuffer, valueSize) )
174 			{
175 //				rtl_freeMemory(pBuffer);
176 				return sal_False;
177 			}
178 
179 //			rtl_freeMemory(pBuffer);
180 		}
181 	}
182 
183 	typeDependencies.setGenerated(typeName);
184 	sal_Bool ret = produceDependedTypes(typeName, typeMgr, typeDependencies,
185 										pOptions, o, regKey, filterTypes);
186 
187 	return ret;
188 }
189 
190 
191 
192