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., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 # define INCL_DOSFILEMGR
25 # define INCL_DOSERROR
32 #include <sys/types.h>
33 #include <sys/param.h>
37 #include <fcntl.h> /* open, O_RDWR */
49 # include <sys/mman.h>
54 #include "cmd.h" /* Our definitions */
55 #include "view.h" /* view() */
56 #include "dialog.h" /* query_dialog, message */
57 #include "file.h" /* the file operations */
58 #include "fileopctx.h"
59 #include "find.h" /* do_find */
62 #include "subshell.h" /* use_subshell */
63 #include "cons.saver.h"
64 #include "dlg.h" /* required by wtools.h */
65 #include "widget.h" /* required by wtools.h */
66 #include "wtools.h" /* listbox */
67 #include "command.h" /* for input_w */
68 #include "win.h" /* do_exit_ca_mode */
69 #include "layout.h" /* get_current/other_type */
70 #include "ext.h" /* regex_command */
71 #include "view.h" /* view */
72 #include "key.h" /* get_key_code */
73 #include "help.h" /* interactive_display */
74 #include "boxes.h" /* cd_dialog */
82 #ifdef USE_INTERNAL_EDIT
83 extern int edit (const char *file
, int line
);
85 #include "../vfs/vfs.h"
87 #include "main.h" /* global variables, global functions */
93 # include "tkscreen.h"
96 /* If set and you don't have subshell support,then C-o will give you a shell */
97 int output_starts_shell
= 0;
99 /* Source routing destination */
100 int source_route
= 0;
102 /* If set, use the builtin editor */
103 int use_internal_edit
= 1;
105 /* Ugly hack in order to distinguish between left and right panel in menubar */
107 #define MENU_PANEL_IDX (is_right ? 1 : 0)
110 #ifndef PORT_HAS_FILTER_CHANGED
111 # define x_filter_changed(p)
114 /* This is used since the parameter panel on some of the commands */
115 /* defined in this file may receive a 0 parameter if they are invoked */
116 /* The drop down menu */
119 get_a_panel (WPanel
*panel
)
123 if (get_current_type () == view_listing
){
129 /* view_file (filename, normal, internal)
132 * filename: The file name to view
133 * plain_view: If set does not do any fancy pre-processing (no filtering) and
134 * always invokes the internal viewer.
135 * internal: If set uses the internal viewer, otherwise an external viewer.
137 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
139 static char *viewer
= 0;
144 int changed_hex_mode
= 0;
145 int changed_nroff_flag
= 0;
146 int changed_magic_flag
= 0;
148 altered_hex_mode
= 0;
149 altered_nroff_flag
= 0;
150 altered_magic_flag
= 0;
151 if (default_hex_mode
)
152 changed_hex_mode
= 1;
153 if (default_nroff_flag
)
154 changed_nroff_flag
= 1;
155 if (default_magic_flag
)
156 changed_magic_flag
= 1;
157 default_hex_mode
= 0;
158 default_nroff_flag
= 0;
159 default_magic_flag
= 0;
160 view (0, filename
, &move_dir
, start_line
);
161 if (changed_hex_mode
&& !altered_hex_mode
)
162 default_hex_mode
= 1;
163 if (changed_nroff_flag
&& !altered_nroff_flag
)
164 default_nroff_flag
= 1;
165 if (changed_magic_flag
&& !altered_magic_flag
)
166 default_magic_flag
= 1;
171 char view_entry
[BUF_TINY
];
174 if (!gmc_view (filename
, start_line
)){
175 view (0, filename
, &move_dir
, start_line
);
179 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
181 strcpy (view_entry
, "View");
183 if (!regex_command (filename
, view_entry
, NULL
, &move_dir
)){
184 view (0, filename
, &move_dir
, start_line
);
192 viewer
= getenv ("PAGER");
196 /* The file may be a non local file, get a copy */
197 if (!vfs_file_is_local (filename
)){
198 localcopy
= mc_getlocalcopy (filename
);
199 if (localcopy
== NULL
){
200 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
203 execute_internal (viewer
, localcopy
);
204 mc_ungetlocalcopy (filename
, localcopy
, 0);
206 execute_internal (viewer
, filename
);
212 view_file (char *filename
, int plain_view
, int internal
)
214 return view_file_at_line (filename
, plain_view
, internal
, 0);
217 /* scan_for_file (panel, idx, direction)
220 * panel: pointer to the panel on which we operate
221 * idx: starting file.
222 * direction: 1, or -1
224 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
226 int i
= idx
+ direction
;
230 i
= panel
->count
- 1;
231 if (i
== panel
->count
)
233 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
240 /* do_view: Invoked as the F3/F13 key. */
241 static void do_view_cmd (WPanel
*panel
, int normal
)
244 panel
= get_a_panel (panel
);
246 /* Directories are viewed by changing to them */
247 if (S_ISDIR (selection (panel
)->buf
.st_mode
) ||
248 link_isdir (selection (panel
))) {
249 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)){
250 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
251 0, 2, _("&Yes"), _("&No")) == 1){
255 if (!do_cd (selection (panel
)->fname
, cd_exact
))
256 message (1, MSG_ERROR
, _("Could not change directory") );
262 file_idx
= panel
->selected
;
266 filename
= panel
->dir
.list
[file_idx
].fname
;
268 dir
= view_file (filename
, normal
, use_internal_view
);
271 file_idx
= scan_for_file (panel
, file_idx
, dir
);
275 void view_cmd (WPanel
*panel
)
277 do_view_cmd (panel
, 0);
280 void view_file_cmd (WPanel
*panel
)
284 panel
= get_a_panel (panel
);
285 filename
= input_dialog (_(" View file "), _(" Filename:"), selection (panel
)->fname
);
286 if (!filename
) return;
288 view_file (filename
, 0, use_internal_view
);
292 void view_simple_cmd (WPanel
*panel
)
294 do_view_cmd (panel
, 1);
297 void filtered_view_cmd (WPanel
*panel
)
301 panel
= get_a_panel (panel
);
302 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
303 selection (panel
)->fname
);
307 view (command
, "", 0, 0);
312 void filtered_view_cmd_cpanel (void)
314 filtered_view_cmd (cpanel
);
317 void do_edit_at_line (const char *what
, int start_line
)
319 static char *editor
= 0;
321 #ifdef USE_INTERNAL_EDIT
322 if (use_internal_edit
){
323 edit (what
, start_line
);
324 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
330 editor
= getenv ("EDITOR");
332 editor
= get_default_editor ();
334 execute_internal (editor
, what
);
335 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
340 do_edit (const char *what
)
342 do_edit_at_line (what
, 1);
345 void edit_cmd (WPanel
*panel
)
347 panel
= get_a_panel(panel
);
348 if (!regex_command (selection (panel
)->fname
, "Edit", NULL
, 0))
349 do_edit (selection (panel
)->fname
);
352 void edit_cmd_new (WPanel
*panel
)
360 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)){
361 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
369 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
370 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
375 void copymove_cmd_with_default (int copy
, char *thedefault
)
378 if (panel_operate (cpanel
, copy
? OP_COPY
: OP_MOVE
, thedefault
, TRUE
)){
379 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
384 void mkdir_cmd (WPanel
*panel
)
389 panel
= get_a_panel (panel
);
390 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
395 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
396 tempdir
= g_strdup (dir
);
398 tempdir
= concat_dir_and_file (panel
->cwd
, dir
);
402 if (my_mkdir (tempdir
, 0777) == 0){
403 update_panels (UP_OPTIMIZE
, tempdir
);
405 select_item (cpanel
);
410 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
413 void delete_cmd (void)
417 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
418 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
429 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
435 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
436 p
->filter
= allocated_filter_string
;
438 g_free (allocated_filter_string
);
440 x_filter_changed (p
);
443 /* Set a given panel filter expression */
444 void set_panel_filter (WPanel
*p
)
449 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
451 reg_exp
= input_dialog (_(" Filter "), _(" Set expression for filtering filenames"), x
);
454 set_panel_filter_to (p
, reg_exp
);
457 /* Invoked from the left/right menus */
458 void filter_cmd (void)
462 if (!SELECTED_IS_PANEL
)
466 set_panel_filter (p
);
469 void reread_cmd (void)
473 mad_check (__FILE__
, __LINE__
);
474 if (get_current_type () == view_listing
&&
475 get_other_type () == view_listing
)
476 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
478 flag
= UP_ONLY_CURRENT
;
480 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
484 /* Panel sorting related routines */
485 void do_re_sort (WPanel
*panel
)
487 panel
= get_a_panel (panel
);
488 panel_re_sort (panel
);
491 void reverse_selection_cmd_panel (WPanel
*panel
)
496 for (i
= 0; i
< panel
->count
; i
++){
497 file
= &panel
->dir
.list
[i
];
498 if (S_ISDIR (file
->buf
.st_mode
))
500 do_file_mark (panel
, i
, !file
->f
.marked
);
505 void reverse_selection_cmd (void)
507 reverse_selection_cmd_panel (cpanel
);
510 void select_cmd_panel (WPanel
*panel
)
512 char *reg_exp
, *reg_exp_t
;
517 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
523 /* Check if they specified a directory */
524 if (*reg_exp_t
== PATH_SEP
){
528 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
530 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
533 for (i
= 0; i
< panel
->count
; i
++){
534 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
536 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
543 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
545 message (1, MSG_ERROR
, _(" Malformed regular expression "));
550 do_file_mark (panel
, i
, 1);
557 void select_cmd (void)
559 select_cmd_panel (cpanel
);
562 void unselect_cmd_panel (WPanel
*panel
)
564 char *reg_exp
, *reg_exp_t
;
569 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
575 /* Check if they specified directory matching */
576 if (*reg_exp_t
== PATH_SEP
){
580 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
582 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
584 for (i
= 0; i
< panel
->count
; i
++){
585 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
587 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
594 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
596 message (1, MSG_ERROR
, _(" Malformed regular expression "));
601 do_file_mark (panel
, i
, 0);
608 void unselect_cmd (void)
610 unselect_cmd_panel (cpanel
);
613 /* Check if the file exists */
614 /* If not copy the default */
615 static int check_for_default(char *default_file
, char *file
)
622 if (mc_stat (file
, &s
)){
623 if (mc_stat (default_file
, &s
)){
626 ctx
= file_op_context_new ();
627 file_op_context_create_ui (ctx
, OP_COPY
, 0);
628 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
629 file_op_context_destroy (ctx
);
641 if (geteuid () == 0){
642 dir
= query_dialog (_("Extension file edit"),
643 _(" Which extension file you want to edit? "), 0, 2,
644 _("&User"), _("&System Wide"));
646 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
649 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
650 check_for_default (extdir
, buffer
);
657 flush_extension_file ();
660 void menu_edit_cmd (void)
668 _(" Which menu file will you edit? "),
669 0, geteuid() ? 2 : 3,
670 _("&Local"), _("&Home"), _("&System Wide")
673 menufile
= concat_dir_and_file(mc_home
, MC_GLOBAL_MENU
);
677 buffer
= g_strdup (MC_LOCAL_MENU
);
678 check_for_default (menufile
, buffer
);
682 buffer
= concat_dir_and_file (home_dir
, MC_HOME_MENU
);
683 check_for_default (menufile
, buffer
);
687 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
701 void quick_chdir_cmd (void)
705 target
= hotlist_cmd (LIST_HOTLIST
);
710 if (get_current_type () == view_tree
)
711 tree_chdir (the_tree
, target
);
714 if (!do_cd (target
, cd_exact
))
715 message (1, MSG_ERROR
, _("Could not change directory") );
720 void reselect_vfs (void)
724 target
= hotlist_cmd (LIST_VFSLIST
);
728 if (!do_cd (target
, cd_exact
))
729 message (1, MSG_ERROR
, _("Could not change directory") );
734 static int compare_files (char *name1
, char *name2
, long size
)
738 int result
= -1; /* Different by default */
740 file1
= open (name1
, O_RDONLY
);
742 file2
= open (name2
, O_RDONLY
);
746 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
747 if (data1
!= (char*) -1){
748 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
749 if (data2
!= (char*) -1){
751 result
= memcmp (data1
, data2
, size
);
752 munmap (data2
, size
);
754 munmap (data1
, size
);
757 /* Don't have mmap() :( Even more ugly :) */
758 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
763 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
764 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
765 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
766 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
776 compare_quick
, compare_size_only
, compare_thourough
780 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
783 char *src_name
, *dst_name
;
785 panel
= get_a_panel (panel
);
787 /* No marks by default */
790 panel
->dirs_marked
= 0;
792 /* Handle all files in the panel */
793 for (i
= 0; i
< panel
->count
; i
++){
794 file_entry
*source
= &panel
->dir
.list
[i
];
796 /* Default: unmarked */
797 file_mark (panel
, i
, 0);
799 /* Skip directories */
800 if (S_ISDIR (source
->buf
.st_mode
))
803 /* Search the corresponding entry from the other panel */
804 for (j
= 0; j
< other
->count
; j
++){
805 if (strcmp (source
->fname
,
806 other
->dir
.list
[j
].fname
) == 0)
809 if (j
>= other
->count
)
810 /* Not found -> mark */
811 do_file_mark (panel
, i
, 1);
814 file_entry
*target
= &other
->dir
.list
[j
];
816 if (mode
!= compare_size_only
){
817 /* Older version is not marked */
818 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
822 /* Newer version with different size is marked */
823 if (source
->buf
.st_size
!= target
->buf
.st_size
){
824 do_file_mark (panel
, i
, 1);
828 if (mode
== compare_size_only
)
831 if (mode
== compare_quick
){
832 /* Thorough compare off, compare only time stamps */
833 /* Mark newer version, don't mark version with the same date */
834 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
835 do_file_mark (panel
, i
, 1);
840 /* Thorough compare on, do byte-by-byte comparison */
841 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
842 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
843 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
844 do_file_mark (panel
, i
, 1);
851 void compare_dirs_cmd (void)
853 enum CompareMode thorough_flag
= compare_quick
;
855 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
856 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
857 if (thorough_flag
< 0 || thorough_flag
> 2)
859 if (get_current_type () == view_listing
&&
860 get_other_type () == view_listing
){
861 compare_dir (cpanel
, opanel
, thorough_flag
);
862 compare_dir (opanel
, cpanel
, thorough_flag
);
863 paint_panel (cpanel
);
864 paint_panel (opanel
);
866 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
870 void history_cmd (void)
875 if (input_w (cmdline
)->need_push
){
876 if (push_history (input_w (cmdline
), input_w (cmdline
)->buffer
) == 2)
877 input_w (cmdline
)->need_push
= 0;
879 if (!input_w (cmdline
)->history
){
880 message (1, MSG_ERROR
, _(" The command history is empty "));
883 current
= input_w (cmdline
)->history
;
884 while (current
->prev
)
885 current
= current
->prev
;
886 listbox
= create_listbox_window (60, 10, _(" Command history "),
889 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
,
891 current
= current
->next
;
893 run_dlg (listbox
->dlg
);
894 if (listbox
->dlg
->ret_value
== B_CANCEL
)
897 current
= listbox
->list
->current
->data
;
898 destroy_dlg (listbox
->dlg
);
903 input_w (cmdline
)->history
= current
;
904 assign_text (input_w (cmdline
), input_w (cmdline
)->history
->text
);
905 update_input (input_w (cmdline
), 1);
908 #if !defined(HAVE_XVIEW) && !defined(HAVE_GNOME)
918 view_other_cmd (void)
920 static int message_flag
= TRUE
;
921 #ifdef HAVE_SUBSHELL_SUPPORT
922 char *new_dir
= NULL
;
926 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
928 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
929 " the panels cannot be toggled. "));
930 message_flag
= FALSE
;
935 if (clear_before_exec
)
937 if (alternate_plus_minus
)
938 numeric_keypad_mode ();
941 /* With slang we don't want any of this, since there
942 * is no mc_raw_mode supported
948 keypad(stdscr
, FALSE
);
951 if (!status_using_ncurses
)
957 #ifdef HAVE_SUBSHELL_SUPPORT
959 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
960 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
961 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
965 if (output_starts_shell
){
967 _("Type `exit' to return to the Midnight Commander"));
968 fprintf (stderr
, "\n\r\n\r");
970 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
975 handle_console (CONSOLE_SAVE
);
977 if (!status_using_ncurses
)
982 keypad(stdscr
, TRUE
);
985 if (alternate_plus_minus
)
986 application_keypad_mode ();
989 #ifdef HAVE_SUBSHELL_SUPPORT
993 do_possible_cd (new_dir
);
994 if (console_flag
&& output_lines
)
995 show_console_contents (output_start_y
,
996 LINES
-keybar_visible
-output_lines
-1,
997 LINES
-keybar_visible
-1);
1004 /* prevent screen flash when user did 'exit' or 'logout' within
1013 do_link (int symbolic_link
, char *fname
)
1019 if (!symbolic_link
){
1020 stat_r
= mc_stat (fname
, &s
);
1022 message (1, MSG_ERROR
, _(" Couldn't stat %s \n %s "),
1023 fname
, unix_error_string (errno
));
1026 if (!S_ISREG (s
.st_mode
))
1030 if (!symbolic_link
){
1031 src
= g_strconcat (_(" Link "), name_trunc (fname
, 46),
1033 dest
= input_expand_dialog (_(" Link "), src
, "");
1042 if (-1 == mc_link (fname
, dest
))
1043 message (1, MSG_ERROR
, _(" link: %s "), unix_error_string (errno
));
1045 #ifdef OLD_SYMLINK_VERSION
1046 symlink_dialog (fname
, "", &dest
, &src
);
1048 /* suggest the full path for symlink */
1049 char s
[MC_MAXPATHLEN
];
1050 char d
[MC_MAXPATHLEN
];
1052 strcpy(s
, cpanel
->cwd
);
1053 if ( ! ((s
[0] == '/') && (s
[1] == 0)))
1056 if (get_other_type () == view_listing
)
1057 strcpy(d
, opanel
->cwd
);
1061 if ( ! ((d
[0] == '/') && (d
[1] == 0)))
1063 symlink_dialog (s
, d
, &dest
, &src
);
1065 if (!dest
|| !*dest
) {
1075 if (-1 == mc_symlink (dest
, src
))
1076 message (1, MSG_ERROR
, _(" symlink: %s "),
1077 unix_error_string (errno
));
1083 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1087 void link_cmd (void)
1089 do_link (0, selection (cpanel
)->fname
);
1092 void symlink_cmd (void)
1094 do_link (1, selection (cpanel
)->fname
);
1097 void edit_symlink_cmd (void)
1099 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1100 char buffer
[MC_MAXPATHLEN
], *p
= selection (cpanel
)->fname
;
1102 char *dest
, *q
= g_strconcat (_(" Symlink "), name_trunc (p
, 32), _(" points to:"), NULL
);
1104 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1107 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1109 if (*dest
&& strcmp (buffer
, dest
)) {
1112 if (-1 == mc_symlink (dest
, p
))
1113 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1114 unix_error_string (errno
));
1115 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1125 void other_symlink_cmd (void)
1127 char *dest
, *q
, *p
, *r
, *s
, *t
;
1129 if (get_other_type () != view_listing
)
1132 if (!strcmp (selection (opanel
)->fname
, ".."))
1134 p
= concat_dir_and_file (cpanel
->cwd
, selection (cpanel
)->fname
);
1135 r
= concat_dir_and_file (opanel
->cwd
, selection (cpanel
)->fname
);
1137 q
= g_strconcat (_(" Link symbolically "), name_trunc (p
, 32), _(" to:"), NULL
);
1138 dest
= input_expand_dialog (_(" Relative symlink "), q
, r
);
1141 t
= strrchr (dest
, PATH_SEP
);
1144 s
= diff_two_paths (dest
, p
);
1148 if (-1 == mc_symlink (dest
, s
))
1149 message (1, MSG_ERROR
, _(" relative symlink: %s "),
1150 unix_error_string (errno
));
1151 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1165 void help_cmd (void)
1167 char *hlpfile
= concat_dir_and_file (mc_home
, "mc.hlp");
1168 interactive_display (hlpfile
, "[main]");
1172 void view_panel_cmd (void)
1177 void edit_panel_cmd (void)
1182 void mkdir_panel_cmd (void)
1187 /* Returns a random hint */
1188 char *get_random_hint (void)
1190 char *data
, *result
, *eol
;
1195 /* Do not change hints more often than one minute */
1202 if ((now
- last
) < 60)
1203 return g_strdup ("");
1206 static int last_sec
;
1207 static struct timeval tv
;
1209 gettimeofday (&tv
, NULL
);
1210 if (!(tv
.tv_sec
> last_sec
+60))
1211 return g_strdup ("");
1212 last_sec
= tv
.tv_sec
;
1215 hintfile
= concat_dir_and_file (mc_home
, MC_HINT
);
1216 data
= load_file (hintfile
);
1222 srand ((short) now
);
1226 /* get a random entry */
1227 len
= strlen (data
);
1228 start
= rand () % len
;
1230 for (;start
; start
--){
1231 if (data
[start
] == '\n'){
1236 eol
= strchr (&data
[start
], '\n');
1239 result
= g_strdup (&data
[start
]);
1252 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1254 static void nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1259 if (!SELECTED_IS_PANEL
)
1262 machine
= input_dialog_help (text
,
1268 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1269 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1271 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1273 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1274 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1276 message (1, MSG_ERROR
, N_(" Could not chdir to %s "), cd_path
);
1281 void netlink_cmd (void)
1283 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1284 "[Network File System]", "/#mc:", 1);
1287 void ftplink_cmd (void)
1289 nice_cd (_(" FTP to machine "), _(machine_str
),
1290 "[FTP File System]", "/#ftp:", 1);
1293 #ifdef HAVE_SETSOCKOPT
1294 void source_routing (void)
1299 source
= input_dialog (_(" Socket source routing setup "),
1300 _(" Enter host name to use as a source routing hop: ")n
,
1305 hp
= gethostbyname (source
);
1307 message (1, _(" Host name "), _(" Error while looking up IP address "));
1310 source_route
= *((int *)hp
->h_addr
);
1312 #endif /* HAVE_SETSOCKOPT */
1313 #endif /* USE_NETCODE */
1315 #ifdef USE_EXT2FSLIB
1316 void undelete_cmd (void)
1318 nice_cd (_(" Undelete files on an ext2 file system "),
1319 _(" Enter device (without /dev/) to undelete\n "
1320 " files on: (F1 for details)"),
1321 "[Undelete File System]", "/#undel:", 0);
1325 void quick_cd_cmd (void)
1327 char *p
= cd_dialog ();
1330 char *q
= g_strconcat ("cd ", p
, NULL
);
1342 WPanel
*panel
= cpanel
;
1347 for (i
= 0; i
< panel
->count
; i
++)
1348 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1349 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1350 !panel
->dirs_marked
) &&
1351 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1353 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1354 panel
->dir
.list
[i
].buf
.st_size
= (long)total
;
1355 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1358 recalculate_panel_summary (panel
);
1359 paint_panel (panel
);
1363 save_setup_cmd (void)
1369 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1374 message (0, _(" Setup "), str
);
1380 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1384 p
->user_mini_status
= use_msformat
;
1385 p
->list_type
= view_type
;
1387 if (view_type
== list_user
|| use_msformat
){
1388 g_free (p
->user_format
);
1389 p
->user_format
= user
;
1391 g_free (p
->user_status_format
[view_type
]);
1392 p
->user_status_format
[view_type
] = status
;
1394 err
= set_panel_formats (p
);
1398 g_free (p
->user_format
);
1399 p
->user_format
= g_strdup (DEFAULT_USER_FORMAT
);
1403 g_free (p
->user_status_format
[view_type
]);
1404 p
->user_status_format
[view_type
] = g_strdup (DEFAULT_USER_FORMAT
);
1413 set_panel_formats (p
);
1421 info_cmd_no_menu (void)
1423 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1427 quick_cmd_no_menu (void)
1429 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1433 switch_to_listing (int panel_index
)
1435 if (get_display_type (panel_index
) != view_listing
)
1436 set_display_type (panel_index
, view_listing
);
1442 int view_type
, use_msformat
;
1443 char *user
, *status
;
1447 display_type
= get_display_type (MENU_PANEL_IDX
);
1448 if (display_type
== view_listing
)
1449 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1453 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1455 if (view_type
== -1)
1458 switch_to_listing (MENU_PANEL_IDX
);
1460 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1462 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1468 set_display_type (MENU_PANEL_IDX
, view_tree
);
1474 set_display_type (MENU_PANEL_IDX
, view_info
);
1478 quick_view_cmd (void)
1480 set_display_type (MENU_PANEL_IDX
, view_quick
);
1484 /* Handle the tree internal listing modes switching */
1486 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1488 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1491 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
);