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. */
23 # define INCL_DOSFILEMGR
25 # define INCL_DOSERROR
33 #include <sys/types.h>
36 #include <fcntl.h> /* open, O_RDWR */
44 # include <sys/mman.h>
51 #include "cmd.h" /* Our definitions */
52 #include "view.h" /* view() */
53 #include "dialog.h" /* query_dialog, message */
54 #include "file.h" /* the file operations */
55 #include "fileopctx.h"
56 #include "find.h" /* do_find */
59 #include "subshell.h" /* use_subshell */
60 #include "cons.saver.h"
61 #include "dlg.h" /* required by wtools.h */
62 #include "widget.h" /* required by wtools.h */
63 #include "wtools.h" /* listbox */
64 #include "command.h" /* for input_w */
65 #include "win.h" /* do_exit_ca_mode */
66 #include "layout.h" /* get_current/other_type */
67 #include "ext.h" /* regex_command */
68 #include "key.h" /* get_key_code */
69 #include "help.h" /* interactive_display */
70 #include "boxes.h" /* cd_dialog */
78 #include "main.h" /* global variables, global functions */
83 /* If set and you don't have subshell support,then C-o will give you a shell */
84 int output_starts_shell
= 0;
86 /* Source routing destination */
89 /* If set, use the builtin editor */
90 int use_internal_edit
= 1;
92 /* Ugly hack in order to distinguish between left and right panel in menubar */
94 #define MENU_PANEL_IDX (is_right ? 1 : 0)
97 /* This is used since the parameter panel on some of the commands */
98 /* defined in this file may receive a 0 parameter if they are invoked */
99 /* The drop down menu */
102 get_a_panel (WPanel
*panel
)
106 if (get_current_type () == view_listing
){
112 /* view_file (filename, normal, internal)
115 * filename: The file name to view
116 * plain_view: If set does not do any fancy pre-processing (no filtering) and
117 * always invokes the internal viewer.
118 * internal: If set uses the internal viewer, otherwise an external viewer.
120 int view_file_at_line (char *filename
, int plain_view
, int internal
, int start_line
)
122 static char *viewer
= 0;
127 int changed_hex_mode
= 0;
128 int changed_nroff_flag
= 0;
129 int changed_magic_flag
= 0;
131 altered_hex_mode
= 0;
132 altered_nroff_flag
= 0;
133 altered_magic_flag
= 0;
134 if (default_hex_mode
)
135 changed_hex_mode
= 1;
136 if (default_nroff_flag
)
137 changed_nroff_flag
= 1;
138 if (default_magic_flag
)
139 changed_magic_flag
= 1;
140 default_hex_mode
= 0;
141 default_nroff_flag
= 0;
142 default_magic_flag
= 0;
143 view (0, filename
, &move_dir
, start_line
);
144 if (changed_hex_mode
&& !altered_hex_mode
)
145 default_hex_mode
= 1;
146 if (changed_nroff_flag
&& !altered_nroff_flag
)
147 default_nroff_flag
= 1;
148 if (changed_magic_flag
&& !altered_magic_flag
)
149 default_magic_flag
= 1;
154 char view_entry
[BUF_TINY
];
157 g_snprintf (view_entry
, sizeof (view_entry
), "View:%d", start_line
);
159 strcpy (view_entry
, "View");
161 if (!regex_command (filename
, view_entry
, NULL
, &move_dir
)){
162 view (0, filename
, &move_dir
, start_line
);
169 viewer
= getenv ("PAGER");
173 /* The file may be a non local file, get a copy */
174 if (!vfs_file_is_local (filename
)){
175 localcopy
= mc_getlocalcopy (filename
);
176 if (localcopy
== NULL
){
177 message (1, MSG_ERROR
, _(" Can not fetch a local copy of %s "), filename
);
180 execute_internal (viewer
, localcopy
);
181 mc_ungetlocalcopy (filename
, localcopy
, 0);
183 execute_internal (viewer
, filename
);
189 view_file (char *filename
, int plain_view
, int internal
)
191 return view_file_at_line (filename
, plain_view
, internal
, 0);
194 /* scan_for_file (panel, idx, direction)
197 * panel: pointer to the panel on which we operate
198 * idx: starting file.
199 * direction: 1, or -1
201 static int scan_for_file (WPanel
*panel
, int idx
, int direction
)
203 int i
= idx
+ direction
;
207 i
= panel
->count
- 1;
208 if (i
== panel
->count
)
210 if (!S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
))
217 /* do_view: Invoked as the F3/F13 key. */
218 static void 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
)){
227 if (query_dialog (_(" CD "), _("Files tagged, want to cd?"),
228 0, 2, _("&Yes"), _("&No")) == 1){
232 if (!do_cd (selection (panel
)->fname
, cd_exact
))
233 message (1, MSG_ERROR
, _("Could not change directory") );
239 file_idx
= panel
->selected
;
243 filename
= panel
->dir
.list
[file_idx
].fname
;
245 dir
= view_file (filename
, normal
, use_internal_view
);
248 file_idx
= scan_for_file (panel
, file_idx
, dir
);
252 void view_cmd (WPanel
*panel
)
254 do_view_cmd (panel
, 0);
257 void view_file_cmd (WPanel
*panel
)
261 panel
= get_a_panel (panel
);
262 filename
= input_dialog (_(" View file "), _(" Filename:"), selection (panel
)->fname
);
263 if (!filename
) return;
265 view_file (filename
, 0, use_internal_view
);
269 void view_simple_cmd (WPanel
*panel
)
271 do_view_cmd (panel
, 1);
274 void filtered_view_cmd (WPanel
*panel
)
278 panel
= get_a_panel (panel
);
279 command
= input_dialog (_(" Filtered view "), _(" Filter command and arguments:"),
280 selection (panel
)->fname
);
284 view (command
, "", 0, 0);
289 void filtered_view_cmd_cpanel (void)
291 filtered_view_cmd (cpanel
);
294 void do_edit_at_line (const char *what
, int start_line
)
296 static char *editor
= 0;
298 #ifdef USE_INTERNAL_EDIT
299 if (use_internal_edit
){
300 edit (what
, start_line
);
301 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
305 #endif /* USE_INTERNAL_EDIT */
307 editor
= getenv ("EDITOR");
309 editor
= get_default_editor ();
311 execute_internal (editor
, what
);
312 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
317 do_edit (const char *what
)
319 do_edit_at_line (what
, 1);
322 void edit_cmd (WPanel
*panel
)
324 panel
= get_a_panel(panel
);
325 if (!regex_command (selection (panel
)->fname
, "Edit", NULL
, 0))
326 do_edit (selection (panel
)->fname
);
329 void edit_cmd_new (WPanel
*panel
)
337 if (panel_operate (cpanel
, OP_COPY
, NULL
, TRUE
)){
338 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
346 if (panel_operate (cpanel
, OP_MOVE
, NULL
, TRUE
)){
347 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
352 void copymove_cmd_with_default (int copy
, char *thedefault
)
355 if (panel_operate (cpanel
, copy
? OP_COPY
: OP_MOVE
, thedefault
, TRUE
)){
356 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
361 void mkdir_cmd (WPanel
*panel
)
366 panel
= get_a_panel (panel
);
367 dir
= input_expand_dialog (_("Create a new Directory"), _(" Enter directory name:") , "");
372 if (dir
[0] && (dir
[0] == '/' || dir
[0] == '~'))
373 tempdir
= g_strdup (dir
);
375 tempdir
= concat_dir_and_file (panel
->cwd
, dir
);
379 if (my_mkdir (tempdir
, 0777) == 0){
380 update_panels (UP_OPTIMIZE
, tempdir
);
382 select_item (cpanel
);
387 message (1, MSG_ERROR
, " %s ", unix_error_string (errno
));
390 void delete_cmd (void)
394 if (panel_operate (cpanel
, OP_DELETE
, NULL
, TRUE
)){
395 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
406 set_panel_filter_to (WPanel
*p
, char *allocated_filter_string
)
412 if (!(allocated_filter_string
[0] == '*' && allocated_filter_string
[1] == 0))
413 p
->filter
= allocated_filter_string
;
415 g_free (allocated_filter_string
);
419 /* Set a given panel filter expression */
420 void set_panel_filter (WPanel
*p
)
425 x
= p
->filter
? p
->filter
: easy_patterns
? "*" : ".";
427 reg_exp
= input_dialog_help (_(" Filter "),
428 _(" Set expression for filtering filenames"),
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
)
465 panel
= get_a_panel (panel
);
466 panel_re_sort (panel
);
469 void reverse_selection_cmd_panel (WPanel
*panel
)
474 for (i
= 0; i
< panel
->count
; i
++){
475 file
= &panel
->dir
.list
[i
];
476 if (S_ISDIR (file
->buf
.st_mode
))
478 do_file_mark (panel
, i
, !file
->f
.marked
);
483 void reverse_selection_cmd (void)
485 reverse_selection_cmd_panel (cpanel
);
488 void select_cmd_panel (WPanel
*panel
)
490 char *reg_exp
, *reg_exp_t
;
495 reg_exp
= input_dialog (_(" Select "), "", easy_patterns
? "*" : ".");
501 /* Check if they specified a directory */
502 if (*reg_exp_t
== PATH_SEP
){
506 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
508 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
511 for (i
= 0; i
< panel
->count
; i
++){
512 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
514 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
521 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
523 message (1, MSG_ERROR
, _(" Malformed regular expression "));
528 do_file_mark (panel
, i
, 1);
535 void select_cmd (void)
537 select_cmd_panel (cpanel
);
540 void unselect_cmd_panel (WPanel
*panel
)
542 char *reg_exp
, *reg_exp_t
;
547 reg_exp
= input_dialog (_(" Unselect "),"", easy_patterns
? "*" : ".");
553 /* Check if they specified directory matching */
554 if (*reg_exp_t
== PATH_SEP
){
558 if (reg_exp_t
[strlen(reg_exp_t
) - 1] == PATH_SEP
){
560 reg_exp_t
[strlen(reg_exp_t
) - 1] = 0;
562 for (i
= 0; i
< panel
->count
; i
++){
563 if (!strcmp (panel
->dir
.list
[i
].fname
, ".."))
565 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
)){
572 c
= regexp_match (reg_exp_t
, panel
->dir
.list
[i
].fname
, match_file
);
574 message (1, MSG_ERROR
, _(" Malformed regular expression "));
579 do_file_mark (panel
, i
, 0);
586 void unselect_cmd (void)
588 unselect_cmd_panel (cpanel
);
591 /* Check if the file exists */
592 /* If not copy the default */
593 int check_for_default(char *default_file
, char *file
)
600 if (mc_stat (file
, &s
)){
601 if (mc_stat (default_file
, &s
)){
604 ctx
= file_op_context_new ();
605 file_op_context_create_ui (ctx
, OP_COPY
, 0);
606 copy_file_file (ctx
, default_file
, file
, 1, &count
, &bytes
, 1);
607 file_op_context_destroy (ctx
);
619 if (geteuid () == 0){
620 dir
= query_dialog (_("Extension file edit"),
621 _(" Which extension file you want to edit? "), 0, 2,
622 _("&User"), _("&System Wide"));
624 extdir
= concat_dir_and_file (mc_home
, MC_LIB_EXT
);
627 buffer
= concat_dir_and_file (home_dir
, MC_USER_EXT
);
628 check_for_default (extdir
, buffer
);
635 flush_extension_file ();
638 /* where = 0 - do edit a file menu for mc */
639 /* where = 1 - do edit a file menu for cool edit */
640 void menu_edit_cmd (int where
)
648 _(" Which menu file will you edit ? "),
649 0, geteuid() ? 2 : 3,
650 _("&Local"), _("&Home"), _("&System Wide")
653 menufile
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
657 buffer
= g_strdup (where
? CEDIT_LOCAL_MENU
: MC_LOCAL_MENU
);
658 check_for_default (menufile
, buffer
);
662 buffer
= concat_dir_and_file (home_dir
, where
? CEDIT_HOME_MENU
: MC_HOME_MENU
);
663 check_for_default (menufile
, buffer
);
667 buffer
= concat_dir_and_file (mc_home
, where
? CEDIT_GLOBAL_MENU
: MC_GLOBAL_MENU
);
681 void quick_chdir_cmd (void)
685 target
= hotlist_cmd (LIST_HOTLIST
);
689 if (get_current_type () == view_tree
)
690 tree_chdir (the_tree
, target
);
692 if (!do_cd (target
, cd_exact
))
693 message (1, MSG_ERROR
, _("Could not change directory") );
698 void free_vfs_now (void)
703 void reselect_vfs (void)
707 target
= hotlist_cmd (LIST_VFSLIST
);
711 if (!do_cd (target
, cd_exact
))
712 message (1, MSG_ERROR
, _("Could not change directory") );
717 static int compare_files (char *name1
, char *name2
, off_t size
)
720 int result
= -1; /* Different by default */
722 file1
= open (name1
, O_RDONLY
);
724 file2
= open (name2
, O_RDONLY
);
729 data1
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file1
, 0);
730 if (data1
!= (char*) -1){
731 data2
= mmap (0, size
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, file2
, 0);
732 if (data2
!= (char*) -1){
734 result
= memcmp (data1
, data2
, size
);
735 munmap (data2
, size
);
737 munmap (data1
, size
);
740 /* Don't have mmap() :( Even more ugly :) */
741 char buf1
[BUFSIZ
], buf2
[BUFSIZ
];
746 while((n1
= read(file1
,buf1
,BUFSIZ
)) == -1 && errno
== EINTR
);
747 while((n2
= read(file2
,buf2
,BUFSIZ
)) == -1 && errno
== EINTR
);
748 } while (n1
== n2
&& n1
== BUFSIZ
&& !memcmp(buf1
,buf2
,BUFSIZ
));
749 result
= (n1
!= n2
) || memcmp(buf1
,buf2
,n1
);
750 #endif /* !HAVE_MMAP */
759 compare_quick
, compare_size_only
, compare_thourough
763 compare_dir (WPanel
*panel
, WPanel
*other
, enum CompareMode mode
)
766 char *src_name
, *dst_name
;
768 panel
= get_a_panel (panel
);
770 /* No marks by default */
773 panel
->dirs_marked
= 0;
775 /* Handle all files in the panel */
776 for (i
= 0; i
< panel
->count
; i
++){
777 file_entry
*source
= &panel
->dir
.list
[i
];
779 /* Default: unmarked */
780 file_mark (panel
, i
, 0);
782 /* Skip directories */
783 if (S_ISDIR (source
->buf
.st_mode
))
786 /* Search the corresponding entry from the other panel */
787 for (j
= 0; j
< other
->count
; j
++){
788 if (strcmp (source
->fname
,
789 other
->dir
.list
[j
].fname
) == 0)
792 if (j
>= other
->count
)
793 /* Not found -> mark */
794 do_file_mark (panel
, i
, 1);
797 file_entry
*target
= &other
->dir
.list
[j
];
799 if (mode
!= compare_size_only
){
800 /* Older version is not marked */
801 if (source
->buf
.st_mtime
< target
->buf
.st_mtime
)
805 /* Newer version with different size is marked */
806 if (source
->buf
.st_size
!= target
->buf
.st_size
){
807 do_file_mark (panel
, i
, 1);
811 if (mode
== compare_size_only
)
814 if (mode
== compare_quick
){
815 /* Thorough compare off, compare only time stamps */
816 /* Mark newer version, don't mark version with the same date */
817 if (source
->buf
.st_mtime
> target
->buf
.st_mtime
){
818 do_file_mark (panel
, i
, 1);
823 /* Thorough compare on, do byte-by-byte comparison */
824 src_name
= concat_dir_and_file (panel
->cwd
, source
->fname
);
825 dst_name
= concat_dir_and_file (other
->cwd
, target
->fname
);
826 if (compare_files (src_name
, dst_name
, source
->buf
.st_size
))
827 do_file_mark (panel
, i
, 1);
834 void compare_dirs_cmd (void)
836 enum CompareMode thorough_flag
= compare_quick
;
838 thorough_flag
= query_dialog (_(" Compare directories "), _(" Select compare method: "),
839 0, 3, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel"));
840 if (thorough_flag
< 0 || thorough_flag
> 2)
842 if (get_current_type () == view_listing
&&
843 get_other_type () == view_listing
){
844 compare_dir (cpanel
, opanel
, thorough_flag
);
845 compare_dir (opanel
, cpanel
, thorough_flag
);
846 paint_panel (cpanel
);
847 paint_panel (opanel
);
849 message (1, MSG_ERROR
, _(" Both panels should be on the listing view mode to use this command "));
853 void history_cmd (void)
858 if (input_w (cmdline
)->need_push
){
859 if (push_history (input_w (cmdline
), input_w (cmdline
)->buffer
) == 2)
860 input_w (cmdline
)->need_push
= 0;
862 if (!input_w (cmdline
)->history
){
863 message (1, MSG_ERROR
, _(" The command history is empty "));
866 current
= input_w (cmdline
)->history
;
867 while (current
->prev
)
868 current
= current
->prev
;
869 listbox
= create_listbox_window (60, 10, _(" Command history "),
872 LISTBOX_APPEND_TEXT (listbox
, 0, current
->text
,
874 current
= current
->next
;
876 run_dlg (listbox
->dlg
);
877 if (listbox
->dlg
->ret_value
== B_CANCEL
)
880 current
= listbox
->list
->current
->data
;
881 destroy_dlg (listbox
->dlg
);
886 input_w (cmdline
)->history
= current
;
887 assign_text (input_w (cmdline
), input_w (cmdline
)->history
->text
);
888 update_input (input_w (cmdline
), 1);
899 view_other_cmd (void)
901 static int message_flag
= TRUE
;
902 #ifdef HAVE_SUBSHELL_SUPPORT
903 char *new_dir
= NULL
;
905 #endif /* HAVE_SUBSHELL_SUPPORT */
907 if (!xterm_flag
&& !console_flag
&& !use_subshell
){
909 message (1, MSG_ERROR
, _(" Not an xterm or Linux console; \n"
910 " the panels cannot be toggled. "));
911 message_flag
= FALSE
;
914 if (clear_before_exec
)
916 if (alternate_plus_minus
)
917 numeric_keypad_mode ();
919 /* With slang we don't want any of this, since there
920 * is no mc_raw_mode supported
924 #endif /* !HAVE_SLANG */
925 keypad(stdscr
, FALSE
);
932 #ifdef HAVE_SUBSHELL_SUPPORT
934 new_dir_p
= vfs_current_is_local () ? &new_dir
: NULL
;
935 if (invoke_subshell (NULL
, VISIBLY
, new_dir_p
))
936 quiet_quit_cmd(); /* User did `exit' or `logout': quit MC quietly */
938 #endif /* HAVE_SUBSHELL_SUPPORT */
940 if (output_starts_shell
){
942 _("Type `exit' to return to the Midnight Commander"));
943 fprintf (stderr
, "\n\r\n\r");
945 my_system (EXECUTE_AS_SHELL
, shell
, NULL
);
950 handle_console (CONSOLE_SAVE
);
955 keypad(stdscr
, TRUE
);
957 if (alternate_plus_minus
)
958 application_keypad_mode ();
960 #ifdef HAVE_SUBSHELL_SUPPORT
964 do_possible_cd (new_dir
);
965 if (console_flag
&& output_lines
)
966 show_console_contents (output_start_y
,
967 LINES
-keybar_visible
-output_lines
-1,
968 LINES
-keybar_visible
-1);
970 #endif /* HAVE_SUBSHELL_SUPPORT */
973 /* prevent screen flash when user did 'exit' or 'logout' within
982 do_link (int symbolic_link
, char *fname
)
987 src
= g_strconcat (_(" Link "), name_trunc (fname
, 46),
989 dest
= input_expand_dialog (_(" Link "), src
, "");
998 if (-1 == mc_link (fname
, dest
))
999 message (1, MSG_ERROR
, _(" link: %s "), unix_error_string (errno
));
1004 /* suggest the full path for symlink */
1005 s
= concat_dir_and_file (cpanel
->cwd
, fname
);
1007 if (get_other_type () == view_listing
) {
1008 d
= concat_dir_and_file (opanel
->cwd
, fname
);
1010 d
= g_strdup (fname
);
1013 symlink_dialog (s
, d
, &dest
, &src
);
1017 if (!dest
|| !*dest
|| !src
|| !*src
) {
1025 if (-1 == mc_symlink (dest
, src
))
1026 message (1, MSG_ERROR
, _(" symlink: %s "),
1027 unix_error_string (errno
));
1031 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1035 void link_cmd (void)
1037 do_link (0, selection (cpanel
)->fname
);
1040 void symlink_cmd (void)
1042 char *filename
= NULL
;
1043 if (is_a_desktop_panel (cpanel
)) {
1045 for (i
= 0; i
< cpanel
->count
; i
++)
1046 if (cpanel
->dir
.list
[i
].f
.marked
) {
1047 filename
= cpanel
->dir
.list
[i
].fname
;
1051 filename
= selection (cpanel
)->fname
;
1055 do_link (1, filename
);
1059 void edit_symlink_cmd (void)
1061 if (S_ISLNK (selection (cpanel
)->buf
.st_mode
)) {
1062 char buffer
[MC_MAXPATHLEN
];
1067 if (is_a_desktop_panel (cpanel
)) {
1069 for (i
= 0; i
< cpanel
->count
; i
++)
1070 if (cpanel
->dir
.list
[i
].f
.marked
) {
1071 p
= cpanel
->dir
.list
[i
].fname
;
1075 p
= selection (cpanel
)->fname
;
1078 q
= g_strdup_printf (_(" Symlink `%s\' points to: "), name_trunc (p
, 32));
1080 i
= readlink (p
, buffer
, MC_MAXPATHLEN
);
1083 dest
= input_expand_dialog (_(" Edit symlink "), q
, buffer
);
1085 if (*dest
&& strcmp (buffer
, dest
)) {
1087 if (-1 == mc_unlink (p
)){
1088 message (1, MSG_ERROR
, _(" edit symlink, unable to remove %s: %s "),
1089 p
, unix_error_string (errno
));
1091 if (-1 == mc_symlink (dest
, p
))
1092 message (1, MSG_ERROR
, _(" edit symlink: %s "),
1093 unix_error_string (errno
));
1095 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1103 message (1, MSG_ERROR
, _("`%s' is not a symbolic link"),
1104 selection (cpanel
)->fname
);
1108 void other_symlink_cmd (void)
1110 char *dest
, *q
, *p
, *r
, *s
, *t
;
1112 if (get_other_type () != view_listing
)
1115 if (!strcmp (selection (opanel
)->fname
, ".."))
1117 p
= concat_dir_and_file (cpanel
->cwd
, selection (cpanel
)->fname
);
1118 r
= concat_dir_and_file (opanel
->cwd
, selection (cpanel
)->fname
);
1120 q
= g_strconcat (_(" Link symbolically "), name_trunc (p
, 32), _(" to:"), NULL
);
1121 dest
= input_expand_dialog (_(" Relative symlink "), q
, r
);
1124 t
= strrchr (dest
, PATH_SEP
);
1127 s
= diff_two_paths (dest
, p
);
1131 if (-1 == mc_symlink (dest
, s
))
1132 message (1, MSG_ERROR
, _(" relative symlink: %s "),
1133 unix_error_string (errno
));
1134 update_panels (UP_OPTIMIZE
, UP_KEEPSEL
);
1146 #endif /* !OS2_NT */
1148 void help_cmd (void)
1150 interactive_display (NULL
, "[main]");
1153 void view_panel_cmd (void)
1158 void edit_panel_cmd (void)
1163 void mkdir_panel_cmd (void)
1168 /* partly taken from dcigettext.c, returns "" for default locale */
1169 /* value should be freed by calling function g_free() */
1170 char *guess_message_value (void)
1172 const char *var
[] = {
1173 /* The highest priority value is the `LANGUAGE' environment
1174 variable. This is a GNU extension. */
1176 /* Setting of LC_ALL overwrites all other. */
1178 /* Next comes the name of the desired category. */
1180 /* Last possibility is the LANG environment variable. */
1182 /* NULL exit loops */
1187 char *locale
= NULL
;
1189 while (var
[i
] != NULL
) {
1190 locale
= getenv (var
[i
]);
1191 if (locale
!= NULL
&& locale
[0] != '\0')
1199 return g_strdup (locale
);
1202 /* Returns a random hint */
1203 char *get_random_hint (void)
1205 char *data
, *result
, *eol
;
1209 /* Do not change hints more often than one minute */
1216 if ((now
- last
) < 60)
1217 return g_strdup ("");
1220 static int last_sec
;
1221 static struct timeval tv
;
1223 gettimeofday (&tv
, NULL
);
1224 if (!(tv
.tv_sec
> last_sec
+60))
1225 return g_strdup ("");
1226 last_sec
= tv
.tv_sec
;
1227 #endif /* !SCO_FLAVOR */
1229 data
= load_mc_home_file (MC_HINT
, NULL
);
1234 srand ((short) now
);
1237 #endif /* !SCO_FLAVOR */
1238 /* get a random entry */
1239 len
= strlen (data
);
1240 start
= rand () % len
;
1242 for (;start
; start
--){
1243 if (data
[start
] == '\n'){
1248 eol
= strchr (&data
[start
], '\n');
1251 result
= g_strdup (&data
[start
]);
1258 static char *machine_str
= N_(" Enter machine name (F1 for details): ");
1260 static void nice_cd (char *text
, char *xtext
, char *help
, char *prefix
, int to_home
)
1265 if (!SELECTED_IS_PANEL
)
1268 machine
= input_dialog_help (text
,
1274 to_home
= 0; /* FIXME: how to solve going to home nicely? /~/ is
1275 ugly as hell and leads to problems in vfs layer */
1277 if (strncmp (prefix
, machine
, strlen (prefix
)) == 0)
1278 cd_path
= g_strconcat (machine
, to_home
? "/~/" : NULL
, NULL
);
1280 cd_path
= g_strconcat (prefix
, machine
, to_home
? "/~/" : NULL
, NULL
);
1282 if (do_panel_cd (MENU_PANEL
, cd_path
, 0))
1283 directory_history_add (MENU_PANEL
, (MENU_PANEL
)->cwd
);
1285 message (1, MSG_ERROR
, _(" Could not chdir to %s "), cd_path
);
1290 void netlink_cmd (void)
1292 nice_cd (_(" Link to a remote machine "), _(machine_str
),
1293 "[Network File System]", "/#mc:", 1);
1296 void ftplink_cmd (void)
1298 nice_cd (_(" FTP to machine "), _(machine_str
),
1299 "[FTP File System]", "/#ftp:", 1);
1302 void smblink_cmd (void)
1304 nice_cd (_(" SMB link to machine "), _(machine_str
),
1305 "[SMB File System]", "/#smb:", 0);
1308 #ifdef HAVE_SETSOCKOPT
1309 void source_routing (void)
1314 source
= input_dialog (_(" Socket source routing setup "),
1315 _(" Enter host name to use as a source routing hop: "),
1320 hp
= gethostbyname (source
);
1323 message (1, _(" Host name "), _(" Error while looking up IP address "));
1326 source_route
= *((int *)hp
->h_addr
);
1328 #endif /* HAVE_SETSOCKOPT */
1329 #endif /* USE_NETCODE */
1331 #ifdef USE_EXT2FSLIB
1332 void undelete_cmd (void)
1334 nice_cd (_(" Undelete files on an ext2 file system "),
1335 _(" Enter device (without /dev/) to undelete\n "
1336 " files on: (F1 for details)"),
1337 "[Undelete File System]", "/#undel:", 0);
1339 #endif /* USE_EXT2FSLIB */
1341 void quick_cd_cmd (void)
1343 char *p
= cd_dialog ();
1346 char *q
= g_strconcat ("cd ", p
, NULL
);
1358 WPanel
*panel
= cpanel
;
1363 for (i
= 0; i
< panel
->count
; i
++)
1364 if (S_ISDIR (panel
->dir
.list
[i
].buf
.st_mode
) &&
1365 ((panel
->dirs_marked
&& panel
->dir
.list
[i
].f
.marked
) ||
1366 !panel
->dirs_marked
) &&
1367 strcmp (panel
->dir
.list
[i
].fname
, "..") != 0) {
1369 compute_dir_size (panel
->dir
.list
[i
].fname
, &marked
, &total
);
1370 panel
->dir
.list
[i
].buf
.st_size
= (off_t
) total
;
1371 panel
->dir
.list
[i
].f
.dir_size_computed
= 1;
1374 recalculate_panel_summary (panel
);
1375 paint_panel (panel
);
1379 save_setup_cmd (void)
1385 str
= g_strconcat ( _(" Setup saved to ~/"), PROFILE_NAME
, NULL
);
1387 message (0, _(" Setup "), str
);
1392 configure_panel_listing (WPanel
*p
, int view_type
, int use_msformat
, char *user
, char *status
)
1394 p
->user_mini_status
= use_msformat
;
1395 p
->list_type
= view_type
;
1397 if (view_type
== list_user
|| use_msformat
){
1398 g_free (p
->user_format
);
1399 p
->user_format
= user
;
1401 g_free (p
->user_status_format
[view_type
]);
1402 p
->user_status_format
[view_type
] = status
;
1404 set_panel_formats (p
);
1411 set_panel_formats (p
);
1418 info_cmd_no_menu (void)
1420 set_display_type (cpanel
== left_panel
? 1 : 0, view_info
);
1424 quick_cmd_no_menu (void)
1426 set_display_type (cpanel
== left_panel
? 1 : 0, view_quick
);
1430 switch_to_listing (int panel_index
)
1432 if (get_display_type (panel_index
) != view_listing
)
1433 set_display_type (panel_index
, view_listing
);
1439 int view_type
, use_msformat
;
1440 char *user
, *status
;
1444 display_type
= get_display_type (MENU_PANEL_IDX
);
1445 if (display_type
== view_listing
)
1446 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1450 view_type
= display_box (p
, &user
, &status
, &use_msformat
, MENU_PANEL_IDX
);
1452 if (view_type
== -1)
1455 switch_to_listing (MENU_PANEL_IDX
);
1457 p
= MENU_PANEL_IDX
== 0 ? left_panel
: right_panel
;
1459 configure_panel_listing (p
, view_type
, use_msformat
, user
, status
);
1465 set_display_type (MENU_PANEL_IDX
, view_tree
);
1471 set_display_type (MENU_PANEL_IDX
, view_info
);
1475 quick_view_cmd (void)
1477 if ((WPanel
*) get_panel_widget (MENU_PANEL_IDX
) == cpanel
)
1479 set_display_type (MENU_PANEL_IDX
, view_quick
);
1482 /* Handle the tree internal listing modes switching */
1484 set_basic_panel_listing_to (int panel_index
, int listing_mode
)
1486 WPanel
*p
= (WPanel
*) get_panel_widget (panel_index
);
1488 switch_to_listing (panel_index
);
1489 p
->list_type
= listing_mode
;
1490 if (set_panel_formats (p
))
1499 toggle_listing_cmd (void)
1501 int current
= get_current_index ();
1502 WPanel
*p
= (WPanel
*) get_panel_widget (current
);
1503 int list_mode
= p
->list_type
;
1517 if (set_basic_panel_listing_to (current
, m
))
1519 set_basic_panel_listing_to (current
, list_full
);