From f91d894f9b3c6b095d997aa5818ca0c0f73dc05b Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 23 Oct 2021 21:10:29 +0300 Subject: [PATCH] (input_get_text): new API. Signed-off-by: Andrew Borodin --- lib/widget/input.c | 19 +++++++++++++++++++ lib/widget/input.h | 1 + lib/widget/quick.c | 4 ++-- src/filemanager/find.c | 13 ++++++------- src/filemanager/panelize.c | 5 +++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/widget/input.c b/lib/widget/input.c index 528e89362..846c434cb 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -1193,6 +1193,25 @@ input_assign_text (WInput * in, const char *text) /* --------------------------------------------------------------------------------------------- */ +/** + * Get text of input line. + * + * @param in input line + * + * @return newly allocated string that contains a copy of @in's text. + * If @in is empty, return NULL. + */ +char * +input_get_text (const WInput * in) +{ + if (input_is_empty (in)) + return NULL; + + return g_strdup (in->buffer); +} + +/* --------------------------------------------------------------------------------------------- */ + gboolean input_is_empty (const WInput * in) { diff --git a/lib/widget/input.h b/lib/widget/input.h index 2a855424f..83553fa75 100644 --- a/lib/widget/input.h +++ b/lib/widget/input.h @@ -91,6 +91,7 @@ cb_ret_t input_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm void input_set_default_colors (void); cb_ret_t input_handle_char (WInput * in, int key); void input_assign_text (WInput * in, const char *text); +char *input_get_text (const WInput * in); gboolean input_is_empty (const WInput * in); void input_insert (WInput * in, const char *text, gboolean insert_extra_space); void input_set_point (WInput * in, int pos); diff --git a/lib/widget/quick.c b/lib/widget/quick.c index 9b0fff8e8..89e50c459 100644 --- a/lib/widget/quick.c +++ b/lib/widget/quick.c @@ -9,7 +9,7 @@ Radek Doulik, 1994, 1995 Jakub Jelinek, 1995 Andrej Borsenkow, 1995 - Andrew Borodin , 2009, 2010, 2011, 2012, 2013 + Andrew Borodin , 2009-2022 This file is part of the Midnight Commander. @@ -599,7 +599,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip) *item->quick_widget->u.input.result = tilde_expand (INPUT (item->widget)->buffer); else - *item->quick_widget->u.input.result = g_strdup (INPUT (item->widget)->buffer); + *item->quick_widget->u.input.result = input_get_text (INPUT (item->widget)); break; case quick_radio: diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 09208b938..fba893ee0 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -7,7 +7,7 @@ Written by: Miguel de Icaza, 1995 Slava Zanko , 2013 - Andrew Borodin , 2013 + Andrew Borodin , 2013-2022 This file is part of the Midnight Commander. @@ -820,12 +820,11 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len, options.skip_hidden = skip_hidden_cbox->state; options.ignore_dirs_enable = ignore_dirs_cbox->state; g_free (options.ignore_dirs); - options.ignore_dirs = g_strdup (in_ignore->buffer); + options.ignore_dirs = input_get_text (in_ignore); - *content = !input_is_empty (in_with) ? g_strdup (in_with->buffer) : NULL; - if (!input_is_empty (in_name)) - *pattern = g_strdup (in_name->buffer); - else + *content = input_get_text (in_with); + *pattern = input_get_text (in_name); + if (*pattern == NULL) *pattern = g_strdup (options.file_pattern ? "*" : ".*"); *start_dir = !input_is_empty (in_start) ? in_start->buffer : (char *) "."; if (in_start_dir != INPUT_LAST_TEXT) @@ -861,7 +860,7 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len, || DIR_IS_DOT (in_ignore->buffer)) *ignore_dirs = NULL; else - *ignore_dirs = g_strdup (in_ignore->buffer); + *ignore_dirs = input_get_text (in_ignore); find_save_options (); diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index b072d6519..3c64eaab8 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -7,6 +7,7 @@ Written by: Janne Kukonlehto, 1995 Jakub Jelinek, 1995 + Andrew Borodin 2011-2022 This file is part of the Midnight Commander. @@ -270,7 +271,7 @@ add2panelize_cmd (void) if (label == NULL || *label == '\0') g_free (label); else - add2panelize (label, g_strdup (pname->buffer)); + add2panelize (label, input_get_text (pname)); } } @@ -622,7 +623,7 @@ external_panelize (void) { char *cmd; - cmd = g_strdup (pname->buffer); + cmd = input_get_text (pname); widget_destroy (WIDGET (panelize_dlg)); do_external_panelize (cmd); g_free (cmd);