#include #include #include #if defined(__MINGW32__) #define PATH_SEPS wxT(";\r\n") #else #define PATH_SEPS wxT(":;\r\n") // unix == linux | mac #endif int SEARCH_STACK::Split( wxArrayString* aResult, const wxString aPathString ) { wxStringTokenizer tokenizer( aPathString, PATH_SEPS, wxTOKEN_STRTOK ); while( tokenizer.HasMoreTokens() ) { wxString path = tokenizer.GetNextToken(); aResult->Add( path ); } return aResult->GetCount(); } // Convert aRelativePath to an absolute path based on aBaseDir static wxString base_dir( const wxString& aRelativePath, const wxString& aBaseDir ) { wxFileName fn = aRelativePath; if( !fn.IsAbsolute() && !!aBaseDir ) { wxASSERT_MSG( wxFileName( aBaseDir ).IsAbsolute(), wxT( "Must pass absolute path in aBaseDir" ) ); fn.MakeRelativeTo( aBaseDir ); } return fn.GetFullPath(); } wxString SEARCH_STACK::FilenameWithRelativePathInSearchList( const wxString& aFullFilename, const wxString& aBaseDir ) { wxFileName fn = aFullFilename; wxString filename = aFullFilename; unsigned pathlen = fn.GetPath().Len(); // path len, used to find the better (shortest) // subpath within defaults paths for( unsigned kk = 0; kk < GetCount(); kk++ ) { fn = aFullFilename; // Search for the shortest subpath within 'this': if( fn.MakeRelativeTo( base_dir( (*this)[kk], aBaseDir ) ) ) { if( fn.GetPathWithSep().StartsWith( wxT("..") ) ) // Path outside kicad libs paths continue; if( pathlen > fn.GetPath().Len() ) // A better (shortest) subpath is found { filename = fn.GetPathWithSep() + fn.GetFullName(); pathlen = fn.GetPath().Len(); } } } return filename; } void SEARCH_STACK::RemovePaths( const wxString& aPaths ) { bool isCS = wxFileName::IsCaseSensitive(); wxArrayString paths; Split( &paths, aPaths ); for( unsigned i=0; i= GetCount() ) { for( unsigned i=0; i