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.
115 view_file_at_line (char *filename
, int plain_view
, int internal
,
118 static char *viewer
= 0;
123 int changed_hex_mode
= 0;
124 int changed_nroff_flag
= 0;
125 int changed_magic_flag
= 0;
127 altered_hex_mode
= 0;
128 altered_nroff_flag
= 0;
129 altered_magic_flag
= 0;
130 if (default_hex_mode
)
131 changed_hex_mode
= 1;
132 if (default_nroff_flag
)
133 changed_nroff_flag
= 1;
134 if (default_magic_flag
)
135 changed_magic_flag
= 1;
136 default_hex_mode
= 0;
137 default_nroff_flag
= 0;
138 default_magic_flag
= 0;
139 view (0, filename
, &move_dir
, start_line
);
140 if (changed_hex_mode
&& !altered_hex_mode
)
141 default_hex_mode
= 1;
142 if (changed_nroff_flag
&& !altered_nroff_flag
)
143 default_nroff_flag
= 1;
144 if (changed_magic_flag
&& !altered_magic_flag
)
145 default_magic_flag
= 1;
150 char view_entry
[BUF_TINY
];
153 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d",
156 strcpy (view_entry
, "View");
158 if (regex_command (filename
, view_entry
, &move_dir
) == 0) {
159 view (0, filename
, &move_dir
, start_line
);
166 viewer
= getenv ("PAGER");
170 /* The file may be a non local file, get a copy */
171 if (!vfs_file_is_local (filename
)) {
172 localcopy
= mc_getlocalcopy (filename
);
173 if (localcopy
== NULL
) {
174 message (1, MSG_ERROR
,
175 _(" Can not fetch a local copy of %s "),
179 execute_internal (viewer
, localcopy
);
180 mc_ungetlocalcopy (filename
, localcopy
, 0);
182 execute_internal (viewer
, filename
);
188 view_file (char *filename
, int plain_view
, int internal
)
190 return view_file_at_line (filename
, plain_view
, internal
, 0);
193 /* scan_for_file (panel, idx, direction)
196 * panel: pointer to the panel on which we operate
197 * idx: starting file.
198 * direction: 1, or -1
200 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
202 int i
= idx
+ direction
;
206 i
= panel
->count
- 1;
207 if (i
== panel
->count
)
209 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
216 /* do_view: Invoked as the F3/F13 key. */
218 do_view_cmd (WPanel
*panel
, int normal
)
221 panel
= get_a_panel (panel
);
223 /* Directories are viewed by changing to them */
224 if (S_ISDIR (selection (panel
)->buf
.st_mode
)
225 || link_isdir (selection (panel
))) {
226 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)) {
228 (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2,
229 _("&Yes"), _("&No")) != 0) {
233 if (!do_cd (selection (panel
)->fname
, cd_exact
))
234 message (1, MSG_ERROR
, _("Could not change directory"));
240 file_idx
= panel
->selected
;
244 filename
= panel
->dir
.list
[file_idx
].fname
;
246 dir
= view_file (filename
, normal
, use_internal_view
);
249 file_idx
= scan_for_file (panel
, file_idx
, dir
);
253 void view_cmd (WPanel
*panel
)
255 do_view_cmd (panel
, 0);
258 void view_file_cmd (WPanel
*panel
)
262 panel
= get_a_panel (panel
);
263 filename
= input_dialog (_(" View file "), _(" Filename:"), selection (panel
)->fname
);
264 if (!filename
) return;
266 view_file (filename
, 0, use_internal_view
);
270 void view_simple_cmd (WPanel
*panel
)
272 do_view_cmd (panel
, 1);
275 void filtered_view_cmd (WPanel
*panel
)
279 panel
= get_a_panel (panel
);
280 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
281 selection (panel
)->fname
);
285 view (command
, "", 0, 0);
290 void filtered_view_cmd_cpanel (void)
292 filtered_view_cmd (cpanel
);
295 void do_edit_at_line (const char *what
, int start_line
)
297 static char *editor
= 0;
299 #ifdef USE_INTERNAL_EDIT
300 if (use_internal_edit
){
301 edit (what
, start_line
);
302 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
306 #endif /* USE_INTERNAL_EDIT */
308 editor
= getenv ("EDITOR");
310 editor
= get_default_editor ();
312 execute_internal (editor
, what
);
313 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
318 do_edit (const char *what
)
320 do_edit_at_line (what
, 1);
324 edit_cmd (WPanel
*panel
)
326 panel
= get_a_panel (panel
);
327 if (regex_command (selection (panel
)->fname
, "Edit", 0) == 0)
328 do_edit (selection (panel
)->fname
);
332 edit_cmd_new (WPanel
*panel
)
337 /* Invoked by F5. Copy, default to the other panel. */
342 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)) {
343 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
348 /* Invoked by F6. Move/rename, default to the other panel. */
352 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
353 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
358 /* Invoked by F15. Copy, default to the same panel. */
359 void copy_cmd_local (void)
362 if (panel_operate (cpanel
, OP_COPY
, selection (cpanel
)->fname
, TRUE
)){
363 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
368 /* Invoked by F16. Move/rename, default to the same panel. */
369 void ren_cmd_local (void)
372 if (panel_operate (cpanel
, OP_MOVE
, selection (cpanel
)->fname
, TRUE
)){
373 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
378 void mkdir_cmd (WPanel
*panel
)
383 panel
= get_a_panel (panel
);
384 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
389 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
390 tempdir
= g_strdup (dir
);
392 tempdir
= concat_dir_and_file (panel
->cwd
, dir
);
396 if (my_mkdir (tempdir
, 0777) == 0){
397 update_panels (UP_OPTIMIZE
, tempdir
);
399 select_item (cpanel
);
404 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
407 void delete_cmd (void)
411 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
412 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
423 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
429 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
430 p
->filter
= allocated_filter_string
;
432 g_free (allocated_filter_string
);
436 /* Set a given panel filter expression */
437 void set_panel_filter (WPanel
*p
)
442 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
444 reg_exp
= input_dialog_help (_(" Filter "),
445 _(" Set expression for filtering filenames"),
449 set_panel_filter_to (p
, reg_exp
);
452 /* Invoked from the left/right menus */
453 void filter_cmd (void)
457 if (!SELECTED_IS_PANEL
)
461 set_panel_filter (p
);
464 void reread_cmd (void)
468 if (get_current_type () == view_listing
&&
469 get_other_type () == view_listing
)
470 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
472 flag
= UP_ONLY_CURRENT
;
474 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
478 /* Panel sorting related routines */
479 void do_re_sort (WPanel
*panel
)
481 panel
= get_a_panel (panel
);
482 panel_re_sort (panel
);
485 void reverse_selection_cmd_panel (WPanel
*panel
)
490 for (i
= 0; i
< panel
->count
; i
++){
491 file
= &panel
->dir
.list
[i
];
492 if (S_ISDIR (file
->buf
.st_mode
))
494 do_file_mark (panel
, i
, !file
->f
.marked
);
499 void reverse_selection_cmd (void)
501 reverse_selection_cmd_panel (cpanel
);
504 void select_cmd_panel (WPanel
*panel
)
506 char *reg_exp
, *reg_exp_t
;
511 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
517 /* Check if they specified a directory */
518 if (*reg_exp_t
== PATH_SEP
){
522 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
524 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
527 for (i
= 0; i
< panel
->count
; i
++){
528 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
530 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
537 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
539 message (1, MSG_ERROR
, _(" Malformed regular expression "));
544 do_file_mark (panel
, i
, 1);
551 void select_cmd (void)
553 select_cmd_panel (cpanel
);
556 void unselect_cmd_panel (WPanel
*panel
)
558 char *reg_exp
, *reg_exp_t
;
563 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
569 /* Check if they specified directory matching */
570 if (*reg_exp_t
== PATH_SEP
){
574 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
576 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
578 for (i
= 0; i
< panel
->count
; i
++){
579 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
581 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
588 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
590 message (1, MSG_ERROR
, _(" Malformed regular expression "));
595 do_file_mark (panel
, i
, 0);
602 void unselect_cmd (void)
604 unselect_cmd_panel (cpanel
);
607 /* Check if the file exists */
608 /* If not copy the default */
609 int check_for_default(char *default_file
, char *file
)
616 if (mc_stat (file
, &s
)){
617 if (mc_stat (default_file
, &s
)){
620 ctx
= file_op_context_new ();
621 file_op_context_create_ui (ctx
, OP_COPY
, 0);
622 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
623 file_op_context_destroy (ctx
);
635 if (geteuid () == 0){
636 dir
= query_dialog (_("Extension file edit"),
637 _(" Which extension file you want to edit? "), 0, 2,
638 _("&User"), _("&System Wide"));
640 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
643 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
644 check_for_default (extdir
, buffer
);
651 flush_extension_file ();
654 #ifdef USE_INTERNAL_EDIT
655 void edit_syntax_cmd (void)
661 if (geteuid () == 0){
662 dir
= query_dialog (_("Syntax file edit"),
663 _(" Which syntax file you want to edit? "), 0, 2,
664 _("&User"), _("&System Wide"));
666 extdir
= concat_dir_and_file (mc_home
, "syntax" PATH_SEP_STR
"Syntax");
669 buffer
= concat_dir_and_file (home_dir
, SYNTAX_FILE
);
670 check_for_default (extdir
, buffer
);
680 /* where = 0 - do edit a file menu for mc */
681 /* where = 1 - do edit a file menu for cool edit */
682 void menu_edit_cmd (int where
)
690 _(" Which menu file will you edit ? "),
691 0, geteuid() ? 2 : 3,
692 _("&Local"), _("&Home"), _("&System Wide")
695 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
699 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
700 check_for_default (menufile
, buffer
);
704 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
705 check_for_default (menufile
, buffer
);
709 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
723 void quick_chdir_cmd (void)
727 target
= hotlist_cmd (LIST_HOTLIST
);
731 if (get_current_type () == view_tree
)
732 tree_chdir (the_tree
, target
);
734 if (!do_cd (target
, cd_exact
))
735 message (1, MSG_ERROR
, _("Could not change directory") );
740 void free_vfs_now (void)
745 void reselect_vfs (void)
749 target
= hotlist_cmd (LIST_VFSLIST
);
753 if (!do_cd (target
, cd_exact
))
754 message (1, MSG_ERROR
, _("Could not change directory") );
759 static int compare_files (char *name1
, char *name2
, off_t size
)
762 int result
= -1; /* Different by default */
764 file1
= open (name1
, O_RDONLY
);
766 file2
= open (name2
, O_RDONLY
);
771 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
772 if (data1
!= (char*) -1){
773 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
774 if (data2
!= (char*) -1){
776 result
= memcmp (data1
, data2
, size
);
777 munmap (data2
, size
);
779 munmap (data1
, size
);
782 /* Don't have mmap() :( Even more ugly :) */
783 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
788 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
789 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
790 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
791 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
792 #endif /* !HAVE_MMAP */
801 compare_quick
, compare_size_only
, compare_thourough
805 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
808 char *src_name
, *dst_name
;
810 panel
= get_a_panel (panel
);
812 /* No marks by default */
815 panel
->dirs_marked
= 0;
817 /* Handle all files in the panel */
818 for (i
= 0; i
< panel
->count
; i
++){
819 file_entry
*source
= &panel
->dir
.list
[i
];
821 /* Default: unmarked */
822 file_mark (panel
, i
, 0);
824 /* Skip directories */
825 if (S_ISDIR (source
->buf
.st_mode
))
828 /* Search the corresponding entry from the other panel */
829 for (j
= 0; j
< other
->count
; j
++){
830 if (strcmp (source
->fname
,
831 other
->dir
.list
[j
].fname
) == 0)
834 if (j
>= other
->count
)
835 /* Not found -> mark */
836 do_file_mark (panel
, i
, 1);
839 file_entry
*target
= &other
->dir
.list
[j
];
841 if (mode
!= compare_size_only
){
842 /* Older version is not marked */
843 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
847 /* Newer version with different size is marked */
848 if (source
->buf
.st_size
!= target
->buf
.st_size
){
849 do_file_mark (panel
, i
, 1);
853 if (mode
== compare_size_only
)
856 if (mode
== compare_quick
){
857 /* Thorough compare off, compare only time stamps */
858 /* Mark newer version, don't mark version with the same date */
859 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
860 do_file_mark (panel
, i
, 1);
865 /* Thorough compare on, do byte-by-byte comparison */
866 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
867 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
868 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
869 do_file_mark (panel
, i
, 1);
876 void compare_dirs_cmd (void)
878 enum CompareMode thorough_flag
= compare_quick
;
880 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
881 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
882 if (thorough_flag
< 0 || thorough_flag
> 2)
884 if (get_current_type () == view_listing
&&
885 get_other_type () == view_listing
){
886 compare_dir (cpanel
, opanel
, thorough_flag
);
887 compare_dir (opanel
, cpanel
, thorough_flag
);
888 paint_panel (cpanel
);
889 paint_panel (opanel
);
891 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
901 if (cmdline
->need_push
) {
902 if (push_history (cmdline
, cmdline
->buffer
) == 2)
903 cmdline
->need_push
= 0;
905 if (!cmdline
->history
) {
906 message (1, MSG_ERROR
, _(" The command history is empty "));
909 current
= cmdline
->history
;
910 while (current
->prev
)
911 current
= current
->prev
;
912 listbox
= create_listbox_window (60, 10, _(" Command history "),
915 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
, current
);
916 current
= current
->next
;
918 run_dlg (listbox
->dlg
);
919 if (listbox
->dlg
->ret_value
== B_CANCEL
)
922 current
= listbox
->list
->current
->data
;
923 destroy_dlg (listbox
->dlg
);
928 cmdline
->history
= current
;
929 assign_text (cmdline
, cmdline
->history
->text
);
930 update_input (cmdline
, 1);
941 view_other_cmd (void)
943 static int message_flag
= TRUE
;
944 #ifdef HAVE_SUBSHELL_SUPPORT
945 char *new_dir
= NULL
;
947 #endif /* HAVE_SUBSHELL_SUPPORT */
949 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
951 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
952 " the panels cannot be toggled. "));
953 message_flag
= FALSE
;
957 if (clear_before_exec
)
959 if (alternate_plus_minus
)
960 numeric_keypad_mode ();
962 /* With slang we don't want any of this, since there
963 * is no mc_raw_mode supported
967 #endif /* !HAVE_SLANG */
968 keypad(stdscr
, FALSE
);
975 #ifdef HAVE_SUBSHELL_SUPPORT
977 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
978 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
979 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
981 #endif /* HAVE_SUBSHELL_SUPPORT */
983 if (output_starts_shell
){
985 _("Type `exit' to return to the Midnight Commander"));
986 fprintf (stderr
, "\n\r\n\r");
988 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
993 handle_console (CONSOLE_SAVE
);
998 keypad(stdscr
, TRUE
);
1000 /* Prevent screen flash when user did 'exit' or 'logout' within
1007 if (alternate_plus_minus
)
1008 application_keypad_mode ();
1010 #ifdef HAVE_SUBSHELL_SUPPORT
1014 do_possible_cd (new_dir
);
1015 if (console_flag
&& output_lines
)
1016 show_console_contents (output_start_y
,
1017 LINES
-keybar_visible
-output_lines
-1,
1018 LINES
-keybar_visible
-1);
1020 #endif /* HAVE_SUBSHELL_SUPPORT */
1027 #ifndef NATIVE_WIN32
1029 do_link (int symbolic_link
, char *fname
)
1033 if (!symbolic_link
) {
1034 src
= g_strdup_printf (_("Link %s to:"), name_trunc (fname
, 46));
1035 dest
= input_expand_dialog (_(" Link "), src
, "");
1044 if (-1 == mc_link (fname
, dest
))
1045 message (1, MSG_ERROR
, _(" link: %s "),
1046 unix_error_string (errno
));
1051 /* suggest the full path for symlink */
1052 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1054 if (get_other_type () == view_listing
) {
1055 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1057 d
= g_strdup (fname
);
1060 symlink_dialog (s
, d
, &dest
, &src
);
1064 if (!dest
|| !*dest
|| !src
|| !*src
) {
1072 if (-1 == mc_symlink (dest
, src
))
1073 message (1, MSG_ERROR
, _(" symlink: %s "),
1074 unix_error_string (errno
));
1078 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1082 void link_cmd (void)
1084 do_link (0, selection (cpanel
)->fname
);
1087 void symlink_cmd (void)
1089 char *filename
= NULL
;
1090 filename
= selection (cpanel
)->fname
;
1093 do_link (1, filename
);
1097 void edit_symlink_cmd (void)
1099 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1100 char buffer
[MC_MAXPATHLEN
];
1105 p
= selection (cpanel
)->fname
;
1107 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1109 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1112 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1114 if (*dest
&& strcmp (buffer
, dest
)) {
1116 if (-1 == mc_unlink (p
)){
1117 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1118 p
, unix_error_string (errno
));
1120 if (-1 == mc_symlink (dest
, p
))
1121 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1122 unix_error_string (errno
));
1124 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1132 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1133 selection (cpanel
)->fname
);
1136 #endif /* !NATIVE_WIN32 */
1138 void help_cmd (void)
1140 interactive_display (NULL
, "[main]");
1143 void view_panel_cmd (void)
1148 void edit_panel_cmd (void)
1153 void mkdir_panel_cmd (void)
1158 /* partly taken from dcigettext.c, returns "" for default locale */
1159 /* value should be freed by calling function g_free() */
1160 char *guess_message_value (void)
1162 static const char * const var
[] = {
1163 /* The highest priority value is the `LANGUAGE' environment
1164 variable. This is a GNU extension. */
1166 /* Setting of LC_ALL overwrites all other. */
1168 /* Next comes the name of the desired category. */
1170 /* Last possibility is the LANG environment variable. */
1172 /* NULL exit loops */
1177 char *locale
= NULL
;
1179 while (var
[i
] != NULL
) {
1180 locale
= getenv (var
[i
]);
1181 if (locale
!= NULL
&& locale
[0] != '\0')
1189 return g_strdup (locale
);
1192 /* Returns a random hint */
1193 char *get_random_hint (void)
1195 char *data
, *result
, *eol
;
1199 /* Do not change hints more often than one minute */
1206 if ((now
- last
) < 60)
1207 return g_strdup ("");
1210 static int last_sec
;
1211 static struct timeval tv
;
1213 gettimeofday (&tv
, NULL
);
1214 if (!(tv
.tv_sec
> last_sec
+60))
1215 return g_strdup ("");
1216 last_sec
= tv
.tv_sec
;
1217 #endif /* !SCO_FLAVOR */
1219 data
= load_mc_home_file (MC_HINT
, NULL
);
1224 srand ((short) now
);
1227 #endif /* !SCO_FLAVOR */
1228 /* get a random entry */
1229 len
= strlen (data
);
1230 start
= rand () % len
;
1232 for (;start
; start
--){
1233 if (data
[start
] == '\n'){
1238 eol
= strchr (&data
[start
], '\n');
1241 result
= g_strdup (&data
[start
]);
1246 #if defined(USE_NETCODE) || defined(USE_EXT2FSLIB)
1248 nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1253 if (!SELECTED_IS_PANEL
)
1256 machine
= input_dialog_help (text
,
1262 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1263 ugly as hell and leads to problems in vfs layer */
1265 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1266 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1268 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1270 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1271 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1273 message (1, MSG_ERROR
, _(" Could not chdir to %s "), cd_path
);
1277 #endif /* USE_NETCODE || USE_EXT2FSLIB */
1282 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1285 void netlink_cmd (void)
1287 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1288 "[Network File System]", "/#mc:", 1);
1290 #endif /* WITH_MCFS */
1292 void ftplink_cmd (void)
1294 nice_cd (_(" FTP to machine "), _(machine_str
),
1295 "[FTP File System]", "/#ftp:", 1);
1298 void fishlink_cmd (void)
1300 nice_cd (_(" Shell link to machine "), _(machine_str
),
1301 "[FIle transfer over SHell filesystem]", "/#sh:", 1);
1305 void smblink_cmd (void)
1307 nice_cd (_(" SMB link to machine "), _(machine_str
),
1308 "[SMB File System]", "/#smb:", 0);
1310 #endif /* WITH_SMBFS */
1312 #ifdef HAVE_SETSOCKOPT
1313 void source_routing (void)
1318 source
= input_dialog (_(" Socket source routing setup "),
1319 _(" Enter host name to use as a source routing hop: "),
1324 hp
= gethostbyname (source
);
1327 message (1, _(" Host name "), _(" Error while looking up IP address "));
1330 source_route
= *((int *)hp
->h_addr
);
1332 #endif /* HAVE_SETSOCKOPT */
1333 #endif /* USE_NETCODE */
1335 #ifdef USE_EXT2FSLIB
1336 void undelete_cmd (void)
1338 nice_cd (_(" Undelete files on an ext2 file system "),
1339 _(" Enter device (without /dev/) to undelete\n "
1340 " files on: (F1 for details)"),
1341 "[Undelete File System]", "/#undel:", 0);
1343 #endif /* USE_EXT2FSLIB */
1345 void quick_cd_cmd (void)
1347 char *p
= cd_dialog ();
1350 char *q
= g_strconcat ("cd ", p
, NULL
);
1362 WPanel
*panel
= cpanel
;
1367 for (i
= 0; i
< panel
->count
; i
++)
1368 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1369 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1370 !panel
->dirs_marked
) &&
1371 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1373 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1374 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1375 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1378 recalculate_panel_summary (panel
);
1379 paint_panel (panel
);
1383 save_setup_cmd (void)
1389 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1391 message (0, _(" Setup "), str
);
1396 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1398 p
->user_mini_status
= use_msformat
;
1399 p
->list_type
= view_type
;
1401 if (view_type
== list_user
|| use_msformat
){
1402 g_free (p
->user_format
);
1403 p
->user_format
= user
;
1405 g_free (p
->user_status_format
[view_type
]);
1406 p
->user_status_format
[view_type
] = status
;
1408 set_panel_formats (p
);
1415 set_panel_formats (p
);
1422 info_cmd_no_menu (void)
1424 if (get_display_type (0) == view_info
)
1425 set_display_type (0, view_listing
);
1426 else if (get_display_type (1) == view_info
)
1427 set_display_type (1, view_listing
);
1429 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1433 quick_cmd_no_menu (void)
1435 if (get_display_type (0) == view_quick
)
1436 set_display_type (0, view_listing
);
1437 else if (get_display_type (1) == view_quick
)
1438 set_display_type (1, view_listing
);
1440 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1444 switch_to_listing (int panel_index
)
1446 if (get_display_type (panel_index
) != view_listing
)
1447 set_display_type (panel_index
, view_listing
);
1453 int view_type
, use_msformat
;
1454 char *user
, *status
;
1458 display_type
= get_display_type (MENU_PANEL_IDX
);
1459 if (display_type
== view_listing
)
1460 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1464 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1466 if (view_type
== -1)
1469 switch_to_listing (MENU_PANEL_IDX
);
1471 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1473 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1479 set_display_type (MENU_PANEL_IDX
, view_tree
);
1485 set_display_type (MENU_PANEL_IDX
, view_info
);
1489 quick_view_cmd (void)
1491 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1493 set_display_type (MENU_PANEL_IDX
, view_quick
);
1496 /* Handle the tree internal listing modes switching */
1498 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1500 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1502 switch_to_listing (panel_index
);
1503 p
->list_type
= listing_mode
;
1504 if (set_panel_formats (p
))
1513 toggle_listing_cmd (void)
1515 int current
= get_current_index ();
1516 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1517 int list_mode
= p
->list_type
;
1531 if (set_basic_panel_listing_to (current
, m
))
1533 set_basic_panel_listing_to (current
, list_full
);