From ba77017857e2d32862820a58398720751fdafd40 Mon Sep 17 00:00:00 2001 From: Alexander Zhylin Date: Tue, 27 Jan 2026 13:53:59 +0200 Subject: [PATCH] C23 standard. get rid of warnings --- Makefile | 2 +- src/file_processor.c | 5 +---- src/main.c | 1 - src/main.h | 9 +++++++++ src/query.c | 3 +++ src/server.c | 29 ----------------------------- src/ui/widget.c | 13 ++++++------- src/ui/widget/dialogue.c | 13 ++++++------- src/ui/widget/file_list.c | 4 +--- src/ui/widget/fs_file_list.c | 7 +------ src/ui/widget/group.c | 2 -- src/ui/widget/input.c | 1 - 12 files changed, 28 insertions(+), 61 deletions(-) diff --git a/Makefile b/Makefile index c75c8f0..f69bf99 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS := -ggdb -Wall -pedantic -lcurses +CFLAGS := -ggdb -Wall -std=c23 -pedantic -lcurses SRC_DIR := src OBJ_DIR := src/obj diff --git a/src/file_processor.c b/src/file_processor.c index 15a3649..1ba4877 100644 --- a/src/file_processor.c +++ b/src/file_processor.c @@ -28,7 +28,6 @@ void fl_clear(fl_item_t **start, fl_item_t **current); void file_list(file_args_t *f_args, query_args_t *q_args) { uint32_t qlen; char *query = NULL; - static uint32_t idx = 1; static char qbuf[INBUFSIZE * 2]; static uint32_t qbuf_used = 0; ui_file_list_t *fui = (ui_file_list_t *)q_args->file_list_ui; @@ -44,7 +43,6 @@ void file_list(file_args_t *f_args, query_args_t *q_args) { if (!strncmp(":END:", query, sizeof(":END:") - 1)) { sscanf(query, ":END: PAGE %u/%u COUNT: %u/%u\n", &fui->current_page, &fui->pages, &fui->current_count, &fui->full_count); - idx = 1; if (d != NULL && d->is_initiated) { d->needs_update = true; } @@ -179,7 +177,7 @@ void file_download(file_args_t *f_args, query_args_t *q_args) { ui_progress_bar_t *pb = (ui_progress_bar_t *)q_args->progress_bar; dialogue_t *d = (dialogue_t *)q_args->active_dialogue; ui_file_list_t *fui = (ui_file_list_t *)q_args->file_list_ui; - uint32_t a_len = 0; + int32_t a_len = 0; if (size_rest == 0) size_rest = f_selected->size; @@ -247,7 +245,6 @@ int32_t file_upload_request(char *query, query_args_t *q_args) { } int32_t file_upload_open(char *dpath, char *fname, query_args_t *q_args) { - char a_perm; q_args->file = malloc(sizeof(p_file_t)); q_args->file->path = malloc(strlen(dpath) + strlen(fname) + 2); sprintf(q_args->file->path, "%s/%s", dpath, fname); diff --git a/src/main.c b/src/main.c index 3b60225..17101be 100644 --- a/src/main.c +++ b/src/main.c @@ -24,7 +24,6 @@ int main(int argc, char **argv) { app_t *app; params_t params; query_args_t *q_args = malloc(sizeof(query_args_t)); - char buf[INBUFSIZE]; app = calloc(1, sizeof(app_t)); diff --git a/src/main.h b/src/main.h index 4579c4c..14a938b 100644 --- a/src/main.h +++ b/src/main.h @@ -13,10 +13,19 @@ #define DIALOGUE_TITLE 64 #define DIALOGUE_TEXT 4096 #define INPUT_TEXT DIALOGUE_TITLE + #ifndef __USE_GNU #define __USE_GNU 1 #endif +#ifndef __USE_MISC +#define __USE_MISC 1 +#endif + +#ifndef __USE_XOPEN_EXTENDED +#define __USE_XOPEN_EXTENDED 1 +#endif + typedef struct params { unsigned short port; unsigned addr; diff --git a/src/query.c b/src/query.c index f3a571b..97c4f92 100644 --- a/src/query.c +++ b/src/query.c @@ -184,6 +184,9 @@ int process_query(query_args_t *query_args, file_args_t *file_args) { case S_ASK_SEVER_IP: case S_ASK_LOGIN_TYPE: case S_N_D: + case S_ASK_LOGIN_USER: + case S_PRINT_SERVER_MESSAGE: + case S_UPLOAD_FILE_SELECT: break; } return 0; diff --git a/src/server.c b/src/server.c index 0c0622d..383413e 100644 --- a/src/server.c +++ b/src/server.c @@ -26,8 +26,6 @@ void ask_register(params_t *params, char *email); int process_server_command(char *line, int l_len, query_args_t *q_args) { int ws_pos = l_len; params_t *params = q_args->params; - const char *login_options[] = {"Username", "Anonymous", "Register", NULL}; - uint32_t answer; uint64_t new_capacity; ui_file_list_t *fui = (ui_file_list_t *)q_args->file_list_ui; char query[INBUFSIZE]; @@ -130,33 +128,6 @@ int process_server_command(char *line, int l_len, query_args_t *q_args) { return 0; } -static void file_receive(int sd, char *line) { - char fname[128]; - char command[32]; - size_t fsize; - sscanf(line, "%s %s %zu", command, fname, &fsize); - char buf[INBUFSIZE]; - int rlen; - - int file_d = open(fname, O_WRONLY); - - if (file_d == -1) { - char err_mes[256]; - int mlen; - mlen = sprintf(err_mes, "Can't write file named \"%s\"\n", fname); - write(sd, err_mes, mlen); - close(file_d); - return; - } - - while (fsize && (rlen = read(sd, buf, INBUFSIZE))) { - write(file_d, buf, rlen); - fsize -= rlen; - } - - close(file_d); -} - void ask_uname_and_password(params_t *params) { size_t lsize; char *bufptr = NULL; diff --git a/src/ui/widget.c b/src/ui/widget.c index d1b6f8f..9277614 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c @@ -21,10 +21,9 @@ void init_widget(widget_t *w, widget_t *w_parent, WINDOW **win, char *title) { } int32_t get_max_line_len(const char *text, uint32_t *line_count) { - uint32_t nl_pos = 0; // new line position - uint32_t c_start = 0; // current line start position - uint32_t c_len = 0; // current line length - uint32_t m_len = 0; // max length + uint32_t nl_pos = 0; /* new line position */ + uint32_t c_len = 0; /* current line length */ + uint32_t m_len = 0; /* max length */ uint32_t line_num = 1; for (int i = 0; text[i] != '\0'; i++, c_len++) { if (text[i] == '\n') { @@ -32,7 +31,6 @@ int32_t get_max_line_len(const char *text, uint32_t *line_count) { m_len = c_len; } nl_pos = i; - c_start = i + 1; c_len = 0; line_num++; } @@ -109,8 +107,6 @@ uint32_t print_multiline_text(WINDOW *win, const char *_text, int32_t rsize_to_value(int32_t size, enum rsize rsize) { switch (rsize) { - case s_auto: - return size; case s_1: return size; case s_1_2: @@ -123,5 +119,8 @@ int32_t rsize_to_value(int32_t size, enum rsize rsize) { return size / 4; case s_3_4: return size / 4 * 3; + case s_auto: + default: + return size; } } \ No newline at end of file diff --git a/src/ui/widget/dialogue.c b/src/ui/widget/dialogue.c index 1f63d27..ea8966d 100644 --- a/src/ui/widget/dialogue.c +++ b/src/ui/widget/dialogue.c @@ -56,10 +56,8 @@ widget_t *get_active_widget(dialogue_t *d) { void dialogue_default_callback(callback_args_t *args) { dialogue_t *d = (void *)args->element; int32_t key = *((int32_t *)args->data); - app_t *app = (app_t *)args->app; callback_args_t new_args; int32_t *resp_value = (int32_t *)args->resp_data; - group_el_t *default_element = NULL; memcpy(&new_args, args, sizeof(callback_args_t)); new_args.active_id = d->active.id; int32_t diff; @@ -120,7 +118,7 @@ void dialogue_default_callback(callback_args_t *args) { break; } /* Default cases */ if (d->active.type == g_action) { - new_args.element = new_args.element = d->g_action; + new_args.element = d->g_action; group_default_callback(&new_args); } else if (d->g_action != NULL) { for (int i = 0; i < d->g_action->count; i++) { @@ -156,9 +154,9 @@ void dialogue_default_callback(callback_args_t *args) { default: /* run callback function */ if (d->active.type == g_content) { - new_args.element = new_args.element = d->g_content; + new_args.element = d->g_content; } else { - new_args.element = new_args.element = d->g_action; + new_args.element = d->g_action; } group_default_callback(&new_args); } @@ -317,8 +315,9 @@ int32_t draw_dialogue(dialogue_t *d) { if (d->g_content != NULL) { FIND_ACTIVE_ELEMENT(d->g_content, d->active.id, ae_ptr, ae_idx); } - if (ae_ptr == NULL && d->g_action != NULL) + if (ae_ptr == NULL && d->g_action != NULL) { FIND_ACTIVE_ELEMENT(d->g_action, d->active.id, ae_ptr, ae_idx); + } if (ae_ptr != NULL && ae_ptr->id == d->active.id) { if (ae_ptr->type == w_input) { @@ -338,7 +337,7 @@ int32_t draw_dialogue(dialogue_t *d) { d->needs_update = false; return 0; -}; +} void destroy_dialogue(dialogue_t *d, void *_app) { app_t *app = (app_t *)_app; diff --git a/src/ui/widget/file_list.c b/src/ui/widget/file_list.c index d0a3111..118a200 100644 --- a/src/ui/widget/file_list.c +++ b/src/ui/widget/file_list.c @@ -20,8 +20,6 @@ void file_list_cb(callback_args_t *args) { int32_t key = *((int32_t *)args->data); char query[256]; int32_t q_len = 0; - fl_item_t *f_item; - ui_progress_bar_t *pb; switch (key) { case KEY_DOWN: if (fui->current_idx < fui->current_count - 1) { @@ -128,7 +126,7 @@ void draw_file_list(ui_file_list_t *fl_ui) { mvwprintw(parent_win, p_y, p_x, "%*s", sz_x - 1, ""); } char p_info[64]; - uint32_t p_len; + int32_t p_len; p_x = 1; sprintf(p_info, "page: %u/%u files: %u left: %u%n", fl_ui->current_page, diff --git a/src/ui/widget/fs_file_list.c b/src/ui/widget/fs_file_list.c index 12de02a..f21b0da 100644 --- a/src/ui/widget/fs_file_list.c +++ b/src/ui/widget/fs_file_list.c @@ -55,7 +55,7 @@ static void fl_clear(fs_fl_item_t **start, fs_fl_item_t **arg_current) { fs_fl_item_t *get_files_from_fs(char *path) { DIR *dir; struct dirent *dent; - char name[64]; + char name[257]; struct fl_args f_args; fs_fl_item_t *d_start = NULL, *d_current = NULL; /* directories */ @@ -118,9 +118,6 @@ void select_item(ui_fs_file_list_t *fui, int32_t *resp_data) { void fs_file_list_cb(callback_args_t *args) { ui_fs_file_list_t *fui = args->element; int32_t key = *((int32_t *)args->data); - int32_t q_len = 0; - fs_fl_item_t *f_item; - ui_progress_bar_t *pb; switch (key) { case KEY_DOWN: if (fui->current->next != NULL) { @@ -169,7 +166,6 @@ void draw_fs_file_list(ui_fs_file_list_t *fl_ui) { p_y = 1; p_x = 1; fs_fl_item_t *el = fl_ui->start; - fs_fl_item_t *active_el = fl_ui->start; if (fl_ui->current_idx + 1 >= sz_y_f) { p_y -= fl_ui->current_idx - sz_y_f + 2; @@ -184,7 +180,6 @@ void draw_fs_file_list(ui_fs_file_list_t *fl_ui) { } if (el == fl_ui->current) { wattrset(win, COLOR_PAIR(3) | A_BOLD | A_REVERSE); - active_el = el; } p_x = 1; mvwprintw(win, p_y, p_x, "%s%n", el->name, &p_x); diff --git a/src/ui/widget/group.c b/src/ui/widget/group.c index e39dd06..c8b5971 100644 --- a/src/ui/widget/group.c +++ b/src/ui/widget/group.c @@ -145,8 +145,6 @@ group_t *init_group(WINDOW **win, widget_t *w_parent, group_el_init_t *children, void draw_group(WINDOW *win, group_t *group, int32_t active_id, widget_t *dialog_w) { group_el_t *children = group->elements; - group_el_t *active_element = NULL; - uint32_t active_idx; for (int i = 0; i < group->count; i++) { group_el_t *el = &children[i]; switch (el->type) { diff --git a/src/ui/widget/input.c b/src/ui/widget/input.c index a9e36a9..6daaf39 100644 --- a/src/ui/widget/input.c +++ b/src/ui/widget/input.c @@ -56,7 +56,6 @@ int32_t draw_input(input_t *input, uint32_t active_id) { wattrset(win, COLOR_PAIR(0) | A_BOLD); } - uint32_t x_c = 0; if (input->is_hidden) { mvwprintw(win, margin_y + 1, margin_x, "%.*s%*s", (int) input->value_len, stars, input->w.x - input->value_len - 2, "");