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>
38 # include <sys/mman.h>
45 #include "cmd.h" /* Our definitions */
46 #include "view.h" /* view() */
47 #include "dialog.h" /* query_dialog, message */
48 #include "file.h" /* the file operations */
49 #include "fileopctx.h"
50 #include "find.h" /* do_find */
53 #include "subshell.h" /* use_subshell */
54 #include "cons.saver.h"
55 #include "dlg.h" /* required by wtools.h */
56 #include "widget.h" /* required by wtools.h */
57 #include "wtools.h" /* listbox */
58 #include "command.h" /* for cmdline */
59 #include "win.h" /* do_exit_ca_mode */
60 #include "layout.h" /* get_current/other_type */
61 #include "ext.h" /* regex_command */
62 #include "key.h" /* get_key_code */
63 #include "help.h" /* interactive_display */
64 #include "boxes.h" /* cd_dialog */
72 #include "main.h" /* global variables, global functions */
77 /* If set and you don't have subshell support,then C-o will give you a shell */
78 int output_starts_shell
= 0;
80 /* Source routing destination */
83 /* If set, use the builtin editor */
84 int use_internal_edit
= 1;
86 /* Ugly hack in order to distinguish between left and right panel in menubar */
88 #define MENU_PANEL_IDX (is_right ? 1 : 0)
91 /* This is used since the parameter panel on some of the commands */
92 /* defined in this file may receive a 0 parameter if they are invoked */
93 /* The drop down menu */
96 get_a_panel (WPanel
*panel
)
100 if (get_current_type () == view_listing
){
106 /* view_file (filename, normal, internal)
109 * filename: The file name to view
110 * plain_view: If set does not do any fancy pre-processing (no filtering) and
111 * always invokes the internal viewer.
112 * internal: If set uses the internal viewer, otherwise an external viewer.
114 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
116 static char *viewer
= 0;
121 int changed_hex_mode
= 0;
122 int changed_nroff_flag
= 0;
123 int changed_magic_flag
= 0;
125 altered_hex_mode
= 0;
126 altered_nroff_flag
= 0;
127 altered_magic_flag
= 0;
128 if (default_hex_mode
)
129 changed_hex_mode
= 1;
130 if (default_nroff_flag
)
131 changed_nroff_flag
= 1;
132 if (default_magic_flag
)
133 changed_magic_flag
= 1;
134 default_hex_mode
= 0;
135 default_nroff_flag
= 0;
136 default_magic_flag
= 0;
137 view (0, filename
, &move_dir
, start_line
);
138 if (changed_hex_mode
&& !altered_hex_mode
)
139 default_hex_mode
= 1;
140 if (changed_nroff_flag
&& !altered_nroff_flag
)
141 default_nroff_flag
= 1;
142 if (changed_magic_flag
&& !altered_magic_flag
)
143 default_magic_flag
= 1;
148 char view_entry
[BUF_TINY
];
151 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
153 strcpy (view_entry
, "View");
155 if (!regex_command (filename
, view_entry
, &move_dir
)){
156 view (0, filename
, &move_dir
, start_line
);
163 viewer
= getenv ("PAGER");
167 /* The file may be a non local file, get a copy */
168 if (!vfs_file_is_local (filename
)){
169 localcopy
= mc_getlocalcopy (filename
);
170 if (localcopy
== NULL
){
171 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
174 execute_internal (viewer
, localcopy
);
175 mc_ungetlocalcopy (filename
, localcopy
, 0);
177 execute_internal (viewer
, filename
);
183 view_file (char *filename
, int plain_view
, int internal
)
185 return view_file_at_line (filename
, plain_view
, internal
, 0);
188 /* scan_for_file (panel, idx, direction)
191 * panel: pointer to the panel on which we operate
192 * idx: starting file.
193 * direction: 1, or -1
195 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
197 int i
= idx
+ direction
;
201 i
= panel
->count
- 1;
202 if (i
== panel
->count
)
204 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
211 /* do_view: Invoked as the F3/F13 key. */
212 static void do_view_cmd (WPanel
*panel
, int normal
)
215 panel
= get_a_panel (panel
);
217 /* Directories are viewed by changing to them */
218 if (S_ISDIR (selection (panel
)->buf
.st_mode
) ||
219 link_isdir (selection (panel
))) {
220 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)){
221 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
222 0, 2, _("&Yes"), _("&No")) == 1){
226 if (!do_cd (selection (panel
)->fname
, cd_exact
))
227 message (1, MSG_ERROR
, _("Could not change directory") );
233 file_idx
= panel
->selected
;
237 filename
= panel
->dir
.list
[file_idx
].fname
;
239 dir
= view_file (filename
, normal
, use_internal_view
);
242 file_idx
= scan_for_file (panel
, file_idx
, dir
);
246 void view_cmd (WPanel
*panel
)
248 do_view_cmd (panel
, 0);
251 void view_file_cmd (WPanel
*panel
)
255 panel
= get_a_panel (panel
);
256 filename
= input_dialog (_(" View file "), _(" Filename:"), selection (panel
)->fname
);
257 if (!filename
) return;
259 view_file (filename
, 0, use_internal_view
);
263 void view_simple_cmd (WPanel
*panel
)
265 do_view_cmd (panel
, 1);
268 void filtered_view_cmd (WPanel
*panel
)
272 panel
= get_a_panel (panel
);
273 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
274 selection (panel
)->fname
);
278 view (command
, "", 0, 0);
283 void filtered_view_cmd_cpanel (void)
285 filtered_view_cmd (cpanel
);
288 void do_edit_at_line (const char *what
, int start_line
)
290 static char *editor
= 0;
292 #ifdef USE_INTERNAL_EDIT
293 if (use_internal_edit
){
294 edit (what
, start_line
);
295 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
299 #endif /* USE_INTERNAL_EDIT */
301 editor
= getenv ("EDITOR");
303 editor
= get_default_editor ();
305 execute_internal (editor
, what
);
306 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
311 do_edit (const char *what
)
313 do_edit_at_line (what
, 1);
316 void edit_cmd (WPanel
*panel
)
318 panel
= get_a_panel(panel
);
319 if (!regex_command (selection (panel
)->fname
, "Edit", 0))
320 do_edit (selection (panel
)->fname
);
323 void edit_cmd_new (WPanel
*panel
)
328 /* Invoked by F5. Copy, default to the other panel. */
332 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)){
333 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
338 /* Invoked by F6. Move/rename, default to the other panel. */
342 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
343 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
348 /* Invoked by F15. Copy, default to the same panel. */
349 void copy_cmd_local (void)
352 if (panel_operate (cpanel
, OP_COPY
, selection (cpanel
)->fname
, TRUE
)){
353 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
358 /* Invoked by F16. Move/rename, default to the same panel. */
359 void ren_cmd_local (void)
362 if (panel_operate (cpanel
, OP_MOVE
, selection (cpanel
)->fname
, TRUE
)){
363 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
368 void mkdir_cmd (WPanel
*panel
)
373 panel
= get_a_panel (panel
);
374 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
379 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
380 tempdir
= g_strdup (dir
);
382 tempdir
= concat_dir_and_file (panel
->cwd
, dir
);
386 if (my_mkdir (tempdir
, 0777) == 0){
387 update_panels (UP_OPTIMIZE
, tempdir
);
389 select_item (cpanel
);
394 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
397 void delete_cmd (void)
401 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
402 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
413 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
419 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
420 p
->filter
= allocated_filter_string
;
422 g_free (allocated_filter_string
);
426 /* Set a given panel filter expression */
427 void set_panel_filter (WPanel
*p
)
432 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
434 reg_exp
= input_dialog_help (_(" Filter "),
435 _(" Set expression for filtering filenames"),
439 set_panel_filter_to (p
, reg_exp
);
442 /* Invoked from the left/right menus */
443 void filter_cmd (void)
447 if (!SELECTED_IS_PANEL
)
451 set_panel_filter (p
);
454 void reread_cmd (void)
458 if (get_current_type () == view_listing
&&
459 get_other_type () == view_listing
)
460 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
462 flag
= UP_ONLY_CURRENT
;
464 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
468 /* Panel sorting related routines */
469 void do_re_sort (WPanel
*panel
)
471 panel
= get_a_panel (panel
);
472 panel_re_sort (panel
);
475 void reverse_selection_cmd_panel (WPanel
*panel
)
480 for (i
= 0; i
< panel
->count
; i
++){
481 file
= &panel
->dir
.list
[i
];
482 if (S_ISDIR (file
->buf
.st_mode
))
484 do_file_mark (panel
, i
, !file
->f
.marked
);
489 void reverse_selection_cmd (void)
491 reverse_selection_cmd_panel (cpanel
);
494 void select_cmd_panel (WPanel
*panel
)
496 char *reg_exp
, *reg_exp_t
;
501 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
507 /* Check if they specified a directory */
508 if (*reg_exp_t
== PATH_SEP
){
512 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
514 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
517 for (i
= 0; i
< panel
->count
; i
++){
518 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
520 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
527 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
529 message (1, MSG_ERROR
, _(" Malformed regular expression "));
534 do_file_mark (panel
, i
, 1);
541 void select_cmd (void)
543 select_cmd_panel (cpanel
);
546 void unselect_cmd_panel (WPanel
*panel
)
548 char *reg_exp
, *reg_exp_t
;
553 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
559 /* Check if they specified directory matching */
560 if (*reg_exp_t
== PATH_SEP
){
564 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
566 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
568 for (i
= 0; i
< panel
->count
; i
++){
569 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
571 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
578 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
580 message (1, MSG_ERROR
, _(" Malformed regular expression "));
585 do_file_mark (panel
, i
, 0);
592 void unselect_cmd (void)
594 unselect_cmd_panel (cpanel
);
597 /* Check if the file exists */
598 /* If not copy the default */
599 int check_for_default(char *default_file
, char *file
)
606 if (mc_stat (file
, &s
)){
607 if (mc_stat (default_file
, &s
)){
610 ctx
= file_op_context_new ();
611 file_op_context_create_ui (ctx
, OP_COPY
, 0);
612 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
613 file_op_context_destroy (ctx
);
625 if (geteuid () == 0){
626 dir
= query_dialog (_("Extension file edit"),
627 _(" Which extension file you want to edit? "), 0, 2,
628 _("&User"), _("&System Wide"));
630 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
633 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
634 check_for_default (extdir
, buffer
);
641 flush_extension_file ();
644 #ifdef USE_INTERNAL_EDIT
645 void edit_syntax_cmd (void)
651 if (geteuid () == 0){
652 dir
= query_dialog (_("Syntax file edit"),
653 _(" Which syntax file you want to edit? "), 0, 2,
654 _("&User"), _("&System Wide"));
656 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
659 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
660 check_for_default (extdir
, buffer
);
670 /* where = 0 - do edit a file menu for mc */
671 /* where = 1 - do edit a file menu for cool edit */
672 void menu_edit_cmd (int where
)
680 _(" Which menu file will you edit ? "),
681 0, geteuid() ? 2 : 3,
682 _("&Local"), _("&Home"), _("&System Wide")
685 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
689 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
690 check_for_default (menufile
, buffer
);
694 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
695 check_for_default (menufile
, buffer
);
699 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
713 void quick_chdir_cmd (void)
717 target
= hotlist_cmd (LIST_HOTLIST
);
721 if (get_current_type () == view_tree
)
722 tree_chdir (the_tree
, target
);
724 if (!do_cd (target
, cd_exact
))
725 message (1, MSG_ERROR
, _("Could not change directory") );
730 void free_vfs_now (void)
735 void reselect_vfs (void)
739 target
= hotlist_cmd (LIST_VFSLIST
);
743 if (!do_cd (target
, cd_exact
))
744 message (1, MSG_ERROR
, _("Could not change directory") );
749 static int compare_files (char *name1
, char *name2
, off_t size
)
752 int result
= -1; /* Different by default */
754 file1
= open (name1
, O_RDONLY
);
756 file2
= open (name2
, O_RDONLY
);
761 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
762 if (data1
!= (char*) -1){
763 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
764 if (data2
!= (char*) -1){
766 result
= memcmp (data1
, data2
, size
);
767 munmap (data2
, size
);
769 munmap (data1
, size
);
772 /* Don't have mmap() :( Even more ugly :) */
773 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
778 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
779 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
780 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
781 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
782 #endif /* !HAVE_MMAP */
791 compare_quick
, compare_size_only
, compare_thourough
795 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
798 char *src_name
, *dst_name
;
800 panel
= get_a_panel (panel
);
802 /* No marks by default */
805 panel
->dirs_marked
= 0;
807 /* Handle all files in the panel */
808 for (i
= 0; i
< panel
->count
; i
++){
809 file_entry
*source
= &panel
->dir
.list
[i
];
811 /* Default: unmarked */
812 file_mark (panel
, i
, 0);
814 /* Skip directories */
815 if (S_ISDIR (source
->buf
.st_mode
))
818 /* Search the corresponding entry from the other panel */
819 for (j
= 0; j
< other
->count
; j
++){
820 if (strcmp (source
->fname
,
821 other
->dir
.list
[j
].fname
) == 0)
824 if (j
>= other
->count
)
825 /* Not found -> mark */
826 do_file_mark (panel
, i
, 1);
829 file_entry
*target
= &other
->dir
.list
[j
];
831 if (mode
!= compare_size_only
){
832 /* Older version is not marked */
833 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
837 /* Newer version with different size is marked */
838 if (source
->buf
.st_size
!= target
->buf
.st_size
){
839 do_file_mark (panel
, i
, 1);
843 if (mode
== compare_size_only
)
846 if (mode
== compare_quick
){
847 /* Thorough compare off, compare only time stamps */
848 /* Mark newer version, don't mark version with the same date */
849 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
850 do_file_mark (panel
, i
, 1);
855 /* Thorough compare on, do byte-by-byte comparison */
856 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
857 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
858 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
859 do_file_mark (panel
, i
, 1);
866 void compare_dirs_cmd (void)
868 enum CompareMode thorough_flag
= compare_quick
;
870 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
871 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
872 if (thorough_flag
< 0 || thorough_flag
> 2)
874 if (get_current_type () == view_listing
&&
875 get_other_type () == view_listing
){
876 compare_dir (cpanel
, opanel
, thorough_flag
);
877 compare_dir (opanel
, cpanel
, thorough_flag
);
878 paint_panel (cpanel
);
879 paint_panel (opanel
);
881 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
891 if (cmdline
->need_push
) {
892 if (push_history (cmdline
, cmdline
->buffer
) == 2)
893 cmdline
->need_push
= 0;
895 if (!cmdline
->history
) {
896 message (1, MSG_ERROR
, _(" The command history is empty "));
899 current
= 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
, current
);
906 current
= current
->next
;
908 run_dlg (listbox
->dlg
);
909 if (listbox
->dlg
->ret_value
== B_CANCEL
)
912 current
= listbox
->list
->current
->data
;
913 destroy_dlg (listbox
->dlg
);
918 cmdline
->history
= current
;
919 assign_text (cmdline
, cmdline
->history
->text
);
920 update_input (cmdline
, 1);
931 view_other_cmd (void)
933 static int message_flag
= TRUE
;
934 #ifdef HAVE_SUBSHELL_SUPPORT
935 char *new_dir
= NULL
;
937 #endif /* HAVE_SUBSHELL_SUPPORT */
939 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
941 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
942 " the panels cannot be toggled. "));
943 message_flag
= FALSE
;
947 if (clear_before_exec
)
949 if (alternate_plus_minus
)
950 numeric_keypad_mode ();
952 /* With slang we don't want any of this, since there
953 * is no mc_raw_mode supported
957 #endif /* !HAVE_SLANG */
958 keypad(stdscr
, FALSE
);
965 #ifdef HAVE_SUBSHELL_SUPPORT
967 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
968 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
969 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
971 #endif /* HAVE_SUBSHELL_SUPPORT */
973 if (output_starts_shell
){
975 _("Type `exit' to return to the Midnight Commander"));
976 fprintf (stderr
, "\n\r\n\r");
978 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
983 handle_console (CONSOLE_SAVE
);
988 keypad(stdscr
, TRUE
);
990 /* Prevent screen flash when user did 'exit' or 'logout' within
997 if (alternate_plus_minus
)
998 application_keypad_mode ();
1000 #ifdef HAVE_SUBSHELL_SUPPORT
1004 do_possible_cd (new_dir
);
1005 if (console_flag
&& output_lines
)
1006 show_console_contents (output_start_y
,
1007 LINES
-keybar_visible
-output_lines
-1,
1008 LINES
-keybar_visible
-1);
1010 #endif /* HAVE_SUBSHELL_SUPPORT */
1017 #ifndef NATIVE_WIN32
1019 do_link (int symbolic_link
, char *fname
)
1023 if (!symbolic_link
) {
1024 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
1025 dest
= input_expand_dialog (_(" Link "), src
, "");
1034 if (-1 == mc_link (fname
, dest
))
1035 message (1, MSG_ERROR
, _(" link: %s "),
1036 unix_error_string (errno
));
1041 /* suggest the full path for symlink */
1042 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1044 if (get_other_type () == view_listing
) {
1045 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1047 d
= g_strdup (fname
);
1050 symlink_dialog (s
, d
, &dest
, &src
);
1054 if (!dest
|| !*dest
|| !src
|| !*src
) {
1062 if (-1 == mc_symlink (dest
, src
))
1063 message (1, MSG_ERROR
, _(" symlink: %s "),
1064 unix_error_string (errno
));
1068 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1072 void link_cmd (void)
1074 do_link (0, selection (cpanel
)->fname
);
1077 void symlink_cmd (void)
1079 char *filename
= NULL
;
1080 filename
= selection (cpanel
)->fname
;
1083 do_link (1, filename
);
1087 void edit_symlink_cmd (void)
1089 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1090 char buffer
[MC_MAXPATHLEN
];
1095 p
= selection (cpanel
)->fname
;
1097 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1099 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1102 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1104 if (*dest
&& strcmp (buffer
, dest
)) {
1106 if (-1 == mc_unlink (p
)){
1107 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1108 p
, unix_error_string (errno
));
1110 if (-1 == mc_symlink (dest
, p
))
1111 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1112 unix_error_string (errno
));
1114 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1122 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1123 selection (cpanel
)->fname
);
1126 #endif /* !NATIVE_WIN32 */
1128 void help_cmd (void)
1130 interactive_display (NULL
, "[main]");
1133 void view_panel_cmd (void)
1138 void edit_panel_cmd (void)
1143 void mkdir_panel_cmd (void)
1148 /* partly taken from dcigettext.c, returns "" for default locale */
1149 /* value should be freed by calling function g_free() */
1150 char *guess_message_value (void)
1152 static const char * const var
[] = {
1153 /* The highest priority value is the `LANGUAGE' environment
1154 variable. This is a GNU extension. */
1156 /* Setting of LC_ALL overwrites all other. */
1158 /* Next comes the name of the desired category. */
1160 /* Last possibility is the LANG environment variable. */
1162 /* NULL exit loops */
1167 char *locale
= NULL
;
1169 while (var
[i
] != NULL
) {
1170 locale
= getenv (var
[i
]);
1171 if (locale
!= NULL
&& locale
[0] != '\0')
1179 return g_strdup (locale
);
1182 /* Returns a random hint */
1183 char *get_random_hint (void)
1185 char *data
, *result
, *eol
;
1189 /* Do not change hints more often than one minute */
1196 if ((now
- last
) < 60)
1197 return g_strdup ("");
1200 static int last_sec
;
1201 static struct timeval tv
;
1203 gettimeofday (&tv
, NULL
);
1204 if (!(tv
.tv_sec
> last_sec
+60))
1205 return g_strdup ("");
1206 last_sec
= tv
.tv_sec
;
1207 #endif /* !SCO_FLAVOR */
1209 data
= load_mc_home_file (MC_HINT
, NULL
);
1214 srand ((short) now
);
1217 #endif /* !SCO_FLAVOR */
1218 /* get a random entry */
1219 len
= strlen (data
);
1220 start
= rand () % len
;
1222 for (;start
; start
--){
1223 if (data
[start
] == '\n'){
1228 eol
= strchr (&data
[start
], '\n');
1231 result
= g_strdup (&data
[start
]);
1236 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1238 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1243 if (!SELECTED_IS_PANEL
)
1246 machine
= input_dialog_help (text
,
1252 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1253 ugly as hell and leads to problems in vfs layer */
1255 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1256 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1258 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1260 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1261 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1263 message (1, MSG_ERROR
, _(" Could not chdir to %s "), cd_path
);
1267 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1272 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1275 void netlink_cmd (void)
1277 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1278 "[Network File System]", "/#mc:", 1);
1280 #endif /* WITH_MCFS */
1282 void ftplink_cmd (void)
1284 nice_cd (_(" FTP to machine "), _(machine_str
),
1285 "[FTP File System]", "/#ftp:", 1);
1288 void fishlink_cmd (void)
1290 nice_cd (_(" Shell link to machine "), _(machine_str
),
1291 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1295 void smblink_cmd (void)
1297 nice_cd (_(" SMB link to machine "), _(machine_str
),
1298 "[SMB File System]", "/#smb:", 0);
1300 #endif /* WITH_SMBFS */
1302 #ifdef HAVE_SETSOCKOPT
1303 void source_routing (void)
1308 source
= input_dialog (_(" Socket source routing setup "),
1309 _(" Enter host name to use as a source routing hop: "),
1314 hp
= gethostbyname (source
);
1317 message (1, _(" Host name "), _(" Error while looking up IP address "));
1320 source_route
= *((int *)hp
->h_addr
);
1322 #endif /* HAVE_SETSOCKOPT */
1323 #endif /* USE_NETCODE */
1325 #ifdef USE_EXT2FSLIB
1326 void undelete_cmd (void)
1328 nice_cd (_(" Undelete files on an ext2 file system "),
1329 _(" Enter device (without /dev/) to undelete\n "
1330 " files on: (F1 for details)"),
1331 "[Undelete File System]", "/#undel:", 0);
1333 #endif /* USE_EXT2FSLIB */
1335 void quick_cd_cmd (void)
1337 char *p
= cd_dialog ();
1340 char *q
= g_strconcat ("cd ", p
, NULL
);
1352 WPanel
*panel
= cpanel
;
1357 for (i
= 0; i
< panel
->count
; i
++)
1358 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1359 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1360 !panel
->dirs_marked
) &&
1361 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1363 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1364 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1365 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1368 recalculate_panel_summary (panel
);
1369 paint_panel (panel
);
1373 save_setup_cmd (void)
1379 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1381 message (0, _(" Setup "), str
);
1386 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1388 p
->user_mini_status
= use_msformat
;
1389 p
->list_type
= view_type
;
1391 if (view_type
== list_user
|| use_msformat
){
1392 g_free (p
->user_format
);
1393 p
->user_format
= user
;
1395 g_free (p
->user_status_format
[view_type
]);
1396 p
->user_status_format
[view_type
] = status
;
1398 set_panel_formats (p
);
1405 set_panel_formats (p
);
1412 info_cmd_no_menu (void)
1414 if (get_display_type (0) == view_info
)
1415 set_display_type (0, view_listing
);
1416 else if (get_display_type (1) == view_info
)
1417 set_display_type (1, view_listing
);
1419 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1423 quick_cmd_no_menu (void)
1425 if (get_display_type (0) == view_quick
)
1426 set_display_type (0, view_listing
);
1427 else if (get_display_type (1) == view_quick
)
1428 set_display_type (1, view_listing
);
1430 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1434 switch_to_listing (int panel_index
)
1436 if (get_display_type (panel_index
) != view_listing
)
1437 set_display_type (panel_index
, view_listing
);
1443 int view_type
, use_msformat
;
1444 char *user
, *status
;
1448 display_type
= get_display_type (MENU_PANEL_IDX
);
1449 if (display_type
== view_listing
)
1450 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1454 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1456 if (view_type
== -1)
1459 switch_to_listing (MENU_PANEL_IDX
);
1461 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1463 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1469 set_display_type (MENU_PANEL_IDX
, view_tree
);
1475 set_display_type (MENU_PANEL_IDX
, view_info
);
1479 quick_view_cmd (void)
1481 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1483 set_display_type (MENU_PANEL_IDX
, view_quick
);
1486 /* Handle the tree internal listing modes switching */
1488 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1490 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1492 switch_to_listing (panel_index
);
1493 p
->list_type
= listing_mode
;
1494 if (set_panel_formats (p
))
1503 toggle_listing_cmd (void)
1505 int current
= get_current_index ();
1506 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1507 int list_mode
= p
->list_type
;
1521 if (set_basic_panel_listing_to (current
, m
))
1523 set_basic_panel_listing_to (current
, list_full
);