From c927039b68fc926eb6254a51b35de98e7f9162f1 Mon Sep 17 00:00:00 2001 From: nova Date: Wed, 26 Feb 2025 22:42:51 +0100 Subject: [PATCH] refractoring & hidden files functionality --- backend.c | 40 ++++++++++++++++------------------------ backend.h | 4 ++-- main.c | 2 ++ th | Bin 20992 -> 16888 bytes window.c | 1 - 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/backend.c b/backend.c index b6300d4..356ba41 100644 --- a/backend.c +++ b/backend.c @@ -4,6 +4,7 @@ #include #include +extern unsigned int settings; extern unsigned long longest_name; extern unsigned long file_count; extern char **content_l; @@ -11,18 +12,18 @@ extern char **content_m; extern char **content_r; extern char *path; -void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden){ +void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name){ DIR *dir = opendir(path); if (dir) { unsigned long index = 0; struct dirent *entry; while ( entry=readdir(dir) ) { - if (entry->d_name[0] != '.' && !show_hidden) { + if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files index++; if ((unsigned long)sizeof(entry->d_name) > *longest_name) { *longest_name = sizeof(entry->d_name); } - } else if (show_hidden){ + } else if (settings & 1){ //bit 0 = show_hidden_files index++; if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) { longest_name = (unsigned long*)sizeof(entry->d_name); @@ -34,24 +35,19 @@ void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_ closedir(dir); } -void get_dir_content(char *path, char **dir_content, char show_hidden){ +void get_dir_content(char *path, char **dir_content){ DIR *dir = opendir(path); char content[file_count][longest_name]; memset(content,0,sizeof(content)); if (dir) { int index = 0; struct dirent *entry; - while ( entry=readdir(dir) ) { - if (entry->d_name[0] != '.' && !show_hidden) { + while ( entry=readdir(dir) ) { + if (entry->d_name[0] != '.' && !(settings & 1)) { //bit 0 = show_hidden_files strcpy(dir_content[index], entry->d_name); index++; - } else if (show_hidden){ - for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) { - if ((entry->d_name[i]) != '\0'){ - } else { - break; - } - } + } else if (settings & 1){ //bit 0 = show_hidden_files + strcpy(dir_content[index], entry->d_name); index++; } } @@ -60,43 +56,39 @@ void get_dir_content(char *path, char **dir_content, char show_hidden){ } void print_dir(WINDOW *win, char **dir_content){ - char str[longest_name]; for (unsigned long i = 0; i < (unsigned long)file_count; i++ ){ - strcpy(str, dir_content[i]); - wprintw(win, "%s",str); + wprintw(win, "%s",dir_content[i]); wmove(win, i, 1); } } void *populate_dir(void *which){ // 0=left, 1=main, 2=right char wh = (char)which; - if (wh) { if (wh==1) { - get_dir_size(path, &file_count, &longest_name, 0); + get_dir_size(path, &file_count, &longest_name); content_m = calloc(file_count, sizeof(*content_m)); for (unsigned long i = 0; i1M{=Re0 zcXf4bb<^Gcvok&(={w)=dz|ll=iGDdmGAjxaO)1PupatDG>Iz6e ztP<1leWkcUOa(thVoDxR1X5K--Q~1e<5i$!H=8OG(90Dpm~wf+ z_Ly=$DJS$W(NtI-afG^*QS%I$p> zc9fUTT6mau>h>y)gLD4TcvD#tjqF{yd`YxvaWoR^>|WfxYUSdU%l#d3|1v43xB~dl zoZ7r?x4^LU6UM{o?os>&z^J%{OUl{5Tk}e)#*ShpIr*bPzVvWQO4kC(RUQtyM31np zkI`%Izx;Ig`8J3rEQ3I2P9PbpfKxlZ3G^SWpx;*kzXpybYWL;}`aiFLM=Icn3ixdm za9@RZ{<(twkqY>n3VyDDz7HQ~xu}BvVJJ?NpQ9Dw)|5ah78M zCW`aL3V1^WoR+nV#2n!Zpn}5dkQ@1#r=aq0bIYy+ZccL}UBihzlV# z-eoqn-eoq2B2fX)VbK_kcZ8cF3DKTxO@u>D<~QPqhM7h{N$L_7o<`lJwh$Cdv#~p5 zHb-KiC^bx$CbH;BymX{CE>bSv50HHnDRP2D-xMbtK8Q# z_OtK&HI}g|5z>6;+{ovs%_w*(ykGMCSUOALV|qViJge_hssl>SIP*0Qe7aBRjjmIa z)>0L*;?}a2- z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h}x^2@r|p6qn-}e-i~Xc3GdFpZWYbK4*@{H|udf-V0r7BJ11F(@OzTD$;(o^S&0b z^_!)Z5cP`kJf+b|?fC=+WQ+CrIib2>kGixccr1e+gB<&!&S)jvMgP$E)iL@xlu`+=u&X8;=ce8 CR^18! diff --git a/window.c b/window.c index d1c24da..8c1a2d4 100644 --- a/window.c +++ b/window.c @@ -37,7 +37,6 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char * } void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){ - DIR *dir = opendir("."); unsigned int local_width; unsigned int local_height; unsigned long file_count = 0;