program Project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes,
sysutils,
CodeToolManager,
CodeTree, CodeCache
{ you can add units after this };
var
Code: TCodeBuffer;
Tool: TCodeTool;
i: Integer;
procedure ExtractUsesSectionFromFile( AFileName: String );
var
Main, Impl: TStrings;
j: Integer;
begin
Code:= CodeToolBoss.LoadFile( ExpandFileName( AFileName ), False, False );
if ( not Assigned( Code )) then
raise Exception.Create( 'Could not load the unit file: ' + AFileName );
Tool:= nil;
if ( not CodeToolBoss.Explore( Code, Tool, False, True )) then
raise Exception.Create( 'The code of the unit file could not be parsed as it contains errors: ' + AFileName );
if ( not Assigned( Tool )) then
Tool:= TCodeTool( CodeToolBoss.GetCodeToolForSource( Code, False, False ));
Tool.FindUsedUnitFiles( Main, Impl );
WriteLn( 'Used units of ', AFileName );
WriteLn( 'Used units in uses section:' );
for j:= 0 to Main.Count - 1 do
WriteLn( Main[ j ]);
//WriteLn( Main.Text );
WriteLn();
WriteLn( 'Used units in implementation section:' );
WriteLn( Impl.Text );
Main.Free;
Impl.Free;
end;
begin
if ( ParamCount > 0 ) then
for i:= 1 to ParamCount do
ExtractUsesSectionFromFile( ParamStr( i ))
else
WriteLn( 'Error: no files passed as parameter' );
end.