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