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 <stdlib.h> /* getenv (), rand */
33 #include <sys/types.h>
34 #include <sys/param.h>
37 #include <sys/time.h___>
43 #include <fcntl.h> /* open, O_RDWR */
55 # include <sys/mman.h>
61 #include "cmd.h" /* Our definitions */
62 #include "view.h" /* view() */
63 #include "dialog.h" /* query_dialog, message */
64 #include "file.h" /* the file operations */
65 #include "find.h" /* do_find */
68 #include "subshell.h" /* use_subshell */
69 #include "cons.saver.h"
71 #include "dlg.h" /* required by wtools.h */
72 #include "widget.h" /* required by wtools.h */
73 #include "wtools.h" /* listbox */
74 #include "command.h" /* for input_w */
75 #include "win.h" /* do_exit_ca_mode */
76 #include "layout.h" /* get_current/other_type */
77 #include "ext.h" /* regex_command */
78 #include "view.h" /* view */
79 #include "key.h" /* get_key_code */
80 #include "help.h" /* interactive_display */
82 #include "boxes.h" /* cd_dialog */
90 #ifdef USE_INTERNAL_EDIT
91 extern int edit (const char *file
, int line
);
93 #include "../vfs/vfs.h"
95 #include "main.h" /* global variables, global functions */
101 # include "tkscreen.h"
104 /* If set and you don't have subshell support,then C-o will give you a shell */
105 int output_starts_shell
= 0;
107 /* Source routing destination */
108 int source_route
= 0;
110 /* If set, use the builtin editor */
111 int use_internal_edit
= 1;
113 /* Ugly hack in order to distinguish between left and right panel in menubar */
115 #define MENU_PANEL_IDX (is_right ? 1 : 0)
118 #ifndef PORT_HAS_FILTER_CHANGED
119 # define x_filter_changed(p)
122 /* This is used since the parameter panel on some of the commands */
123 /* defined in this file may receive a 0 parameter if they are invoked */
124 /* The drop down menu */
126 WPanel
*get_a_panel (WPanel
*panel
)
130 if (get_current_type () == view_listing
){
136 /* view_file (filename, normal, internal)
139 * filename: The file name to view
140 * plain_view: If set does not do any fancy pre-processing (no filtering) and
141 * always invokes the internal viewer.
142 * internal: If set uses the internal viewer, otherwise an external viewer.
144 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
146 static char *viewer
= 0;
151 int changed_hex_mode
= 0;
152 int changed_nroff_flag
= 0;
153 int changed_magic_flag
= 0;
155 altered_hex_mode
= 0;
156 altered_nroff_flag
= 0;
157 altered_magic_flag
= 0;
158 if (default_hex_mode
)
159 changed_hex_mode
= 1;
160 if (default_nroff_flag
)
161 changed_nroff_flag
= 1;
162 if (default_magic_flag
)
163 changed_magic_flag
= 1;
164 default_hex_mode
= 0;
165 default_nroff_flag
= 0;
166 default_magic_flag
= 0;
167 view (0, filename
, &move_dir
, start_line
);
168 if (changed_hex_mode
&& !altered_hex_mode
)
169 default_hex_mode
= 1;
170 if (changed_nroff_flag
&& !altered_nroff_flag
)
171 default_nroff_flag
= 1;
172 if (changed_magic_flag
&& !altered_magic_flag
)
173 default_magic_flag
= 1;
178 char view_entry
[32];
181 sprintf (view_entry
, "View:%d", start_line
);
183 strcpy (view_entry
, "View");
185 if (!regex_command (filename
, view_entry
, NULL
, &move_dir
)){
186 view (0, filename
, &move_dir
, start_line
);
193 viewer
= getenv ("PAGER");
197 /* The file may be a non local file, get a copy */
198 if (!vfs_file_is_local (filename
)){
199 localcopy
= mc_getlocalcopy (filename
);
200 if (localcopy
== NULL
){
201 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
204 execute_internal (viewer
, localcopy
);
205 mc_ungetlocalcopy (filename
, localcopy
, 0);
207 execute_internal (viewer
, filename
);
213 view_file (char *filename
, int plain_view
, int internal
)
215 return view_file_at_line (filename
, plain_view
, internal
, 0);
218 /* scan_for_file (panel, idx, direction)
221 * panel: pointer to the panel on which we operate
222 * idx: starting file.
223 * direction: 1, or -1
225 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
227 int i
= idx
+ direction
;
231 i
= panel
->count
- 1;
232 if (i
== panel
->count
)
234 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
241 /* do_view: Invoked as the F3/F13 key. */
242 static void do_view_cmd (WPanel
*panel
, int normal
)
245 panel
= get_a_panel (panel
);
247 /* Directories are viewed by changing to them */
248 if (S_ISDIR (selection (panel
)->buf
.st_mode
) ||
249 link_isdir (selection (panel
))){
250 if (confirm_view_dir
&& (panel
->marked
|| panel
->dirs_marked
)){
251 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
252 0, 2, _("&Yes"), _("&No")) == 1){
256 do_cd (selection (panel
)->fname
, cd_exact
);
261 file_idx
= panel
->selected
;
265 filename
= panel
->dir
.list
[file_idx
].fname
;
267 dir
= view_file (filename
, normal
, use_internal_view
);
270 file_idx
= scan_for_file (panel
, file_idx
, dir
);
274 void view_cmd (WPanel
*panel
)
276 do_view_cmd (panel
, 0);
279 void view_simple_cmd (WPanel
*panel
)
281 do_view_cmd (panel
, 1);
284 void filtered_view_cmd (WPanel
*panel
)
288 panel
= get_a_panel (panel
);
289 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
290 selection (panel
)->fname
);
294 view (command
, "", 0, 0);
299 void filtered_view_cmd_cpanel (void)
301 filtered_view_cmd (cpanel
);
304 void do_edit_at_line (const char *what
, int start_line
)
306 static char *editor
= 0;
308 #ifdef USE_INTERNAL_EDIT
309 if (use_internal_edit
){
310 edit (what
, start_line
);
316 editor
= getenv ("EDITOR");
318 editor
= get_default_editor ();
320 execute_internal (editor
, what
);
325 do_edit (const char *what
)
327 do_edit_at_line (what
, 1);
330 void edit_cmd (WPanel
*panel
)
332 panel
= get_a_panel(panel
);
333 if (!regex_command (selection (panel
)->fname
, "Edit", NULL
, 0))
334 do_edit (selection (panel
)->fname
);
337 void edit_cmd_new (WPanel
*panel
)
345 if (panel_operate (cpanel
, OP_COPY
, NULL
)){
346 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
354 if (panel_operate (cpanel
, OP_MOVE
, NULL
)){
355 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
360 void copymove_cmd_with_default (int copy
, char *thedefault
)
363 if (panel_operate (cpanel
, copy
? OP_COPY
: OP_MOVE
, thedefault
)){
364 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
369 void mkdir_cmd (WPanel
*panel
)
373 panel
= get_a_panel (panel
);
374 dir
= input_expand_dialog (_(" Mkdir "), _(" Enter directory name:") , "");
380 if (my_mkdir (dir
, 0777) == 0){
381 update_panels (UP_OPTIMIZE
, dir
);
383 select_item (cpanel
);
388 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
391 void delete_cmd (void)
395 if (panel_operate (cpanel
, OP_DELETE
, NULL
)){
396 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
407 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
413 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
414 p
->filter
= allocated_filter_string
;
416 free (allocated_filter_string
);
418 x_filter_changed (p
);
421 /* Set a given panel filter expression */
422 void set_panel_filter (WPanel
*p
)
427 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
429 reg_exp
= input_dialog (_(" Filter "), _(" Set expression for filtering filenames"), x
);
432 set_panel_filter_to (p
, reg_exp
);
435 /* Invoked from the left/right menus */
436 void filter_cmd (void)
440 if (!SELECTED_IS_PANEL
)
444 set_panel_filter (p
);
447 void reread_cmd (void)
451 mad_check (__FILE__
, __LINE__
);
452 if (get_current_type () == view_listing
&&
453 get_other_type () == view_listing
)
454 flag
= strcmp (cpanel
->cwd
, opanel
->cwd
) ? UP_ONLY_CURRENT
: 0;
456 flag
= UP_ONLY_CURRENT
;
458 update_panels (UP_RELOAD
|flag
, UP_KEEPSEL
);
462 /* Panel sorting related routines */
463 void do_re_sort (WPanel
*panel
)
468 panel
= get_a_panel (panel
);
469 filename
= strdup (selection (cpanel
)->fname
);
470 unselect_item (panel
);
471 do_sort (&panel
->dir
, panel
->sort_type
, panel
->count
-1, panel
->reverse
, panel
->case_sensitive
);
472 panel
->selected
= -1;
473 for (i
= panel
->count
; i
; i
--){
474 if (!strcmp (panel
->dir
.list
[i
-1].fname
, filename
)){
475 panel
->selected
= i
-1;
480 cpanel
->top_file
= cpanel
->selected
- ITEMS (cpanel
)/2;
481 if (cpanel
->top_file
< 0)
482 cpanel
->top_file
= 0;
484 panel_update_contents (panel
);
487 void reverse_selection_cmd_panel (WPanel
*panel
)
492 for (i
= 0; i
< panel
->count
; i
++){
493 file
= &panel
->dir
.list
[i
];
494 if (S_ISDIR (file
->buf
.st_mode
))
496 do_file_mark (panel
, i
, !file
->f
.marked
);
501 void reverse_selection_cmd (void)
503 reverse_selection_cmd_panel (cpanel
);
506 void select_cmd_panel (WPanel
*panel
)
508 char *reg_exp
, *reg_exp_t
;
513 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
519 /* Check if they specified a directory */
520 if (*reg_exp_t
== PATH_SEP
){
524 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
526 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
529 for (i
= 0; i
< panel
->count
; i
++){
530 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
532 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
539 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
541 message (1, MSG_ERROR
, _(" Malformed regular expression "));
546 do_file_mark (panel
, i
, 1);
553 void select_cmd (void)
555 select_cmd_panel (cpanel
);
558 void unselect_cmd_panel (WPanel
*panel
)
560 char *reg_exp
, *reg_exp_t
;
565 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
571 /* Check if they specified directory matching */
572 if (*reg_exp_t
== PATH_SEP
){
576 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
578 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
580 for (i
= 0; i
< panel
->count
; i
++){
581 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
583 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
590 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
592 message (1, MSG_ERROR
, _(" Malformed regular expression "));
597 do_file_mark (panel
, i
, 0);
604 void unselect_cmd (void)
606 unselect_cmd_panel (cpanel
);
609 /* Check if the file exists */
610 /* If not copy the default */
611 static int check_for_default(char *default_file
, char *file
)
614 if (mc_stat (file
, &s
)){
615 if (mc_stat (default_file
, &s
)){
618 create_op_win (OP_COPY
, 0);
619 file_mask_defaults ();
620 copy_file_file (default_file
, file
, 1);
633 if (geteuid () == 0){
634 dir
= query_dialog (_("Extension file edit"),
635 _(" Which extension file you want to edit? "), 0, 2,
636 _("&User"), _("&System Wide"));
638 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
641 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
642 check_for_default (extdir
, buffer
);
649 flush_extension_file ();
652 void menu_edit_cmd (void)
660 _(" Which menu file will you edit? "),
661 0, geteuid() ? 2 : 3,
662 _("&Local"), _("&Home"), _("&System Wide")
665 menufile
= concat_dir_and_file(mc_home
, MC_GLOBAL_MENU
);
669 buffer
= strdup (MC_LOCAL_MENU
);
670 check_for_default (menufile
, buffer
);
674 buffer
= concat_dir_and_file (home_dir
, MC_HOME_MENU
);
675 check_for_default (menufile
, buffer
);
679 buffer
= concat_dir_and_file (mc_home
, MC_GLOBAL_MENU
);
693 void quick_chdir_cmd (void)
697 target
= hotlist_cmd (LIST_HOTLIST
);
701 if (get_current_type () == view_tree
)
702 tree_chdir (the_tree
, target
);
704 do_cd (target
, cd_exact
);
709 void reselect_vfs (void)
713 target
= hotlist_cmd (LIST_VFSLIST
);
717 do_cd (target
, cd_exact
);
722 static int compare_files (char *name1
, char *name2
, long size
)
725 int result
= -1; /* Different by default */
727 file1
= open (name1
, O_RDONLY
);
729 file2
= open (name2
, O_RDONLY
);
733 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
734 if (data1
!= (char*) -1){
735 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
736 if (data2
!= (char*) -1){
738 result
= memcmp (data1
, data2
, size
);
739 munmap (data2
, size
);
741 munmap (data1
, size
);
744 /* Don't have mmap() :( Even more ugly :) */
745 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
750 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
751 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
752 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
753 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
763 compare_quick
, compare_size_only
, compare_thourough
767 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
770 char *src_name
, *dst_name
;
772 panel
= get_a_panel (panel
);
774 /* No marks by default */
777 panel
->dirs_marked
= 0;
779 /* Handle all files in the panel */
780 for (i
= 0; i
< panel
->count
; i
++){
781 file_entry
*source
= &panel
->dir
.list
[i
];
783 /* Default: unmarked */
784 file_mark (panel
, i
, 0);
786 /* Skip directories */
787 if (S_ISDIR (source
->buf
.st_mode
))
790 /* Search the corresponding entry from the other panel */
791 for (j
= 0; j
< other
->count
; j
++){
792 if (strcmp (source
->fname
,
793 other
->dir
.list
[j
].fname
) == 0)
796 if (j
>= other
->count
)
797 /* Not found -> mark */
798 do_file_mark (panel
, i
, 1);
801 file_entry
*target
= &other
->dir
.list
[j
];
803 if (mode
!= compare_size_only
){
804 /* Older version is not marked */
805 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
809 /* Newer version with different size is marked */
810 if (source
->buf
.st_size
!= target
->buf
.st_size
){
811 do_file_mark (panel
, i
, 1);
815 if (mode
== compare_size_only
)
818 if (mode
== compare_quick
){
819 /* Thorough compare off, compare only time stamps */
820 /* Mark newer version, don't mark version with the same date */
821 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
822 do_file_mark (panel
, i
, 1);
827 /* Thorough compare on, do byte-by-byte comparison */
828 src_name
= get_full_name (panel
->cwd
, source
->fname
);
829 dst_name
= get_full_name (other
->cwd
, target
->fname
);
830 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
831 do_file_mark (panel
, i
, 1);
838 void compare_dirs_cmd (void)
840 enum CompareMode thorough_flag
= compare_quick
;
842 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
843 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
844 if (thorough_flag
< 0 || thorough_flag
> 2)
846 if (get_current_type () == view_listing
&&
847 get_other_type () == view_listing
){
848 compare_dir (cpanel
, opanel
, thorough_flag
);
849 compare_dir (opanel
, cpanel
, thorough_flag
);
850 paint_panel (cpanel
);
851 paint_panel (opanel
);
853 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
857 void history_cmd (void)
862 if (input_w (cmdline
)->need_push
){
863 if (push_history (input_w (cmdline
), input_w (cmdline
)->buffer
) == 2)
864 input_w (cmdline
)->need_push
= 0;
866 if (!input_w (cmdline
)->history
){
867 message (1, MSG_ERROR
, _(" The command history is empty "));
870 current
= input_w (cmdline
)->history
;
871 while (current
->prev
)
872 current
= current
->prev
;
873 listbox
= create_listbox_window (60, 10, _(" Command history "),
876 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
,
878 current
= current
->next
;
880 run_dlg (listbox
->dlg
);
881 if (listbox
->dlg
->ret_value
== B_CANCEL
)
884 current
= listbox
->list
->current
->data
;
885 destroy_dlg (listbox
->dlg
);
890 input_w (cmdline
)->history
= current
;
891 assign_text (input_w (cmdline
), input_w (cmdline
)->history
->text
);
892 update_input (input_w (cmdline
), 1);
895 #if !defined(HAVE_XVIEW) && !defined(HAVE_GNOME)
905 view_other_cmd (void)
907 static int message_flag
= TRUE
;
908 #ifdef HAVE_SUBSHELL_SUPPORT
909 char *new_dir
= NULL
;
913 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
915 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
916 " the panels cannot be toggled. "));
917 message_flag
= FALSE
;
922 if (clear_before_exec
)
924 if (alternate_plus_minus
)
925 numeric_keypad_mode ();
928 /* With slang we don't want any of this, since there
929 * is no mc_raw_mode supported
934 keypad(stdscr
, FALSE
);
936 if (!status_using_ncurses
)
942 #ifdef HAVE_SUBSHELL_SUPPORT
944 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
945 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
946 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
950 if (output_starts_shell
){
952 _("Type `exit' to return to the Midnight Commander\n\r\n\r"));
953 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
958 handle_console (CONSOLE_SAVE
);
960 if (!status_using_ncurses
)
964 keypad(stdscr
, TRUE
);
968 if (alternate_plus_minus
)
969 application_keypad_mode ();
972 #ifdef HAVE_SUBSHELL_SUPPORT
976 do_possible_cd (new_dir
);
977 if (console_flag
&& output_lines
)
978 show_console_contents (output_start_y
,
979 LINES
-keybar_visible
-output_lines
-1,
980 LINES
-keybar_visible
-1);
985 /* prevent screen flash when user did 'exit' or 'logout' within
994 do_link (int symbolic_link
, char *fname
)
1000 if (!symbolic_link
){
1001 stat_r
= mc_stat (fname
, &s
);
1003 message (1, MSG_ERROR
, _(" Couldn't stat %s \n %s "),
1004 fname
, unix_error_string (errno
));
1007 if (!S_ISREG (s
.st_mode
))
1011 if (!symbolic_link
){
1012 src
= copy_strings (_(" Link "), name_trunc (fname
, 46),
1014 dest
= input_expand_dialog (_(" Link "), src
, "");
1023 if (-1 == mc_link (fname
, dest
))
1024 message (1, MSG_ERROR
, _(" link: %s "), unix_error_string (errno
));
1026 #ifdef OLD_SYMLINK_VERSION
1027 symlink_dialog (fname
, "", &dest
, &src
);
1029 /* suggest the full path for symlink */
1030 char s
[MC_MAXPATHLEN
];
1031 char d
[MC_MAXPATHLEN
];
1033 strcpy(s
, cpanel
->cwd
);
1034 if ( ! ((s
[0] == '/') && (s
[1] == 0)))
1037 if (get_other_type () == view_listing
)
1038 strcpy(d
, opanel
->cwd
);
1042 if ( ! ((d
[0] == '/') && (d
[1] == 0)))
1044 symlink_dialog (s
, d
, &dest
, &src
);
1046 if (!dest
|| !*dest
) {
1056 if (-1 == mc_symlink (dest
, src
))
1057 message (1, MSG_ERROR
, _(" symlink: %s "),
1058 unix_error_string (errno
));
1064 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1068 void link_cmd (void)
1070 do_link (0, selection (cpanel
)->fname
);
1073 void symlink_cmd (void)
1075 do_link (1, selection (cpanel
)->fname
);
1078 void edit_symlink_cmd (void)
1080 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1081 char buffer
[MC_MAXPATHLEN
], *p
= selection (cpanel
)->fname
;
1083 char *dest
, *q
= copy_strings (_(" Symlink "), name_trunc (p
, 32), _(" points to:"), NULL
);
1085 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1088 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1090 if (*dest
&& strcmp (buffer
, dest
)) {
1093 if (-1 == mc_symlink (dest
, p
))
1094 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1095 unix_error_string (errno
));
1096 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1106 void other_symlink_cmd (void)
1108 char *dest
, *q
, *p
, *r
, *s
, *t
;
1110 if (get_other_type () != view_listing
)
1113 if (!strcmp (selection (opanel
)->fname
, ".."))
1115 p
= concat_dir_and_file (cpanel
->cwd
, selection (cpanel
)->fname
);
1116 r
= concat_dir_and_file (opanel
->cwd
, selection (cpanel
)->fname
);
1118 q
= copy_strings (_(" Link symbolically "), name_trunc (p
, 32), _(" to:"), NULL
);
1119 dest
= input_expand_dialog (_(" Relative symlink "), q
, r
);
1122 t
= strrchr (dest
, PATH_SEP
);
1125 s
= diff_two_paths (dest
, p
);
1129 if (-1 == mc_symlink (dest
, s
))
1130 message (1, MSG_ERROR
, _(" relative symlink: %s "),
1131 unix_error_string (errno
));
1132 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1146 void help_cmd (void)
1148 char *hlpfile
= concat_dir_and_file (mc_home
, "mc.hlp");
1149 interactive_display (hlpfile
, "[main]");
1153 void view_panel_cmd (void)
1158 void edit_panel_cmd (void)
1163 void mkdir_panel_cmd (void)
1168 /* Returns a random hint */
1169 char *get_random_hint (void)
1171 char *data
, *result
, *eol
;
1176 /* Do not change hints more often than one minute */
1183 if ((now
- last
) < 60)
1187 static int last_sec
;
1188 static struct timeval tv
;
1190 gettimeofday (&tv
, NULL
);
1191 if (!(tv
.tv_sec
> last_sec
+60))
1193 last_sec
= tv
.tv_sec
;
1196 hintfile
= concat_dir_and_file (mc_home
, MC_HINT
);
1197 data
= load_file (hintfile
);
1203 srand ((short) now
);
1207 /* get a random entry */
1208 len
= strlen (data
);
1209 start
= rand () % len
;
1211 for (;start
; start
--){
1212 if (data
[start
] == '\n'){
1217 eol
= strchr (&data
[start
], '\n');
1220 result
= strdup (&data
[start
]);
1233 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1235 static void nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1240 if (!SELECTED_IS_PANEL
)
1243 machine
= input_dialog_help (text
,
1249 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1250 cd_path
= copy_strings (machine
, to_home
? "/~/" : NULL
, NULL
);
1252 cd_path
= copy_strings (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1254 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1255 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1257 message (1, MSG_ERROR
, N_(" Could not chdir to %s "), cd_path
);
1262 void netlink_cmd (void)
1264 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1265 "[Network File System]", "mc:", 1);
1268 void ftplink_cmd (void)
1270 nice_cd (_(" FTP to machine "), _(machine_str
),
1271 "[FTP File System]", "ftp://", 1);
1274 #ifdef HAVE_SETSOCKOPT
1275 void source_routing (void)
1280 source
= input_dialog (_(" Socket source routing setup "),
1281 _(" Enter host name to use as a source routing hop: ")n
,
1286 hp
= gethostbyname (source
);
1288 message (1, _(" Host name "), _(" Error while looking up IP address "));
1291 source_route
= *((int *)hp
->h_addr
);
1293 #endif /* HAVE_SETSOCKOPT */
1294 #endif /* USE_NETCODE */
1296 #ifdef USE_EXT2FSLIB
1297 void undelete_cmd (void)
1299 nice_cd (_(" Undelete files on an ext2 file system "),
1300 _(" Enter the file system name where you want to run the\n "
1301 " undelete file system on: (F1 for details)"),
1302 "[Undelete File System]", "undel:", 0);
1306 void quick_cd_cmd (void)
1308 char *p
= cd_dialog ();
1311 char *q
= copy_strings ("cd ", p
, NULL
);
1323 #endif /* SCO_FLAVOR */
1326 void dirsizes_cmd (void)
1328 WPanel
*panel
= cpanel
;
1330 char *cmd
, *p
, *q
, *r
;
1333 # define dirsizes_command "du -s -b "
1335 # define dirsizes_command "du -s "
1337 #ifndef DUSUM_FACTOR
1338 # define DUSUM_FACTOR 512
1341 if (!vfs_current_is_local ())
1343 for (i
= 0; i
< panel
->count
; i
++)
1344 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
1345 j
+= strlen (panel
->dir
.list
[i
].fname
) + 1;
1348 cmd
= xmalloc (strlen (dirsizes_command
) + j
+ 1, "dirsizes_cmd");
1349 strcpy (cmd
, dirsizes_command
);
1350 p
= strchr (cmd
, 0);
1351 for (i
= 0; i
< panel
->count
; i
++)
1352 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1353 strcmp (panel
->dir
.list
[i
].fname
, "..")) {
1354 strcpy (p
, panel
->dir
.list
[i
].fname
);
1360 f
= popen (cmd
, "r");
1363 /* Assume that du will display the directories in the order
1364 * I've passed to it :(
1367 p
= xmalloc (1024, "dirsizes_cmd");
1368 while (fgets (p
, 1024, f
)) {
1369 j
= atoi (p
) * DUSUM_FACTOR
;
1370 for (q
= p
; *q
&& *q
!= ' ' && *q
!= '\t'; q
++);
1371 while (*q
== ' ' || *q
== '\t')
1373 r
= strchr (q
, '\n');
1376 for (; i
< panel
->count
; i
++)
1377 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
1378 if (!strncmp (q
, panel
->dir
.list
[i
].fname
,
1380 if (panel
->dir
.list
[i
].f
.marked
)
1382 ((panel
->has_dir_sizes
) ? panel
->dir
.list
[i
].buf
.st_size
: 0);
1383 panel
->dir
.list
[i
].buf
.st_size
= j
;
1386 if (i
== panel
->count
)
1392 message (0, _("Show directory sizes"), _("Pipe close failed"));
1394 #else /* SCO_FLAVOR */
1396 ** SCO reports about error while all seems to be ok. Just ignore it...
1397 ** (alex@bcs.zaporizhzhe.ua)
1400 #endif /* SCO_FLAVOR */
1401 panel
->has_dir_sizes
= 1;
1402 close_error_pipe (0, 0);
1403 paint_panel (panel
);
1405 close_error_pipe (1, _("Cannot invoke du command."));
1410 save_setup_cmd (void)
1416 str
= copy_strings ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1421 message (0, _(" Setup "), str
);
1427 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1431 p
->user_mini_status
= use_msformat
;
1432 p
->list_type
= view_type
;
1434 if (view_type
== list_user
|| use_msformat
){
1435 free (p
->user_format
);
1436 p
->user_format
= user
;
1438 free (p
->user_status_format
[view_type
]);
1439 p
->user_status_format
[view_type
] = status
;
1441 err
= set_panel_formats (p
);
1445 free (p
->user_format
);
1446 p
->user_format
= strdup (DEFAULT_USER_FORMAT
);
1450 free (p
->user_status_format
[view_type
]);
1451 p
->user_status_format
[view_type
] = strdup (DEFAULT_USER_FORMAT
);
1460 set_panel_formats (p
);
1468 info_cmd_no_menu (void)
1470 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1474 quick_cmd_no_menu (void)
1476 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1480 switch_to_listing (int panel_index
)
1482 if (get_display_type (panel_index
) != view_listing
)
1483 set_display_type (panel_index
, view_listing
);
1489 int view_type
, use_msformat
;
1490 char *user
, *status
;
1494 display_type
= get_display_type (MENU_PANEL_IDX
);
1495 if (display_type
== view_listing
)
1496 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1500 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1502 if (view_type
== -1)
1505 switch_to_listing (MENU_PANEL_IDX
);
1507 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1509 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1515 set_display_type (MENU_PANEL_IDX
, view_tree
);
1521 set_display_type (MENU_PANEL_IDX
, view_info
);
1525 quick_view_cmd (void)
1527 set_display_type (MENU_PANEL_IDX
, view_quick
);
1531 /* Handle the tree internal listing modes switching */
1533 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1535 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1538 switch_to_listing (panel_index
);
1540 p
->list_type
= listing_mode
;
1541 if (set_panel_formats (p
))
1550 toggle_listing_cmd (void)
1552 int current
= get_current_index ();
1553 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1554 int list_mode
= p
->list_type
;
1568 if (set_basic_panel_listing_to (current
, m
))
1570 set_basic_panel_listing_to (current
, list_full
);