diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:11:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:11:51 +0000 |
commit | a6f3675fc4e21b3f899286b9a02005368d913f74 (patch) | |
tree | c9bfa92b223783ff03b8e941c3bb0d36c68d3b5e /lib/tty | |
parent | Releasing progress-linux version 3:4.8.30-1~progress7.99u1. (diff) | |
download | mc-a6f3675fc4e21b3f899286b9a02005368d913f74.tar.xz mc-a6f3675fc4e21b3f899286b9a02005368d913f74.zip |
Merging upstream version 3:4.8.31.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/tty')
-rw-r--r-- | lib/tty/Makefile.in | 2 | ||||
-rw-r--r-- | lib/tty/color-internal.c | 6 | ||||
-rw-r--r-- | lib/tty/color-internal.h | 11 | ||||
-rw-r--r-- | lib/tty/color-ncurses.c | 14 | ||||
-rw-r--r-- | lib/tty/color-slang.c | 14 | ||||
-rw-r--r-- | lib/tty/color.c | 109 | ||||
-rw-r--r-- | lib/tty/color.h | 18 | ||||
-rw-r--r-- | lib/tty/key.c | 36 | ||||
-rw-r--r-- | lib/tty/keyxdef.c | 2 | ||||
-rw-r--r-- | lib/tty/mouse.c | 2 | ||||
-rw-r--r-- | lib/tty/tty-internal.c | 2 | ||||
-rw-r--r-- | lib/tty/tty-ncurses.c | 2 | ||||
-rw-r--r-- | lib/tty/tty-slang.c | 2 | ||||
-rw-r--r-- | lib/tty/tty.c | 2 | ||||
-rw-r--r-- | lib/tty/win.c | 2 | ||||
-rw-r--r-- | lib/tty/x11conn.c | 2 |
16 files changed, 107 insertions, 119 deletions
diff --git a/lib/tty/Makefile.in b/lib/tty/Makefile.in index 0aa0af8..26f9901 100644 --- a/lib/tty/Makefile.in +++ b/lib/tty/Makefile.in @@ -137,7 +137,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-sfs.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-ftp.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-sftp.m4 \ - $(top_srcdir)/m4.include/vfs/mc-vfs-fish.m4 \ + $(top_srcdir)/m4.include/vfs/mc-vfs-shell.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-undelfs.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-tarfs.m4 \ $(top_srcdir)/m4.include/vfs/mc-vfs-cpiofs.m4 \ diff --git a/lib/tty/color-internal.c b/lib/tty/color-internal.c index 8db2b6c..16b76ef 100644 --- a/lib/tty/color-internal.c +++ b/lib/tty/color-internal.c @@ -1,7 +1,7 @@ /* Internal stuff of color setup - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -184,9 +184,9 @@ tty_color_get_name_by_index (int idx) char name[9]; if (idx < 256) - sprintf (name, "color%d", idx); + g_snprintf (name, sizeof (name), "color%d", idx); else - sprintf (name, "#%06X", (unsigned int) idx & 0xFFFFFF); + g_snprintf (name, sizeof (name), "#%06X", (unsigned int) idx & 0xFFFFFF); return g_intern_string (name); } return "default"; diff --git a/lib/tty/color-internal.h b/lib/tty/color-internal.h index dc85225..a9b8d69 100644 --- a/lib/tty/color-internal.h +++ b/lib/tty/color-internal.h @@ -31,14 +31,15 @@ typedef enum { /*** structures declarations (and typedefs of structures)*****************************************/ -typedef struct mc_color_pair_struct +/* Screen library specific color pair */ +typedef struct { - int ifg; - int ibg; + int fg; + int bg; int attr; size_t pair_index; gboolean is_temp; -} tty_color_pair_t; +} tty_color_lib_pair_t; /*** global variables defined in .c file *********************************************************/ @@ -54,7 +55,7 @@ int tty_attr_get_bits (const char *attrs); void tty_color_init_lib (gboolean disable, gboolean force); void tty_color_deinit_lib (void); -void tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair); +void tty_color_try_alloc_lib_pair (tty_color_lib_pair_t * mc_color_pair); /*** inline functions ****************************************************************************/ diff --git a/lib/tty/color-ncurses.c b/lib/tty/color-ncurses.c index f01d697..055a3af 100644 --- a/lib/tty/color-ncurses.c +++ b/lib/tty/color-ncurses.c @@ -1,7 +1,7 @@ /* Color setup for NCurses screen library - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -103,7 +103,7 @@ color_get_attr (int color_pair) /* --------------------------------------------------------------------------------------------- */ static void -mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair, +mc_tty_color_pair_init_special (tty_color_lib_pair_t * mc_color_pair, int fg1, int bg1, int fg2, int bg2, int attr) { if (has_colors () && !mc_tty_color_disable) @@ -145,11 +145,11 @@ tty_color_deinit_lib (void) /* --------------------------------------------------------------------------------------------- */ void -tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) +tty_color_try_alloc_lib_pair (tty_color_lib_pair_t * mc_color_pair) { - if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) + if (mc_color_pair->fg <= (int) SPEC_A_REVERSE) { - switch (mc_color_pair->ifg) + switch (mc_color_pair->fg) { case SPEC_A_REVERSE: mc_tty_color_pair_init_special (mc_color_pair, @@ -179,8 +179,8 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) { int ifg, ibg, attr; - ifg = mc_color_pair->ifg; - ibg = mc_color_pair->ibg; + ifg = mc_color_pair->fg; + ibg = mc_color_pair->bg; attr = mc_color_pair->attr; /* In legacy color mode, change bright colors into bold */ diff --git a/lib/tty/color-slang.c b/lib/tty/color-slang.c index 5dd2663..33344b5 100644 --- a/lib/tty/color-slang.c +++ b/lib/tty/color-slang.c @@ -1,7 +1,7 @@ /* Color setup for S_Lang screen library - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -99,7 +99,7 @@ has_colors (gboolean disable, gboolean force) /* --------------------------------------------------------------------------------------------- */ static void -mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair, +mc_tty_color_pair_init_special (tty_color_lib_pair_t * mc_color_pair, const char *fg1, const char *bg1, const char *fg2, const char *bg2, SLtt_Char_Type mask) { @@ -145,11 +145,11 @@ tty_color_deinit_lib (void) /* --------------------------------------------------------------------------------------------- */ void -tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) +tty_color_try_alloc_lib_pair (tty_color_lib_pair_t * mc_color_pair) { - if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) + if (mc_color_pair->fg <= (int) SPEC_A_REVERSE) { - switch (mc_color_pair->ifg) + switch (mc_color_pair->fg) { case SPEC_A_REVERSE: mc_tty_color_pair_init_special (mc_color_pair, @@ -176,8 +176,8 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) { const char *fg, *bg; - fg = tty_color_get_name_by_index (mc_color_pair->ifg); - bg = tty_color_get_name_by_index (mc_color_pair->ibg); + fg = tty_color_get_name_by_index (mc_color_pair->fg); + bg = tty_color_get_name_by_index (mc_color_pair->bg); SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg); SLtt_add_color_attribute (mc_color_pair->pair_index, mc_color_pair->attr); } diff --git a/lib/tty/color.c b/lib/tty/color.c index c79e13a..78d50b7 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -2,7 +2,7 @@ Color setup. Interface functions. - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -46,9 +46,15 @@ /*** global variables ****************************************************************************/ -static char *tty_color_defaults__fg = NULL; -static char *tty_color_defaults__bg = NULL; -static char *tty_color_defaults__attrs = NULL; +/* *INDENT-OFF* */ +static tty_color_pair_t tty_color_defaults = +{ + .fg = NULL, + .bg = NULL, + .attrs = NULL, + .pair_index = 0 +}; +/* *INDENT-ON* */ /* Set if we are actually using colors */ gboolean use_colors = FALSE; @@ -67,25 +73,23 @@ static GHashTable *mc_tty_color__hashtable = NULL; /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -static gboolean -tty_color_free_condition_cb (gpointer key, gpointer value, gpointer user_data) +static void +mc_color__deinit (tty_color_pair_t * color) { - tty_color_pair_t *mc_color_pair = (tty_color_pair_t *) value; - gboolean is_temp_color; - - (void) key; - - is_temp_color = user_data != NULL; - return (mc_color_pair->is_temp == is_temp_color); + g_free (color->fg); + g_free (color->bg); + g_free (color->attrs); } /* --------------------------------------------------------------------------------------------- */ -static void -tty_color_free_all (gboolean is_temp_color) +static gboolean +tty_color_free_temp_cb (gpointer key, gpointer value, gpointer user_data) { - g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_condition_cb, - is_temp_color ? GSIZE_TO_POINTER (1) : NULL); + (void) key; + (void) user_data; + + return ((tty_color_lib_pair_t *) value)->is_temp; } /* --------------------------------------------------------------------------------------------- */ @@ -93,7 +97,7 @@ tty_color_free_all (gboolean is_temp_color) static gboolean tty_color_get_next_cpn_cb (gpointer key, gpointer value, gpointer user_data) { - tty_color_pair_t *mc_color_pair = (tty_color_pair_t *) value; + tty_color_lib_pair_t *mc_color_pair = (tty_color_lib_pair_t *) value; size_t cp = GPOINTER_TO_SIZE (user_data); (void) key; @@ -134,10 +138,7 @@ void tty_colors_done (void) { tty_color_deinit_lib (); - g_free (tty_color_defaults__fg); - g_free (tty_color_defaults__bg); - g_free (tty_color_defaults__attrs); - + mc_color__deinit (&tty_color_defaults); g_hash_table_destroy (mc_tty_color__hashtable); } @@ -152,30 +153,27 @@ tty_use_colors (void) /* --------------------------------------------------------------------------------------------- */ int -tty_try_alloc_color_pair2 (const char *fg, const char *bg, const char *attrs, - gboolean is_temp_color) +tty_try_alloc_color_pair (const tty_color_pair_t * color, gboolean is_temp) { + gboolean is_base; gchar *color_pair; - tty_color_pair_t *mc_color_pair; + tty_color_lib_pair_t *mc_color_pair; int ifg, ibg, attr; - if (fg == NULL || strcmp (fg, "base") == 0) - fg = tty_color_defaults__fg; - if (bg == NULL || strcmp (bg, "base") == 0) - bg = tty_color_defaults__bg; - if (attrs == NULL || strcmp (attrs, "base") == 0) - attrs = tty_color_defaults__attrs; - - ifg = tty_color_get_index_by_name (fg); - ibg = tty_color_get_index_by_name (bg); - attr = tty_attr_get_bits (attrs); + is_base = (color->fg == NULL || strcmp (color->fg, "base") == 0); + ifg = tty_color_get_index_by_name (is_base ? tty_color_defaults.fg : color->fg); + is_base = (color->bg == NULL || strcmp (color->bg, "base") == 0); + ibg = tty_color_get_index_by_name (is_base ? tty_color_defaults.bg : color->bg); + is_base = (color->attrs == NULL || strcmp (color->attrs, "base") == 0); + attr = tty_attr_get_bits (is_base ? tty_color_defaults.attrs : color->attrs); color_pair = g_strdup_printf ("%d.%d.%d", ifg, ibg, attr); if (color_pair == NULL) return 0; mc_color_pair = - (tty_color_pair_t *) g_hash_table_lookup (mc_tty_color__hashtable, (gpointer) color_pair); + (tty_color_lib_pair_t *) g_hash_table_lookup (mc_tty_color__hashtable, + (gpointer) color_pair); if (mc_color_pair != NULL) { @@ -183,20 +181,20 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, const char *attrs, return mc_color_pair->pair_index; } - mc_color_pair = g_try_new0 (tty_color_pair_t, 1); + mc_color_pair = g_try_new0 (tty_color_lib_pair_t, 1); if (mc_color_pair == NULL) { g_free (color_pair); return 0; } - mc_color_pair->is_temp = is_temp_color; - mc_color_pair->ifg = ifg; - mc_color_pair->ibg = ibg; + mc_color_pair->is_temp = is_temp; + mc_color_pair->fg = ifg; + mc_color_pair->bg = ibg; mc_color_pair->attr = attr; mc_color_pair->pair_index = tty_color_get_next__color_pair_number (); - tty_color_try_alloc_pair_lib (mc_color_pair); + tty_color_try_alloc_lib_pair (mc_color_pair); g_hash_table_insert (mc_tty_color__hashtable, (gpointer) color_pair, (gpointer) mc_color_pair); @@ -205,40 +203,31 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, const char *attrs, /* --------------------------------------------------------------------------------------------- */ -int -tty_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs) -{ - return tty_try_alloc_color_pair2 (fg, bg, attrs, TRUE); -} - -/* --------------------------------------------------------------------------------------------- */ - void -tty_color_free_all_tmp (void) +tty_color_free_temp (void) { - tty_color_free_all (TRUE); + g_hash_table_foreach_remove (mc_tty_color__hashtable, tty_color_free_temp_cb, NULL); } /* --------------------------------------------------------------------------------------------- */ void -tty_color_free_all_non_tmp (void) +tty_color_free_all (void) { - tty_color_free_all (FALSE); + g_hash_table_remove_all (mc_tty_color__hashtable); } /* --------------------------------------------------------------------------------------------- */ void -tty_color_set_defaults (const char *fgcolor, const char *bgcolor, const char *attrs) +tty_color_set_defaults (const tty_color_pair_t * color) { - g_free (tty_color_defaults__fg); - g_free (tty_color_defaults__bg); - g_free (tty_color_defaults__attrs); + mc_color__deinit (&tty_color_defaults); - tty_color_defaults__fg = g_strdup (fgcolor); - tty_color_defaults__bg = g_strdup (bgcolor); - tty_color_defaults__attrs = g_strdup (attrs); + tty_color_defaults.fg = g_strdup (color->fg); + tty_color_defaults.bg = g_strdup (color->bg); + tty_color_defaults.attrs = g_strdup (color->attrs); + tty_color_defaults.pair_index = 0; } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/color.h b/lib/tty/color.h index 583cce3..e09516f 100644 --- a/lib/tty/color.h +++ b/lib/tty/color.h @@ -21,6 +21,14 @@ /*** typedefs(not structures) and defined constants **********************************************/ +typedef struct +{ + char *fg; + char *bg; + char *attrs; + size_t pair_index; +} tty_color_pair_t; + /*** enums ***************************************************************************************/ /*** structures declarations (and typedefs of structures)*****************************************/ @@ -33,18 +41,16 @@ void tty_init_colors (gboolean disable, gboolean force); void tty_colors_done (void); gboolean tty_use_colors (void); -int tty_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs); -int tty_try_alloc_color_pair2 (const char *fg, const char *bg, const char *attrs, - gboolean is_temp_color); +int tty_try_alloc_color_pair (const tty_color_pair_t * color, gboolean is_temp); -void tty_color_free_all_tmp (void); -void tty_color_free_all_non_tmp (void); +void tty_color_free_temp (void); +void tty_color_free_all (void); void tty_setcolor (int color); void tty_lowlevel_setcolor (int color); void tty_set_normal_attrs (void); -void tty_color_set_defaults (const char *fgcolor, const char *bgcolor, const char *attrs); +void tty_color_set_defaults (const tty_color_pair_t * color); extern gboolean tty_use_256colors (GError ** error); extern gboolean tty_use_truecolors (GError ** error); diff --git a/lib/tty/key.c b/lib/tty/key.c index 5671666..8e7770b 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -1,7 +1,7 @@ /* Keyboard support routines. - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: @@ -1173,28 +1173,19 @@ getch_with_timeout (unsigned int delay_us) /* --------------------------------------------------------------------------------------------- */ static void -learn_store_key (char *buffer, char **p, int c) +learn_store_key (GString * buffer, int c) { - if (*p - buffer > 253) - return; - if (c == ESC_CHAR) - { - *(*p)++ = '\\'; - *(*p)++ = 'e'; - } + g_string_append (buffer, "\\e"); else if (c < ' ') { - *(*p)++ = '^'; - *(*p)++ = c + 'a' - 1; + g_string_append_c (buffer, '^'); + g_string_append_c (buffer, c + 'a' - 1); } else if (c == '^') - { - *(*p)++ = '^'; - *(*p)++ = '^'; - } + g_string_append (buffer, "^^"); else - *(*p)++ = (char) c; + g_string_append_c (buffer, (char) c); } /* --------------------------------------------------------------------------------------------- */ @@ -2163,14 +2154,15 @@ learn_key (void) fd_set Read_FD_Set; gint64 end_time; int c; - char buffer[256]; - char *p = buffer; + GString *buffer; + + buffer = g_string_sized_new (16); tty_keypad (FALSE); /* disable interpreting keys by ncurses */ c = tty_lowlevel_getch (); while (c == -1) c = tty_lowlevel_getch (); /* Sanity check, should be unnecessary */ - learn_store_key (buffer, &p, c); + learn_store_key (buffer, c); end_time = g_get_monotonic_time () + LEARN_TIMEOUT * MC_USEC_PER_MSEC; @@ -2194,12 +2186,12 @@ learn_key (void) } if (c == -1) break; - learn_store_key (buffer, &p, c); + learn_store_key (buffer, c); } tty_keypad (TRUE); tty_nodelay (FALSE); - *p = '\0'; - return (buffer[0] != '\0' ? g_strdup (buffer) : NULL); + + return g_string_free (buffer, buffer->len == 0); #undef LEARN_TIMEOUT } diff --git a/lib/tty/keyxdef.c b/lib/tty/keyxdef.c index a496f67..4527161 100644 --- a/lib/tty/keyxdef.c +++ b/lib/tty/keyxdef.c @@ -3,7 +3,7 @@ /* Additional keyboard support routines. - Copyright (C) 1998-2023 + Copyright (C) 1998-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/mouse.c b/lib/tty/mouse.c index cf42287..574e349 100644 --- a/lib/tty/mouse.c +++ b/lib/tty/mouse.c @@ -1,7 +1,7 @@ /* Mouse managing - Copyright (C) 1994-2023 + Copyright (C) 1994-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty-internal.c b/lib/tty/tty-internal.c index c79301d..4693235 100644 --- a/lib/tty/tty-internal.c +++ b/lib/tty/tty-internal.c @@ -1,7 +1,7 @@ /* Internal stuff of the terminal controlling library. - Copyright (C) 2019-2023 + Copyright (C) 2019-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 08f663d..fa503da 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -2,7 +2,7 @@ Interface to the terminal controlling library. Ncurses wrapper. - Copyright (C) 2005-2023 + Copyright (C) 2005-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 3aa74de..752825b 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -2,7 +2,7 @@ Interface to the terminal controlling library. Slang wrapper. - Copyright (C) 2005-2023 + Copyright (C) 2005-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/tty.c b/lib/tty/tty.c index cae0a05..55ba0e9 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -1,7 +1,7 @@ /* Interface to the terminal controlling library. - Copyright (C) 2005-2023 + Copyright (C) 2005-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/win.c b/lib/tty/win.c index 45451a4..5ac8a5a 100644 --- a/lib/tty/win.c +++ b/lib/tty/win.c @@ -1,7 +1,7 @@ /* Terminal management xterm and rxvt support - Copyright (C) 1995-2023 + Copyright (C) 1995-2024 Free Software Foundation, Inc. Written by: diff --git a/lib/tty/x11conn.c b/lib/tty/x11conn.c index 20e201b..dfd6454 100644 --- a/lib/tty/x11conn.c +++ b/lib/tty/x11conn.c @@ -1,7 +1,7 @@ /* X11 support for the Midnight Commander. - Copyright (C) 2005-2023 + Copyright (C) 2005-2024 Free Software Foundation, Inc. Written by: |