merge the formfield patch from ooo-build
[ooovba.git] / xml2cmp / source / xcd / main.cxx
blob6d360d380143ca0e0583b0fbc7073a094b5eaf6c
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: main.cxx,v $
10 * $Revision: 1.12 $
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 #include <iostream>
32 #include <fstream>
33 #include <stdio.h>
36 #include <string.h>
37 #include "../support/cmdline.hxx"
38 #include "cr_metho.hxx"
39 #include "cr_html.hxx"
40 #include "cr_index.hxx"
41 #include "xmlelem.hxx"
42 #include "xmltree.hxx"
43 #include "parse.hxx"
44 #include "../support/syshelp.hxx"
45 #include "../support/heap.hxx"
49 int Do_IndexCommandLine(
50 const CommandLine & i_rCommandLine );
51 int Do_SingleFileCommandLine(
52 const CommandLine & i_rCommandLine );
53 void Create_TypeInfo(
54 const char * o_sOutputFile,
55 ModuleDescription & i_rData );
58 int
59 #ifdef WNT
60 _cdecl
61 #endif
62 main( int argc,
63 char * argv[] )
65 // Variables
66 CommandLine aCommandLine(argc, argv);
67 int ret = 0;
69 if (! aCommandLine.IsOk())
71 std::cerr << aCommandLine.ErrorText() << std::endl ;
72 return 1;
75 if ( aCommandLine.IsIndexCommand() )
76 ret = Do_IndexCommandLine(aCommandLine);
77 else
78 ret = Do_SingleFileCommandLine(aCommandLine);
80 return ret;
84 int
85 Do_SingleFileCommandLine(const CommandLine & i_rCommandLine)
87 ModuleDescription aDescr;
88 X2CParser aParser(aDescr);
90 // Load file and create Function-file
91 bool bLoadResult = aParser.LoadFile(i_rCommandLine.XmlSrcFile());
92 if (! bLoadResult)
94 std::cerr << "Error: File %s could not be loaded." << i_rCommandLine.XmlSrcFile() << std::endl;
95 return 1;
98 if ( strlen(i_rCommandLine.FuncFile()) > 0 )
100 Create_AccessMethod( i_rCommandLine.FuncFile(),
101 aParser.PureText() );
103 std::cout << "File "
104 << i_rCommandLine.FuncFile()
105 << " with component_getDescriptionFunc() is created now."
106 << std::endl;
109 // Parse
110 aParser.Parse();
112 // Produce output
113 if ( strlen(i_rCommandLine.HtmlFile()) > 0 )
115 HtmlCreator aHtmlCreator( i_rCommandLine.HtmlFile(),
116 aDescr,
117 i_rCommandLine.IdlRootPath() );
118 aHtmlCreator.Run();
121 if (strlen(i_rCommandLine.TypeInfoFile()) > 0)
123 Create_TypeInfo( i_rCommandLine.TypeInfoFile(),
124 aDescr );
127 return 0;
131 Do_IndexCommandLine(const CommandLine & i_rCommandLine)
133 // Parsen files:
134 List<Simstr> aFiles;
135 Index aIndex( i_rCommandLine.OutputDirectory(),
136 i_rCommandLine.IdlRootPath(),
137 i_rCommandLine.IndexedTags() );
139 std::cout << "Gather xml-files ..." << std::endl;
140 GatherFileNames( aFiles, i_rCommandLine.XmlSrcDirectory() );
142 std::cout << "Create output ..." << std::endl;
143 aIndex.GatherData(aFiles);
144 aIndex.WriteOutput( i_rCommandLine.IndexOutputFile() );
146 std::cout << "... done." << std::endl;
148 return 0;
153 //******************** Creating of typeinfo ********************//
156 void Put2StdOut_TypeInfo(
157 ModuleDescription & i_rData );
158 void Put2File_TypeInfo(
159 const char * i_sOutputFile,
160 ModuleDescription & i_rData );
161 void StreamOut_TypeInfo(
162 std::ostream & o_rOut,
163 ModuleDescription & i_rData,
164 const char * i_sSeparator );
169 void
170 Create_TypeInfo( const char * o_sOutputFile,
171 ModuleDescription & i_rData )
173 if ( strcmp(o_sOutputFile, "stdout") == 0 )
174 Put2StdOut_TypeInfo(i_rData);
175 else
176 Put2File_TypeInfo(o_sOutputFile,i_rData);
178 #if 0
179 std::ofstream aOut(o_sOutputFile, std::ios::out
180 #if defined(WNT) || defined(OS2)
181 | std::ios::binary
182 #endif
184 if ( !aOut )
186 std::cerr << "Error: " << o_sOutputFile << " could not be created." << std::endl;
187 return;
190 Heap aTypesHeap(12);
191 Simstr sLibPrefix = i_rData.ModuleName();
193 // Gather types:
194 List< const MultipleTextElement * > aTypes;
195 i_rData.Get_Types(aTypes);
197 for ( unsigned t = 0; t < aTypes.size(); ++t )
199 unsigned i_max = aTypes[t]->Size();
200 for ( unsigned i = 0; i < i_max; ++i )
202 aTypesHeap.InsertValue( aTypes[t]->Data(i), "" );
203 } // end for
206 // Write types:
207 WriteStr( aOut, sLibPrefix );
208 WriteStr( aOut, "_XML2CMPTYPES= ");
210 HeapItem * pLastHeapTop = 0;
211 for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() )
213 if (pLastHeapTop != 0)
215 if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) )
216 continue;
217 delete pLastHeapTop;
218 // pLastHeapTop = 0;
220 pLastHeapTop = pHeapTop;
222 WriteStr( aOut, "\t\\\n\t\t" );
224 const char * sEnd = strchr( pHeapTop->Key(), ' ' );
225 if (sEnd != 0)
227 const char * sQuali = strrchr( pHeapTop->Key(), ' ' )+1;
228 WriteStr( aOut, sQuali );
229 WriteStr( aOut, "." );
230 aOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() );
232 else
233 WriteStr( aOut, pHeapTop->Key() );
234 } // end for
236 if (pLastHeapTop != 0)
238 delete pLastHeapTop;
239 pLastHeapTop = 0;
242 aOut.close();
243 #endif // 0
246 void
247 Put2StdOut_TypeInfo( ModuleDescription & i_rData )
249 StreamOut_TypeInfo(std::cout, i_rData, " ");
252 void
253 Put2File_TypeInfo( const char * i_sOutputFile,
254 ModuleDescription & i_rData )
256 std::ofstream aOut(i_sOutputFile, std::ios::out
257 #if defined(WNT) || defined(OS2)
258 | std::ios::binary
259 #endif
261 if ( !aOut )
263 std::cerr << "Error: " << i_sOutputFile << " could not be created." << std::endl;
264 return;
267 Simstr sLibPrefix = i_rData.ModuleName();
268 WriteStr( aOut, sLibPrefix );
269 WriteStr( aOut, "_XML2CMPTYPES= ");
271 StreamOut_TypeInfo(aOut, i_rData, "\t\\\n\t\t");
273 aOut.close();
276 void
277 StreamOut_TypeInfo( std::ostream & o_rOut,
278 ModuleDescription & i_rData,
279 const char * i_sSeparator )
281 Heap aTypesHeap(12);
283 // Gather types:
284 List< const MultipleTextElement * > aTypes;
285 i_rData.Get_Types(aTypes);
287 for ( unsigned t = 0; t < aTypes.size(); ++t )
289 unsigned i_max = aTypes[t]->Size();
290 for ( unsigned i = 0; i < i_max; ++i )
292 aTypesHeap.InsertValue( aTypes[t]->Data(i), "" );
293 } // end for
296 // Write types:
297 HeapItem * pLastHeapTop = 0;
298 for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() )
300 if (pLastHeapTop != 0)
302 if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) )
303 continue;
304 delete pLastHeapTop;
305 // pLastHeapTop = 0;
307 pLastHeapTop = pHeapTop;
309 WriteStr( o_rOut, i_sSeparator );
311 const char * sEnd = strchr( pHeapTop->Key(), ' ' );
312 if (sEnd != 0)
314 const char * sQuali = strrchr( pHeapTop->Key(), ' ' ) + 1;
315 WriteStr( o_rOut, sQuali );
316 WriteStr( o_rOut, "." );
317 o_rOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() );
319 else
320 WriteStr( o_rOut, pHeapTop->Key() );
321 } // end for
323 if (pLastHeapTop != 0)
325 delete pLastHeapTop;
326 pLastHeapTop = 0;