From 8cf1918b0d76b001991003f4acd6f506627dc9a6 Mon Sep 17 00:00:00 2001 From: nova Date: Wed, 26 Feb 2025 22:19:32 +0100 Subject: [PATCH] base layout for multithreading --- backend.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ backend.h | 8 +++++ main.c | 42 ++++++++++++++++------ th | Bin 16512 -> 20992 bytes window.c | 94 ++++++++----------------------------------------- window.h | 13 +++---- 6 files changed, 160 insertions(+), 99 deletions(-) create mode 100644 backend.c create mode 100644 backend.h diff --git a/backend.c b/backend.c new file mode 100644 index 0000000..b6300d4 --- /dev/null +++ b/backend.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include + +extern unsigned long longest_name; +extern unsigned long file_count; +extern char **content_l; +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){ + DIR *dir = opendir(path); + if (dir) { + unsigned long index = 0; + struct dirent *entry; + while ( entry=readdir(dir) ) { + if (entry->d_name[0] != '.' && !show_hidden) { + index++; + if ((unsigned long)sizeof(entry->d_name) > *longest_name) { + *longest_name = sizeof(entry->d_name); + } + } else if (show_hidden){ + index++; + if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) { + longest_name = (unsigned long*)sizeof(entry->d_name); + } + } + } + *file_count = index; + } + closedir(dir); +} + +void get_dir_content(char *path, char **dir_content, char show_hidden){ + 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) { + 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; + } + } + index++; + } + } + } + closedir(dir); +} + +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); + 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); + content_m = calloc(file_count, sizeof(*content_m)); + for (unsigned long i = 0; i +#include "backend.c" + + +void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden); +void get_dir_content(char *path, char **dir_content, char show_hidden); +void print_dir(WINDOW *win, char **dir_content); +void *populate_dir(void *dir); diff --git a/main.c b/main.c index f4cc36c..03fb6a4 100644 --- a/main.c +++ b/main.c @@ -1,29 +1,51 @@ #include #include #include +#include #include "window.h" unsigned int terminal_height; unsigned int terminal_width; +unsigned long file_count; +unsigned long longest_name; +char **content_l; //content of parent dir, used in left window +char **content_m; //content of current dir, used in main window +char **content_r; //content of child dir, used in right window +char *path = "."; + int main() { initscr(); //start ncurses unsigned int ch; getmaxyx(stdscr, terminal_height, terminal_width); - WINDOW *win_m = newwin(terminal_height, terminal_width/3, 0, 0); - WINDOW *win_l = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3)); - WINDOW *win_r = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2)); - while((ch = wgetch(win_m)) != 'q'){ + WINDOW *winl = newwin(terminal_height, terminal_width/3, terminal_height, (terminal_width/3)); + WINDOW *winm = newwin(terminal_height, terminal_width/3, 0, 0); + WINDOW *winr = newwin(terminal_height, terminal_width/3, terminal_height, ((terminal_width/3)*2)); + + + while((ch = wgetch(winm)) != 'q'){ getmaxyx(stdscr, terminal_height, terminal_width); - pthread_t main_window_thread; - pthread_t left_window_thread; - pthread_t right_window_thread; - window_left(win_l,0,0); - window_main(win_m,0,(terminal_width/3)); - window_right(win_r,0,((terminal_width/3)*2)); + pthread_t populate_l; + pthread_t populate_m; + pthread_t populate_r; + + pthread_create(&populate_l, NULL, populate_dir, (void*)0); //parent_content slash win_l + pthread_create(&populate_m, NULL, populate_dir, (void*)1); //current_content slash win_m + pthread_create(&populate_r, NULL, populate_dir, (void*)2); //child_content slash win_r + + pthread_join(populate_l, NULL); + pthread_join(populate_m, NULL); + pthread_join(populate_r, NULL); + + window_left(winl, 0, 0, content_l); + window_main(winm, 0, terminal_width/3, content_m); + window_right(winr, 0, (terminal_width/3)*2, content_r); wmove(stdscr,0,0); + free(content_l); + free(content_m); + free(content_r); } diff --git a/th b/th index ba3f2691128a16068304dbbc108a3cc1bd4badd9..8e4b1546088dbb11d07784c0099f24acf18eefc4 100755 GIT binary patch literal 20992 zcmeHPeRNyJl^@v=xR69nz~GPsv_L4I!VZZ^C?R$dCC?BO7ZM7kpeVK+tJsn&%dx}R zPzNWwc}JKHJ-aQtOS>ssXbyCN!=^OAfptPQF`Ql2&QkF914J5Hi2!T9%}4Y0cW354 zJv~eP*pEN<9F323=lOqW9rnS*rcyidg;~qbdhd%zox85=16Z`>y2wYrj@!r zrW{X-34PeEn>M425>vO{4(*4V`lXf-OgZ+~zmaVH@6^|<^(u87-Lym3$CT^)GV~}e ze`u=Ig4gN#iuHqEx0@;TH>FEEq8sWKT-wokNk=r+(|1YVqPk1!76iKEf%&qW{Hn)? z#?-27*9mmX5MkV%W&Mgj5f~+p@W^tuU#59gs``$6rgE}JiEQcamUJ$7DpzsX>Jj|{ zSD;E`7u_{yH1cAnW+#z<0WxzED#S-caH_{&K>m>;^1F)Qm%vb=dao}c|8x;NS_DrN z!EY{tpI5}6(IWCYi{NJ!u|xgg$H$#cFCxDKf`#I9ZxQ@AMewaf@Y{>v8;anU0r%tM zPP+jV^7Cg!@E;e!n~LBU1D_#g34b#(NIXAPAZ}+XDE~XuxV9cJL9oXcQTwvhC-q{+1lNb5K^O{eCMX#XiW5Oh$moB#3H?tZRv=F z6QVZ}X-h=9+eI`MO_G`3jge$ayNJYErBqiU8cX()Sa4PeG~w1hi4;w_>x(%BtJig*{i1q$U@OHZOZ(oGXt z9r4L%tSxSHEh@Kab>p(-q4|LYf^(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9~YMeT( zk17?sZ~$3L%xnloL-aDjx<{ZDibTy;9P{Th`~|++^h*T%q5{tI3muQRYPh+zrA3#; zZy4|k2;lKLLYsP9!8GwAgc;bd8m~PRf8Rm9l#q*VTO^cdKpX7u8Whyeq<0^4U?AsP?^)<)Q?eWA84Xs$YZhj)TO-NZo z5HDExLOY`Hr)VOsB-_LBmPjmGz?hK5!;L{Q(7EQugz(8)`jGW)i-Dy~OSn$>65)2R za_soxF*zoE;Rdrl9&8Gm4Iy}APWdo{@pusRBn!@?s9;kB&XhU2L-^`qO-(eYejkaZ zOS)Rfgv| zhF2qlza(N@KJPb}-lY}sf4@x5@;3mby$0L!euU`(Euj4h#fj~CU+@iJRAsj3{S8yz z&p<^cJ-sq3oWP5&|QE?wYq_iTrU$$p@2@<=#@N3ltigGy`9o3#I5Rfk} z-|JVJ<=UR-IfV-0<&37+K&gDKo|Ce@v;Rq#lAZF{Q4;mrt{sl(0YmE$#gN<0^`hrA iTz6%uew&vly2s(1%Vk} +#include #include +#include "backend.h" extern unsigned int terminal_height; extern unsigned int terminal_width; - -void get_dir_size(char *path, unsigned long *file_count, unsigned long *longest_name, char show_hidden) { - DIR *dir = opendir(path); - if (dir) { - unsigned long index = 0; - struct dirent *entry; - while ( entry=readdir(dir) ) { - if (entry->d_name[0] != '.' && !show_hidden) { - index++; - if ((unsigned long)sizeof(entry->d_name) > *longest_name) { - *longest_name = sizeof(entry->d_name); - } - } else if (show_hidden){ - index++; - if ((unsigned long*)sizeof(entry->d_name) > (unsigned long*)longest_name) { - longest_name = (unsigned long*)sizeof(entry->d_name); - } - } - } - *file_count = index; - } - closedir(dir); -} - -void get_dir_content(char *path, unsigned long file_count, unsigned long longest_name, char *dir_content[file_count], char show_hidden){ - 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) { -// for (unsigned long i = 0; i < sizeof(entry->d_name)/sizeof(char); i++) { -// if ((entry->d_name[i]) != '\0'){ -// dir_content[index][i] = entry->d_name[i]; -// } else { -// break; -// } -// } - 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; - } - } - index++; - } - } - } - closedir(dir); -} -void print_dir(WINDOW *win, unsigned long file_count, unsigned long longest_name, 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); - wmove(win, i, 1); - } -} +extern unsigned long longest_name; +extern unsigned long file_count; -void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){ + +void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content){ + + //WINDOW *win = (window_data)window_data.win; unsigned int local_width; unsigned int local_height; unsigned long file_count = 0; @@ -86,24 +27,15 @@ void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x){ //}}} wmove(win, 1, 1); - wprintw(win, "meow"); - get_dir_size(".", &file_count, &longest_name, 0); - char **dir_content; - dir_content = calloc(file_count, sizeof(*dir_content)); - for (unsigned long i = 0; i #include "window.c" -void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x); -void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x); -void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x); +void window_left(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content); +void window_main(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content); +void window_right(WINDOW *win, unsigned int start_y, unsigned int start_x, char **dir_content); -typedef struct window_data { - WINDOW *win; - unsigned int start_y; - unsigned int start_x; -} window_data;