From aa7da5dfcd61c011ea8a58e3c964c1f7fb906996 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 5 May 2018 23:39:43 +0100 Subject: [PATCH] Treat ${...} and $(...) envvar references uniformly. Fixes: lp:1769282 * https://bugs.launchpad.net/kicad/+bug/1769282 --- 3d-viewer/3d_cache/3d_filename_resolver.cpp | 6 +-- .../3d_cache/dialogs/dlg_3d_pathconfig.cpp | 3 +- common/lib_table_base.cpp | 33 ------------ eeschema/dialogs/dialog_sym_lib_table.cpp | 53 +++++++------------ eeschema/files-io.cpp | 6 +++ include/lib_table_base.h | 12 ----- pcbnew/dialogs/dialog_fp_lib_table.cpp | 53 +++++++------------ utils/kicad2step/pcb/3d_resolver.cpp | 8 ++- 8 files changed, 50 insertions(+), 124 deletions(-) diff --git a/3d-viewer/3d_cache/3d_filename_resolver.cpp b/3d-viewer/3d_cache/3d_filename_resolver.cpp index cc07cffde5..afc9890e98 100644 --- a/3d-viewer/3d_cache/3d_filename_resolver.cpp +++ b/3d-viewer/3d_cache/3d_filename_resolver.cpp @@ -374,8 +374,7 @@ wxString S3D_FILENAME_RESOLVER::ResolvePath( const wxString& aFileName ) } // ${ENV_VAR} paths have already been checked; skip them - while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) - || sPL->m_alias.StartsWith( "$(" ) ) ) + while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) || sPL->m_alias.StartsWith( "$(" ) ) ) ++sPL; // at this point the filename must contain an alias or else it is invalid @@ -641,8 +640,7 @@ bool S3D_FILENAME_RESOLVER::writePathList( void ) std::list< S3D_ALIAS >::const_iterator sPL = m_Paths.begin(); std::list< S3D_ALIAS >::const_iterator ePL = m_Paths.end(); - while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) - || sPL->m_alias.StartsWith( "$(" ) ) ) + while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) || sPL->m_alias.StartsWith( "$(" ) ) ) ++sPL; wxFileName cfgpath( m_ConfigDir, S3D_RESOLVER_CONFIG ); diff --git a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp index 19c9ed9c3a..2f73c8563d 100644 --- a/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp +++ b/3d-viewer/3d_cache/dialogs/dlg_3d_pathconfig.cpp @@ -75,8 +75,7 @@ void DLG_3D_PATH_CONFIG::initDialog() size_t listsize = rpaths->size(); size_t listidx = 0; - while( rI != rE && ( (*rI).m_alias.StartsWith( "${" ) - || (*rI).m_alias.StartsWith( "$(" ) ) ) + while( rI != rE && ( (*rI).m_alias.StartsWith( "${" ) || (*rI).m_alias.StartsWith( "$(" ) ) ) { ++listidx; ++rI; diff --git a/common/lib_table_base.cpp b/common/lib_table_base.cpp index f8ff1fef75..5147d68d87 100644 --- a/common/lib_table_base.cpp +++ b/common/lib_table_base.cpp @@ -446,39 +446,6 @@ void LIB_TABLE::Save( const wxString& aFileName ) const } -size_t LIB_TABLE::GetEnvVars( wxArrayString& aEnvVars ) const -{ - const LIB_TABLE* cur = this; - - do - { - for( unsigned i = 0; i < cur->rows.size(); i++ ) - { - wxString uri = cur->rows[i].GetFullURI( false ); - - int start = uri.Find( "${" ); - - if( start == wxNOT_FOUND ) - continue; - - int end = uri.Find( '}' ); - - if( end == wxNOT_FOUND || end < start+2 ) - continue; - - wxString envVar = uri.Mid( start+2, end - (start+2) ); - - if( aEnvVars.Index( envVar, false ) == wxNOT_FOUND ) - aEnvVars.Add( envVar ); - } - - // not found, search fall back table(s), if any - } while( ( cur = cur->fallBack ) != 0 ); - - return aEnvVars.GetCount(); -} - - PROPERTIES* LIB_TABLE::ParseOptions( const std::string& aOptionsList ) { if( aOptionsList.size() ) diff --git a/eeschema/dialogs/dialog_sym_lib_table.cpp b/eeschema/dialogs/dialog_sym_lib_table.cpp index 2e0e6f6dd6..a61596e1fc 100644 --- a/eeschema/dialogs/dialog_sym_lib_table.cpp +++ b/eeschema/dialogs/dialog_sym_lib_table.cpp @@ -603,51 +603,36 @@ bool DIALOG_SYMBOL_LIB_TABLE::TransferDataFromWindow() void DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable() { - wxRegEx re( ".*?\\$\\{(.+?)\\}.*?", wxRE_ADVANCED ); + wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. - std::set< wxString > unique; - typedef std::set::const_iterator SET_CITER; + std::set< wxString > unique; // clear the table m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() ); - SYMBOL_LIB_TABLE_GRID* gbl = global_model(); - SYMBOL_LIB_TABLE_GRID* prj = project_model(); - - int gblRowCount = gbl->GetNumberRows(); - int prjRowCount = prj->GetNumberRows(); - int row; - - for( row = 0; row < gblRowCount; ++row ) + for( int i = 0; i < 2; ++i ) { - wxString uri = gbl->GetValue( row, COL_URI ); + SYMBOL_LIB_TABLE_GRID* tbl = i == 0 ? global_model() : project_model(); - while( re.Matches( uri ) ) + for( int row = 0; row < tbl->GetNumberRows(); ++row ) { - wxString envvar = re.GetMatch( uri, 1 ); + wxString uri = tbl->GetValue( row, COL_URI ); - // ignore duplicates - unique.insert( envvar ); + while( re.Matches( uri ) ) + { + wxString envvar = re.GetMatch( uri, 2 ); - // delete the last match and search again - uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); - } - } + // if not ${...} form then must be $(...) + if( envvar.IsEmpty() ) + envvar = re.GetMatch( uri, 4 ); - for( row = 0; row < prjRowCount; ++row ) - { - wxString uri = prj->GetValue( row, COL_URI ); + // ignore duplicates + unique.insert( envvar ); - while( re.Matches( uri ) ) - { - wxString envvar = re.GetMatch( uri, 1 ); - - // ignore duplicates - unique.insert( envvar ); - - // delete the last match and search again - uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); + // delete the last match and search again + uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); + } } } @@ -659,9 +644,9 @@ void DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable() m_path_subs_grid->AppendRows( unique.size() ); - row = 0; + int row = 0; - for( SET_CITER it = unique.begin(); it != unique.end(); ++it, ++row ) + for( auto it = unique.begin(); it != unique.end(); ++it, ++row ) { wxString evName = *it; wxString evValue; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index a1fe88ed43..bc64d6a694 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -545,6 +545,12 @@ bool SCH_EDIT_FRAME::AppendSchematic() newLib.SetFullName( uri.AfterLast( '}' ) ); uri = newLib.GetFullPath(); } + else if( uri.Contains( "$(KIPRJMOD)" ) ) + { + newLib.SetPath( fn.GetPath() ); + newLib.SetFullName( uri.AfterLast( ')' ) ); + uri = newLib.GetFullPath(); + } else { uri = table.GetFullURI( libName ); diff --git a/include/lib_table_base.h b/include/lib_table_base.h index 576f6295f4..7ba8700dbc 100644 --- a/include/lib_table_base.h +++ b/include/lib_table_base.h @@ -409,18 +409,6 @@ public: */ void Save( const wxString& aFileName ) const; - /** - * Search the paths all of the #LIB_TABLE_ROWS of the #LIB_TABLE and add all of the - * environment variable substitutions to \a aEnvVars. - * - * This will only add unique environment variables to the list. Duplicates are ignored. - * - * @param aEnvVars is the array to load the environment variables. - * - * @return the number of unique environment variables found in the table. - */ - size_t GetEnvVars( wxArrayString& aEnvVars ) const; - /** * Parses \a aOptionsList and places the result into a #PROPERTIES object which is * returned. If the options field is empty, then the returned PROPERTIES will be diff --git a/pcbnew/dialogs/dialog_fp_lib_table.cpp b/pcbnew/dialogs/dialog_fp_lib_table.cpp index 693aca4e84..c51893bc35 100644 --- a/pcbnew/dialogs/dialog_fp_lib_table.cpp +++ b/pcbnew/dialogs/dialog_fp_lib_table.cpp @@ -617,51 +617,36 @@ private: /// by examining all the full_uri columns. void populateEnvironReadOnlyTable() { - wxRegEx re( ".*?\\$\\{(.+?)\\}.*?", wxRE_ADVANCED ); + wxRegEx re( ".*?(\\$\\{(.+?)\\})|(\\$\\((.+?)\\)).*?", wxRE_ADVANCED ); wxASSERT( re.IsValid() ); // wxRE_ADVANCED is required. - std::set< wxString > unique; - typedef std::set::const_iterator SET_CITER; + std::set< wxString > unique; // clear the table m_path_subs_grid->DeleteRows( 0, m_path_subs_grid->GetNumberRows() ); - FP_LIB_TABLE_GRID* gbl = global_model(); - FP_LIB_TABLE_GRID* prj = project_model(); - - int gblRowCount = gbl->GetNumberRows(); - int prjRowCount = prj->GetNumberRows(); - int row; - - for( row = 0; row < gblRowCount; ++row ) + for( int i = 0; i < 2; ++i ) { - wxString uri = gbl->GetValue( row, COL_URI ); + FP_LIB_TABLE_GRID* tbl = i == 0 ? global_model() : project_model(); - while( re.Matches( uri ) ) + for( int row = 0; row < tbl->GetNumberRows(); ++row ) { - wxString envvar = re.GetMatch( uri, 1 ); + wxString uri = tbl->GetValue( row, COL_URI ); - // ignore duplicates - unique.insert( envvar ); + while( re.Matches( uri ) ) + { + wxString envvar = re.GetMatch( uri, 2 ); - // delete the last match and search again - uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); - } - } + // if not ${...} form then must be $(...) + if( envvar.IsEmpty() ) + envvar = re.GetMatch( uri, 4 ); - for( row = 0; row < prjRowCount; ++row ) - { - wxString uri = prj->GetValue( row, COL_URI ); + // ignore duplicates + unique.insert( envvar ); - while( re.Matches( uri ) ) - { - wxString envvar = re.GetMatch( uri, 1 ); - - // ignore duplicates - unique.insert( envvar ); - - // delete the last match and search again - uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); + // delete the last match and search again + uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString ); + } } } @@ -675,9 +660,9 @@ private: m_path_subs_grid->AppendRows( unique.size() ); - row = 0; + int row = 0; - for( SET_CITER it = unique.begin(); it != unique.end(); ++it, ++row ) + for( auto it = unique.begin(); it != unique.end(); ++it, ++row ) { wxString evName = *it; wxString evValue; diff --git a/utils/kicad2step/pcb/3d_resolver.cpp b/utils/kicad2step/pcb/3d_resolver.cpp index 7c104a394f..86c0d7adf1 100644 --- a/utils/kicad2step/pcb/3d_resolver.cpp +++ b/utils/kicad2step/pcb/3d_resolver.cpp @@ -458,8 +458,7 @@ wxString S3D_RESOLVER::ResolvePath( const wxString& aFileName ) } // ${ENV_VAR} paths have already been checked; skip them - while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) - || sPL->m_alias.StartsWith( "$(" ) ) ) + while( sPL != ePL && ( sPL->m_alias.StartsWith( "${" ) || sPL->m_alias.StartsWith( "$(" ) ) ) ++sPL; // at this point the filename must contain an alias or else it is invalid @@ -542,9 +541,8 @@ bool S3D_RESOLVER::addPath( const S3D_ALIAS& aPath ) if( !path.DirExists() ) { - // suppress the message if the missing pathvar is the - // legacy KISYS3DMOD variable - if( aPath.m_pathvar.compare( "${KISYS3DMOD}" ) ) + // suppress the message if the missing pathvar is the legacy KISYS3DMOD variable + if( aPath.m_pathvar != "${KISYS3DMOD}" && aPath.m_pathvar != "$(KISYS3DMOD)" ) { wxString msg = _( "The given path does not exist" ); msg.append( "\n" );