diff options
Diffstat (limited to 'cosv/source')
28 files changed, 4745 insertions, 0 deletions
diff --git a/cosv/source/comphelp/badcast.cxx b/cosv/source/comphelp/badcast.cxx new file mode 100644 index 000000000000..f36d9875b52c --- /dev/null +++ b/cosv/source/comphelp/badcast.cxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + + +/* Include this for instantiating bad-cast, + due to problems with WNT-STL-headers. +*/ + +#if defined(WNT) && !defined(__MINGW32__) + +#define _NTSDK +#include<typeinfo> + +_STD_BEGIN +bad_cast G_Dummy_Inst_bad_cast; +_STD_END +#endif // WNT + + + diff --git a/cosv/source/comphelp/makefile.mk b/cosv/source/comphelp/makefile.mk new file mode 100644 index 000000000000..7c8fac8f2b0b --- /dev/null +++ b/cosv/source/comphelp/makefile.mk @@ -0,0 +1,55 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_badcast_wnt +TARGETTYPE=CUI + +# --- Settings ----------------------------------------------------- + +ENABLE_EXCEPTIONS=true + +.INCLUDE : settings.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/badcast.obj + + + +# --- Targets ------------------------------------------------------ + + +.INCLUDE : target.mk + + + diff --git a/cosv/source/fullcpp.mk b/cosv/source/fullcpp.mk new file mode 100644 index 000000000000..ffbcb9805273 --- /dev/null +++ b/cosv/source/fullcpp.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + + + +# --- Settings ----------------------------------------------------- +# Has to be inlcuded AFTER settings.mk ! + + +.IF "$(GUI)"=="WNT" + +# RTTI +CFLAGS+= -GR + +.IF "$(NP_LOCALBUILD)"!="" + +# Precompiled Headers +PCH_NAME= cosv +.IF "$(DBG_LEVEL)"<"2" +CFLAGS+= -YX"precomp.h" /Fp$(PRJ)$/$(INPATH)$/misc$/$(PCH_NAME).pch +.ELSE +CFLAGS+= -YX"precomp.h" /Fp$(PRJ)$/$(INPATH)$/misc$/$(PCH_NAME).pcd -DNP_LOCALBUILD +.ENDIF + +.ENDIF + +.ENDIF + +.IF "$(OS)"=="LINUX" +# RTTI +CFLAGSCXX+= -frtti +.ENDIF + diff --git a/cosv/source/inc/precomp.h b/cosv/source/inc/precomp.h new file mode 100644 index 000000000000..f280d522ac03 --- /dev/null +++ b/cosv/source/inc/precomp.h @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef CSV_PRECOMP_H +#define CSV_PRECOMP_H + + +#include <cosv/csv_precomp.h> + + + +#endif + diff --git a/cosv/source/service/comdline.cxx b/cosv/source/service/comdline.cxx new file mode 100644 index 000000000000..fc3003d20e79 --- /dev/null +++ b/cosv/source/service/comdline.cxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/comdline.hxx> + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +bool +CommandLine_Ifc::CheckParameters() const +{ + if ( NOT inq_CheckParameters() ) + { + PrintUse(); + return false; + } + + return true; +} + + + + +} // namespace csv + + + + diff --git a/cosv/source/service/comfunc.cxx b/cosv/source/service/comfunc.cxx new file mode 100644 index 000000000000..ab8f274d90d8 --- /dev/null +++ b/cosv/source/service/comfunc.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> + +#include <ctype.h> +#include <cosv/comfunc.hxx> +#include <cosv/string.hxx> +#include <cosv/x.hxx> +#include <cosv/std_outp.hxx> + + + +namespace csv +{ + + +void +X_Default::GetInfo( ostream & o_rOutputMedium ) const +{ + o_rOutputMedium << "Error (general exception): "; + o_rOutputMedium << sMessage + << Endl; +} + +intt +count_chars(const char * str, char c) +{ + intt nCount = 0; + for ( const char * pSpc = strchr(str, c); + pSpc != 0; + pSpc = strchr(pSpc+1, c) ) + { + nCount++; + } + return nCount; +} + + + +// Zeit-Typecasts +bool +str2date(const char * str, int & out_day, int & out_month, int & out_year) +{ + const char * z = str; + out_day = 0; + out_month = 0; + out_year = 0; + + while (isdigit(*z)) + out_day = 10*out_day + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_month = 10*out_month + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_year = 10*out_year + *(z++) - '0'; + return true; +} + +void +date2str(String & out_Str, int day, int month, int year) +{ + char buf[11] = "00.00.0000"; + buf[0] = static_cast<char>(day/10 + '0'); + buf[1] = static_cast<char>(day%10 + '0'); + buf[3] = static_cast<char>(month/10 + '0'); + buf[4] = static_cast<char>(month%10 + '0'); + + if (year < 100) + { + buf[6] = static_cast<char>(year/10 + '0'); + buf[7] = static_cast<char>(year%10 + '0'); + buf[8] = 0; + } + else + { + buf[6] = static_cast<char>(year/1000 + '0'); + buf[7] = static_cast<char>(year%1000/100 + '0'); + buf[8] = static_cast<char>(year%100/10 + '0'); + buf[9] = static_cast<char>(year%10 + '0'); + } + out_Str = buf; +} + +bool +str2time(const char * str, int & out_hour, int & out_min, int & out_sec) +{ + const char * z = str; + out_hour = 0; + out_min = 0; + out_sec = 0; + + while (isdigit(*z)) + out_hour = 10*out_hour + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_min = 10*out_min + *(z++) - '0'; + if (*z == 0) + return false; + z++; + while (isdigit(*z)) + out_sec = 10*out_sec + *(z++) - '0'; + return true; +} + +void +time2str(String & out_Str, int hour, int min, int sec) +{ + char buf[9] = "00:00:00"; + buf[0] = static_cast<char>(hour/10 + '0'); + buf[1] = static_cast<char>(hour%10 + '0'); + buf[3] = static_cast<char>(min/10 + '0'); + buf[4] = static_cast<char>(min%10 + '0'); + buf[6] = static_cast<char>(sec/10 + '0'); + buf[7] = static_cast<char>(sec%10 + '0'); + out_Str = buf; +} + + + +} // namespace csv + + + diff --git a/cosv/source/service/commandline.cxx b/cosv/source/service/commandline.cxx new file mode 100644 index 000000000000..383811a9ac25 --- /dev/null +++ b/cosv/source/service/commandline.cxx @@ -0,0 +1,342 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/commandline.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/file.hxx> + + +namespace csv +{ + +namespace +{ + +const intt C_nNoOption = -1; + +const char * sIncludeOptionShort = "-A:"; +const char * sIncludeOptionLong = "--Arguments:"; +const uintt nIncludeOptionShort_Length = strlen(sIncludeOptionShort); +const uintt nIncludeOptionLong_Length = strlen(sIncludeOptionLong); + + +/** Analyses, if an option is the one to include a file with + further command line arguments. +*/ +bool IsIncludeOption( + const String & i_option ); + +/** Gets the file name from an include-arguments-option. +*/ +String IncludeFile_fromIncludeOption( + const String & i_option ); + + +bool +IsIncludeOption(const String & i_option) +{ + return strncmp(i_option, sIncludeOptionShort, nIncludeOptionShort_Length) == 0 + OR + strncmp(i_option, sIncludeOptionLong, nIncludeOptionLong_Length) == 0; +} + +String +IncludeFile_fromIncludeOption(const String & i_option) +{ + if ( strncmp(i_option, sIncludeOptionShort, nIncludeOptionShort_Length) + == 0 ) + { + return String(i_option, nIncludeOptionShort_Length, str::maxsize); + } + else + if ( strncmp(i_option, sIncludeOptionLong, nIncludeOptionLong_Length) + == 0 ) + { + return String(i_option, nIncludeOptionLong_Length, str::maxsize); + } + return String::Null_(); +} + + +} // end anonymous namespace + + + + +/** Local helper class for searching a possible option name in a vector of + ->OptionDescription. +*/ +struct CommandLine:: +FindOptionByText +{ + bool operator()( + const CommandLine::OptionDescription & + i_option ) + { return i_option.sText == sOption; } + + /// @param i_searchText [i_searchText != ""] + FindOptionByText( + const String & i_option ) + : sOption(i_option) { } + private: + const String sOption; +}; + + +typedef std::vector<StringVector::const_iterator> StringCIteratorList; +typedef std::vector<intt> OptionIdList; + +bool +CommandLine::Interpret( int argc, + char * argv[] ) +{ + Get_Arguments(argc,argv); + csv_assert(aOptionPoints.size() == aOptionIds.size()); + + StringVector::const_iterator + itNext = aCommandLine.begin(); + ++itNext; // Move 1 forward from program name. + StringVector::const_iterator + itEnd = aCommandLine.end(); + StringCIteratorList::const_iterator + itOptPtsEnd = aOptionPoints.end(); + + OptionIdList::const_iterator + itOptIds = aOptionIds.begin(); + for ( StringCIteratorList::const_iterator itOptPts = aOptionPoints.begin(); + itOptPts != itOptPtsEnd AND bIsOk; + ++itOptPts, ++itOptIds ) + { + // May be, there are arguments which do not belong to the last option: + // itNext != *is + Handle_FreeArguments(itNext, *itOptPts); + + itNext = do_HandleOption( *itOptIds, + *itOptPts + 1, + itOptPts+1 == itOptPtsEnd ? itEnd : *(itOptPts+1) ); + csv_assert(itNext <= itEnd); + } // end for (is) + Handle_FreeArguments(itNext, itEnd); + + return bIsOk; +} + +CommandLine::CommandLine() + : aOptions(), + aCommandLine(), + bIsOk(false) +{ +} + +void +CommandLine::Add_Option( intt i_id, + String i_text ) +{ + aOptions.push_back(OptionDescription( i_id, + i_text )); +} + +void +CommandLine::Get_Arguments( int argc, + char * argv[] ) +{ + aCommandLine.erase(aCommandLine.begin(),aCommandLine.end()); + aCommandLine.reserve(argc); + + char ** pArgEnd = argv + argc; + for ( char ** pArg = &argv[0]; + pArg != pArgEnd; + ++pArg ) + { + Store_Argument(*pArg); + } // end for + Find_OptionPoints(); + bIsOk = true; +} + +intt +CommandLine::Find_Option( const String & i_text ) const +{ + if (i_text.empty()) + return C_nNoOption; + + FindOptionByText aSearch(i_text); + OptionList::const_iterator + itFound = std::find_if( aOptions.begin(), + aOptions.end(), + aSearch ); + if (itFound != aOptions.end()) + { + return (*itFound).nId; + } + return C_nNoOption; +} + +bool +CommandLine::Store_Argument( const String & i_arg ) +{ + if ( NOT IsIncludeOption(i_arg) ) + { + aCommandLine.push_back(i_arg); + return true; + } + + return Try2Include_Options(i_arg); +} + +void +CommandLine::Find_OptionPoints() +{ + StringVector::const_iterator itEnd = aCommandLine.end(); + for ( StringVector::const_iterator it = aCommandLine.begin() + 1; + it != itEnd; + ++it ) + { + intt nOption = Find_Option(*it); + if (nOption != C_nNoOption) + { + aOptionPoints.push_back(it); + aOptionIds.push_back(nOption); + } + } // end for (i) +} + +void +CommandLine::Handle_FreeArguments( StringVector::const_iterator i_begin, + StringVector::const_iterator i_end ) +{ + for ( StringVector::const_iterator it = i_begin; + it != i_end AND bIsOk; + ++it ) + { + do_HandleFreeArgument(*it); + } +} + +bool +CommandLine::Try2Include_Options(const String & i_includeOption) +{ + static StringVector + aIncludedOptionFiles_; + + const String + aOptionFile(IncludeFile_fromIncludeOption(i_includeOption)); + + // Avoid recursion deadlock 1 + if ( std::find( aIncludedOptionFiles_.begin(), + aIncludedOptionFiles_.end(), + aOptionFile ) + != aIncludedOptionFiles_.end() ) + { + Cerr() << "\nError: Self inclusion of option file " + << aOptionFile + << ".\n" + << Endl(); + return false; + } + + // Avoid recursion deadlock 2 + aIncludedOptionFiles_.push_back(aOptionFile); + + bool ok = Include_Options(aOptionFile); + + // Avoid recursion deadlock 3 + aIncludedOptionFiles_.pop_back(); + + return ok; +} + +bool +CommandLine::Include_Options( const String & i_optionsFile ) +{ + StreamStr + aIncludedText(500); + bool ok = Load_Options(aIncludedText, i_optionsFile); + if (NOT ok) + return false; + + StringVector + aIncludedOptions; + Split(aIncludedOptions, aIncludedText.c_str()); + + StringVector::const_iterator itEnd = aIncludedOptions.end(); + for ( StringVector::const_iterator it = aIncludedOptions.begin(); + it != itEnd; + ++it ) + { + Store_Argument(*it); + } // end for + + return true; +} + +bool +CommandLine::Load_Options( StreamStr & o_text, + const String & i_optionsFile ) +{ + if (i_optionsFile.empty()) + return false; + + File + aOptionsFile(i_optionsFile, CFM_READ); + OpenCloseGuard + aOFGuard(aOptionsFile); + if (NOT aOFGuard) + { + Cerr() << "\nError: Options file " + << i_optionsFile + << " not found.\n" + << Endl(); + return false; + } + + StreamStr + aLoad(aOptionsFile); + o_text.swap(aLoad); + return true; +} + + + + +/****************** OptionDescription ***********************/ + + +CommandLine:: +OptionDescription::OptionDescription( intt i_id, + String i_text ) + : nId(i_id), + sText(i_text) +{ +} + + + + +} // namespace csv diff --git a/cosv/source/service/csv_ostream.cxx b/cosv/source/service/csv_ostream.cxx new file mode 100644 index 000000000000..30c5736343a2 --- /dev/null +++ b/cosv/source/service/csv_ostream.cxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/csv_ostream.hxx> + +// NOT FULLY DECLARED SERVICES + + +#ifndef CSV_NO_IOSTREAMS +#else + +#include <cosv/streamstr.hxx> + +namespace csv +{ + +ostream::~ostream() { } + +ostream & ostream::operator<<( + const char * i_s ) { *pData << i_s; return *this; } +ostream & ostream::operator<<( + char i_c ) { *pData << i_c; return *this; } +ostream & ostream::operator<<( + unsigned char i_c ) { *pData << i_c; return *this; } +ostream & ostream::operator<<( + signed char i_c ) { *pData << i_c; return *this; } + +ostream & ostream::operator<<( + short i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned short i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + int i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned int i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + long i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + unsigned long i_n ) { *pData << i_n; return *this; } + +ostream & ostream::operator<<( + float i_n ) { *pData << i_n; return *this; } +ostream & ostream::operator<<( + double i_n ) { *pData << i_n; return *this; } + +ostream & +ostream::seekp( intt i_nOffset, + seek_dir i_eStart ) +{ + pData->seekp(i_nOffset, csv::seek_dir(int(i_eStart)) ); + return *this; +} + +ostream::ostream( uintt i_nStartSize ) + : pData( new StreamStr(i_nStartSize) ) +{ +} + + + +} // namespace csv + +#endif + + + + diff --git a/cosv/source/service/datetime.cxx b/cosv/source/service/datetime.cxx new file mode 100644 index 000000000000..00acabe6e1d7 --- /dev/null +++ b/cosv/source/service/datetime.cxx @@ -0,0 +1,84 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <precomp.h> +#include <cosv/datetime.hxx> + + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +Date::Date() + : nData( 0 ) +{ +} + +Date::Date( unsigned i_nDay, + unsigned i_nMonth, + unsigned i_nYear ) + : nData( (i_nDay << 24) + (i_nMonth << 16) + i_nYear ) +{ +} + +const Date & +Date::Null_() +{ + static const Date C_DateNull_(0,0,0); + return C_DateNull_; +} + + +Time::Time() + : nData( 0 ) +{ +} + +Time::Time( unsigned i_nHour, + unsigned i_nMinutes, + unsigned i_nSeconds, + unsigned i_nSeconds100 ) + : nData( (i_nHour << 24) + (i_nMinutes << 16) + (i_nSeconds << 8) + i_nSeconds100 ) +{ +} + +const Time & +Time::Null_() +{ + static const Time C_TimeNull_(0,0); + return C_TimeNull_; +} + + + +} // namespace csv + + diff --git a/cosv/source/service/makefile.mk b/cosv/source/service/makefile.mk new file mode 100644 index 000000000000..fc44f35e5ea3 --- /dev/null +++ b/cosv/source/service/makefile.mk @@ -0,0 +1,59 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_service + +ENABLE_EXCEPTIONS=true + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/comdline.obj \ + $(OBJ)$/comfunc.obj \ + $(OBJ)$/csv_ostream.obj \ + $(OBJ)$/datetime.obj \ + $(OBJ)$/std_outp.obj + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/service/std_outp.cxx b/cosv/source/service/std_outp.cxx new file mode 100644 index 000000000000..315abec11978 --- /dev/null +++ b/cosv/source/service/std_outp.cxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/std_outp.hxx> + +// NOT FULLY DECLARED SERVICES +#include <stdlib.h> + + +namespace csv +{ + +#ifdef CSV_NO_IOSTREAMS +redirect_out * redirect_out::pStdOut_ = 0; +redirect_out * redirect_out::pStdErr_ = 0; +#endif // defined(CSV_NO_IOSTREAMS) + + +void +Endl( ostream & io_rStream, bool /*bUseRedirect*/, int* ) +{ +#ifndef CSV_NO_IOSTREAMS +// if (NOT bUseRedirect) + io_rStream << std::endl; +// else +#endif +// static_cast< redirect_out& >(io_rStream).re_endl(); +} + +void +Flush( ostream & io_rStream, bool /*bUseRedirect*/, int* ) +{ +#ifndef CSV_NO_IOSTREAMS +// if (NOT bUseRedirect) + io_rStream << std::flush; +// else +#endif +// static_cast< redirect_out& >(io_rStream).re_flush(); +} + +void +PerformAssertion(const char * condition, const char * file, unsigned line) +{ + Cout() << "assertion failed: " + << condition + << " in file: " + << file + << " at line: " + << line + << Endl; + + exit(3); +} + +} // namespace csv + diff --git a/cosv/source/storage/dirchain.cxx b/cosv/source/storage/dirchain.cxx new file mode 100644 index 000000000000..b183c0f990f7 --- /dev/null +++ b/cosv/source/storage/dirchain.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/dirchain.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/bstream.hxx> + + + + +namespace csv +{ +namespace ploc +{ + + +DirectoryChain::DirectoryChain() +{ +} + +DirectoryChain::DirectoryChain( const char * i_sSubPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + Set( i_sSubPath, i_bPathIsAlwaysDir, i_sDelimiter ); +} + +DirectoryChain::~DirectoryChain() +{ +} + +void +DirectoryChain::Set( const char * i_sSubPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + csv_assert(i_sDelimiter != 0); + if (i_sSubPath == 0) + return; + + const char * pRestPath = i_sSubPath; + if (*pRestPath == *i_sDelimiter) + ++pRestPath; + + for ( const char * pDirEnd = strchr(pRestPath,*i_sDelimiter); + pDirEnd != 0; + pDirEnd = strchr(pRestPath,*i_sDelimiter) ) + { + aPath.push_back( String(pRestPath, pDirEnd) ); + pRestPath = pDirEnd + 1; + } + if (*pRestPath != 0 AND i_bPathIsAlwaysDir) + aPath.push_back( String(pRestPath) ); +} + +void +DirectoryChain::PushFront( const String & i_sName ) +{ + aPath.insert( aPath.begin(), i_sName ); +} + +void +DirectoryChain::PushFront( const DirectoryChain & i_sPath ) +{ + aPath.insert( aPath.begin(), i_sPath.Begin(), i_sPath.End() ); +} + +void +DirectoryChain::PushBack( const String & i_sName ) +{ + aPath.push_back(i_sName); +} + +void +DirectoryChain::PushBack( const DirectoryChain & i_sPath ) +{ + aPath.insert( aPath.end(), i_sPath.Begin(), i_sPath.End() ); +} + +void +DirectoryChain::PopFront( uintt i_nCount ) +{ + if (i_nCount <= aPath.size()) + aPath.erase( aPath.begin(), aPath.begin() + i_nCount ); + else + aPath.erase( aPath.begin(), aPath.end() ); +} + +void +DirectoryChain::PopBack( uintt i_nCount ) +{ + if (i_nCount <= aPath.size()) + aPath.erase( aPath.end() - i_nCount, aPath.end() ); + else + aPath.erase( aPath.begin(), aPath.end() ); +} + +void +DirectoryChain::Get( ostream & o_rPath, + const char * i_sDelimiter ) const +{ + for ( std::vector<String>::const_iterator it = aPath.begin(); + it != aPath.end(); + ++it ) + { + o_rPath << (*it).c_str() << i_sDelimiter; + } +} + +void +DirectoryChain::Get( bostream & o_rPath, + const char * i_sDelimiter ) const +{ + uintt deliLen = strlen(i_sDelimiter); + + for ( std::vector<String>::const_iterator it = aPath.begin(); + it != aPath.end(); + ++it ) + { + o_rPath.write( (*it).c_str() ); + o_rPath.write( i_sDelimiter, deliLen); + } +} + + + + +} // namespace ploc +} // namespace csv diff --git a/cosv/source/storage/file.cxx b/cosv/source/storage/file.cxx new file mode 100644 index 000000000000..aa1190ec9fab --- /dev/null +++ b/cosv/source/storage/file.cxx @@ -0,0 +1,242 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/file.hxx> + +// NOT FULLY DECLARED SERVICES + + +namespace csv +{ + + +File::File( uintt i_nMode ) + : // aPath, + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const ploc::Path & i_rLocation, + uintt i_nMode ) + : aPath(i_rLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const char * i_sLocation, + uintt i_nMode ) + : aPath(i_sLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::File( const String & i_sLocation, + uintt i_nMode ) + : aPath(i_sLocation), + pStream(0), + nMode(i_nMode), + eLastIO(io_none) +{ +} + +File::~File() +{ + if ( inq_is_open() ) + close(); +} + +bool +File::Assign( ploc::Path i_rLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath = i_rLocation; + return true; +} + +bool +File::Assign( const char * i_sLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath.Set( i_sLocation ); + return true; +} + +bool +File::Assign( const String & i_sLocation ) +{ + if (is_open() ) + return false; + + InvalidatePath(); + aPath.Set( i_sLocation ); + return true; +} + +uintt +File::do_read( void * out_pDest, + uintt i_nNrofBytes ) +{ + if ( NOT inq_is_open() ) + return 0; + + if ( eLastIO == io_write ) + ::fseek( pStream, 0, SEEK_CUR ); + uintt ret = position(); + int iRet= ::fread( out_pDest, 1, i_nNrofBytes, pStream ); + if ( iRet < 0 ) { + fprintf(stderr, "warning: read failed in %s line %d \n", __FILE__, __LINE__); + } + ret = position() - ret; + + eLastIO = io_read; + return ret; +} + +bool +File::inq_eod() const +{ + if ( NOT inq_is_open() ) + return true; + return feof(pStream) != 0; +} + +uintt +File::do_write( const void * i_pSrc, + uintt i_nNrofBytes ) +{ + if ( NOT inq_is_open() ) + return 0; + + if ( eLastIO == io_write ) + ::fseek( pStream, 0, SEEK_CUR ); + uintt ret = position(); + ::fwrite( i_pSrc, 1, i_nNrofBytes, pStream ); + ret = position() - ret; + + eLastIO = io_write; + return ret; +} + +uintt +File::do_seek( intt i_nDistance, + seek_dir i_eStartPoint ) +{ + if ( NOT inq_is_open() ) + return uintt(-1); + + static int eSearchDir[3] = { SEEK_SET, SEEK_CUR, SEEK_END }; + + ::fseek( pStream, + intt(i_nDistance), + eSearchDir[i_eStartPoint] ); + return position(); +} + +uintt +File::inq_position() const +{ + if ( inq_is_open() ) + return uintt( ::ftell(pStream) ); + else + return uintt(-1); +} + +bool +File::do_open( uintt i_nOpenMode ) +{ + if ( inq_is_open() ) + { + if ( i_nOpenMode == 0 OR i_nOpenMode == nMode ) + return true; + close(); + } + + if ( i_nOpenMode != 0 ) + nMode = i_nOpenMode; + + const char * sFacadeMode = ""; + switch ( nMode ) + { + case CFM_RW: sFacadeMode = "r+b"; + break; + case CFM_CREATE: sFacadeMode = "w+b"; + break; + case CFM_READ: sFacadeMode = "rb"; + break; + default: + sFacadeMode = "rb"; + } + + pStream = ::fopen( StrPath(), sFacadeMode ); + if ( pStream == 0 AND nMode == CFM_RW ) + { + sFacadeMode = "w+b"; + pStream = ::fopen( StrPath(), sFacadeMode ); + } + + return pStream != 0; +} + +void +File::do_close() +{ + if ( inq_is_open() ) + { + ::fclose(pStream); + pStream = 0; + } + eLastIO = io_none; +} + +bool +File::inq_is_open() const +{ + return pStream != 0; +} + +const ploc::Path & +File::inq_MyPath() const +{ + return aPath; +} + + +} // namespace csv + diff --git a/cosv/source/storage/makefile.mk b/cosv/source/storage/makefile.mk new file mode 100644 index 000000000000..84e396c425ba --- /dev/null +++ b/cosv/source/storage/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_storage + +ENABLE_EXCEPTIONS=true + + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/dirchain.obj \ + $(OBJ)$/file.obj \ + $(OBJ)$/mbstream.obj \ + $(OBJ)$/persist.obj \ + $(OBJ)$/ploc.obj \ + $(OBJ)$/ploc_dir.obj \ + $(OBJ)$/plocroot.obj + +#SLOFILES= \ +# $(SLO)$/file.obj \ +# $(SLO)$/csfileim.obj \ +# $(SLO)$/memstorg.obj + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/storage/mbstream.cxx b/cosv/source/storage/mbstream.cxx new file mode 100644 index 000000000000..5559d1f6d59a --- /dev/null +++ b/cosv/source/storage/mbstream.cxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/mbstream.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> + + +namespace csv +{ + + + +mbstream::mbstream( uintt i_nSize ) + : dpOwnedMemorySpace( new char[i_nSize+1] ), + nSize( i_nSize ), + nCurPosition( 0 ) +{ + dpOwnedMemorySpace[i_nSize] = '\0'; +} + +mbstream::~mbstream() +{ + delete [] dpOwnedMemorySpace; +} + +void +mbstream::resize( uintt i_nSize ) +{ + DYN char * pNew = new char[i_nSize]; + memcpy( pNew, dpOwnedMemorySpace, min(i_nSize,nSize) ); + delete [] dpOwnedMemorySpace; + dpOwnedMemorySpace = pNew; + nSize = i_nSize; +} + +uintt +mbstream::do_read( void * out_pDest, + uintt i_nNrofBytes ) +{ + uintt ret = min( i_nNrofBytes, nSize - nCurPosition ); + memcpy( out_pDest, dpOwnedMemorySpace, ret ); + nCurPosition += ret; + return ret; +} + +bool +mbstream::inq_eod() const +{ + return nCurPosition == nSize; +} + +uintt +mbstream::do_write( const void * i_pSrc, + uintt i_nNrofBytes ) +{ + resize( max( 3 * (nSize+1) / 2, nCurPosition + i_nNrofBytes) ); + memcpy( dpOwnedMemorySpace+nCurPosition, i_pSrc, i_nNrofBytes ); + nCurPosition += i_nNrofBytes; + return i_nNrofBytes; +} + +uintt +mbstream::do_seek( intt i_nDistance, + seek_dir i_eStartPoint ) +{ + switch ( i_eStartPoint ) + { + case beg: if ( uintt(i_nDistance) < nSize ) + nCurPosition = uintt(i_nDistance); + break; + case cur: if ( i_nDistance < 0 + ? uintt(-i_nDistance) <= nCurPosition + : uintt(i_nDistance) + nCurPosition < nSize ) + nCurPosition = uintt( intt(nCurPosition) + i_nDistance ); + break; + case end: if ( i_nDistance < 0 + AND uintt(-i_nDistance) < nSize - 1 ) + nCurPosition = uintt( intt(nSize) - 1 + i_nDistance ); + break; + } + return position(); +} + +uintt +mbstream::inq_position() const +{ + return nCurPosition; +} + + +} // namespace csv + diff --git a/cosv/source/storage/persist.cxx b/cosv/source/storage/persist.cxx new file mode 100644 index 000000000000..aa63767c1b0e --- /dev/null +++ b/cosv/source/storage/persist.cxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/persist.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/streamstr.hxx> +#include <cosv/ploc.hxx> + + +#ifdef WNT +#include <io.h> + +namespace csv +{ +namespace ploc +{ + +bool +Persistent::Exists() const +{ + return access( StrPath(), 00) == 0; +} + +} // namespace ploc +} // namespace csv + + +#elif defined(UNX) +#include <unistd.h> + +/* +#ifndef __SUNPRO_CC +#include <unistd.h> +#else +#define F_OK 0 // Test for existence of File +extern int access(const char *, int); +#endif +*/ + +namespace csv +{ +namespace ploc +{ + +bool +Persistent::Exists() const +{ + return access( StrPath(), F_OK ) == 0; +} + + +} // namespace ploc +} // namespace csv + +#else +#error For using csv::ploc there has to be defined: WNT or UNX. +#endif + +namespace csv +{ +namespace ploc +{ + +const char * +Persistent::StrPath() const +{ + if (sPath.empty() ) + { +#ifndef CSV_NO_MUTABLE + StreamStr & rsPath = sPath; +#else + StreamStr & rsPath = const_cast< StreamStr& >(sPath); +#endif + rsPath.seekp(0); + rsPath << MyPath(); + if (MyPath().IsDirectory()) + rsPath.pop_back(1); // Remove closing delimiter. + } + return sPath.c_str(); +} + +} // namespace ploc +} // namespace csv + + + + diff --git a/cosv/source/storage/ploc.cxx b/cosv/source/storage/ploc.cxx new file mode 100644 index 000000000000..66061cd8df55 --- /dev/null +++ b/cosv/source/storage/ploc.cxx @@ -0,0 +1,157 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/bstream.hxx> + + + + +namespace csv +{ +namespace ploc +{ + + +Path::Path( const char * i_sPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) + : pRoot(0) + // aPath, + // sFile +{ + Set(i_sPath, i_bPathIsAlwaysDir, i_sDelimiter ); +} + +Path::Path( const Path & i_rPath ) + : pRoot(i_rPath.pRoot->CreateCopy()), + aPath(i_rPath.aPath), + sFile(i_rPath.sFile) +{ +} + +Path::~Path() +{ +} + +Path & +Path::operator=( const Path & i_rPath ) +{ + pRoot = i_rPath.pRoot->CreateCopy(); + aPath = i_rPath.aPath; + sFile = i_rPath.sFile; + return *this; +} + + +void +Path::Set( const char * i_sPath, + bool i_bPathIsAlwaysDir, + const char * i_sDelimiter ) +{ + if ( *i_sDelimiter != '\\' AND *i_sDelimiter != '/' ) + return; + + const char * + restPath = 0; + pRoot = Root::Create_( restPath, i_sPath, i_sDelimiter ); + if (restPath == 0) + return; + + aPath.Set(restPath, i_bPathIsAlwaysDir, i_sDelimiter); + + if (NOT i_bPathIsAlwaysDir) + { + const char * + file = strrchr( restPath, *i_sDelimiter ); + if (file == 0) + file = restPath; + else + file++; + sFile = file; + } +} + +void +Path::SetFile( const String & i_sName ) +{ + sFile = i_sName; +} + +const char * +Path::FileExtension() const +{ + const char * + ext = strrchr(sFile, '.'); + if (ext != 0) + ++ext; + else + ext = ""; + return ext; +} + +bool +Path::IsValid() const +{ + return RootDir().OwnDelimiter() != 0; +} + +void +Path::Get( ostream & o_rPath ) const +{ + if (NOT IsValid()) + return; + + pRoot->Get( o_rPath ); + aPath.Get( o_rPath, pRoot->OwnDelimiter() ); + + if ( sFile.length() > 0 ) + o_rPath << sFile; + +} + +void +Path::Get( bostream & o_rPath ) const +{ + if (NOT IsValid()) + return; + + pRoot->Get( o_rPath ); + aPath.Get( o_rPath, pRoot->OwnDelimiter() ); + + if ( sFile.length() > 0 ) + o_rPath.write( sFile ); +} + + + + +} // namespace ploc +} // namespace csv diff --git a/cosv/source/storage/ploc_dir.cxx b/cosv/source/storage/ploc_dir.cxx new file mode 100644 index 000000000000..0f769a5f7e6f --- /dev/null +++ b/cosv/source/storage/ploc_dir.cxx @@ -0,0 +1,364 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc_dir.hxx> + +// NOT FULLY DECLARED SERVICES +#include <cosv/ploc.hxx> + + +namespace csv +{ +namespace ploc +{ + +Directory::Directory() +{ +} + +Directory::Directory( const Path & i_rPath ) + : aPath(i_rPath) + // sPath +{ +} + +Directory::Directory( const Directory & i_rDir ) + : Persistent(), aPath(i_rDir.aPath) + // sPath +{ +} + +Directory::Directory( const char * i_rLocation ) + : aPath(i_rLocation, true) +{ +} + +Directory::Directory( const String & i_rLocation ) + : aPath(i_rLocation.c_str(), true) +{ +} + +Directory::~Directory() +{ +} + +Directory & +Directory::operator+=( const String & i_sName ) +{ + InvalidatePath(); + aPath.DirChain() += i_sName; + return *this; +} + +Directory & +Directory::operator+=( const DirectoryChain & i_sDirChain ) +{ + InvalidatePath(); + aPath.DirChain() += i_sDirChain; + return *this; +} + +Directory & +Directory::operator-=( uintt i_nLevels ) +{ + InvalidatePath(); + aPath.DirChain().PopBack(i_nLevels); + return *this; +} + +bool +Directory::PhysicalCreate( bool i_bCreateParentsIfNecessary ) const +{ + bool ret = PhysicalCreate_Dir( StrPath() ); + if ( ret OR NOT i_bCreateParentsIfNecessary ) + return ret; + + ret = Check_Parent(); + if (ret) + ret = PhysicalCreate_Dir( StrPath() ); + return ret; +} + +bool +Directory::Check_Parent() const +{ + // There is no parent of root directories: + if ( aPath.DirChain().Size() == 0 ) + return false; + + // Become my own parent: + String sLastToken = aPath.DirChain().Back(); + const_cast< Directory* >(this)->operator-=(1); + + // Begin behaving as parent: + bool ret = Exists(); + if (NOT ret) + { + ret = Check_Parent(); + if (ret) + ret = PhysicalCreate_Dir( StrPath() ); + } + // End behaving as parent. + + // Become myself again: + const_cast< Directory* >(this)->operator+=(sLastToken); + return ret; +} + +} // namespace ploc +} // namespace csv + + +#ifdef WNT +#include <direct.h> +#include <io.h> + +namespace csv +{ +namespace ploc +{ + +bool +Directory::PhysicalCreate_Dir( const char * i_sStr ) const +{ + return mkdir( i_sStr ) == 0; +} + +void +Directory::GetContainedDirectories( StringVector & o_rResult ) const +{ + const char * c_sANYDIR = "\\*.*"; + String sNew; + + StreamStr sFilter(200); + sFilter << StrPath() + << c_sANYDIR; + + struct _finddata_t + aEntry; + long hFile = _findfirst( sFilter.c_str(), &aEntry ); + + for ( int bFindMore = (hFile == -1 ? 1 : 0); + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + if ( (aEntry.attrib & _A_SUBDIR) AND *aEntry.name != '.' ) + { + sNew = aEntry.name; + o_rResult.push_back( sNew ); + } + } // end for + _findclose(hFile); +} + +void +Directory::GetContainedFiles( StringVector & o_rResult, + const char * i_sFilter, + E_Recursivity i_eRecursivity ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + StreamStr sFilter(200); + sFilter << StrPath() + << "\\" + << i_sFilter; + + struct _finddata_t + aEntry; + long hFile = _findfirst( sFilter.c_str(), &aEntry ); + for ( int bFindMore = (hFile == -1 ? 1 : 0); + bFindMore == 0; + bFindMore = _findnext( hFile, &aEntry ) ) + { + sNew.seekp(nStartFilename); + sNew << aEntry.name; + String sNewAsString( sNew.c_str() ); + o_rResult.push_back(sNewAsString); + } // end for + + _findclose(hFile); + if ( i_eRecursivity == flat ) + return; + + // gathering from subdirectories: + StringVector aSubDirectories; + GetContainedDirectories( aSubDirectories ); + + StringVector::const_iterator dEnd = aSubDirectories.end(); + for ( StringVector::const_iterator d = aSubDirectories.begin(); + d != dEnd; + ++d ) + { + Directory aSub(*this); + aSub += *d; + aSub.GetContainedFiles( o_rResult, + i_sFilter, + i_eRecursivity ); + } +} + +} // namespace ploc +} // namespace csv + + +#elif defined(UNX) +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> + +namespace csv +{ +namespace ploc +{ + +bool +Directory::PhysicalCreate_Dir( const char * i_sStr ) const +{ + return mkdir( i_sStr, 00777 ) == 0; +} + +void +Directory::GetContainedDirectories( StringVector & o_rResult ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + DIR * pDir = opendir( StrPath() ); + dirent * pEntry = 0; + struct stat aEntryStatus; + + while ( (pEntry = readdir(pDir)) != 0 ) + { + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + + stat(sNew.c_str(), &aEntryStatus); + if ( (aEntryStatus.st_mode & S_IFDIR) == S_IFDIR + AND *pEntry->d_name != '.' ) + { + String sNew2(pEntry->d_name); + o_rResult.push_back(sNew2); + } // endif (aEntry.attrib == _A_SUBDIR) + } // end while + closedir( pDir ); +} + +void +Directory::GetContainedFiles( StringVector & o_rResult, + const char * i_sFilter, + E_Recursivity i_eRecursivity ) const +{ + StreamStr sNew(240); + sNew << aPath; + StreamStr::size_type + nStartFilename = sNew.tellp(); + + bool bUseFilter = strcmp( i_sFilter, "*.*" ) != 0 + AND strncmp( i_sFilter, "*.", 2) == 0; + + DIR * pDir = opendir( StrPath() ); + dirent * pEntry = 0; + struct stat aEntryStatus; + + while ( (pEntry = readdir(pDir)) != 0 ) + { + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + + stat(sNew.c_str(), &aEntryStatus); + if ( (aEntryStatus.st_mode & S_IFDIR) == S_IFDIR ) + continue; // Don't gather directories. + + if ( bUseFilter ) + { + const char * pEnding = strrchr(pEntry->d_name,'.'); + if (pEnding == 0) + continue; + if ( strcasecmp( pEnding + 1, i_sFilter + 2 ) != 0 ) + continue; + } + + sNew.seekp(nStartFilename); + sNew << pEntry->d_name; + String sNewAsString( sNew.c_str() ); + o_rResult.push_back(sNewAsString); + } // end while + + closedir( pDir ); + if ( i_eRecursivity == flat ) + return; + + // gathering from subdirectories: + StringVector aSubDirectories; + GetContainedDirectories( aSubDirectories ); + + StringVector::const_iterator dEnd = aSubDirectories.end(); + for ( StringVector::const_iterator d = aSubDirectories.begin(); + d != dEnd; + ++d ) + { + Directory aSub(*this); + aSub += *d; + aSub.GetContainedFiles( o_rResult, + i_sFilter, + i_eRecursivity ); + } +} + +} // namespace ploc +} // namespace csv + + +#else +#error For using csv::ploc there has to be defined: WNT or UNX. +#endif + + +namespace csv +{ +namespace ploc +{ + +const Path & +Directory::inq_MyPath() const +{ + return aPath; +} + + + +} // namespace ploc +} // namespace csv + + + diff --git a/cosv/source/storage/plocroot.cxx b/cosv/source/storage/plocroot.cxx new file mode 100644 index 000000000000..441a241b3a63 --- /dev/null +++ b/cosv/source/storage/plocroot.cxx @@ -0,0 +1,525 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/ploc.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ctype.h> +#include <cosv/bstream.hxx> +#include <cosv/csv_ostream.hxx> + + +namespace csv +{ +namespace ploc +{ + + +class UnixRootDir : public Root +{ + public: + UnixRootDir(); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + +class WorkingDir : public Root +{ + public: + WorkingDir( + const char * i_sDelimiter = Delimiter() ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + String sOwnDelimiter; +}; + +class WinRootDir : public Root +{ + public: + WinRootDir(); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + +class WinDrive : public Root +{ + public: + WinDrive( + char i_cDrive ); + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + char cDrive; +}; + +class WinDriveRootDir : public Root +{ + public: + WinDriveRootDir( + const char * i_sPath ); + WinDriveRootDir( + char i_cDrive ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + char cDrive; +}; + +class UNCRoot : public Root +{ + public: + UNCRoot( + const char * i_sPath ); + UNCRoot( + const String & i_sComputer, + const String & i_sEntryPt ); + + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; + private: + String sComputer; + String sEntryPt; +}; + +class InvalidRoot : public Root +{ + public: + virtual void Get( + ostream & o_rPath ) const; + virtual void Get( + bostream & o_rPath ) const; + virtual DYN Root * CreateCopy() const; + virtual const char * + OwnDelimiter() const; +}; + + +DYN Root * +Create_WindowsRoot( const char * & o_sPathAfterRoot, + const char * i_sPath ) +{ + if (i_sPath[0] == '\\') + { + if (i_sPath[1] == '\\') + { // UNC path name + o_sPathAfterRoot = strchr(i_sPath+2,'\\'); + if (o_sPathAfterRoot != 0) + { + o_sPathAfterRoot = strchr(o_sPathAfterRoot+1,'\\'); + if (o_sPathAfterRoot != 0) + ++o_sPathAfterRoot; + return new UNCRoot(i_sPath); + } + return new InvalidRoot; // Incomplete UNC root. + } + else + { + o_sPathAfterRoot = i_sPath+1; + return new WinRootDir; + } + } + else if (i_sPath[1] == ':') + { + if ( i_sPath[2] == '\\') + { + o_sPathAfterRoot = i_sPath + 3; + return new WinDriveRootDir(i_sPath); + } + else + { + o_sPathAfterRoot = i_sPath + 2; + return new WinDrive(*i_sPath); + } + } + else + { + o_sPathAfterRoot = i_sPath; + return new WorkingDir("\\"); + } +} + +DYN Root * +Create_UnixRoot( const char * & o_sPathAfterRoot, + const char * i_sPath ) +{ + if (*i_sPath == '/') + { + o_sPathAfterRoot = i_sPath + 1; + return new UnixRootDir; + } + else // + { + o_sPathAfterRoot = i_sPath; + return new WorkingDir("/"); + } // endif +} + + +//********************** Root ****************************// + +Root::~Root() +{ + +} + +DYN Root * +Root::Create_( const char * & o_sPathAfterRoot, + const char * i_sPath, + const char * i_sDelimiter ) +{ + if (i_sPath[0] == '.') + { + switch ( i_sPath[1] ) + { + case '\0': o_sPathAfterRoot = i_sPath + 1; + break; + case '\\': o_sPathAfterRoot = i_sPath + 2; + break; + case '/': o_sPathAfterRoot = i_sPath + 2; + break; + case '.': o_sPathAfterRoot = i_sPath; + break; + default: + o_sPathAfterRoot = 0; + return new InvalidRoot; + } // end switch (i_sPath[1]) + + return new WorkingDir; + } // end if (i_sPath[0] == '.') + + switch (*i_sDelimiter) + { + case '\\': return Create_WindowsRoot(o_sPathAfterRoot, i_sPath); + case '/': return Create_UnixRoot(o_sPathAfterRoot, i_sPath); + } + + o_sPathAfterRoot = 0; + return new InvalidRoot; +} + + + +//********************** UnixRootDir ****************************// + + +UnixRootDir::UnixRootDir() +{ +} + +void +UnixRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << '/'; +} + +void +UnixRootDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( "/", 1 ); +} + +DYN Root * +UnixRootDir::CreateCopy() const +{ + return new UnixRootDir; +} + +const char * +UnixRootDir::OwnDelimiter() const +{ + return "/"; +} + + +//********************** WorkingDir ****************************// + +WorkingDir::WorkingDir( const char * i_sDelimiter ) + : sOwnDelimiter(i_sDelimiter) +{ +} + +void +WorkingDir::Get( ostream & o_rPath ) const +{ + o_rPath << '.' << sOwnDelimiter; +} + +void +WorkingDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( ".", 1 ); + o_rPath.write( sOwnDelimiter ); +} + +DYN Root * +WorkingDir::CreateCopy() const +{ + return new WorkingDir(sOwnDelimiter); +} + +const char * +WorkingDir::OwnDelimiter() const +{ + return sOwnDelimiter; +} + + +//********************** WinRootDir ****************************// + +WinRootDir::WinRootDir() +{ +} + +void +WinRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << '\\'; +} + +void +WinRootDir::Get( bostream & o_rPath ) const +{ + o_rPath.write( "\\", 1 ); +} + +DYN Root * +WinRootDir::CreateCopy() const +{ + return new WinRootDir; +} + +const char * +WinRootDir::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** WinDrive ****************************// + +WinDrive::WinDrive( char i_cDrive ) + : cDrive(static_cast< char >(toupper(i_cDrive))) +{ +} + +void +WinDrive::Get( ostream & o_rPath ) const +{ + o_rPath << cDrive << ':'; +} + +void +WinDrive::Get( bostream & o_rPath ) const +{ + static char buf_[3] = " :"; + buf_[0] = cDrive; + o_rPath.write( &buf_[0], 2 ); +} + +DYN Root * +WinDrive::CreateCopy() const +{ + return new WinDrive(cDrive); +} + +const char * +WinDrive::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** WinDriveRootDir ****************************// + +WinDriveRootDir::WinDriveRootDir( const char * i_sPath ) + : cDrive(static_cast< char >(toupper(*i_sPath))) +{ + if ( 'A' > cDrive OR 'Z' < cDrive ) + cDrive = 0; +} + +WinDriveRootDir::WinDriveRootDir( char i_cDrive ) + : cDrive(i_cDrive) +{ +} + +void +WinDriveRootDir::Get( ostream & o_rPath ) const +{ + o_rPath << cDrive << ":\\"; +} + +void +WinDriveRootDir::Get( bostream & o_rPath ) const +{ + static char buf_[4] = " :\\"; + buf_[0] = cDrive; + o_rPath.write( &buf_[0], 3 ); +} + +DYN Root * +WinDriveRootDir::CreateCopy() const +{ + return new WinDriveRootDir(cDrive); +} + +const char * +WinDriveRootDir::OwnDelimiter() const +{ + return "\\"; +} + + +//********************** UNCRoot ****************************// + +UNCRoot::UNCRoot( const char * i_sPath ) +// : // sComputer, + // sEntryPt +{ + const char * pRestPath = i_sPath + 2; + const char * pDirEnd = strchr(pRestPath, '\\'); + csv_assert(pDirEnd != 0); + + sComputer = String(pRestPath, pDirEnd - pRestPath); + pRestPath = pDirEnd+1; + pDirEnd = strchr(pRestPath, '\\'); + + if ( pDirEnd != 0 ) + { + sEntryPt = String(pRestPath, pDirEnd - pRestPath); + } + else + { + sEntryPt = pRestPath; + } +} + +UNCRoot::UNCRoot( const String & i_sComputer, + const String & i_sEntryPt ) + : sComputer(i_sComputer), + sEntryPt(i_sEntryPt) +{ +} + +void +UNCRoot::Get( ostream & o_rPath ) const +{ + o_rPath << "\\\\" << sComputer << '\\' << sEntryPt << "\\"; +} + +void +UNCRoot::Get( bostream & o_rPath ) const +{ + o_rPath.write( "\\\\", 2 ); + o_rPath.write( sComputer ); + o_rPath.write( "\\", 1 ); + o_rPath.write( sEntryPt ); + o_rPath.write( "\\", 1 ); +} + +DYN Root * +UNCRoot::CreateCopy() const +{ + return new UNCRoot(sComputer,sEntryPt); +} + +const char * +UNCRoot::OwnDelimiter() const +{ + return "\\"; +} + + + +//********************** InvalidRoot ****************************// + +void +InvalidRoot::Get( ostream & ) const +{ +} + +void +InvalidRoot::Get( bostream & ) const +{ +} + +DYN Root * +InvalidRoot::CreateCopy() const +{ + return new InvalidRoot; +} + +const char * +InvalidRoot::OwnDelimiter() const +{ + return 0; +} + + + + +} // namespace ploc +} // namespace csv + + + diff --git a/cosv/source/strings/makefile.mk b/cosv/source/strings/makefile.mk new file mode 100644 index 000000000000..2bd9bab1ddc8 --- /dev/null +++ b/cosv/source/strings/makefile.mk @@ -0,0 +1,58 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_strings + +ENABLE_EXCEPTIONS=true + + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/str_types.obj \ + $(OBJ)$/streamstr.obj \ + $(OBJ)$/string.obj + + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/strings/str_types.cxx b/cosv/source/strings/str_types.cxx new file mode 100644 index 000000000000..5508d3517ecb --- /dev/null +++ b/cosv/source/strings/str_types.cxx @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/str_types.hxx> + + + +namespace csv +{ + +CharOrder_Table::CharOrder_Table( const int * i_pCharWeightsArray ) +{ + memcpy( cWeights, i_pCharWeightsArray, 256 * sizeof(int) ); +} + + +} // namespace csv + + diff --git a/cosv/source/strings/streamstr.cxx b/cosv/source/strings/streamstr.cxx new file mode 100644 index 000000000000..371d9b36c02a --- /dev/null +++ b/cosv/source/strings/streamstr.cxx @@ -0,0 +1,981 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/streamstr.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> +#include <stdio.h> +#include <stdarg.h> // both are needed to satisfy all compilers +#include <cstdarg> // std::va_list and friends + +#include <cosv/comfunc.hxx> +#include <cosv/tpl/swelist.hxx> + + + +namespace csv +{ + + +// Maximal sizes of resulting integers in text form: +const uintt C_short_max_size = sizeof(short) * 3; +const uintt C_int_max_size = sizeof(int) * 3; +const uintt C_long_max_size = sizeof(long) * 3; + + +inline void +StreamStr::Advance(size_type i_nAddedSize) +{ pCur += i_nAddedSize; } + + + +StreamStr::StreamStr( size_type i_nCapacity ) + : bostream(), + nCapacity1( i_nCapacity + 1 ), + dpData( new char [i_nCapacity + 1] ), + pEnd(dpData), + pCur(dpData), + eMode(str::overwrite) +{ + *pEnd = '\0'; +} + +StreamStr::StreamStr( const char * i_sInitStr, + size_type i_nCapacity ) + : bostream(), + nCapacity1(0), + dpData(0), + pEnd(0), + pCur(0), + eMode(str::overwrite) +{ + size_type nLength = strlen(i_sInitStr); + nCapacity1 = csv::max(nLength, i_nCapacity) + 1; + dpData = new char [nCapacity1]; + strcpy(dpData, i_sInitStr); // SAFE STRCPY (#100211# - checked) + pCur = dpData + nLength; + pEnd = pCur; +} + +StreamStr::StreamStr( size_type i_nGuessedCapacity, + const char * str1, + const char * str2, + ... ) + : bostream(), + nCapacity1( i_nGuessedCapacity + 1 ), + dpData( new char [i_nGuessedCapacity + 1] ), + pEnd(dpData), + pCur(dpData), + eMode(str::overwrite) +{ + *pEnd = '\0'; + + operator<<(str1); + operator<<(str2); + + ::va_list ap; + + va_start(ap, str2); + for ( const char * strAdd = va_arg(ap,const char*); + strAdd != 0; + strAdd = va_arg(ap,const char*) ) + { + size_type nLen = strlen(strAdd); + ProvideAddingSize( nLen ); + memcpy(pCur, strAdd, nLen); + Advance(nLen); + } // end for + va_end(ap); +} + +StreamStr::StreamStr( const self & i_rOther ) + : bostream(), + nCapacity1( i_rOther.nCapacity1 ), + dpData( new char [i_rOther.nCapacity1] ), + pEnd( dpData + strlen(i_rOther.dpData) ), + pCur( dpData + i_rOther.tellp() ), + eMode(i_rOther.eMode) +{ + strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) +} + +StreamStr::StreamStr(csv::bstream & i_source) + : bostream(), + nCapacity1(0), + dpData(0), + pEnd(0), + pCur(0), + eMode(str::overwrite) +{ + i_source.seek(0, csv::end); + nCapacity1 = static_cast<size_type>(i_source.position()) + 1; + i_source.seek(0); + + dpData = new char[nCapacity1]; + i_source.read(dpData, nCapacity1 - 1); + pCur = dpData + nCapacity1 - 1; + pEnd = pCur; + *pCur = '\0'; +} + +StreamStr::~StreamStr() +{ + delete [] dpData; +} + + +StreamStr & +StreamStr::operator=( const self & i_rOther ) +{ + delete [] dpData; + + nCapacity1 = i_rOther.nCapacity1; + dpData = new char [i_rOther.nCapacity1]; + pEnd = dpData + strlen(i_rOther.dpData); + strcpy( dpData, i_rOther.dpData ); // SAFE STRCPY (#100211# - checked) + pCur = dpData + i_rOther.tellp(); + eMode = i_rOther.eMode; + + return *this; +} + +StreamStr & +StreamStr::operator<<( const char * i_s ) +{ + size_type nLength = strlen(i_s); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_s, nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator<<( const String & i_s ) +{ + size_type nLength = i_s.length(); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_s.c_str(), nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator<<( char i_c ) +{ + ProvideAddingSize( 1 ); + *pCur = i_c; + Advance(1); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned char i_c ) +{ + return operator<<( char(i_c) ); +} + +StreamStr & +StreamStr::operator<<( signed char i_c ) +{ + return operator<<( char(i_c) ); +} + +StreamStr & +StreamStr::operator<<( short i_n ) +{ + char buf[C_short_max_size] = ""; + sprintf( buf, "%hi", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned short i_n ) +{ + char buf[C_short_max_size] = ""; + sprintf( buf, "%hu", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( int i_n ) +{ + char buf[C_int_max_size] = ""; + sprintf( buf, "%i", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned int i_n ) +{ + char buf[C_int_max_size] = ""; + sprintf( buf, "%u", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( long i_n ) +{ + char buf[C_long_max_size] = ""; + sprintf( buf, "%li", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( unsigned long i_n ) +{ + char buf[C_long_max_size] = ""; + sprintf( buf, "%lu", i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( float i_n ) +{ + const int C_float_max_size = 20; + char buf[C_float_max_size] = ""; + sprintf( buf, "%.*g", C_float_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +StreamStr & +StreamStr::operator<<( double i_n ) +{ + const int C_double_max_size = 30; + char buf[C_double_max_size] = ""; + sprintf( buf, "%.*lg", C_double_max_size-8, i_n ); // SAFE SPRINTF (#100211# - checked) + + size_type nLength = strlen(buf); + ProvideAddingSize( nLength ); + memcpy( pCur, buf, nLength ); + Advance( nLength ); + + return *this; +} + +const char & +StreamStr::operator[]( position_type i_nPosition ) const +{ + static const char aNull_ = '\0'; + + if ( position_type(pEnd - dpData) > i_nPosition ) + return dpData[i_nPosition]; + return aNull_; +} + +char & +StreamStr::operator[]( position_type i_nPosition ) +{ + static char aDummy_ = '\0'; + + if ( position_type(pEnd - dpData) > i_nPosition ) + return dpData[i_nPosition]; + return aDummy_; +} + +void +StreamStr::resize( size_type i_nMinimumCapacity ) +{ + if ( i_nMinimumCapacity <= capacity() ) + return; + + Resize(i_nMinimumCapacity); +} + +void +StreamStr::swap( StreamStr & io_swap ) +{ + size_type + n = io_swap.nCapacity1; + io_swap.nCapacity1 = nCapacity1; + nCapacity1 = n; + + char * + p = io_swap.dpData; + io_swap.dpData = dpData; + dpData = p; + + p = io_swap.pEnd; + io_swap.pEnd = pEnd; + pEnd = p; + + p = io_swap.pCur; + io_swap.pCur = pCur; + pCur = p; + + insert_mode + m = io_swap.eMode; + io_swap.eMode = eMode; + eMode = m; +} + +StreamStr & +StreamStr::seekp( seek_type i_nCount, + seek_dir i_eDirection ) +{ + seek_type nLength = seek_type( length() ); + seek_type nNewPos = tellp(); + + switch ( i_eDirection ) + { + case ::csv::beg: nNewPos = i_nCount; + break; + case ::csv::cur: nNewPos += i_nCount; + break; + case ::csv::end: nNewPos = nLength + i_nCount; + break; + } + + if ( in_range<seek_type>(0, nNewPos, nLength + 1) ) + { + pCur = dpData + nNewPos; + if (eMode == str::overwrite) + { + pEnd = pCur; + *pEnd = '\0'; + } + } + + return *this; +} + +StreamStr & +StreamStr::set_insert_mode( insert_mode i_eMode ) +{ + eMode = i_eMode; + return *this; +} + +void +StreamStr::push_front( const char * i_str ) +{ + insert_mode eOriginalMode = eMode; + char * pOriginalCur = pCur; + eMode = str::insert; + pCur = dpData; + + operator<<(i_str); + + eMode = eOriginalMode; + pCur = pOriginalCur + strlen(i_str); +} + +void +StreamStr::push_front( char i_c ) +{ + insert_mode eOriginalMode = eMode; + char * pOriginalCur = pCur; + eMode = str::insert; + pCur = dpData; + + operator<<(i_c); + + eMode = eOriginalMode; + pCur = pOriginalCur + 1; +} + +void +StreamStr::push_back( const char * i_str ) +{ + insert_mode eOriginalMode = eMode; + eMode = str::overwrite; + + operator<<(i_str); + + eMode = eOriginalMode; +} + +void +StreamStr::push_back( char i_c ) +{ + insert_mode eOriginalMode = eMode; + eMode = str::overwrite; + + operator<<(i_c); + + eMode = eOriginalMode; +} + +void +StreamStr::pop_front( size_type i_nCount ) +{ + size_type nCount = min(i_nCount, length()); + + MoveData( dpData + nCount, pEnd, -(seek_type(nCount)) ); + + pCur -= nCount; + pEnd -= nCount; + *pEnd = '\0'; +} + +void +StreamStr::pop_back( size_type i_nCount ) +{ + size_type nCount = min(i_nCount, length()); + pEnd -= nCount; + if (pCur > pEnd) + pCur = pEnd; + *pEnd = '\0'; +} + +StreamStr & +StreamStr::operator_join( std::vector<String>::const_iterator i_rBegin, + std::vector<String>::const_iterator i_rEnd, + const char * i_sLink ) +{ + std::vector<String>::const_iterator it = i_rBegin; + if ( it != i_rEnd ) + { + operator<<(*it); + for ( ++it; it != i_rEnd; ++it ) + { + operator<<(i_sLink); + operator<<(*it); + } + } + return *this; +} + +StreamStr & +StreamStr::operator_add_substr( const char * i_sText, + size_type i_nLength ) +{ + size_type nLength = csv::min<size_type>(i_nLength, strlen(i_sText)); + + ProvideAddingSize( nLength ); + memcpy( pCur, i_sText, nLength ); + Advance(nLength); + + return *this; +} + +StreamStr & +StreamStr::operator_add_token( const char * i_sText, + char i_cDelimiter ) +{ + const char * pTokenEnd = strchr(i_sText, i_cDelimiter); + if (pTokenEnd == 0) + operator<<(i_sText); + else + operator_add_substr(i_sText, pTokenEnd-i_sText); + return *this; +} + +StreamStr & +StreamStr::operator_read_line( bstream & i_src ) +{ + char c = 0; + intt nCount = 0; + for ( nCount = i_src.read(&c, 1); + nCount == 1 AND c != 13 AND c != 10; + nCount = i_src.read(&c, 1) ) + { + operator<<(c); + } + + bool bEndOfStream = nCount == 0; + // Check for line-end: + if ( NOT bEndOfStream AND c != 0 ) + { + char oldc = c; + if (i_src.read(&c, 1) == 1) + { + if ( (c != 13 AND c != 10) OR c == oldc) + i_src.seek(-1,::csv::cur); + } + } + return *this; +} + +void +StreamStr::strip_front(char i_cToRemove) +{ + const_iterator it = begin(); + for ( ; + it != end() ? *it == i_cToRemove : false; + ++it ) ; + pop_front(it - begin()); +} + +void +StreamStr::strip_back(char i_cToRemove) +{ + const_iterator it = end(); + for ( ; + it != begin() ? *(it-1) == i_cToRemove : false; + --it ) ; + pop_back(end() - it); +} + +void +StreamStr::strip_frontback(char i_cToRemove) +{ + strip_front(i_cToRemove); + strip_back(i_cToRemove); +} + +void +StreamStr::strip_front_whitespace() +{ + const_iterator it = begin(); + for ( ; + it != end() ? *it < 33 : false; + ++it ) ; + pop_front(it - begin()); +} + +void +StreamStr::strip_back_whitespace() +{ + const_iterator it = end(); + for ( ; + it != begin() ? *(it-1) < 33 : false; + --it ) ; + pop_back(end() - it); +} + +void +StreamStr::strip_frontback_whitespace() +{ + strip_front_whitespace(); + strip_back_whitespace(); +} + +void +StreamStr::remove( iterator i_begin, + iterator i_end ) +{ + csv_assert(i_begin >= dpData AND i_begin <= pEnd); + csv_assert(i_end >= dpData AND i_end <= pEnd); + csv_assert(i_end >= i_begin); + MoveData(i_end, pEnd, i_begin - i_end); + pCur = pEnd; +} + +void +StreamStr::replace( position_type i_nStart, + size_type i_nSize, + Area i_aReplacement ) +{ + if (i_nStart >= length() OR i_nSize < 1) + return; + + insert_mode eOldMode = eMode; + eMode = str::insert; + pCur = dpData + i_nStart; + + size_type anz = min( length() - i_nStart, i_nSize ); + + if ( anz < i_aReplacement.nLength ) + { + ProvideAddingSize( i_aReplacement.nLength - anz ); + } + else if ( anz > i_aReplacement.nLength ) + { + seek_type nMove = seek_type(anz - i_aReplacement.nLength); + + MoveData( dpData + i_nStart + anz, + pEnd, + -nMove ); + pEnd -= nMove; + *pEnd = '\0'; + } + + if (i_aReplacement.nLength > 0) + { + memcpy( dpData + i_nStart, i_aReplacement.sStr, i_aReplacement.nLength ); + Advance(i_aReplacement.nLength); + } + + eMode = eOldMode; + pCur = pEnd; +} + +void +StreamStr::replace_all( char i_cCarToSearch, + char i_cReplacement ) +{ + for ( char * p = dpData; p != pEnd; ++p ) + { + if (*p == i_cCarToSearch) + *p = i_cReplacement; + } +} + +void +StreamStr::replace_all( Area i_aStrToSearch, + Area i_aReplacement ) +{ + position_type p = 0; + const char * pSearch = i_aStrToSearch.sStr; + size_type nSearch = i_aStrToSearch.nLength; + + while ( p <= length() - nSearch ) + { + if ( strncmp(dpData+p, pSearch, nSearch) == 0 ) + { + replace( p, nSearch, i_aReplacement ); + p += i_aReplacement.nLength; + } + else + { + ++p; + } + } // end while +} + +StreamStr & +StreamStr::to_lower( position_type i_nStart, + size_type i_nLength ) +{ + static char cLower[128] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95, + 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111, + 112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127 }; + + if ( i_nStart < length() ) + { + char * pStop = i_nStart + i_nLength < length() + ? dpData + i_nStart + i_nLength + : pEnd; + for ( char * pChange = dpData + i_nStart; + pChange != pStop; + ++pChange ) + { + *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 + ? cLower[ UINT8(*pChange) ] + : *pChange; + } + } + return *this; +} + +StreamStr & +StreamStr::to_upper( position_type i_nStart, + size_type i_nLength ) +{ + static char cUpper[128] = + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123,124,125,126,127 }; + + if ( i_nStart < length() ) + { + char * pStop = i_nStart + i_nLength < length() + ? dpData + i_nStart + i_nLength + : pEnd; + for ( char * pChange = dpData + i_nStart; + pChange != pStop; + ++pChange ) + { + *pChange = (static_cast< unsigned char >(*pChange) & 0x80) == 0 + ? cUpper[ UINT8(*pChange) ] + : *pChange; + } + } + return *this; +} + + +StreamStr::size_type +StreamStr::token_count( char i_cSplit ) const +{ + return count_chars(dpData, i_cSplit) + 1; +} + +String +StreamStr::token( position_type i_nNr, + char i_cSplit ) const +{ + // Find begin: + const char * pTokenBegin = dpData; + for ( position_type nNr = i_nNr; + nNr > 0; + --nNr ) + { + pTokenBegin = strchr(pTokenBegin,i_cSplit); + if (pTokenBegin == 0) + return String(""); + ++pTokenBegin; + } + + // Find end: + const char * pTokenEnd = strchr(pTokenBegin, i_cSplit); + if (pTokenEnd == 0) + pTokenEnd = pEnd; + + return String(pTokenBegin, size_type(pTokenEnd-pTokenBegin) ); +} + +class StreamStrPool +{ + public: + StreamStrPool(); + ~StreamStrPool(); + private: + // Non-copyable + StreamStrPool(StreamStrPool &); // not defined + void operator =(StreamStrPool &); // not defined + + // Interface to: + friend class StreamStrLock; + static StreamStr & AcquireFromPool_( + uintt i_nMinimalSize ); + static void ReleaseToPool_( + DYN StreamStr * let_dpUsedStr ); + + // DATA + SweList< DYN StreamStr* > + aPool; +}; + +StreamStrPool::StreamStrPool() +{ +} + +StreamStrPool::~StreamStrPool() +{ + for ( SweList< DYN StreamStr* >::iterator it = aPool.begin(); + it != aPool.end(); + ++it ) + { + delete (*it); + } +} + +namespace +{ + static StreamStrPool aPool_; +} + + +StreamStr & +StreamStrPool::AcquireFromPool_( uintt i_nMinimalSize ) +{ + if ( aPool_.aPool.empty() ) + { + return *new StreamStr(i_nMinimalSize); + } + + StreamStr & ret = *aPool_.aPool.front(); + aPool_.aPool.pop_front(); + ret.resize(i_nMinimalSize); + ret.seekp(0); + ret.set_insert_mode(str::overwrite); + return ret; +} + +void +StreamStrPool::ReleaseToPool_( DYN StreamStr * let_dpUsedStr ) +{ + aPool_.aPool.push_back( let_dpUsedStr ); +} + +StreamStrLock::StreamStrLock( uintt i_nMinimalSize ) + : pStr( &StreamStrPool::AcquireFromPool_(i_nMinimalSize) ) +{ +} + +StreamStrLock::~StreamStrLock() +{ + StreamStrPool::ReleaseToPool_(pStr); +} + + +UINT32 +StreamStr::do_write( const void * i_pSrc, + UINT32 i_nNrofBytes ) +{ + ProvideAddingSize( i_nNrofBytes ); + memcpy( pCur, i_pSrc, i_nNrofBytes ); + Advance(i_nNrofBytes); + + return i_nNrofBytes; +} + +void +StreamStr::ProvideAddingSize( size_type i_nSize2Add ) +{ + size_type nLength = length(); + if ( capacity() - nLength < i_nSize2Add ) + Resize( nLength + i_nSize2Add ); + + pEnd += i_nSize2Add; + *pEnd = '\0'; + + if (eMode == str::insert AND pCur != pEnd) + { + MoveData( pCur, pCur + i_nSize2Add, seek_type(i_nSize2Add) ); + } +} + +void +StreamStr::Resize( size_type i_nMinimumCapacity ) +{ + size_type nNewSize = nCapacity1 < 128 + ? nCapacity1 << 1 + : (nCapacity1 << 1) - (nCapacity1 >> 1); + nCapacity1 = csv::max( nNewSize, size_type(i_nMinimumCapacity + 1) ); + + char * pNew = new char[nCapacity1]; + strcpy ( pNew, dpData ); // SAFE STRCPY (#100211# - checked) + pEnd = pNew + (pEnd - dpData); + pCur = pNew + (pCur - dpData); + + delete [] dpData; + dpData = pNew; +} + +void +StreamStr::MoveData( char * i_pStart, + char * i_pEnd, + seek_type i_nDiff ) +{ + if (i_nDiff > 0) + { + register const char * pSrc = i_pEnd; + register char * pDest = i_pEnd + i_nDiff; + for ( ; pSrc != i_pStart; --pSrc, --pDest ) + { + *pDest = *pSrc; + } + *pDest = *pSrc; + } + else if (i_nDiff < 0) + { + const char * pSrc = i_pStart; + char * pDest = i_pStart + i_nDiff; + for ( ; pSrc != i_pEnd; ++pSrc, ++pDest ) + { + *pDest = *pSrc; + } + } +} + +// Does nothing, only the name of this function is needed. +void +c_str() +{ + // Does nothing. +} + + + +void +Split( std::vector<String> & o_list, + const char * i_text ) +{ + const char * + pCurrentToken = 0; + bool + white = false; + for (const char * p = i_text; *p != '\0'; ++p) + { + white = UINT8(*p) > 32; + if (pCurrentToken != 0) + { + if (white) + { + o_list.push_back(String(pCurrentToken, p)); + pCurrentToken = 0; + } + } + else + { + if ( NOT white) + pCurrentToken = p; + } // endif (bInToken) else + } // end for + + if (pCurrentToken != 0) + { + o_list.push_back(String(pCurrentToken)); + } +} + + + + +} // namespace csv diff --git a/cosv/source/strings/string.cxx b/cosv/source/strings/string.cxx new file mode 100644 index 000000000000..92ac305f8f32 --- /dev/null +++ b/cosv/source/strings/string.cxx @@ -0,0 +1,414 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/string.hxx> + +// NOT FULLY DECLARED SERVICES +#include <string.h> +#include <cosv/comfunc.hxx> + + + + +namespace csv +{ + + +inline const char * +str_from_StringOffset( const String & i_rStr, + str::size i_nOffset ) +{ + return i_nOffset < i_rStr.size() + ? i_rStr.c_str() + i_nOffset + : ""; +} + +inline const char * +str_from_ptr( const char * i_str ) +{ + + return valid_str(i_str); +} + + +//********************* String::S_Data **********************// + +inline String:: +S_Data::S_Data() + : nCount(1) +{ +} + +String:: +S_Data::S_Data( const char * i_sData, + size_type i_nValidLength ) + : aStr( str_from_ptr(i_sData), + (i_nValidLength != str::maxsize + ? i_nValidLength + : strlen(i_sData)) ), + nCount(1) +{ +} + +String:: +S_Data::~S_Data() +{ + csv_assert( nCount == 0 ); +} + +const String::S_Data * +String:: +S_Data::Acquire() const +{ +#ifdef CSV_NO_MUTABLE + ++ (const_cast< uintt& >(nCount)); +#else + ++nCount; +#endif + return this; +} + +void +String:: +S_Data::Release() const +{ +#ifdef CSV_NO_MUTABLE + -- (const_cast< uintt& >(nCount)); +#else + --nCount; +#endif + if (nCount == 0) + delete (const_cast< S_Data* >(this)); +} + + +//************************** String **************************// + + +String::String() + : pd( String::Null_().pd->Acquire() ) +{ +} + +String::String( const char * i_str ) + : pd( new S_Data(i_str) ) +{ +} + +String::String( const char * i_str, + size_type i_nLength ) + : pd( new S_Data(i_str, i_nLength) ) +{ +} + +/* For efficiency see the previous c'tor. +*/ +String::String( const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ) + : pd( new S_Data(str_from_StringOffset(i_rStr, i_nStartPosition), i_nLength) ) +{ +} + +String::String( const_iterator i_itBegin, + const_iterator i_itEnd ) + : pd( new S_Data(i_itBegin, size_type(i_itEnd - i_itBegin)) ) +{ +} + +String::String( const self & i_rStr ) + : pd( i_rStr.pd->Acquire() ) +{ +} + +String::~String() +{ + pd->Release(); +} + + +String & +String::operator=( const self & i_rStr ) +{ + i_rStr.pd->Acquire(); + pd->Release(); + pd = i_rStr.pd; + + return *this; +} + +String & +String::operator=( const char * i_str ) +{ + const S_Data * + pTemp = new S_Data(i_str); + pd->Release(); + pd = pTemp; + + return *this; +} + +void +String::swap( self & i_rStr ) +{ + const S_Data * pTemp = pd; + pd = i_rStr.pd; + i_rStr.pd = pTemp; +} + +void +String::assign( const self & i_rStr, + position_type i_nStartPosition, + size_type i_nLength ) +{ + const S_Data * + pTemp = new S_Data( str_from_StringOffset(i_rStr, i_nStartPosition), + i_nLength ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const char * i_str ) +{ + const S_Data * + pTemp = new S_Data( i_str ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const char * i_str, + size_type i_nLength ) +{ + const S_Data * + pTemp = new S_Data( i_str, i_nLength ); + pd->Release(); + pd = pTemp; +} + +void +String::assign( const_iterator i_itBegin, + const_iterator i_itEnd ) +{ + const S_Data * + pTemp = new S_Data( i_itBegin, + size_type(i_itEnd - i_itBegin) ); + pd->Release(); + pd = pTemp; +} + + +int +String::compare( const self & i_rStr ) const +{ + return strcmp( c_str(), i_rStr.c_str() ); +} + +int +String::compare( const CharOrder_Table & i_rOrder, + const self & i_rStr ) const +{ + return csv::compare( i_rOrder, c_str(), i_rStr.c_str() ); +} + +String +String::substr( position_type i_nStartPosition, + size_type i_nLength ) const +{ + size_type nSize = size(); + + if ( i_nStartPosition < nSize ) + { + if ( i_nLength == str::maxsize + OR i_nLength >= nSize - i_nStartPosition ) + return String( c_str() + i_nStartPosition ); + else + return String( c_str() + i_nStartPosition, + i_nLength ); + } + + return Null_(); +} + +String::position_type +String::find( const char * i_strToSearch, + position_type i_nSearchStartPosition ) const +{ + csv_assert(i_strToSearch != 0); + + if ( i_nSearchStartPosition < length() + AND + *i_strToSearch != '\0' ) + { + const char * p = strstr(c_str() + i_nSearchStartPosition, i_strToSearch); + if (p != 0) + return static_cast<position_type>(p - c_str()); + } + return str::position(str::npos); +} + +String::position_type +String::find( char i_charToSearch, + position_type i_nSearchStartPosition ) const +{ + if (i_nSearchStartPosition <= length()) + { + const char * p = strchr(c_str() + i_nSearchStartPosition, i_charToSearch); + if (p != 0) + return static_cast<position_type>(p - c_str()); + } + return str::position(str::npos); +} + +const String & +String::Null_() +{ + // Must not use the default constructor! Because that one calls + // this function, which would create a circular dependency. + static const String aNull_(""); + return aNull_; +} + +const char & +String::Nulch_() +{ + static const char cNull_ = '\0'; + return cNull_; +} + + +int +compare( const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * pS1 = str_from_StringOffset( i_s1, i_nStartPosition1 ); + + if ( i_nLength != csv::str::maxsize ) + return strncmp( pS1, + i_s2, + i_nLength ); + else + return strcmp( pS1, + i_s2 ); +} + +int +compare( const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ) +{ + const char * pS2 = str_from_StringOffset( i_s2, i_nStartPosition2 ); + + if ( i_nLength != csv::str::maxsize ) + return strncmp( i_s1, + pS2, + i_nLength ); + else + return strcmp( i_s1, + pS2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2 ) +{ + const char * it1 = i_s1; + const char * it2 = i_s2; + for ( ; i_rOrder(*it1) == i_rOrder(*it2) AND *it1 != '\0'; ++it1, ++it2 ) + {} + return int( i_rOrder(*it1) - i_rOrder(*it2) ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const String & i_s1, + csv::str::position i_nStartPosition1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * pS1 = str_from_StringOffset( i_s1, i_nStartPosition1 ); + + if ( i_nLength != csv::str::maxsize ) + return compare( i_rOrder, + pS1, + i_s2, + i_nLength ); + else + return compare( i_rOrder, + pS1, + i_s2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const String & i_s2, + csv::str::position i_nStartPosition2, + csv::str::size i_nLength ) +{ + const char * pS2 = str_from_StringOffset( i_s2, i_nStartPosition2 ); + + if ( i_nLength != csv::str::maxsize ) + return compare( i_rOrder, + i_s1, + pS2, + i_nLength ); + else + return compare( i_rOrder, + i_s1, + pS2 ); +} + +int +compare( const CharOrder_Table & i_rOrder, + const char * i_s1, + const char * i_s2, + csv::str::size i_nLength ) +{ + const char * sEnd = i_s1 + i_nLength; + + const char * it1 = i_s1; + const char * it2 = i_s2; + for ( ; i_rOrder(*it1) == i_rOrder(*it2) AND *it1 != '\0' AND it1 != sEnd; ++it1, ++it2 ) + {} + + if ( it1 != sEnd ) + return int( i_rOrder(*it1) - i_rOrder(*it2) ); + else + return 0; +} + + + + +} // namespace csv diff --git a/cosv/source/unittest/file_ut.cxx b/cosv/source/unittest/file_ut.cxx new file mode 100644 index 000000000000..b1c2a0a17cb9 --- /dev/null +++ b/cosv/source/unittest/file_ut.cxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/file.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ut.hxx> + +using csv::File; + + +/** @file + UnitTests for class File. +*/ + +FUT_DECL( File, Read ); +FUT_DECL( File, Write ); +FUT_DECL( File, Seek ); +FUT_DECL( File, SeekBack ); +FUT_DECL( File, SeekRelative ); + + +bool +classtest_File() +{ + csv::File aFile( "bigfile.txt", csv::CFM_RW, 0 ); + csv::File & rFile = aFile; + + rFile.Open(); + + bool ret = ftest_Read( rFile ); + ret = ftest_Write( rFile ) AND ret; + ret = ftest_SeekBack( rFile ) AND ret; + ret = ftest_SeekRelative( rFile ) AND ret; + + rFile.Close(); + + return ret; +} + + + +FUT_DECL( File, Read ) +{ + bool ret = true; + + rFile.SeekBack(0); + uintt nSourceSize = rFile.Position(); + rFile.Seek(0); + + char * pBuf = new char[nSourceSize+1]; + uintt nCount = rFile.Read(pBuf,nSourceSize); + + UT_CHECK( Read, nCount == nSourceSize ); + + return ret; +} + +FUT_DECL( File, Write ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, Seek ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, SeekBack ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( File, SeekRelative ) +{ + bool ret = true; + + + + return ret; +} + + + diff --git a/cosv/source/unittest/makefile.mk b/cosv/source/unittest/makefile.mk new file mode 100644 index 000000000000..173ce8c991fe --- /dev/null +++ b/cosv/source/unittest/makefile.mk @@ -0,0 +1,80 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=cosv +TARGET=cosv_unittest +TARGETTYPE=CUI + +# --- Settings ----------------------------------------------------- + +ENABLE_EXCEPTIONS=true +PRJINC=$(PRJ)$/source + +.INCLUDE : settings.mk +.INCLUDE : static.mk + +.INCLUDE : $(PRJ)$/source$/fullcpp.mk + + + + +# --- Files -------------------------------------------------------- + +OBJFILES= \ + $(OBJ)$/file_ut.obj \ + $(OBJ)$/simplestring_ut.obj + + + + +APP1TARGET= $(TARGET) +APP1STACK= 1000000 +APP1OBJS= $(OBJ)$/ut_main.obj + +.IF "$(GUI)"=="WNT" +APP1STDLIBS= $(LIBSTLPORT) +.ELSE +.IF "$(OS)"=="MACOSX" +APP1STDLIBS= $(LIBSTLPORT) +.ENDIF +.ENDIF + + +APP1LIBS= $(LB)$/$(TARGET).lib $(LB)$/cosv.lib + + +APP1DEPN= $(LB)$/$(TARGET).lib $(LB)$/cosv.lib + + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + + diff --git a/cosv/source/unittest/string_ut.cxx b/cosv/source/unittest/string_ut.cxx new file mode 100644 index 000000000000..690950d8ee97 --- /dev/null +++ b/cosv/source/unittest/string_ut.cxx @@ -0,0 +1,140 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> +#include <cosv/string.hxx> + +// NOT FULLY DECLARED SERVICES +#include <ut.hxx> + +using csv::SimpleString; + + +/** @file + UnitTests for class String. +*/ + +inline bool +check_value( const String & a, const char * b ) +{ + return strcmp( a.c_str(), b ) == 0; +} + + +bool +classtest_String( csv::SimpleString & rSimpleString ) +{ + bool ret = true; + + String x1; + UT_CHECK( String(), check_value(x1,"") ) + + const char * s2a = ""; + String x2a(s2a); + UT_CHECK( String(const char*), check_value(x2a,s2a) ) + + const char * s2b = "_zluoadninger prrg chiäßi(/%$##@\\\"'''fh kl"; + String x2b(s2b); + UT_CHECK( String(const char*), check_value(x2b,s2b) ) + + + bool ret = ftest_Read( rSimpleString ); + ret = ftest_Write( rSimpleString ) AND ret; + ret = ftest_SeekBack( rSimpleString ) AND ret; + ret = ftest_SeekRelative( rSimpleString ) AND ret; + + rSimpleString.Close(); + + return ret; +} + + + + +#if 0 +FUT_DECL( SimpleString, Ctor_Def ); +FUT_DECL( SimpleString, Seek ); +FUT_DECL( SimpleString, SeekBack ); +FUT_DECL( SimpleString, SeekRelative ); + + + +FUT_DECL( SimpleString, Read ) +{ + bool ret = true; + + rSimpleString.SeekBack(0); + uintt nSourceSize = rSimpleString.Position(); + rSimpleString.Seek(0); + + char * pBuf = new char[nSourceSize+1]; + uintt nCount = rSimpleString.Read(pBuf,nSourceSize); + + UT_CHECK( Read, nCount == nSourceSize ); + + return ret; +} + +FUT_DECL( SimpleString, Write ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, Seek ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, SeekBack ) +{ + bool ret = true; + + + + return ret; +} + +FUT_DECL( SimpleString, SeekRelative ) +{ + bool ret = true; + + + + return ret; +} + +#endif + + diff --git a/cosv/source/unittest/ut.hxx b/cosv/source/unittest/ut.hxx new file mode 100644 index 000000000000..b46d97f12bae --- /dev/null +++ b/cosv/source/unittest/ut.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef COSV_UNITTEST_UT_HXX +#define COSV_UNITTEST_UT_HXX + + +#define UT_CHECK( fname, cond ) \ + if ( NOT (cond) ) { std::cerr << "ftest_" << #fname << " " << #cond << endl; \ + ret = false; } + +#define CUT_DECL( nsp, cname ) \ + bool classtest_##cname() +#define FUT_DECL( cname, fname ) \ + bool ftest_##fname( cname & r##cname ) + +#define UT_RESULT( result ) \ + if (result ) std::cout << "All unit tests passed successfully." << std::endl; \ + else std::cout << "Errors in unit tests.\n" << std::endl + + + +CUT_DECL( csv, File ); +CUT_DECL( csv, String ); + +#endif + + + diff --git a/cosv/source/unittest/ut_main.cxx b/cosv/source/unittest/ut_main.cxx new file mode 100644 index 000000000000..750c628f32fb --- /dev/null +++ b/cosv/source/unittest/ut_main.cxx @@ -0,0 +1,47 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <precomp.h> + +#include <cosv/file.hxx> +#include <cosv/simplestring.hxx> +#include "ut.hxx" + + + +int _cdecl +main(int argc, char * argv[]) +{ + bool ret = classtest_File(); + ret = classtest_SimpleString AND ret; + + UT_RESULT( ret ); + + return 0; +} + + |