file_list: double list integration [not finished]
This commit is contained in:
+2
-3
@@ -4,6 +4,7 @@
|
|||||||
#ifndef COMMON_H
|
#ifndef COMMON_H
|
||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
|
#include "dlist.h"
|
||||||
#include <d_array.h>
|
#include <d_array.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@@ -44,7 +45,6 @@ typedef struct fl_item {
|
|||||||
char *name;
|
char *name;
|
||||||
char *description;
|
char *description;
|
||||||
char *owner;
|
char *owner;
|
||||||
struct fl_item *next;
|
|
||||||
} fl_item_t;
|
} fl_item_t;
|
||||||
|
|
||||||
enum main_window_type {
|
enum main_window_type {
|
||||||
@@ -66,15 +66,14 @@ typedef struct main_window {
|
|||||||
int32_t b_keys_len;
|
int32_t b_keys_len;
|
||||||
} main_window_t;
|
} main_window_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct file_args {
|
typedef struct file_args {
|
||||||
int file_d;
|
int file_d;
|
||||||
fl_item_t f_selected;
|
fl_item_t f_selected;
|
||||||
fl_item_t *l_start;
|
fl_item_t *l_start;
|
||||||
fl_item_t *l_current;
|
fl_item_t *l_current;
|
||||||
|
dlist_t *f_list;
|
||||||
} file_args_t;
|
} file_args_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct params {
|
typedef struct params {
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
unsigned addr;
|
unsigned addr;
|
||||||
|
|||||||
+60
-52
@@ -2,8 +2,10 @@
|
|||||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||||
|
|
||||||
#include "alert.h"
|
#include "alert.h"
|
||||||
|
#include "dlist.h"
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <common.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
@@ -19,28 +21,24 @@
|
|||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <widget.h>
|
#include <widget.h>
|
||||||
#include <common.h>
|
|
||||||
#include <windows/file_list.h>
|
#include <windows/file_list.h>
|
||||||
|
|
||||||
#include "file_processor.h"
|
#include "file_processor.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
|
||||||
static void fl_add(fl_item_t **cur, fl_item_t **start, char *fname);
|
static void fl_add(dlist_t *fl_list, char *q_line);
|
||||||
fl_item_t *fl_select(fl_item_t *start, int num);
|
|
||||||
void fl_clear(fl_item_t **start, fl_item_t **current);
|
void fl_clear(fl_item_t **start, fl_item_t **current);
|
||||||
|
|
||||||
void file_list(file_args_t *f_args, query_args_t *q_args) {
|
void file_list(file_args_t *f_args, query_args_t *q_args) {
|
||||||
int32_t qlen;
|
int32_t qlen;
|
||||||
char *query = NULL;
|
char *query = NULL;
|
||||||
static char qbuf[INBUFSIZE * 2];
|
static char q_buf[INBUFSIZE * 2];
|
||||||
static int32_t qbuf_used = 0;
|
static int32_t qbuf_used = 0;
|
||||||
w_ui_file_list_t *fui = (w_ui_file_list_t *)q_args->main_ui->ui;
|
w_ui_file_list_t *fui = (w_ui_file_list_t *)q_args->main_ui->ui;
|
||||||
w_dialogue_t *d = (w_dialogue_t *)q_args->active_dialogue;
|
w_dialogue_t *d = (w_dialogue_t *)q_args->active_dialogue;
|
||||||
fui->start = &(f_args->l_start);
|
|
||||||
fui->current = &(f_args->l_current);
|
|
||||||
|
|
||||||
if (qbuf_used == 0)
|
if (qbuf_used == 0)
|
||||||
qbuf[0] = 0;
|
q_buf[0] = 0;
|
||||||
|
|
||||||
while ((qlen = query_extract_from_buf(q_args->buf, &(q_args->buf_used),
|
while ((qlen = query_extract_from_buf(q_args->buf, &(q_args->buf_used),
|
||||||
&query))) {
|
&query))) {
|
||||||
@@ -55,16 +53,16 @@ void file_list(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
q_args->state = WAIT_CLIENT;
|
q_args->state = WAIT_CLIENT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strcat(qbuf, query);
|
strcat(q_buf, query);
|
||||||
qbuf_used += strlen(qbuf);
|
qbuf_used += strlen(q_buf);
|
||||||
if (strchr(qbuf, '\n') == NULL)
|
if (strchr(q_buf, '\n') == NULL)
|
||||||
continue;
|
continue;
|
||||||
fl_add(&(f_args->l_current), &(f_args->l_start), qbuf);
|
fl_add(f_args->f_list, q_buf);
|
||||||
fui->current_count++;
|
fui->current_count++;
|
||||||
free(query);
|
free(query);
|
||||||
query = NULL;
|
query = NULL;
|
||||||
qbuf_used = 0;
|
qbuf_used = 0;
|
||||||
qbuf[0] = 0;
|
q_buf[0] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +72,7 @@ int32_t ui_file_select(file_args_t *f_args, query_args_t *q_args, int32_t idx) {
|
|||||||
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
&(f_args->f_selected); /* new copy of file struct (list be cleared) */
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
|
|
||||||
l_selected = fl_select(f_args->l_start, idx);
|
l_selected = NULL; /* TODO: FIX */
|
||||||
|
|
||||||
if (l_selected == NULL) {
|
if (l_selected == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -173,8 +171,8 @@ void file_download(file_args_t *f_args, query_args_t *q_args) {
|
|||||||
if (q_args->file->package_rest <= q_args->buf_used) {
|
if (q_args->file->package_rest <= q_args->buf_used) {
|
||||||
write_len = q_args->file->package_rest;
|
write_len = q_args->file->package_rest;
|
||||||
qlen = write(f_args->file_d, q_args->buf, write_len);
|
qlen = write(f_args->file_d, q_args->buf, write_len);
|
||||||
file_download_receive_after(qlen, q_args, f_args, d, pb)
|
file_download_receive_after(qlen, q_args, f_args, d,
|
||||||
if (q_args->file->signal == sig_continue) {
|
pb) if (q_args->file->signal == sig_continue) {
|
||||||
server_send_string(q_args, "continue %d\n", PACKAGE_SIZE * 10);
|
server_send_string(q_args, "continue %d\n", PACKAGE_SIZE * 10);
|
||||||
if (q_args->file->package_rest == 0) {
|
if (q_args->file->package_rest == 0) {
|
||||||
q_args->file->package_rest = PACKAGE_SIZE * 10;
|
q_args->file->package_rest = PACKAGE_SIZE * 10;
|
||||||
@@ -316,66 +314,77 @@ void clear_file_in_query(query_args_t *q_args) {
|
|||||||
q_args->file = NULL;
|
q_args->file = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_file_args(file_args_t *f_args) {
|
void init_file_args(file_args_t *f_args, app_t *app) {
|
||||||
|
w_ui_file_list_t *fui = NULL;
|
||||||
f_args->file_d = 0;
|
f_args->file_d = 0;
|
||||||
f_args->f_selected.name = NULL;
|
f_args->f_selected.name = NULL;
|
||||||
f_args->f_selected.next = NULL;
|
|
||||||
f_args->f_selected.size = 0;
|
f_args->f_selected.size = 0;
|
||||||
f_args->l_current = NULL;
|
f_args->l_current = NULL;
|
||||||
f_args->l_start = NULL;
|
f_args->l_start = NULL;
|
||||||
|
if (app->main_ui.type == mw_fl_server) {
|
||||||
|
fui = app->main_ui.ui;
|
||||||
|
if (fui != NULL) {
|
||||||
|
f_args->f_list = fui->f_list;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* work with file list */
|
static void fl_q_extract(fl_item_t *f, char *line) {
|
||||||
static void fl_add(fl_item_t **cur, fl_item_t **start, char *line) {
|
|
||||||
char fowner[32];
|
char fowner[32];
|
||||||
char *descr_begin = NULL;
|
char *descr_begin = NULL;
|
||||||
int h_len;
|
int h_len;
|
||||||
char *name_begin = strchr(line, '[') + 1;
|
char *name_begin = strchr(line, '[') + 1;
|
||||||
char *name_end = strchr(line, ']');
|
char *name_end = strchr(line, ']');
|
||||||
int name_len = name_end - name_begin;
|
int name_len = name_end - name_begin;
|
||||||
fl_item_t *fitem = malloc(sizeof(fl_item_t));
|
sscanf(name_end, "] %zu %s%n", &(f->size), fowner, &h_len);
|
||||||
sscanf(name_end, "] %zu %s%n", &(fitem->size), fowner, &h_len);
|
strncpy(f->name, name_begin, name_len);
|
||||||
/* file name */
|
f->name[name_len] = 0;
|
||||||
fitem->name = malloc((sizeof(char)) * (name_len + 1));
|
strcpy(f->owner, fowner);
|
||||||
strncpy(fitem->name, name_begin, name_len);
|
|
||||||
fitem->name[name_len] = 0;
|
|
||||||
/* file owner */
|
|
||||||
fitem->owner = malloc((sizeof(char)) * (strlen(fowner) + 1));
|
|
||||||
strcpy(fitem->owner, fowner);
|
|
||||||
/* file description */
|
|
||||||
descr_begin = name_end + h_len + 1;
|
descr_begin = name_end + h_len + 1;
|
||||||
if (strcmp(descr_begin, "\n")) {
|
if (strcmp(descr_begin, "\n")) {
|
||||||
int d_len = strlen(line) - h_len;
|
int d_len = strlen(line) - h_len;
|
||||||
fitem->description = malloc((sizeof(char)) * (d_len));
|
strcpy(f->description, descr_begin); // +1 to escape the dividing \32
|
||||||
strcpy(fitem->description, descr_begin); // +1 to escape the dividing \32
|
|
||||||
for (int i = 0; i < d_len; i++) {
|
for (int i = 0; i < d_len; i++) {
|
||||||
if (fitem->description[i] == '\a') {
|
if (f->description[i] == '\a') {
|
||||||
fitem->description[i] = '\n';
|
f->description[i] = '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fitem->description = NULL;
|
f->description = NULL;
|
||||||
}
|
}
|
||||||
/* fitem->description[strlen(line + line_pos)] = 0; */
|
|
||||||
fitem->next = NULL;
|
|
||||||
if (*cur != NULL) {
|
|
||||||
(*cur)->next = fitem;
|
|
||||||
} else {
|
|
||||||
*start = fitem;
|
|
||||||
}
|
|
||||||
*cur = fitem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fl_item_t *fl_select(fl_item_t *start, int num) {
|
static bool fl_add_cb(void *_dst, void *_src) {
|
||||||
fl_item_t *current = start;
|
fl_item_t *dst = _dst;
|
||||||
for (; num != 1; num--) {
|
fl_item_t *src = _src;
|
||||||
if (current->next != NULL) {
|
|
||||||
current = current->next;
|
dst->size = src->size;
|
||||||
} else {
|
|
||||||
return NULL;
|
dst->description = malloc(sizeof(char) * (strlen(src->description) + 1));
|
||||||
|
strcpy(dst->description, src->description);
|
||||||
|
|
||||||
|
dst->name = malloc(sizeof(char) * (strlen(src->name) + 1));
|
||||||
|
strcpy(dst->name, src->name);
|
||||||
|
|
||||||
|
dst->owner = malloc(sizeof(char) * (strlen(src->owner) + 1));
|
||||||
|
strcpy(dst->owner, src->owner);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return current;
|
/* work with file list */
|
||||||
|
static void fl_add(dlist_t *fl_list, char *q_line) {
|
||||||
|
fl_item_t f_item;
|
||||||
|
char f_description[INBUFSIZE * 100];
|
||||||
|
char f_owner[256];
|
||||||
|
char f_name[256];
|
||||||
|
f_item.description = f_description;
|
||||||
|
f_item.owner = f_owner;
|
||||||
|
f_item.name = f_name;
|
||||||
|
f_item.size = 0;
|
||||||
|
|
||||||
|
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) {
|
void fl_clear(fl_item_t **start, fl_item_t **arg_current) {
|
||||||
@@ -385,7 +394,6 @@ void fl_clear(fl_item_t **start, fl_item_t **arg_current) {
|
|||||||
current = *start;
|
current = *start;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
next = current->next;
|
|
||||||
free(current->description);
|
free(current->description);
|
||||||
free(current->name);
|
free(current->name);
|
||||||
free(current);
|
free(current);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
void file_list(file_args_t *f_args, query_args_t *q_args);
|
void file_list(file_args_t *f_args, query_args_t *q_args);
|
||||||
void file_download(file_args_t *f_args, query_args_t *q_args);
|
void file_download(file_args_t *f_args, query_args_t *q_args);
|
||||||
void init_file_args(file_args_t *fargs);
|
void init_file_args(file_args_t *fargs, app_t *app);
|
||||||
int file_upload_request(char *, query_args_t *q_args);
|
int file_upload_request(char *, query_args_t *q_args);
|
||||||
int file_upload_start(query_args_t *q_args);
|
int file_upload_start(query_args_t *q_args);
|
||||||
int file_upload(query_args_t *q_args);
|
int file_upload(query_args_t *q_args);
|
||||||
|
|||||||
+1
-1
@@ -54,7 +54,7 @@ void query_loop(app_t *app) {
|
|||||||
w_cb_args_t d_args = {
|
w_cb_args_t d_args = {
|
||||||
.app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none};
|
.app = app, .element = NULL, .data = NULL, .resp_data.code = cbrc_none};
|
||||||
|
|
||||||
init_file_args(&file_args);
|
init_file_args(&file_args, app);
|
||||||
query_args->sd = sd;
|
query_args->sd = sd;
|
||||||
app->file_args = &file_args;
|
app->file_args = &file_args;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "file_list.h"
|
#include "file_list.h"
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
|
#include "dlist.h"
|
||||||
#include "main_window.h"
|
#include "main_window.h"
|
||||||
#include <bstrlib.h>
|
#include <bstrlib.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
@@ -191,6 +192,11 @@ void *w_fl_init(app_t *app) {
|
|||||||
fui->w.sz.x = getmaxx(app->win);
|
fui->w.sz.x = getmaxx(app->win);
|
||||||
fui->w.sz.y = getmaxy(app->win);
|
fui->w.sz.y = getmaxy(app->win);
|
||||||
|
|
||||||
|
fui->f_list = dlist_init(NULL, fl_item_t, NULL);
|
||||||
|
if (app->file_args != NULL) {
|
||||||
|
app->file_args->f_list = fui->f_list;
|
||||||
|
}
|
||||||
|
|
||||||
/* * INIT UI * */
|
/* * INIT UI * */
|
||||||
|
|
||||||
/* define the width for each sub window */
|
/* define the width for each sub window */
|
||||||
@@ -240,8 +246,8 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
|||||||
sz_x -= 1; /* do not count the borders */
|
sz_x -= 1; /* do not count the borders */
|
||||||
p_y = 1;
|
p_y = 1;
|
||||||
p_x = 1;
|
p_x = 1;
|
||||||
fl_item_t *el = NULL;
|
fl_item_t *el = dlist_it_next(fui->f_list);
|
||||||
fl_item_t *active_el = NULL;
|
fl_item_t *active_el = dlist_get_ptr(fui->f_selected);
|
||||||
int32_t cur_el_idx = 0;
|
int32_t cur_el_idx = 0;
|
||||||
|
|
||||||
box(fui->win_list, 0, 0);
|
box(fui->win_list, 0, 0);
|
||||||
@@ -279,7 +285,7 @@ void w_fl_draw(w_ui_file_list_t *fui) {
|
|||||||
}
|
}
|
||||||
p_y++;
|
p_y++;
|
||||||
cur_el_idx++;
|
cur_el_idx++;
|
||||||
} while ((el = el->next) != NULL && p_y < sz_y_f);
|
} while ((el = dlist_it_next(fui->f_list)) != NULL && p_y < sz_y_f);
|
||||||
|
|
||||||
p_x = 1;
|
p_x = 1;
|
||||||
int32_t p_len;
|
int32_t p_len;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#ifndef W_FILE_LIST_H
|
#ifndef W_FILE_LIST_H
|
||||||
#define W_FILE_LIST_H
|
#define W_FILE_LIST_H
|
||||||
|
|
||||||
|
#include "dlist.h"
|
||||||
#include <bstrlib.h>
|
#include <bstrlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <widget_core.h>
|
#include <widget_core.h>
|
||||||
@@ -12,6 +13,8 @@ typedef struct {
|
|||||||
w_t w;
|
w_t w;
|
||||||
fl_item_t **current;
|
fl_item_t **current;
|
||||||
fl_item_t **start;
|
fl_item_t **start;
|
||||||
|
dlist_t *f_list;
|
||||||
|
dlist_node_t *f_selected;
|
||||||
int32_t current_idx;
|
int32_t current_idx;
|
||||||
int32_t current_count;
|
int32_t current_count;
|
||||||
int32_t full_count;
|
int32_t full_count;
|
||||||
|
|||||||
Reference in New Issue
Block a user