From d681f11bef625f4e550516ee9289f4bc066b0ac1 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Mon, 17 Aug 2026 19:43:47 +0300 Subject: [PATCH] updates file list->fl_clear, gets rid of **current and **start pointers in w_ui_file_list_t --- src/core/file_processor.c | 39 +++++++++++++++++++-------------------- src/core/file_processor.h | 2 +- src/windows/file_list.c | 15 +++++---------- src/windows/file_list.h | 2 -- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/core/file_processor.c b/src/core/file_processor.c index 8e596d7..9cfa111 100644 --- a/src/core/file_processor.c +++ b/src/core/file_processor.c @@ -27,7 +27,10 @@ #include "query.h" static void fl_add(dlist_t *fl_list, char *q_line); -void fl_clear(fl_item_t **start, fl_item_t **current); +static bool fl_rm_cb(void *_ptr); + + +void fl_clear(dlist_t *dlist) { dlist_clear_list(dlist, fl_rm_cb); } void file_list(file_args_t *f_args, query_args_t *q_args) { int32_t qlen; @@ -68,7 +71,8 @@ void file_list(file_args_t *f_args, query_args_t *q_args) { static bool fl_add_cb(void *_dst, void *_src); -int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *l_selected) { +int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, + fl_item_t *l_selected) { fl_item_t *f_selected = &(f_args->f_selected); /* new copy of file struct (list be cleared) */ struct stat st = {0}; @@ -89,7 +93,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *l_s f_selected->name = NULL; sprintf(file_path, "%s/%s", DOWNLOADS_DIR, l_selected->name); f_selected->name = strdup(l_selected->name); - fl_clear(&f_args->l_start, &f_args->l_current); + fl_clear(f_args->f_list); f_args->file_d = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (f_args->file_d == -1) { server_send_string(q_args, "error: %s\n", f_selected->name); @@ -378,6 +382,18 @@ static bool fl_add_cb(void *_dst, void *_src) { return true; } +static bool fl_rm_cb(void *_ptr) { + fl_item_t *ptr = _ptr; + if (ptr->description != NULL) + free(ptr->description); + if (ptr->name != NULL) + free(ptr->name); + if (ptr->owner != NULL) + free(ptr->owner); + free(ptr); + return true; +} + /* work with file list */ static void fl_add(dlist_t *fl_list, char *q_line) { fl_item_t f_item; @@ -392,21 +408,4 @@ static void fl_add(dlist_t *fl_list, char *q_line) { fl_q_extract(&f_item, q_line); dlist_add(fl_list, &f_item, fl_item_t, fl_add_cb, false); -} - -void fl_clear(fl_item_t **start, fl_item_t **arg_current) { - if (*start == NULL) - return; - fl_item_t *next, *current; - current = *start; - - do { - if (current->description != NULL) { - free(current->description); - } - free(current->name); - free(current); - } while ((current = next) != NULL); - *start = NULL; - *arg_current = NULL; } \ No newline at end of file diff --git a/src/core/file_processor.h b/src/core/file_processor.h index cba43c7..0598038 100644 --- a/src/core/file_processor.h +++ b/src/core/file_processor.h @@ -13,7 +13,7 @@ int file_upload_request(char *, query_args_t *q_args); int file_upload_start(query_args_t *q_args); int file_upload(query_args_t *q_args); int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args); -void fl_clear(fl_item_t **start, fl_item_t **arg_current); +void fl_clear(dlist_t *dlist); int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, fl_item_t *ptr); void clear_file_in_query(query_args_t *q_args); diff --git a/src/windows/file_list.c b/src/windows/file_list.c index 24870a8..452c7cd 100644 --- a/src/windows/file_list.c +++ b/src/windows/file_list.c @@ -2,10 +2,10 @@ /* Copyright (c) 2026 Oleksandr Zhylin */ #include "file_list.h" +#include "main_window.h" +#include "dlist.h" #include #include -#include "dlist.h" -#include "main_window.h" #include #include #include @@ -216,13 +216,13 @@ void *w_fl_init(app_t *app) { } void w_fl_destroy(w_ui_file_list_t **fui) { - fl_clear((*fui)->start, (*fui)->current); + fl_clear((*fui)->f_list); free(*fui); *fui = NULL; } void w_fl_reset(w_ui_file_list_t *fl_ui) { - fl_clear(fl_ui->start, fl_ui->current); + fl_clear(fl_ui->f_list); fl_ui->current_idx = 0; fl_ui->current_page = 0; fl_ui->pages = 0; @@ -256,11 +256,6 @@ void w_fl_draw(w_ui_file_list_t *fui) { int32_t cur_el_idx = 0; box(fui->win_list, 0, 0); - if (fui->start != NULL) { - el = *(fui->start); - active_el = el; - } - if (fui->activate_last) { fui->current_idx = fui->max_lines - 1; fui->activate_last = false; @@ -297,7 +292,7 @@ void w_fl_draw(w_ui_file_list_t *fui) { int32_t p_len; if (!fui->active_search && fui->search_key->slen > 0 && - *(fui->start) == NULL) { + fui->f_list->start == NULL) { bstring text = bfromStatic("[No data to show]"); for (; p_y < (sz_y_f / 2); p_y++) { mvwprintw(win, p_y, p_x, "%*s", sz_x - 1, ""); diff --git a/src/windows/file_list.h b/src/windows/file_list.h index 38dc783..2c5f666 100644 --- a/src/windows/file_list.h +++ b/src/windows/file_list.h @@ -11,8 +11,6 @@ typedef struct { w_t w; - fl_item_t **current; - fl_item_t **start; dlist_t *f_list; dlist_node_t *f_selected; int32_t current_idx;