1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: main.cxx,v $
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 ************************************************************************/
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"
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
);
54 const char * o_sOutputFile
,
55 ModuleDescription
& i_rData
);
66 CommandLine
aCommandLine(argc
, argv
);
69 if (! aCommandLine
.IsOk())
71 std::cerr
<< aCommandLine
.ErrorText() << std::endl
;
75 if ( aCommandLine
.IsIndexCommand() )
76 ret
= Do_IndexCommandLine(aCommandLine
);
78 ret
= Do_SingleFileCommandLine(aCommandLine
);
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());
94 std::cerr
<< "Error: File %s could not be loaded." << i_rCommandLine
.XmlSrcFile() << std::endl
;
98 if ( strlen(i_rCommandLine
.FuncFile()) > 0 )
100 Create_AccessMethod( i_rCommandLine
.FuncFile(),
101 aParser
.PureText() );
104 << i_rCommandLine
.FuncFile()
105 << " with component_getDescriptionFunc() is created now."
113 if ( strlen(i_rCommandLine
.HtmlFile()) > 0 )
115 HtmlCreator
aHtmlCreator( i_rCommandLine
.HtmlFile(),
117 i_rCommandLine
.IdlRootPath() );
121 if (strlen(i_rCommandLine
.TypeInfoFile()) > 0)
123 Create_TypeInfo( i_rCommandLine
.TypeInfoFile(),
131 Do_IndexCommandLine(const CommandLine
& i_rCommandLine
)
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
;
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
);
170 Create_TypeInfo( const char * o_sOutputFile
,
171 ModuleDescription
& i_rData
)
173 if ( strcmp(o_sOutputFile
, "stdout") == 0 )
174 Put2StdOut_TypeInfo(i_rData
);
176 Put2File_TypeInfo(o_sOutputFile
,i_rData
);
179 std::ofstream
aOut(o_sOutputFile
, std::ios::out
180 #if defined(WNT) || defined(OS2)
186 std::cerr
<< "Error: " << o_sOutputFile
<< " could not be created." << std::endl
;
191 Simstr sLibPrefix
= i_rData
.ModuleName();
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
), "" );
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()) )
220 pLastHeapTop
= pHeapTop
;
222 WriteStr( aOut
, "\t\\\n\t\t" );
224 const char * sEnd
= strchr( pHeapTop
->Key(), ' ' );
227 const char * sQuali
= strrchr( pHeapTop
->Key(), ' ' )+1;
228 WriteStr( aOut
, sQuali
);
229 WriteStr( aOut
, "." );
230 aOut
.write( pHeapTop
->Key(), sEnd
- pHeapTop
->Key() );
233 WriteStr( aOut
, pHeapTop
->Key() );
236 if (pLastHeapTop
!= 0)
247 Put2StdOut_TypeInfo( ModuleDescription
& i_rData
)
249 StreamOut_TypeInfo(std::cout
, i_rData
, " ");
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)
263 std::cerr
<< "Error: " << i_sOutputFile
<< " could not be created." << std::endl
;
267 Simstr sLibPrefix
= i_rData
.ModuleName();
268 WriteStr( aOut
, sLibPrefix
);
269 WriteStr( aOut
, "_XML2CMPTYPES= ");
271 StreamOut_TypeInfo(aOut
, i_rData
, "\t\\\n\t\t");
277 StreamOut_TypeInfo( std::ostream
& o_rOut
,
278 ModuleDescription
& i_rData
,
279 const char * i_sSeparator
)
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
), "" );
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()) )
307 pLastHeapTop
= pHeapTop
;
309 WriteStr( o_rOut
, i_sSeparator
);
311 const char * sEnd
= strchr( pHeapTop
->Key(), ' ' );
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() );
320 WriteStr( o_rOut
, pHeapTop
->Key() );
323 if (pLastHeapTop
!= 0)