Manual pages: mc • mcdiff • mcedit • mcview

root/src/filemanager/cmd.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. do_view_cmd
  2. do_edit
  3. compare_read
  4. compare_files
  5. compare_dir
  6. do_link
  7. nice_cd
  8. configure_panel_listing
  9. switch_to_listing
  10. view_file_at_line
  11. view_file
  12. view_cmd
  13. view_file_cmd
  14. view_raw_cmd
  15. view_filtered_cmd
  16. edit_file_at_line
  17. edit_cmd
  18. edit_cmd_force_internal
  19. edit_cmd_new
  20. mkdir_cmd
  21. reread_cmd
  22. ext_cmd
  23. edit_mc_menu_cmd
  24. edit_fhl_cmd
  25. hotlist_cmd
  26. vfs_list
  27. compare_dirs_cmd
  28. diff_view_cmd
  29. swap_cmd
  30. link_cmd
  31. edit_symlink_cmd
  32. help_cmd
  33. ftplink_cmd
  34. sftplink_cmd
  35. shelllink_cmd
  36. quick_cd_cmd
  37. smart_dirsize_cmd
  38. single_dirsize_cmd
  39. dirsizes_cmd
  40. save_setup_cmd
  41. info_cmd_no_menu
  42. quick_cmd_no_menu
  43. listing_cmd
  44. setup_listing_format_cmd
  45. panel_tree_cmd
  46. info_cmd
  47. quick_view_cmd
  48. encoding_cmd

   1 /*
   2    Routines invoked by a function key
   3    They normally operate on the current panel.
   4 
   5    Copyright (C) 1994-2026
   6    Free Software Foundation, Inc.
   7 
   8    Written by:
   9    Andrew Borodin <aborodin@vmail.ru>, 2013-2022
  10 
  11    This file is part of the Midnight Commander.
  12 
  13    The Midnight Commander is free software: you can redistribute it
  14    and/or modify it under the terms of the GNU General Public License as
  15    published by the Free Software Foundation, either version 3 of the License,
  16    or (at your option) any later version.
  17 
  18    The Midnight Commander is distributed in the hope that it will be useful,
  19    but WITHOUT ANY WARRANTY; without even the implied warranty of
  20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21    GNU General Public License for more details.
  22 
  23    You should have received a copy of the GNU General Public License
  24    along with this program.  If not, see <https://www.gnu.org/licenses/>.
  25  */
  26 
  27 /** \file cmd.c
  28  *  \brief Source: routines invoked by a function key
  29  *
  30  *  They normally operate on the current panel.
  31  */
  32 
  33 #include <config.h>
  34 
  35 #include <errno.h>
  36 #include <stdio.h>
  37 #include <string.h>
  38 
  39 #include <sys/types.h>
  40 #include <sys/stat.h>
  41 #ifdef ENABLE_VFS_NET
  42 #include <netdb.h>
  43 #endif
  44 #include <unistd.h>
  45 #include <stdlib.h>
  46 #include <pwd.h>
  47 #include <grp.h>
  48 
  49 #include "lib/global.h"
  50 
  51 #include "lib/tty/tty.h"  // LINES, tty_touch_screen()
  52 #include "lib/tty/key.h"  // ALT() macro
  53 #include "lib/mcconfig.h"
  54 #include "lib/filehighlight.h"  // MC_FHL_INI_FILE
  55 #include "lib/vfs/vfs.h"
  56 #include "lib/fileloc.h"
  57 #include "lib/strutil.h"
  58 #include "lib/file-entry.h"
  59 #include "lib/util.h"
  60 #include "lib/widget.h"
  61 #include "lib/keybind.h"  // CK_Down, CK_History
  62 #include "lib/event.h"    // mc_event_raise()
  63 
  64 #include "src/setup.h"
  65 #include "src/execute.h"  // toggle_panels()
  66 #include "src/history.h"
  67 #include "src/util.h"  // check_for_default(), file_error_message()
  68 
  69 #include "src/viewer/mcviewer.h"
  70 
  71 #ifdef USE_INTERNAL_EDIT
  72 #include "src/editor/edit.h"
  73 #endif
  74 
  75 #ifdef USE_DIFF_VIEW
  76 #include "src/diffviewer/ydiff.h"
  77 #endif
  78 
  79 #include "filegui.h"
  80 #include "hotlist.h"      // hotlist_show()
  81 #include "tree.h"         // tree_chdir()
  82 #include "filemanager.h"  // change_panel()
  83 #include "command.h"      // the_cmdline
  84 #include "layout.h"       // get_current_type()
  85 #include "ext.h"          // regex_command()
  86 #include "boxes.h"        // cd_box()
  87 #include "dir.h"
  88 #include "cd.h"
  89 #include "ioblksize.h"  // IO_BUFSIZE
  90 
  91 #include "cmd.h"  // Our definitions
  92 
  93 /*** global variables ****************************************************************************/
  94 
  95 /*** file scope macro definitions ****************************************************************/
  96 
  97 /*** file scope type declarations ****************************************************************/
  98 
  99 enum CompareMode
 100 {
 101     compare_quick = 0,
 102     compare_size_only,
 103     compare_thourough
 104 };
 105 
 106 /*** forward declarations (file scope functions) *************************************************/
 107 
 108 /*** file scope variables ************************************************************************/
 109 
 110 #ifdef ENABLE_VFS_NET
 111 static const char *machine_str = N_ ("Enter machine name (F1 for details):");
 112 #endif
 113 
 114 /* --------------------------------------------------------------------------------------------- */
 115 /*** file scope functions ************************************************************************/
 116 /* --------------------------------------------------------------------------------------------- */
 117 /**
 118  * Run viewer (internal or external) on the current file.
 119  * If @plain_view is TRUE, force internal viewer and raw mode (used for F13).
 120  */
 121 static void
 122 do_view_cmd (WPanel *panel, gboolean plain_view)
     /* [previous][next][first][last][top][bottom][index][help]  */
 123 {
 124     const file_entry_t *fe;
 125 
 126     fe = panel_current_entry (panel);
 127     if (fe == NULL)
 128         return;
 129 
 130     // Directories are viewed by changing to them
 131     if (S_ISDIR (fe->st.st_mode) || link_isdir (fe))
 132     {
 133         vfs_path_t *fname_vpath;
 134 
 135         if (confirm_view_dir && (panel->marked != 0 || panel->dirs_marked != 0)
 136             && query_dialog (_ ("Confirmation"), _ ("Files tagged, want to cd?"), D_NORMAL, 2,
 137                              _ ("&Yes"), _ ("&No"))
 138                 != 0)
 139             return;
 140 
 141         fname_vpath = vfs_path_from_str (fe->fname->str);
 142         if (!panel_cd (panel, fname_vpath, cd_exact))
 143             cd_error_message (fe->fname->str);
 144         vfs_path_free (fname_vpath, TRUE);
 145     }
 146     else
 147     {
 148         vfs_path_t *filename_vpath;
 149 
 150         filename_vpath = vfs_path_from_str (fe->fname->str);
 151         view_file (filename_vpath, plain_view, use_internal_view);
 152         vfs_path_free (filename_vpath, TRUE);
 153     }
 154 
 155     repaint_screen ();
 156 }
 157 
 158 /* --------------------------------------------------------------------------------------------- */
 159 
 160 static inline void
 161 do_edit (const vfs_path_t *what_vpath)
     /* [previous][next][first][last][top][bottom][index][help]  */
 162 {
 163     edit_file_at_line (what_vpath, use_internal_edit, 0);
 164 }
 165 
 166 /* --------------------------------------------------------------------------------------------- */
 167 
 168 /**
 169  * Read from @fd until @buf is full or the end of the file is reached: read() may return less
 170  * than requested before the end of the file (network and FUSE/FSKit file systems, VFS).
 171  *
 172  * @return number of bytes read, -1 on error
 173  */
 174 
 175 static ssize_t
 176 compare_read (int fd, char *buf, size_t size)
     /* [previous][next][first][last][top][bottom][index][help]  */
 177 {
 178     size_t done = 0;
 179 
 180     while (done < size)
 181     {
 182         const ssize_t n = mc_read (fd, buf + done, size - done);
 183 
 184         if (n < 0)
 185         {
 186             if (errno == EINTR)
 187                 continue;
 188             return -1;
 189         }
 190         if (n == 0)
 191             break;
 192         done += (size_t) n;
 193     }
 194 
 195     return (ssize_t) done;
 196 }
 197 
 198 /* --------------------------------------------------------------------------------------------- */
 199 /**
 200  * Compare the contents of two files, which can be on any VFS.
 201  *
 202  * @return 0 if the files are identical, non-zero if they differ or can't be read
 203  */
 204 
 205 static int
 206 compare_files (const vfs_path_t *vpath1, const vfs_path_t *vpath2, off_t size)
     /* [previous][next][first][last][top][bottom][index][help]  */
 207 {
 208     int file1;
 209     int result = -1;  // Different by default
 210 
 211     if (size == 0)
 212         return 0;
 213 
 214     file1 = mc_open (vpath1, O_RDONLY);
 215     if (file1 >= 0)
 216     {
 217         int file2;
 218 
 219         file2 = mc_open (vpath2, O_RDONLY);
 220         if (file2 >= 0)
 221         {
 222             char *buf1, *buf2;
 223             ssize_t n1, n2;
 224 
 225             buf1 = g_malloc (IO_BUFSIZE);
 226             buf2 = g_malloc (IO_BUFSIZE);
 227 
 228             rotate_dash (TRUE);
 229             do
 230             {
 231                 n1 = compare_read (file1, buf1, IO_BUFSIZE);
 232                 n2 = compare_read (file2, buf2, IO_BUFSIZE);
 233             }
 234             while (n1 == IO_BUFSIZE && n2 == IO_BUFSIZE && memcmp (buf1, buf2, IO_BUFSIZE) == 0);
 235             result = n1 < 0 || n2 < 0 || n1 != n2 || memcmp (buf1, buf2, (size_t) n1) != 0;
 236             rotate_dash (FALSE);
 237 
 238             g_free (buf1);
 239             g_free (buf2);
 240             mc_close (file2);
 241         }
 242         mc_close (file1);
 243     }
 244 
 245     return result;
 246 }
 247 
 248 /* --------------------------------------------------------------------------------------------- */
 249 
 250 static void
 251 compare_dir (WPanel *panel, const WPanel *other, enum CompareMode mode)
     /* [previous][next][first][last][top][bottom][index][help]  */
 252 {
 253     // the same file in both panels: the same directory, or hard links
 254     const gboolean same_vfs = vfs_path_get_last_path_vfs (panel->cwd_vpath)
 255         == vfs_path_get_last_path_vfs (other->cwd_vpath);
 256     int i, j;
 257 
 258     // No marks by default
 259     panel->marked = 0;
 260     panel->total = 0;
 261     panel->dirs_marked = 0;
 262 
 263     // Handle all files in the panel
 264     for (i = 0; i < panel->dir.len; i++)
 265     {
 266         file_entry_t *source = &panel->dir.list[i];
 267         const char *source_fname;
 268 
 269         // Default: unmarked
 270         file_mark (panel, i, 0);
 271 
 272         // Skip directories
 273         if (S_ISDIR (source->st.st_mode))
 274             continue;
 275 
 276         source_fname = source->fname->str;
 277         if (panel->is_panelized)
 278             source_fname = x_basename (source_fname);
 279 
 280         // Search the corresponding entry from the other panel
 281         for (j = 0; j < other->dir.len; j++)
 282         {
 283             const char *other_fname;
 284 
 285             other_fname = other->dir.list[j].fname->str;
 286             if (other->is_panelized)
 287                 other_fname = x_basename (other_fname);
 288 
 289             if (strcmp (source_fname, other_fname) == 0)
 290                 break;
 291         }
 292 
 293         if (j >= other->dir.len)
 294             // Not found -> mark
 295             do_file_mark (panel, i, 1);
 296         else
 297         {
 298             // Found
 299             file_entry_t *target = &other->dir.list[j];
 300 
 301             if (mode != compare_size_only)
 302                 // Older version is not marked
 303                 if (source->st.st_mtime < target->st.st_mtime)
 304                     continue;
 305 
 306             // Newer version with different size is marked
 307             if (source->st.st_size != target->st.st_size)
 308             {
 309                 do_file_mark (panel, i, 1);
 310                 continue;
 311             }
 312 
 313             if (mode == compare_size_only)
 314                 continue;
 315 
 316             if (mode == compare_quick)
 317             {
 318                 // Thorough compare off, compare only time stamps
 319                 // Mark newer version, don't mark version with the same date
 320                 if (source->st.st_mtime > target->st.st_mtime)
 321                     do_file_mark (panel, i, 1);
 322 
 323                 continue;
 324             }
 325 
 326             // the same file: no need to read it (a VFS without inode numbers gives 0)
 327             if (same_vfs && source->st.st_ino != 0 && source->st.st_ino == target->st.st_ino
 328                 && source->st.st_dev == target->st.st_dev)
 329                 continue;
 330 
 331             // Thorough compare on, do byte-by-byte comparison
 332             {
 333                 vfs_path_t *src_name, *dst_name;
 334 
 335                 src_name =
 336                     vfs_path_append_new (panel->cwd_vpath, source->fname->str, (char *) NULL);
 337                 dst_name =
 338                     vfs_path_append_new (other->cwd_vpath, target->fname->str, (char *) NULL);
 339                 if (compare_files (src_name, dst_name, source->st.st_size))
 340                     do_file_mark (panel, i, 1);
 341                 vfs_path_free (src_name, TRUE);
 342                 vfs_path_free (dst_name, TRUE);
 343             }
 344         }
 345     }  // for (i ...)
 346 }
 347 
 348 /* --------------------------------------------------------------------------------------------- */
 349 
 350 static void
 351 do_link (link_type_t link_type, const char *fname)
     /* [previous][next][first][last][top][bottom][index][help]  */
 352 {
 353     char *dest = NULL, *src = NULL;
 354     vfs_path_t *dest_vpath = NULL;
 355 
 356     if (link_type == LINK_HARDLINK)
 357     {
 358         vfs_path_t *fname_vpath;
 359 
 360         src = g_strdup_printf (_ ("Link %s to:"), str_trunc (fname, 46));
 361         dest =
 362             input_expand_dialog (_ ("Link"), src, MC_HISTORY_FM_LINK, "", INPUT_COMPLETE_FILENAMES);
 363         if (dest == NULL || *dest == '\0')
 364             goto cleanup;
 365 
 366         save_cwds_stat ();
 367 
 368         fname_vpath = vfs_path_from_str (fname);
 369         dest_vpath = vfs_path_from_str (dest);
 370         if (mc_link (fname_vpath, dest_vpath) == -1)
 371             file_error_message (_ ("Cannot create link\n%s"), dest);
 372         vfs_path_free (fname_vpath, TRUE);
 373     }
 374     else
 375     {
 376         vfs_path_t *s, *d;
 377 
 378         /* suggest the full path for symlink, and either the full or
 379            relative path to the file it points to  */
 380         s = vfs_path_append_new (current_panel->cwd_vpath, fname, (char *) NULL);
 381 
 382         if (get_other_type () == view_listing)
 383             d = vfs_path_append_new (other_panel->cwd_vpath, fname, (char *) NULL);
 384         else
 385             d = vfs_path_from_str (fname);
 386 
 387         if (link_type == LINK_SYMLINK_RELATIVE)
 388         {
 389             char *s_str;
 390 
 391             s_str = diff_two_paths (other_panel->cwd_vpath, s);
 392             vfs_path_free (s, TRUE);
 393             s = vfs_path_from_str_flags (s_str, VPF_NO_CANON);
 394             g_free (s_str);
 395         }
 396 
 397         symlink_box (s, d, &dest, &src);
 398         vfs_path_free (d, TRUE);
 399         vfs_path_free (s, TRUE);
 400 
 401         if (dest == NULL || *dest == '\0' || src == NULL || *src == '\0')
 402             goto cleanup;
 403 
 404         save_cwds_stat ();
 405 
 406         dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
 407 
 408         s = vfs_path_from_str (src);
 409         if (mc_symlink (dest_vpath, s) == -1)
 410             file_error_message (_ ("Cannot create symbolic link\n%s"), dest);
 411         vfs_path_free (s, TRUE);
 412     }
 413 
 414     update_panels (UP_OPTIMIZE, UP_KEEPSEL);
 415     repaint_screen ();
 416 
 417 cleanup:
 418     vfs_path_free (dest_vpath, TRUE);
 419     g_free (src);
 420     g_free (dest);
 421 }
 422 
 423 /* --------------------------------------------------------------------------------------------- */
 424 
 425 #if defined(ENABLE_VFS_NET)
 426 static void
 427 nice_cd (const char *text, const char *xtext, const char *help, const char *history_name,
     /* [previous][next][first][last][top][bottom][index][help]  */
 428          const char *prefix, int to_home, gboolean strip_password)
 429 {
 430     char *machine;
 431     char *cd_path;
 432 
 433     machine = input_dialog_help (text, xtext, help, history_name, INPUT_LAST_TEXT, strip_password,
 434                                  INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_CD
 435                                      | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_USERNAMES);
 436     if (machine == NULL)
 437         return;
 438 
 439     to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is
 440                     ugly as hell and leads to problems in vfs layer */
 441 
 442     if (strncmp (prefix, machine, strlen (prefix)) == 0)
 443         cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
 444     else
 445         cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL);
 446 
 447     g_free (machine);
 448 
 449     if (!IS_PATH_SEP (*cd_path))
 450     {
 451         char *tmp = cd_path;
 452 
 453         cd_path = g_strconcat (PATH_SEP_STR, tmp, (char *) NULL);
 454         g_free (tmp);
 455     }
 456 
 457     {
 458         panel_view_mode_t save_type;
 459         vfs_path_t *cd_vpath;
 460 
 461         save_type = get_panel_type (MENU_PANEL_IDX);
 462 
 463         if (save_type != view_listing)
 464             create_panel (MENU_PANEL_IDX, view_listing);
 465 
 466         cd_vpath = vfs_path_from_str_flags (cd_path, VPF_NO_CANON);
 467         if (!panel_do_cd (MENU_PANEL, cd_vpath, cd_parse_command))
 468         {
 469             cd_error_message (cd_path);
 470 
 471             if (save_type != view_listing)
 472                 create_panel (MENU_PANEL_IDX, save_type);
 473         }
 474         vfs_path_free (cd_vpath, TRUE);
 475     }
 476     g_free (cd_path);
 477 
 478     // In case of passive panel, restore current VFS directory that was changed in panel_do_cd()
 479     if (MENU_PANEL != current_panel)
 480         (void) mc_chdir (current_panel->cwd_vpath);
 481 }
 482 #endif
 483 
 484 /* --------------------------------------------------------------------------------------------- */
 485 
 486 static void
 487 configure_panel_listing (WPanel *p, int list_format, int brief_cols, gboolean use_msformat,
     /* [previous][next][first][last][top][bottom][index][help]  */
 488                          char **user, char **status)
 489 {
 490     p->user_mini_status = use_msformat;
 491     p->list_format = list_format;
 492 
 493     if (list_format == list_brief)
 494         p->brief_cols = brief_cols;
 495 
 496     if (list_format == list_user || use_msformat)
 497     {
 498         g_free (p->user_format);
 499         p->user_format = *user;
 500         *user = NULL;
 501 
 502         g_free (p->user_status_format[list_format]);
 503         p->user_status_format[list_format] = *status;
 504         *status = NULL;
 505 
 506         set_panel_formats (p);
 507     }
 508 
 509     set_panel_formats (p);
 510     do_refresh ();
 511 }
 512 
 513 /* --------------------------------------------------------------------------------------------- */
 514 
 515 static void
 516 switch_to_listing (int panel_index)
     /* [previous][next][first][last][top][bottom][index][help]  */
 517 {
 518     if (get_panel_type (panel_index) != view_listing)
 519         create_panel (panel_index, view_listing);
 520 }
 521 
 522 /* --------------------------------------------------------------------------------------------- */
 523 /*** public functions ****************************************************************************/
 524 /* --------------------------------------------------------------------------------------------- */
 525 
 526 gboolean
 527 view_file_at_line (const vfs_path_t *filename_vpath, gboolean plain_view, gboolean internal,
     /* [previous][next][first][last][top][bottom][index][help]  */
 528                    long start_line, off_t search_start, off_t search_end)
 529 {
 530     gboolean ret = TRUE;
 531 
 532     if (plain_view)
 533     {
 534         mcview_mode_flags_t changed_flags;
 535 
 536         mcview_clear_mode_flags (&changed_flags);
 537         mcview_altered_flags.hex = FALSE;
 538         mcview_altered_flags.magic = FALSE;
 539         mcview_altered_flags.nroff = FALSE;
 540         if (mcview_global_flags.hex)
 541             changed_flags.hex = TRUE;
 542         if (mcview_global_flags.magic)
 543             changed_flags.magic = TRUE;
 544         if (mcview_global_flags.nroff)
 545             changed_flags.nroff = TRUE;
 546         mcview_global_flags.hex = FALSE;
 547         mcview_global_flags.magic = FALSE;
 548         mcview_global_flags.nroff = FALSE;
 549 
 550         ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
 551 
 552         if (changed_flags.hex && !mcview_altered_flags.hex)
 553             mcview_global_flags.hex = TRUE;
 554         if (changed_flags.magic && !mcview_altered_flags.magic)
 555             mcview_global_flags.magic = TRUE;
 556         if (changed_flags.nroff && !mcview_altered_flags.nroff)
 557             mcview_global_flags.nroff = TRUE;
 558 
 559         dialog_switch_process_pending ();
 560     }
 561     else if (internal)
 562     {
 563         char view_entry[BUF_TINY];
 564 
 565         if (start_line > 0)
 566             g_snprintf (view_entry, sizeof (view_entry), "View:%ld", start_line);
 567         else
 568             strcpy (view_entry, "View");
 569 
 570         ret = (regex_command (filename_vpath, view_entry) == 0);
 571         if (ret)
 572         {
 573             ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end);
 574             dialog_switch_process_pending ();
 575         }
 576     }
 577     else
 578     {
 579         static const char *viewer = NULL;
 580 
 581         if (viewer == NULL)
 582         {
 583             viewer = getenv ("VIEWER");
 584             if (viewer == NULL)
 585                 viewer = getenv ("PAGER");
 586             if (viewer == NULL)
 587                 viewer = "view";
 588         }
 589 
 590         execute_external_editor_or_viewer (viewer, filename_vpath, start_line);
 591     }
 592 
 593     return ret;
 594 }
 595 
 596 /* --------------------------------------------------------------------------------------------- */
 597 /** view_file (filename, plain_view, internal)
 598  *
 599  * Inputs:
 600  *   filename_vpath: The file name to view
 601  *   plain_view:     If set does not do any fancy pre-processing (no filtering) and
 602  *                   always invokes the internal viewer.
 603  *   internal:       If set uses the internal viewer, otherwise an external viewer.
 604  */
 605 
 606 gboolean
 607 view_file (const vfs_path_t *filename_vpath, gboolean plain_view, gboolean internal)
     /* [previous][next][first][last][top][bottom][index][help]  */
 608 {
 609     return view_file_at_line (filename_vpath, plain_view, internal, 0, 0, 0);
 610 }
 611 
 612 /* --------------------------------------------------------------------------------------------- */
 613 /** Run user's preferred viewer on the current file */
 614 
 615 void
 616 view_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 617 {
 618     do_view_cmd (panel, FALSE);
 619 }
 620 
 621 /* --------------------------------------------------------------------------------------------- */
 622 /** Ask for file and run user's preferred viewer on it */
 623 
 624 void
 625 view_file_cmd (const WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 626 {
 627     const file_entry_t *fe;
 628     char *filename;
 629     vfs_path_t *vpath;
 630 
 631     fe = panel_current_entry (panel);
 632     if (fe == NULL)
 633         return;
 634 
 635     filename = input_expand_dialog (_ ("View file"), _ ("Filename:"), MC_HISTORY_FM_VIEW_FILE,
 636                                     fe->fname->str, INPUT_COMPLETE_FILENAMES);
 637     if (filename == NULL)
 638         return;
 639 
 640     vpath = vfs_path_from_str (filename);
 641     g_free (filename);
 642     view_file (vpath, FALSE, use_internal_view);
 643     vfs_path_free (vpath, TRUE);
 644 }
 645 
 646 /* --------------------------------------------------------------------------------------------- */
 647 /** Run plain internal viewer on the current file */
 648 void
 649 view_raw_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 650 {
 651     do_view_cmd (panel, TRUE);
 652 }
 653 
 654 /* --------------------------------------------------------------------------------------------- */
 655 
 656 void
 657 view_filtered_cmd (const WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 658 {
 659     char *command;
 660     const char *initial_command;
 661 
 662     if (input_is_empty (the_cmdline))
 663     {
 664         const file_entry_t *fe;
 665 
 666         fe = panel_current_entry (panel);
 667         if (fe == NULL)
 668             return;
 669 
 670         initial_command = fe->fname->str;
 671     }
 672     else
 673         initial_command = input_get_ctext (the_cmdline);
 674 
 675     command = input_dialog (_ ("Filtered view"), _ ("Filter command and arguments:"),
 676                             MC_HISTORY_FM_FILTERED_VIEW, initial_command,
 677                             INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_COMMANDS);
 678 
 679     if (command != NULL)
 680     {
 681         mcview_viewer (command, NULL, 0, 0, 0);
 682         g_free (command);
 683         dialog_switch_process_pending ();
 684     }
 685 }
 686 
 687 /* --------------------------------------------------------------------------------------------- */
 688 
 689 void
 690 edit_file_at_line (const vfs_path_t *what_vpath, gboolean internal, long start_line)
     /* [previous][next][first][last][top][bottom][index][help]  */
 691 {
 692 #ifdef USE_INTERNAL_EDIT
 693     if (internal)
 694     {
 695         const edit_arg_t arg = { (vfs_path_t *) what_vpath, start_line };
 696 
 697         edit_file (&arg);
 698         dialog_switch_process_pending ();
 699     }
 700     else
 701 #endif
 702     {
 703         static const char *editor = NULL;
 704 
 705         (void) internal;
 706 
 707         if (editor == NULL)
 708         {
 709             editor = getenv ("EDITOR");
 710             if (editor == NULL)
 711                 editor = get_default_editor ();
 712         }
 713 
 714         execute_external_editor_or_viewer (editor, what_vpath, start_line);
 715     }
 716 }
 717 
 718 /* --------------------------------------------------------------------------------------------- */
 719 
 720 void
 721 edit_cmd (const WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 722 {
 723     const file_entry_t *fe;
 724     vfs_path_t *fname;
 725 
 726     fe = panel_current_entry (panel);
 727     if (fe == NULL)
 728         return;
 729 
 730     fname = vfs_path_from_str (fe->fname->str);
 731     if (regex_command (fname, "Edit") == 0)
 732         do_edit (fname);
 733     vfs_path_free (fname, TRUE);
 734 }
 735 
 736 /* --------------------------------------------------------------------------------------------- */
 737 
 738 #ifdef USE_INTERNAL_EDIT
 739 void
 740 edit_cmd_force_internal (const WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 741 {
 742     const file_entry_t *fe;
 743     vfs_path_t *fname;
 744 
 745     fe = panel_current_entry (panel);
 746     if (fe == NULL)
 747         return;
 748 
 749     fname = vfs_path_from_str (fe->fname->str);
 750     if (regex_command (fname, "Edit") == 0)
 751         edit_file_at_line (fname, TRUE, 1);
 752     vfs_path_free (fname, TRUE);
 753 }
 754 #endif
 755 
 756 /* --------------------------------------------------------------------------------------------- */
 757 
 758 void
 759 edit_cmd_new (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 760 {
 761     vfs_path_t *fname_vpath = NULL;
 762 
 763     if (editor_ask_filename_before_edit)
 764     {
 765         char *fname;
 766 
 767         fname = input_expand_dialog (_ ("Edit file"), _ ("Enter file name:"), MC_HISTORY_EDIT_LOAD,
 768                                      "", INPUT_COMPLETE_FILENAMES);
 769         if (fname == NULL)
 770             return;
 771 
 772         if (*fname != '\0')
 773             fname_vpath = vfs_path_from_str (fname);
 774 
 775         g_free (fname);
 776     }
 777 
 778     mc_global.source_codepage = default_source_codepage;
 779     do_edit (fname_vpath);
 780 
 781     vfs_path_free (fname_vpath, TRUE);
 782 }
 783 
 784 /* --------------------------------------------------------------------------------------------- */
 785 
 786 void
 787 mkdir_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 788 {
 789     const file_entry_t *fe;
 790     char *dir;
 791     const char *name = "";
 792 
 793     fe = panel_current_entry (panel);
 794     if (fe == NULL)
 795         return;
 796 
 797     // If 'on' then automatically fills name with current item name
 798     if (auto_fill_mkdir_name && !DIR_IS_DOTDOT (fe->fname->str))
 799         name = fe->fname->str;
 800 
 801     dir = input_expand_dialog (_ ("Create a new Directory"), _ ("Enter directory name:"),
 802                                MC_HISTORY_FM_MKDIR, name, INPUT_COMPLETE_FILENAMES);
 803 
 804     if (dir != NULL && *dir != '\0')
 805     {
 806         vfs_path_t *absdir;
 807 
 808         if (IS_PATH_SEP (dir[0]) || dir[0] == '~')
 809             absdir = vfs_path_from_str (dir);
 810         else
 811         {
 812             // possible escaped '~'
 813             // allow create directory with name '~'
 814             char *tmpdir = dir;
 815 
 816             if (dir[0] == '\\' && dir[1] == '~')
 817                 tmpdir = dir + 1;
 818 
 819             absdir = vfs_path_append_new (panel->cwd_vpath, tmpdir, (char *) NULL);
 820         }
 821 
 822         save_cwds_stat ();
 823 
 824         if (mc_mkdir (absdir, 0777) != 0)
 825             file_error_message (_ ("Cannot create directory\n%s"), vfs_path_as_str (absdir));
 826         else
 827         {
 828             update_panels (UP_OPTIMIZE, dir);
 829             repaint_screen ();
 830             select_item (panel);
 831         }
 832 
 833         vfs_path_free (absdir, TRUE);
 834     }
 835     g_free (dir);
 836 }
 837 
 838 /* --------------------------------------------------------------------------------------------- */
 839 
 840 void
 841 reread_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 842 {
 843     panel_update_flags_t flag = UP_ONLY_CURRENT;
 844 
 845     if (get_current_type () == view_listing && get_other_type () == view_listing
 846         && vfs_path_equal (current_panel->cwd_vpath, other_panel->cwd_vpath))
 847         flag = UP_OPTIMIZE;
 848 
 849     update_panels (UP_RELOAD | flag, UP_KEEPSEL);
 850     repaint_screen ();
 851 }
 852 
 853 /* --------------------------------------------------------------------------------------------- */
 854 
 855 void
 856 ext_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 857 {
 858     vfs_path_t *extdir_vpath;
 859     int dir = 0;
 860 
 861     if (geteuid () == 0)
 862         dir = query_dialog (_ ("Extension file edit"), _ ("Which extension file you want to edit?"),
 863                             D_NORMAL, 2, _ ("&User"), _ ("&System Wide"));
 864 
 865     extdir_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_EXT_FILE, (char *) NULL);
 866 
 867     if (dir == 0)
 868     {
 869         vfs_path_t *buffer_vpath;
 870 
 871         buffer_vpath = mc_config_get_full_vpath (MC_EXT_FILE);
 872         check_for_default (extdir_vpath, buffer_vpath);
 873         do_edit (buffer_vpath);
 874         vfs_path_free (buffer_vpath, TRUE);
 875     }
 876     else if (dir == 1)
 877     {
 878         if (!exist_file (vfs_path_get_last_path_str (extdir_vpath)))
 879         {
 880             vfs_path_free (extdir_vpath, TRUE);
 881             extdir_vpath =
 882                 vfs_path_build_filename (mc_global.share_data_dir, MC_EXT_FILE, (char *) NULL);
 883         }
 884         do_edit (extdir_vpath);
 885     }
 886 
 887     vfs_path_free (extdir_vpath, TRUE);
 888     flush_extension_file ();
 889 }
 890 
 891 /* --------------------------------------------------------------------------------------------- */
 892 /** edit file menu for mc */
 893 
 894 void
 895 edit_mc_menu_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 896 {
 897     vfs_path_t *buffer_vpath;
 898     vfs_path_t *menufile_vpath;
 899     int dir = 0;
 900 
 901     query_set_sel (1);
 902     dir = query_dialog (_ ("Menu edit"), _ ("Which menu file do you want to edit?"), D_NORMAL,
 903                         geteuid () ? 2 : 3, _ ("&Local"), _ ("&User"), _ ("&System Wide"));
 904 
 905     menufile_vpath =
 906         vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, (char *) NULL);
 907 
 908     if (!exist_file (vfs_path_get_last_path_str (menufile_vpath)))
 909     {
 910         vfs_path_free (menufile_vpath, TRUE);
 911         menufile_vpath =
 912             vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, (char *) NULL);
 913     }
 914 
 915     switch (dir)
 916     {
 917     case 0:
 918         buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU);
 919         check_for_default (menufile_vpath, buffer_vpath);
 920         chmod (vfs_path_get_last_path_str (buffer_vpath), 0600);
 921         break;
 922 
 923     case 1:
 924         buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE);
 925         check_for_default (menufile_vpath, buffer_vpath);
 926         break;
 927 
 928     case 2:
 929         buffer_vpath =
 930             vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, (char *) NULL);
 931         if (!exist_file (vfs_path_get_last_path_str (buffer_vpath)))
 932         {
 933             vfs_path_free (buffer_vpath, TRUE);
 934             buffer_vpath =
 935                 vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, (char *) NULL);
 936         }
 937         break;
 938 
 939     default:
 940         vfs_path_free (menufile_vpath, TRUE);
 941         return;
 942     }
 943 
 944     do_edit (buffer_vpath);
 945 
 946     vfs_path_free (buffer_vpath, TRUE);
 947     vfs_path_free (menufile_vpath, TRUE);
 948 }
 949 
 950 /* --------------------------------------------------------------------------------------------- */
 951 
 952 void
 953 edit_fhl_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
 954 {
 955     vfs_path_t *fhlfile_vpath = NULL;
 956     int dir = 0;
 957 
 958     if (geteuid () == 0)
 959         dir = query_dialog (_ ("Highlighting groups file edit"),
 960                             _ ("Which highlighting file you want to edit?"), D_NORMAL, 2,
 961                             _ ("&User"), _ ("&System Wide"));
 962 
 963     fhlfile_vpath =
 964         vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL);
 965 
 966     if (dir == 0)
 967     {
 968         vfs_path_t *buffer_vpath;
 969 
 970         buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE);
 971         check_for_default (fhlfile_vpath, buffer_vpath);
 972         do_edit (buffer_vpath);
 973         vfs_path_free (buffer_vpath, TRUE);
 974     }
 975     else if (dir == 1)
 976     {
 977         if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath)))
 978         {
 979             vfs_path_free (fhlfile_vpath, TRUE);
 980             fhlfile_vpath =
 981                 vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL);
 982         }
 983         do_edit (fhlfile_vpath);
 984     }
 985 
 986     vfs_path_free (fhlfile_vpath, TRUE);
 987     // refresh highlighting rules
 988     mc_fhl_free (&mc_filehighlight);
 989     mc_filehighlight = mc_fhl_new (TRUE);
 990 }
 991 
 992 /* --------------------------------------------------------------------------------------------- */
 993 
 994 void
 995 hotlist_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
 996 {
 997     char *target;
 998 
 999     target = hotlist_show (LIST_HOTLIST, panel);
1000     if (target == NULL)
1001         return;
1002 
1003     if (get_current_type () == view_tree)
1004     {
1005         vfs_path_t *vpath;
1006 
1007         vpath = vfs_path_from_str (target);
1008         tree_chdir (the_tree, vpath);
1009         vfs_path_free (vpath, TRUE);
1010     }
1011     else
1012     {
1013         vfs_path_t *deprecated_vpath;
1014         const char *deprecated_path;
1015 
1016         deprecated_vpath = vfs_path_from_str_flags (target, VPF_USE_DEPRECATED_PARSER);
1017         deprecated_path = vfs_path_as_str (deprecated_vpath);
1018         cd_to (deprecated_path);
1019         vfs_path_free (deprecated_vpath, TRUE);
1020     }
1021 
1022     g_free (target);
1023 }
1024 
1025 /* --------------------------------------------------------------------------------------------- */
1026 
1027 #ifdef ENABLE_VFS
1028 void
1029 vfs_list (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1030 {
1031     char *target;
1032     vfs_path_t *target_vpath;
1033 
1034     target = hotlist_show (LIST_VFSLIST, panel);
1035     if (target == NULL)
1036         return;
1037 
1038     target_vpath = vfs_path_from_str (target);
1039     if (!panel_cd (current_panel, target_vpath, cd_exact))
1040         cd_error_message (target);
1041     vfs_path_free (target_vpath, TRUE);
1042     g_free (target);
1043 }
1044 #endif
1045 
1046 /* --------------------------------------------------------------------------------------------- */
1047 
1048 void
1049 compare_dirs_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1050 {
1051     int choice;
1052     enum CompareMode thorough_flag;
1053 
1054     choice = query_dialog (_ ("Compare directories"), _ ("Select compare method:"), D_NORMAL, 4,
1055                            _ ("&Quick"), _ ("&Size only"), _ ("&Thorough"), _ ("&Cancel"));
1056 
1057     if (choice < 0 || choice > 2)
1058         return;
1059 
1060     thorough_flag = choice;
1061 
1062     if (get_current_type () == view_listing && get_other_type () == view_listing)
1063     {
1064         compare_dir (current_panel, other_panel, thorough_flag);
1065         compare_dir (other_panel, current_panel, thorough_flag);
1066     }
1067     else
1068         message (D_ERROR, MSG_ERROR,
1069                  _ ("Both panels should be in the listing mode\nto use this command"));
1070 }
1071 
1072 /* --------------------------------------------------------------------------------------------- */
1073 
1074 #ifdef USE_DIFF_VIEW
1075 void
1076 diff_view_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1077 {
1078     // both panels must be in the list mode
1079     if (get_current_type () == view_listing && get_other_type () == view_listing)
1080     {
1081         if (get_current_index () == 0)
1082             dview_diff_cmd (current_panel, other_panel);
1083         else
1084             dview_diff_cmd (other_panel, current_panel);
1085 
1086         if (mc_global.mc_run_mode == MC_RUN_FULL)
1087             update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1088 
1089         dialog_switch_process_pending ();
1090     }
1091 }
1092 #endif
1093 
1094 /* --------------------------------------------------------------------------------------------- */
1095 
1096 void
1097 swap_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1098 {
1099     swap_panels ();
1100     tty_touch_screen ();
1101     repaint_screen ();
1102 }
1103 
1104 /* --------------------------------------------------------------------------------------------- */
1105 
1106 void
1107 link_cmd (link_type_t link_type)
     /* [previous][next][first][last][top][bottom][index][help]  */
1108 {
1109     const file_entry_t *fe;
1110 
1111     fe = panel_current_entry (current_panel);
1112     if (fe != NULL)
1113         do_link (link_type, fe->fname->str);
1114 }
1115 
1116 /* --------------------------------------------------------------------------------------------- */
1117 
1118 void
1119 edit_symlink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1120 {
1121     const file_entry_t *fe;
1122     const char *p;
1123 
1124     fe = panel_current_entry (current_panel);
1125     if (fe == NULL)
1126         return;
1127 
1128     p = fe->fname->str;
1129 
1130     if (!S_ISLNK (fe->st.st_mode))
1131         message (D_ERROR, MSG_ERROR, _ ("'%s' is not a symbolic link"), p);
1132     else
1133     {
1134         char buffer[MC_MAXPATHLEN];
1135         int i;
1136 
1137         i = readlink (p, buffer, sizeof (buffer) - 1);
1138         if (i > 0)
1139         {
1140             char *q, *dest;
1141 
1142             buffer[i] = '\0';
1143 
1144             q = g_strdup_printf (_ ("Symlink '%s\' points to:"), str_trunc (p, 32));
1145             dest = input_expand_dialog (_ ("Edit symlink"), q, MC_HISTORY_FM_EDIT_LINK, buffer,
1146                                         INPUT_COMPLETE_FILENAMES);
1147             g_free (q);
1148 
1149             if (dest != NULL && *dest != '\0' && strcmp (buffer, dest) != 0)
1150             {
1151                 vfs_path_t *p_vpath;
1152 
1153                 p_vpath = vfs_path_from_str (p);
1154 
1155                 save_cwds_stat ();
1156 
1157                 if (mc_unlink (p_vpath) == -1)
1158                     file_error_message (_ ("Edit symlink, unable to remove\n%s"), p);
1159                 else
1160                 {
1161                     vfs_path_t *dest_vpath;
1162 
1163                     dest_vpath = vfs_path_from_str_flags (dest, VPF_NO_CANON);
1164                     if (mc_symlink (dest_vpath, p_vpath) == -1)
1165                         file_error_message (_ ("Cannot edit symlink\n%s"),
1166                                             vfs_path_as_str (dest_vpath));
1167                     vfs_path_free (dest_vpath, TRUE);
1168                 }
1169 
1170                 vfs_path_free (p_vpath, TRUE);
1171 
1172                 update_panels (UP_OPTIMIZE, UP_KEEPSEL);
1173                 repaint_screen ();
1174             }
1175 
1176             g_free (dest);
1177         }
1178     }
1179 }
1180 
1181 /* --------------------------------------------------------------------------------------------- */
1182 
1183 void
1184 help_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1185 {
1186     ev_help_t event_data = { NULL, NULL };
1187 
1188     if (current_panel->quick_search.active)
1189         event_data.node = "[Quick search]";
1190     else
1191         event_data.node = "[main]";
1192 
1193     mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
1194 }
1195 
1196 /* --------------------------------------------------------------------------------------------- */
1197 
1198 #ifdef ENABLE_VFS_FTP
1199 void
1200 ftplink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1201 {
1202     nice_cd (_ ("FTP to machine"), _ (machine_str), "[FTP File System]",
1203              ":ftplink_cmd: FTP to machine ", "ftp://", 1, TRUE);
1204 }
1205 #endif
1206 
1207 /* --------------------------------------------------------------------------------------------- */
1208 
1209 #ifdef ENABLE_VFS_SFTP
1210 void
1211 sftplink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1212 {
1213     nice_cd (_ ("SFTP to machine"), _ (machine_str),
1214              "[SFTP (SSH File Transfer Protocol) filesystem]", ":sftplink_cmd: SFTP to machine ",
1215              "sftp://", 1, TRUE);
1216 }
1217 #endif
1218 
1219 /* --------------------------------------------------------------------------------------------- */
1220 
1221 #ifdef ENABLE_VFS_SHELL
1222 void
1223 shelllink_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1224 {
1225     nice_cd (_ ("Shell link to machine"), _ (machine_str), "[FIle transfer over SHell filesystem]",
1226              ":fishlink_cmd: Shell link to machine ", "sh://", 1, TRUE);
1227 }
1228 #endif
1229 
1230 /* --------------------------------------------------------------------------------------------- */
1231 
1232 void
1233 quick_cd_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1234 {
1235     char *p;
1236 
1237     p = cd_box (panel);
1238     if (p != NULL && *p != '\0')
1239         cd_to (p);
1240     g_free (p);
1241 }
1242 
1243 /* --------------------------------------------------------------------------------------------- */
1244 /*!
1245    \brief calculate dirs sizes
1246 
1247    calculate dirs sizes and resort panel:
1248    dirs_selected = show size for selected dirs,
1249    otherwise = show size for dir under cursor:
1250    dir under cursor ".." = show size for all dirs,
1251    otherwise = show size for dir under cursor
1252  */
1253 
1254 void
1255 smart_dirsize_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1256 {
1257     const file_entry_t *entry;
1258 
1259     entry = panel_current_entry (panel);
1260     if ((entry != NULL && S_ISDIR (entry->st.st_mode) && DIR_IS_DOTDOT (entry->fname->str))
1261         || panel->dirs_marked)
1262         dirsizes_cmd (panel);
1263     else
1264         single_dirsize_cmd (panel);
1265 }
1266 
1267 /* --------------------------------------------------------------------------------------------- */
1268 
1269 void
1270 single_dirsize_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1271 {
1272     file_entry_t *entry;
1273 
1274     entry = panel_current_entry (panel);
1275 
1276     if (entry != NULL && S_ISDIR (entry->st.st_mode) && !DIR_IS_DOTDOT (entry->fname->str))
1277     {
1278         size_t dir_count = 0;
1279         size_t count = 0;
1280         uintmax_t total = 0;
1281         dirsize_status_msg_t dsm;
1282         vfs_path_t *p;
1283 
1284         p = vfs_path_from_str (entry->fname->str);
1285 
1286         memset (&dsm, 0, sizeof (dsm));
1287         status_msg_init (STATUS_MSG (&dsm), _ ("Directory scanning"), 0, dirsize_status_init_cb,
1288                          dirsize_status_update_cb, dirsize_status_deinit_cb);
1289 
1290         if (compute_dir_size (p, &dsm, &dir_count, &count, &total, FALSE) == FILE_CONT)
1291         {
1292             entry->st.st_size = (off_t) total;
1293             entry->f.dir_size_computed = 1;
1294         }
1295 
1296         vfs_path_free (p, TRUE);
1297 
1298         status_msg_deinit (STATUS_MSG (&dsm));
1299     }
1300 
1301     if (panels_options.mark_moves_down)
1302         send_message (panel, NULL, MSG_ACTION, CK_Down, NULL);
1303 
1304     recalculate_panel_summary (panel);
1305 
1306     if (panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1307         panel_re_sort (panel);
1308 
1309     panel->dirty = TRUE;
1310 }
1311 
1312 /* --------------------------------------------------------------------------------------------- */
1313 
1314 void
1315 dirsizes_cmd (WPanel *panel)
     /* [previous][next][first][last][top][bottom][index][help]  */
1316 {
1317     int i;
1318     dirsize_status_msg_t dsm;
1319 
1320     memset (&dsm, 0, sizeof (dsm));
1321     status_msg_init (STATUS_MSG (&dsm), _ ("Directory scanning"), 0, dirsize_status_init_cb,
1322                      dirsize_status_update_cb, dirsize_status_deinit_cb);
1323 
1324     for (i = 0; i < panel->dir.len; i++)
1325         if (S_ISDIR (panel->dir.list[i].st.st_mode)
1326             && ((panel->dirs_marked != 0 && panel->dir.list[i].f.marked != 0)
1327                 || panel->dirs_marked == 0)
1328             && !DIR_IS_DOTDOT (panel->dir.list[i].fname->str))
1329         {
1330             vfs_path_t *p;
1331             size_t dir_count = 0;
1332             size_t count = 0;
1333             uintmax_t total = 0;
1334             gboolean ok;
1335 
1336             p = vfs_path_from_str (panel->dir.list[i].fname->str);
1337             ok = compute_dir_size (p, &dsm, &dir_count, &count, &total, FALSE) != FILE_CONT;
1338             vfs_path_free (p, TRUE);
1339             if (ok)
1340                 break;
1341 
1342             panel->dir.list[i].st.st_size = (off_t) total;
1343             panel->dir.list[i].f.dir_size_computed = 1;
1344         }
1345 
1346     status_msg_deinit (STATUS_MSG (&dsm));
1347 
1348     recalculate_panel_summary (panel);
1349 
1350     if (panel->sort_field->sort_routine == (GCompareFunc) sort_size)
1351         panel_re_sort (panel);
1352 
1353     panel->dirty = TRUE;
1354 }
1355 
1356 /* --------------------------------------------------------------------------------------------- */
1357 
1358 void
1359 save_setup_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1360 {
1361     vfs_path_t *vpath;
1362     const char *path;
1363 
1364     vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
1365     path = vfs_path_as_str (vpath);
1366 
1367     if (save_setup (TRUE, TRUE))
1368         message (D_NORMAL, _ ("Setup"), _ ("Setup saved to %s"), path);
1369     else
1370         message (D_ERROR, _ ("Setup"), _ ("Unable to save setup to %s"), path);
1371 
1372     vfs_path_free (vpath, TRUE);
1373 }
1374 
1375 /* --------------------------------------------------------------------------------------------- */
1376 
1377 void
1378 info_cmd_no_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1379 {
1380     if (get_panel_type (0) == view_info)
1381         create_panel (0, view_listing);
1382     else if (get_panel_type (1) == view_info)
1383         create_panel (1, view_listing);
1384     else
1385         create_panel (current_panel == left_panel ? 1 : 0, view_info);
1386 }
1387 
1388 /* --------------------------------------------------------------------------------------------- */
1389 
1390 void
1391 quick_cmd_no_menu (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1392 {
1393     if (get_panel_type (0) == view_quick)
1394         create_panel (0, view_listing);
1395     else if (get_panel_type (1) == view_quick)
1396         create_panel (1, view_listing);
1397     else
1398         create_panel (current_panel == left_panel ? 1 : 0, view_quick);
1399 }
1400 
1401 /* --------------------------------------------------------------------------------------------- */
1402 
1403 void
1404 listing_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1405 {
1406     WPanel *p;
1407 
1408     switch_to_listing (MENU_PANEL_IDX);
1409 
1410     p = PANEL (get_panel_widget (MENU_PANEL_IDX));
1411 
1412     p->is_panelized = FALSE;
1413     panel_set_filter (p, NULL);  // including panel reload
1414 }
1415 
1416 /* --------------------------------------------------------------------------------------------- */
1417 
1418 void
1419 setup_listing_format_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1420 {
1421     int list_format;
1422     gboolean use_msformat;
1423     int brief_cols;
1424     char *user, *status;
1425     WPanel *p = NULL;
1426 
1427     if (SELECTED_IS_PANEL)
1428         p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1429 
1430     list_format = panel_listing_box (p, MENU_PANEL_IDX, &user, &status, &use_msformat, &brief_cols);
1431     if (list_format != -1)
1432     {
1433         switch_to_listing (MENU_PANEL_IDX);
1434         p = MENU_PANEL_IDX == 0 ? left_panel : right_panel;
1435         configure_panel_listing (p, list_format, brief_cols, use_msformat, &user, &status);
1436         g_free (user);
1437         g_free (status);
1438     }
1439 }
1440 
1441 /* --------------------------------------------------------------------------------------------- */
1442 
1443 void
1444 panel_tree_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1445 {
1446     create_panel (MENU_PANEL_IDX, view_tree);
1447 }
1448 
1449 /* --------------------------------------------------------------------------------------------- */
1450 
1451 void
1452 info_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1453 {
1454     create_panel (MENU_PANEL_IDX, view_info);
1455 }
1456 
1457 /* --------------------------------------------------------------------------------------------- */
1458 
1459 void
1460 quick_view_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1461 {
1462     if (PANEL (get_panel_widget (MENU_PANEL_IDX)) == current_panel)
1463         (void) change_panel ();
1464     create_panel (MENU_PANEL_IDX, view_quick);
1465 }
1466 
1467 /* --------------------------------------------------------------------------------------------- */
1468 
1469 void
1470 encoding_cmd (void)
     /* [previous][next][first][last][top][bottom][index][help]  */
1471 {
1472     if (SELECTED_IS_PANEL)
1473         panel_change_encoding (MENU_PANEL);
1474 }
1475 
1476 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */