Added Wildcards and -fc to PasIntfExtract
This commit is contained in:
@@ -41,6 +41,10 @@ type
|
|||||||
InDegree: Integer;
|
InDegree: Integer;
|
||||||
Processed: Boolean;
|
Processed: Boolean;
|
||||||
|
|
||||||
|
// Fields for the -fc (focus complete) feature
|
||||||
|
IsFcStartFile: Boolean;
|
||||||
|
FullSource: TStringList;
|
||||||
|
|
||||||
constructor Create(const AFilePath: string);
|
constructor Create(const AFilePath: string);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function ParseUnit: Boolean;
|
function ParseUnit: Boolean;
|
||||||
@@ -100,6 +104,8 @@ begin
|
|||||||
AdjacencyList := TUnitInfoList.Create;
|
AdjacencyList := TUnitInfoList.Create;
|
||||||
InDegree := 0;
|
InDegree := 0;
|
||||||
Processed := False;
|
Processed := False;
|
||||||
|
IsFcStartFile := False;
|
||||||
|
FullSource := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TUnitInfo.Destroy;
|
destructor TUnitInfo.Destroy;
|
||||||
@@ -108,6 +114,7 @@ begin
|
|||||||
InterfaceUses.Free;
|
InterfaceUses.Free;
|
||||||
FOriginalLines.Free;
|
FOriginalLines.Free;
|
||||||
AdjacencyList.Free;
|
AdjacencyList.Free;
|
||||||
|
FullSource.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -425,7 +432,6 @@ begin
|
|||||||
end
|
end
|
||||||
else if inUsesBlock then
|
else if inUsesBlock then
|
||||||
begin
|
begin
|
||||||
// FIXED: Use AppendLine to preserve newlines for comment stripping logic
|
|
||||||
usesBuilder.AppendLine(Trim(LineValue));
|
usesBuilder.AppendLine(Trim(LineValue));
|
||||||
lineIsForUses := True;
|
lineIsForUses := True;
|
||||||
end;
|
end;
|
||||||
@@ -534,6 +540,7 @@ var
|
|||||||
writeToClipboard: Boolean;
|
writeToClipboard: Boolean;
|
||||||
currentParamIndex: Integer;
|
currentParamIndex: Integer;
|
||||||
focusMode: Boolean;
|
focusMode: Boolean;
|
||||||
|
fcMode: Boolean;
|
||||||
focusFilesParameter: string;
|
focusFilesParameter: string;
|
||||||
initialFocusFiles: TStringList;
|
initialFocusFiles: TStringList;
|
||||||
filesToExcludeFromOutput: TStringList;
|
filesToExcludeFromOutput: TStringList;
|
||||||
@@ -552,10 +559,11 @@ begin
|
|||||||
filesToExcludeFromOutput := nil;
|
filesToExcludeFromOutput := nil;
|
||||||
exitcode := 0;
|
exitcode := 0;
|
||||||
focusMode := False;
|
focusMode := False;
|
||||||
|
fcMode := False;
|
||||||
focusFilesParameter := '';
|
focusFilesParameter := '';
|
||||||
|
|
||||||
try
|
try
|
||||||
var usageStr := 'Usage: ExtractPascalInterfaces.exe [-r] [-dirs <file>] [-f <files> | -fx <files>] [-o <file> | -c] <SrcDir1> ...';
|
var usageStr := 'Usage: ExtractPascalInterfaces.exe [-r] [-dirs <file>] [-f|-fx|-fc <files>] [-o <file> | -c] <SrcDir1> ...';
|
||||||
|
|
||||||
WriteLn('Delphi Interface Extractor');
|
WriteLn('Delphi Interface Extractor');
|
||||||
sourceDirectories := TList<string>.Create;
|
sourceDirectories := TList<string>.Create;
|
||||||
@@ -623,11 +631,11 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if SameText(currentParam, '-f') or SameText(currentParam, '-fx') then
|
else if SameText(currentParam, '-f') or SameText(currentParam, '-fx') or SameText(currentParam, '-fc') then
|
||||||
begin
|
begin
|
||||||
if focusMode then
|
if focusMode then
|
||||||
begin
|
begin
|
||||||
WriteLn('Error: -f and -fx options cannot be used together.');
|
WriteLn('Error: Focus options (-f, -fx, -fc) cannot be used together.');
|
||||||
WriteLn(usageStr);
|
WriteLn(usageStr);
|
||||||
exitcode := 1;
|
exitcode := 1;
|
||||||
exit;
|
exit;
|
||||||
@@ -636,10 +644,42 @@ begin
|
|||||||
if currentParamIndex + 1 <= ParamCount then
|
if currentParamIndex + 1 <= ParamCount then
|
||||||
begin
|
begin
|
||||||
focusMode := True;
|
focusMode := True;
|
||||||
|
fcMode := SameText(currentParam, '-fc');
|
||||||
focusFilesParameter := ParamStr(currentParamIndex + 1);
|
focusFilesParameter := ParamStr(currentParamIndex + 1);
|
||||||
initialFocusFiles.Text := StringReplace(focusFilesParameter, ';', sLineBreak, [rfReplaceAll]);
|
var patternsList := TStringList.Create;
|
||||||
if SameText(currentParam, '-fx') then
|
var expandedFocusFiles := TStringList.Create;
|
||||||
filesToExcludeFromOutput.Text := initialFocusFiles.Text;
|
try
|
||||||
|
patternsList.Text := StringReplace(focusFilesParameter, ';', sLineBreak, [rfReplaceAll]);
|
||||||
|
for var pattern in patternsList do
|
||||||
|
begin
|
||||||
|
if (pattern.Contains('*')) or (pattern.Contains('?')) then
|
||||||
|
begin
|
||||||
|
var searchPath := ExtractFilePath(pattern);
|
||||||
|
var searchMask := ExtractFileName(pattern);
|
||||||
|
if searchPath = '' then
|
||||||
|
searchPath := TDirectory.GetCurrentDirectory;
|
||||||
|
try
|
||||||
|
expandedFocusFiles.AddStrings(TDirectory.GetFiles(searchPath, searchMask));
|
||||||
|
except
|
||||||
|
on E: EDirectoryNotFoundException do
|
||||||
|
WriteLn('Warning: Directory for pattern not found, skipping: ' + pattern);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
expandedFocusFiles.Add(pattern);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialFocusFiles.Clear;
|
||||||
|
initialFocusFiles.AddStrings(expandedFocusFiles);
|
||||||
|
|
||||||
|
if SameText(currentParam, '-fx') then
|
||||||
|
filesToExcludeFromOutput.Text := initialFocusFiles.Text;
|
||||||
|
finally
|
||||||
|
patternsList.Free;
|
||||||
|
expandedFocusFiles.Free;
|
||||||
|
end;
|
||||||
Inc(currentParamIndex, 2);
|
Inc(currentParamIndex, 2);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -822,6 +862,19 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if fcMode then
|
||||||
|
begin
|
||||||
|
// After filtering, identify the start files and store their full source
|
||||||
|
for var unitInfo in allUnits.Values do
|
||||||
|
begin
|
||||||
|
if initialFocusFiles.IndexOf(unitInfo.FilePath) > -1 then
|
||||||
|
begin
|
||||||
|
unitInfo.IsFcStartFile := True;
|
||||||
|
unitInfo.FullSource.AddStrings(unitInfo.FOriginalLines);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
WriteLn('Building dependency graph...');
|
WriteLn('Building dependency graph...');
|
||||||
for var currentUnit in allUnits.Values do
|
for var currentUnit in allUnits.Values do
|
||||||
for var usedUnitName in currentUnit.InterfaceUses do
|
for var usedUnitName in currentUnit.InterfaceUses do
|
||||||
@@ -921,7 +974,13 @@ begin
|
|||||||
outputContent.Add('// - ' + dirPath + IfThen(recursiveSearch, ' (recursive)', ''));
|
outputContent.Add('// - ' + dirPath + IfThen(recursiveSearch, ' (recursive)', ''));
|
||||||
if focusMode then
|
if focusMode then
|
||||||
begin
|
begin
|
||||||
var modeStr := IfThen(filesToExcludeFromOutput.Count > 0, '-fx', '-f');
|
var modeStr: string;
|
||||||
|
if fcMode then
|
||||||
|
modeStr := '-fc'
|
||||||
|
else if filesToExcludeFromOutput.Count > 0 then
|
||||||
|
modeStr := '-fx'
|
||||||
|
else
|
||||||
|
modeStr := '-f';
|
||||||
outputContent.Add('// Focus mode (' + modeStr + ') active for files: ' + focusFilesParameter);
|
outputContent.Add('// Focus mode (' + modeStr + ') active for files: ' + focusFilesParameter);
|
||||||
end;
|
end;
|
||||||
outputContent.Add('// Generated on: ' + DateTimeToStr(Now));
|
outputContent.Add('// Generated on: ' + DateTimeToStr(Now));
|
||||||
@@ -963,15 +1022,32 @@ begin
|
|||||||
if filesToExcludeFromOutput.IndexOf(item.FilePath) > -1 then
|
if filesToExcludeFromOutput.IndexOf(item.FilePath) > -1 then
|
||||||
Continue;
|
Continue;
|
||||||
|
|
||||||
if item.InterfaceSection.Count > 0 then
|
if item.IsFcStartFile then
|
||||||
begin
|
begin
|
||||||
|
// For -fc start files, add the complete source code
|
||||||
outputContent
|
outputContent
|
||||||
.Add('//==================================================================================================');
|
.Add('//==================================================================================================');
|
||||||
outputContent.Add('//== UNIT START: ' + item.Name + ' (from ' + ExtractFileName(item.FilePath) + ')');
|
outputContent.Add('//== FULL UNIT START: ' + item.Name + ' (from ' + ExtractFileName(item.FilePath) + ')');
|
||||||
|
outputContent
|
||||||
|
.Add('//==================================================================================================');
|
||||||
|
outputContent.AddStrings(item.FullSource);
|
||||||
|
outputContent
|
||||||
|
.Add('//==================================================================================================');
|
||||||
|
outputContent.Add('//== FULL UNIT END: ' + item.Name);
|
||||||
|
outputContent
|
||||||
|
.Add('//==================================================================================================');
|
||||||
|
outputContent.Add('');
|
||||||
|
end
|
||||||
|
else if item.InterfaceSection.Count > 0 then
|
||||||
|
begin
|
||||||
|
// For all other units, add the interface section only
|
||||||
|
outputContent
|
||||||
|
.Add('//==================================================================================================');
|
||||||
|
outputContent.Add('//== INTERFACE START: ' + item.Name + ' (from ' + ExtractFileName(item.FilePath) + ')');
|
||||||
outputContent
|
outputContent
|
||||||
.Add('//==================================================================================================');
|
.Add('//==================================================================================================');
|
||||||
outputContent.AddStrings(item.InterfaceSection);
|
outputContent.AddStrings(item.InterfaceSection);
|
||||||
outputContent.Add('//== UNIT END: ' + item.Name);
|
outputContent.Add('//== INTERFACE END: ' + item.Name);
|
||||||
outputContent
|
outputContent
|
||||||
.Add('//==================================================================================================');
|
.Add('//==================================================================================================');
|
||||||
outputContent.Add('');
|
outputContent.Add('');
|
||||||
|
|||||||
Reference in New Issue
Block a user