2010-01-25 08:59:44 -05:00
|
|
|
{
|
|
|
|
This file is part of the Mufasa Macro Library (MML)
|
|
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
|
|
|
|
|
|
|
MML is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
MML is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
See the file COPYING, included in this distribution,
|
|
|
|
for details about the copyright.
|
|
|
|
|
|
|
|
MMLPSThread for the Mufasa Macro Library
|
|
|
|
}
|
|
|
|
|
|
|
|
unit mmlpsthread;
|
|
|
|
|
2011-08-05 07:04:52 -04:00
|
|
|
{$define PS_USESSUPPORT}
|
2011-02-19 07:18:08 -05:00
|
|
|
//{$define USE_RUTIS}
|
2011-08-05 07:04:52 -04:00
|
|
|
{$define USE_LAPE}
|
2010-01-25 08:59:44 -05:00
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, client, uPSComponent,uPSCompiler,
|
2011-02-21 09:56:17 -05:00
|
|
|
uPSRuntime, uPSPreProcessor,MufasaTypes,MufasaBase, web,
|
|
|
|
bitmaps, plugins, dynlibs,internets,scriptproperties,
|
2011-02-05 18:33:56 -05:00
|
|
|
settings,settingssandbox, lcltype, dialogs
|
|
|
|
{$IFDEF USE_RUTIS}
|
2011-08-05 07:04:52 -04:00
|
|
|
, Rutis_Engine, Rutis_Defs
|
2011-02-19 07:18:08 -05:00
|
|
|
{$ENDIF}
|
2011-08-05 07:04:52 -04:00
|
|
|
{$IFDEF USE_LAPE}
|
|
|
|
, lpparser, lpcompiler, lptypes, lpvartypes,
|
|
|
|
lpeval, lpinterpreter, lpdisassembler
|
|
|
|
{$ENDIF};
|
2010-01-25 08:59:44 -05:00
|
|
|
|
2010-08-17 19:22:03 -04:00
|
|
|
const
|
|
|
|
m_Status = 0; //Data = PChar to new status
|
|
|
|
m_Disguise = 1; //Data = PChar to new title
|
|
|
|
m_DisplayDebugImgWindow = 2; //Data = PPoint to window size
|
|
|
|
m_DrawBitmapDebugImg = 3; //Data = TMufasaBitmap
|
|
|
|
m_GetDebugBitmap = 4; //Data = TMufasaBitmap
|
|
|
|
m_ClearDebugImg = 5; //Data = nil
|
|
|
|
m_ClearDebug = 6; //Data = nil
|
2010-09-11 08:01:56 -04:00
|
|
|
m_InputQuery = 7; //Data = PInputQueryData
|
|
|
|
m_ShowMessage = 8; //Data = PChar
|
|
|
|
m_MessageBox = 9; //Data = PMessageBoxData
|
|
|
|
m_MessageDlg = 10; //Data = PMessageDlg
|
2010-01-25 08:59:44 -05:00
|
|
|
type
|
|
|
|
{ TMMLPSThread }
|
2010-08-17 19:22:03 -04:00
|
|
|
TCallBackData = record
|
|
|
|
FormCallBack : procedure of object;
|
|
|
|
cmd : integer;
|
|
|
|
data : pointer;
|
|
|
|
end;
|
|
|
|
PCallBackData = ^TCallBackData;
|
2010-01-25 08:59:44 -05:00
|
|
|
TSyncInfo = record
|
2010-04-07 08:01:26 -04:00
|
|
|
V : MufasaTypes.PVariantArray;
|
2010-01-25 08:59:44 -05:00
|
|
|
MethodName : string;
|
2010-04-11 15:42:42 -04:00
|
|
|
Res : ^Variant;
|
2010-01-25 08:59:44 -05:00
|
|
|
SyncMethod : procedure of object;
|
|
|
|
OldThread : TThread;
|
|
|
|
end;
|
|
|
|
|
|
|
|
PSyncInfo = ^TSyncInfo;
|
|
|
|
TErrorType = (errRuntime,errCompile);
|
|
|
|
TOnError = procedure of object;
|
|
|
|
TErrorData = record
|
2010-02-26 11:59:05 -05:00
|
|
|
Row,Col,Position : integer;
|
2010-01-25 08:59:44 -05:00
|
|
|
Error : string;
|
|
|
|
ErrType : TErrorType;
|
|
|
|
Module : string;
|
|
|
|
IncludePath : string;
|
|
|
|
end;
|
|
|
|
PErrorData = ^TErrorData;
|
|
|
|
TExpMethod = record
|
|
|
|
Section : string;
|
|
|
|
FuncDecl : string;
|
|
|
|
FuncPtr : Pointer;
|
|
|
|
end;
|
|
|
|
TExpMethodArr = array of TExpMethod;
|
2010-05-01 18:44:30 -04:00
|
|
|
TInputQueryData = record
|
|
|
|
ACaption, APrompt,Value : String;
|
|
|
|
Res : boolean;
|
|
|
|
end;
|
2010-09-11 08:01:56 -04:00
|
|
|
PInputQueryData = ^TInputQueryData;
|
|
|
|
TMessageBoxData = record
|
|
|
|
AText, ACaption : PChar;
|
|
|
|
AFlags, res : integer;
|
|
|
|
end;
|
|
|
|
PMessageBoxData = ^TMessageBoxdata;
|
|
|
|
TMessageDlgData = record
|
|
|
|
ACaption, AMsg : string;
|
|
|
|
ADlgType : TMsgDlgType;
|
|
|
|
AButtons : TMsgDlgButtons;
|
|
|
|
Res : integer;
|
|
|
|
end;
|
|
|
|
PMessageDlgData = ^TMessageDlgData;
|
|
|
|
|
2010-03-06 09:23:24 -05:00
|
|
|
{ TMThread }
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
TMThread = class(TThread)
|
2010-04-07 08:01:26 -04:00
|
|
|
private
|
|
|
|
procedure SetOpenConnectionEvent(const AValue: TOpenConnectionEvent);
|
|
|
|
procedure SetOpenFileEvent(const AValue: TOpenFileEvent);
|
|
|
|
procedure SetWriteFileEvent(const AValue: TWriteFileEvent);
|
2010-01-25 12:38:43 -05:00
|
|
|
protected
|
|
|
|
ScriptPath, AppPath, IncludePath, PluginPath, FontPath: string;
|
|
|
|
DebugTo: TWritelnProc;
|
|
|
|
ExportedMethods : TExpMethodArr;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes : TStringList;
|
2010-04-07 08:01:26 -04:00
|
|
|
FOpenConnectionEvent : TOpenConnectionEvent;
|
|
|
|
FWriteFileEvent : TWriteFileEvent;
|
|
|
|
FOpenFileEvent : TOpenFileEvent;
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure LoadPlugin(plugidx: integer); virtual; abstract;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
|
|
|
public
|
2010-05-20 04:08:54 -04:00
|
|
|
Prop: TScriptProperties;
|
2010-01-25 12:38:43 -05:00
|
|
|
Client : TClient;
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet : TMInternet;
|
2010-12-20 01:48:42 -05:00
|
|
|
Socks: TSocks;
|
2010-01-25 12:38:43 -05:00
|
|
|
StartTime : LongWord;
|
2010-07-09 05:36:44 -04:00
|
|
|
Settings: TMMLSettings;
|
|
|
|
SimbaSettingsFile: String;
|
2010-03-25 08:37:52 -04:00
|
|
|
Sett: TMMLSettingsSandbox;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-08-17 19:22:03 -04:00
|
|
|
CallBackData : PCallBackData; //Handles general callback functions for threadsafety
|
2010-01-25 12:38:43 -05:00
|
|
|
SyncInfo : PSyncInfo; //We need this for callthreadsafe
|
|
|
|
ErrorData : PErrorData; //We need this for thread-safety etc
|
|
|
|
OnError : TOnError; //Error handeler
|
|
|
|
|
2010-01-31 07:29:33 -05:00
|
|
|
CompileOnly : boolean;
|
2010-04-07 08:01:26 -04:00
|
|
|
|
2010-08-17 19:22:03 -04:00
|
|
|
procedure FormCallBackEx(cmd : integer; var data : pointer);
|
|
|
|
procedure FormCallBack(cmd : integer; data : pointer);
|
2010-02-26 11:59:05 -05:00
|
|
|
procedure HandleError(ErrorRow,ErrorCol,ErrorPosition : integer; ErrorStr : string; ErrorType : TErrorType; ErrorModule : string);
|
2011-02-21 08:36:55 -05:00
|
|
|
function ProcessDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
DirectiveName, DirectiveArgs: string; Filename:String): boolean;
|
2010-02-26 11:59:05 -05:00
|
|
|
function LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure AddMethod(meth: TExpMethod); virtual;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure SetDebug( writelnProc : TWritelnProc );
|
|
|
|
procedure SetPaths(ScriptP,AppP,IncludeP,PluginP,FontP : string);
|
2010-07-09 05:36:44 -04:00
|
|
|
procedure SetSettings(S: TMMLSettings; SimbaSetFile: String);
|
2010-03-25 08:37:52 -04:00
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure OnThreadTerminate(Sender: TObject);
|
|
|
|
procedure SetScript(script: string); virtual; abstract;
|
|
|
|
procedure Execute; override; abstract;
|
|
|
|
procedure Terminate; virtual; abstract;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
constructor Create(CreateSuspended: boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-01-25 12:38:43 -05:00
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
class function GetExportedMethods : TExpMethodArr;
|
2010-04-07 08:01:26 -04:00
|
|
|
|
|
|
|
property OpenConnectionEvent : TOpenConnectionEvent read FOpenConnectionEvent write SetOpenConnectionEvent;
|
|
|
|
property WriteFileEvent : TWriteFileEvent read FWriteFileEvent write SetWriteFileEvent;
|
|
|
|
property OpenFileEvent : TOpenFileEvent read FOpenFileEvent write SetOpenFileEvent;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
2010-04-10 08:34:24 -04:00
|
|
|
{ TPSThread }
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
TPSThread = class(TMThread)
|
2010-01-26 17:58:41 -05:00
|
|
|
public
|
|
|
|
procedure OnProcessDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2011-02-21 08:36:55 -05:00
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean;
|
|
|
|
Filename: String);
|
2010-01-26 17:58:41 -05:00
|
|
|
function PSScriptFindUnknownFile(Sender: TObject;
|
|
|
|
const OrginFileName: string; var FileName, Output: string): Boolean;
|
2011-02-21 08:36:55 -05:00
|
|
|
procedure PSScriptProcessUnknownDirective(Sender: TPSPreProcessor;
|
2010-01-26 17:58:41 -05:00
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2011-02-21 08:36:55 -05:00
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean;
|
|
|
|
Filename: string);
|
2010-01-26 17:58:41 -05:00
|
|
|
protected
|
2010-02-07 03:42:06 -05:00
|
|
|
PluginsToload : array of integer;
|
|
|
|
procedure LoadPlugin(plugidx: integer); override;
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure OnCompile(Sender: TPSScript);
|
|
|
|
function RequireFile(Sender: TObject; const OriginFileName: String;
|
|
|
|
var FileName, OutPut: string): Boolean;
|
2011-07-31 11:36:34 -04:00
|
|
|
function FileAlreadyIncluded(Sender: TObject; OrgFileName, FileName: string): Boolean;
|
|
|
|
function OnIncludingFile(Sender: TObject; OrgFileName, FileName: string): Boolean;
|
2011-02-19 09:19:08 -05:00
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
|
|
|
procedure OnExecImport(Sender: TObject; se: TPSExec; x: TPSRuntimeClassImporter);
|
|
|
|
procedure OutputMessages;
|
2010-04-10 08:34:24 -04:00
|
|
|
procedure HandleScriptTerminates;
|
2010-01-26 17:58:41 -05:00
|
|
|
public
|
|
|
|
PSScript : TPSScript;
|
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TPrecompiler_Callback = function(name, args: PChar): boolean; stdcall;
|
2010-01-27 10:52:58 -05:00
|
|
|
TErrorHandeler_Callback = procedure(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
2010-01-26 17:58:41 -05:00
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
TCPThread = class(TMThread)
|
2010-01-26 17:58:41 -05:00
|
|
|
protected
|
|
|
|
instance: pointer;
|
2010-01-27 10:52:58 -05:00
|
|
|
added_methods: array of TExpMethod;
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure LoadPlugin(plugidx: integer); override;
|
2010-01-26 17:58:41 -05:00
|
|
|
public
|
2010-01-28 01:01:07 -05:00
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-01-26 17:58:41 -05:00
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
procedure AddMethod(meth: TExpMethod); override;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-08-20 11:21:04 -04:00
|
|
|
{ TRTThread }
|
2011-02-05 18:33:56 -05:00
|
|
|
{$IFDEF USE_RUTIS}
|
2010-08-20 11:21:04 -04:00
|
|
|
TRTThread = class(TMThread)
|
|
|
|
private
|
|
|
|
procedure RTOnWrite(s : String);
|
|
|
|
procedure RTOnError(s : String; ErrorType : TRutisErrorType);
|
|
|
|
public
|
|
|
|
RUTIS : TRutisEngine;
|
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
end;
|
2011-02-05 18:33:56 -05:00
|
|
|
{$ENDIF}
|
2010-08-20 11:21:04 -04:00
|
|
|
|
2011-08-05 07:04:52 -04:00
|
|
|
{$IFDEF USE_LAPE}
|
|
|
|
{ TLPThread }
|
|
|
|
TLPThread = class(TMThread)
|
|
|
|
protected
|
|
|
|
procedure LoadPlugin(plugidx: integer); override;
|
|
|
|
public
|
|
|
|
Parser: TLapeTokenizerString;
|
|
|
|
Compiler: TLapeCompiler;
|
|
|
|
constructor Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure SetScript(Script: string); override;
|
|
|
|
procedure Execute; override;
|
|
|
|
procedure Terminate; override;
|
|
|
|
function OnFindFile(Sender: TLapeCompiler; var FileName: lpString): TLapeTokenizerBase;
|
|
|
|
function OnHandleDirective(Sender: TLapeCompiler; Directive, Argument: lpString; InPeek: Boolean): Boolean;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2010-08-20 11:21:04 -04:00
|
|
|
|
2010-07-24 08:41:53 -04:00
|
|
|
threadvar
|
2010-01-25 12:38:43 -05:00
|
|
|
CurrThread : TMThread;
|
2010-01-26 17:58:41 -05:00
|
|
|
var
|
|
|
|
PluginsGlob: TMPlugins;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
libcpascal: integer;
|
|
|
|
interp_init: function(precomp: TPrecompiler_Callback; err: TErrorHandeler_Callback): Pointer; cdecl;
|
|
|
|
interp_meth: procedure(interp: Pointer; addr: Pointer; def: PChar); cdecl;
|
2010-02-05 14:24:27 -05:00
|
|
|
interp_type: procedure(interp: Pointer; def: PChar); cdecl;
|
2010-01-28 01:01:07 -05:00
|
|
|
interp_set: procedure(interp: Pointer; ppg: PChar); cdecl;
|
|
|
|
interp_comp: function(interp: Pointer): boolean; cdecl;
|
|
|
|
interp_run: function(interp: Pointer): boolean; cdecl;
|
|
|
|
interp_free: procedure(interp: Pointer); cdecl;
|
2010-01-25 12:38:43 -05:00
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
implementation
|
2010-01-27 00:44:43 -05:00
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
uses
|
|
|
|
colour_conv,dtmutil,
|
2010-02-26 11:59:05 -05:00
|
|
|
{$ifdef mswindows}windows, MMSystem,{$endif}//MMSystem -> Sounds
|
2010-03-25 06:57:55 -04:00
|
|
|
uPSC_std, uPSC_controls,uPSC_classes,uPSC_graphics,uPSC_stdctrls,uPSC_forms, uPSC_menus,
|
2010-05-22 10:07:35 -04:00
|
|
|
uPSC_extctrls, uPSC_mml, uPSC_dll, //Compile-libs
|
2010-01-25 08:59:44 -05:00
|
|
|
uPSUtils,
|
|
|
|
fontloader,
|
2010-02-05 14:20:35 -05:00
|
|
|
IOmanager,//TTarget_Exported
|
2010-01-28 18:34:03 -05:00
|
|
|
IniFiles,//Silly INI files
|
2010-02-25 20:02:41 -05:00
|
|
|
stringutil, //String st00f
|
2010-04-07 08:01:26 -04:00
|
|
|
|
2010-05-19 16:36:45 -04:00
|
|
|
uPSR_std, uPSR_controls,uPSR_classes,uPSR_graphics,uPSR_stdctrls,uPSR_forms, uPSR_mml,
|
2010-05-22 10:07:35 -04:00
|
|
|
uPSR_menus, uPSI_ComCtrls, uPSI_Dialogs, uPSR_dll,
|
2010-03-27 09:10:16 -04:00
|
|
|
files,
|
2010-05-19 10:01:01 -04:00
|
|
|
dtm, //Dtms!
|
2010-01-25 08:59:44 -05:00
|
|
|
uPSR_extctrls, //Runtime-libs
|
|
|
|
Graphics, //For Graphics types
|
|
|
|
math, //Maths!
|
2010-05-12 17:51:18 -04:00
|
|
|
mmath, //Real maths!
|
2010-01-25 08:59:44 -05:00
|
|
|
strutils,
|
2010-05-15 07:57:55 -04:00
|
|
|
fileutil,
|
2010-01-25 08:59:44 -05:00
|
|
|
tpa, //Tpa stuff
|
|
|
|
forms,//Forms
|
2010-04-21 18:01:19 -04:00
|
|
|
SynRegExpr,
|
2010-10-10 16:54:50 -04:00
|
|
|
lclintf, // for GetTickCount and others.
|
2010-10-22 06:07:13 -04:00
|
|
|
Clipbrd,
|
|
|
|
DCPcrypt2,
|
|
|
|
DCPhaval,
|
|
|
|
DCPmd4, DCPmd5,
|
|
|
|
DCPripemd128, DCPripemd160,
|
|
|
|
DCPsha1, DCPsha256, DCPsha512,
|
|
|
|
DCPtiger;
|
2010-01-28 18:34:03 -05:00
|
|
|
{$ifdef Linux}
|
2010-04-07 18:40:28 -04:00
|
|
|
{$define PS_SafeCall}
|
2010-01-28 18:34:03 -05:00
|
|
|
{$else}
|
2010-04-07 18:40:28 -04:00
|
|
|
//{$define PS_SafeCall}
|
2010-01-28 18:34:03 -05:00
|
|
|
{$endif}
|
2010-01-26 11:51:36 -05:00
|
|
|
{$MACRO ON}
|
2010-04-07 18:40:28 -04:00
|
|
|
{$ifdef PS_SafeCall}
|
2010-04-07 12:23:02 -04:00
|
|
|
{$define extdecl := safecall}
|
2010-04-07 18:40:28 -04:00
|
|
|
{$else}
|
|
|
|
{$define extdecl := register}
|
2010-01-26 11:51:36 -05:00
|
|
|
{$endif}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
|
|
|
{Some General PS Functions here}
|
2010-01-28 18:34:03 -05:00
|
|
|
procedure psWriteln(str : string); extdecl;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2010-10-04 11:06:22 -04:00
|
|
|
if Assigned(CurrThread) and CurrThread.Prop.WriteTimeStamp then
|
2010-03-19 19:12:43 -04:00
|
|
|
str := format('[%s]: %s', [TimeToStr(TimeStampToDateTime(MSecsToTimeStamp(GetTickCount - CurrThread.StartTime))), str]);
|
2010-10-04 11:06:22 -04:00
|
|
|
if Assigned(CurrThread) and Assigned(CurrThread.DebugTo) then
|
2010-01-25 08:59:44 -05:00
|
|
|
CurrThread.DebugTo(str)
|
|
|
|
else
|
2010-03-07 10:57:10 -05:00
|
|
|
mDebugLn(str);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-05-11 10:22:25 -04:00
|
|
|
procedure ps_DebugLn(str : string); extdecl;
|
|
|
|
begin
|
2010-10-04 11:10:05 -04:00
|
|
|
if Assigned(CurrThread) and CurrThread.Prop.WriteTimeStamp then
|
2010-05-11 10:22:25 -04:00
|
|
|
str := format('[%s]: %s', [TimeToStr(TimeStampToDateTime(MSecsToTimeStamp(GetTickCount - CurrThread.StartTime))), str]);
|
|
|
|
mDebugLn(str);
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
{***implementation TMThread***}
|
2010-01-26 17:58:41 -05:00
|
|
|
constructor TMThread.Create(CreateSuspended: boolean; TheSyncInfo: PSyncInfo; plugin_dir: string);
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
2010-03-25 11:21:21 -04:00
|
|
|
inherited Create(CreateSuspended);
|
2010-01-25 12:38:43 -05:00
|
|
|
Client := TClient.Create(plugin_dir);
|
2010-04-07 08:01:26 -04:00
|
|
|
if Assigned(WriteFileEvent) then
|
|
|
|
Client.MFiles.WriteFileEvent := WriteFileEvent;
|
|
|
|
if Assigned(OpenFileEvent) then
|
|
|
|
Client.MFiles.OpenFileEvent := OpenFileEvent;
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet := TMInternet.Create(Client);
|
2010-12-20 01:48:42 -05:00
|
|
|
Socks := TSocks.Create(Client);
|
2010-04-07 08:01:26 -04:00
|
|
|
if Assigned(OpenConnectionEvent) then
|
|
|
|
MInternet.OpenConnectionEvent := Self.OpenConnectionEvent;
|
2010-01-26 17:58:41 -05:00
|
|
|
SyncInfo:= TheSyncInfo;
|
2010-01-25 12:38:43 -05:00
|
|
|
ExportedMethods:= GetExportedMethods;
|
|
|
|
FreeOnTerminate := True;
|
2010-01-31 07:29:33 -05:00
|
|
|
CompileOnly := false;
|
2010-01-25 12:38:43 -05:00
|
|
|
OnTerminate := @OnThreadTerminate;
|
2010-01-26 20:50:17 -05:00
|
|
|
OnError:= nil;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes := TStringList.Create;
|
|
|
|
Includes.CaseSensitive:= {$ifdef linux}true{$else}false{$endif};
|
2010-03-25 08:37:52 -04:00
|
|
|
Sett := nil;
|
2010-03-19 19:12:43 -04:00
|
|
|
|
|
|
|
Prop := TScriptProperties.Create;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TMThread.Destroy;
|
|
|
|
begin
|
2010-02-13 11:56:46 -05:00
|
|
|
MInternet.Free;
|
2011-01-13 17:35:53 -05:00
|
|
|
Socks.Free;
|
2010-01-25 12:38:43 -05:00
|
|
|
Client.Free;
|
2010-02-26 11:59:05 -05:00
|
|
|
Includes.free;
|
2010-03-19 19:16:04 -04:00
|
|
|
Prop.Free;
|
2010-03-25 11:21:21 -04:00
|
|
|
if Sett <> nil then
|
|
|
|
Sett.Free;
|
2010-01-25 12:38:43 -05:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2010-04-07 08:01:26 -04:00
|
|
|
procedure TMThread.SetOpenConnectionEvent(const AValue: TOpenConnectionEvent);
|
|
|
|
begin
|
|
|
|
FOpenConnectionEvent:= AValue;
|
|
|
|
if Assigned(MInternet) then
|
|
|
|
self.MInternet.OpenConnectionEvent := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetOpenFileEvent(const AValue: TOpenFileEvent);
|
|
|
|
begin
|
|
|
|
FOpenFileEvent:= AValue;
|
|
|
|
if Assigned(Client) then
|
|
|
|
self.Client.MFiles.OpenFileEvent := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetWriteFileEvent(const AValue: TWriteFileEvent);
|
|
|
|
begin
|
|
|
|
FWriteFileEvent:= AValue;
|
|
|
|
if Assigned(Client) then
|
|
|
|
self.Client.MFiles.WriteFileEvent := AValue;;
|
|
|
|
end;
|
|
|
|
|
2010-08-17 19:22:03 -04:00
|
|
|
procedure TMThread.FormCallBackEx(cmd: integer; var data: pointer);
|
|
|
|
begin
|
|
|
|
if (CallBackData = nil) or not Assigned(CallBackData^.FormCallBack) then
|
|
|
|
exit;
|
|
|
|
CallBackData^.cmd:= cmd;
|
|
|
|
CallBackData^.data:= data;
|
|
|
|
Synchronize(CallBackData^.FormCallBack);
|
|
|
|
data := CallBackData^.data;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.FormCallBack(cmd: integer; data: pointer);
|
|
|
|
begin
|
|
|
|
if (CallBackData = nil) or (not Assigned(CallBackData^.FormCallBack)) then
|
|
|
|
exit;
|
|
|
|
CallBackData^.cmd:= cmd;
|
|
|
|
CallBackData^.data:= data;
|
|
|
|
Synchronize(CallBackData^.FormCallBack);
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
procedure TMThread.HandleError(ErrorRow,ErrorCol, ErrorPosition: integer; ErrorStr: string; ErrorType: TErrorType; ErrorModule : string);
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
if OnError = nil then
|
|
|
|
exit;
|
2010-05-13 06:14:33 -04:00
|
|
|
ErrorData^.Row:= ErrorRow - 1;
|
2010-02-26 11:59:05 -05:00
|
|
|
ErrorData^.Col := ErrorCol;
|
2010-01-25 12:38:43 -05:00
|
|
|
ErrorData^.Position:= ErrorPosition;
|
|
|
|
ErrorData^.Error:= ErrorStr;
|
|
|
|
ErrorData^.ErrType:= ErrorType;
|
|
|
|
ErrorData^.Module:= ErrorModule;
|
|
|
|
ErrorData^.IncludePath:= IncludePath;
|
2010-01-25 16:37:33 -05:00
|
|
|
CurrThread.Synchronize(OnError);
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.OnThreadTerminate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
procedure TMThread.AddMethod(meth: TExpMethod);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
function TMThread.LoadFile(ParentFile : string; var filename, contents: string): boolean;
|
2010-01-25 12:38:43 -05:00
|
|
|
var
|
|
|
|
path: string;
|
|
|
|
f: TFileStream;
|
|
|
|
begin
|
2010-02-26 11:59:05 -05:00
|
|
|
path := FindFile(filename,[includepath,ScriptPath,IncludeTrailingPathDelimiter(ExtractFileDir(parentfile))]);
|
|
|
|
if path = '' then
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
psWriteln(Path + ' doesn''t exist');
|
|
|
|
Result := false;
|
|
|
|
Exit;
|
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
filename := path;//Yeah!
|
2011-07-31 10:49:16 -04:00
|
|
|
|
|
|
|
if Includes.IndexOf(path) = -1 then
|
|
|
|
Includes.Add(path);
|
2010-02-26 11:59:05 -05:00
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
try
|
2010-05-23 05:55:27 -04:00
|
|
|
f:= TFileStream.Create(UTF8ToSys(Path), fmOpenRead);
|
2010-02-26 11:59:05 -05:00
|
|
|
SetLength(contents, f.Size);
|
|
|
|
f.Read(contents[1], Length(contents));
|
|
|
|
result:= true;
|
|
|
|
f.free;
|
2010-01-25 12:38:43 -05:00
|
|
|
except
|
|
|
|
Result := false;
|
2010-02-26 11:59:05 -05:00
|
|
|
psWriteln('ERROR in TMThread.LoadFile');
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
end;
|
|
|
|
|
2011-02-21 08:36:55 -05:00
|
|
|
function TMThread.ProcessDirective(Sender: TPSPreProcessor;
|
|
|
|
Parser: TPSPascalPreProcessorParser;
|
|
|
|
DirectiveName, DirectiveArgs: string; FileName: string): boolean;
|
2010-02-26 11:59:05 -05:00
|
|
|
var
|
2011-02-21 09:56:17 -05:00
|
|
|
plugin_idx: integer;
|
2011-02-21 08:36:55 -05:00
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
begin
|
2010-05-19 04:50:29 -04:00
|
|
|
Result := False;
|
2010-05-18 14:58:15 -04:00
|
|
|
if CompareText(DirectiveName,'LOADLIB') = 0 then
|
2010-02-26 11:59:05 -05:00
|
|
|
begin
|
|
|
|
if DirectiveArgs <> '' then
|
|
|
|
begin;
|
|
|
|
plugin_idx:= PluginsGlob.LoadPlugin(DirectiveArgs);
|
|
|
|
if plugin_idx < 0 then
|
|
|
|
psWriteln(Format('Your DLL %s has not been found',[DirectiveArgs]))
|
2010-05-19 04:50:29 -04:00
|
|
|
else
|
|
|
|
begin
|
2010-02-26 11:59:05 -05:00
|
|
|
LoadPlugin(plugin_idx);
|
2010-05-19 04:50:29 -04:00
|
|
|
Result:= True;
|
2010-02-26 11:59:05 -05:00
|
|
|
end;
|
2010-05-19 04:50:29 -04:00
|
|
|
end
|
|
|
|
else
|
2010-05-18 14:58:15 -04:00
|
|
|
psWriteln('Your LoadLib directive has no params, thus cannot find the plugin');
|
2010-05-19 04:50:29 -04:00
|
|
|
end
|
2011-02-21 09:03:42 -05:00
|
|
|
else if CompareText(DirectiveName,'WARNING') = 0 then
|
2010-02-26 11:59:05 -05:00
|
|
|
begin
|
2011-02-21 08:36:55 -05:00
|
|
|
if (sender = nil) or (parser = nil) then
|
|
|
|
begin
|
2011-02-21 09:03:42 -05:00
|
|
|
psWriteln('ERROR: WARNING directive not supported for this interpreter');
|
2011-02-21 08:36:55 -05:00
|
|
|
exit(False);
|
|
|
|
end;
|
|
|
|
|
2010-05-19 04:50:29 -04:00
|
|
|
if (DirectiveArgs <> '') then
|
2010-02-26 11:59:05 -05:00
|
|
|
begin
|
2011-02-21 08:36:55 -05:00
|
|
|
Result := True;
|
2011-02-21 09:03:42 -05:00
|
|
|
if FileName = '' then
|
|
|
|
psWriteln(format('Warning: In %s: at row: %d, col: %d, pos %d: %s',
|
|
|
|
['Main script', Parser.row, Parser.col,
|
|
|
|
Parser.pos, DirectiveArgs]))
|
|
|
|
else
|
|
|
|
psWriteln(format('Warning: In file %s: at row: %d, col: %d, pos %d: %s',
|
|
|
|
[FileName, Parser.row, Parser.col,
|
|
|
|
Parser.pos, DirectiveArgs]));
|
|
|
|
//HandleError(Parser.Row + 1, Parser.Col, Parser.Pos, 'Warning at ' + DirectiveArgs, errCompile, FileName);
|
|
|
|
end;
|
|
|
|
end else if CompareText(DirectiveName,'ERROR') = 0 then
|
|
|
|
begin
|
|
|
|
if (sender = nil) or (parser = nil) then
|
|
|
|
begin
|
|
|
|
psWriteln('ERROR: ERROR directive not supported for this interpreter');
|
|
|
|
exit(False);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (DirectiveArgs <> '') then
|
|
|
|
begin
|
|
|
|
Result := True;
|
2011-02-21 11:40:55 -05:00
|
|
|
{if FileName = '' then
|
2011-02-21 09:03:42 -05:00
|
|
|
psWriteln(format('Error: In %s: at row: %d, col: %d, pos %d: %s',
|
|
|
|
['Main script', Parser.row, Parser.col,
|
|
|
|
Parser.pos, DirectiveArgs]))
|
|
|
|
else
|
|
|
|
psWriteln(format('Error: In file %s: at row: %d, col: %d, pos %d: %s',
|
|
|
|
[FileName, Parser.row, Parser.col,
|
2011-02-21 11:40:55 -05:00
|
|
|
Parser.pos, DirectiveArgs])); }
|
|
|
|
HandleError(Parser.Row + 1, Parser.Col, Parser.Pos, 'Error: ' + DirectiveArgs, errCompile, FileName);
|
2011-02-21 09:03:42 -05:00
|
|
|
raise EPSPreProcessor.Create('ERROR directive found');
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
2010-02-26 11:59:05 -05:00
|
|
|
end else
|
2011-02-21 09:03:42 -05:00
|
|
|
Result := False; // If we do not know the directive; return true so Continue
|
2011-02-21 08:36:55 -05:00
|
|
|
// will be false.
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMThread.SetDebug(writelnProc: TWritelnProc);
|
|
|
|
begin
|
|
|
|
DebugTo := writelnProc;
|
2010-03-07 10:57:10 -05:00
|
|
|
Client.WritelnProc:= writelnProc;
|
2010-01-25 12:38:43 -05:00
|
|
|
end;
|
|
|
|
|
2010-07-09 05:36:44 -04:00
|
|
|
procedure TMThread.SetSettings(S: TMMLSettings; SimbaSetFile: String);
|
2010-03-25 08:37:52 -04:00
|
|
|
begin
|
2010-07-09 05:36:44 -04:00
|
|
|
Self.SimbaSettingsFile := SimbaSetFile;
|
|
|
|
Self.Settings := S;
|
|
|
|
Self.Sett := TMMLSettingsSandbox.Create(Self.Settings);
|
|
|
|
Self.Sett.prefix := 'Scripts/';
|
2010-03-25 08:37:52 -04:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TMThread.SetPaths(ScriptP, AppP,IncludeP,PluginP,FontP: string);
|
|
|
|
begin
|
|
|
|
AppPath:= AppP;
|
|
|
|
ScriptPath:= ScriptP;
|
|
|
|
IncludePath:= IncludeP;
|
|
|
|
PluginPath:= PluginP;
|
|
|
|
FontPath:= FontP;
|
|
|
|
end;
|
|
|
|
|
2010-02-26 11:59:05 -05:00
|
|
|
function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant; extdecl;
|
2010-01-25 16:37:33 -05:00
|
|
|
begin
|
2010-04-11 15:42:42 -04:00
|
|
|
if GetCurrentThreadId = MainThreadID then
|
|
|
|
begin
|
|
|
|
with TPSThread(currthread).PSScript do
|
|
|
|
Result := Exec.RunProcPVar(V,Exec.GetProc(Procname));
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
CurrThread.SyncInfo^.MethodName:= ProcName;
|
|
|
|
CurrThread.SyncInfo^.V:= @V;
|
|
|
|
CurrThread.SyncInfo^.OldThread := CurrThread;
|
|
|
|
CurrThread.SyncInfo^.Res := @Result;
|
|
|
|
CurrThread.Synchronize(CurrThread.SyncInfo^.SyncMethod);
|
|
|
|
end;
|
2010-01-25 16:37:33 -05:00
|
|
|
end;
|
|
|
|
|
2010-09-10 19:10:49 -04:00
|
|
|
function CallProc(ProcName: string; var V: TVariantArray): Variant; extdecl;
|
|
|
|
begin
|
|
|
|
with TPSThread(currthread).PSScript do
|
|
|
|
Result := Exec.RunProcPVar(V,Exec.GetProc(Procname));
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/other.inc}
|
2010-03-25 08:37:52 -04:00
|
|
|
{$I PSInc/Wrappers/settings.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/bitmap.inc}
|
|
|
|
{$I PSInc/Wrappers/window.inc}
|
2010-02-06 16:01:35 -05:00
|
|
|
{$I PSInc/Wrappers/tpa.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/strings.inc}
|
2010-10-22 06:07:13 -04:00
|
|
|
{$I PSInc/Wrappers/crypto.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/colour.inc}
|
2010-04-07 17:04:25 -04:00
|
|
|
{$I PSInc/Wrappers/colourconv.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
{$I PSInc/Wrappers/math.inc}
|
|
|
|
{$I PSInc/Wrappers/mouse.inc}
|
|
|
|
{$I PSInc/Wrappers/file.inc}
|
|
|
|
{$I PSInc/Wrappers/keyboard.inc}
|
|
|
|
{$I PSInc/Wrappers/dtm.inc}
|
|
|
|
{$I PSInc/Wrappers/ocr.inc}
|
|
|
|
{$I PSInc/Wrappers/internets.inc}
|
2010-09-11 10:30:39 -04:00
|
|
|
{$I PSInc/psmethods.inc}
|
2010-01-25 12:38:43 -05:00
|
|
|
|
|
|
|
class function TMThread.GetExportedMethods: TExpMethodArr;
|
|
|
|
var
|
|
|
|
c : integer;
|
|
|
|
CurrSection : string;
|
|
|
|
|
|
|
|
procedure SetCurrSection(str : string);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin;
|
2010-01-25 12:38:43 -05:00
|
|
|
CurrSection := Str;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure AddFunction( Ptr : Pointer; DeclStr : String);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin;
|
2010-12-18 14:35:27 -05:00
|
|
|
if c >= 500 then
|
2010-12-23 05:46:43 -05:00
|
|
|
raise exception.create('PSThread.LoadMethods: Exported more than 500 functions');
|
2010-01-25 12:38:43 -05:00
|
|
|
Result[c].FuncDecl:= DeclStr;
|
|
|
|
Result[c].FuncPtr:= Ptr;
|
|
|
|
Result[c].Section:= CurrSection;
|
|
|
|
inc(c);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
begin
|
|
|
|
c := 0;
|
|
|
|
CurrSection := 'Other';
|
2010-12-18 14:35:27 -05:00
|
|
|
SetLength(Result, 500);
|
2010-01-25 12:38:43 -05:00
|
|
|
|
|
|
|
{$i PSInc/psexportedmethods.inc}
|
|
|
|
|
|
|
|
SetLength(Result,c);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{***implementation TPSThread***}
|
2010-01-25 08:59:44 -05:00
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
constructor TPSThread.Create(CreateSuspended : boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2010-02-05 11:30:42 -05:00
|
|
|
var
|
|
|
|
I : integer;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2010-03-25 11:21:21 -04:00
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
2010-01-25 08:59:44 -05:00
|
|
|
PSScript := TPSScript.Create(nil);
|
|
|
|
PSScript.UsePreProcessor:= True;
|
2010-05-13 10:42:51 -04:00
|
|
|
PSScript.CompilerOptions := PSScript.CompilerOptions + [icBooleanShortCircuit];
|
2010-01-25 08:59:44 -05:00
|
|
|
PSScript.OnNeedFile := @RequireFile;
|
2011-07-31 10:49:16 -04:00
|
|
|
PSScript.OnIncludingFile := @OnIncludingFile;
|
2011-02-19 09:19:08 -05:00
|
|
|
PSScript.OnFileAlreadyIncluded := @FileAlreadyIncluded;
|
2010-01-25 08:59:44 -05:00
|
|
|
PSScript.OnProcessDirective:=@OnProcessDirective;
|
2011-02-21 08:36:55 -05:00
|
|
|
PSScript.OnProcessUnknowDirective:=@PSScriptProcessUnknownDirective;
|
2010-01-25 08:59:44 -05:00
|
|
|
PSScript.OnCompile:= @OnCompile;
|
|
|
|
PSScript.OnCompImport:= @OnCompImport;
|
|
|
|
PSScript.OnExecImport:= @OnExecImport;
|
2010-05-22 10:07:35 -04:00
|
|
|
PSScript.OnFindUnknownFile:= @PSScriptFindUnknownFile;
|
2010-05-20 04:08:54 -04:00
|
|
|
|
|
|
|
with PSScript do
|
|
|
|
begin
|
|
|
|
// Set some defines
|
|
|
|
{$I PSInc/psdefines.inc}
|
|
|
|
end;
|
|
|
|
|
2010-02-05 11:30:42 -05:00
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if pos('Writeln',exportedmethods[i].FuncDecl) > 0 then
|
|
|
|
begin
|
|
|
|
ExportedMethods[i].FuncPtr := nil;
|
|
|
|
break;
|
|
|
|
end;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
destructor TPSThread.Destroy;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
PSScript.Free;
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnProcessDirective(Sender: TPSPreProcessor;
|
2010-01-25 08:59:44 -05:00
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2011-02-21 08:36:55 -05:00
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean; Filename: String);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2011-02-21 09:03:42 -05:00
|
|
|
if (CompareText(DirectiveName, 'LOADLIB') = 0)
|
|
|
|
or (CompareText(DirectiveName, 'WARNING') = 0)
|
|
|
|
or (CompareText(DirectiveName, 'ERROR') = 0) then
|
2011-02-21 08:36:55 -05:00
|
|
|
Continue := not ProcessDirective(Sender, Parser, DirectiveName,DirectiveParam,
|
|
|
|
FileName);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
function TPSThread.PSScriptFindUnknownFile(Sender: TObject;
|
2010-01-25 08:59:44 -05:00
|
|
|
const OrginFileName: string; var FileName, Output: string): Boolean;
|
|
|
|
begin
|
2010-03-07 10:57:10 -05:00
|
|
|
mDebugLn(OrginFileName + '-' + Output + '-' + FileName);
|
2010-03-02 16:27:49 -05:00
|
|
|
Result := false;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2011-02-21 08:36:55 -05:00
|
|
|
procedure TPSThread.PSScriptProcessUnknownDirective(Sender: TPSPreProcessor;
|
2010-01-25 08:59:44 -05:00
|
|
|
Parser: TPSPascalPreProcessorParser; const Active: Boolean;
|
2011-02-21 08:36:55 -05:00
|
|
|
const DirectiveName, DirectiveParam: string; var Continue: Boolean;
|
|
|
|
Filename: string);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2011-02-21 08:36:55 -05:00
|
|
|
Continue:= not ProcessDirective(Sender, Parser, DirectiveName, DirectiveParam,
|
|
|
|
FileName);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-02-04 18:32:24 -05:00
|
|
|
function Muf_Conv_to_PS_Conv( conv : integer) : TDelphiCallingConvention;
|
|
|
|
begin
|
|
|
|
case conv of
|
|
|
|
cv_StdCall : result := cdStdCall;
|
|
|
|
cv_Register: result := cdRegister;
|
|
|
|
else
|
|
|
|
raise exception.createfmt('Unknown Calling Convention[%d]',[conv]);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure TPSThread.LoadPlugin(plugidx: integer);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
for i := High(PluginsToLoad) downto 0 do
|
|
|
|
if PluginsToLoad[i] = plugidx then
|
|
|
|
Exit;
|
|
|
|
SetLength(PluginsToLoad,Length(PluginsToLoad)+1);
|
|
|
|
PluginsToLoad[High(PluginsToLoad)]:= plugidx;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnCompile(Sender: TPSScript);
|
2010-01-25 08:59:44 -05:00
|
|
|
var
|
|
|
|
i,ii : integer;
|
|
|
|
Fonts : TMFonts;
|
|
|
|
begin
|
2010-04-04 18:35:49 -04:00
|
|
|
Fonts := Client.MOCR.Fonts;
|
2010-01-25 08:59:44 -05:00
|
|
|
for i := fonts.count - 1 downto 0 do
|
2010-03-27 08:12:06 -04:00
|
|
|
Sender.Comp.AddConstantN(Fonts[i].Name,'string').SetString(Fonts[i].Name);
|
2010-01-25 08:59:44 -05:00
|
|
|
|
2010-12-23 08:33:21 -05:00
|
|
|
for i := High(PluginsToLoad) downto 0 do
|
|
|
|
begin
|
|
|
|
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].TypesLen - 1 do
|
|
|
|
Sender.Comp.AddTypeS(PluginsGlob.MPlugins[PluginsToLoad[i]].Types[ii].TypeName,
|
|
|
|
PluginsGlob.MPlugins[PluginsToLoad[i]].Types[ii].TypeDef);
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
for ii := 0 to PluginsGlob.MPlugins[PluginsToLoad[i]].MethodLen - 1 do
|
2010-03-27 08:12:06 -04:00
|
|
|
Sender.AddFunctionEx(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncPtr,
|
2010-02-04 18:32:24 -05:00
|
|
|
PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncStr,
|
|
|
|
Muf_Conv_to_PS_Conv(PluginsGlob.MPlugins[PluginsToLoad[i]].Methods[ii].FuncConv));
|
2010-12-23 08:33:21 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
for i := 0 to high(VirtualKeys) do
|
2010-03-27 08:12:06 -04:00
|
|
|
Sender.Comp.AddConstantN(Format('VK_%S',[VirtualKeys[i].Str]),'Byte').SetInt(VirtualKeys[i].Key);
|
2010-01-25 08:59:44 -05:00
|
|
|
// Here we add all the Consts/Types to the engine.
|
|
|
|
|
|
|
|
//Export all the methods
|
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if ExportedMethods[i].FuncPtr <> nil then
|
2010-03-27 08:12:06 -04:00
|
|
|
Sender.AddFunctionEx(ExportedMethods[i].FuncPtr,ExportedMethods[i].FuncDecl,
|
2010-04-07 18:40:28 -04:00
|
|
|
{$ifdef PS_SafeCall}cdSafeCall{$else}cdRegister{$endif});
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
function TPSThread.RequireFile(Sender: TObject;
|
2010-01-25 08:59:44 -05:00
|
|
|
const OriginFileName: String; var FileName, OutPut: string): Boolean;
|
|
|
|
begin
|
2010-05-18 09:01:08 -04:00
|
|
|
Result := LoadFile(OriginFileName,FileName,OutPut);
|
|
|
|
|
2010-05-13 06:14:33 -04:00
|
|
|
if Result then
|
2010-05-18 09:01:08 -04:00
|
|
|
Output :=
|
|
|
|
'{$IFNDEF IS_INCLUDE}{$DEFINE IS_INCLUDE}{$DEFINE __REMOVE_IS_INCLUDE}{$ENDIF}' + LineEnding +
|
|
|
|
Output + LineEnding +
|
|
|
|
'{$IFDEF __REMOVE_IS_INCLUDE}{$UNDEF IS_INCLUDE}{$ENDIF}';
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2011-07-31 11:36:34 -04:00
|
|
|
function TPSThread.FileAlreadyIncluded(Sender: TObject; OrgFileName, FileName: string): Boolean;
|
2011-02-19 09:19:08 -05:00
|
|
|
var
|
|
|
|
path: string;
|
|
|
|
i: integer;
|
|
|
|
begin
|
2011-07-31 11:36:34 -04:00
|
|
|
path := FindFile(filename,[includepath,ScriptPath,IncludeTrailingPathDelimiter(ExtractFileDir(OrgFileName))]);
|
|
|
|
if path = '' then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
Exit;
|
|
|
|
end;
|
2011-07-31 10:49:16 -04:00
|
|
|
path := ExpandFileNameUTF8(path);
|
|
|
|
|
2011-02-19 09:19:08 -05:00
|
|
|
if (path <> '') then
|
2011-07-31 10:49:16 -04:00
|
|
|
if Includes.IndexOf(path) <> -1 then
|
2011-02-19 09:19:08 -05:00
|
|
|
begin
|
2011-07-26 15:44:01 -04:00
|
|
|
{$IFDEF SIMBA_VERBOSE}
|
2011-07-31 11:36:34 -04:00
|
|
|
writeln('Include_Once file already included:' + Path);
|
2011-07-26 15:44:01 -04:00
|
|
|
{$ENDIF}
|
|
|
|
Result := True;
|
|
|
|
Exit;
|
2011-02-19 09:19:08 -05:00
|
|
|
end;
|
2011-07-26 15:44:01 -04:00
|
|
|
|
2011-07-31 10:49:16 -04:00
|
|
|
{$IFDEF SIMBA_VERBOSE}
|
|
|
|
writeln('OnFileAlreadyIncluded, Adding: ' + path);
|
|
|
|
{$ENDIF}
|
2011-02-19 09:19:08 -05:00
|
|
|
Includes.Add(path);
|
2011-07-26 15:44:01 -04:00
|
|
|
Result := False;
|
2011-02-19 09:19:08 -05:00
|
|
|
end;
|
|
|
|
|
2011-07-31 11:36:34 -04:00
|
|
|
function TPSThread.OnIncludingFile(Sender: TObject; OrgFileName, FileName: string): Boolean;
|
2011-07-31 10:49:16 -04:00
|
|
|
var
|
|
|
|
path: string;
|
|
|
|
begin
|
2011-07-31 11:36:34 -04:00
|
|
|
path := FindFile(filename,[includepath,ScriptPath,IncludeTrailingPathDelimiter(ExtractFileDir(OrgFileName))]);
|
|
|
|
if path = '' then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
Exit;
|
|
|
|
end;
|
2011-07-31 10:49:16 -04:00
|
|
|
path := ExpandFileNameUTF8(path);
|
|
|
|
|
|
|
|
if Includes.IndexOf(path) = -1 then
|
|
|
|
begin
|
|
|
|
{$IFDEF SIMBA_VERBOSE}
|
|
|
|
writeln('OnIncludingFile, Adding: ' + path);
|
|
|
|
{$ENDIF}
|
|
|
|
Includes.Add(path);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := True; // Not used
|
|
|
|
end;
|
|
|
|
|
2010-05-19 10:01:01 -04:00
|
|
|
procedure SIRegister_Mufasa(cl: TPSPascalCompiler);
|
2010-05-07 08:45:17 -04:00
|
|
|
begin
|
2010-05-19 10:01:01 -04:00
|
|
|
SIRegister_MML(cl);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnCompImport(Sender: TObject; x: TPSPascalCompiler);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
SIRegister_Std(x);
|
|
|
|
SIRegister_Controls(x);
|
|
|
|
SIRegister_Classes(x, true);
|
|
|
|
SIRegister_Graphics(x, true);
|
|
|
|
SIRegister_stdctrls(x);
|
|
|
|
SIRegister_Forms(x);
|
|
|
|
SIRegister_ExtCtrls(x);
|
2010-03-25 06:57:55 -04:00
|
|
|
SIRegister_Menus(x);
|
2010-05-01 18:44:30 -04:00
|
|
|
SIRegister_ComCtrls(x);
|
|
|
|
SIRegister_Dialogs(x);
|
2010-07-09 05:36:44 -04:00
|
|
|
if self.settings <> nil then
|
|
|
|
begin
|
|
|
|
if lowercase(self.settings.GetKeyValueDefLoad('Settings/Interpreter/AllowSysCalls',
|
2010-07-09 06:07:08 -04:00
|
|
|
'False', Self.SimbaSettingsFile)) = 'true' then
|
2010-07-09 05:36:44 -04:00
|
|
|
begin
|
2010-07-09 06:07:08 -04:00
|
|
|
{ Can remove later }
|
|
|
|
psWriteln('Allowing API/SysCalls.');
|
2010-07-09 05:36:44 -04:00
|
|
|
RegisterDll_Compiletime(x);
|
|
|
|
end;
|
|
|
|
end;
|
2010-05-20 04:08:54 -04:00
|
|
|
|
|
|
|
with x do
|
|
|
|
begin
|
|
|
|
{$I PSInc/pscompile.inc}
|
|
|
|
end;
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
SIRegister_Mufasa(x);
|
|
|
|
with x.AddFunction('procedure writeln;').decl do
|
|
|
|
with AddParam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmIn;
|
|
|
|
end;
|
|
|
|
with x.AddFunction('function ToStr:string').decl do
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmIn;
|
|
|
|
end;
|
|
|
|
with x.AddFunction('procedure swap;').decl do
|
|
|
|
begin
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'x';
|
|
|
|
Mode:= pmInOut;
|
|
|
|
end;
|
|
|
|
with addparam do
|
|
|
|
begin
|
|
|
|
OrgName:= 'y';
|
|
|
|
Mode:= pmInOut;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-05-19 10:01:01 -04:00
|
|
|
function TMufasaBitmapCreate : TMufasaBitmap;
|
2011-02-21 08:36:55 -05:00
|
|
|
begin
|
2010-05-19 10:01:01 -04:00
|
|
|
result := TMufasaBitmap.Create;
|
|
|
|
CurrThread.Client.MBitmaps.AddBMP(result);
|
|
|
|
end;
|
2011-02-21 08:36:55 -05:00
|
|
|
|
|
|
|
procedure TMufasaBitmapFree(Self : TMufasaBitmap);
|
|
|
|
begin
|
|
|
|
CurrThread.Client.MBitmaps.FreeBMP(Self.Index);
|
|
|
|
end;
|
|
|
|
|
2010-05-19 10:01:01 -04:00
|
|
|
function TMufasaBitmapCopy(Self : TMufasaBitmap;const xs,ys,xe,ye : integer) : TMufasaBitmap;
|
|
|
|
begin
|
|
|
|
result := Self.Copy(xs,ys,xe,ye);
|
|
|
|
CurrThread.Client.MBitmaps.AddBMP(result);
|
|
|
|
end;
|
|
|
|
function TMDTMCreate : TMDTM;
|
|
|
|
begin
|
|
|
|
result := TMDTM.Create;
|
|
|
|
CurrThread.Client.MDTMs.AddDTM(result);
|
|
|
|
end;
|
|
|
|
procedure TMDTMFree(Self : TMDTM);
|
|
|
|
begin
|
|
|
|
CurrThread.Client.MDTMs.FreeDTM(self.Index);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure RIRegister_Mufasa(CL: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
RIRegister_MML(cl);
|
|
|
|
//Overwrites the default stuff
|
|
|
|
with cl.FindClass('TMufasaBitmap') do
|
|
|
|
begin
|
|
|
|
RegisterConstructor(@TMufasaBitmapCreate,'Create');
|
|
|
|
RegisterMethod(@TMufasaBitmapFree,'Free');
|
|
|
|
RegisterMethod(@TMufasaBitmapCopy,'Copy');
|
|
|
|
end;
|
|
|
|
With cl.FindClass('TMDTM') do
|
|
|
|
begin
|
|
|
|
RegisterConstructor(@TMDTMCreate,'Create');
|
|
|
|
RegisterMethod(@TMDTMFree,'Free');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OnExecImport(Sender: TObject; se: TPSExec;
|
2010-01-25 08:59:44 -05:00
|
|
|
x: TPSRuntimeClassImporter);
|
|
|
|
begin
|
|
|
|
RIRegister_Std(x);
|
|
|
|
RIRegister_Classes(x, True);
|
|
|
|
RIRegister_Controls(x);
|
|
|
|
RIRegister_Graphics(x, True);
|
|
|
|
RIRegister_stdctrls(x);
|
|
|
|
RIRegister_Forms(x);
|
|
|
|
RIRegister_ExtCtrls(x);
|
2010-03-25 06:57:55 -04:00
|
|
|
RIRegister_Menus(x);
|
2010-01-25 08:59:44 -05:00
|
|
|
RIRegister_Mufasa(x);
|
2010-05-01 18:44:30 -04:00
|
|
|
RIRegister_ComCtrls(x);
|
|
|
|
RIRegister_Dialogs(x);
|
2010-05-22 10:07:35 -04:00
|
|
|
RegisterDLLRuntime(se);
|
2010-01-25 08:59:44 -05:00
|
|
|
se.RegisterFunctionName('WRITELN',@Writeln_,nil,nil);
|
|
|
|
se.RegisterFunctionName('TOSTR',@ToStr_,nil,nil);
|
|
|
|
se.RegisterFunctionName('SWAP',@swap_,nil,nil);
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.OutputMessages;
|
2010-01-25 08:59:44 -05:00
|
|
|
var
|
|
|
|
l: Longint;
|
|
|
|
b: Boolean;
|
|
|
|
begin
|
|
|
|
b := False;
|
|
|
|
for l := 0 to PSScript.CompilerMessageCount - 1 do
|
|
|
|
begin
|
|
|
|
if (not b) and (PSScript.CompilerMessages[l] is TIFPSPascalCompilerError) then
|
|
|
|
begin
|
|
|
|
b := True;
|
|
|
|
if OnError <> nil then
|
|
|
|
with PSScript.CompilerMessages[l] do
|
2010-02-26 11:59:05 -05:00
|
|
|
HandleError(Row, Col, Pos, MessageToString,errCompile, ModuleName)
|
2010-01-25 08:59:44 -05:00
|
|
|
else
|
2010-05-13 06:26:38 -04:00
|
|
|
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row - 1));
|
2010-01-25 08:59:44 -05:00
|
|
|
end else
|
2010-05-13 06:26:38 -04:00
|
|
|
psWriteln(PSScript.CompilerErrorToStr(l) + ' at line ' + inttostr(PSScript.CompilerMessages[l].Row - 1));
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-04-10 08:34:24 -04:00
|
|
|
procedure TPSThread.HandleScriptTerminates;
|
|
|
|
var
|
|
|
|
I : integer;
|
|
|
|
begin
|
|
|
|
if (PSScript.Exec.ExceptionCode =ErNoError) and (SP_OnTerminate in Prop.Properties) then
|
|
|
|
begin;
|
|
|
|
for i := 0 to Prop.OnTerminateProcs.Count - 1 do
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
PSScript.ExecuteFunction([],Prop.OnTerminateProcs[i]);
|
|
|
|
finally
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.Execute;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
|
|
|
CurrThread := Self;
|
|
|
|
Starttime := lclintf.GetTickCount;
|
|
|
|
|
|
|
|
try
|
|
|
|
if PSScript.Compile then
|
|
|
|
begin
|
|
|
|
OutputMessages;
|
|
|
|
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
|
2010-01-31 07:29:33 -05:00
|
|
|
if CompileOnly then
|
|
|
|
exit;
|
2010-01-25 08:59:44 -05:00
|
|
|
// if not (ScriptState = SCompiling) then
|
|
|
|
if not PSScript.Execute then
|
2010-02-26 11:59:05 -05:00
|
|
|
HandleError(PSScript.ExecErrorRow,PSScript.ExecErrorCol,PSScript.ExecErrorPosition,PSScript.ExecErrorToString,
|
2010-01-25 08:59:44 -05:00
|
|
|
errRuntime, PSScript.ExecErrorFileName)
|
|
|
|
else
|
2010-04-10 08:34:24 -04:00
|
|
|
begin
|
|
|
|
HandleScriptTerminates;
|
2010-02-27 10:55:31 -05:00
|
|
|
psWriteln('Successfully executed.');
|
2010-04-10 08:34:24 -04:00
|
|
|
end;
|
2010-01-25 08:59:44 -05:00
|
|
|
end else
|
|
|
|
begin
|
|
|
|
OutputMessages;
|
2010-02-27 10:55:31 -05:00
|
|
|
psWriteln('Compiling failed.');
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
except
|
|
|
|
on E : Exception do
|
2010-03-07 10:57:10 -05:00
|
|
|
psWriteln('Exception in Script: ' + e.message);
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.Terminate;
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2010-01-25 12:38:43 -05:00
|
|
|
PSScript.Stop;
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-25 12:38:43 -05:00
|
|
|
procedure TPSThread.SetScript(script: string);
|
2010-01-25 08:59:44 -05:00
|
|
|
begin
|
2010-05-13 06:14:33 -04:00
|
|
|
PSScript.Script.Text:= LineEnding+Script; //A LineEnding to create space for future extra's in first line (defines?)
|
2010-01-25 08:59:44 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
{***implementation TCPThread***}
|
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
procedure LoadCPascal(plugin_dir: string);
|
|
|
|
begin
|
|
|
|
libcpascal:= LoadLibrary(PChar(plugin_dir + 'libcpascal' + {$ifdef LINUX} '.so' {$else} '.dll' {$endif}));
|
|
|
|
if libcpascal = 0 then
|
|
|
|
raise Exception.Create('CPascal library not found');
|
|
|
|
Pointer(interp_init):= GetProcAddress(libcpascal, PChar('interp_init'));
|
|
|
|
Pointer(interp_meth):= GetProcAddress(libcpascal, PChar('interp_meth'));
|
2010-02-05 14:24:27 -05:00
|
|
|
Pointer(interp_type):= GetProcAddress(libcpascal, PChar('interp_type'));
|
2010-01-28 01:01:07 -05:00
|
|
|
Pointer(interp_set):= GetProcAddress(libcpascal, PChar('interp_set'));
|
|
|
|
Pointer(interp_comp):= GetProcAddress(libcpascal, PChar('interp_comp'));
|
|
|
|
Pointer(interp_run):= GetProcAddress(libcpascal, PChar('interp_run'));
|
|
|
|
Pointer(interp_free):= GetProcAddress(libcpascal, PChar('interp_free'));
|
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
function Interpreter_Precompiler(name, args: PChar): boolean; stdcall;
|
2010-03-02 16:27:49 -05:00
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2011-02-21 08:36:55 -05:00
|
|
|
result:= CurrThread.ProcessDirective(nil, nil, name, args, '');
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
procedure Interpreter_ErrorHandler(line, pos: integer; err: PChar; runtime: boolean); stdcall;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
if runtime then
|
2010-02-26 11:59:05 -05:00
|
|
|
CurrThread.HandleError(line,-1,pos,err,errRuntime,'')
|
2010-01-27 10:52:58 -05:00
|
|
|
else
|
2010-02-26 11:59:05 -05:00
|
|
|
CurrThread.HandleError(line,-1,pos,err,errCompile,'')
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-28 01:01:07 -05:00
|
|
|
constructor TCPThread.Create(CreateSuspended: Boolean; TheSyncInfo : PSyncInfo; plugin_dir: string);
|
2011-02-21 09:56:17 -05:00
|
|
|
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-03-25 11:21:21 -04:00
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
2010-01-28 01:01:07 -05:00
|
|
|
if libcpascal = 0 then
|
|
|
|
LoadCPascal(plugin_dir);
|
2010-01-27 10:52:58 -05:00
|
|
|
instance:= interp_init(@Interpreter_Precompiler, @Interpreter_ErrorHandler);
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 10:52:58 -05:00
|
|
|
destructor TCPThread.Destroy;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
interp_free(instance);
|
|
|
|
inherited Destroy;
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.SetScript(script: string);
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 10:52:58 -05:00
|
|
|
interp_set(instance,PChar(script));
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.AddMethod(meth: TExpMethod);
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
interp_meth(instance,meth.FuncPtr,PChar(meth.FuncDecl));
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
|
|
|
|
2010-02-07 03:42:06 -05:00
|
|
|
procedure TCPThread.LoadPlugin(plugidx: integer);
|
|
|
|
var
|
|
|
|
i: integer;
|
|
|
|
begin
|
|
|
|
with PluginsGlob.MPlugins[plugidx] do
|
|
|
|
for i := 0 to MethodLen - 1 do
|
|
|
|
with Methods[i] do
|
|
|
|
begin
|
|
|
|
pswriteln(FuncStr);
|
|
|
|
interp_meth(self.instance,FuncPtr,PChar(FuncStr));
|
|
|
|
end;
|
|
|
|
pswriteln('done')
|
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.Execute;
|
2010-01-27 10:52:58 -05:00
|
|
|
var
|
2010-03-02 16:27:49 -05:00
|
|
|
i: integer;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
CurrThread := Self;
|
2010-01-27 10:52:58 -05:00
|
|
|
Starttime := GetTickCount;
|
2010-01-27 00:44:43 -05:00
|
|
|
psWriteln('Invoking CPascal Interpreter');
|
2010-02-07 03:42:06 -05:00
|
|
|
interp_type(self.instance,'type longword = integer;');
|
|
|
|
interp_type(self.instance,'type word = integer;');
|
|
|
|
interp_type(self.instance,'type longint = integer;');
|
|
|
|
interp_type(self.instance,'type pointer = integer;');
|
|
|
|
interp_type(self.instance,'type byte = integer;');
|
2010-02-05 14:24:27 -05:00
|
|
|
interp_type(self.instance,'type extended = real;');
|
2010-02-07 03:42:06 -05:00
|
|
|
interp_type(self.instance,'type tcolor = integer;');
|
|
|
|
|
|
|
|
interp_type(self.instance,'type TExtendedArray = array of extended;');
|
|
|
|
interp_type(self.instance,'type T2DExtendedArray = array of array of extended;');
|
|
|
|
interp_type(self.instance,'type TIntegerArray = array of integer;');
|
|
|
|
|
|
|
|
interp_type(self.instance,'type TBox = record X1,Y1,X2,Y2: integer; end;');
|
|
|
|
interp_type(self.instance,'type TPoint = record x,y: integer; end;');
|
|
|
|
interp_type(self.instance,'type TPointArray = array of TPoint;'); ;
|
|
|
|
interp_type(self.instance,'type T2DPointArray = array of array of TPoint;'); ;
|
|
|
|
interp_type(self.instance,'type TPointArrayArray = T2DPointArray;');
|
|
|
|
|
2010-04-10 07:36:09 -04:00
|
|
|
interp_type(self.instance,'type TTarget_Exported = record int1,int2,int3,int4,int5,int6,int7,int8,int9,int10,int11,int12,int13,int14, int15:integer; end;');
|
2010-02-07 03:42:06 -05:00
|
|
|
interp_type(self.instance,'type TMask = record White, Black : TPointArray; WhiteHi,BlackHi : integer; W,H : integer;end;');
|
|
|
|
interp_type(self.instance,'type TDTMPointDef = record x, y, Color, Tolerance, AreaSize, AreaShape: integer; end;');
|
|
|
|
interp_type(self.instance,'type TDTMPointDefArray = Array Of TDTMPointDef;');
|
|
|
|
interp_type(self.instance,'type TDTM = record MainPoint: TDTMPointDef; SubPoints: TDTMPointDefArray; end;');
|
|
|
|
interp_type(self.instance,'type pDTM = record l: Integer;p: TPointArray;c, t, asz, ash: TIntegerArray; bp: Array Of Boolean; n: String; end;');
|
|
|
|
|
2010-02-05 14:24:27 -05:00
|
|
|
|
|
|
|
for i := 0 to high(ExportedMethods) do
|
|
|
|
if ExportedMethods[i].FuncPtr <> nil then
|
|
|
|
with ExportedMethods[i] do
|
|
|
|
interp_meth(self.instance,FuncPtr,PChar(FuncDecl));
|
2010-01-27 10:52:58 -05:00
|
|
|
if interp_comp(instance) then
|
|
|
|
begin
|
|
|
|
psWriteln('Compiled Successfully in ' + IntToStr(GetTickCount - Starttime) + 'ms');
|
2010-01-31 07:29:33 -05:00
|
|
|
if CompileOnly then
|
|
|
|
exit;
|
2010-01-27 10:52:58 -05:00
|
|
|
if interp_run(instance) then
|
|
|
|
psWriteln('Executed Successfully')
|
|
|
|
else
|
|
|
|
psWriteln('Execution Failed');
|
|
|
|
end else
|
|
|
|
psWriteln('Compile Failed');
|
2010-01-26 17:58:41 -05:00
|
|
|
|
|
|
|
end;
|
|
|
|
|
2010-01-27 00:44:43 -05:00
|
|
|
procedure TCPThread.Terminate;
|
2010-01-26 17:58:41 -05:00
|
|
|
begin
|
2010-01-27 00:44:43 -05:00
|
|
|
raise Exception.Create('Stopping Interpreter not yet implemented');
|
2010-01-26 17:58:41 -05:00
|
|
|
end;
|
2010-01-25 08:59:44 -05:00
|
|
|
|
2010-08-20 11:21:04 -04:00
|
|
|
{ TRTThread }
|
2011-02-05 18:33:56 -05:00
|
|
|
{$IFDEF USE_RUTIS}
|
2010-08-20 11:21:04 -04:00
|
|
|
procedure TRTThread.RTOnWrite(s: String);
|
|
|
|
begin
|
|
|
|
psWriteln(s);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRTThread.RTOnError(s: String; ErrorType: TRutisErrorType);
|
|
|
|
begin
|
2010-08-20 11:55:03 -04:00
|
|
|
if ErrorType in [etRuntimeError,etCompilerError] then
|
|
|
|
psWriteln(s)
|
|
|
|
else
|
|
|
|
writeln(s);
|
2010-08-20 11:21:04 -04:00
|
|
|
end;
|
|
|
|
|
2010-09-10 19:10:49 -04:00
|
|
|
type
|
|
|
|
PBoolean = ^Boolean;
|
|
|
|
PStringArray = ^TStringArray;
|
|
|
|
PBmpMirrorStyle = ^TBmpMirrorStyle;
|
|
|
|
PPointArray = ^TPointArray;
|
|
|
|
P2DIntArray = ^T2DIntArray;
|
|
|
|
PCanvas = ^TCanvas;
|
|
|
|
P2DPointArray = ^T2DPointArray;
|
|
|
|
PMask = ^Tmask;
|
|
|
|
PBox = ^TBox;
|
|
|
|
PTarget_Exported = ^TTarget_Exported;
|
|
|
|
PIntegerArray = ^TIntegerArray;
|
|
|
|
PExtendedArray = ^TExtendedArray;
|
|
|
|
// PStrExtr = ^TStrExtr;
|
|
|
|
PReplaceFlags = ^TReplaceFlags;
|
|
|
|
PClickType = ^TClickType;
|
|
|
|
P2DExtendedArray = ^T2DExtendedArray;
|
|
|
|
PMDTM = ^TMDTM;
|
|
|
|
PSDTM = ^TSDTM;
|
|
|
|
|
|
|
|
{$I RTInc/other.inc}
|
|
|
|
{$I RTInc/settings.inc}
|
|
|
|
{$I RTInc/bitmap.inc}
|
|
|
|
{$I RTInc/window.inc}
|
|
|
|
{$I RTInc/tpa.inc}
|
|
|
|
{$I RTInc/strings.inc}
|
|
|
|
{$I RTInc/colour.inc}
|
|
|
|
{$I RTInc/colourconv.inc}
|
|
|
|
{$I RTInc/math.inc}
|
|
|
|
{$I RTInc/mouse.inc}
|
|
|
|
{$I RTInc/file.inc}
|
|
|
|
{$I RTInc/keyboard.inc}
|
|
|
|
{$I RTInc/dtm.inc}
|
|
|
|
{$I RTInc/ocr.inc}
|
|
|
|
{$I RTInc/internets.inc}
|
|
|
|
|
|
|
|
|
2010-08-20 11:21:04 -04:00
|
|
|
constructor TRTThread.Create(CreateSuspended: Boolean; TheSyncInfo: PSyncInfo;
|
|
|
|
plugin_dir: string);
|
2010-09-10 19:10:49 -04:00
|
|
|
var
|
|
|
|
RutisEngine : TRutisEngine;
|
2010-08-20 11:21:04 -04:00
|
|
|
begin
|
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
|
|
|
RUTIS := TRutisEngine.Create;
|
|
|
|
RUTIS.OnWrite:= @RTOnWrite;
|
|
|
|
RUTIS.OnError:= @RTOnError;
|
|
|
|
RUTIS.OptProcessTimer:= false;
|
2010-08-20 11:55:03 -04:00
|
|
|
RUTIS.Compiler.optArrayRangeCheck:= true;
|
2010-09-10 19:10:49 -04:00
|
|
|
RutisEngine := RUTIS;
|
|
|
|
{$I RTInc/rtexportedmethods.inc}
|
2010-08-20 11:21:04 -04:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TRTThread.Destroy;
|
|
|
|
begin
|
|
|
|
RUTIS.Free;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRTThread.SetScript(script: string);
|
|
|
|
begin
|
|
|
|
RUTIS.ScriptCode.Text:= Script;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRTThread.Execute;
|
|
|
|
begin
|
|
|
|
CurrThread := self;
|
|
|
|
Starttime := lclintf.GetTickCount;
|
|
|
|
try
|
|
|
|
RUTIS.Compile;
|
|
|
|
if not RUTIS.CompilerError then
|
|
|
|
begin
|
|
|
|
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
|
|
|
|
if CompileOnly then
|
|
|
|
exit;
|
|
|
|
RUTIS.Run;
|
|
|
|
end else
|
|
|
|
begin
|
2010-08-20 11:55:03 -04:00
|
|
|
CurrThread.HandleError(RUTIS.Error.ELine + 2,RUTIS.Error.EChrPos,-1,RUTIS.Error.Message,errCompile,'');
|
2010-08-20 11:21:04 -04:00
|
|
|
psWriteln('Compiling failed.');
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on E : Exception do
|
|
|
|
psWriteln('Exception in Script: ' + e.message);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TRTThread.Terminate;
|
|
|
|
begin
|
|
|
|
RUTIS.Stop;
|
|
|
|
end;
|
2011-02-05 18:33:56 -05:00
|
|
|
{$ENDIF}
|
2010-08-20 11:21:04 -04:00
|
|
|
|
2011-08-05 07:04:52 -04:00
|
|
|
{$IFDEF USE_LAPE}
|
|
|
|
{ TLPThread }
|
|
|
|
|
|
|
|
type
|
|
|
|
PBoolean = ^Boolean;
|
|
|
|
PStringArray = ^TStringArray;
|
|
|
|
PBmpMirrorStyle = ^TBmpMirrorStyle;
|
|
|
|
PPointArray = ^TPointArray;
|
|
|
|
P2DIntArray = ^T2DIntArray;
|
|
|
|
PCanvas = ^TCanvas;
|
|
|
|
P2DPointArray = ^T2DPointArray;
|
|
|
|
PMask = ^TMask;
|
|
|
|
PBox = ^TBox;
|
|
|
|
PTarget_Exported = ^TTarget_Exported;
|
|
|
|
PIntegerArray = ^TIntegerArray;
|
|
|
|
PExtendedArray = ^TExtendedArray;
|
|
|
|
PFont = ^TFont;
|
|
|
|
// PStrExtr = ^TStrExtr;
|
|
|
|
PReplaceFlags = ^TReplaceFlags;
|
|
|
|
PClickType = ^TClickType;
|
|
|
|
P2DExtendedArray = ^T2DExtendedArray;
|
|
|
|
PMDTM = ^TMDTM;
|
|
|
|
PMDTMPoint = ^TMDTMPoint;
|
|
|
|
PSDTM = ^TSDTM;
|
|
|
|
|
|
|
|
procedure lp_WriteLn(Params: PParamArray);
|
|
|
|
begin
|
|
|
|
psWriteLn(PlpString(Params^[0])^);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{$I LPInc/Wrappers/other.inc}
|
|
|
|
{$I LPInc/Wrappers/settings.inc}
|
|
|
|
{$I LPInc/Wrappers/bitmap.inc}
|
|
|
|
{$I LPInc/Wrappers/window.inc}
|
|
|
|
{$I LPInc/Wrappers/tpa.inc}
|
|
|
|
{$I LPInc/Wrappers/strings.inc}
|
|
|
|
{$I LPInc/Wrappers/colour.inc}
|
|
|
|
{$I LPInc/Wrappers/colourconv.inc}
|
|
|
|
{$I LPInc/Wrappers/crypto.inc}
|
|
|
|
{$I LPInc/Wrappers/math.inc}
|
|
|
|
{$I LPInc/Wrappers/mouse.inc}
|
|
|
|
{$I LPInc/Wrappers/file.inc}
|
|
|
|
{$I LPInc/Wrappers/keyboard.inc}
|
|
|
|
{$I LPInc/Wrappers/dtm.inc}
|
|
|
|
{.$I LPInc/Wrappers/extensions.inc} //Doesn't work for me!
|
|
|
|
{$I LPInc/Wrappers/ocr.inc}
|
|
|
|
{$I LPInc/Wrappers/internets.inc}
|
|
|
|
|
|
|
|
constructor TLPThread.Create(CreateSuspended: Boolean; TheSyncInfo: PSyncInfo; plugin_dir: string);
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
Fonts: TMFonts;
|
|
|
|
begin
|
|
|
|
inherited Create(CreateSuspended, TheSyncInfo, plugin_dir);
|
|
|
|
|
|
|
|
Parser := TLapeTokenizerString.Create('');
|
|
|
|
Compiler := TLapeCompiler.Create(Parser);
|
|
|
|
Compiler.OnFindFile := @OnFindFile;
|
|
|
|
Compiler.OnHandleDirective := @OnHandleDirective;
|
|
|
|
Fonts := Client.MOCR.Fonts;
|
|
|
|
with Compiler do
|
|
|
|
begin
|
|
|
|
addGlobalFunc('procedure _writeln; override;', @lp_WriteLn);
|
|
|
|
|
|
|
|
for I := Fonts.Count - 1 downto 0 do
|
|
|
|
addGlobalVar(Fonts[I].Name, Fonts[I].Name);
|
|
|
|
|
|
|
|
for I := 0 to High(VirtualKeys) do
|
|
|
|
addGlobalVar(VirtualKeys[I].Key, Format('VK_%S', [VirtualKeys[i].Str]));
|
|
|
|
|
|
|
|
{$I LPInc/lpdefines.inc}
|
|
|
|
{$I LPInc/lpcompile.inc}
|
|
|
|
|
|
|
|
{$I LPInc/lpexportedmethods.inc}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TLPThread.Destroy;
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
{if (Compiler <> nil) then
|
|
|
|
Compiler.Free;}
|
|
|
|
|
|
|
|
if (Parser <> nil) then
|
|
|
|
Parser.Free;
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
psWriteln('Exception TLPThread.Destroy: ' + e.message);
|
|
|
|
end;
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLPThread.SetScript(Script: string);
|
|
|
|
begin
|
|
|
|
Parser.Doc := Script;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TLPThread.OnFindFile(Sender: TLapeCompiler; var FileName: lpString): TLapeTokenizerBase;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
FileName := IncludePath + FileName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TLPThread.OnHandleDirective(Sender: TLapeCompiler; Directive, Argument: lpString; InPeek: Boolean): Boolean;
|
|
|
|
var
|
|
|
|
plugin_idx: integer;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
if (Directive = 'loadlib') then
|
|
|
|
begin
|
|
|
|
if (Argument <> '') then
|
|
|
|
begin
|
|
|
|
plugin_idx := PluginsGlob.LoadPlugin(Argument);
|
|
|
|
if (plugin_idx >= 0) then
|
|
|
|
begin
|
|
|
|
LoadPlugin(plugin_idx);
|
|
|
|
Result := True;
|
|
|
|
end else
|
|
|
|
psWriteln(Format('Your DLL %s has not been found', [Argument]))
|
|
|
|
end else
|
|
|
|
psWriteln('Your LoadLib directive has no params, thus cannot find the plugin');
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLPThread.LoadPlugin(plugidx: integer);
|
|
|
|
var
|
|
|
|
I: integer;
|
|
|
|
begin
|
|
|
|
with PluginsGlob.MPlugins[plugidx] do
|
|
|
|
begin
|
|
|
|
for i := 0 to TypesLen -1 do
|
|
|
|
with Types[I] do
|
|
|
|
Compiler.addGlobalType(TypeDef, TypeName);
|
|
|
|
|
|
|
|
for i := 0 to MethodLen - 1 do
|
|
|
|
with Methods[i] do
|
|
|
|
Compiler.addGlobalFunc(FuncStr, FuncPtr);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLPThread.Execute;
|
|
|
|
function CombineDeclArray(a, b: TLapeDeclArray): TLapeDeclArray;
|
|
|
|
var
|
|
|
|
i, l: Integer;
|
|
|
|
begin
|
|
|
|
Result := a;
|
|
|
|
l := Length(a);
|
|
|
|
SetLength(Result, l + Length(b));
|
|
|
|
for i := High(b) downto 0 do
|
|
|
|
Result[l + i] := b[i];
|
|
|
|
end;
|
|
|
|
begin
|
|
|
|
CurrThread := self;
|
|
|
|
try
|
|
|
|
Starttime := lclintf.GetTickCount;
|
|
|
|
if Compiler.Compile() then
|
|
|
|
begin
|
|
|
|
psWriteln('Compiled succesfully in ' + IntToStr(GetTickCount - Starttime) + ' ms.');
|
|
|
|
if CompileOnly then
|
|
|
|
Exit;
|
|
|
|
RunCode(Compiler.Emitter.Code);
|
|
|
|
psWriteln('Successfully executed.');
|
|
|
|
end else
|
|
|
|
psWriteln('Compiling failed.');
|
|
|
|
except
|
|
|
|
on E : Exception do
|
|
|
|
psWriteln('Exception in Script: ' + e.message);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TLPThread.Terminate;
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2010-01-25 08:59:44 -05:00
|
|
|
initialization
|
|
|
|
PluginsGlob := TMPlugins.Create;
|
2010-01-28 01:01:07 -05:00
|
|
|
libcpascal:= 0;
|
2010-01-25 08:59:44 -05:00
|
|
|
finalization
|
|
|
|
//PluginsGlob.Free;
|
|
|
|
//Its a nice idea, but it will segfault... the program is closing anyway.
|
|
|
|
end.
|