/** **************************************************************************************** * Does the job for * \ref cs::aworx::lox::Lox::SetSourcePathTrimRule "Lox.SetSourcePathTrimRule" and * \ref cs::aworx::lox::Lox::ClearSourcePathTrimRules "Lox.ClearSourcePathTrimRules". * * @param path The path to search for. If not starting with <c> '*'</c>, a prefix * is searched. * @param includeString Determines if \p path should be included in the trimmed path or not. * @param trimOffset Adjusts the portion of \p path that is trimmed. 999999 to clear! * @param sensitivity Determines if the comparison of \p path with a source files' path * is performed case sensitive or not. * @param global If Inclusion.Exclude, only this instance is affected. Otherwise * the setting applies to all instances of class \b Lox. ******************************************************************************************/ public void SetSourcePathTrimRule(String path, Inclusion includeString, int trimOffset, Case sensitivity, Inclusion global) { // unset current origFile to have lazy variables reset with the next invocation for (int i = 0; i < cacheSize; i++) { cache[i].origFile = null; } // clear command if (trimOffset == 999999) { LocalSPTRs.Clear(); if (global == Inclusion.Include) { GlobalSPTRs.Clear(); } AutoDetectTrimableSourcePath = (includeString == Inclusion.Include); // reset config read flag. This is done for unit testing. Not really // useful/needed in real life. GlobalSPTRsReadFromConfig = false; return; } // choosel local or global list List <SourcePathTrimRule> trimInfoList = global == Inclusion.Include ? GlobalSPTRs : LocalSPTRs; // add new entry SourcePathTrimRule rule = new SourcePathTrimRule(); // if path starts with '*', it is not a prefix. We store without * rule.Path = new AString((rule.IsPrefix = !path.StartsWith("*")) ? path : path.Substring(1)); if (rule.Path.CharAtEnd() == '*') { rule.Path.DeleteEnd(1); } if (rule.Path.IsEmpty()) { return; } if (Path.DirectorySeparatorChar == '/') { rule.Path.SearchAndReplaceAll("\\", "/"); } else { rule.Path.SearchAndReplaceAll("/", "\\"); } rule.IncludeString = includeString; rule.TrimOffset = trimOffset; rule.Sensitivity = sensitivity; trimInfoList.Add(rule); }
/** **************************************************************************************** * Does the job for * \ref cs::aworx::lox::Lox::SetSourcePathTrimRule "Lox.SetSourcePathTrimRule" and * \ref cs::aworx::lox::Lox::ClearSourcePathTrimRules "Lox.ClearSourcePathTrimRules". * * @param path The path to search for. If not starting with <c> '*'</c>, * a prefix is searched. * @param includeString Determines if \p path should be included in the trimmed path * or not. * @param trimOffset Adjusts the portion of \p path that is trimmed. 999999 to clear! * @param sensitivity Determines if the comparison of \p path with a source files' path * is performed case sensitive or not. * @param trimReplacement Replacement string for trimmed portion of the path. * @param reach Denotes whether the rule is applied locally (to this \b %Lox only) * or applies to all instances of class \b %Lox. * @param priority The priority of the setting. ******************************************************************************************/ public void SetSourcePathTrimRule( String path, Inclusion includeString, int trimOffset, Case sensitivity, String trimReplacement, Reach reach, int priority ) { // unset current origFile to have lazy variables reset with the next invocation for ( int i= 0; i< cacheSize; i++ ) cache[i].origFile= null; // clear command if ( trimOffset == 999999 ) { LocalSPTRs.Clear(); if ( reach == Reach.Global ) GlobalSPTRs.Clear(); AutoDetectTrimableSourcePath= (includeString == Inclusion.Include); // reset config read flag. This is done for unit testing. Not really // useful/needed in real life. GlobalSPTRsReadFromConfig= false; return; } // choosel local or global list List<SourcePathTrimRule> trimInfoList = reach == Reach.Global ? GlobalSPTRs : LocalSPTRs; // add new entry SourcePathTrimRule rule= new SourcePathTrimRule(); // if path starts with '*', it is not a prefix. We store without * rule.Path= new AString( (rule.IsPrefix= !path.StartsWith("*")) ? path : path.Substring( 1 ) ); if ( rule.Path.CharAtEnd() == '*' ) rule.Path.DeleteEnd( 1 ); if ( rule.Path.IsEmpty() ) return; if( Path.DirectorySeparatorChar == '/' ) rule.Path.SearchAndReplaceAll( "\\", "/" ); else rule.Path.SearchAndReplaceAll( "/" , "\\" ); rule.IncludeString= includeString; rule.TrimOffset= trimOffset; rule.Sensitivity= sensitivity; rule.TrimReplacement= trimReplacement; // add rule ordered by priority rule.Priority= priority; int pos= 0; while( pos < trimInfoList.Count && priority < trimInfoList[pos].Priority ) ++pos; trimInfoList.Insert( pos, rule ); }
// ############################################################################################# // public interface // ############################################################################################# /** **************************************************************************************** * Constructs a scope info. * @param name The name of the Lox we belong to. * Will be converted to upper case. * @param threadDictionary A dictionary to map thread IDs to user friendly names which is * managed outside of this class. ******************************************************************************************/ public ScopeInfo( String name, Dictionary<int, String> threadDictionary ) { loxName= name.ToUpper(); ALIB.ASSERT_ERROR( !loxName.Equals( "GLOBAL" ), "Name \"GLOBAL\" not allowed for Lox instances" ); this.threadDictionary= threadDictionary; cache= new SourceFile[cacheSize= DefaultCacheSize]; for ( int i= 0; i< cacheSize; i++ ) cache[i]= new SourceFile(); actual= cache[0]; // read trim rules from config // do 2 times, 0== local list, 1== global list List<SourcePathTrimRule> trimInfoList; for( int trimInfoNo= 0; trimInfoNo < 2 ; trimInfoNo++ ) { // check if done... or set list Variable variable= new Variable(); if ( trimInfoNo == 0 ) { trimInfoList= LocalSPTRs; variable.Define(ALox.SPTR_LOX, loxName).Load(); } else { if ( GlobalSPTRsReadFromConfig ) continue; GlobalSPTRsReadFromConfig= true; trimInfoList= GlobalSPTRs; variable.Define(ALox.SPTR_GLOBAL).Load(); } if( variable.Priority != 0 ) { Tokenizer ruleTok = new Tokenizer(); for( int ruleNo= 0; ruleNo< variable.Size(); ruleNo++ ) { try { ruleTok.Set( variable.GetString( ruleNo ), ',' ); SourcePathTrimRule rule= new SourcePathTrimRule(); rule.Priority= variable.Priority; rule.Path= new AString(); ruleTok.Next(); if( ! ( rule.IsPrefix= !ruleTok.Actual.StartsWith( "*" ) ) ) ruleTok.Actual.Consume(1); rule.Path._( ruleTok.Actual ); if ( rule.Path.CharAtEnd() == '*' ) rule.Path.DeleteEnd( 1 ); if ( rule.Path.IsEmpty() ) continue; if( Path.DirectorySeparatorChar == '/' ) rule.Path.SearchAndReplaceAll( "\\", "/" ); else rule.Path.SearchAndReplaceAll( "/" , "\\" ); rule.IncludeString = ALIB.ReadInclusion( ruleTok.Next() ); if ( ruleTok.HasNext () ) ruleTok.Next().ConsumeInteger( out rule.TrimOffset ); rule.Sensitivity = ALIB.ReadCase( ruleTok.Next() ); if ( ruleTok.HasNext () ) rule.TrimReplacement= ruleTok.Next().ToString(); trimInfoList.Add( rule ); } catch( Exception ) { ALIB.ERROR( "Error reading source path trim rule from configuration. Invalid String: " + variable.GetString( ruleNo ).ToString() ); } } } } }
// ############################################################################################# // public interface // ############################################################################################# /** **************************************************************************************** * Constructs a scope info. * @param name The name of the Lox we belong to * @param threadDictionary A dictionary to map thread IDs to user friendly names which is * managed outside of this class. ******************************************************************************************/ public ScopeInfo(String name, Dictionary <int, String> threadDictionary) { loxName = name.ToUpper(); ALIB.ASSERT_ERROR(!loxName.Equals("GLOBAL"), "Name \"GLOBAL\" not allowed for Lox instances"); this.threadDictionary = threadDictionary; cache = new SourceFile[cacheSize = DefaultCacheSize]; for (int i = 0; i < cacheSize; i++) { cache[i] = new SourceFile(); } actual = cache[0]; // read trim rules from config // do 2 times, 0== local list, 1== global list List <SourcePathTrimRule> trimInfoList; AString rules = new AString(); AString variableName = new AString(); for (int trimInfoNo = 0; trimInfoNo < 2; trimInfoNo++) { // check if done... or set list variableName._(); if (trimInfoNo == 0) { trimInfoList = LocalSPTRs; variableName._(loxName); } else { if (GlobalSPTRsReadFromConfig) { continue; } GlobalSPTRsReadFromConfig = true; trimInfoList = GlobalSPTRs; variableName._("GLOBAL"); } variableName._("_SOURCE_PATH_TRIM_RULES"); // get auto sizes from last session rules._(); if (ALIB.Config.Get(ALox.ConfigCategoryName, variableName, rules) != 0) { Tokenizer rulesTok = new Tokenizer(); Tokenizer ruleTok = new Tokenizer(); rulesTok.Set(rules, ';'); Substring ruleStr; while ((ruleStr = rulesTok.Next()).IsNotEmpty()) { try { ruleTok.Set(ruleStr, ','); SourcePathTrimRule rule = new SourcePathTrimRule(); rule.Path = new AString(); ruleTok.Next(); if (!(rule.IsPrefix = !ruleTok.Actual.StartsWith("*"))) { ruleTok.Actual.Consume(1); } rule.Path._(ruleTok.Actual); if (rule.Path.CharAtEnd() == '*') { rule.Path.DeleteEnd(1); } if (rule.Path.IsEmpty()) { continue; } if (Path.DirectorySeparatorChar == '/') { rule.Path.SearchAndReplaceAll("\\", "/"); } else { rule.Path.SearchAndReplaceAll("/", "\\"); } rule.IncludeString = ALIB.ReadInclusion(ruleTok.Next()); if (ruleTok.HasNext()) { ruleTok.Next().ConsumeInteger(out rule.TrimOffset); } rule.Sensitivity = ALIB.ReadCase(ruleTok.Next()); trimInfoList.Add(rule); } catch (Exception) { ALIB.ERROR("Error reading source path trim rule from configuration. Invalid String: " + ruleStr.ToString()); } } } } }