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