From 37a69c4efa33fe9caad12af1bd2771bf311a1698 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sun, 5 Apr 2020 19:29:24 +0000 Subject: [PATCH] cmm: reduce C-- app sizes by removing sprintf() from some apps and libs git-svn-id: svn://kolibrios.org@7768 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/diff/diff_gui.h | 2 +- programs/cmm/kf_font_viewer/font_viewer.c | 4 +++- programs/cmm/lib/dll.h | 16 ++++++++------- programs/cmm/lib/io.h | 4 +++- programs/cmm/lib/strings.h | 1 + programs/cmm/pipet/pipet.c | 24 +++++++++++++++++++---- programs/cmm/txtread/txtread.c | 6 ++++-- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/programs/cmm/diff/diff_gui.h b/programs/cmm/diff/diff_gui.h index 71797d12eb..8b7c298334 100644 --- a/programs/cmm/diff/diff_gui.h +++ b/programs/cmm/diff/diff_gui.h @@ -132,7 +132,7 @@ void UpdateEditBoxes(dword f1, f2) void EventGo() { char run_param[4096]; - sprintf(#run_param, "\"%s\" \"%s\"", #src_path, #dst_path); + wsprintf(#run_param, "\"%s\" \"%s\"", #src_path, #dst_path); RunProgram(I_Path, #run_param); } #endif diff --git a/programs/cmm/kf_font_viewer/font_viewer.c b/programs/cmm/kf_font_viewer/font_viewer.c index eaac2c9e51..2358734e67 100644 --- a/programs/cmm/kf_font_viewer/font_viewer.c +++ b/programs/cmm/kf_font_viewer/font_viewer.c @@ -80,7 +80,9 @@ void DrawPreviewPhrase() for (i=10, y=12; i<22; i++, y+=kfont.height+3;) //not flexible, need to calculate font count and max line length { if (colored.checked) c = pal[i-10]; else c=0; - sprintf(#line,"Размер шрифта/size font %d пикселей.",i); + strcpy(#line, "Размер шрифта/forn size is "); + strcat(#line, itoa(i)); + strcat(#line, " пикселей/px."); kfont.WriteIntoBuffer(14,y,Form.cwidth,Form.cheight-PANELH, 0xFFFFFF, c, i, #line); } if (kfont.smooth) kfont.ApplySmooth(); diff --git a/programs/cmm/lib/dll.h b/programs/cmm/lib/dll.h index 4254a8c198..908b0407f2 100644 --- a/programs/cmm/lib/dll.h +++ b/programs/cmm/lib/dll.h @@ -7,20 +7,22 @@ #endif #ifdef LANG_RUS - #define _TEXT_ERROR_ADD "'Ошибка при загрузке библиотеки" + #define _TEXT_ERROR_ADD "'Ошибка при загрузке библиотеки\n" #elif LANG_EST - #define _TEXT_ERROR_ADD "'Viga teegi laadimisel" + #define _TEXT_ERROR_ADD "'Viga teegi laadimisel\n" #else - #define _TEXT_ERROR_ADD "'Error while loading library" + #define _TEXT_ERROR_ADD "'Error while loading library\n" #endif char a_libdir[43] = "/sys/lib/\0"; -:inline void error_init(dword text) +:inline void error_init(dword lirary_path) { - dword TEXT_ERROR[1024]; - sprintf(TEXT_ERROR, "%s `%s`' -E",_TEXT_ERROR_ADD,text); - notify(TEXT_ERROR); + char error_text[1024]; + strcpy(#error_text, _TEXT_ERROR_ADD); + strcat(#error_text, lirary_path); + strcat(#error_text, "' -E"); + notify(#error_text); } // stdcall with 1 parameter diff --git a/programs/cmm/lib/io.h b/programs/cmm/lib/io.h index 4df9c3b1d2..29c8b1ccd9 100644 --- a/programs/cmm/lib/io.h +++ b/programs/cmm/lib/io.h @@ -232,7 +232,9 @@ { return PATH; } - sprintf(#__PATH_NEW,"%s/%s",self.dir,PATH); + strcpy(#__PATH_NEW, self.dir); + chrcat(#__PATH_NEW, '/'); + strcpy(#__PATH_NEW, PATH); return #__PATH_NEW; } diff --git a/programs/cmm/lib/strings.h b/programs/cmm/lib/strings.h index 833417d86c..301edeca59 100644 --- a/programs/cmm/lib/strings.h +++ b/programs/cmm/lib/strings.h @@ -867,6 +867,7 @@ inline cdecl int sprintf(dword buf, format,...) strlcpy(buf,"0x00000000",10); buf+=10; l=buf; + debugval("tmp", tmp); while(tmp) { $dec buf diff --git a/programs/cmm/pipet/pipet.c b/programs/cmm/pipet/pipet.c index 448b864a8c..3a1a38d875 100644 --- a/programs/cmm/pipet/pipet.c +++ b/programs/cmm/pipet/pipet.c @@ -1,4 +1,4 @@ -#define MEMSIZE 4096*10 +#define MEMSIZE 1024*40 #include "../lib/gui.h" #include "../lib/clipboard.h" @@ -89,13 +89,29 @@ void draw_window() EventUpdateWindowContent(); } +//copy of sprintf() => %A +void str2col(dword buf, number) +{ + byte s; + strlcpy(buf,"0x00000000",10); + buf+=10; + while(number) + { + $dec buf + s=number&0xF; + if(s>9)DSBYTE[buf]='A'+s-10; + else DSBYTE[buf]='0'+s; + number>>=4; + } +} + void EventUpdateWindowContent() { - sprintf(#picked_color_string, "%A", picked_color); + //sprintf(#picked_color_string, "%A", picked_color); + str2col(#picked_color_string, picked_color); rgb.DwordToRgb(picked_color); - EDI = 0xFFFfff; - WriteText(12,12, 0xD0, 0x000111, #picked_color_string+4); + WriteTextWithBg(12,12, 0xD0, 0x000111, #picked_color_string+4, 0xFFFfff); WriteNumber(12,33, 0xD0, 0xff0000, 3, rgb.r); WriteNumber(43,33, 0xD0, 0x008000, 3, rgb.g); diff --git a/programs/cmm/txtread/txtread.c b/programs/cmm/txtread/txtread.c index 3bd1f1400b..e631167777 100644 --- a/programs/cmm/txtread/txtread.c +++ b/programs/cmm/txtread/txtread.c @@ -270,7 +270,8 @@ void EventShowFileProperties() { char ss_param[4096]; if (!param) return; - sprintf(#ss_param, "-p %s", #param); + strcpy(#ss_param, "-p "); + strcpy(#ss_param+3, #param); RunProgram("/sys/File managers/Eolite", #ss_param); } @@ -365,7 +366,8 @@ void EventMenuClick() EventOpenFileInAnotherProgram("/sys/develop/heed"); break; case 25: - sprintf(#open_param,"~%s",#param); + open_param[0]='~'; + strcpy(#open_param+1,#param); RunProgram("/sys/@open", #open_param); break; //ColorSchemes