main.c

来自「ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机」· C语言 代码 · 共 2,658 行 · 第 1/5 页

C
2,658
字号

#ifdef HAVE_SUBSHELL_SUPPORT
int
load_prompt (int fd, void *unused)
{
    if (!read_subshell_prompt (QUIETLY))
	return 0;

    if (command_prompt){
	int  prompt_len;

	prompt = strip_ctrl_codes (subshell_prompt);
	prompt_len = strlen (prompt);

	/* Check for prompts too big */
	if (prompt_len > COLS - 8) {
	    prompt [COLS - 8 ] = 0;
	    prompt_len = COLS - 8;
	}
	label_set_text (the_prompt, prompt);
	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
	 * automatically: force a cursor update and a screen refresh
	 */
	if (current_dlg == midnight_dlg){
	    update_cursor (midnight_dlg);
	    mc_refresh ();
	}
    }
    update_prompt = 1;
    return 0;
}
#endif

/* The user pressed the enter key */
int
menu_bar_event (Gpm_Event *event, void *x)
{
    if (event->type != GPM_DOWN)
	return MOU_NORMAL;

    return MOU_ENDLOOP;
}

/* Used to emulate Lynx's entering leaving a directory with the arrow keys */
int
maybe_cd (int char_code, int move_up_dir)
{
    if (navigate_with_arrows){
	if (!input_w (cmdline)->buffer [0]){
	    if (!move_up_dir){
		do_cd ("..", cd_exact);
		return 1;
	    }
	    if (S_ISDIR (selection (cpanel)->buf.st_mode)
		|| link_isdir (selection (cpanel))){
		do_cd (selection (cpanel)->fname, cd_exact);
		return 1;
	    }
	}
    }
    return 0;
}

void
set_sort_to (WPanel *p, sortfn *sort_order)
{
    p->sort_type = sort_order;

    /* The directory is already sorted, we have to load the unsorted stuff */
    if (sort_order == (sortfn *) unsorted){
	char *current_file;

	current_file = strdup (cpanel->dir.list [cpanel->selected].fname);
	panel_reload (cpanel);
	try_to_select (cpanel, current_file);
	free (current_file);
    }
    do_re_sort (p);
}

void
sort_cmd (void)
{
    WPanel  *p;
    sortfn *sort_order;

    if (!SELECTED_IS_PANEL)
	return;

    p = MENU_PANEL;
    sort_order = sort_box (p->sort_type, &p->reverse, &p->case_sensitive);

    if (sort_order == 0)
	return;

    p->sort_type = sort_order;

    /* The directory is already sorted, we have to load the unsorted stuff */
    if (sort_order == (sortfn *) unsorted){
	char *current_file;

	current_file = strdup (cpanel->dir.list [cpanel->selected].fname);
	panel_reload (cpanel);
	try_to_select (cpanel, current_file);
	free (current_file);
    }
    do_re_sort (p);
}

static void
tree_box (void)
{
    char *sel_dir;

    sel_dir = tree (selection (cpanel)->fname);
    if (sel_dir){
	do_cd(sel_dir, cd_exact);
	free (sel_dir);
    }
}

#if SOMEDAY_WE_WILL_FINISH_THIS_CODE
static void
	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);
    free (newmode);
}
#endif

#ifdef HAVE_GNOME
void init_menu () {};
void done_menu () {};
#else
/* NOTICE: hotkeys specified here are overriden in menubar_paint_idx (alex) */
static menu_entry PanelMenu [] = {
    { ' ', N_("&Listing mode..."),          'L', listing_cmd },
    { ' ', N_("&Quick view     C-x q"),     'Q', quick_view_cmd },
    { ' ', N_("&Info           C-x i"),     'I', info_cmd },
    { ' ', N_("&Tree"),                     'T', tree_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("&Sort order..."),            'S', sort_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("&Filter..."),                'F', filter_cmd },
#ifdef USE_NETCODE
    { ' ', "", ' ', 0 },
    { ' ', N_("&Network link..."),          'N', netlink_cmd },
    { ' ', N_("FT&P link..."),              'P', ftplink_cmd },
#endif
    { ' ', "", ' ', 0 },
#ifdef OS2_NT
    { ' ', N_("&Drive...       M-d"),       'D', drive_cmd_a },
#endif
    { ' ', N_("&Rescan         C-r"),       'R', reread_cmd }
};

