mirror of
https://github.com/MidnightCommander/mc
synced 2025-03-13 11:23:09 +03:00
(enter): use GString instead of hand-made memory (re)allocation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
1d3132c08f
commit
7c415f2ec5
@ -258,8 +258,8 @@ enter (WInput * lc_cmdline)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *command, *s;
|
GString *command;
|
||||||
size_t i, j, cmd_len;
|
size_t i;
|
||||||
|
|
||||||
if (!vfs_current_is_local ())
|
if (!vfs_current_is_local ())
|
||||||
{
|
{
|
||||||
@ -275,30 +275,25 @@ enter (WInput * lc_cmdline)
|
|||||||
return MSG_NOT_HANDLED;
|
return MSG_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
cmd_len = strlen (cmd);
|
command = g_string_sized_new (32);
|
||||||
command = g_malloc (cmd_len + 1);
|
|
||||||
command[0] = 0;
|
for (i = 0; cmd[i] != '\0'; i++)
|
||||||
for (i = j = 0; i < cmd_len; i++)
|
|
||||||
{
|
{
|
||||||
if (cmd[i] == '%')
|
if (cmd[i] != '%')
|
||||||
{
|
g_string_append_c (command, cmd[i]);
|
||||||
i++;
|
|
||||||
s = expand_format (NULL, cmd[i], TRUE);
|
|
||||||
command = g_realloc (command, j + strlen (s) + cmd_len - i + 1);
|
|
||||||
strcpy (command + j, s);
|
|
||||||
g_free (s);
|
|
||||||
j = strlen (command);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
command[j] = cmd[i];
|
char *s;
|
||||||
j++;
|
|
||||||
|
s = expand_format (NULL, cmd[++i], TRUE);
|
||||||
|
g_string_append (command, s);
|
||||||
|
g_free (s);
|
||||||
}
|
}
|
||||||
command[j] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input_clean (lc_cmdline);
|
input_clean (lc_cmdline);
|
||||||
shell_execute (command, 0);
|
shell_execute (command->str, 0);
|
||||||
g_free (command);
|
g_string_free (command, TRUE);
|
||||||
|
|
||||||
#ifdef ENABLE_SUBSHELL
|
#ifdef ENABLE_SUBSHELL
|
||||||
if ((quit & SUBSHELL_EXIT) != 0)
|
if ((quit & SUBSHELL_EXIT) != 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user