Example #1
0
        public void MakeExlude(ref List <ExcludeStruct> exclList, string pat, UInt32 mFlags)
        {
            int           exLen  = 0;
            int           patLen = pat.Length;
            ExcludeStruct ret    = new ExcludeStruct();

            if (options.excludePathPrefix != null)
            {
                mFlags |= Options.MATCHFLG_ABS_PATH;
            }
            if (options.excludePathPrefix != null && pat[0] == '/')
            {
                exLen = options.excludePathPrefix.Length;
            }
            else
            {
                exLen = 0;
            }
            ret.pattern = String.Empty;
            if (exLen != 0)
            {
                ret.pattern += options.excludePathPrefix;
            }
            ret.pattern += pat.Replace('\\', '/');
            patLen      += exLen;

            if (ret.pattern.IndexOfAny(new char[] { '*', '[', '?' }) != -1)
            {
                mFlags |= Options.MATCHFLG_WILD;
                if (ret.pattern.IndexOf("**") != -1)
                {
                    mFlags |= Options.MATCHFLG_WILD2;
                    if (ret.pattern.IndexOf("**") == 0)
                    {
                        mFlags |= Options.MATCHFLG_WILD2_PREFIX;
                    }
                }
            }

            if (patLen > 1 && ret.pattern[ret.pattern.Length - 1] == '/')
            {
                ret.pattern = ret.pattern.Remove(ret.pattern.Length - 1, 1);
                mFlags     |= Options.MATCHFLG_DIRECTORY;
            }

            for (int i = 0; i < ret.pattern.Length; i++)
            {
                if (ret.pattern[i] == '/')
                {
                    ret.slashCnt++;
                }
            }
            ret.matchFlags = mFlags;
            exclList.Add(ret);
        }
Example #2
0
        public void MakeExlude(ref List <ExcludeStruct> exclList, string pat, UInt32 mFlags)
        {
            var exLen  = 0;
            var patLen = pat.Length;
            var ret    = new ExcludeStruct();

            if (_options.ExcludePathPrefix != null)
            {
                mFlags |= Options.MatchflgAbsPath;
            }
            if (_options.ExcludePathPrefix != null && pat[0] == '/')
            {
                exLen = _options.ExcludePathPrefix.Length;
            }
            else
            {
                exLen = 0;
            }
            ret.Pattern = String.Empty;
            if (exLen != 0)
            {
                ret.Pattern += _options.ExcludePathPrefix;
            }
            ret.Pattern += pat.Replace('\\', '/');
            patLen      += exLen;

            if (ret.Pattern.IndexOfAny(new[] { '*', '[', '?' }) != -1)
            {
                mFlags |= Options.MatchflgWild;
                if (ret.Pattern.IndexOf("**") != -1)
                {
                    mFlags |= Options.MatchflgWild2;
                    if (ret.Pattern.IndexOf("**") == 0)
                    {
                        mFlags |= Options.MatchflgWild2Prefix;
                    }
                }
            }

            if (patLen > 1 && ret.Pattern[ret.Pattern.Length - 1] == '/')
            {
                ret.Pattern = ret.Pattern.Remove(ret.Pattern.Length - 1, 1);
                mFlags     |= Options.MatchflgDirectory;
            }

            for (var i = 0; i < ret.Pattern.Length; i++)
            {
                if (ret.Pattern[i] == '/')
                {
                    ret.SlashCnt++;
                }
            }
            ret.MatchFlags = mFlags;
            exclList.Add(ret);
        }
Example #3
0
        public void ReportExcludeResult(string name, ExcludeStruct ent, int nameIsDir)
        {
            /* If a trailing slash is present to match only directories,
             * then it is stripped out by make_exclude.  So as a special
             * case we add it back in here. */

            if (options.verbose >= 2)
            {
                Log.Write(options.WhoAmI() + " " + ((ent.matchFlags & Options.MATCHFLG_INCLUDE) != 0 ? "in" : "ex") +
                          "cluding " + (nameIsDir != 0 ? "directory" : "file") + " " +
                          name + " because of " + ent.pattern + " pattern " +
                          ((ent.matchFlags & Options.MATCHFLG_DIRECTORY) != 0 ? "/" : String.Empty) + "\n");
            }
        }
Example #4
0
		public void ReportExcludeResult(string name, ExcludeStruct ent, int nameIsDir)
		{
			/* If a trailing slash is present to match only directories,
			* then it is stripped out by make_exclude.  So as a special
			* case we add it back in here. */

			if (options.verbose >= 2) 
			{
				Log.Write(options.WhoAmI() + " "+ ((ent.matchFlags & Options.MATCHFLG_INCLUDE) != 0 ? "in" : "ex") +
					"cluding " + (nameIsDir != 0 ? "directory" : "file") + " " +
					name + " because of " + ent.pattern + " pattern " +
					((ent.matchFlags & Options.MATCHFLG_DIRECTORY) != 0 ? "/" : "") + "\n");
			}
		}
