1 /* Routines invoked by a function key
2 They normally operate on the current panel.
4 Copyright (C) 1994, 1995 Miguel de Icaza
5 Copyright (C) 1994, 1995 Janne Kukonlehto
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include <sys/types.h>
31 #include <fcntl.h> /* open, O_RDWR */
39 # include <sys/mman.h>
46 #include "cmd.h" /* Our definitions */
47 #include "view.h" /* view() */
48 #include "dialog.h" /* query_dialog, message */
49 #include "file.h" /* the file operations */
50 #include "fileopctx.h"
51 #include "find.h" /* do_find */
54 #include "subshell.h" /* use_subshell */
55 #include "cons.saver.h"
56 #include "dlg.h" /* required by wtools.h */
57 #include "widget.h" /* required by wtools.h */
58 #include "wtools.h" /* listbox */
59 #include "command.h" /* for input_w */
60 #include "win.h" /* do_exit_ca_mode */
61 #include "layout.h" /* get_current/other_type */
62 #include "ext.h" /* regex_command */
63 #include "key.h" /* get_key_code */
64 #include "help.h" /* interactive_display */
65 #include "boxes.h" /* cd_dialog */
73 #include "main.h" /* global variables, global functions */
78 /* If set and you don't have subshell support,then C-o will give you a shell */
79 int output_starts_shell
= 0;
81 /* Source routing destination */
84 /* If set, use the builtin editor */
85 int use_internal_edit
= 1;
87 /* Ugly hack in order to distinguish between left and right panel in menubar */
89 #define MENU_PANEL_IDX (is_right ? 1 : 0)
92 /* This is used since the parameter panel on some of the commands */
93 /* defined in this file may receive a 0 parameter if they are invoked */
94 /* The drop down menu */
97 get_a_panel (WPanel
*panel
)
101 if (get_current_type () == view_listing
){
107 /* view_file (filename, normal, internal)
110 * filename: The file name to view
111 * plain_view: If set does not do any fancy pre-processing (no filtering) and
112 * always invokes the internal viewer.
113 * internal: If set uses the internal viewer, otherwise an external viewer.
115 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
117 static char *viewer
= 0;
122 int changed_hex_mode
= 0;
123 int changed_nroff_flag
= 0;
124 int changed_magic_flag
= 0;
126 altered_hex_mode
= 0;
127 altered_nroff_flag
= 0;
128 altered_magic_flag
= 0;
129 if (default_hex_mode
)
130 changed_hex_mode
= 1;
131 if (default_nroff_flag
)
132 changed_nroff_flag
= 1;
133 if (default_magic_flag
)
134 changed_magic_flag
= 1;
135 default_hex_mode
= 0;
136 default_nroff_flag
= 0;
137 default_magic_flag
= 0;
138 view (0, filename
, &move_dir
, start_line
);
139 if (changed_hex_mode
&& !altered_hex_mode
)
140 default_hex_mode
= 1;
141 if (changed_nroff_flag
&& !altered_nroff_flag
)
142 default_nroff_flag
= 1;
143 if (changed_magic_flag
&& !altered_magic_flag
)
144 default_magic_flag
= 1;
149 char view_entry
[BUF_TINY
];
152 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
154 strcpy (view_entry
, "View");
156 if (!regex_command (filename
, view_entry
, &move_dir
)){
157 view (0, filename
, &move_dir
, start_line
);
164 viewer
= getenv ("PAGER");
168 /* The file may be a non local file, get a copy */
169 if (!vfs_file_is_local (filename
)){
170 localcopy
= mc_getlocalcopy (filename
);
171 if (localcopy
== NULL
){
172 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
175 execute_internal (viewer
, localcopy
);
176 mc_ungetlocalcopy (filename
, localcopy
, 0);
178 execute_internal (viewer
, filename
);
184 view_file (char *filename
, int plain_view
, int internal
)
186 return view_file_at_line (filename
, plain_view
, internal
, 0);
189 /* scan_for_file (panel, idx, direction)
192 * panel: pointer to the panel on which we operate
193 * idx: starting file.
194 * direction: 1, or -1
196 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
198 int i
= idx
+ direction
;
202 i
= panel
->count
- 1;
203 if (i
== panel
->count
)
205 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
212 /* do_view: Invoked as the F3/F13 key. */
213 static void do_view_cmd (WPanel
*panel
, int normal
)
216 panel
= get_a_panel (panel
);
218 /* Directories are viewed by changing to them */
219 if (S_ISDIR (selection (panel
)->buf
.st_mode
) ||
220 link_isdir (selection (panel
))) {
221 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)){
222 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
223 0, 2, _("&Yes"), _("&No")) == 1){
227 if (!do_cd (selection (panel
)->fname
, cd_exact
))
228 message (1, MSG_ERROR
, _("Could not change directory") );
234 file_idx
= panel
->selected
;
238 filename
= panel
->dir
.list
[file_idx
].fname
;
240 dir
= view_file (filename
, normal
, use_internal_view
);
243 file_idx
= scan_for_file (panel
, file_idx
, dir
);
247 void view_cmd (WPanel
*panel
)
249 do_view_cmd (panel
, 0);
252 void view_file_cmd (WPanel
*panel
)
256 panel
= get_a_panel (panel
);
257 filename
= input_dialog (_(" View file "), _(" Filename:"), selection (panel
)->fname
);
258 if (!filename
) return;
260 view_file (filename
, 0, use_internal_view
);
264 void view_simple_cmd (WPanel
*panel
)
266 do_view_cmd (panel
, 1);
269 void filtered_view_cmd (WPanel
*panel
)
273 panel
= get_a_panel (panel
);
274 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
275 selection (panel
)->fname
);
279 view (command
, "", 0, 0);
284 void filtered_view_cmd_cpanel (void)
286 filtered_view_cmd (cpanel
);
289 void do_edit_at_line (const char *what
, int start_line
)
291 static char *editor
= 0;
293 #ifdef USE_INTERNAL_EDIT
294 if (use_internal_edit
){
295 edit (what
, start_line
);
296 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
300 #endif /* USE_INTERNAL_EDIT */
302 editor
= getenv ("EDITOR");
304 editor
= get_default_editor ();
306 execute_internal (editor
, what
);
307 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
312 do_edit (const char *what
)
314 do_edit_at_line (what
, 1);
317 void edit_cmd (WPanel
*panel
)
319 panel
= get_a_panel(panel
);
320 if (!regex_command (selection (panel
)->fname
, "Edit", 0))
321 do_edit (selection (panel
)->fname
);
324 void edit_cmd_new (WPanel
*panel
)
329 /* Invoked by F5. Copy, default to the other panel. */
333 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)){
334 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
339 /* Invoked by F6. Move/rename, default to the other panel. */
343 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
344 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
349 /* Invoked by F15. Copy, default to the same panel. */
350 void copy_cmd_local (void)
353 if (panel_operate (cpanel
, OP_COPY
, selection (cpanel
)->fname
, TRUE
)){
354 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
359 /* Invoked by F16. Move/rename, default to the same panel. */
360 void ren_cmd_local (void)
363 if (panel_operate (cpanel
, OP_MOVE
, selection (cpanel
)->fname
, TRUE
)){
364 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
369 void mkdir_cmd (WPanel
*panel
)
374 panel
= get_a_panel (panel
);
375 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
380 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
381 tempdir
= g_strdup (dir
);
383 tempdir
= concat_dir_and_file (panel
->cwd
, dir
);
387 if (my_mkdir (tempdir
, 0777) == 0){
388 update_panels (UP_OPTIMIZE
, tempdir
);
390 select_item (cpanel
);
395 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
398 void delete_cmd (void)
402 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
403 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
414 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
420 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
421 p
->filter
= allocated_filter_string
;
423 g_free (allocated_filter_string
);
427 /* Set a given panel filter expression */
428 void set_panel_filter (WPanel
*p
)
433 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
435 reg_exp
= input_dialog_help (_(" Filter "),
436 _(" Set expression for filtering filenames"),
440 set_panel_filter_to (p
, reg_exp
);
443 /* Invoked from the left/right menus */
444 void filter_cmd (void)
448 if (!SELECTED_IS_PANEL
)
452 set_panel_filter (p
);
455 void reread_cmd (void)
459 if (get_current_type () == view_listing
&&
460 get_other_type () == view_listing
)
461 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
463 flag
= UP_ONLY_CURRENT
;
465 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
469 /* Panel sorting related routines */
470 void do_re_sort (WPanel
*panel
)
472 panel
= get_a_panel (panel
);
473 panel_re_sort (panel
);
476 void reverse_selection_cmd_panel (WPanel
*panel
)
481 for (i
= 0; i
< panel
->count
; i
++){
482 file
= &panel
->dir
.list
[i
];
483 if (S_ISDIR (file
->buf
.st_mode
))
485 do_file_mark (panel
, i
, !file
->f
.marked
);
490 void reverse_selection_cmd (void)
492 reverse_selection_cmd_panel (cpanel
);
495 void select_cmd_panel (WPanel
*panel
)
497 char *reg_exp
, *reg_exp_t
;
502 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
508 /* Check if they specified a directory */
509 if (*reg_exp_t
== PATH_SEP
){
513 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
515 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
518 for (i
= 0; i
< panel
->count
; i
++){
519 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
521 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
528 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
530 message (1, MSG_ERROR
, _(" Malformed regular expression "));
535 do_file_mark (panel
, i
, 1);
542 void select_cmd (void)
544 select_cmd_panel (cpanel
);
547 void unselect_cmd_panel (WPanel
*panel
)
549 char *reg_exp
, *reg_exp_t
;
554 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
560 /* Check if they specified directory matching */
561 if (*reg_exp_t
== PATH_SEP
){
565 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
567 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
569 for (i
= 0; i
< panel
->count
; i
++){
570 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
572 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
579 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
581 message (1, MSG_ERROR
, _(" Malformed regular expression "));
586 do_file_mark (panel
, i
, 0);
593 void unselect_cmd (void)
595 unselect_cmd_panel (cpanel
);
598 /* Check if the file exists */
599 /* If not copy the default */
600 int check_for_default(char *default_file
, char *file
)
607 if (mc_stat (file
, &s
)){
608 if (mc_stat (default_file
, &s
)){
611 ctx
= file_op_context_new ();
612 file_op_context_create_ui (ctx
, OP_COPY
, 0);
613 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
614 file_op_context_destroy (ctx
);
626 if (geteuid () == 0){
627 dir
= query_dialog (_("Extension file edit"),
628 _(" Which extension file you want to edit? "), 0, 2,
629 _("&User"), _("&System Wide"));
631 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
634 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
635 check_for_default (extdir
, buffer
);
642 flush_extension_file ();
645 #ifdef USE_INTERNAL_EDIT
646 void edit_syntax_cmd (void)
652 if (geteuid () == 0){
653 dir
= query_dialog (_("Syntax file edit"),
654 _(" Which syntax file you want to edit? "), 0, 2,
655 _("&User"), _("&System Wide"));
657 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
660 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
661 check_for_default (extdir
, buffer
);
671 /* where = 0 - do edit a file menu for mc */
672 /* where = 1 - do edit a file menu for cool edit */
673 void menu_edit_cmd (int where
)
681 _(" Which menu file will you edit ? "),
682 0, geteuid() ? 2 : 3,
683 _("&Local"), _("&Home"), _("&System Wide")
686 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
690 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
691 check_for_default (menufile
, buffer
);
695 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
696 check_for_default (menufile
, buffer
);
700 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
714 void quick_chdir_cmd (void)
718 target
= hotlist_cmd (LIST_HOTLIST
);
722 if (get_current_type () == view_tree
)
723 tree_chdir (the_tree
, target
);
725 if (!do_cd (target
, cd_exact
))
726 message (1, MSG_ERROR
, _("Could not change directory") );
731 void free_vfs_now (void)
736 void reselect_vfs (void)
740 target
= hotlist_cmd (LIST_VFSLIST
);
744 if (!do_cd (target
, cd_exact
))
745 message (1, MSG_ERROR
, _("Could not change directory") );
750 static int compare_files (char *name1
, char *name2
, off_t size
)
753 int result
= -1; /* Different by default */
755 file1
= open (name1
, O_RDONLY
);
757 file2
= open (name2
, O_RDONLY
);
762 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
763 if (data1
!= (char*) -1){
764 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
765 if (data2
!= (char*) -1){
767 result
= memcmp (data1
, data2
, size
);
768 munmap (data2
, size
);
770 munmap (data1
, size
);
773 /* Don't have mmap() :( Even more ugly :) */
774 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
779 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
780 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
781 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
782 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
783 #endif /* !HAVE_MMAP */
792 compare_quick
, compare_size_only
, compare_thourough
796 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
799 char *src_name
, *dst_name
;
801 panel
= get_a_panel (panel
);
803 /* No marks by default */
806 panel
->dirs_marked
= 0;
808 /* Handle all files in the panel */
809 for (i
= 0; i
< panel
->count
; i
++){
810 file_entry
*source
= &panel
->dir
.list
[i
];
812 /* Default: unmarked */
813 file_mark (panel
, i
, 0);
815 /* Skip directories */
816 if (S_ISDIR (source
->buf
.st_mode
))
819 /* Search the corresponding entry from the other panel */
820 for (j
= 0; j
< other
->count
; j
++){
821 if (strcmp (source
->fname
,
822 other
->dir
.list
[j
].fname
) == 0)
825 if (j
>= other
->count
)
826 /* Not found -> mark */
827 do_file_mark (panel
, i
, 1);
830 file_entry
*target
= &other
->dir
.list
[j
];
832 if (mode
!= compare_size_only
){
833 /* Older version is not marked */
834 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
838 /* Newer version with different size is marked */
839 if (source
->buf
.st_size
!= target
->buf
.st_size
){
840 do_file_mark (panel
, i
, 1);
844 if (mode
== compare_size_only
)
847 if (mode
== compare_quick
){
848 /* Thorough compare off, compare only time stamps */
849 /* Mark newer version, don't mark version with the same date */
850 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
851 do_file_mark (panel
, i
, 1);
856 /* Thorough compare on, do byte-by-byte comparison */
857 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
858 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
859 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
860 do_file_mark (panel
, i
, 1);
867 void compare_dirs_cmd (void)
869 enum CompareMode thorough_flag
= compare_quick
;
871 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
872 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
873 if (thorough_flag
< 0 || thorough_flag
> 2)
875 if (get_current_type () == view_listing
&&
876 get_other_type () == view_listing
){
877 compare_dir (cpanel
, opanel
, thorough_flag
);
878 compare_dir (opanel
, cpanel
, thorough_flag
);
879 paint_panel (cpanel
);
880 paint_panel (opanel
);
882 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
886 void history_cmd (void)
891 if (input_w (cmdline
)->need_push
){
892 if (push_history (input_w (cmdline
), input_w (cmdline
)->buffer
) == 2)
893 input_w (cmdline
)->need_push
= 0;
895 if (!input_w (cmdline
)->history
){
896 message (1, MSG_ERROR
, _(" The command history is empty "));
899 current
= input_w (cmdline
)->history
;
900 while (current
->prev
)
901 current
= current
->prev
;
902 listbox
= create_listbox_window (60, 10, _(" Command history "),
905 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
,
907 current
= current
->next
;
909 run_dlg (listbox
->dlg
);
910 if (listbox
->dlg
->ret_value
== B_CANCEL
)
913 current
= listbox
->list
->current
->data
;
914 destroy_dlg (listbox
->dlg
);
919 input_w (cmdline
)->history
= current
;
920 assign_text (input_w (cmdline
), input_w (cmdline
)->history
->text
);
921 update_input (input_w (cmdline
), 1);
932 view_other_cmd (void)
934 static int message_flag
= TRUE
;
935 #ifdef HAVE_SUBSHELL_SUPPORT
936 char *new_dir
= NULL
;
938 #endif /* HAVE_SUBSHELL_SUPPORT */
940 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
942 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
943 " the panels cannot be toggled. "));
944 message_flag
= FALSE
;
948 if (clear_before_exec
)
950 if (alternate_plus_minus
)
951 numeric_keypad_mode ();
953 /* With slang we don't want any of this, since there
954 * is no mc_raw_mode supported
958 #endif /* !HAVE_SLANG */
959 keypad(stdscr
, FALSE
);
966 #ifdef HAVE_SUBSHELL_SUPPORT
968 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
969 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
970 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
972 #endif /* HAVE_SUBSHELL_SUPPORT */
974 if (output_starts_shell
){
976 _("Type `exit' to return to the Midnight Commander"));
977 fprintf (stderr
, "\n\r\n\r");
979 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
984 handle_console (CONSOLE_SAVE
);
989 keypad(stdscr
, TRUE
);
991 /* Prevent screen flash when user did 'exit' or 'logout' within
998 if (alternate_plus_minus
)
999 application_keypad_mode ();
1001 #ifdef HAVE_SUBSHELL_SUPPORT
1005 do_possible_cd (new_dir
);
1006 if (console_flag
&& output_lines
)
1007 show_console_contents (output_start_y
,
1008 LINES
-keybar_visible
-output_lines
-1,
1009 LINES
-keybar_visible
-1);
1011 #endif /* HAVE_SUBSHELL_SUPPORT */
1018 #ifndef NATIVE_WIN32
1020 do_link (int symbolic_link
, char *fname
)
1024 if (!symbolic_link
) {
1025 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
1026 dest
= input_expand_dialog (_(" Link "), src
, "");
1035 if (-1 == mc_link (fname
, dest
))
1036 message (1, MSG_ERROR
, _(" link: %s "),
1037 unix_error_string (errno
));
1042 /* suggest the full path for symlink */
1043 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1045 if (get_other_type () == view_listing
) {
1046 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1048 d
= g_strdup (fname
);
1051 symlink_dialog (s
, d
, &dest
, &src
);
1055 if (!dest
|| !*dest
|| !src
|| !*src
) {
1063 if (-1 == mc_symlink (dest
, src
))
1064 message (1, MSG_ERROR
, _(" symlink: %s "),
1065 unix_error_string (errno
));
1069 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1073 void link_cmd (void)
1075 do_link (0, selection (cpanel
)->fname
);
1078 void symlink_cmd (void)
1080 char *filename
= NULL
;
1081 filename
= selection (cpanel
)->fname
;
1084 do_link (1, filename
);
1088 void edit_symlink_cmd (void)
1090 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1091 char buffer
[MC_MAXPATHLEN
];
1096 p
= selection (cpanel
)->fname
;
1098 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1100 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1103 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1105 if (*dest
&& strcmp (buffer
, dest
)) {
1107 if (-1 == mc_unlink (p
)){
1108 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1109 p
, unix_error_string (errno
));
1111 if (-1 == mc_symlink (dest
, p
))
1112 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1113 unix_error_string (errno
));
1115 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1123 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1124 selection (cpanel
)->fname
);
1129 other_symlink_cmd (void)
1131 char *dest
, *q
, *p
, *r
, *s
, *t
;
1133 if (get_other_type () != view_listing
)
1136 if (!strcmp (selection (opanel
)->fname
, ".."))
1138 p
= concat_dir_and_file (cpanel
->cwd
, selection (cpanel
)->fname
);
1139 r
= concat_dir_and_file (opanel
->cwd
, selection (cpanel
)->fname
);
1141 q
= g_strdup_printf (_("Link symbolically %s to:"),
1142 name_trunc (p
, 32));
1143 dest
= input_expand_dialog (_(" Relative symlink "), q
, r
);
1146 t
= strrchr (dest
, PATH_SEP
);
1149 s
= diff_two_paths (dest
, p
);
1153 if (-1 == mc_symlink (dest
, s
))
1154 message (1, MSG_ERROR
, _(" relative symlink: %s "),
1155 unix_error_string (errno
));
1156 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1168 #endif /* !NATIVE_WIN32 */
1170 void help_cmd (void)
1172 interactive_display (NULL
, "[main]");
1175 void view_panel_cmd (void)
1180 void edit_panel_cmd (void)
1185 void mkdir_panel_cmd (void)
1190 /* partly taken from dcigettext.c, returns "" for default locale */
1191 /* value should be freed by calling function g_free() */
1192 char *guess_message_value (void)
1194 static const char * const var
[] = {
1195 /* The highest priority value is the `LANGUAGE' environment
1196 variable. This is a GNU extension. */
1198 /* Setting of LC_ALL overwrites all other. */
1200 /* Next comes the name of the desired category. */
1202 /* Last possibility is the LANG environment variable. */
1204 /* NULL exit loops */
1209 char *locale
= NULL
;
1211 while (var
[i
] != NULL
) {
1212 locale
= getenv (var
[i
]);
1213 if (locale
!= NULL
&& locale
[0] != '\0')
1221 return g_strdup (locale
);
1224 /* Returns a random hint */
1225 char *get_random_hint (void)
1227 char *data
, *result
, *eol
;
1231 /* Do not change hints more often than one minute */
1238 if ((now
- last
) < 60)
1239 return g_strdup ("");
1242 static int last_sec
;
1243 static struct timeval tv
;
1245 gettimeofday (&tv
, NULL
);
1246 if (!(tv
.tv_sec
> last_sec
+60))
1247 return g_strdup ("");
1248 last_sec
= tv
.tv_sec
;
1249 #endif /* !SCO_FLAVOR */
1251 data
= load_mc_home_file (MC_HINT
, NULL
);
1256 srand ((short) now
);
1259 #endif /* !SCO_FLAVOR */
1260 /* get a random entry */
1261 len
= strlen (data
);
1262 start
= rand () % len
;
1264 for (;start
; start
--){
1265 if (data
[start
] == '\n'){
1270 eol
= strchr (&data
[start
], '\n');
1273 result
= g_strdup (&data
[start
]);
1278 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1280 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1285 if (!SELECTED_IS_PANEL
)
1288 machine
= input_dialog_help (text
,
1294 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1295 ugly as hell and leads to problems in vfs layer */
1297 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1298 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1300 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1302 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1303 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1305 message (1, MSG_ERROR
, _(" Could not chdir to %s "), cd_path
);
1309 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1314 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1317 void netlink_cmd (void)
1319 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1320 "[Network File System]", "/#mc:", 1);
1322 #endif /* WITH_MCFS */
1324 void ftplink_cmd (void)
1326 nice_cd (_(" FTP to machine "), _(machine_str
),
1327 "[FTP File System]", "/#ftp:", 1);
1330 void fishlink_cmd (void)
1332 nice_cd (_(" Shell link to machine "), _(machine_str
),
1333 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1337 void smblink_cmd (void)
1339 nice_cd (_(" SMB link to machine "), _(machine_str
),
1340 "[SMB File System]", "/#smb:", 0);
1342 #endif /* WITH_SMBFS */
1344 #ifdef HAVE_SETSOCKOPT
1345 void source_routing (void)
1350 source
= input_dialog (_(" Socket source routing setup "),
1351 _(" Enter host name to use as a source routing hop: "),
1356 hp
= gethostbyname (source
);
1359 message (1, _(" Host name "), _(" Error while looking up IP address "));
1362 source_route
= *((int *)hp
->h_addr
);
1364 #endif /* HAVE_SETSOCKOPT */
1365 #endif /* USE_NETCODE */
1367 #ifdef USE_EXT2FSLIB
1368 void undelete_cmd (void)
1370 nice_cd (_(" Undelete files on an ext2 file system "),
1371 _(" Enter device (without /dev/) to undelete\n "
1372 " files on: (F1 for details)"),
1373 "[Undelete File System]", "/#undel:", 0);
1375 #endif /* USE_EXT2FSLIB */
1377 void quick_cd_cmd (void)
1379 char *p
= cd_dialog ();
1382 char *q
= g_strconcat ("cd ", p
, NULL
);
1394 WPanel
*panel
= cpanel
;
1399 for (i
= 0; i
< panel
->count
; i
++)
1400 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1401 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1402 !panel
->dirs_marked
) &&
1403 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1405 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1406 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1407 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1410 recalculate_panel_summary (panel
);
1411 paint_panel (panel
);
1415 save_setup_cmd (void)
1421 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1423 message (0, _(" Setup "), str
);
1428 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1430 p
->user_mini_status
= use_msformat
;
1431 p
->list_type
= view_type
;
1433 if (view_type
== list_user
|| use_msformat
){
1434 g_free (p
->user_format
);
1435 p
->user_format
= user
;
1437 g_free (p
->user_status_format
[view_type
]);
1438 p
->user_status_format
[view_type
] = status
;
1440 set_panel_formats (p
);
1447 set_panel_formats (p
);
1454 info_cmd_no_menu (void)
1456 if (get_display_type (0) == view_info
)
1457 set_display_type (0, view_listing
);
1458 else if (get_display_type (1) == view_info
)
1459 set_display_type (1, view_listing
);
1461 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1465 quick_cmd_no_menu (void)
1467 if (get_display_type (0) == view_quick
)
1468 set_display_type (0, view_listing
);
1469 else if (get_display_type (1) == view_quick
)
1470 set_display_type (1, view_listing
);
1472 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1476 switch_to_listing (int panel_index
)
1478 if (get_display_type (panel_index
) != view_listing
)
1479 set_display_type (panel_index
, view_listing
);
1485 int view_type
, use_msformat
;
1486 char *user
, *status
;
1490 display_type
= get_display_type (MENU_PANEL_IDX
);
1491 if (display_type
== view_listing
)
1492 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1496 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1498 if (view_type
== -1)
1501 switch_to_listing (MENU_PANEL_IDX
);
1503 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1505 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1511 set_display_type (MENU_PANEL_IDX
, view_tree
);
1517 set_display_type (MENU_PANEL_IDX
, view_info
);
1521 quick_view_cmd (void)
1523 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1525 set_display_type (MENU_PANEL_IDX
, view_quick
);
1528 /* Handle the tree internal listing modes switching */
1530 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1532 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1534 switch_to_listing (panel_index
);
1535 p
->list_type
= listing_mode
;
1536 if (set_panel_formats (p
))
1545 toggle_listing_cmd (void)
1547 int current
= get_current_index ();
1548 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1549 int list_mode
= p
->list_type
;
1563 if (set_basic_panel_listing_to (current
, m
))
1565 set_basic_panel_listing_to (current
, list_full
);