update dev300-m58
[ooovba.git] / codemaker / source / bonobowrappermaker / corbamaker.cxx
blob7c7c20a5c496e0e9f4f51f1fac903c737d32aa81
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: corbamaker.cxx,v $
11 * $Revision: 1.7 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_codemaker.hxx"
35 #include <stdio.h>
37 #include "sal/main.h"
39 #include <codemaker/typemanager.hxx>
40 #include <codemaker/dependency.hxx>
42 #include "corbaoptions.hxx"
43 #include "corbatype.hxx"
45 using namespace rtl;
47 sal_Bool produceAllTypes(const OString& typeName,
48 TypeManager& typeMgr,
49 TypeDependency& typeDependencies,
50 CorbaOptions* pOptions,
51 sal_Bool bFullScope,
52 FileStream& o,
53 TypeSet* pAllreadyDumped,
54 TypeSet* generatedConversion)
56 throw( CannotDumpException )
58 if (!produceType(typeName, typeMgr, typeDependencies, pOptions, o, pAllreadyDumped, generatedConversion))
60 fprintf(stderr, "%s ERROR: %s\n",
61 pOptions->getProgramName().getStr(),
62 OString("cannot dump Type '" + typeName + "'").getStr());
63 exit(99);
66 RegistryKey typeKey = typeMgr.getTypeKey(typeName);
67 RegistryKeyNames subKeys;
69 if (typeKey.getKeyNames(OUString(), subKeys))
70 return sal_False;
72 OString tmpName;
73 for (sal_uInt32 i=0; i < subKeys.getLength(); i++)
75 tmpName = OUStringToOString(subKeys.getElement(i), RTL_TEXTENCODING_UTF8);
77 if (pOptions->isValid("-B"))
78 tmpName = tmpName.copy(tmpName.indexOf('/', 1) + 1);
79 else
80 tmpName = tmpName.copy(1);
82 if (bFullScope)
84 if (!produceAllTypes(tmpName, typeMgr, typeDependencies, pOptions, sal_True, o, pAllreadyDumped, generatedConversion))
85 return sal_False;
86 } else
88 if (!produceType(tmpName, typeMgr, typeDependencies, pOptions, o, pAllreadyDumped, generatedConversion))
89 return sal_False;
93 return sal_True;
96 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
98 CorbaOptions options;
100 try
102 if (!options.initOptions(argc, argv))
104 exit(1);
107 catch( IllegalArgument& e)
109 fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
110 exit(99);
113 RegistryTypeManager typeMgr;
114 TypeDependency typeDependencies;
116 if (!typeMgr.init(!options.isValid("-T"), options.getInputFiles()))
118 fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr());
119 exit(99);
122 if (options.isValid("-B"))
124 typeMgr.setBase(options.getOption("-B"));
127 try
129 TypeSet generatedConversion;
130 FileStream cppFile;
131 OString outPath;
132 if (options.isValid("-O"))
133 outPath = options.getOption("-O");
135 cppFile.open(outPath);
137 if(!cppFile.isValid())
139 OString message("cannot open ");
140 message += outPath + " for writing";
141 throw CannotDumpException(message);
144 if (options.isValid("-H"))
146 OString corbaHeader = options.getOption("-H");
148 cppFile << "#include <"
149 << corbaHeader
150 << ">\n\n";
152 CorbaType::dumpDefaultHxxIncludes(cppFile);
153 cppFile << "\n";
156 if (options.isValid("-T"))
158 OString tOption(options.getOption("-T"));
160 OString typeName, tmpName;
161 sal_Bool ret = sal_False;
162 sal_Int32 nIndex = 0;
165 typeName = tOption.getToken(0, ';', nIndex);
167 sal_Int32 nPos = typeName.lastIndexOf( '.' );
168 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 );
169 if (tmpName == "*")
171 // produce this type and his scope, but the scope is not recursively generated.
172 if (typeName.equals("*"))
174 tmpName = "/";
175 } else
177 tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
178 if (tmpName.getLength() == 0)
179 tmpName = "/";
180 else
181 tmpName.replace('.', '/');
183 ret = produceAllTypes(tmpName, typeMgr, typeDependencies, &options, sal_False, cppFile, NULL, &generatedConversion);
184 } else
186 // produce only this type
187 ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, &options, cppFile, NULL, &generatedConversion);
190 if (!ret)
192 fprintf(stderr, "%s ERROR: %s\n",
193 options.getProgramName().getStr(),
194 OString("cannot dump Type '" + typeName + "'").getStr());
195 exit(99);
197 } while( nIndex != -1 );
198 } else
200 // produce all types
201 if (!produceAllTypes("/", typeMgr, typeDependencies, &options, sal_True, cppFile, NULL, &generatedConversion))
203 fprintf(stderr, "%s ERROR: %s\n",
204 options.getProgramName().getStr(),
205 "an error occurs while dumping all types.");
206 exit(99);
210 cppFile << "namespace bonobobridge {\n"
211 << "const ConversionInfo* get_conversion_functions() {\n"
212 << " static ConversionInfo allFunctions[" << generatedConversion.size()+1<< "] = {\n";
214 for (TypeSet::iterator iter = generatedConversion.begin(); iter != generatedConversion.end(); iter++)
216 cppFile << " {\"" << (*iter).getStr() << "\""
217 << ", &TC_" << (*iter).replace('/','_').getStr() << "_struct"
218 << ", sizeof(" << (*iter).replace('/','_').getStr() << ")"
219 << ", convert_b2u_" << (*iter).replace('/','_').getStr()
220 << ", convert_u2b_" << (*iter).replace('/','_').getStr()
221 << " },\n";
224 cppFile << " {NULL, NULL, 0 , NULL, NULL} };\n"
225 << " return allFunctions;\n"
226 << "}\n"
227 << "}; // namespace bonobobridge\n";
229 cppFile.close();
231 catch( CannotDumpException& e)
233 fprintf(stderr, "%s ERROR: %s\n",
234 options.getProgramName().getStr(),
235 e.m_message.getStr());
236 exit(99);
239 return 0;