diff options
author | Nikolai Pretzell <np@openoffice.org> | 2001-03-09 14:23:00 +0000 |
---|---|---|
committer | Nikolai Pretzell <np@openoffice.org> | 2001-03-09 14:23:00 +0000 |
commit | dc814e7937205eedb80446b7eecc1822d9717ec5 (patch) | |
tree | a1b85902764f467d734db7291154f9dfe1a460ed /xml2cmp | |
parent | 9708f8092dc64dd0441ec8ceaa410de63349fc0b (diff) |
New dtd for component descriptions and additional linking - step2.
Diffstat (limited to 'xml2cmp')
24 files changed, 5263 insertions, 0 deletions
diff --git a/xml2cmp/source/support/cmdline.cxx b/xml2cmp/source/support/cmdline.cxx new file mode 100644 index 000000000000..541b69e12dcc --- /dev/null +++ b/xml2cmp/source/support/cmdline.cxx @@ -0,0 +1,257 @@ +/************************************************************************* + * + * $RCSfile: cmdline.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "cmdline.hxx" + +#include <ctype.h> +#include <string.h> +#include <stdlib.h> +#include <ostream.h> + + +char C_sUseText[] = "Use: xml2cmp.exe \n" + " [-func funcFile] \n" + " [-html] \n" + " [-types typeFile] \n" + " [-idlpath idlPath] \n" + " Xml_FileName\n" + " or: xml2cmp.exe \n" + " -ix \n" + " sourceDirectory \n" + " outputDirectory \n" + " [-idlpath idlPath] \n" + " tagname [tagname ...]"; + + +char C_sCmdFunc[] = "-func"; +char C_sCmdHtml[] = "-html"; +char C_sCmdType[] = "-types"; +char C_sCmdIndex[] = "-ix"; +char C_sCmdIdlPath[] = "-idlpath"; + + + +bool GetParameter( Simstr & o_rMemory, int & io_nCountArg, int argc, char * argv[] ); + + +CommandLine::CommandLine( int argc, + char * argv[] ) + : bIsOk(true) +{ + int nCountArg = 0; + bool bDisplayUse = false; + + /* Check command line: */ + if ( argc < 2 ) + bDisplayUse = true; + else if ( argc == 2 && ! isalnum(argv[1][0]) ) + bDisplayUse = true; + else if ( strcmp( argv[1], C_sCmdIndex ) == 0 && argc < 5 ) + bDisplayUse = true; + + if (bDisplayUse) + { + cout << C_sUseText; + bIsOk = false; + exit(0); + } + + if ( strcmp( argv[1], C_sCmdIndex ) == 0 ) + { + ParseIndexCommand(argc,argv); + } + else + { + ParseSingleFileCommand(argc,argv); + } + + if ( sXmlSourceFile.l() == 0 + && sXmlSourceDirectory.l() == 0 ) + { + bIsOk = false; + } + else if ( sXmlSourceFile.l() > 0 + && sXmlSourceDirectory.l() > 0 ) + { + bIsOk = false; + } + else if ( sIndexFile.l() > 0 + && ( sXmlSourceDirectory.l() == 0 + || aTagsInIndex.size() == 0 + ) + ) + { + bIsOk = false; + } + +} + +CommandLine::~CommandLine() +{ +} + + +const char * +CommandLine::ErrorText() const +{ + static char cOut[] = "Error: Command line was incorrect. Probably there was a flag without\n" + " the corresponding parameter. Or there was no XML-sourcefile specified.\n"; + return cOut; +} + +bool +GetParameter( Simstr & o_pMemory, + int & io_pCountArg, + int argc, + char * argv[] ) +{ + io_pCountArg++; + if( io_pCountArg < argc ) + { + o_pMemory = argv[io_pCountArg]; + return true; + } + return false; +} + + +void +CommandLine::ParseIndexCommand( int argc, + char * argv[] ) +{ + int nCountArg = 1; + bIsOk = GetParameter( + sXmlSourceDirectory, + nCountArg, + argc, + argv ); + if (bIsOk) + bIsOk = GetParameter( + sOutputDirectory, + nCountArg, + argc, + argv ); + if (bIsOk && strcmp( argv[nCountArg+1], C_sCmdIdlPath ) == 0 ) + bIsOk = GetParameter( + sIdlRootPath, + ++nCountArg, + argc, + argv ); + + sIndexFile = sOutputDirectory; +#ifdef WNT + sIndexFile+= "\\xmlindex.html"; +#elif defined(UNX) + sIndexFile+= "/xmlindex.html"; +#endif + + for ( ++nCountArg; nCountArg < argc; ++nCountArg ) + { + Simstr sElementName(argv[nCountArg]); + aTagsInIndex.push_back( sElementName ); + } +} + + +void +CommandLine::ParseSingleFileCommand( int argc, + char * argv[] ) +{ + for ( int nCountArg = 1; nCountArg < argc && bIsOk; ++nCountArg ) + { + if ( strcmp( argv[nCountArg], C_sCmdFunc ) == 0 ) + { + bIsOk = GetParameter( + sFuncFile, + nCountArg, + argc, + argv ); + } + else if ( strcmp( argv[nCountArg], C_sCmdHtml ) == 0 ) + { + bIsOk = GetParameter( + sHtmlFile, + nCountArg, + argc, + argv ); + } + else if ( strcmp( argv[nCountArg], C_sCmdType ) == 0 ) + { + bIsOk = GetParameter( + sTypeInfoFile, + nCountArg, + argc, + argv ); + } + else if ( strcmp( argv[nCountArg], C_sCmdIdlPath ) == 0 ) + { + bIsOk = GetParameter( + sIdlRootPath, + nCountArg, + argc, + argv ); + } + else + { + sXmlSourceFile = argv[nCountArg]; + } + } /* end for */ +} diff --git a/xml2cmp/source/support/cmdline.hxx b/xml2cmp/source/support/cmdline.hxx new file mode 100644 index 000000000000..bc55fff0fd59 --- /dev/null +++ b/xml2cmp/source/support/cmdline.hxx @@ -0,0 +1,120 @@ +/************************************************************************* + * + * $RCSfile: cmdline.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_CMDLINE_HXX +#define X2C_CMDLINE_HXX + +#include "sistr.hxx" +#include "list.hxx" + + +class CommandLine +{ + public: + CommandLine( + int i_argc, + char * i_argv[] ); + ~CommandLine(); + + bool IsOk() const { return bIsOk; } + const char * ErrorText() const; + + const char * XmlSrcFile() const { return sXmlSourceFile.str(); } + const char * FuncFile() const { return sFuncFile.str(); } + const char * HtmlFile() const { return sHtmlFile.str(); } + const char * TypeInfoFile() const { return sTypeInfoFile.str(); } + + bool IsIndexCommand() const { return sIndexFile.l() > 0; } + const char * XmlSrcDirectory() const { return sXmlSourceDirectory.str(); } + const char * IndexOutputFile() const { return sIndexFile.str(); } + const char * OutputDirectory() const { return sOutputDirectory.str(); } + const List<Simstr> & + IndexedTags() const { return aTagsInIndex; } + + const char * IdlRootPath() const { return sIdlRootPath.str(); } + + private: + void ParseIndexCommand( + int argc, + char * argv[] ); + void ParseSingleFileCommand( + int argc, + char * argv[] ); + Simstr sXmlSourceFile; + Simstr sFuncFile; + Simstr sHtmlFile; + Simstr sTypeInfoFile; + + Simstr sXmlSourceDirectory; + Simstr sIndexFile; + Simstr sOutputDirectory; + List<Simstr> aTagsInIndex; + + Simstr sIdlRootPath; + + bool bIsOk; +}; + + + + +#endif + diff --git a/xml2cmp/source/support/heap.cxx b/xml2cmp/source/support/heap.cxx new file mode 100644 index 000000000000..fa5c6224f449 --- /dev/null +++ b/xml2cmp/source/support/heap.cxx @@ -0,0 +1,234 @@ +/************************************************************************* + * + * $RCSfile: heap.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <string.h> +#include "heap.hxx" + + +#include <iostream.h> +#include <stdlib.h> +#define AssertionOf(x) {if (!(x)) {cerr << "Assertion failed: " << #x << __FILE__ << __LINE__ << endl; exit(3); }} + + +Heap::Heap(unsigned i_nWidth) + : dpColumnsArray(new Column[i_nWidth]), + nColumnsArraySize(i_nWidth), + nActiveColumn(nColumnsArraySize-1) +{ + for ( unsigned i = 0; i < nColumnsArraySize; i++) + { + dpColumnsArray[i] = 0; + } // end for +} + +Heap::~Heap() +{ + for ( unsigned i = 0; i < nColumnsArraySize; i++) + { + HeapItem * & rColumn = dpColumnsArray[i]; + for ( HeapItem * pValue = rColumn; pValue != 0; pValue = rColumn ) + { + rColumn = rColumn->Next(); + delete pValue; + } + } // end for +} + +void +Heap::InsertValue( const char * i_sKey, + const char * i_sValue ) +{ + HeapItem * pSearch1 = 0; + HeapItem * pSearch2 = 0; + HeapItem * pNew = new HeapItem(i_sKey, i_sValue); + + IncColumn(); + pSearch1 = ActiveColumn(); + + if ( pSearch1 != 0 ? *pNew < *pSearch1 : true ) + { + pNew->SetNext( pSearch1 ); + ActiveColumn() = pNew; + + if ( pNew->Next() != 0) + { + AssertionOf( *pNew <= *pNew->Next() ); + } + + return; + } + + do + { + pSearch2 = pSearch1; + pSearch1 = pSearch1->Next(); + + if ( pSearch1 != 0 ? *pNew < *pSearch1 : true ) + { + pNew->SetNext( pSearch1 ); + pSearch2->SetNext(pNew); + + + AssertionOf( *pSearch2 <= *pNew ); + if ( pNew->Next() != 0) + { + AssertionOf( *pNew <= *pNew->Next() ); + } + + } + } while (pSearch2->Next() != pNew); +} + + +Simstr sKey1; +Simstr sValue1; +Simstr sKey2; +Simstr sValue2; +int nCol1 = 0; +int nCol2 = 0; + + +HeapItem * +Heap::ReleaseTop() +{ + unsigned nRetColumn = 0; + HeapItem * ret = dpColumnsArray[0]; + HeapItem * pSearch = 0; + + for ( unsigned i = 1; i < nColumnsArraySize; ++i ) + { + pSearch = dpColumnsArray[i]; + if (pSearch != 0) + { + if ( ret == 0 ? true : *pSearch < *ret) + { + ret = pSearch; + nRetColumn = i; + } + } + } // for + + if (ret != 0) + { + dpColumnsArray[nRetColumn] = ret->Next(); + } + return ret; +} + +void +Heap::IncColumn() +{ + if (++nActiveColumn >= nColumnsArraySize) + nActiveColumn = 0; +} + + + +HeapItem::HeapItem( const char * i_sKey, + const char * i_sValue ) + : sValue(i_sValue), + sKey(i_sKey), + pNext(0) +{ +} + +HeapItem::~HeapItem() +{ +} + +bool +HeapItem::operator<( const HeapItem & i_rOther ) const +{ + int ret = stricmp(sKey.str(), i_rOther.sKey.str()); + if (ret == 0) + ret = strcmp(sKey.str(), i_rOther.sKey.str()); + if (ret == 0) + ret = stricmp(sValue.str(), i_rOther.sValue.str()); + if (ret == 0) + ret = strcmp(sValue.str(), i_rOther.sValue.str()); + return ret < 0; +} + +const Simstr & +HeapItem::Value() const +{ + return sValue; +} + +const Simstr & +HeapItem::Key() const +{ + return sKey; +} + +HeapItem * +HeapItem::Next() const +{ + return pNext; +} + +void +HeapItem::SetNext( HeapItem * i_pNext ) +{ + pNext = i_pNext; +} + + diff --git a/xml2cmp/source/support/heap.hxx b/xml2cmp/source/support/heap.hxx new file mode 100644 index 000000000000..5560d5218bdd --- /dev/null +++ b/xml2cmp/source/support/heap.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * $RCSfile: heap.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_HEAP_HXX +#define X2C_HEAP_HXX + +#include "sistr.hxx" + +class HeapItem; + +class Heap +{ + public: + Heap( + unsigned i_nWidth ); + ~Heap(); + + void InsertValue( + const char * i_sKey, + const char * i_sValue ); + HeapItem * ReleaseTop(); /// @return must be deleted by caller of method. + + private: + typedef HeapItem * Column; + + void IncColumn(); + Column & ActiveColumn() { return dpColumnsArray[nActiveColumn]; } + + Column * dpColumnsArray; + unsigned nColumnsArraySize; + unsigned nActiveColumn; +}; + + +class HeapItem +{ + public: + HeapItem( + const char * i_sKey, + const char * i_sValue ); + ~HeapItem( ); + + bool operator<( + const HeapItem & i_rOther ) const; + bool operator<=( + const HeapItem & i_rOther ) const + { return ! (i_rOther < *this); } + const Simstr & Value() const; + const Simstr & Key() const; + HeapItem * Next() const; + + void SetNext( + HeapItem * i_pNext ); + private: + Simstr sValue; + Simstr sKey; + HeapItem * pNext; +}; + + + + + + +#endif + + diff --git a/xml2cmp/source/support/list.hxx b/xml2cmp/source/support/list.hxx new file mode 100644 index 000000000000..b37d921e92d9 --- /dev/null +++ b/xml2cmp/source/support/list.hxx @@ -0,0 +1,232 @@ +/***************************************************************** +* Project: +* +* File: LIST.HXX +* Description: Template for Lists +* +* Created: 21. 8. 1994 + * Author: Nikolai Pretzell +******************************************************************/ + +#ifndef __LISTEN_123456__ +#define __LISTEN_123456__ + +#include <string.h> +#include <ostream.h> +#include <stdlib.h> + +template <class XX> +class List +{ + public : + typedef XX * iterator; + typedef const XX * const_iterator; + + // LIFECYCLE + List(); + virtual ~List() { } + + // OPERATORS + const XX & operator[]( + unsigned n) const + { return elem(n); } + XX & operator[]( + unsigned n) + { return elem(n); } + // OPERATIONS + void reserve( + unsigned i_nSize ) + { alloc(i_nSize,true); } + virtual void insert( + unsigned pos, + const XX & elem ); + void push_back( + const XX & elem) + { insert(size(),elem); } + + virtual void remove( + unsigned pos ); + void pop_back() { remove(size()-1); } + void erase_all() { while (size()) remove(size()-1); } + + // INQUIRY + const XX & front() const { return elem(0); } + const XX & back() const { return elem(len-1); } + + unsigned size() const { return len; } + unsigned space() const { return allocated; } + bool is_valid_index( + unsigned n) const + { return n < len; } + // ACCESS + XX & front() { return elem(0); } + XX & back() { return elem(len-1); } + + protected: + void checkSize( + unsigned newLength); + void alloc( + unsigned newSpace, + bool re = false ); + + const XX & elem( + unsigned n ) const + { return inhalt[n]; } + XX & elem( + unsigned n ) + { return inhalt[n]; } + // DATA + XX * inhalt; + unsigned len; + unsigned allocated; + + private: + // forbidden functions + List(const List<XX> & L); + List<XX> & operator=( + const List<XX> & L); + +}; + +template <class XY> +class DynamicList : public List<XY*> +{ + public: + virtual ~DynamicList(); + + virtual void insert( + unsigned pos, + XY * const & elem ); + virtual void remove( + unsigned pos ); +}; + + + +template <class XX> +List<XX>::List() + : len(0), + inhalt(0) +{ + alloc(1); +} + + +template <class XX> +void +List<XX>::insert(unsigned pos, const XX & elem) +{ + if ( pos > len ) + return; + + checkSize(len+2); + for ( unsigned p = len; p > pos; --p) + { + inhalt[p] = inhalt[p-1]; + } + inhalt[pos] = elem; + len++; +} + + +template <class XX> +void +List<XX>::remove(unsigned pos) +{ + if ( pos >= len ) + return; + len--; + for ( unsigned p = pos; p < len; ++p) + { + inhalt[p] = inhalt[p+1]; + } +} + + +// Protected: +template <class XX> +void +List<XX>::checkSize(unsigned newLength) +{ + // neuen Platzbedarf pruefen: + unsigned newSpace = space(); + if (newLength > newSpace) + { + if (!newSpace) + newSpace = 1; + const unsigned nBorder = 65536 / 2; + while(newLength > newSpace) + { + if (newSpace < nBorder) + newSpace <<= 1; + else + { + cerr << "List becomes too big" << endl; + exit(1); + } + } + } + + // Veraenderung ?: + if (newSpace != space()) + alloc(newSpace,true); +} + +template <class XX> +void +List<XX>::alloc( unsigned newSpace, + bool re ) +{ + XX * pNew = new XX[newSpace]; + + if (inhalt != 0) + { + if (re) + { + for (unsigned i = 0; i < len; ++i) + { + pNew[i] = inhalt[i]; + } // end for + } + delete [] inhalt; + } + + inhalt = pNew; + allocated = newSpace; +} + + +template <class XY> +DynamicList<XY>::~DynamicList() +{ + erase_all(); +} + +template <class XY> +void +DynamicList<XY>::insert(unsigned pos, XY * const & elem) +{ + if ( pos > len ) + return; + + checkSize(len+2); + memmove(inhalt[pos+1], inhalt[pos], (len-pos) * sizeof(XY*) ); + inhalt[pos] = elem; + len++; +} + +template <class XY> +void +DynamicList<XY>::remove( unsigned pos ) +{ + if (!is_valid_index(pos) ) + return; + len--; + delete inhalt[pos]; + memmove(inhalt[pos], inhalt[pos+1], (len-pos) * sizeof(XY*) ); +} + + + +#endif + diff --git a/xml2cmp/source/support/makefile.mk b/xml2cmp/source/support/makefile.mk new file mode 100644 index 000000000000..b8f8b58a0f55 --- /dev/null +++ b/xml2cmp/source/support/makefile.mk @@ -0,0 +1,93 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=xml2cmp +TARGET=x2c_support +TARGETTYPE=CUI + + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/cmdline.obj \ + $(OBJ)$/heap.obj \ + $(OBJ)$/sistr.obj \ + $(OBJ)$/syshelp.obj + + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/xml2cmp/source/support/sistr.cxx b/xml2cmp/source/support/sistr.cxx new file mode 100644 index 000000000000..d12a3178c7c0 --- /dev/null +++ b/xml2cmp/source/support/sistr.cxx @@ -0,0 +1,852 @@ +/************************************************************************* + * + * $RCSfile: sistr.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include <sistr.hxx> + +// The following two header-files declare +// standard ANSI-C++ functions. They may be replaced +// by the corresponding header-file-names of the +// actually used runtime library. +#include <string.h> // strlen(), memcpy(), memset() +#include <ctype.h> // tolower() +#include <limits.h> // INT_MAX + +const char NULCH = '\0'; +const int NO_POS = -1; + + +Simstr::Simstr(const char * str) +{ + if (str == 0) + { + len = 0; + sz = new char[1]; + *sz = 0; + } + else + { + len = strlen(str); + sz = new char[len+1]; + memcpy(sz,str,len+1); + } +} + +Simstr::Simstr(const char * txt, int anzahl) +{ + int txtlen = txt != 0 ? strlen(txt) : 0; + if (txt == 0 || anzahl < 1 || long(anzahl) * txtlen > INT_MAX) + { + len = 0; + sz = new char[1]; + *sz = 0; + } + else + { + len = anzahl * txtlen; + sz = new char[len+1]; + for (int i = 0; i < anzahl; i++) + memcpy(sz + (i*txtlen), txt, txtlen); + sz[len] = 0; + } +} + +Simstr::Simstr(char c, int anzahl) +{ + if (anzahl < 1) + { + len = 0; + sz = new char[1]; + *sz = 0; + } + else + { + len = anzahl; + sz = new char[len+1]; + memset(sz,c,anzahl); + sz[len] = 0; + } +} + +Simstr::Simstr( const char * anybytes, + int firstBytesPos, + int nrOfBytes) +{ + unsigned slen = strlen(anybytes); + if (anybytes == 0 || slen <= unsigned(firstBytesPos)) + { + len = 0; + sz = new char[1]; + *sz = 0; + } + else + { + int maxLen = slen - unsigned(firstBytesPos); + len = maxLen < nrOfBytes + ? maxLen + : nrOfBytes; + sz = new char[len+1]; + memcpy(sz,anybytes+firstBytesPos,len); + *(sz+len) = 0; + } +} + + +Simstr::Simstr(const Simstr & S) +{ + len = S.len; + sz = new char[len+1]; + memcpy(sz,S.sz,len+1); +} + +Simstr & Simstr::operator=(const Simstr & S) +{ + if (sz == S.sz) + return *this; + + delete [] sz; + + len = S.len; + sz = new char[len+1]; + memcpy(sz,S.sz,len+1); + + return *this; +} + +Simstr::~Simstr() +{ + delete [] sz; +} + +char & +Simstr::ch(int n) +{ + static char nullCh = NULCH; + nullCh = NULCH; + if (n >= long(len) || n < 0) + return nullCh; + else + return sz[unsigned(n)]; +} + + +Simstr +Simstr::operator+(const Simstr & S) const +{ + Simstr ret = sz; + ret.push_back(S); + return ret; +} + +Simstr & +Simstr::operator+=(const Simstr & S) +{ + push_back(S); + return *this; +} + + +// REL + +bool +Simstr::operator==(const Simstr & S) const +{ return !strcmp(sz,S.sz) ? true : false; } + +bool +Simstr::operator!=(const Simstr & S) const +{ return strcmp(sz,S.sz) ? true : false; } + +bool +Simstr::operator<(const Simstr & S) const +{ return (strcmp(sz,S.sz) < 0) ? true : false; } + +bool +Simstr::operator>(const Simstr & S) const +{ return (strcmp(sz,S.sz) > 0) ? true : false; } + +bool +Simstr::operator<=(const Simstr & S) const +{ return (strcmp(sz,S.sz) <= 0) ? true : false; } + +bool +Simstr::operator>=(const Simstr & S) const +{ return (strcmp(sz,S.sz) >= 0) ? true : false; } + + + + +// ************** LIST - Funktionen ***************** + + +// Einzelzugriff + +char +Simstr::get(int n) const { return (n >= len || n < 0) ? 0 : sz[n]; } + +char +Simstr::get_front() const { return sz[0]; } + +char +Simstr::get_back() const { return len ? sz[len-1] : 0; } + +Simstr +Simstr::get(int startPos, int anzahl) const +{ + if (startPos >= len || startPos < 0 || anzahl < 1) + return ""; + + int anz = len - startPos < anzahl ? len - startPos : anzahl; + + Simstr ret(' ',anz); + memcpy(ret.sz, sz+startPos, anz); + return ret; +} + +Simstr +Simstr::get_front(int anzahl) const +{ + int anz = len < anzahl ? len : anzahl; + if (anz < 1) + return ""; + + Simstr ret(' ',anz); + memcpy(ret.sz, sz, anz); + return ret; +} + +Simstr +Simstr::get_back(int anzahl) const +{ + int anz = len < anzahl ? len : anzahl; + if (anz < 1) + return ""; + int start = len-anz; + + Simstr ret(' ',anz); + memcpy(ret.sz, sz+start, anz); + return ret; +} + +Simstr +Simstr::get_first_token(char c) const +{ + int posc = pos_first(c); + if (posc != NO_POS) + return get_front(posc); + else + return sz; +} + +Simstr +Simstr::get_last_token(char c) const +{ + int posc = pos_last(c); + if (posc != NO_POS) + return get_back(len-posc-1); + else + return sz; +} + + + +// Insert + +void +Simstr::insert(int pos, char c) +{ + if (pos < 0 || pos > len) + return; + + char * result = new char[len+2]; + + memcpy(result,sz,pos); + result[pos] = c; + memcpy(result+pos+1,sz+pos,len-pos+1); + + delete [] sz; + sz = result; + len++; +} + +void +Simstr::push_front(char c) +{ + char * result = new char[len+2]; + + result[0] = c; + memcpy(result+1,sz,len+1); + + delete [] sz; + sz = result; + len++; +} + +void +Simstr::push_back(char c) +{ + char * result = new char[len+2]; + + memcpy(result,sz,len); + result[len] = c; + result[len+1] = 0; + + delete [] sz; + sz = result; + len++; +} + +void +Simstr::insert(int pos, const Simstr & S) +{ + if (pos < 0 || pos > len) + return; + + char * result = new char[len+1+S.len]; + + memcpy(result,sz,pos); + memcpy(result+pos,S.sz,S.len); + memcpy(result+pos+S.len,sz+pos,len-pos+1); + + delete [] sz; + sz = result; + len += S.len; +} + +void +Simstr::push_front(const Simstr & S) +{ + char * result = new char[len+1+S.len]; + + memcpy(result,S.sz,S.len); + memcpy(result+S.len,sz,len+1); + + delete [] sz; + sz = result; + len += S.len; +} + +void +Simstr::push_back(const Simstr & S) +{ + char * result = new char[len+1+S.len]; + + memcpy(result,sz,len); + memcpy(result+len,S.sz,S.len+1); + + delete [] sz; + sz = result; + len += S.len; +} + + +// Remove + +void +Simstr::remove(int pos, int anzahl) +{ + if (pos >= len || pos < 0 || anzahl < 1) + return; + + int anz = len - pos < anzahl ? len - pos : anzahl; + + char * result = new char[len-anz+1]; + + memcpy(result,sz,pos); + memcpy(result+pos,sz+pos+anz,len-pos-anz+1); + + delete [] sz; + sz = result; + len -= anz; +} + +void +Simstr::remove_trailing_blanks() +{ + int newlen = len-1; + for ( ; newlen > 1 && sz[newlen] <= 32; --newlen ) {} + + if (newlen < len-1) + remove ( newlen+1, len-newlen); +} + +void +Simstr::pop_front(int anzahl) +{ + if (anzahl < 1) + return; + int anz = len < anzahl ? len : anzahl; + + char * result = new char[len-anz+1]; + + memcpy(result,sz+anz,len-anz+1); + + delete [] sz; + sz = result; + len -= anz; +} + +void +Simstr::pop_back(int anzahl) +{ + if (anzahl < 1) + return; + + int anz = len < anzahl ? len : anzahl; + + char * result = new char[len-anz+1]; + + memcpy(result,sz,len-anz); + result[len-anz] = 0; + + delete [] sz; + sz = result; + len -= anz; +} + +void +Simstr::rem_back_from(int removeStartPos) +{ + if (removeStartPos != NO_POS) + pop_back(len-removeStartPos); +} + +void +Simstr::remove_all(char c) +{ + if (!len) + return; + char * result = new char[len]; + int i,j=0; + for (i = 0; i < len; i++) + if (sz[i] != c) + result[j++] = sz[i]; + + delete [] sz; + sz = new char[j+1]; + memcpy(sz,result,j); + sz[j] = 0; + len = j; + delete [] result; +} + +void +Simstr::remove_all(const Simstr & S) +{ + int pos; + while ( (pos=pos_first(S)) != NO_POS ) + remove(pos,S.len); +} + +void +Simstr::strip(char c) +{ + int start = 0; + if (c == ' ') + { // Sonderbehandlung: SPC entfernt auch TABs: + while ( start < len + ? sz[start] == ' ' + || sz[start] == '\t' + : false ) + start++; + } + else + { + while (start < len && sz[start] == c) + start++; + } + + int ende = len-1; + if (c == ' ') + { // Sonderbehandlung: SPC entfernt auch TABs: + while ( ende >= start + ? sz[ende] == ' ' + || sz[ende] == '\t' + : false ) + ende--; + } + else + { + while (ende >= start && sz[ende] == c) + ende--; + } + *this = get(start,ende-start+1); +} + +void +Simstr::empty() +{ + if (len > 0) + { + delete [] sz; + sz = new char[1]; + *sz = 0; + len = 0; + } +} + +Simstr +Simstr::take_first_token(char c) +{ + Simstr ret; + int pos = pos_first(c); + if (pos != NO_POS) + { + ret = get_front(pos); + pop_front(pos+1); + } + else + { + ret = sz; + delete [] sz; + sz = new char[1]; + *sz = NULCH; + len = 0; + } + + return ret; +} + +Simstr +Simstr::take_last_token(char c) +{ + Simstr ret; + int pos = pos_last(c); + if (pos != NO_POS) + { + ret = get_back(len-pos-1); + pop_back(len-pos); + } + else + { + ret = sz; + delete [] sz; + sz = new char[1]; + *sz = NULCH; + len = 0; + } + + return ret; +} + + + +// Find + +int +Simstr::pos_first(char c) const +{ + int i = 0; + for (i = 0; i < len ? sz[i] != c : false; i++); + if (i >= len) + return NO_POS; + else + return i; +} + +int +Simstr::pos_first_after( char c, + int startSearchPos) const +{ + int i = 0; + if (startSearchPos >= i) + i = startSearchPos+1; + for (; i < len ? sz[i] != c : false; i++); + if (i >= len) + return NO_POS; + else + return i; +} + + +int +Simstr::pos_last(char c) const +{ + int i = 0; + for (i = len-1; i >= 0 ? sz[i] != c : false; i--); + if (i < 0) + return NO_POS; + else + return i; +} + +int +Simstr::pos_first(const Simstr & S) const +{ + char * ptr = strstr(sz,S.sz); + if (ptr) + return int(ptr-sz); + else + return NO_POS; +} + +int +Simstr::pos_last(const Simstr & S) const +{ + Simstr vgl; + int i; + for (i = len-S.len; i >= 0 ; i--) + { + vgl = get(i,S.len); + if (vgl == S) + break; + } + if (i >= 0) + return i; + else + return NO_POS; +} + +int +Simstr::count(char c) const +{ + int ret = 0; + for (int i =0; i < len; i++) + if (sz[i] == c) + ret++; + return ret; +} + +bool +Simstr::is_no_text() const +{ + if (!len) + return true; + + int i; + for (i = 0; ( sz[i] == ' ' || sz[i] == '\t' ) && i < len; i++); + if (i < len) + return false; + return true; +} + +// Change + +void +Simstr::replace(int pos, char c) +{ + if (pos < 0 || pos >= len) + return; + else + sz[unsigned(pos)] = c; +} + +void +Simstr::replace(int startPos, int anzahl, const Simstr & S) +{ + if (startPos >= len || startPos < 0 || anzahl < 1) + return; + + int anz = len - startPos < anzahl ? len - startPos : anzahl; + + char * result = new char[len-anz+S.len+1]; + + memcpy(result,sz,startPos); + memcpy(result+startPos, S.sz, S.len); + memcpy(result+startPos+S.len, sz+startPos+anz, len-startPos-anz+1); + + delete [] sz; + sz = result; + len = len-anz+S.len; +} + +void +Simstr::replace_all(char oldCh, char newCh) +{ + for (int i=0; i < len; i++) + if (sz[i] == oldCh) + sz[i] = newCh; +} + +void +Simstr::replace_all(const Simstr & oldS, const Simstr & newS) +{ + Simstr vgl; + int i = 0; + while (i <= len-oldS.len) + { + vgl = get(i,oldS.len); + if (strcmp(vgl.sz,oldS.sz) == 0) + { + replace(i,oldS.len,newS); + i += newS.len; + } + else + i++; + } +} + +void +Simstr::to_lower() +{ + for (int i = 0; i < len; i++) + sz[i] = (char) tolower(sz[i]); +} + + + +// Simstr addition +Simstr +operator+(const char * str, const Simstr & S) +{ + Simstr ret = S; + ret.push_front(str); + return ret; +} + +Simstr +operator+(const Simstr & S, const char * str) +{ + Simstr ret = S; + ret.push_back(str); + return ret; +} + +Simstr +operator+(char c, const Simstr & S) +{ + Simstr ret = S; + ret.push_front(c); + return ret; +} + +Simstr +operator+(const Simstr & S, char c) +{ + Simstr ret = S; + ret.push_back(c); + return ret; +} + + +// Simstr-Vergleiche mit char * +bool +operator==(const Simstr & S, const char * str) +{ + return strcmp(S,str) == 0; +} + +bool +operator!=(const Simstr & S, const char * str) +{ + return strcmp(S,str) != 0; +} + +bool +operator<(const Simstr & S, const char * str) +{ + return strcmp(S,str) < 0; +} + +bool +operator>(const Simstr & S, const char * str) +{ + return strcmp(S,str) > 0; +} + +bool +operator<=(const Simstr & S, const char * str) +{ + return strcmp(S,str) <= 0; +} + +bool +operator>=(const Simstr & S, const char * str) +{ + return strcmp(S,str) >= 0; +} + +bool +operator==(const char * str, const Simstr & S) +{ + return strcmp(str,S) == 0; +} + +bool +operator!=(const char * str, const Simstr & S) +{ + return strcmp(str,S) != 0; +} + +bool +operator<(const char * str, const Simstr & S) +{ + return strcmp(str,S) < 0; +} + +bool +operator>(const char * str, const Simstr & S) +{ + return strcmp(str,S) > 0; +} + +bool +operator<=(const char * str, const Simstr & S) +{ + return strcmp(str,S) <= 0; +} + +bool +operator>=(const char * str, const Simstr & S) +{ + return strcmp(str,S) >= 0; +} + + diff --git a/xml2cmp/source/support/sistr.hxx b/xml2cmp/source/support/sistr.hxx new file mode 100644 index 000000000000..644fdcca41a9 --- /dev/null +++ b/xml2cmp/source/support/sistr.hxx @@ -0,0 +1,244 @@ +/************************************************************************* + * + * $RCSfile: sistr.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:22:59 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef XML2CMP_SISTR_HXX +#define XML2CMP_SISTR_HXX + + +class Simstr +{ +// INTERFACE + public: + // Constructors, destructor, '=' and typecasts + Simstr( + const char * str = 0); + Simstr( // Creates Simstr of 'anzahl' times 'txt'. + const char * txt, + int anzahl); + Simstr( + char c, // Creates Simstr of 'anzahl' times 'c'. + int anzahl); + Simstr( // Creates Simstr out of a copy of the described bytes within 'anyBytes'. + // Adds a '\0' at the end. + const char * anybytes, + int firstBytesPos, + int nrOfBytes); + virtual ~Simstr(); + Simstr( + const Simstr & S); + Simstr & operator=( + const Simstr & S); + operator const char*() const; + + // diverse utility functions + const char * str() const { return sz; } + char * s(); // ATTENTION !!! // Only to be used, when a function needs a 'char*' but + // nevertheless THAT WILL BE NOT CHANGED! + // Typecasts to 'const char*' are performed automatically. + int l() const; // Length of string without '\0' at end. + char & ch( int n); // Reference to sz[n]. Allows change of this char. + // !!! No safety, if n is out of the allowed range! + Simstr operator+( + const Simstr & S) const; + Simstr & operator+=( + const Simstr & S); + + // comparison operators + bool operator==( + const Simstr & S) const; + bool operator!=( + const Simstr & S) const; + bool operator<( + const Simstr & S) const; + bool operator>( + const Simstr & S) const; + bool operator<=( + const Simstr & S) const; + bool operator>=( + const Simstr & S) const; + + + // 'List of characters' - functions + // get - functions + char get( int n) const; + char get_front() const; + char get_back() const; + Simstr get( int startPos, + int anzahl) const; + Simstr get_front( + int anzahl) const; + Simstr get_back( + int anzahl) const; + // insert - functions + void insert( int pos, + char c); + void push_front( + char c); + void push_back( + char c); + void insert( int pos, + const Simstr & S); + void push_front( + const Simstr & S); + void push_back( + const Simstr & S); + // remove - functions + void remove( + int pos, + int anzahl = 1); + void remove_trailing_blanks(); + void pop_front( + int anzahl = 1); + void pop_back( + int anzahl = 1); + void rem_back_from( + int removeStartPos); + void remove_all( + char c); + void remove_all( // Starts search left. + const Simstr & S); + void strip(char c); // Removes all characters == c from front and back. + // c == ' ' removes also TABs !!! + void empty(); // Changes object to the value "". + + // search functions + int pos_first( + char c) const; + int pos_first_after( // Sucht ab erstem char nach startSearchPos + char c, + int startSearchPos) const; + int pos_last( + char c) const; + int pos_first( + const Simstr & S) const; + int pos_last( + const Simstr & S) const; + int count( + char c) const; + bool is_empty() const; // Only true if object == "". + bool is_no_text() const; // String may contain spaces or tabs. + + // substitution functions + void replace( + int pos, + char c); + void replace( + int startPos, + int anzahl, + const Simstr & S); + void replace_all( + char oldCh, + char newCh); + void replace_all( + const Simstr & oldS, + const Simstr & newS); + void to_lower(); + + // token functions + // get...-functions return the token, separated by char 'c' and leave the object unchanged. + // take...-functions return the same, but remove the token and the corresponding separator from the object. + Simstr get_first_token( + char c) const; + Simstr get_last_token( + char c) const; + Simstr take_first_token( + char c); + Simstr take_last_token( + char c); + + private: + char * sz; + int len; +}; + +// Simstr - char* / char - concatenations +Simstr operator+(const char * str, const Simstr & S); +Simstr operator+(const Simstr & S, const char * str); +Simstr operator+(char c, const Simstr & S); +Simstr operator+(const Simstr & S, char c); + +// Simstr - char* - comparison operators +bool operator==(const Simstr & S, const char * str); +bool operator!=(const Simstr & S, const char * str); +bool operator<(const Simstr & S, const char * str); +bool operator>(const Simstr & S, const char * str); +bool operator<=(const Simstr & S, const char * str); +bool operator>=(const Simstr & S, const char * str); +bool operator==(const char * str, const Simstr & S); +bool operator!=(const char * str, const Simstr & S); +bool operator<(const char * str, const Simstr & S); +bool operator>(const char * str, const Simstr & S); +bool operator<=(const char * str, const Simstr & S); +bool operator>=(const char * str, const Simstr & S); + + +inline char * +Simstr::s() { return sz; } +inline int +Simstr::l() const { return len; } +inline +Simstr::operator const char*() const { return sz; } +inline bool +Simstr::is_empty() const { return len == 0; } + + +#endif + diff --git a/xml2cmp/source/support/syshelp.cxx b/xml2cmp/source/support/syshelp.cxx new file mode 100644 index 000000000000..36807eba4125 --- /dev/null +++ b/xml2cmp/source/support/syshelp.cxx @@ -0,0 +1,150 @@ +/************************************************************************* +#* +#* $Workfile: syshelp.cxx $ +#* +#* class +#* +#* Beschreibung +#* +#* Ersterstellung NP +#* Letzte Aenderung $Author: np $ +#* $Date: 2001-03-09 15:22:59 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: T:/solar/source/... $ +#* +#* Copyright (c) 2000, Star Office Gmbh +#* +#**************************************************************************/ + + +#include <syshelp.hxx> + + +// NOT FULLY DEFINED SERVICES +#include <fstream.h> +#include <string.h> +#include "sistr.hxx" + + + +char C_sSpaceInName[] = " "; + +void +WriteName( ofstream & o_rFile, + const Simstr & i_rIdlDocuBaseDir, + const Simstr & i_rName, + E_LinkType i_eLinkType ) +{ + if (i_rName.l() == 0) + return; + + + const char * pNameEnd = strstr( i_rName.str(), " in " ); + + // No link: + if ( i_eLinkType == lt_nolink ) + { + if ( pNameEnd != 0 ) + { + const char * pStart = i_rName.str(); + o_rFile.write( pStart, pNameEnd -1 - pStart ); + WriteStr( o_rFile, C_sSpaceInName ); + WriteStr( o_rFile, pNameEnd ); + } + else + { + WriteStr( o_rFile, i_rName ); + } + return; + } + + if ( i_eLinkType == lt_idl ) + { + Simstr sPath(i_rName); + sPath.replace_all('.','/'); + int nNameEnd = sPath.pos_first(' '); + int nPathStart = sPath.pos_last(' '); + WriteStr( o_rFile, "<A HREF=\"" ); + + if ( nNameEnd > -1 ) + { + WriteStr( o_rFile, "file:///" ); + WriteStr( o_rFile, i_rIdlDocuBaseDir ); + WriteStr( o_rFile, "/" ); + WriteStr( o_rFile, sPath.str() + 1 + nPathStart ); + WriteStr( o_rFile, "/" ); + o_rFile.write( sPath.str(), nNameEnd ); + WriteStr( o_rFile, ".html\">" ); + } + else + { // Should not be reached: + WriteStr(o_rFile, i_rName); + return; + } + } + else if ( i_eLinkType == lt_html ) + { + int nKomma = i_rName.pos_first(','); + int nEnd = i_rName.pos_first(' '); + if ( nKomma > -1 ) + { + o_rFile.write( i_rName.str(), nKomma ); + WriteStr( o_rFile, ": " ); + + WriteStr( o_rFile, "<A HREF=\"" ); + + o_rFile.write( i_rName.str(), nKomma ); + WriteStr( o_rFile, ".html#" ); + if ( nEnd > -1 ) + o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma ); + else + WriteStr( o_rFile, i_rName.str() + nKomma + 1 ); + WriteStr( o_rFile, "\">" ); + + o_rFile.write( i_rName.str() + nKomma + 1, nEnd - nKomma ); + } + else + { + WriteStr( o_rFile, "<A HREF=\"" ); + WriteStr( o_rFile, i_rName ); + WriteStr( o_rFile, ".html\">" ); + + WriteStr( o_rFile, i_rName ); + } + WriteStr( o_rFile, "</A>" ); + return; + } + + if ( pNameEnd != 0 ) + { + const char * pStart = i_rName.str(); + if ( pNameEnd > pStart ) + o_rFile.write( pStart, pNameEnd - pStart ); + WriteStr( o_rFile, "</A>" ); + + WriteStr( o_rFile, C_sSpaceInName ); + WriteStr( o_rFile, pNameEnd ); + } + else + { + WriteStr( o_rFile, i_rName ); + WriteStr( o_rFile, "</A>" ); + } +} + + +void +WriteStr( ofstream & o_rFile, + const char * i_sStr ) +{ + o_rFile.write( i_sStr, strlen(i_sStr) ); +} + +void +WriteStr( ofstream & o_rFile, + const Simstr & i_sStr ) +{ + o_rFile.write( i_sStr.str(), i_sStr.l() ); +} + diff --git a/xml2cmp/source/support/syshelp.hxx b/xml2cmp/source/support/syshelp.hxx new file mode 100644 index 000000000000..6b86d834b1ab --- /dev/null +++ b/xml2cmp/source/support/syshelp.hxx @@ -0,0 +1,68 @@ +/************************************************************************* +#* +#* $Workfile: syshelp.hxx $ +#* +#* class +#* +#* Beschreibung +#* +#* Ersterstellung NP +#* Letzte Aenderung $Author: np $ +#* $Date: 2001-03-09 15:22:59 $ +#* $Revision: 1.1 $ +#* +#* $Logfile: T:/solar/source/... $ +#* +#* Copyright (c) 2000, Star Office Gmbh +#* +#**************************************************************************/ + +#ifndef X2C_SYSHELP_HXX +#define X2C_SYSHELP_HXX + + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS + // PARAMETERS +class ofstream; +class Simstr; + + + +#ifdef WNT +const char C_sSLASH[] = "\\"; +const char C_cSLASH = '\\'; +#elif defined(UNX) +const char C_sSLASH[] = "/"; +const char C_cSLASH = '/'; +#else +#error Must run under unix or windows, please define UNX or WNT. +#endif + +enum E_LinkType +{ + lt_nolink = 0, + lt_idl, + lt_html +}; + + +void WriteName( + ofstream & o_rFile, + const Simstr & i_rIdlDocuBaseDir, + const Simstr & i_rName, + E_LinkType i_eLinkType ); + + +void WriteStr( + ofstream & o_rFile, + const char * i_sStr ); +void WriteStr( + ofstream & o_rFile, + const Simstr & i_sStr ); + + +#endif + diff --git a/xml2cmp/source/xcd/cr_html.cxx b/xml2cmp/source/xcd/cr_html.cxx new file mode 100644 index 000000000000..3916c170f1b6 --- /dev/null +++ b/xml2cmp/source/xcd/cr_html.cxx @@ -0,0 +1,355 @@ +/************************************************************************* + * + * $RCSfile: cr_html.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <fstream.h> +#include "cr_html.hxx" +#include "xmltree.hxx" +#include "../support/syshelp.hxx" + + + + + +char C_sHtmlFileHeader1[] = + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n" + "<HTML>\n" + "<HEAD>\n" + " <TITLE>"; + +char C_sHtmlFileHeader2[] = + "</TITLE>\n" + " <META NAME=\"GENERATOR\" CONTENT=\"xml2cmp\">\n" + "</HEAD>\n" + "<BODY BGCOLOR=\"#ffffff\">\n<P><BR></P>"; + + +char C_sHtmlFileFoot[] = "</BODY>\n</HTML>\n"; + + +HtmlCreator::HtmlCreator( const char * i_pOutputFileName, + const ModuleDescription & i_rDescr, + const Simstr & i_sIDL_BaseDirectory ) + : aFile(i_pOutputFileName, ios::out +#ifdef WNT + | ios::binary +#endif + ), + rDescr(i_rDescr), + sIdl_BaseDirectory(i_sIDL_BaseDirectory) +{ + if ( !aFile ) + { + cerr << "Error: " << i_pOutputFileName << " could not be created." << endl; + exit(0); + } +} + +HtmlCreator::~HtmlCreator() +{ + aFile.close(); +} + +void +HtmlCreator::Run() +{ + WriteStr( C_sHtmlFileHeader1 ); + WriteStr( "ModuleDescription" ); + WriteStr( C_sHtmlFileHeader2 ); + + StartTable(); + + const ParentElement::ChildList & rModuleElements = rDescr.Children(); + unsigned i_max = rModuleElements.size(); + + for (unsigned i = 0; i < i_max; i++) + { + Write_TextElement( *rModuleElements[i], lt_nolink ); // Name, + // ProjectBuildDependency, + // RuntimeModuleDependency + } // end for + + WriteStr( "<TR><TD COLSPAN=2>\n" + "<H4><BR>Components</H4>\n" ); + + const ModuleDescription::CD_List & rCDs = rDescr.Components(); + unsigned d_max = rCDs.size(); + for (unsigned d = 0; d < d_max; d++) + { + WriteStr( "<P><BR><BR></P>\n" ); + + Write_Description( *rCDs[d] ); + } // end for + + WriteStr( "</TD><TR>\n" ); + FinishTable(); + + WriteStr( "<P><BR><BR></P>\n" ); + WriteStr( C_sHtmlFileFoot ); +} + + +void +HtmlCreator::Write_Description( const ComponentDescription & i_rDescr ) +{ + StartTable(); + + const ParentElement::ChildList & rDescrElements = i_rDescr.Children(); + + unsigned i_max = rDescrElements.size(); + Write_TextElement( *rDescrElements[0], lt_nolink ); // Name + Write_TextElement( *rDescrElements[1], lt_nolink ); // Author + Write_TextElement( *rDescrElements[2], lt_nolink ); // Description + Write_TextElement( *rDescrElements[3], lt_idl ); // Loader Name + Write_TextElement( *rDescrElements[4], lt_nolink ); // Language + + Write_Status(i_rDescr.Status()); // Status + + for (unsigned i = 5; i < i_max; i++) + { + Write_TextElement( *rDescrElements[i], lt_idl ); // Supported Service, + // Service Dependency, + // Type + + } // end for + + const ComponentDescription::Docu_List & rDocuRefs = i_rDescr.DocuRefs(); + unsigned r_max = rDocuRefs.size(); + for (unsigned r = 0; r < r_max; r++) + { + Write_ReferenceDocu(*rDocuRefs[r]); + } // end for + + FinishTable(); +} + +void +HtmlCreator::Write_TextElement( TextElement & i_rElement, + E_LinkType i_eLinkType ) +{ + StartRow(); + + WriteElementName( i_rElement ); + WriteElementData( i_rElement, i_eLinkType ); + + FinishRow(); +} + +void +HtmlCreator::Write_ReferenceDocu( const ReferenceDocuElement & i_rRefDocu ) +{ + StartRow(); + + StartCell( "23%" ); + WriteStr("ReferenceDocu"); + FinishCell(); + + StartCell( "77%" ); + if ( i_rRefDocu.sAttr_href.l() > 0) + { + WriteStr("<A href=\"http://"); + WriteStr(i_rRefDocu.sAttr_href.str()); + WriteStr("\">"); + WriteStr(i_rRefDocu.sAttr_href.str()); + WriteStr("</A><BR>\n"); + } + if ( i_rRefDocu.sAttr_title.l() > 0) + { + WriteStr("Title: "); + WriteStr(i_rRefDocu.sAttr_title.str()); + WriteStr("<BR>\n"); + } + if ( i_rRefDocu.sAttr_role.l() > 0) + { + WriteStr("Role: "); + WriteStr(i_rRefDocu.sAttr_role.str()); + } + FinishCell(); + + FinishRow(); +} + +void +HtmlCreator::Write_Status(const char * i_sStatus) +{ + StartRow(); + + StartCell( "23%" ); + WriteStr("status"); + FinishCell(); + + StartCell( "77%"); + WriteName( aFile, sIdl_BaseDirectory, i_sStatus, lt_nolink ); + FinishCell(); + + FinishRow(); +} + +void +HtmlCreator::PrintH1( char * i_pText) +{ + static char sH1a[] = "<H1 ALIGN=CENTER>"; + static char sH1e[] = "</H1>"; + WriteStr(sH1a); + WriteStr(i_pText); + WriteStr(sH1e); +} + +void +HtmlCreator::StartTable() +{ + WriteStr( + "<TABLE WIDTH=95% BORDER=1 CELLSPACING=0 CELLPADDING=4>\n" + " <TBODY>\n" ); +} + +void +HtmlCreator::FinishTable() +{ + WriteStr( " </TBODY>\n" + "</TABLE>\n\n" ); +} + +void +HtmlCreator::StartRow() +{ + WriteStr( " <TR VALIGN=TOP>\n" ); +} + +void +HtmlCreator::FinishRow() +{ + WriteStr( " </TR>\n" ); +} + +void +HtmlCreator::StartCell( char * i_pWidth) +{ + WriteStr( " <TD WIDTH=" ); + WriteStr( i_pWidth ); + WriteStr( ">\n <P>" ); +} + +void +HtmlCreator::FinishCell() +{ + WriteStr( "</P>\n </TD>\n" ); +} + +void +HtmlCreator::WriteElementName( TextElement & i_rElement ) +{ + StartCell( "23%" ); + const char * pName = i_rElement.Name(); + bool bStrong = strcmp(pName,"name") == 0 || strcmp(pName,"module-name") == 0; + + if (bStrong) + WriteStr( "<H4>" ); + WriteStr(pName); + if (bStrong) + WriteStr( "</H4>" ); + FinishCell(); +} + +void +HtmlCreator::WriteElementData( TextElement & i_rElement, + E_LinkType i_eLinkType ) +{ + StartCell( "77%"); + + bool bStrong = strcmp(i_rElement.Name(),"name") == 0 || strcmp(i_rElement.Name(),"module-name") == 0; + + if (bStrong) + { + WriteStr( "<H4><A NAME=\"" ); + int nLen = strlen(i_rElement.Data()); + if ( *i_rElement.Name() == 'n') + { + const char * pEnd = strchr(i_rElement.Data(), ' '); + if (pEnd) + { + nLen = pEnd - i_rElement.Data(); + } + } + aFile.write( i_rElement.Data(), nLen ); + WriteStr( "\">" ); + } + + WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(), i_eLinkType ); + + if (bStrong) + WriteStr( "</A></H4>" ); + + + unsigned i_max = i_rElement.Size(); + if ( i_max > 1 ) + { + for ( unsigned i = 1; i < i_max; ++i ) + { + WriteStr( "<BR>\n" ); + WriteName( aFile, sIdl_BaseDirectory, i_rElement.Data(i), i_eLinkType ); + } // end for + } // end if + + FinishCell(); +} + + + diff --git a/xml2cmp/source/xcd/cr_html.hxx b/xml2cmp/source/xcd/cr_html.hxx new file mode 100644 index 000000000000..e17fc05d35fd --- /dev/null +++ b/xml2cmp/source/xcd/cr_html.hxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * $RCSfile: cr_html.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_CR_HTML_HXX +#define X2C_CR_HTML_HXX + + +#include <string.h> +#include <fstream.h> +#include "../support/sistr.hxx" +#include "../support/syshelp.hxx" + + +class ModuleDescription; +class ComponentDescription; +class TextElement; +class ReferenceDocuElement; + + +class HtmlCreator +{ + public: + HtmlCreator( + const char * i_pOutputFileName, + const ModuleDescription & + i_rDescr, + const Simstr & i_sIDL_BaseDirectory ); + ~HtmlCreator(); + + void Run(); + + private: + void PrintH1( + char * i_pText ); + void StartTable(); + void FinishTable(); + void StartRow(); + void FinishRow(); + void StartCell( + char * i_pWidth ); + void FinishCell(); + + + void Write_Description( + const ComponentDescription & + i_rDescr ); + void Write_TextElement( + TextElement & i_rElement, + E_LinkType i_eLinkType ); + void Write_ReferenceDocu( + const ReferenceDocuElement & + i_rRefDocu ); + void Write_Status( + const char * i_sStatus ); + void WriteElementName( + TextElement & i_rElement ); + void WriteElementData( + TextElement & i_rElement, + E_LinkType i_eLinkType ); + + void WriteStr( + const char * i_sStr ) + { aFile.write( i_sStr, strlen(i_sStr) ); } + // DATA + ofstream aFile; + const ModuleDescription & + rDescr; + Simstr sIdl_BaseDirectory; +}; + + + + +#endif diff --git a/xml2cmp/source/xcd/cr_index.cxx b/xml2cmp/source/xcd/cr_index.cxx new file mode 100644 index 000000000000..93369e6a48eb --- /dev/null +++ b/xml2cmp/source/xcd/cr_index.cxx @@ -0,0 +1,456 @@ +/************************************************************************* + * + * $RCSfile: cr_index.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include "cr_index.hxx" + +#include <string.h> +#include <fstream.h> +#include "../support/syshelp.hxx" +#include "xmltree.hxx" +#include "parse.hxx" +#include "cr_html.hxx" + + +char C_sLineEnd[] = "\n"; + +char C_sFileBegin[] = "<HTML><HEAD></HEAD><BODY bgcolor=\"#ffffff\">\n"; +char C_sFileEnd[] = "</BODY></HTML>\n"; +char C_sTableBegin[] = "<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=0><TBODY>\n"; +char C_sTableEnd[] = "</TBODY></TABLE>\n"; +char C_sService[] = "SupportedService"; +char C_sModule[] = "ModuleName"; +char C_sComponentname[] = "ComponentName"; + + +int NrOfTagName(const char * i_sName); + + +Simstr sIdlRootPath; + +void WriteTableFromHeap( + ofstream & o_rOut, + Heap & i_rHeap, + const char * i_sIndexKey, + const char * i_sIndexReference, + E_LinkType i_eLinkType ); +void WriteHeap( + ofstream & o_rOut, + Heap & i_rHeap, + E_LinkType i_eLinkType ); + + +Index::Index( const char * i_sOutputDirectory, + const char * i_sIdlRootPath, + const List<Simstr> & i_rTagList ) + : aService2Module(20), + aModule2Service(20), + aTagIndices(i_rTagList), + sOutputDirectory(i_sOutputDirectory), + sIdlRootPath(i_sIdlRootPath) +{ + ::sIdlRootPath = i_sIdlRootPath; +} + +Index::IndexedTags::IndexedTags( const List<Simstr> & i_rTagList ) + : nSize(i_rTagList.size()) +{ + aTagHeaps.reserve(nSize); + aTagNames.reserve(nSize); + + for (int h = 0; h < C_nNrOfTagNames; ++h ) + { + aHeapsPerIndex[h] = 0; + } + + for ( unsigned i = 0; i < nSize; ++i ) + { + int nNr = NrOfTagName(i_rTagList[i]); + if ( nNr > -1 ) + { + Heap * pNew = new Heap(20); + aTagHeaps.push_back( pNew ); + aTagNames.push_back( i_rTagList[i] ); + aHeapsPerIndex[nNr] = pNew; + } + else + { + cerr << "Warning: It is not possible to create an index for the tag " + << i_rTagList[i] + << "." + << endl; + } + } // end for +} + +Index::~Index() +{ +} + +Index::IndexedTags::~IndexedTags() +{ +} + +Heap * +Index::IndexedTags::HeapFor( const char * i_sTagName ) +{ + int nNr = NrOfTagName(i_sTagName); + if (nNr > -1 ) + return aHeapsPerIndex[nNr]; + return 0; +} + +void +Index::GatherData( const List<Simstr> & i_rInputFileList ) +{ + for ( unsigned i = 0; i < i_rInputFileList.size(); ++i ) + { + ReadFile( i_rInputFileList[i].str() ); + } +} + +void +Index::WriteOutput( const char * i_sOuputFile ) +{ + ofstream aOut( i_sOuputFile, ios::out ); + if (! aOut) + { + cerr << "Error: Indexfile \"" + << i_sOuputFile + << "\" could not be created." + << endl; + return; + } + + WriteStr(aOut, C_sFileBegin); + + WriteStr(aOut, "<H2>Module Descriptions Index</H2>"); + WriteStr(aOut, C_sLineEnd ); + + + WriteTableFromHeap( aOut, aService2Module, C_sService, C_sModule, lt_html ); + WriteTableFromHeap( aOut, aModule2Service, C_sModule, C_sService, lt_idl ); + + for ( unsigned i = 0; i < aTagIndices.nSize; ++i ) + { + WriteTableFromHeap( aOut, *aTagIndices.aTagHeaps[i], + aTagIndices.aTagNames[i], C_sComponentname, lt_html ); + } + + WriteStr( aOut, C_sFileEnd ); + aOut.close(); +} + +void +Index::ReadFile( const char * i_sFilename ) +{ + static char sOutputHtml[1020]; + + ModuleDescription aModule; + X2CParser aParser(aModule); + + if ( ! aParser.Parse(i_sFilename) ) + { + cerr << "Error: File \"" + << i_sFilename + << "\" could not be parsed." + << endl; + return; + } + + // Create Html: + CreateHtmlFileName( sOutputHtml, aModule ); + HtmlCreator aHtmlCreator( sOutputHtml, aModule, sIdlRootPath ); + aHtmlCreator.Run(); + + // GetResults: + Simstr sModuleName = aModule.Name(); + + // Module Tags + const ModuleDescription::ChildList & + rModuleElements = aModule.Children(); + for ( unsigned mi = 1; mi < rModuleElements.size(); ++mi ) + { + Heap * pHeap = aTagIndices.HeapFor(rModuleElements[mi]->Name()); + if (pHeap != 0) + { + unsigned nDatSize = rModuleElements[mi]->Size(); + for ( unsigned d = 0; d < nDatSize; ++d ) + { + pHeap->InsertValue( rModuleElements[mi]->Data(d), sModuleName.str() ); + } + } + } // end for + + // Component Tags + const ModuleDescription::CD_List & + rCDs = aModule.Components(); + static char sCD_inModule[1020]; + strcpy( sCD_inModule, sModuleName.str() ); + strcat( sCD_inModule, "," ); + char * pCut = strchr(sCD_inModule,',') + 1; + + for ( unsigned cd = 0; cd < rCDs.size(); ++cd ) + { + const ComponentDescription::ChildList & + rCD_Elements = rCDs[cd]->Children(); + strcpy( pCut, rCDs[cd]->Name() ); + for ( unsigned ci = 1; ci < rCD_Elements.size(); ++ci ) + { + if ( ci == 5 ) + { + TextElement * pElem = rCD_Elements[ci]; + unsigned nDatSize = pElem->Size(); + for ( unsigned d = 0; d < nDatSize; ++d ) + { + aService2Module.InsertValue( + pElem->Data(d), + sModuleName ); + aModule2Service.InsertValue( + sModuleName, + pElem->Data(d) ); + } + } + else + { + Heap * pHeap = aTagIndices.HeapFor(rCD_Elements[ci]->Name()); + if (pHeap != 0) + { + unsigned nDatSize = rCD_Elements[ci]->Size(); + for ( unsigned d = 0; d < nDatSize; ++d ) + { + pHeap->InsertValue( rCD_Elements[ci]->Data(d), sCD_inModule ); + } + } + } // end if (ci == 6) else + } // end for + } // for +} + +void +Index::CreateHtmlFileName( char * o_sOutputHtml, + const ModuleDescription & i_rModule ) +{ + strcpy( o_sOutputHtml, sOutputDirectory.str() ); +#ifdef WNT + strcat(o_sOutputHtml, "\\"); +#elif defined(UNX) + strcat(o_sOutputHtml, "/"); +#else +#error WNT or UNX have to be defined. +#endif + strcat( o_sOutputHtml, i_rModule.Name() ); + strcat( o_sOutputHtml, ".html" ); +} + + +void +WriteTableFromHeap( ofstream & o_rOut, + Heap & i_rHeap, + const char * i_sIndexValue, + const char * i_sIndexReference, + E_LinkType i_eLinkType ) +{ + WriteStr(o_rOut, "<H3><BR>"); + WriteStr(o_rOut, i_sIndexValue ); + WriteStr(o_rOut, " -> "); + WriteStr(o_rOut, i_sIndexReference ); + WriteStr(o_rOut, "</H3>\n"); + + WriteStr(o_rOut, C_sTableBegin); + WriteHeap( o_rOut, i_rHeap, i_eLinkType ); + WriteStr(o_rOut, C_sTableEnd); +} + + +void +WriteHeap( ofstream & o_rOut, + Heap & i_rHeap, + E_LinkType i_eLinkType ) +{ + static Simstr S_sKey; + static char C_sSpaceInName[] = " "; + S_sKey = ""; + + + WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" ); + + for ( HeapItem * pHeapTop = i_rHeap.ReleaseTop(); + pHeapTop != 0; + pHeapTop = i_rHeap.ReleaseTop() ) + { + if ( S_sKey != pHeapTop->Key() ) + { + const char * pStart = pHeapTop->Key().str(); + const char * pBreak = strstr( pStart, " in "); + + if (S_sKey.l()>0) + { + WriteStr( o_rOut, "</TD></TR>\n" ); + WriteStr( o_rOut, "<TR><TD width=33% valign=\"top\">" ); + } + + if ( pBreak == 0 ) + WriteStr( o_rOut, pStart ); + else + { + o_rOut.write( pStart, pBreak - pStart ); + WriteStr( o_rOut, C_sSpaceInName ); + WriteStr( o_rOut, pBreak ); + } + WriteStr( o_rOut, "</TD><TD width=66%>" ); + S_sKey = pHeapTop->Key(); + } + else + { + WriteStr( o_rOut, "<BR>" ); + } + WriteName( o_rOut, sIdlRootPath, pHeapTop->Value(), i_eLinkType ); + delete pHeapTop; + } + + WriteStr( o_rOut, "</TD></TR>\n" ); +} + +int +NrOfTagName( const char * i_sName ) +{ + static const char * aTagNames[C_nNrOfTagNames] = + { +// "module-name", // 1 + "author", // 1 0 +// "name", // 1 +// "description", // 1 + "loader-name", // 1 1 + "language", // 1 2 +// "status", + "supported-service", // + 3 +// "reference-docu", + "service-dependency", // * 4 + "type", // * 5 + "project-build-dependency", // * 6 + "runtime-module-dependency", // * 7 + }; + if (! i_sName) + return -1; + + switch (*i_sName) + { + case 'a': if ( strcmp( aTagNames[0], i_sName ) == 0 ) + return 0; + break; + case 'l': if ( strcmp( aTagNames[1], i_sName ) == 0 ) + return 1; + else if ( strcmp( aTagNames[2], i_sName ) == 0 ) + return 1; + break; + case 's': if ( strcmp( aTagNames[3], i_sName ) == 0 ) + return 3; + else if ( strcmp( aTagNames[4], i_sName ) == 0 ) + return 4; + break; + case 't': if ( strcmp( aTagNames[5], i_sName ) == 0 ) + return 5; + break; + case 'p': if ( strcmp( aTagNames[6], i_sName ) == 0 ) + return 6; + break; + case 'r': if ( strcmp( aTagNames[7], i_sName ) == 0 ) + return 7; + break; + } + return -1; +} + + + + + +/** Übersicht der Struktur + +MODULEDESCRIPTION +{ + ModuleName, + COMPONENTDESCRIPTION + { + Author, + Name, + Description, + LoaderName, + Language, + Status, + SupportedService+, + ReferenceDocu* + ServiceDependency* + Type* + } + ProjectBuildDependency* + RuntimeModuleDependency* +} + + +*/ + + + + + + diff --git a/xml2cmp/source/xcd/cr_index.hxx b/xml2cmp/source/xcd/cr_index.hxx new file mode 100644 index 000000000000..0a4e5925d2b6 --- /dev/null +++ b/xml2cmp/source/xcd/cr_index.hxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * $RCSfile: cr_index.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_CR_INDEX_HXX +#define X2C_CR_INDEX_HXX + +#include "../support/sistr.hxx" +#include "../support/heap.hxx" +#include "../support/list.hxx" + + +const unsigned C_nNrOfTagNames = 8; +class ModuleDescription; + + +class Index +{ + public: + Index( + const char * i_sOutputDirectory, + const char * i_sIdlRootPath, + const List<Simstr> & + i_rTagList ); + ~Index(); + + void GatherData( + const List<Simstr> & + i_rInputFileList ); + void WriteOutput( + const char * i_sOuputFile ); + + private: + struct IndexedTags + { + public: + IndexedTags( + const List<Simstr> & + i_rTagList ); + ~IndexedTags(); + + Heap * HeapFor( + const char * i_sTagName ); + + DynamicList< Heap > + aTagHeaps; + List< Simstr > aTagNames; + unsigned nSize; + + private: + Heap * aHeapsPerIndex[C_nNrOfTagNames]; + }; + + void ReadFile( + const char * i_sFilename ); + void CreateHtmlFileName( + char * o_sOutputHtml, + const ModuleDescription & + i_rModule ); + + Heap aService2Module; + Heap aModule2Service; + IndexedTags aTagIndices; + + Simstr sOutputDirectory; + Simstr sIdlRootPath; +}; + + + + +#endif + + diff --git a/xml2cmp/source/xcd/cr_metho.cxx b/xml2cmp/source/xcd/cr_metho.cxx new file mode 100644 index 000000000000..86863b802a84 --- /dev/null +++ b/xml2cmp/source/xcd/cr_metho.cxx @@ -0,0 +1,137 @@ +/************************************************************************* + * + * $RCSfile: cr_metho.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "cr_metho.hxx" + +#include <string.h> +#include <iostream.h> +#include <fstream.h> + + +char C_sFileHeader1[] = "/* "; +char C_sFileHeader2[] = " */\r\n/* Implementation of component_getDescriptionFunc() */\r\n\r\n" + "#include <sal/types.h>\r\n\r\n"; +char C_sFuncBegin[] = "#ifdef __cplusplus\r\n" + "extern \"C\" {\r\n" + "#endif\r\n\r\n" + "const sal_Char * SAL_CALL\ncomponent_getDescriptionFunc()\r\n" + "{\r\n" + " return (sal_Char*) \r\n" + " \""; +char C_sFuncEnd[] = "\";\r\n" + "}\r\n\r\n" + "#ifdef __cplusplus\r\n" + "} /* end of extern \"C\" */\r\n" + "#endif\r\n"; + + +void +Create_AccessMethod( const char * i_pOutputFileName, + const char * i_sText ) +{ + const char * pText = i_sText; + const char * pTrans = 0; + char sDescrLineChange[] = "\"\r\n \""; + int sDescrLen = strlen(sDescrLineChange); + + ofstream aFile(i_pOutputFileName, ios::out +#ifdef WNT + | ios::binary +#endif + ); + + + if ( !aFile ) + { + cerr << "Error: " << i_pOutputFileName << " could not be created." << endl; + return; + } + + aFile.write( C_sFileHeader1, strlen(C_sFileHeader1) ); + aFile.write( i_pOutputFileName, strlen(i_pOutputFileName) ); + aFile.write( C_sFileHeader2, strlen(C_sFileHeader2) ); + aFile.write( C_sFuncBegin, strlen(C_sFuncBegin) ); + + for ( pTrans = pText; *pTrans != '\0'; pTrans++ ) + { + switch (*pTrans) + { + case '"': aFile.write( "\\\"", 2); + break; + case '\n': aFile.write( "\\n", 2); + aFile.write( sDescrLineChange, sDescrLen); + break; + case '\r': aFile.write( "\\r", 2); + break; +// case '\t': aFile.write( "\\t", 2); +// break; + default: aFile.write( pTrans, 1); + } + } /* end for */ + + aFile.write( C_sFuncEnd, strlen(C_sFuncEnd) ); + + + aFile.close(); +} + + + diff --git a/xml2cmp/source/xcd/cr_metho.hxx b/xml2cmp/source/xcd/cr_metho.hxx new file mode 100644 index 000000000000..ba96ad1de102 --- /dev/null +++ b/xml2cmp/source/xcd/cr_metho.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * $RCSfile: cr_metho.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef CPV_CR_METHOD_H +#define CPV_CR_METHOD_H + + + +void Create_AccessMethod( + const char * i_pOutputFileName, + const char * i_sText ); + +#endif diff --git a/xml2cmp/source/xcd/filebuff.cxx b/xml2cmp/source/xcd/filebuff.cxx new file mode 100644 index 000000000000..7487f8f218b7 --- /dev/null +++ b/xml2cmp/source/xcd/filebuff.cxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * $RCSfile: filebuff.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include "filebuff.hxx" + +#include <string.h> +#include <fstream.h> +#include <ctype.h> + + +bool +LoadXmlFile( Buffer & o_rBuffer, + const char * i_sXmlFilePath ) +{ + ifstream aXmlFile; + + aXmlFile.open(i_sXmlFilePath, ios::in +#ifdef WNT + | ios::binary +#endif // WNT + ); + + if (! aXmlFile) + return false; + + // Prepare buffer: + aXmlFile.seekg(0, ios::end); + unsigned long nBufferSize = aXmlFile.tellg(); + o_rBuffer.SetSize(nBufferSize + 1); + o_rBuffer.Data()[nBufferSize] = '\0'; + aXmlFile.seekg(0); + + // Read file: + aXmlFile.read(o_rBuffer.Data(), nBufferSize); + bool ret = aXmlFile.good() != 0; + aXmlFile.close(); + return ret; +} + + diff --git a/xml2cmp/source/xcd/filebuff.hxx b/xml2cmp/source/xcd/filebuff.hxx new file mode 100644 index 000000000000..fa6fe8736828 --- /dev/null +++ b/xml2cmp/source/xcd/filebuff.hxx @@ -0,0 +1,89 @@ +/************************************************************************* + * + * $RCSfile: filebuff.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_FILEBUFF_HXX +#define X2C_FILEBUFF_HXX + + +class Buffer +{ + public: + Buffer() : s(0) {} + ~Buffer() { if (s) delete [] s; } + operator const char *() const + { return s; } + char * Data() { return s; } + void SetSize( + long i_size ) + { if (s) delete [] s; s = new char [i_size]; } + private: + char * s; +}; + + +bool LoadXmlFile( + Buffer & o_rBuffer, + const char * i_sXmlFilePath ); + + + +#endif + diff --git a/xml2cmp/source/xcd/main.cxx b/xml2cmp/source/xcd/main.cxx new file mode 100644 index 000000000000..5fd1a1768183 --- /dev/null +++ b/xml2cmp/source/xcd/main.cxx @@ -0,0 +1,410 @@ +/************************************************************************* + * + * $RCSfile: main.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <stdio.h> + +#include <string.h> +#include "../support/cmdline.hxx" +#include "cr_metho.hxx" +#include "cr_html.hxx" +#include "cr_index.hxx" +#include "xmltree.hxx" +#include "parse.hxx" +#include "../support/syshelp.hxx" +#include "../support/heap.hxx" + + +#ifdef WNT +#include <io.h> +#elif defined(UNX) +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#else +#error Must run under unix or windows, please define UNX or WNT. +#endif + + + + +int Do_IndexCommandLine( + const CommandLine & i_rCommandLine ); +int Do_SingleFileCommandLine( + const CommandLine & i_rCommandLine ); +void GatherFileNames( + List<Simstr> & o_sFiles, + const char * i_sSrcDirectory ); +void GatherSubDirectories( + List<Simstr> & o_sSubDirectories, + const char * i_sParentdDirectory ); +void Create_TypeInfoFile( + const char * o_sOutputFile, + ModuleDescription & i_rData ); + + +int +#ifdef WNT +_cdecl +#endif +main( int argc, + char * argv[] ) +{ + // Variables + CommandLine aCommandLine(argc, argv); + int ret = 0; + + if (! aCommandLine.IsOk()) + { + cerr << aCommandLine.ErrorText() << endl; + return 1; + } + + if ( aCommandLine.IsIndexCommand() ) + ret = Do_IndexCommandLine(aCommandLine); + else + ret = Do_SingleFileCommandLine(aCommandLine); + + return ret; +} + + +int +Do_SingleFileCommandLine(const CommandLine & i_rCommandLine) +{ + ModuleDescription aDescr; + X2CParser aParser(aDescr); + + // Parse + bool bParseResult = aParser.Parse(i_rCommandLine.XmlSrcFile()); + if (! bParseResult) + { + cerr << "Error: File %s could not be parsed." << i_rCommandLine.XmlSrcFile() << endl; + return 1; + } + + // Produce output + if ( strlen(i_rCommandLine.FuncFile()) > 0 ) + { + Create_AccessMethod( i_rCommandLine.FuncFile(), + aParser.PureText() ); + } + if ( strlen(i_rCommandLine.HtmlFile()) > 0 ) + { + HtmlCreator aHtmlCreator( i_rCommandLine.HtmlFile(), + aDescr, + i_rCommandLine.IdlRootPath() ); + aHtmlCreator.Run(); + } + + if (strlen(i_rCommandLine.TypeInfoFile()) > 0) + { + Create_TypeInfoFile( i_rCommandLine.TypeInfoFile() , + aDescr ); + } + + return 0; +}; + +int +Do_IndexCommandLine(const CommandLine & i_rCommandLine) +{ + // Parsen files: + List<Simstr> aFiles; + Index aIndex( i_rCommandLine.OutputDirectory(), + i_rCommandLine.IdlRootPath(), + i_rCommandLine.IndexedTags() ); + + cout << "Gather xml-files ..." << endl; + GatherFileNames( aFiles, i_rCommandLine.XmlSrcDirectory() ); + + cout << "Create output ..." << endl; + aIndex.GatherData(aFiles); + aIndex.WriteOutput( i_rCommandLine.IndexOutputFile() ); + + cout << "... done." << endl; + + return 0; +}; + + +const char C_sXML_END[] = "\\*.xml"; + +void +GatherFileNames( List<Simstr> & o_sFiles, + const char * i_sSrcDirectory ) +{ + static int nAliveCounter = 0; + + char * sNextDir = 0; + Simstr sNew = 0; + +#ifdef WNT + struct _finddata_t aEntry; + long hFile = 0; + int bFindMore = 0; + char * sFilter = new char[ strlen(i_sSrcDirectory) + sizeof C_sXML_END ]; + + // Stayingalive sign + if (++nAliveCounter % 100 == 1) + fprintf(stdout,"."); + + strcpy(sFilter, i_sSrcDirectory); + strcat(sFilter,C_sXML_END); + + hFile = _findfirst( sFilter, &aEntry ); + for ( bFindMore = hFile == -1; + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + sNew = i_sSrcDirectory; + sNew += "\\"; + sNew += aEntry.name; + o_sFiles.push_back(sNew); + } // end for + + _findclose(hFile); + delete [] sFilter; +#elif defined(UNX) + struct DIR * pDir = opendir( i_sSrcDirectory ); + struct dirent * pEntry = 0; + char * sEnding; + + while ( pEntry = readdir(pDir) != 0 ) + { + sEnding = strrchr(pEntry->d_name,'.'); + if (sEnding != 0 ? stricmp(sEnding,".xml") == 0 : False ) + { + sNew = i_sSrcDirectory; + sNew += "/"; + sNew += pEntry->d_name; + o_sFiles.push_back(sNew); + } + } // end while + + closedir( pDir ); +#else +#error Must run on unix or windows, please define UNX or WNT. +#endif + + // gathering from subdirectories: + List<Simstr> aSubDirectories; + GatherSubDirectories( aSubDirectories, i_sSrcDirectory ); + + unsigned d_max = aSubDirectories.size(); + for ( unsigned d = 0; d < d_max; ++d ) + { + sNextDir = new char[ strlen(i_sSrcDirectory) + 2 + aSubDirectories[d].l() ]; + + strcpy(sNextDir, i_sSrcDirectory); + strcat(sNextDir, C_sSLASH); + strcat(sNextDir, aSubDirectories[d].str()); + GatherFileNames(o_sFiles, sNextDir); + + delete [] sNextDir; + } +} + + +const char * C_sANYDIR = "\\*.*"; + +void +GatherSubDirectories( List<Simstr> & o_sSubDirectories, + const char * i_sParentdDirectory ) +{ + Simstr sNew; + +#ifdef WNT + struct _finddata_t aEntry; + long hFile = 0; + int bFindMore = 0; + char * sFilter = new char[strlen(i_sParentdDirectory) + sizeof C_sANYDIR]; + + strcpy(sFilter, i_sParentdDirectory); + strcat(sFilter,C_sANYDIR); + + hFile = _findfirst( sFilter, &aEntry ); + for ( bFindMore = hFile == -1; + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + if (aEntry.attrib == _A_SUBDIR) + { + // Do not gather . .. and outputtree directories + if ( strchr(aEntry.name,'.') == 0 + && strncmp(aEntry.name, "wnt", 3) != 0 + && strncmp(aEntry.name, "unx", 3) != 0 ) + { + sNew = aEntry.name; + o_sSubDirectories.push_back(sNew); + } + } // endif (aEntry.attrib == _A_SUBDIR) + } // end for + _findclose(hFile); + delete [] sFilter; + +#elif defined(UNX) + struct DIR * pDir = opendir( i_sParentdDirectory ); + struct dirent * pEntry = 0; + struct stat aEntryStatus; + char * sEnding; + + while ( pEntry = readdir(pDir) != 0 ) + { + stat(pEntry->d_name, &aEntryStatus); + if ( ( aEntryStatus.st_mode & S_IFDIR ) == S_IFDIR ) + { + // Do not gather . .. and outputtree directories + if ( strchr(pEntry->d_name,'.') == 0 + && strncmp(pEntry->d_name, "wnt", 3) != 0 + && strncmp(pEntry->d_name, "unx", 3) != 0 ) + { + sNew = pEntry->d_name; + o_sSubDirectories.push_back(pNew); + } + } // endif (aEntry.attrib == _A_SUBDIR) + } // end while + closedir( pDir ); +#else +#error Must run on unix or windows, please define UNX or WNT. +#endif +} + + + +void +Create_TypeInfoFile( const char * o_sOutputFile, + ModuleDescription & i_rData ) +{ + ofstream aOut(o_sOutputFile, ios::out +#ifdef WNT + | ios::binary +#endif + ); + if ( !aOut ) + { + cerr << "Error: " << o_sOutputFile << " could not be created." << endl; + return; + } + + Heap aTypesHeap(12); + Simstr sLibPrefix = i_rData.Children()[0]->Data(); + + // Gather types: + const ModuleDescription::CD_List & rListDescriptions = i_rData.Components(); + + // Descriptions: + for ( unsigned nDescrIter = 0; nDescrIter < rListDescriptions.size(); ++nDescrIter ) + { + // Find Type-Tag: + TextElement * pTypes = 0; + ComponentDescription::ChildList & rTags = rListDescriptions[nDescrIter]->Children(); + for ( unsigned nTagIter = 0; nTagIter < rTags.size(); ++nTagIter ) + { + if ( strcmp( rTags[nTagIter]->Name(),"type") == 0 ) + { + pTypes = rTags[nTagIter]; + break; + } + } // end for (aTagIter) + + if ( pTypes != 0) + { + for ( unsigned nTypeIter = 0; nTypeIter < pTypes->Size(); ++nTypeIter ) + { // Loop Services + aTypesHeap.InsertValue( pTypes->Data(nTypeIter), "" ); + } // end for aDataIter + } + } // end for (aDescrIter) + + // Write types: + WriteStr( aOut, sLibPrefix ); + WriteStr( aOut, "_XML2CMPTYPES= "); + + HeapItem * pLastHeapTop = 0; + for ( HeapItem * pHeapTop = aTypesHeap.ReleaseTop(); pHeapTop != 0; pHeapTop = aTypesHeap.ReleaseTop() ) + { + if (pLastHeapTop != 0) + { + if ( 0 == strcmp(pHeapTop->Key(), pLastHeapTop->Key()) ) + continue; + delete pLastHeapTop; + // pLastHeapTop = 0; + } + pLastHeapTop = pHeapTop; + + WriteStr( aOut, "\t\\\n\t\t" ); + + const char * sEnd = strchr( pHeapTop->Key(), ' ' ); + if (sEnd != 0) + aOut.write( pHeapTop->Key(), sEnd - pHeapTop->Key() ); + else + WriteStr( aOut, pHeapTop->Key() ); + } // end for + + if (pLastHeapTop != 0) + { + delete pLastHeapTop; + pLastHeapTop = 0; + } + + aOut.close(); +} + diff --git a/xml2cmp/source/xcd/makefile.mk b/xml2cmp/source/xcd/makefile.mk new file mode 100644 index 000000000000..d5bbff38ed32 --- /dev/null +++ b/xml2cmp/source/xcd/makefile.mk @@ -0,0 +1,96 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1 $ +# +# last change: $Author: np $ $Date: 2001-03-09 15:23:00 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=xml2cmp +TARGET=x2c_xcd +TARGETTYPE=CUI + + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/main.obj \ + $(OBJ)$/cr_html.obj \ + $(OBJ)$/cr_index.obj \ + $(OBJ)$/cr_metho.obj \ + $(OBJ)$/filebuff.obj \ + $(OBJ)$/parse.obj \ + $(OBJ)$/xmltree.obj + + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/xml2cmp/source/xcd/parse.cxx b/xml2cmp/source/xcd/parse.cxx new file mode 100644 index 000000000000..63cb2ca6b17e --- /dev/null +++ b/xml2cmp/source/xcd/parse.cxx @@ -0,0 +1,422 @@ +/************************************************************************* + * + * $RCSfile: parse.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $Date: $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include <parse.hxx> + +#include <string.h> +#include <ostream.h> +#include <xmltree.hxx> + + +// NOT FULLY DEFINED SERVICES + +char C_sMODULEDESCRIPTION[] = "module-description"; +char C_sCOMPONENTDESCRIPTION[] = "component-description"; +char C_sAuthor[] = "author"; +char C_sName[] = "name"; +char C_sDescription[] = "description"; +char C_sReferenceDocu[] = "reference-docu"; +char C_sModuleName[] = "module-name"; +char C_sLoaderName[] = "loader-name"; +char C_sSupportedService[] = "supported-service"; +char C_sServiceDependency[] = "service-dependency"; +char C_sProjectBuildDependency[] = "project-build-dependency"; +char C_sRuntimeModuleDependency[] = "runtime-module-dependency"; +char C_sLanguage[] = "language"; +char C_sStatus[] = "status"; +char C_sType[] = "type"; + + + +#define AssertionOf(x) \ + {if (!(x)) {cerr << "Assertion failed: " << #x << __FILE__ << __LINE__ << endl; exit(3); }} +#define SyntaxAssertion(x,file) \ + {if (!(x)) {cerr << "Syntax error in file: " << #file << endl; exit(3); }} + + + +X2CParser::X2CParser( ModuleDescription & o_rData ) + : pData(&o_rData) +{ +} + +X2CParser::~X2CParser() +{ +} + +bool +X2CParser::Parse( const char * i_sFilename ) +{ + // Load file: + if ( ! LoadXmlFile( aFile, i_sFilename ) ) + return false; + + // Test correct end: + const char * pLastTag = strrchr(aFile.operator const char *(),'<'); + if (pLastTag == 0) + return false; + if ( strnicmp(pLastTag+2, C_sMODULEDESCRIPTION, strlen(C_sMODULEDESCRIPTION)) != 0 + || strnicmp(pLastTag, "</", 2) != 0 ) + return false; + if (strchr(pLastTag,'>') == 0) + return false; + + // Parse: + text = aFile.operator const char *(); + + Parse_XmlDeclaration(); + Parse_Doctype(); + Parse_ModuleDescription(); + + return true; +} + +void +X2CParser::Parse_XmlDeclaration() +{ + Goto('<'); + if ( IsText("<?xml") ) + { + Goto_And_Pass('>'); + } +} + +void +X2CParser::Parse_Doctype() +{ + Goto('<'); + if ( IsText("<!DOCTYPE") ) + Goto_And_Pass('>'); +} + +void +X2CParser::Parse_ModuleDescription() +{ + Goto('<'); + AssertionOf( IsBeginTag(C_sMODULEDESCRIPTION) ); + Goto_And_Pass('>'); + + Parse_TextElement(C_sModuleName,*pData, true, false); + + for ( Goto('<'); + IsBeginTag(C_sCOMPONENTDESCRIPTION); + Goto('<') ) + { + Parse_ComponentDescription(*pData); + } + + for ( ; ! IsEndTag(C_sMODULEDESCRIPTION); Goto('<') ) + { + if ( IsBeginTag(C_sProjectBuildDependency) ) + Parse_TextElement(C_sProjectBuildDependency,*pData,false,false); + else if ( IsBeginTag(C_sRuntimeModuleDependency) ) + Parse_TextElement(C_sRuntimeModuleDependency,*pData,false,false); + } + Goto_And_Pass('>'); +} + +void +X2CParser::Parse_ComponentDescription(ModuleDescription & o_rParent) +{ + Goto('<'); + AssertionOf( IsBeginTag(C_sCOMPONENTDESCRIPTION) ); + Goto_And_Pass('>'); + + ComponentDescription * dpCD = new ComponentDescription; + o_rParent.AddComponentDescription(*dpCD); + + Parse_TextElement(C_sAuthor,*dpCD,true,false); + Parse_TextElement(C_sName,*dpCD,true,true); + Parse_TextElement(C_sDescription,*dpCD,true,false); + Parse_TextElement(C_sLoaderName,*dpCD,true,true); + Parse_TextElement(C_sLanguage,*dpCD,true,false); + Parse_Status(*dpCD); + for ( Goto('<'); + IsBeginTag(C_sSupportedService); + Goto('<') ) + { + Parse_TextElement(C_sSupportedService,*dpCD,false,true); + } + + for ( Goto('<'); + ! IsEndTag(C_sCOMPONENTDESCRIPTION); + Goto('<') ) + { + if ( IsBeginTag(C_sReferenceDocu) ) + { + ReferenceDocuElement * pNewElem = new ReferenceDocuElement; + Parse_ReferenceDocu(*pNewElem); + dpCD->DocuRefs().push_back(pNewElem); + } + else if ( IsBeginTag(C_sServiceDependency) ) + Parse_TextElement(C_sServiceDependency,*dpCD,false,true); + else if ( IsBeginTag(C_sType) ) + Parse_TextElement(C_sType,*dpCD,false,true); + } + Goto_And_Pass('>'); + + // Take Name to front: + ParentElement::ChildList & rDescrElements = dpCD->Children(); + TextElement * pTE = rDescrElements[0]; + rDescrElements[0] = rDescrElements[1]; + rDescrElements[1] = pTE; +} + +void +X2CParser::Parse_ReferenceDocu(ReferenceDocuElement & o_rElement) +{ + Move( strlen(C_sReferenceDocu) + 1 ); + + for ( Pass_White(); *text != '/'; Pass_White() ) + { + Get_ReferenceDocuAttribute(o_rElement); + } + Move(1); +} + +void +X2CParser::Parse_TextElement( const char * i_sElementName, + ParentElement & o_rParent, + bool i_bSingle, + bool i_bReverseName ) +{ + Goto('<'); + text++; + AssertionOf( IsText(i_sElementName) ); + Goto_And_Pass('>'); + Pass_White(); + + TextElement * pNew = 0; + + if ( !i_bSingle && o_rParent.Children().size() > 0 ) + { + if ( strcmp( o_rParent.Children().back()->Name(), + i_sElementName ) == 0 ) + { + pNew = o_rParent.Children().back(); + } + } + if (pNew == 0) + { + pNew = i_bSingle + ? (TextElement*) new SglTextElement(i_sElementName) + : (TextElement*) new MultipleTextElement(i_sElementName); + o_rParent.AddChild(*pNew); + } + + // Add new Element + Simstr sText; + GetTextTill( sText, '<', i_bReverseName ); + sText.remove_trailing_blanks(); + pNew->SetText(sText); + + AssertionOf( IsText("</") ); + Move(2); + AssertionOf( IsText(i_sElementName) ); + Goto_And_Pass('>'); +} + +void +X2CParser::Parse_Status( ComponentDescription & o_rParent ) +{ + Goto('<'); + AssertionOf( IsBeginTag(C_sStatus) ); + Move( strlen(C_sStatus) + 1 ); + + Pass_White(); + AssertionOf(*text != '>'); + Simstr sAttrName; + Simstr sAttrValue = Get_Attribute(sAttrName); + o_rParent.SetStatus(sAttrValue); + + Move(2); +} + +void +X2CParser::Get_ReferenceDocuAttribute( ReferenceDocuElement & o_rElement ) +{ + Simstr sAttrName; + Simstr sAttrValue = Get_Attribute(sAttrName); + if ( strcmp( sAttrName.str(), "xlink:href") == 0 ) + o_rElement.sAttr_href = sAttrValue; + else if ( strcmp( sAttrName.str(), "xlink:role") == 0 ) + o_rElement.sAttr_role = sAttrValue; + else if ( strcmp( sAttrName.str(), "xlink:title") == 0 ) + o_rElement.sAttr_title = sAttrValue; +} + +Simstr +X2CParser::Get_Attribute( Simstr & o_rAttrName ) +{ + GetTextTill( o_rAttrName, '='); + + while (*(++text) != '"') + { + AssertionOf(*text != '\0'); + } + + ++text; + Simstr ret; + GetTextTill( ret, '"'); + ++text; + return ret; +} + +bool +X2CParser::IsText( const char * i_sComparedText ) +{ + return strnicmp( text, i_sComparedText, strlen(i_sComparedText) ) == 0; +} + +bool +X2CParser::IsBeginTag( const char * i_sTagName ) +{ + return strnicmp( text+1, i_sTagName, strlen(i_sTagName) ) == 0 + && *text == '<'; +} + +bool +X2CParser::IsEndTag( const char * i_sTagName ) +{ + return strnicmp( text+2, i_sTagName, strlen(i_sTagName) ) == 0 + && strnicmp( text, "</", 2 ) == 0; +} + +void +X2CParser::Goto( char i_cNext ) +{ + while (*text != i_cNext) + { + ++text; + AssertionOf(*text != '\0'); + } +} + +void +X2CParser::Goto_And_Pass( char i_cNext ) +{ + Goto(i_cNext); + ++text; +} + +void +X2CParser::Move( int i_nForward ) +{ + text += i_nForward; +} + +void +X2CParser::Pass_White() +{ + while (*text <= 32) + { + ++text; + AssertionOf(*text != '\0'); + } +} + +void +X2CParser::GetTextTill( Simstr & o_rText, + char i_cEnd, + bool i_bReverseName ) +{ + char * pResult = &sWord[0]; + + for ( char * pSet = pResult; + *text != i_cEnd; + ++text ) + { + AssertionOf(*text !='\0'); + *pSet++ = *text; + } + + while ( *pResult < 33 && *pResult > 0 ) + ++pResult; + while ( pSet > pResult ? *(pSet-1) < 33 : false ) + pSet--; + *pSet = '\0'; + + + if (i_bReverseName) + { + char * sBreak = strrchr(pResult,'.'); + if (sBreak != 0) + { + static char sScope[1000]; + static char sName[1000]; + + unsigned nScopeLen = sBreak - pResult; + strncpy ( sScope, pResult, nScopeLen ); + sScope[nScopeLen] = '\0'; + strcpy( sName, sBreak + 1 ); + strcat( sName, " in " ); + strcat( sName, sScope ); + + o_rText = sName; + return; + } + } + + o_rText = &sWord[0]; +} + + diff --git a/xml2cmp/source/xcd/parse.hxx b/xml2cmp/source/xcd/parse.hxx new file mode 100644 index 000000000000..efc6dc8ef6e2 --- /dev/null +++ b/xml2cmp/source/xcd/parse.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: parse.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $Date: $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_PARSE_HXX +#define X2C_PARSE_HXX + + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include "filebuff.hxx" +#include "../support/sistr.hxx" + // PARAMETERS + + +class ModuleDescription; +class ParentElement; +class ComponentDescription; +class ReferenceDocuElement; + +class X2CParser +{ + public: + X2CParser( + ModuleDescription & o_rData ); + ~X2CParser(); + + bool Parse( + const char * i_sFilename ); + const char * PureText() const { return aFile.operator const char*(); } + + private: + void Parse_XmlDeclaration(); + void Parse_Doctype(); + void Parse_ModuleDescription(); + void Parse_ComponentDescription( + ModuleDescription & o_rParent ); + void Parse_ReferenceDocu( + ReferenceDocuElement & + o_rElement ); + void Parse_TextElement( + const char * i_sElementName, + ParentElement & o_rParent, + bool i_bSingle, + bool i_bReverseName ); + void Parse_Status( + ComponentDescription & + o_rParent ); + void Get_ReferenceDocuAttribute( + ReferenceDocuElement & + o_rElement ); + Simstr Get_Attribute( + Simstr & o_rAttrName ); + bool IsText( + const char * i_sComparedText ); + bool IsBeginTag( + const char * i_sTagName ); + bool IsEndTag( + const char * i_sTagName ); + void Goto( + char i_cNext ); + void Goto_And_Pass( + char i_cNext ); + void Move( + int i_nForward ); + void Pass_White(); + void GetTextTill( + Simstr & o_rText, + char i_cEnd, + bool i_bReverseName = false ); + + // DATA + Buffer aFile; + ModuleDescription * pData; + + char sWord[8192]; + const char * text; +}; + + + +// IMPLEMENTATION + +#endif + diff --git a/xml2cmp/source/xcd/xmltree.cxx b/xml2cmp/source/xcd/xmltree.cxx new file mode 100644 index 000000000000..06b07513c80c --- /dev/null +++ b/xml2cmp/source/xcd/xmltree.cxx @@ -0,0 +1,149 @@ +/************************************************************************* + * + * $RCSfile: xmltree.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $Date: $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + + +#include <xmltree.hxx> + + +// NOT FULLY DEFINED SERVICES + + +void +ParentElement::AddChild( TextElement & let_drElement ) +{ + aChildren.push_back(&let_drElement); +} + + +void +ModuleDescription::AddComponentDescription( ComponentDescription & let_drCD ) +{ + aCDs.push_back(&let_drCD); +} + +void +ComponentDescription::SetStatus( const char * i_sText ) +{ + sStatus = i_sText; +} + +SglTextElement::SglTextElement( const char * i_sName ) + : sName(i_sName) +{ +} + +void +SglTextElement::SetText( const char * i_sText ) +{ + sContent = i_sText; +} + +const char * +SglTextElement::Name() const +{ + return sName; +} + +const char * +SglTextElement::Data( unsigned i_nNr ) const +{ + return sContent.str(); +} + +unsigned +SglTextElement::Size() const +{ + return 1; +} + + +MultipleTextElement::MultipleTextElement( const char * i_sName ) + : sName(i_sName) +{ +} + +void +MultipleTextElement::SetText( const char * i_sText ) +{ + aContent.push_back(i_sText); +} + +const char * +MultipleTextElement::Name() const +{ + return sName; +} + +const char * +MultipleTextElement::Data( unsigned i_nNr ) const +{ + if (i_nNr < aContent.size()) + return aContent[i_nNr].str(); + else + return ""; +} + +unsigned +MultipleTextElement::Size() const +{ + return aContent.size(); +} + diff --git a/xml2cmp/source/xcd/xmltree.hxx b/xml2cmp/source/xcd/xmltree.hxx new file mode 100644 index 000000000000..0ea829b63176 --- /dev/null +++ b/xml2cmp/source/xcd/xmltree.hxx @@ -0,0 +1,198 @@ +/************************************************************************* + * + * $RCSfile: xmltree.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: np $Date: $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef X2C_XMLTREE_HXX +#define X2C_XMLTREE_HXX + + + +// USED SERVICES + // BASE CLASSES + // COMPONENTS +#include "../support/sistr.hxx" +#include "../support/list.hxx" + // PARAMETERS + + +class ComponentDescription; +class ReferenceDocuElement; + +class TextElement +{ + public: + virtual void SetText( + const char * i_sText ) = 0; + virtual const char * + Name() const = 0; + virtual const char * + Data( + unsigned i_nNr = 0 ) const = 0; + virtual unsigned Size() const = 0; +}; + +class ParentElement +{ + public: + typedef DynamicList<TextElement> ChildList; + void AddChild( + TextElement & let_drElement ); + + const ChildList & Children() const { return aChildren; } + ChildList & Children() { return aChildren; } + + private: + ChildList aChildren; +}; + + + +class ModuleDescription : public ParentElement +{ + public: + typedef DynamicList<ComponentDescription> CD_List; + + void AddComponentDescription( + ComponentDescription & + let_drCD ); + + const char * Name() const { return Children()[0]->Data(); } + const CD_List & Components() const { return aCDs; } + + private: + CD_List aCDs; +}; + + +class ComponentDescription : public ParentElement +{ + public: + typedef DynamicList<ReferenceDocuElement> Docu_List; + + void SetStatus( + const char * i_sText ); + + const char * Name() const { return Children()[0]->Data(); } + const Docu_List & DocuRefs() const { return aDocuRefs; } + Docu_List & DocuRefs() { return aDocuRefs; } + const char * Status() const { return sStatus; } + + private: + Simstr sStatus; + Docu_List aDocuRefs; +}; + + +class SglTextElement : public TextElement +{ + public: + SglTextElement( + const char * i_sName ); + virtual void SetText( + const char * i_sText ); + + virtual const char * + Name() const; + virtual const char * + Data( + unsigned i_nNr = 0 ) const; + virtual unsigned Size() const; + + private: + Simstr sName; + Simstr sContent; +}; + + +class MultipleTextElement : public TextElement +{ + public: + MultipleTextElement( + const char * i_sName ); + virtual void SetText( + const char * i_sText ); + + virtual const char * + Name() const; + virtual const char * + Data( + unsigned i_nNr = 0 ) const; + virtual unsigned Size() const; + + private: + Simstr sName; + List<Simstr> aContent; +}; + + +class ReferenceDocuElement +{ + public: + + Simstr sAttr_href; + Simstr sAttr_role; + Simstr sAttr_title; +}; + +// IMPLEMENTATION + + +#endif + |