* main.[ch], user.c: Fixed a double free in mc_maybe_editor_or_viewer().

Restructured setup_dummy_mc() and expand_format() accordingly.
This commit is contained in:
Leonard den Ottolander 2005-06-22 21:38:52 +00:00
parent a52ce4e9ac
commit f10fe35005
4 changed files with 48 additions and 27 deletions

View File

@ -1,3 +1,12 @@
2005-06-22 Pavel Tsekov <ptsekov@gmx.net>
* main.h: Export edit_one_file.
* main.c (setup_dummy_mc): Remove dummy dir_list and remove argument.
* main.c (mc_maybe_editor_or_viewer): Fix a double free and restructure
according to fixes to setup_dummy_mc().
* dir.c (expand_format): Use edit_widget->filename as fname when
invoked as mcedit.
2005-06-21 Pavel Roskin <proski@gnu.org>
* view.c (view_percent): Remove unused variable.

View File

@ -257,7 +257,7 @@ char *command_line_colors = NULL;
static const char *view_one_file = NULL;
/* File name to edit if argument was supplied */
static const char *edit_one_file = NULL;
const char *edit_one_file = NULL;
/* Line to start the editor on */
static int edit_one_file_start_line = 0;
@ -1400,21 +1400,13 @@ setup_mc (void)
}
static void
setup_dummy_mc (const char *file)
setup_dummy_mc ()
{
char d[MC_MAXPATHLEN];
mc_get_current_wd (d, MC_MAXPATHLEN);
setup_mc ();
mc_chdir (d);
/* Create a fake current_panel, this is needed because the
* expand_format routine will use current panel.
*/
strcpy (current_panel->cwd, d);
current_panel->selected = 0;
current_panel->count = 1;
current_panel->dir.list[0].fname = (char *) file;
}
static void
@ -1701,27 +1693,25 @@ prepend_cwd_on_local (const char *filename)
static int
mc_maybe_editor_or_viewer (void)
{
char *path = NULL;
if (!(view_one_file || edit_one_file))
return 0;
setup_dummy_mc ();
/* Invoke the internal view/edit routine with:
* the default processing and forcing the internal viewer/editor
*/
if (view_one_file) {
char *path = NULL;
path = prepend_cwd_on_local (view_one_file);
setup_dummy_mc (path);
view_file (path, 0, 1);
g_free (path);
}
#ifdef USE_INTERNAL_EDIT
else {
path = prepend_cwd_on_local ("");
setup_dummy_mc (path);
edit_file (edit_one_file, edit_one_file_start_line);
}
#endif /* USE_INTERNAL_EDIT */
g_free (path);
midnight_shutdown = 1;
done_mc ();
return 1;

View File

@ -109,6 +109,7 @@ void print_vfs_message(const char *msg, ...)
__attribute__ ((format (printf, 1, 2)));
extern char *prompt;
extern const char *edit_one_file;
extern char *mc_home;
char *get_mc_lib_dir (void);

View File

@ -171,7 +171,7 @@ strip_ext(char *ss)
char *
expand_format (struct WEdit *edit_widget, char c, int quote)
{
WPanel *panel;
WPanel *panel = NULL;
char *(*quote_func) (const char *, int);
char *fname;
char *result;
@ -180,15 +180,18 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
if (c == '%')
return g_strdup ("%");
if (islower ((unsigned char) c))
panel = current_panel;
if (edit_one_file != NULL)
fname = edit_widget->filename;
else {
if (get_other_type () != view_listing)
return g_strdup ("");
panel = other_panel;
if (islower ((unsigned char) c))
panel = current_panel;
else {
if (get_other_type () != view_listing)
return g_strdup ("");
panel = other_panel;
}
fname = panel->dir.list[panel->selected].fname;
}
if (!panel)
panel = current_panel;
if (quote)
quote_func = name_quote;
@ -196,7 +199,6 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
quote_func = fake_name_quote;
c_lc = tolower ((unsigned char) c);
fname = panel->dir.list[panel->selected].fname;
switch (c_lc) {
case 'f':
@ -205,7 +207,23 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
case 'x':
return (*quote_func) (extension (fname), 0);
case 'd':
return (*quote_func) (panel->cwd, 0);
{
char *cwd;
char *qstr;
cwd = g_malloc(MC_MAXPATHLEN + 1);
if (panel)
g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
else
mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);
qstr = (*quote_func) (cwd, 0);
g_free (cwd);
return qstr;
}
case 'i': /* indent equal number cursor position in line */
if (edit_widget)
return g_strnfill (edit_widget->curs_col, ' ');
@ -235,7 +253,7 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
return (*quote_func) (menu, 0);
break;
case 's':
if (!panel->marked)
if (!panel || !panel->marked)
return (*quote_func) (fname, 0);
/* Fall through */
@ -246,6 +264,9 @@ expand_format (struct WEdit *edit_widget, char c, int quote)
int length = 2, i;
char *block, *tmp;
if (!panel)
return g_strdup ("");
for (i = 0; i < panel->count; i++)
if (panel->dir.list[i].f.marked)
length += strlen (panel->dir.list[i].fname) + 1; /* for space */