[CEdit, FB2 Reader]: optimize import

git-svn-id: svn://kolibrios.org@9645 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Anton Krotov 2022-01-16 07:18:30 +00:00
parent 361657b326
commit e2efa4256f
9 changed files with 91 additions and 215 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
(* (*
BSD 2-Clause License BSD 2-Clause License
Copyright (c) 2018, 2020-2021, Anton Krotov Copyright (c) 2018, 2020-2022, Anton Krotov
All rights reserved. All rights reserved.
*) *)
@ -36,7 +36,7 @@ VAR
CriticalSection: CRITICAL_SECTION; CriticalSection: CRITICAL_SECTION;
_import*, multi: BOOLEAN; multi: BOOLEAN;
base*: INTEGER; base*: INTEGER;
@ -226,19 +226,6 @@ BEGIN
END exit_thread; END exit_thread;
PROCEDURE OutChar (c: CHAR);
BEGIN
K.sysfunc3(63, 1, ORD(c))
END OutChar;
PROCEDURE OutLn;
BEGIN
OutChar(0DX);
OutChar(0AX)
END OutLn;
PROCEDURE OutStr (pchar: INTEGER); PROCEDURE OutStr (pchar: INTEGER);
VAR VAR
c: CHAR; c: CHAR;
@ -247,7 +234,7 @@ BEGIN
REPEAT REPEAT
SYSTEM.GET(pchar, c); SYSTEM.GET(pchar, c);
IF c # 0X THEN IF c # 0X THEN
OutChar(c) K.OutChar(c)
END; END;
INC(pchar) INC(pchar)
UNTIL c = 0X UNTIL c = 0X
@ -258,54 +245,25 @@ END OutStr;
PROCEDURE DebugMsg* (lpText, lpCaption: INTEGER); PROCEDURE DebugMsg* (lpText, lpCaption: INTEGER);
BEGIN BEGIN
IF lpCaption # 0 THEN IF lpCaption # 0 THEN
OutLn; K.OutLn;
OutStr(lpCaption); OutStr(lpCaption);
OutChar(":"); K.OutChar(":");
OutLn K.OutLn
END; END;
OutStr(lpText); OutStr(lpText);
IF lpCaption # 0 THEN IF lpCaption # 0 THEN
OutLn K.OutLn
END END
END DebugMsg; END DebugMsg;
PROCEDURE OutString (s: ARRAY OF CHAR);
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE (i < LEN(s)) & (s[i] # 0X) DO
OutChar(s[i]);
INC(i)
END
END OutString;
PROCEDURE imp_error;
BEGIN
OutString("import error: ");
IF K.imp_error.error = 1 THEN
OutString("can't load '"); OutString(K.imp_error.lib)
ELSIF K.imp_error.error = 2 THEN
OutString("not found '"); OutString(K.imp_error.proc); OutString("' in '"); OutString(K.imp_error.lib)
END;
OutString("'");
OutLn
END imp_error;
PROCEDURE init* (import_, code: INTEGER); PROCEDURE init* (import_, code: INTEGER);
BEGIN BEGIN
multi := FALSE; multi := FALSE;
base := code - SizeOfHeader; base := code - SizeOfHeader;
K.sysfunc2(68, 11); K.sysfunc2(68, 11);
InitializeCriticalSection(CriticalSection); InitializeCriticalSection(CriticalSection);
K._init; K._init(import_)
_import := (K.dll_Load(import_) = 0) & (K.imp_error.error = 0);
IF ~_import THEN
imp_error
END
END init; END init;

View File

@ -28,7 +28,7 @@ IMPORT
RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar; RW, Ini, EB := EditBox, Tabs, Toolbar, SB := StatusBar;
CONST CONST
HEADER = "CEdit (13-jan-2022)"; HEADER = "CEdit (16-jan-2022)";
ShellFilter = ""; ShellFilter = "";
EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON"; EditFilter = "SH|INC|TXT|ASM|OB07|C|CPP|H|PAS|PP|LUA|INI|JSON";

View File

@ -49,13 +49,10 @@ TYPE
END; END;
VAR PROCEDURE [stdcall, "box_lib.obj", "edit_box_draw"] draw* (eb: tEditBox); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_mouse"] mouse* (eb: tEditBox); END;
draw *: PROCEDURE (eb: tEditBox); PROCEDURE [stdcall, "box_lib.obj", "edit_box_set_text"] _setValue (eb: tEditBox; text: INTEGER); END;
mouse *: PROCEDURE (eb: tEditBox); PROCEDURE [stdcall, "box_lib.obj", "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
_setValue : PROCEDURE (eb: tEditBox; text: INTEGER);
key *: PROCEDURE (eb: tEditBox; key: INTEGER);
PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR); PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR);
VAR VAR
@ -108,29 +105,4 @@ BEGIN
END create; END create;
PROCEDURE GetProc (Lib, v: INTEGER; name: ARRAY OF CHAR);
VAR
a: INTEGER;
BEGIN
a := KOSAPI.GetProcAdr(name, Lib);
ASSERT(a # 0);
SYSTEM.PUT(v, a)
END GetProc;
PROCEDURE main;
VAR
Lib: INTEGER;
BEGIN
Lib := KOSAPI.LoadLib("/sys/lib/box_lib.obj");
ASSERT(Lib # 0);
GetProc(Lib, SYSTEM.ADR(draw), "edit_box_draw");
GetProc(Lib, SYSTEM.ADR(key), "edit_box_key_safe");
GetProc(Lib, SYSTEM.ADR(mouse), "edit_box_mouse");
GetProc(Lib, SYSTEM.ADR(_setValue), "edit_box_set_text");
END main;
BEGIN
main
END EditBox. END EditBox.

View File

@ -21,7 +21,7 @@ MODULE Ini;
IMPORT IMPORT
KOSAPI, SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS, Lines; SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS, Lines;
CONST CONST
@ -46,10 +46,6 @@ TYPE
VAR VAR
get_color, get_int: PROCEDURE [stdcall] (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER;
get_str: PROCEDURE [stdcall] (f_name, sec_name, key_name, buffer, buf_len, def_val: INTEGER): INTEGER;
enum_sections: PROCEDURE [stdcall] (f_name: RW.tFileName; callback: INTEGER);
IniFileName: RW.tFileName; IniFileName: RW.tFileName;
sections*: List.tList; sections*: List.tList;
@ -58,6 +54,11 @@ VAR
blink*: INTEGER; blink*: INTEGER;
PROCEDURE [stdcall, "libini.obj", "ini_get_color"] get_color (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libini.obj", "ini_get_int"] get_int (f_name: RW.tFileName; sec_name: tASCIISectionName; key_name: tString; def_val: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libini.obj", "ini_get_str"] get_str (f_name, sec_name, key_name, buffer, buf_len, def_val: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libini.obj", "ini_enum_sections"] enum_sections (f_name: RW.tFileName; callback: INTEGER); END;
PROCEDURE getColor (key: tString; def: INTEGER): INTEGER; PROCEDURE getColor (key: tString; def: INTEGER): INTEGER;
RETURN get_color(IniFileName, curSection, key, def) RETURN get_color(IniFileName, curSection, key, def)
END getColor; END getColor;
@ -158,18 +159,6 @@ END getSettings;
PROCEDURE load* (path: RW.tFileName); PROCEDURE load* (path: RW.tFileName);
VAR
Lib: INTEGER;
PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
VAR
a: INTEGER;
BEGIN
a := KOSAPI.GetProcAdr(name, Lib);
ASSERT(a # 0);
SYSTEM.PUT(v, a)
END GetProc;
BEGIN BEGIN
sections := List.create(NIL); sections := List.create(NIL);
@ -181,12 +170,6 @@ BEGIN
IniFileName := "/sys/settings/cedit.ini" IniFileName := "/sys/settings/cedit.ini"
END; END;
Lib := KOSAPI.LoadLib("/sys/Lib/Libini.obj");
GetProc(Lib, SYSTEM.ADR(get_color), "ini_get_color");
GetProc(Lib, SYSTEM.ADR(get_int), "ini_get_int");
GetProc(Lib, SYSTEM.ADR(get_str), "ini_get_str");
GetProc(Lib, SYSTEM.ADR(enum_sections), "ini_enum_sections");
enum_sections(IniFileName, SYSTEM.ADR(section_callback)); enum_sections(IniFileName, SYSTEM.ADR(section_callback));
Languages.init(getStr); Languages.init(getStr);
selectSection(0); selectSection(0);

View File

@ -19,13 +19,6 @@ VAR
DLL_INIT: PROCEDURE [stdcall] (entry: INTEGER); DLL_INIT: PROCEDURE [stdcall] (entry: INTEGER);
imp_error*: RECORD
proc*, lib*: STRING;
error*: INTEGER
END;
PROCEDURE [stdcall-] sysfunc1* (arg1: INTEGER): INTEGER; PROCEDURE [stdcall-] sysfunc1* (arg1: INTEGER): INTEGER;
BEGIN BEGIN
@ -176,7 +169,6 @@ END sysfunc22;
PROCEDURE mem_commit (adr, size: INTEGER); PROCEDURE mem_commit (adr, size: INTEGER);
VAR VAR
tmp: INTEGER; tmp: INTEGER;
BEGIN BEGIN
FOR tmp := adr TO adr + size - 1 BY 4096 DO FOR tmp := adr TO adr + size - 1 BY 4096 DO
SYSTEM.PUT(tmp, 0) SYSTEM.PUT(tmp, 0)
@ -187,7 +179,6 @@ END mem_commit;
PROCEDURE [stdcall] malloc* (size: INTEGER): INTEGER; PROCEDURE [stdcall] malloc* (size: INTEGER): INTEGER;
VAR VAR
ptr: INTEGER; ptr: INTEGER;
BEGIN BEGIN
SYSTEM.CODE(060H); (* pusha *) SYSTEM.CODE(060H); (* pusha *)
IF sysfunc2(18, 16) > ASR(size, 10) THEN IF sysfunc2(18, 16) > ASR(size, 10) THEN
@ -227,7 +218,6 @@ PROCEDURE AppAdr (): INTEGER;
VAR VAR
buf: ARRAY 1024 OF CHAR; buf: ARRAY 1024 OF CHAR;
a: INTEGER; a: INTEGER;
BEGIN BEGIN
a := sysfunc3(9, SYSTEM.ADR(buf), -1); a := sysfunc3(9, SYSTEM.ADR(buf), -1);
SYSTEM.GET(SYSTEM.ADR(buf) + 22, a) SYSTEM.GET(SYSTEM.ADR(buf) + 22, a)
@ -238,7 +228,6 @@ END AppAdr;
PROCEDURE GetCommandLine* (): INTEGER; PROCEDURE GetCommandLine* (): INTEGER;
VAR VAR
param: INTEGER; param: INTEGER;
BEGIN BEGIN
SYSTEM.GET(28 + AppAdr(), param) SYSTEM.GET(28 + AppAdr(), param)
RETURN param RETURN param
@ -248,7 +237,6 @@ END GetCommandLine;
PROCEDURE GetName* (): INTEGER; PROCEDURE GetName* (): INTEGER;
VAR VAR
name: INTEGER; name: INTEGER;
BEGIN BEGIN
SYSTEM.GET(32 + AppAdr(), name) SYSTEM.GET(32 + AppAdr(), name)
RETURN name RETURN name
@ -276,11 +264,9 @@ PROCEDURE GetProcAdr* (name: ARRAY OF CHAR; lib: INTEGER): INTEGER;
VAR VAR
cur, procname, adr: INTEGER; cur, procname, adr: INTEGER;
PROCEDURE streq (str1, str2: INTEGER): BOOLEAN; PROCEDURE streq (str1, str2: INTEGER): BOOLEAN;
VAR VAR
c1, c2: CHAR; c1, c2: CHAR;
BEGIN BEGIN
REPEAT REPEAT
SYSTEM.GET(str1, c1); SYSTEM.GET(str1, c1);
@ -292,7 +278,6 @@ VAR
RETURN c1 = c2 RETURN c1 = c2
END streq; END streq;
BEGIN BEGIN
adr := 0; adr := 0;
IF (lib # 0) & (name # "") THEN IF (lib # 0) & (name # "") THEN
@ -313,7 +298,6 @@ END GetProcAdr;
PROCEDURE init (dll: INTEGER); PROCEDURE init (dll: INTEGER);
VAR VAR
lib_init: INTEGER; lib_init: INTEGER;
BEGIN BEGIN
lib_init := GetProcAdr("lib_init", dll); lib_init := GetProcAdr("lib_init", dll);
IF lib_init # 0 THEN IF lib_init # 0 THEN
@ -326,6 +310,44 @@ BEGIN
END init; END init;
PROCEDURE OutChar* (c: CHAR);
BEGIN
sysfunc3(63, 1, ORD(c))
END OutChar;
PROCEDURE OutLn*;
BEGIN
OutChar(0DX);
OutChar(0AX)
END OutLn;
PROCEDURE OutString (s: ARRAY OF CHAR);
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE (i < LEN(s)) & (s[i] # 0X) DO
OutChar(s[i]);
INC(i)
END
END OutString;
PROCEDURE imp_error (lib, proc: STRING);
BEGIN
OutString("import error: ");
IF proc = "" THEN
OutString("can't load '")
ELSE
OutString("not found '"); OutString(proc); OutString("' in '")
END;
OutString(lib);
OutString("'" + 0DX + 0AX)
END imp_error;
PROCEDURE GetStr (adr, i: INTEGER; VAR str: STRING); PROCEDURE GetStr (adr, i: INTEGER; VAR str: STRING);
VAR VAR
c: CHAR; c: CHAR;
@ -337,63 +359,47 @@ BEGIN
END GetStr; END GetStr;
PROCEDURE [stdcall] dll_Load* (import_table: INTEGER): INTEGER; PROCEDURE [stdcall-] dll_Load* (import_table: INTEGER): INTEGER;
CONST CONST
path = "/sys/lib/"; path = "/sys/lib/";
VAR VAR
imp, lib, exp, proc, res, pathLen: INTEGER; imp, lib, exp, proc, pathLen: INTEGER;
fail, done: BOOLEAN;
procname, libname: STRING; procname, libname: STRING;
BEGIN BEGIN
SYSTEM.CODE(060H); (* pusha *) SYSTEM.CODE(060H); (* pusha *)
fail := FALSE;
done := FALSE;
res := 0;
libname := path; libname := path;
pathLen := LENGTH(libname); pathLen := LENGTH(libname);
REPEAT
SYSTEM.GET(import_table, imp); SYSTEM.GET(import_table, imp);
IF imp # 0 THEN WHILE imp # 0 DO
SYSTEM.GET(import_table + 4, lib); SYSTEM.GET(import_table + 4, lib);
GetStr(lib, pathLen, libname); GetStr(lib, pathLen, libname);
exp := sysfunc3(68, 19, SYSTEM.ADR(libname[0])); exp := sysfunc3(68, 19, SYSTEM.ADR(libname[0]));
fail := exp = 0; IF exp = 0 THEN
imp_error(libname, "")
ELSE ELSE
done := TRUE
END;
IF fail THEN
done := TRUE;
imp_error.proc := "";
imp_error.lib := libname;
imp_error.error := 1
END;
IF (imp # 0) & ~fail THEN
REPEAT REPEAT
SYSTEM.GET(imp, proc); SYSTEM.GET(imp, proc);
IF proc # 0 THEN IF proc # 0 THEN
GetStr(proc, 0, procname); GetStr(proc, 0, procname);
proc := GetProcAdr(procname, exp); proc := GetProcAdr(procname, exp);
IF proc # 0 THEN IF proc # 0 THEN
SYSTEM.PUT(imp, proc); SYSTEM.PUT(imp, proc)
INC(imp, 4)
ELSE ELSE
imp_error.proc := procname; proc := 1;
imp_error.lib := libname; imp_error(libname, procname)
imp_error.error := 2 END;
END INC(imp, 4)
END END
UNTIL proc = 0; UNTIL proc = 0;
init(exp); init(exp)
INC(import_table, 8) END;
END INC(import_table, 8);
UNTIL done; SYSTEM.GET(import_table, imp);
IF fail THEN
res := 1
END; END;
import_table := res;
SYSTEM.CODE(061H) (* popa *) SYSTEM.CODE(061H) (* popa *)
RETURN import_table RETURN 0
END dll_Load; END dll_Load;
@ -410,7 +416,6 @@ END dll_Init;
PROCEDURE LoadLib* (name: ARRAY OF CHAR): INTEGER; PROCEDURE LoadLib* (name: ARRAY OF CHAR): INTEGER;
VAR VAR
Lib: INTEGER; Lib: INTEGER;
BEGIN BEGIN
DLL_INIT := dll_Init; DLL_INIT := dll_Init;
Lib := sysfunc3(68, 19, SYSTEM.ADR(name[0])); Lib := sysfunc3(68, 19, SYSTEM.ADR(name[0]));
@ -421,12 +426,10 @@ BEGIN
END LoadLib; END LoadLib;
PROCEDURE _init*; PROCEDURE _init* (import_table: INTEGER);
BEGIN BEGIN
DLL_INIT := dll_Init; DLL_INIT := dll_Init;
imp_error.lib := ""; dll_Load(import_table)
imp_error.proc := "";
imp_error.error := 0
END _init; END _init;

View File

@ -17,7 +17,7 @@
MODULE OpenDlg; MODULE OpenDlg;
IMPORT sys := SYSTEM, KOSAPI; IMPORT sys := SYSTEM;
CONST CONST
topen* = 0; topen* = 0;
@ -59,17 +59,18 @@ TYPE
VAR VAR
Dialog_start, Dialog_init: PROCEDURE [stdcall] (od: Dialog);
filter_area: tFilterArea; filter_area: tFilterArea;
PROCEDURE [stdcall, "proc_lib.obj", ""] OpenDialog_init (od: Dialog); END;
PROCEDURE [stdcall, "proc_lib.obj", ""] OpenDialog_start (od: Dialog); END;
PROCEDURE Show*(od: Dialog; Width, Height: INTEGER); PROCEDURE Show*(od: Dialog; Width, Height: INTEGER);
BEGIN BEGIN
IF od # NIL THEN IF od # NIL THEN
od.X := Width; od.X := Width;
od.Y := Height; od.Y := Height;
Dialog_start(od) OpenDialog_start(od)
END END
END Show; END Show;
@ -135,7 +136,7 @@ BEGIN
res.dir_default_path := sys.ADR(res.s_dir_default_path[0]); res.dir_default_path := sys.ADR(res.s_dir_default_path[0]);
res.openfile_path := sys.ADR(res.FilePath[0]); res.openfile_path := sys.ADR(res.FilePath[0]);
res.filename_area := sys.ADR(res.FileName[0]); res.filename_area := sys.ADR(res.FileName[0]);
Dialog_init(res) OpenDialog_init(res)
ELSE ELSE
DISPOSE(res) DISPOSE(res)
END END
@ -151,23 +152,5 @@ BEGIN
END END
END Destroy; END Destroy;
PROCEDURE Load;
VAR Lib: INTEGER;
PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
VAR a: INTEGER;
BEGIN
a := KOSAPI.GetProcAdr(name, Lib);
ASSERT(a # 0);
sys.PUT(v, a)
END GetProc;
BEGIN
Lib := KOSAPI.LoadLib("/sys/Lib/Proc_lib.obj");
GetProc(Lib, sys.ADR(Dialog_init), "OpenDialog_init");
GetProc(Lib, sys.ADR(Dialog_start), "OpenDialog_start");
END Load;
BEGIN
Load
END OpenDlg. END OpenDlg.

View File

@ -24,14 +24,13 @@ IMPORT SYSTEM, KOSAPI, File;
VAR VAR
file : INTEGER; file: INTEGER;
img_decode : PROCEDURE (data, size, options: INTEGER): INTEGER;
img_to_rgb2 : PROCEDURE (data, data_rgb: INTEGER);
img_scale : PROCEDURE (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER;
img_destroy* : PROCEDURE (img: INTEGER);
PROCEDURE [stdcall, "libimg.obj", ""] img_decode (data, size, options: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libimg.obj", ""] img_to_rgb2 (data, data_rgb: INTEGER); END;
PROCEDURE [stdcall, "libimg.obj", ""] img_scale (src, crop_x, crop_y, crop_width, crop_height, dst, scale, inter, param1, param2: INTEGER): INTEGER; END;
PROCEDURE [stdcall, "libimg.obj", ""] img_destroy* (img: INTEGER); END;
PROCEDURE GetInf*(img: INTEGER; VAR sizeX, sizeY, data: INTEGER); PROCEDURE GetInf*(img: INTEGER; VAR sizeX, sizeY, data: INTEGER);
BEGIN BEGIN
@ -95,26 +94,4 @@ BEGIN
END LoadFromFile; END LoadFromFile;
PROCEDURE load;
VAR Lib: INTEGER;
PROCEDURE GetProc(Lib, v: INTEGER; name: ARRAY OF CHAR);
VAR a: INTEGER;
BEGIN
a := KOSAPI.GetProcAdr(name, Lib);
ASSERT(a # 0);
SYSTEM.PUT(v, a)
END GetProc;
BEGIN
Lib := KOSAPI.LoadLib("/sys/Lib/Libimg.obj");
GetProc(Lib, SYSTEM.ADR(img_decode), "img_decode");
GetProc(Lib, SYSTEM.ADR(img_destroy), "img_destroy");
GetProc(Lib, SYSTEM.ADR(img_to_rgb2), "img_to_rgb2");
GetProc(Lib, SYSTEM.ADR(img_scale), "img_scale");
END load;
BEGIN
load
END LibImg. END LibImg.