static menu_entry RightMenu [] = {
    { ' ', N_("&Listing mode..."),       'L', listing_cmd },
    { ' ', N_("&Quick view     C-x q"),  'Q', quick_view_cmd },
    { ' ', N_("&Info           C-x i"),  'I', info_cmd },
    { ' ', N_("&Tree"),                  'T', tree_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("&Sort order..."),         'S', sort_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("&Filter..."),             'F', filter_cmd },
#ifdef USE_NETCODE
    { ' ', "", ' ', 0 },
    { ' ', N_("&Network link..."),       'N', netlink_cmd },
    { ' ', N_("FT&P link..."),           'P', ftplink_cmd },
#endif
    { ' ', "", ' ', 0 },
#ifdef OS2_NT
    { ' ', N_("&Drive...       M-d"),    'D', drive_cmd_b },
#endif
    { ' ', N_("&Rescan         C-r"),    'R', reread_cmd }
};

static menu_entry FileMenu [] = {
    { ' ', N_("&User menu          F2"), 'U', user_menu_cmd },
    { ' ', N_("&View               F3"), 'V', view_cmd },
    { ' ', N_("&Filtered view     M-!"), 'F', filtered_view_cmd },
    { ' ', N_("&Edit               F4"), 'E', edit_cmd },
    { ' ', N_("&Copy               F5"), 'C', copy_cmd },
    { ' ', N_("c&Hmod           C-x c"), 'H', chmod_cmd },
#ifndef OS2_NT
    { ' ', N_("&Link            C-x l"), 'L', link_cmd },
    { ' ', N_("&SymLink         C-x s"), 'S', symlink_cmd },
    { ' ', N_("edit s&Ymlink  C-x C-s"), 'Y', edit_symlink_cmd },
    { ' ', N_("ch&Own           C-x o"), 'O', chown_cmd },
    { ' ', N_("&Advanced chown       "), 'A', chown_advanced_cmd },
#endif
    { ' ', N_("&Rename/Move        F6"), 'R', ren_cmd },
    { ' ', N_("&Mkdir              F7"), 'M', mkdir_cmd },
    { ' ', N_("&Delete             F8"), 'D', delete_cmd },
    { ' ', N_("&Quick cd          M-c"), 'Q', quick_cd_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("select &Group      M-+"), 'G', select_cmd },
    { ' ', N_("u&Nselect group    M-\\"),'N', unselect_cmd },
    { ' ', N_("reverse selec&Tion M-*"), 'T', reverse_selection_cmd },
    { ' ', "", ' ', 0 },
    { ' ', N_("e&Xit              F10"), 'X', (callfn) quit_cmd }
};

void external_panelize (void);
static menu_entry CmdMenu [] = {
    /* I know, I'm lazy, but the tree widget when it's not running
     * as a panel still has some problems, I have not yet finished
     * the WTree widget port, sorry.
     */
    { ' ', N_("&Directory tree"),               'D', tree_box },
    { ' ', N_("&Find file            M-?"),     'F', find_cmd },
#ifndef HAVE_XVIEW
    { ' ', N_("s&Wap panels          C-u"),     'W', swap_cmd },
    { ' ', N_("switch &Panels on/off C-o"),     'P', view_other_cmd },
#endif
    { ' ', N_("&Compare directories  C-x d"),   'C', compare_dirs_cmd },
    { ' ', N_("e&Xternal panelize    C-x !"),   'X', external_panelize },
#ifdef HAVE_DUSUM
    { ' ', N_("show directory s&Izes"),         'I', dirsizes_cmd },
#endif
    { ' ', "", ' ', 0 },
    { ' ', N_("command &History"),              'H', history_cmd },
    { ' ', N_("di&Rectory hotlist    C-\\"),    'R', quick_chdir_cmd },
#ifdef USE_VFS
    { ' ', N_("&Active VFS list      C-x a"),   'A', reselect_vfs },
#endif
#ifdef WITH_BACKGROUND
    { ' ', N_("&Background jobs      C-x j"),   'B', jobs_cmd },
#endif
    { ' ', "", ' ', 0 },
#ifdef USE_EXT2FSLIB
    { ' ', N_("&Undelete files (ext2fs only)"), 'U', undelete_cmd },
#endif
#ifdef VERSION_4
    { ' ', N_("&Listing format edit"),          'L', listmode_cmd},
#endif
    { ' ', N_("&Extension file edit"),          'E', ext_cmd },
    { ' ', N_("&Menu file edit"),               'M', menu_edit_cmd }
};

