* main.c: Option -P takes an argument (output filename) now.

(main): Output the last directory to the specified file.  Don't
output "." is this information is unavailable.
This commit is contained in:
Pavel Roskin 2002-10-31 04:31:52 +00:00
parent 2c3b0c50b6
commit a04dd8754e
2 changed files with 583 additions and 568 deletions

View File

@ -1,5 +1,9 @@
2002-10-30 Pavel Roskin <proski@gnu.org>
* main.c: Option -P takes an argument (output filename) now.
(main): Output the last directory to the specified file. Don't
output "." is this information is unavailable.
* subshell.c (subshell_name_quote): Don't quote numbers and
letters if possible and safe.

View File

@ -254,9 +254,10 @@ char *this_dir = 0;
*/
int xtree_mode = 0;
/* If true, then print on stdout the last directory we were at */
static int print_last_wd = 0;
/* If set, then print to the given file the last directory we were at */
static char *last_wd_file;
static char *last_wd_string;
/* Set to 1 to suppress printing the last directory */
static int print_last_revert = 0;
/* Force colors, only used by Slang */
@ -344,7 +345,8 @@ reload_panelized (WPanel *panel)
}
static void
update_one_panel_widget (WPanel *panel, int force_update, char *current_file)
update_one_panel_widget (WPanel *panel, int force_update,
char *current_file)
{
int free_pointer;
@ -510,7 +512,6 @@ do_execute (const char *shell, const char *command, int flags)
printf ("%s%s%s\n", last_paused ? "\r\n" : "", prompt, command);
last_paused = 0;
}
#ifdef HAVE_SUBSHELL_SUPPORT
if (use_subshell && !(flags & EXECUTE_INTERNAL)) {
do_update_prompt ();
@ -526,9 +527,9 @@ do_execute (const char *shell, const char *command, int flags)
my_system (flags, shell, command);
if (!(flags & EXECUTE_INTERNAL)) {
if ((pause_after_run == pause_always ||
(pause_after_run == pause_on_dumb_terminals &&
!xterm_flag && !console_flag)) && !quit
if ((pause_after_run == pause_always
|| (pause_after_run == pause_on_dumb_terminals && !xterm_flag
&& !console_flag)) && !quit
#ifdef HAVE_SUBSHELL_SUPPORT
&& subshell_state != RUNNING_COMMAND
#endif /* HAVE_SUBSHELL_SUPPORT */
@ -579,7 +580,8 @@ shell_execute (char *command, int flags)
if (subshell_state == INACTIVE || force_subshell_execution)
do_execute (shell, command, flags | EXECUTE_AS_SHELL);
else
message (1, MSG_ERROR, _(" The shell is already running a command "));
message (1, MSG_ERROR,
_(" The shell is already running a command "));
else
#endif /* HAVE_SUBSHELL_SUPPORT */
do_execute (shell, command, flags | EXECUTE_AS_SHELL);
@ -600,7 +602,8 @@ change_panel (void)
/* Stop MC main dialog and the current dialog if it exists.
* Needed to provide fast exit from MC viewer or editor on shell exit */
static void stop_dialogs (void)
static void
stop_dialogs (void)
{
midnight_dlg->running = 0;
if (current_dlg) {
@ -616,17 +619,17 @@ quit_cmd_internal (int quiet)
if (quiet || !confirm_exit) {
q = 1;
} else {
if (query_dialog (_(" The Midnight Commander "),
_(" Do you really want to quit the Midnight Commander? "),
0, 2, _("&Yes"), _("&No")) == 0)
if (query_dialog
(_(" The Midnight Commander "),
_(" Do you really want to quit the Midnight Commander? "), 0,
2, _("&Yes"), _("&No")) == 0)
q = 1;
}
if (q) {
#ifdef HAVE_SUBSHELL_SUPPORT
if (!use_subshell)
stop_dialogs ();
else
if ((q = exit_subshell ()))
else if ((q = exit_subshell ()))
#endif
stop_dialogs ();
}
@ -635,13 +638,15 @@ quit_cmd_internal (int quiet)
return quit;
}
int quit_cmd (void)
int
quit_cmd (void)
{
quit_cmd_internal (0);
return quit;
}
int quiet_quit_cmd (void)
int
quiet_quit_cmd (void)
{
print_last_revert = 1;
quit_cmd_internal (1);
@ -776,8 +781,9 @@ _do_panel_cd (WPanel *panel, char *new_dir, enum cd_enum cd_type)
/* Reload current panel */
panel_clean_dir (panel);
panel->count = do_load_dir (&panel->dir, panel->sort_type,
panel->reverse, panel->case_sensitive, panel->filter);
panel->count =
do_load_dir (&panel->dir, panel->sort_type, panel->reverse,
panel->case_sensitive, panel->filter);
try_to_select (panel, get_parent_dir_name (panel->cwd, olddir));
load_hint ();
panel_update_contents (panel);
@ -829,14 +835,16 @@ directory_history_list (WPanel * panel)
/* must be at least two to show a history */
if (panel->dir_history) {
if (panel->dir_history->prev || panel->dir_history->next) {
s = show_hist (panel->dir_history, panel->widget.x, panel->widget.y);
s = show_hist (panel->dir_history, panel->widget.x,
panel->widget.y);
if (s) {
int r;
r = _do_panel_cd (panel, s, cd_exact);
if (r)
directory_history_add (panel, panel->cwd);
else
message (1, MSG_ERROR, _("Could not change directory") );
message (1, MSG_ERROR,
_("Could not change directory"));
g_free (s);
}
}
@ -863,7 +871,8 @@ load_prompt (int fd, void *unused)
prompt_len = COLS - 8;
}
label_set_text (the_prompt, prompt);
winput_set_origin ((WInput *)cmdline, prompt_len, COLS-prompt_len);
winput_set_origin ((WInput *) cmdline, prompt_len,
COLS - prompt_len);
/* since the prompt has changed, and we are called from one of the
* get_event channels, the prompt updating does not take place
@ -931,7 +940,8 @@ listmode_cmd (void)
{
char *newmode;
newmode = listmode_edit ("half <type,>name,|,size:8,|,perm:4+");
message (0, _(" Listing format edit "), _(" New mode is \"%s\" "), newmode);
message (0, _(" Listing format edit "), _(" New mode is \"%s\" "),
newmode);
g_free (newmode);
}
#endif /* LISTMODE_EDITOR */
@ -1081,16 +1091,21 @@ static Menu MenuBar [5];
void
init_menu (void)
{
MenuBar [0] = create_menu ( horizontal_split ? _(" &Above ") : _(" &Left "),
MenuBar[0] =
create_menu (horizontal_split ? _(" &Above ") : _(" &Left "),
PanelMenu, menu_entries (PanelMenu),
"[Left and Right Menus]");
MenuBar [1] = create_menu (_(" &File "), FileMenu, menu_entries (FileMenu),
MenuBar[1] =
create_menu (_(" &File "), FileMenu, menu_entries (FileMenu),
"[File Menu]");
MenuBar [2] = create_menu (_(" &Command "), CmdMenu, menu_entries (CmdMenu),
MenuBar[2] =
create_menu (_(" &Command "), CmdMenu, menu_entries (CmdMenu),
"[Command Menu]");
MenuBar [3] = create_menu (_(" &Options "), OptMenu, menu_entries (OptMenu),
MenuBar[3] =
create_menu (_(" &Options "), OptMenu, menu_entries (OptMenu),
"[Options Menu]");
MenuBar [4] = create_menu (horizontal_split ? _(" &Below ") : _(" &Right "),
MenuBar[4] =
create_menu (horizontal_split ? _(" &Below ") : _(" &Right "),
RightMenu, menu_entries (PanelMenu),
"[Left and Right Menus]");
}
@ -1134,7 +1149,8 @@ toggle_fast_reload (void)
fast_reload = !fast_reload;
if (fast_reload_w == 0 && fast_reload) {
message (0, _(" Information "),
_(" Using the fast reload option may not reflect the exact \n"
_
(" Using the fast reload option may not reflect the exact \n"
" directory contents. In this cases you'll need to do a \n"
" manual reload of the directory. See the man page for \n"
" the details. "));
@ -1243,7 +1259,8 @@ create_panels (void)
the_menubar = menubar_new (0, 0, COLS, MenuBar, 5);
}
static void copy_current_pathname (void)
static void
copy_current_pathname (void)
{
if (!command_prompt)
return;
@ -1253,7 +1270,8 @@ static void copy_current_pathname (void)
command_insert (cmdline, PATH_SEP_STR, 0);
}
static void copy_other_pathname (void)
static void
copy_other_pathname (void)
{
if (get_other_type () != view_listing)
return;
@ -1266,13 +1284,15 @@ static void copy_other_pathname (void)
command_insert (cmdline, PATH_SEP_STR, 0);
}
static void copy_readlink (WPanel *panel)
static void
copy_readlink (WPanel *panel)
{
if (!command_prompt)
return;
if (S_ISLNK (selection (panel)->buf.st_mode)) {
char buffer[MC_MAXPATHLEN];
char *p = concat_dir_and_file (panel->cwd, selection (panel)->fname);
char *p =
concat_dir_and_file (panel->cwd, selection (panel)->fname);
int i;
i = mc_readlink (p, buffer, MC_MAXPATHLEN);
@ -1284,12 +1304,14 @@ static void copy_readlink (WPanel *panel)
}
}
static void copy_current_readlink (void)
static void
copy_current_readlink (void)
{
copy_readlink (cpanel);
}
static void copy_other_readlink (void)
static void
copy_other_readlink (void)
{
if (get_other_type () != view_listing)
return;
@ -1298,7 +1320,8 @@ static void copy_other_readlink (void)
/* Inserts the selected file name into the input line */
/* Exported so that the command modules uses it */
void copy_prog_name (void)
void
copy_prog_name (void)
{
char *tmp;
if (!command_prompt)
@ -1333,19 +1356,22 @@ copy_tagged (WPanel * panel)
input_enable_update (cmdline);
}
static void copy_current_tagged (void)
static void
copy_current_tagged (void)
{
copy_tagged (cpanel);
}
static void copy_other_tagged (void)
static void
copy_other_tagged (void)
{
if (get_other_type () != view_listing)
return;
copy_tagged (opanel);
}
static void do_suspend_cmd (void)
static void
do_suspend_cmd (void)
{
pre_exec ();
@ -1387,9 +1413,11 @@ static void
init_labels (Widget *paneletc)
{
define_label (midnight_dlg, paneletc, 1, _("Help"), help_cmd);
define_label (midnight_dlg, paneletc, 2, _("Menu"), user_file_menu_cmd);
define_label (midnight_dlg, paneletc, 2, _("Menu"),
user_file_menu_cmd);
define_label (midnight_dlg, paneletc, 9, _("PullDn"), menu_cmd);
define_label (midnight_dlg, paneletc, 10, _("Quit"), (voidfn) quit_cmd);
define_label (midnight_dlg, paneletc, 10, _("Quit"),
(voidfn) quit_cmd);
}
static const key_map ctl_x_map[] = {
@ -1426,12 +1454,14 @@ static const key_map ctl_x_map [] = {
static int ctl_x_map_enabled = 0;
static void ctl_x_cmd (int ignore)
static void
ctl_x_cmd (int ignore)
{
ctl_x_map_enabled = 1;
}
static void nothing (void)
static void
nothing (void)
{
}
@ -1480,7 +1510,8 @@ static const key_map default_map [] = {
{0, 0},
};
static void setup_sigwinch (void)
static void
setup_sigwinch (void)
{
#if (defined(HAVE_SLANG) || (NCURSES_VERSION_MAJOR >= 4)) && \
!defined(NATIVE_WIN32) && defined(SIGWINCH)
@ -1547,8 +1578,7 @@ init_xterm_support (void)
use_mouse_p = MOUSE_DISABLED;
}
if (force_xterm
|| strncmp (termvalue, "xterm", 5) == 0
if (force_xterm || strncmp (termvalue, "xterm", 5) == 0
|| strncmp (termvalue, "rxvt", 4) == 0
|| strcmp (termvalue, "dtterm") == 0) {
xterm_flag = 1;
@ -1562,14 +1592,14 @@ init_xterm_support (void)
if (use_mouse_p != MOUSE_DISABLED) {
use_mouse_p = MOUSE_XTERM;
}
#if 0 /* It works on xterm, but not on rxvt */
printf (ESC_STR "]0;GNU Midnight Commander\7");
#endif
}
}
static void setup_mc (void)
static void
setup_mc (void)
{
setup_pre ();
init_menu ();
@ -1589,7 +1619,8 @@ static void setup_mc (void)
init_mouse ();
}
static void setup_dummy_mc (const char *file)
static void
setup_dummy_mc (const char *file)
{
char d[MC_MAXPATHLEN];
@ -1606,7 +1637,8 @@ static void setup_dummy_mc (const char *file)
cpanel->dir.list[0].fname = (char *) file;
}
static void done_mc (void)
static void
done_mc (void)
{
disable_mouse ();
@ -1630,7 +1662,8 @@ static void done_mc (void)
/* This should be called after destroy_dlg since panel widgets
* save their state on the profiles
*/
static void done_mc_profile (void)
static void
done_mc_profile (void)
{
if (!auto_save_setup)
profile_forget_profile (profile_name);
@ -1709,8 +1742,8 @@ midnight_callback (struct Dlg_head *h, int id, int msg)
return MSG_HANDLED;
}
if ((!alternate_plus_minus || !(console_flag || xterm_flag)) &&
!quote && !cpanel->searching) {
if ((!alternate_plus_minus || !(console_flag || xterm_flag))
&& !quote && !cpanel->searching) {
if (!only_leading_plus_minus) {
/* Special treatement, since the input line will eat them */
if (id == '+') {
@ -1770,8 +1803,7 @@ midnight_callback (struct Dlg_head *h, int id, int msg)
(*ctl_x_map[i].fn) (id);
return MSG_HANDLED;
}
} else
{
} else {
for (i = 0; default_map[i].key_code; i++) {
if (id == default_map[i].key_code) {
(*default_map[i].fn) (id);
@ -1786,8 +1818,8 @@ midnight_callback (struct Dlg_head *h, int id, int msg)
attrset (SELECTED_COLOR);
if (console_flag && output_lines)
show_console_contents (output_start_y,
LINES-output_lines-keybar_visible-1,
LINES-keybar_visible-1);
LINES - output_lines - keybar_visible -
1, LINES - keybar_visible - 1);
return MSG_HANDLED;
}
@ -1912,9 +1944,9 @@ do_nc (void)
midnight_colors[2] = INPUT_COLOR; /* HOT_NORMALC */
midnight_colors[3] = NORMAL_COLOR; /* HOT_FOCUSC */
midnight_dlg = create_dlg (0, 0, LINES, COLS, midnight_colors,
midnight_callback, "[main]", NULL,
DLG_HAS_MENUBAR);
midnight_dlg =
create_dlg (0, 0, LINES, COLS, midnight_colors, midnight_callback,
"[main]", NULL, DLG_HAS_MENUBAR);
/* Check if we were invoked as an editor or file viewer */
if (mc_maybe_editor_or_viewer ())
@ -1928,10 +1960,7 @@ do_nc (void)
midnight_shutdown = 1;
/* destroy_dlg destroys even cpanel->cwd, so we have to save a copy :) */
if (print_last_wd) {
if (!vfs_current_is_local ())
last_wd_string = g_strdup (".");
else
if (last_wd_file && vfs_current_is_local ()) {
last_wd_string = g_strdup (cpanel->cwd);
}
done_mc ();
@ -2071,13 +2100,15 @@ print_mc_usage (poptContext ctx, FILE * stream)
{
int leftColWidth;
poptSetOtherOptionHelp (ctx, _("[flags] [this_dir] [other_panel_dir]\n"));
poptSetOtherOptionHelp (ctx,
_("[flags] [this_dir] [other_panel_dir]\n"));
/* print help for options */
leftColWidth = poptPrintHelp (ctx, stream, 0);
fprintf (stream, " %-*s %s\n", leftColWidth, _("+number"),
_("Set initial line number for the internal editor"));
fputs (_("\n"
fputs (_
("\n"
"Please send any bug reports (including the output of `mc -V')\n"
"to mc-devel@gnome.org\n"), stream);
version (0);
@ -2091,18 +2122,17 @@ print_color_usage (void)
* and editmarked. To preserve translations, lines should be split.
*/
/* TRANSLATORS: don't translate keywords and names of colors */
fputs (_("--colors KEYWORD={FORE},{BACK}\n\n"
fputs (_
("--colors KEYWORD={FORE},{BACK}\n\n"
"{FORE} and {BACK} can be omitted, and the default will be used\n"
"\n"
"Keywords:\n"
"\n" "Keywords:\n"
" Global: errors, reverse, gauge, input\n"
" File display: normal, selected, marked, markselect\n"
" Dialog boxes: dnormal, dfocus, dhotnormal, dhotfocus\n"
" Menus: menu, menuhot, menusel, menuhotsel\n"
" Help: helpnormal, helpitalic, helplink, helpslink\n"
" File types: directory, executable, link, stalelink, device, special, core\n"
"\n"
"Colors:\n"
"\n" "Colors:\n"
" black, gray, red, brightred, green, brightgreen, brown,\n"
" yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
" brightcyan, lightgray and white\n\n"), stdout);
@ -2112,8 +2142,6 @@ static void
probably_finish_program (void)
{
if (finish_program) {
if (print_last_wd)
printf (".");
exit (1);
}
}
@ -2214,8 +2242,8 @@ static const struct poptOption argument_table[] = {
{"forceexec", 'r', POPT_ARG_NONE, &force_subshell_execution, 0,
N_("Force subshell execution")},
#endif
{"printwd", 'P', POPT_ARG_NONE, &print_last_wd, 0,
N_("Prints working directory at program exit")},
{"printwd", 'P', POPT_ARG_STRING, &last_wd_file, 0,
N_("Print last working directory to specified file")},
{"resetsoft", 'k', POPT_ARG_NONE, &reset_hp_softkeys, 0,
N_("Resets soft keys on HP terminals")},
{"slow", 's', POPT_ARG_NONE, &slow_terminal, 0,
@ -2250,7 +2278,8 @@ handle_args (int argc, char *argv [])
char *base;
int c;
ctx = poptGetContext ("mc", argc, argv, argument_table,
ctx =
poptGetContext ("mc", argc, argv, argument_table,
POPT_CONTEXT_NO_EXEC);
#ifdef USE_TERMCAP
@ -2294,8 +2323,7 @@ handle_args (int argc, char *argv [])
}
edit_one_file = g_strdup (tmp);
}
} else
if (!STRNCOMP (base, "mcv", 3) || !STRCOMP(base, "view")) {
} else if (!STRNCOMP (base, "mcv", 3) || !STRCOMP (base, "view")) {
if (tmp)
view_one_file = g_strdup (tmp);
else {
@ -2347,7 +2375,8 @@ compatibility_move_mc_files (void)
int move = 0;
char *mc_dir = concat_dir_and_file (home_dir, ".mc");
if (stat (mc_dir, &s) && (errno == ENOENT) && (mkdir (mc_dir, 0777) != -1)) {
if (stat (mc_dir, &s) && (errno == ENOENT)
&& (mkdir (mc_dir, 0777) != -1)) {
move = do_mc_filename_rename (mc_dir, ".mc.ini", "ini");
move += do_mc_filename_rename (mc_dir, ".mc.hot", "hotlist");
@ -2401,28 +2430,6 @@ main (int argc, char *argv [])
handle_args (argc, argv);
/* Used to report the last working directory at program end */
if (print_last_wd){
#ifndef NATIVE_WIN32
stdout_fd = dup (1);
close (1);
if (open (ttyname (0), O_RDWR) < 0)
if (open ("/dev/tty", O_RDWR) < 0) {
/* Try if stderr is not redirected as the last chance */
char *p = g_strdup (ttyname (0));
if (!strcmp (p, ttyname (2)))
dup2 (2, 1);
else {
fputs (_("Couldn't open tty line. You have to run mc without the -P flag.\n"
"On some systems you may want to run # `which mc`\n"), stderr);
exit (1);
}
g_free (p);
}
#endif
}
/* Must be done before installing the SIGCHLD handler [[FIXME]] */
handle_console (CONSOLE_INIT);
@ -2482,7 +2489,6 @@ main (int argc, char *argv [])
" are now stored in the ~/.mc directory, the \n"
" files have been moved now\n"));
}
#ifdef HAVE_SUBSHELL_SUPPORT
if (use_subshell) {
prompt = strip_ctrl_codes (subshell_prompt);
@ -2528,17 +2534,22 @@ main (int argc, char *argv [])
/* On NT, home_dir is malloced */
g_free (home_dir);
#endif
if (print_last_wd) {
if (print_last_revert || edit_one_file || view_one_file)
write (stdout_fd, ".", 1);
else
write (stdout_fd, last_wd_string, strlen (last_wd_string));
g_free (last_wd_string);
if (last_wd_file && !print_last_revert && !edit_one_file
&& !view_one_file) {
int last_wd_fd =
open (last_wd_file, O_WRONLY | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR);
if (last_wd_fd != -1) {
write (last_wd_fd, last_wd_string, strlen (last_wd_string));
close (last_wd_fd);
}
}
g_free (last_wd_string);
#ifndef NATIVE_WIN32
g_free (mc_home);
#endif /* (NATIVE_WIN32) */
#endif /* NATIVE_WIN32 */
done_key ();
#ifdef HAVE_CHARSET
free_codepages_list ();