[PATCH] Re: mcedit stackdumps on exit
- From: Pavel Tsekov <ptsekov gmx net>
- To: MC Devel <mc-devel gnome org>
- Subject: [PATCH] Re: mcedit stackdumps on exit
- Date: Mon, 13 Jun 2005 16:29:46 +0300
Hello,
On Mon, 13 Jun 2005, Pavel Tsekov wrote:
> Hello,
>
> On Sun, 12 Jun 2005, Leonard den Ottolander wrote:
>
> > Hi Pavel,
> >
> > On Sun, 2005-06-12 at 19:49, Pavel Tsekov wrote:
> > > current_panel->dir.list[0].fname = (char *) file;
> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > Will a g_strdup() suffice?
>
> Yes, but it is not a long term solution. I'm almost done with a patch
> which makes expand_format() work even if `current_panel' is not set. Stay
> tuned.
I am posting a patch for review, comments, etc. This is a candidate for mc
4.6.1. I have another patch which is more intrusive and needs much more
attention. I'll post later when I am sure it is clean enough - it
will be candidate for HEAD.
The patch includes the following changes:
1) Exports the global variable `edit_one_file'.
2) The code initializing a dummy `dir_list' entry in setup_dummy_mc() is
removed.
The argument to setup_dummy_mc() is removed since it is no longer used.
3) mc_maybe_editor_or_viewer() is rearranged to reflect the changes to
setup_dummy_mc().
3) expand_format() is changed so that it will use the `filename' member of
WEdit if the MC is started as `mcedit'. `mc_get_current_wd' will be
used to determine the current directory `mcedit' mode instead of
`panel->cwd'. Finally the code just eats the `u' and `t' format
specifiers when in `mcedit' mode.
? .swp
? m4/isc-posix.m4
Index: src/main.c
===================================================================
RCS file: /cvsroot/mc/mc/src/main.c,v
retrieving revision 1.355
diff -u -p -r1.355 main.c
--- src/main.c 7 Jun 2005 20:55:13 -0000 1.355
+++ src/main.c 13 Jun 2005 13:24:38 -0000
@@ -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 *filena
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;
Index: src/main.h
===================================================================
RCS file: /cvsroot/mc/mc/src/main.h,v
retrieving revision 1.59
diff -u -p -r1.59 main.h
--- src/main.h 23 May 2005 16:37:02 -0000 1.59
+++ src/main.h 13 Jun 2005 13:24:38 -0000
@@ -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);
Index: src/user.c
===================================================================
RCS file: /cvsroot/mc/mc/src/user.c,v
retrieving revision 1.71
diff -u -p -r1.71 user.c
--- src/user.c 27 May 2005 03:35:15 -0000 1.71
+++ src/user.c 13 Jun 2005 13:24:39 -0000
@@ -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
if (c == '%')
return g_strdup ("%");
- if (islower ((unsigned char) c))
+ if (edit_one_file != NULL)
+ fname = edit_widget->filename;
+ else if (islower ((unsigned char) c))
panel = current_panel;
else {
if (get_other_type () != view_listing)
return g_strdup ("");
panel = other_panel;
}
- if (!panel)
- panel = current_panel;
+
+ if (panel)
+ fname = panel->dir.list[panel->selected].fname;
if (quote)
quote_func = name_quote;
@@ -196,7 +199,6 @@ expand_format (struct WEdit *edit_widget
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
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
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
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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]