From f3dae9ae788ef53c9fdf4e6a754ececca99d2df9 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 20 Oct 2009 20:30:11 +0000 Subject: [PATCH] .include now quite working.. git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@144 3f818213-9676-44b0-a9b4-5e4c4e03d09d --- Includes/test.mufa | 7 ++++++ Projects/SAMufasaGUI/testunit.pas | 4 ++-- Units/MMLAddon/mmlpsthread.pas | 37 +++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 Includes/test.mufa diff --git a/Includes/test.mufa b/Includes/test.mufa new file mode 100644 index 0000000..0106e0f --- /dev/null +++ b/Includes/test.mufa @@ -0,0 +1,7 @@ +const + TestStr = 'Hai, seems like you got includes working!'; + +function Multiply(a,b : integer) : integer; +begin; + result := a*b; +end; \ No newline at end of file diff --git a/Projects/SAMufasaGUI/testunit.pas b/Projects/SAMufasaGUI/testunit.pas index 3e95706..4563773 100644 --- a/Projects/SAMufasaGUI/testunit.pas +++ b/Projects/SAMufasaGUI/testunit.pas @@ -140,9 +140,9 @@ begin MMLPSThread.SetPSScript(Self.SynEdit1.Lines.Text); MMLPSThread.SetDebug(Self.Memo1); if ScriptFile <> '' then - MMLPSThread.SetPaths( ExtractFileDir(ScriptFile) + DS,MainDir +DS) + MMLPSThread.SetPaths( ExtractFileDir(ScriptFile) + DS,IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds))) else - MMLPSThread.SetPaths('',MainDir + DS); + MMLPSThread.SetPaths('', IncludeTrailingPathDelimiter(ExpandFileName(MainDir +DS + '..' + DS + '..' + ds))); // This doesn't actually set the Client's MWindow to the passed window, it // only copies the current set window handle. diff --git a/Units/MMLAddon/mmlpsthread.pas b/Units/MMLAddon/mmlpsthread.pas index e90da05..2f6c49f 100644 --- a/Units/MMLAddon/mmlpsthread.pas +++ b/Units/MMLAddon/mmlpsthread.pas @@ -44,6 +44,9 @@ type PSyncInfo = ^TSyncInfo; TMMLPSThread = class(TThread) + procedure OnProcessDirective(Sender: TPSPreProcessor; + Parser: TPSPascalPreProcessorParser; const Active: Boolean; + const DirectiveName, DirectiveParam: string; var Continue: Boolean); procedure PSScriptProcessUnknowDirective(Sender: TPSPreProcessor; Parser: TPSPascalPreProcessorParser; const Active: Boolean; const DirectiveName, DirectiveParam: string; var Continue: Boolean); @@ -150,6 +153,7 @@ begin PSScript := TPSScript.Create(nil); PSScript.UsePreProcessor:= True; PSScript.OnNeedFile := @RequireFile; + PSScript.OnProcessDirective:=@OnProcessDirective; PSScript.OnProcessUnknowDirective:=@PSScriptProcessUnknowDirective; PSScript.OnCompile:= @OnCompile; PSScript.OnCompImport:= @OnCompImport; @@ -187,6 +191,11 @@ end; {$I PSInc/Wrappers/mouse.inc} {$I PSInc/Wrappers/dtm.inc} +procedure TMMLPSThread.OnProcessDirective(Sender: TPSPreProcessor; + Parser: TPSPascalPreProcessorParser; const Active: Boolean; + const DirectiveName, DirectiveParam: string; var Continue: Boolean); +begin +end; procedure TMMLPSThread.PSScriptProcessUnknowDirective(Sender: TPSPreProcessor; Parser: TPSPascalPreProcessorParser; const Active: Boolean; @@ -233,9 +242,33 @@ end; function TMMLPSThread.RequireFile(Sender: TObject; const OriginFileName: String; var FileName, OutPut: string): Boolean; +var + path: string; + f: TFileStream; begin - - Result := False; + if FileExists(FileName) then + Path := FileName + else + Path := AppPath+ 'Includes' + DS + Filename; + if not FileExists(Path) then + begin; + Writeln(Path + ' doesn''t exist'); + Result := false; + Exit; + end; + try + F := TFileStream.Create(Path, fmOpenRead or fmShareDenyWrite); + except + Result := false; + exit; + end; + try + SetLength(Output, f.Size); + f.Read(Output[1], Length(Output)); + finally + f.Free; + end; + Result := True; end; procedure TMMLPSThread.OnCompImport(Sender: TObject; x: TPSPascalCompiler);