/* Must keep in sync with the constants in menu_cmd */
static menu_entry OptMenu [] = {
    { ' ', N_("&Configuration..."),    'C', configure_box },
    { ' ', N_("&Layout..."),           'L', layout_cmd },
    { ' ', N_("c&Onfirmation..."),     'O', confirm_box },
    { ' ', N_("&Display bits..."),     'D', display_bits_box },
#if !defined(HAVE_X) && !defined(OS2_NT)
    { ' ', N_("learn &Keys..."),       'K', learn_keys },
#endif
#ifdef USE_VFS
    { ' ', N_("&Virtual FS..."),       'V', configure_vfs },
#endif
    { ' ', "", ' ', 0 },
    { ' ', N_("&Save setup"),          'S', save_setup_cmd }
};

#define menu_entries(x) sizeof(x)/sizeof(menu_entry)

Menu MenuBar [5];
#ifndef HAVE_X
static Menu MenuBarEmpty [5];
#endif

void
init_menu (void)
{
    int i;

#ifdef HAVE_X
    MenuBar [0] = create_menu (_(" Left "), PanelMenu, menu_entries (PanelMenu));
#else
    MenuBar [0] = create_menu ( horizontal_split ? _(" Above ") : _(" Left "),
                                PanelMenu, menu_entries (PanelMenu));
#endif
    MenuBar [1] = create_menu (_(" File "), FileMenu, menu_entries (FileMenu));
    MenuBar [2] = create_menu (_(" Command "), CmdMenu, menu_entries (CmdMenu));
    MenuBar [3] = create_menu (_(" Options "), OptMenu, menu_entries (OptMenu));
#ifndef HAVE_XVIEW
#ifdef HAVE_X
    MenuBar [4] = create_menu (_(" Right "), RightMenu, menu_entries (PanelMenu));
#else
    MenuBar [4] = create_menu (horizontal_split ? _(" Below ") : _(" Right "),
			       RightMenu, menu_entries (PanelMenu));
    for (i = 0; i < 5; i++)
	MenuBarEmpty [i] = create_menu (MenuBar [i]->name, 0, 0);
#endif /* HAVE_X */
#endif /* ! HAVE_XVIEW */
}

void
done_menu (void)
{
    int i;

#ifndef HAVE_XVIEW
    for (i = 0; i < 5; i++){
	destroy_menu (MenuBar [i]);
#ifndef HAVE_X
	destroy_menu (MenuBarEmpty [i]);
#endif
#else
    for (i = 0; i < 4; i++){
	destroy_menu (MenuBar [i]);
#endif
    }
}
#endif

static void
menu_last_selected_cmd (void)
{
    the_menubar->active = 1;
    the_menubar->dropped = drop_menus;
    the_menubar->previous_selection = dlg_item_number (midnight_dlg);
    dlg_select_widget (midnight_dlg, the_menubar);
}

static void
menu_cmd (void)
{
    if (the_menubar->active)
	return;

    if (get_current_index () == 0)
	the_menubar->selected = 0;
    else
	the_menubar->selected = 4;
    menu_last_selected_cmd ();
}

/* Flag toggling functions */
void
toggle_confirm_delete (void)
{
    confirm_delete = !confirm_delete;
}

void
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"
		   " 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.                                           "));
	fast_reload_w = 1;
    }
}

void
toggle_mix_all_files (void)
{
    mix_all_files = !mix_all_files;
    update_panels (UP_RELOAD, UP_KEEPSEL);
}

