1
1

* subshell.c (subshell_name_quote): Eliminate sprintf(d, "%c", ...).

(do_subshell_chdir): Eliminate strlcpy() and optimize.
Этот коммит содержится в:
Andrew V. Samoilov 2005-01-14 10:00:29 +00:00
родитель d332606fd5
Коммит 50a2118525
2 изменённых файлов: 28 добавлений и 22 удалений

Просмотреть файл

@ -1,3 +1,8 @@
2005-01-14 Andrew V. Samoilov <sav@bcs.zp.ua>
* subshell.c (subshell_name_quote): Eliminate sprintf(d, "%c", ...).
(do_subshell_chdir): Eliminate strlcpy() and optimize.
2005-01-14 Pavel Shirshov <me@pavelsh.pp.ru> 2005-01-14 Pavel Shirshov <me@pavelsh.pp.ru>
* subshell.c (do_subshell_chdir): Use mc_realpath() to fix tcsh's * subshell.c (do_subshell_chdir): Use mc_realpath() to fix tcsh's

Просмотреть файл

@ -724,8 +724,7 @@ subshell_name_quote (const char *s)
for (; *s; s++) { for (; *s; s++) {
/* Must quote numbers, so that they are not glued to octals */ /* Must quote numbers, so that they are not glued to octals */
if (isalpha ((unsigned char) *s)) { if (isalpha ((unsigned char) *s)) {
sprintf (d, "%c", (unsigned char) *s); *d++ = (unsigned char) *s;
d += 1;
} else { } else {
sprintf (d, "\\%03o", (unsigned char) *s); sprintf (d, "\\%03o", (unsigned char) *s);
d += 4; d += 4;
@ -734,8 +733,7 @@ subshell_name_quote (const char *s)
} else { } else {
for (; *s; s++) { for (; *s; s++) {
if (isalnum ((unsigned char) *s)) { if (isalnum ((unsigned char) *s)) {
sprintf (d, "%c", (unsigned char) *s); *d++ = (unsigned char) *s;
d += 1;
} else { } else {
sprintf (d, "\\0%03o", (unsigned char) *s); sprintf (d, "\\0%03o", (unsigned char) *s);
d += 5; d += 5;
@ -753,8 +751,6 @@ subshell_name_quote (const char *s)
void void
do_subshell_chdir (const char *directory, int do_update, int reset_prompt) do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
{ {
int bPathNotEq;
if (! if (!
(subshell_state == INACTIVE (subshell_state == INACTIVE
&& strcmp (subshell_cwd, current_panel->cwd))) { && strcmp (subshell_cwd, current_panel->cwd))) {
@ -771,8 +767,7 @@ do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
because we set "HISTCONTROL=ignorespace") */ because we set "HISTCONTROL=ignorespace") */
write (subshell_pty, " cd ", 4); write (subshell_pty, " cd ", 4);
if (*directory) { if (*directory) {
char *temp; char *temp = subshell_name_quote (directory);
temp = subshell_name_quote (directory);
if (temp) { if (temp) {
write (subshell_pty, temp, strlen (temp)); write (subshell_pty, temp, strlen (temp));
g_free (temp); g_free (temp);
@ -789,25 +784,31 @@ do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
subshell_state = RUNNING_COMMAND; subshell_state = RUNNING_COMMAND;
feed_subshell (QUIETLY, FALSE); feed_subshell (QUIETLY, FALSE);
if (subshell_type == TCSH) { if (subshell_alive) {
int bPathNotEq = strcmp (subshell_cwd, current_panel->cwd);
if (bPathNotEq && subshell_type == TCSH) {
char rp_subshell_cwd[PATH_MAX]; char rp_subshell_cwd[PATH_MAX];
char rp_current_panel_cwd[PATH_MAX]; char rp_current_panel_cwd[PATH_MAX];
if (mc_realpath(subshell_cwd, rp_subshell_cwd) == NULL) char *p_subshell_cwd =
strlcpy(rp_subshell_cwd, subshell_cwd, PATH_MAX); mc_realpath (subshell_cwd, rp_subshell_cwd);
char *p_current_panel_cwd =
mc_realpath (current_panel->cwd, rp_current_panel_cwd);
if (mc_realpath(current_panel->cwd, rp_current_panel_cwd) == NULL) if (p_subshell_cwd == NULL)
strlcpy(rp_current_panel_cwd, current_panel->cwd, PATH_MAX); p_subshell_cwd = subshell_cwd;
if (p_current_panel_cwd == NULL)
p_current_panel_cwd = current_panel->cwd;
bPathNotEq = strcmp (p_subshell_cwd, p_current_panel_cwd);
}
bPathNotEq = strcmp (rp_subshell_cwd, rp_current_panel_cwd); if (bPathNotEq && strcmp (current_panel->cwd, ".")) {
} else bPathNotEq = strcmp (subshell_cwd, current_panel->cwd);
if (subshell_alive && bPathNotEq && strcmp (current_panel->cwd, ".")) {
char *cwd = strip_password (g_strdup (current_panel->cwd), 1); char *cwd = strip_password (g_strdup (current_panel->cwd), 1);
fprintf (stderr, _("Warning: Cannot change to %s.\n"), fprintf (stderr, _("Warning: Cannot change to %s.\n"), cwd);
cwd);
g_free (cwd); g_free (cwd);
} }
}
if (reset_prompt) if (reset_prompt)
prompt_pos = 0; prompt_pos = 0;