mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-05 11:04:42 +03:00
lib/tty/key.c: (SelectList): rename to select_t and refactor using GSList.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
870c1db722
commit
c6f269a2c3
108
lib/tty/key.c
108
lib/tty/key.c
@ -252,13 +252,12 @@ typedef struct
|
|||||||
} key_define_t;
|
} key_define_t;
|
||||||
|
|
||||||
/* File descriptor monitoring add/remove routines */
|
/* File descriptor monitoring add/remove routines */
|
||||||
typedef struct SelectList
|
typedef struct
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
select_fn callback;
|
select_fn callback;
|
||||||
void *info;
|
void *info;
|
||||||
struct SelectList *next;
|
} select_t;
|
||||||
} SelectList;
|
|
||||||
|
|
||||||
typedef enum KeySortType
|
typedef enum KeySortType
|
||||||
{
|
{
|
||||||
@ -522,7 +521,7 @@ static key_def *keys = NULL;
|
|||||||
static int input_fd;
|
static int input_fd;
|
||||||
static int disabled_channels = 0; /* Disable channels checking */
|
static int disabled_channels = 0; /* Disable channels checking */
|
||||||
|
|
||||||
static SelectList *select_list = NULL;
|
static GSList *select_list = NULL;
|
||||||
|
|
||||||
static int seq_buffer[SEQ_BUFFER_LEN];
|
static int seq_buffer[SEQ_BUFFER_LEN];
|
||||||
static int *seq_append = NULL;
|
static int *seq_append = NULL;
|
||||||
@ -548,9 +547,32 @@ static const size_t key_conv_tab_size = G_N_ELEMENTS (key_name_conv_tab) - 1;
|
|||||||
|
|
||||||
static const key_code_name_t *key_conv_tab_sorted[G_N_ELEMENTS (key_name_conv_tab) - 1];
|
static const key_code_name_t *key_conv_tab_sorted[G_N_ELEMENTS (key_name_conv_tab) - 1];
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
select_cmp_by_fd_set (gconstpointer a, gconstpointer b)
|
||||||
|
{
|
||||||
|
const select_t *s = (const select_t *) a;
|
||||||
|
const fd_set *f = (const fd_set *) b;
|
||||||
|
|
||||||
|
return (FD_ISSET (s->fd, f) ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
select_cmp_by_fd (gconstpointer a, gconstpointer b)
|
||||||
|
{
|
||||||
|
const select_t *s = (const select_t *) a;
|
||||||
|
const int fd = GPOINTER_TO_INT (b);
|
||||||
|
|
||||||
|
return (s->fd == fd ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
add_selects (fd_set * select_set)
|
add_selects (fd_set * select_set)
|
||||||
{
|
{
|
||||||
@ -558,10 +580,12 @@ add_selects (fd_set * select_set)
|
|||||||
|
|
||||||
if (disabled_channels == 0)
|
if (disabled_channels == 0)
|
||||||
{
|
{
|
||||||
SelectList *p;
|
GSList *s;
|
||||||
|
|
||||||
for (p = select_list; p != NULL; p = p->next)
|
for (s = select_list; s != NULL; s = g_slist_next (s))
|
||||||
{
|
{
|
||||||
|
select_t *p = (select_t *) s->data;
|
||||||
|
|
||||||
FD_SET (p->fd, select_set);
|
FD_SET (p->fd, select_set);
|
||||||
if (p->fd > top_fd)
|
if (p->fd > top_fd)
|
||||||
top_fd = p->fd;
|
top_fd = p->fd;
|
||||||
@ -576,25 +600,18 @@ add_selects (fd_set * select_set)
|
|||||||
static void
|
static void
|
||||||
check_selects (fd_set * select_set)
|
check_selects (fd_set * select_set)
|
||||||
{
|
{
|
||||||
if (disabled_channels == 0)
|
while (disabled_channels == 0)
|
||||||
{
|
{
|
||||||
gboolean retry;
|
GSList *s;
|
||||||
|
select_t *p;
|
||||||
|
|
||||||
do
|
s = g_slist_find_custom (select_list, select_set, select_cmp_by_fd_set);
|
||||||
{
|
if (s == NULL)
|
||||||
SelectList *p;
|
|
||||||
|
|
||||||
retry = FALSE;
|
|
||||||
for (p = select_list; p; p = p->next)
|
|
||||||
if (FD_ISSET (p->fd, select_set))
|
|
||||||
{
|
|
||||||
FD_CLR (p->fd, select_set);
|
|
||||||
(*p->callback) (p->fd, p->info);
|
|
||||||
retry = TRUE;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
p = (select_t *) s->data;
|
||||||
while (retry);
|
FD_CLR (p->fd, select_set);
|
||||||
|
p->callback (p->fd, p->info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1193,18 +1210,6 @@ k_dispose (key_def * k)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
|
||||||
s_dispose (SelectList * sel)
|
|
||||||
{
|
|
||||||
if (sel != NULL)
|
|
||||||
{
|
|
||||||
s_dispose (sel->next);
|
|
||||||
g_free (sel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
key_code_comparator_by_name (const void *p1, const void *p2)
|
key_code_comparator_by_name (const void *p1, const void *p2)
|
||||||
{
|
{
|
||||||
@ -1385,7 +1390,7 @@ void
|
|||||||
done_key (void)
|
done_key (void)
|
||||||
{
|
{
|
||||||
k_dispose (keys);
|
k_dispose (keys);
|
||||||
s_dispose (select_list);
|
g_slist_free_full (select_list, g_free);
|
||||||
|
|
||||||
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
#ifdef HAVE_TEXTMODE_X11_SUPPORT
|
||||||
if (x11_display)
|
if (x11_display)
|
||||||
@ -1398,14 +1403,14 @@ done_key (void)
|
|||||||
void
|
void
|
||||||
add_select_channel (int fd, select_fn callback, void *info)
|
add_select_channel (int fd, select_fn callback, void *info)
|
||||||
{
|
{
|
||||||
SelectList *new;
|
select_t *new;
|
||||||
|
|
||||||
new = g_new (SelectList, 1);
|
new = g_new (select_t, 1);
|
||||||
new->fd = fd;
|
new->fd = fd;
|
||||||
new->callback = callback;
|
new->callback = callback;
|
||||||
new->info = info;
|
new->info = info;
|
||||||
new->next = select_list;
|
|
||||||
select_list = new;
|
select_list = g_slist_prepend (select_list, new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -1413,28 +1418,11 @@ add_select_channel (int fd, select_fn callback, void *info)
|
|||||||
void
|
void
|
||||||
delete_select_channel (int fd)
|
delete_select_channel (int fd)
|
||||||
{
|
{
|
||||||
SelectList *p = select_list;
|
GSList *p;
|
||||||
SelectList *p_prev = NULL;
|
|
||||||
SelectList *p_next;
|
|
||||||
|
|
||||||
while (p != NULL)
|
p = g_slist_find_custom (select_list, GINT_TO_POINTER (fd), select_cmp_by_fd);
|
||||||
if (p->fd == fd)
|
if (p != NULL)
|
||||||
{
|
select_list = g_slist_delete_link (select_list, p);
|
||||||
p_next = p->next;
|
|
||||||
|
|
||||||
if (p_prev != NULL)
|
|
||||||
p_prev->next = p_next;
|
|
||||||
else
|
|
||||||
select_list = p_next;
|
|
||||||
|
|
||||||
g_free (p);
|
|
||||||
p = p_next;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p_prev = p;
|
|
||||||
p = p->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user