Codepage messages related translated & other stuff...
[midnight-commander.git] / src / main.c
blob8aa0e5d5f63b92e09159a80ecc18970cbe893fce
1 /* Main program for the Midnight Commander
2 Copyright (C) 1994, 1995, 1996, 1997 The Free Software Foundation
4 Written by: 1994, 1995, 1996, 1997 Miguel de Icaza
5 1994, 1995 Janne Kukonlehto
6 1997 Norbert Warmuth
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <locale.h>
25 #ifdef _OS_NT
26 # include <windows.h>
27 #endif
29 #ifdef __os2__
30 # define INCL_DOS
31 # define INCL_DOSFILEMGR
32 # define INCL_DOSERRORS
33 # include <os2.h>
34 #endif
36 #include "tty.h"
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/param.h>
43 #include <sys/stat.h>
45 #ifdef HAVE_UNISTD_H
46 # include <unistd.h>
47 #endif
49 /* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
50 #if defined(HAVE_DIRENT_H) || defined(_POSIX_VERSION)
51 # include <dirent.h>
52 # define NLENGTH(dirent) (strlen ((dirent)->d_name))
53 #else
54 # define dirent direct
55 # define NLENGTH(dirent) ((dirent)->d_namlen)
57 # ifdef HAVE_SYS_NDIR_H
58 # include <sys/ndir.h>
59 # endif /* HAVE_SYS_NDIR_H */
61 # ifdef HAVE_SYS_DIR_H
62 # include <sys/dir.h>
63 # endif /* HAVE_SYS_DIR_H */
65 # ifdef HAVE_NDIR_H
66 # include <ndir.h>
67 # endif /* HAVE_NDIR_H */
68 #endif /* not (HAVE_DIRENT_H or _POSIX_VERSION) */
70 #if HAVE_SYS_WAIT_H
71 # include <sys/wait.h> /* For waitpid() */
72 #endif
74 #include <errno.h>
75 #ifndef HAS_NO_GRP_PWD_H
76 # include <pwd.h>
77 #endif
78 #include <ctype.h>
79 #include <fcntl.h> /* For O_RDWR */
80 #include <signal.h>
82 #ifdef HAVE_CORBA
83 # include <libgnorba/gnorba.h>
84 #endif
86 #include <glib.h>
88 /* Program include files */
89 #include "x.h"
90 #include "dir.h"
91 #include "color.h"
92 #include "global.h"
93 #include "dialog.h"
94 #include "menu.h"
95 #include "file.h"
96 #include "panel.h"
97 #include "main.h"
98 #include "win.h"
99 #include "user.h"
100 #include "mouse.h"
101 #include "option.h"
102 #include "tree.h"
103 #include "cons.saver.h"
104 #include "subshell.h"
105 #include "key.h" /* For init_key() and mi_getch() */
106 #include "setup.h" /* save_setup() */
107 #include "profile.h" /* free_profiles() */
108 #include "boxes.h"
109 #include "layout.h"
110 #include "cmd.h" /* Normal commands */
111 #include "hotlist.h"
112 #include "panelize.h"
113 #ifndef __os2__
114 # include "learn.h"
115 #endif
116 #include "listmode.h"
117 #include "background.h"
118 #include "ext.h" /* For flush_extension_file() */
120 /* Listbox for the command history feature */
121 #include "widget.h"
122 #include "command.h"
123 #include "wtools.h"
124 #include "complete.h" /* For the free_completion */
125 #ifndef HAVE_X
126 #include "textconf.h"
127 #endif
129 #include "chmod.h"
130 #include "chown.h"
132 #ifdef NEEDS_IO_H
133 # include <io.h>
134 #endif
135 #ifdef NEEDS_DRIVE_H
136 # include <drive.h>
137 #endif
139 #include "../vfs/vfs.h"
140 #include "../vfs/extfs.h"
142 #include "popt.h"
144 #ifdef HAVE_GNOME
145 #include "gcorba.h"
146 #include "gmain.h"
147 #include "gsession.h"
148 #ifdef HAVE_GNOME_WINDOW_ICON
149 # include <libgnomeui/gnome-window-icon.h>
150 #endif
151 #endif
153 /* "$Id$" */
155 /* When the modes are active, left_panel, right_panel and tree_panel */
156 /* Point to a proper data structure. You should check with the functions */
157 /* get_current_type and get_other_type the types of the panels before using */
158 /* This pointer variables */
160 /* The structures for the panels */
161 WPanel *left_panel;
162 WPanel *right_panel;
164 /* The pointer to the tree */
165 WTree *the_tree;
167 #ifndef HAVE_X
168 /* The Menubar */
169 WMenu *the_menubar;
170 #endif /* HAVE_X */
172 /* Pointers to the selected and unselected panel */
173 WPanel *current_panel = NULL;
175 /* Set when we want use advanced chmod command instead of chmod and/or chown */
176 int advanced_chfns = 0;
178 /* Set when main loop should be terminated */
179 volatile int quit = 0;
181 /* Set if you want the possible completions dialog for the first time */
182 int show_all_if_ambiguous = 0;
184 /* Set when cd symlink following is desirable (bash mode) */
185 #ifndef HAVE_GNOME
186 int cd_symlinks = 1;
187 #else
188 int cd_symlinks = 0;
189 #endif
191 /* If set then dialogs just clean the screen when refreshing, else */
192 /* they do a complete refresh, refreshing all the parts of the program */
193 int fast_refresh = 0;
195 /* If true, marking a files moves the cursor down */
196 int mark_moves_down = 1;
198 /* If true, at startup the user-menu is invoked */
199 int auto_menu = 0;
201 /* If true, use + and \ keys normally and select/unselect do if M-+ / M-\
202 and M-- and keypad + / - */
203 int alternate_plus_minus = 0;
205 /* If true, then the +, - and \ keys have their special meaning only if the
206 * command line is emtpy, otherwise they behave like regular letters
208 int only_leading_plus_minus = 1;
210 /* If true, after executing a command, wait for a keystroke */
211 enum { pause_never, pause_on_dumb_terminals, pause_always };
213 int pause_after_run = pause_on_dumb_terminals;
215 /* It true saves the setup when quitting */
216 int auto_save_setup = 1;
218 #ifndef HAVE_CHARSET
219 /* If true, be eight bit clean */
220 int eight_bit_clean = 1;
222 /* If true, then display chars 0-255, else iso-8859-1,
223 requires eight_bit_clean */
224 int full_eight_bits = 1;
225 #endif
227 /* If true use the internal viewer */
228 int use_internal_view = 1;
230 /* Have we shown the fast-reload warning in the past? */
231 int fast_reload_w = 0;
233 /* Move page/item? When clicking on the top or bottom of a panel */
234 int mouse_move_pages = 1;
236 /* If true: l&r arrows are used to chdir if the input line is empty */
237 int navigate_with_arrows = 0;
239 /* If it is set, the commander will iconify itself when executing a program */
240 int iconify_on_exec = 1;
242 /* If true use +, -, | for line drawing */
243 int force_ugly_line_drawing = 0;
245 /* If true message "The shell is already running a command" never */
246 int force_subshell_execution = 0;
248 /* If true program softkeys (HP terminals only) on startup and after every
249 command ran in the subshell to the description found in the termcap/terminfo
250 database */
251 int reset_hp_softkeys = 0;
253 /* The prompt */
254 char *prompt = 0;
256 /* The widget where we draw the prompt */
257 WLabel *the_prompt;
259 /* The hint bar */
260 WLabel *the_hint;
262 /* The button bar */
263 WButtonBar *the_bar;
265 /* For slow terminals */
266 int slow_terminal = 0;
268 /* use mouse? */
269 int use_mouse_p = GPM_MOUSE;
271 /* If true, assume we are running on an xterm terminal */
272 static int force_xterm = 0;
274 /* Controls screen clearing before an exec */
275 int clear_before_exec = 1;
277 /* Asks for confirmation before deleting a file */
278 int confirm_delete = 1;
280 /* Asks for confirmation before overwriting a file */
281 int confirm_overwrite = 1;
283 /* Asks for confirmation before executing a program by pressing enter */
284 int confirm_execute = 0;
286 /* Asks for confirmation before leaving the program */
287 int confirm_exit = 1;
289 /* Asks for confirmation when using F3 to view a directory and there
290 are tagged files */
291 int confirm_view_dir = 0;
293 /* This flag indicates if the pull down menus by default drop down */
294 int drop_menus = 0;
296 /* The dialog handle for the main program */
297 Dlg_head *midnight_dlg;
299 /* Subshell: if set, then the prompt was not saved on CONSOLE_SAVE */
300 /* We need to paint it after CONSOLE_RESTORE, see: load_prompt */
301 int update_prompt = 0;
303 /* The name which was used to invoke mc */
304 char *program_name;
306 /* The home directory */
307 char *home_dir;
309 /* The value of the other directory, only used when loading the setup */
310 char *other_dir = 0;
311 char *this_dir = 0;
313 /* If this is true, then when browsing the tree the other window will
314 * automatically reload it's directory with the contents of the currently
315 * selected directory.
317 int xtree_mode = 0;
319 /* If true, then print on stdout the last directory we were at */
320 static int print_last_wd = 0;
321 static char *last_wd_string;
322 static int print_last_revert = 0;
324 /* On OS/2 and on Windows NT, we need a batch file to do the -P magic */
325 #ifdef OS2_NT
326 static char *batch_file_name = 0;
327 #endif
329 /* widget colors for the midnight commander */
330 int midnight_colors [4];
332 /* Force colors, only used by Slang */
333 int force_colors = 0;
335 /* colors specified on the command line: they override any other setting */
336 char *command_line_colors;
338 /* File name to view if argument was supplied */
339 char *view_one_file = 0;
341 /* File name to edit if argument was supplied */
342 char *edit_one_file = 0;
343 static int edit_one_file_start_line = 1;
345 /* Used so that widgets know if they are being destroyed or
346 shut down */
347 int midnight_shutdown = 0;
349 /* to show nice prompts */
350 static int last_paused = 0;
352 /* Only used at program boot */
353 int boot_current_is_left = 1;
355 /* Used for keeping track of the original stdout */
356 int stdout_fd = 0;
358 /* The user's shell */
359 char *shell;
361 /* mc_home: The home of MC */
362 char *mc_home;
364 /* if on, it displays the information that files have been moved to ~/.mc */
365 int show_change_notice = 0;
367 char cmd_buf [512];
369 /* Used during argument processing */
370 int finish_program = 0;
372 /* If set, then no windows are displayed in the GNOME edition */
373 int nowindows = 0, nodesktop = 0, twopanel;
375 /* If set it displays the directory that holds the gnome .links files */
376 int display_linksdir = 0;
378 /* Forward declarations */
379 char *get_mc_lib_dir ();
380 int panel_event (Gpm_Event *event, WPanel *panel);
381 int menu_bar_event (Gpm_Event *event, void *);
383 #ifndef HAVE_GNOME
384 static void menu_cmd (void);
386 WPanel *
387 get_current_panel ()
389 return current_panel;
392 WPanel *
393 get_other_panel ()
395 return (WPanel *) get_panel_widget (get_other_index ());
397 #endif
399 void
400 try_to_select (WPanel *panel, char *name)
402 Xtry_to_select (panel, name);
403 #ifndef HAVE_X
404 select_item (panel);
405 #endif
406 display_mini_info (panel);
409 static void
410 reload_panelized (WPanel *panel)
412 int i, j;
413 dir_list *list = &panel->dir;
415 if (panel != cpanel)
416 mc_chdir (panel->cwd);
418 for (i = 0, j = 0; i < panel->count; i++){
419 if (list->list [i].f.marked) {
420 /* Unmark the file in advance. In case the following mc_lstat
421 * fails we are done, else we have to mark the file again
422 * (Note: do_file_mark depends on a valid "list->list [i].buf").
423 * IMO that's the best way to update the panel's summary status
424 * -- Norbert
426 do_file_mark (panel, i, 0);
428 if (mc_lstat (list->list [i].fname, &list->list [i].buf)){
429 g_free (list->list [i].fname);
430 continue;
432 if (list->list [i].f.marked)
433 do_file_mark (panel, i, 1);
434 if (j != i)
435 list->list [j] = list->list [i];
436 j++;
438 if (j == 0)
439 panel->count = set_zero_dir (list);
440 else
441 panel->count = j;
443 if (panel != cpanel)
444 mc_chdir (cpanel->cwd);
447 void
448 update_one_panel_widget (WPanel *panel, int force_update, char *current_file)
450 int free_pointer;
452 if (force_update & UP_RELOAD){
453 panel->is_panelized = 0;
455 #if 0
456 ftpfs_flushdir ();
457 #endif
458 /* FIXME: Should supply flushdir method */
459 memset (&(panel->dir_stat), 0, sizeof (panel->dir_stat));
462 /* If current_file == -1 (an invalid pointer) then preserve selection */
463 if (current_file == UP_KEEPSEL){
464 free_pointer = 1;
465 current_file = g_strdup (panel->dir.list [panel->selected].fname);
466 } else
467 free_pointer = 0;
469 if (panel->is_panelized)
470 reload_panelized (panel);
471 else
472 panel_reload (panel);
474 try_to_select (panel, current_file);
475 panel->dirty = 1;
477 if (free_pointer)
478 g_free (current_file);
480 #ifdef HAVE_X
481 paint_panel (panel);
482 panel->dirty = 0;
483 #endif
486 void
487 panel_clean_dir (WPanel *panel)
489 int count = panel->count;
491 panel->count = 0;
492 panel->top_file = 0;
493 panel->selected = 0;
494 panel->marked = 0;
495 panel->dirs_marked = 0;
496 panel->total = 0;
497 panel->searching = 0;
498 panel->is_panelized = 0;
500 clean_dir (&panel->dir, count);
503 #ifndef PORT_HAS_UPDATE_PANELS
504 void
505 update_one_panel (int which, int force_update, char *current_file)
507 WPanel *panel;
509 if (get_display_type (which) != view_listing)
510 return;
512 panel = (WPanel *) get_panel_widget (which);
513 update_one_panel_widget (panel, force_update, current_file);
516 /* This routine reloads the directory in both panels. It tries to
517 * select current_file in current_panel and other_file in other_panel.
518 * If current_file == -1 then it automatically sets current_file and
519 * other_file to the currently selected files in the panels.
521 * if force_update has the UP_ONLY_CURRENT bit toggled on, then it
522 * will not reload the other panel.
524 void
525 update_panels (int force_update, char *current_file)
527 int reload_other = !(force_update & UP_ONLY_CURRENT);
528 WPanel *panel;
530 update_one_panel (get_current_index (), force_update, current_file);
531 if (reload_other)
532 update_one_panel (get_other_index (), force_update, UP_KEEPSEL);
534 if (get_current_type () == view_listing)
535 panel = (WPanel *) get_panel_widget (get_current_index ());
536 else
537 panel = (WPanel *) get_panel_widget (get_other_index ());
539 mc_chdir (panel->cwd);
541 #endif
543 #ifdef WANT_PARSE
544 static void select_by_index (WPanel *panel, int i);
546 /* Called by parse_control_file */
547 static int index_by_name (file_entry *list, int count)
549 char *name;
550 int i;
552 name = strtok (NULL, " \t\n");
553 if (!name || !*name)
554 return -1;
555 for (i = 0; i < count; i++){
556 if (strcmp (name, list[i].fname) == 0)
557 return i;
559 return -1;
562 /* Called by parse_control_file */
563 static void select_by_index (WPanel *panel, int i)
565 if (i >= panel->count)
566 return;
568 unselect_item (panel);
569 panel->selected = i;
571 #ifndef HAVE_X
572 while (panel->selected - panel->top_file >= ITEMS (panel)){
573 /* Scroll window half screen */
574 panel->top_file += ITEMS (panel)/2;
575 paint_dir (panel);
576 select_item (panel);
578 while (panel->selected < panel->top_file){
579 /* Scroll window half screen */
580 panel->top_file -= ITEMS (panel)/2;
581 if (panel->top_file < 0) panel->top_file = 0;
582 paint_dir (panel);
584 #endif
585 select_item (panel);
588 /* Called by my_system
589 No error reporting, just exits on the first sign of trouble */
590 static void parse_control_file (void)
592 char *data, *current;
593 WPanel *panel;
594 file_entry *list;
595 int i;
596 FILE *file;
597 struct stat s;
599 if ((file = fopen (control_file, "r")) == NULL){
600 return;
602 /* Use of fstat prevents race conditions */
603 if (fstat (fileno (file), &s) != 0){
604 fclose (file);
605 return;
607 #ifndef OS2_NT
608 /* Security: Check that the user owns the control file and this file
609 is not group/world writable to prevent other users from playing tricks
610 on him/her. */
611 if (s.st_uid != getuid () || ((s.st_mode) & (S_IWGRP|S_IWOTH))) {
612 fclose (file);
613 return;
615 #endif
616 data = (char *) g_malloc (s.st_size+1);
617 if (!data){
618 fclose (file);
619 return;
621 if (s.st_size != fread (data, 1, s.st_size, file)){
622 g_free (data);
623 fclose (file);
624 return;
626 data [s.st_size] = 0;
627 fclose (file);
629 /* The Control file has now been loaded to memory -> start parsing. */
630 current = strtok (data, " \t\n");
631 while (current && *current){
632 if (isupper (*current)){
633 if (get_other_type () != view_listing)
634 break;
635 else
636 panel = other_panel;
637 } else
638 panel = cpanel;
640 list = panel->dir.list;
641 *current = tolower (*current);
643 if (strcmp (current, "clear_tags") == 0){
644 unmark_files (panel);
645 } else if (strcmp (current, "tag") == 0){
646 i = index_by_name (list, panel->count);
647 if (i >= 0) {
648 do_file_mark (panel, i, 1);
650 } else if (strcmp (current, "untag") == 0){
651 i = index_by_name (list, panel->count);
652 if (i >= 0){
653 do_file_mark (panel, i, 0);
655 } else if (strcmp (current, "select") == 0){
656 i = index_by_name (list, panel->count);
657 if (i >= 0){
658 select_by_index (panel, i);
660 } else if (strcmp (current, "change_panel") == 0){
661 change_panel ();
662 } else if (strcmp (current, "cd") == 0){
663 int change = 0;
664 current = strtok (NULL, " \t\n");
665 if (!current) break;
666 if (cpanel != panel){
667 change_panel ();
668 change = 1;
670 do_cd (current, cd_parse_command);
671 if (change)
672 change_panel ();
673 } else {
674 /* Unknown command -> let's give up */
675 break;
677 current = strtok (NULL, " \t\n");
680 g_free (data);
681 paint_panel (cpanel);
682 paint_panel (opanel);
684 #else
685 #define parse_control_file()
686 #endif /* WANT_PARSE */
688 /* Sets up the terminal before executing a program */
689 static void
690 pre_exec (void)
692 use_dash (0);
693 edition_pre_exec ();
696 /* Save current stat of directories to avoid reloading the panels */
697 /* when no modifications have taken place */
698 void
699 save_cwds_stat (void)
701 if (fast_reload){
702 mc_stat (cpanel->cwd, &(cpanel->dir_stat));
703 if (get_other_type () == view_listing)
704 mc_stat (opanel->cwd, &(opanel->dir_stat));
708 #ifdef HAVE_SUBSHELL_SUPPORT
709 void
710 do_possible_cd (char *new_dir)
712 if (!do_cd (new_dir, cd_exact))
713 message (1, _(" Warning "),
714 _(" The Commander can't change to the directory that \n"
715 " the subshell claims you are in. Perhaps you have \n"
716 " deleted your working directory, or given yourself \n"
717 " extra access permissions with the \"su\" command? "));
720 void
721 do_update_prompt ()
723 if (update_prompt){
724 printf ("%s", subshell_prompt);
725 fflush (stdout);
726 update_prompt = 0;
729 #endif
731 void
732 restore_console (void)
734 handle_console (CONSOLE_RESTORE);
737 void
738 exec_shell ()
740 do_execute (shell, 0, 0);
743 void
744 do_execute (const char *shell, const char *command, int flags)
746 #ifdef HAVE_SUBSHELL_SUPPORT
747 char *new_dir = NULL;
748 #endif
750 #ifdef USE_VFS
751 char *old_vfs_dir = 0;
753 if (!vfs_current_is_local ())
754 old_vfs_dir = g_strdup (vfs_get_current_dir ());
755 #endif
757 save_cwds_stat ();
758 pre_exec ();
759 if (console_flag)
760 restore_console ();
762 #ifndef __os2__
763 unlink (control_file);
764 #endif
765 if (!use_subshell && !(flags & EXECUTE_INTERNAL)){
766 printf ("%s%s%s\n", last_paused ? "\r\n":"", prompt, command);
767 last_paused = 0;
770 #ifdef HAVE_SUBSHELL_SUPPORT
771 if (use_subshell && !(flags & EXECUTE_INTERNAL)){
772 do_update_prompt ();
774 /* We don't care if it died, higher level takes care of this */
775 #ifdef USE_VFS
776 invoke_subshell (command, VISIBLY, old_vfs_dir ? 0 : &new_dir);
777 #else
778 invoke_subshell (command, VISIBLY, &new_dir);
779 #endif
780 } else
781 #endif
782 my_system (flags, shell, command);
784 #ifndef HAVE_GNOME
785 if (!(flags & EXECUTE_INTERNAL)){
786 if ((pause_after_run == pause_always ||
787 (pause_after_run == pause_on_dumb_terminals &&
788 !xterm_flag && !console_flag)) && !quit){
789 printf (_("Press any key to continue..."));
790 last_paused = 1;
791 fflush (stdout);
792 mc_raw_mode ();
793 xgetch ();
795 if (console_flag){
796 if (output_lines && keybar_visible) {
797 putchar('\n');
798 fflush(stdout);
802 #endif
804 if (console_flag)
805 handle_console (CONSOLE_SAVE);
806 edition_post_exec ();
808 #ifdef HAVE_SUBSHELL_SUPPORT
809 if (new_dir)
810 do_possible_cd (new_dir);
812 #endif
813 #ifdef USE_VFS
814 if (old_vfs_dir){
815 mc_chdir (old_vfs_dir);
816 g_free (old_vfs_dir);
818 #endif
820 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
822 parse_control_file ();
823 #ifndef __os2__
824 unlink (control_file);
825 #endif
826 do_refresh ();
827 use_dash (TRUE);
830 /* Executes a command */
831 void
832 shell_execute (char *command, int flags)
834 #ifdef HAVE_SUBSHELL_SUPPORT
835 if (use_subshell)
836 if (subshell_state == INACTIVE || force_subshell_execution)
837 do_execute (shell, command, flags | EXECUTE_AS_SHELL);
838 else
839 message (1, MSG_ERROR, _(" The shell is already running a command "));
840 else
841 #endif
842 do_execute (shell, command, flags | EXECUTE_AS_SHELL);
845 void
846 execute (char *command)
848 shell_execute (command, 0);
851 void
852 change_panel (void)
854 free_completions (input_w (cmdline));
855 dlg_one_down (midnight_dlg);
858 static int
859 quit_cmd_internal (int quiet)
861 int q = quit;
863 if (quiet || !confirm_exit){
864 q = 1;
865 } else {
866 if (query_dialog (_(" The Midnight Commander "),
867 _(" Do you really want to quit the Midnight Commander? "),
868 0, 2, _("&Yes"), _("&No")) == 0)
869 q = 1;
871 if (q){
872 #ifdef HAVE_SUBSHELL_SUPPORT
873 if (!use_subshell)
874 midnight_dlg->running = 0;
875 else
876 if ((q = exit_subshell ()))
877 #endif
878 midnight_dlg->running = 0;
880 if (q)
881 quit |= 1;
882 return quit;
885 int quit_cmd (void)
887 quit_cmd_internal (0);
888 return quit;
891 int quiet_quit_cmd (void)
893 print_last_revert = 1;
894 quit_cmd_internal (1);
895 return quit;
899 * Touch window and refresh window functions
902 /* This routine untouches the first line on both panels in order */
903 /* to avoid the refreshing the menu bar */
905 #ifdef HAVE_X
906 void
907 untouch_bar (void)
911 void
912 repaint_screen (void)
914 do_refresh ();
917 #else /* HAVE_X */
918 void
919 untouch_bar (void)
921 do_refresh ();
924 void
925 repaint_screen (void)
927 do_refresh ();
928 mc_refresh ();
930 #endif /* HAVE_X */
932 /* Wrapper for do_subshell_chdir, check for availability of subshell */
933 void
934 subshell_chdir (char *directory)
936 #ifdef HAVE_SUBSHELL_SUPPORT
937 if (use_subshell){
938 if (vfs_current_is_local ())
939 do_subshell_chdir (directory, 0, 1);
941 #endif
944 void
945 directory_history_add (WPanel * panel, char *s)
947 if (!panel->dir_history) {
948 panel->dir_history = g_new0 (Hist, 1);
949 panel->dir_history->text = g_strdup (s);
950 strip_password (panel->dir_history->text, 1);
951 return;
953 if (!strcmp (panel->dir_history->text, s))
954 return;
955 if (panel->dir_history->next) {
956 if (panel->dir_history->next->text) {
957 g_free (panel->dir_history->next->text);
958 panel->dir_history->next->text = 0;
960 } else {
961 panel->dir_history->next = g_new0 (Hist, 1);
962 panel->dir_history->next->prev = panel->dir_history;
964 panel->dir_history = panel->dir_history->next;
965 panel->dir_history->text = g_strdup (s);
966 strip_password (panel->dir_history->text, 1);
968 panel_update_marks (panel);
972 * If we moved to the parent directory move the selection pointer to
973 * the old directory name; If we leave VFS dir, remove FS specificator.
974 * Warn: This code spoils lwd string.
976 * You do _NOT_ want to add any vfs aware code here. <pavel@ucw.cz>
978 static char*
979 get_parent_dir_name (char *cwd, char *lwd)
981 char *p;
982 if (strlen (lwd) > strlen (cwd))
983 if((p=strrchr(lwd, PATH_SEP)) && !strncmp(cwd, lwd, p-lwd)){
984 return (p+1);
986 return NULL;
989 /* Changes the current panel directory */
990 static int
991 _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type)
993 char *directory, *olddir;
994 char temp [MC_MAXPATHLEN];
995 char *translated_url;
996 #ifdef USE_VFS
997 vfs *oldvfs;
998 vfsid oldvfsid;
999 struct vfs_stamping *parent;
1000 #endif
1001 olddir = g_strdup (panel->cwd);
1002 translated_url = new_dir = vfs_translate_url (new_dir);
1004 /* Convert *new_path to a suitable pathname, handle ~user */
1006 if (cd_type == cd_parse_command){
1007 while (*new_dir == ' ')
1008 new_dir++;
1010 if (!strcmp (new_dir, "-")){
1011 strcpy (temp, panel->lwd);
1012 new_dir = temp;
1015 directory = *new_dir ? new_dir : home_dir;
1017 #ifdef HAVE_GNOME
1018 if (is_a_desktop_panel (panel)) {
1019 new_panel_at (directory);
1020 g_free (olddir);
1021 g_free (translated_url);
1022 return 0; /* Don't add to history */
1024 #endif
1026 if (mc_chdir (directory) == -1){
1027 strcpy (panel->cwd, olddir);
1028 g_free (olddir);
1029 g_free (translated_url);
1030 return 0;
1032 g_free (translated_url);
1034 /* Success: save previous directory, shutdown status of previous dir */
1035 strcpy (panel->lwd, olddir);
1036 free_completions (input_w (cmdline));
1038 mc_get_current_wd (panel->cwd, sizeof (panel->cwd) - 2);
1040 #ifdef USE_VFS
1041 oldvfs = vfs_type (olddir);
1042 oldvfsid = vfs_ncs_getid (oldvfs, olddir, &parent);
1043 vfs_add_noncurrent_stamps (oldvfs, oldvfsid, parent);
1044 vfs_rm_parents (parent);
1045 #endif
1047 subshell_chdir (panel->cwd);
1049 /* Reload current panel */
1050 panel_clean_dir (panel);
1051 panel->count = do_load_dir (&panel->dir, panel->sort_type,
1052 panel->reverse, panel->case_sensitive, panel->filter);
1053 try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
1054 load_hint ();
1055 panel_update_contents (panel);
1057 g_free (olddir);
1059 return 1;
1063 do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type)
1065 int r;
1067 r = _do_panel_cd (panel, new_dir, cd_type);
1068 if (r)
1069 directory_history_add (cpanel, cpanel->cwd);
1070 return r;
1074 do_cd (char *new_dir, enum cd_enum exact)
1076 return (do_panel_cd (cpanel, new_dir, exact));
1079 void
1080 directory_history_next (WPanel * panel)
1082 if (!panel->dir_history->next)
1083 return;
1084 if (_do_panel_cd (panel, panel->dir_history->next->text, cd_exact))
1085 panel->dir_history = panel->dir_history->next;
1086 panel_update_marks (panel);
1089 void
1090 directory_history_prev (WPanel * panel)
1092 if (!panel->dir_history->prev)
1093 return;
1094 if (_do_panel_cd (panel, panel->dir_history->prev->text, cd_exact))
1095 panel->dir_history = panel->dir_history->prev;
1096 panel_update_marks (panel);
1099 void
1100 directory_history_list (WPanel * panel)
1102 char *s;
1103 /* must be at least two to show a history */
1104 if (panel->dir_history) {
1105 if (panel->dir_history->prev || panel->dir_history->next) {
1106 s = show_hist (panel->dir_history, panel->widget.x, panel->widget.y);
1107 if (s) {
1108 int r;
1109 r = _do_panel_cd (panel, s, cd_exact);
1110 if (r)
1111 directory_history_add (panel, panel->cwd);
1112 g_free (s);
1118 #ifdef HAVE_SUBSHELL_SUPPORT
1120 load_prompt (int fd, void *unused)
1122 if (!read_subshell_prompt (QUIETLY))
1123 return 0;
1125 if (command_prompt){
1126 int prompt_len;
1128 prompt = strip_ctrl_codes (subshell_prompt);
1129 prompt_len = strlen (prompt);
1131 /* Check for prompts too big */
1132 if (prompt_len > COLS - 8) {
1133 prompt [COLS - 8 ] = 0;
1134 prompt_len = COLS - 8;
1136 label_set_text (the_prompt, prompt);
1137 winput_set_origin ((WInput *)cmdline, prompt_len, COLS-prompt_len);
1139 /* since the prompt has changed, and we are called from one of the
1140 * get_event channels, the prompt updating does not take place
1141 * automatically: force a cursor update and a screen refresh
1143 if (current_dlg == midnight_dlg){
1144 update_cursor (midnight_dlg);
1145 mc_refresh ();
1148 update_prompt = 1;
1149 return 0;
1151 #endif
1153 /* The user pressed the enter key */
1155 menu_bar_event (Gpm_Event *event, void *x)
1157 if (event->type != GPM_DOWN)
1158 return MOU_NORMAL;
1160 return MOU_ENDLOOP;
1163 /* Used to emulate Lynx's entering leaving a directory with the arrow keys */
1165 maybe_cd (int char_code, int move_up_dir)
1167 if (navigate_with_arrows){
1168 if (!input_w (cmdline)->buffer [0]){
1169 if (!move_up_dir){
1170 do_cd ("..", cd_exact);
1171 return 1;
1173 if (S_ISDIR (selection (cpanel)->buf.st_mode)
1174 || link_isdir (selection (cpanel))){
1175 do_cd (selection (cpanel)->fname, cd_exact);
1176 return 1;
1180 return 0;
1182 #if 0
1183 static void
1184 set_sort_to (WPanel *p, sortfn *sort_order)
1186 p->sort_type = sort_order;
1188 /* The directory is already sorted, we have to load the unsorted stuff */
1189 if (sort_order == (sortfn *) unsorted){
1190 char *current_file;
1192 current_file = g_strdup (cpanel->dir.list [cpanel->selected].fname);
1193 panel_reload (cpanel);
1194 try_to_select (cpanel, current_file);
1195 g_free (current_file);
1197 do_re_sort (p);
1199 #endif
1200 #ifndef HAVE_GNOME
1201 void
1202 sort_cmd (void)
1204 WPanel *p;
1205 sortfn *sort_order;
1207 if (!SELECTED_IS_PANEL)
1208 return;
1210 p = MENU_PANEL;
1211 sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive);
1213 panel_set_sort_order (p, sort_order);
1217 static void
1218 tree_box (void)
1220 char *sel_dir;
1222 sel_dir = tree (selection (cpanel)->fname);
1223 if (sel_dir){
1224 do_cd(sel_dir, cd_exact);
1225 g_free (sel_dir);
1229 #ifdef LISTMODE_EDITOR
1230 static void
1231 listmode_cmd (void)
1233 char *newmode;
1234 newmode = listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
1235 message (0, _(" Listing format edit "), _(" New mode is \"%s\" "), newmode);
1236 g_free (newmode);
1238 #endif /* LISTMODE_EDITOR */
1239 #endif /* !HAVE_GNOME */
1241 #ifdef HAVE_GNOME
1242 void init_menu (void) {};
1243 void done_menu (void) {};
1244 #else
1245 /* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
1246 static menu_entry PanelMenu [] = {
1247 { ' ', N_("&Listing mode..."), 'L', listing_cmd },
1248 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd },
1249 { ' ', N_("&Info C-x i"), 'I', info_cmd },
1250 { ' ', N_("&Tree"), 'T', tree_cmd },
1251 { ' ', "", ' ', 0 },
1252 { ' ', N_("&Sort order..."), 'S', sort_cmd },
1253 { ' ', "", ' ', 0 },
1254 { ' ', N_("&Filter..."), 'F', filter_cmd },
1255 #ifdef USE_NETCODE
1256 { ' ', "", ' ', 0 },
1257 { ' ', N_("&Network link..."), 'N', netlink_cmd },
1258 { ' ', N_("FT&P link..."), 'P', ftplink_cmd },
1259 #ifdef WITH_SMBFS
1260 { ' ', N_("SM&B link..."), 'B', smblink_cmd },
1261 #endif
1262 #endif
1263 { ' ', "", ' ', 0 },
1264 #ifdef OS2_NT
1265 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_a },
1266 #endif
1267 { ' ', N_("&Rescan C-r"), 'R', reread_cmd }
1270 static menu_entry RightMenu [] = {
1271 { ' ', N_("&Listing mode..."), 'L', listing_cmd },
1272 { ' ', N_("&Quick view C-x q"), 'Q', quick_view_cmd },
1273 { ' ', N_("&Info C-x i"), 'I', info_cmd },
1274 { ' ', N_("&Tree"), 'T', tree_cmd },
1275 { ' ', "", ' ', 0 },
1276 { ' ', N_("&Sort order..."), 'S', sort_cmd },
1277 { ' ', "", ' ', 0 },
1278 { ' ', N_("&Filter..."), 'F', filter_cmd },
1279 #ifdef USE_NETCODE
1280 { ' ', "", ' ', 0 },
1281 { ' ', N_("&Network link..."), 'N', netlink_cmd },
1282 { ' ', N_("FT&P link..."), 'P', ftplink_cmd },
1283 #ifdef WITH_SMBFS
1284 { ' ', N_("SM&B link..."), 'B', smblink_cmd },
1285 #endif
1286 #endif
1287 { ' ', "", ' ', 0 },
1288 #ifdef OS2_NT
1289 { ' ', N_("&Drive... M-d"), 'D', drive_cmd_b },
1290 #endif
1291 { ' ', N_("&Rescan C-r"), 'R', reread_cmd }
1294 static menu_entry FileMenu [] = {
1295 { ' ', N_("&User menu F2"), 'U', user_file_menu_cmd },
1296 { ' ', N_("&View F3"), 'V', view_cmd },
1297 { ' ', N_("Vie&w file... "), 'W', view_file_cmd },
1298 { ' ', N_("&Filtered view M-!"), 'F', filtered_view_cmd },
1299 { ' ', N_("&Edit F4"), 'E', edit_cmd },
1300 { ' ', N_("&Copy F5"), 'C', copy_cmd },
1301 { ' ', N_("c&Hmod C-x c"), 'H', chmod_cmd },
1302 #ifndef OS2_NT
1303 { ' ', N_("&Link C-x l"), 'L', link_cmd },
1304 { ' ', N_("&SymLink C-x s"), 'S', symlink_cmd },
1305 { ' ', N_("edit s&Ymlink C-x C-s"), 'Y', edit_symlink_cmd },
1306 { ' ', N_("ch&Own C-x o"), 'O', chown_cmd },
1307 { ' ', N_("&Advanced chown "), 'A', chown_advanced_cmd },
1308 #endif
1309 { ' ', N_("&Rename/Move F6"), 'R', ren_cmd },
1310 { ' ', N_("&Mkdir F7"), 'M', mkdir_cmd },
1311 { ' ', N_("&Delete F8"), 'D', delete_cmd },
1312 { ' ', N_("&Quick cd M-c"), 'Q', quick_cd_cmd },
1313 { ' ', "", ' ', 0 },
1314 { ' ', N_("select &Group M-+"), 'G', select_cmd },
1315 { ' ', N_("u&Nselect group M-\\"),'N', unselect_cmd },
1316 { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd },
1317 { ' ', "", ' ', 0 },
1318 { ' ', N_("e&Xit F10"), 'X', (callfn) quit_cmd }
1321 void external_panelize (void);
1322 static menu_entry CmdMenu [] = {
1323 /* I know, I'm lazy, but the tree widget when it's not running
1324 * as a panel still has some problems, I have not yet finished
1325 * the WTree widget port, sorry.
1327 { ' ', N_("&Directory tree"), 'D', tree_box },
1328 { ' ', N_("&Find file M-?"), 'F', find_cmd },
1329 { ' ', N_("s&Wap panels C-u"), 'W', swap_cmd },
1330 { ' ', N_("switch &Panels on/off C-o"), 'P', view_other_cmd },
1331 { ' ', N_("&Compare directories C-x d"), 'C', compare_dirs_cmd },
1332 { ' ', N_("e&Xternal panelize C-x !"), 'X', external_panelize },
1333 { ' ', N_("show directory s&Izes"), 'I', dirsizes_cmd },
1334 { ' ', "", ' ', 0 },
1335 { ' ', N_("command &History"), 'H', history_cmd },
1336 { ' ', N_("di&Rectory hotlist C-\\"), 'R', quick_chdir_cmd },
1337 #ifdef USE_VFS
1338 { ' ', N_("&Active VFS list C-x a"), 'A', reselect_vfs },
1339 { ' ', N_("Fr&ee VFSs now"), 'E', free_vfs_now },
1340 #endif
1341 #ifdef WITH_BACKGROUND
1342 { ' ', N_("&Background jobs C-x j"), 'B', jobs_cmd },
1343 #endif
1344 { ' ', "", ' ', 0 },
1345 #ifdef USE_EXT2FSLIB
1346 { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd },
1347 #endif
1348 #ifdef LISTMODE_EDITOR
1349 { ' ', N_("&Listing format edit"), 'L', listmode_cmd},
1350 #endif
1351 #if defined (USE_EXT2FSLIB) || defined (LISTMODE_EDITOR)
1352 { ' ', "", ' ', 0 },
1353 #endif
1354 { ' ', N_("&Extension file edit"), 'E', ext_cmd },
1355 { ' ', N_("&Menu file edit"), 'M', menu_edit_cmd },
1356 #ifdef USE_INTERNAL_EDIT
1357 {' ', N_("Menu edi&Tor edit"), 'T', edit_user_menu_cmd}
1358 #endif /* USE_INTERNAL_EDIT */
1361 /* Must keep in sync with the constants in menu_cmd */
1362 static menu_entry OptMenu [] = {
1363 { ' ', N_("&Configuration..."), 'C', configure_box },
1364 { ' ', N_("&Layout..."), 'L', layout_cmd },
1365 { ' ', N_("c&Onfirmation..."), 'O', confirm_box },
1366 { ' ', N_("&Display bits..."), 'D', display_bits_box },
1367 #ifndef OS2_NT
1368 { ' ', N_("learn &Keys..."), 'K', learn_keys },
1369 #endif /* !OS2_NT */
1370 #ifdef USE_VFS
1371 { ' ', N_("&Virtual FS..."), 'V', configure_vfs },
1372 #endif /* !USE_VFS */
1373 { ' ', "", ' ', 0 },
1374 { ' ', N_("&Save setup"), 'S', save_setup_cmd }
1377 #define menu_entries(x) sizeof(x)/sizeof(menu_entry)
1379 Menu MenuBar [5];
1380 static Menu MenuBarEmpty [5];
1382 void
1383 init_menu (void)
1385 int i;
1387 MenuBar [0] = create_menu ( horizontal_split ? _(" &Above ") : _(" &Left "),
1388 PanelMenu, menu_entries (PanelMenu));
1389 MenuBar [1] = create_menu (_(" &File "), FileMenu, menu_entries (FileMenu));
1390 MenuBar [2] = create_menu (_(" &Command "), CmdMenu, menu_entries (CmdMenu));
1391 MenuBar [3] = create_menu (_(" &Options "), OptMenu, menu_entries (OptMenu));
1392 MenuBar [4] = create_menu (horizontal_split ? _(" &Below ") : _(" &Right "),
1393 RightMenu, menu_entries (PanelMenu));
1394 for (i = 0; i < 5; i++)
1395 MenuBarEmpty [i] = create_menu (MenuBar [i]->name, 0, 0);
1398 void
1399 done_menu (void)
1401 int i;
1403 for (i = 0; i < 5; i++){
1404 destroy_menu (MenuBar [i]);
1405 destroy_menu (MenuBarEmpty [i]);
1409 static void
1410 menu_last_selected_cmd (void)
1412 the_menubar->active = 1;
1413 the_menubar->dropped = drop_menus;
1414 the_menubar->previous_selection = dlg_item_number (midnight_dlg);
1415 dlg_select_widget (midnight_dlg, the_menubar);
1418 static void
1419 menu_cmd (void)
1421 if (the_menubar->active)
1422 return;
1424 if (get_current_index () == 0)
1425 the_menubar->selected = 0;
1426 else
1427 the_menubar->selected = 4;
1428 menu_last_selected_cmd ();
1430 #endif /* !HAVE_GNOME */
1432 /* Flag toggling functions */
1433 void
1434 toggle_confirm_delete (void)
1436 confirm_delete = !confirm_delete;
1439 void
1440 toggle_fast_reload (void)
1442 fast_reload = !fast_reload;
1443 if (fast_reload_w == 0 && fast_reload){
1444 message (0, _(" Information "),
1445 _(" Using the fast reload option may not reflect the exact \n"
1446 " directory contents. In this cases you'll need to do a \n"
1447 " manual reload of the directory. See the man page for \n"
1448 " the details. "));
1449 fast_reload_w = 1;
1453 void
1454 toggle_mix_all_files (void)
1456 mix_all_files = !mix_all_files;
1457 update_panels (UP_RELOAD, UP_KEEPSEL);
1460 void
1461 toggle_show_backup (void)
1463 show_backups = !show_backups;
1464 update_panels (UP_RELOAD, UP_KEEPSEL);
1467 void
1468 toggle_show_hidden (void)
1470 show_dot_files = !show_dot_files;
1471 update_panels (UP_RELOAD, UP_KEEPSEL);
1474 void
1475 toggle_show_mini_status (void)
1477 show_mini_info = !show_mini_info;
1478 paint_panel (cpanel);
1479 if (get_other_type () == view_listing)
1480 paint_panel (opanel);
1483 void
1484 toggle_align_extensions (void)
1486 align_extensions = !align_extensions;
1490 * Just a hack for allowing url-like pathnames to be accepted from the
1491 * command line.
1493 #ifndef PORT_HAS_CREATE_PANELS
1494 static void
1495 translated_mc_chdir (char *dir)
1497 char *newdir;
1499 newdir = vfs_translate_url (dir);
1500 mc_chdir (newdir);
1501 g_free (newdir);
1504 void
1505 create_panels (void)
1507 int current_index;
1508 int other_index;
1509 int current_mode;
1510 int other_mode;
1511 char original_dir [1024];
1513 original_dir [0] = 0;
1515 if (boot_current_is_left){
1516 current_index = 0;
1517 other_index = 1;
1518 current_mode = startup_left_mode;
1519 other_mode = startup_right_mode;
1520 } else {
1521 current_index = 1;
1522 other_index = 0;
1523 current_mode = startup_right_mode;
1524 other_mode = startup_left_mode;
1526 /* Creates the left panel */
1527 if (this_dir){
1528 if (other_dir){
1529 /* Ok, user has specified two dirs, save the original one,
1530 * since we may not be able to chdir to the proper
1531 * second directory later
1533 mc_get_current_wd (original_dir, sizeof (original_dir)-2);
1535 translated_mc_chdir (this_dir);
1537 set_display_type (current_index, current_mode);
1539 /* The other panel */
1540 if (other_dir){
1541 if (original_dir [0])
1542 translated_mc_chdir (original_dir);
1543 translated_mc_chdir (other_dir);
1545 set_display_type (other_index, other_mode);
1547 if (startup_left_mode == view_listing){
1548 current_panel = left_panel;
1549 } else {
1550 if (right_panel)
1551 current_panel = right_panel;
1552 else
1553 current_panel = left_panel;
1556 /* Create the nice widgets */
1557 cmdline = command_new (0, 0, 0);
1558 the_prompt = label_new (0, 0, prompt, NULL);
1559 the_prompt->transparent = 1;
1560 the_bar = buttonbar_new (keybar_visible);
1562 #ifndef HAVE_GNOME
1563 the_hint = label_new (0, 0, 0, NULL);
1564 the_hint->transparent = 1;
1565 the_hint->auto_adjust_cols = 0;
1566 the_hint->widget.cols = COLS;
1567 #endif
1569 the_menubar = menubar_new (0, 0, COLS, MenuBar, 5);
1571 #endif
1573 #ifndef HAVE_GNOME
1574 static void copy_current_pathname (void)
1576 if (!command_prompt)
1577 return;
1579 stuff (input_w (cmdline), cpanel->cwd, 0);
1580 if (cpanel->cwd [strlen (cpanel->cwd) - 1] != PATH_SEP)
1581 stuff (input_w (cmdline), PATH_SEP_STR, 0);
1584 static void copy_other_pathname (void)
1586 if (get_other_type () != view_listing)
1587 return;
1589 if (!command_prompt)
1590 return;
1592 stuff (input_w (cmdline), opanel->cwd, 0);
1593 if (cpanel->cwd [strlen (opanel->cwd) - 1] != PATH_SEP)
1594 stuff (input_w (cmdline), PATH_SEP_STR, 0);
1596 #endif /* !HAVE_GNOME */
1598 static void copy_readlink (WPanel *panel)
1600 if (!command_prompt)
1601 return;
1602 if (S_ISLNK (selection (panel)->buf.st_mode)) {
1603 char buffer [MC_MAXPATHLEN];
1604 char *p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
1605 int i;
1607 i = mc_readlink (p, buffer, MC_MAXPATHLEN);
1608 g_free (p);
1609 if (i > 0) {
1610 buffer [i] = 0;
1611 stuff (input_w (cmdline), buffer, 0);
1616 static void copy_current_readlink (void)
1618 copy_readlink (cpanel);
1621 static void copy_other_readlink (void)
1623 if (get_other_type () != view_listing)
1624 return;
1625 copy_readlink (opanel);
1628 /* Inserts the selected file name into the input line */
1629 /* Exported so that the command modules uses it */
1630 void copy_prog_name (void)
1632 char *tmp;
1633 if (!command_prompt)
1634 return;
1636 if (get_current_type () == view_tree){
1637 WTree *tree = (WTree *) get_panel_widget (get_current_index ());
1638 tmp = name_quote (tree->selected_ptr->name, 1);
1639 } else
1640 tmp = name_quote (selection (cpanel)->fname, 1);
1641 stuff (input_w (cmdline), tmp, 1);
1642 g_free (tmp);
1645 #ifndef HAVE_GNOME
1646 static void copy_tagged (WPanel *panel)
1648 int i;
1650 if (!command_prompt)
1651 return;
1652 input_disable_update (input_w (cmdline));
1653 if (panel->marked){
1654 for (i = 0; i < panel->count; i++)
1655 if (panel->dir.list [i].f.marked) {
1656 char *tmp = name_quote (panel->dir.list [i].fname, 1);
1657 stuff (input_w (cmdline), tmp, 1);
1658 g_free (tmp);
1660 } else {
1661 char *tmp = name_quote (panel->dir.list [panel->selected].fname, 1);
1662 stuff (input_w (cmdline), tmp, 1);
1663 g_free (tmp);
1665 input_enable_update (input_w (cmdline));
1668 static void copy_current_tagged (void)
1670 copy_tagged (cpanel);
1673 static void copy_other_tagged (void)
1675 if (get_other_type () != view_listing)
1676 return;
1677 copy_tagged (opanel);
1680 static void do_suspend_cmd (void)
1682 pre_exec ();
1684 if (console_flag && !use_subshell)
1685 restore_console ();
1687 #ifdef SIGTSTP
1689 struct sigaction sigtstp_action;
1691 /* Make sure that the SIGTSTP below will suspend us directly,
1692 without calling ncurses' SIGTSTP handler; we *don't* want
1693 ncurses to redraw the screen immediately after the SIGCONT */
1694 sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
1696 kill (getpid (), SIGTSTP);
1698 /* Restore previous SIGTSTP action */
1699 sigaction (SIGTSTP, &sigtstp_action, NULL);
1701 #endif /* SIGTSTP */
1703 if (console_flag && !use_subshell)
1704 handle_console (CONSOLE_SAVE);
1706 edition_post_exec ();
1709 void
1710 suspend_cmd (void)
1712 save_cwds_stat ();
1713 do_suspend_cmd ();
1714 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1715 do_refresh ();
1718 static void
1719 init_labels (Widget *paneletc)
1721 define_label (midnight_dlg, paneletc, 1, _("Help"), help_cmd);
1722 define_label (midnight_dlg, paneletc, 2, _("Menu"), user_file_menu_cmd);
1723 define_label (midnight_dlg, paneletc, 9, _("PullDn"), menu_cmd);
1724 define_label (midnight_dlg, paneletc, 10, _("Quit"), (voidfn) quit_cmd);
1726 #endif /* !HAVE_GNOME */
1728 static const key_map ctl_x_map [] = {
1729 { XCTRL('c'), (callfn) quit_cmd },
1730 { 'd', compare_dirs_cmd },
1731 #ifndef HAVE_GNOME
1732 #ifdef USE_VFS
1733 { 'a', reselect_vfs },
1734 #endif /* USE_VFS */
1735 { 'p', copy_current_pathname },
1736 { XCTRL('p'), copy_other_pathname },
1737 { 't', copy_current_tagged },
1738 { XCTRL('t'), copy_other_tagged },
1739 { 'c', chmod_cmd },
1740 #endif /* !HAVE_GNOME */
1741 #ifndef OS2_NT
1742 #ifndef HAVE_GNOME
1743 { 'o', chown_cmd },
1744 #endif /* !HAVE_GNOME */
1745 { 'l', link_cmd },
1746 { XCTRL('l'), other_symlink_cmd },
1747 { 's', symlink_cmd },
1748 { XCTRL('s'), edit_symlink_cmd },
1749 { 'r', copy_current_readlink },
1750 { XCTRL('r'), copy_other_readlink },
1751 #endif /* !OS2_NT */
1752 #ifndef HAVE_GNOME
1753 { 'i', info_cmd_no_menu },
1754 { 'q', quick_cmd_no_menu },
1755 { 'h', add2hotlist_cmd },
1756 #endif /* !HAVE_GNOME */
1757 { '!', external_panelize },
1758 #if defined(WITH_BACKGROUND) && !defined(HAVE_GNOME)
1759 { 'j', jobs_cmd },
1760 #endif
1761 #ifdef HAVE_SETSOCKOPT
1762 { '%', source_routing },
1763 #endif
1764 { 0, 0 }
1767 static int ctl_x_map_enabled = 0;
1769 static void ctl_x_cmd (int ignore)
1771 ctl_x_map_enabled = 1;
1774 static void nothing ()
1778 static const key_map default_map [] = {
1779 #ifndef HAVE_GNOME
1780 { KEY_F(19), menu_last_selected_cmd },
1781 { KEY_F(20), (key_callback) quiet_quit_cmd },
1783 /* Copy useful information to the command line */
1784 { ALT('\n'), copy_prog_name },
1785 { ALT('\r'), copy_prog_name },
1786 { ALT('a'), copy_current_pathname },
1787 { ALT('A'), copy_other_pathname },
1789 { ALT('c'), quick_cd_cmd },
1791 /* To access the directory hotlist */
1792 { XCTRL('\\'), quick_chdir_cmd },
1794 /* Suspend */
1795 { XCTRL('z'), suspend_cmd },
1796 #endif
1797 /* The filtered view command */
1798 { ALT('!'), filtered_view_cmd_cpanel },
1800 /* Find file */
1801 { ALT('?'), find_cmd },
1803 /* Panel refresh */
1804 { XCTRL('r'), reread_cmd },
1806 { ALT('t'), toggle_listing_cmd },
1808 #ifndef HAVE_X
1809 /* Swap panels */
1810 { XCTRL('u'), swap_cmd },
1812 /* View output */
1813 { XCTRL('o'), view_other_cmd },
1814 #endif
1816 /* Control-X keybindings */
1817 { XCTRL('x'), ctl_x_cmd },
1819 /* Trap dlg's exit commands */
1820 { ESC_CHAR, nothing },
1821 { XCTRL('c'), nothing },
1822 { XCTRL('g'), nothing },
1823 { 0, 0 },
1826 #ifndef HAVE_X
1827 static void setup_sigwinch ()
1829 #if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
1830 !defined(OS2_NT) && defined(SIGWINCH)
1831 struct sigaction act, oact;
1832 act.sa_handler = flag_winch;
1833 sigemptyset (&act.sa_mask);
1834 act.sa_flags = 0;
1835 # ifdef SA_RESTART
1836 act.sa_flags |= SA_RESTART;
1837 # endif
1838 sigaction (SIGWINCH, &act, &oact);
1839 #endif
1842 static void
1843 setup_pre ()
1845 /* Call all the inits */
1846 #ifdef HAVE_CHARSET
1847 int full_eight_bits = (display_codepage != 0 && display_codepage != 1);
1848 #endif
1850 #ifndef HAVE_SLANG
1851 meta (stdscr, eight_bit_clean);
1852 #else
1853 SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160;
1854 #endif
1856 #else
1857 #define setup_pre()
1858 #define setup_sigwinch()
1859 #endif
1861 static void
1862 setup_post ()
1864 setup_sigwinch ();
1866 init_uid_gid_cache ();
1868 #ifndef HAVE_X
1869 if (baudrate () < 9600 || slow_terminal){
1870 verbose = 0;
1872 if (use_mouse_p)
1873 init_mouse ();
1874 #endif
1876 midnight_colors [0] = 0;
1877 midnight_colors [1] = REVERSE_COLOR; /* FOCUSC */
1878 midnight_colors [2] = INPUT_COLOR; /* HOT_NORMALC */
1879 midnight_colors [3] = NORMAL_COLOR; /* HOT_FOCUSC */
1882 static void setup_mc (void)
1884 setup_pre ();
1885 init_menu ();
1886 create_panels ();
1888 #ifdef HAVE_GNOME
1889 return;
1890 #endif
1891 setup_panels ();
1893 #ifdef HAVE_SUBSHELL_SUPPORT
1894 if (use_subshell)
1895 add_select_channel (subshell_pty, load_prompt, 0);
1896 #endif
1898 setup_post ();
1901 static void setup_dummy_mc (const char *file)
1903 char d[MC_MAXPATHLEN];
1905 mc_get_current_wd (d, MC_MAXPATHLEN);
1906 setup_mc ();
1907 mc_chdir (d);
1909 /* Create a fake current_panel, this is needed because the
1910 * expand_format routine will use current panel.
1912 strcpy (cpanel->cwd, d);
1913 cpanel->selected = 0;
1914 cpanel->count = 1;
1915 cpanel->dir.list[0].fname = (char *) file;
1918 static void done_mc ()
1920 done_menu ();
1922 /* Setup shutdown
1924 * We sync the profiles since the hotlist may have changed, while
1925 * we only change the setup data if we have the auto save feature set
1927 if (auto_save_setup)
1928 save_setup (); /* does also call save_hotlist */
1929 #ifndef HAVE_X
1930 else
1931 save_hotlist();
1932 #endif /* !HAVE_X */
1933 done_screen ();
1934 vfs_add_current_stamps ();
1935 #ifndef HAVE_X
1936 if (xterm_flag && xterm_hintbar)
1937 set_hintbar(_("Thank you for using GNU Midnight Commander"));
1938 #endif /* !HAVE_X */
1941 /* This should be called after destroy_dlg since panel widgets
1942 * save their state on the profiles
1944 static void done_mc_profile ()
1946 if (!auto_save_setup)
1947 profile_forget_profile (profile_name);
1948 sync_profiles ();
1949 done_setup ();
1950 free_profiles ();
1953 /* This routine only handles cpanel, and opanel, it is easy to
1954 * change to use npanels, just loop over the number of panels
1955 * and use get_panel_widget (i) and make the test done below
1957 static void
1958 make_panels_dirty ()
1960 if (cpanel->dirty)
1961 panel_update_contents (cpanel);
1963 if ((get_other_type () == view_listing) && opanel->dirty)
1964 panel_update_contents (opanel);
1967 /* In OS/2 and Windows NT people want to actually type the '\' key frequently */
1968 #ifdef OS2_NT
1969 # define check_key_backslash(x) 0
1970 #else
1971 # define check_key_backslash(x) ((x) == '\\')
1972 #endif
1975 midnight_callback (struct Dlg_head *h, int id, int msg)
1977 int i;
1979 switch (msg){
1980 /* Speed up routine: now, we just set the */
1981 case DLG_PRE_EVENT:
1982 make_panels_dirty ();
1983 return MSG_HANDLED;
1985 case DLG_KEY:
1986 if (ctl_x_map_enabled){
1987 ctl_x_map_enabled = 0;
1988 for (i = 0; ctl_x_map [i].key_code; i++)
1989 if (id == ctl_x_map [i].key_code){
1990 (*ctl_x_map [i].fn)(id);
1991 return MSG_HANDLED;
1995 #ifndef HAVE_X
1996 if (id == KEY_F(10) && !the_menubar->active){
1997 quit_cmd ();
1998 return MSG_HANDLED;
2001 if (id == '\t')
2002 free_completions (input_w (cmdline));
2004 /* On Linux, we can tell the difference */
2005 if (id == '\n' && ctrl_pressed ()){
2006 copy_prog_name ();
2007 return MSG_HANDLED;
2010 if (id == '\n' && input_w (cmdline)->buffer [0]){
2011 send_message_to (h, (Widget *) cmdline, WIDGET_KEY, id);
2012 return MSG_HANDLED;
2015 if ((!alternate_plus_minus || !(console_flag || xterm_flag)) &&
2016 !quote && !cpanel->searching) {
2017 if(!only_leading_plus_minus) {
2018 /* Special treatement, since the input line will eat them */
2019 if (id == '+' ) {
2020 select_cmd ();
2021 return MSG_HANDLED;
2024 if (check_key_backslash (id) || id == '-'){
2025 unselect_cmd ();
2026 return MSG_HANDLED;
2029 if (id == '*') {
2030 reverse_selection_cmd ();
2031 return MSG_HANDLED;
2033 } else if (command_prompt && !strlen (input_w (cmdline)->buffer)) {
2034 /* Special treatement '+', '-', '\', '*' only when this is
2035 * first char on input line
2038 if (id == '+') {
2039 select_cmd ();
2040 return MSG_HANDLED;
2043 if (check_key_backslash (id) || id == '-') {
2044 unselect_cmd ();
2045 return MSG_HANDLED;
2048 if (id == '*') {
2049 reverse_selection_cmd ();
2050 return MSG_HANDLED;
2054 break;
2055 #endif /* HAVE_X */
2057 case DLG_HOTKEY_HANDLED:
2058 if (get_current_type () == view_listing)
2059 cpanel->searching = 0;
2060 break;
2062 case DLG_UNHANDLED_KEY:
2063 if (command_prompt){
2064 int v;
2066 v = send_message_to (h, (Widget *) cmdline, WIDGET_KEY, id);
2067 if (v)
2068 return v;
2070 if (ctl_x_map_enabled){
2071 ctl_x_map_enabled = 0;
2072 for (i = 0; ctl_x_map [i].key_code; i++)
2073 if (id == ctl_x_map [i].key_code){
2074 (*ctl_x_map [i].fn)(id);
2075 return MSG_HANDLED;
2077 } else {
2078 for (i = 0; default_map [i].key_code; i++){
2079 if (id == default_map [i].key_code){
2080 (*default_map [i].fn)(id);
2081 return MSG_HANDLED;
2085 return MSG_NOT_HANDLED;
2087 #ifndef HAVE_X
2088 /* We handle the special case of the output lines */
2089 case DLG_DRAW:
2090 attrset (SELECTED_COLOR);
2091 if (console_flag && output_lines)
2092 show_console_contents (output_start_y,
2093 LINES-output_lines-keybar_visible-1,
2094 LINES-keybar_visible-1);
2095 break;
2096 #endif
2099 return default_dlg_callback (h, id, msg);
2102 #ifdef HAVE_X
2103 /* This should be rewritten in order to support as many panel containers as
2104 the user wants */
2106 #ifndef HAVE_GNOME
2107 widget_data containers [2];
2108 int containers_no = 2;
2110 void
2111 xtoolkit_panel_setup ()
2113 containers [0] = x_create_panel_container (0);
2114 containers [1] = x_create_panel_container (1);
2115 input_w (cmdline)->widget.wcontainer = containers [0];
2116 input_w (cmdline)->widget.area = AREA_BOTTOM;
2117 the_prompt->widget.wcontainer = containers [0];
2118 the_prompt->widget.area = AREA_BOTTOM;
2119 the_bar->widget.wcontainer = containers [0];
2120 the_bar->widget.area = AREA_TOP;
2121 get_panel_widget (0)->wcontainer = containers [0];
2122 get_panel_widget (0)->area = AREA_RIGHT;
2123 get_panel_widget (1)->wcontainer = containers [1];
2124 get_panel_widget (1)->area = AREA_RIGHT;
2125 the_menubar->widget.wcontainer = (widget_data) NULL;
2127 #else
2128 # define xtoolkit_panel_setup()
2129 #endif
2131 #else
2132 # define xtoolkit_panel_setup()
2133 #endif
2135 #ifndef PORT_HAS_LOAD_HINT
2136 void load_hint ()
2138 char *hint;
2140 if (!the_hint->widget.parent)
2141 return;
2143 if (!message_visible && (!xterm_flag || !xterm_hintbar)){
2144 label_set_text (the_hint, 0);
2145 return;
2148 if ((hint = get_random_hint ())){
2149 if (*hint)
2150 set_hintbar (hint);
2151 g_free (hint);
2152 } else {
2153 set_hintbar ("The Midnight Commander " VERSION
2154 " (C) 1995-1997 the Free Software Foundation");
2157 #endif
2159 #ifndef HAVE_GNOME
2160 static void
2161 setup_panels_and_run_mc ()
2163 int first, second;
2165 xtoolkit_panel_setup ();
2166 add_widget (midnight_dlg, the_hint);
2167 load_hint ();
2168 add_widget (midnight_dlg, cmdline);
2169 add_widget (midnight_dlg, the_prompt);
2170 add_widget (midnight_dlg, the_bar);
2172 if (boot_current_is_left){
2173 first = 1;
2174 second = 0;
2175 } else {
2176 first = 0;
2177 second = 1;
2179 add_widget (midnight_dlg, get_panel_widget (first));
2180 add_widget (midnight_dlg, get_panel_widget (second));
2181 add_widget (midnight_dlg, the_menubar);
2183 init_labels (get_panel_widget (0));
2184 init_labels (get_panel_widget (1));
2186 /* Run the Midnight Commander if no file was specified in the command line */
2187 run_dlg (midnight_dlg);
2189 #endif /* !HAVE_GNOME */
2191 /* result must be free'd (I think this should go in util.c) */
2192 static char *
2193 prepend_cwd_on_local (char *filename)
2195 char *d;
2196 int l;
2198 if (vfs_file_is_local (filename)){
2199 if (*filename == PATH_SEP) /* an absolute pathname */
2200 return g_strdup (filename);
2201 d = g_malloc (MC_MAXPATHLEN + strlen (filename) + 2);
2202 mc_get_current_wd (d, MC_MAXPATHLEN);
2203 l = strlen(d);
2204 d[l++] = PATH_SEP;
2205 strcpy (d + l, filename);
2206 return canonicalize_pathname (d);
2207 } else
2208 return g_strdup (filename);
2211 #ifdef USE_INTERNAL_EDIT
2213 static int
2214 mc_maybe_editor_or_viewer (void)
2216 char *path;
2218 if (!(view_one_file || edit_one_file))
2219 return 0;
2221 /* Invoke the internal view/edit routine with:
2222 * the default processing and forcing the internal viewer/editor
2224 if (view_one_file) {
2225 path = prepend_cwd_on_local (view_one_file);
2226 setup_dummy_mc (path);
2227 view_file (path, 0, 1);
2229 else {
2230 path = prepend_cwd_on_local ("");
2231 #ifndef HAVE_GNOME
2232 setup_dummy_mc (path);
2233 #endif
2234 edit (edit_one_file, edit_one_file_start_line);
2235 #ifdef HAVE_GNOME
2236 gtk_main ();
2237 exit (1);
2238 #endif
2240 g_free (path);
2241 midnight_shutdown = 1;
2242 done_mc ();
2243 return 1;
2246 #endif /* USE_INTERNAL_EDIT */
2248 static void
2249 do_nc (void)
2251 midnight_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors, midnight_callback, "[main]", "midnight", 0);
2252 midnight_dlg->has_menubar = 1;
2254 #ifdef USE_INTERNAL_EDIT
2255 /* Check if we were invoked as an editor or file viewer */
2256 if (mc_maybe_editor_or_viewer ())
2257 return;
2258 #endif
2260 setup_mc ();
2262 #ifndef HAVE_GNOME
2263 setup_panels_and_run_mc ();
2264 #endif
2266 /* Program end */
2267 midnight_shutdown = 1;
2269 /* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
2270 if (print_last_wd) {
2271 if (!vfs_current_is_local ())
2272 last_wd_string = g_strdup (".");
2273 else
2274 last_wd_string = g_strdup (cpanel->cwd);
2276 done_mc ();
2278 #ifndef HAVE_GNOME
2279 destroy_dlg (midnight_dlg);
2280 current_panel = 0;
2281 #endif
2282 done_mc_profile ();
2285 #if defined (_OS_NT)
2286 /* Windows NT code */
2287 #define CONTROL_FILE "\\mc.%d.control"
2288 char control_file [sizeof (CONTROL_FILE) + 8];
2290 void
2291 OS_Setup ()
2293 SetConsoleTitle ("GNU Midnight Commander");
2295 shell = getenv ("COMSPEC");
2296 if (!shell || !*shell)
2297 shell = get_default_shell ();
2299 /* Default opening mode for files is binary, not text (CR/LF translation) */
2300 #ifndef __EMX__
2301 _fmode = O_BINARY;
2302 #endif
2304 mc_home = get_mc_lib_dir ();
2307 static void
2308 sigchld_handler_no_subshell (int sig)
2312 void
2313 init_sigchld (void)
2317 void
2318 init_sigfatals (void)
2320 /* Nothing to be done on the OS/2, Windows/NT */
2324 #elif defined (__os2__)
2325 /* OS/2 Version */
2326 # define CONTROL_FILE "\\mc.%d.control"
2327 char control_file [sizeof (CONTROL_FILE) + 8];
2329 void
2330 OS_Setup (void)
2332 /* .ado: This does not work: */
2333 /* DosSMSetTitle ((PSZ) "This is my app"); */
2334 /* In DEF: IMPORTS
2335 DosSMSetTitle = SESMGR.DOSSMSETTITLE */
2336 shell = getenv ("COMSPEC");
2337 if (!shell || !*shell)
2338 shell = get_default_shell ();
2340 mc_home = get_mc_lib_dir ();
2343 static void
2344 sigchld_handler_no_subshell (int sig)
2348 void
2349 init_sigchld (void)
2353 void
2354 init_sigfatals (void)
2356 /* Nothing to be done on the OS/2, Windows/NT */
2358 #else
2360 /* Unix version */
2361 #define CONTROL_FILE "/tmp/mc.%d.control"
2362 char control_file [sizeof (CONTROL_FILE) + 8];
2364 static void
2365 OS_Setup ()
2367 char *mc_libdir;
2368 #ifndef HAVE_X
2369 char *termvalue;
2371 termvalue = getenv ("TERM");
2372 if (!termvalue || !(*termvalue)){
2373 fprintf (stderr, _("The TERM environment variable is unset!\n"));
2374 exit (1);
2376 if (force_xterm || (strncmp (termvalue, "xterm", 5) == 0 || strcmp (termvalue, "dtterm") == 0)){
2377 use_mouse_p = XTERM_MOUSE;
2378 xterm_flag = 1;
2379 # ifdef SET_TITLE
2380 printf ("\33]0;GNU Midnight Commander\7");
2381 # endif
2383 #endif /* ! HAVE_X */
2384 shell = getenv ("SHELL");
2385 if (!shell || !*shell)
2386 shell = g_strdup (getpwuid (geteuid ())->pw_shell);
2387 if (!shell || !*shell)
2388 shell = "/bin/sh";
2390 g_snprintf (control_file, sizeof (control_file), CONTROL_FILE, getpid ());
2391 my_putenv ("MC_CONTROL_FILE", control_file);
2393 /* This is the directory, where MC was installed, on Unix this is LIBDIR */
2394 /* and can be overriden by the MC_LIBDIR environment variable */
2395 if ((mc_libdir = getenv ("MC_LIBDIR")) != NULL) {
2396 mc_home = g_strdup (mc_libdir);
2397 } else {
2398 mc_home = g_strdup (LIBDIR);
2402 static void
2403 sigchld_handler_no_subshell (int sig)
2405 #ifndef HAVE_X
2406 int pid, status;
2408 if (!console_flag)
2409 return;
2411 /* COMMENT: if it were true that after the call to handle_console(..INIT)
2412 the value of console_flag never changed, we could simply not install
2413 this handler at all if (!console_flag && !use_subshell). */
2415 /* That comment is no longer true. We need to wait() on a sigchld
2416 handler (that's at least what the tarfs code expects currently). */
2418 #ifndef SCO_FLAVOR
2419 pid = waitpid (cons_saver_pid, &status, WUNTRACED | WNOHANG);
2421 if (pid == cons_saver_pid){
2422 /* {{{ Someone has stopped or killed cons.saver; restart it */
2424 # ifdef SIGTSTP
2425 if (WIFSTOPPED (status))
2426 kill (pid, SIGCONT);
2427 else
2428 # endif
2430 handle_console (CONSOLE_DONE);
2431 handle_console (CONSOLE_INIT);
2433 /* }}} */
2435 #endif /* ! SCO_FLAVOR */
2437 /* If we get here, some other child exited; ignore it */
2438 #endif /* ! HAVE_X */
2441 void
2442 init_sigchld (void)
2444 struct sigaction sigchld_action;
2446 sigchld_action.sa_handler =
2447 #ifdef HAVE_SUBSHELL_SUPPORT
2448 use_subshell ? sigchld_handler :
2449 #endif
2450 sigchld_handler_no_subshell;
2452 sigemptyset (&sigchld_action.sa_mask);
2454 #ifdef SA_RESTART
2455 sigchld_action.sa_flags = SA_RESTART;
2456 #else
2457 sigchld_action.sa_flags = 0;
2458 #endif
2460 sigaction (SIGCHLD, &sigchld_action, NULL);
2463 #endif /* _OS_NT, __os2__, UNIX */
2465 #ifndef HAVE_X
2466 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2467 extern int SLtt_Try_Termcap;
2468 #endif
2469 #endif
2471 #ifndef HAVE_X
2472 static void
2473 print_mc_usage (void)
2475 const char * const * ptr;
2476 const char * const usage [] = {
2478 N_("Usage is:\n\n"
2479 "mc [flags] [this_dir] [other_panel_dir]\n\n"),
2480 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2481 N_("-a, --stickchars Force use of +, -, | for line drawing.\n"),
2482 #endif
2483 N_("-b, --nocolor Force black and white display.\n"),
2484 #ifdef WITH_BACKGROUND
2485 N_("-B, --background [DEVEL-ONLY: Debug the background code]\n"),
2486 #endif
2487 N_("-c, --color Force color mode.\n"
2488 "-C, --colors Specify colors (use --help-colors to get a list).\n"
2489 "-d, --nomouse Disable mouse support.\n"),
2490 #ifdef USE_INTERNAL_EDIT
2491 N_("-e, --edit Startup the internal editor.\n"),
2492 #endif
2493 N_("-f, --libdir Print configured paths.\n"
2494 "-h, --help Shows this help message.\n"
2495 "-k, --resetsoft Reset softkeys (HP terminals only) to their terminfo/termcap\n"
2496 " default.\n"),
2497 #ifdef USE_NETCODE
2498 N_("-l, --ftplog file Log ftpfs commands to the file.\n"),
2499 #endif
2500 #ifdef HAVE_MAD
2501 N_("-M, --memory file [DEVEL-ONLY: Log MAD messages to the file.]\n"),
2502 #endif
2503 N_("-P, --printwd At exit, print the last working directory.\n"
2504 "-s, --slow Disables verbose operation (for slow terminals).\n"),
2505 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2506 N_("-t, --termcap Activate support for the TERMCAP variable.\n"),
2507 #endif
2508 #if defined(HAVE_SLANG) && defined(OS2_NT)
2509 N_("-S, --createcmdile Create command file to set default directory upon exit.\n"),
2510 #endif
2511 #ifdef HAVE_SUBSHELL_SUPPORT
2512 N_("-u, --nosubshell Disable the concurrent subshell mode.\n"
2513 "-U, --subshell Force the concurrent subshell mode.\n"
2514 "-r, --forceexec Force subshell execution.\n"),
2515 #endif
2516 N_("-v, --view fname Start up into the viewer mode.\n"
2517 "-V, --version Report version and configuration options.\n"
2518 "-x, --xterm Force xterm mouse support and screen save/restore.\n"
2519 "+number number it is the start line number of file for `mcedit'.\n"),
2520 #ifdef HAVE_SUBSHELL_SUPPORT
2521 N_("-X, --dbgsubshell [DEVEL-ONLY: Debug the subshell].\n"),
2522 #endif
2523 N_("\n"
2524 "Please send any bug reports (including the output of `mc -V')\n"
2525 "to mc-devel@gnome.org\n"),
2526 NULL
2529 version (0);
2531 for (ptr = usage; *ptr; ptr++)
2532 fprintf (stderr, _(*ptr));
2535 static void
2536 print_color_usage (void)
2538 fprintf (stderr, _(
2539 "--colors KEYWORD={FORE},{BACK}\n\n"
2540 "{FORE} and {BACK} can be ommited, and the default will be used\n"
2541 "\n"
2542 "Keywords:\n"
2543 " Global: errors, reverse, gauge, input\n"
2544 " File display: normal, selected, marked, markselect\n"
2545 " Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
2546 " Menus: menu, menuhot, menusel, menuhotsel\n"
2547 " Help: helpnormal, helpitalic, helplink, helpslink\n"
2548 " File types: directory, execute, link, device, special, core\n"
2549 "\n"
2550 "Colors:\n"
2551 " black, gray, red, brightred, green, brightgreen, brown,\n"
2552 " yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
2553 " brightcyan, lightgray and white\n\n"));
2555 #endif /* !HAVE_X */
2557 static void
2558 probably_finish_program (void)
2560 if (finish_program){
2561 if (print_last_wd)
2562 printf (".");
2563 exit (1);
2567 enum {
2568 GEOMETRY_KEY = -1,
2569 NOWIN_KEY = -2
2572 static void
2573 process_args (int c, const char *option_arg)
2575 switch (c) {
2576 #ifndef HAVE_X
2577 case 'V':
2578 version (1);
2579 finish_program = 1;
2580 break;
2582 case 'c':
2583 disable_colors = 0;
2584 #ifdef HAVE_SLANG
2585 force_colors = 1;
2586 #endif
2587 break;
2588 #endif /* !HAVE_X */
2590 case 'f':
2591 fprintf (stderr, _("Library directory for the Midnight Commander: %s\n"), mc_home);
2592 finish_program = 1;
2593 break;
2595 #ifdef USE_NETCODE
2596 case 'l':
2597 ftpfs_set_debug (option_arg);
2598 #ifdef WITH_SMBFS
2599 /* smbfs_set_debug (option_arg); */
2600 #endif
2601 break;
2602 #endif
2604 case 'm':
2605 fprintf (stderr, _("Option -m is obsolete. Please look at Display Bits... in the Option's menu\n"));
2606 finish_program = 1;
2607 break;
2609 #ifdef HAVE_MAD
2610 case 'M':
2611 mad_set_debug (option_arg);
2612 break;
2613 #endif
2615 #ifdef OS2_NT
2616 case 'S':
2617 print_last_wd = 2;
2618 batch_file_name = option_arg;
2619 break;
2620 #endif
2622 case 'd':
2623 use_mouse_p = NO_MOUSE;
2624 break;
2626 #ifdef HAVE_SUBSHELL_SUPPORT
2627 case 'X':
2628 debug_subshell = 1;
2629 break;
2631 case 'U':
2632 use_subshell = 1;
2633 break;
2635 case 'u':
2636 use_subshell = 0;
2637 break;
2639 case 'r':
2640 force_subshell_execution = 1;
2641 break;
2642 #endif /* HAVE_SUBSHELL_SUPPORT */
2644 #ifndef HAVE_X
2645 case 'H':
2646 print_color_usage ();
2647 finish_program = 1;
2648 break;
2650 case 'h':
2651 print_mc_usage ();
2652 finish_program = 1;
2653 #endif
2657 #ifdef HAVE_GNOME
2658 static void parse_an_arg (poptContext state,
2659 enum poptCallbackReason reason,
2660 const struct poptOption *opt,
2661 const char *arg, void *data)
2663 process_args (opt->shortName, arg);
2666 #endif
2668 char *cmdline_geometry = NULL;
2670 static const struct poptOption argument_table [] = {
2671 #ifdef HAVE_GNOME
2672 { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0},
2673 #endif
2674 #ifdef WITH_BACKGROUND
2675 { "background", 'B', POPT_ARG_NONE, &background_wait, 0,
2676 N_("Use to debug the background code") },
2677 #endif
2678 #if defined(HAVE_SLANG) && defined(OS2_NT)
2679 { "createcmdfile", 'S', POPT_ARG_STRING, NULL, 'S' },
2680 #endif
2681 { "color", 'c', POPT_ARG_NONE, NULL, 'c',
2682 N_("Request to run in color mode") },
2683 { "colors", 'C', POPT_ARG_STRING, &command_line_colors, 0,
2684 N_("Specifies a color configuration") },
2685 #ifdef HAVE_SUBSHELL_SUPPORT
2686 { "dbgsubshell", 'X', POPT_ARG_NONE, &debug_subshell, 0 },
2687 #endif
2688 { "edit", 'e', POPT_ARG_STRING, &edit_one_file, 0,
2689 N_("Edits one file") },
2691 #ifndef HAVE_GNOME
2692 { "help", 'h', POPT_ARG_NONE, NULL, 'h',
2693 N_("Displays this help message") },
2694 #endif
2695 { "help-colors", 'H', POPT_ARG_NONE, NULL, 'H',
2696 N_("Displays a help screen on how to change the color scheme") },
2697 #ifdef USE_NETCODE
2698 { "ftplog", 'l', POPT_ARG_STRING, NULL, 'l',
2699 N_("Log ftp dialog to specified file") },
2700 #endif
2701 #ifdef HAVE_MAD
2702 { "memory", 'M', POPT_ARG_STRING, NULL, 'M', },
2703 #endif
2704 { "libdir", 'f', POPT_ARG_NONE, NULL, 'f' },
2705 { NULL, 'm', POPT_ARG_NONE, NULL, 'm',
2706 N_("Obsolete") },
2707 { "nocolor", 'b', POPT_ARG_NONE, &disable_colors, 0,
2708 N_("Requests to run in black and white") },
2709 { "nomouse", 'd', POPT_ARG_NONE, NULL, 'd',
2710 N_("Disable mouse support in text version") },
2711 #ifdef HAVE_SUBSHELL_SUPPORT
2712 { "nosubshell", 'u', POPT_ARG_NONE, NULL, 'u',
2713 N_("Disables subshell support") },
2714 { "forceexec", 'r', POPT_ARG_NONE, NULL, 'r' },
2715 #endif
2716 { "printwd", 'P', POPT_ARG_NONE, &print_last_wd, 0,
2717 N_("Prints working directory at program exit") },
2718 { "resetsoft", 'k', POPT_ARG_NONE, &reset_hp_softkeys, 0,
2719 N_("Resets soft keys on HP terminals") },
2720 { "slow", 's', POPT_ARG_NONE, &slow_terminal, 0,
2721 N_("To run on slow terminals") },
2722 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2723 { "stickchars", 'a', 0, &force_ugly_line_drawing, 0,
2724 N_("Use stickchars to draw") },
2725 #endif
2726 #ifdef HAVE_SUBSHELL_SUPPORT
2727 { "subshell", 'U', POPT_ARG_NONE, NULL, 'U',
2728 N_("Enables subshell support (default)")},
2729 #endif
2730 #if !defined(HAVE_X)
2731 #if defined(HAVE_SLANG) && !defined(OS2_NT)
2732 { "termcap", 't', 0, &SLtt_Try_Termcap, 0,
2733 N_("Tries to use termcap instead of terminfo") },
2734 #endif
2735 #endif
2736 { "version", 'V', POPT_ARG_NONE, NULL, 'V',
2737 N_("Displays the current version") },
2738 { "view", 'v', POPT_ARG_STRING, &view_one_file, 0,
2739 N_("Launches the file viewer on a file") },
2740 { "xterm", 'x', POPT_ARG_NONE, &force_xterm, 0,
2741 N_("Forces xterm features") },
2742 #ifdef HAVE_GNOME
2743 { "geometry", '\0', POPT_ARG_STRING, &cmdline_geometry, 0, N_("Geometry for the window"), N_("GEOMETRY")},
2744 {"nowindows", '\0', POPT_ARG_NONE, &nowindows, 0, N_("No windows opened at startup"), NULL},
2745 {"nodesktop", '\0', POPT_ARG_NONE, &nodesktop, 0, N_("No desktop icons"), NULL},
2746 {"twopanel", '\0', POPT_ARG_NONE, &twopanel, 0, N_("Look more like traditional gmc"), NULL},
2747 {"desktop-linksdir", '\0', POPT_ARG_NONE, &display_linksdir, 0,
2748 N_("Display the directory that holds the .links startup files and exit")},
2749 #endif
2751 { NULL, 0, 0, NULL, 0 }
2754 #if defined(HAVE_CORBA) || defined(HAVE_GNOME)
2755 /* Convenience function to display the desktop initialization directory and exit */
2756 static void
2757 maybe_display_linksdir (void)
2759 if (display_linksdir) {
2760 puts (DESKTOP_INIT_DIR);
2761 exit (1);
2764 #endif
2766 #ifdef HAVE_CORBA
2767 /* Initializes the ORB and does the initial argument processing */
2768 static void
2769 init_corba_with_args (int *argc, char **argv, poptContext *ctx)
2771 CORBA_Environment ev;
2773 CORBA_exception_init (&ev);
2774 orb = gnome_CORBA_init_with_popt_table ("gmc", VERSION, argc, argv, argument_table, 0, ctx,
2775 GNORBA_INIT_SERVER_FUNC, &ev);
2777 maybe_display_linksdir ();
2779 if (ev._major != CORBA_NO_EXCEPTION) {
2780 CORBA_exception_free (&ev);
2781 g_warning ("Could not initialize CORBA");
2782 exit (1);
2785 CORBA_exception_free (&ev);
2787 if (!corba_init_server ()) {
2788 g_warning ("Could not initialize the CORBA server");
2789 exit (1);
2792 #endif
2794 #ifndef HAVE_CORBA
2795 void
2796 corba_activate_server (void)
2798 /* nothing */
2801 void
2802 corba_create_window (char *startup_dir)
2804 /* nothing */
2806 #endif
2808 static void
2809 handle_args (int argc, char *argv [])
2811 char *tmp;
2812 poptContext ctx;
2813 #ifndef HAVE_GNOME
2814 char *option_arg, *base;
2815 int c;
2816 #endif /* !HAVE_GNOME */
2818 #ifdef HAVE_GNOME
2819 /* special case, handle --desktop-linksdir without initing X */
2820 if (argc > 1){
2821 if (strcmp (argv [1], "--desktop-linksdir") == 0){
2822 puts (DESKTOP_INIT_DIR);
2823 exit (1);
2826 #ifdef HAVE_CORBA
2827 init_corba_with_args (&argc, argv, &ctx);
2828 #else
2829 gnome_init_with_popt_table ("gmc", VERSION, argc, argv, argument_table, 0, &ctx);
2830 maybe_display_linksdir ();
2831 #endif
2833 #ifdef HAVE_GNOME_WINDOW_ICON
2834 gnome_window_icon_set_default_from_file (ICONDIR"/i-directory.png");
2835 #endif
2836 gtk_widget_push_visual (gdk_imlib_get_visual ());
2837 gtk_widget_push_colormap (gdk_imlib_get_colormap ());
2839 /* poptResetContext (ctx); */
2840 #else
2841 ctx = poptGetContext ("mc", argc, argv, argument_table, 0);
2842 #endif
2844 #ifndef HAVE_X
2845 #ifdef USE_TERMCAP
2846 SLtt_Try_Termcap = 1;
2847 #endif
2848 #endif
2850 #ifndef HAVE_GNOME
2851 while ((c = poptGetNextOpt (ctx)) > 0){
2852 option_arg = poptGetOptArg (ctx);
2854 process_args (c, option_arg);
2857 if (c < -1){
2858 print_mc_usage ();
2859 fprintf(stderr, "%s: %s\n",
2860 poptBadOption (ctx, POPT_BADOPTION_NOALIAS),
2861 poptStrerror (c));
2862 finish_program = 1;
2864 probably_finish_program ();
2865 #endif /* !HAVE_GNOME */
2867 tmp = poptGetArg (ctx);
2869 #ifndef HAVE_GNOME
2871 * Check for special invocation names mcedit and mcview,
2872 * if none apply then set the current directory and the other
2873 * directory from the command line arguments
2875 base = x_basename (argv[0]);
2876 if (!STRNCOMP (base, "mce", 3) || !STRCOMP(base, "vi")) {
2877 edit_one_file = "";
2878 edit_one_file_start_line = 1;
2879 if (tmp) {
2880 if (*tmp == '+' && isdigit (tmp[1])){
2881 int start_line = atoi (tmp);
2882 if (start_line > 0) {
2883 char *file = poptGetArg (ctx);
2884 if (file) {
2885 tmp = file;
2886 edit_one_file_start_line = start_line;
2890 edit_one_file = g_strdup (tmp);
2892 } else
2893 if (!STRNCOMP (base, "mcv", 3) || !STRCOMP(base, "view")) {
2894 if (tmp)
2895 view_one_file = g_strdup (tmp);
2896 else {
2897 fprintf (stderr, "No arguments given to the viewer\n");
2898 finish_program = 1;
2899 probably_finish_program ();
2901 } else
2902 #endif /* !HAVE_GNOME */
2904 /* sets the current dir and the other dir */
2905 if (tmp) {
2906 char buffer[MC_MAXPATHLEN + 2];
2907 this_dir = g_strdup (tmp);
2908 mc_get_current_wd (buffer, sizeof (buffer) - 2);
2909 if ((tmp = poptGetArg (ctx)))
2910 other_dir = g_strdup (tmp);
2914 poptFreeContext (ctx);
2918 * The compatibility_move_mc_files routine is intended to
2919 * move all of the hidden .mc files into a private ~/.mc
2920 * directory in the home directory, to avoid cluttering the users.
2922 * Previous versions of the program had all of their files in
2923 * the $HOME, we are now putting them in $HOME/.mc
2925 #ifdef OS2_NT
2926 # define compatibility_move_mc_files()
2927 #else
2929 static int
2930 do_mc_filename_rename (char *mc_dir, char *o_name, char *n_name)
2932 char *full_o_name = concat_dir_and_file (home_dir, o_name);
2933 char *full_n_name = g_strconcat (home_dir, MC_BASE, n_name, NULL);
2934 int move;
2936 move = 0 == rename (full_o_name, full_n_name);
2937 g_free (full_o_name);
2938 g_free (full_n_name);
2939 return move;
2942 static void
2943 do_compatibility_move (char *mc_dir)
2945 struct stat s;
2946 int move;
2948 if (stat (mc_dir, &s) == 0)
2949 return;
2950 if (errno != ENOENT)
2951 return;
2953 if (mkdir (mc_dir, 0777) == -1)
2954 return;
2956 move = do_mc_filename_rename (mc_dir, ".mc.ini", "ini");
2957 move += do_mc_filename_rename (mc_dir, ".mc.hot", "hotlist");
2958 move += do_mc_filename_rename (mc_dir, ".mc.ext", "ext");
2959 move += do_mc_filename_rename (mc_dir, ".mc.menu", "menu");
2960 move += do_mc_filename_rename (mc_dir, ".mc.bashrc", "bashrc");
2961 move += do_mc_filename_rename (mc_dir, ".mc.inputrc", "inputrc");
2962 move += do_mc_filename_rename (mc_dir, ".mc.tcshrc", "tcshrc");
2963 move += do_mc_filename_rename (mc_dir, ".mc.tree", "tree");
2965 if (!move)
2966 return;
2968 show_change_notice = 1;
2971 static void
2972 compatibility_move_mc_files (void)
2974 char *mc_dir = concat_dir_and_file (home_dir, ".mc");
2976 do_compatibility_move (mc_dir);
2977 g_free (mc_dir);
2979 #endif /* OS2_NT */
2982 main (int argc, char *argv [])
2984 /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
2985 setlocale (LC_ALL, "");
2986 bindtextdomain ("mc", LOCALEDIR);
2987 textdomain ("mc");
2988 mad_init ();
2989 #if 0
2990 /* This is here to debug startup stuff */
2992 volatile int i = 0;
2994 printf ("GMC IS WAITING %d\n", getpid ());
2995 while (!i)
2999 #endif
3000 /* Initialize list of all user group for timur_clr_mode */
3001 init_groups ();
3003 OS_Setup ();
3005 /* This variable is used by the subshell */
3006 home_dir = getenv ("HOME");
3007 if (!home_dir) {
3008 /* mc_home was computed by OS_Setup */
3009 home_dir = mc_home;
3012 vfs_init ();
3014 #ifdef HAVE_X
3015 /* NOTE: This call has to be before any our argument handling :) */
3017 #ifdef HAVE_GNOME
3019 char *base = x_basename (argv [0]);
3021 if (base){
3022 if (strcmp (base, "mcedit") == 0)
3023 edit_one_file = "";
3024 else
3025 if (strcmp (base, "mcview") == 0)
3026 view_one_file = "";
3030 handle_args(argc, argv);
3032 tree_store_load ();
3034 session_init ();
3035 probably_finish_program ();
3036 #endif
3038 if (xtoolkit_init (&argc, argv) == -1)
3039 exit (1);
3040 #endif /* HAVE_X */
3043 #ifndef HAVE_X
3044 #ifdef HAVE_SLANG
3045 SLtt_Ignore_Beep = 1;
3046 #endif
3048 /* NOTE: This has to be called before slang_init or whatever routine
3049 calls any define_sequence */
3050 init_key ();
3052 handle_args (argc, argv);
3053 #endif /* HAVE_X */
3055 /* Used to report the last working directory at program end */
3056 if (print_last_wd){
3057 #ifndef OS2_NT
3058 stdout_fd = dup (1);
3059 close (1);
3060 if (open (ttyname (0), O_RDWR) < 0)
3061 if (open ("/dev/tty", O_RDWR) < 0) {
3062 /* Try if stderr is not redirected as the last chance */
3063 char *p = g_strdup (ttyname (0));
3065 if (!strcmp (p, ttyname (2)))
3066 dup2 (2, 1);
3067 else {
3068 fprintf (stderr,
3069 _("Couldn't open tty line. You have to run mc without the -P flag.\n"
3070 "On some systems you may want to run # `which mc`\n"));
3071 exit (1);
3073 g_free (p);
3075 #endif
3078 # ifdef HAVE_X
3079 /* This is to avoid subshell trying to restard any child pid
3080 * that happends to have cons_saver_pid (a random startup value).
3081 * and PID 1 is init, unlikely we could be the parent of it.
3083 /* cons_saver_pid = 1; */
3084 # else
3085 /* Must be done before installing the SIGCHLD handler [[FIXME]] */
3086 handle_console (CONSOLE_INIT);
3087 # endif
3089 # ifdef HAVE_SUBSHELL_SUPPORT
3090 subshell_get_console_attributes ();
3091 # endif
3093 /* Install the SIGCHLD handler; must be done before init_subshell() */
3094 init_sigchld ();
3096 compatibility_move_mc_files ();
3098 #ifdef HAVE_X
3099 /* We need this, since ncurses endwin () doesn't restore the signals */
3100 /* Very strange comment given that ifdef HAVE_X stands here since
3101 revision 1.1 - Pavel Roskin */
3102 save_stop_handler ();
3104 #else /* !HAVE_X */
3106 /* Must be done before init_subshell, to set up the terminal size: */
3107 /* FIXME: Should be removed and LINES and COLS computed on subshell */
3108 #ifdef HAVE_SLANG
3109 slang_init ();
3110 #endif
3111 /* NOTE: This call has to be after slang_init. It's the small part from
3112 the previous init_key which had to be moved after the call of slang_init */
3113 init_key_input_fd ();
3114 #endif /* !HAVE_X */
3116 load_setup ();
3118 #ifdef HAVE_GNOME
3119 init_colors ();
3120 #else
3121 init_curses ();
3122 #endif
3124 #ifdef HAVE_SUBSHELL_SUPPORT
3126 /* Don't use subshell in GNOME and when invoked as a viewer or editor */
3127 #ifndef HAVE_GNOME
3128 if (edit_one_file || view_one_file)
3129 #endif /* !HAVE_GNOME */
3130 use_subshell = 0;
3132 /* Done here to ensure that the subshell doesn't */
3133 /* inherit the file descriptors opened below, etc */
3134 if (use_subshell)
3135 init_subshell ();
3137 #endif /* HAVE_SUBSHELL_SUPPORT */
3139 #ifndef HAVE_X
3140 /* Removing this from the X code let's us type C-c */
3141 load_key_defs ();
3143 /* Also done after init_subshell, to save any shell init file messages */
3144 if (console_flag)
3145 handle_console (CONSOLE_SAVE);
3147 if (alternate_plus_minus)
3148 application_keypad_mode ();
3149 #endif /* !HAVE_X */
3151 #ifdef HAVE_GNOME
3152 gnome_check_super_user ();
3153 #endif
3155 if (show_change_notice){
3156 message (1, _(" Notice "),
3157 _(" The Midnight Commander configuration files \n"
3158 " are now stored in the ~/.mc directory, the \n"
3159 " files have been moved now\n"));
3162 # ifdef HAVE_SUBSHELL_SUPPORT
3163 if (use_subshell){
3164 prompt = strip_ctrl_codes (subshell_prompt);
3165 if (!prompt)
3166 prompt = "";
3167 } else
3168 # endif
3169 prompt = (geteuid () == 0) ? "# " : "$ ";
3171 /* Program main loop */
3172 do_nc ();
3174 /* Save the tree store */
3175 tree_store_save ();
3177 /* Virtual File System shutdown */
3178 vfs_shut ();
3180 /* Delete list of all user groups*/
3181 delete_groups ();
3183 flush_extension_file (); /* does only free memory */
3185 # ifndef HAVE_X
3186 /* Miguel, maybe the fix in slang is not required and
3187 * it could be done by removing the slang_done_screen.
3188 * Do I need to call slang_reset_tty then?
3190 endwin ();
3191 slang_shutdown ();
3193 if (console_flag && !(quit & SUBSHELL_EXIT))
3194 restore_console ();
3195 if (alternate_plus_minus)
3196 numeric_keypad_mode ();
3197 # endif
3199 #ifndef OS2_NT
3200 signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */
3201 #endif
3203 # ifndef HAVE_X
3204 if (console_flag)
3205 handle_console (CONSOLE_DONE);
3206 putchar ('\n'); /* Hack to make shell's prompt start at left of screen */
3207 # endif
3209 #ifdef _OS_NT
3210 /* On NT, home_dir is malloced */
3211 g_free (home_dir);
3212 #endif
3213 #if defined(OS2_NT)
3214 if (print_last_wd == 2){
3215 FILE *bat_file;
3217 print_last_wd = 0;
3218 bat_file = fopen(batch_file_name, "w");
3219 if (bat_file != NULL){
3220 /* .ado: \r\n for Win95 */
3221 fprintf(bat_file, "@echo off\r\n");
3222 if (isalpha(last_wd_string[0]))
3223 fprintf(bat_file, "%c:\r\n", last_wd_string[0]);
3224 fprintf(bat_file, "cd %s\r\n", last_wd_string);
3225 fclose(bat_file);
3228 #endif
3229 if (print_last_wd) {
3230 if (print_last_revert || edit_one_file || view_one_file)
3231 write (stdout_fd, ".", 1);
3232 else
3233 write (stdout_fd, last_wd_string, strlen (last_wd_string));
3234 g_free (last_wd_string);
3237 #ifdef HAVE_MAD
3238 done_key ();
3239 #endif
3241 mad_finalize (__FILE__, __LINE__);
3242 #ifdef HAVE_X
3243 xtoolkit_end ();
3244 #endif
3245 return 0;