Share same code between update_xterm_title_path() and midnight_get_title() functions

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2011-11-28 23:18:56 +03:00
parent 2b5c28b316
commit ccfea7a142
3 changed files with 32 additions and 35 deletions

View File

@ -429,36 +429,18 @@ midnight_get_shortcut (unsigned long command)
static char *
midnight_get_title (const Dlg_head * h, size_t len)
{
/* TODO: share code with update_xterm_title_path() */
char *path_origin, *p;
char *path;
char host[BUF_TINY];
struct passwd *pw = NULL;
char *login = NULL;
int res = 0;
char *login;
char *p;
(void) h;
path_origin =
vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
title_path_prepare (&path, &login);
res = gethostname (host, sizeof (host));
if (res != 0)
host[0] = '\0';
else
host[sizeof (host) - 1] = '\0';
pw = getpwuid (getuid ());
if (pw != NULL)
login = g_strdup_printf ("%s@%s", pw->pw_name, host);
else
login = g_strdup (host);
p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path_origin);
g_free (path_origin);
path = g_strdup (str_trunc (p, len - 4));
p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path);
g_free (path);
g_free (login);
path = g_strdup (str_trunc (p, len - 4));
g_free (p);
return path;

View File

@ -334,23 +334,19 @@ load_prompt (int fd, void *unused)
/* --------------------------------------------------------------------------------------------- */
/** Show current directory in the xterm title */
void
update_xterm_title_path (void)
title_path_prepare (char **path, char **login)
{
/* TODO: share code with midnight_get_title () */
char *path;
char host[BUF_TINY];
char *p;
struct passwd *pw = NULL;
char *login = NULL;
int res = 0;
if (!(mc_global.tty.xterm_flag && xterm_title))
return;
*login = NULL;
path = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
*path =
vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
res = gethostname (host, sizeof (host));
if (res)
{ /* On success, res = 0 */
@ -363,12 +359,29 @@ update_xterm_title_path (void)
pw = getpwuid (getuid ());
if (pw)
{
login = g_strdup_printf ("%s@%s", pw->pw_name, host);
*login = g_strdup_printf ("%s@%s", pw->pw_name, host);
}
else
{
login = g_strdup (host);
*login = g_strdup (host);
}
}
/* --------------------------------------------------------------------------------------------- */
/** Show current directory in the xterm title */
void
update_xterm_title_path (void)
{
char *p;
char *path;
char *login;
if (!(mc_global.tty.xterm_flag && xterm_title))
return;
title_path_prepare (&path, &login);
p = g_strdup_printf ("mc [%s]:%s", login, path);
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
g_free (login);

View File

@ -93,6 +93,8 @@ int load_prompt (int fd, void *unused);
gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
void update_xterm_title_path (void);
void title_path_prepare (char **path, char **login);
/*** inline functions ****************************************************************************/
#endif /* MC__MAIN_H */