1999-08-27 Federico Mena Quintero <federico@redhat.com>

* ext.c (quote_block): How did this ever work?  People, if you
	realloc() things, don't keep pointers to stuff inside the original
	block.

	* screen.c (do_enter_on_file_entry): Pass in the full name to
	if_link_is_exe().

	* dir.[ch] (if_link_is_exe): Take in the full name, not the directory
	and the file entry.

1999-08-26  Federico Mena Quintero  <federico@redhat.com>

	* gscreen.c (panel_clist_drag_motion): Pass the full name to
	gdnd_validate_action().
	(panel_icon_list_drag_motion): Likewise.
	(panel_tree_drag_motion): Likewise.

	* gdnd.c (gdnd_perform_drop): Renamed the "directory" argument to
	"dest_full_name" for clarity.
	(gdnd_validate_action): Likewise.  Pass in the full name to
	if_link_is_exe().
	(drop_on_file): Do not compute the full name, since we are already
	get it from the caller.
	(drop_on_file): Pass in the full name to if_link_is_exe().

	* gscreen.c (panel_tree_drag_data_received): Free the pathname.

	* gdesktop.c (icon_drag_data_received): Pass the full name of the
	file to gdnd_perform_drop(), not just the desktop directory.
This commit is contained in:
Miguel de Icaza 1999-08-27 05:01:08 +00:00
parent 2eae1a244e
commit 871a880139
10 changed files with 596 additions and 547 deletions

View File

@ -1,3 +1,23 @@
1999-08-26 Federico Mena Quintero <federico@redhat.com>
* gscreen.c (panel_clist_drag_motion): Pass the full name to
gdnd_validate_action().
(panel_icon_list_drag_motion): Likewise.
(panel_tree_drag_motion): Likewise.
* gdnd.c (gdnd_perform_drop): Renamed the "directory" argument to
"dest_full_name" for clarity.
(gdnd_validate_action): Likewise. Pass in the full name to
if_link_is_exe().
(drop_on_file): Do not compute the full name, since we are already
get it from the caller.
(drop_on_file): Pass in the full name to if_link_is_exe().
* gscreen.c (panel_tree_drag_data_received): Free the pathname.
* gdesktop.c (icon_drag_data_received): Pass the full name of the
file to gdnd_perform_drop(), not just the desktop directory.
1999-08-23 Federico Mena Quintero <federico@redhat.com>
* gdesktop-prefs.[ch]: New files that handle the desktop

View File

@ -2044,7 +2044,7 @@ icon_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gin
return;
}
if (gdnd_perform_drop (context, data, desktop_directory, fe))
if (gdnd_perform_drop (context, data, full_name, fe))
desktop_reload_icons (FALSE, 0, 0);
file_entry_free (fe);

View File

