unit TariffCalculator; {$mode ObjFPC}{$H+} interface uses SysUtils, CTypes, fpjson, jsonparser; type // Can't use the class directly, so it is treated as an opaque handle. // THandle is guaranteed to have the right size, even on other platforms. TariffCalculatorHandle = THandle; PTJSONObject = ^TJSONObject; function NewTariffCalculator: TariffCalculatorHandle; stdcall; procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; function GetFileMenu(const localRepository: PChar): PChar; stdcall; function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; function GetFileNameStr(const localRepository: String; const fileId: String): String; function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; procedure DeleteMem(P: PChar); stdcall; function InitGitLibrary: cint32; stdcall; function ShutdownGitLibrary: cint32; stdcall; function CloneRepository(var url; var local_path) : cint32; stdcall; function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; function CommitFile(var local_path; var branch_name; var file_name; var comment) : cint32; stdcall; function PushLocalRepository(var local_path; var branch_name; var user_name; var password) : cint32; stdcall; implementation const DLLName = 'CalculatorCInterface.dll'; function GetFileNameStr(const localRepository: String; const fileId: String): String; var p: PChar; begin Result := ''; try p := GetFileName(PChar(localRepository), PChar(fileId)); if p <> nil then begin Result := String(p); end; finally DeleteMem(p); end; end; function GetFileMenuAsJson(const localRepository: String; jObj: PTJSONObject): Boolean; var p: PChar; fileMenuContent: String; begin Result := false; try p := GetFileMenu(PChar(localRepository)); if p <> nil then begin fileMenuContent := String(p); writeln(fileMenuContent); jObj^ := GetJSON(fileMenuContent) as TJSONObject; Result := true; end; finally DeleteMem(p); end; end; function NewTariffCalculator: TariffCalculatorHandle; stdcall; external DLLName; procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; external DLLName; function GetFileMenu(const localRepository: PChar): PChar; stdcall; external DLLName; function GetFileMenuSize(const localRepository: PChar): cint32; stdcall; external DLLName; function GetFileName(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; function GetFileSize(const localRepository: PChar; const fileId: PChar): cint32; stdcall; external DLLName; function GetFile(const localRepository: PChar; const fileId: PChar): PChar; stdcall; external DLLName; procedure DeleteMem(P: PChar); stdcall; external DLLName; function InitGitLibrary: cint32; stdcall; external DLLName; function ShutdownGitLibrary: cint32; stdcall; external DLLName; function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName; function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName; function CommitFile(var local_path; var branch_name; var file_name; var comment) : cint32; stdcall; external DLLName; function PushLocalRepository(var local_path; var branch_name; var user_name; var password) : cint32; stdcall; external DLLName; end.