Use local buffers instead of global cmd_buf one.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2009-10-11 11:13:55 +04:00
parent 998001a22e
commit 42ba60cebe
4 changed files with 43 additions and 45 deletions

View File

@ -1,7 +1,7 @@
/* File management.
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007 Free Software Foundation, Inc.
Written by: 1994, 1995 Janne Kukonlehto
1994, 1995 Fred Leeflang
1994, 1995, 1996 Miguel de Icaza
@ -22,7 +22,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -66,7 +66,7 @@
#include "setup.h"
#include "dialog.h"
#include "widget.h"
#include "main.h" /* cmd_buf */
#include "main.h"
#include "layout.h"
#include "widget.h"
#include "wtools.h"
@ -1639,8 +1639,8 @@ static const char *op_names1[] = {
};
#define FMD_XLEN 64
int fmd_xlen = FMD_XLEN;
char fmd_buf [BUF_MEDIUM];
/*
* These are formats for building a prompt. Parts encoded as follows:
@ -1741,13 +1741,13 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
*dp = '\0';
if (single_source) {
i = fmd_xlen - str_term_width1 (format_string) - 4;
g_snprintf (cmd_buf, sizeof (cmd_buf), format_string,
i = fmd_xlen - str_term_width1 (format_string) - 4;
g_snprintf (fmd_buf, sizeof (fmd_buf), format_string,
str_trunc (single_source, i));
} else {
g_snprintf (cmd_buf, sizeof (cmd_buf), format_string,
g_snprintf (fmd_buf, sizeof (fmd_buf), format_string,
panel->marked);
i = str_term_width1 (cmd_buf) + 6 - fmd_xlen;
i = str_term_width1 (fmd_buf) + 6 - fmd_xlen;
if (i > 0) {
fmd_xlen += i;
}
@ -1758,7 +1758,7 @@ panel_operate_generate_prompt (const WPanel *panel, const int operation,
* panel_operate:
*
* Performs one of the operations on the selection on the source_panel
* (copy, delete, move).
* (copy, delete, move).
*
* Returns 1 if did change the directory
* structure, Returns 0 if user aborted
@ -1796,13 +1796,11 @@ panel_operate (void *source_panel, FileOperation operation,
free_linklist (&linklist);
free_linklist (&dest_dirs);
#if 0
/* Update panel contents to avoid actions on deleted files */
if (!panel->is_panelized) {
update_panels (UP_RELOAD, UP_KEEPSEL);
repaint_screen ();
}
#endif
if (single_entry) {
if (force_single) {
@ -1854,7 +1852,7 @@ panel_operate (void *source_panel, FileOperation operation,
return 0;
}
dest = file_mask_dialog (ctx, operation, cmd_buf, dest_dir_,
dest = file_mask_dialog (ctx, operation, fmd_buf, dest_dir_,
single_entry, &do_bg);
g_free (dest_dir_);
@ -1867,7 +1865,7 @@ panel_operate (void *source_panel, FileOperation operation,
if (safe_delete)
query_set_sel (1);
i = query_dialog (_(op_names[operation]), cmd_buf, D_ERROR, 2,
i = query_dialog (_(op_names[operation]), fmd_buf, D_ERROR, 2,
_("&Yes"), _("&No"));
if (i != 0) {
@ -2189,26 +2187,29 @@ real_do_file_error (enum OperationMode mode, const char *error)
FileProgressStatus
file_error (const char *format, const char *file)
{
g_snprintf (cmd_buf, sizeof (cmd_buf), format,
char buf [BUF_MEDIUM];
g_snprintf (buf, sizeof (buf), format,
path_trunc (file, 30), unix_error_string (errno));
return do_file_error (cmd_buf);
return do_file_error (buf);
}
/* Report error with two files */
static FileProgressStatus
files_error (const char *format, const char *file1, const char *file2)
{
char buf [BUF_MEDIUM];
char *nfile1 = g_strdup (path_trunc (file1, 15));
char *nfile2 = g_strdup (path_trunc (file2, 15));
g_snprintf (cmd_buf, sizeof (cmd_buf), format, nfile1, nfile2,
g_snprintf (buf, sizeof (buf), format, nfile1, nfile2,
unix_error_string (errno));
g_free (nfile1);
g_free (nfile2);
return do_file_error (cmd_buf);
return do_file_error (buf);
}
static FileProgressStatus

View File

@ -298,8 +298,6 @@ char *mc_home = NULL;
/* mc_home_alt: Alternative home of MC - deprecated /usr/share/mc */
char *mc_home_alt = NULL;
char cmd_buf[512];
/* Define this function for glib-style error handling */
GQuark
mc_main_error_quark (void)

View File

@ -66,7 +66,6 @@ extern int vfs_use_limit;
extern int only_leading_plus_minus;
extern int output_starts_shell;
extern int midnight_shutdown;
extern char cmd_buf [512];
extern char *shell;
extern int auto_fill_mkdir_name;
extern int skip_check_codeset;

View File

@ -608,32 +608,29 @@ tree_forget_cmd (void *data)
tree_remove_entry (tree, tree->selected_ptr->name);
}
static void tree_copy (WTree *tree, const char *default_dest)
static void
tree_copy (WTree *tree, const char *default_dest)
{
char msg [BUF_MEDIUM];
char *dest;
off_t count = 0;
double bytes = 0;
FileOpContext *ctx;
if (!tree->selected_ptr)
return;
g_snprintf (cmd_buf, sizeof(cmd_buf), _("Copy \"%s\" directory to:"),
str_trunc (tree->selected_ptr->name, 50));
dest = input_expand_dialog (_(" Copy "), cmd_buf, MC_HISTORY_FM_TREE_COPY, default_dest);
if (!dest)
if (tree->selected_ptr == NULL)
return;
if (!*dest){
g_free (dest);
return;
g_snprintf (msg, sizeof (msg), _("Copy \"%s\" directory to:"),
str_trunc (tree->selected_ptr->name, 50));
dest = input_expand_dialog (_(" Copy "), msg, MC_HISTORY_FM_TREE_COPY, default_dest);
if (dest != NULL && *dest != '\0') {
ctx = file_op_context_new (OP_COPY);
file_op_context_create_ui (ctx, FALSE);
copy_dir_dir (ctx, tree->selected_ptr->name, dest, 1, 0, 0, 0, &count, &bytes);
file_op_context_destroy (ctx);
}
ctx = file_op_context_new (OP_COPY);
file_op_context_create_ui (ctx, FALSE);
copy_dir_dir (ctx, tree->selected_ptr->name, dest, 1, 0, 0, 0, &count, &bytes);
file_op_context_destroy (ctx);
g_free (dest);
}
@ -650,25 +647,28 @@ tree_copy_cmd (void *data)
tree_copy (tree, "");
}
static void tree_move (WTree *tree, const char *default_dest)
static void
tree_move (WTree *tree, const char *default_dest)
{
char msg [BUF_MEDIUM];
char *dest;
struct stat buf;
double bytes = 0;
off_t count = 0;
FileOpContext *ctx;
if (!tree->selected_ptr)
if (tree->selected_ptr == NULL)
return;
g_snprintf (cmd_buf, sizeof (cmd_buf), _("Move \"%s\" directory to:"),
str_trunc (tree->selected_ptr->name, 50));
dest = input_expand_dialog (_(" Move "), cmd_buf, MC_HISTORY_FM_TREE_MOVE, default_dest);
if (!dest)
return;
if (!*dest){
g_snprintf (msg, sizeof (msg), _("Move \"%s\" directory to:"),
str_trunc (tree->selected_ptr->name, 50));
dest = input_expand_dialog (_(" Move "), msg, MC_HISTORY_FM_TREE_MOVE, default_dest);
if (dest == NULL || *dest == '\0') {
g_free (dest);
return;
}
if (stat (dest, &buf)){
message (D_ERROR, MSG_ERROR, _(" Cannot stat the destination \n %s "),
unix_error_string (errno));