[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
Copyright (c) 2018, 2020-2021, Anton Krotov
Copyright (c) 2018, 2020-2022, Anton Krotov
All rights reserved.
*)
@ -36,7 +36,7 @@ VAR
CriticalSection: CRITICAL_SECTION;
_import*, multi: BOOLEAN;
multi: BOOLEAN;
base*: INTEGER;
@ -226,19 +226,6 @@ BEGIN
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);
VAR
c: CHAR;
@ -247,7 +234,7 @@ BEGIN
REPEAT
SYSTEM.GET(pchar, c);
IF c # 0X THEN
OutChar(c)
K.OutChar(c)
END;
INC(pchar)
UNTIL c = 0X
@ -258,54 +245,25 @@ END OutStr;
PROCEDURE DebugMsg* (lpText, lpCaption: INTEGER);
BEGIN
IF lpCaption # 0 THEN
OutLn;
K.OutLn;
OutStr(lpCaption);
OutChar(":");
OutLn
K.OutChar(":");
K.OutLn
END;
OutStr(lpText);
IF lpCaption # 0 THEN
OutLn
K.OutLn
END
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);
BEGIN
multi := FALSE;
base := code - SizeOfHeader;
K.sysfunc2(68, 11);
InitializeCriticalSection(CriticalSection);
K._init;
_import := (K.dll_Load(import_) = 0) & (K.imp_error.error = 0);
IF ~_import THEN
imp_error
END
K._init(import_)
END init;

View File

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

View File

@ -49,13 +49,10 @@ TYPE
END;
VAR
draw *: PROCEDURE (eb: tEditBox);
mouse *: PROCEDURE (eb: tEditBox);
_setValue : PROCEDURE (eb: tEditBox; text: INTEGER);
key *: PROCEDURE (eb: tEditBox; key: INTEGER);
PROCEDURE [stdcall, "box_lib.obj", "edit_box_draw"] draw* (eb: tEditBox); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_mouse"] mouse* (eb: tEditBox); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_set_text"] _setValue (eb: tEditBox; text: INTEGER); END;
PROCEDURE [stdcall, "box_lib.obj", "edit_box_key_safe"] key* (eb: tEditBox; key: INTEGER); END;
PROCEDURE getValue* (text: tEditBox; VAR str: ARRAY OF CHAR);
VAR
@ -108,29 +105,4 @@ BEGIN
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.

View File

@ -21,7 +21,7 @@ MODULE Ini;
IMPORT
KOSAPI, SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS, Lines;
SYSTEM, RW, Text, Utils, File, List, Languages, KolibriOS, Lines;
CONST
@ -46,10 +46,6 @@ TYPE
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;
sections*: List.tList;
@ -58,6 +54,11 @@ VAR
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;
RETURN get_color(IniFileName, curSection, key, def)
END getColor;
@ -158,18 +159,6 @@ END getSettings;
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
sections := List.create(NIL);
@ -181,12 +170,6 @@ BEGIN
IniFileName := "/sys/settings/cedit.ini"
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));
Languages.init(getStr);
selectSection(0);

View File

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

View File

@ -17,7 +17,7 @@
MODULE OpenDlg;
IMPORT sys := SYSTEM, KOSAPI;
IMPORT sys := SYSTEM;
CONST
topen* = 0;
@ -59,17 +59,18 @@ TYPE
VAR
Dialog_start, Dialog_init: PROCEDURE [stdcall] (od: Dialog);
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);
BEGIN
IF od # NIL THEN
od.X := Width;
od.Y := Height;
Dialog_start(od)
OpenDialog_start(od)
END
END Show;
@ -135,7 +136,7 @@ BEGIN
res.dir_default_path := sys.ADR(res.s_dir_default_path[0]);
res.openfile_path := sys.ADR(res.FilePath[0]);
res.filename_area := sys.ADR(res.FileName[0]);
Dialog_init(res)
OpenDialog_init(res)
ELSE
DISPOSE(res)
END
@ -151,23 +152,5 @@ BEGIN
END
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.

View File

@ -24,14 +24,13 @@ IMPORT SYSTEM, KOSAPI, File;
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);
BEGIN
@ -95,26 +94,4 @@ BEGIN
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.