(input_get_ctext): mew API.

Use it instead of direct access to WInput's buffer.

(handle_cmdline_enter): additional minor refactoring.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2022-08-04 09:44:55 +03:00
parent 28154dc520
commit 79645187c6
7 changed files with 38 additions and 16 deletions

View File

@ -121,6 +121,21 @@ input_get_text (const WInput * in)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/**
* Get pointer to input line buffer.
*
* @param in input line
*
* @return pointer to @in->buffer->str.
*/
static inline const char *
input_get_ctext (const WInput * in)
{
return in->buffer->str;
}
/* --------------------------------------------------------------------------------------------- */
/** /**
* Is input line empty or not. * Is input line empty or not.
* *

View File

@ -599,7 +599,7 @@ quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip)
case quick_input: case quick_input:
if ((item->quick_widget->u.input.completion_flags & INPUT_COMPLETE_CD) != 0) if ((item->quick_widget->u.input.completion_flags & INPUT_COMPLETE_CD) != 0)
*item->quick_widget->u.input.result = *item->quick_widget->u.input.result =
tilde_expand (INPUT (item->widget)->buffer->str); tilde_expand (input_get_ctext (INPUT (item->widget)));
else else
*item->quick_widget->u.input.result = input_get_text (INPUT (item->widget)); *item->quick_widget->u.input.result = input_get_text (INPUT (item->widget));
break; break;

View File

@ -622,7 +622,7 @@ view_filtered_cmd (const WPanel * panel)
if (input_is_empty (cmdline)) if (input_is_empty (cmdline))
initial_command = selection (panel)->fname->str; initial_command = selection (panel)->fname->str;
else else
initial_command = cmdline->buffer->str; initial_command = input_get_ctext (cmdline);
command = command =
input_dialog (_("Filtered view"), input_dialog (_("Filtered view"),

View File

@ -81,11 +81,13 @@ static input_colors_t command_colors;
static cb_ret_t static cb_ret_t
enter (WInput * lc_cmdline) enter (WInput * lc_cmdline)
{ {
const char *cmd = lc_cmdline->buffer->str; const char *cmd;
if (!command_prompt) if (!command_prompt)
return MSG_HANDLED; return MSG_HANDLED;
cmd = input_get_ctext (lc_cmdline);
/* Any initial whitespace should be removed at this point */ /* Any initial whitespace should be removed at this point */
while (whiteness (*cmd)) while (whiteness (*cmd))
cmd++; cmd++;

View File