@ -28,7 +28,7 @@ GdkAtom dnd_target_atoms[TARGET_NTARGETS];
/**
* gdnd_init:
*
*
* Initializes the dnd_target_atoms array by interning the DnD target atom names.
**/
void
@ -194,7 +194,7 @@ perform_action (GList *names, GdkDragAction action, char *destdir)
} else {
long count = 0;
double bytes = 0;
if (S_ISDIR (s.st_mode)) {
if (action == GDK_ACTION_COPY)
copy_dir_dir (ctx,
@ -301,41 +301,38 @@ drop_on_directory (GdkDragContext *context, GtkSelectionData *selection_data,
/* Drop stuff on a non-directory file. This uses metadata and MIME as well. */
static int
drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data,
char *directory, file_entry *dest_fe)
char *dest_full_name, file_entry *dest_fe)
{
int size;
char *buf;
const char *mime_type;
char *full_name;
int retval;
GList *names, *l;
int len, i;
char **drops;
retval = FALSE; /* assume we cannot drop */
full_name = g_concat_dir_and_file (directory, dest_fe->fname);
/* Convert the data list into an array of strings */
names = gnome_uri_list_extract_uris (selection_data->data);
len = g_list_length (names);
drops = g_new (char *, len + 1);
for (l = names, i = 0; i < len; i++, l = l->next) {
char *text = l->data;
if (strncmp (text, "file:", 5) == 0)
text += 5;
drops[i] = text;
}
drops[i] = NULL;
/* 1. Try to use a metadata-based drop action */
if (gnome_metadata_get (full_name, "drop-action", &size, &buf) == 0) {
exec_extension (full_name, buf, drops, NULL, 0, 0);
if (gnome_metadata_get (dest_full_name, "drop-action", &size, &buf) == 0) {
exec_extension (dest_full_name, buf, drops, NULL, 0, 0);
g_free (buf);
retval = TRUE;
goto out;
@ -343,13 +340,13 @@ drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data,
/* 2. Try a drop action from the MIME-type */
mime_type = gnome_mime_type_or_default (full_name, NULL);
mime_type = gnome_mime_type_or_default (dest_full_name, NULL);
if (mime_type) {
const char *action;
action = gnome_mime_get_value (mime_type, "drop-action");
if (action) {
exec_extension (full_name, action, drops, NULL, 0, 0);
exec_extension (dest_full_name, action, drops, NULL, 0, 0);
retval = TRUE;
goto out;
}
@ -357,13 +354,13 @@ drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data,
/* 3. If executable, try metadata keys for "open" */
if (is_exe (dest_fe->buf.st_mode) && if_link_is_exe (directory, dest_fe)) {
if (is_exe (dest_fe->buf.st_mode) && if_link_is_exe (dest_full_name, dest_fe)) {
/* FIXME: handle the case for Netscape URLs */
if (gnome_metadata_get (full_name, "open", &size, &buf) == 0)
exec_extension (full_name, buf, drops, NULL, 0, 0);
if (gnome_metadata_get (dest_full_name, "open", &size, &buf) == 0)
exec_extension (dest_full_name, buf, drops, NULL, 0, 0);
else
exec_extension (full_name, "%f %q", drops, NULL, 0, 0);
exec_extension (dest_full_name, "%f %q", drops, NULL, 0, 0);
g_free (buf);
@ -374,19 +371,18 @@ drop_on_file (GdkDragContext *context, GtkSelectionData *selection_data,
out:
g_free (drops);
gnome_uri_list_free_strings (names);
g_free (full_name);
return retval;
}
int
gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data,
char *directory, file_entry *dest_fe)
char *dest_full_name, file_entry *dest_fe)
{
GdkDragAction action;
g_return_val_if_fail (context != NULL, FALSE);
g_return_val_if_fail (selection_data != NULL, FALSE);
g_return_val_if_fail (directory != NULL, FALSE);
g_return_val_if_fail (dest_full_name != NULL, FALSE);
g_return_val_if_fail (dest_fe != NULL, FALSE);
/* Get action */
@ -399,18 +395,18 @@ gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data,
action = context->action;
if (S_ISDIR (dest_fe->buf.st_mode) || dest_fe->f.link_to_dir)
return drop_on_directory (context, selection_data, action, directory);
return drop_on_directory (context, selection_data, action, dest_full_name);
else
return drop_on_file (context, selection_data, directory, dest_fe);
return drop_on_file (context, selection_data, dest_full_name, dest_fe);
}
/**
* gdnd_drag_context_has_target:
* @context: The context to query for a target type
* @type: The sought target type
*
*
* Tests whether the specified drag context has a target of the specified type.
*
*
* Return value: TRUE if the context has the specified target type, FALSE
* otherwise.
**/
@ -432,10 +428,10 @@ gdnd_drag_context_has_target (GdkDragContext *context, TargetType type)
* gdnd_find_panel_by_drag_context:
* @context: The context by which to find a panel.
* @source_widget: The source widget is returned here.
*
*
* Looks in the list of panels for the one that corresponds to the specified
* drag context.
*
*
* Return value: The sought panel, or NULL if no panel corresponds to the
* context.
**/
@ -477,22 +473,22 @@ gdnd_find_panel_by_drag_context (GdkDragContext *context, GtkWidget **source_wid
* @same_source: If same_process, then whether the source and dest widgets are the same.
* @dest: The destination file entry, or NULL if dropping on empty space.
* @dest_selected: If dest is non-NULL, whether it is selected or not.
*
*
* Computes the final drag action based on the suggested action of the specified
* context and conditions.
*
*
* Return value: The computed action, meant to be passed to gdk_drag_action().
**/
GdkDragAction
gdnd_validate_action (GdkDragContext *context,
int on_desktop, int same_process, int same_source,
char *directory, file_entry *dest_fe, int dest_selected)
char *dest_full_name, file_entry *dest_fe, int dest_selected)
{
int on_directory;
int on_exe;
g_return_val_if_fail (context != NULL, 0);
g_return_val_if_fail (directory != NULL, 0);
g_return_val_if_fail (dest_full_name != NULL, 0);
/* If we are dragging a desktop icon onto the desktop or onto a selected
* desktop icon, unconditionally specify MOVE.
@ -506,7 +502,7 @@ gdnd_validate_action (GdkDragContext *context,
if (dest_fe) {
on_directory = S_ISDIR (dest_fe->buf.st_mode) || dest_fe->f.link_to_dir;
on_exe = is_exe (dest_fe->buf.st_mode) && if_link_is_exe (directory, dest_fe);
on_exe = is_exe (dest_fe->buf.st_mode) && if_link_is_exe (dest_full_name, dest_fe);
}
if (gdnd_drag_context_has_target (context, TARGET_URI_LIST)) {

View File

@ -40,7 +40,7 @@ void gdnd_init (void);
* Returns TRUE if an action was performed, FALSE otherwise (i.e. invalid drop).
*/
int gdnd_perform_drop (GdkDragContext *context, GtkSelectionData *selection_data,
char *directory, file_entry *dest_fe);
char *dest_full_name, file_entry *dest_fe);
/* Test whether the specified context has a certain target type */
int gdnd_drag_context_has_target (GdkDragContext *context, TargetType type);
@ -53,7 +53,7 @@ WPanel *gdnd_find_panel_by_drag_context (GdkDragContext *context, GtkWidget **so
*/
GdkDragAction gdnd_validate_action (GdkDragContext *context,
int on_desktop, int same_process, int same_source,
char *directory, file_entry *dest_fe, int dest_selected);
char *dest_full_name, file_entry *dest_fe, int dest_selected);
#endif

View File

@ -909,8 +909,10 @@ panel_tree_drag_data_received (GtkWidget *widget,
path = gtk_dtree_get_row_path (dtree, node, 0);
fe = file_entry_from_file (path);
if (!fe)
if (!fe) {
g_free (path);
return; /* eeeek */
}
reload = gdnd_perform_drop (context, selection_data, path, fe);
@ -1071,6 +1073,7 @@ panel_clist_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gin
GtkWidget *source_widget;
gint idx;
file_entry *fe;
char *full_name;
panel = data;
@ -1101,14 +1104,19 @@ panel_clist_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gin
else
fe = &panel->dir.list[idx];
full_name = fe ? g_concat_dir_and_file (panel->cwd, fe->fname) : panel->cwd;
action = gdnd_validate_action (context,
FALSE,
source_widget != NULL,
source_widget == widget,
panel->cwd,
full_name,
fe,
fe ? fe->f.marked : FALSE);
if (full_name != panel->cwd)
g_free (full_name);
gdk_drag_status (context, action, time);
out:
@ -1202,6 +1210,7 @@ panel_icon_list_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x,
GtkWidget *source_widget;
int idx;
file_entry *fe;
char *full_name;
panel = data;
@ -1218,14 +1227,19 @@ panel_icon_list_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x,
idx = gnome_icon_list_get_icon_at (GNOME_ICON_LIST (widget), x, y);
fe = (idx == -1) ? NULL : &panel->dir.list[idx];
full_name = fe ? g_concat_dir_and_file (panel->cwd, fe->fname) : panel->cwd;
action = gdnd_validate_action (context,
FALSE,
source_widget != NULL,
source_widget == widget,
panel->cwd,
full_name,
fe,
fe ? fe->f.marked : FALSE);
if (full_name != panel->cwd)
g_free (full_name);
gdk_drag_status (context, action, time);
return TRUE;
}
@ -1995,7 +2009,6 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y
GtkWidget *source_widget;
char *row_path;
int on_drag_row;
char *parent_dir, *p;
dtree = GTK_DTREE (widget);
panel = data;
@ -2046,13 +2059,6 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y
panel->drag_tree_row = row;
}
/* Compute the parent directory of the file entry */
parent_dir = g_strdup (row_path);
p = strrchr (parent_dir, PATH_SEP);
g_assert (p != NULL);
p[1] = 0;
/* Validate the action */
gdnd_find_panel_by_drag_context (context, &source_widget);
@ -2071,11 +2077,10 @@ panel_tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y
FALSE,
source_widget != NULL,
source_widget == widget,
parent_dir,
row_path,
panel->drag_tree_fe,
on_drag_row);
g_free (parent_dir);
g_free (row_path);
} else {
panel->drag_tree_row = -1;

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
/* Directory routines
Copyright (C) 1994 Miguel de Icaza.
This program is free software; you can redistribute it and/or modify
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
@ -89,7 +89,7 @@ sort_name (const file_entry *a, const file_entry *b)
{
int ad = MY_ISDIR (a);
int bd = MY_ISDIR (b);
if (ad == bd || mix_all_files)
return string_sortcomp (a->fname, b->fname) * reverse;
return bd-ad;
@ -120,7 +120,7 @@ sort_owner (const file_entry *a, const file_entry *b)
{
int ad = MY_ISDIR (a);
int bd = MY_ISDIR (b);
if (ad == bd || mix_all_files)
return string_sortcomp (get_owner (a->buf.st_uid), get_owner (a->buf.st_uid)) * reverse;
return bd-ad;
@ -131,7 +131,7 @@ sort_group (const file_entry *a, const file_entry *b)
{
int ad = MY_ISDIR (a);
int bd = MY_ISDIR (b);
if (ad == bd || mix_all_files)
return string_sortcomp (get_group (a->buf.st_gid), get_group (a->buf.st_gid)) * reverse;
return bd-ad;
@ -237,7 +237,7 @@ inline static int
file_type_to_num (const file_entry *fe)
{
const struct stat *s = &fe->buf;
if (S_ISDIR (s->st_mode))
return 0;
if (S_ISLNK (s->st_mode)){
@ -266,7 +266,7 @@ sort_type (const file_entry *a, const file_entry *b)
{
int aa = file_type_to_num (a);
int bb = file_type_to_num (b);
return bb-aa;
}
@ -304,13 +304,13 @@ clean_dir (dir_list *list, int count)
}
}
static int
static int
add_dotdot_to_list (dir_list *list, int index)
{
char buffer [MC_MAXPATHLEN + MC_MAXPATHLEN];
char *p;
int i = 0;
/* Need to grow the *list? */
if (index == list->size) {
list->list = g_realloc (list->list, sizeof (file_entry) *
@ -325,7 +325,7 @@ add_dotdot_to_list (dir_list *list, int index)
(list->list) [index].f.link_to_dir = 0;
(list->list) [index].f.stalled_link = 0;
(list->list) [index].f.dir_size_computed = 0;
/* FIXME: We need to get the panel definition! to use file_mark */
(list->list) [index].f.marked = 0;
mc_get_current_wd (buffer, sizeof (buffer) - 1 );
@ -389,7 +389,7 @@ handle_dirent (dir_list *list, char *filter, struct dirent *dp,
if (S_ISDIR (buf1->st_mode))
tree_store_mark_checked (dp->d_name);
/* A link to a file or a directory? */
*link_to_dir = 0;
*stalled_link = 0;
@ -415,9 +415,9 @@ handle_dirent (dir_list *list, char *filter, struct dirent *dp,
return 1;
}
/* handle_path is a simplified handle_dirent. The difference is that
/* handle_path is a simplified handle_dirent. The difference is that
handle_path doesn't pay attention to show_dot_files and show_backups.
Moreover handle_path can't be used with a filemask.
Moreover handle_path can't be used with a filemask.
If you change handle_path then check also handle_dirent. */
/* Return values: -1 = failure, 0 = don't add, 1 = add to the list */
int
@ -432,7 +432,7 @@ handle_path (dir_list *list, char *path,
if (S_ISDIR (buf1->st_mode))
tree_store_mark_checked (path);
/* A link to a file or a directory? */
*link_to_dir = 0;
*stalled_link = 0;
@ -466,7 +466,7 @@ do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive, char
int dotdot_found = 0;
tree_store_start_check_cwd ();
dirp = mc_opendir (".");
if (!dirp){
tree_store_end_check ();
@ -503,7 +503,7 @@ do_load_dir (dir_list *list, sortfn *sort, int reverse, int case_sensitive, char
tree_store_end_check ();
return set_zero_dir (list);
}
mc_closedir (dirp);
tree_store_end_check ();
return next_free;
@ -517,19 +517,14 @@ link_isdir (file_entry *file)
else
return 0;
}
int
if_link_is_exe (char *directory, file_entry *file)
if_link_is_exe (char *full_name, file_entry *file)
{
struct stat b;
char *full_name;
full_name = concat_dir_and_file (directory, file->fname);
if (S_ISLNK (file->buf.st_mode)) {
full_name = concat_dir_and_file (directory, file->fname);
mc_stat (full_name, &b);
g_free (full_name);
return is_exe (b.st_mode);
} else
return 1;
@ -541,7 +536,7 @@ static void
alloc_dir_copy (int size)
{
int i;
if (dir_copy.size < size){
if (dir_copy.list){
@ -572,7 +567,7 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
int i, found, status, link_to_dir, stalled_link;
struct stat buf;
int tmp_len; /* For optimisation */
int dotdot_found = 0;
int dotdot_found = 0;
tree_store_start_check_cwd ();
dirp = mc_opendir (".");
@ -599,20 +594,20 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
continue;
if (status == -1) {
mc_closedir (dirp);
/* Norbert (Feb 12, 1997):
/* Norbert (Feb 12, 1997):
Just in case someone finds this memory leak:
-1 means big trouble (at the moment no memory left),
-1 means big trouble (at the moment no memory left),
I don't bother with further cleanup because if one gets to
this point he will have more problems than a few memory
leaks and because one 'clean_dir' would not be enough (and
because I don't want to spent the time to make it working,
IMHO it's not worthwhile).
because I don't want to spent the time to make it working,
IMHO it's not worthwhile).
clean_dir (&dir_copy, count);
*/
tree_store_end_check ();
return next_free;
}
tmp_len = NLENGTH (dp);
for (found = i = 0; i < count; i++)
if (tmp_len == dir_copy.list [i].fnamelen
@ -621,10 +616,10 @@ do_reload_dir (dir_list *list, sortfn *sort, int count, int rev,
found = 1;
break;
}
if (!found)
list->list [next_free].f.marked = 0;
list->list [next_free].fnamelen = tmp_len;
list->list [next_free].fname = g_strdup (dp->d_name);
list->list [next_free].f.link_to_dir = link_to_dir;

View File

@ -79,7 +79,7 @@ typedef struct {
extern sort_orders_t sort_orders [SORT_TYPES_TOTAL];
int link_isdir (file_entry *);
int if_link_is_exe (char *directory, file_entry *file);
int if_link_is_exe (char *full_name, file_entry *file);
extern int show_backups;
extern int show_dot_files;

125
src/ext.c
View File

@ -1,14 +1,14 @@
/* Extension dependent execution.
Copyright (C) 1994, 1995 The Free Software Foundation
Written by: 1995 Jakub Jelinek
1994 Miguel de Icaza
This program is free software; you can redistribute it and/or modify
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
@ -56,8 +56,8 @@
int use_file_to_check_type = 1;
/* This variable points to a copy of the mc.ext file in memory
* With this we avoid loading/parsing the file each time we
* need it
* With this we avoid loading/parsing the file each time we
* need it
*/
static char *data = NULL;
@ -68,7 +68,7 @@ flush_extension_file (void)
g_free (data);
data = NULL;
}
}
typedef char *(*quote_func_t)(const char *name, int i);
@ -76,29 +76,38 @@ typedef char *(*quote_func_t)(const char *name, int i);
static char *
quote_block (quote_func_t quote_func, char **quoting_block)
{
char **p = quoting_block;
char *result = 0;
char *tail = 0;
int current_len = 0;
char **p;
char *result;
char *tail;
int tail_index;
int current_len;
for (p = quoting_block; *p; p++){
int temp_len;
char *temp = quote_func (*p, 0);
result = NULL;
current_len = 0;
tail_index = 0;
for (p = quoting_block; *p; p++) {
int temp_len;
char *temp;
temp = quote_func (*p, FALSE);
temp_len = strlen (temp);
current_len += temp_len + 2;
result = g_realloc (result, current_len);
if (!tail)
tail = result;
tail = result + tail_index;
strcpy (tail, temp);
strcat (tail, " ");
tail += temp_len + 1;
tail[temp_len] = ' ';
tail[temp_len + 1] = '\0';
tail_index += temp_len + 1;
g_free (temp);
}
return result;
}
void
exec_extension (const char *filename, const char *data, char **drops, int *move_dir, int start_line, int needs_term)
{
@ -129,7 +138,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
do_local_copy = 1;
else
do_local_copy = 0;
if ((file_name = tempnam (NULL, "mcext")) == 0) {
message (1, MSG_ERROR, _(" Can't generate unique filename \n %s "),
unix_error_string (errno));
@ -146,7 +155,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
cmd_file = fdopen (cmd_file_fd, "w");
/* FIXME: This is a hack, that makes us sure, we are using the right syntax */
fprintf (cmd_file, "#!/bin/sh\n");
prompt [0] = 0;
for (;*data && *data != '\n'; data++){
if (parameter_found){
@ -182,7 +191,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
else {
int i = check_format_view (data);
char *v;
if (i){
data += i - 1;
run_view = 1;
@ -251,11 +260,11 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
changed_hex_mode = 1;
if (def_nroff_flag != default_nroff_flag)
changed_nroff_flag = 1;
/* If we've written whitespace only, then just load filename
* into view
*/
if (written_nonspace)
if (written_nonspace)
view (file_name, filename, move_dir, start_line);
else
view (0, filename, move_dir, start_line);
@ -270,7 +279,7 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
p = buffer;
while (*p == ' ' && *p == '\t')
p++;
/* Search last non-space character. Start search at the end in order
not to short filenames containing spaces. */
q = p + strlen (p) - 1;
@ -295,10 +304,10 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
show_console_contents (output_start_y,
LINES-keybar_visible-output_lines-1,
LINES-keybar_visible-1);
}
}
#ifdef OLD_CODE
if (vfs_current_is_local ())
shell_execute (file_name, EXECUTE_INTERNAL);
@ -359,12 +368,12 @@ char *regex_command (char *filename, char *action, char **drops, int *move_dir)
int view_at_line_number;
char *include_target;
int include_target_len;
#ifdef FILE_STDIN
int file_supports_stdin = 1;
#else
int file_supports_stdin = 0;
#endif
#endif
/* Check for the special View:%d parameter */
if (action && strncmp (action, "View:", 5) == 0){
@ -396,13 +405,13 @@ check_stock_mc_ext:
data = NULL;
if (extension_file == buffer) {
home_error = 1;
goto check_stock_mc_ext;
goto check_stock_mc_ext;
} else {
char *msg;
char *msg2;
msg = g_strconcat (" ", mc_home, MC_LIB_EXT, _(" file error"), NULL);
msg2 = g_strconcat (_("Format of the "),
mc_home,
msg2 = g_strconcat (_("Format of the "),
mc_home,
("mc.ext file has changed\n\
with version 3.0. It seems that installation\n\
failed. Please fetch a fresh new copy from the\n\
@ -432,7 +441,7 @@ file as an example of how to write it.\n\
g_free (buffer);
}
mc_stat (filename, &mystat);
if (regex_command_title){
g_free (regex_command_title);
regex_command_title = NULL;
@ -456,11 +465,11 @@ file as an example of how to write it.\n\
* keyword/descNL
*/
if (found && action == NULL) /* We have already accumulated all
* the user actions
* the user actions
*/
break;
found = 0;
q = strchr (p, '\n');
q = strchr (p, '\n');
if (q == NULL)
q = strchr (p, 0);
c = *q;
@ -482,7 +491,7 @@ file as an example of how to write it.\n\
} else if (!strncmp (p, "shell/", 6)) {
p += 6;
if (*p == '.') {
if (!strncmp (p, filename + file_len - (q - p),
if (!strncmp (p, filename + file_len - (q - p),
q - p))
found = 1;
} else {
@ -492,7 +501,7 @@ file as an example of how to write it.\n\
} else if (!strncmp (p, "type/", 5)) {
int islocal = vfs_file_is_local (filename);
p += 5;
if (islocal || file_supports_stdin) {
char *pp;
int hasread = use_file_to_check_type;
@ -506,18 +515,18 @@ file as an example of how to write it.\n\
char *command =
g_strconcat (FILE_CMD, tmp, NULL);
FILE *f = popen (command, "r");
g_free (tmp);
g_free (command);
if (f != NULL) {
hasread = (fgets (content_string, 2047, f)
hasread = (fgets (content_string, 2047, f)
!= NULL);
if (!hasread)
content_string [0] = 0;
pclose (f);
#ifdef SCO_FLAVOR
/*
** SCO 3.2 does has a buggy pclose(), so
/*
** SCO 3.2 does has a buggy pclose(), so
** <command> become zombie (alex)
*/
waitpid(-1,NULL,WNOHANG);
@ -529,18 +538,18 @@ file as an example of how to write it.\n\
#else
int pipehandle, remotehandle;
pid_t p;
remotehandle = mc_open (filename, O_RDONLY);
if (remotehandle != -1) {
/* 8192 is HOWMANY hardcoded value in the file-3.14
* sources. Tell me if any other file uses larger
* chunk from beginning
* chunk from beginning
*/
pipehandle = mc_doublepopen
(remotehandle, 8192, &p,"file", "file", "-", NULL);
if (pipehandle != -1) {
int i;
while ((i = read (pipehandle, content_string
while ((i = read (pipehandle, content_string
+ hasread, 2047 - hasread)) > 0)
hasread += i;
mc_doublepclose (pipehandle, p);
@ -555,22 +564,22 @@ match_file_output:
if (hasread) {
if ((pp = strchr (content_string, '\n')) != 0)
*pp = 0;
if (islocal && !strncmp (content_string,
if (islocal && !strncmp (content_string,
filename, file_len)) {
content_shift = file_len;
if (content_string [content_shift] == ':')
for (content_shift++;
content_string [content_shift] == ' ';
for (content_shift++;
content_string [content_shift] == ' ';
content_shift++);
} else if (!islocal
&& !strncmp (content_string,
} else if (!islocal
&& !strncmp (content_string,
"standard input:", 15)) {
for (content_shift = 15;
content_string [content_shift] == ' ';
content_shift++);
}
if (content_string &&
regexp_match (p, content_string +
if (content_string &&
regexp_match (p, content_string +
content_shift, match_normal)){
found = 1;
}
@ -606,13 +615,13 @@ match_file_output:
*r = c;
p = q;
found = 0;
if (!*p)
break;
continue;
}
if (action == NULL) {
if (strcmp (p, "Open") &&
if (strcmp (p, "Open") &&
strcmp (p, "View") &&
strcmp (p, "Edit") &&
strcmp (p, "Drop") &&
@ -621,11 +630,11 @@ match_file_output:
strcmp (p, "Title")) {
/* I.e. this is a name of a user defined action */
static char *q;
if (to_return == NULL) {
to_return = g_malloc (512);
q = to_return;
} else
} else
*(q++) = '='; /* Mark separator */
strcpy (q, p);
q = strchr (q, 0);
@ -662,12 +671,12 @@ match_file_output:
* filename parameter invalid (ie, most of the time,
* we get filename as a pointer from cpanel->dir).
*/
if (p < q) {
if (p < q) {
char *filename_copy = g_strdup (filename);
exec_extension (filename_copy, r + 1, drops, move_dir, view_at_line_number, 0);
g_free (filename_copy);
to_return = "Success";
}
break;

View File

@ -1,11 +1,11 @@
/* Panel managing.
Copyright (C) 1994, 1995 Miguel de Icaza.
This program is free software; you can redistribute it and/or modify
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
@ -91,7 +91,7 @@ int panel_event (Gpm_Event *event, WPanel *panel);
#endif
#ifndef PORT_HAS_PANEL_RESET_SORT_LABELS
# define x_reset_sort_labels(x)
# define x_reset_sort_labels(x)
#endif
/* This macro extracts the number of available lines in a panel */
@ -139,7 +139,7 @@ static void
delete_format (format_e *format)
{
format_e *next;
while (format){
next = format->next;
g_free (format);
@ -153,9 +153,9 @@ static void
add_permission_string (char *dest, int width, file_entry *fe, int attr, int color, int is_octal)
{
int i, r, l;
l = get_user_rights (&fe->buf);
if (is_octal){
/* Place of the access bit in octal mode */
l = width + l - 3;
@ -165,7 +165,7 @@ add_permission_string (char *dest, int width, file_entry *fe, int attr, int colo
l = l * 3 + 1;
r = l + 3;
}
for(i = 0; i < width; i++){
if (i >= l && i < r){
if (attr == SELECTED || attr == MARKED_SELECTED)
@ -174,7 +174,7 @@ add_permission_string (char *dest, int width, file_entry *fe, int attr, int colo
attrset (MARKED_COLOR);
} else
attrset (color);
addch (dest[i]);
}
}
@ -197,12 +197,12 @@ string_file_size (file_entry *fe, int len)
#ifdef HAVE_ST_RDEV
if (S_ISBLK (fe->buf.st_mode) || S_ISCHR (fe->buf.st_mode))
g_snprintf (buffer, sizeof (buffer), "%3d,%3d",
(int) ((fe->buf.st_rdev >> 8) & 0xff),
g_snprintf (buffer, sizeof (buffer), "%3d,%3d",
(int) ((fe->buf.st_rdev >> 8) & 0xff),
(int) (fe->buf.st_rdev & 0xff));
else
#endif
{
#endif
{
g_snprintf (buffer, sizeof (buffer), "%lu", (unsigned long) fe->buf.st_size);
if (len && (i = strlen (buffer)) > len) {
if (i - 2 > len) {
@ -439,9 +439,9 @@ to_buffer (char *dest, int just_mode, int len, char *txt)
/* Fill buffer with spaces */
memset (dest, ' ', len);
still = (over=(txtlen > len)) ? (txtlen - len) : (len - txtlen);
switch (HIDE_FIT(just_mode)){
case J_LEFT:
still = 0;
@ -452,18 +452,18 @@ to_buffer (char *dest, int just_mode, int len, char *txt)
case J_RIGHT:
default:
break;
}
}
if (over){
if (IS_FIT(just_mode))
strcpy (dest, name_trunc(txt, len));
else
strncpy (dest, txt+still, len);
} else
} else
strncpy (dest+still, txt, txtlen);
dest[len] = '\0';
return (dest + len);
}
@ -484,7 +484,7 @@ file_compute_color (int attr, file_entry *fe)
if (!filetype_mode)
return (NORMAL_COLOR);
}
/* if filetype_mode == true */
if (S_ISDIR (fe->buf.st_mode))
return (DIRECTORY_COLOR);
@ -521,10 +521,10 @@ format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int
char *cdest = dest;
format_e *format, *home;
file_entry *fe;
length = 0;
empty_line = (file_index >= panel->count);
home = (isstatus) ? panel->status_format : panel->format;
home = (isstatus) ? panel->status_format : panel->format;
fe = &panel->dir.list [file_index];
if (!empty_line)
@ -539,7 +539,7 @@ format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int
if (format->string_fn){
int len;
if (empty_line)
txt = " ";
else
@ -555,7 +555,7 @@ format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int
#ifndef HAVE_X
attrset (color);
if (permission_mode && !strcmp(format->id, "perm"))
add_permission_string (old_pos, format->field_len, fe, attr, color, 0);
else if (permission_mode && !strcmp(format->id, "mode"))
@ -577,7 +577,7 @@ format_file (char *dest, WPanel *panel, int file_index, int width, int attr, int
length++;
}
}
if (length < width){
int still = width - length;
while (still--)
@ -600,14 +600,14 @@ repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
offset = 0;
if (!isstatus && panel->split){
second_column = (file_index - panel->top_file) / llines (panel);
width = (panel->widget.cols - 2)/2 - 1;
if (second_column){
offset = 1 + width;
width = (panel->widget.cols-2) - (panel->widget.cols-2)/2 - 1;
}
}
} else
width = (panel->widget.cols - 2);
@ -620,9 +620,9 @@ repaint_file (WPanel *panel, int file_index, int mv, int attr, int isstatus)
} else
widget_move (&panel->widget, file_index - panel->top_file + 2, 1);
}
format_file (buffer, panel, file_index, width, attr, isstatus);
if (!isstatus && panel->split){
if (second_column)
addch (' ');
@ -640,9 +640,9 @@ display_mini_info (WPanel *panel)
{
if (!show_mini_info)
return;
widget_move (&panel->widget, llines (panel)+3, 1);
if (panel->searching){
attrset (INPUT_COLOR);
printw ("/%-*s", panel->widget.cols-3, panel->search_buffer);
@ -654,7 +654,7 @@ display_mini_info (WPanel *panel)
if (panel->marked){
char buffer [BUF_SMALL];
char *p;
attrset (MARKED_COLOR);
printw ("%*s", panel->widget.cols-2, " ");
widget_move (&panel->widget, llines (panel)+3, 1);
@ -672,7 +672,7 @@ display_mini_info (WPanel *panel)
/* Status resolves links and show them */
set_colors (panel);
#ifndef OS2_NT
#ifndef OS2_NT
if (S_ISLNK (panel->dir.list [panel->selected].buf.st_mode)){
char *link, link_target [MC_MAXPATHLEN];
int len;
@ -684,7 +684,7 @@ display_mini_info (WPanel *panel)
link_target[len] = 0;
printw ("-> %-*s", panel->widget.cols - 5,
name_trunc (link_target, panel->widget.cols - 5));
} else
} else
addstr (_("<readlink failed>"));
return;
}
@ -704,7 +704,7 @@ paint_dir (WPanel *panel)
int items; /* Number of items */
items = llines (panel) * (panel->split ? 2 : 1);
for (i = 0; i < items; i++){
if (i+panel->top_file >= panel->count)
color = 0;
@ -712,7 +712,7 @@ paint_dir (WPanel *panel)
color = 2 * (panel->dir.list [i+panel->top_file].f.marked);
color += (panel->selected==i+panel->top_file && panel->active);
}
repaint_file (panel, i+panel->top_file, 1, color, 0);
repaint_file (panel, i+panel->top_file, 1, color, 0);
}
standend ();
panel->dirty = 0;
@ -727,7 +727,7 @@ mini_info_separator (WPanel *panel)
{
if (!show_mini_info)
return;
standend ();
widget_move (&panel->widget, llines (panel)+2, 1);
#ifdef HAVE_SLANG
@ -736,7 +736,7 @@ mini_info_separator (WPanel *panel)
#else
hline ((slow_terminal ? '-' : ACS_HLINE) | NORMAL_COLOR,
panel->widget.cols-2);
#endif
#endif
}
void
@ -749,13 +749,13 @@ show_dir (WPanel *panel)
panel->widget.y, panel->widget.x,
panel->widget.lines, panel->widget.cols);
#ifdef HAVE_SLANG
#ifdef HAVE_SLANG
if (show_mini_info) {
#ifdef linux_unicode
if (SLtt_Unicode) {
SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
panel->widget.x, SLUNI_DSLTEE_CHAR);
SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
SLsmg_draw_unicode (panel->widget.y + llines (panel) + 2,
panel->widget.x + panel->widget.cols - 1, SLUNI_DSRTEE_CHAR);
} else
#endif /* linux_unicode */
@ -767,7 +767,7 @@ show_dir (WPanel *panel)
}
}
#endif /* have_slang */
if (panel->active)
attrset (REVERSE_COLOR);
@ -781,7 +781,7 @@ show_dir (WPanel *panel)
addstr (">");
widget_move (&panel->widget, 0, panel->widget.cols-3);
addstr ("v");
if (panel->active)
standend ();
}
@ -793,7 +793,7 @@ static void
adjust_top_file (WPanel *panel)
{
int old_top = panel->top_file;
if (panel->selected - old_top > llines (panel))
panel->top_file = panel->selected;
if (old_top - panel->count > llines (panel))
@ -879,7 +879,7 @@ void
panel_update_cols (Widget *widget, int frame_size)
{
int cols, origin;
if (horizontal_split){
widget->cols = COLS;
return;
@ -897,7 +897,7 @@ panel_update_cols (Widget *widget, int frame_size)
origin = first_panel_size;
}
}
widget->cols = cols;
widget->x = origin;
}
@ -907,7 +907,7 @@ static char *
panel_save_name (WPanel *panel)
{
extern int saving_setup;
/* If the program is shuting down */
if ((midnight_shutdown && auto_save_setup) || saving_setup)
return g_strdup (panel->panel_name);
@ -925,7 +925,7 @@ panel_destroy (WPanel *p)
panel_save_setup (p, name);
x_panel_destroy (p);
panel_clean_dir (p);
/* save and clean history */
if (p->dir_history){
Hist *current, *old;
@ -944,7 +944,7 @@ panel_destroy (WPanel *p)
delete_format (p->format);
delete_format (p->status_format);
g_free (p->user_format);
for (i = 0; i < LIST_TYPES; i++)
g_free (p->user_status_format [i]);
@ -1012,7 +1012,7 @@ panel_new (char *panel_name)
panel->dirs_marked = 0;
panel->is_panelized = 0;
panel->format = 0;
panel->status_format = 0;
panel->status_format = 0;
panel->format_modified = 1;
#ifdef HAVE_GNOME
panel->drag_tree_row = -1;
@ -1075,7 +1075,7 @@ panel_reload (WPanel *panel)
memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
show_dir (panel);
}
panel->count = do_reload_dir (&panel->dir, panel->sort_type, panel->count,
panel->reverse, panel->case_sensitive, panel->filter);
@ -1093,11 +1093,11 @@ paint_frame (WPanel *panel)
int header_len;
int spaces, extra;
int side, width;
char *txt, buffer[30]; /*Hope that this is enough ;-) */
if (!panel->split)
adjust_top_file (panel);
widget_erase (&panel->widget);
show_dir (panel);
@ -1105,7 +1105,7 @@ paint_frame (WPanel *panel)
for (side = 0; side <= panel->split; side++){
format_e *format;
if (side){
attrset (NORMAL_COLOR);
one_vline ();
@ -1114,11 +1114,11 @@ paint_frame (WPanel *panel)
width = panel->widget.cols/2 - 3;
else
width = panel->widget.cols - 2;
for (format = panel->format; format; format = format->next){
if (format->string_fn){
txt = format->title;
header_len = strlen (txt);
if (header_len > format->field_len){
strcpy (buffer, txt);
@ -1126,7 +1126,7 @@ paint_frame (WPanel *panel)
txt [format->field_len] = 0;
header_len = strlen (txt);
}
attrset (MARKED_COLOR);
spaces = (format->field_len - header_len) / 2;
extra = (format->field_len - header_len) % 2;
@ -1140,7 +1140,7 @@ paint_frame (WPanel *panel)
continue;
}
}
if (width > 0)
printw ("%*s", width, "");
}
@ -1165,10 +1165,10 @@ parse_panel_size (WPanel *panel, char *format, int isstatus)
panel->frame_size = frame;
panel->split = 0;
}
/* Now, the optional column specifier */
format = skip_separators (format);
if (*format == '1' || *format == '2'){
if (!isstatus)
panel->split = *format == '2';
@ -1177,7 +1177,7 @@ parse_panel_size (WPanel *panel, char *format, int isstatus)
if (!isstatus)
panel_update_cols (&(panel->widget), panel->frame_size);
return skip_separators (format);
}
@ -1193,7 +1193,7 @@ parse_panel_size (WPanel *panel, char *format, int isstatus)
opt_size := : size [opt_expand]
size := [0-9]+
opt_expand := +
*/
static format_e *
@ -1212,12 +1212,12 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
if (i18n_timelength == 0) {
i18n_timelength = i18n_checktimelength (); /* Musn't be 0 */
for (i = 0; i < ELEMENTS(formats); i++)
if (strcmp ("time", formats [i].id+1) == 0)
formats [i].min_size = i18n_timelength;
}
/*
* This makes sure that the panel and mini status full/half mode
* setting is equal
@ -1228,15 +1228,15 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
int found = 0;
darr = g_new (format_e, 1);
/* I'm so ugly, don't look at me :-) */
if (!home)
home = old = darr;
old->next = darr;
darr->next = 0;
old = darr;
format = skip_separators (format);
if (strchr ("<=>", *format)){
@ -1257,7 +1257,7 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
format = skip_separators (format+1);
} else
set_justify = 0;
for (i = 0; i < ELEMENTS(formats); i++){
int klen = strlen (formats [i].id);
@ -1279,7 +1279,7 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
darr->id = formats [i].id;
darr->expand = formats [i].expands;
darr->just_mode = formats [i].default_just;
if (set_justify) {
if (IS_FIT(darr->just_mode))
darr->just_mode = MAKE_FIT(justify);
@ -1316,7 +1316,7 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
}
if (!found){
char old_char;
int pos = min (8, strlen (format));
delete_format (home);
old_char = format [pos];
@ -1327,7 +1327,7 @@ parse_display_format (WPanel *panel, char *format, char **error, int isstatus, i
}
total_cols += darr->requested_field_len;
}
*res_total_cols = total_cols;
if (home)
home->items = items;
@ -1344,36 +1344,36 @@ use_display_format (WPanel *panel, char *format, char **error, int isstatus)
char *expand_list [MAX_EXPAND]; /* Expand at most 4 fields. */
int i;
format_e *darr, *home;
if (!format)
format = DEFAULT_USER_FORMAT;
home = parse_display_format (panel, format, error, isstatus, &total_cols);
if (*error)
return 0;
/* Status needn't to be split */
usable_columns = ((panel->widget.cols-2)/((isstatus)
? 1
: (panel->split+1))) - (!isstatus && panel->split);
/* Clean expand list */
for (i = 0; i < MAX_EXPAND; i++)
expand_list [i] = '\0';
/* Look for the expandable fields and set field_len based on the requested field len */
for (darr = home; darr && expand_top < MAX_EXPAND; darr = darr->next){
darr->field_len = darr->requested_field_len;
if (darr->expand)
expand_list [expand_top++] = darr->id;
}
/* If we used more columns than the available columns, adjust that */
if (total_cols > usable_columns){
int pdif, dif = total_cols - usable_columns;
while (dif){
pdif = dif;
for (darr = home; darr; darr = darr->next){
@ -1385,7 +1385,7 @@ use_display_format (WPanel *panel, char *format, char **error, int isstatus)
/* avoid endless loop if num fields > 40 */
if (pdif == dif)
break;
break;
}
total_cols = usable_columns; /* give up, the rest should be truncated */
}
@ -1411,11 +1411,11 @@ int
set_panel_formats (WPanel *p)
{
format_e *form;
char *err;
char *err;
int retcode = 0;
form = use_display_format (p, panel_format (p), &err, 0);
if (err){
g_free (err);
retcode = 1;
@ -1423,14 +1423,14 @@ set_panel_formats (WPanel *p)
else {
if (p->format)
delete_format (p->format);
p->format = form;
}
if (show_mini_info){
form = use_display_format (p, mini_status_format (p), &err, 1);
if (err){
g_free (err);
retcode += 2;
@ -1438,11 +1438,11 @@ set_panel_formats (WPanel *p)
else {
if (p->status_format)
delete_format (p->status_format);
p->status_format = form;
}
}
panel_format_modified (p);
panel_update_cols (&(p->widget), p->frame_size);
@ -1456,7 +1456,7 @@ set_panel_formats (WPanel *p)
g_free (p->user_status_format [p->list_type]);
p->user_status_format [p->list_type] = g_strdup (DEFAULT_USER_FORMAT);
}
return retcode;
}
@ -1528,7 +1528,7 @@ select_item (WPanel *panel)
{
int repaint = 0;
int items = ITEMS (panel);
/* Although currently all over the code we set the selection and
top file to decent values before calling select_item, I could
forget it someday, so it's better to do the actual fitting here */
@ -1540,7 +1540,7 @@ select_item (WPanel *panel)
if (is_a_desktop_panel (panel))
return;
if (panel->top_file < 0){
repaint = 1;
panel->top_file = 0;
@ -1556,14 +1556,14 @@ select_item (WPanel *panel)
repaint = 1;
panel->top_file = panel->count-1;
}
if ((panel->count - panel->top_file) < items){
repaint = 1;
panel->top_file = panel->count - items;
if (panel->top_file < 0)
panel->top_file = 0;
}
if (panel->selected < panel->top_file){
repaint = 1;
panel->top_file = panel->selected;
@ -1574,7 +1574,7 @@ select_item (WPanel *panel)
panel->top_file = panel->selected - items + 1;
}
#ifndef HAVE_X
#ifndef HAVE_X
if (repaint)
paint_panel (panel);
else
@ -1625,7 +1625,7 @@ do_move_down (WPanel *panel)
{
if (panel->selected+1 == panel->count)
return;
unselect_item (panel);
panel->selected++;
@ -1666,7 +1666,7 @@ static void
move_rel (WPanel *panel, int rel)
{
unselect_item (panel);
if (rel < 0){
if (panel->selected + rel < 0)
panel->selected = 0;
@ -1726,12 +1726,12 @@ move_selection (WPanel *panel, int lines)
panel->top_file += lines;
adjust = 1;
}
if (panel->selected - panel->top_file < 0){
panel->top_file += lines;
adjust = 1;
}
if (adjust){
if (panel->top_file > panel->selected)
panel->top_file = panel->selected;
@ -1749,11 +1749,11 @@ move_left (WPanel *panel, int c_code)
if (panel->list_type == list_icons){
do_move_up (panel);
return 1;
} else {
} else {
if (panel->split){
move_selection (panel, -llines (panel));
return 1;
} else
} else
return maybe_cd (c_code, 0);
}
}
@ -1886,7 +1886,7 @@ move_home (WPanel *panel)
if (panel->selected == 0)
return;
unselect_item (panel);
if (torben_fj_mode){
int middle_pos = panel->top_file + (ITEMS (panel)/2);
@ -1899,7 +1899,7 @@ move_home (WPanel *panel)
return;
}
}
panel->top_file = 0;
panel->selected = 0;
@ -1927,7 +1927,7 @@ move_end (WPanel *panel)
return;
}
}
panel->selected = panel->count-1;
#ifndef HAVE_X
paint_dir (panel);
@ -1973,7 +1973,7 @@ do_file_mark (WPanel *panel, int idx, int mark)
if (panel->dir.list [idx].f.dir_size_computed)
panel->total += panel->dir.list [idx].buf.st_size;
panel->dirs_marked++;
} else
} else
panel->total += panel->dir.list [idx].buf.st_size;
set_colors (panel);
} else {
@ -1996,7 +1996,7 @@ do_file_mark_range (WPanel *panel, int r1, int r2)
int i, mark;
mark = !panel->dir.list [start].f.marked;
for (i = start; i < end; i++)
do_file_mark (panel, i, mark);
}
@ -2057,7 +2057,7 @@ do_search (WPanel *panel, int c_code)
}
if (!found)
panel->search_buffer [--l] = 0;
#ifndef HAVE_X
#ifndef HAVE_X
paint_panel (panel);
#endif
}
@ -2087,7 +2087,8 @@ int
do_enter_on_file_entry (file_entry *fe)
{
gint retval;
char *full_name;
set_cursor_busy (cpanel);
/* Can we change dirs? */
if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe)) {
@ -2101,10 +2102,12 @@ do_enter_on_file_entry (file_entry *fe)
return 1;
}
/* can we change dirs? */
if (is_exe (fe->buf.st_mode) && if_link_is_exe (cpanel->cwd, fe)) {
#ifdef USE_VFS
if (vfs_current_is_local ())
#endif
full_name = concat_dir_and_file (cpanel->cwd, fe->fname);
if (is_exe (fe->buf.st_mode) && if_link_is_exe (full_name, fe)) {
g_free (full_name);
#ifdef USE_VFS
if (vfs_current_is_local ())
#endif
{
char *tmp = name_quote (fe->fname, 0);
char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, NULL);
@ -2112,39 +2115,47 @@ do_enter_on_file_entry (file_entry *fe)
_(" Do you really want to execute? "),
0, 2, _("Yes"), _("No")) == 0))
execute (cmd);
g_free (tmp);
g_free (cmd);
}
#ifdef USE_VFS
}
#ifdef USE_VFS
else {
char *tmp;
tmp = concat_dir_and_file (vfs_get_current_dir(), fe->fname);
if (!mc_setctl (tmp, MCCTL_EXTFS_RUN, NULL))
message (1, _(" Warning "), _(" No action taken "));
g_free (tmp);
}
#endif /* USE_VFS */
#endif /* USE_VFS */
set_cursor_normal (cpanel);
return 1;
}
g_free (full_name);
/* looks like we couldn't open it. Let's ask the user */
retval = gmc_open_with (fe->fname);
set_cursor_normal (cpanel);
return retval;
}
}
#else
int
do_enter_on_file_entry (file_entry *fe)
{
char *full_name;
if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe)) {
do_cd (fe->fname, cd_exact);
return 1;
} else {
if (is_exe (fe->buf.st_mode) && if_link_is_exe (cpanel->cwd, fe)) {
#ifdef USE_VFS
if (vfs_current_is_local ())
#endif
full_name = concat_dir_and_file (cpanel->cwd, fe->fname);
if (is_exe (fe->buf.st_mode) && if_link_is_exe (full_name, fe)) {
g_free (full_name);
#ifdef USE_VFS
if (vfs_current_is_local ())
#endif
{
char *tmp = name_quote (fe->fname, 0);
char *cmd = g_strconcat (".", PATH_SEP_STR, tmp, NULL);
@ -2154,8 +2165,8 @@ do_enter_on_file_entry (file_entry *fe)
execute (cmd);
g_free (tmp);
g_free (cmd);
}
#ifdef USE_VFS
}
#ifdef USE_VFS
else {
/* if (vfs_current_is_extfs ()) - I see no reason why
filesystems other than extfs could not implement same
@ -2168,12 +2179,13 @@ do_enter_on_file_entry (file_entry *fe)
g_free (tmp);
}
#endif /* USE_VFS */
#endif /* USE_VFS */
return 1;
} else {
char *p;
g_free (full_name);
p = regex_command (fe->fname, "Open", NULL, 0);
if (p && (strcmp (p, "Success") == 0))
return 1;
@ -2181,7 +2193,7 @@ do_enter_on_file_entry (file_entry *fe)
return 0;
}
}
}
}
#endif /* else not HAVE_GNOME */
int
do_enter (WPanel *panel)
@ -2207,7 +2219,7 @@ chdir_other_panel (WPanel *panel)
change_panel ();
move_down (panel);
g_free (new_dir);
}
@ -2223,7 +2235,7 @@ chdir_to_readlink (WPanel *panel)
char buffer [MC_MAXPATHLEN], *p;
int i;
struct stat mybuf;
i = readlink (selection (panel)->fname, buffer, MC_MAXPATHLEN);
if (i < 0)
return;
@ -2248,9 +2260,9 @@ chdir_to_readlink (WPanel *panel)
change_panel ();
do_cd (new_dir, cd_exact);
change_panel ();
move_down (panel);
g_free (new_dir);
}
}
@ -2281,7 +2293,7 @@ static key_map panel_keymap [] = {
{ ALT(KEY_F(12)), drive_cmd_b },
{ ALT('d'), drive_chg },
#endif
/* Emacs-like bindings */
{ XCTRL('v'), next_page }, /* C-v like emacs */
{ ALT('v'), prev_page }, /* M-v like emacs */
@ -2304,7 +2316,7 @@ static key_map panel_keymap [] = {
{ KEY_KP_SUBTRACT, unselect_cmd_panel },
{ ALT('*'), reverse_selection_cmd_panel },
{ KEY_KP_MULTIPLY, reverse_selection_cmd_panel },
#ifdef HAVE_GNOME
{ '+', select_cmd_panel },
@ -2320,10 +2332,10 @@ static key_map panel_keymap [] = {
{ KEY_F(8), delete_cmd },
{ KEY_DC, delete_cmd },
#endif
{ 0, 0 }
};
static inline int
panel_key (WPanel *panel, int key)
{
@ -2388,9 +2400,9 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
define_label (h, (Widget *)panel, 7, _("Mkdir"), mkdir_panel_cmd);
define_label (h, (Widget *)panel, 8, _("Delete"), delete_cmd);
x_create_panel (h, h->wdata, panel);
#endif
#endif
return 1;
case WIDGET_DRAW:
paint_panel (panel);
break;
@ -2405,10 +2417,10 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
panel->cwd, unix_error_string (errno));
} else
subshell_chdir (panel->cwd);
show_dir (panel);
focus_select_item (panel);
#ifndef HAVE_X
#ifndef HAVE_X
define_label (h, (Widget *)panel, 1, _("Help"), help_cmd);
define_label (h, (Widget *)panel, 2, _("Menu"), user_menu_cmd);
define_label (h, (Widget *)panel, 3, _("View"), view_panel_cmd);
@ -2422,14 +2434,14 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
/* Chain behaviour */
default_proc (h, WIDGET_FOCUS, par);
return 1;
case WIDGET_UNFOCUS:
/* Janne: look at this for the multiple panel options */
if (panel->searching){
panel->searching = 0;
display_mini_info (panel);
}
#ifdef HAVE_X
#ifdef HAVE_X
show_dir (panel);
unfocus_unselect_item (panel);
panel->active = 0;
@ -2439,7 +2451,7 @@ panel_callback (Dlg_head *h, WPanel *panel, int msg, int par)
unselect_item (panel);
#endif
return 1;
case WIDGET_KEY:
return panel_key (panel, par);
break;
@ -2512,7 +2524,7 @@ int
panel_event (Gpm_Event *event, WPanel *panel)
{
const int lines = panel->count;
int my_index;
extern void change_panel (void);
@ -2540,7 +2552,7 @@ panel_event (Gpm_Event *event, WPanel *panel)
if (my_index >= panel->count)
my_index = panel->count - 1;
if (my_index != panel->selected){
unselect_item (panel);
panel->selected = my_index;
@ -2549,7 +2561,7 @@ panel_event (Gpm_Event *event, WPanel *panel)
/* This one is new */
mark_if_marking (panel, event);
} else if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){
if (event->y > 0 && event->y <= lines)
do_enter (panel);
@ -2563,7 +2575,7 @@ int
panel_event (Gpm_Event *event, WPanel *panel)
{
const int lines = llines (panel);
int my_index;
extern void change_panel (void);
@ -2614,7 +2626,7 @@ panel_event (Gpm_Event *event, WPanel *panel)
if (my_index >= panel->count)
my_index = panel->count - 1;
if (my_index != panel->selected){
unselect_item (panel);
panel->selected = my_index;
@ -2623,7 +2635,7 @@ panel_event (Gpm_Event *event, WPanel *panel)
/* This one is new */
mark_if_marking (panel, event);
} else if ((event->type & (GPM_UP|GPM_DOUBLE)) == (GPM_UP|GPM_DOUBLE)){
if (event->y > 0 && event->y <= lines)
do_enter (panel);
@ -2648,7 +2660,7 @@ panel_re_sort (WPanel *panel)
if (panel == NULL)
return;
filename = g_strdup (selection (panel)->fname);
unselect_item (panel);
do_sort (&panel->dir, panel->sort_type, panel->count-1, panel->reverse, panel->case_sensitive);
@ -2678,7 +2690,7 @@ panel_set_sort_order (WPanel *panel, sortfn *sort_order)
/* The directory is already sorted, we have to load the unsorted stuff */
if (sort_order == (sortfn *) unsorted){
char *current_file;
current_file = g_strdup (panel->dir.list [panel->selected].fname);
panel_reload (panel);
try_to_select (panel, current_file);