From 68f6c4906660cb6aabe257e6c9e93268c4e0b812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 27 Dec 2017 14:53:19 +0100 Subject: [PATCH] More migration to T_FSPath --- c-opcomp.hh | 5 +++-- c-opmgr.cc | 12 ++++++------ c-opparser.cc | 1 + c-project.cc | 22 +++++++++++++++++----- c-project.hh | 7 +++++-- c-sync.cc | 4 ++-- m-builder.cc | 48 ++++++++++++++++++++++++++++-------------------- ui-shaders.cc | 13 ++++++------- 8 files changed, 68 insertions(+), 44 deletions(-) diff --git a/c-opcomp.hh b/c-opcomp.hh index 85ddb96..8ba3ed4 100644 --- a/c-opcomp.hh +++ b/c-opcomp.hh @@ -36,7 +36,8 @@ class T_OpsParser : public ebcl::A_PrivateImplementation } } - bool parse( ebcl::T_SRDList const& input ) noexcept; + bool parse( T_FSPath const& filePath , + ebcl::T_SRDList const& input ) noexcept; T_Array< ebcl::T_SRDError > const& errors( ) const noexcept { return errors_; } @@ -92,7 +93,7 @@ class T_ScriptManager : public A_ProjectPathListener { return errors_; } private: - T_String path_; + T_FSPath path_; T_WatchedFiles watcher_; T_OpsParser parser_; diff --git a/c-opmgr.cc b/c-opmgr.cc index bf8fb1f..c0034b5 100644 --- a/c-opmgr.cc +++ b/c-opmgr.cc @@ -58,7 +58,7 @@ void T_ScriptManager::projectPathChanged( ) noexcept { path_ = Common::Project( ).pathOf( "demo.srd" ); watcher_.clear( ); - watcher_.watch( path_ ); + watcher_.watch( path_.toString( ) ); loadScript( ); } @@ -70,7 +70,7 @@ void T_ScriptManager::loadScript( ) noexcept errors_.clear( ); using namespace ebcl; - T_File input( path_ , E_FileMode::READ_ONLY ); + T_File input( path_.toString( ) , E_FileMode::READ_ONLY ); try { input.open( ); } catch ( X_StreamError const& e ) { @@ -80,7 +80,7 @@ void T_ScriptManager::loadScript( ) noexcept sb << " (error code " << e.systemError( ) << ")"; } errors_.addNew( std::move( sb ) , - T_SRDLocation{ path_ , 1 , 1 } ); + T_SRDLocation{ path_.toString( ) , 1 , 1 } ); DumpSRDErrors( "Script not found" , errors_ ); return; } @@ -91,7 +91,7 @@ void T_ScriptManager::loadScript( ) noexcept try { T_SRDTextReader srdReader{ srdOut }; T_FileInputStream fis{ input }; - srdReader.read( path_ , fis ); + srdReader.read( path_.toString( ) , fis ); } catch ( X_StreamError const& e ) { T_StringBuilder sb; sb << "could not load: " << e.what( ); @@ -99,7 +99,7 @@ void T_ScriptManager::loadScript( ) noexcept sb << " (error code " << e.systemError( ) << ")"; } errors_.addNew( std::move( sb ) , - T_SRDLocation{ path_ , 1 , 1 } ); + T_SRDLocation{ path_.toString( ) , 1 , 1 } ); DumpSRDErrors( "Script not loaded" , errors_ ); return; @@ -115,7 +115,7 @@ void T_ScriptManager::loadScript( ) noexcept } // Parse the fuck - if ( !parser_.parse( srdOut.list( ) ) ) { + if ( !parser_.parse( path_ , srdOut.list( ) ) ) { errors_.addAll( parser_.errors( ) ); DumpSRDErrors( "Parse errors" , errors_ ); return; diff --git a/c-opparser.cc b/c-opparser.cc index 6847ced..8ae8ee3 100644 --- a/c-opparser.cc +++ b/c-opparser.cc @@ -2219,6 +2219,7 @@ T_OpsParser::T_OpsParser( ) noexcept {} bool T_OpsParser::parse( + T_FSPath const& filePath , T_SRDList const& input ) noexcept { errors_.clear( ); diff --git a/c-project.cc b/c-project.cc index fdc40e1..208ebd1 100644 --- a/c-project.cc +++ b/c-project.cc @@ -31,14 +31,26 @@ void T_Project::setBasePath( /*----------------------------------------------------------------------------*/ -T_String T_Project::pathOf( - T_String const& file ) const noexcept +T_FSPath T_Project::pathOf( + T_FSPath const& file ) const noexcept { - return ( basePath_ + T_FSPath{ file } ).canonical( ).toString( ); + return ( basePath_ + file ).canonical( ); } -T_String T_Project::pathOf( +T_FSPath T_Project::pathOf( char const* file ) const noexcept { - return ( basePath_ + T_FSPath{ file } ).canonical( ).toString( ); + return pathOf( T_String{ file } ); +} + +T_String T_Project::strPathOf( + T_FSPath const& file ) const noexcept +{ + return pathOf( file ).toString( ); +} + +T_String T_Project::strPathOf( + char const* file ) const noexcept +{ + return strPathOf( T_String{ file } ); } diff --git a/c-project.hh b/c-project.hh index 4dc5f19..b0109e9 100644 --- a/c-project.hh +++ b/c-project.hh @@ -26,8 +26,11 @@ struct T_Project T_FSPath const& basePath( ) const noexcept { return basePath_; } - T_String pathOf( T_String const& file ) const noexcept; - T_String pathOf( char const* file ) const noexcept; + T_FSPath pathOf( T_FSPath const& file ) const noexcept; + T_FSPath pathOf( char const* file ) const noexcept; + + T_String strPathOf( T_FSPath const& file ) const noexcept; + T_String strPathOf( char const* file ) const noexcept; void addListener( A_ProjectPathListener* listener ) noexcept { listeners_.add( listener ); } diff --git a/c-sync.cc b/c-sync.cc index b019d2a..cca0ad8 100644 --- a/c-sync.cc +++ b/c-sync.cc @@ -684,7 +684,7 @@ T_SyncManager::T_SyncManager( ) noexcept { auto& p{ Common::Project( ) }; p.addListener( this ); - curvesFile_ = p.pathOf( "curves.srd" ); + curvesFile_ = p.strPathOf( "curves.srd" ); watcher_.watch( curvesFile_ ); loadCurves( false ); } @@ -977,7 +977,7 @@ void T_SyncManager::visitOverrides( void T_SyncManager::projectPathChanged( ) noexcept { - curvesFile_ = Common::Project( ).pathOf( "curves.srd" ); + curvesFile_ = Common::Project( ).strPathOf( "curves.srd" ); watcher_.clear( ); watcher_.watch( curvesFile_ ); loadCurves( false ); diff --git a/m-builder.cc b/m-builder.cc index 0273929..1bfa0a2 100644 --- a/m-builder.cc +++ b/m-builder.cc @@ -31,11 +31,12 @@ const struct option CmdLineOpts_[] = { void PrintStreamError( char const* const prefix , - T_String const& name , + T_FSPath const& name , X_StreamError const& error ) noexcept { + const T_FSPath rp{ name.makeRelative( Filesystem::Cwd( ) ) }; T_StringBuilder sb; - sb << prefix << " '" << name << "': " << error.what( ); + sb << prefix << " '" << rp << "': " << error.what( ); if ( error.code( ) == E_StreamError::SYSTEM_ERROR ) { sb << " (error code " << error.systemError( ) << ")"; } @@ -89,19 +90,15 @@ void WriteSRDErrors( fprintf( stderr , "%s" , sb.data( ) ); } -T_String FilePath( - T_String const& path , +T_FSPath FilePath( + T_FSPath const& path , char const* const name ) noexcept { - T_StringBuilder sb; - if ( path ) { - sb << path; - if ( !path.endsWith( "/" ) ) { - sb << '/'; - } + const T_FSPath fp{ name }; + if ( fp.isAbsolute( ) ) { + return fp.canonical( ); } - sb << name; - return T_String{ std::move( sb ) }; + return ( path + fp ).canonical( ); } @@ -141,6 +138,17 @@ int main( int argc , char** argv ) } } + const T_FSPath srcPath{ ([&](){ + const T_FSPath raw{ oSrcPath }; + if ( !raw.isAbsolute( ) ) { + return ( Filesystem::Cwd( ) + raw ).canonical( ); + } + return raw.canonical( ); + })() }; + if ( !srcPath.isValid( ) ) { + fprintf( stderr , "Invalid source path\n" ); + return EXIT_FAILURE; + } // Logger setup const uint32_t logLevel{ oLogLevel ? *oLogLevel : 0 }; @@ -155,11 +163,11 @@ int main( int argc , char** argv ) // Build configurations M_LOGSTR( "Loading build configurations" , 1 ); - const T_String bcfgFile{ FilePath( oSrcPath , "build.srd" ) }; + const auto bcfgFile{ FilePath( srcPath , "build.srd" ) }; const T_BuildConfiguration cfg{ [&]() { try { T_BuildConfigurationLoader bcfgLoader; - T_BuildConfigurations cfs{ bcfgLoader.load( bcfgFile ) }; + T_BuildConfigurations cfs{ bcfgLoader.load( bcfgFile.toString( ) ) }; if ( oBuildCfg && !cfs.contains( oBuildCfg ) ) { fprintf( stderr , "===== BUILD CONFIGURATIONS\n" ); fprintf( stderr , "Build configuration not found\n" ); @@ -186,10 +194,10 @@ int main( int argc , char** argv ) // Load curves M_LOGSTR( "Loading curves data" , 1 ); - const T_String curvesFile{ FilePath( oSrcPath , "curves.srd" ) }; + const auto curvesFile{ FilePath( srcPath , "curves.srd" ) }; T_SyncCurvesIO::T_Data p; try { - p = T_SyncCurvesIO{}.load( curvesFile ); + p = T_SyncCurvesIO{}.load( curvesFile.toString( ) ); } catch ( ebcl::X_StreamError const& e ) { fprintf( stderr , "===== CURVES DATA\n" ); PrintStreamError( "Could not open" , curvesFile , e ); @@ -202,10 +210,10 @@ int main( int argc , char** argv ) // Open and load script M_LOGSTR( "Loading script" , 1 ); - const T_String inputName{ FilePath( oSrcPath , "demo.srd" ) }; + const auto inputName{ FilePath( srcPath , "demo.srd" ) }; T_SRDMemoryTarget srdOut; { - T_File input( inputName , E_FileMode::READ_ONLY ); + T_File input( inputName.toString( ) , E_FileMode::READ_ONLY ); try { input.open( ); } catch ( X_StreamError const& e ) { @@ -216,7 +224,7 @@ int main( int argc , char** argv ) try { T_SRDTextReader srdReader{ srdOut }; T_FileInputStream fis{ input }; - srdReader.read( inputName , fis ); + srdReader.read( inputName.toString( ) , fis ); } catch ( X_StreamError const& e ) { fprintf( stderr , "===== SCRIPT\n" ); PrintStreamError( "Could not open" , inputName , e ); @@ -231,7 +239,7 @@ int main( int argc , char** argv ) M_LOGSTR( "Parsing script" , 1 ); T_OpsParser parser; parser.setLogger( logger ); - if ( !parser.parse( srdOut.list( ) ) ) { + if ( !parser.parse( inputName , srdOut.list( ) ) ) { WriteSRDErrors( "SCRIPT" , parser.errors( ) ); exit( EXIT_FAILURE ); } diff --git a/ui-shaders.cc b/ui-shaders.cc index c400d02..1a5bbfa 100644 --- a/ui-shaders.cc +++ b/ui-shaders.cc @@ -536,10 +536,10 @@ void T_ShaderManager::update( ) // Check for missing files for ( auto it = missing_.keys( ).cbegin( ) ; it.valid( ) ; ++it ) { - const bool exists( ([&sb] ( T_String const& name ) -> bool { + const bool exists( ([] ( T_String const& name ) -> bool { + T_FSPath p{ T_FSPath{ "shaders" } + T_FSPath{ name } }; struct stat buffer; - sb << "shaders/" << name << '\0'; - return ( stat( Common::Project( ).pathOf( std::move( sb ) ).data( ) , &buffer ) == 0 ); + return ( stat( Common::Project( ).strPathOf( p ).data( ) , &buffer ) == 0 ); })( *it ) ); if ( !exists ) { continue; @@ -726,7 +726,7 @@ T_ShaderInput const* T_ShaderManager::getInput( sb << "shaders/" << name; return std::move( sb ); }() }; - if ( !ni.load( Common::Project( ).pathOf( path ) ) ) { + if ( !ni.load( Common::Project( ).strPathOf( path ) ) ) { return nullptr; } inputs_.add( name , NewOwned< T_ShaderInput >( std::move( ni ) ) ); @@ -864,9 +864,8 @@ void T_ShaderManager::initProgram( for ( auto i = 0u ; i < nf ; i ++ ) { T_String const& fn( code.files.keys( )[ i ] ); if ( code.files.values( )[ i ] ) { - T_StringBuilder sb; - sb << "shaders/" << fn; - w.watch( Common::Project( ).pathOf( std::move( sb ) ) ); + T_FSPath p{ T_FSPath{ "shaders" } + T_FSPath{ fn } }; + w.watch( Common::Project( ).strPathOf( p ) ); } else { auto& mset( missing_.getOrCreate( fn ) ); if ( !mset.contains( name ) ) {