From 9c689736770ded5b4f93634fff372f844e19aa74 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Wed, 16 Dec 2015 16:13:34 +0000 Subject: [PATCH] Eolite: use collections for history.h, better code git-svn-id: svn://kolibrios.org@5974 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/eolite/Eolite.c | 52 ++++----------- programs/cmm/eolite/include/history.h | 78 ++++++++-------------- programs/cmm/eolite/include/settings.h | 9 ++- programs/cmm/eolite/include/translations.h | 4 +- programs/cmm/examples/collections.c | 28 ++++++-- programs/cmm/lib/collection.h | 11 ++- 6 files changed, 79 insertions(+), 103 deletions(-) diff --git a/programs/cmm/eolite/Eolite.c b/programs/cmm/eolite/Eolite.c index 561ee6110d..1b92fb2246 100644 --- a/programs/cmm/eolite/Eolite.c +++ b/programs/cmm/eolite/Eolite.c @@ -6,7 +6,7 @@ #endif //libraries -#define MEMSIZE 4096 * 150 +#define MEMSIZE 4096 * 180 #include "..\lib\clipboard.h" #include "..\lib\strings.h" #include "..\lib\mem.h" @@ -33,7 +33,6 @@ enum {CREATE_FILE=1, CREATE_FOLDER, RENAME_ITEM }; //NewElement dword col_padding, col_selec, col_lpanel; int toolbar_buttons_x[7]={9,46,85,134,167,203}; -struct path_string { char Item[4096]; }; byte smooth_font=false; byte active_about=0; @@ -110,8 +109,6 @@ char *fd_path_eolite_ini_path; #include "include\about.h" #include "include\properties.h" -char TMPS[4096]; -//char *TMP_PARS,*TMP_PARS2; void main() { word id; @@ -125,27 +122,9 @@ void main() load_dll(boxlib, #box_lib_init,0); load_dll(libini, #lib_init,1); + eolite_ini_path = abspath("Eolite.ini"); - fd_path_eolite_ini_path = "/fd/1/File Managers/Eolite.ini"; - /* - TMP_PARS2 = #fd_path_eolite_ini_path; - WHILE(DSBYTE[TMP_PARS]) - { - IF(count_sl!=1) - { - DSBYTE[TMP_PARS2] = DSBYTE[TMP_PARS]; - TMP_PARS2++; - } - ELSE IF(count_sl==2) - { - strlcpy(TMP_PARS2,"fd",2); - TMP_PARS2+=2; - } - IF(DSBYTE[TMP_PARS]=='/')count_sl++; - TMP_PARS++; - } - */ LoadIniSettings(); GetSystemDiscs(); @@ -159,13 +138,6 @@ void main() Open_Dir(#path,ONLY_OPEN); strcpy(#inactive_path, #path); llist_copy(#files_inactive, #files); - font.no_bg_copy = true; - - ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font file",#TMPS,4096,"/sys/FONTS/Tahoma.kf"); - font.load(#TMPS); - ini_get_str stdcall ("/sys/SETTINGS/SYSTEM.INI", "system", "font smoothing",#TMPS,4096,"on"); - if(!strcmp(#TMPS,"off"))smooth_font = false; - else smooth_font = true; SetEventMask(1100111b); loop(){ switch(WaitEvent()) @@ -198,7 +170,7 @@ void main() { if (dif_x > 150) { - if (HistoryPath(GO_FORWARD)) + if (FoldersHistory.forward()) { files.KeyHome(); Open_Dir(#path,WITH_REDRAW); @@ -351,7 +323,7 @@ void main() GoBack(); break; case 22: //Forward - if (HistoryPath(GO_FORWARD)) + if (FoldersHistory.forward()) { files.KeyHome(); Open_Dir(#path,WITH_REDRAW); @@ -510,7 +482,7 @@ void main() case 059...068: //F1-F10 FnProcess(key_scancode-58); break; - default: + default: for (i=files.cur_y+1; i0) && (!strcmp(#path,#history_list[history_current].Item)) return; - - MAX_HISTORY_NUM = sizeof(history_list)/sizeof(path_string); - if (history_current>=MAX_HISTORY_NUM-1) - { - history_current/=2; - for (i=0; i Hello + debugln(s.get(1)); //-> World + s.drop(); +} + +void main() +{ + int i; + s.add("0"); + s.add("1"); + s.add("2"); + s.add("3"); + for (i=0; i 0 1 2 3 + s.count--; + s.count--; + s.add("4"); + for (i=0; i 0 1 4 s.drop(); } \ No newline at end of file diff --git a/programs/cmm/lib/collection.h b/programs/cmm/lib/collection.h index dd765bca37..f12a394e1d 100644 --- a/programs/cmm/lib/collection.h +++ b/programs/cmm/lib/collection.h @@ -6,7 +6,6 @@ struct collection { int realloc_size, count; dword data_start; - dword data_cur_pos; dword data_size; dword element_offset[4090]; int add(); @@ -31,25 +30,25 @@ void collection::increase_data_size() { int collection::add(dword in) { if (count >= 4090) return 0; - if (data_cur_pos+strlen(in)+2 > data_size) { + if (element_offset[count]+strlen(in)+2 > data_size) { increase_data_size(); add(in); return; } - strcpy(data_start+data_cur_pos, in); - element_offset[count] = data_cur_pos; - data_cur_pos += strlen(in) + 1; + strcpy(data_start+element_offset[count], in); count++; + element_offset[count] = element_offset[count-1] + strlen(in) + 1; return 1; } dword collection::get(dword pos) { + if (pos<0) || (pos>=count) return 0; return data_start + element_offset[pos]; } void collection::drop() { if (data_start) free(data_start); - data_size = data_start = data_cur_pos = count = 0; + data_size = data_start = element_offset[count] = count = 0; } #endif \ No newline at end of file