@ -1460,12 +1460,12 @@ is_cmdline_mute (void)
static gboolean static gboolean
handle_cmdline_enter (void) handle_cmdline_enter (void)
{ {
size_t i; const char *s;
for (i = 0; i < cmdline->buffer->len && whitespace (cmdline->buffer->str[i]); i++) for (s = input_get_ctext (cmdline); *s != '\0' && whitespace (*s); s++)
; ;
if (i != cmdline->buffer->len) if (*s != '\0')
{ {
send_message (cmdline, NULL, MSG_KEY, '\n', NULL); send_message (cmdline, NULL, MSG_KEY, '\n', NULL);
return TRUE; return TRUE;

View File

@ -501,7 +501,7 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
/* check filename regexp */ /* check filename regexp */
if (!file_pattern_cbox->state && !input_is_empty (in_name) if (!file_pattern_cbox->state && !input_is_empty (in_name)
&& !find_check_regexp (in_name->buffer->str)) && !find_check_regexp (input_get_ctext (in_name)))
{ {
/* Don't stop the dialog */ /* Don't stop the dialog */
widget_set_state (w, WST_ACTIVE, TRUE); widget_set_state (w, WST_ACTIVE, TRUE);
@ -512,7 +512,7 @@ find_parm_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, voi
/* check content regexp */ /* check content regexp */
if (content_regexp_cbox->state && !content_is_empty if (content_regexp_cbox->state && !content_is_empty
&& !find_check_regexp (in_with->buffer->str)) && !find_check_regexp (input_get_ctext (in_with)))
{ {
/* Don't stop the dialog */ /* Don't stop the dialog */
widget_set_state (w, WST_ACTIVE, TRUE); widget_set_state (w, WST_ACTIVE, TRUE);
@ -783,12 +783,15 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len,
case B_TREE: case B_TREE:
{ {
const char *start_cstr;
const char *temp_dir; const char *temp_dir;
if (input_is_empty (in_start) || DIR_IS_DOT (in_start->buffer->str)) start_cstr = input_get_ctext (in_start);
if (input_is_empty (in_start) || DIR_IS_DOT (start_cstr))
temp_dir = vfs_path_as_str (panel->cwd_vpath); temp_dir = vfs_path_as_str (panel->cwd_vpath);
else else
temp_dir = in_start->buffer->str; temp_dir = start_cstr;
if (in_start_dir != INPUT_LAST_TEXT) if (in_start_dir != INPUT_LAST_TEXT)
g_free (in_start_dir); g_free (in_start_dir);
@ -828,7 +831,7 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len,
*pattern = g_strdup (options.file_pattern ? "*" : ".*"); *pattern = g_strdup (options.file_pattern ? "*" : ".*");
else else
*pattern = input_get_text (in_name); *pattern = input_get_text (in_name);
*start_dir = !input_is_empty (in_start) ? in_start->buffer->str : (char *) "."; *start_dir = (char *) (!input_is_empty (in_start) ? input_get_ctext (in_start) : ".");
if (in_start_dir != INPUT_LAST_TEXT) if (in_start_dir != INPUT_LAST_TEXT)
g_free (in_start_dir); g_free (in_start_dir);
in_start_dir = g_strdup (*start_dir); in_start_dir = g_strdup (*start_dir);
@ -859,7 +862,7 @@ find_parameters (WPanel * panel, char **start_dir, ssize_t * start_dir_len,
} }
if (!options.ignore_dirs_enable || input_is_empty (in_ignore) if (!options.ignore_dirs_enable || input_is_empty (in_ignore)
|| DIR_IS_DOT (in_ignore->buffer->str)) || DIR_IS_DOT (input_get_ctext (in_ignore)))
*ignore_dirs = NULL; *ignore_dirs = NULL;
else else
*ignore_dirs = input_get_text (in_ignore); *ignore_dirs = input_get_text (in_ignore);

View File

@ -1462,21 +1462,23 @@ invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath)
if (use_persistent_buffer) if (use_persistent_buffer)
{ {
const char *s;
size_t i; size_t i;
int pos; int pos;
s = input_get_ctext (cmdline);
/* Check to make sure there are no non text characters in the command buffer, /* Check to make sure there are no non text characters in the command buffer,
* such as tab, or newline, as this could cause problems. */ * such as tab, or newline, as this could cause problems. */
for (i = 0; i < cmdline->buffer->len; i++) for (i = 0; i < cmdline->buffer->len; i++)
if ((unsigned char) cmdline->buffer->str[i] < 32 if ((unsigned char) s[i] < 32 || (unsigned char) s[i] == 127)
|| (unsigned char) cmdline->buffer->str[i] == 127)
g_string_overwrite_len (cmdline->buffer, i, " ", 1); g_string_overwrite_len (cmdline->buffer, i, " ", 1);
/* Write the command buffer to the subshell. */ /* Write the command buffer to the subshell. */
write_all (mc_global.tty.subshell_pty, cmdline->buffer->str, cmdline->buffer->len); write_all (mc_global.tty.subshell_pty, s, cmdline->buffer->len);
/* Put the cursor in the correct place in the subshell. */ /* Put the cursor in the correct place in the subshell. */
pos = str_length (cmdline->buffer->str) - cmdline->point; pos = str_length (s) - cmdline->point;
for (i = 0; i < (size_t) pos; i++) for (i = 0; i < (size_t) pos; i++)
write_all (mc_global.tty.subshell_pty, ESC_STR "[D", 3); write_all (mc_global.tty.subshell_pty, ESC_STR "[D", 3);
} }