From 9a12f43e6b63d5f4aed273eaa0853356322c6082 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sun, 21 Apr 2013 15:35:11 +0000 Subject: [PATCH] * ./vlsisapd/src/utilities: - New: Path module to provide a ligthweight alternative to boost::filesystem. The compatibility change in boost was giving more and more touble and was not worth it. Path is aimed to provides the same services, but with a better portability. --- vlsisapd/CMakeLists.txt | 2 +- vlsisapd/cmake_modules/FindVLSISAPD.cmake | 6 + vlsisapd/src/CMakeLists.txt | 1 + vlsisapd/src/bookshelf/src/Bookshelf.cpp | 24 +- .../src/bookshelf/src/BookshelfTkMain.cpp | 23 +- vlsisapd/src/bookshelf/src/CMakeLists.txt | 5 +- vlsisapd/src/bookshelf/src/Circuit.cpp | 44 ++- vlsisapd/src/bookshelf/src/Main.cpp | 21 +- vlsisapd/src/bookshelf/src/Parser.cpp | 42 ++- .../bookshelf/src/vlsisapd/bookshelf/Parser.h | 49 ++-- vlsisapd/src/configuration/src/CMakeLists.txt | 6 +- .../src/configuration/src/ConfEditorMain.cpp | 20 +- vlsisapd/src/configuration/src/Parameter.cpp | 14 +- vlsisapd/src/utilities/CMakeLists.txt | 1 + vlsisapd/src/utilities/src/CMakeLists.txt | 17 ++ vlsisapd/src/utilities/src/Path.cpp | 265 ++++++++++++++++++ .../utilities/src/vlsisapd/utilities/Path.h | 124 ++++++++ 17 files changed, 504 insertions(+), 160 deletions(-) create mode 100644 vlsisapd/src/utilities/CMakeLists.txt create mode 100644 vlsisapd/src/utilities/src/CMakeLists.txt create mode 100644 vlsisapd/src/utilities/src/Path.cpp create mode 100644 vlsisapd/src/utilities/src/vlsisapd/utilities/Path.h diff --git a/vlsisapd/CMakeLists.txt b/vlsisapd/CMakeLists.txt index 4eb5cc8c..e51dcc7c 100644 --- a/vlsisapd/CMakeLists.txt +++ b/vlsisapd/CMakeLists.txt @@ -8,7 +8,7 @@ list(INSERT CMAKE_MODULE_PATH 0 "${VLSISAPD_SOURCE_DIR}/cmake_modules/") set_cmake_policies() - setup_boost(program_options filesystem python regex) + setup_boost(program_options python regex) find_package(LibXml2 REQUIRED) find_package(PythonSitePackages REQUIRED) diff --git a/vlsisapd/cmake_modules/FindVLSISAPD.cmake b/vlsisapd/cmake_modules/FindVLSISAPD.cmake index a16eef12..35b82a08 100644 --- a/vlsisapd/cmake_modules/FindVLSISAPD.cmake +++ b/vlsisapd/cmake_modules/FindVLSISAPD.cmake @@ -35,6 +35,12 @@ SETUP_SEARCH_DIR(VLSISAPD) IF(VLSISAPD_DIR_SEARCH) #MESSAGE("-- VLSISAPD_DIR_SEARCH: ${VLSISAPD_DIR_SEARCH}") + # Utilities + FIND_PATH (UTILITIES_INCLUDE_DIR NAMES vlsisapd/utilities/Path.h PATHS ${VLSISAPD_DIR_SEARCH} PATH_SUFFIXES include) + FIND_LIBRARY(UTILITIES_LIBRARY NAMES vlsisapdutils PATHS ${VLSISAPD_DIR_SEARCH} PATH_SUFFIXES lib${LIB_SUFFIX}) + SET_FOUND (UTILITIES) + MESSAGE("-- Utilities: ${UTILITIES_LIBRARY}") + # AGDS FIND_PATH (AGDS_INCLUDE_DIR NAMES vlsisapd/agds/GdsLibrary.h PATHS ${VLSISAPD_DIR_SEARCH} PATH_SUFFIXES include) FIND_LIBRARY(AGDS_LIBRARY NAMES agds PATHS ${VLSISAPD_DIR_SEARCH} PATH_SUFFIXES lib${LIB_SUFFIX}) diff --git a/vlsisapd/src/CMakeLists.txt b/vlsisapd/src/CMakeLists.txt index e2aee49b..d84266d9 100644 --- a/vlsisapd/src/CMakeLists.txt +++ b/vlsisapd/src/CMakeLists.txt @@ -1,3 +1,4 @@ +ADD_SUBDIRECTORY(utilities) ADD_SUBDIRECTORY(agds) ADD_SUBDIRECTORY(cif) IF(IS_DIRECTORY ${VLSISAPD_SOURCE_DIR}/src/openChams) diff --git a/vlsisapd/src/bookshelf/src/Bookshelf.cpp b/vlsisapd/src/bookshelf/src/Bookshelf.cpp index 783ebfb8..dfe579b2 100644 --- a/vlsisapd/src/bookshelf/src/Bookshelf.cpp +++ b/vlsisapd/src/bookshelf/src/Bookshelf.cpp @@ -2,31 +2,19 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | // | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | // | C++ Module : "./Bookshelf.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ -#include -#include -namespace bfs = boost::filesystem; - #include "vlsisapd/bookshelf/Bookshelf.h" #include "vlsisapd/bookshelf/BookshelfException.h" @@ -40,8 +28,8 @@ namespace Bookshelf { void BookshelfParser::readFromFile ( std::string auxFile ) { - bfs::path auxPath ( auxFile ); - if ( not bfs::exists(auxPath) ) { + Utilities::Path auxPath ( auxFile ); + if ( not auxPath.exists() ) { throw BookshelfException ( "%s .aux file not found.", auxPath.string().c_str() ); } diff --git a/vlsisapd/src/bookshelf/src/BookshelfTkMain.cpp b/vlsisapd/src/bookshelf/src/BookshelfTkMain.cpp index 7c8775d9..ea874152 100644 --- a/vlsisapd/src/bookshelf/src/BookshelfTkMain.cpp +++ b/vlsisapd/src/bookshelf/src/BookshelfTkMain.cpp @@ -2,25 +2,17 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2010, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | // | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | -// | C++ Module : "./Main.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Module : "./BookshelfTkMain.cpp" | +// +-----------------------------------------------------------------+ #include @@ -31,9 +23,6 @@ using namespace std; #include namespace boptions = boost::program_options; -#include -namespace bfs = boost::filesystem; - #include "vlsisapd/bookshelf/Exception.h" #include "vlsisapd/bookshelf/Node.h" #include "vlsisapd/bookshelf/Pin.h" @@ -146,8 +135,6 @@ int main ( int argc, char* argv[] ) exit ( 0 ); } - bfs::path::default_name_check ( bfs::portable_posix_name ); - if ( arguments.count("aux") ) { auto_ptr circuit ( Circuit::parse(arguments["aux"].as()) ); diff --git a/vlsisapd/src/bookshelf/src/CMakeLists.txt b/vlsisapd/src/bookshelf/src/CMakeLists.txt index bb66684d..cd42acb4 100644 --- a/vlsisapd/src/bookshelf/src/CMakeLists.txt +++ b/vlsisapd/src/bookshelf/src/CMakeLists.txt @@ -1,6 +1,7 @@ - include_directories ( ${VLSISAPD_SOURCE_DIR}/src/bookshelf/src + include_directories ( ${VLSISAPD_SOURCE_DIR}/src/utilities/src + ${VLSISAPD_SOURCE_DIR}/src/bookshelf/src ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ) @@ -23,7 +24,7 @@ ) set ( testcpps BookshelfTkMain.cpp ) add_library ( bookshelf ${cpps} ) - target_link_libraries ( bookshelf ${Boost_LIBRARIES} ) + target_link_libraries ( bookshelf vlsisapdutils ) set_target_properties ( bookshelf PROPERTIES VERSION 1.0 SOVERSION 1 ) add_executable ( bookshelf-tk ${testcpps} ) target_link_libraries ( bookshelf-tk bookshelf ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) diff --git a/vlsisapd/src/bookshelf/src/Circuit.cpp b/vlsisapd/src/bookshelf/src/Circuit.cpp index 13dd7209..97e242cc 100644 --- a/vlsisapd/src/bookshelf/src/Circuit.cpp +++ b/vlsisapd/src/bookshelf/src/Circuit.cpp @@ -2,28 +2,22 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | -// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | -// | C++ Module : "./Circuit.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Module : "./Circuit.cpp" | +// +-----------------------------------------------------------------+ #include +#include +#include "vlsisapd/utilities/Path.h" #include "vlsisapd/bookshelf/Exception.h" #include "vlsisapd/bookshelf/Node.h" #include "vlsisapd/bookshelf/Net.h" @@ -222,55 +216,55 @@ namespace Bookshelf { void Circuit::drive ( std::string directory, unsigned int flags ) { - bfs::path rootDirectory ( directory ); - if ( not bfs::exists(rootDirectory) ) { - bfs::create_directory ( rootDirectory ); + Utilities::Path rootDirectory ( directory ); + if ( not rootDirectory.exists() ) { + rootDirectory.mkdir(); } if ( flags & Nodes ) { - bfs::path nodesPath ( rootDirectory ); + Utilities::Path nodesPath ( rootDirectory ); if ( getNodesName().empty() ) nodesPath /= getDesignName() + ".nodes"; else nodesPath /= getNodesName(); - bfs::ofstream ofnodes ( nodesPath ); + std::ofstream ofnodes ( nodesPath.c_str() ); writeNodesToStream ( ofnodes ); ofnodes.close (); } if ( flags & Nets ) { - bfs::path netsPath ( rootDirectory ); + Utilities::Path netsPath ( rootDirectory ); if ( getNetsName().empty() ) netsPath /= getDesignName() + ".nets"; else netsPath /= getNetsName(); - bfs::ofstream ofnets ( netsPath ); + std::ofstream ofnets ( netsPath.c_str() ); writeNetsToStream ( ofnets ); ofnets.close (); } if ( (flags & Scl) and (hasScl()) ) { - bfs::path sclPath ( rootDirectory ); + Utilities::Path sclPath ( rootDirectory ); if ( getSclName().empty() ) sclPath /= getDesignName() + ".scl"; else sclPath /= getSclName(); - bfs::ofstream ofscl ( sclPath ); + std::ofstream ofscl ( sclPath.c_str() ); writeSclToStream ( ofscl ); ofscl.close (); } if ( (flags & Pl) and (hasPl()) ) { - bfs::path plPath ( rootDirectory ); + Utilities::Path plPath ( rootDirectory ); if ( getPlName().empty() ) plPath /= getDesignName() + ".pl"; else plPath /= getPlName(); - bfs::ofstream ofpl ( plPath ); + std::ofstream ofpl ( plPath.c_str() ); writePlToStream ( ofpl ); ofpl.close (); } diff --git a/vlsisapd/src/bookshelf/src/Main.cpp b/vlsisapd/src/bookshelf/src/Main.cpp index 85340503..4c235e3e 100644 --- a/vlsisapd/src/bookshelf/src/Main.cpp +++ b/vlsisapd/src/bookshelf/src/Main.cpp @@ -2,25 +2,17 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | // | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | // | C++ Module : "./Main.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ #include @@ -30,9 +22,6 @@ using namespace std; #include namespace boptions = boost::program_options; -#include -namespace bfs = boost::filesystem; - #include "vlsisapd/bookshelf/Exception.h" #include "vlsisapd/bookshelf/Node.h" #include "vlsisapd/bookshelf/Pin.h" @@ -62,8 +51,6 @@ int main ( int argc, char* argv[] ) exit ( 0 ); } - bfs::path::default_name_check ( bfs::portable_posix_name ); - if ( arguments.count("aux") ) { auto_ptr circuit ( Circuit::parse(arguments["aux"].as()) ); diff --git a/vlsisapd/src/bookshelf/src/Parser.cpp b/vlsisapd/src/bookshelf/src/Parser.cpp index 31d8f926..928723e9 100644 --- a/vlsisapd/src/bookshelf/src/Parser.cpp +++ b/vlsisapd/src/bookshelf/src/Parser.cpp @@ -2,25 +2,17 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | -// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | -// | C++ Module : "./Parser.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Module : "./Parser.cpp" | +// +-----------------------------------------------------------------+ #include @@ -87,10 +79,10 @@ namespace Bookshelf { { } - bool Parser::_openStream ( const bfs::path& filePath ) + bool Parser::_openStream ( const Utilities::Path& filePath ) { if ( _stream.is_open() ) _closeStream(); - _stream.open ( filePath ); + _stream.open ( filePath.string() ); _lineno = 0; return _stream.is_open(); @@ -229,7 +221,7 @@ namespace Bookshelf { } - void Parser::_parseNodes ( const bfs::path& nodesPath ) + void Parser::_parseNodes ( const Utilities::Path& nodesPath ) { _circuit->setNodesName ( nodesPath.string()); @@ -334,7 +326,7 @@ namespace Bookshelf { } - void Parser::_parseNets ( const bfs::path& netsPath ) + void Parser::_parseNets ( const Utilities::Path& netsPath ) { _circuit->setNetsName ( netsPath.string()); @@ -377,7 +369,7 @@ namespace Bookshelf { } - void Parser::_parseWts ( const bfs::path& nodesPath ) + void Parser::_parseWts ( const Utilities::Path& nodesPath ) { //_circuit->setWtsName ( wtsPath.string()); @@ -466,7 +458,7 @@ namespace Bookshelf { } - void Parser::_parseScl ( const bfs::path& sclPath ) + void Parser::_parseScl ( const Utilities::Path& sclPath ) { _circuit->setSclName ( sclPath.string()); @@ -565,7 +557,7 @@ namespace Bookshelf { } - void Parser::_parsePl ( const bfs::path& plPath ) + void Parser::_parsePl ( const Utilities::Path& plPath ) { _circuit->setPlName ( plPath.string()); @@ -590,8 +582,8 @@ namespace Bookshelf { Circuit* Parser::parse ( std::string designName, unsigned int flags ) { - bfs::path auxPath ( designName+".aux" ); - if ( not bfs::exists(auxPath) ) { + Utilities::Path auxPath ( designName+".aux" ); + if ( not auxPath.exists() ) { throw Exception ( "%s .aux file not found.", auxPath.string().c_str() ); } @@ -649,8 +641,8 @@ namespace Bookshelf { for ( size_t iext=0 ; iext<5 ; ++iext ) { if ( ordereds[iext].empty() ) continue; - bfs::path slotPath ( ordereds[iext] ); - if ( bfs::exists(slotPath) ) { + Utilities::Path slotPath ( ordereds[iext] ); + if ( slotPath.exists() ) { std::cout << " o Reading <" << slotPath.string() << ">" << std::endl; switch ( iext ) { diff --git a/vlsisapd/src/bookshelf/src/vlsisapd/bookshelf/Parser.h b/vlsisapd/src/bookshelf/src/vlsisapd/bookshelf/Parser.h index 84aecd18..a3325dbe 100644 --- a/vlsisapd/src/bookshelf/src/vlsisapd/bookshelf/Parser.h +++ b/vlsisapd/src/bookshelf/src/vlsisapd/bookshelf/Parser.h @@ -2,37 +2,27 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | -// | C O R I O L I S | +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | // | B o o k s h e l f P a r s e r | // | | // | Author : Jean-Paul CHAPUT | -// | E-mail : Jean-Paul.Chaput@asim.lip6.fr | +// | E-mail : Jean-Paul.Chaput@lip6.fr | // | =============================================================== | -// | C++ Header : "./bookshelf/Parser.h" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// | C++ Header : "./vlsisapd/bookshelf/Parser.cpp" | +// +-----------------------------------------------------------------+ -#ifndef __VLSISAPD_BOOKSHELF_PARSER__ -#define __VLSISAPD_BOOKSHELF_PARSER__ - -#include -#include -namespace bfs = boost::filesystem; +#ifndef VLSISAPD_BOOKSHELF_PARSER_H +#define VLSISAPD_BOOKSHELF_PARSER_H #include #include +#include #include +#include "vlsisapd/utilities/Path.h" namespace Bookshelf { @@ -45,26 +35,26 @@ namespace Bookshelf { Parser (); Circuit* parse ( std::string designName, unsigned int flags ); private: - bool _openStream ( const bfs::path& ); + bool _openStream ( const Utilities::Path& ); void _closeStream (); char* _readLine (); void _tokenize (); void _checkExtraDatas ( size_t maxtoken, std::vector& ); void _parseFormatRevision ( const std::string& slotName ); size_t _parseNum ( const std::string& slotName, const std::string& token ); - void _parseNodes ( const bfs::path& ); + void _parseNodes ( const Utilities::Path& ); void _parseNodesNode (); - void _parseNets ( const bfs::path& ); + void _parseNets ( const Utilities::Path& ); void _parseNetsNetDegree (); void _parseNetsPin (); - void _parseWts ( const bfs::path& ); - void _parseScl ( const bfs::path& ); + void _parseWts ( const Utilities::Path& ); + void _parseScl ( const Utilities::Path& ); void _parseSclCoreRow (); void _parseSclSiteorient (); void _parseSclSitesymmetry (); void _parseSclSubrowOrigin (); void _parseSclCorerowEnd (); - void _parsePl ( const bfs::path& ); + void _parsePl ( const Utilities::Path& ); void _parsePlNodePlace (); inline bool _isComment () const; inline bool _hasExtraDatas () const; @@ -72,7 +62,7 @@ namespace Bookshelf { enum Misc { BufferSize=4096 }; private: size_t _lineno; - bfs::ifstream _stream; + std::ifstream _stream; char _buffer[BufferSize]; std::vector _tokens; unsigned int _flags; @@ -87,7 +77,6 @@ namespace Bookshelf { inline bool Parser::_hasExtraDatas () const { return _flags&ExtraDatas; } -} // End of Bookshelf namespace. +} // Bookshelf namespace. - -#endif // __VLSISAPD_BOOKSHELF_PARSER__ +#endif // VLSISAPD_BOOKSHELF_PARSER_H diff --git a/vlsisapd/src/configuration/src/CMakeLists.txt b/vlsisapd/src/configuration/src/CMakeLists.txt index 856f9bca..0da505a5 100644 --- a/vlsisapd/src/configuration/src/CMakeLists.txt +++ b/vlsisapd/src/configuration/src/CMakeLists.txt @@ -1,7 +1,8 @@ include ( ${QT_USE_FILE} ) - include_directories ( ${VLSISAPD_SOURCE_DIR}/src/configuration/src + include_directories ( ${VLSISAPD_SOURCE_DIR}/src/utilities/src + ${VLSISAPD_SOURCE_DIR}/src/configuration/src ${VLSISAPD_SOURCE_DIR}/src/openChams/src ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} @@ -40,7 +41,8 @@ add_library ( configuration ${cpps} ${mocCpps} ${RCC_SRCS} ) set_target_properties ( configuration PROPERTIES VERSION 1.0 SOVERSION 1 ) - target_link_libraries ( configuration ${QT_LIBRARIES} + target_link_libraries ( configuration vlsisapdutils + ${QT_LIBRARIES} ${PYTHON_LIBRARIES} ${LIBXML2_LIBRARIES} ${Boost_LIBRARIES} diff --git a/vlsisapd/src/configuration/src/ConfEditorMain.cpp b/vlsisapd/src/configuration/src/ConfEditorMain.cpp index ea184d96..5ae298ea 100644 --- a/vlsisapd/src/configuration/src/ConfEditorMain.cpp +++ b/vlsisapd/src/configuration/src/ConfEditorMain.cpp @@ -2,7 +2,7 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2012, All Rights Reserved +// Copyright (c) UPMC 2008-2013, All Rights Reserved // // +-----------------------------------------------------------------+ // | V L S I Stand - Alone Parsers / Drivers | @@ -22,13 +22,11 @@ #include namespace boptions = boost::program_options; -#include -namespace bfs = boost::filesystem; - #include #if (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) and not defined (__APPLE__) # include #endif +#include "vlsisapd/utilities/Path.h" #include "vlsisapd/configuration/Configuration.h" #include "vlsisapd/configuration/ConfigurationWidget.h" #include "vlsisapd/configuration/ConfEditorWidget.h" @@ -67,13 +65,11 @@ int main ( int argc, char* argv[] ) if ( not disableGtkStyle ) qa->setStyle ( new QGtkStyle() ); #endif - bfs::path::default_name_check ( bfs::portable_posix_name ); - Configuration* conf = Configuration::get (); if ( arguments.count("conf") ) { - bfs::path confPath = ( arguments["conf"].as() ); - if ( bfs::exists(confPath) ) { + Utilities::Path confPath = ( arguments["conf"].as() ); + if ( confPath.exists() ) { cout << "Reading configuration: <" << confPath.string() << ">." << endl; conf->readFromFile ( confPath.string() ); } else { @@ -81,8 +77,8 @@ int main ( int argc, char* argv[] ) } } - bfs::path dotConfPath ( "./.coriolis2.configuration.xml" ); - if ( bfs::exists(dotConfPath) ) { + Utilities::Path dotConfPath ( "./.coriolis2.configuration.xml" ); + if ( dotConfPath.exists() ) { cout << "Reading dot configuration: <" << dotConfPath.string() << ">." << endl; conf->readFromFile ( dotConfPath.string() ); } @@ -90,8 +86,8 @@ int main ( int argc, char* argv[] ) //cout << "misc.catchCore: " << conf->getParameter("misc.catchCore" )->asBool() << endl; //cout << "kite.eventsLimit: " << conf->getParameter("kite.eventsLimit")->asInt () << endl; - bfs::path pyDotConfPath ( "./.coriolis2.configuration.py" ); - if ( bfs::exists(pyDotConfPath) ) { + Utilities::Path pyDotConfPath ( "./.coriolis2.configuration.py" ); + if ( pyDotConfPath.exists() ) { cout << "Reading python dot configuration: <" << pyDotConfPath.string() << ">." << endl; Py_Initialize (); FILE* fd = fopen ( pyDotConfPath.string().c_str(), "r" ); diff --git a/vlsisapd/src/configuration/src/Parameter.cpp b/vlsisapd/src/configuration/src/Parameter.cpp index d0302a56..253b6e97 100644 --- a/vlsisapd/src/configuration/src/Parameter.cpp +++ b/vlsisapd/src/configuration/src/Parameter.cpp @@ -2,11 +2,7 @@ // -*- C++ -*- // // This file is part of the VSLSI Stand-Alone Software. -// Copyright (c) UPMC/LIP6 2008-2011, All Rights Reserved -// -// =================================================================== -// -// $Id$ +// Copyright (c) UPMC 2008-2013, All Rights Reserved // // +-----------------------------------------------------------------+ // | C O R I O L I S | @@ -20,9 +16,7 @@ #include -#include -namespace bfs = boost::filesystem; - +#include "vlsisapd/utilities/Path.h" #include "vlsisapd/configuration/Parameter.h" #include "vlsisapd/configuration/Configuration.h" @@ -304,8 +298,8 @@ namespace Cfg { if ( (flags & MustExist) and hasFlags(MustExist) ) { if ( _type == String ) { - bfs::path filePath = ( svalue.str() ); - if ( not bfs::exists(filePath) ) { + Utilities::Path filePath ( svalue.str() ); + if ( not filePath.exists() ) { //cerr << " needrestart" << _id << endl; configuration->addLog ( Configuration::LogNeedExist, _id ); } else diff --git a/vlsisapd/src/utilities/CMakeLists.txt b/vlsisapd/src/utilities/CMakeLists.txt new file mode 100644 index 00000000..4b7537b5 --- /dev/null +++ b/vlsisapd/src/utilities/CMakeLists.txt @@ -0,0 +1 @@ +ADD_SUBDIRECTORY(src) diff --git a/vlsisapd/src/utilities/src/CMakeLists.txt b/vlsisapd/src/utilities/src/CMakeLists.txt new file mode 100644 index 00000000..cb95231e --- /dev/null +++ b/vlsisapd/src/utilities/src/CMakeLists.txt @@ -0,0 +1,17 @@ + + + include_directories ( ${VLSISAPD_SOURCE_DIR}/src/utilities/src + ) + + set ( includes vlsisapd/utilities/Path.h + ) + set ( cpps Path.cpp + ) + + add_library ( vlsisapdutils ${cpps} ) + set_target_properties ( vlsisapdutils PROPERTIES VERSION 1.0 SOVERSION 1 ) + + install ( TARGETS vlsisapdutils DESTINATION lib${LIB_SUFFIX} ) + install ( FILES ${includes} + DESTINATION include/vlsisapd/utilities ) + diff --git a/vlsisapd/src/utilities/src/Path.cpp b/vlsisapd/src/utilities/src/Path.cpp new file mode 100644 index 00000000..b43d4683 --- /dev/null +++ b/vlsisapd/src/utilities/src/Path.cpp @@ -0,0 +1,265 @@ + +// -*- C++ -*- +// +// This file is part of the VSLSI Stand-Alone Software. +// Copyright (c) UPMC 2013-2013, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | +// | M i s c e l l a n e o u s U t i l i t i e s | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./Path.cpp" | +// +-----------------------------------------------------------------+ + + +#include +#include +#include +#include +#include +#include +using namespace std; + +#include "vlsisapd/utilities/Path.h" + + +namespace Utilities { + + + int Path::_toUnistd ( unsigned int mode ) + { + int unimode = 0; + if (mode & PermRead ) unimode |= R_OK; + if (mode & PermWrite ) unimode |= W_OK; + if (mode & PermExecute) unimode |= X_OK; + return unimode; + } + + + int Path::_toMode_T ( unsigned int mode ) + { + int unimode = 0; + if (mode & s_isuid ) unimode |= S_ISUID; + if (mode & s_isgid ) unimode |= S_ISGID; + if (mode & s_isvtx ) unimode |= S_ISVTX; + if (mode & s_irusr ) unimode |= S_IRUSR; + if (mode & s_iwusr ) unimode |= S_IWUSR; + if (mode & s_ixusr ) unimode |= S_IXUSR; + if (mode & s_irgrp ) unimode |= S_IRGRP; + if (mode & s_iwgrp ) unimode |= S_IWGRP; + if (mode & s_ixgrp ) unimode |= S_IXGRP; + if (mode & s_iroth ) unimode |= S_IROTH; + if (mode & s_iwoth ) unimode |= S_IWOTH; + if (mode & s_ixoth ) unimode |= S_IXOTH; + return unimode; + } + + + void Path::_split ( const std::string& path, vector& elements, unsigned int& flags ) + { + if (path.empty()) return; + + size_t begin = 0; + if (path[0] == '/') { + flags |= Absolute; + begin = 1; + } + + size_t end = path.find_first_of( '/', begin ); + while ( end != string::npos ) { + elements.push_back(path.substr(begin,end-begin)); + begin = end+1; + end = path.find_first_of( '/', begin ); + } + elements.push_back(path.substr(begin)); + } + + + void Path::_normalize () + { + if ( (size() == 1) and (_elements[0] == ".") ) return; + + if (not _elements.empty() and (_elements[0] == "~")) { + char* home = getenv( "HOME" ); + if (home) { + vector vhome; + unsigned int vflags = 0; + _split( home, vhome, vflags ); + _flags |= vflags; + _elements.insert( _elements.begin(), vhome.begin(), vhome.end() ); + } + } + + vector::iterator ie = _elements.begin(); + while ( ie != _elements.end() ) { + if ( ((*ie) == ".") or (*ie).empty()) { + _elements.erase(ie); + } else { + ++ie; + } + } + + ie = _elements.begin(); + while ( ie != _elements.end() ) { + if ( ((*ie) == "..") and (ie != _elements.begin()) ) { + --ie; + _elements.erase(ie,ie+2); + } else { + ++ie; + } + } + + if (not _elements.empty() and (_elements.back().find_last_of('.') != std::string::npos)) + _flags |= Extension; + + // cout << "_normalize(" << path << ")" << endl; + // cout << " Absolute: " << boolalpha << (bool)(_flags & Absolute) << endl; + // for ( size_t i=0 ; i<_elements.size() ; ++i ) { + // cout << " " << i << ": <" << _elements[i] << '>' << endl; + // } + } + + + void Path::_normalize ( const std::string& path ) + { + _split( path, _elements, _flags ); + _normalize(); + } + + + std::string Path::ext () const + { + if (not (_flags&Extension)) return ""; + return _elements.back().substr(_elements.back().find_last_of('.')+1); + } + + + bool Path::mkdir ( unsigned int mode ) const + { + int status = ::mkdir( c_str(), _toMode_T(mode) ); + return (status == 0); + } + + + const std::string& Path::string () const + { + _pathcache.clear(); + + for ( size_t i=0 ; i size()) or (begin > end)) return Path(); + if (end > size()) end = size()-1; + + Path sub; + for ( size_t i=begin; i().swap( _elements ); + _elements = other._elements; + _flags = other._flags; + _pathcache = other._pathcache; + return *this; + } + + + Path Path::cwd () + { + static char curdir [4096]; + if (::getcwd( curdir, 4096 ) == NULL) { + strcpy( curdir, "/cwd/has/failed"); + } + + return Path(curdir); + } + + +} // Utilities namespace. diff --git a/vlsisapd/src/utilities/src/vlsisapd/utilities/Path.h b/vlsisapd/src/utilities/src/vlsisapd/utilities/Path.h new file mode 100644 index 00000000..de492d25 --- /dev/null +++ b/vlsisapd/src/utilities/src/vlsisapd/utilities/Path.h @@ -0,0 +1,124 @@ + +// -*- C++ -*- +// +// This file is part of the VSLSI Stand-Alone Software. +// Copyright (c) UPMC 2013-2013, All Rights Reserved +// +// +-----------------------------------------------------------------+ +// | V L S I Stand - Alone Parsers / Drivers | +// | M i s c e l l a n e o u s U t i l i t i e s | +// | | +// | Author : Jean-Paul CHAPUT | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Header : "./utilities/Path.h" | +// +-----------------------------------------------------------------+ + + +#ifndef VLSISAPD_UTILITIES_PATH_H +#define VLSISAPD_UTILITIES_PATH_H + +#include +#include + + +namespace Utilities { + + + class Path { + public: + enum Flag { NoFlag = 0x00000000 + , Absolute = 0x00000001 + , Extension = 0x00000002 + , PermRead = 0x00000004 + , PermWrite = 0x00000008 + , PermExecute = 0x00000010 + , PermAll = PermRead|PermWrite|PermExecute + }; + enum Mode_T { s_ifmt = 0x00170000 + , s_ifsock = 0x00140000 + , s_iflnk = 0x00120000 + , s_ifreg = 0x00100000 + , s_ifblk = 0x00060000 + , s_ifdir = 0x00040000 + , s_ifchr = 0x00020000 + , s_ififo = 0x00010000 + , s_isuid = 0x00004000 + , s_isgid = 0x00002000 + , s_isvtx = 0x00001000 + , s_irusr = 0x00000400 + , s_iwusr = 0x00000200 + , s_ixusr = 0x00000100 + , s_irwxu = s_irusr|s_iwusr|s_ixusr + , s_irgrp = 0x00000040 + , s_iwgrp = 0x00000020 + , s_ixgrp = 0x00000010 + , s_irwxg = s_irgrp|s_iwgrp|s_ixgrp + , s_iroth = 0x00000004 + , s_iwoth = 0x00000002 + , s_ixoth = 0x00000001 + , s_irwxo = s_iroth|s_iwoth|s_ixoth + }; + public: + static Path cwd (); + public: + inline Path ( const std::string& path="" ); + inline Path ( const char* ); + inline Path ( const Path& ); + inline bool absolute () const; + inline bool extension () const; + bool exists () const; + bool access ( unsigned int mode ) const; + inline bool empty () const; + inline size_t size () const; + inline Path head () const; + inline Path tail () const; + Path basename ( const std::string& ext="" ) const; + Path dirname () const; + Path stem () const; + Path subpath ( size_t begin, size_t end ) const; + Path join ( const Path& tail ) const; + std::string ext () const; + bool mkdir ( unsigned int mode=s_irwxu|s_irwxg|s_irwxo ) const; + const std::string& string () const; + inline const char* c_str () const; + Path& operator= ( const Path& ); + Path& operator/= ( const Path& ); + inline Path& operator/= ( const char* ); + inline Path& operator/= ( const std::string& ); + private: + static int _toUnistd ( unsigned int mode ); + static int _toMode_T ( unsigned int mode ); + static void _split ( const std::string&, std::vector&, unsigned int& ); + void _normalize (); + void _normalize ( const std::string& ); + private: + unsigned int _flags; + std::vector _elements; + mutable std::string _pathcache; + }; + + + inline Path::Path ( const char* path ) : _flags(NoFlag), _elements(), _pathcache() { _normalize(path); } + inline Path::Path ( const std::string& path ) : _flags(NoFlag), _elements(), _pathcache() { _normalize(path); } + inline Path::Path ( const Path& path ) : _flags(path._flags), _elements(path._elements), _pathcache(path._pathcache) {} + + inline bool Path::absolute () const { return _flags&Absolute; } + inline bool Path::extension () const { return _flags&Extension; } + inline bool Path::empty () const { return _elements.empty(); } + inline size_t Path::size () const { return _elements.size(); } + inline Path Path::head () const { return (size() > 1) ? subpath(0,size()-1) : *this; } + inline Path Path::tail () const { return (size() > 1) ? subpath(1,size()) : *this; } + inline const char* Path::c_str () const { return Path::string().c_str(); } + inline Path& Path::operator/= ( const std::string& tail ) { (*this) /= Path(tail); return *this; } + inline Path& Path::operator/= ( const char* tail ) { (*this) /= Path(tail); return *this; } + + inline Path operator/ ( const Path& rop, const Path& lop ) { return rop.join(lop); } + inline Path operator/ ( const std::string& rop, const Path& lop ) { return Path(rop) / lop; } + inline Path operator/ ( const Path& rop, const char* lop ) { return rop / Path(lop); } + inline Path operator/ ( const Path& rop, const std::string& lop ) { return rop / Path(lop); } + + +} // Utilities namespace. + +#endif // VLSISAPD_UTILITIES_PATH_H