Treat ${...} and $(...) envvar references uniformly.

Fixes: lp:1769282
* https://bugs.launchpad.net/kicad/+bug/1769282
This commit is contained in:
Jeff Young 2018-05-05 23:39:43 +01:00
parent a31017bc9c
commit aa7da5dfcd
8 changed files with 50 additions and 124 deletions

View File

@ -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 );

View File

@ -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;

View File

@ -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() )

View File

@ -603,29 +603,29 @@ 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<wxString>::const_iterator SET_CITER;
// 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();
for( int row = 0; row < tbl->GetNumberRows(); ++row )
{
wxString uri = tbl->GetValue( row, COL_URI );
while( re.Matches( uri ) )
{
wxString envvar = re.GetMatch( uri, 1 );
wxString envvar = re.GetMatch( uri, 2 );
// if not ${...} form then must be $(...)
if( envvar.IsEmpty() )
envvar = re.GetMatch( uri, 4 );
// ignore duplicates
unique.insert( envvar );
@ -634,21 +634,6 @@ void DIALOG_SYMBOL_LIB_TABLE::populateEnvironReadOnlyTable()
uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
}
}
for( row = 0; row < prjRowCount; ++row )
{
wxString uri = prj->GetValue( row, COL_URI );
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 );
}
}
// Make sure this special environment variable shows up even if it was
@ -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;

View File

@ -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 );

View File

@ -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

View File

@ -617,29 +617,29 @@ 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<wxString>::const_iterator SET_CITER;
// 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();
for( int row = 0; row < tbl->GetNumberRows(); ++row )
{
wxString uri = tbl->GetValue( row, COL_URI );
while( re.Matches( uri ) )
{
wxString envvar = re.GetMatch( uri, 1 );
wxString envvar = re.GetMatch( uri, 2 );
// if not ${...} form then must be $(...)
if( envvar.IsEmpty() )
envvar = re.GetMatch( uri, 4 );
// ignore duplicates
unique.insert( envvar );
@ -648,21 +648,6 @@ private:
uri.Replace( re.GetMatch( uri, 0 ), wxEmptyString );
}
}
for( row = 0; row < prjRowCount; ++row )
{
wxString uri = prj->GetValue( row, COL_URI );
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 );
}
}
// Make sure this special environment variable shows up even if it was
@ -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;

View File

@ -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" );