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.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: corbamaker.cxx,v $
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"
39 #include <codemaker/typemanager.hxx>
40 #include <codemaker/dependency.hxx>
42 #include "corbaoptions.hxx"
43 #include "corbatype.hxx"
47 sal_Bool
produceAllTypes(const OString
& typeName
,
49 TypeDependency
& typeDependencies
,
50 CorbaOptions
* pOptions
,
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());
66 RegistryKey typeKey
= typeMgr
.getTypeKey(typeName
);
67 RegistryKeyNames subKeys
;
69 if (typeKey
.getKeyNames(OUString(), subKeys
))
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);
80 tmpName
= tmpName
.copy(1);
84 if (!produceAllTypes(tmpName
, typeMgr
, typeDependencies
, pOptions
, sal_True
, o
, pAllreadyDumped
, generatedConversion
))
88 if (!produceType(tmpName
, typeMgr
, typeDependencies
, pOptions
, o
, pAllreadyDumped
, generatedConversion
))
96 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
102 if (!options
.initOptions(argc
, argv
))
107 catch( IllegalArgument
& e
)
109 fprintf(stderr
, "Illegal option: %s\n", e
.m_message
.getStr());
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());
122 if (options
.isValid("-B"))
124 typeMgr
.setBase(options
.getOption("-B"));
129 TypeSet generatedConversion
;
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 <"
152 CorbaType::dumpDefaultHxxIncludes(cppFile
);
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 );
171 // produce this type and his scope, but the scope is not recursively generated.
172 if (typeName
.equals("*"))
177 tmpName
= typeName
.copy(0, typeName
.lastIndexOf('.')).replace('.', '/');
178 if (tmpName
.getLength() == 0)
181 tmpName
.replace('.', '/');
183 ret
= produceAllTypes(tmpName
, typeMgr
, typeDependencies
, &options
, sal_False
, cppFile
, NULL
, &generatedConversion
);
186 // produce only this type
187 ret
= produceType(typeName
.replace('.', '/'), typeMgr
, typeDependencies
, &options
, cppFile
, NULL
, &generatedConversion
);
192 fprintf(stderr
, "%s ERROR: %s\n",
193 options
.getProgramName().getStr(),
194 OString("cannot dump Type '" + typeName
+ "'").getStr());
197 } while( nIndex
!= -1 );
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.");
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()
224 cppFile
<< " {NULL, NULL, 0 , NULL, NULL} };\n"
225 << " return allFunctions;\n"
227 << "}; // namespace bonobobridge\n";
231 catch( CannotDumpException
& e
)
233 fprintf(stderr
, "%s ERROR: %s\n",
234 options
.getProgramName().getStr(),
235 e
.m_message
.getStr());