mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Code indentation in src directory
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
14e958a0a4
commit
1ff8b77f92
@ -18,4 +18,4 @@
|
||||
void chown_advanced_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__ACHOWN_H */
|
||||
|
@ -52,4 +52,4 @@ void unregister_task_with_pid (pid_t pid);
|
||||
|
||||
#endif /* !WITH_BACKGROUND */
|
||||
|
||||
#endif /* MC_BACKGROUND_H */
|
||||
#endif /* MC__BACKGROUND_H */
|
||||
|
@ -30,4 +30,4 @@ void symlink_dialog (const char *existing, const char *new, char **ret_existing,
|
||||
char *tree_box (const char *current_dir);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__BOXES_H */
|
||||
|
@ -106,4 +106,4 @@ convert_from_input_c (int c)
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
#endif /* MC_CHARSETS_H */
|
||||
#endif /* MC__CHARSETS_H */
|
||||
|
@ -18,4 +18,4 @@
|
||||
void chmod_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CHMOD_H */
|
||||
|
@ -18,4 +18,4 @@
|
||||
void chown_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CHOWN_H */
|
||||
|
@ -19,4 +19,4 @@ gboolean copy_file_to_ext_clip (void);
|
||||
gboolean paste_to_file_from_ext_clip (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CLIPBOARD_H */
|
||||
|
@ -101,4 +101,4 @@ void toggle_listing_cmd (void);
|
||||
void encoding_cmd (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__CMD_H */
|
||||
|
@ -524,4 +524,4 @@
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_CMD_DEF_H */
|
||||
#endif /* MC__CMD_DEF_H */
|
||||
|
@ -24,4 +24,4 @@ void do_cd_command (char *cmd);
|
||||
void command_insert (WInput * in, const char *text, int insert_extra_space);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
#endif /* MC__COMMAND_H */
|
||||
|
@ -37,13 +37,15 @@
|
||||
#include "wtools.h" /* Listbox */
|
||||
#include "dialog-switch.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
/* List of dialogs: filemanagers, editors, viewers */
|
||||
static GList *mc_dialogs = NULL;
|
||||
@ -52,7 +54,8 @@ static GList *mc_current = NULL;
|
||||
/* Is there any dialogs that we have to run after returning to the manager from another dialog */
|
||||
static gboolean dialog_switch_pending = FALSE;
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static unsigned char
|
||||
get_hotkey (int n)
|
||||
@ -60,6 +63,8 @@ get_hotkey (int n)
|
||||
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
dialog_switch_goto (GList * dlg)
|
||||
{
|
||||
@ -91,7 +96,9 @@ dialog_switch_goto (GList *dlg)
|
||||
}
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_add (Dlg_head * h)
|
||||
@ -109,6 +116,8 @@ dialog_switch_add (Dlg_head *h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_remove (Dlg_head * h)
|
||||
{
|
||||
@ -128,12 +137,16 @@ dialog_switch_remove (Dlg_head *h)
|
||||
mc_current = mc_dialogs;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
size_t
|
||||
dialog_switch_num (void)
|
||||
{
|
||||
return g_list_length (mc_dialogs);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_next (void)
|
||||
{
|
||||
@ -149,6 +162,8 @@ dialog_switch_next (void)
|
||||
dialog_switch_goto (next);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_prev (void)
|
||||
{
|
||||
@ -164,6 +179,8 @@ dialog_switch_prev (void)
|
||||
dialog_switch_goto (prev);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_list (void)
|
||||
{
|
||||
@ -209,6 +226,8 @@ dialog_switch_list (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
dialog_switch_process_pending (void)
|
||||
{
|
||||
@ -238,6 +257,8 @@ dialog_switch_process_pending (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_got_winch (void)
|
||||
{
|
||||
@ -248,6 +269,8 @@ dialog_switch_got_winch (void)
|
||||
((Dlg_head *) dlg->data)->winch_pending = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
dialog_switch_shutdown (void)
|
||||
{
|
||||
@ -259,3 +282,5 @@ dialog_switch_shutdown (void)
|
||||
destroy_dlg (dlg);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,11 +1,22 @@
|
||||
|
||||
#ifndef MC_DIALOG_SWITCH_H
|
||||
#define MC_DIALOG_SWITCH_H
|
||||
#ifndef MC__DIALOG_SWITCH_H
|
||||
#define MC__DIALOG_SWITCH_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void dialog_switch_add (struct Dlg_head *h);
|
||||
void dialog_switch_remove (struct Dlg_head *h);
|
||||
size_t dialog_switch_num (void);
|
||||
@ -18,4 +29,5 @@ int dialog_switch_process_pending (void);
|
||||
void dialog_switch_got_winch (void);
|
||||
void dialog_switch_shutdown (void);
|
||||
|
||||
#endif /* MC_DIALOG_SWITCH_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__DIALOG_SWITCH_H */
|
||||
|
1005
src/dialog.c
1005
src/dialog.c
File diff suppressed because it is too large
Load Diff
182
src/dialog.h
182
src/dialog.h
@ -24,8 +24,8 @@
|
||||
* \brief Header: dialog box features module
|
||||
*/
|
||||
|
||||
#ifndef MC_DIALOG_H
|
||||
#define MC_DIALOG_H
|
||||
#ifndef MC__DIALOG_H
|
||||
#define MC__DIALOG_H
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
#include "lib/tty/mouse.h"
|
||||
#include "lib/hook.h" /* hook_t */
|
||||
|
||||
/*** defined constants ***************************************************************************/
|
||||
|
||||
/* Common return values */
|
||||
#define B_EXIT 0
|
||||
#define B_CANCEL 1
|
||||
@ -40,7 +42,19 @@
|
||||
#define B_HELP 3
|
||||
#define B_USER 100
|
||||
|
||||
typedef struct Widget Widget;
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
||||
|
||||
/* Sets/clear the specified flag in the options field */
|
||||
#define widget_option(w,f,i) \
|
||||
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
|
||||
|
||||
#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
|
||||
#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
|
||||
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
|
||||
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Widget messages */
|
||||
typedef enum
|
||||
@ -111,23 +125,9 @@ typedef enum
|
||||
DLG_CLOSED = 2 /* Dialog is closed */
|
||||
} dlg_state_t;
|
||||
|
||||
/* Dialog callback */
|
||||
typedef struct Dlg_head Dlg_head;
|
||||
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender,
|
||||
dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* menu command execution */
|
||||
typedef cb_ret_t (*menu_exec_fn) (int command);
|
||||
|
||||
/* get string representation of shortcut assigned with command */
|
||||
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
||||
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||
|
||||
/* get dialog name to show in dialog list */
|
||||
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
||||
|
||||
/* Dialog color constants */
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
DLG_COLOR_NORMAL,
|
||||
DLG_COLOR_FOCUS,
|
||||
DLG_COLOR_HOT_NORMAL,
|
||||
@ -136,8 +136,54 @@ typedef enum {
|
||||
DLG_COLOR_COUNT
|
||||
} dlg_colors_enum_t;
|
||||
|
||||
/* widget options */
|
||||
typedef enum
|
||||
{
|
||||
W_WANT_HOTKEY = (1 << 1),
|
||||
W_WANT_CURSOR = (1 << 2),
|
||||
W_WANT_IDLE = (1 << 3),
|
||||
W_IS_INPUT = (1 << 4),
|
||||
W_DISABLED = (1 << 5) /* Widget cannot be selected */
|
||||
} widget_options_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
typedef enum
|
||||
{
|
||||
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
||||
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
||||
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
||||
WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
|
||||
WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
|
||||
WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
|
||||
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
|
||||
} widget_pos_flags_t;
|
||||
|
||||
/*** typedefs(not structures) ********************************************************************/
|
||||
|
||||
typedef struct Widget Widget;
|
||||
|
||||
/* Dialog callback */
|
||||
typedef struct Dlg_head Dlg_head;
|
||||
|
||||
/* get string representation of shortcut assigned with command */
|
||||
/* as menu is a widget of dialog, ask dialog about shortcut string */
|
||||
typedef char *(*dlg_shortcut_str) (unsigned long command);
|
||||
|
||||
/* get dialog name to show in dialog list */
|
||||
typedef char *(*dlg_title_str) (const Dlg_head * h, size_t len);
|
||||
|
||||
typedef int dlg_colors_t[DLG_COLOR_COUNT];
|
||||
|
||||
/* Widget callback */
|
||||
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
||||
|
||||
typedef cb_ret_t (*dlg_cb_fn) (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* menu command execution */
|
||||
typedef cb_ret_t (*menu_exec_fn) (int command);
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct Dlg_head
|
||||
{
|
||||
/* Set by the user */
|
||||
@ -172,35 +218,6 @@ struct Dlg_head
|
||||
struct Dlg_head *parent; /* Parent dialog */
|
||||
};
|
||||
|
||||
/* Color styles for normal and error dialogs */
|
||||
extern dlg_colors_t dialog_colors;
|
||||
extern dlg_colors_t alarm_colors;
|
||||
|
||||
/* Widget callback */
|
||||
typedef cb_ret_t (*callback_fn) (Widget * widget, widget_msg_t msg, int parm);
|
||||
|
||||
/* widget options */
|
||||
typedef enum
|
||||
{
|
||||
W_WANT_HOTKEY = (1 << 1),
|
||||
W_WANT_CURSOR = (1 << 2),
|
||||
W_WANT_IDLE = (1 << 3),
|
||||
W_IS_INPUT = (1 << 4),
|
||||
W_DISABLED = (1 << 5) /* Widget cannot be selected */
|
||||
} widget_options_t;
|
||||
|
||||
/* Flags for widget repositioning on dialog resize */
|
||||
typedef enum
|
||||
{
|
||||
WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */
|
||||
WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */
|
||||
WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */
|
||||
WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */
|
||||
WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT,
|
||||
WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM,
|
||||
WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT
|
||||
} widget_pos_flags_t;
|
||||
|
||||
/* Every Widget must have this as its first element */
|
||||
struct Widget
|
||||
{
|
||||
@ -214,6 +231,19 @@ struct Widget
|
||||
struct Dlg_head *owner;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* Color styles for normal and error dialogs */
|
||||
extern dlg_colors_t dialog_colors;
|
||||
extern dlg_colors_t alarm_colors;
|
||||
|
||||
extern GList *top_dlg;
|
||||
|
||||
/* A hook list for idle events */
|
||||
extern hook_t *idle_hook;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* draw box in window */
|
||||
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
|
||||
|
||||
@ -260,13 +290,28 @@ cb_ret_t default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int
|
||||
/* Default paint routine for dialogs */
|
||||
void common_dialog_repaint (Dlg_head * h);
|
||||
|
||||
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + _y, ((Widget *)(w))->x + _x)
|
||||
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + _y, ((Dlg_head *)(h))->x + _x)
|
||||
void dlg_replace_widget (Widget * old, Widget * new);
|
||||
int dlg_overlap (Widget * a, Widget * b);
|
||||
void widget_erase (Widget *);
|
||||
void dlg_erase (Dlg_head * h);
|
||||
void dlg_stop (Dlg_head * h);
|
||||
|
||||
extern GList *top_dlg;
|
||||
/* Widget selection */
|
||||
void dlg_select_widget (void *widget);
|
||||
void dlg_one_up (Dlg_head * h);
|
||||
void dlg_one_down (Dlg_head * h);
|
||||
int dlg_focus (Dlg_head * h);
|
||||
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||
Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
|
||||
void dlg_select_by_id (const Dlg_head * h, unsigned int id);
|
||||
|
||||
/* A hook list for idle events */
|
||||
extern hook_t *idle_hook;
|
||||
/* Redraw all dialogs */
|
||||
void do_refresh (void);
|
||||
|
||||
/* Used in load_prompt() */
|
||||
void update_cursor (Dlg_head * h);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline cb_ret_t
|
||||
send_message (Widget * w, widget_msg_t msg, int parm)
|
||||
@ -288,33 +333,4 @@ dlg_get_current_widget_id (const Dlg_head * h)
|
||||
return ((Widget *) h->current->data)->id;
|
||||
}
|
||||
|
||||
void dlg_replace_widget (Widget * old, Widget * new);
|
||||
int dlg_overlap (Widget * a, Widget * b);
|
||||
void widget_erase (Widget *);
|
||||
void dlg_erase (Dlg_head * h);
|
||||
void dlg_stop (Dlg_head * h);
|
||||
|
||||
/* Widget selection */
|
||||
void dlg_select_widget (void *widget);
|
||||
void dlg_one_up (Dlg_head * h);
|
||||
void dlg_one_down (Dlg_head * h);
|
||||
int dlg_focus (Dlg_head * h);
|
||||
Widget *find_widget_type (const Dlg_head * h, callback_fn callback);
|
||||
Widget *dlg_find_by_id (const Dlg_head * h, unsigned int id);
|
||||
void dlg_select_by_id (const Dlg_head * h, unsigned int id);
|
||||
|
||||
/* Redraw all dialogs */
|
||||
void do_refresh (void);
|
||||
|
||||
/* Sets/clear the specified flag in the options field */
|
||||
#define widget_option(w,f,i) \
|
||||
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))
|
||||
|
||||
#define widget_want_cursor(w,i) widget_option((w), W_WANT_CURSOR, (i))
|
||||
#define widget_want_hotkey(w,i) widget_option((w), W_WANT_HOTKEY, (i))
|
||||
#define widget_disable(w,i) widget_option((w), W_DISABLED, (i))
|
||||
|
||||
/* Used in load_prompt() */
|
||||
void update_cursor (Dlg_head * h);
|
||||
|
||||
#endif /* MC_DIALOG_H */
|
||||
#endif /* MC__DIALOG_H */
|
||||
|
406
src/dir.c
406
src/dir.c
@ -40,6 +40,19 @@
|
||||
#include "setup.h" /* panels_options */
|
||||
#include "layout.h" /* rotate_dash() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define MY_ISDIR(x) (\
|
||||
(is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && (exec_first == 1)) \
|
||||
? 1 \
|
||||
: ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 2 : 0) )
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Reverse flag */
|
||||
static int reverse = 1;
|
||||
|
||||
@ -49,7 +62,11 @@ static int case_sensitive = OS_SORT_CASE_SENSITIVE_DEFAULT;
|
||||
/* Are the exec_bit files top in list */
|
||||
static int exec_first = 1;
|
||||
|
||||
#define MY_ISDIR(x) ( (is_exe (x->st.st_mode) && !(S_ISDIR (x->st.st_mode) || x->f.link_to_dir) && (exec_first == 1)) ? 1 : ( (S_ISDIR (x->st.st_mode) || x->f.link_to_dir) ? 2 : 0) )
|
||||
static dir_list dir_copy = { 0, 0 };
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
sort_orders_t sort_orders [SORT_TYPES_TOTAL] = {
|
||||
{ N_("&Unsorted"), unsorted },
|
||||
@ -90,6 +107,128 @@ key_collate (const char *t1, const char *t2)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** clear keys, should be call after sorting is finished */
|
||||
|
||||
static void
|
||||
clean_sort_keys (dir_list * list, int start, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
str_release_key (list->list[i + start].sort_key, case_sensitive);
|
||||
list->list[i + start].sort_key = NULL;
|
||||
str_release_key (list->list[i + start].second_sort_key, case_sensitive);
|
||||
list->list[i + start].second_sort_key = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* If you change handle_dirent then check also handle_path.
|
||||
* @returns -1 = failure, 0 = don't add, 1 = add to the list
|
||||
*/
|
||||
|
||||
static int
|
||||
handle_dirent (dir_list * list, const char *fltr, struct dirent *dp,
|
||||
struct stat *buf1, int next_free, int *link_to_dir, int *stale_link)
|
||||
{
|
||||
if (dp->d_name[0] == '.' && dp->d_name[1] == 0)
|
||||
return 0;
|
||||
if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0)
|
||||
return 0;
|
||||
if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
|
||||
return 0;
|
||||
if (!panels_options.show_backups && dp->d_name[NLENGTH (dp) - 1] == '~')
|
||||
return 0;
|
||||
|
||||
if (mc_lstat (dp->d_name, buf1) == -1)
|
||||
{
|
||||
/*
|
||||
* lstat() fails - such entries should be identified by
|
||||
* buf1->st_mode being 0.
|
||||
* It happens on QNX Neutrino for /fs/cd0 if no CD is inserted.
|
||||
*/
|
||||
memset (buf1, 0, sizeof (*buf1));
|
||||
}
|
||||
|
||||
if (S_ISDIR (buf1->st_mode))
|
||||
tree_store_mark_checked (dp->d_name);
|
||||
|
||||
/* A link to a file or a directory? */
|
||||
*link_to_dir = 0;
|
||||
*stale_link = 0;
|
||||
if (S_ISLNK (buf1->st_mode))
|
||||
{
|
||||
struct stat buf2;
|
||||
if (!mc_stat (dp->d_name, &buf2))
|
||||
*link_to_dir = S_ISDIR (buf2.st_mode) != 0;
|
||||
else
|
||||
*stale_link = 1;
|
||||
}
|
||||
if (!(S_ISDIR (buf1->st_mode) || *link_to_dir) && (fltr != NULL)
|
||||
&& !mc_search (fltr, dp->d_name, MC_SEARCH_T_GLOB))
|
||||
return 0;
|
||||
|
||||
/* Need to grow the *list? */
|
||||
if (next_free == list->size)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
return -1;
|
||||
list->size += RESIZE_STEPS;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** get info about ".." */
|
||||
|
||||
static gboolean
|
||||
get_dotdot_dir_stat (const char *path, struct stat *st)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if ((path != NULL) && (path[0] != '\0') && (st != NULL))
|
||||
{
|
||||
char *dotdot_dir;
|
||||
struct stat s;
|
||||
|
||||
dotdot_dir = g_strdup_printf ("%s/../", path);
|
||||
canonicalize_pathname (dotdot_dir);
|
||||
ret = mc_stat (dotdot_dir, &s) == 0;
|
||||
g_free (dotdot_dir);
|
||||
*st = s;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
alloc_dir_copy (int size)
|
||||
{
|
||||
if (dir_copy.size < size)
|
||||
{
|
||||
if (dir_copy.list)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < dir_copy.size; i++)
|
||||
g_free (dir_copy.list[i].fname);
|
||||
g_free (dir_copy.list);
|
||||
}
|
||||
|
||||
dir_copy.list = g_new0 (file_entry, size);
|
||||
dir_copy.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
unsorted (file_entry * a, file_entry * b)
|
||||
{
|
||||
@ -98,13 +237,16 @@ unsorted (file_entry *a, file_entry *b)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_name (file_entry * a, file_entry * b)
|
||||
{
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
/* create key if does not exist, key will be freed after sorting */
|
||||
if (a->sort_key == NULL)
|
||||
a->sort_key = str_create_key_for_filename (a->fname, case_sensitive);
|
||||
@ -116,19 +258,26 @@ sort_name (file_entry *a, file_entry *b)
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_vers (file_entry * a, file_entry * b)
|
||||
{
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
return str_verscmp (a->fname, b->fname) * reverse;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return bd - ad;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_ext (file_entry * a, file_entry * b)
|
||||
{
|
||||
@ -136,7 +285,8 @@ sort_ext (file_entry *a, file_entry *b)
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
if (a->second_sort_key == NULL)
|
||||
a->second_sort_key = str_create_key (extension (a->fname), case_sensitive);
|
||||
if (b->second_sort_key == NULL)
|
||||
@ -147,19 +297,22 @@ sort_ext (file_entry *a, file_entry *b)
|
||||
return r * reverse;
|
||||
else
|
||||
return sort_name (a, b);
|
||||
} else
|
||||
}
|
||||
else
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_time (file_entry * a, file_entry * b)
|
||||
{
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
int result = a->st.st_mtime < b->st.st_mtime ? -1 :
|
||||
a->st.st_mtime > b->st.st_mtime;
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
int result = a->st.st_mtime < b->st.st_mtime ? -1 : a->st.st_mtime > b->st.st_mtime;
|
||||
if (result != 0)
|
||||
return result * reverse;
|
||||
else
|
||||
@ -169,15 +322,17 @@ sort_time (file_entry *a, file_entry *b)
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_ctime (file_entry * a, file_entry * b)
|
||||
{
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
int result = a->st.st_ctime < b->st.st_ctime ? -1 :
|
||||
a->st.st_ctime > b->st.st_ctime;
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
int result = a->st.st_ctime < b->st.st_ctime ? -1 : a->st.st_ctime > b->st.st_ctime;
|
||||
if (result != 0)
|
||||
return result * reverse;
|
||||
else
|
||||
@ -187,15 +342,17 @@ sort_ctime (file_entry *a, file_entry *b)
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_atime (file_entry * a, file_entry * b)
|
||||
{
|
||||
int ad = MY_ISDIR (a);
|
||||
int bd = MY_ISDIR (b);
|
||||
|
||||
if (ad == bd || panels_options.mix_all_files) {
|
||||
int result = a->st.st_atime < b->st.st_atime ? -1 :
|
||||
a->st.st_atime > b->st.st_atime;
|
||||
if (ad == bd || panels_options.mix_all_files)
|
||||
{
|
||||
int result = a->st.st_atime < b->st.st_atime ? -1 : a->st.st_atime > b->st.st_atime;
|
||||
if (result != 0)
|
||||
return result * reverse;
|
||||
else
|
||||
@ -205,6 +362,8 @@ sort_atime (file_entry *a, file_entry *b)
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_inode (file_entry * a, file_entry * b)
|
||||
{
|
||||
@ -217,6 +376,8 @@ sort_inode (file_entry *a, file_entry *b)
|
||||
return bd - ad;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
sort_size (file_entry * a, file_entry * b)
|
||||
{
|
||||
@ -227,31 +388,18 @@ sort_size (file_entry *a, file_entry *b)
|
||||
if (ad != bd && !panels_options.mix_all_files)
|
||||
return bd - ad;
|
||||
|
||||
result = a->st.st_size < b->st.st_size ? -1 :
|
||||
a->st.st_size > b->st.st_size;
|
||||
result = a->st.st_size < b->st.st_size ? -1 : a->st.st_size > b->st.st_size;
|
||||
if (result != 0)
|
||||
return result * reverse;
|
||||
else
|
||||
return sort_name (a, b);
|
||||
}
|
||||
|
||||
/* clear keys, should be call after sorting is finished */
|
||||
static void
|
||||
clean_sort_keys (dir_list *list, int start, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++){
|
||||
str_release_key (list->list [i + start].sort_key, case_sensitive);
|
||||
list->list [i + start].sort_key = NULL;
|
||||
str_release_key (list->list [i + start].second_sort_key, case_sensitive);
|
||||
list->list [i + start].second_sort_key = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitive_f, int exec_first_f)
|
||||
do_sort (dir_list * list, sortfn * sort, int top, int reverse_f, int case_sensitive_f,
|
||||
int exec_first_f)
|
||||
{
|
||||
int dot_dot_found = 0;
|
||||
|
||||
@ -266,31 +414,35 @@ do_sort (dir_list *list, sortfn *sort, int top, int reverse_f, int case_sensitiv
|
||||
reverse = reverse_f ? -1 : 1;
|
||||
case_sensitive = case_sensitive_f;
|
||||
exec_first = exec_first_f;
|
||||
qsort (&(list->list) [dot_dot_found],
|
||||
top + 1 - dot_dot_found, sizeof (file_entry), sort);
|
||||
qsort (&(list->list)[dot_dot_found], top + 1 - dot_dot_found, sizeof (file_entry), sort);
|
||||
|
||||
clean_sort_keys (list, dot_dot_found, top + 1 - dot_dot_found);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
clean_dir (dir_list * list, int count)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < count; i++){
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
g_free (list->list[i].fname);
|
||||
list->list[i].fname = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Used to set up a directory list when there is no access to a directory */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Used to set up a directory list when there is no access to a directory */
|
||||
|
||||
gboolean
|
||||
set_zero_dir (dir_list * list)
|
||||
{
|
||||
/* Need to grow the *list? */
|
||||
if (list->size == 0) {
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) *
|
||||
(list->size + RESIZE_STEPS));
|
||||
if (list->size == 0)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
return FALSE;
|
||||
|
||||
@ -308,89 +460,18 @@ set_zero_dir (dir_list *list)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If you change handle_dirent then check also handle_path. */
|
||||
/* Return values: -1 = failure, 0 = don't add, 1 = add to the list */
|
||||
static int
|
||||
handle_dirent (dir_list *list, const char *fltr, struct dirent *dp,
|
||||
struct stat *buf1, int next_free, int *link_to_dir,
|
||||
int *stale_link)
|
||||
{
|
||||
if (dp->d_name[0] == '.' && dp->d_name[1] == 0)
|
||||
return 0;
|
||||
if (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == 0)
|
||||
return 0;
|
||||
if (!panels_options.show_dot_files && (dp->d_name[0] == '.'))
|
||||
return 0;
|
||||
if (!panels_options.show_backups && dp->d_name[NLENGTH (dp) - 1] == '~')
|
||||
return 0;
|
||||
|
||||
if (mc_lstat (dp->d_name, buf1) == -1) {
|
||||
/*
|
||||
* lstat() fails - such entries should be identified by
|
||||
* buf1->st_mode being 0.
|
||||
* It happens on QNX Neutrino for /fs/cd0 if no CD is inserted.
|
||||
*/
|
||||
memset (buf1, 0, sizeof (*buf1));
|
||||
}
|
||||
|
||||
if (S_ISDIR (buf1->st_mode))
|
||||
tree_store_mark_checked (dp->d_name);
|
||||
|
||||
/* A link to a file or a directory? */
|
||||
*link_to_dir = 0;
|
||||
*stale_link = 0;
|
||||
if (S_ISLNK (buf1->st_mode)) {
|
||||
struct stat buf2;
|
||||
if (!mc_stat (dp->d_name, &buf2))
|
||||
*link_to_dir = S_ISDIR (buf2.st_mode) != 0;
|
||||
else
|
||||
*stale_link = 1;
|
||||
}
|
||||
if (!(S_ISDIR (buf1->st_mode) || *link_to_dir) && (fltr != NULL)
|
||||
&& !mc_search (fltr, dp->d_name, MC_SEARCH_T_GLOB))
|
||||
return 0;
|
||||
|
||||
/* Need to grow the *list? */
|
||||
if (next_free == list->size) {
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) *
|
||||
(list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
return -1;
|
||||
list->size += RESIZE_STEPS;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* get info about ".." */
|
||||
static gboolean
|
||||
get_dotdot_dir_stat (const char *path, struct stat *st)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
|
||||
if ((path != NULL) && (path[0] != '\0') && (st != NULL)) {
|
||||
char *dotdot_dir;
|
||||
struct stat s;
|
||||
|
||||
dotdot_dir = g_strdup_printf ("%s/../", path);
|
||||
canonicalize_pathname (dotdot_dir);
|
||||
ret = mc_stat (dotdot_dir, &s) == 0;
|
||||
g_free (dotdot_dir);
|
||||
*st = s;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* handle_path is a simplified handle_dirent. The difference is that
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
handle_path is a simplified handle_dirent. The difference is that
|
||||
handle_path doesn't pay attention to panels_options.show_dot_files
|
||||
and panels_options.show_backups.
|
||||
Moreover handle_path can't be used with a filemask.
|
||||
If you change handle_path then check also handle_dirent. */
|
||||
/* Return values: -1 = failure, 0 = don't add, 1 = add to the list */
|
||||
|
||||
int
|
||||
handle_path (dir_list * list, const char *path,
|
||||
struct stat *buf1, int next_free, int *link_to_dir,
|
||||
int *stale_link)
|
||||
struct stat *buf1, int next_free, int *link_to_dir, int *stale_link)
|
||||
{
|
||||
if (path[0] == '.' && path[1] == 0)
|
||||
return 0;
|
||||
@ -405,7 +486,8 @@ handle_path (dir_list *list, const char *path,
|
||||
/* A link to a file or a directory? */
|
||||
*link_to_dir = 0;
|
||||
*stale_link = 0;
|
||||
if (S_ISLNK(buf1->st_mode)){
|
||||
if (S_ISLNK (buf1->st_mode))
|
||||
{
|
||||
struct stat buf2;
|
||||
if (!mc_stat (path, &buf2))
|
||||
*link_to_dir = S_ISDIR (buf2.st_mode) != 0;
|
||||
@ -414,9 +496,9 @@ handle_path (dir_list *list, const char *path,
|
||||
}
|
||||
|
||||
/* Need to grow the *list? */
|
||||
if (next_free == list->size){
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) *
|
||||
(list->size + RESIZE_STEPS));
|
||||
if (next_free == list->size)
|
||||
{
|
||||
list->list = g_try_realloc (list->list, sizeof (file_entry) * (list->size + RESIZE_STEPS));
|
||||
if (list->list == NULL)
|
||||
return -1;
|
||||
list->size += RESIZE_STEPS;
|
||||
@ -424,6 +506,8 @@ handle_path (dir_list *list, const char *path,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
do_load_dir (const char *path, dir_list * list, sortfn * sort, int lc_reverse,
|
||||
int lc_case_sensitive, int exec_ff, const char *fltr)
|
||||
@ -443,7 +527,8 @@ do_load_dir (const char *path, dir_list *list, sortfn *sort, int lc_reverse,
|
||||
next_free++;
|
||||
|
||||
dirp = mc_opendir (path);
|
||||
if (!dirp) {
|
||||
if (!dirp)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
|
||||
return next_free;
|
||||
}
|
||||
@ -454,13 +539,13 @@ do_load_dir (const char *path, dir_list *list, sortfn *sort, int lc_reverse,
|
||||
if ((path[0] == PATH_SEP) && (path[1] == '\0'))
|
||||
next_free--;
|
||||
|
||||
while ((dp = mc_readdir (dirp))) {
|
||||
status =
|
||||
handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir,
|
||||
&stale_link);
|
||||
while ((dp = mc_readdir (dirp)))
|
||||
{
|
||||
status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link);
|
||||
if (status == 0)
|
||||
continue;
|
||||
if (status == -1) {
|
||||
if (status == -1)
|
||||
{
|
||||
tree_store_end_check ();
|
||||
mc_closedir (dirp);
|
||||
return next_free;
|
||||
@ -488,6 +573,8 @@ do_load_dir (const char *path, dir_list *list, sortfn *sort, int lc_reverse,
|
||||
return next_free;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
link_isdir (const file_entry * file)
|
||||
{
|
||||
@ -497,36 +584,24 @@ link_isdir (const file_entry *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
if_link_is_exe (const char *full_name, const file_entry * file)
|
||||
{
|
||||
struct stat b;
|
||||
|
||||
if (S_ISLNK (file->st.st_mode) && !mc_stat (full_name, &b)) {
|
||||
if (S_ISLNK (file->st.st_mode) && !mc_stat (full_name, &b))
|
||||
{
|
||||
return is_exe (b.st_mode);
|
||||
} else
|
||||
}
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
static dir_list dir_copy = { 0, 0 };
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** If fltr is null, then it is a match */
|
||||
|
||||
static void
|
||||
alloc_dir_copy (int size)
|
||||
{
|
||||
if (dir_copy.size < size) {
|
||||
if (dir_copy.list) {
|
||||
int i;
|
||||
for (i = 0; i < dir_copy.size; i++)
|
||||
g_free (dir_copy.list [i].fname);
|
||||
g_free (dir_copy.list);
|
||||
}
|
||||
|
||||
dir_copy.list = g_new0 (file_entry, size);
|
||||
dir_copy.size = size;
|
||||
}
|
||||
}
|
||||
|
||||
/* If fltr is null, then it is a match */
|
||||
int
|
||||
do_reload_dir (const char *path, dir_list * list, sortfn * sort, int count,
|
||||
int rev, int lc_case_sensitive, int exec_ff, const char *fltr)
|
||||
@ -540,7 +615,8 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
||||
GHashTable *marked_files;
|
||||
|
||||
dirp = mc_opendir (path);
|
||||
if (!dirp) {
|
||||
if (!dirp)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot read directory contents"));
|
||||
clean_dir (list, count);
|
||||
return set_zero_dir (list) ? 1 : 0;
|
||||
@ -549,27 +625,29 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
||||
tree_store_start_check (path);
|
||||
marked_files = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
alloc_dir_copy (list->size);
|
||||
for (marked_cnt = i = 0; i < count; i++) {
|
||||
for (marked_cnt = i = 0; i < count; i++)
|
||||
{
|
||||
dir_copy.list[i].fnamelen = list->list[i].fnamelen;
|
||||
dir_copy.list[i].fname = list->list[i].fname;
|
||||
dir_copy.list[i].f.marked = list->list[i].f.marked;
|
||||
dir_copy.list[i].f.dir_size_computed =
|
||||
list->list[i].f.dir_size_computed;
|
||||
dir_copy.list[i].f.dir_size_computed = list->list[i].f.dir_size_computed;
|
||||
dir_copy.list[i].f.link_to_dir = list->list[i].f.link_to_dir;
|
||||
dir_copy.list[i].f.stale_link = list->list[i].f.stale_link;
|
||||
dir_copy.list[i].sort_key = NULL;
|
||||
dir_copy.list[i].second_sort_key = NULL;
|
||||
if (list->list[i].f.marked) {
|
||||
g_hash_table_insert (marked_files, dir_copy.list[i].fname,
|
||||
&dir_copy.list[i]);
|
||||
if (list->list[i].f.marked)
|
||||
{
|
||||
g_hash_table_insert (marked_files, dir_copy.list[i].fname, &dir_copy.list[i]);
|
||||
marked_cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add ".." except to the root directory. The ".." entry
|
||||
(if any) must be the first in the list. */
|
||||
if (!((path[0] == PATH_SEP) && (path[1] == '\0'))) {
|
||||
if (!set_zero_dir (list)) {
|
||||
if (!((path[0] == PATH_SEP) && (path[1] == '\0')))
|
||||
{
|
||||
if (!set_zero_dir (list))
|
||||
{
|
||||
clean_dir (list, count);
|
||||
clean_dir (&dir_copy, count);
|
||||
return next_free;
|
||||
@ -581,13 +659,13 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
||||
next_free++;
|
||||
}
|
||||
|
||||
while ((dp = mc_readdir (dirp))) {
|
||||
status =
|
||||
handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir,
|
||||
&stale_link);
|
||||
while ((dp = mc_readdir (dirp)))
|
||||
{
|
||||
status = handle_dirent (list, fltr, dp, &st, next_free, &link_to_dir, &stale_link);
|
||||
if (status == 0)
|
||||
continue;
|
||||
if (status == -1) {
|
||||
if (status == -1)
|
||||
{
|
||||
mc_closedir (dirp);
|
||||
/* Norbert (Feb 12, 1997):
|
||||
Just in case someone finds this memory leak:
|
||||
@ -611,8 +689,10 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
||||
* to find matching file. Decrease number of remaining marks if
|
||||
* we copied one.
|
||||
*/
|
||||
if (marked_cnt > 0) {
|
||||
if ((g_hash_table_lookup (marked_files, dp->d_name))) {
|
||||
if (marked_cnt > 0)
|
||||
{
|
||||
if ((g_hash_table_lookup (marked_files, dp->d_name)))
|
||||
{
|
||||
list->list[next_free].f.marked = 1;
|
||||
marked_cnt--;
|
||||
}
|
||||
@ -633,10 +713,12 @@ do_reload_dir (const char *path, dir_list *list, sortfn *sort, int count,
|
||||
mc_closedir (dirp);
|
||||
tree_store_end_check ();
|
||||
g_hash_table_destroy (marked_files);
|
||||
if (next_free) {
|
||||
if (next_free)
|
||||
{
|
||||
do_sort (list, sort, next_free - 1, rev, lc_case_sensitive, exec_ff);
|
||||
}
|
||||
clean_dir (&dir_copy, count);
|
||||
return next_free;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
30
src/dir.h
30
src/dir.h
@ -1,20 +1,28 @@
|
||||
|
||||
/** \file dir.h
|
||||
* \brief Header: directory routines
|
||||
*/
|
||||
|
||||
#ifndef MC_DIR_H
|
||||
#define MC_DIR_H
|
||||
#ifndef MC__DIR_H
|
||||
#define MC__DIR_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define MIN_FILES 128
|
||||
#define RESIZE_STEPS 128
|
||||
|
||||
typedef int sortfn (const void *, const void *);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* keys are set only during sorting */
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/* File attributes */
|
||||
size_t fnamelen;
|
||||
char *fname;
|
||||
@ -25,7 +33,8 @@ typedef struct {
|
||||
char *second_sort_key;
|
||||
|
||||
/* Flags */
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
unsigned int marked:1; /* File marked in pane window */
|
||||
unsigned int link_to_dir:1; /* If this is a link, does it point to directory? */
|
||||
unsigned int stale_link:1; /* If this is a symlink and points to Charon's land */
|
||||
@ -33,12 +42,15 @@ typedef struct {
|
||||
} f;
|
||||
} file_entry;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
file_entry *list;
|
||||
int size;
|
||||
} dir_list;
|
||||
|
||||
typedef int sortfn (const void *, const void *);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int do_load_dir (const char *path, dir_list * list, sortfn * sort, int reverse,
|
||||
int case_sensitive, int exec_ff, const char *fltr);
|
||||
@ -62,8 +74,8 @@ int sort_ctime (file_entry *a, file_entry *b);
|
||||
int sort_size (file_entry * a, file_entry * b);
|
||||
int sort_inode (file_entry * a, file_entry * b);
|
||||
|
||||
|
||||
int link_isdir (const file_entry *);
|
||||
int if_link_is_exe (const char *full_name, const file_entry * file);
|
||||
|
||||
#endif /* MC_DIR_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__DIR_H */
|
||||
|
127
src/execute.c
127
src/execute.c
@ -41,6 +41,16 @@
|
||||
#include "execute.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edition_post_exec (void)
|
||||
@ -59,6 +69,7 @@ edition_post_exec (void)
|
||||
application_keypad_mode ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
edition_pre_exec (void)
|
||||
@ -89,23 +100,7 @@ edition_pre_exec (void)
|
||||
do_exit_ca_mode ();
|
||||
}
|
||||
|
||||
|
||||
/* Set up the terminal before executing a program */
|
||||
void
|
||||
pre_exec (void)
|
||||
{
|
||||
use_dash (FALSE);
|
||||
edition_pre_exec ();
|
||||
}
|
||||
|
||||
/* Hide the terminal after executing a program */
|
||||
void
|
||||
post_exec (void)
|
||||
{
|
||||
edition_post_exec ();
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
static void
|
||||
@ -120,6 +115,8 @@ do_possible_cd (const char *new_dir)
|
||||
}
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_execute (const char *lc_shell, const char *command, int flags)
|
||||
{
|
||||
@ -208,8 +205,63 @@ do_execute (const char *lc_shell, const char *command, int flags)
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_suspend_cmd (void)
|
||||
{
|
||||
pre_exec ();
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_RESTORE);
|
||||
|
||||
#ifdef SIGTSTP
|
||||
{
|
||||
struct sigaction sigtstp_action;
|
||||
|
||||
/* Make sure that the SIGTSTP below will suspend us directly,
|
||||
without calling ncurses' SIGTSTP handler; we *don't* want
|
||||
ncurses to redraw the screen immediately after the SIGCONT */
|
||||
sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
|
||||
|
||||
kill (getpid (), SIGTSTP);
|
||||
|
||||
/* Restore previous SIGTSTP action */
|
||||
sigaction (SIGTSTP, &sigtstp_action, NULL);
|
||||
}
|
||||
#endif /* SIGTSTP */
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_SAVE);
|
||||
|
||||
edition_post_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Set up the terminal before executing a program */
|
||||
|
||||
void
|
||||
pre_exec (void)
|
||||
{
|
||||
use_dash (FALSE);
|
||||
edition_pre_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Hide the terminal after executing a program */
|
||||
void
|
||||
post_exec (void)
|
||||
{
|
||||
edition_post_exec ();
|
||||
use_dash (TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Executes a command */
|
||||
|
||||
void
|
||||
shell_execute (const char *command, int flags)
|
||||
{
|
||||
@ -234,6 +286,7 @@ shell_execute (const char *command, int flags)
|
||||
g_free (cmd);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
exec_shell (void)
|
||||
@ -241,6 +294,7 @@ exec_shell (void)
|
||||
do_execute (shell, 0, 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
toggle_panels (void)
|
||||
@ -340,37 +394,7 @@ toggle_panels (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
do_suspend_cmd (void)
|
||||
{
|
||||
pre_exec ();
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_RESTORE);
|
||||
|
||||
#ifdef SIGTSTP
|
||||
{
|
||||
struct sigaction sigtstp_action;
|
||||
|
||||
/* Make sure that the SIGTSTP below will suspend us directly,
|
||||
without calling ncurses' SIGTSTP handler; we *don't* want
|
||||
ncurses to redraw the screen immediately after the SIGCONT */
|
||||
sigaction (SIGTSTP, &startup_handler, &sigtstp_action);
|
||||
|
||||
kill (getpid (), SIGTSTP);
|
||||
|
||||
/* Restore previous SIGTSTP action */
|
||||
sigaction (SIGTSTP, &sigtstp_action, NULL);
|
||||
}
|
||||
#endif /* SIGTSTP */
|
||||
|
||||
if (console_flag && !use_subshell)
|
||||
handle_console (CONSOLE_SAVE);
|
||||
|
||||
edition_post_exec ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
suspend_cmd (void)
|
||||
@ -383,11 +407,12 @@ suspend_cmd (void)
|
||||
do_refresh ();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Execute command on a filename that can be on VFS.
|
||||
* Errors are reported to the user.
|
||||
*/
|
||||
|
||||
void
|
||||
execute_with_vfs_arg (const char *command, const char *filename)
|
||||
{
|
||||
@ -430,3 +455,5 @@ execute_with_vfs_arg (const char *command, const char *filename)
|
||||
g_free (localcopy);
|
||||
g_free (fn);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,16 +1,25 @@
|
||||
|
||||
/** \file execute.h
|
||||
* \brief Header: execution routines
|
||||
*/
|
||||
|
||||
#ifndef MC_EXECUTE_H
|
||||
#define MC_EXECUTE_H
|
||||
#ifndef MC__EXECUTE_H
|
||||
#define MC__EXECUTE_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* flags for shell_execute */
|
||||
#define EXECUTE_INTERNAL (1 << 0)
|
||||
#define EXECUTE_AS_SHELL (1 << 2)
|
||||
#define EXECUTE_HIDE (1 << 3)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Execute functions that use the shell to execute */
|
||||
void shell_execute (const char *command, int flags);
|
||||
|
||||
@ -29,4 +38,5 @@ void execute_with_vfs_arg (const char *command, const char *filename);
|
||||
void post_exec (void);
|
||||
void pre_exec (void);
|
||||
|
||||
#endif /* MC_EXECUTE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__EXECUTE_H */
|
||||
|
72
src/ext.c
72
src/ext.c
@ -55,23 +55,33 @@
|
||||
#include "dialog-switch.h"
|
||||
#include "ext.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* If set, we execute the file command to check the file type */
|
||||
int use_file_to_check_type = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifdef FILE_L
|
||||
#define FILE_CMD "file -L "
|
||||
#else
|
||||
#define FILE_CMD "file "
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef char *(*quote_func_t) (const char *name, int quote_percent);
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* This variable points to a copy of the mc.ext file in memory
|
||||
* With this we avoid loading/parsing the file each time we
|
||||
* need it
|
||||
*/
|
||||
static char *data = NULL;
|
||||
|
||||
void
|
||||
flush_extension_file (void)
|
||||
{
|
||||
g_free (data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
typedef char *(*quote_func_t) (const char *name, int quote_percent);
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
exec_extension (const char *filename, const char *lc_data, int *move_dir, int start_line)
|
||||
@ -134,8 +144,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
||||
char *parameter;
|
||||
|
||||
parameter_found = 0;
|
||||
parameter =
|
||||
input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
|
||||
parameter = input_dialog (_("Parameter"), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
|
||||
if (parameter == NULL)
|
||||
{
|
||||
/* User canceled */
|
||||
@ -364,19 +373,15 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FILE_L
|
||||
# define FILE_CMD "file -L "
|
||||
#else
|
||||
# define FILE_CMD "file "
|
||||
#endif
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run cmd_file with args, put result into buf.
|
||||
* If error, put '\0' into buf[0]
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*
|
||||
* NOTES: buf is null-terminated string.
|
||||
*/
|
||||
|
||||
static int
|
||||
get_popen_information (const char *cmd_file, const char *args, char *buf, int buflen)
|
||||
{
|
||||
@ -413,10 +418,12 @@ get_popen_information (const char *cmd_file, const char *args, char *buf, int bu
|
||||
return read_bytes ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run the "file" command on the local file.
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*/
|
||||
|
||||
static int
|
||||
get_file_type_local (const char *filename, char *buf, int buflen)
|
||||
{
|
||||
@ -430,11 +437,13 @@ get_file_type_local (const char *filename, char *buf, int buflen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Run the "enca" command on the local file.
|
||||
* Return 1 if the data is valid, 0 otherwise, -1 for fatal errors.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CHARSET
|
||||
static int
|
||||
get_file_encoding_local (const char *filename, char *buf, int buflen)
|
||||
{
|
||||
@ -455,12 +464,14 @@ get_file_encoding_local (const char *filename, char *buf, int buflen)
|
||||
}
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Invoke the "file" command on the file and match its output against PTR.
|
||||
* have_type is a flag that is set if we already have tried to determine
|
||||
* the type of that file.
|
||||
* Return 1 for match, 0 for no match, -1 errors.
|
||||
*/
|
||||
|
||||
static int
|
||||
regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
{
|
||||
@ -563,8 +574,20 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
return found;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* The second argument is action, i.e. Open, View or Edit
|
||||
void
|
||||
flush_extension_file (void)
|
||||
{
|
||||
g_free (data);
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* The second argument is action, i.e. Open, View or Edit
|
||||
*
|
||||
* This function returns:
|
||||
*
|
||||
@ -575,6 +598,7 @@ regex_check_type (const char *filename, const char *ptr, int *have_type)
|
||||
* If action == "View" then a parameter is checked in the form of "View:%d",
|
||||
* if the value for %d exists, then the viewer is started up at that line number.
|
||||
*/
|
||||
|
||||
int
|
||||
regex_command (const char *filename, const char *action, int *move_dir)
|
||||
{
|
||||
@ -651,8 +675,7 @@ regex_command (const char *filename, const char *action, int *move_dir)
|
||||
}
|
||||
if (home_error)
|
||||
{
|
||||
char *title =
|
||||
g_strdup_printf (_("~/%s file error"),
|
||||
char *title = g_strdup_printf (_("~/%s file error"),
|
||||
MC_USERCONF_DIR PATH_SEP_STR MC_FILEBIND_FILE);
|
||||
message (D_ERROR, title,
|
||||
_("The format of the ~/%s file has "
|
||||
@ -812,3 +835,4 @@ regex_command (const char *filename, const char *action, int *move_dir)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
17
src/ext.h
17
src/ext.h
@ -1,10 +1,18 @@
|
||||
|
||||
/** \file ext.h
|
||||
* \brief Header: extension dependent execution
|
||||
*/
|
||||
|
||||
#ifndef MC_EXT_H
|
||||
#define MC_EXT_H
|
||||
#ifndef MC__EXT_H
|
||||
#define MC__EXT_H
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
int regex_command (const char *filename, const char *action, int *move_dir);
|
||||
|
||||
@ -13,4 +21,5 @@ int regex_command (const char *filename, const char *action, int *move_dir);
|
||||
*/
|
||||
void flush_extension_file (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__EXT_H */
|
||||
|
1550
src/file.c
1550
src/file.c
File diff suppressed because it is too large
Load Diff
43
src/file.h
43
src/file.h
@ -1,10 +1,9 @@
|
||||
|
||||
/** \file file.h
|
||||
* \brief Header: File and directory operation routines
|
||||
*/
|
||||
|
||||
#ifndef MC_FILE_H
|
||||
#define MC_FILE_H
|
||||
#ifndef MC__FILE_H
|
||||
#define MC__FILE_H
|
||||
|
||||
#include <sys/types.h> /* off_t */
|
||||
#include <sys/time.h>
|
||||
@ -14,8 +13,31 @@
|
||||
#include "widget.h" /* WLabel */
|
||||
#include "fileopctx.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Compute directory size */
|
||||
/* callback to update status dialog */
|
||||
typedef FileProgressStatus (*compute_dir_size_callback) (const void *ui, const char *dirname);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct link;
|
||||
|
||||
/* status dialog of directory size computing */
|
||||
typedef struct
|
||||
{
|
||||
Dlg_head *dlg;
|
||||
WLabel *dirname;
|
||||
} ComputeDirSizeUI;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int file_op_compute_totals;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
FileProgressStatus copy_file_file (FileOpTotalContext * tctx, FileOpContext * ctx,
|
||||
const char *src_path, const char *dst_path);
|
||||
FileProgressStatus move_dir_dir (FileOpTotalContext * tctx, FileOpContext * ctx,
|
||||
@ -28,32 +50,21 @@ FileProgressStatus erase_dir (FileOpTotalContext * tctx, FileOpContext * ctx, co
|
||||
|
||||
gboolean panel_operate (void *source_panel, FileOperation op, gboolean force_single);
|
||||
|
||||
extern int file_op_compute_totals;
|
||||
|
||||
/* Error reporting routines */
|
||||
|
||||
/* Report error with one file */
|
||||
FileProgressStatus file_error (const char *format, const char *file);
|
||||
|
||||
/* Compute directory size */
|
||||
/* callback to update status dialog */
|
||||
typedef FileProgressStatus (*compute_dir_size_callback) (const void *ui, const char *dirname);
|
||||
|
||||
/* return value is FILE_CONT or FILE_ABORT */
|
||||
FileProgressStatus compute_dir_size (const char *dirname, const void *ui,
|
||||
compute_dir_size_callback cback,
|
||||
off_t * ret_marked, double *ret_total,
|
||||
gboolean compute_symlinks);
|
||||
|
||||
/* status dialog of directory size computing */
|
||||
typedef struct
|
||||
{
|
||||
Dlg_head *dlg;
|
||||
WLabel *dirname;
|
||||
} ComputeDirSizeUI;
|
||||
|
||||
ComputeDirSizeUI *compute_dir_size_create_ui (void);
|
||||
void compute_dir_size_destroy_ui (ComputeDirSizeUI * ui);
|
||||
FileProgressStatus compute_dir_size_update_ui (const void *ui, const char *dirname);
|
||||
|
||||
#endif /* MC_FILE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILE_H */
|
||||
|
837
src/filegui.c
837
src/filegui.c
@ -97,6 +97,26 @@
|
||||
#include "filegui.h"
|
||||
|
||||
/* }}} */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int classic_progressbar = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* Hack: the vfs code should not rely on this */
|
||||
#define WITH_FULL_PATHS 1
|
||||
|
||||
/* File operate window sizes */
|
||||
#define WX 58
|
||||
#define WY 11
|
||||
#define FCOPY_LABEL_X 3
|
||||
|
||||
#define truncFileString(ui, s) str_trunc (s, 52)
|
||||
#define truncFileStringSecure(ui, s) path_trunc (s, 52)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
typedef enum {
|
||||
MSDOS_SUPER_MAGIC = 0x4d44,
|
||||
@ -109,9 +129,6 @@ typedef enum {
|
||||
} filegui_nonattrs_fs_t;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* Hack: the vfs code should not rely on this */
|
||||
#define WITH_FULL_PATHS 1
|
||||
|
||||
/* Used for button result values */
|
||||
typedef enum
|
||||
{
|
||||
@ -156,15 +173,13 @@ typedef struct
|
||||
struct stat *s_stat, *d_stat;
|
||||
} FileOpContextUI;
|
||||
|
||||
int classic_progressbar = 1;
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Used to save the hint line */
|
||||
static int last_hint_line;
|
||||
|
||||
/* File operate window sizes */
|
||||
#define WX 58
|
||||
#define WY 11
|
||||
#define FCOPY_LABEL_X 3
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
filegui__check_attrs_on_fs (const char *fs_path)
|
||||
@ -210,182 +225,7 @@ filegui__check_attrs_on_fs (const char *fs_path)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
FileProgressStatus
|
||||
check_progress_buttons (FileOpContext * ctx)
|
||||
{
|
||||
int c;
|
||||
Gpm_Event event;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return FILE_CONT;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
event.x = -1; /* Don't show the GPM cursor */
|
||||
c = tty_get_event (&event, FALSE, FALSE);
|
||||
if (c == EV_NONE)
|
||||
return FILE_CONT;
|
||||
|
||||
/* Reinitialize to avoid old values after events other than
|
||||
selecting a button */
|
||||
ui->op_dlg->ret_value = FILE_CONT;
|
||||
|
||||
dlg_process_event (ui->op_dlg, c, &event);
|
||||
switch (ui->op_dlg->ret_value)
|
||||
{
|
||||
case FILE_SKIP:
|
||||
return FILE_SKIP;
|
||||
case B_CANCEL:
|
||||
case FILE_ABORT:
|
||||
return FILE_ABORT;
|
||||
default:
|
||||
return FILE_CONT;
|
||||
}
|
||||
}
|
||||
|
||||
/* {{{ File progress display routines */
|
||||
|
||||
void
|
||||
file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
int minus = 0, total_reserve = 0;
|
||||
const char *abort_button_label = N_("&Abort");
|
||||
const char *skip_button_label = N_("&Skip");
|
||||
int abort_button_width, skip_button_width, buttons_width;
|
||||
int dlg_width;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
abort_button_label = _(abort_button_label);
|
||||
skip_button_label = _(skip_button_label);
|
||||
#endif
|
||||
|
||||
abort_button_width = str_term_width1 (abort_button_label) + 3;
|
||||
skip_button_width = str_term_width1 (skip_button_label) + 3;
|
||||
buttons_width = abort_button_width + skip_button_width + 2;
|
||||
|
||||
dlg_width = max (WX, buttons_width + 6);
|
||||
|
||||
ui = g_new0 (FileOpContextUI, 1);
|
||||
ctx->ui = ui;
|
||||
|
||||
ctx->dialog_type = dialog_type;
|
||||
|
||||
switch (dialog_type)
|
||||
{
|
||||
case FILEGUI_DIALOG_ONE_ITEM:
|
||||
total_reserve = 0;
|
||||
minus = verbose ? 0 : 2;
|
||||
break;
|
||||
case FILEGUI_DIALOG_MULTI_ITEM:
|
||||
total_reserve = 5;
|
||||
minus = verbose ? 0 : 7;
|
||||
break;
|
||||
case FILEGUI_DIALOG_DELETE_ITEM:
|
||||
total_reserve = -5;
|
||||
minus = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->recursive_result = RECURSIVE_YES;
|
||||
|
||||
ui->replace_result = REPLACE_YES;
|
||||
ui->showing_eta = with_eta;
|
||||
ui->showing_bps = with_eta;
|
||||
|
||||
ui->op_dlg =
|
||||
create_dlg (TRUE, 0, 0, WY - minus + 1 + total_reserve, dlg_width,
|
||||
dialog_colors, NULL, NULL, op_names[ctx->operation], DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
last_hint_line = the_hint->widget.y;
|
||||
if ((ui->op_dlg->y + ui->op_dlg->lines) > last_hint_line)
|
||||
the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1;
|
||||
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 + 1, FILE_ABORT,
|
||||
NORMAL_BUTTON, abort_button_label, NULL));
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 - 1 - skip_button_width, FILE_SKIP,
|
||||
NORMAL_BUTTON, skip_button_label, NULL));
|
||||
|
||||
|
||||
if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
{
|
||||
add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_bytes_label = label_new (8, FCOPY_LABEL_X + 15, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_total_gauge =
|
||||
gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_files_processed_label =
|
||||
label_new (11, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->time_label = label_new (12, FCOPY_LABEL_X, ""));
|
||||
}
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_label = label_new (7, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_gauge = gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_string[1] = label_new (5, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_label[1] = label_new (4, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_string[0] = label_new (3, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_label[0] = label_new (2, FCOPY_LABEL_X, ""));
|
||||
|
||||
if ((right_panel == current_panel) && !classic_progressbar)
|
||||
{
|
||||
ui->progress_file_gauge->from_left_to_right = FALSE;
|
||||
if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
ui->progress_total_gauge->from_left_to_right = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
file_op_context_create_ui_without_init (ctx, with_eta, dialog_type);
|
||||
ui = ctx->ui;
|
||||
|
||||
/* We will manage the dialog without any help, that's why
|
||||
we have to call init_dlg */
|
||||
init_dlg (ui->op_dlg);
|
||||
}
|
||||
|
||||
void
|
||||
file_op_context_destroy_ui (FileOpContext * ctx)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui)
|
||||
{
|
||||
ui = ctx->ui;
|
||||
|
||||
dlg_run_done (ui->op_dlg);
|
||||
destroy_dlg (ui->op_dlg);
|
||||
g_free (ui);
|
||||
}
|
||||
|
||||
the_hint->widget.y = last_hint_line;
|
||||
|
||||
ctx->ui = NULL;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_frmt_time (char *buffer, double eta_secs)
|
||||
@ -397,6 +237,8 @@ file_frmt_time (char *buffer, double eta_secs)
|
||||
g_snprintf (buffer, BUF_TINY, _("%d:%02d.%02d"), eta_hours, eta_mins, eta_s);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
|
||||
{
|
||||
@ -412,6 +254,8 @@ file_eta_prepare_for_show (char *buffer, double eta_secs, gboolean always_show)
|
||||
g_snprintf (buffer, BUF_TINY, _("ETA %s"), _fmt_buff);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
file_bps_prepare_for_show (char *buffer, long bps)
|
||||
{
|
||||
@ -431,204 +275,7 @@ file_bps_prepare_for_show (char *buffer, long bps)
|
||||
*buffer = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
show progressbar for file
|
||||
*/
|
||||
void
|
||||
file_progress_show (FileOpContext * ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (total == 0)
|
||||
{
|
||||
gauge_show (ui->progress_file_gauge, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
gauge_set_value (ui->progress_file_gauge, 1024, (int) (1024 * done / total));
|
||||
gauge_show (ui->progress_file_gauge, 1);
|
||||
|
||||
if (!force_update)
|
||||
return;
|
||||
|
||||
if (ui->showing_eta && ctx->eta_secs > 0.5)
|
||||
{
|
||||
file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE);
|
||||
file_bps_prepare_for_show (buffer3, ctx->bps);
|
||||
g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf (buffer, BUF_TINY, "%s", stalled_msg);
|
||||
}
|
||||
|
||||
label_set_text (ui->progress_file_label, buffer);
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_count (FileOpContext * ctx, off_t done, off_t total)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Files processed: %llu of %llu"),
|
||||
(unsigned long long) done, (unsigned long long) total);
|
||||
|
||||
label_set_text (ui->total_files_processed_label, buffer);
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, double copyed_bytes,
|
||||
gboolean need_show_total_summary)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
char buffer4[BUF_TINY];
|
||||
struct timeval tv_current;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (ctx->progress_bytes > 0)
|
||||
{
|
||||
gauge_set_value (ui->progress_total_gauge, 1024,
|
||||
(int) (1024 * copyed_bytes / ctx->progress_bytes));
|
||||
gauge_show (ui->progress_total_gauge, 1);
|
||||
}
|
||||
else
|
||||
gauge_show (ui->progress_total_gauge, 0);
|
||||
|
||||
|
||||
if (!need_show_total_summary && tctx->bps == 0)
|
||||
return;
|
||||
|
||||
gettimeofday (&tv_current, NULL);
|
||||
file_frmt_time (buffer2, tv_current.tv_sec - tctx->transfer_start.tv_sec);
|
||||
file_eta_prepare_for_show (buffer3, tctx->eta_secs, TRUE);
|
||||
file_bps_prepare_for_show (buffer4, (long) tctx->bps);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
|
||||
label_set_text (ui->time_label, buffer);
|
||||
|
||||
size_trunc_len (buffer2, 5, tctx->copyed_bytes, 0, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer3, 5, ctx->progress_bytes, 0, panels_options.kilobyte_si);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Total: %s of %s"), buffer2, buffer3);
|
||||
|
||||
label_set_text (ui->total_bytes_label, buffer);
|
||||
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
#define truncFileString(ui, s) str_trunc (s, 52)
|
||||
#define truncFileStringSecure(ui, s) path_trunc (s, 52)
|
||||
|
||||
void
|
||||
file_progress_show_source (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
#ifdef WITH_FULL_PATHS
|
||||
int i = strlen (current_panel->cwd);
|
||||
|
||||
/* We remove the full path we have added before */
|
||||
if (!strncmp (s, current_panel->cwd, i))
|
||||
{
|
||||
if (s[i] == PATH_SEP)
|
||||
s += i + 1;
|
||||
}
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
label_set_text (ui->file_label[0], _("Source"));
|
||||
label_set_text (ui->file_string[0], truncFileString (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[0], "");
|
||||
label_set_text (ui->file_string[0], "");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_target (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
label_set_text (ui->file_label[1], _("Target"));
|
||||
label_set_text (ui->file_string[1], truncFileStringSecure (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[1], "");
|
||||
label_set_text (ui->file_string[1], "");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
file_progress_show_deleting (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
label_set_text (ui->file_label[0], _("Deleting"));
|
||||
label_set_text (ui->file_label[0], truncFileStringSecure (ui, s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*
|
||||
* FIXME: probably it is better to replace this with quick dialog machinery,
|
||||
* but actually I'm not familiar with it and have not much time :(
|
||||
@ -825,6 +472,417 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
||||
#undef ADD_RD_BUTTON
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
is_wildcarded (char *p)
|
||||
{
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (*p == '*')
|
||||
return TRUE;
|
||||
if (*p == '\\' && p[1] >= '1' && p[1] <= '9')
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileProgressStatus
|
||||
check_progress_buttons (FileOpContext * ctx)
|
||||
{
|
||||
int c;
|
||||
Gpm_Event event;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return FILE_CONT;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
event.x = -1; /* Don't show the GPM cursor */
|
||||
c = tty_get_event (&event, FALSE, FALSE);
|
||||
if (c == EV_NONE)
|
||||
return FILE_CONT;
|
||||
|
||||
/* Reinitialize to avoid old values after events other than
|
||||
selecting a button */
|
||||
ui->op_dlg->ret_value = FILE_CONT;
|
||||
|
||||
dlg_process_event (ui->op_dlg, c, &event);
|
||||
switch (ui->op_dlg->ret_value)
|
||||
{
|
||||
case FILE_SKIP:
|
||||
return FILE_SKIP;
|
||||
case B_CANCEL:
|
||||
case FILE_ABORT:
|
||||
return FILE_ABORT;
|
||||
default:
|
||||
return FILE_CONT;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* {{{ File progress display routines */
|
||||
|
||||
void
|
||||
file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
int minus = 0, total_reserve = 0;
|
||||
const char *abort_button_label = N_("&Abort");
|
||||
const char *skip_button_label = N_("&Skip");
|
||||
int abort_button_width, skip_button_width, buttons_width;
|
||||
int dlg_width;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
abort_button_label = _(abort_button_label);
|
||||
skip_button_label = _(skip_button_label);
|
||||
#endif
|
||||
|
||||
abort_button_width = str_term_width1 (abort_button_label) + 3;
|
||||
skip_button_width = str_term_width1 (skip_button_label) + 3;
|
||||
buttons_width = abort_button_width + skip_button_width + 2;
|
||||
|
||||
dlg_width = max (WX, buttons_width + 6);
|
||||
|
||||
ui = g_new0 (FileOpContextUI, 1);
|
||||
ctx->ui = ui;
|
||||
|
||||
ctx->dialog_type = dialog_type;
|
||||
|
||||
switch (dialog_type)
|
||||
{
|
||||
case FILEGUI_DIALOG_ONE_ITEM:
|
||||
total_reserve = 0;
|
||||
minus = verbose ? 0 : 2;
|
||||
break;
|
||||
case FILEGUI_DIALOG_MULTI_ITEM:
|
||||
total_reserve = 5;
|
||||
minus = verbose ? 0 : 7;
|
||||
break;
|
||||
case FILEGUI_DIALOG_DELETE_ITEM:
|
||||
total_reserve = -5;
|
||||
minus = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
ctx->recursive_result = RECURSIVE_YES;
|
||||
|
||||
ui->replace_result = REPLACE_YES;
|
||||
ui->showing_eta = with_eta;
|
||||
ui->showing_bps = with_eta;
|
||||
|
||||
ui->op_dlg =
|
||||
create_dlg (TRUE, 0, 0, WY - minus + 1 + total_reserve, dlg_width,
|
||||
dialog_colors, NULL, NULL, op_names[ctx->operation], DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
last_hint_line = the_hint->widget.y;
|
||||
if ((ui->op_dlg->y + ui->op_dlg->lines) > last_hint_line)
|
||||
the_hint->widget.y = ui->op_dlg->y + ui->op_dlg->lines + 1;
|
||||
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 + 1, FILE_ABORT,
|
||||
NORMAL_BUTTON, abort_button_label, NULL));
|
||||
add_widget (ui->op_dlg,
|
||||
button_new (WY - minus - 2 + total_reserve,
|
||||
dlg_width / 2 - 1 - skip_button_width, FILE_SKIP,
|
||||
NORMAL_BUTTON, skip_button_label, NULL));
|
||||
|
||||
|
||||
if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
{
|
||||
add_widget (ui->op_dlg, hline_new (8, 1, dlg_width - 2));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_bytes_label = label_new (8, FCOPY_LABEL_X + 15, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_total_gauge =
|
||||
gauge_new (9, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->total_files_processed_label =
|
||||
label_new (11, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->time_label = label_new (12, FCOPY_LABEL_X, ""));
|
||||
}
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_label = label_new (7, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->progress_file_gauge = gauge_new (6, FCOPY_LABEL_X + 3, 0, 100, 0));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_string[1] = label_new (5, FCOPY_LABEL_X, ""));
|
||||
|
||||
add_widget (ui->op_dlg, ui->file_label[1] = label_new (4, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_string[0] = label_new (3, FCOPY_LABEL_X, ""));
|
||||
add_widget (ui->op_dlg, ui->file_label[0] = label_new (2, FCOPY_LABEL_X, ""));
|
||||
|
||||
if ((right_panel == current_panel) && !classic_progressbar)
|
||||
{
|
||||
ui->progress_file_gauge->from_left_to_right = FALSE;
|
||||
if (dialog_type == FILEGUI_DIALOG_MULTI_ITEM)
|
||||
ui->progress_total_gauge->from_left_to_right = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
g_return_if_fail (ctx->ui == NULL);
|
||||
|
||||
file_op_context_create_ui_without_init (ctx, with_eta, dialog_type);
|
||||
ui = ctx->ui;
|
||||
|
||||
/* We will manage the dialog without any help, that's why
|
||||
we have to call init_dlg */
|
||||
init_dlg (ui->op_dlg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_context_destroy_ui (FileOpContext * ctx)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui)
|
||||
{
|
||||
ui = ctx->ui;
|
||||
|
||||
dlg_run_done (ui->op_dlg);
|
||||
destroy_dlg (ui->op_dlg);
|
||||
g_free (ui);
|
||||
}
|
||||
|
||||
the_hint->widget.y = last_hint_line;
|
||||
|
||||
ctx->ui = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
show progressbar for file
|
||||
*/
|
||||
|
||||
void
|
||||
file_progress_show (FileOpContext * ctx, off_t done, off_t total,
|
||||
const char *stalled_msg, gboolean force_update)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (total == 0)
|
||||
{
|
||||
gauge_show (ui->progress_file_gauge, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
gauge_set_value (ui->progress_file_gauge, 1024, (int) (1024 * done / total));
|
||||
gauge_show (ui->progress_file_gauge, 1);
|
||||
|
||||
if (!force_update)
|
||||
return;
|
||||
|
||||
if (ui->showing_eta && ctx->eta_secs > 0.5)
|
||||
{
|
||||
file_eta_prepare_for_show (buffer2, ctx->eta_secs, FALSE);
|
||||
file_bps_prepare_for_show (buffer3, ctx->bps);
|
||||
g_snprintf (buffer, BUF_TINY, "%s (%s) %s", buffer2, buffer3, stalled_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_snprintf (buffer, BUF_TINY, "%s", stalled_msg);
|
||||
}
|
||||
|
||||
label_set_text (ui->progress_file_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_count (FileOpContext * ctx, off_t done, off_t total)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Files processed: %llu of %llu"),
|
||||
(unsigned long long) done, (unsigned long long) total);
|
||||
|
||||
label_set_text (ui->total_files_processed_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_total (FileOpTotalContext * tctx, FileOpContext * ctx, double copyed_bytes,
|
||||
gboolean need_show_total_summary)
|
||||
{
|
||||
char buffer[BUF_TINY];
|
||||
char buffer2[BUF_TINY];
|
||||
char buffer3[BUF_TINY];
|
||||
char buffer4[BUF_TINY];
|
||||
struct timeval tv_current;
|
||||
FileOpContextUI *ui;
|
||||
|
||||
if (!verbose)
|
||||
return;
|
||||
|
||||
if (ctx->dialog_type != FILEGUI_DIALOG_MULTI_ITEM || ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (ctx->progress_bytes > 0)
|
||||
{
|
||||
gauge_set_value (ui->progress_total_gauge, 1024,
|
||||
(int) (1024 * copyed_bytes / ctx->progress_bytes));
|
||||
gauge_show (ui->progress_total_gauge, 1);
|
||||
}
|
||||
else
|
||||
gauge_show (ui->progress_total_gauge, 0);
|
||||
|
||||
|
||||
if (!need_show_total_summary && tctx->bps == 0)
|
||||
return;
|
||||
|
||||
gettimeofday (&tv_current, NULL);
|
||||
file_frmt_time (buffer2, tv_current.tv_sec - tctx->transfer_start.tv_sec);
|
||||
file_eta_prepare_for_show (buffer3, tctx->eta_secs, TRUE);
|
||||
file_bps_prepare_for_show (buffer4, (long) tctx->bps);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Time: %s %s (%s)"), buffer2, buffer3, buffer4);
|
||||
label_set_text (ui->time_label, buffer);
|
||||
|
||||
size_trunc_len (buffer2, 5, tctx->copyed_bytes, 0, panels_options.kilobyte_si);
|
||||
size_trunc_len (buffer3, 5, ctx->progress_bytes, 0, panels_options.kilobyte_si);
|
||||
|
||||
g_snprintf (buffer, BUF_TINY, _("Total: %s of %s"), buffer2, buffer3);
|
||||
|
||||
label_set_text (ui->total_bytes_label, buffer);
|
||||
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_source (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
#ifdef WITH_FULL_PATHS
|
||||
int i = strlen (current_panel->cwd);
|
||||
|
||||
/* We remove the full path we have added before */
|
||||
if (!strncmp (s, current_panel->cwd, i))
|
||||
{
|
||||
if (s[i] == PATH_SEP)
|
||||
s += i + 1;
|
||||
}
|
||||
#endif /* WITH_FULL_PATHS */
|
||||
|
||||
label_set_text (ui->file_label[0], _("Source"));
|
||||
label_set_text (ui->file_string[0], truncFileString (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[0], "");
|
||||
label_set_text (ui->file_string[0], "");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_target (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
|
||||
if (s != NULL)
|
||||
{
|
||||
label_set_text (ui->file_label[1], _("Target"));
|
||||
label_set_text (ui->file_string[1], truncFileStringSecure (ui, s));
|
||||
}
|
||||
else
|
||||
{
|
||||
label_set_text (ui->file_label[1], "");
|
||||
label_set_text (ui->file_string[1], "");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_progress_show_deleting (FileOpContext * ctx, const char *s)
|
||||
{
|
||||
FileOpContextUI *ui;
|
||||
|
||||
g_return_if_fail (ctx != NULL);
|
||||
|
||||
if (ctx->ui == NULL)
|
||||
return;
|
||||
|
||||
ui = ctx->ui;
|
||||
label_set_text (ui->file_label[0], _("Deleting"));
|
||||
label_set_text (ui->file_label[0], truncFileStringSecure (ui, s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileProgressStatus
|
||||
file_progress_real_query_replace (FileOpContext * ctx,
|
||||
enum OperationMode mode, const char *destname,
|
||||
@ -882,18 +940,7 @@ file_progress_real_query_replace (FileOpContext * ctx,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_wildcarded (char *p)
|
||||
{
|
||||
for (; *p; p++)
|
||||
{
|
||||
if (*p == '*')
|
||||
return TRUE;
|
||||
if (*p == '\\' && p[1] >= '1' && p[1] <= '9')
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
@ -1135,3 +1182,5 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
|
||||
return dest_dir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,22 +1,34 @@
|
||||
|
||||
/** \file filegui.h
|
||||
* \brief Header: file management GUI for the text mode edition
|
||||
*/
|
||||
|
||||
#ifndef MC_FILEGUI_H
|
||||
#define MC_FILEGUI_H
|
||||
#ifndef MC__FILEGUI_H
|
||||
#define MC__FILEGUI_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "fileopctx.h"
|
||||
|
||||
typedef enum {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FILEGUI_DIALOG_ONE_ITEM,
|
||||
FILEGUI_DIALOG_MULTI_ITEM,
|
||||
FILEGUI_DIALOG_DELETE_ITEM
|
||||
} filegui_dialog_type_t;
|
||||
|
||||
void file_op_context_create_ui (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_create_ui_without_init (FileOpContext *ctx, gboolean with_eta, filegui_dialog_type_t dialog_type);
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void file_op_context_create_ui (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_create_ui_without_init (FileOpContext * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type);
|
||||
void file_op_context_destroy_ui (FileOpContext * ctx);
|
||||
|
||||
|
||||
@ -36,4 +48,5 @@ void file_progress_show_source (FileOpContext *ctx, const char *path);
|
||||
void file_progress_show_target (FileOpContext * ctx, const char *path);
|
||||
void file_progress_show_deleting (FileOpContext * ctx, const char *path);
|
||||
|
||||
#endif /* MC_FILEGUI_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILEGUI_H */
|
||||
|
@ -39,7 +39,16 @@
|
||||
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
get_absolute_name (const char *file)
|
||||
@ -52,6 +61,8 @@ get_absolute_name (const char *file)
|
||||
return concat_dir_and_file (dir, file);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
my_mkdir_rec (char *s, mode_t mode)
|
||||
{
|
||||
@ -67,7 +78,8 @@ my_mkdir_rec (char *s, mode_t mode)
|
||||
if (!vfs_file_is_local (s))
|
||||
return -1;
|
||||
|
||||
if (!strcmp (s, PATH_SEP_STR)) {
|
||||
if (!strcmp (s, PATH_SEP_STR))
|
||||
{
|
||||
errno = ENOTDIR;
|
||||
return -1;
|
||||
}
|
||||
@ -84,6 +96,10 @@ my_mkdir_rec (char *s, mode_t mode)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
my_mkdir (const char *s, mode_t mode)
|
||||
{
|
||||
@ -91,13 +107,15 @@ my_mkdir (const char *s, mode_t mode)
|
||||
char *my_s;
|
||||
|
||||
result = mc_mkdir (s, mode);
|
||||
if (result) {
|
||||
if (result)
|
||||
{
|
||||
char *p = vfs_canon (s);
|
||||
|
||||
result = my_mkdir_rec (p, mode);
|
||||
g_free (p);
|
||||
}
|
||||
if (result == 0) {
|
||||
if (result == 0)
|
||||
{
|
||||
my_s = get_absolute_name (s);
|
||||
|
||||
#ifdef FIXME
|
||||
@ -109,6 +127,8 @@ my_mkdir (const char *s, mode_t mode)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
my_rmdir (const char *s)
|
||||
{
|
||||
@ -120,7 +140,8 @@ my_rmdir (const char *s)
|
||||
|
||||
/* FIXME: Should receive a Wtree! */
|
||||
result = mc_rmdir (s);
|
||||
if (result == 0) {
|
||||
if (result == 0)
|
||||
{
|
||||
my_s = get_absolute_name (s);
|
||||
|
||||
#ifdef FIXME
|
||||
@ -131,3 +152,5 @@ my_rmdir (const char *s)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -38,6 +38,21 @@
|
||||
#include "lib/search.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* \fn FileOpContext * file_op_context_new (FileOperation op)
|
||||
* \param op file operation struct
|
||||
@ -46,6 +61,7 @@
|
||||
* Creates a new file operation context with the default values. If you later want
|
||||
* to have a user interface for this, call file_op_context_create_ui().
|
||||
*/
|
||||
|
||||
FileOpContext *
|
||||
file_op_context_new (FileOperation op)
|
||||
{
|
||||
@ -66,7 +82,7 @@ file_op_context_new (FileOperation op)
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn void file_op_context_destroy (FileOpContext *ctx)
|
||||
* \param ctx The file operation context to destroy.
|
||||
@ -74,6 +90,7 @@ file_op_context_new (FileOperation op)
|
||||
* Destroys the specified file operation context and its associated UI data, if
|
||||
* it exists.
|
||||
*/
|
||||
|
||||
void
|
||||
file_op_context_destroy (FileOpContext * ctx)
|
||||
{
|
||||
@ -89,6 +106,8 @@ file_op_context_destroy (FileOpContext * ctx)
|
||||
g_free (ctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
FileOpTotalContext *
|
||||
file_op_total_context_new (void)
|
||||
{
|
||||
@ -99,9 +118,13 @@ file_op_total_context_new (void)
|
||||
return tctx;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
file_op_total_context_destroy (FileOpTotalContext * tctx)
|
||||
{
|
||||
g_return_if_fail (tctx != NULL);
|
||||
g_free (tctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file fileopctx.h
|
||||
* \brief Header: file operation contexts
|
||||
* \date 1998
|
||||
@ -12,8 +11,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILEOPCTX_H
|
||||
#define FILEOPCTX_H
|
||||
#ifndef MC__FILEOPCTX_H
|
||||
#define MC__FILEOPCTX_H
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
@ -21,15 +20,22 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
struct mc_search_struct;
|
||||
|
||||
typedef enum {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef int (*mc_stat_fn) (const char *filename, struct stat * buf);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OP_COPY = 0,
|
||||
OP_MOVE = 1,
|
||||
OP_DELETE = 2
|
||||
} FileOperation;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
RECURSIVE_YES = 0,
|
||||
RECURSIVE_NO = 1,
|
||||
RECURSIVE_ALWAYS = 2,
|
||||
@ -37,12 +43,30 @@ typedef enum {
|
||||
RECURSIVE_ABORT = 4
|
||||
} FileCopyMode;
|
||||
|
||||
typedef int (*mc_stat_fn) (const char *filename, struct stat *buf);
|
||||
typedef enum
|
||||
{
|
||||
FILE_CONT = 0,
|
||||
FILE_RETRY = 1,
|
||||
FILE_SKIP = 2,
|
||||
FILE_ABORT = 3
|
||||
} FileProgressStatus;
|
||||
|
||||
/* First argument passed to real functions */
|
||||
enum OperationMode
|
||||
{
|
||||
Foreground,
|
||||
Background
|
||||
};
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct mc_search_struct;
|
||||
|
||||
/* This structure describes a context for file operations. It is used to update
|
||||
* the progress windows and pass around options.
|
||||
*/
|
||||
typedef struct FileOpContext {
|
||||
typedef struct FileOpContext
|
||||
{
|
||||
/* Operation type (copy, move, delete) */
|
||||
FileOperation operation;
|
||||
|
||||
@ -127,7 +151,8 @@ typedef struct FileOpContext {
|
||||
void *ui;
|
||||
} FileOpContext;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
off_t progress_count;
|
||||
double progress_bytes;
|
||||
double copyed_bytes;
|
||||
@ -141,6 +166,11 @@ typedef struct {
|
||||
|
||||
} FileOpTotalContext;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern const char *op_names[3];
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
FileOpContext *file_op_context_new (FileOperation op);
|
||||
void file_op_context_destroy (FileOpContext * ctx);
|
||||
@ -148,29 +178,11 @@ void file_op_context_destroy (FileOpContext *ctx);
|
||||
FileOpTotalContext *file_op_total_context_new (void);
|
||||
void file_op_total_context_destroy (FileOpTotalContext * tctx);
|
||||
|
||||
|
||||
extern const char *op_names [3];
|
||||
|
||||
typedef enum {
|
||||
FILE_CONT = 0,
|
||||
FILE_RETRY = 1,
|
||||
FILE_SKIP = 2,
|
||||
FILE_ABORT = 3
|
||||
} FileProgressStatus;
|
||||
|
||||
/* First argument passed to real functions */
|
||||
enum OperationMode {
|
||||
Foreground,
|
||||
Background
|
||||
};
|
||||
|
||||
/* The following functions are implemented separately by each port */
|
||||
|
||||
FileProgressStatus file_progress_real_query_replace (FileOpContext * ctx,
|
||||
enum OperationMode mode,
|
||||
const char *destname,
|
||||
struct stat *_s_stat,
|
||||
struct stat *_d_stat);
|
||||
struct stat *_s_stat, struct stat *_d_stat);
|
||||
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FILEOPCTX_H */
|
||||
|
170
src/find.c
170
src/find.c
@ -57,20 +57,20 @@
|
||||
|
||||
#include "find.h"
|
||||
|
||||
/* Size of the find parameters window */
|
||||
#if HAVE_CHARSET
|
||||
static int FIND_Y = 17;
|
||||
#else
|
||||
static int FIND_Y = 16;
|
||||
#endif
|
||||
static int FIND_X = 68;
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* List of directories to be ignored, separated by ':' */
|
||||
char **find_ignore_dirs = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* Size of the find window */
|
||||
#define FIND2_Y (LINES - 4)
|
||||
|
||||
static int FIND2_X = 64;
|
||||
#define FIND2_X_USE (FIND2_X - 20)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* A couple of extra messages we need */
|
||||
enum
|
||||
{
|
||||
@ -88,8 +88,36 @@ typedef enum
|
||||
FIND_ABORT
|
||||
} FindProgressStatus;
|
||||
|
||||
/* List of directories to be ignored, separated by ':' */
|
||||
char **find_ignore_dirs = NULL;
|
||||
/* find file options */
|
||||
typedef struct
|
||||
{
|
||||
/* file name options */
|
||||
gboolean file_case_sens;
|
||||
gboolean file_pattern;
|
||||
gboolean find_recurs;
|
||||
gboolean skip_hidden;
|
||||
gboolean file_all_charsets;
|
||||
|
||||
/* file content options */
|
||||
gboolean content_use;
|
||||
gboolean content_case_sens;
|
||||
gboolean content_regexp;
|
||||
gboolean content_first_hit;
|
||||
gboolean content_whole_words;
|
||||
gboolean content_all_charsets;
|
||||
} find_file_options_t;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Size of the find parameters window */
|
||||
#if HAVE_CHARSET
|
||||
static int FIND_Y = 17;
|
||||
#else
|
||||
static int FIND_Y = 16;
|
||||
#endif
|
||||
static int FIND_X = 68;
|
||||
|
||||
static int FIND2_X = 64;
|
||||
|
||||
/* static variables to remember find parameters */
|
||||
static WInput *in_start; /* Start path */
|
||||
@ -162,25 +190,6 @@ static struct
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* find file options */
|
||||
typedef struct
|
||||
{
|
||||
/* file name options */
|
||||
gboolean file_case_sens;
|
||||
gboolean file_pattern;
|
||||
gboolean find_recurs;
|
||||
gboolean skip_hidden;
|
||||
gboolean file_all_charsets;
|
||||
|
||||
/* file content options */
|
||||
gboolean content_use;
|
||||
gboolean content_case_sens;
|
||||
gboolean content_regexp;
|
||||
gboolean content_first_hit;
|
||||
gboolean content_whole_words;
|
||||
gboolean content_all_charsets;
|
||||
} find_file_options_t;
|
||||
|
||||
static find_file_options_t options = {
|
||||
TRUE, TRUE, TRUE, FALSE, FALSE,
|
||||
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE
|
||||
@ -191,12 +200,16 @@ static char *in_start_dir = INPUT_LAST_TEXT;
|
||||
static mc_search_t *search_file_handle = NULL;
|
||||
static mc_search_t *search_content_handle = NULL;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
static int
|
||||
find_ignore_dirs_cmp (const void *d1, const void *d2)
|
||||
{
|
||||
return strcmp (*(const char **) d1, *(const char **) d2);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_load_options (void)
|
||||
{
|
||||
@ -287,6 +300,8 @@ find_load_options (void)
|
||||
mc_config_get_bool (mc_main_config, "FindFile", "content_all_charsets", FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_save_options (void)
|
||||
{
|
||||
@ -305,24 +320,32 @@ find_save_options (void)
|
||||
options.content_all_charsets);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
add_to_list (const char *text, void *data)
|
||||
{
|
||||
return listbox_add_item (find_list, LISTBOX_APPEND_AT_END, 0, text, data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
stop_idle (void *data)
|
||||
{
|
||||
set_idle_proc (data, 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
status_update (const char *text)
|
||||
{
|
||||
label_set_text (status_label, text);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
found_num_update (void)
|
||||
{
|
||||
@ -331,13 +354,17 @@ found_num_update (void)
|
||||
label_set_text (found_num_label, buffer);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
get_list_info (char **file, char **dir)
|
||||
{
|
||||
listbox_get_current (find_list, file, (void **) dir);
|
||||
}
|
||||
|
||||
/* check regular expression */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** check regular expression */
|
||||
|
||||
static gboolean
|
||||
find_check_regexp (const char *r)
|
||||
{
|
||||
@ -356,10 +383,12 @@ find_check_regexp (const char *r)
|
||||
return regexp_ok;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Callback for the parameter dialog.
|
||||
* Validate regex, prevent closing the dialog if it's invalid.
|
||||
*/
|
||||
|
||||
static cb_ret_t
|
||||
find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -424,7 +453,8 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* find_parameters: gets information from the user
|
||||
*
|
||||
* If the return value is TRUE, then the following holds:
|
||||
@ -437,6 +467,7 @@ find_parm_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
* behavior for the other two parameters.
|
||||
*
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
find_parameters (char **start_dir, char **pattern, char **content)
|
||||
{
|
||||
@ -659,21 +690,26 @@ find_parameters (char **start_dir, char **pattern, char **content)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 14, 0)
|
||||
static inline void
|
||||
push_directory (const char *dir)
|
||||
{
|
||||
g_queue_push_head (&dir_queue, (void *) dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
pop_directory (void)
|
||||
{
|
||||
return (char *) g_queue_pop_tail (&dir_queue);
|
||||
}
|
||||
|
||||
/* Remove all the items from the stack */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Remove all the items from the stack */
|
||||
|
||||
static void
|
||||
clear_stack (void)
|
||||
{
|
||||
@ -681,8 +717,9 @@ clear_stack (void)
|
||||
g_queue_clear (&dir_queue);
|
||||
}
|
||||
|
||||
#else /* GLIB_CHECK_VERSION */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#else /* GLIB_CHECK_VERSION */
|
||||
static void
|
||||
push_directory (const char *dir)
|
||||
{
|
||||
@ -694,6 +731,8 @@ push_directory (const char *dir)
|
||||
dir_stack_base = new;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
pop_directory (void)
|
||||
{
|
||||
@ -711,7 +750,9 @@ pop_directory (void)
|
||||
return name;
|
||||
}
|
||||
|
||||
/* Remove all the items from the stack */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Remove all the items from the stack */
|
||||
|
||||
static void
|
||||
clear_stack (void)
|
||||
{
|
||||
@ -719,9 +760,10 @@ clear_stack (void)
|
||||
while ((dir = pop_directory ()) != NULL)
|
||||
g_free (dir);
|
||||
}
|
||||
|
||||
#endif /* GLIB_CHECK_VERSION */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
insert_file (const char *dir, const char *file)
|
||||
{
|
||||
@ -751,6 +793,8 @@ insert_file (const char *dir, const char *file)
|
||||
g_free (tmp_name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_add_match (const char *dir, const char *file)
|
||||
{
|
||||
@ -765,7 +809,8 @@ find_add_match (const char *dir, const char *file)
|
||||
found_num_update ();
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* get_line_at:
|
||||
*
|
||||
* Returns malloced null-terminated line from file file_fd.
|
||||
@ -774,6 +819,7 @@ find_add_match (const char *dir, const char *file)
|
||||
* n_read - number of read chars.
|
||||
* has_newline - is there newline ?
|
||||
*/
|
||||
|
||||
static char *
|
||||
get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboolean * has_newline)
|
||||
{
|
||||
@ -819,6 +865,8 @@ get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboole
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static FindProgressStatus
|
||||
check_find_events (Dlg_head * h)
|
||||
{
|
||||
@ -846,7 +894,8 @@ check_find_events (Dlg_head * h)
|
||||
return FIND_CONT;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* search_content:
|
||||
*
|
||||
* Search the content_pattern string in the DIRECTORY/FILE.
|
||||
@ -855,6 +904,7 @@ check_find_events (Dlg_head * h)
|
||||
* returns FALSE if do_search should look for another file
|
||||
* TRUE if do_search should exit and proceed to the event handler
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
search_content (Dlg_head * h, const char *directory, const char *filename)
|
||||
{
|
||||
@ -953,6 +1003,8 @@ search_content (Dlg_head * h, const char *directory, const char *filename)
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline gboolean
|
||||
find_ignore_dir_search (const char *dir)
|
||||
{
|
||||
@ -981,6 +1033,8 @@ find_ignore_dir_search (const char *dir)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_rotate_dash (const Dlg_head *h, gboolean finish)
|
||||
{
|
||||
@ -997,6 +1051,8 @@ find_rotate_dash (const Dlg_head *h, gboolean finish)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
do_search (Dlg_head *h)
|
||||
{
|
||||
@ -1129,6 +1185,8 @@ do_search (Dlg_head *h)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_find_vars (void)
|
||||
{
|
||||
@ -1140,6 +1198,8 @@ init_find_vars (void)
|
||||
clear_stack ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
make_fullname (const char *dirname, const char *filename)
|
||||
{
|
||||
@ -1151,6 +1211,8 @@ make_fullname (const char *dirname, const char *filename)
|
||||
return concat_dir_and_file (dirname, filename);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
|
||||
{
|
||||
@ -1177,6 +1239,8 @@ find_do_view_edit (int unparsed_view, int edit, char *dir, char *file)
|
||||
g_free (fullname);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
view_edit_currently_selected_file (int unparsed_view, int edit)
|
||||
{
|
||||
@ -1192,6 +1256,8 @@ view_edit_currently_selected_file (int unparsed_view, int edit)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
find_callback (Dlg_head *h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -1218,7 +1284,9 @@ find_callback (Dlg_head *h, Widget * sender, dlg_msg_t msg, int parm, void *data
|
||||
}
|
||||
}
|
||||
|
||||
/* Handles the Stop/Start button in the find window */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handles the Stop/Start button in the find window */
|
||||
|
||||
static int
|
||||
start_stop (WButton * button, int action)
|
||||
{
|
||||
@ -1235,7 +1303,9 @@ start_stop (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle view command, when invoked as a button */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle view command, when invoked as a button */
|
||||
|
||||
static int
|
||||
find_do_view_file (WButton * button, int action)
|
||||
{
|
||||
@ -1246,7 +1316,9 @@ find_do_view_file (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handle edit command, when invoked as a button */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle edit command, when invoked as a button */
|
||||
|
||||
static int
|
||||
find_do_edit_file (WButton * button, int action)
|
||||
{
|
||||
@ -1257,6 +1329,8 @@ find_do_edit_file (WButton * button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup_gui (void)
|
||||
{
|
||||
@ -1340,6 +1414,8 @@ setup_gui (void)
|
||||
add_widget (find_dlg, find_list);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
run_process (void)
|
||||
{
|
||||
@ -1372,6 +1448,8 @@ run_process (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
kill_gui (void)
|
||||
{
|
||||
@ -1379,6 +1457,8 @@ kill_gui (void)
|
||||
destroy_dlg (find_dlg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
find_file (const char *start_dir, const char *pattern, const char *content,
|
||||
char **dirname, char **filename)
|
||||
@ -1493,6 +1573,10 @@ find_file (const char *start_dir, const char *pattern, const char *content,
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
do_find (void)
|
||||
{
|
||||
@ -1549,3 +1633,5 @@ do_find (void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/find.h
18
src/find.h
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file find.h
|
||||
* \brief Header: Find file command
|
||||
*/
|
||||
|
||||
#ifndef MC_FIND_H
|
||||
#define MC_FIND_H
|
||||
#ifndef MC__FIND_H
|
||||
#define MC__FIND_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void do_find (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__FIND_H */
|
||||
|
116
src/help.c
116
src/help.c
@ -67,6 +67,10 @@
|
||||
#include "help.h"
|
||||
#include "main.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define MAXLINKNAME 80
|
||||
#define HISTORY_SIZE 20
|
||||
#define HELP_WINDOW_WIDTH min(80, COLS - 16)
|
||||
@ -76,6 +80,16 @@
|
||||
#define STRING_LINK_END "\03"
|
||||
#define STRING_NODE_END "\04"
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* Link areas for the mouse */
|
||||
typedef struct Link_Area
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
const char *link_name;
|
||||
} Link_Area;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static char *fdata = NULL; /* Pointer to the loaded data file */
|
||||
static int help_lines; /* Lines in help viewer */
|
||||
@ -95,20 +109,17 @@ static struct
|
||||
const char *link; /* Pointer to the selected link */
|
||||
} history[HISTORY_SIZE];
|
||||
|
||||
/* Link areas for the mouse */
|
||||
typedef struct Link_Area
|
||||
{
|
||||
int x1, y1, x2, y2;
|
||||
const char *link_name;
|
||||
} Link_Area;
|
||||
|
||||
static GSList *link_area = NULL;
|
||||
static gboolean inside_link_area = FALSE;
|
||||
|
||||
static cb_ret_t help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data);
|
||||
|
||||
/* returns the position where text was found in the start buffer */
|
||||
/* or 0 if not found */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** returns the position where text was found in the start buffer
|
||||
* or 0 if not found
|
||||
*/
|
||||
static const char *
|
||||
search_string (const char *start, const char *text)
|
||||
{
|
||||
@ -144,8 +155,12 @@ search_string (const char *start, const char *text)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Searches text in the buffer pointed by start. Search ends */
|
||||
/* if the CHAR_NODE_END is found in the text. Returns 0 on failure */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Searches text in the buffer pointed by start. Search ends
|
||||
* if the CHAR_NODE_END is found in the text.
|
||||
* @returns 0 on failure
|
||||
*/
|
||||
|
||||
static const char *
|
||||
search_string_node (const char *start, const char *text)
|
||||
{
|
||||
@ -166,8 +181,11 @@ search_string_node (const char *start, const char *text)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Searches the_char in the buffer pointer by start and searches */
|
||||
/* it can search forward (direction = 1) or backward (direction = -1) */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Searches the_char in the buffer pointer by start and searches
|
||||
* it can search forward (direction = 1) or backward (direction = -1)
|
||||
*/
|
||||
|
||||
static const char *
|
||||
search_char_node (const char *start, char the_char, int direction)
|
||||
{
|
||||
@ -180,7 +198,9 @@ search_char_node (const char *start, char the_char, int direction)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Returns the new current pointer when moved lines lines */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the new current pointer when moved lines lines */
|
||||
|
||||
static const char *
|
||||
move_forward2 (const char *c, int lines)
|
||||
{
|
||||
@ -199,6 +219,8 @@ move_forward2 (const char *c, int lines)
|
||||
return currentpoint = c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
move_backward2 (const char *c, int lines)
|
||||
{
|
||||
@ -225,6 +247,8 @@ move_backward2 (const char *c, int lines)
|
||||
return currentpoint = c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_forward (int i)
|
||||
{
|
||||
@ -232,12 +256,16 @@ move_forward (int i)
|
||||
currentpoint = move_forward2 (currentpoint, i);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_backward (int i)
|
||||
{
|
||||
currentpoint = move_backward2 (currentpoint, ++i);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_to_top (void)
|
||||
{
|
||||
@ -250,6 +278,8 @@ move_to_top (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
move_to_bottom (void)
|
||||
{
|
||||
@ -259,6 +289,8 @@ move_to_bottom (void)
|
||||
move_backward (1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
help_follow_link (const char *start, const char *lc_selected_item)
|
||||
{
|
||||
@ -290,6 +322,8 @@ help_follow_link (const char *start, const char *lc_selected_item)
|
||||
return _("Help file format error\n");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
select_next_link (const char *current_link)
|
||||
{
|
||||
@ -307,12 +341,16 @@ select_next_link (const char *current_link)
|
||||
return p - 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
select_prev_link (const char *current_link)
|
||||
{
|
||||
return current_link == NULL ? NULL : search_char_node (current_link - 1, CHAR_LINK_START, -1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
start_link_area (int x, int y, const char *link_name)
|
||||
{
|
||||
@ -333,6 +371,8 @@ start_link_area (int x, int y, const char *link_name)
|
||||
inside_link_area = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
end_link_area (int x, int y)
|
||||
{
|
||||
@ -346,6 +386,8 @@ end_link_area (int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
clear_link_areas (void)
|
||||
{
|
||||
@ -355,6 +397,8 @@ clear_link_areas (void)
|
||||
inside_link_area = FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_print_word (Dlg_head * h, GString * word, int *col, int *line, gboolean add_space)
|
||||
{
|
||||
@ -397,6 +441,8 @@ help_print_word (Dlg_head * h, GString * word, int *col, int *line, gboolean add
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_show (Dlg_head * h, const char *paint_start)
|
||||
{
|
||||
@ -549,6 +595,8 @@ help_show (Dlg_head * h, const char *paint_start)
|
||||
dlg_move (h, active_line, active_col);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
help_event (Gpm_Event * event, void *vp)
|
||||
{
|
||||
@ -621,7 +669,9 @@ help_event (Gpm_Event * event, void *vp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* show help */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** show help */
|
||||
|
||||
static void
|
||||
help_help (Dlg_head * h)
|
||||
{
|
||||
@ -640,6 +690,8 @@ help_help (Dlg_head * h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_index (Dlg_head * h)
|
||||
{
|
||||
@ -661,6 +713,8 @@ help_index (Dlg_head * h)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_back (Dlg_head * h)
|
||||
{
|
||||
@ -673,6 +727,8 @@ help_back (Dlg_head * h)
|
||||
help_callback (h, NULL, DLG_DRAW, 0, NULL); /* FIXME: unneeded? */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_next_link (gboolean move_down)
|
||||
{
|
||||
@ -696,6 +752,8 @@ help_next_link (gboolean move_down)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_prev_link (gboolean move_up)
|
||||
{
|
||||
@ -714,6 +772,8 @@ help_prev_link (gboolean move_up)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_next_node (void)
|
||||
{
|
||||
@ -733,6 +793,8 @@ help_next_node (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_prev_node (void)
|
||||
{
|
||||
@ -750,6 +812,8 @@ help_prev_node (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
help_select_link (void)
|
||||
{
|
||||
@ -781,6 +845,8 @@ help_select_link (void)
|
||||
selected_item = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_execute_cmd (unsigned long command)
|
||||
{
|
||||
@ -846,6 +912,8 @@ help_execute_cmd (unsigned long command)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_handle_key (Dlg_head * h, int c)
|
||||
{
|
||||
@ -859,6 +927,8 @@ help_handle_key (Dlg_head * h, int c)
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -890,13 +960,17 @@ help_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *dat
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
interactive_display_finish (void)
|
||||
{
|
||||
clear_link_areas ();
|
||||
}
|
||||
|
||||
/* translate help file into terminal encoding */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** translate help file into terminal encoding */
|
||||
|
||||
static void
|
||||
translate_file (char *filedata)
|
||||
{
|
||||
@ -925,6 +999,8 @@ translate_file (char *filedata)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
md_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -939,6 +1015,8 @@ md_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Widget *
|
||||
mousedispatch_new (int y, int x, int yl, int xl)
|
||||
{
|
||||
@ -947,6 +1025,10 @@ mousedispatch_new (int y, int x, int yl, int xl)
|
||||
return w;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
interactive_display (const char *filename, const char *node)
|
||||
{
|
||||
@ -1043,3 +1125,5 @@ interactive_display (const char *filename, const char *node)
|
||||
interactive_display_finish ();
|
||||
destroy_dlg (whelp);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/help.h
18
src/help.h
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file help.h
|
||||
* \brief Header: hypertext file browser
|
||||
*
|
||||
@ -26,8 +25,10 @@
|
||||
* This file is included by help.c and man2hlp.c
|
||||
*/
|
||||
|
||||
#ifndef MC_HELP_H
|
||||
#define MC_HELP_H
|
||||
#ifndef MC__HELP_H
|
||||
#define MC__HELP_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Markers used in the help files */
|
||||
#define CHAR_LINK_START '\01' /* Ctrl-A */
|
||||
@ -41,6 +42,15 @@
|
||||
#define CHAR_FONT_NORMAL '\013' /* Ctrl-K */
|
||||
#define CHAR_FONT_ITALIC '\024' /* Ctrl-T */
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void interactive_display (const char *filename, const char *node);
|
||||
|
||||
#endif /* MC_HELP_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__HELP_H */
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
/** \file history.h
|
||||
* \brief Header: defines history section names
|
||||
*/
|
||||
|
||||
#ifndef MC_HISTORY_H
|
||||
#define MC_HISTORY_H
|
||||
#ifndef MC__HISTORY_H
|
||||
#define MC__HISTORY_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* history section names */
|
||||
|
||||
@ -45,4 +46,14 @@
|
||||
|
||||
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
|
||||
|
||||
#endif /* MC_HISTORY_H */
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC__HISTORY_H */
|
||||
|
365
src/hotlist.c
365
src/hotlist.c
@ -61,6 +61,12 @@
|
||||
#include "command.h" /* cmdline */
|
||||
#include "history.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int hotlist_has_dot_dot = 1;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -83,15 +89,49 @@
|
||||
#define B_REFRESH_VFS (B_USER + 9)
|
||||
#endif
|
||||
|
||||
int hotlist_has_dot_dot = 1;
|
||||
#define new_hotlist() g_new0(struct hotlist, 1)
|
||||
|
||||
static WListbox *l_hotlist;
|
||||
static WListbox *l_movelist;
|
||||
#define CHECK_BUFFER \
|
||||
do \
|
||||
{ \
|
||||
size_t i; \
|
||||
i = strlen (current->label); \
|
||||
if (i + 3 > buflen) { \
|
||||
g_free (buf); \
|
||||
buflen = 1024 * (i/1024 + 1); \
|
||||
buf = g_malloc (buflen); \
|
||||
} \
|
||||
buf[0] = '\0'; \
|
||||
} while (0)
|
||||
|
||||
static Dlg_head *hotlist_dlg;
|
||||
static Dlg_head *movelist_dlg;
|
||||
#define TKN_GROUP 0
|
||||
#define TKN_ENTRY 1
|
||||
#define TKN_STRING 2
|
||||
#define TKN_URL 3
|
||||
#define TKN_ENDGROUP 4
|
||||
#define TKN_COMMENT 5
|
||||
#define TKN_EOL 125
|
||||
#define TKN_EOF 126
|
||||
#define TKN_UNKNOWN 127
|
||||
|
||||
static WLabel *pname, *pname_group, *movelist_group;
|
||||
#define SKIP_TO_EOL \
|
||||
{ \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) \
|
||||
{ \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
tkn = hot_next_token (); \
|
||||
break; \
|
||||
}
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum HotListType
|
||||
{
|
||||
@ -122,6 +162,27 @@ static struct
|
||||
int type; /* LIST_HOTLIST || LIST_VFSLIST */
|
||||
} hotlist_state;
|
||||
|
||||
/* Directory hotlist */
|
||||
struct hotlist
|
||||
{
|
||||
enum HotListType type;
|
||||
char *directory;
|
||||
char *label;
|
||||
struct hotlist *head;
|
||||
struct hotlist *up;
|
||||
struct hotlist *next;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_hotlist;
|
||||
static WListbox *l_movelist;
|
||||
|
||||
static Dlg_head *hotlist_dlg;
|
||||
static Dlg_head *movelist_dlg;
|
||||
|
||||
static WLabel *pname, *pname_group, *movelist_group;
|
||||
|
||||
static struct _hotlist_but
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
@ -159,19 +220,21 @@ static struct _hotlist_but
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
/* Directory hotlist */
|
||||
static struct hotlist
|
||||
{
|
||||
enum HotListType type;
|
||||
char *directory;
|
||||
char *label;
|
||||
struct hotlist *head;
|
||||
struct hotlist *up;
|
||||
struct hotlist *next;
|
||||
} *hotlist = NULL;
|
||||
static struct hotlist *hotlist = NULL;
|
||||
|
||||
static struct hotlist *current_group;
|
||||
|
||||
static GString *tkn_buf = NULL;
|
||||
|
||||
static char *hotlist_file_name;
|
||||
static FILE *hotlist_file;
|
||||
static time_t hotlist_file_mtime;
|
||||
|
||||
static int list_level = 0;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void init_movelist (int, struct hotlist *);
|
||||
static void add_new_group_cmd (void);
|
||||
static void add_new_entry_cmd (void);
|
||||
@ -179,7 +242,7 @@ static void remove_from_hotlist (struct hotlist *entry);
|
||||
static void load_hotlist (void);
|
||||
static void add_dotdot_to_list (void);
|
||||
|
||||
#define new_hotlist() g_new0(struct hotlist, 1)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hotlist_refresh (Dlg_head * dlg)
|
||||
@ -192,7 +255,9 @@ hotlist_refresh (Dlg_head * dlg)
|
||||
draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2), TRUE);
|
||||
}
|
||||
|
||||
/* If current->data is 0, then we are dealing with a VFS pathname */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** If current->data is 0, then we are dealing with a VFS pathname */
|
||||
|
||||
static void
|
||||
update_path_name (void)
|
||||
{
|
||||
@ -232,18 +297,7 @@ update_path_name (void)
|
||||
dlg_redraw (dlg);
|
||||
}
|
||||
|
||||
#define CHECK_BUFFER \
|
||||
do \
|
||||
{ \
|
||||
size_t i; \
|
||||
i = strlen (current->label); \
|
||||
if (i + 3 > buflen) { \
|
||||
g_free (buf); \
|
||||
buflen = 1024 * (i/1024 + 1); \
|
||||
buf = g_malloc (buflen); \
|
||||
} \
|
||||
buf[0] = '\0'; \
|
||||
} while (0)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
fill_listbox (void)
|
||||
@ -282,6 +336,8 @@ fill_listbox (void)
|
||||
g_string_free (buff, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
unlink_entry (struct hotlist *entry)
|
||||
{
|
||||
@ -299,6 +355,8 @@ unlink_entry (struct hotlist *entry)
|
||||
entry->next = entry->up = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
static void
|
||||
add_name_to_list (const char *path)
|
||||
@ -307,6 +365,8 @@ add_name_to_list (const char *path)
|
||||
}
|
||||
#endif /* !ENABLE_VFS */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hotlist_button_callback (WButton * button, int action)
|
||||
{
|
||||
@ -456,6 +516,8 @@ hotlist_button_callback (WButton *button, int action)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline cb_ret_t
|
||||
hotlist_handle_key (Dlg_head * h, int key)
|
||||
{
|
||||
@ -521,6 +583,8 @@ hotlist_handle_key (Dlg_head * h, int key)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -556,6 +620,8 @@ hotlist_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
l_call (WListbox * list)
|
||||
{
|
||||
@ -596,7 +662,8 @@ l_call (WListbox * list)
|
||||
return LISTBOX_CONT;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Expands all button names (once) and recalculates button positions.
|
||||
* returns number of columns in the dialog box, which is 10 chars longer
|
||||
* then buttonbar.
|
||||
@ -604,6 +671,7 @@ l_call (WListbox * list)
|
||||
* If common width of the window (i.e. in xterm) is less than returned
|
||||
* width - sorry :) (anyway this did not handled in previous version too)
|
||||
*/
|
||||
|
||||
static int
|
||||
init_i18n_stuff (int list_type, int cols)
|
||||
{
|
||||
@ -677,6 +745,8 @@ init_i18n_stuff (int list_type, int cols)
|
||||
return cols;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_hotlist (int list_type)
|
||||
{
|
||||
@ -755,6 +825,8 @@ init_hotlist (int list_type)
|
||||
/* add listbox to the dialogs */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_movelist (int list_type, struct hotlist *item)
|
||||
{
|
||||
@ -796,10 +868,12 @@ init_movelist (int list_type, struct hotlist *item)
|
||||
/* add listbox to the dialogs */
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Destroy the list dialog.
|
||||
* Don't confuse with done_hotlist() for the list in memory.
|
||||
*/
|
||||
|
||||
static void
|
||||
hotlist_done (void)
|
||||
{
|
||||
@ -810,12 +884,16 @@ hotlist_done (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline char *
|
||||
find_group_section (struct hotlist *grp)
|
||||
{
|
||||
return g_strconcat (grp->directory, ".Group", (char *) NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct hotlist *
|
||||
add2hotlist (char *label, char *directory, enum HotListType type, listbox_append_t pos)
|
||||
{
|
||||
@ -902,8 +980,8 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append
|
||||
|
||||
}
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Support routine for add_new_entry_input()/add_new_group_input()
|
||||
* Change positions of buttons (first three widgets).
|
||||
*
|
||||
@ -911,6 +989,8 @@ add2hotlist (char *label, char *directory, enum HotListType type, listbox_append
|
||||
* internationalized label lengths and total buttonbar length...assume
|
||||
* 64 is longer anyway.
|
||||
*/
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static void
|
||||
add_widgets_i18n (QuickWidget * qw, int len)
|
||||
{
|
||||
@ -931,6 +1011,8 @@ add_widgets_i18n (QuickWidget * qw, int len)
|
||||
}
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
add_new_entry_input (const char *header, const char *text1, const char *text2,
|
||||
const char *help, char **r1, char **r2)
|
||||
@ -997,6 +1079,8 @@ add_new_entry_input (const char *header, const char *text1, const char *text2,
|
||||
#undef RELATIVE_Y_INPUT_PTH
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_new_entry_cmd (void)
|
||||
{
|
||||
@ -1027,6 +1111,8 @@ add_new_entry_cmd (void)
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
add_new_group_input (const char *header, const char *label, char **result)
|
||||
{
|
||||
@ -1080,6 +1166,8 @@ add_new_group_input (const char *header, const char *label, char **result)
|
||||
return (ret != B_CANCEL) ? ret : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_new_group_cmd (void)
|
||||
{
|
||||
@ -1098,29 +1186,7 @@ add_new_group_cmd (void)
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
void
|
||||
add2hotlist_cmd (void)
|
||||
{
|
||||
char *lc_prompt, *label;
|
||||
const char *cp = _("Label for \"%s\":");
|
||||
int l = str_term_width1 (cp);
|
||||
char *label_string = g_strdup (current_panel->cwd);
|
||||
|
||||
strip_password (label_string, 1);
|
||||
|
||||
lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS - 2 * UX - (l + 8)));
|
||||
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
||||
g_free (lc_prompt);
|
||||
|
||||
if (!label || !*label)
|
||||
{
|
||||
g_free (label_string);
|
||||
g_free (label);
|
||||
return;
|
||||
}
|
||||
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_group (struct hotlist *grp)
|
||||
@ -1143,6 +1209,8 @@ remove_group (struct hotlist *grp)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_from_hotlist (struct hotlist *entry)
|
||||
{
|
||||
@ -1200,44 +1268,7 @@ remove_from_hotlist (struct hotlist *entry)
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
char *
|
||||
hotlist_cmd (int vfs_or_hotlist)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
hotlist_state.type = vfs_or_hotlist;
|
||||
load_hotlist ();
|
||||
|
||||
init_hotlist (vfs_or_hotlist);
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
hotlist_state.running = 1;
|
||||
run_dlg (hotlist_dlg);
|
||||
hotlist_state.running = 0;
|
||||
save_hotlist ();
|
||||
|
||||
switch (hotlist_dlg->ret_value)
|
||||
{
|
||||
default:
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ENTER:
|
||||
{
|
||||
char *text = NULL;
|
||||
struct hotlist *hlp = NULL;
|
||||
|
||||
listbox_get_current (l_hotlist, &text, (void **) &hlp);
|
||||
target = g_strdup (hlp != NULL ? hlp->directory : text);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
hotlist_done ();
|
||||
return target;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_group (struct hotlist *grp)
|
||||
@ -1276,21 +1307,7 @@ load_group (struct hotlist *grp)
|
||||
load_group (current);
|
||||
}
|
||||
|
||||
#define TKN_GROUP 0
|
||||
#define TKN_ENTRY 1
|
||||
#define TKN_STRING 2
|
||||
#define TKN_URL 3
|
||||
#define TKN_ENDGROUP 4
|
||||
#define TKN_COMMENT 5
|
||||
#define TKN_EOL 125
|
||||
#define TKN_EOF 126
|
||||
#define TKN_UNKNOWN 127
|
||||
|
||||
static GString *tkn_buf = NULL;
|
||||
|
||||
static char *hotlist_file_name;
|
||||
static FILE *hotlist_file;
|
||||
static time_t hotlist_file_mtime;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hot_skip_blanks (void)
|
||||
@ -1303,6 +1320,8 @@ hot_skip_blanks (void)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
hot_next_token (void)
|
||||
{
|
||||
@ -1386,22 +1405,7 @@ hot_next_token (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SKIP_TO_EOL \
|
||||
{ \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) \
|
||||
{ \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
tkn = hot_next_token (); \
|
||||
break; \
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_load_group (struct hotlist *grp)
|
||||
@ -1453,6 +1457,8 @@ hot_load_group (struct hotlist *grp)
|
||||
SKIP_TO_EOL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_load_file (struct hotlist *grp)
|
||||
{
|
||||
@ -1497,6 +1503,8 @@ hot_load_file (struct hotlist *grp)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
clean_up_hotlist_groups (const char *section)
|
||||
{
|
||||
@ -1523,7 +1531,7 @@ clean_up_hotlist_groups (const char *section)
|
||||
g_free (grp_section);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_hotlist (void)
|
||||
@ -1569,7 +1577,8 @@ load_hotlist (void)
|
||||
remove_old_list = 1;
|
||||
else
|
||||
message (D_ERROR, _("Hotlist Load"),
|
||||
_("MC was unable to write ~/%s file,\nyour old hotlist entries were not deleted"),
|
||||
_
|
||||
("MC was unable to write ~/%s file,\nyour old hotlist entries were not deleted"),
|
||||
MC_USERCONF_DIR PATH_SEP_STR MC_HOTLIST_FILE);
|
||||
}
|
||||
else
|
||||
@ -1592,8 +1601,7 @@ load_hotlist (void)
|
||||
current_group = hotlist;
|
||||
}
|
||||
|
||||
|
||||
static int list_level = 0;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hot_save_group (struct hotlist *grp)
|
||||
@ -1654,6 +1662,89 @@ do { \
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add_dotdot_to_list (void)
|
||||
{
|
||||
if (current_group != hotlist)
|
||||
{
|
||||
if (hotlist_has_dot_dot != 0)
|
||||
add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
add2hotlist_cmd (void)
|
||||
{
|
||||
char *lc_prompt, *label;
|
||||
const char *cp = _("Label for \"%s\":");
|
||||
int l = str_term_width1 (cp);
|
||||
char *label_string = g_strdup (current_panel->cwd);
|
||||
|
||||
strip_password (label_string, 1);
|
||||
|
||||
lc_prompt = g_strdup_printf (cp, path_trunc (current_panel->cwd, COLS - 2 * UX - (l + 8)));
|
||||
label = input_dialog (_("Add to hotlist"), lc_prompt, MC_HISTORY_HOTLIST_ADD, label_string);
|
||||
g_free (lc_prompt);
|
||||
|
||||
if (!label || !*label)
|
||||
{
|
||||
g_free (label_string);
|
||||
g_free (label);
|
||||
return;
|
||||
}
|
||||
add2hotlist (label, label_string, HL_TYPE_ENTRY, LISTBOX_APPEND_AT_END);
|
||||
hotlist_state.modified = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
hotlist_cmd (int vfs_or_hotlist)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
hotlist_state.type = vfs_or_hotlist;
|
||||
load_hotlist ();
|
||||
|
||||
init_hotlist (vfs_or_hotlist);
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
hotlist_state.running = 1;
|
||||
run_dlg (hotlist_dlg);
|
||||
hotlist_state.running = 0;
|
||||
save_hotlist ();
|
||||
|
||||
switch (hotlist_dlg->ret_value)
|
||||
{
|
||||
default:
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ENTER:
|
||||
{
|
||||
char *text = NULL;
|
||||
struct hotlist *hlp = NULL;
|
||||
|
||||
listbox_get_current (l_hotlist, &text, (void **) &hlp);
|
||||
target = g_strdup (hlp != NULL ? hlp->directory : text);
|
||||
break;
|
||||
}
|
||||
} /* switch */
|
||||
|
||||
hotlist_done ();
|
||||
return target;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
save_hotlist (void)
|
||||
{
|
||||
@ -1681,10 +1772,12 @@ save_hotlist (void)
|
||||
return saved;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Unload list from memory.
|
||||
* Don't confuse with hotlist_done() for GUI.
|
||||
*/
|
||||
|
||||
void
|
||||
done_hotlist (void)
|
||||
{
|
||||
@ -1711,12 +1804,4 @@ done_hotlist (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_dotdot_to_list (void)
|
||||
{
|
||||
if (current_group != hotlist)
|
||||
{
|
||||
if (hotlist_has_dot_dot != 0)
|
||||
add2hotlist (g_strdup (".."), g_strdup (".."), HL_TYPE_DOTDOT, LISTBOX_APPEND_AT_END);
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,18 +1,28 @@
|
||||
|
||||
/** \file hotlist.h
|
||||
* \brief Header: directory hotlist
|
||||
*/
|
||||
|
||||
#ifndef MC_HOTLIST_H
|
||||
#define MC_HOTLIST_H
|
||||
#ifndef MC__HOTLIST_H
|
||||
#define MC__HOTLIST_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define LIST_VFSLIST 0x01
|
||||
#define LIST_HOTLIST 0x02
|
||||
#define LIST_MOVELIST 0x04
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void add2hotlist_cmd (void);
|
||||
char *hotlist_cmd (int list_vfs);
|
||||
int save_hotlist (void);
|
||||
void done_hotlist (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__HOTLIST_H */
|
||||
|
25
src/info.c
25
src/info.c
@ -44,18 +44,29 @@
|
||||
#include "setup.h" /* panels_options */
|
||||
#include "info.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef VERSION
|
||||
#define VERSION "undefined"
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct WInfo
|
||||
{
|
||||
Widget widget;
|
||||
int ready;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct my_statfs myfs_stats;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_box (struct WInfo *info)
|
||||
{
|
||||
@ -78,6 +89,8 @@ info_box (struct WInfo *info)
|
||||
tty_draw_hline (info->widget.y + 2, info->widget.x + 1, ACS_HLINE, info->widget.cols - 2);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_show_info (struct WInfo *info)
|
||||
{
|
||||
@ -238,6 +251,8 @@ info_show_info (struct WInfo *info)
|
||||
g_string_free (buff, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
info_hook (void *data)
|
||||
{
|
||||
@ -254,6 +269,8 @@ info_hook (void *data)
|
||||
info_show_info (info);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
info_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -285,6 +302,8 @@ info_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
info_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -300,6 +319,10 @@ info_event (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WInfo *
|
||||
info_new (int y, int x, int lines, int cols)
|
||||
{
|
||||
@ -312,3 +335,5 @@ info_new (int y, int x, int lines, int cols)
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/info.h
18
src/info.h
@ -1,14 +1,24 @@
|
||||
|
||||
/** \file info.h
|
||||
* \brief Header: panel managing
|
||||
*/
|
||||
|
||||
#ifndef MC_INFO_H
|
||||
#define MC_INFO_H
|
||||
#ifndef MC__INFO_H
|
||||
#define MC__INFO_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WInfo;
|
||||
typedef struct WInfo WInfo;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WInfo *info_new (int y, int x, int lines, int cols);
|
||||
|
||||
#endif /* MC_INFO_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__INFO_H */
|
||||
|
1022
src/keybind.c
1022
src/keybind.c
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,24 @@
|
||||
|
||||
#ifndef MC_KEYBIND_H
|
||||
#define MC_KEYBIND_H
|
||||
#ifndef MC__KEYBIND_H
|
||||
#define MC__KEYBIND_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
typedef struct name_keymap_t {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct name_keymap_t
|
||||
{
|
||||
const char *name;
|
||||
unsigned long val;
|
||||
} name_keymap_t;
|
||||
|
||||
typedef struct key_config_t {
|
||||
typedef struct key_config_t
|
||||
{
|
||||
time_t mtime; /* mtime at the moment we read config file */
|
||||
GArray *keymap;
|
||||
GArray *ext_keymap;
|
||||
@ -17,17 +26,14 @@ typedef struct key_config_t {
|
||||
} key_config_t;
|
||||
|
||||
/* The global keymaps are of this type */
|
||||
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
||||
typedef struct global_keymap_t {
|
||||
typedef struct global_keymap_t
|
||||
{
|
||||
long key;
|
||||
unsigned long command;
|
||||
char caption[KEYMAP_SHORTCUT_LENGTH];
|
||||
} global_keymap_t;
|
||||
|
||||
void keybind_cmd_bind (GArray *keymap, const char *keybind, unsigned long action);
|
||||
unsigned long lookup_action (const char *name);
|
||||
const char *lookup_keymap_shortcut (const global_keymap_t *keymap, unsigned long action);
|
||||
unsigned long lookup_keymap_command (const global_keymap_t *keymap, long key);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
extern GArray *editor_keymap;
|
||||
@ -98,4 +104,12 @@ extern const global_keymap_t default_dialog_keymap[];
|
||||
extern const global_keymap_t default_diff_keymap[];
|
||||
#endif
|
||||
|
||||
#endif /* MC_KEYBIND_H */
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void keybind_cmd_bind (GArray * keymap, const char *keybind, unsigned long action);
|
||||
unsigned long lookup_action (const char *name);
|
||||
const char *lookup_keymap_shortcut (const global_keymap_t * keymap, unsigned long action);
|
||||
unsigned long lookup_keymap_command (const global_keymap_t * keymap, long key);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__KEYBIND_H */
|
||||
|
255
src/layout.c
255
src/layout.c
@ -74,6 +74,8 @@
|
||||
|
||||
#include "setup.h" /* For save_setup() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* Controls the display of the rotating dash on the verbose mode */
|
||||
int nice_rotating_dash = 1;
|
||||
|
||||
@ -110,11 +112,30 @@ int free_space = 1;
|
||||
/* The starting line for the output of the subprogram */
|
||||
int output_start_y = 0;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* The maximum number of views managed by the set_display_type routine */
|
||||
/* Must be at least two (for current and other). Please note that until */
|
||||
/* Janne gets around this, we will only manage two of them :-) */
|
||||
#define MAX_VIEWS 2
|
||||
|
||||
/* Width 12 for a wee Quick (Hex) View */
|
||||
#define MINWIDTH 12
|
||||
#define MINHEIGHT 5
|
||||
|
||||
#define B_2LEFT B_USER
|
||||
#define B_2RIGHT (B_USER + 1)
|
||||
#define B_PLUS (B_USER + 2)
|
||||
#define B_MINUS (B_USER + 3)
|
||||
|
||||
|
||||
#define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
|
||||
#define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct
|
||||
{
|
||||
panel_view_mode_t type;
|
||||
@ -149,15 +170,6 @@ static int _free_space;
|
||||
|
||||
static int height;
|
||||
|
||||
/* Width 12 for a wee Quick (Hex) View */
|
||||
#define MINWIDTH 12
|
||||
#define MINHEIGHT 5
|
||||
|
||||
#define B_2LEFT B_USER
|
||||
#define B_2RIGHT (B_USER + 1)
|
||||
#define B_PLUS (B_USER + 2)
|
||||
#define B_MINUS (B_USER + 3)
|
||||
|
||||
static const char *s_split_direction[2] = {
|
||||
N_("&Vertical"),
|
||||
N_("&Horizontal")
|
||||
@ -184,15 +196,17 @@ static struct
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#define LAYOUT_OPTIONS_COUNT (sizeof (check_options) / sizeof (check_options[0]))
|
||||
#define OTHER_OPTIONS_COUNT (LAYOUT_OPTIONS_COUNT - 1)
|
||||
|
||||
static gsize first_width;
|
||||
static const char *output_lines_label = NULL;
|
||||
static int output_lines_label_len;
|
||||
|
||||
static WButton *bleft_widget, *bright_widget;
|
||||
|
||||
static int ok_to_refresh = 1;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
_check_split (void)
|
||||
{
|
||||
@ -219,6 +233,8 @@ _check_split (void)
|
||||
old_horizontal_split = _horizontal_split;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_split (const Dlg_head * h)
|
||||
{
|
||||
@ -241,6 +257,8 @@ update_split (const Dlg_head *h)
|
||||
tty_print_char ('=');
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
b_left_right_cback (WButton * button, int action)
|
||||
{
|
||||
@ -255,6 +273,8 @@ b_left_right_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bplus_cback (WButton * button, int action)
|
||||
{
|
||||
@ -266,6 +286,8 @@ bplus_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bminus_cback (WButton * button, int action)
|
||||
{
|
||||
@ -277,6 +299,8 @@ bminus_cback (WButton *button, int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -380,6 +404,8 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Dlg_head *
|
||||
init_layout (void)
|
||||
{
|
||||
@ -525,6 +551,86 @@ init_layout (void)
|
||||
return layout_dlg;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
check_split (void)
|
||||
{
|
||||
if (horizontal_split)
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = height / 2;
|
||||
else if (first_panel_size < MINHEIGHT)
|
||||
first_panel_size = MINHEIGHT;
|
||||
else if (first_panel_size > height - MINHEIGHT)
|
||||
first_panel_size = height - MINHEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = COLS / 2;
|
||||
else if (first_panel_size < MINWIDTH)
|
||||
first_panel_size = MINWIDTH;
|
||||
else if (first_panel_size > COLS - MINWIDTH)
|
||||
first_panel_size = COLS - MINWIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_do_cols (int idx)
|
||||
{
|
||||
if (get_display_type (idx) == view_listing)
|
||||
set_panel_formats ((WPanel *) panels[idx].widget);
|
||||
else
|
||||
panel_update_cols (panels[idx].widget, frame_half);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
low_level_change_screen_size (void)
|
||||
{
|
||||
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
|
||||
#if defined TIOCGWINSZ
|
||||
struct winsize winsz;
|
||||
|
||||
winsz.ws_col = winsz.ws_row = 0;
|
||||
/* Ioctl on the STDIN_FILENO */
|
||||
ioctl (0, TIOCGWINSZ, &winsz);
|
||||
if (winsz.ws_col && winsz.ws_row)
|
||||
{
|
||||
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
|
||||
resizeterm (winsz.ws_row, winsz.ws_col);
|
||||
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
|
||||
#else
|
||||
COLS = winsz.ws_col;
|
||||
LINES = winsz.ws_row;
|
||||
#endif
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
resize_subshell ();
|
||||
#endif
|
||||
}
|
||||
#endif /* TIOCGWINSZ */
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
dlg_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Dlg_head *d = data;
|
||||
|
||||
(void) user_data;
|
||||
d->callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
layout_change (void)
|
||||
{
|
||||
@ -537,6 +643,8 @@ layout_change (void)
|
||||
load_hint (1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
layout_box (void)
|
||||
{
|
||||
@ -569,28 +677,7 @@ layout_box (void)
|
||||
layout_change ();
|
||||
}
|
||||
|
||||
static void
|
||||
check_split (void)
|
||||
{
|
||||
if (horizontal_split)
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = height / 2;
|
||||
else if (first_panel_size < MINHEIGHT)
|
||||
first_panel_size = MINHEIGHT;
|
||||
else if (first_panel_size > height - MINHEIGHT)
|
||||
first_panel_size = height - MINHEIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (equal_split)
|
||||
first_panel_size = COLS / 2;
|
||||
else if (first_panel_size < MINWIDTH)
|
||||
first_panel_size = MINWIDTH;
|
||||
else if (first_panel_size > COLS - MINWIDTH)
|
||||
first_panel_size = COLS - MINWIDTH;
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
clr_scr (void)
|
||||
@ -600,6 +687,8 @@ clr_scr (void)
|
||||
tty_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
repaint_screen (void)
|
||||
{
|
||||
@ -607,6 +696,8 @@ repaint_screen (void)
|
||||
tty_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mc_refresh (void)
|
||||
{
|
||||
@ -624,14 +715,7 @@ mc_refresh (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
panel_do_cols (int idx)
|
||||
{
|
||||
if (get_display_type (idx) == view_listing)
|
||||
set_panel_formats ((WPanel *) panels[idx].widget);
|
||||
else
|
||||
panel_update_cols (panels[idx].widget, frame_half);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
setup_panels (void)
|
||||
@ -717,41 +801,7 @@ setup_panels (void)
|
||||
update_xterm_title_path ();
|
||||
}
|
||||
|
||||
static inline void
|
||||
low_level_change_screen_size (void)
|
||||
{
|
||||
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
|
||||
#if defined TIOCGWINSZ
|
||||
struct winsize winsz;
|
||||
|
||||
winsz.ws_col = winsz.ws_row = 0;
|
||||
/* Ioctl on the STDIN_FILENO */
|
||||
ioctl (0, TIOCGWINSZ, &winsz);
|
||||
if (winsz.ws_col && winsz.ws_row)
|
||||
{
|
||||
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
|
||||
resizeterm (winsz.ws_row, winsz.ws_col);
|
||||
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
|
||||
#else
|
||||
COLS = winsz.ws_col;
|
||||
LINES = winsz.ws_row;
|
||||
#endif
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
resize_subshell ();
|
||||
#endif
|
||||
}
|
||||
#endif /* TIOCGWINSZ */
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
static void
|
||||
dlg_resize_cb (void *data, void *user_data)
|
||||
{
|
||||
Dlg_head *d = data;
|
||||
|
||||
(void) user_data;
|
||||
d->callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
sigwinch_handler (int dummy)
|
||||
@ -763,6 +813,8 @@ sigwinch_handler (int dummy)
|
||||
winch_flag = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
change_screen_size (void)
|
||||
{
|
||||
@ -799,7 +851,8 @@ change_screen_size (void)
|
||||
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
|
||||
}
|
||||
|
||||
static int ok_to_refresh = 1;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
use_dash (gboolean flag)
|
||||
@ -810,6 +863,8 @@ use_dash (gboolean flag)
|
||||
ok_to_refresh--;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
set_hintbar (const char *str)
|
||||
{
|
||||
@ -818,6 +873,8 @@ set_hintbar (const char *str)
|
||||
mc_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
print_vfs_message (const char *msg, ...)
|
||||
{
|
||||
@ -855,6 +912,8 @@ print_vfs_message (const char *msg, ...)
|
||||
set_hintbar (str);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
rotate_dash (void)
|
||||
{
|
||||
@ -873,6 +932,8 @@ rotate_dash (void)
|
||||
pos++;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
get_nth_panel_name (int num)
|
||||
{
|
||||
@ -889,6 +950,7 @@ get_nth_panel_name (int num)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* I wonder if I should start to use the folding mode than Dugan uses */
|
||||
/* */
|
||||
/* This is the centralized managing of the panel display types */
|
||||
@ -900,6 +962,7 @@ get_nth_panel_name (int num)
|
||||
/* Set the num-th panel to the view type: type */
|
||||
/* This routine also keeps at least one WPanel object in the screen */
|
||||
/* since a lot of routines depend on the current_panel variable */
|
||||
|
||||
void
|
||||
set_display_type (int num, panel_view_mode_t type)
|
||||
{
|
||||
@ -1022,9 +1085,11 @@ set_display_type (int num, panel_view_mode_t type)
|
||||
g_free (old_widget);
|
||||
}
|
||||
|
||||
/* This routine is deeply sticked to the two panels idea.
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** This routine is deeply sticked to the two panels idea.
|
||||
What should it do in more panels. ANSWER - don't use it
|
||||
in any multiple panels environment. */
|
||||
|
||||
void
|
||||
swap_panels (void)
|
||||
{
|
||||
@ -1118,18 +1183,24 @@ swap_panels (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
panel_view_mode_t
|
||||
get_display_type (int idx)
|
||||
{
|
||||
return panels[idx].type;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct Widget *
|
||||
get_panel_widget (int idx)
|
||||
{
|
||||
return panels[idx].widget;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
get_current_index (void)
|
||||
{
|
||||
@ -1139,19 +1210,25 @@ get_current_index (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
get_other_index (void)
|
||||
{
|
||||
return !get_current_index ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct WPanel *
|
||||
get_other_panel (void)
|
||||
{
|
||||
return (struct WPanel *) get_panel_widget (get_other_index ());
|
||||
}
|
||||
|
||||
/* Returns the view type for the current panel/view */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the view type for the current panel/view */
|
||||
|
||||
panel_view_mode_t
|
||||
get_current_type (void)
|
||||
{
|
||||
@ -1161,7 +1238,9 @@ get_current_type (void)
|
||||
return panels[1].type;
|
||||
}
|
||||
|
||||
/* Returns the view type of the unselected panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the view type of the unselected panel */
|
||||
|
||||
panel_view_mode_t
|
||||
get_other_type (void)
|
||||
{
|
||||
@ -1171,7 +1250,9 @@ get_other_type (void)
|
||||
return panels[0].type;
|
||||
}
|
||||
|
||||
/* Save current list_view widget directory into panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save current list_view widget directory into panel */
|
||||
|
||||
void
|
||||
save_panel_dir (int idx)
|
||||
{
|
||||
@ -1189,7 +1270,9 @@ save_panel_dir (int idx)
|
||||
}
|
||||
}
|
||||
|
||||
/* Save current list_view widget directory into panel */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save current list_view widget directory into panel */
|
||||
|
||||
Widget *
|
||||
restore_into_right_dir_panel (int idx, Widget * from_widget)
|
||||
{
|
||||
@ -1206,8 +1289,10 @@ restore_into_right_dir_panel (int idx, Widget * from_widget)
|
||||
return new_widget;
|
||||
}
|
||||
|
||||
/* Return working dir, if it's view_listing - cwd,
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return working dir, if it's view_listing - cwd,
|
||||
but for other types - last_saved_dir */
|
||||
|
||||
const char *
|
||||
get_panel_dir_for (const WPanel * widget)
|
||||
{
|
||||
@ -1225,3 +1310,5 @@ get_panel_dir_for (const WPanel * widget)
|
||||
|
||||
return panels[i].last_saved_dir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
46
src/layout.h
46
src/layout.h
@ -1,15 +1,38 @@
|
||||
|
||||
/** \file layout.h
|
||||
* \brief Header: panel layout module
|
||||
*/
|
||||
|
||||
#ifndef MC_LAYOUT_H
|
||||
#define MC_LAYOUT_H
|
||||
#ifndef MC__LAYOUT_H
|
||||
#define MC__LAYOUT_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "panel.h"
|
||||
#include "widget.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int winch_flag;
|
||||
extern int equal_split;
|
||||
extern int first_panel_size;
|
||||
extern int output_lines;
|
||||
extern int command_prompt;
|
||||
extern int keybar_visible;
|
||||
extern int output_start_y;
|
||||
extern int message_visible;
|
||||
extern int xterm_title;
|
||||
extern int free_space;
|
||||
|
||||
extern int horizontal_split;
|
||||
extern int nice_rotating_dash;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void layout_change (void);
|
||||
void layout_box (void);
|
||||
void setup_panels (void);
|
||||
@ -44,18 +67,5 @@ void clr_scr (void);
|
||||
void repaint_screen (void);
|
||||
void mc_refresh (void);
|
||||
|
||||
extern int winch_flag;
|
||||
extern int equal_split;
|
||||
extern int first_panel_size;
|
||||
extern int output_lines;
|
||||
extern int command_prompt;
|
||||
extern int keybar_visible;
|
||||
extern int output_start_y;
|
||||
extern int message_visible;
|
||||
extern int xterm_title;
|
||||
extern int free_space;
|
||||
|
||||
extern int horizontal_split;
|
||||
extern int nice_rotating_dash;
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LAYOUT_H */
|
||||
|
158
src/learn.c
158
src/learn.c
@ -49,6 +49,10 @@
|
||||
#include "learn.h"
|
||||
#include "wtools.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 4
|
||||
#define UY 3
|
||||
|
||||
@ -59,31 +63,45 @@
|
||||
|
||||
#define BUTTONS 2
|
||||
|
||||
static struct {
|
||||
int ret_cmd, flags, y, x;
|
||||
const char *text;
|
||||
} learn_but[BUTTONS] = {
|
||||
/* *INDENT-OFF */
|
||||
{ B_CANCEL, NORMAL_BUTTON, 0, 39, N_("&Cancel") },
|
||||
{ B_ENTER, DEFPUSH_BUTTON, 0, 25, N_("&Save") }
|
||||
/* *INDENT-ON */
|
||||
};
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
static Dlg_head *learn_dlg;
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Widget *button;
|
||||
Widget *label;
|
||||
int ok;
|
||||
char *sequence;
|
||||
} learnkey;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
const char *text;
|
||||
} learn_but[BUTTONS] =
|
||||
{
|
||||
/* *INDENT-OFF */
|
||||
{
|
||||
B_CANCEL, NORMAL_BUTTON, 0, 39, N_("&Cancel")},
|
||||
{
|
||||
B_ENTER, DEFPUSH_BUTTON, 0, 25, N_("&Save")}
|
||||
/* *INDENT-ON */
|
||||
};
|
||||
|
||||
static Dlg_head *learn_dlg;
|
||||
|
||||
static learnkey *learnkeys = NULL;
|
||||
static int learn_total;
|
||||
static int learnok;
|
||||
static int learnchanged;
|
||||
static const char *learn_title = N_("Learn keys");
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int learn_button (WButton *button, int action)
|
||||
static int
|
||||
learn_button (WButton * button, int action)
|
||||
{
|
||||
Dlg_head *d;
|
||||
char *seq;
|
||||
@ -96,35 +114,34 @@ _("Please press the %s\n"
|
||||
"Then, press it again to see if OK appears\n"
|
||||
"next to its button.\n\n"
|
||||
"If you want to escape, press a single Escape key\n"
|
||||
"and wait as well."),
|
||||
_(key_name_conv_tab [action - B_USER].longname));
|
||||
"and wait as well."), _(key_name_conv_tab[action - B_USER].longname));
|
||||
mc_refresh ();
|
||||
if (learnkeys [action - B_USER].sequence != NULL) {
|
||||
if (learnkeys[action - B_USER].sequence != NULL)
|
||||
{
|
||||
g_free (learnkeys[action - B_USER].sequence);
|
||||
learnkeys[action - B_USER].sequence = NULL;
|
||||
}
|
||||
seq = learn_key ();
|
||||
|
||||
if (seq){
|
||||
if (seq)
|
||||
{
|
||||
/* Esc hides the dialog and do not allow definitions of
|
||||
* regular characters
|
||||
*/
|
||||
gboolean seq_ok = FALSE;
|
||||
|
||||
if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
|
||||
&& strcmp (seq, "^m" ) && strcmp (seq, "^i" )
|
||||
&& (seq [1] || (*seq < ' ' || *seq > '~'))){
|
||||
&& strcmp (seq, "^m") && strcmp (seq, "^i") && (seq[1] || (*seq < ' ' || *seq > '~')))
|
||||
{
|
||||
|
||||
learnchanged = 1;
|
||||
learnkeys[action - B_USER].sequence = seq;
|
||||
seq = convert_controls (seq);
|
||||
seq_ok = define_sequence (key_name_conv_tab [action - B_USER].code,
|
||||
seq, MCKEY_NOACTION);
|
||||
seq_ok = define_sequence (key_name_conv_tab[action - B_USER].code, seq, MCKEY_NOACTION);
|
||||
}
|
||||
|
||||
if (!seq_ok)
|
||||
message (D_NORMAL, _("Cannot accept this key"),
|
||||
_("You have entered \"%s\""), seq);
|
||||
message (D_NORMAL, _("Cannot accept this key"), _("You have entered \"%s\""), seq);
|
||||
|
||||
g_free (seq);
|
||||
}
|
||||
@ -135,19 +152,26 @@ _("Please press the %s\n"
|
||||
return 0; /* Do not kill learn_dlg */
|
||||
}
|
||||
|
||||
static int learn_move (int right)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
learn_move (int right)
|
||||
{
|
||||
int i, totalcols;
|
||||
|
||||
totalcols = (learn_total - 1) / ROWS + 1;
|
||||
for (i = 0; i < learn_total; i++)
|
||||
if (learnkeys [i].button == (Widget *) learn_dlg->current->data) {
|
||||
if (right) {
|
||||
if (learnkeys[i].button == (Widget *) learn_dlg->current->data)
|
||||
{
|
||||
if (right)
|
||||
{
|
||||
if (i < learn_total - ROWS)
|
||||
i += ROWS;
|
||||
else
|
||||
i %= ROWS;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i / ROWS)
|
||||
i -= ROWS;
|
||||
else if (i + (totalcols - 1) * ROWS >= learn_total)
|
||||
@ -161,12 +185,15 @@ static int learn_move (int right)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
learn_check_key (int c)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < learn_total; i++) {
|
||||
for (i = 0; i < learn_total; i++)
|
||||
{
|
||||
if (key_name_conv_tab[i].code != c || learnkeys[i].ok)
|
||||
continue;
|
||||
|
||||
@ -175,16 +202,20 @@ learn_check_key (int c)
|
||||
label_set_text ((WLabel *) learnkeys[i].label, _("OK"));
|
||||
learnkeys[i].ok = 1;
|
||||
learnok++;
|
||||
if (learnok >= learn_total) {
|
||||
if (learnok >= learn_total)
|
||||
{
|
||||
learn_dlg->ret_value = B_CANCEL;
|
||||
if (learnchanged) {
|
||||
if (learnchanged)
|
||||
{
|
||||
if (query_dialog (learn_title,
|
||||
_
|
||||
("It seems that all your keys already\n"
|
||||
"work fine. That's great."), D_ERROR, 2,
|
||||
_("&Save"), _("&Discard")) == 0)
|
||||
learn_dlg->ret_value = B_ENTER;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
message (D_ERROR, learn_title,
|
||||
_
|
||||
("Great! You have a complete terminal database!\n"
|
||||
@ -194,7 +225,8 @@ learn_check_key (int c)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
switch (c) {
|
||||
switch (c)
|
||||
{
|
||||
case KEY_LEFT:
|
||||
case 'h':
|
||||
return learn_move (0);
|
||||
@ -217,11 +249,13 @@ learn_check_key (int c)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
learn_callback (Dlg_head *h, Widget *sender,
|
||||
dlg_msg_t msg, int parm, void *data)
|
||||
learn_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
switch (msg) {
|
||||
case DLG_DRAW:
|
||||
common_dialog_repaint (h);
|
||||
return MSG_HANDLED;
|
||||
@ -234,6 +268,8 @@ learn_callback (Dlg_head *h, Widget *sender,
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_learn (void)
|
||||
{
|
||||
@ -243,7 +279,8 @@ init_learn (void)
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static int i18n_flag = 0;
|
||||
if (!i18n_flag) {
|
||||
if (!i18n_flag)
|
||||
{
|
||||
learn_but[0].text = _(learn_but[0].text);
|
||||
learn_but[0].x = 78 / 2 + 4;
|
||||
|
||||
@ -264,14 +301,12 @@ init_learn (void)
|
||||
for (i = 0; i < BUTTONS; i++)
|
||||
add_widget (learn_dlg,
|
||||
button_new (BY + learn_but[i].y, learn_but[i].x,
|
||||
learn_but[i].ret_cmd, learn_but[i].flags,
|
||||
_(learn_but[i].text), 0));
|
||||
learn_but[i].ret_cmd, learn_but[i].flags, _(learn_but[i].text), 0));
|
||||
|
||||
x = UX;
|
||||
y = UY;
|
||||
for (key = key_name_conv_tab, j = 0;
|
||||
key->name != NULL && strcmp (key->name, "kpleft");
|
||||
key++, j++)
|
||||
key->name != NULL && strcmp (key->name, "kpleft"); key++, j++)
|
||||
;
|
||||
learnkeys = g_new (learnkey, j);
|
||||
x += ((j - 1) / ROWS) * COLSHIFT;
|
||||
@ -279,42 +314,44 @@ init_learn (void)
|
||||
learn_total = j;
|
||||
learnok = 0;
|
||||
learnchanged = 0;
|
||||
for (i = j - 1, key = key_name_conv_tab + j - 1; i >= 0; i--, key--) {
|
||||
for (i = j - 1, key = key_name_conv_tab + j - 1; i >= 0; i--, key--)
|
||||
{
|
||||
learnkeys[i].ok = 0;
|
||||
learnkeys[i].sequence = NULL;
|
||||
g_snprintf (buffer, sizeof (buffer), "%-16s", _(key->longname));
|
||||
add_widget (learn_dlg, learnkeys[i].button = (Widget *)
|
||||
button_new (y, x, B_USER + i, NARROW_BUTTON, buffer,
|
||||
learn_button));
|
||||
add_widget (learn_dlg, learnkeys[i].label = (Widget *)
|
||||
label_new (y, x + 19, ""));
|
||||
button_new (y, x, B_USER + i, NARROW_BUTTON, buffer, learn_button));
|
||||
add_widget (learn_dlg, learnkeys[i].label = (Widget *) label_new (y, x + 19, ""));
|
||||
if (i % 13)
|
||||
y--;
|
||||
else {
|
||||
else
|
||||
{
|
||||
x -= COLSHIFT;
|
||||
y = UY + ROWS - 1;
|
||||
}
|
||||
}
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 14, 5,
|
||||
_
|
||||
("Press all the keys mentioned here. After you have done it, check")));
|
||||
_("Press all the keys mentioned here. After you have done it, check")));
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 15, 5,
|
||||
_
|
||||
("which keys are not marked with OK. Press space on the missing")));
|
||||
_("which keys are not marked with OK. Press space on the missing")));
|
||||
add_widget (learn_dlg,
|
||||
label_new (UY + 16, 5,
|
||||
_
|
||||
("key, or click with the mouse to define it. Move around with Tab.")));
|
||||
_("key, or click with the mouse to define it. Move around with Tab.")));
|
||||
}
|
||||
|
||||
static void learn_done (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
learn_done (void)
|
||||
{
|
||||
destroy_dlg (learn_dlg);
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
learn_save (void)
|
||||
{
|
||||
@ -323,8 +360,10 @@ learn_save (void)
|
||||
char *section = g_strconcat ("terminal:", getenv ("TERM"), (char *) NULL);
|
||||
char *esc_str;
|
||||
|
||||
for (i = 0; i < learn_total; i++) {
|
||||
if (learnkeys [i].sequence != NULL) {
|
||||
for (i = 0; i < learn_total; i++)
|
||||
{
|
||||
if (learnkeys[i].sequence != NULL)
|
||||
{
|
||||
profile_changed = 1;
|
||||
|
||||
esc_str = strutils_escape (learnkeys[i].sequence, -1, ";\\", TRUE);
|
||||
@ -348,7 +387,12 @@ learn_save (void)
|
||||
g_free (section);
|
||||
}
|
||||
|
||||
void learn_keys (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
learn_keys (void)
|
||||
{
|
||||
int save_old_esc_mode = old_esc_mode;
|
||||
int save_alternate_plus_minus = alternate_plus_minus;
|
||||
@ -368,7 +412,8 @@ void learn_keys (void)
|
||||
if (!alternate_plus_minus)
|
||||
numeric_keypad_mode ();
|
||||
|
||||
switch (learn_dlg->ret_value) {
|
||||
switch (learn_dlg->ret_value)
|
||||
{
|
||||
case B_ENTER:
|
||||
learn_save ();
|
||||
break;
|
||||
@ -377,3 +422,4 @@ void learn_keys (void)
|
||||
learn_done ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/learn.h
18
src/learn.h
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file learn.h
|
||||
* \brief Header: learn keys module
|
||||
*/
|
||||
|
||||
#ifndef MC_LEARN_H
|
||||
#define MC_LEARN_H
|
||||
#ifndef MC__LEARN_H
|
||||
#define MC__LEARN_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void learn_keys (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LEARN_H */
|
||||
|
124
src/listmode.c
124
src/listmode.c
@ -51,6 +51,10 @@
|
||||
#include "main.h"
|
||||
#include "listmode.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -60,6 +64,26 @@
|
||||
#define B_ADD B_USER
|
||||
#define B_REMOVE (B_USER + 1)
|
||||
|
||||
#define B_PLUS B_USER
|
||||
#define B_MINUS (B_USER+1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct listmode_button
|
||||
{
|
||||
int ret_cmd, flags, y, x;
|
||||
char *text;
|
||||
bcback callback;
|
||||
};
|
||||
|
||||
struct listmode_label
|
||||
{
|
||||
int y, x;
|
||||
char *text;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_listmode;
|
||||
|
||||
static WLabel *pname;
|
||||
@ -67,29 +91,20 @@ static WLabel *pname;
|
||||
static char *listmode_section = "[Listing format edit]";
|
||||
|
||||
static char *s_genwidth[2] = { "Half width", "Full width" };
|
||||
|
||||
static WRadio *radio_genwidth;
|
||||
static char *s_columns[2] = { "One column", "Two columns" };
|
||||
|
||||
static WRadio *radio_columns;
|
||||
static char *s_justify[3] =
|
||||
{ "Left justified", "Default justification", "Right justified" };
|
||||
static char *s_justify[3] = { "Left justified", "Default justification", "Right justified" };
|
||||
|
||||
static WRadio *radio_justify;
|
||||
static char *s_itemwidth[3] =
|
||||
{ "Free width", "Fixed width", "Growable width" };
|
||||
static char *s_itemwidth[3] = { "Free width", "Fixed width", "Growable width" };
|
||||
|
||||
static WRadio *radio_itemwidth;
|
||||
|
||||
struct listmode_button {
|
||||
int ret_cmd, flags, y, x;
|
||||
char *text;
|
||||
bcback callback;
|
||||
};
|
||||
|
||||
#define B_PLUS B_USER
|
||||
#define B_MINUS (B_USER+1)
|
||||
|
||||
struct listmode_label {
|
||||
int y, x;
|
||||
char *text;
|
||||
};
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
select_new_item (void)
|
||||
@ -101,10 +116,9 @@ select_new_item (void)
|
||||
|
||||
possible_items = panel_get_user_possible_fields (NULL);
|
||||
|
||||
mylistbox =
|
||||
create_listbox_window (20, 12, "Add listing format item",
|
||||
listmode_section);
|
||||
for (i = 0; possible_items[i]; i++) {
|
||||
mylistbox = create_listbox_window (20, 12, "Add listing format item", listmode_section);
|
||||
for (i = 0; possible_items[i]; i++)
|
||||
{
|
||||
listbox_add_item (mylistbox->list, LISTBOX_APPEND_AT_END, 0, possible_items[i], NULL);
|
||||
}
|
||||
|
||||
@ -116,29 +130,38 @@ select_new_item (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bplus_cback (int action)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bminus_cback (int action)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
badd_cback (int action)
|
||||
{
|
||||
char *s = select_new_item ();
|
||||
if (s) {
|
||||
if (s)
|
||||
{
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
g_free (s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
bremove_cback (int action)
|
||||
{
|
||||
@ -146,6 +169,8 @@ bremove_cback (int action)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static Dlg_head *
|
||||
init_listmode (char *oldlistformat)
|
||||
{
|
||||
@ -174,28 +199,21 @@ init_listmode (char *oldlistformat)
|
||||
create_dlg (TRUE, 0, 0, 22, 74, dialog_colors, NULL, listmode_section,
|
||||
"Listing format edit", DLG_CENTER | DLG_REVERSE);
|
||||
|
||||
add_widget (listmode_dlg,
|
||||
groupbox_new (UY, UX, 4, 63, "General options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY, UX, 4, 63, "General options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY + 4, UX, 11, 18, "Items"));
|
||||
add_widget (listmode_dlg,
|
||||
groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));
|
||||
add_widget (listmode_dlg, groupbox_new (UY + 4, UX + 20, 11, 43, "Item options"));
|
||||
|
||||
for (i = 0;
|
||||
i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
|
||||
for (i = 0; i < sizeof (listmode_but) / sizeof (struct listmode_button); i++)
|
||||
add_widget (listmode_dlg,
|
||||
button_new (listmode_but[i].y, listmode_but[i].x,
|
||||
listmode_but[i].ret_cmd,
|
||||
listmode_but[i].flags,
|
||||
listmode_but[i].text,
|
||||
listmode_but[i].callback));
|
||||
listmode_but[i].text, listmode_but[i].callback));
|
||||
|
||||
/* We add the labels. */
|
||||
for (i = 0;
|
||||
i < sizeof (listmode_labels) / sizeof (struct listmode_label);
|
||||
i++) {
|
||||
pname =
|
||||
label_new (listmode_labels[i].y, listmode_labels[i].x,
|
||||
listmode_labels[i].text);
|
||||
for (i = 0; i < sizeof (listmode_labels) / sizeof (struct listmode_label); i++)
|
||||
{
|
||||
pname = label_new (listmode_labels[i].y, listmode_labels[i].x, listmode_labels[i].text);
|
||||
add_widget (listmode_dlg, pname);
|
||||
}
|
||||
|
||||
@ -209,23 +227,28 @@ init_listmode (char *oldlistformat)
|
||||
/* get new listbox */
|
||||
l_listmode = listbox_new (UY + 5, UX + 1, 9, 16, FALSE, NULL);
|
||||
|
||||
if (strncmp (oldlistformat, "full ", 5) == 0) {
|
||||
if (strncmp (oldlistformat, "full ", 5) == 0)
|
||||
{
|
||||
format_width = 1;
|
||||
oldlistformat += 5;
|
||||
}
|
||||
if (strncmp (oldlistformat, "half ", 5) == 0) {
|
||||
if (strncmp (oldlistformat, "half ", 5) == 0)
|
||||
{
|
||||
oldlistformat += 5;
|
||||
}
|
||||
if (strncmp (oldlistformat, "2 ", 2) == 0) {
|
||||
if (strncmp (oldlistformat, "2 ", 2) == 0)
|
||||
{
|
||||
format_columns = 1;
|
||||
oldlistformat += 2;
|
||||
}
|
||||
if (strncmp (oldlistformat, "1 ", 2) == 0) {
|
||||
if (strncmp (oldlistformat, "1 ", 2) == 0)
|
||||
{
|
||||
oldlistformat += 2;
|
||||
}
|
||||
s = strtok (oldlistformat, ",");
|
||||
|
||||
while (s) {
|
||||
while (s)
|
||||
{
|
||||
listbox_add_item (l_listmode, LISTBOX_APPEND_AT_END, 0, s, NULL);
|
||||
s = strtok (NULL, ",");
|
||||
}
|
||||
@ -243,6 +266,8 @@ init_listmode (char *oldlistformat)
|
||||
return listmode_dlg;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
listmode_done (Dlg_head * h)
|
||||
{
|
||||
@ -252,6 +277,8 @@ listmode_done (Dlg_head *h)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
collect_new_format (void)
|
||||
{
|
||||
@ -268,7 +295,8 @@ collect_new_format (void)
|
||||
if (radio_columns->sel)
|
||||
strcat (newformat, "2 ");
|
||||
last = NULL;
|
||||
for (i = 0;; i++) {
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
listbox_select_entry (l_listmode, i);
|
||||
listbox_get_current (l_listmode, &text, &extra);
|
||||
if (text == last)
|
||||
@ -281,7 +309,11 @@ collect_new_format (void)
|
||||
return newformat;
|
||||
}
|
||||
|
||||
/* Return new format or NULL if the user cancelled the dialog */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Return new format or NULL if the user cancelled the dialog */
|
||||
char *
|
||||
listmode_edit (char *oldlistformat)
|
||||
{
|
||||
@ -293,11 +325,15 @@ listmode_edit (char *oldlistformat)
|
||||
listmode_dlg = init_listmode (s);
|
||||
g_free (s);
|
||||
|
||||
if (run_dlg (listmode_dlg) == B_ENTER) {
|
||||
if (run_dlg (listmode_dlg) == B_ENTER)
|
||||
{
|
||||
newformat = collect_new_format ();
|
||||
}
|
||||
|
||||
listmode_done (listmode_dlg);
|
||||
return newformat;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* LISTMODE_EDITOR */
|
||||
|
@ -1,13 +1,22 @@
|
||||
|
||||
/** \file listmode.h
|
||||
* \brief Header: directory panel listing format editor
|
||||
*/
|
||||
|
||||
#ifndef MC_LISTMODE_H
|
||||
#define MC_LISTMODE_H
|
||||
#ifndef MC__LISTMODE_H
|
||||
#define MC__LISTMODE_H
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
#ifdef LISTMODE_EDITOR
|
||||
char *listmode_edit (char *);
|
||||
#endif /* LISTMODE_EDITOR */
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__LISTMODE_H */
|
||||
|
@ -1,14 +1,21 @@
|
||||
|
||||
/** \file main-widgets.h
|
||||
* \brief Header: provides definitions for some widgets
|
||||
*/
|
||||
|
||||
#ifndef MC_MAIN_WIDGETS_H
|
||||
#define MC_MAIN_WIDGETS_H
|
||||
#ifndef MC__MAIN_WIDGETS_H
|
||||
#define MC__MAIN_WIDGETS_H
|
||||
|
||||
#include "widget.h"
|
||||
#include "dialog.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern WButtonBar *the_bar;
|
||||
extern WLabel *the_prompt;
|
||||
extern WLabel *the_hint;
|
||||
@ -16,4 +23,7 @@ extern Dlg_head *midnight_dlg;
|
||||
|
||||
extern struct WMenuBar *the_menubar;
|
||||
|
||||
#endif
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MAIN_WIDGETS_H */
|
||||
|
705
src/main.c
705
src/main.c
File diff suppressed because it is too large
Load Diff
76
src/main.h
76
src/main.h
@ -1,14 +1,21 @@
|
||||
|
||||
/** \file main.h
|
||||
* \brief Header: this is a main module header
|
||||
*/
|
||||
|
||||
#ifndef MC_MAIN_H
|
||||
#define MC_MAIN_H
|
||||
#ifndef MC__MAIN_H
|
||||
#define MC__MAIN_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "keybind.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define MENU_PANEL (is_right ? right_panel : left_panel)
|
||||
#define MENU_PANEL_IDX (is_right ? 1 : 0)
|
||||
#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* run mode and params */
|
||||
typedef enum
|
||||
{
|
||||
@ -18,6 +25,25 @@ typedef enum
|
||||
MC_RUN_DIFFVIEWER
|
||||
} mc_run_mode_t;
|
||||
|
||||
/* If true, after executing a command, wait for a keystroke */
|
||||
enum
|
||||
{ pause_never, pause_on_dumb_terminals, pause_always };
|
||||
|
||||
enum cd_enum
|
||||
{
|
||||
cd_parse_command,
|
||||
cd_exact
|
||||
};
|
||||
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WButtonBar;
|
||||
|
||||
struct mc_fhl_struct;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern mc_run_mode_t mc_run_mode;
|
||||
/*
|
||||
* MC_RUN_FULL: dir for left panel
|
||||
@ -34,20 +60,9 @@ extern char *mc_run_param0;
|
||||
*/
|
||||
extern char *mc_run_param1;
|
||||
|
||||
void toggle_show_hidden (void);
|
||||
|
||||
extern int quote;
|
||||
extern volatile int quit;
|
||||
|
||||
/* If true, after executing a command, wait for a keystroke */
|
||||
enum { pause_never, pause_on_dumb_terminals, pause_always };
|
||||
|
||||
void subshell_chdir (const char *command);
|
||||
|
||||
struct WButtonBar;
|
||||
|
||||
void midnight_set_buttonbar (struct WButtonBar *b);
|
||||
|
||||
/* See main.c for details on these variables */
|
||||
extern int auto_menu;
|
||||
extern int pause_after_run;
|
||||
@ -95,21 +110,26 @@ extern char *shell;
|
||||
extern int auto_fill_mkdir_name;
|
||||
/* Ugly hack in order to distinguish between left and right panel in menubar */
|
||||
extern int is_right; /* If the selected menu was the right */
|
||||
#define MENU_PANEL (is_right ? right_panel : left_panel)
|
||||
#define MENU_PANEL_IDX (is_right ? 1 : 0)
|
||||
#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing)
|
||||
|
||||
extern const char *mc_prompt;
|
||||
extern char *mc_home;
|
||||
extern char *mc_home_alt;
|
||||
|
||||
extern struct mc_fhl_struct *mc_filehighlight;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void toggle_show_hidden (void);
|
||||
|
||||
void subshell_chdir (const char *command);
|
||||
|
||||
void midnight_set_buttonbar (struct WButtonBar *b);
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
void do_update_prompt (void);
|
||||
int load_prompt (int fd, void *unused);
|
||||
#endif
|
||||
|
||||
enum cd_enum
|
||||
{
|
||||
cd_parse_command,
|
||||
cd_exact
|
||||
};
|
||||
|
||||
int do_cd (const char *new_dir, enum cd_enum cd_type);
|
||||
void sort_cmd (void);
|
||||
void change_panel (void);
|
||||
@ -122,13 +142,6 @@ void load_hint (int force);
|
||||
|
||||
void print_vfs_message (const char *msg, ...) __attribute__ ((format (__printf__, 1, 2)));
|
||||
|
||||
extern const char *mc_prompt;
|
||||
extern char *mc_home;
|
||||
extern char *mc_home_alt;
|
||||
|
||||
struct mc_fhl_struct;
|
||||
extern struct mc_fhl_struct *mc_filehighlight;
|
||||
|
||||
char *get_mc_lib_dir (void);
|
||||
|
||||
void done_menu (void);
|
||||
@ -136,4 +149,5 @@ void init_menu (void);
|
||||
|
||||
char *remove_encoding_from_path (const char *);
|
||||
|
||||
#endif /* MC_MAIN_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MAIN_H */
|
||||
|
171
src/menu.c
171
src/menu.c
@ -41,34 +41,20 @@
|
||||
#include "main.h" /* is_right */
|
||||
#include "menu.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int menubar_visible = 1; /* This is the new default */
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static cb_ret_t menubar_callback (Widget * w, widget_msg_t msg, int parm);
|
||||
|
||||
menu_entry_t *
|
||||
menu_entry_create (const char *name, unsigned long command)
|
||||
{
|
||||
menu_entry_t *entry;
|
||||
|
||||
entry = g_new (menu_entry_t, 1);
|
||||
entry->first_letter = ' ';
|
||||
entry->text = parse_hotkey (name);
|
||||
entry->command = command;
|
||||
entry->shortcut = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void
|
||||
menu_entry_free (menu_entry_t * entry)
|
||||
{
|
||||
if (entry != NULL)
|
||||
{
|
||||
release_hotkey (entry->text);
|
||||
g_free (entry->shortcut);
|
||||
g_free (entry);
|
||||
}
|
||||
}
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
@ -107,32 +93,7 @@ menu_arrange (Menu * menu, dlg_shortcut_str get_shortcut)
|
||||
}
|
||||
}
|
||||
|
||||
Menu *
|
||||
create_menu (const char *name, GList * entries, const char *help_node)
|
||||
{
|
||||
Menu *menu;
|
||||
|
||||
menu = g_new (Menu, 1);
|
||||
menu->start_x = 0;
|
||||
menu->text = parse_hotkey (name);
|
||||
menu->entries = entries;
|
||||
menu->max_entry_len = 1;
|
||||
menu->max_hotkey_len = 0;
|
||||
menu->selected = 0;
|
||||
menu->help_node = g_strdup (help_node);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||
g_list_free (menu->entries);
|
||||
g_free (menu->help_node);
|
||||
g_free (menu);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
@ -189,6 +150,8 @@ menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_draw_drop (WMenuBar * menubar)
|
||||
{
|
||||
@ -210,6 +173,8 @@ menubar_draw_drop (WMenuBar * menubar)
|
||||
i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||
{
|
||||
@ -221,6 +186,8 @@ menubar_set_color (WMenuBar * menubar, gboolean current, gboolean hotkey)
|
||||
tty_setcolor (hotkey ? MENU_HOT_COLOR : MENU_ENTRY_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_draw (WMenuBar * menubar)
|
||||
{
|
||||
@ -262,6 +229,8 @@ menubar_draw (WMenuBar * menubar)
|
||||
((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->start_x);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_remove (WMenuBar * menubar)
|
||||
{
|
||||
@ -273,6 +242,8 @@ menubar_remove (WMenuBar * menubar)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_left (WMenuBar * menubar)
|
||||
{
|
||||
@ -284,6 +255,8 @@ menubar_left (WMenuBar * menubar)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_right (WMenuBar * menubar)
|
||||
{
|
||||
@ -292,6 +265,8 @@ menubar_right (WMenuBar * menubar)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_finish (WMenuBar * menubar)
|
||||
{
|
||||
@ -304,6 +279,8 @@ menubar_finish (WMenuBar * menubar)
|
||||
do_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||
{
|
||||
@ -312,6 +289,8 @@ menubar_drop (WMenuBar * menubar, unsigned int selected)
|
||||
menubar_draw (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_execute (WMenuBar * menubar)
|
||||
{
|
||||
@ -328,6 +307,8 @@ menubar_execute (WMenuBar * menubar)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_down (WMenuBar * menubar)
|
||||
{
|
||||
@ -347,6 +328,8 @@ menubar_down (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_up (WMenuBar * menubar)
|
||||
{
|
||||
@ -369,6 +352,8 @@ menubar_up (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_first (WMenuBar * menubar)
|
||||
{
|
||||
@ -395,6 +380,8 @@ menubar_first (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
menubar_last (WMenuBar * menubar)
|
||||
{
|
||||
@ -419,6 +406,8 @@ menubar_last (WMenuBar * menubar)
|
||||
menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
menubar_handle_key (WMenuBar * menubar, int key)
|
||||
{
|
||||
@ -530,6 +519,8 @@ menubar_handle_key (WMenuBar * menubar, int key)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -590,6 +581,8 @@ menubar_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
menubar_event (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -714,6 +707,70 @@ menubar_event (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
menu_entry_t *
|
||||
menu_entry_create (const char *name, unsigned long command)
|
||||
{
|
||||
menu_entry_t *entry;
|
||||
|
||||
entry = g_new (menu_entry_t, 1);
|
||||
entry->first_letter = ' ';
|
||||
entry->text = parse_hotkey (name);
|
||||
entry->command = command;
|
||||
entry->shortcut = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menu_entry_free (menu_entry_t * entry)
|
||||
{
|
||||
if (entry != NULL)
|
||||
{
|
||||
release_hotkey (entry->text);
|
||||
g_free (entry->shortcut);
|
||||
g_free (entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Menu *
|
||||
create_menu (const char *name, GList * entries, const char *help_node)
|
||||
{
|
||||
Menu *menu;
|
||||
|
||||
menu = g_new (Menu, 1);
|
||||
menu->start_x = 0;
|
||||
menu->text = parse_hotkey (name);
|
||||
menu->entries = entries;
|
||||
menu->max_entry_len = 1;
|
||||
menu->max_hotkey_len = 0;
|
||||
menu->selected = 0;
|
||||
menu->help_node = g_strdup (help_node);
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
destroy_menu (Menu * menu)
|
||||
{
|
||||
release_hotkey (menu->text);
|
||||
g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
|
||||
g_list_free (menu->entries);
|
||||
g_free (menu->help_node);
|
||||
g_free (menu);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WMenuBar *
|
||||
menubar_new (int y, int x, int cols, GList * menu)
|
||||
{
|
||||
@ -725,6 +782,8 @@ menubar_new (int y, int x, int cols, GList * menu)
|
||||
return menubar;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||
{
|
||||
@ -742,6 +801,8 @@ menubar_set_menu (WMenuBar * menubar, GList * menu)
|
||||
menubar_arrange (menubar);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||
{
|
||||
@ -754,10 +815,12 @@ menubar_add_menu (WMenuBar * menubar, Menu * menu)
|
||||
menubar_arrange (menubar);
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Properly space menubar items. Should be called when menubar is created
|
||||
* and also when widget width is changed (i.e. upon xterm resize).
|
||||
*/
|
||||
|
||||
void
|
||||
menubar_arrange (WMenuBar * menubar)
|
||||
{
|
||||
@ -811,9 +874,13 @@ menubar_arrange (WMenuBar * menubar)
|
||||
#endif /* RESIZABLE_MENUBAR */
|
||||
}
|
||||
|
||||
/* Find MenuBar widget in the dialog */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Find MenuBar widget in the dialog */
|
||||
|
||||
WMenuBar *
|
||||
find_menubar (const Dlg_head * h)
|
||||
{
|
||||
return (WMenuBar *) find_widget_type (h, menubar_callback);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
47
src/menu.h
47
src/menu.h
@ -1,4 +1,3 @@
|
||||
|
||||
/* Header file for pulldown menu engine for Midnignt Commander
|
||||
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
2007, 2009 Free Software Foundation, Inc.
|
||||
@ -21,26 +20,30 @@
|
||||
* \brief Header: pulldown menu code
|
||||
*/
|
||||
|
||||
#ifndef MC_MENU_H
|
||||
#define MC_MENU_H
|
||||
#ifndef MC__MENU_H
|
||||
#define MC__MENU_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "widget.h"
|
||||
|
||||
extern int menubar_visible;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef struct menu_entry_t {
|
||||
#define menu_separator_create() NULL
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct menu_entry_t
|
||||
{
|
||||
unsigned char first_letter;
|
||||
struct hotkey_t text;
|
||||
unsigned long command;
|
||||
char *shortcut;
|
||||
} menu_entry_t;
|
||||
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t *me);
|
||||
#define menu_separator_create() NULL
|
||||
|
||||
typedef struct Menu {
|
||||
typedef struct Menu
|
||||
{
|
||||
int start_x; /* position relative to menubar start */
|
||||
struct hotkey_t text;
|
||||
GList *entries;
|
||||
@ -50,13 +53,9 @@ typedef struct Menu {
|
||||
char *help_node;
|
||||
} Menu;
|
||||
|
||||
Menu *create_menu (const char *name, GList *entries,
|
||||
const char *help_node);
|
||||
|
||||
void destroy_menu (Menu *menu);
|
||||
|
||||
/* The button bar menu */
|
||||
typedef struct WMenuBar {
|
||||
typedef struct WMenuBar
|
||||
{
|
||||
Widget widget;
|
||||
|
||||
gboolean is_active; /* If the menubar is in use */
|
||||
@ -66,6 +65,19 @@ typedef struct WMenuBar {
|
||||
int previous_widget; /* Selected widget ID before activating menu */
|
||||
} WMenuBar;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern int menubar_visible;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
menu_entry_t *menu_entry_create (const char *name, unsigned long command);
|
||||
void menu_entry_free (menu_entry_t * me);
|
||||
|
||||
Menu *create_menu (const char *name, GList * entries, const char *help_node);
|
||||
|
||||
void destroy_menu (Menu * menu);
|
||||
|
||||
WMenuBar *menubar_new (int y, int x, int cols, GList * menu);
|
||||
void menubar_set_menu (WMenuBar * menubar, GList * menu);
|
||||
void menubar_add_menu (WMenuBar * menubar, Menu * menu);
|
||||
@ -73,4 +85,5 @@ void menubar_arrange (WMenuBar *menubar);
|
||||
|
||||
WMenuBar *find_menubar (const Dlg_head * h);
|
||||
|
||||
#endif /* MC_MENU_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__MENU_H */
|
||||
|
61
src/mfmt.c
61
src/mfmt.c
@ -22,7 +22,14 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
enum states {
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum states
|
||||
{
|
||||
header,
|
||||
definition,
|
||||
plain,
|
||||
@ -34,6 +41,15 @@ enum states {
|
||||
seen_m
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
@ -41,8 +57,10 @@ main (void)
|
||||
int state = newline;
|
||||
int space_seen = 0;
|
||||
|
||||
while ((c = getchar ()) != EOF){
|
||||
switch (state){
|
||||
while ((c = getchar ()) != EOF)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case plain:
|
||||
if (c == '\n')
|
||||
state = newline;
|
||||
@ -54,7 +72,8 @@ main (void)
|
||||
state = seen_f;
|
||||
else if (c == '\n')
|
||||
putchar ('\n');
|
||||
else {
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
putchar (c);
|
||||
}
|
||||
@ -63,7 +82,8 @@ main (void)
|
||||
case seen_f:
|
||||
if (c == 'r')
|
||||
state = seen_r;
|
||||
else {
|
||||
else
|
||||
{
|
||||
printf ("F%c", c);
|
||||
state = plain;
|
||||
}
|
||||
@ -72,26 +92,33 @@ main (void)
|
||||
case seen_r:
|
||||
if (c == 'o')
|
||||
state = seen_o;
|
||||
else {
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("Fr%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_o:
|
||||
if (c == 'm'){
|
||||
if (c == 'm')
|
||||
{
|
||||
state = seen_m;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("Fro%c", c);
|
||||
}
|
||||
break;
|
||||
|
||||
case seen_m:
|
||||
if (c == ' '){
|
||||
if (c == ' ')
|
||||
{
|
||||
state = definition;
|
||||
printf ("_\bF_\br_\bo_\bm ");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
state = plain;
|
||||
printf ("From%c", c);
|
||||
}
|
||||
@ -99,19 +126,22 @@ main (void)
|
||||
|
||||
case header_new:
|
||||
space_seen = 0;
|
||||
if (c == ' ' || c == '\t') {
|
||||
if (c == ' ' || c == '\t')
|
||||
{
|
||||
state = definition;
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
if (c == '\n'){
|
||||
if (c == '\n')
|
||||
{
|
||||
state = plain;
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
|
||||
case header:
|
||||
if (c == '\n'){
|
||||
if (c == '\n')
|
||||
{
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
@ -124,7 +154,8 @@ main (void)
|
||||
break;
|
||||
|
||||
case definition:
|
||||
if (c == '\n'){
|
||||
if (c == '\n')
|
||||
{
|
||||
putchar (c);
|
||||
state = header_new;
|
||||
break;
|
||||
@ -135,3 +166,5 @@ main (void)
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
241
src/mountlist.c
241
src/mountlist.c
@ -113,6 +113,10 @@
|
||||
#include "lib/global.h"
|
||||
#include "mountlist.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifdef DOLPHIN
|
||||
/* So special that it's not worth putting this in autoconf. */
|
||||
#undef MOUNTED_FREAD_FSTYP
|
||||
@ -127,6 +131,8 @@
|
||||
#define HAVE_INFOMOUNT
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* A mount table entry. */
|
||||
struct mount_entry
|
||||
{
|
||||
@ -146,12 +152,18 @@ struct fs_usage
|
||||
fsfilcnt_t fsu_ffree; /* Free file nodes. */
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static int get_fs_usage (char *path, struct fs_usage *fsp);
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
|
||||
static struct mount_entry *mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
static void
|
||||
free_mount_entry (struct mount_entry *me)
|
||||
{
|
||||
@ -167,6 +179,8 @@ free_mount_entry (struct mount_entry *me)
|
||||
}
|
||||
|
||||
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Return the value of the hexadecimal number represented by CP.
|
||||
No prefix (like '0x') or suffix (like 'h') is expected to be
|
||||
part of CP. */
|
||||
@ -195,6 +209,8 @@ xatoi (const char *cp)
|
||||
|
||||
#ifdef MOUNTED_GETMNTINFO
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
||||
static char *
|
||||
fstype_to_string (short t)
|
||||
@ -293,6 +309,8 @@ fstype_to_string (short t)
|
||||
|
||||
#endif /* MOUNTED_GETMNTINFO */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef MOUNTED_VMOUNT /* AIX. */
|
||||
static char *
|
||||
fstype_to_string (int t)
|
||||
@ -307,7 +325,8 @@ fstype_to_string (int t)
|
||||
}
|
||||
#endif /* MOUNTED_VMOUNT */
|
||||
|
||||
/* Return a list of the currently mounted filesystems, or NULL on error.
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return a list of the currently mounted filesystems, or NULL on error.
|
||||
Add each entry to the tail of the list so that they stay in order.
|
||||
If NEED_FS_TYPE is nonzero, ensure that the filesystem type fields in
|
||||
the returned list are valid. Otherwise, they might not be.
|
||||
@ -612,8 +631,10 @@ read_filesystem_list (int need_fs_type, int all_fs)
|
||||
}
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
/**
|
||||
** QNX has no [gs]etmnt*(), [gs]etfs*(), or /etc/mnttab, but can do
|
||||
** this via the following code.
|
||||
** Note that, as this is based on CWD, it only fills one mount_entry
|
||||
@ -707,109 +728,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
|
||||
}
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
|
||||
void
|
||||
free_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
while (mount_list)
|
||||
{
|
||||
struct mount_entry *next = mount_list->me_next;
|
||||
free_mount_entry (mount_list);
|
||||
mount_list = next;
|
||||
}
|
||||
mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
init_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
free_my_statfs ();
|
||||
mount_list = read_filesystem_list (1, 1);
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
void
|
||||
my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
size_t i, len = 0;
|
||||
struct mount_entry *entry = NULL;
|
||||
struct mount_entry *temp = mount_list;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
while (temp)
|
||||
{
|
||||
i = strlen (temp->me_mountdir);
|
||||
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
|
||||
{
|
||||
len = i;
|
||||
entry = temp;
|
||||
}
|
||||
temp = temp->me_next;
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memset (&fs_use, 0, sizeof (struct fs_usage));
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
** This is the "other side" of the hack to read_filesystem_list() in
|
||||
** mountlist.c.
|
||||
** It's not the most efficient approach, but consumes less memory. It
|
||||
** also accomodates QNX's ability to mount filesystems on the fly.
|
||||
*/
|
||||
struct mount_entry *entry;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
entry = read_filesystem_list (0, 0);
|
||||
if (entry != NULL)
|
||||
{
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
|
||||
myfs_stats->avail = fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
{
|
||||
myfs_stats->type = 0;
|
||||
myfs_stats->mpoint = "unknown";
|
||||
myfs_stats->device = "unknown";
|
||||
myfs_stats->avail = 0;
|
||||
myfs_stats->total = 0;
|
||||
myfs_stats->nfree = 0;
|
||||
myfs_stats->nodes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_INFOMOUNT
|
||||
|
||||
/* Return the number of TOSIZE-byte blocks used by
|
||||
/** Return the number of TOSIZE-byte blocks used by
|
||||
BLOCKS FROMSIZE-byte blocks, rounding away from zero.
|
||||
TOSIZE must be positive. Return -1 if FROMSIZE is not positive. */
|
||||
|
||||
@ -829,6 +749,7 @@ fs_adjust_blocks (fsblkcnt_t blocks, int fromsize, int tosize)
|
||||
return blocks / (tosize / fromsize);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
#if defined(_AIX) && defined(_I386)
|
||||
/* AIX PS/2 does not supply statfs. */
|
||||
static int
|
||||
@ -860,6 +781,7 @@ aix_statfs (char *path, struct statfs *fsb)
|
||||
the filesystem on which PATH resides.
|
||||
Return 0 if successful, -1 if not. */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
static int
|
||||
get_fs_usage (char *path, struct fs_usage *fsp)
|
||||
{
|
||||
@ -942,3 +864,112 @@ get_fs_usage (char *path, struct fs_usage *fsp)
|
||||
}
|
||||
|
||||
#endif /* HAVE_INFOMOUNT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
free_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
while (mount_list)
|
||||
{
|
||||
struct mount_entry *next = mount_list->me_next;
|
||||
free_mount_entry (mount_list);
|
||||
mount_list = next;
|
||||
}
|
||||
mount_list = NULL;
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_my_statfs (void)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
free_my_statfs ();
|
||||
mount_list = read_filesystem_list (1, 1);
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
size_t i, len = 0;
|
||||
struct mount_entry *entry = NULL;
|
||||
struct mount_entry *temp = mount_list;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
while (temp)
|
||||
{
|
||||
i = strlen (temp->me_mountdir);
|
||||
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
|
||||
{
|
||||
len = i;
|
||||
entry = temp;
|
||||
}
|
||||
temp = temp->me_next;
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memset (&fs_use, 0, sizeof (struct fs_usage));
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
myfs_stats->avail = getuid ()? fs_use.fsu_bavail / 2 : fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_LIST */
|
||||
|
||||
#ifdef HAVE_INFOMOUNT_QNX
|
||||
/*
|
||||
** This is the "other side" of the hack to read_filesystem_list() in
|
||||
** mountlist.c.
|
||||
** It's not the most efficient approach, but consumes less memory. It
|
||||
** also accomodates QNX's ability to mount filesystems on the fly.
|
||||
*/
|
||||
struct mount_entry *entry;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
entry = read_filesystem_list (0, 0);
|
||||
if (entry != NULL)
|
||||
{
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
myfs_stats->type = entry->me_dev;
|
||||
myfs_stats->typename = entry->me_type;
|
||||
myfs_stats->mpoint = entry->me_mountdir;
|
||||
myfs_stats->device = entry->me_devname;
|
||||
|
||||
myfs_stats->avail = fs_use.fsu_bfree / 2;
|
||||
myfs_stats->total = fs_use.fsu_blocks / 2;
|
||||
myfs_stats->nfree = fs_use.fsu_ffree;
|
||||
myfs_stats->nodes = fs_use.fsu_files;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_INFOMOUNT_QNX */
|
||||
{
|
||||
myfs_stats->type = 0;
|
||||
myfs_stats->mpoint = "unknown";
|
||||
myfs_stats->device = "unknown";
|
||||
myfs_stats->avail = 0;
|
||||
myfs_stats->total = 0;
|
||||
myfs_stats->nfree = 0;
|
||||
myfs_stats->nodes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -19,8 +19,14 @@
|
||||
* \brief Header: list of mounted filesystems
|
||||
*/
|
||||
|
||||
#ifndef MC_MOUNTLIST_H
|
||||
#define MC_MOUNTLIST_H
|
||||
#ifndef MC__MOUNTLIST_H
|
||||
#define MC__MOUNTLIST_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* Filesystem status */
|
||||
struct my_statfs
|
||||
@ -35,8 +41,14 @@ struct my_statfs
|
||||
int nodes;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
void init_my_statfs (void);
|
||||
void my_statfs (struct my_statfs *myfs_stats, const char *path);
|
||||
void free_my_statfs (void);
|
||||
|
||||
#endif
|
||||
#endif /* MC__MOUNTLIST_H */
|
||||
|
34
src/option.c
34
src/option.c
@ -47,6 +47,17 @@
|
||||
|
||||
#include "option.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -77,6 +88,10 @@ configure_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
configure_box (void)
|
||||
{
|
||||
@ -135,7 +150,8 @@ configure_box (void)
|
||||
|
||||
/* file operation options */
|
||||
QUICK_CHECKBOX (5, dlg_width, 6, dlg_height, N_("Mkdi&r autoname"), &auto_fill_mkdir_name),
|
||||
QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"), &classic_progressbar),
|
||||
QUICK_CHECKBOX (5, dlg_width, 5, dlg_height, N_("Classic pro&gressbar"),
|
||||
&classic_progressbar),
|
||||
QUICK_CHECKBOX (5, dlg_width, 4, dlg_height, N_("Compute tota&ls"),
|
||||
&file_op_compute_totals),
|
||||
QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("&Verbose operation"), &verbose),
|
||||
@ -260,6 +276,8 @@ configure_box (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_options_box (void)
|
||||
{
|
||||
@ -280,7 +298,8 @@ panel_options_box (void)
|
||||
/* quick search */
|
||||
QUICK_RADIO (dlg_width / 2 + 2, dlg_width, 12, dlg_height, QSEARCH_NUM, qsearch_options,
|
||||
(int *) &panels_options.qsearch_mode),
|
||||
QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4, QSEARCH_NUM + 2,
|
||||
QUICK_GROUPBOX (dlg_width / 2, dlg_width, 11, dlg_height, dlg_width / 2 - 4,
|
||||
QSEARCH_NUM + 2,
|
||||
N_("Quick search")),
|
||||
/* file highlighting */
|
||||
QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("&Permissions"),
|
||||
@ -315,7 +334,8 @@ panel_options_box (void)
|
||||
&panels_options.mix_all_files),
|
||||
QUICK_CHECKBOX (5, dlg_width, 3, dlg_height, N_("Use SI si&ze units"),
|
||||
&panels_options.kilobyte_si),
|
||||
QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14, N_("Main panel options")),
|
||||
QUICK_GROUPBOX (3, dlg_width, 2, dlg_height, dlg_width / 2 - 4, 14,
|
||||
N_("Main panel options")),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
@ -398,8 +418,7 @@ panel_options_box (void)
|
||||
|
||||
/* right column */
|
||||
quick_widgets[4].relative_x =
|
||||
quick_widgets[ 7].relative_x =
|
||||
quick_widgets[11].relative_x = Quick_input.xlen / 2;
|
||||
quick_widgets[7].relative_x = quick_widgets[11].relative_x = Quick_input.xlen / 2;
|
||||
for (i = 3; i < 11; i++)
|
||||
if ((i != 4) && (i != 7))
|
||||
quick_widgets[i].relative_x = quick_widgets[4].relative_x + 2;
|
||||
@ -418,8 +437,7 @@ panel_options_box (void)
|
||||
message (D_NORMAL, _("Information"),
|
||||
_("Using the fast reload option may not reflect the exact\n"
|
||||
"directory contents. In this case you'll need to do a\n"
|
||||
"manual reload of the directory. See the man page for\n"
|
||||
"the details."));
|
||||
"manual reload of the directory. See the man page for\n" "the details."));
|
||||
panels_options.fast_reload_msg_shown = TRUE;
|
||||
}
|
||||
update_panels (UP_RELOAD, UP_KEEPSEL);
|
||||
@ -432,3 +450,5 @@ panel_options_box (void)
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
18
src/option.h
18
src/option.h
@ -1,12 +1,22 @@
|
||||
|
||||
/** \file option.h
|
||||
* \brief Header: configure box module
|
||||
*/
|
||||
|
||||
#ifndef MC_OPTION_H
|
||||
#define MC_OPTION_H
|
||||
#ifndef MC__OPTION_H
|
||||
#define MC__OPTION_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void configure_box (void);
|
||||
void panel_options_box (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__OPTION_H */
|
||||
|
71
src/panel.h
71
src/panel.h
@ -1,10 +1,9 @@
|
||||
|
||||
/** \file panel.h
|
||||
* \brief Header: defines WPanel structure
|
||||
*/
|
||||
|
||||
#ifndef MC_PANEL_H
|
||||
#define MC_PANEL_H
|
||||
#ifndef MC__PANEL_H
|
||||
#define MC__PANEL_H
|
||||
|
||||
#include "lib/global.h" /* gboolean */
|
||||
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
||||
@ -14,19 +13,33 @@
|
||||
#include "dialog.h" /* Widget */
|
||||
#include "main.h" /* cd_enum */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define selection(p) (&(p->dir.list[p->selected]))
|
||||
#define DEFAULT_USER_FORMAT "half type name | size | perm"
|
||||
|
||||
#define LIST_TYPES 4
|
||||
|
||||
enum list_types {
|
||||
#define UP_OPTIMIZE 0
|
||||
#define UP_RELOAD 1
|
||||
#define UP_ONLY_CURRENT 2
|
||||
|
||||
#define UP_KEEPSEL ((char *) -1)
|
||||
|
||||
#define other_panel get_other_panel()
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
enum list_types
|
||||
{
|
||||
list_full, /* Name, size, perm/date */
|
||||
list_brief, /* Name */
|
||||
list_long, /* Like ls -l */
|
||||
list_user /* User defined */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
view_listing = 0, /* Directory listing */
|
||||
view_info = 1, /* Information panel */
|
||||
view_tree = 2, /* Tree view */
|
||||
@ -34,14 +47,18 @@ typedef enum {
|
||||
view_nothing = 4, /* Undefined */
|
||||
} panel_view_mode_t;
|
||||
|
||||
enum panel_display_enum {
|
||||
enum panel_display_enum
|
||||
{
|
||||
frame_full, /* full screen frame */
|
||||
frame_half /* half screen frame */
|
||||
};
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct format_e;
|
||||
|
||||
typedef struct panel_format_struct {
|
||||
typedef struct panel_format_struct
|
||||
{
|
||||
const char *id;
|
||||
int min_size;
|
||||
int expands;
|
||||
@ -54,9 +71,8 @@ typedef struct panel_format_struct {
|
||||
sortfn *sort_routine; /* used by mouse_sort_col() */
|
||||
} panel_field_t;
|
||||
|
||||
extern panel_field_t panel_fields [];
|
||||
|
||||
typedef struct WPanel {
|
||||
typedef struct WPanel
|
||||
{
|
||||
Widget widget;
|
||||
dir_list dir; /* Directory contents */
|
||||
|
||||
@ -104,42 +120,40 @@ typedef struct WPanel {
|
||||
int search_chpoint; /*point after last characters in search_char */
|
||||
} WPanel;
|
||||
|
||||
WPanel *panel_new (const char *panel_name);
|
||||
WPanel *panel_new_with_dir (const char *panel_name, const char *dr);
|
||||
void panel_clean_dir (WPanel *panel);
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern panel_field_t panel_fields[];
|
||||
|
||||
extern int torben_fj_mode;
|
||||
extern int show_mini_info;
|
||||
|
||||
extern WPanel *left_panel;
|
||||
extern WPanel *right_panel;
|
||||
extern WPanel *current_panel;
|
||||
|
||||
extern hook_t *select_file_hook;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WPanel *panel_new (const char *panel_name);
|
||||
WPanel *panel_new_with_dir (const char *panel_name, const char *dr);
|
||||
void panel_clean_dir (WPanel * panel);
|
||||
|
||||
void panel_reload (WPanel * panel);
|
||||
void panel_set_sort_order (WPanel * panel, const panel_field_t * sort_order);
|
||||
void panel_re_sort (WPanel * panel);
|
||||
void panel_change_encoding (WPanel * panel);
|
||||
|
||||
#define UP_OPTIMIZE 0
|
||||
#define UP_RELOAD 1
|
||||
#define UP_ONLY_CURRENT 2
|
||||
|
||||
#define UP_KEEPSEL ((char *) -1)
|
||||
|
||||
void update_dirty_panels (void);
|
||||
void update_panels (int force_update, const char *current_file);
|
||||
void panel_update_cols (Widget * widget, int frame_size);
|
||||
int set_panel_formats (WPanel * p);
|
||||
|
||||
#define other_panel get_other_panel()
|
||||
|
||||
extern WPanel *left_panel;
|
||||
extern WPanel *right_panel;
|
||||
extern WPanel *current_panel;
|
||||
|
||||
void try_to_select (WPanel * panel, const char *name);
|
||||
|
||||
void unmark_files (WPanel * panel);
|
||||
void select_item (WPanel * panel);
|
||||
|
||||
extern hook_t *select_file_hook;
|
||||
|
||||
void recalculate_panel_summary (WPanel * panel);
|
||||
void file_mark (WPanel * panel, int idx, int val);
|
||||
void do_file_mark (WPanel * panel, int idx, int val);
|
||||
@ -159,4 +173,5 @@ const char **panel_get_user_possible_fields(gsize *);
|
||||
void panel_init (void);
|
||||
void panel_deinit (void);
|
||||
|
||||
#endif /* MC_PANEL_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__PANEL_H */
|
||||
|
308
src/panelize.c
308
src/panelize.c
@ -51,6 +51,10 @@
|
||||
#include "panelize.h"
|
||||
#include "history.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UX 5
|
||||
#define UY 2
|
||||
|
||||
@ -62,6 +66,10 @@
|
||||
#define B_ADD B_USER
|
||||
#define B_REMOVE (B_USER + 1)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static WListbox *l_panelize;
|
||||
static Dlg_head *panelize_dlg;
|
||||
static int last_listitem;
|
||||
@ -82,7 +90,6 @@ static struct
|
||||
};
|
||||
|
||||
static const char *panelize_section = "Panelize";
|
||||
static void do_external_panelize (char *command);
|
||||
|
||||
/* Directory panelize */
|
||||
static struct panelize
|
||||
@ -92,6 +99,13 @@ static struct panelize
|
||||
struct panelize *next;
|
||||
} *panelize = NULL;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void do_external_panelize (char *command);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
update_command (void)
|
||||
{
|
||||
@ -107,6 +121,8 @@ update_command (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -129,6 +145,8 @@ panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_panelize (void)
|
||||
{
|
||||
@ -197,6 +215,8 @@ init_panelize (void)
|
||||
listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panelize_done (void)
|
||||
{
|
||||
@ -204,6 +224,8 @@ panelize_done (void)
|
||||
repaint_screen ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add2panelize (char *label, char *command)
|
||||
{
|
||||
@ -235,6 +257,8 @@ add2panelize (char *label, char *command)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
add2panelize_cmd (void)
|
||||
{
|
||||
@ -256,6 +280,8 @@ add2panelize_cmd (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_from_panelize (struct panelize *entry)
|
||||
{
|
||||
@ -282,139 +308,7 @@ remove_from_panelize (struct panelize *entry)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
external_panelize (void)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
if (!vfs_current_is_local ())
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot run external panelize in a non-local directory"));
|
||||
return;
|
||||
}
|
||||
|
||||
init_panelize ();
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
run_dlg (panelize_dlg);
|
||||
|
||||
switch (panelize_dlg->ret_value)
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ADD:
|
||||
add2panelize_cmd ();
|
||||
break;
|
||||
|
||||
case B_REMOVE:
|
||||
{
|
||||
struct panelize *entry;
|
||||
|
||||
listbox_get_current (l_panelize, NULL, (void **) &entry);
|
||||
remove_from_panelize (entry);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_ENTER:
|
||||
target = pname->buffer;
|
||||
if (target != NULL && *target)
|
||||
{
|
||||
char *cmd = g_strdup (target);
|
||||
destroy_dlg (panelize_dlg);
|
||||
do_external_panelize (cmd);
|
||||
g_free (cmd);
|
||||
repaint_screen ();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
panelize_done ();
|
||||
}
|
||||
|
||||
void
|
||||
load_panelize (void)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
|
||||
conv = str_crt_conv_from ("UTF-8");
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||
|
||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||
|
||||
if (!profile_keys || *profile_keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
g_strdup ("find . -name \\*.rej -print"));
|
||||
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||
g_strdup ("find . -name \\*.orig -print"));
|
||||
add2panelize (g_strdup (_("Find SUID and SGID programs")),
|
||||
g_strdup
|
||||
("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
||||
return;
|
||||
}
|
||||
|
||||
while (*profile_keys)
|
||||
{
|
||||
|
||||
if (utf8_display || conv == INVALID_CONV)
|
||||
{
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = g_string_new ("");
|
||||
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free (buffer, TRUE);
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
}
|
||||
|
||||
add2panelize (g_string_free (buffer, FALSE),
|
||||
mc_config_get_string (mc_main_config, panelize_section, *profile_keys, ""));
|
||||
profile_keys++;
|
||||
}
|
||||
g_strfreev (keys);
|
||||
str_close_conv (conv);
|
||||
}
|
||||
|
||||
void
|
||||
save_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
|
||||
mc_config_del_group (mc_main_config, panelize_section);
|
||||
for (; current; current = current->next)
|
||||
{
|
||||
if (strcmp (current->label, _("Other command")))
|
||||
mc_config_set_string (mc_main_config,
|
||||
panelize_section, current->label, current->command);
|
||||
}
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
done_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
struct panelize *next;
|
||||
|
||||
for (; current; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
g_free (current->label);
|
||||
g_free (current->command);
|
||||
g_free (current);
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
do_external_panelize (char *command)
|
||||
@ -495,3 +389,149 @@ do_external_panelize (char *command)
|
||||
try_to_select (current_panel, NULL);
|
||||
panel_re_sort (current_panel);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
external_panelize (void)
|
||||
{
|
||||
char *target = NULL;
|
||||
|
||||
if (!vfs_current_is_local ())
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot run external panelize in a non-local directory"));
|
||||
return;
|
||||
}
|
||||
|
||||
init_panelize ();
|
||||
|
||||
/* display file info */
|
||||
tty_setcolor (SELECTED_COLOR);
|
||||
|
||||
run_dlg (panelize_dlg);
|
||||
|
||||
switch (panelize_dlg->ret_value)
|
||||
{
|
||||
case B_CANCEL:
|
||||
break;
|
||||
|
||||
case B_ADD:
|
||||
add2panelize_cmd ();
|
||||
break;
|
||||
|
||||
case B_REMOVE:
|
||||
{
|
||||
struct panelize *entry;
|
||||
|
||||
listbox_get_current (l_panelize, NULL, (void **) &entry);
|
||||
remove_from_panelize (entry);
|
||||
break;
|
||||
}
|
||||
|
||||
case B_ENTER:
|
||||
target = pname->buffer;
|
||||
if (target != NULL && *target)
|
||||
{
|
||||
char *cmd = g_strdup (target);
|
||||
destroy_dlg (panelize_dlg);
|
||||
do_external_panelize (cmd);
|
||||
g_free (cmd);
|
||||
repaint_screen ();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
panelize_done ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_panelize (void)
|
||||
{
|
||||
gchar **profile_keys, **keys;
|
||||
gsize len;
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
|
||||
conv = str_crt_conv_from ("UTF-8");
|
||||
|
||||
profile_keys = keys = mc_config_get_keys (mc_main_config, panelize_section, &len);
|
||||
|
||||
add2panelize (g_strdup (_("Other command")), g_strdup (""));
|
||||
|
||||
if (!profile_keys || *profile_keys == NULL)
|
||||
{
|
||||
add2panelize (g_strdup (_("Find rejects after patching")),
|
||||
g_strdup ("find . -name \\*.rej -print"));
|
||||
add2panelize (g_strdup (_("Find *.orig after patching")),
|
||||
g_strdup ("find . -name \\*.orig -print"));
|
||||
add2panelize (g_strdup (_("Find SUID and SGID programs")),
|
||||
g_strdup
|
||||
("find . \\( \\( -perm -04000 -a -perm +011 \\) -o \\( -perm -02000 -a -perm +01 \\) \\) -print"));
|
||||
return;
|
||||
}
|
||||
|
||||
while (*profile_keys)
|
||||
{
|
||||
|
||||
if (utf8_display || conv == INVALID_CONV)
|
||||
{
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer = g_string_new ("");
|
||||
if (str_convert (conv, *profile_keys, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free (buffer, TRUE);
|
||||
buffer = g_string_new (*profile_keys);
|
||||
}
|
||||
}
|
||||
|
||||
add2panelize (g_string_free (buffer, FALSE),
|
||||
mc_config_get_string (mc_main_config, panelize_section, *profile_keys, ""));
|
||||
profile_keys++;
|
||||
}
|
||||
g_strfreev (keys);
|
||||
str_close_conv (conv);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
|
||||
mc_config_del_group (mc_main_config, panelize_section);
|
||||
for (; current; current = current->next)
|
||||
{
|
||||
if (strcmp (current->label, _("Other command")))
|
||||
mc_config_set_string (mc_main_config,
|
||||
panelize_section, current->label, current->command);
|
||||
}
|
||||
mc_config_save_file (mc_main_config, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
done_panelize (void)
|
||||
{
|
||||
struct panelize *current = panelize;
|
||||
struct panelize *next;
|
||||
|
||||
for (; current; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
g_free (current->label);
|
||||
g_free (current->command);
|
||||
g_free (current);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,14 +1,24 @@
|
||||
|
||||
/** \file panelize.h
|
||||
* \brief Header: External panelization module
|
||||
*/
|
||||
|
||||
#ifndef MC_PANELIZE_H
|
||||
#define MC_PANELIZE_H
|
||||
#ifndef MC__PANELIZE_H
|
||||
#define MC__PANELIZE_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void external_panelize (void);
|
||||
void load_panelize (void);
|
||||
void save_panelize (void);
|
||||
void done_panelize (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__PANELIZE_H */
|
||||
|
2282
src/screen.c
2282
src/screen.c
File diff suppressed because it is too large
Load Diff
@ -36,7 +36,7 @@
|
||||
#include "selcodepage.h"
|
||||
#include "main.h"
|
||||
|
||||
#define ENTRY_LEN 30
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
|
||||
int source_codepage = -1;
|
||||
@ -45,12 +45,28 @@ int display_codepage = -1;
|
||||
char *autodetect_codeset = NULL;
|
||||
gboolean is_autodetect_codeset_enabled = FALSE;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define ENTRY_LEN 30
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
static unsigned char
|
||||
get_hotkey (int n)
|
||||
{
|
||||
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Return value:
|
||||
* -2 (SELECT_CHARSET_CANCEL) : Cancel
|
||||
* -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE
|
||||
@ -71,17 +87,17 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
|
||||
"[Codepages Translation]");
|
||||
|
||||
if (!seldisplay)
|
||||
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"),
|
||||
NULL);
|
||||
LISTBOX_APPEND_TEXT (listbox, '-', _("- < No translation >"), NULL);
|
||||
|
||||
/* insert all the items found */
|
||||
for (i = 0; i < codepages->len; i++) {
|
||||
for (i = 0; i < codepages->len; i++)
|
||||
{
|
||||
const char *name = ((codepage_desc *) g_ptr_array_index (codepages, i))->name;
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i),
|
||||
name);
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey (i), name);
|
||||
LISTBOX_APPEND_TEXT (listbox, get_hotkey (i), buffer, NULL);
|
||||
}
|
||||
if (seldisplay) {
|
||||
if (seldisplay)
|
||||
{
|
||||
unsigned char hotkey = get_hotkey (codepages->len);
|
||||
g_snprintf (buffer, sizeof (buffer), "%c %s", hotkey, _("Other 8 bit"));
|
||||
LISTBOX_APPEND_TEXT (listbox, hotkey, buffer, NULL);
|
||||
@ -96,24 +112,31 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
|
||||
|
||||
listbox_result = run_listbox (listbox);
|
||||
|
||||
if (listbox_result < 0) {
|
||||
if (listbox_result < 0)
|
||||
{
|
||||
/* Cancel dialog */
|
||||
return SELECT_CHARSET_CANCEL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* some charset has been selected */
|
||||
if (seldisplay) {
|
||||
if (seldisplay)
|
||||
{
|
||||
/* charset list is finished with "Other 8 bit" item */
|
||||
return (listbox_result >= (int) codepages->len)
|
||||
? SELECT_CHARSET_OTHER_8BIT
|
||||
: listbox_result;
|
||||
} else {
|
||||
? SELECT_CHARSET_OTHER_8BIT : listbox_result;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* charset list is began with "- < No translation >" item */
|
||||
return (listbox_result - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set codepage */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Set codepage */
|
||||
gboolean
|
||||
do_set_codepage (int codepage)
|
||||
{
|
||||
@ -122,11 +145,11 @@ do_set_codepage (int codepage)
|
||||
|
||||
source_codepage = codepage;
|
||||
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
||||
display_codepage : source_codepage,
|
||||
display_codepage);
|
||||
display_codepage : source_codepage, display_codepage);
|
||||
ret = errmsg == NULL;
|
||||
|
||||
if (!ret) {
|
||||
if (!ret)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
}
|
||||
@ -134,7 +157,8 @@ do_set_codepage (int codepage)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Show menu selecting codepage */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show menu selecting codepage */
|
||||
|
||||
gboolean
|
||||
do_select_codepage (void)
|
||||
@ -149,4 +173,6 @@ do_select_codepage (void)
|
||||
return do_set_codepage (default_source_codepage);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
@ -3,14 +3,12 @@
|
||||
* \brief Header: user %interface for charset %selection
|
||||
*/
|
||||
|
||||
#ifndef MC_SELCODEPAGE_H
|
||||
#define MC_SELCODEPAGE_H
|
||||
#ifndef MC__SELCODEPAGE_H
|
||||
#define MC__SELCODEPAGE_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay);
|
||||
gboolean do_set_codepage (int);
|
||||
gboolean do_select_codepage (void);
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* some results of select_charset() */
|
||||
#define SELECT_CHARSET_CANCEL -2
|
||||
@ -24,4 +22,18 @@ gboolean do_select_codepage (void);
|
||||
/* In other cases select_charset() returns non-negative value
|
||||
* which is number of codepage in codepage list */
|
||||
|
||||
#endif /* MC_SELCODEPAGE_H */
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
int select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay);
|
||||
gboolean do_set_codepage (int);
|
||||
gboolean do_select_codepage (void);
|
||||
|
||||
#endif /* MC__SELCODEPAGE_H */
|
||||
|
70
src/setup.c
70
src/setup.c
@ -71,8 +71,7 @@
|
||||
|
||||
#include "setup.h"
|
||||
|
||||
/*** global variables **************************************************/
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
char *profile_name; /* .mc/ini */
|
||||
char *global_profile_name; /* mc.lib */
|
||||
|
||||
@ -112,15 +111,15 @@ panels_options_t panels_options = {
|
||||
|
||||
int easy_patterns = 1;
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/* In order to use everywhere the same setup for the locale we use defines */
|
||||
#define FMTYEAR _("%b %e %Y")
|
||||
#define FMTTIME _("%b %e %H:%M")
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static char *panels_profile_name = NULL; /* .mc/panels.ini */
|
||||
|
||||
@ -301,7 +300,9 @@ static const struct
|
||||
|
||||
static const char *panels_section = "Panels";
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/**
|
||||
Get name of config file.
|
||||
@ -377,6 +378,8 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
setup__is_cfg_group_must_panel_config (const char *grp)
|
||||
{
|
||||
@ -387,6 +390,8 @@ setup__is_cfg_group_must_panel_config (const char *grp)
|
||||
? grp : NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
setup__move_panels_config_into_separate_file (const char *profile)
|
||||
{
|
||||
@ -442,11 +447,13 @@ setup__move_panels_config_into_separate_file (const char *profile)
|
||||
mc_config_deinit (tmp_cfg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
Create new mc_config object from specified ini-file or
|
||||
append data to existing mc_config object from ini-file
|
||||
|
||||
*/
|
||||
|
||||
static void
|
||||
load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
|
||||
{
|
||||
@ -462,6 +469,8 @@ load_setup_init_config_from_file (mc_config_t ** config, const char *fname)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_layout (void)
|
||||
{
|
||||
@ -472,6 +481,8 @@ load_layout (void)
|
||||
layout[i].opt_name, *layout[i].opt_addr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
{
|
||||
@ -536,6 +547,8 @@ load_keys_from_section (const char *terminal, mc_config_t * cfg)
|
||||
g_free (section_name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t * cfg)
|
||||
{
|
||||
@ -587,6 +600,8 @@ load_keymap_from_section (const char *section_name, GArray * keymap, mc_config_t
|
||||
g_strfreev (keys);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static mc_config_t *
|
||||
load_setup_get_keymap_profile_config (void)
|
||||
{
|
||||
@ -642,6 +657,8 @@ load_setup_get_keymap_profile_config (void)
|
||||
return keymap_config;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static panel_view_mode_t
|
||||
setup__load_panel_state (const char *section)
|
||||
{
|
||||
@ -664,6 +681,8 @@ setup__load_panel_state (const char *section)
|
||||
return mode;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
panel_save_type (const char *section, panel_view_mode_t type)
|
||||
{
|
||||
@ -677,7 +696,9 @@ panel_save_type (const char *section, panel_view_mode_t type)
|
||||
}
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
setup_init (void)
|
||||
@ -716,6 +737,8 @@ setup_init (void)
|
||||
return profile;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_setup (void)
|
||||
{
|
||||
@ -850,6 +873,8 @@ load_setup (void)
|
||||
clipboard_paste_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_paste", "");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
save_setup (void)
|
||||
{
|
||||
@ -890,6 +915,8 @@ save_setup (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
done_setup (void)
|
||||
{
|
||||
@ -915,6 +942,8 @@ done_setup (void)
|
||||
/* directory_history_free (); */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_config (void)
|
||||
{
|
||||
@ -940,6 +969,8 @@ save_config (void)
|
||||
g_free (profile);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
setup_save_config_show_error (const char *filename, GError ** error)
|
||||
{
|
||||
@ -951,6 +982,8 @@ setup_save_config_show_error (const char *filename, GError ** error)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_layout (void)
|
||||
{
|
||||
@ -965,6 +998,8 @@ save_layout (void)
|
||||
g_free (profile);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_key_defs (void)
|
||||
{
|
||||
@ -986,6 +1021,8 @@ load_key_defs (void)
|
||||
load_keys_from_section (getenv ("TERM"), mc_main_config);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
char *
|
||||
load_anon_passwd (void)
|
||||
@ -1002,6 +1039,8 @@ load_anon_passwd (void)
|
||||
}
|
||||
#endif /* ENABLE_VFS_FTP */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
load_keymap_defs (void)
|
||||
{
|
||||
@ -1097,6 +1136,8 @@ load_keymap_defs (void)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
free_keymap_defs (void)
|
||||
{
|
||||
@ -1132,6 +1173,8 @@ free_keymap_defs (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_load_setup (WPanel * panel, const char *section)
|
||||
{
|
||||
@ -1179,6 +1222,8 @@ panel_load_setup (WPanel * panel, const char *section)
|
||||
panel->user_mini_status = mc_config_get_int (mc_panels_config, section, "user_mini_status", 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
panel_save_setup (struct WPanel *panel, const char *section)
|
||||
{
|
||||
@ -1209,6 +1254,8 @@ panel_save_setup (struct WPanel *panel, const char *section)
|
||||
mc_config_set_int (mc_panels_config, section, "user_mini_status", panel->user_mini_status);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
save_panel_types (void)
|
||||
{
|
||||
@ -1244,6 +1291,8 @@ save_panel_types (void)
|
||||
mc_config_save_file (mc_panels_config, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Load panels options from [Panels] section.
|
||||
*/
|
||||
@ -1258,7 +1307,8 @@ panels_load_options (void)
|
||||
*panels_ini_options[i].opt_addr =
|
||||
mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
|
||||
panels_ini_options[i].opt_old_name != NULL
|
||||
? panels_ini_options[i].opt_old_name : panels_ini_options[i].opt_name,
|
||||
? panels_ini_options[i].
|
||||
opt_old_name : panels_ini_options[i].opt_name,
|
||||
*panels_ini_options[i].opt_addr);
|
||||
|
||||
qmode = mc_config_get_int (mc_main_config, CONFIG_APP_SECTION,
|
||||
@ -1290,6 +1340,8 @@ panels_load_options (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
Save panels options in [Panels] section.
|
||||
*/
|
||||
@ -1305,3 +1357,5 @@ panels_save_options (void)
|
||||
mc_config_set_int (mc_main_config, panels_section,
|
||||
"quick_search_mode", (int) panels_options.qsearch_mode);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
80
src/setup.h
80
src/setup.h
@ -1,51 +1,21 @@
|
||||
|
||||
/** \file setup.h
|
||||
* \brief Header: setup loading/saving
|
||||
*/
|
||||
|
||||
#ifndef MC_SETUP_H
|
||||
#define MC_SETUP_H
|
||||
#ifndef MC__SETUP_H
|
||||
#define MC__SETUP_H
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "lib/global.h" /* GError */
|
||||
|
||||
#include "panel.h" /* WPanel, panel_view_mode_t */
|
||||
|
||||
/* global paremeters */
|
||||
extern char *profile_name;
|
||||
extern char *global_profile_name;
|
||||
extern char *setup_color_string;
|
||||
extern char *term_color_string;
|
||||
extern char *color_terminal_string;
|
||||
extern int verbose;
|
||||
extern int mouse_close_dialog;
|
||||
extern int select_flags;
|
||||
extern int setup_copymove_persistent_attr;
|
||||
extern int num_history_items_recorded;
|
||||
extern int classic_progressbar;
|
||||
extern int easy_patterns;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* TAB length for editor and viewer */
|
||||
#define DEFAULT_TAB_SPACING 8
|
||||
extern int option_tab_spacing;
|
||||
|
||||
char *setup_init (void);
|
||||
void load_setup (void);
|
||||
gboolean save_setup (void);
|
||||
void done_setup (void);
|
||||
void save_config (void);
|
||||
void setup_save_config_show_error (const char *filename, GError **error);
|
||||
|
||||
void save_layout (void);
|
||||
|
||||
void load_key_defs (void);
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
char *load_anon_passwd (void);
|
||||
#endif /* ENABLE_VFS_FTP */
|
||||
|
||||
void load_keymap_defs (void);
|
||||
void free_keymap_defs (void);
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@ -55,6 +25,9 @@ typedef enum
|
||||
QSEARCH_NUM
|
||||
} qsearch_mode_t;
|
||||
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/* panels ini options; [Panels] section */
|
||||
typedef struct
|
||||
{
|
||||
@ -77,11 +50,47 @@ typedef struct
|
||||
qsearch_mode_t qsearch_mode; /* Quick search mode */
|
||||
} panels_options_t;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* global paremeters */
|
||||
extern char *profile_name;
|
||||
extern char *global_profile_name;
|
||||
extern char *setup_color_string;
|
||||
extern char *term_color_string;
|
||||
extern char *color_terminal_string;
|
||||
extern int verbose;
|
||||
extern int mouse_close_dialog;
|
||||
extern int select_flags;
|
||||
extern int setup_copymove_persistent_attr;
|
||||
extern int num_history_items_recorded;
|
||||
extern int classic_progressbar;
|
||||
extern int easy_patterns;
|
||||
extern int option_tab_spacing;
|
||||
|
||||
extern panels_options_t panels_options;
|
||||
|
||||
extern panel_view_mode_t startup_left_mode;
|
||||
extern panel_view_mode_t startup_right_mode;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
char *setup_init (void);
|
||||
void load_setup (void);
|
||||
gboolean save_setup (void);
|
||||
void done_setup (void);
|
||||
void save_config (void);
|
||||
void setup_save_config_show_error (const char *filename, GError ** error);
|
||||
|
||||
void save_layout (void);
|
||||
|
||||
void load_key_defs (void);
|
||||
#ifdef ENABLE_VFS_FTP
|
||||
char *load_anon_passwd (void);
|
||||
#endif /* ENABLE_VFS_FTP */
|
||||
|
||||
void load_keymap_defs (void);
|
||||
void free_keymap_defs (void);
|
||||
|
||||
void panel_load_setup (struct WPanel *panel, const char *section);
|
||||
void panel_save_setup (struct WPanel *panel, const char *section);
|
||||
void save_panel_types (void);
|
||||
@ -89,4 +98,5 @@ void save_panel_types (void);
|
||||
void panels_load_options (void);
|
||||
void panels_save_options (void);
|
||||
|
||||
#endif /* MC_SETUP_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__SETUP_H */
|
||||
|
827
src/subshell.c
827
src/subshell.c
@ -60,6 +60,30 @@
|
||||
#include "consaver/cons.saver.h" /* handle_console() */
|
||||
#include "subshell.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* If using a subshell for evaluating commands this is true */
|
||||
int use_subshell =
|
||||
#ifdef SUBSHELL_OPTIONAL
|
||||
FALSE;
|
||||
#else
|
||||
TRUE;
|
||||
#endif
|
||||
|
||||
/* File descriptors of the pseudoterminal used by the subshell */
|
||||
int subshell_pty = 0;
|
||||
|
||||
/* State of the subshell:
|
||||
* INACTIVE: the default state; awaiting a command
|
||||
* ACTIVE: remain in the shell until the user hits `subshell_switch_key'
|
||||
* RUNNING_COMMAND: return to MC when the current command finishes */
|
||||
enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
char *subshell_prompt = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef WEXITSTATUS
|
||||
#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
||||
#endif
|
||||
@ -68,17 +92,6 @@
|
||||
#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
/* tcsh closes all non-standard file descriptors, so we have to use a pipe */
|
||||
static char tcsh_fifo[128];
|
||||
|
||||
/* Local functions */
|
||||
static void init_raw_mode (void);
|
||||
static gboolean feed_subshell (int how, int fail_on_error);
|
||||
static void synchronize (void);
|
||||
static int pty_open_master (char *pty_name);
|
||||
static int pty_open_slave (const char *pty_name);
|
||||
static int resize_tty (int fd);
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
@ -91,30 +104,6 @@ static int resize_tty (int fd);
|
||||
#define STDERR_FILENO 2
|
||||
#endif
|
||||
|
||||
/* If using a subshell for evaluating commands this is true */
|
||||
int use_subshell =
|
||||
#ifdef SUBSHELL_OPTIONAL
|
||||
FALSE;
|
||||
#else
|
||||
TRUE;
|
||||
#endif
|
||||
|
||||
/* File descriptors of the pseudoterminal used by the subshell */
|
||||
int subshell_pty = 0;
|
||||
static int subshell_pty_slave = -1;
|
||||
|
||||
/* The key for switching back to MC from the subshell */
|
||||
static const char subshell_switch_key = XCTRL ('o') & 255;
|
||||
|
||||
/* State of the subshell:
|
||||
* INACTIVE: the default state; awaiting a command
|
||||
* ACTIVE: remain in the shell until the user hits `subshell_switch_key'
|
||||
* RUNNING_COMMAND: return to MC when the current command finishes */
|
||||
enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
char *subshell_prompt = NULL;
|
||||
|
||||
/* Initial length of the buffer for the subshell's prompt */
|
||||
#define INITIAL_PROMPT_SIZE 10
|
||||
|
||||
@ -124,6 +113,8 @@ char *subshell_prompt = NULL;
|
||||
/* Length of the buffer for all I/O with the subshell */
|
||||
#define PTY_BUFFER_SIZE BUF_SMALL /* Arbitrary; but keep it >= 80 */
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/* For pipes */
|
||||
enum
|
||||
{
|
||||
@ -131,11 +122,6 @@ enum
|
||||
WRITE = 1
|
||||
};
|
||||
|
||||
static char pty_buffer[PTY_BUFFER_SIZE] = "\0"; /* For reading/writing on the subshell's pty */
|
||||
static int subshell_pipe[2]; /* To pass CWD info from the subshell to MC */
|
||||
static pid_t subshell_pid = 1; /* The subshell's process ID */
|
||||
static char subshell_cwd[MC_MAXPATHLEN + 1]; /* One extra char for final '\n' */
|
||||
|
||||
/* Subshell type (gleaned from the SHELL environment variable, if available) */
|
||||
static enum
|
||||
{
|
||||
@ -145,6 +131,30 @@ static enum
|
||||
FISH
|
||||
} subshell_type;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* tcsh closes all non-standard file descriptors, so we have to use a pipe */
|
||||
static char tcsh_fifo[128];
|
||||
|
||||
static int subshell_pty_slave = -1;
|
||||
|
||||
/* The key for switching back to MC from the subshell */
|
||||
/* *INDENT-OFF* */
|
||||
static const char subshell_switch_key = XCTRL ('o') & 255;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
/* For reading/writing on the subshell's pty */
|
||||
static char pty_buffer[PTY_BUFFER_SIZE] = "\0";
|
||||
|
||||
/* To pass CWD info from the subshell to MC */
|
||||
static int subshell_pipe[2];
|
||||
|
||||
/* The subshell's process ID */
|
||||
static pid_t subshell_pid = 1;
|
||||
|
||||
/* One extra char for final '\n' */
|
||||
static char subshell_cwd[MC_MAXPATHLEN + 1];
|
||||
|
||||
/* Flag to indicate whether the subshell is ready for next command */
|
||||
static int subshell_ready;
|
||||
|
||||
@ -167,9 +177,21 @@ static struct termios raw_mode;
|
||||
static int prompt_pos;
|
||||
|
||||
|
||||
/*
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void init_raw_mode (void);
|
||||
static gboolean feed_subshell (int how, int fail_on_error);
|
||||
static void synchronize (void);
|
||||
static int pty_open_master (char *pty_name);
|
||||
static int pty_open_slave (const char *pty_name);
|
||||
static int resize_tty (int fd);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Write all data, even if the write() call is interrupted.
|
||||
*/
|
||||
|
||||
static ssize_t
|
||||
write_all (int fd, const void *buf, size_t count)
|
||||
{
|
||||
@ -195,7 +217,8 @@ write_all (int fd, const void *buf, size_t count)
|
||||
return written;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Prepare child process to running the shell and run it.
|
||||
*
|
||||
* Modifies the global variables (in the child process only):
|
||||
@ -203,6 +226,7 @@ write_all (int fd, const void *buf, size_t count)
|
||||
*
|
||||
* Returns: never.
|
||||
*/
|
||||
|
||||
static void
|
||||
init_subshell_child (const char *pty_name)
|
||||
{
|
||||
@ -326,13 +350,15 @@ init_subshell_child (const char *pty_name)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Check MC_SID to prevent running one mc from another.
|
||||
* Return:
|
||||
* 0 if no parent mc in our session was found,
|
||||
* 1 if parent mc was found and the user wants to continue,
|
||||
* 2 if parent mc was found and the user wants to quit mc.
|
||||
*/
|
||||
|
||||
static int
|
||||
check_sid (void)
|
||||
{
|
||||
@ -368,8 +394,358 @@ check_sid (void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_raw_mode ()
|
||||
{
|
||||
static int initialized = 0;
|
||||
|
||||
/* MC calls tty_reset_shell_mode() in pre_exec() to set the real tty to its */
|
||||
/* original settings. However, here we need to make this tty very raw, */
|
||||
/* so that all keyboard signals, XON/XOFF, etc. will get through to the */
|
||||
/* pty. So, instead of changing the code for execute(), pre_exec(), */
|
||||
/* etc, we just set up the modes we need here, before each command. */
|
||||
|
||||
if (initialized == 0) /* First time: initialise `raw_mode' */
|
||||
{
|
||||
tcgetattr (STDOUT_FILENO, &raw_mode);
|
||||
raw_mode.c_lflag &= ~ICANON; /* Disable line-editing chars, etc. */
|
||||
raw_mode.c_lflag &= ~ISIG; /* Disable intr, quit & suspend chars */
|
||||
raw_mode.c_lflag &= ~ECHO; /* Disable input echoing */
|
||||
raw_mode.c_iflag &= ~IXON; /* Pass ^S/^Q to subshell undisturbed */
|
||||
raw_mode.c_iflag &= ~ICRNL; /* Don't translate CRs into LFs */
|
||||
raw_mode.c_oflag &= ~OPOST; /* Don't postprocess output */
|
||||
raw_mode.c_cc[VTIME] = 0; /* IE: wait forever, and return as */
|
||||
raw_mode.c_cc[VMIN] = 1; /* soon as a character is available */
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Feed the subshell our keyboard input until it says it's finished */
|
||||
|
||||
static gboolean
|
||||
feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
fd_set read_set; /* For `select' */
|
||||
int maxfdp;
|
||||
int bytes; /* For the return value from `read' */
|
||||
int i; /* Loop counter */
|
||||
|
||||
struct timeval wtime; /* Maximum time we wait for the subshell */
|
||||
struct timeval *wptr;
|
||||
|
||||
/* we wait up to 10 seconds if fail_on_error, forever otherwise */
|
||||
wtime.tv_sec = 10;
|
||||
wtime.tv_usec = 0;
|
||||
wptr = fail_on_error ? &wtime : NULL;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
/* Prepare the file-descriptor set and call `select' */
|
||||
|
||||
FD_ZERO (&read_set);
|
||||
FD_SET (subshell_pty, &read_set);
|
||||
FD_SET (subshell_pipe[READ], &read_set);
|
||||
maxfdp = max (subshell_pty, subshell_pipe[READ]);
|
||||
if (how == VISIBLY)
|
||||
{
|
||||
FD_SET (STDIN_FILENO, &read_set);
|
||||
maxfdp = max (maxfdp, STDIN_FILENO);
|
||||
}
|
||||
|
||||
if (select (maxfdp + 1, &read_set, NULL, NULL, wptr) == -1)
|
||||
{
|
||||
|
||||
/* Despite using SA_RESTART, we still have to check for this */
|
||||
if (errno == EINTR)
|
||||
continue; /* try all over again */
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "select (FD_SETSIZE, &read_set...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (FD_ISSET (subshell_pty, &read_set))
|
||||
/* Read from the subshell, write to stdout */
|
||||
|
||||
/* This loop improves performance by reducing context switches
|
||||
by a factor of 20 or so... unfortunately, it also hangs MC
|
||||
randomly, because of an apparent Linux bug. Investigate. */
|
||||
/* for (i=0; i<5; ++i) * FIXME -- experimental */
|
||||
{
|
||||
bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer));
|
||||
|
||||
/* The subshell has died */
|
||||
if (bytes == -1 && errno == EIO && !subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pty...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (how == VISIBLY)
|
||||
write_all (STDOUT_FILENO, pty_buffer, bytes);
|
||||
}
|
||||
|
||||
else if (FD_ISSET (subshell_pipe[READ], &read_set))
|
||||
/* Read the subshell's CWD and capture its prompt */
|
||||
{
|
||||
bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN + 1);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pipe[READ]...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
subshell_cwd[bytes - 1] = 0; /* Squash the final '\n' */
|
||||
|
||||
synchronize ();
|
||||
|
||||
subshell_ready = TRUE;
|
||||
if (subshell_state == RUNNING_COMMAND)
|
||||
{
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (FD_ISSET (STDIN_FILENO, &read_set))
|
||||
/* Read from stdin, write to the subshell */
|
||||
{
|
||||
bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer));
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr,
|
||||
"read (STDIN_FILENO, pty_buffer...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
if (pty_buffer[i] == subshell_switch_key)
|
||||
{
|
||||
write_all (subshell_pty, pty_buffer, i);
|
||||
if (subshell_ready)
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
write_all (subshell_pty, pty_buffer, bytes);
|
||||
|
||||
if (pty_buffer[bytes - 1] == '\n' || pty_buffer[bytes - 1] == '\r')
|
||||
subshell_ready = FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Wait until the subshell dies or stops. If it stops, make it resume.
|
||||
* Possibly modifies the globals `subshell_alive' and `subshell_stopped'
|
||||
*/
|
||||
|
||||
static void
|
||||
synchronize (void)
|
||||
{
|
||||
sigset_t sigchld_mask, old_mask;
|
||||
|
||||
sigemptyset (&sigchld_mask);
|
||||
sigaddset (&sigchld_mask, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask);
|
||||
|
||||
/*
|
||||
* SIGCHLD should not be blocked, but we unblock it just in case.
|
||||
* This is known to be useful for cygwin 1.3.12 and older.
|
||||
*/
|
||||
sigdelset (&old_mask, SIGCHLD);
|
||||
|
||||
/* Wait until the subshell has stopped */
|
||||
while (subshell_alive && !subshell_stopped)
|
||||
sigsuspend (&old_mask);
|
||||
|
||||
if (subshell_state != ACTIVE)
|
||||
{
|
||||
/* Discard all remaining data from stdin to the subshell */
|
||||
tcflush (subshell_pty_slave, TCIFLUSH);
|
||||
}
|
||||
|
||||
subshell_stopped = FALSE;
|
||||
kill (subshell_pid, SIGCONT);
|
||||
|
||||
sigprocmask (SIG_SETMASK, &old_mask, NULL);
|
||||
/* We can't do any better without modifying the shell(s) */
|
||||
}
|
||||
|
||||
/* pty opening functions */
|
||||
|
||||
#ifdef HAVE_GRANTPT
|
||||
|
||||
/* System V version of pty_open_master */
|
||||
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
char *slave_name;
|
||||
int pty_master;
|
||||
|
||||
#ifdef HAVE_POSIX_OPENPT
|
||||
pty_master = posix_openpt (O_RDWR);
|
||||
#elif HAVE_GETPT
|
||||
/* getpt () is a GNU extension (glibc 2.1.x) */
|
||||
pty_master = getpt ();
|
||||
#elif IS_AIX
|
||||
strcpy (pty_name, "/dev/ptc");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#else
|
||||
strcpy (pty_name, "/dev/ptmx");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#endif
|
||||
|
||||
if (pty_master == -1)
|
||||
return -1;
|
||||
|
||||
if (grantpt (pty_master) == -1 /* Grant access to slave */
|
||||
|| unlockpt (pty_master) == -1 /* Clear slave's lock flag */
|
||||
|| !(slave_name = ptsname (pty_master))) /* Get slave's name */
|
||||
{
|
||||
close (pty_master);
|
||||
return -1;
|
||||
}
|
||||
strcpy (pty_name, slave_name);
|
||||
return pty_master;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** System V version of pty_open_slave */
|
||||
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave = open (pty_name, O_RDWR);
|
||||
|
||||
if (pty_slave == -1)
|
||||
{
|
||||
fprintf (stderr, "open (%s, O_RDWR): %s\r\n", pty_name, unix_error_string (errno));
|
||||
return -1;
|
||||
}
|
||||
#if !defined(__osf__) && !defined(__linux__)
|
||||
#if defined (I_FIND) && defined (I_PUSH)
|
||||
if (!ioctl (pty_slave, I_FIND, "ptem"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ptem") == -1)
|
||||
{
|
||||
fprintf (stderr, "ioctl (%d, I_PUSH, \"ptem\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ioctl (pty_slave, I_FIND, "ldterm"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ldterm") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ldterm\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#if !defined(sgi) && !defined(__sgi)
|
||||
if (!ioctl (pty_slave, I_FIND, "ttcompat"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ttcompat") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ttcompat\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#endif /* sgi || __sgi */
|
||||
#endif /* I_FIND && I_PUSH */
|
||||
#endif /* __osf__ || __linux__ */
|
||||
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#else /* !HAVE_GRANTPT */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** BSD version of pty_open_master */
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
int pty_master;
|
||||
const char *ptr1, *ptr2;
|
||||
|
||||
strcpy (pty_name, "/dev/ptyXX");
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
|
||||
{
|
||||
pty_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
|
||||
{
|
||||
pty_name[9] = *ptr2;
|
||||
|
||||
/* Try to open master */
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
if (pty_master == -1)
|
||||
{
|
||||
if (errno == ENOENT) /* Different from EIO */
|
||||
return -1; /* Out of pty devices */
|
||||
continue; /* Try next pty device */
|
||||
}
|
||||
pty_name[5] = 't'; /* Change "pty" to "tty" */
|
||||
if (access (pty_name, 6) != 0)
|
||||
{
|
||||
close (pty_master);
|
||||
pty_name[5] = 'p';
|
||||
continue;
|
||||
}
|
||||
return pty_master;
|
||||
}
|
||||
}
|
||||
return -1; /* Ran out of pty devices */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** BSD version of pty_open_slave */
|
||||
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave;
|
||||
struct group *group_info = getgrnam ("tty");
|
||||
|
||||
if (group_info != NULL)
|
||||
{
|
||||
/* The following two calls will only succeed if we are root */
|
||||
/* [Commented out while permissions problem is investigated] */
|
||||
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
|
||||
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
|
||||
}
|
||||
pty_slave = open (pty_name, O_RDWR);
|
||||
if (pty_slave == -1)
|
||||
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
#endif /* !HAVE_GRANTPT */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Fork the subshell, and set up many, many things.
|
||||
*
|
||||
* Possibly modifies the global variables:
|
||||
@ -533,33 +909,7 @@ init_subshell (void)
|
||||
use_subshell = FALSE; /* Subshell died instantly, so don't use it */
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
init_raw_mode ()
|
||||
{
|
||||
static int initialized = 0;
|
||||
|
||||
/* MC calls tty_reset_shell_mode() in pre_exec() to set the real tty to its */
|
||||
/* original settings. However, here we need to make this tty very raw, */
|
||||
/* so that all keyboard signals, XON/XOFF, etc. will get through to the */
|
||||
/* pty. So, instead of changing the code for execute(), pre_exec(), */
|
||||
/* etc, we just set up the modes we need here, before each command. */
|
||||
|
||||
if (initialized == 0) /* First time: initialise `raw_mode' */
|
||||
{
|
||||
tcgetattr (STDOUT_FILENO, &raw_mode);
|
||||
raw_mode.c_lflag &= ~ICANON; /* Disable line-editing chars, etc. */
|
||||
raw_mode.c_lflag &= ~ISIG; /* Disable intr, quit & suspend chars */
|
||||
raw_mode.c_lflag &= ~ECHO; /* Disable input echoing */
|
||||
raw_mode.c_iflag &= ~IXON; /* Pass ^S/^Q to subshell undisturbed */
|
||||
raw_mode.c_iflag &= ~ICRNL; /* Don't translate CRs into LFs */
|
||||
raw_mode.c_oflag &= ~OPOST; /* Don't postprocess output */
|
||||
raw_mode.c_cc[VTIME] = 0; /* IE: wait forever, and return as */
|
||||
raw_mode.c_cc[VMIN] = 1; /* soon as a character is available */
|
||||
initialized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
invoke_subshell (const char *command, int how, char **new_dir)
|
||||
@ -612,6 +962,8 @@ invoke_subshell (const char *command, int how, char **new_dir)
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
read_subshell_prompt (void)
|
||||
{
|
||||
@ -670,7 +1022,9 @@ read_subshell_prompt (void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Resize given terminal using TIOCSWINSZ, return ioctl() result */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Resize given terminal using TIOCSWINSZ, return ioctl() result */
|
||||
|
||||
static int
|
||||
resize_tty (int fd)
|
||||
{
|
||||
@ -687,7 +1041,9 @@ resize_tty (int fd)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Resize subshell_pty */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Resize subshell_pty */
|
||||
|
||||
void
|
||||
resize_subshell (void)
|
||||
{
|
||||
@ -697,6 +1053,8 @@ resize_subshell (void)
|
||||
resize_tty (subshell_pty);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
exit_subshell (void)
|
||||
{
|
||||
@ -726,7 +1084,8 @@ exit_subshell (void)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Carefully quote directory name to allow entering any directory safely,
|
||||
* no matter what weird characters it may contain in its name.
|
||||
* NOTE: Treat directory name an untrusted data, don't allow it to cause
|
||||
@ -742,6 +1101,7 @@ exit_subshell (void)
|
||||
* cd "`printf "%b" 'ABC\0nnnDEF\0nnnXYZ'`"
|
||||
*
|
||||
*/
|
||||
|
||||
static char *
|
||||
subshell_name_quote (const char *s)
|
||||
{
|
||||
@ -809,7 +1169,9 @@ subshell_name_quote (const char *s)
|
||||
}
|
||||
|
||||
|
||||
/* If it actually changed the directory it returns true */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** If it actually changed the directory it returns true */
|
||||
|
||||
void
|
||||
do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
|
||||
{
|
||||
@ -903,6 +1265,7 @@ do_subshell_chdir (const char *directory, int do_update, int reset_prompt)
|
||||
/* like /usr////lib/../bin, or the strcmp() above will fail */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
subshell_get_console_attributes (void)
|
||||
@ -917,9 +1280,11 @@ subshell_get_console_attributes (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Figure out whether the subshell has stopped, exited or been killed
|
||||
* Possibly modifies: `subshell_alive', `subshell_stopped' and `quit' */
|
||||
|
||||
/* Figure out whether the subshell has stopped, exited or been killed */
|
||||
/* Possibly modifies: `subshell_alive', `subshell_stopped' and `quit' */
|
||||
void
|
||||
sigchld_handler (int sig)
|
||||
{
|
||||
@ -978,314 +1343,6 @@ sigchld_handler (int sig)
|
||||
/* If we got here, some other child exited; ignore it */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Feed the subshell our keyboard input until it says it's finished */
|
||||
static gboolean
|
||||
feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
fd_set read_set; /* For `select' */
|
||||
int maxfdp;
|
||||
int bytes; /* For the return value from `read' */
|
||||
int i; /* Loop counter */
|
||||
|
||||
struct timeval wtime; /* Maximum time we wait for the subshell */
|
||||
struct timeval *wptr;
|
||||
|
||||
/* we wait up to 10 seconds if fail_on_error, forever otherwise */
|
||||
wtime.tv_sec = 10;
|
||||
wtime.tv_usec = 0;
|
||||
wptr = fail_on_error ? &wtime : NULL;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
if (!subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
/* Prepare the file-descriptor set and call `select' */
|
||||
|
||||
FD_ZERO (&read_set);
|
||||
FD_SET (subshell_pty, &read_set);
|
||||
FD_SET (subshell_pipe[READ], &read_set);
|
||||
maxfdp = max (subshell_pty, subshell_pipe[READ]);
|
||||
if (how == VISIBLY)
|
||||
{
|
||||
FD_SET (STDIN_FILENO, &read_set);
|
||||
maxfdp = max (maxfdp, STDIN_FILENO);
|
||||
}
|
||||
|
||||
if (select (maxfdp + 1, &read_set, NULL, NULL, wptr) == -1)
|
||||
{
|
||||
|
||||
/* Despite using SA_RESTART, we still have to check for this */
|
||||
if (errno == EINTR)
|
||||
continue; /* try all over again */
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "select (FD_SETSIZE, &read_set...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (FD_ISSET (subshell_pty, &read_set))
|
||||
/* Read from the subshell, write to stdout */
|
||||
|
||||
/* This loop improves performance by reducing context switches
|
||||
by a factor of 20 or so... unfortunately, it also hangs MC
|
||||
randomly, because of an apparent Linux bug. Investigate. */
|
||||
/* for (i=0; i<5; ++i) * FIXME -- experimental */
|
||||
{
|
||||
bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer));
|
||||
|
||||
/* The subshell has died */
|
||||
if (bytes == -1 && errno == EIO && !subshell_alive)
|
||||
return FALSE;
|
||||
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pty...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (how == VISIBLY)
|
||||
write_all (STDOUT_FILENO, pty_buffer, bytes);
|
||||
}
|
||||
|
||||
else if (FD_ISSET (subshell_pipe[READ], &read_set))
|
||||
/* Read the subshell's CWD and capture its prompt */
|
||||
{
|
||||
bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN + 1);
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pipe[READ]...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
subshell_cwd[bytes - 1] = 0; /* Squash the final '\n' */
|
||||
|
||||
synchronize ();
|
||||
|
||||
subshell_ready = TRUE;
|
||||
if (subshell_state == RUNNING_COMMAND)
|
||||
{
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
else if (FD_ISSET (STDIN_FILENO, &read_set))
|
||||
/* Read from stdin, write to the subshell */
|
||||
{
|
||||
bytes = read (STDIN_FILENO, pty_buffer, sizeof (pty_buffer));
|
||||
if (bytes <= 0)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr,
|
||||
"read (STDIN_FILENO, pty_buffer...): %s\r\n", unix_error_string (errno));
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
if (pty_buffer[i] == subshell_switch_key)
|
||||
{
|
||||
write_all (subshell_pty, pty_buffer, i);
|
||||
if (subshell_ready)
|
||||
subshell_state = INACTIVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
write_all (subshell_pty, pty_buffer, bytes);
|
||||
|
||||
if (pty_buffer[bytes - 1] == '\n' || pty_buffer[bytes - 1] == '\r')
|
||||
subshell_ready = FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Wait until the subshell dies or stops. If it stops, make it resume. */
|
||||
/* Possibly modifies the globals `subshell_alive' and `subshell_stopped' */
|
||||
static void
|
||||
synchronize (void)
|
||||
{
|
||||
sigset_t sigchld_mask, old_mask;
|
||||
|
||||
sigemptyset (&sigchld_mask);
|
||||
sigaddset (&sigchld_mask, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigchld_mask, &old_mask);
|
||||
|
||||
/*
|
||||
* SIGCHLD should not be blocked, but we unblock it just in case.
|
||||
* This is known to be useful for cygwin 1.3.12 and older.
|
||||
*/
|
||||
sigdelset (&old_mask, SIGCHLD);
|
||||
|
||||
/* Wait until the subshell has stopped */
|
||||
while (subshell_alive && !subshell_stopped)
|
||||
sigsuspend (&old_mask);
|
||||
|
||||
if (subshell_state != ACTIVE)
|
||||
{
|
||||
/* Discard all remaining data from stdin to the subshell */
|
||||
tcflush (subshell_pty_slave, TCIFLUSH);
|
||||
}
|
||||
|
||||
subshell_stopped = FALSE;
|
||||
kill (subshell_pid, SIGCONT);
|
||||
|
||||
sigprocmask (SIG_SETMASK, &old_mask, NULL);
|
||||
/* We can't do any better without modifying the shell(s) */
|
||||
}
|
||||
|
||||
/* pty opening functions */
|
||||
|
||||
#ifdef HAVE_GRANTPT
|
||||
|
||||
/* System V version of pty_open_master */
|
||||
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
char *slave_name;
|
||||
int pty_master;
|
||||
|
||||
#ifdef HAVE_POSIX_OPENPT
|
||||
pty_master = posix_openpt (O_RDWR);
|
||||
#elif HAVE_GETPT
|
||||
/* getpt () is a GNU extension (glibc 2.1.x) */
|
||||
pty_master = getpt ();
|
||||
#elif IS_AIX
|
||||
strcpy (pty_name, "/dev/ptc");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#else
|
||||
strcpy (pty_name, "/dev/ptmx");
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
#endif
|
||||
|
||||
if (pty_master == -1)
|
||||
return -1;
|
||||
|
||||
if (grantpt (pty_master) == -1 /* Grant access to slave */
|
||||
|| unlockpt (pty_master) == -1 /* Clear slave's lock flag */
|
||||
|| !(slave_name = ptsname (pty_master))) /* Get slave's name */
|
||||
{
|
||||
close (pty_master);
|
||||
return -1;
|
||||
}
|
||||
strcpy (pty_name, slave_name);
|
||||
return pty_master;
|
||||
}
|
||||
|
||||
/* System V version of pty_open_slave */
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave = open (pty_name, O_RDWR);
|
||||
|
||||
if (pty_slave == -1)
|
||||
{
|
||||
fprintf (stderr, "open (%s, O_RDWR): %s\r\n", pty_name, unix_error_string (errno));
|
||||
return -1;
|
||||
}
|
||||
#if !defined(__osf__) && !defined(__linux__)
|
||||
#if defined (I_FIND) && defined (I_PUSH)
|
||||
if (!ioctl (pty_slave, I_FIND, "ptem"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ptem") == -1)
|
||||
{
|
||||
fprintf (stderr, "ioctl (%d, I_PUSH, \"ptem\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!ioctl (pty_slave, I_FIND, "ldterm"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ldterm") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ldterm\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#if !defined(sgi) && !defined(__sgi)
|
||||
if (!ioctl (pty_slave, I_FIND, "ttcompat"))
|
||||
if (ioctl (pty_slave, I_PUSH, "ttcompat") == -1)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"ioctl (%d, I_PUSH, \"ttcompat\") failed: %s\r\n",
|
||||
pty_slave, unix_error_string (errno));
|
||||
close (pty_slave);
|
||||
return -1;
|
||||
}
|
||||
#endif /* sgi || __sgi */
|
||||
#endif /* I_FIND && I_PUSH */
|
||||
#endif /* __osf__ || __linux__ */
|
||||
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#else /* !HAVE_GRANTPT */
|
||||
|
||||
/* BSD version of pty_open_master */
|
||||
static int
|
||||
pty_open_master (char *pty_name)
|
||||
{
|
||||
int pty_master;
|
||||
const char *ptr1, *ptr2;
|
||||
|
||||
strcpy (pty_name, "/dev/ptyXX");
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
|
||||
{
|
||||
pty_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
|
||||
{
|
||||
pty_name[9] = *ptr2;
|
||||
|
||||
/* Try to open master */
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
if (pty_master == -1)
|
||||
{
|
||||
if (errno == ENOENT) /* Different from EIO */
|
||||
return -1; /* Out of pty devices */
|
||||
continue; /* Try next pty device */
|
||||
}
|
||||
pty_name[5] = 't'; /* Change "pty" to "tty" */
|
||||
if (access (pty_name, 6) != 0)
|
||||
{
|
||||
close (pty_master);
|
||||
pty_name[5] = 'p';
|
||||
continue;
|
||||
}
|
||||
return pty_master;
|
||||
}
|
||||
}
|
||||
return -1; /* Ran out of pty devices */
|
||||
}
|
||||
|
||||
/* BSD version of pty_open_slave */
|
||||
static int
|
||||
pty_open_slave (const char *pty_name)
|
||||
{
|
||||
int pty_slave;
|
||||
struct group *group_info = getgrnam ("tty");
|
||||
|
||||
if (group_info != NULL)
|
||||
{
|
||||
/* The following two calls will only succeed if we are root */
|
||||
/* [Commented out while permissions problem is investigated] */
|
||||
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
|
||||
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
|
||||
}
|
||||
pty_slave = open (pty_name, O_RDWR);
|
||||
if (pty_slave == -1)
|
||||
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_GRANTPT */
|
||||
#endif /* HAVE_SUBSHELL_SUPPORT */
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
/** \file subshell.h
|
||||
* \brief Header: concurrent shell support
|
||||
*/
|
||||
|
||||
#ifndef MC_SUBSHELL_H
|
||||
#define MC_SUBSHELL_H
|
||||
#ifndef MC__SUBSHELL_H
|
||||
#define MC__SUBSHELL_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Used to distinguish between a normal MC termination and */
|
||||
/* one caused by typing `exit' or `logout' in the subshell */
|
||||
@ -12,23 +13,34 @@
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* State of the subshell; see subshell.c for an explanation */
|
||||
|
||||
enum subshell_state_enum
|
||||
{ INACTIVE, ACTIVE, RUNNING_COMMAND };
|
||||
|
||||
/* For the `how' argument to various functions */
|
||||
enum
|
||||
{ QUIETLY, VISIBLY };
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* If using a subshell for evaluating commands this is true */
|
||||
extern int use_subshell;
|
||||
|
||||
/* File descriptor of the pseudoterminal used by the subshell */
|
||||
extern int subshell_pty;
|
||||
|
||||
/* State of the subshell; see subshell.c for an explanation */
|
||||
enum subshell_state_enum {INACTIVE, ACTIVE, RUNNING_COMMAND};
|
||||
extern enum subshell_state_enum subshell_state;
|
||||
|
||||
/* Holds the latest prompt captured from the subshell */
|
||||
extern char *subshell_prompt;
|
||||
|
||||
/* For the `how' argument to various functions */
|
||||
enum {QUIETLY, VISIBLY};
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Exported functions */
|
||||
void init_subshell (void);
|
||||
int invoke_subshell (const char *command, int how, char **new_dir);
|
||||
int read_subshell_prompt (void);
|
||||
@ -38,8 +50,9 @@ void do_subshell_chdir (const char *directory, int update_prompt, int reset_prom
|
||||
void subshell_get_console_attributes (void);
|
||||
void sigchld_handler (int sig);
|
||||
|
||||
#else
|
||||
#else /* not HAVE_SUBSHELL_SUPPORT */
|
||||
#define use_subshell 0
|
||||
#endif /* not HAVE_SUBSHELL_SUPPORT */
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__SUBSHELL_H */
|
||||
|
@ -31,6 +31,14 @@
|
||||
#include "lib/global.h"
|
||||
#include "src/textconf.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
static const char *const vfs_supported[] = {
|
||||
#ifdef ENABLE_VFS_CPIO
|
||||
@ -61,7 +69,6 @@ static const char *const vfs_supported[] = {
|
||||
};
|
||||
#endif /* ENABLE_VFS */
|
||||
|
||||
|
||||
static const char *const features[] = {
|
||||
#ifdef USE_INTERNAL_EDIT
|
||||
N_("With builtin Editor\n"),
|
||||
@ -119,6 +126,13 @@ static const char *const features[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
show_version (void)
|
||||
{
|
||||
@ -149,3 +163,5 @@ show_version (void)
|
||||
#undef TYPE_INFO
|
||||
(void) printf ("\n");
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,11 +1,21 @@
|
||||
|
||||
/** \file textconf.h
|
||||
* \brief Header: prints features specific for this build
|
||||
*/
|
||||
|
||||
#ifndef MC_TEXTCONF_H
|
||||
#define MC_TEXTCONF_H
|
||||
#ifndef MC__TEXTCONF_H
|
||||
#define MC__TEXTCONF_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
extern void show_version (void);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TEXTCONF_H */
|
||||
|
132
src/tree.c
132
src/tree.c
@ -68,14 +68,17 @@
|
||||
#include "tree.h"
|
||||
#include "filegui.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define tlines(t) (t->is_panel ? t->widget.lines - 2 - (show_mini_info ? 2 : 0) : t->widget.lines)
|
||||
|
||||
/* Use the color of the parent widget for the unselected entries */
|
||||
#define TREE_NORMALC(h) (h->color[DLG_COLOR_NORMAL])
|
||||
#define TREE_CURRENTC(h) (h->color[DLG_COLOR_FOCUS])
|
||||
|
||||
/* Specifies the display mode: 1d or 2d */
|
||||
static gboolean tree_navigation_flag = FALSE;
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct WTree
|
||||
{
|
||||
@ -91,9 +94,18 @@ struct WTree
|
||||
shown and the selected */
|
||||
};
|
||||
|
||||
/* Forwards */
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Specifies the display mode: 1d or 2d */
|
||||
static gboolean tree_navigation_flag = FALSE;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void tree_rescan (void *data);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
back_ptr (tree_entry * ptr, int *count)
|
||||
{
|
||||
@ -108,6 +120,8 @@ back_ptr (tree_entry * ptr, int *count)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
forw_ptr (tree_entry * ptr, int *count)
|
||||
{
|
||||
@ -122,6 +136,8 @@ forw_ptr (tree_entry * ptr, int *count)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
remove_callback (tree_entry * entry, void *data)
|
||||
{
|
||||
@ -136,7 +152,9 @@ remove_callback (tree_entry * entry, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the ~/.mc/Tree file */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Save the ~/.mc/Tree file */
|
||||
|
||||
static void
|
||||
save_tree (WTree * tree)
|
||||
{
|
||||
@ -156,6 +174,8 @@ save_tree (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_remove_entry (WTree * tree, char *name)
|
||||
{
|
||||
@ -163,6 +183,8 @@ tree_remove_entry (WTree * tree, char *name)
|
||||
tree_store_remove_entry (name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_destroy (WTree * tree)
|
||||
{
|
||||
@ -174,7 +196,9 @@ tree_destroy (WTree * tree)
|
||||
tree->selected_ptr = NULL;
|
||||
}
|
||||
|
||||
/* Loads the .mc.tree file */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Loads the .mc.tree file */
|
||||
|
||||
static void
|
||||
load_tree (WTree * tree)
|
||||
{
|
||||
@ -184,6 +208,8 @@ load_tree (WTree * tree)
|
||||
tree_chdir (tree, home_dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
|
||||
{
|
||||
@ -220,6 +246,8 @@ tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
show_tree (WTree * tree)
|
||||
{
|
||||
@ -306,7 +334,8 @@ show_tree (WTree * tree)
|
||||
if (current->sublevel == topsublevel)
|
||||
{
|
||||
/* Show full name */
|
||||
tty_print_string (str_fit_to_term (current->name, tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
|
||||
tty_print_string (str_fit_to_term
|
||||
(current->name, tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -336,7 +365,8 @@ show_tree (WTree * tree)
|
||||
|
||||
/* Show sub-name */
|
||||
tty_print_char (' ');
|
||||
tty_print_string (str_fit_to_term (current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
|
||||
tty_print_string (str_fit_to_term
|
||||
(current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
|
||||
}
|
||||
|
||||
/* Calculate the next value for current */
|
||||
@ -373,6 +403,8 @@ show_tree (WTree * tree)
|
||||
tree_show_mini_info (tree, tree_lines, tree_cols);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_check_focus (WTree * tree)
|
||||
{
|
||||
@ -382,6 +414,8 @@ tree_check_focus (WTree * tree)
|
||||
tree->topdiff = tlines (tree) - 3 - 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_backward (WTree * tree, int i)
|
||||
{
|
||||
@ -409,6 +443,8 @@ tree_move_backward (WTree * tree, int i)
|
||||
tree_check_focus (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_forward (WTree * tree, int i)
|
||||
{
|
||||
@ -436,6 +472,8 @@ tree_move_forward (WTree * tree, int i)
|
||||
tree_check_focus (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_child (WTree * tree)
|
||||
{
|
||||
@ -468,6 +506,8 @@ tree_move_to_child (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_to_parent (WTree * tree)
|
||||
{
|
||||
@ -491,6 +531,8 @@ tree_move_to_parent (WTree * tree)
|
||||
return tree->selected_ptr != old;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_top (WTree * tree)
|
||||
{
|
||||
@ -498,6 +540,8 @@ tree_move_to_top (WTree * tree)
|
||||
tree->topdiff = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_to_bottom (WTree * tree)
|
||||
{
|
||||
@ -505,7 +549,9 @@ tree_move_to_bottom (WTree * tree)
|
||||
tree->topdiff = tlines (tree) - 3 - 1;
|
||||
}
|
||||
|
||||
/* Handle mouse click */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Handle mouse click */
|
||||
|
||||
static void
|
||||
tree_event (WTree * tree, int y)
|
||||
{
|
||||
@ -517,6 +563,8 @@ tree_event (WTree * tree, int y)
|
||||
show_tree (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_chdir_sel (WTree * tree)
|
||||
{
|
||||
@ -535,6 +583,8 @@ tree_chdir_sel (WTree * tree)
|
||||
show_tree (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
maybe_chdir (WTree * tree)
|
||||
{
|
||||
@ -542,7 +592,9 @@ maybe_chdir (WTree * tree)
|
||||
tree_chdir_sel (tree);
|
||||
}
|
||||
|
||||
/* Mouse callback */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Mouse callback */
|
||||
|
||||
static int
|
||||
event_callback (Gpm_Event * event, void *data)
|
||||
{
|
||||
@ -587,7 +639,9 @@ event_callback (Gpm_Event * event, void *data)
|
||||
return MOU_NORMAL;
|
||||
}
|
||||
|
||||
/* Search tree for text */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Search tree for text */
|
||||
|
||||
static int
|
||||
search_tree (WTree * tree, char *text)
|
||||
{
|
||||
@ -619,6 +673,8 @@ search_tree (WTree * tree, char *text)
|
||||
return found;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_do_search (WTree * tree, int key)
|
||||
{
|
||||
@ -640,6 +696,8 @@ tree_do_search (WTree * tree, int key)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_rescan (void *data)
|
||||
{
|
||||
@ -655,6 +713,8 @@ tree_rescan (void *data)
|
||||
ret = mc_chdir (old_dir);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_forget (void *data)
|
||||
{
|
||||
@ -663,6 +723,8 @@ tree_forget (void *data)
|
||||
tree_remove_entry (tree, tree->selected_ptr->name);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_copy (WTree * tree, const char *default_dest)
|
||||
{
|
||||
@ -695,6 +757,8 @@ tree_copy (WTree * tree, const char *default_dest)
|
||||
g_free (dest);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move (WTree * tree, const char *default_dest)
|
||||
{
|
||||
@ -743,6 +807,8 @@ tree_move (WTree * tree, const char *default_dest)
|
||||
g_free (dest);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
static void
|
||||
tree_mkdir (WTree * tree)
|
||||
@ -763,6 +829,8 @@ tree_mkdir (WTree * tree)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_rmdir (void *data)
|
||||
{
|
||||
@ -795,6 +863,8 @@ tree_rmdir (void *data)
|
||||
file_op_context_destroy (ctx);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_up (WTree * tree)
|
||||
{
|
||||
@ -803,6 +873,8 @@ tree_move_up (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_down (WTree * tree)
|
||||
{
|
||||
@ -811,6 +883,8 @@ tree_move_down (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_home (WTree * tree)
|
||||
{
|
||||
@ -819,6 +893,8 @@ tree_move_home (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static inline void
|
||||
tree_move_end (WTree * tree)
|
||||
{
|
||||
@ -827,6 +903,8 @@ tree_move_end (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_pgup (WTree * tree)
|
||||
{
|
||||
@ -835,6 +913,8 @@ tree_move_pgup (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_move_pgdn (WTree * tree)
|
||||
{
|
||||
@ -843,6 +923,8 @@ tree_move_pgdn (WTree * tree)
|
||||
maybe_chdir (tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_left (WTree * tree)
|
||||
{
|
||||
@ -858,6 +940,8 @@ tree_move_left (WTree * tree)
|
||||
return v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
tree_move_right (WTree * tree)
|
||||
{
|
||||
@ -874,6 +958,8 @@ tree_move_right (WTree * tree)
|
||||
return v;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_start_search (WTree * tree)
|
||||
{
|
||||
@ -904,6 +990,8 @@ tree_start_search (WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_toggle_navig (WTree * tree)
|
||||
{
|
||||
@ -913,6 +1001,8 @@ tree_toggle_navig (WTree * tree)
|
||||
: Q_ ("ButtonBar|Dynamc"), tree_map, (Widget *) tree);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_execute_cmd (WTree * tree, unsigned long command)
|
||||
{
|
||||
@ -977,6 +1067,8 @@ tree_execute_cmd (WTree * tree, unsigned long command)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_key (WTree * tree, int key)
|
||||
{
|
||||
@ -1030,6 +1122,8 @@ tree_key (WTree * tree, int key)
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_frame (Dlg_head * h, WTree * tree)
|
||||
{
|
||||
@ -1055,6 +1149,8 @@ tree_frame (Dlg_head * h, WTree * tree)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
{
|
||||
@ -1117,6 +1213,10 @@ tree_callback (Widget * w, widget_msg_t msg, int parm)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WTree *
|
||||
tree_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
{
|
||||
@ -1140,6 +1240,8 @@ tree_new (int y, int x, int lines, int cols, gboolean is_panel)
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_chdir (WTree * tree, const char *dir)
|
||||
{
|
||||
@ -1154,21 +1256,29 @@ tree_chdir (WTree * tree, const char *dir)
|
||||
}
|
||||
}
|
||||
|
||||
/* Return name of the currently selected entry */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Return name of the currently selected entry */
|
||||
|
||||
char *
|
||||
tree_selected_name (const WTree * tree)
|
||||
{
|
||||
return tree->selected_ptr->name;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
sync_tree (const char *path)
|
||||
{
|
||||
tree_chdir (the_tree, path);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
WTree *
|
||||
find_tree (struct Dlg_head *h)
|
||||
{
|
||||
return (WTree *) find_widget_type (h, tree_callback);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
22
src/tree.h
22
src/tree.h
@ -1,18 +1,29 @@
|
||||
|
||||
/** \file tree.h
|
||||
* \brief Header: directory tree browser
|
||||
*/
|
||||
|
||||
#ifndef MC_TREE_H
|
||||
#define MC_TREE_H
|
||||
#ifndef MC__TREE_H
|
||||
#define MC__TREE_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct WTree WTree;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern WTree *the_tree;
|
||||
extern int xtree_mode;
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
WTree *tree_new (int y, int x, int lines, int cols, gboolean is_panel);
|
||||
|
||||
void tree_chdir (WTree * tree, const char *dir);
|
||||
@ -20,8 +31,7 @@ char *tree_selected_name (const WTree *tree);
|
||||
|
||||
void sync_tree (const char *pathname);
|
||||
|
||||
struct Dlg_head;
|
||||
|
||||
WTree *find_tree (struct Dlg_head *h);
|
||||
|
||||
#endif /* MC_TREE_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TREE_H */
|
||||
|
318
src/treestore.c
318
src/treestore.c
@ -56,13 +56,26 @@
|
||||
#include "treestore.h"
|
||||
#include "setup.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define TREE_SIGNATURE "Midnight Commander TreeStore v 2.0"
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct TreeStore ts;
|
||||
|
||||
static hook_t *remove_entry_hooks;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *tree_store_add_entry (const char *name);
|
||||
|
||||
static hook_t *remove_entry_hooks;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_store_dirty (int state)
|
||||
@ -70,7 +83,9 @@ tree_store_dirty (int state)
|
||||
ts.dirty = state;
|
||||
}
|
||||
|
||||
/* Returns the number of common bytes in the strings. */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the number of common bytes in the strings. */
|
||||
|
||||
static size_t
|
||||
str_common (const char *s1, const char *s2)
|
||||
{
|
||||
@ -81,6 +96,7 @@ str_common (const char *s1, const char *s2)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* The directory names are arranged in a single linked list in the same
|
||||
order as they are displayed. When the tree is displayed the expected
|
||||
order is like this:
|
||||
@ -102,6 +118,7 @@ str_common (const char *s1, const char *s2)
|
||||
greater than zero if p1 is found to be less than, to match, or be greater
|
||||
than p2.
|
||||
*/
|
||||
|
||||
static int
|
||||
pathcmp (const char *p1, const char *p2)
|
||||
{
|
||||
@ -120,27 +137,7 @@ pathcmp (const char *p1, const char *p2)
|
||||
return (*p1 - *p2);
|
||||
}
|
||||
|
||||
/* Searches for specified directory */
|
||||
tree_entry *
|
||||
tree_store_whereis (const char *name)
|
||||
{
|
||||
tree_entry *current = ts.tree_first;
|
||||
int flag = -1;
|
||||
|
||||
while (current && (flag = pathcmp (current->name, name)) < 0)
|
||||
current = current->next;
|
||||
|
||||
if (flag == 0)
|
||||
return current;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct TreeStore *
|
||||
tree_store_get (void)
|
||||
{
|
||||
return &ts;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
decode (char *buffer)
|
||||
@ -179,7 +176,9 @@ decode (char *buffer)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Loads the tree store from the specified filename */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Loads the tree store from the specified filename */
|
||||
|
||||
static int
|
||||
tree_store_load_from (char *name)
|
||||
{
|
||||
@ -283,23 +282,7 @@ tree_store_load_from (char *name)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn int tree_store_load(void)
|
||||
* \brief Loads the tree from the default location
|
||||
* \return 1 if success (true), 0 otherwise (false)
|
||||
*/
|
||||
int
|
||||
tree_store_load (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
retval = tree_store_load_from (name);
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
encode (const char *string)
|
||||
@ -341,7 +324,9 @@ encode (const char *string)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Saves the tree to the specified filename */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Saves the tree to the specified filename */
|
||||
|
||||
static int
|
||||
tree_store_save_to (char *name)
|
||||
{
|
||||
@ -392,32 +377,7 @@ tree_store_save_to (char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn int tree_store_save(void)
|
||||
* \brief Saves the tree to the default file in an atomic fashion
|
||||
* \return 0 if success, errno on error
|
||||
*/
|
||||
int
|
||||
tree_store_save (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
mc_util_make_backup_if_possible (name, ".tmp");
|
||||
|
||||
retval = tree_store_save_to (name);
|
||||
if (retval != 0)
|
||||
{
|
||||
mc_util_restore_from_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return retval;
|
||||
}
|
||||
|
||||
mc_util_unlink_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return 0;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
tree_store_add_entry (const char *name)
|
||||
@ -530,17 +490,7 @@ tree_store_add_entry (const char *name)
|
||||
return new;
|
||||
}
|
||||
|
||||
void
|
||||
tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data)
|
||||
{
|
||||
add_hook (&remove_entry_hooks, (void (*)(void *)) callback, data);
|
||||
}
|
||||
|
||||
void
|
||||
tree_store_remove_entry_remove_hook (tree_store_remove_fn callback)
|
||||
{
|
||||
delete_hook (&remove_entry_hooks, (void (*)(void *)) callback);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tree_store_notify_remove (tree_entry * entry)
|
||||
@ -556,6 +506,8 @@ tree_store_notify_remove (tree_entry * entry)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static tree_entry *
|
||||
remove_entry (tree_entry * entry)
|
||||
{
|
||||
@ -594,6 +546,153 @@ remove_entry (tree_entry * entry)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
process_special_dirs (GList ** special_dirs, char *file)
|
||||
{
|
||||
gchar **buffers, **start_buff;
|
||||
mc_config_t *cfg;
|
||||
gsize buffers_len;
|
||||
|
||||
cfg = mc_config_init (file);
|
||||
if (cfg == NULL)
|
||||
return;
|
||||
|
||||
start_buff = buffers = mc_config_get_string_list (cfg, "Special dirs", "list", &buffers_len);
|
||||
if (buffers != NULL)
|
||||
{
|
||||
while (*buffers != NULL)
|
||||
{
|
||||
*special_dirs = g_list_prepend (*special_dirs, *buffers);
|
||||
*buffers = NULL;
|
||||
buffers++;
|
||||
}
|
||||
g_strfreev (start_buff);
|
||||
}
|
||||
mc_config_deinit (cfg);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
should_skip_directory (const char *dir)
|
||||
{
|
||||
static GList *special_dirs = NULL;
|
||||
GList *l;
|
||||
static gboolean loaded = FALSE;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = TRUE;
|
||||
setup_init ();
|
||||
process_special_dirs (&special_dirs, profile_name);
|
||||
process_special_dirs (&special_dirs, global_profile_name);
|
||||
}
|
||||
|
||||
for (l = special_dirs; l != NULL; l = g_list_next (l))
|
||||
if (strncmp (dir, l->data, strlen (l->data)) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Searches for specified directory */
|
||||
tree_entry *
|
||||
tree_store_whereis (const char *name)
|
||||
{
|
||||
tree_entry *current = ts.tree_first;
|
||||
int flag = -1;
|
||||
|
||||
while (current && (flag = pathcmp (current->name, name)) < 0)
|
||||
current = current->next;
|
||||
|
||||
if (flag == 0)
|
||||
return current;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
struct TreeStore *
|
||||
tree_store_get (void)
|
||||
{
|
||||
return &ts;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn int tree_store_load(void)
|
||||
* \brief Loads the tree from the default location
|
||||
* \return 1 if success (true), 0 otherwise (false)
|
||||
*/
|
||||
|
||||
int
|
||||
tree_store_load (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
retval = tree_store_load_from (name);
|
||||
g_free (name);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* \fn int tree_store_save(void)
|
||||
* \brief Saves the tree to the default file in an atomic fashion
|
||||
* \return 0 if success, errno on error
|
||||
*/
|
||||
|
||||
int
|
||||
tree_store_save (void)
|
||||
{
|
||||
char *name;
|
||||
int retval;
|
||||
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
mc_util_make_backup_if_possible (name, ".tmp");
|
||||
|
||||
retval = tree_store_save_to (name);
|
||||
if (retval != 0)
|
||||
{
|
||||
mc_util_restore_from_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return retval;
|
||||
}
|
||||
|
||||
mc_util_unlink_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data)
|
||||
{
|
||||
add_hook (&remove_entry_hooks, (void (*)(void *)) callback, data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_remove_entry_remove_hook (tree_store_remove_fn callback)
|
||||
{
|
||||
delete_hook (&remove_entry_hooks, (void (*)(void *)) callback);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tree_store_remove_entry (const char *name)
|
||||
{
|
||||
@ -627,7 +726,9 @@ tree_store_remove_entry (const char *name)
|
||||
return;
|
||||
}
|
||||
|
||||
/* This subdirectory exists -> clear deletion mark */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** This subdirectory exists -> clear deletion mark */
|
||||
|
||||
void
|
||||
tree_store_mark_checked (const char *subname)
|
||||
{
|
||||
@ -678,7 +779,9 @@ tree_store_mark_checked (const char *subname)
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark the subdirectories of the current directory for delete */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Mark the subdirectories of the current directory for delete */
|
||||
|
||||
tree_entry *
|
||||
tree_store_start_check (const char *path)
|
||||
{
|
||||
@ -729,7 +832,9 @@ tree_store_start_check (const char *path)
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Delete subdirectories which still have the deletion mark */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Delete subdirectories which still have the deletion mark */
|
||||
|
||||
void
|
||||
tree_store_end_check (void)
|
||||
{
|
||||
@ -767,52 +872,7 @@ tree_store_end_check (void)
|
||||
g_list_free (the_queue);
|
||||
}
|
||||
|
||||
static void
|
||||
process_special_dirs (GList ** special_dirs, char *file)
|
||||
{
|
||||
gchar **buffers, **start_buff;
|
||||
mc_config_t *cfg;
|
||||
gsize buffers_len;
|
||||
|
||||
cfg = mc_config_init (file);
|
||||
if (cfg == NULL)
|
||||
return;
|
||||
|
||||
start_buff = buffers = mc_config_get_string_list (cfg, "Special dirs", "list", &buffers_len);
|
||||
if (buffers != NULL)
|
||||
{
|
||||
while (*buffers != NULL)
|
||||
{
|
||||
*special_dirs = g_list_prepend (*special_dirs, *buffers);
|
||||
*buffers = NULL;
|
||||
buffers++;
|
||||
}
|
||||
g_strfreev (start_buff);
|
||||
}
|
||||
mc_config_deinit (cfg);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
should_skip_directory (const char *dir)
|
||||
{
|
||||
static GList *special_dirs = NULL;
|
||||
GList *l;
|
||||
static gboolean loaded = FALSE;
|
||||
|
||||
if (!loaded)
|
||||
{
|
||||
loaded = TRUE;
|
||||
setup_init ();
|
||||
process_special_dirs (&special_dirs, profile_name);
|
||||
process_special_dirs (&special_dirs, global_profile_name);
|
||||
}
|
||||
|
||||
for (l = special_dirs; l != NULL; l = g_list_next (l))
|
||||
if (strncmp (dir, l->data, strlen (l->data)) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
tree_entry *
|
||||
tree_store_rescan (const char *dir)
|
||||
@ -863,3 +923,5 @@ tree_store_rescan (const char *dir)
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,14 +1,26 @@
|
||||
|
||||
/** \file treestore.h
|
||||
* \brief Header: tree store
|
||||
*
|
||||
* Contains a storage of the file system tree representation.
|
||||
*/
|
||||
|
||||
#ifndef MC_TREE_STORE_H
|
||||
#define MC_TREE_STORE_H
|
||||
#ifndef MC__TREE_STORE_H
|
||||
#define MC__TREE_STORE_H
|
||||
|
||||
typedef struct tree_entry {
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*
|
||||
* Register/unregister notification functions for "entry_remove"
|
||||
*/
|
||||
struct tree_entry;
|
||||
typedef void (*tree_store_remove_fn) (struct tree_entry * tree, void *data);
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct tree_entry
|
||||
{
|
||||
char *name; /* The full path of directory */
|
||||
int sublevel; /* Number of parent directories (slashes) */
|
||||
long submask; /* Bitmask of existing sublevels after this entry */
|
||||
@ -19,7 +31,8 @@ typedef struct tree_entry {
|
||||
struct tree_entry *prev; /* Previous item in the list */
|
||||
} tree_entry;
|
||||
|
||||
struct TreeStore {
|
||||
struct TreeStore
|
||||
{
|
||||
tree_entry *tree_first; /* First entry in the list */
|
||||
tree_entry *tree_last; /* Last entry in the list */
|
||||
tree_entry *check_start; /* Start of checked subdirectories */
|
||||
@ -29,6 +42,10 @@ struct TreeStore {
|
||||
unsigned int dirty:1;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
struct TreeStore *tree_store_get (void);
|
||||
int tree_store_load (void);
|
||||
int tree_store_save (void);
|
||||
@ -39,12 +56,8 @@ void tree_store_end_check (void);
|
||||
tree_entry *tree_store_whereis (const char *name);
|
||||
tree_entry *tree_store_rescan (const char *dir);
|
||||
|
||||
/*
|
||||
* Register/unregister notification functions for "entry_remove"
|
||||
*/
|
||||
typedef void (*tree_store_remove_fn) (tree_entry *tree, void *data);
|
||||
void tree_store_add_entry_remove_hook (tree_store_remove_fn callback,
|
||||
void *data);
|
||||
void tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data);
|
||||
void tree_store_remove_entry_remove_hook (tree_store_remove_fn callback);
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__TREE_STORE_H */
|
||||
|
1025
src/user.c
1025
src/user.c
File diff suppressed because it is too large
Load Diff
18
src/user.h
18
src/user.h
@ -1,19 +1,29 @@
|
||||
|
||||
/** \file user.h
|
||||
* \brief Header: user menu implementation
|
||||
*/
|
||||
|
||||
#ifndef MC_USER_H
|
||||
#define MC_USER_H
|
||||
#ifndef MC__USER_H
|
||||
#define MC__USER_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct WEdit;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void user_menu_cmd (struct WEdit *edit_widget);
|
||||
char *expand_format (struct WEdit *edit_widget, char c, gboolean do_quote);
|
||||
int check_format_view (const char *);
|
||||
int check_format_var (const char *, char **);
|
||||
int check_format_cd (const char *);
|
||||
|
||||
#endif /* MC_USER_H */
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__USER_H */
|
||||
|
409
src/wtools.c
409
src/wtools.c
@ -44,6 +44,206 @@
|
||||
#include "wtools.h"
|
||||
#include "background.h" /* parent_call */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static Dlg_head *last_query_dlg;
|
||||
|
||||
static int sel_pos = 0;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** default query callback, used to reposition query */
|
||||
|
||||
static cb_ret_t
|
||||
default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
{
|
||||
int xpos = COLS / 2 - h->cols / 2;
|
||||
int ypos = LINES / 3 - (h->lines - 3) / 2;
|
||||
|
||||
/* set position */
|
||||
dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols);
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Create message dialog */
|
||||
|
||||
static struct Dlg_head *
|
||||
do_create_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
char *p;
|
||||
Dlg_head *d;
|
||||
|
||||
/* Add empty lines before and after the message */
|
||||
p = g_strconcat ("\n", text, "\n", (char *) NULL);
|
||||
query_dialog (title, p, flags, 0);
|
||||
d = last_query_dlg;
|
||||
|
||||
/* do resize before initing and running */
|
||||
default_query_callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
|
||||
init_dlg (d);
|
||||
g_free (p);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Show message dialog. Dismiss it when any key is pressed.
|
||||
* Not safe to call from background.
|
||||
*/
|
||||
|
||||
static void
|
||||
fg_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
Dlg_head *d;
|
||||
|
||||
d = do_create_message (flags, title, text);
|
||||
tty_getch ();
|
||||
dlg_run_done (d);
|
||||
destroy_dlg (d);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show message box from background */
|
||||
|
||||
#ifdef WITH_BACKGROUND
|
||||
static void
|
||||
bg_message (int dummy, int *flags, char *title, const char *text)
|
||||
{
|
||||
(void) dummy;
|
||||
title = g_strconcat (_("Background process:"), " ", title, (char *) NULL);
|
||||
fg_message (*flags, title, text);
|
||||
g_free (title);
|
||||
}
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
||||
/* {{{ Input routines */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Show dialog, not background safe.
|
||||
*
|
||||
* If the arguments "header" and "text" should be translated,
|
||||
* that MUST be done by the caller of fg_input_dialog_help().
|
||||
*
|
||||
* The argument "history_name" holds the name of a section
|
||||
* in the history file. Data entered in the input field of
|
||||
* the dialog box will be stored there.
|
||||
*
|
||||
*/
|
||||
static char *
|
||||
fg_input_dialog_help (const char *header, const char *text, const char *help,
|
||||
const char *history_name, const char *def_text)
|
||||
{
|
||||
char *my_str;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, 0, NULL, &my_str),
|
||||
/* 3 */ QUICK_LABEL (3, 64, 2, 0, ""),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
int b0_len, b1_len, b_len, gap;
|
||||
char histname[64] = "inp|";
|
||||
int lines, cols;
|
||||
int len;
|
||||
int i;
|
||||
char *p_text;
|
||||
int ret;
|
||||
|
||||
/* buttons */
|
||||
#ifdef ENABLE_NLS
|
||||
quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
|
||||
quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
|
||||
b_len = b0_len + b1_len + 2; /* including gap */
|
||||
|
||||
/* input line */
|
||||
if (history_name != NULL && *history_name != '\0')
|
||||
{
|
||||
g_strlcpy (histname + 3, history_name, sizeof (histname) - 3);
|
||||
quick_widgets[2].u.input.histname = histname;
|
||||
}
|
||||
|
||||
/* The special value of def_text is used to identify password boxes
|
||||
and hide characters with "*". Don't save passwords in history! */
|
||||
if (def_text == INPUT_PASSWORD)
|
||||
{
|
||||
quick_widgets[2].u.input.flags = 1;
|
||||
histname[3] = '\0';
|
||||
quick_widgets[2].u.input.text = "";
|
||||
}
|
||||
|
||||
/* text */
|
||||
p_text = g_strstrip (g_strdup (text));
|
||||
msglen (p_text, &lines, &cols);
|
||||
quick_widgets[3].u.label.text = p_text;
|
||||
|
||||
/* dialog width */
|
||||
len = max (max (str_term_width1 (header), cols) + 4, 64);
|
||||
len = min (max (len, b_len + 6), COLS);
|
||||
|
||||
/* button locations */
|
||||
gap = (len - 8 - b_len) / 3;
|
||||
quick_widgets[1].relative_x = 3 + gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2;
|
||||
|
||||
{
|
||||
QuickDialog Quick_input = {
|
||||
len, lines + 6, -1, -1, header,
|
||||
help, quick_widgets, NULL, TRUE
|
||||
};
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
quick_widgets[i].y_divisions = Quick_input.ylen;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].relative_y += 2 + lines;
|
||||
|
||||
/* input line length */
|
||||
quick_widgets[2].u.input.len = Quick_input.xlen - 6;
|
||||
|
||||
ret = quick_dialog (&Quick_input);
|
||||
}
|
||||
|
||||
g_free (p_text);
|
||||
|
||||
return (ret != B_CANCEL) ? my_str : NULL;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Listbox *
|
||||
create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
@ -110,13 +310,17 @@ create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
return listbox;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Listbox *
|
||||
create_listbox_window (int lines, int cols, const char *title, const char *help)
|
||||
{
|
||||
return create_listbox_window_centered (-1, -1, lines, cols, title, help);
|
||||
}
|
||||
|
||||
/* Returns the number of the item selected */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Returns the number of the item selected */
|
||||
|
||||
int
|
||||
run_listbox (Listbox * l)
|
||||
{
|
||||
@ -129,32 +333,9 @@ run_listbox (Listbox * l)
|
||||
return val;
|
||||
}
|
||||
|
||||
/* default query callback, used to reposition query */
|
||||
static cb_ret_t
|
||||
default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
||||
{
|
||||
switch (msg)
|
||||
{
|
||||
case DLG_RESIZE:
|
||||
{
|
||||
int xpos = COLS / 2 - h->cols / 2;
|
||||
int ypos = LINES / 3 - (h->lines - 3) / 2;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Used to ask questions to the user */
|
||||
|
||||
/* set position */
|
||||
dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols);
|
||||
}
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return default_dlg_callback (h, sender, msg, parm, data);
|
||||
}
|
||||
}
|
||||
|
||||
static Dlg_head *last_query_dlg;
|
||||
|
||||
static int sel_pos = 0;
|
||||
|
||||
/* Used to ask questions to the user */
|
||||
int
|
||||
query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
{
|
||||
@ -246,39 +427,20 @@ query_dialog (const char *header, const char *text, int flags, int count, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
query_set_sel (int new_sel)
|
||||
{
|
||||
sel_pos = new_sel;
|
||||
}
|
||||
|
||||
|
||||
/* Create message dialog */
|
||||
static struct Dlg_head *
|
||||
do_create_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
char *p;
|
||||
Dlg_head *d;
|
||||
|
||||
/* Add empty lines before and after the message */
|
||||
p = g_strconcat ("\n", text, "\n", (char *) NULL);
|
||||
query_dialog (title, p, flags, 0);
|
||||
d = last_query_dlg;
|
||||
|
||||
/* do resize before initing and running */
|
||||
default_query_callback (d, NULL, DLG_RESIZE, 0, NULL);
|
||||
|
||||
init_dlg (d);
|
||||
g_free (p);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Create message dialog. The caller must call dlg_run_done() and
|
||||
* destroy_dlg() to dismiss it. Not safe to call from background.
|
||||
*/
|
||||
|
||||
struct Dlg_head *
|
||||
create_message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
@ -296,37 +458,9 @@ create_message (int flags, const char *title, const char *text, ...)
|
||||
return d;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show message box, background safe */
|
||||
|
||||
/*
|
||||
* Show message dialog. Dismiss it when any key is pressed.
|
||||
* Not safe to call from background.
|
||||
*/
|
||||
static void
|
||||
fg_message (int flags, const char *title, const char *text)
|
||||
{
|
||||
Dlg_head *d;
|
||||
|
||||
d = do_create_message (flags, title, text);
|
||||
tty_getch ();
|
||||
dlg_run_done (d);
|
||||
destroy_dlg (d);
|
||||
}
|
||||
|
||||
|
||||
/* Show message box from background */
|
||||
#ifdef WITH_BACKGROUND
|
||||
static void
|
||||
bg_message (int dummy, int *flags, char *title, const char *text)
|
||||
{
|
||||
(void) dummy;
|
||||
title = g_strconcat (_("Background process:"), " ", title, (char *) NULL);
|
||||
fg_message (*flags, title, text);
|
||||
g_free (title);
|
||||
}
|
||||
#endif /* WITH_BACKGROUND */
|
||||
|
||||
|
||||
/* Show message box, background safe */
|
||||
void
|
||||
message (int flags, const char *title, const char *text, ...)
|
||||
{
|
||||
@ -362,6 +496,8 @@ message (int flags, const char *title, const char *text, ...)
|
||||
/* {{{ Quick dialog routines */
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
{
|
||||
@ -509,6 +645,8 @@ quick_dialog_skip (QuickDialog * qd, int nskip)
|
||||
#undef I18N
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
quick_dialog (QuickDialog * qd)
|
||||
{
|
||||
@ -519,111 +657,14 @@ quick_dialog (QuickDialog * qd)
|
||||
|
||||
/* {{{ Input routines */
|
||||
|
||||
/*
|
||||
* Show dialog, not background safe.
|
||||
*
|
||||
* If the arguments "header" and "text" should be translated,
|
||||
* that MUST be done by the caller of fg_input_dialog_help().
|
||||
*
|
||||
* The argument "history_name" holds the name of a section
|
||||
* in the history file. Data entered in the input field of
|
||||
* the dialog box will be stored there.
|
||||
*
|
||||
*/
|
||||
static char *
|
||||
fg_input_dialog_help (const char *header, const char *text, const char *help,
|
||||
const char *history_name, const char *def_text)
|
||||
{
|
||||
char *my_str;
|
||||
|
||||
QuickWidget quick_widgets[] = {
|
||||
/* 0 */ QUICK_BUTTON (6, 64, 1, 0, N_("&Cancel"), B_CANCEL, NULL),
|
||||
/* 1 */ QUICK_BUTTON (3, 64, 1, 0, N_("&OK"), B_ENTER, NULL),
|
||||
/* 2 */ QUICK_INPUT (3, 64, 0, 0, def_text, 58, 0, NULL, &my_str),
|
||||
/* 3 */ QUICK_LABEL (3, 64, 2, 0, ""),
|
||||
QUICK_END
|
||||
};
|
||||
|
||||
int b0_len, b1_len, b_len, gap;
|
||||
char histname[64] = "inp|";
|
||||
int lines, cols;
|
||||
int len;
|
||||
int i;
|
||||
char *p_text;
|
||||
int ret;
|
||||
|
||||
/* buttons */
|
||||
#ifdef ENABLE_NLS
|
||||
quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text);
|
||||
quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text);
|
||||
#endif /* ENABLE_NLS */
|
||||
|
||||
b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3;
|
||||
b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */
|
||||
b_len = b0_len + b1_len + 2; /* including gap */
|
||||
|
||||
/* input line */
|
||||
if (history_name != NULL && *history_name != '\0')
|
||||
{
|
||||
g_strlcpy (histname + 3, history_name, sizeof (histname) - 3);
|
||||
quick_widgets[2].u.input.histname = histname;
|
||||
}
|
||||
|
||||
/* The special value of def_text is used to identify password boxes
|
||||
and hide characters with "*". Don't save passwords in history! */
|
||||
if (def_text == INPUT_PASSWORD)
|
||||
{
|
||||
quick_widgets[2].u.input.flags = 1;
|
||||
histname[3] = '\0';
|
||||
quick_widgets[2].u.input.text = "";
|
||||
}
|
||||
|
||||
/* text */
|
||||
p_text = g_strstrip (g_strdup (text));
|
||||
msglen (p_text, &lines, &cols);
|
||||
quick_widgets[3].u.label.text = p_text;
|
||||
|
||||
/* dialog width */
|
||||
len = max (max (str_term_width1 (header), cols) + 4, 64);
|
||||
len = min (max (len, b_len + 6), COLS);
|
||||
|
||||
/* button locations */
|
||||
gap = (len - 8 - b_len) / 3;
|
||||
quick_widgets[1].relative_x = 3 + gap;
|
||||
quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + gap + 2;
|
||||
|
||||
{
|
||||
QuickDialog Quick_input = {
|
||||
len, lines + 6, -1, -1, header,
|
||||
help, quick_widgets, NULL, TRUE
|
||||
};
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
quick_widgets[i].x_divisions = Quick_input.xlen;
|
||||
quick_widgets[i].y_divisions = Quick_input.ylen;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
quick_widgets[i].relative_y += 2 + lines;
|
||||
|
||||
/* input line length */
|
||||
quick_widgets[2].u.input.len = Quick_input.xlen - 6;
|
||||
|
||||
ret = quick_dialog (&Quick_input);
|
||||
}
|
||||
|
||||
g_free (p_text);
|
||||
|
||||
return (ret != B_CANCEL) ? my_str : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Show input dialog, background safe.
|
||||
*
|
||||
* If the arguments "header" and "text" should be translated,
|
||||
* that MUST be done by the caller of these wrappers.
|
||||
*/
|
||||
|
||||
char *
|
||||
input_dialog_help (const char *header, const char *text, const char *help,
|
||||
const char *history_name, const char *def_text)
|
||||
@ -648,13 +689,17 @@ input_dialog_help (const char *header, const char *text, const char *help,
|
||||
return fg_input_dialog_help (header, text, help, history_name, def_text);
|
||||
}
|
||||
|
||||
/* Show input dialog with default help, background safe */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Show input dialog with default help, background safe */
|
||||
|
||||
char *
|
||||
input_dialog (const char *header, const char *text, const char *history_name, const char *def_text)
|
||||
{
|
||||
return input_dialog_help (header, text, "[Input Line Keys]", history_name, def_text);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
input_expand_dialog (const char *header, const char *text,
|
||||
const char *history_name, const char *def_text)
|
||||
@ -672,6 +717,8 @@ input_expand_dialog (const char *header, const char *text,
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* }}} */
|
||||
|
210
src/wtools.h
210
src/wtools.h
@ -1,101 +1,19 @@
|
||||
|
||||
/** \file wtools.h
|
||||
* \brief Header: widget based utility functions
|
||||
*/
|
||||
|
||||
#ifndef MC_WTOOLS_H
|
||||
#define MC_WTOOLS_H
|
||||
#ifndef MC__WTOOLS_H
|
||||
#define MC__WTOOLS_H
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "dialog.h"
|
||||
#include "widget.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct Dlg_head *dlg;
|
||||
struct WListbox *list;
|
||||
} Listbox;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Listbox utility functions */
|
||||
Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help);
|
||||
Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
|
||||
#define LISTBOX_APPEND_TEXT(l,h,t,d) \
|
||||
listbox_add_item (l->list, LISTBOX_APPEND_AT_END, h, t, d)
|
||||
|
||||
int run_listbox (Listbox * l);
|
||||
|
||||
/* Quick Widgets */
|
||||
typedef enum
|
||||
{
|
||||
quick_end = 0,
|
||||
quick_checkbox = 1,
|
||||
quick_button = 2,
|
||||
quick_input = 3,
|
||||
quick_label = 4,
|
||||
quick_radio = 5,
|
||||
quick_groupbox = 6
|
||||
} quick_t;
|
||||
|
||||
/* The widget is placed on relative_?/divisions_? of the parent widget */
|
||||
typedef struct
|
||||
{
|
||||
quick_t widget_type;
|
||||
|
||||
int relative_x;
|
||||
int x_divisions;
|
||||
int relative_y;
|
||||
int y_divisions;
|
||||
|
||||
Widget *widget;
|
||||
widget_options_t options;
|
||||
|
||||
/* widget parameters */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int *state; /* in/out */
|
||||
} checkbox;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int action;
|
||||
bcback callback;
|
||||
} button;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int len;
|
||||
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
|
||||
const char *histname;
|
||||
char **result;
|
||||
} input;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
} label;
|
||||
|
||||
struct
|
||||
{
|
||||
int count;
|
||||
const char **items;
|
||||
int *value; /* in/out */
|
||||
} radio;
|
||||
|
||||
struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const char *title;
|
||||
} groupbox;
|
||||
} u;
|
||||
} QuickWidget;
|
||||
|
||||
#define QUICK_CHECKBOX(x, xdiv, y, ydiv, txt, st) \
|
||||
{ \
|
||||
.widget_type = quick_checkbox, \
|
||||
@ -223,6 +141,100 @@ typedef struct
|
||||
} \
|
||||
}
|
||||
|
||||
/* Pass this as def_text to request a password */
|
||||
#define INPUT_PASSWORD ((char *) -1)
|
||||
|
||||
/* Use this as header for message() - it expands to "Error" */
|
||||
#define MSG_ERROR ((char *) -1)
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/* Quick Widgets */
|
||||
typedef enum
|
||||
{
|
||||
quick_end = 0,
|
||||
quick_checkbox = 1,
|
||||
quick_button = 2,
|
||||
quick_input = 3,
|
||||
quick_label = 4,
|
||||
quick_radio = 5,
|
||||
quick_groupbox = 6
|
||||
} quick_t;
|
||||
|
||||
/* flags for message() and query_dialog() */
|
||||
enum
|
||||
{
|
||||
D_NORMAL = 0,
|
||||
D_ERROR = 1
|
||||
} /* dialog options */ ;
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct Dlg_head *dlg;
|
||||
struct WListbox *list;
|
||||
} Listbox;
|
||||
|
||||
/* The widget is placed on relative_?/divisions_? of the parent widget */
|
||||
typedef struct
|
||||
{
|
||||
quick_t widget_type;
|
||||
|
||||
int relative_x;
|
||||
int x_divisions;
|
||||
int relative_y;
|
||||
int y_divisions;
|
||||
|
||||
Widget *widget;
|
||||
widget_options_t options;
|
||||
|
||||
/* widget parameters */
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int *state; /* in/out */
|
||||
} checkbox;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int action;
|
||||
bcback callback;
|
||||
} button;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
int len;
|
||||
int flags; /* 1 -- is_password, 2 -- INPUT_COMPLETE_CD */
|
||||
const char *histname;
|
||||
char **result;
|
||||
} input;
|
||||
|
||||
struct
|
||||
{
|
||||
const char *text;
|
||||
} label;
|
||||
|
||||
struct
|
||||
{
|
||||
int count;
|
||||
const char **items;
|
||||
int *value; /* in/out */
|
||||
} radio;
|
||||
|
||||
struct
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
const char *title;
|
||||
} groupbox;
|
||||
} u;
|
||||
} QuickWidget;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int xlen, ylen;
|
||||
@ -234,14 +246,22 @@ typedef struct
|
||||
gboolean i18n; /* If true, internationalization has happened */
|
||||
} QuickDialog;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* Listbox utility functions */
|
||||
Listbox *create_listbox_window_centered (int center_y, int center_x, int lines, int cols,
|
||||
const char *title, const char *help);
|
||||
Listbox *create_listbox_window (int lines, int cols, const char *title, const char *help);
|
||||
|
||||
int run_listbox (Listbox * l);
|
||||
|
||||
int quick_dialog (QuickDialog * qd);
|
||||
int quick_dialog_skip (QuickDialog * qd, int nskip);
|
||||
|
||||
/* The input dialogs */
|
||||
|
||||
/* Pass this as def_text to request a password */
|
||||
#define INPUT_PASSWORD ((char *) -1)
|
||||
|
||||
char *input_dialog (const char *header, const char *text,
|
||||
const char *history_name, const char *def_text);
|
||||
char *input_dialog_help (const char *header, const char *text, const char *help,
|
||||
@ -259,17 +279,7 @@ struct Dlg_head *create_message (int flags, const char *title,
|
||||
void message (int flags, const char *title, const char *text, ...)
|
||||
__attribute__ ((format (__printf__, 3, 4)));
|
||||
|
||||
|
||||
/* Use this as header for message() - it expands to "Error" */
|
||||
#define MSG_ERROR ((char *) -1)
|
||||
|
||||
int query_dialog (const char *header, const char *text, int flags, int count, ...);
|
||||
|
||||
/* flags for message() and query_dialog() */
|
||||
enum
|
||||
{
|
||||
D_NORMAL = 0,
|
||||
D_ERROR = 1
|
||||
} /* dialog options */ ;
|
||||
|
||||
#endif
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC__WTOOLS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user