void
toggle_show_backup (void)
{
    show_backups = !show_backups;
    update_panels (UP_RELOAD, UP_KEEPSEL);
}

void
toggle_show_hidden (void)
{
    show_dot_files = !show_dot_files;
    update_panels (UP_RELOAD, UP_KEEPSEL);
}

void
toggle_show_mini_status (void)
{
    show_mini_info = !show_mini_info;
    paint_panel (cpanel);
    if (get_other_type () == view_listing)
	paint_panel (opanel);
}

void
toggle_align_extensions (void)
{
    align_extensions = !align_extensions;
}

#ifndef PORT_HAS_CREATE_PANELS
void
create_panels (void)
{
    int current_index;
    int other_index;
    int current_mode;
    int other_mode;
    char original_dir [1024];

    original_dir [0] = 0;

    if (boot_current_is_left){
	current_index = 0;
	other_index = 1;
	current_mode = startup_left_mode;
	other_mode = startup_right_mode;
    } else {
	current_index = 1;
	other_index = 0;
	current_mode = startup_right_mode;
	other_mode = startup_left_mode;
    }
    /* Creates the left panel */
    if (this_dir){
	if (other_dir){
	    /* Ok, user has specified two dirs, save the original one,
	     * since we may not be able to chdir to the proper
	     * second directory later
	     */
	    mc_get_current_wd (original_dir, sizeof (original_dir)-2);
	}
	mc_chdir (this_dir);
    }
    set_display_type (current_index, current_mode);

    /* The other panel */
    if (other_dir){
	if (original_dir [0])
	    mc_chdir (original_dir);
	mc_chdir (other_dir);
    }
    set_display_type (other_index, other_mode);

    if (startup_left_mode == view_listing){
	current_panel = left_panel;
    } else {
	if (right_panel)
	    current_panel = right_panel;
	else
	    current_panel = left_panel;
    }

    /* Create the nice widgets */
    cmdline     = command_new (0, 0, 0);
    the_prompt  = label_new (0, 0, prompt, NULL);
    the_prompt->transparent = 1;
    the_bar     = buttonbar_new (keybar_visible);

#ifndef HAVE_GNOME
    the_hint    = label_new (0, 0, 0, NULL);
    the_hint->transparent = 1;
    the_hint->auto_adjust_cols = 0;
    the_hint->widget.cols = COLS;
#endif

#ifndef HAVE_XVIEW
    the_menubar = menubar_new (0, 0, COLS, MenuBar, 5);
#else
    the_menubar = menubar_new (0, 0, COLS, MenuBar + 1, 3);
    the_bar2    = buttonbar_new (keybar_visible);
#endif
}
#endif

static void copy_current_pathname (void)
{
    if (!command_prompt)
	return;

    stuff (input_w (cmdline), cpanel->cwd, 0);
    if (cpanel->cwd [strlen (cpanel->cwd) - 1] != PATH_SEP)
        stuff (input_w (cmdline), PATH_SEP_STR, 0);
}

static void copy_other_pathname (void)
{
    if (get_other_type () != view_listing)
	return;

    if (!command_prompt)
	return;

    stuff (input_w (cmdline), opanel->cwd, 0);
    if (cpanel->cwd [strlen (opanel->cwd) - 1] != PATH_SEP)
        stuff (input_w (cmdline), PATH_SEP_STR, 0);
}

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);
	int i;

	i = mc_readlink (p, buffer, MC_MAXPATHLEN);
	free (p);
	if (i > 0) {
	    buffer [i] = 0;
	    stuff (input_w (cmdline), buffer, 0);
	}
    }
}

static void copy_current_readlink (void)
{
    copy_readlink (cpanel);
}

static void copy_other_readlink (void)
{
    if (get_other_type () != view_listing)
	return;
    copy_readlink (opanel);
}

/* Inserts the selected file name into the input line */
/* Exported so that the command modules uses it */
void copy_prog_name (void)
{
    char *tmp;
    if (!command_prompt)
	return;

    if (get_current_type () == view_tree){
	WTree *tree = (WTree *) get_panel_widget (get_current_index ());
	tmp = name_quote (tree->selected_ptr->name, 1);
    } else

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?