From f0bd30c9488293e7285b31cd75fb9fad37733c0d Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Mon, 14 Mar 2016 03:49:23 +0100 Subject: [PATCH] fix #26, DUB excludedSourceFiles are not well managed --- src/ce_common.pas | 53 +++++++++++++++++++++++++++++++++++++++++++ src/ce_dubproject.pas | 31 +++++++++++++++++++------ 2 files changed, 77 insertions(+), 7 deletions(-) diff --git a/src/ce_common.pas b/src/ce_common.pas index bb0e0f91..982c0e9d 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -268,6 +268,13 @@ type *) function isBlank(const str: string): boolean; + (** + * Converts a global match expression to a regular expression. + * Limitation: Windows style, [] not handled. + * src: github.com/spring/svn-spring-archive/blob/master/branches/greenail/rts/System/Platform/filefunctions.h#L29 + *) + function globToReg(const glob: string ): string; + var // supplementatl directories to find background tools additionalPath: string; @@ -1160,6 +1167,52 @@ begin exit(false); end; +function globToReg(const glob: string ): string; + procedure quote(var r: string; c: char); + begin + if not (c in ['a'..'z', 'A'..'Z', '0'..'9', '_']) then + r += '\'; + r += c; + end; +var + i: integer = 0; + b: integer = 0; +begin + result := '^'; + while i < length(glob) do + begin + i += 1; + case glob[i] of + '*': result += '.*'; + '?': result += '.'; + '{': + begin + b += 1; + result += '('; + end; + '}': + begin + b -= 1; + result += ')'; + end; + ',': + begin + if b > 0 then + result += '|' + else + quote(result, glob[i]); + end; + '\': + begin + i += 1; + quote(result, glob[i]); + end; + else + quote(result, glob[i]); + end; + end; +end; + initialization registerClasses([TCEPersistentShortcut]); end. diff --git a/src/ce_dubproject.pas b/src/ce_dubproject.pas index cffb68e6..babf203e 100644 --- a/src/ce_dubproject.pas +++ b/src/ce_dubproject.pas @@ -5,7 +5,8 @@ unit ce_dubproject; interface uses - Classes, SysUtils, xfpjson, xjsonparser, xjsonscanner, process, strutils, LazFileUtils, + Classes, SysUtils, xfpjson, xjsonparser, xjsonscanner, process, strutils, + LazFileUtils, RegExpr, ce_common, ce_interfaces, ce_observer, ce_dialogs, ce_processes; type @@ -595,6 +596,7 @@ begin end; var pth: string; + glb: TRegExpr; begin fSrcs.Clear; if not assigned(fJSON) then @@ -662,14 +664,29 @@ begin // exclusions lst.Clear; getExclusion(fJSON); - conf := getCurrentCustomConfig; + conf := getCurrentCustomConfig; if conf.isNotNil then getExclusion(conf); - for i := fSrcs.Count-1 downto 0 do - for j := 0 to lst.Count-1 do - if SameFileName(fSrcs[i], lst[j]) then - fSrcs.Delete(i); - // TODO-cDUB: manage exclusions with http://dlang.org/phobos/std_path.html#.globMatch + if lst.Count > 0 then + begin + glb := TRegExpr.Create; + try + for j := 0 to lst.Count-1 do + begin + try + glb.Expression := globToReg(lst[j]); + glb.Compile; + for i := fSrcs.Count-1 downto 0 do + if glb.Exec(fSrcs[i]) then + fSrcs.Delete(i); + except + continue; + end; + end; + finally + glb.Free; + end; + end; finally lst.Free; end;