mirror of https://github.com/MidnightCommander/mc
(subshell_prompt): changed to GString.
(read_subshell_prompt): refactoring to ret rid of low-level memory reallocation. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
0e7810eb5f
commit
e35f044ccd
|
@ -816,7 +816,7 @@ setup_cmdline (void)
|
|||
|
||||
#ifdef ENABLE_SUBSHELL
|
||||
if (mc_global.tty.use_subshell)
|
||||
tmp_prompt = strip_ctrl_codes (subshell_prompt);
|
||||
tmp_prompt = strip_ctrl_codes (subshell_prompt->str);
|
||||
if (tmp_prompt == NULL)
|
||||
#endif
|
||||
tmp_prompt = (char *) mc_prompt;
|
||||
|
|
12
src/main.c
12
src/main.c
|
@ -376,16 +376,8 @@ main (int argc, char *argv[])
|
|||
if (mc_global.tty.alternate_plus_minus)
|
||||
application_keypad_mode ();
|
||||
|
||||
#ifdef ENABLE_SUBSHELL
|
||||
if (mc_global.tty.use_subshell)
|
||||
{
|
||||
mc_prompt = strip_ctrl_codes (subshell_prompt);
|
||||
if (mc_prompt == NULL)
|
||||
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
||||
}
|
||||
else
|
||||
#endif /* ENABLE_SUBSHELL */
|
||||
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
||||
/* subshell_prompt is NULL here */
|
||||
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
|
||||
|
||||
if (config_migrated)
|
||||
{
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
char *subshell_prompt = NULL;
|
||||
GString *subshell_prompt = NULL;
|
||||
|
||||
/* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
|
||||
/* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
|
||||
|
@ -984,24 +984,23 @@ invoke_subshell (const char *command, int how, vfs_path_t ** new_dir_vpath)
|
|||
gboolean
|
||||
read_subshell_prompt (void)
|
||||
{
|
||||
static int prompt_size = INITIAL_PROMPT_SIZE;
|
||||
int bytes = 0, i, rc = 0;
|
||||
int rc = 0;
|
||||
ssize_t bytes = 0;
|
||||
struct timeval timeleft = { 0, 0 };
|
||||
|
||||
fd_set tmp;
|
||||
FD_ZERO (&tmp);
|
||||
FD_SET (mc_global.tty.subshell_pty, &tmp);
|
||||
|
||||
/* First time through */
|
||||
if (subshell_prompt == NULL)
|
||||
{ /* First time through */
|
||||
subshell_prompt = g_malloc (prompt_size);
|
||||
*subshell_prompt = '\0';
|
||||
prompt_pos = 0;
|
||||
}
|
||||
subshell_prompt = g_string_sized_new (INITIAL_PROMPT_SIZE);
|
||||
|
||||
while (subshell_alive
|
||||
&& (rc = select (mc_global.tty.subshell_pty + 1, &tmp, NULL, NULL, &timeleft)))
|
||||
&& (rc = select (mc_global.tty.subshell_pty + 1, &tmp, NULL, NULL, &timeleft)) != 0)
|
||||
{
|
||||
ssize_t i;
|
||||
|
||||
/* Check for `select' errors */
|
||||
if (rc == -1)
|
||||
{
|
||||
|
@ -1020,23 +1019,12 @@ read_subshell_prompt (void)
|
|||
bytes = read (mc_global.tty.subshell_pty, pty_buffer, sizeof (pty_buffer));
|
||||
|
||||
/* Extract the prompt from the shell output */
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
g_string_set_size (subshell_prompt, 0);
|
||||
for (i = 0; i < bytes; i++)
|
||||
if (pty_buffer[i] == '\n' || pty_buffer[i] == '\r')
|
||||
{
|
||||
prompt_pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pty_buffer[i])
|
||||
continue;
|
||||
|
||||
subshell_prompt[prompt_pos++] = pty_buffer[i];
|
||||
if (prompt_pos == prompt_size)
|
||||
subshell_prompt = g_realloc (subshell_prompt, prompt_size *= 2);
|
||||
}
|
||||
|
||||
subshell_prompt[prompt_pos] = '\0';
|
||||
g_string_set_size (subshell_prompt, 0);
|
||||
else if (pty_buffer[i] != '\0')
|
||||
g_string_append_c (subshell_prompt, pty_buffer[i]);
|
||||
}
|
||||
|
||||
return (rc != 0 || bytes != 0);
|
||||
|
@ -1049,7 +1037,7 @@ do_update_prompt (void)
|
|||
{
|
||||
if (update_subshell_prompt)
|
||||
{
|
||||
printf ("\r\n%s", subshell_prompt);
|
||||
printf ("\r\n%s", subshell_prompt->str);
|
||||
fflush (stdout);
|
||||
update_subshell_prompt = FALSE;
|
||||
}
|
||||
|
@ -1077,7 +1065,7 @@ exit_subshell (void)
|
|||
tcsh_fifo, unix_error_string (errno));
|
||||
}
|
||||
|
||||
g_free (subshell_prompt);
|
||||
g_string_free (subshell_prompt, TRUE);
|
||||
subshell_prompt = NULL;
|
||||
pty_buffer[0] = '\0';
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ enum
|
|||
extern enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
extern char *subshell_prompt;
|
||||
extern GString *subshell_prompt;
|
||||
|
||||
extern gboolean update_subshell_prompt;
|
||||
|
||||
|
|
Loading…
Reference in New Issue