1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <iostream> 29 #include <fstream> 30 #include <stdio.h> 31 32 33 #include <string.h> 34 #include "../support/cmdline.hxx" 35 #include "cr_metho.hxx" 36 #include "cr_html.hxx" 37 #include "cr_index.hxx" 38 #include "xmlelem.hxx" 39 #include "xmltree.hxx" 40 #include "parse.hxx" 41 #include "../support/syshelp.hxx" 42 #include "../support/heap.hxx" 43 44 45 46 int Do_IndexCommandLine( 47 const CommandLine & i_rCommandLine ); 48 int Do_SingleFileCommandLine( 49 const CommandLine & i_rCommandLine ); 50 void Create_TypeInfo( 51 const char * o_sOutputFile, 52 ModuleDescription & i_rData ); 53 54 55 int 56 #ifdef WNT 57 _cdecl 58 #endif 59 main( int argc, 60 char * argv[] ) 61 { 62 // Variables 63 CommandLine aCommandLine(argc, argv); 64 int ret = 0; 65 66 if (! aCommandLine.IsOk()) 67 { 68 std::cerr << aCommandLine.ErrorText() << std::endl ; 69 return 1; 70 } 71 72 if ( aCommandLine.IsIndexCommand() ) 73 ret = Do_IndexCommandLine(aCommandLine); 74 else 75 ret = Do_SingleFileCommandLine(aCommandLine); 76 77 return ret; 78 } 79 80 81 int 82 Do_SingleFileCommandLine(const CommandLine & i_rCommandLine) 83 { 84 ModuleDescription aDescr; 85 X2CParser aParser(aDescr); 86 87 // Load file and create Function-file 88 bool bLoadResult = aParser.LoadFile(i_rCommandLine.XmlSrcFile()); 89 if (! bLoadResult) 90 { 91 std::cerr << "Error: File " << i_rCommandLine.XmlSrcFile() << " could not be loaded." << std::endl; 92 return 1; 93 } 94 95 if ( strlen(i_rCommandLine.FuncFile()) > 0 ) 96 { 97 Create_AccessMethod( i_rCommandLine.FuncFile(), 98 aParser.PureText() ); 99 100 std::cout << "File " 101 << i_rCommandLine.FuncFile() 102 << " with component_getDescriptionFunc() is created now." 103 << std::endl; 104 } 105 106 // Parse 107 aParser.Parse(); 108 109 // Produce output 110 if ( strlen(i_rCommandLine.HtmlFile()) > 0 ) 111 { 112 HtmlCreator aHtmlCreator( i_rCommandLine.HtmlFile(), 113 aDescr, 114 i_rCommandLine.IdlRootPath() ); 115 aHtmlCreator.Run(); 116 } 117 118 if (strlen(i_rCommandLine.TypeInfoFile()) > 0) 119 { 120 Create_TypeInfo( i_rCommandLine.TypeInfoFile(), 121 aDescr ); 122 } 123 124 return 0; 125 }; 126 127 int 128 Do_IndexCommandLine(const CommandLine & i_rCommandLine) 129 { 130 // Parsen files: 131 List<Simstr> aFiles; 132 Index aIndex( i_rCommandLine.OutputDirectory(), 133 i_rCommandLine.IdlRootPath(), 134 i_rCommandLine.IndexedTags() ); 135 136 std::cout << "Gather xml-files ..." << std::endl; 137 GatherFileNames( aFiles, i_rCommandLine.XmlSrcDirectory() ); 138 139 std::cout << "Create output ..." << std::endl; 140 aIndex.GatherData(aFiles); 141 aIndex.WriteOutput( i_rCommandLine.IndexOutputFile() ); 142 143 std::cout << "... done." << std::endl; 144 145 return 0; 146 }; 147 148 149 150 //******************** Creating of typeinfo ********************// 151 152 153 void Put2StdOut_TypeInfo( 154 ModuleDescription & i_rData ); 155 void Put2File_TypeInfo( 156 const char * i_sOutputFile, 157 ModuleDescription & i_rData ); 158 void StreamOut_TypeInfo( 159 std::ostream & o_rOut, 160 ModuleDescription & i_rData, 161 const char * i_sSeparator ); 162 163 164 165 166 void 167 Create_TypeInfo( const char * o_sOutputFile, 168 ModuleDescription & i_rData ) 169 { 170 if ( strcmp(o_sOutputFile, "stdout") == 0 ) 171 Put2StdOut_TypeInfo(i_rData); 172 else 173 Put2File_TypeInfo(o_sOutputFile,i_rData); 174 175 #if 0 176 std::ofstream aOut(o_sOutputFile, std::ios::out 177 #if defined(WNT) || defined(OS2) 178 | std::ios::binary 179 #endif 180 ); 181 if ( !aOut ) 182 { 183 std::cerr << "Error: " << o_sOutputFile << " could not be created." << std::endl; 184 return; 185 } 186 187 Heap aTypesHeap(12); 188 Simstr sLibPrefix = i_rData.ModuleName(); 189 190 // Gather types: 191 List< const MultipleTextElement * > aTypes; 192 i_rData.Get_Types(aTypes); 193 194 for ( unsigned t = 0; t < aTypes.size(); ++t ) 195 { 196 unsigned i_max = aTypes[t]->Size(); 197 for ( unsigned i = 0; i < i_max; ++i ) 198 { 199 aTypesHeap.InsertValue( aTypes[t]->Data(i), "" ); 200 } // end for 201 } 202 203 // Write types: 204 WriteStr( aOut, sLibPrefix ); 205 WriteStr( aOut, "_XML2CMPTYPES= "); 206 207 HeapItem * pLastHeapTop = 0; 208 for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() ) 209 { 210 if (pLastHeapTop != 0) 211 { 212 if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) ) 213 continue; 214 delete pLastHeapTop; 215 // pLastHeapTop = 0; 216 } 217 pLastHeapTop = pHeapTop; 218 219 WriteStr( aOut, "\t\\\n\t\t" ); 220 221 const char * sEnd = strchr( pHeapTop->Key(), ' ' ); 222 if (sEnd != 0) 223 { 224 const char * sQuali = strrchr( pHeapTop->Key(), ' ' )+1; 225 WriteStr( aOut, sQuali ); 226 WriteStr( aOut, "." ); 227 aOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() ); 228 } 229 else 230 WriteStr( aOut, pHeapTop->Key() ); 231 } // end for 232 233 if (pLastHeapTop != 0) 234 { 235 delete pLastHeapTop; 236 pLastHeapTop = 0; 237 } 238 239 aOut.close(); 240 #endif // 0 241 } 242 243 void 244 Put2StdOut_TypeInfo( ModuleDescription & i_rData ) 245 { 246 StreamOut_TypeInfo(std::cout, i_rData, " "); 247 } 248 249 void 250 Put2File_TypeInfo( const char * i_sOutputFile, 251 ModuleDescription & i_rData ) 252 { 253 std::ofstream aOut(i_sOutputFile, std::ios::out 254 #if defined(WNT) || defined(OS2) 255 | std::ios::binary 256 #endif 257 ); 258 if ( !aOut ) 259 { 260 std::cerr << "Error: " << i_sOutputFile << " could not be created." << std::endl; 261 return; 262 } 263 264 Simstr sLibPrefix = i_rData.ModuleName(); 265 WriteStr( aOut, sLibPrefix ); 266 WriteStr( aOut, "_XML2CMPTYPES= "); 267 268 StreamOut_TypeInfo(aOut, i_rData, "\t\\\n\t\t"); 269 270 aOut.close(); 271 } 272 273 void 274 StreamOut_TypeInfo( std::ostream & o_rOut, 275 ModuleDescription & i_rData, 276 const char * i_sSeparator ) 277 { 278 Heap aTypesHeap(12); 279 280 // Gather types: 281 List< const MultipleTextElement * > aTypes; 282 i_rData.Get_Types(aTypes); 283 284 for ( unsigned t = 0; t < aTypes.size(); ++t ) 285 { 286 unsigned i_max = aTypes[t]->Size(); 287 for ( unsigned i = 0; i < i_max; ++i ) 288 { 289 aTypesHeap.InsertValue( aTypes[t]->Data(i), "" ); 290 } // end for 291 } 292 293 // Write types: 294 HeapItem * pLastHeapTop = 0; 295 for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() ) 296 { 297 if (pLastHeapTop != 0) 298 { 299 if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) ) 300 continue; 301 delete pLastHeapTop; 302 // pLastHeapTop = 0; 303 } 304 pLastHeapTop = pHeapTop; 305 306 WriteStr( o_rOut, i_sSeparator ); 307 308 const char * sEnd = strchr( pHeapTop->Key(), ' ' ); 309 if (sEnd != 0) 310 { 311 const char * sQuali = strrchr( pHeapTop->Key(), ' ' ) + 1; 312 WriteStr( o_rOut, sQuali ); 313 WriteStr( o_rOut, "." ); 314 o_rOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() ); 315 } 316 else 317 WriteStr( o_rOut, pHeapTop->Key() ); 318 } // end for 319 320 if (pLastHeapTop != 0) 321 { 322 delete pLastHeapTop; 323 pLastHeapTop = 0; 324 } 325 } 326 327