library PascalLookup;
{$mode objfpc}{$H+}
{$R *.res}
uses
Classes,
fileutil,
Windows,
sysutils,
xquery, PUCU, internetaccess, w32internetaccess;
//Ez keresi meg az Application Data mappát
function GetAppdataFolder: string;
begin
Result := GetEnvironmentVariable('APPDATA');
end;
//Ennek nincs szerepe a jelenlegi Implementációban
function Initialize(): Longint; cdecl;
begin
Initialize := 0;
end;
//Ennek nincs szerepe a jelenlegi Implementációban
function DeInitialize(): Longint; cdecl;
begin
DeInitialize := 0;
end;
//Ennek nincs szerepe a jelenlegi JAWS Implementációban
function GetInterfaceSchema(var dwSchema: LongWord): Longint; cdecl;
begin
dwSchema := 12;
GetInterfaceSchema := 12;
end;
var
namelist, filename, rulefolder: WideString;
filestring: string;
firstloop: Boolean;
filenamelist: TStringList;
rulefile: TextFile;
namepos, i: Integer;
//Ez írja ki a modulok nevét
function GetFriendlyName(lpszOut: LPWSTR; var dwSize: LongWord): LongWord; cdecl;
begin
rulefolder := 'C:\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\'; //GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\';
filenamelist := TStringList.Create();
FindAllFiles(filenamelist, rulefolder, '*.rul', true);
firstloop := true;
i:=0;
while i < filenamelist.Count do
begin
filename := filenamelist[i];
if(firstloop = false) then
namelist := namelist+'|'
else
firstloop := false;
namelist := namelist+copy(filename, Length(rulefolder)+1, Length(filename)-Length(rulefolder)-4);
//Delete(namelist,Length(namelist)-2,3); //to remove the extension from the name
namelist := namelist+':';
filestring:= ReadFileToString(filename); //I SHOULD PROBABLY GO BACK TO USING READLN
//readln(rulefile, ruleline); //USE POS LIKE THIS: s:='note-book';
//x:=pos('book',s); {x will be 6}
namepos :=pos('FriendlyName=',filestring);
if namepos<>0 then //the line exists
begin
filestring:=copy(filestring,namepos+13,Length(filestring)-namepos-13); //get everything from the start of the Friendlyname value
SetCodePage(RawByteString(filestring), 1252, false);//So utf8 characters work
namelist := namelist + copy(filestring,1,pos(sLineBreak, filestring)-1); //add everything from the value to the next linebreak
end;
i:= i+1;
end;
filenamelist.Free();
namelist := 'hello:Hello|plswork:illwork|thxdud:noprob|thisistheplace:a'+filenamelist[1];
if dwSize >Length(namelist) then
strCopy(lpszOut,PWideChar(namelist))
else
begin
dwSize := Length(namelist)+1;
result := $802A0001
end;
result := 0;
end;
var description, descfilestring: string;
plsmukodj: PWideChar;
descpos: Integer;
//Ez írja ki a modul leírását
function Describe(const lpszRuleSet: LPCWSTR; lpszOut: LPWSTR; var dwSize: DWord): LongWord; cdecl;
begin
rulefolder := GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\';
descfilestring:= ReadFileToString(rulefolder+lpszRuleSet+'.rul'); //I SHOULD PROBABLY GO BACK TO USING READLN
//USE POS LIKE THIS: s:='note-book';
//x:=pos('book',s); {x will be 6}
descpos :=pos('Description=',descfilestring);
if descpos<>0 then //the line exists
begin
descfilestring:=copy(descfilestring,descpos+12,Length(descfilestring)-descpos-12); //get everything from the start of the Description value
SetCodePage(RawByteString(descfilestring), 65001, false);//So utf8 characters work
description := copy(descfilestring,1,pos(sLineBreak, descfilestring)-1); //add everything from the value to the next linebreak
end;
SetCodePage(RawByteString(description), 1252, false);
if dwSize >Length(description) then
begin
strCopy(lpszOut,PWideChar(WideString(description)));
result := 0
end
else
begin
dwSize := Length(description)+1;
result := $802A0001
end;
end;
var
queryresult, querysource, fsi, infoalap: string;
engine: TXQueryEngine;
//Ez fut le amikor ténylegesen be kell töltenie a szöveget a modulnak
function Invoke(const lpszRuleSet: LPCWSTR; const lpszIn: LPCWSTR; const lpszContext: LPCWSTR; dwOffset: LongWord; lcidAppLocale: LongWord; lpszOut: LPWSTR; var dwSize: LongWord; lpExtra: Pointer): LongWord; cdecl;
begin
defaultInternetAccessClass := TW32InternetAccess;
querysource := ReadFileToString(GetAppdataFolder()+'\Freedom Scientific\JAWS\2022\Settings\hun\RuleSets\'+lpszRuleSet+'.qry');
SetCodePage(RawByteString(querysource), 1252, false);
fsi := ReadFileToString('c:\Program Files\Freedom Scientific\JAWS\2022\LookupModules\ResearchItLibrary.jri');
SetCodePage(RawByteString(fsi), 1252, false);
infoalap := ReadFileToString('c:\Program Files\Freedom Scientific\JAWS\2022\LookupModules\InfoalapResearchIt.jri');
SetCodePage(RawByteString(fsi), 1252, false);
engine := defaultQueryEngine();
//engine.StaticContext.baseURI := 'c:\"Program Files"\"Freedom Scientific"\JAWS\2022\LookupModules\';
engine.registerModule(engine.parseQuery(fsi)); //Regisztráljuk a modulokat
engine.registerModule(engine.parseQuery(infoalap));
engine.VariableChangelog.add('inputvar',lpszIn);//A keresési szót is regisztráljuk inputvar néven
queryresult := engine.evaluateXQuery(WideString(querysource)).toXQuery(); //https://www.benibela.de/documentation/internettools/xquery.html#defaultQueryEngine
SetCodePage(RawByteString(queryresult), 65001, false);
if dwSize >Length(queryresult)+1 then
begin
strCopy(lpszOut,PWideChar(WideString(queryresult)));
result := 0
end
else
begin
dwSize := Length(queryresult)+2;
result := $802A0001
end;
end;
exports
Initialize,
DeInitialize,
GetInterfaceSchema,
GetFriendlyName,
Describe,
Invoke;
end.