[Libreoffice-commits] .: Branch 'feature/mork' - connectivity/Library_mork.mk connectivity/source
Fridrich Strba
fridrich at kemper.freedesktop.org
Fri Jul 20 06:29:09 PDT 2012
connectivity/Library_mork.mk | 3
connectivity/source/drivers/mork/MorkDriver.cxx | 243 ++++++++++
connectivity/source/drivers/mork/MorkDriver.hxx | 58 ++
connectivity/source/drivers/mork/MorkParser.cxx | 578 ++++++++++++++++++++++++
connectivity/source/drivers/mork/MorkParser.hxx | 166 ++++++
connectivity/source/drivers/mork/driver.cxx | 243 ----------
connectivity/source/drivers/mork/driver.hxx | 58 --
connectivity/source/drivers/mork/services.cxx | 2
8 files changed, 1048 insertions(+), 303 deletions(-)
New commits:
commit 1599831df2adb3966572c1dcbf5d8ef972ed3fbf
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date: Fri Jul 20 15:28:46 2012 +0200
Integrating the two BSD-licensed MorkParser files
Change-Id: I8e793dfe53556becdcc733a9f76e64df23fb5524
diff --git a/connectivity/Library_mork.mk b/connectivity/Library_mork.mk
index e0ea9c8..ec118ed 100644
--- a/connectivity/Library_mork.mk
+++ b/connectivity/Library_mork.mk
@@ -10,7 +10,8 @@
$(eval $(call gb_Library_Library,mork))
$(eval $(call gb_Library_add_exception_objects,mork, \
- connectivity/source/drivers/mork/driver \
+ connectivity/source/drivers/mork/MorkDriver \
+ connectivity/source/drivers/mork/MorkParser \
connectivity/source/drivers/mork/services \
))
diff --git a/connectivity/source/drivers/mork/MorkDriver.cxx b/connectivity/source/drivers/mork/MorkDriver.cxx
new file mode 100644
index 0000000..83f9d7c
--- /dev/null
+++ b/connectivity/source/drivers/mork/MorkDriver.cxx
@@ -0,0 +1,243 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "sal/config.h"
+
+#include <cassert>
+
+#include "boost/noncopyable.hpp"
+#include "com/sun/star/beans/PropertyValue.hpp"
+#include "com/sun/star/lang/XServiceInfo.hpp"
+#include "com/sun/star/sdbc/DriverPropertyInfo.hpp"
+#include "com/sun/star/sdbc/SQLException.hpp"
+#include "com/sun/star/sdbc/XConnection.hpp"
+#include "com/sun/star/sdbc/XDriver.hpp"
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/RuntimeException.hpp"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "com/sun/star/uno/XComponentContext.hpp"
+#include "cppuhelper/implbase1.hxx"
+#include "cppuhelper/implbase2.hxx"
+#include "cppuhelper/weak.hxx"
+#include "rtl/ustring.hxx"
+#include "sal/types.h"
+
+#include "MorkDriver.hxx"
+
+namespace css = com::sun::star;
+
+namespace connectivity
+{
+namespace mork
+{
+
+class Service:
+ public cppu::WeakImplHelper2< css::lang::XServiceInfo, css::sdbc::XDriver >,
+ private boost::noncopyable
+{
+public:
+ Service(css::uno::Reference< css::uno::XComponentContext > const context):
+ context_(context)
+ {
+ assert(context.is());
+ }
+
+private:
+ virtual ~Service() {}
+
+ rtl::OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException)
+ {
+ return connectivity::mork::getImplementationName();
+ }
+
+ sal_Bool SAL_CALL supportsService(rtl::OUString const &ServiceName)
+ throw (css::uno::RuntimeException)
+ {
+ return ServiceName == getSupportedServiceNames()[0]; //TODO
+ }
+
+ css::uno::Sequence< rtl::OUString > SAL_CALL
+ getSupportedServiceNames() throw (css::uno::RuntimeException)
+ {
+ return connectivity::mork::getSupportedServiceNames();
+ }
+
+ css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(
+ rtl::OUString const &url,
+ css::uno::Sequence< css::beans::PropertyValue > const &info)
+ throw (css::sdbc::SQLException, css::uno::RuntimeException);
+
+ sal_Bool SAL_CALL acceptsURL(
+ rtl::OUString const &url)
+ throw (css::sdbc::SQLException, css::uno::RuntimeException);
+
+ css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL
+ getPropertyInfo(
+ rtl::OUString const &url,
+ css::uno::Sequence< css::beans::PropertyValue > const &info)
+ throw (css::sdbc::SQLException, css::uno::RuntimeException);
+
+ sal_Int32 SAL_CALL getMajorVersion()
+ throw (css::uno::RuntimeException);
+
+ sal_Int32 SAL_CALL getMinorVersion()
+ throw (css::uno::RuntimeException);
+
+ css::uno::Reference< css::uno::XComponentContext > context_;
+};
+
+class Connection:
+ public cppu::WeakImplHelper1< css::sdbc::XConnection >,
+ private boost::noncopyable
+{
+public:
+ Connection(
+ css::uno::Reference< css::uno::XComponentContext > const context);
+
+private:
+ ~Connection();
+
+ // XConnection
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString &sql )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString &sql )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString &sql )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL setAutoCommit( sal_Bool autoCommit )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL getAutoCommit( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL commit( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL rollback( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL isClosed( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL setReadOnly( sal_Bool readOnly )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ sal_Bool SAL_CALL isReadOnly( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL setCatalog( const ::rtl::OUString &catalog )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::rtl::OUString SAL_CALL getCatalog( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL setTransactionIsolation( sal_Int32 level )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ sal_Int32 SAL_CALL getTransactionIsolation( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
+ throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+ // XCloseable
+ void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+
+
+ css::uno::Reference< css::uno::XComponentContext > context_;
+};
+
+}
+}
+
+connectivity::mork::Connection::Connection(
+ css::uno::Reference< css::uno::XComponentContext > const context):
+ context_(context)
+{
+ assert(context.is());
+}
+
+connectivity::mork::Connection::~Connection()
+{
+}
+
+css::uno::Reference< css::sdbc::XConnection > connectivity::mork::Service::connect(
+ rtl::OUString const &url,
+ css::uno::Sequence< css::beans::PropertyValue > const &info)
+throw (css::sdbc::SQLException, css::uno::RuntimeException)
+{
+ //... TODO
+ (void) url;
+ (void) info; // avoid warnings
+
+ return new connectivity::mork::Connection(context_);
+}
+
+sal_Bool connectivity::mork::Service::acceptsURL(rtl::OUString const &url)
+throw (css::sdbc::SQLException, css::uno::RuntimeException)
+{
+ //... TODO
+ (void) url; // avoid warnings
+ return false;
+}
+
+css::uno::Sequence< css::sdbc::DriverPropertyInfo > connectivity::mork::Service::getPropertyInfo(
+ rtl::OUString const &url,
+ css::uno::Sequence< css::beans::PropertyValue > const &info)
+throw (css::sdbc::SQLException, css::uno::RuntimeException)
+{
+ //... TODO
+ (void) url;
+ (void) info; // avoid warnings
+ return css::uno::Sequence< css::sdbc::DriverPropertyInfo >();
+}
+
+sal_Int32 connectivity::mork::Service::getMajorVersion() throw (css::uno::RuntimeException)
+{
+ //... TODO
+ return 0;
+}
+
+sal_Int32 connectivity::mork::Service::getMinorVersion() throw (css::uno::RuntimeException)
+{
+ //... TODO
+ return 0;
+}
+
+css::uno::Reference< css::uno::XInterface > create(
+ css::uno::Reference< css::uno::XComponentContext > const &context)
+{
+ return static_cast< cppu::OWeakObject * >(new connectivity::mork::Service(context));
+}
+
+rtl::OUString connectivity::mork::getImplementationName()
+{
+ return rtl::OUString("com.sun.star.comp.sdbc.MorkDriver");
+}
+
+css::uno::Sequence< rtl::OUString > connectivity::mork::getSupportedServiceNames()
+{
+ rtl::OUString name("com.sun.star.sdbc.Driver");
+ return css::uno::Sequence< rtl::OUString >(&name, 1);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/MorkDriver.hxx b/connectivity/source/drivers/mork/MorkDriver.hxx
new file mode 100644
index 0000000..3ec2890
--- /dev/null
+++ b/connectivity/source/drivers/mork/MorkDriver.hxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef _MORK_DRIVER_HXX_
+#define _MORK_DRIVER_HXX_
+
+#include "sal/config.h"
+
+#include "com/sun/star/uno/Reference.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "sal/types.h"
+
+namespace com
+{
+namespace sun
+{
+namespace star
+{
+namespace uno
+{
+class XComponentContext;
+class XInterface;
+}
+}
+}
+}
+namespace rtl
+{
+class OUString;
+}
+
+namespace connectivity
+{
+namespace mork
+{
+
+com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
+create(
+ com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
+ const &);
+
+rtl::OUString SAL_CALL getImplementationName();
+
+com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
+getSupportedServiceNames();
+
+}
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/MorkParser.cxx b/connectivity/source/drivers/mork/MorkParser.cxx
new file mode 100644
index 0000000..07be7d1
--- /dev/null
+++ b/connectivity/source/drivers/mork/MorkParser.cxx
@@ -0,0 +1,578 @@
+/*
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2006, ScalingWeb.com
+ * All rights reserved.
+ *
+ * Redistribution and use of this software in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * * Neither the name of ScalingWeb.com nor the names of its
+ * contributors may be used to endorse or promote products
+ * derived from this software without specific prior
+ * written permission of ScalingWeb.com.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "MorkParser.hxx"
+#include <stdlib.h>
+#include <sstream>
+#include <string>
+#include <string.h>
+#include <stdexcept>
+#include <fstream>
+#include <iostream>
+
+std::string g_Empty = "";
+
+MorkParser::MorkParser( int DefaultScope ) :
+ columns_(),
+ values_(),
+ mork_(),
+ currentCells_(0),
+ error_(NoError),
+ morkData_(),
+ morkPos_(0),
+ nextAddValueId_(0x7fffffff),
+ defaultScope_(DefaultScope),
+ nowParsing_(NPValues)
+{
+}
+
+bool MorkParser::open( const std::string &path )
+{
+ initVars();
+ std::string line;
+ std::ifstream infile(path.c_str(), std::ios_base::in);
+ if(!infile.is_open())
+ {
+ error_ = FailedToOpen;
+ return false;
+ }
+
+ while (getline(infile, line, '\n'))
+ {
+ morkData_.append(line);
+ morkData_.append("\n");
+ }
+
+ // Parse mork
+ return parse();
+}
+
+inline MorkErrors MorkParser::error()
+{
+ return error_;
+}
+
+void MorkParser::initVars()
+{
+ error_ = NoError;
+ morkPos_ = 0;
+ nowParsing_ = NPValues;
+ currentCells_ = 0;
+ nextAddValueId_ = 0x7fffffff;
+}
+
+bool MorkParser::parse()
+{
+ bool Result = true;
+ char cur = 0;
+
+ // Run over mork chars and parse each term
+ cur = nextChar();
+
+ int i = 0;
+
+ while ( Result && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ i++;
+ // Figure out what a term
+ switch ( cur )
+ {
+ case '<':
+ // Dict
+ Result = parseDict();
+ break;
+ case '/':
+ // Comment
+ Result = parseComment();
+ break;
+ case '{':
+ Result = parseTable();
+ // Table
+ break;
+ case '[':
+ Result = parseRow( 0, 0 );
+ // Row
+ break;
+ case '@':
+ Result = parseGroup();
+ // Group
+ break;
+ default:
+ error_ = DefectedFormat;
+ Result = false;
+ break;
+ }
+ }
+
+ // Get next char
+ cur = nextChar();
+ }
+
+ return Result;
+}
+
+bool MorkParser::isWhiteSpace( char c )
+{
+ switch ( c )
+ {
+ case ' ':
+ case '\t':
+ case '\r':
+ case '\n':
+ case '\f':
+ return true;
+ default:
+ return false;
+ }
+}
+
+inline char MorkParser::nextChar()
+{
+ char cur = 0;
+
+
+ if ( morkPos_ < morkData_.length() )
+ {
+ cur = morkData_[ morkPos_ ];
+ morkPos_++;
+ }
+
+ if ( !cur )
+ {
+ cur = 0;
+ }
+
+ return cur;
+}
+
+bool MorkParser::parseDict()
+{
+ char cur = nextChar();
+ bool Result = true;
+ nowParsing_ = NPValues;
+
+ while ( Result && cur != '>' && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ switch ( cur )
+ {
+ case '<':
+ {
+
+ if ( morkData_.substr( morkPos_ - 1, strlen( MorkDictColumnMeta ) ) == MorkDictColumnMeta )
+ {
+ nowParsing_ = NPColumns;
+ morkPos_ += strlen( MorkDictColumnMeta ) - 1;
+ }
+
+
+ break;
+ }
+ case '(':
+ Result = parseCell();
+ break;
+ case '/':
+ Result = parseComment();
+ break;
+
+ }
+ }
+
+ cur = nextChar();
+ }
+
+ return Result;
+}
+
+inline bool MorkParser::parseComment()
+{
+ char cur = nextChar();
+ if ( '/' != cur ) return false;
+
+ while ( cur != '\r' && cur != '\n' && cur )
+ {
+ cur = nextChar();
+ }
+
+ return true;
+}
+
+bool MorkParser::parseCell()
+{
+ bool Result = true;
+ bool bValueOid = false;
+ bool bColumn = true;
+ int Corners = 0;
+
+ // Column = Value
+ std::string Column;
+ std::string Text;
+ Column.reserve( 4 );
+ Text.reserve( 32 );
+
+ char cur = nextChar();
+
+ // Process cell start with column (bColumn == true)
+ while ( Result && cur != ')' && cur )
+ {
+ switch ( cur )
+ {
+ case '^':
+ // Oids
+ Corners++;
+ if ( 1 == Corners )
+ {
+ }
+ else if ( 2 == Corners )
+ {
+ bColumn = false;
+ bValueOid = true;
+ }
+ else
+ {
+ Text += cur;
+ }
+
+ break;
+ case '=':
+ // From column to value
+ if ( bColumn )
+ {
+ bColumn = false;
+ }
+ else
+ {
+ Text += cur;
+ }
+ break;
+ case '\\':
+ {
+ // Get next two chars
+ char NextChar= nextChar();
+ if ( '\r' != NextChar && '\n' != NextChar )
+ {
+ Text += NextChar;
+ }
+ else nextChar();
+ }
+ break;
+ case '$':
+ {
+ // Get next two chars
+ std::string HexChar;
+ HexChar += nextChar();
+ HexChar += nextChar();
+ Text += (char)strtoul(HexChar.c_str(), 0, 16);
+ }
+ break;
+ default:
+ // Just a char
+ if ( bColumn )
+ {
+ Column += cur;
+ }
+ else
+ {
+ Text += cur;
+ }
+ break;
+ }
+
+ cur = nextChar();
+ }
+
+ // Apply column and text
+ int ColumnId = strtoul(Column.c_str(), 0, 16);
+
+ if ( NPRows != nowParsing_ )
+ {
+ // Dicts
+ if ( "" != Text )
+ {
+ if ( nowParsing_ == NPColumns )
+ {
+ columns_[ ColumnId ] = Text;
+ }
+ else
+ {
+ values_[ ColumnId ] = Text;
+ }
+ }
+ }
+ else
+ {
+ if ( "" != Text )
+ {
+ // Rows
+ //int ValueId = string( Text.c_str() ).toInt( 0, 16 );
+ int ValueId = strtoul(Text.c_str(), 0, 16);
+
+ if ( bValueOid )
+ {
+ ( *currentCells_ )[ ColumnId ] = ValueId;
+ }
+ else
+ {
+ nextAddValueId_--;
+ values_[ nextAddValueId_ ] = Text;
+ ( *currentCells_ )[ ColumnId ] = nextAddValueId_;
+ }
+ }
+ }
+
+ return Result;
+}
+
+bool MorkParser::parseTable()
+{
+ bool Result = true;
+ std::string TextId;
+ int Id = 0, Scope = 0;
+
+ char cur = nextChar();
+
+ // Get id
+ while ( cur != '{' && cur != '[' && cur != '}' && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ TextId += cur;
+ }
+
+ cur = nextChar();
+ }
+
+ parseScopeId( TextId, &Id, &Scope );
+
+ // Parse the table
+ while ( Result && cur != '}' && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ switch ( cur )
+ {
+ case '{':
+ Result = parseMeta( '}' );
+ break;
+ case '[':
+ Result = parseRow( Id, Scope );
+ break;
+ case '-':
+ case '+':
+ break;
+ default:
+ {
+ std::string JustId;
+ while ( !isWhiteSpace( cur ) && cur )
+ {
+ JustId += cur;
+ cur = nextChar();
+
+ if ( cur == '}' )
+ {
+ return Result;
+ }
+ }
+
+ int JustIdNum = 0, JustScopeNum = 0;
+ parseScopeId( JustId, &JustIdNum, &JustScopeNum );
+
+ setCurrentRow( Scope, Id, JustScopeNum, JustIdNum );
+ }
+ break;
+ }
+ }
+
+ cur = nextChar();
+ }
+
+ return Result;
+}
+
+void MorkParser::parseScopeId( const std::string &TextId, int *Id, int *Scope )
+{
+ int Pos = 0;
+
+ if ( ( Pos = TextId.find( ':' ) ) >= 0 )
+ {
+ std::string tId = TextId.substr( 0, Pos );
+ std::string tSc = TextId.substr( Pos + 1, TextId.length() - Pos );
+
+ if ( tSc.length() > 1 && '^' == tSc[ 0 ] )
+ {
+ // Delete '^'
+ tSc.erase( 0, 1 );
+ }
+
+ *Id = strtoul(tId.c_str(), 0, 16);
+
+ *Scope = strtoul(tSc.c_str(), 0, 16);
+ }
+ else
+ {
+ *Id = strtoul(TextId.c_str(), 0, 16);
+ }
+}
+
+inline void MorkParser::setCurrentRow( int TableScope, int TableId, int RowScope, int RowId )
+{
+ if ( !RowScope )
+ {
+ RowScope = defaultScope_;
+ }
+
+ if ( !TableScope )
+ {
+ TableScope = defaultScope_;
+ }
+
+ currentCells_ = &( mork_[ abs( TableScope ) ][ abs( TableId ) ][ abs( RowScope ) ][ abs( RowId ) ] );
+}
+
+bool MorkParser::parseRow( int TableId, int TableScope )
+{
+ bool Result = true;
+ std::string TextId;
+ int Id = 0, Scope = 0;
+ nowParsing_ = NPRows;
+
+ char cur = nextChar();
+
+ // Get id
+ while ( cur != '(' && cur != ']' && cur != '[' && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ TextId += cur;
+ }
+
+ cur = nextChar();
+ }
+
+ parseScopeId( TextId, &Id, &Scope );
+ setCurrentRow( TableScope, TableId, Scope, Id );
+
+ // Parse the row
+ while ( Result && cur != ']' && cur )
+ {
+ if ( !isWhiteSpace( cur ) )
+ {
+ switch ( cur )
+ {
+ case '(':
+ Result = parseCell();
+ break;
+ case '[':
+ Result = parseMeta( ']' );
+ break;
+ default:
+ Result = false;
+ break;
+ }
+ }
+
+ cur = nextChar();
+ }
+
+ return Result;
+}
+
+bool MorkParser::parseGroup()
+{
+ return parseMeta( '@' );
+}
+
+bool MorkParser::parseMeta( char c )
+{
+ char cur = nextChar();
+
+ while ( cur != c && cur )
+ {
+ cur = nextChar();
+ }
+
+ return true;
+}
+
+MorkTableMap *MorkParser::getTables( int TableScope )
+{
+ TableScopeMap::iterator iter;
+ iter = mork_.find( TableScope );
+
+ if ( iter == mork_.end() )
+ {
+ return 0;
+ }
+
+ return &iter->second;
+}
+
+MorkRowMap *MorkParser::getRows( int RowScope, RowScopeMap *table )
+{
+ RowScopeMap::iterator iter;
+ iter = table->find( RowScope );
+
+ if ( iter == table->end() )
+ {
+ return 0;
+ }
+
+ return &iter->second;
+}
+
+std::string &MorkParser::getValue( int oid )
+{
+ MorkDict::iterator foundIter = values_.find( oid );
+
+ if ( values_.end() == foundIter )
+ {
+ return g_Empty;
+ }
+
+ return foundIter->second;
+}
+
+std::string &MorkParser::getColumn( int oid )
+{
+ MorkDict::iterator foundIter = columns_.find( oid );
+
+ if ( columns_.end() == foundIter )
+ {
+ return g_Empty;
+ }
+
+ return foundIter->second;
+}
diff --git a/connectivity/source/drivers/mork/MorkParser.hxx b/connectivity/source/drivers/mork/MorkParser.hxx
new file mode 100644
index 0000000..dca4133
--- /dev/null
+++ b/connectivity/source/drivers/mork/MorkParser.hxx
@@ -0,0 +1,166 @@
+/*
+ * Software License Agreement (BSD License)
+ *
+ * Copyright (c) 2006, ScalingWeb.com
+ * All rights reserved.
+ *
+ * Redistribution and use of this software in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the
+ * following disclaimer in the documentation and/or other
+ * materials provided with the distribution.
+ *
+ * * Neither the name of ScalingWeb.com nor the names of its
+ * contributors may be used to endorse or promote products
+ * derived from this software without specific prior
+ * written permission of ScalingWeb.com.
+
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MORK_PARSER_HXX_
+#define _MORK_PARSER_HXX_
+
+#include <string>
+#include <map>
+
+// Types
+
+typedef std::map< int, std::string > MorkDict;
+typedef std::map< int, int > MorkCells; // ColumnId : ValueId
+typedef std::map< int, MorkCells > MorkRowMap; // Row id
+typedef std::map< int, MorkRowMap > RowScopeMap; // Row scope
+typedef std::map< int, RowScopeMap > MorkTableMap; // Table id
+typedef std::map< int, MorkTableMap > TableScopeMap; // Table Scope
+
+// Mork header of supported format version
+const char *MorkMagicHeader = "// <!-- <mdb:mork:z v=\"1.4\"/> -->";
+
+const char *MorkDictColumnMeta = "<(a=c)>";
+
+// Error codes
+enum MorkErrors
+{
+ NoError = 0,
+ FailedToOpen,
+ UnsupportedVersion,
+ DefectedFormat
+};
+
+// Mork term types
+enum MorkTerm
+{
+ NoneTerm = 0,
+ DictTerm,
+ GroupTerm,
+ TableTerm,
+ RowTerm,
+ CellTerm,
+ CommentTerm,
+ LiteralTerm
+};
+
+
+/// Class MorkParser
+
+class MorkParser
+{
+public:
+
+ MorkParser( int defaultScope = 0x80 );
+
+ ///
+ /// Open and parse mork file
+
+ bool open( const std::string &path );
+
+ ///
+ /// Return error status
+
+ MorkErrors error();
+
+ ///
+ /// Returns all tables of specified scope
+
+ MorkTableMap *getTables( int tableScope );
+
+ ///
+ /// Rerturns all rows under specified scope
+
+ MorkRowMap *getRows( int rowScope, RowScopeMap *table );
+
+ ///
+ /// Return value of specified value oid
+
+ std::string &getValue( int oid );
+
+ ///
+ /// Return value of specified column oid
+
+ std::string &getColumn( int oid );
+
+
+protected: // Members
+
+ void initVars();
+
+ bool isWhiteSpace( char c );
+ char nextChar();
+
+ void parseScopeId( const std::string &TextId, int *Id, int *Scope );
+ void setCurrentRow( int TableScope, int TableId, int RowScope, int RowId );
+
+ // Parse methods
+ bool parse();
+ bool parseDict();
+ bool parseComment();
+ bool parseCell();
+ bool parseTable();
+ bool parseMeta( char c );
+ bool parseRow( int TableId, int TableScope );
+ bool parseGroup();
+
+protected: // Data
+
+ // Columns in mork means value names
+ MorkDict columns_;
+ MorkDict values_;
+
+ // All mork file data
+ TableScopeMap mork_;
+ MorkCells *currentCells_;
+
+ // Error status of last operation
+ MorkErrors error_;
+
+ // All Mork data
+ std::string morkData_;
+
+ unsigned morkPos_;
+ int nextAddValueId_;
+ int defaultScope_;
+
+ // Indicates intity is being parsed
+ enum { NPColumns, NPValues, NPRows } nowParsing_;
+
+private:
+ MorkParser(const MorkParser &);
+ MorkParser &operator=(const MorkParser &);
+
+};
+
+#endif // __MorkParser_h__
+
diff --git a/connectivity/source/drivers/mork/driver.cxx b/connectivity/source/drivers/mork/driver.cxx
deleted file mode 100644
index 2286556..0000000
--- a/connectivity/source/drivers/mork/driver.cxx
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include "sal/config.h"
-
-#include <cassert>
-
-#include "boost/noncopyable.hpp"
-#include "com/sun/star/beans/PropertyValue.hpp"
-#include "com/sun/star/lang/XServiceInfo.hpp"
-#include "com/sun/star/sdbc/DriverPropertyInfo.hpp"
-#include "com/sun/star/sdbc/SQLException.hpp"
-#include "com/sun/star/sdbc/XConnection.hpp"
-#include "com/sun/star/sdbc/XDriver.hpp"
-#include "com/sun/star/uno/Reference.hxx"
-#include "com/sun/star/uno/RuntimeException.hpp"
-#include "com/sun/star/uno/Sequence.hxx"
-#include "com/sun/star/uno/XComponentContext.hpp"
-#include "cppuhelper/implbase1.hxx"
-#include "cppuhelper/implbase2.hxx"
-#include "cppuhelper/weak.hxx"
-#include "rtl/ustring.hxx"
-#include "sal/types.h"
-
-#include "driver.hxx"
-
-namespace css = com::sun::star;
-
-namespace connectivity
-{
-namespace mork
-{
-
-class Service:
- public cppu::WeakImplHelper2< css::lang::XServiceInfo, css::sdbc::XDriver >,
- private boost::noncopyable
-{
-public:
- Service(css::uno::Reference< css::uno::XComponentContext > const context):
- context_(context)
- {
- assert(context.is());
- }
-
-private:
- virtual ~Service() {}
-
- rtl::OUString SAL_CALL getImplementationName()
- throw (css::uno::RuntimeException)
- {
- return connectivity::mork::getImplementationName();
- }
-
- sal_Bool SAL_CALL supportsService(rtl::OUString const &ServiceName)
- throw (css::uno::RuntimeException)
- {
- return ServiceName == getSupportedServiceNames()[0]; //TODO
- }
-
- css::uno::Sequence< rtl::OUString > SAL_CALL
- getSupportedServiceNames() throw (css::uno::RuntimeException)
- {
- return connectivity::mork::getSupportedServiceNames();
- }
-
- css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect(
- rtl::OUString const &url,
- css::uno::Sequence< css::beans::PropertyValue > const &info)
- throw (css::sdbc::SQLException, css::uno::RuntimeException);
-
- sal_Bool SAL_CALL acceptsURL(
- rtl::OUString const &url)
- throw (css::sdbc::SQLException, css::uno::RuntimeException);
-
- css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL
- getPropertyInfo(
- rtl::OUString const &url,
- css::uno::Sequence< css::beans::PropertyValue > const &info)
- throw (css::sdbc::SQLException, css::uno::RuntimeException);
-
- sal_Int32 SAL_CALL getMajorVersion()
- throw (css::uno::RuntimeException);
-
- sal_Int32 SAL_CALL getMinorVersion()
- throw (css::uno::RuntimeException);
-
- css::uno::Reference< css::uno::XComponentContext > context_;
-};
-
-class Connection:
- public cppu::WeakImplHelper1< css::sdbc::XConnection >,
- private boost::noncopyable
-{
-public:
- Connection(
- css::uno::Reference< css::uno::XComponentContext > const context);
-
-private:
- ~Connection();
-
- // XConnection
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement > SAL_CALL createStatement( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareStatement( const ::rtl::OUString &sql )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > SAL_CALL prepareCall( const ::rtl::OUString &sql )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::rtl::OUString SAL_CALL nativeSQL( const ::rtl::OUString &sql )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL setAutoCommit( sal_Bool autoCommit )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- sal_Bool SAL_CALL getAutoCommit( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL commit( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL rollback( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- sal_Bool SAL_CALL isClosed( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > SAL_CALL getMetaData( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL setReadOnly( sal_Bool readOnly )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- sal_Bool SAL_CALL isReadOnly( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL setCatalog( const ::rtl::OUString &catalog )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::rtl::OUString SAL_CALL getCatalog( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL setTransactionIsolation( sal_Int32 level )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- sal_Int32 SAL_CALL getTransactionIsolation( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > SAL_CALL getTypeMap( )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL setTypeMap( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
- throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
- // XCloseable
- void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
-
-
- css::uno::Reference< css::uno::XComponentContext > context_;
-};
-
-}
-}
-
-connectivity::mork::Connection::Connection(
- css::uno::Reference< css::uno::XComponentContext > const context):
- context_(context)
-{
- assert(context.is());
-}
-
-connectivity::mork::Connection::~Connection()
-{
-}
-
-css::uno::Reference< css::sdbc::XConnection > connectivity::mork::Service::connect(
- rtl::OUString const &url,
- css::uno::Sequence< css::beans::PropertyValue > const &info)
-throw (css::sdbc::SQLException, css::uno::RuntimeException)
-{
- //... TODO
- (void) url;
- (void) info; // avoid warnings
-
- return new connectivity::mork::Connection(context_);
-}
-
-sal_Bool connectivity::mork::Service::acceptsURL(rtl::OUString const &url)
-throw (css::sdbc::SQLException, css::uno::RuntimeException)
-{
- //... TODO
- (void) url; // avoid warnings
- return false;
-}
-
-css::uno::Sequence< css::sdbc::DriverPropertyInfo > connectivity::mork::Service::getPropertyInfo(
- rtl::OUString const &url,
- css::uno::Sequence< css::beans::PropertyValue > const &info)
-throw (css::sdbc::SQLException, css::uno::RuntimeException)
-{
- //... TODO
- (void) url;
- (void) info; // avoid warnings
- return css::uno::Sequence< css::sdbc::DriverPropertyInfo >();
-}
-
-sal_Int32 connectivity::mork::Service::getMajorVersion() throw (css::uno::RuntimeException)
-{
- //... TODO
- return 0;
-}
-
-sal_Int32 connectivity::mork::Service::getMinorVersion() throw (css::uno::RuntimeException)
-{
- //... TODO
- return 0;
-}
-
-css::uno::Reference< css::uno::XInterface > create(
- css::uno::Reference< css::uno::XComponentContext > const &context)
-{
- return static_cast< cppu::OWeakObject * >(new connectivity::mork::Service(context));
-}
-
-rtl::OUString connectivity::mork::getImplementationName()
-{
- return rtl::OUString("com.sun.star.comp.sdbc.MorkDriver");
-}
-
-css::uno::Sequence< rtl::OUString > connectivity::mork::getSupportedServiceNames()
-{
- rtl::OUString name("com.sun.star.sdbc.Driver");
- return css::uno::Sequence< rtl::OUString >(&name, 1);
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/driver.hxx b/connectivity/source/drivers/mork/driver.hxx
deleted file mode 100644
index f3b286e..0000000
--- a/connectivity/source/drivers/mork/driver.hxx
+++ /dev/null
@@ -1,58 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_DRIVER_HXX
-#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_DRIVER_HXX
-
-#include "sal/config.h"
-
-#include "com/sun/star/uno/Reference.hxx"
-#include "com/sun/star/uno/Sequence.hxx"
-#include "sal/types.h"
-
-namespace com
-{
-namespace sun
-{
-namespace star
-{
-namespace uno
-{
-class XComponentContext;
-class XInterface;
-}
-}
-}
-}
-namespace rtl
-{
-class OUString;
-}
-
-namespace connectivity
-{
-namespace mork
-{
-
-com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL
-create(
- com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
- const &);
-
-rtl::OUString SAL_CALL getImplementationName();
-
-com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
-getSupportedServiceNames();
-
-}
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/services.cxx b/connectivity/source/drivers/mork/services.cxx
index f808392..aa610e1 100644
--- a/connectivity/source/drivers/mork/services.cxx
+++ b/connectivity/source/drivers/mork/services.cxx
@@ -13,7 +13,7 @@
#include "cppuhelper/implementationentry.hxx"
#include "sal/types.h"
-#include "driver.hxx"
+#include "MorkDriver.hxx"
namespace
{
More information about the Libreoffice-commits
mailing list