From a21d334810c3cff2a04a3735af1a4ee54ffdf1ca Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Tue, 22 Jul 2014 15:10:19 +0200 Subject: [PATCH] additional sources can be indicated using \* project inspector add source folder is now recursive --- src/ce_common.pas | 75 +++++++++++++++++++++++++++++++++++------- src/ce_dmdwrap.pas | 9 ++++- src/ce_main.pas | 6 ++-- src/ce_projinspect.pas | 2 +- 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/src/ce_common.pas b/src/ce_common.pas index 70bb65f6..01495edd 100644 --- a/src/ce_common.pas +++ b/src/ce_common.pas @@ -15,6 +15,10 @@ const DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*'; +var + DExtList: TStringList; + DCompiler: string = 'dmd'; + type (** @@ -121,7 +125,7 @@ type (** * Fills aList with the names of the files located in aPath. *) - procedure listFiles(const aList: TStrings; const aPath: string); + procedure listFiles(const aList: TStrings; const aPath: string; recursive: boolean = false); (** * Fills aList with the names of the folders located in aPath. @@ -129,7 +133,7 @@ type procedure listFolders(const aList: TStrings; const aPath: string); (** - * Checks if aPath contains at least one sub-folder + * Checks if aPath contains at least one sub-folder. *) function hasFolder(const aPath: string): boolean; @@ -138,6 +142,12 @@ type *) procedure listDrives(const aList: TStrings); + (** + * If aPath ends with an asterisk then fills aList with the names of the files located in aPath. + * Returns true if aPath was 'asterisk-ifyed'. + *) + function listAsteriskPath(const aPath: string; const aList: TStrings; const someExts: TStrings = nil): boolean; + (** * Lets the shell open a file *) @@ -455,7 +465,13 @@ begin result += directorySeparator + 'Coedit' + directorySeparator; end; -procedure listFiles(const aList: TStrings; const aPath: string); +function isFolder(sr: TSearchRec): boolean; +begin + result := (sr.Name <> '.') and (sr.Name <> '..' )and (sr.Name <> '' ) and + (sr.Attr and faDirectory = faDirectory); +end; + +procedure listFiles(const aList: TStrings; const aPath: string; recursive: boolean = false); var sr: TSearchrec; procedure tryAdd; @@ -466,19 +482,17 @@ end; begin if findFirst(aPath + directorySeparator + '*.*', faAnyFile, sr) = 0 then try - repeat tryAdd; - until findNext(sr) <> 0; + repeat + tryAdd; + if recursive then if isFolder(sr) then + listFiles(aList, aPath + directorySeparator + sr.Name, recursive); + until + findNext(sr) <> 0; finally sysutils.FindClose(sr); end; end; -function isFolder(sr: TSearchRec): boolean; -begin - result := (sr.Name <> '.') and (sr.Name <> '..' )and (sr.Name <> '' ) and - (sr.Attr and faDirectory = faDirectory); -end; - procedure listFolders(const aList: TStrings; const aPath: string); var sr: TSearchrec; @@ -513,6 +527,38 @@ begin result := res; end; +function listAsteriskPath(const aPath: string; const aList: TStrings; const someExts: TStrings = nil): boolean; +var + pth, ext, fname: string; + files: TStringList; +begin + if aPath[length(aPath)] = '*' then + begin + pth := aPath[1..length(aPath)-2]; + if not directoryExists(pth) then exit(false); + // + files := TStringList.Create; + try + listFiles(files, pth, true); + for fname in files do + begin + if someExts = nil then + aList.Add(fname) + else + begin + ext := extractFileExt(fname); + if someExts.IndexOf(ext) <> -1 then + aList.Add(fname); + end; + end; + finally + files.Free; + end; + exit(true); + end; + exit(false); +end; + procedure listDrives(const aList: TStrings); {$IFDEF WINDOWS} var @@ -555,5 +601,10 @@ begin {$ENDIF} end; - +initialization + DExtList := TStringList.Create; + DExtList.Add('.d'); + DExtList.Add('.di'); +finalization + DExtList.Free; end. diff --git a/src/ce_dmdwrap.pas b/src/ce_dmdwrap.pas index 32d9c0f9..1f684585 100644 --- a/src/ce_dmdwrap.pas +++ b/src/ce_dmdwrap.pas @@ -7,6 +7,8 @@ interface uses classes, sysutils, process; +//TODO-cfeature: scanner for -I and -J sources is the item is a folder. + (* procedure to add a new compiler option: @@ -837,7 +839,12 @@ var str: string; begin for str in fSrcs do if str <> '' then - aList.Add(str); + begin + if not + listAsteriskPath(str, aList, DExtList) + then + aList.Add(str); + end; for str in fIncl do if str <> '' then aList.Add('-I'+ str); for str in fImpt do if str <> '' then diff --git a/src/ce_main.pas b/src/ce_main.pas index bc3e6473..7f242570 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -979,8 +979,8 @@ begin {$IFDEF RELEASE} dmdProc.ShowWindow := swoHIDE; {$ENDIF} - dmdproc.Options:= [poStdErrToOutput, poUsePipes]; - dmdproc.Executable:= 'dmd'; + dmdproc.Options := [poStdErrToOutput, poUsePipes]; + dmdproc.Executable := DCompiler; dmdproc.Parameters.Add(fname + '.d'); dmdproc.Parameters.Add('-w'); dmdproc.Parameters.Add('-wi'); @@ -1086,7 +1086,7 @@ begin {$ENDIF} dmdproc.Options := [{$IFDEF WINDOWS}poNewConsole,{$ENDIF} poStdErrToOutput, poUsePipes]; - dmdproc.Executable := 'dmd'; + dmdproc.Executable := DCompiler; aProject.getOpts(dmdproc.Parameters); try dmdproc.Execute; diff --git a/src/ce_projinspect.pas b/src/ce_projinspect.pas index 19a42269..fac9920d 100644 --- a/src/ce_projinspect.pas +++ b/src/ce_projinspect.pas @@ -189,7 +189,7 @@ begin begin lst := TStringList.Create; try - listFiles(lst, dir); + listFiles(lst, dir, true); for i := 0 to lst.Count-1 do begin fname := lst.Strings[i];