Example #5
0
		static bool CheckOneExclude(string name, ExcludeStruct ex, int nameIsDir)
		{			
			int match_start = 0;
			string pattern = ex.pattern;

			if (name.CompareTo("") == 0)
				return false;
			if (pattern.CompareTo("") == 0)
				return false;

			if (0 != (ex.matchFlags & Options.MATCHFLG_DIRECTORY) && nameIsDir == 0)
				return false;

			if (pattern[0] == '/') 
			{
				match_start = 1;
				pattern = pattern.TrimStart('/');
				if (name[0] == '/')
					name = name.TrimStart('/');					
			}

			if ((ex.matchFlags & Options.MATCHFLG_WILD) != 0) 
			{
				/* A non-anchored match with an infix slash and no "**"
				 * needs to match the last slash_cnt+1 name elements. */
				if (match_start != 0 && ex.slashCnt != 0 && 0 ==(ex.matchFlags & Options.MATCHFLG_WILD2)) 
				{					
					name = name.Substring(name.IndexOf('/') + 1);					
				}
				if (WildMatch.CheckWildMatch(pattern, name))
					return true;
				if ((ex.matchFlags & Options.MATCHFLG_WILD2_PREFIX) != 0) 
				{
					/* If the **-prefixed pattern has a '/' as the next
					* character, then try to match the rest of the
					* pattern at the root. */
					if (pattern[2] == '/' && WildMatch.CheckWildMatch(pattern.Substring(3), name))
						return true;
				}
				else if (0 == match_start && (ex.matchFlags & Options.MATCHFLG_WILD2) != 0) 
				{
					/* A non-anchored match with an infix or trailing "**"
					* (but not a prefixed "**") needs to try matching
					* after every slash. */
					int posSlash;
					while ((posSlash = name.IndexOf('/')) != -1) 
					{
						name = name.Substring(posSlash + 1);
						if (WildMatch.CheckWildMatch(pattern, name))
							return true;
					}
				}
			} 
			else if (match_start != 0) 
			{
				if (name.CompareTo(pattern) == 0)
					return true;
			} 
			else 
			{
				int l1 = name.Length;
				int l2 = pattern.Length;
				if (l2 <= l1 &&
					name.Substring(l1-l2).CompareTo(pattern) == 0 &&
					(l1==l2 || name[l1-(l2+1)] == '/')) 
				{
					return true;
				}
			}

			return false;
		}
Example #6
0
		public void MakeExlude(ref ArrayList exclList, string pat, UInt32 mFlags)
		{
			int exLen = 0;
			int patLen = pat.Length;
			ExcludeStruct ret = new ExcludeStruct();
			if(options.excludePathPrefix != null)
				mFlags |= Options.MATCHFLG_ABS_PATH;
			if(options.excludePathPrefix != null && pat[0] == '/')
				exLen = options.excludePathPrefix.Length;
			else
				exLen = 0;
			ret.pattern = "";
			if(exLen != 0)
				ret.pattern += options.excludePathPrefix;
			ret.pattern += pat.Replace('\\','/');
			patLen += exLen;
			
			if(ret.pattern.IndexOfAny(new char[] {'*','[','?'}) != -1)
			{
				mFlags |= Options.MATCHFLG_WILD;
				if(ret.pattern.IndexOf("**") != -1)
				{
					mFlags |= Options.MATCHFLG_WILD2;
					if(ret.pattern.IndexOf("**") == 0)
						mFlags |= Options.MATCHFLG_WILD2_PREFIX;
				}
			}

			if(patLen > 1 && ret.pattern[ret.pattern.Length - 1] == '/')
			{
				ret.pattern = ret.pattern.Remove(ret.pattern.Length-1,1);
				mFlags |= Options.MATCHFLG_DIRECTORY;
			}

			for(int i = 0; i < ret.pattern.Length; i++)
				if(ret.pattern[i] == '/')
					ret.slashCnt++;
			ret.matchFlags = mFlags;
			exclList.Add(ret);
		}
Example #7
0
        static bool CheckOneExclude(string name, ExcludeStruct ex, int nameIsDir)
        {
            int    match_start = 0;
            string pattern     = ex.pattern;

            if (name.CompareTo(String.Empty) == 0)
            {
                return(false);
            }
            if (pattern.CompareTo(String.Empty) == 0)
            {
                return(false);
            }

            if (0 != (ex.matchFlags & Options.MATCHFLG_DIRECTORY) && nameIsDir == 0)
            {
                return(false);
            }

            if (pattern[0] == '/')
            {
                match_start = 1;
                pattern     = pattern.TrimStart('/');
                if (name[0] == '/')
                {
                    name = name.TrimStart('/');
                }
            }

            if ((ex.matchFlags & Options.MATCHFLG_WILD) != 0)
            {
                /* A non-anchored match with an infix slash and no "**"
                * needs to match the last slash_cnt+1 name elements. */
                if (match_start != 0 && ex.slashCnt != 0 && 0 == (ex.matchFlags & Options.MATCHFLG_WILD2))
                {
                    name = name.Substring(name.IndexOf('/') + 1);
                }
                if (WildMatch.CheckWildMatch(pattern, name))
                {
                    return(true);
                }
                if ((ex.matchFlags & Options.MATCHFLG_WILD2_PREFIX) != 0)
                {
                    /* If the **-prefixed pattern has a '/' as the next
                     * character, then try to match the rest of the
                     * pattern at the root. */
                    if (pattern[2] == '/' && WildMatch.CheckWildMatch(pattern.Substring(3), name))
                    {
                        return(true);
                    }
                }
                else if (0 == match_start && (ex.matchFlags & Options.MATCHFLG_WILD2) != 0)
                {
                    /* A non-anchored match with an infix or trailing "**"
                     * (but not a prefixed "**") needs to try matching
                     * after every slash. */
                    int posSlash;
                    while ((posSlash = name.IndexOf('/')) != -1)
                    {
                        name = name.Substring(posSlash + 1);
                        if (WildMatch.CheckWildMatch(pattern, name))
                        {
                            return(true);
                        }
                    }
                }
            }
            else if (match_start != 0)
            {
                if (name.CompareTo(pattern) == 0)
                {
                    return(true);
                }
            }
            else
            {
                int l1 = name.Length;
                int l2 = pattern.Length;
                if (l2 <= l1 &&
                    name.Substring(l1 - l2).CompareTo(pattern) == 0 &&
                    (l1 == l2 || name[l1 - (l2 + 1)] == '/'))
                {
                    return(true);
                }
            }

            return(false);
        }