update dev300-m58
[ooovba.git] / codemaker / source / cunomaker / cunomaker.cxx
blob9833b1aa8961461b3402f4e64e7a6fa24584e539
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cunomaker.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
34 #include <stdio.h>
36 #include "sal/main.h"
38 #include <codemaker/typemanager.hxx>
39 #include <codemaker/dependency.hxx>
41 #include "cunooptions.hxx"
42 #include "cunotype.hxx"
44 using namespace rtl;
46 sal_Bool produceAllTypes(const OString& typeName,
47 TypeManager& typeMgr,
48 TypeDependency& typeDependencies,
49 CunoOptions* pOptions,
50 sal_Bool bFullScope)
51 throw( CannotDumpException )
53 if (!produceType(typeName, typeMgr, typeDependencies, pOptions))
55 fprintf(stderr, "%s ERROR: %s\n",
56 pOptions->getProgramName().getStr(),
57 OString("cannot dump Type '" + typeName + "'").getStr());
58 exit(99);
61 RegistryKey typeKey = typeMgr.getTypeKey(typeName);
62 RegistryKeyNames subKeys;
64 if (typeKey.getKeyNames(OUString(), subKeys))
65 return sal_False;
67 OString tmpName;
68 for (sal_uInt32 i=0; i < subKeys.getLength(); i++)
70 tmpName = OUStringToOString(subKeys.getElement(i), RTL_TEXTENCODING_UTF8);
72 if (pOptions->isValid("-B"))
73 tmpName = tmpName.copy(tmpName.indexOf('/', 1) + 1);
74 else
75 tmpName = tmpName.copy(1);
77 if (bFullScope)
79 if (!produceAllTypes(tmpName, typeMgr, typeDependencies, pOptions, sal_True))
80 return sal_False;
81 } else
83 if (!produceType(tmpName, typeMgr, typeDependencies, pOptions))
84 return sal_False;
88 return sal_True;
91 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
93 CunoOptions options;
95 try
97 if (!options.initOptions(argc, argv))
99 exit(1);
102 catch( IllegalArgument& e)
104 fprintf(stderr, "Illegal option: %s\n", e.m_message.getStr());
105 exit(99);
108 RegistryTypeManager typeMgr;
109 TypeDependency typeDependencies;
111 if (!typeMgr.init(!options.isValid("-T"), options.getInputFiles()))
113 fprintf(stderr, "%s : init registries failed, check your registry files.\n", options.getProgramName().getStr());
114 exit(99);
117 if (options.isValid("-B"))
119 typeMgr.setBase(options.getOption("-B"));
122 try
124 if (options.isValid("-T"))
126 OString tOption(options.getOption("-T"));
128 OString typeName, tmpName;
129 sal_Bool ret = sal_False;
130 sal_Int32 nIndex = 0;
133 typeName = tOption.getToken(0, ';', nIndex);
135 sal_Int32 nPos = typeName.lastIndexOf( '.' );
136 tmpName = typeName.copy( nPos != -1 ? nPos+1 : 0 );
137 if (tmpName == "*")
139 // produce this type and his scope, but the scope is not recursively generated.
140 if (typeName.equals("*"))
142 tmpName = "/";
143 } else
145 tmpName = typeName.copy(0, typeName.lastIndexOf('.')).replace('.', '/');
146 if (tmpName.getLength() == 0)
147 tmpName = "/";
148 else
149 tmpName.replace('.', '/');
151 ret = produceAllTypes(tmpName, typeMgr, typeDependencies, &options, sal_False);
152 } else
154 // produce only this type
155 ret = produceType(typeName.replace('.', '/'), typeMgr, typeDependencies, &options);
158 if (!ret)
160 fprintf(stderr, "%s ERROR: %s\n",
161 options.getProgramName().getStr(),
162 OString("cannot dump Type '" + typeName + "'").getStr());
163 exit(99);
165 } while( nIndex != -1 );
166 } else
168 // produce all types
169 if (!produceAllTypes("/", typeMgr, typeDependencies, &options, sal_True))
171 fprintf(stderr, "%s ERROR: %s\n",
172 options.getProgramName().getStr(),
173 "an error occurs while dumping all types.");
174 exit(99);
178 catch( CannotDumpException& e)
180 fprintf(stderr, "%s ERROR: %s\n",
181 options.getProgramName().getStr(),
182 e.m_message.getStr());
183 exit(99);
186 return 0;