From c2754de8aad308cba1153c47f31d4f7425a352cd Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 9 Nov 2010 13:02:28 +0200 Subject: [PATCH] Code indentation in src directory Signed-off-by: Slava Zanko --- src/achown.c | 54 +++ src/achown.h | 16 +- src/args.c | 18 +- src/args.h | 5 +- src/background.c | 210 +++++---- src/background.h | 35 +- src/boxes.c | 552 +++++++++++++---------- src/boxes.h | 38 +- src/charsets.c | 229 ++++++---- src/charsets.h | 53 ++- src/chmod.c | 35 +- src/chmod.h | 16 +- src/chown.c | 34 +- src/chown.h | 16 +- src/clipboard.c | 21 +- src/clipboard.h | 16 +- src/cmd.c | 1052 +++++++++++++++++++++++++------------------- src/cmd.h | 28 +- src/cmddef.h | 16 +- src/command.c | 483 +++++++++++--------- src/command.h | 16 +- src/complete.c | 131 ++++-- src/cons.handler.c | 74 +++- 23 files changed, 1926 insertions(+), 1222 deletions(-) diff --git a/src/achown.c b/src/achown.c index baa02ad89..aac7247e6 100644 --- a/src/achown.c +++ b/src/achown.c @@ -52,6 +52,10 @@ #include "layout.h" /* repaint_screen() */ #include "achown.h" +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + #define BX 5 #define BY 6 @@ -69,6 +73,10 @@ #define B_OUSER (B_USER + 6) #define B_OGROUP (B_USER + 7) +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + static struct Dlg_head *ch_dlg; static struct @@ -106,6 +114,9 @@ static int current_file; static int single_set; static char *fname; +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static void update_ownership (void) { @@ -113,6 +124,7 @@ update_ownership (void) button_set_text (b_group, get_group (sf_stat->st_gid)); } +/* --------------------------------------------------------------------------------------------- */ static cb_ret_t inc_flag_pos (int f_pos) @@ -128,6 +140,8 @@ inc_flag_pos (int f_pos) return MSG_HANDLED; } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t dec_flag_pos (int f_pos) { @@ -142,6 +156,8 @@ dec_flag_pos (int f_pos) return MSG_HANDLED; } +/* --------------------------------------------------------------------------------------------- */ + static void set_perm_by_flags (char *s, int f_p) { @@ -158,6 +174,8 @@ set_perm_by_flags (char *s, int f_p) } } +/* --------------------------------------------------------------------------------------------- */ + static void update_permissions (void) { @@ -166,6 +184,8 @@ update_permissions (void) set_perm_by_flags (b_att[2]->text.start, 6); } +/* --------------------------------------------------------------------------------------------- */ + static mode_t get_perm (char *s, int base) { @@ -183,6 +203,8 @@ get_perm (char *s, int base) return m; } +/* --------------------------------------------------------------------------------------------- */ + static mode_t get_mode (void) { @@ -196,6 +218,8 @@ get_mode (void) return m; } +/* --------------------------------------------------------------------------------------------- */ + static void print_flags (void) { @@ -235,6 +259,8 @@ print_flags (void) } } +/* --------------------------------------------------------------------------------------------- */ + static void update_mode (Dlg_head * h) { @@ -245,6 +271,8 @@ update_mode (Dlg_head * h) send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0); } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t chl_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -264,6 +292,8 @@ chl_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data } } +/* --------------------------------------------------------------------------------------------- */ + static void do_enter_key (Dlg_head * h, int f_pos) { @@ -377,6 +407,8 @@ do_enter_key (Dlg_head * h, int f_pos) while (chl_end); } +/* --------------------------------------------------------------------------------------------- */ + static void chown_refresh (void) { @@ -412,6 +444,8 @@ chown_refresh (void) print_flags (); } +/* --------------------------------------------------------------------------------------------- */ + static void chown_info_update (void) { @@ -428,6 +462,8 @@ chown_info_update (void) update_permissions (); } +/* --------------------------------------------------------------------------------------------- */ + static void b_setpos (int f_pos) { @@ -437,6 +473,8 @@ b_setpos (int f_pos) b_att[f_pos]->hotpos = (flag_pos % 3); } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -583,6 +621,8 @@ advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, } } +/* --------------------------------------------------------------------------------------------- */ + static void init_chown_advanced (void) { @@ -646,6 +686,8 @@ init_chown_advanced (void) add_widget (ch_dlg, b_att[0]); } +/* --------------------------------------------------------------------------------------------- */ + static void chown_advanced_done (void) { @@ -655,6 +697,8 @@ chown_advanced_done (void) repaint_screen (); } +/* --------------------------------------------------------------------------------------------- */ + #if 0 static void do_chown (uid_t u, gid_t g) @@ -664,6 +708,8 @@ do_chown (uid_t u, gid_t g) } #endif +/* --------------------------------------------------------------------------------------------- */ + static char * next_file (void) { @@ -673,6 +719,8 @@ next_file (void) return current_panel->dir.list[current_file].fname; } +/* --------------------------------------------------------------------------------------------- */ + static void apply_advanced_chowns (struct stat *sf) { @@ -713,6 +761,10 @@ apply_advanced_chowns (struct stat *sf) while (current_panel->marked); } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + void chown_advanced_cmd (void) { @@ -779,3 +831,5 @@ chown_advanced_cmd (void) chown_advanced_done (); } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/achown.h b/src/achown.h index a506f8221..eff3f7a32 100644 --- a/src/achown.h +++ b/src/achown.h @@ -1,11 +1,21 @@ - /** \file achown.h * \brief Header: Contains functions for advanced chowning */ -#ifndef MC_ACHOWN_H -#define MC_ACHOWN_H +#ifndef MC__ACHOWN_H +#define MC__ACHOWN_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 chown_advanced_cmd (void); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/args.c b/src/args.c index 80e88bdee..54bece838 100644 --- a/src/args.c +++ b/src/args.c @@ -35,7 +35,7 @@ #include "lib/strutil.h" #include "lib/vfs/mc-vfs/vfs.h" #ifdef ENABLE_VFS_SMB -#include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debugf() */ +#include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debugf() */ #endif #include "src/main.h" @@ -92,10 +92,10 @@ int mc_args__debug_level = 0; /*** file scope variables ************************************************************************/ /* forward declarations */ -static gboolean parse_mc_e_argument (const gchar *option_name, const gchar *value, - gpointer data, GError **error); -static gboolean parse_mc_v_argument (const gchar *option_name, const gchar *value, - gpointer data, GError **error); +static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value, + gpointer data, GError ** error); +static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * value, + gpointer data, GError ** error); static GOptionContext *context; @@ -425,7 +425,7 @@ mc_setup_by_args (int argc, char *argv[]) */ char *end, *p; - end = tmp + strlen (tmp);\ + end = tmp + strlen (tmp); p = end; if (p > tmp && p[-1] == ':') @@ -601,8 +601,7 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_ /* --------------------------------------------------------------------------------------------- */ static gboolean -parse_mc_e_argument (const gchar *option_name, const gchar *value, - gpointer data, GError **error) +parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error) { (void) option_name; (void) data; @@ -617,8 +616,7 @@ parse_mc_e_argument (const gchar *option_name, const gchar *value, /* --------------------------------------------------------------------------------------------- */ static gboolean -parse_mc_v_argument (const gchar *option_name, const gchar *value, - gpointer data, GError **error) +parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error) { (void) option_name; (void) data; diff --git a/src/args.h b/src/args.h index 08ec8c3b9..66d458f48 100644 --- a/src/args.h +++ b/src/args.h @@ -1,7 +1,7 @@ #ifndef MC__ARGS_H #define MC__ARGS_H -#include "lib/global.h" /* gboolean */ +#include "lib/global.h" /* gboolean */ /*** typedefs(not structures) and defined constants **********************************************/ @@ -27,6 +27,7 @@ extern int mc_args__debug_level; /*** declarations of public functions ************************************************************/ -gboolean mc_args_handle(int argc, char **argv, const char *translation_domain); +gboolean mc_args_handle (int argc, char **argv, const char *translation_domain); +/*** inline functions ****************************************************************************/ #endif /* MC__ARGS_H */ diff --git a/src/background.c b/src/background.c index f100a518d..6d02777bb 100644 --- a/src/background.c +++ b/src/background.c @@ -50,14 +50,24 @@ #include "fileopctx.h" /* FileOpContext */ #include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */ +/*** global variables ****************************************************************************/ + +#define MAXCALLARGS 4 /* Number of arguments supported */ + +/* If true, this is a background process */ +int we_are_background = 0; + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + enum ReturnType { Return_String, Return_Integer }; -/* If true, this is a background process */ -int we_are_background = 0; +/*** file scope variables ************************************************************************/ /* File descriptor for talking to our parent */ static int parent_fd; @@ -65,12 +75,13 @@ static int parent_fd; /* File descriptor for messages from our parent */ static int from_parent_fd; -#define MAXCALLARGS 4 /* Number of arguments supported */ - struct TaskList *task_list = NULL; static int background_attention (int fd, void *closure); +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static void register_task_running (FileOpContext * ctx, pid_t pid, int fd, int to_child, char *info) { @@ -88,6 +99,8 @@ register_task_running (FileOpContext * ctx, pid_t pid, int fd, int to_child, cha add_select_channel (fd, background_attention, ctx); } +/* --------------------------------------------------------------------------------------------- */ + static int destroy_task_and_return_fd (pid_t pid) { @@ -114,91 +127,7 @@ destroy_task_and_return_fd (pid_t pid) return -1; } -void -unregister_task_running (pid_t pid, int fd) -{ - destroy_task_and_return_fd (pid); - delete_select_channel (fd); -} - -void -unregister_task_with_pid (pid_t pid) -{ - int fd = destroy_task_and_return_fd (pid); - if (fd != -1) - delete_select_channel (fd); -} - -/* - * Try to make the Midnight Commander a background job - * - * Returns: - * 1 for parent - * 0 for child - * -1 on failure - */ -int -do_background (struct FileOpContext *ctx, char *info) -{ - int comm[2]; /* control connection stream */ - int back_comm[2]; /* back connection */ - pid_t pid; - - if (pipe (comm) == -1) - return -1; - - if (pipe (back_comm) == -1) - return -1; - - pid = fork (); - if (pid == -1) - { - int saved_errno = errno; - - (void) close (comm[0]); - (void) close (comm[1]); - (void) close (back_comm[0]); - (void) close (back_comm[1]); - errno = saved_errno; - return -1; - } - - if (pid == 0) - { - int nullfd; - - parent_fd = comm[1]; - from_parent_fd = back_comm[0]; - - we_are_background = 1; - top_dlg = NULL; - - /* Make stdin/stdout/stderr point somewhere */ - close (0); - close (1); - close (2); - - nullfd = open ("/dev/null", O_RDWR); - if (nullfd != -1) - { - while (dup2 (nullfd, 0) == -1 && errno == EINTR) - ; - while (dup2 (nullfd, 1) == -1 && errno == EINTR) - ; - while (dup2 (nullfd, 2) == -1 && errno == EINTR) - ; - } - - return 0; - } - else - { - ctx->pid = pid; - register_task_running (ctx, pid, comm[0], back_comm[1], info); - return 1; - } -} - +/* --------------------------------------------------------------------------------------------- */ /* {{{ Parent handlers */ /* Parent/child protocol @@ -236,7 +165,7 @@ do_background (struct FileOpContext *ctx, char *info) */ /* * Receive requests from background process and invoke the - * specified routine + * specified routine */ static int @@ -453,6 +382,7 @@ background_attention (int fd, void *closure) } +/* --------------------------------------------------------------------------------------------- */ /* }}} */ /* {{{ client RPC routines */ @@ -461,6 +391,7 @@ background_attention (int fd, void *closure) * operation context is not NULL, then it requests that the first parameter of * the call be a file operation context. */ + static void parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext * ctx) { @@ -478,6 +409,101 @@ parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext ret = write (parent_fd, ctx, sizeof (FileOpContext)); } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +void +unregister_task_running (pid_t pid, int fd) +{ + destroy_task_and_return_fd (pid); + delete_select_channel (fd); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +unregister_task_with_pid (pid_t pid) +{ + int fd = destroy_task_and_return_fd (pid); + if (fd != -1) + delete_select_channel (fd); +} + + +/* --------------------------------------------------------------------------------------------- */ +/** + * Try to make the Midnight Commander a background job + * + * Returns: + * 1 for parent + * 0 for child + * -1 on failure + */ +int +do_background (struct FileOpContext *ctx, char *info) +{ + int comm[2]; /* control connection stream */ + int back_comm[2]; /* back connection */ + pid_t pid; + + if (pipe (comm) == -1) + return -1; + + if (pipe (back_comm) == -1) + return -1; + + pid = fork (); + if (pid == -1) + { + int saved_errno = errno; + + (void) close (comm[0]); + (void) close (comm[1]); + (void) close (back_comm[0]); + (void) close (back_comm[1]); + errno = saved_errno; + return -1; + } + + if (pid == 0) + { + int nullfd; + + parent_fd = comm[1]; + from_parent_fd = back_comm[0]; + + we_are_background = 1; + top_dlg = NULL; + + /* Make stdin/stdout/stderr point somewhere */ + close (0); + close (1); + close (2); + + nullfd = open ("/dev/null", O_RDWR); + if (nullfd != -1) + { + while (dup2 (nullfd, 0) == -1 && errno == EINTR) + ; + while (dup2 (nullfd, 1) == -1 && errno == EINTR) + ; + while (dup2 (nullfd, 2) == -1 && errno == EINTR) + ; + } + + return 0; + } + else + { + ctx->pid = pid; + register_task_running (ctx, pid, comm[0], back_comm[1], info); + return 1; + } +} + +/* --------------------------------------------------------------------------------------------- */ + int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...) { @@ -505,6 +531,8 @@ parent_call (void *routine, struct FileOpContext *ctx, int argc, ...) return i; } +/* --------------------------------------------------------------------------------------------- */ + char * parent_call_string (void *routine, int argc, ...) { @@ -539,4 +567,6 @@ parent_call_string (void *routine, int argc, ...) return str; } +/* --------------------------------------------------------------------------------------------- */ + #endif /* WITH_BACKGROUND */ diff --git a/src/background.h b/src/background.h index 2dc4bf4af..bbbcc109b 100644 --- a/src/background.h +++ b/src/background.h @@ -1,21 +1,24 @@ - /** \file background.h * \brief Header: Background support */ -#ifndef MC_BACKGROUND_H -#define MC_BACKGROUND_H +#ifndef MC__BACKGROUND_H +#define MC__BACKGROUND_H #ifdef WITH_BACKGROUND -#include /* pid_t */ +#include /* pid_t */ -enum TaskState { +/*** typedefs(not structures) and defined constants **********************************************/ + +enum TaskState +{ Task_Running, Task_Stopped }; -typedef struct TaskList { +typedef struct TaskList +{ int fd; int to_child_fd; pid_t pid; @@ -24,17 +27,29 @@ typedef struct TaskList { struct TaskList *next; } TaskList; +struct FileOpContext; + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + extern struct TaskList *task_list; -struct FileOpContext; +extern int we_are_background; + +/*** declarations of public functions ************************************************************/ + int do_background (struct FileOpContext *ctx, char *info); int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...); char *parent_call_string (void *routine, int argc, ...); void unregister_task_running (pid_t pid, int fd); void unregister_task_with_pid (pid_t pid); -extern int we_are_background; -#endif /* !WITH_BACKGROUND */ +/*** inline functions ****************************************************************************/ -#endif /* MC_BACKGROUND_H */ +#endif /* !WITH_BACKGROUND */ + +#endif /* MC_BACKGROUND_H */ diff --git a/src/boxes.c b/src/boxes.c index 1dc39d64d..991c64d9f 100644 --- a/src/boxes.c +++ b/src/boxes.c @@ -69,6 +69,31 @@ #include "boxes.h" +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +#ifdef ENABLE_VFS +#define VFSX 56 + +#ifdef ENABLE_VFS_FTP +#define VFSY 17 +#else +#define VFSY 8 +#endif /* ENABLE_VFS_FTP */ +#endif /* ENABLE_VFS */ + +#ifdef WITH_BACKGROUND +#define B_STOP (B_USER+1) +#define B_RESUME (B_USER+2) +#define B_KILL (B_USER+3) +#define JOBS_Y 15 +#endif /* WITH_BACKGROUND */ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + static WRadio *display_radio; static WInput *display_user_format; static WInput *display_mini_status; @@ -76,6 +101,50 @@ static WCheck *display_check_status; static char **displays_status; static int display_user_hotkey = 'u'; +#ifdef HAVE_CHARSET +static int new_display_codepage; +static WLabel *cplabel; +static WCheck *inpcheck; +#endif /* HAVE_CHARSET */ + +#ifdef ENABLE_VFS +static char *ret_timeout; +#ifdef ENABLE_VFS_FTP +static char *ret_ftp_proxy; +static char *ret_passwd; +static char *ret_directory_timeout; +#endif /* ENABLE_VFS_FTP */ +#endif /* ENABLE_VFS */ + +#ifdef WITH_BACKGROUND +static int JOBS_X = 60; +static WListbox *bg_list; +static Dlg_head *jobs_dlg; + +static int task_cb (WButton * button, int action); + +static struct +{ + const char *name; + int xpos; + int value; + bcback callback; +} +job_buttons[] = +{ + /* *INDENT-OFF* */ + { N_("&Stop"), 3, B_STOP, task_cb }, + { N_("&Resume"), 12, B_RESUME, task_cb }, + { N_("&Kill"), 23, B_KILL, task_cb }, + { N_("&OK"), 35, B_CANCEL, NULL } + /* *INDENT-ON* */ +}; + +#endif /* WITH_BACKGROUND */ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -150,6 +219,8 @@ display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void * } } +/* --------------------------------------------------------------------------------------------- */ + static Dlg_head * display_init (int radio_sel, char *init_text, int _check_status, char **_status) { @@ -224,14 +295,15 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status) add_widget (dd, cancel_button); add_widget (dd, ok_button); - display_mini_status = input_new (10, 8, input_get_default_colors(), dlg_width - 12, _status[radio_sel], - "mini-input", INPUT_COMPLETE_DEFAULT); + display_mini_status = + input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel], + "mini-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, display_mini_status); display_check_status = check_new (9, 4, _check_status, user_mini_status); add_widget (dd, display_check_status); - display_user_format = input_new (7, 8, input_get_default_colors(), dlg_width - 12, init_text, + display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text, "user-fmt-input", INPUT_COMPLETE_DEFAULT); add_widget (dd, display_user_format); @@ -242,6 +314,213 @@ display_init (int radio_sel, char *init_text, int _check_status, char **_status) return dd; } +/* --------------------------------------------------------------------------------------------- */ +#ifdef HAVE_CHARSET + +static int +sel_charset_button (WButton * button, int action) +{ + int new_dcp; + + (void) button; + (void) action; + + new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); + + if (new_dcp != SELECT_CHARSET_CANCEL) + { + const char *cpname; + char buf[BUF_TINY]; + + new_display_codepage = new_dcp; + cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? + _("Other 8 bit") : + ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; + if (cpname != NULL) + utf8_display = str_isutf8 (cpname); + /* avoid strange bug with label repainting */ + g_snprintf (buf, sizeof (buf), "%-27s", cpname); + label_set_text (cplabel, buf); + } + + return 0; +} + +/* --------------------------------------------------------------------------------------------- */ + +static Dlg_head * +init_disp_bits_box (void) +{ + /* dialog sizes */ + const int DISPY = 11; + const int DISPX = 46; + + const char *cpname; + Dlg_head *dbits_dlg; + + do_refresh (); + + dbits_dlg = + create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL, + "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE); + + add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:"))); + + cpname = (new_display_codepage < 0) ? _("Other 8 bit") + : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; + cplabel = label_new (4, 4, cpname); + add_widget (dbits_dlg, cplabel); + + add_widget (dbits_dlg, + button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0)); + add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0)); + + inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input")); + add_widget (dbits_dlg, inpcheck); + + cpname = _("&Select"); + add_widget (dbits_dlg, + button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER, + NORMAL_BUTTON, cpname, sel_charset_button)); + + return dbits_dlg; +} +#endif /* HAVE_CHARSET */ + +/* --------------------------------------------------------------------------------------------- */ + +static cb_ret_t +tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) +{ + switch (msg) + { + case DLG_POST_KEY: + /* The enter key will be processed by the tree widget */ + if (parm == '\n') + { + h->ret_value = B_ENTER; + dlg_stop (h); + } + return MSG_HANDLED; + + case DLG_ACTION: + /* command from buttonbar */ + return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm); + + default: + return default_dlg_callback (h, sender, msg, parm, data); + } +} + +/* --------------------------------------------------------------------------------------------- */ + +#ifdef ENABLE_VFS +#ifdef ENABLE_VFS_FTP + +static cb_ret_t +confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) +{ + switch (msg) + { + case DLG_ACTION: + if (sender->id == 6) + { + /* message from "Always use ftp proxy" checkbutton */ + const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL); + Widget *w; + + /* input */ + w = dlg_find_by_id (h, sender->id - 1); + widget_disable (*w, not_use); + send_message (w, WIDGET_DRAW, 0); + + return MSG_HANDLED; + } + return MSG_NOT_HANDLED; + + default: + return default_dlg_callback (h, sender, msg, parm, data); + } +} +#endif /* ENABLE_VFS_FTP */ +#endif /* ENABLE_VFS */ + +#ifdef WITH_BACKGROUND +static void +jobs_fill_listbox (void) +{ + static const char *state_str[2]; + TaskList *tl = task_list; + + if (!state_str[0]) + { + state_str[0] = _("Running"); + state_str[1] = _("Stopped"); + } + + while (tl) + { + char *s; + + s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL); + listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl); + g_free (s); + tl = tl->next; + } +} + +/* --------------------------------------------------------------------------------------------- */ + +static int +task_cb (WButton * button, int action) +{ + TaskList *tl; + int sig = 0; + + (void) button; + + if (bg_list->list == NULL) + return 0; + + /* Get this instance information */ + listbox_get_current (bg_list, NULL, (void **) &tl); + +#ifdef SIGTSTP + if (action == B_STOP) + { + sig = SIGSTOP; + tl->state = Task_Stopped; + } + else if (action == B_RESUME) + { + sig = SIGCONT; + tl->state = Task_Running; + } + else +#endif + if (action == B_KILL) + { + sig = SIGKILL; + } + + if (sig == SIGKILL) + unregister_task_running (tl->pid, tl->fd); + + kill (tl->pid, sig); + listbox_remove_list (bg_list); + jobs_fill_listbox (); + + /* This can be optimized to just redraw this widget :-) */ + dlg_redraw (jobs_dlg); + + return 0; +} +#endif /* WITH_BACKGROUND */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + /* return list type */ int display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num) @@ -294,6 +573,8 @@ display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int return result; } +/* --------------------------------------------------------------------------------------------- */ + const panel_field_t * sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first) { @@ -395,6 +676,7 @@ sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, return result; } +/* --------------------------------------------------------------------------------------------- */ void confirm_box (void) @@ -469,6 +751,7 @@ confirm_box (void) } } +/* --------------------------------------------------------------------------------------------- */ #ifndef HAVE_CHARSET void @@ -563,80 +846,9 @@ display_bits_box (void) /* AB:FIXME: test dialog */ } } +/* --------------------------------------------------------------------------------------------- */ #else /* HAVE_CHARSET */ -static int new_display_codepage; - -static WLabel *cplabel; -static WCheck *inpcheck; - -static int -sel_charset_button (WButton *button, int action) -{ - int new_dcp; - - (void) button; - (void) action; - - new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); - - if (new_dcp != SELECT_CHARSET_CANCEL) - { - const char *cpname; - char buf[BUF_TINY]; - - new_display_codepage = new_dcp; - cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? - _("Other 8 bit") : - ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; - if (cpname != NULL) - utf8_display = str_isutf8 (cpname); - /* avoid strange bug with label repainting */ - g_snprintf (buf, sizeof (buf), "%-27s", cpname); - label_set_text (cplabel, buf); - } - - return 0; -} - -static Dlg_head * -init_disp_bits_box (void) -{ - /* dialog sizes */ - const int DISPY = 11; - const int DISPX = 46; - - const char *cpname; - Dlg_head *dbits_dlg; - - do_refresh (); - - dbits_dlg = - create_dlg (TRUE, 0, 0, DISPY, DISPX, dialog_colors, NULL, - "[Display bits]", _("Display bits"), DLG_CENTER | DLG_REVERSE); - - add_widget (dbits_dlg, label_new (3, 4, _("Input / display codepage:"))); - - cpname = (new_display_codepage < 0) ? _("Other 8 bit") - : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; - cplabel = label_new (4, 4, cpname); - add_widget (dbits_dlg, cplabel); - - add_widget (dbits_dlg, - button_new (DISPY - 3, DISPX / 2 + 3, B_CANCEL, NORMAL_BUTTON, _("&Cancel"), 0)); - add_widget (dbits_dlg, button_new (DISPY - 3, 7, B_ENTER, NORMAL_BUTTON, _("&OK"), 0)); - - inpcheck = check_new (6, 4, !use_8th_bit_as_meta, _("F&ull 8 bits input")); - add_widget (dbits_dlg, inpcheck); - - cpname = _("&Select"); - add_widget (dbits_dlg, - button_new (4, DISPX - 7 - str_term_width1 (cpname), B_USER, - NORMAL_BUTTON, cpname, sel_charset_button)); - - return dbits_dlg; -} - void display_bits_box (void) { @@ -669,33 +881,11 @@ display_bits_box (void) destroy_dlg (dbits_dlg); repaint_screen (); } - #endif /* HAVE_CHARSET */ -static cb_ret_t -tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) -{ - switch (msg) - { - case DLG_POST_KEY: - /* The enter key will be processed by the tree widget */ - if (parm == '\n') - { - h->ret_value = B_ENTER; - dlg_stop (h); - } - return MSG_HANDLED; +/* --------------------------------------------------------------------------------------------- */ +/** Show tree in a box, not on a panel */ - case DLG_ACTION: - /* command from buttonbar */ - return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm); - - default: - return default_dlg_callback (h, sender, msg, parm, data); - } -} - -/* Show tree in a box, not on a panel */ char * tree_box (const char *current_dir) { @@ -727,53 +917,12 @@ tree_box (const char *current_dir) return val; } +/* --------------------------------------------------------------------------------------------- */ + #ifdef ENABLE_VFS - -static char *ret_timeout; - -#ifdef ENABLE_VFS_FTP -static char *ret_ftp_proxy; -static char *ret_passwd; -static char *ret_directory_timeout; - -static cb_ret_t -confvfs_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) -{ - switch (msg) - { - case DLG_ACTION: - if (sender->id == 6) - { - /* message from "Always use ftp proxy" checkbutton */ - const gboolean not_use = !(((WCheck *) sender)->state & C_BOOL); - Widget *w; - - /* input */ - w = dlg_find_by_id (h, sender->id - 1); - widget_disable (*w, not_use); - send_message (w, WIDGET_DRAW, 0); - - return MSG_HANDLED; - } - return MSG_NOT_HANDLED; - - default: - return default_dlg_callback (h, sender, msg, parm, data); - } -} -#endif /* ENABLE_VFS_FTP */ - void configure_vfs (void) { -#define VFSX 56 - -#ifdef ENABLE_VFS_FTP -#define VFSY 17 -#else -#define VFSY 8 -#endif /* ENABLE_VFS_FTP */ - char buffer2[BUF_TINY]; #ifdef ENABLE_VFS_FTP char buffer3[BUF_TINY]; @@ -849,6 +998,8 @@ configure_vfs (void) #endif /* ENABLE_VFS */ +/* --------------------------------------------------------------------------------------------- */ + char * cd_dialog (void) { @@ -882,6 +1033,8 @@ cd_dialog (void) } } +/* --------------------------------------------------------------------------------------------- */ + void symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new) { @@ -908,101 +1061,9 @@ symlink_dialog (const char *existing, const char *new, char **ret_existing, char } } +/* --------------------------------------------------------------------------------------------- */ + #ifdef WITH_BACKGROUND -#define B_STOP (B_USER+1) -#define B_RESUME (B_USER+2) -#define B_KILL (B_USER+3) - -static int JOBS_X = 60; -#define JOBS_Y 15 -static WListbox *bg_list; -static Dlg_head *jobs_dlg; - -static void -jobs_fill_listbox (void) -{ - static const char *state_str[2]; - TaskList *tl = task_list; - - if (!state_str[0]) - { - state_str[0] = _("Running"); - state_str[1] = _("Stopped"); - } - - while (tl) - { - char *s; - - s = g_strconcat (state_str[tl->state], " ", tl->info, (char *) NULL); - listbox_add_item (bg_list, LISTBOX_APPEND_AT_END, 0, s, (void *) tl); - g_free (s); - tl = tl->next; - } -} - -static int -task_cb (WButton *button, int action) -{ - TaskList *tl; - int sig = 0; - - (void) button; - - if (bg_list->list == NULL) - return 0; - - /* Get this instance information */ - listbox_get_current (bg_list, NULL, (void **) &tl); - -# ifdef SIGTSTP - if (action == B_STOP) - { - sig = SIGSTOP; - tl->state = Task_Stopped; - } - else if (action == B_RESUME) - { - sig = SIGCONT; - tl->state = Task_Running; - } - else -# endif - if (action == B_KILL) - { - sig = SIGKILL; - } - - if (sig == SIGKILL) - unregister_task_running (tl->pid, tl->fd); - - kill (tl->pid, sig); - listbox_remove_list (bg_list); - jobs_fill_listbox (); - - /* This can be optimized to just redraw this widget :-) */ - dlg_redraw (jobs_dlg); - - return 0; -} - -static struct -{ - const char *name; - int xpos; - int value; - bcback callback; -} -job_buttons[] = -{ - /* *INDENT-OFF* */ - { N_("&Stop"), 3, B_STOP, task_cb }, - { N_("&Resume"), 12, B_RESUME, task_cb }, - { N_("&Kill"), 23, B_KILL, task_cb }, - { N_("&OK"), 35, B_CANCEL, NULL } - /* *INDENT-ON* */ -}; - void jobs_cmd (void) { @@ -1058,6 +1119,8 @@ jobs_cmd (void) } #endif /* WITH_BACKGROUND */ +/* --------------------------------------------------------------------------------------------- */ + #ifdef ENABLE_VFS_SMB struct smb_authinfo * vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user) @@ -1075,8 +1138,7 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c Dlg_head *auth_dlg; struct smb_authinfo *return_value = NULL; - const int input_colors[3] = - { + const int input_colors[3] = { INPUT_COLOR, INPUT_UNCHANGED_COLOR, INPUT_MARK_COLOR @@ -1130,18 +1192,22 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c g_free (title); - in_user = input_new (5, istart, input_get_default_colors(), ilen, user, "auth_name", INPUT_COMPLETE_DEFAULT); + in_user = + input_new (5, istart, input_get_default_colors (), ilen, user, "auth_name", + INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_user); in_domain = - input_new (3, istart, input_get_default_colors(), ilen, domain, "auth_domain", INPUT_COMPLETE_DEFAULT); + input_new (3, istart, input_get_default_colors (), ilen, domain, "auth_domain", + INPUT_COMPLETE_DEFAULT); add_widget (auth_dlg, in_domain); add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0)); add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0)); - in_password = - input_new (7, istart, input_get_default_colors(), ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT); + in_password = + input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password", + INPUT_COMPLETE_DEFAULT); in_password->completion_flags = 0; in_password->is_password = 1; @@ -1160,3 +1226,5 @@ vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, c return return_value; } #endif /* ENABLE_VFS_SMB */ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/boxes.h b/src/boxes.h index 62aa1d923..a04bde582 100644 --- a/src/boxes.h +++ b/src/boxes.h @@ -1,25 +1,33 @@ - /** \file boxes.h * \brief Header: Some misc dialog boxes for the program */ -#ifndef MC_BOXES_H -#define MC_BOXES_H +#ifndef MC__BOXES_H +#define MC__BOXES_H #include "dir.h" #include "panel.h" -int display_box (WPanel *p, char **user, char **mini, - int *use_msformat, int num); -const panel_field_t *sort_box (const panel_field_t *, int *reverse, - int *case_sensitive, int *exec_first); -void confirm_box (void); -void display_bits_box (void); -void configure_vfs (void); -void jobs_cmd (void); -char *cd_dialog (void); -void symlink_dialog (const char *existing, const char *new, - char **ret_existing, char **ret_new); -char *tree_box (const char *current_dir); +/*** typedefs(not structures) and defined constants **********************************************/ +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +int display_box (WPanel * p, char **user, char **mini, int *use_msformat, int num); +const panel_field_t *sort_box (const panel_field_t *, int *reverse, + int *case_sensitive, int *exec_first); +void confirm_box (void); +void display_bits_box (void); +void configure_vfs (void); +void jobs_cmd (void); +char *cd_dialog (void); +void symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new); +char *tree_box (const char *current_dir); + +/*** inline functions ****************************************************************************/ #endif diff --git a/src/charsets.c b/src/charsets.c index 1f281424a..e0bb8ca25 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -30,12 +30,14 @@ #include #include "lib/global.h" -#include "lib/strutil.h" /* utf-8 functions */ +#include "lib/strutil.h" /* utf-8 functions */ #include "lib/fileloc.h" #include "charsets.h" #include "main.h" +/*** global variables ****************************************************************************/ + GPtrArray *codepages = NULL; unsigned char conv_displ[256]; @@ -44,6 +46,23 @@ unsigned char conv_input[256]; const char *cp_display = NULL; const char *cp_source = NULL; +/*** file scope macro definitions ****************************************************************/ + +#define OTHER_8BIT "Other_8_bit" + +/* + * FIXME: This assumes that ASCII is always the first encoding + * in mc.charsets + */ +#define CP_ASCII 0 + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static codepage_desc * new_codepage_desc (const char *id, const char *name) { @@ -56,6 +75,8 @@ new_codepage_desc (const char *id, const char *name) return desc; } +/* --------------------------------------------------------------------------------------------- */ + static void free_codepage_desc (gpointer data, gpointer user_data) { @@ -67,9 +88,11 @@ free_codepage_desc (gpointer data, gpointer user_data) g_free (desc); } +/* --------------------------------------------------------------------------------------------- */ /* returns display codepage */ + static void -load_codepages_list_from_file (GPtrArray **list, const char *fname) +load_codepages_list_from_file (GPtrArray ** list, const char *fname) { FILE *f; guint i; @@ -80,7 +103,7 @@ load_codepages_list_from_file (GPtrArray **list, const char *fname) if (f == NULL) return; - for (i = 0; fgets (buf, sizeof buf, f) != NULL; ) + for (i = 0; fgets (buf, sizeof buf, f) != NULL;) { /* split string into id and cpname */ char *p = buf; @@ -148,6 +171,29 @@ load_codepages_list_from_file (GPtrArray **list, const char *fname) fclose (f); } +/* --------------------------------------------------------------------------------------------- */ + +static char +translate_character (GIConv cd, char c) +{ + gchar *tmp_buff = NULL; + gsize bytes_read, bytes_written = 0; + const char *ibuf = &c; + char ch = UNKNCHAR; + + int ibuflen = 1; + + tmp_buff = g_convert_with_iconv (ibuf, ibuflen, cd, &bytes_read, &bytes_written, NULL); + if (tmp_buff) + ch = tmp_buff[0]; + g_free (tmp_buff); + return ch; +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + void load_codepages_list (void) { @@ -173,6 +219,8 @@ load_codepages_list (void) } } +/* --------------------------------------------------------------------------------------------- */ + void free_codepages_list (void) { @@ -180,7 +228,7 @@ free_codepages_list (void) g_ptr_array_free (codepages, TRUE); } -#define OTHER_8BIT "Other_8_bit" +/* --------------------------------------------------------------------------------------------- */ const char * get_codepage_id (const int n) @@ -188,24 +236,28 @@ get_codepage_id (const int n) return (n < 0) ? OTHER_8BIT : ((codepage_desc *) g_ptr_array_index (codepages, n))->id; } +/* --------------------------------------------------------------------------------------------- */ + int get_codepage_index (const char *id) { size_t i; if (strcmp (id, OTHER_8BIT) == 0) - return -1; + return -1; if (codepages == NULL) - return -1; + return -1; for (i = 0; i < codepages->len; i++) - if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0) - return i; + if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0) + return i; return -1; } +/* --------------------------------------------------------------------------------------------- */ /** Check if specified encoding can be used in mc. * @param encoding name of encoding * @returns TRUE if encoding has supported by mc, FALSE otherwise */ + gboolean is_supported_encoding (const char *encoding) { @@ -221,28 +273,7 @@ is_supported_encoding (const char *encoding) return result; } -static char -translate_character (GIConv cd, char c) -{ - gchar *tmp_buff = NULL; - gsize bytes_read, bytes_written = 0; - const char *ibuf = &c; - char ch = UNKNCHAR; - - int ibuflen = 1; - - tmp_buff = g_convert_with_iconv (ibuf, ibuflen, cd, &bytes_read, &bytes_written, NULL); - if ( tmp_buff ) - ch = tmp_buff[0]; - g_free (tmp_buff); - return ch; -} - -/* - * FIXME: This assumes that ASCII is always the first encoding - * in mc.charsets - */ -#define CP_ASCII 0 +/* --------------------------------------------------------------------------------------------- */ char * init_translation_table (int cpsource, int cpdisplay) @@ -252,18 +283,21 @@ init_translation_table (int cpsource, int cpdisplay) /* Fill inpit <-> display tables */ - if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay) { - for (i = 0; i <= 255; ++i) { - conv_displ[i] = i; - conv_input[i] = i; - cp_source = cp_display; - } - return NULL; + if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay) + { + for (i = 0; i <= 255; ++i) + { + conv_displ[i] = i; + conv_input[i] = i; + cp_source = cp_display; + } + return NULL; } - for (i = 0; i <= 127; ++i) { - conv_displ[i] = i; - conv_input[i] = i; + for (i = 0; i <= 127; ++i) + { + conv_displ[i] = i; + conv_input[i] = i; } cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id; cp_display = ((codepage_desc *) g_ptr_array_index (codepages, cpdisplay))->id; @@ -272,10 +306,10 @@ init_translation_table (int cpsource, int cpdisplay) cd = g_iconv_open (cp_display, cp_source); if (cd == INVALID_CONV) - return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display); + return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display); for (i = 128; i <= 255; ++i) - conv_displ[i] = translate_character (cd, i); + conv_displ[i] = translate_character (cd, i); g_iconv_close (cd); @@ -283,12 +317,13 @@ init_translation_table (int cpsource, int cpdisplay) cd = g_iconv_open (cp_source, cp_display); if (cd == INVALID_CONV) - return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source); + return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source); - for (i = 128; i <= 255; ++i) { - unsigned char ch; - ch = translate_character (cd, i); - conv_input[i] = (ch == UNKNCHAR) ? i : ch; + for (i = 128; i <= 255; ++i) + { + unsigned char ch; + ch = translate_character (cd, i); + conv_input[i] = (ch == UNKNCHAR) ? i : ch; } g_iconv_close (cd); @@ -296,18 +331,23 @@ init_translation_table (int cpsource, int cpdisplay) return NULL; } +/* --------------------------------------------------------------------------------------------- */ + void convert_to_display (char *str) { if (!str) - return; + return; - while (*str) { - *str = conv_displ[(unsigned char) *str]; - str++; + while (*str) + { + *str = conv_displ[(unsigned char) *str]; + str++; } } +/* --------------------------------------------------------------------------------------------- */ + GString * str_convert_to_display (char *str) { @@ -315,6 +355,8 @@ str_convert_to_display (char *str) } +/* --------------------------------------------------------------------------------------------- */ + GString * str_nconvert_to_display (char *str, int len) { @@ -322,37 +364,44 @@ str_nconvert_to_display (char *str, int len) GIConv conv; if (!str) - return g_string_new(""); + return g_string_new (""); if (cp_display == cp_source) - return g_string_new(str); + return g_string_new (str); conv = str_crt_conv_from (cp_source); - buff = g_string_new(""); + buff = g_string_new (""); str_nconvert (conv, str, len, buff); str_close_conv (conv); return buff; } +/* --------------------------------------------------------------------------------------------- */ + void convert_from_input (char *str) { if (!str) - return; + return; - while (*str) { - *str = conv_input[(unsigned char) *str]; - str++; + while (*str) + { + *str = conv_input[(unsigned char) *str]; + str++; } } +/* --------------------------------------------------------------------------------------------- */ + GString * str_convert_to_input (char *str) { return str_nconvert_to_input (str, -1); } +/* --------------------------------------------------------------------------------------------- */ + GString * str_nconvert_to_input (char *str, int len) { @@ -360,19 +409,21 @@ str_nconvert_to_input (char *str, int len) GIConv conv; if (!str) - return g_string_new(""); + return g_string_new (""); if (cp_display == cp_source) - return g_string_new(str); + return g_string_new (str); conv = str_crt_conv_to (cp_source); - buff = g_string_new(""); + buff = g_string_new (""); str_nconvert (conv, str, len, buff); str_close_conv (conv); return buff; } +/* --------------------------------------------------------------------------------------------- */ + unsigned char convert_from_utf_to_current (const char *str) { @@ -384,11 +435,13 @@ convert_from_utf_to_current (const char *str) if (!str) return '.'; - cp_to = get_codepage_id ( source_codepage ); - conv = str_crt_conv_to ( cp_to ); + cp_to = get_codepage_id (source_codepage); + conv = str_crt_conv_to (cp_to); - if (conv != INVALID_CONV) { - switch (str_translate_char (conv, str, -1, (char *)buf_ch, sizeof(buf_ch))) { + if (conv != INVALID_CONV) + { + switch (str_translate_char (conv, str, -1, (char *) buf_ch, sizeof (buf_ch))) + { case ESTR_SUCCESS: ch = buf_ch[0]; break; @@ -404,6 +457,8 @@ convert_from_utf_to_current (const char *str) } +/* --------------------------------------------------------------------------------------------- */ + unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv) { @@ -413,13 +468,15 @@ convert_from_utf_to_current_c (const int input_char, GIConv conv) int res = 0; - res = g_unichar_to_utf8 (input_char, (char *)str); - if ( res == 0 ) { + res = g_unichar_to_utf8 (input_char, (char *) str); + if (res == 0) + { return ch; } str[res] = '\0'; - switch (str_translate_char (conv, (char *)str, -1, (char *)buf_ch, sizeof(buf_ch))) { + switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof (buf_ch))) + { case ESTR_SUCCESS: ch = buf_ch[0]; break; @@ -431,6 +488,8 @@ convert_from_utf_to_current_c (const int input_char, GIConv conv) return ch; } +/* --------------------------------------------------------------------------------------------- */ + int convert_from_8bit_to_utf_c (const char input_char, GIConv conv) { @@ -442,12 +501,16 @@ convert_from_8bit_to_utf_c (const char input_char, GIConv conv) str[0] = (unsigned char) input_char; str[1] = '\0'; - switch (str_translate_char (conv, (char *)str, -1, (char *)buf_ch, sizeof(buf_ch))) { + switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof (buf_ch))) + { case ESTR_SUCCESS: - res = g_utf8_get_char_validated ((char *)buf_ch, -1); - if ( res < 0 ) { + res = g_utf8_get_char_validated ((char *) buf_ch, -1); + if (res < 0) + { ch = buf_ch[0]; - } else { + } + else + { ch = res; } break; @@ -459,6 +522,8 @@ convert_from_8bit_to_utf_c (const char input_char, GIConv conv) return ch; } +/* --------------------------------------------------------------------------------------------- */ + int convert_from_8bit_to_utf_c2 (const char input_char) { @@ -472,16 +537,21 @@ convert_from_8bit_to_utf_c2 (const char input_char) str[0] = (unsigned char) input_char; str[1] = '\0'; - cp_from = get_codepage_id ( source_codepage ); + cp_from = get_codepage_id (source_codepage); conv = str_crt_conv_to (cp_from); - if (conv != INVALID_CONV) { - switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof(buf_ch))) { + if (conv != INVALID_CONV) + { + switch (str_translate_char (conv, (char *) str, -1, (char *) buf_ch, sizeof (buf_ch))) + { case ESTR_SUCCESS: res = g_utf8_get_char_validated ((char *) buf_ch, -1); - if ( res < 0 ) { + if (res < 0) + { ch = buf_ch[0]; - } else { + } + else + { ch = res; } break; @@ -495,4 +565,7 @@ convert_from_8bit_to_utf_c2 (const char input_char) return ch; } -#endif /* HAVE_CHARSET */ + +/* --------------------------------------------------------------------------------------------- */ + +#endif /* HAVE_CHARSET */ diff --git a/src/charsets.h b/src/charsets.h index f462419b5..f2325b190 100644 --- a/src/charsets.h +++ b/src/charsets.h @@ -1,19 +1,28 @@ - /** \file charsets.h * \brief Header: Text conversion from one charset to another */ -#ifndef MC_CHARSETS_H -#define MC_CHARSETS_H +#ifndef MC__CHARSETS_H +#define MC__CHARSETS_H #include "lib/global.h" + +/*** typedefs(not structures) and defined constants **********************************************/ + #ifdef HAVE_CHARSET - #define UNKNCHAR '\001' +#else +#define convert_to_display_c(c) (c) +#define convert_from_input_c(c) (c) +#define convert_to_display(str) do {} while (0) +#define convert_from_input(str) do {} while (0) +#endif /* HAVE_CHARSET */ -extern unsigned char conv_displ[256]; -extern unsigned char conv_input[256]; +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ +#ifdef HAVE_CHARSET typedef struct { @@ -21,10 +30,17 @@ typedef struct char *name; } codepage_desc; +/*** global variables defined in .c file *********************************************************/ + +extern unsigned char conv_displ[256]; +extern unsigned char conv_input[256]; + extern const char *cp_display; extern const char *cp_source; extern GPtrArray *codepages; +/*** declarations of public functions ************************************************************/ + const char *get_codepage_id (const int n); int get_codepage_index (const char *id); void load_codepages_list (void); @@ -34,29 +50,33 @@ char *init_translation_table (int cpsource, int cpdisplay); void convert_to_display (char *str); void convert_from_input (char *str); void convert_string (unsigned char *str); + /* * Converter from utf to selected codepage * param str, utf char * return char in needle codepage (by global int source_codepage) -*/ + */ unsigned char convert_from_utf_to_current (const char *str); + /* * Converter from utf to selected codepage * param input_char, gunichar * return char in needle codepage (by global int source_codepage) -*/ + */ unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv); + /* * Converter from selected codepage 8-bit * param char input_char, GIConv converter * return int utf char -*/ + */ int convert_from_8bit_to_utf_c (const char input_char, GIConv conv); + /* * Converter from display codepage 8-bit to utf-8 * param char input_char, GIConv converter * return int utf char -*/ + */ int convert_from_8bit_to_utf_c2 (const char input_char); GString *str_convert_to_input (char *str); @@ -65,12 +85,14 @@ GString *str_nconvert_to_input (char *str, int len); GString *str_convert_to_display (char *str); GString *str_nconvert_to_display (char *str, int len); +/*** inline functions ****************************************************************************/ + /* Convert single characters */ static inline int convert_to_display_c (int c) { if (c < 0 || c >= 256) - return c; + return c; return conv_displ[c]; } @@ -78,17 +100,10 @@ static inline int convert_from_input_c (int c) { if (c < 0 || c >= 256) - return c; + return c; return conv_input[c]; } -#else /* !HAVE_CHARSET */ - -#define convert_to_display_c(c) (c) -#define convert_from_input_c(c) (c) -#define convert_to_display(str) do {} while (0) -#define convert_from_input(str) do {} while (0) - #endif /* HAVE_CHARSET */ #endif /* MC_CHARSETS_H */ diff --git a/src/chmod.c b/src/chmod.c index 2ba47ac3c..b55e9c040 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -46,7 +46,9 @@ #include "layout.h" /* repaint_screen() */ #include "chmod.h" -static int single_set; +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ #define PX 5 #define PY 2 @@ -68,6 +70,12 @@ static int single_set; #define B_SETMRK (B_USER+2) #define B_CLRMRK (B_USER+3) +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +static int single_set; + static int mode_change, need_update; static int c_file, end_chmod; @@ -121,6 +129,9 @@ static struct /* *INDENT-ON* */ }; +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static void chmod_toggle_select (Dlg_head * h, int Id) { @@ -132,6 +143,8 @@ chmod_toggle_select (Dlg_head * h, int Id) dlg_move (h, PY + PERMISSIONS - Id, PX + 3); } +/* --------------------------------------------------------------------------------------------- */ + static void chmod_refresh (Dlg_head * h) { @@ -158,6 +171,8 @@ chmod_refresh (Dlg_head * h) tty_print_string (_("and T or INS to mark")); } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -196,6 +211,8 @@ chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da } } +/* --------------------------------------------------------------------------------------------- */ + static Dlg_head * init_chmod (void) { @@ -230,11 +247,13 @@ init_chmod (void) add_widget (ch_dlg, check_perm[i].check); } - add_widget (ch_dlg, groupbox_new ( PY, PX, PERMISSIONS + 2, 33, _("Permission"))); + add_widget (ch_dlg, groupbox_new (PY, PX, PERMISSIONS + 2, 33, _("Permission"))); return ch_dlg; } +/* --------------------------------------------------------------------------------------------- */ + static void chmod_done (void) { @@ -243,6 +262,8 @@ chmod_done (void) repaint_screen (); } +/* --------------------------------------------------------------------------------------------- */ + static char * next_file (void) { @@ -252,6 +273,8 @@ next_file (void) return current_panel->dir.list[c_file].fname; } +/* --------------------------------------------------------------------------------------------- */ + static void do_chmod (struct stat *sf) { @@ -264,6 +287,8 @@ do_chmod (struct stat *sf) do_file_mark (current_panel, c_file, 0); } +/* --------------------------------------------------------------------------------------------- */ + static void apply_mask (struct stat *sf) { @@ -284,6 +309,10 @@ apply_mask (struct stat *sf) while (current_panel->marked); } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + void chmod_cmd (void) { @@ -403,3 +432,5 @@ chmod_cmd (void) chmod_done (); } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/chmod.h b/src/chmod.h index e592f18dc..8c406a4d7 100644 --- a/src/chmod.h +++ b/src/chmod.h @@ -1,11 +1,21 @@ - /** \file chmod.h * \brief Header: chmod command */ -#ifndef MC_CHMOD_H -#define MC_CHMOD_H +#ifndef MC__CHMOD_H +#define MC__CHMOD_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 chmod_cmd (void); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/chown.c b/src/chown.c index 1c62e6900..428315137 100644 --- a/src/chown.c +++ b/src/chown.c @@ -50,6 +50,10 @@ #include "wtools.h" /* init_box_colors() */ #include "setup.h" /* panels_options */ +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + #define UX 5 #define UY 2 @@ -68,6 +72,14 @@ #define B_SETUSR (B_USER + 1) #define B_SETGRP (B_USER + 2) +#define LABELS 5 + +#define chown_label(n,txt) label_set_text (chown_label [n].l, txt) + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + static int need_update, end_chown; static int current_file; static int single_set; @@ -86,7 +98,6 @@ static struct { B_SETALL, NORMAL_BUTTON, 0, 0, N_("Set &all") }, }; -#define LABELS 5 static struct { int y, x; WLabel *l; @@ -99,6 +110,9 @@ static struct { }; /* *INDENT-ON* */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + static void chown_refresh (Dlg_head * h) { @@ -118,6 +132,8 @@ chown_refresh (Dlg_head * h) tty_print_string (_("Permission")); } +/* --------------------------------------------------------------------------------------------- */ + static char * next_file (void) { @@ -127,6 +143,8 @@ next_file (void) return current_panel->dir.list[current_file].fname; } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -141,6 +159,8 @@ chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da } } +/* --------------------------------------------------------------------------------------------- */ + static Dlg_head * init_chown (void) { @@ -204,6 +224,8 @@ init_chown (void) return ch_dlg; } +/* --------------------------------------------------------------------------------------------- */ + static void chown_done (void) { @@ -212,6 +234,8 @@ chown_done (void) repaint_screen (); } +/* --------------------------------------------------------------------------------------------- */ + static void do_chown (uid_t u, gid_t g) { @@ -222,6 +246,8 @@ do_chown (uid_t u, gid_t g) do_file_mark (current_panel, current_file, 0); } +/* --------------------------------------------------------------------------------------------- */ + static void apply_chowns (uid_t u, gid_t g) { @@ -239,7 +265,9 @@ apply_chowns (uid_t u, gid_t g) while (current_panel->marked); } -#define chown_label(n,txt) label_set_text (chown_label [n].l, txt) +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ void chown_cmd (void) @@ -354,3 +382,5 @@ chown_cmd (void) chown_done (); } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/chown.h b/src/chown.h index e572f46b2..e70303914 100644 --- a/src/chown.h +++ b/src/chown.h @@ -1,11 +1,21 @@ - /** \file chown.h * \brief Header: chown command */ -#ifndef MC_CHOWN_H -#define MC_CHOWN_H +#ifndef MC__CHOWN_H +#define MC__CHOWN_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 chown_cmd (void); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/clipboard.c b/src/clipboard.c index e5b2c4303..4c74a68b3 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -37,6 +37,21 @@ #include "clipboard.h" +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + gboolean copy_file_to_ext_clip (void) { @@ -44,7 +59,7 @@ copy_file_to_ext_clip (void) int res = 0; const char *d = getenv ("DISPLAY"); - if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] =='\0') + if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0') return FALSE; tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE); @@ -58,6 +73,8 @@ copy_file_to_ext_clip (void) return TRUE; } +/* --------------------------------------------------------------------------------------------- */ + gboolean paste_to_file_from_ext_clip (void) { @@ -78,3 +95,5 @@ paste_to_file_from_ext_clip (void) g_free (tmp); return TRUE; } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/clipboard.h b/src/clipboard.h index 0c96b7ce1..770b1dbd4 100644 --- a/src/clipboard.h +++ b/src/clipboard.h @@ -1,12 +1,22 @@ - /** \file clipboard.h * \brief Header: Util for external clipboard */ -#ifndef MC_CLIPBOARD_H -#define MC_CLIPBOARD_H +#ifndef MC__CLIPBOARD_H +#define MC__CLIPBOARD_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ gboolean copy_file_to_ext_clip (void); gboolean paste_to_file_from_ext_clip (void); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/cmd.c b/src/cmd.c index 84198d9a2..76deecb6d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -33,7 +33,7 @@ #include #include #ifdef HAVE_MMAP -# include +#include #endif #ifdef ENABLE_VFS_NET #include @@ -83,19 +83,16 @@ #include "dir.h" #include "cmddef.h" /* CK_InputHistoryShow */ -#ifndef MAP_FILE -# define MAP_FILE 0 -#endif #ifdef USE_INTERNAL_EDIT -# include "src/editor/edit.h" +#include "src/editor/edit.h" #endif #ifdef USE_DIFF_VIEW -# include "src/diffviewer/ydiff.h" +#include "src/diffviewer/ydiff.h" #endif - +/*** global variables ****************************************************************************/ /* If set and you don't have subshell support,then C-o will give you a shell */ int output_starts_shell = 0; @@ -106,16 +103,487 @@ int use_internal_edit = 1; /* Automatically fills name with current selected item name on mkdir */ int auto_fill_mkdir_name = 1; -/* selection flags */ -typedef enum -{ - SELECT_FILES_ONLY = 1 << 0, - SELECT_MATCH_CASE = 1 << 1, - SELECT_SHELL_PATTERNS = 1 << 2 -} select_flags_t; - int select_flags = SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS; +/*** file scope macro definitions ****************************************************************/ + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif + +/*** file scope type declarations ****************************************************************/ + +enum CompareMode +{ + compare_quick, compare_size_only, compare_thourough +}; + +/*** file scope variables ************************************************************************/ + +#ifdef ENABLE_VFS_NET +static const char *machine_str = N_("Enter machine name (F1 for details):"); +#endif /* ENABLE_VFS_NET */ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/** scan_for_file (panel, idx, direction) + * + * Inputs: + * panel: pointer to the panel on which we operate + * idx: starting file. + * direction: 1, or -1 + */ + +static int +scan_for_file (WPanel * panel, int idx, int direction) +{ + int i = idx + direction; + + while (i != idx) + { + if (i < 0) + i = panel->count - 1; + if (i == panel->count) + i = 0; + if (!S_ISDIR (panel->dir.list[i].st.st_mode)) + return i; + i += direction; + } + return i; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Run viewer (internal or external) on the currently selected file. + * If normal is 1, force internal viewer and raw mode (used for F13). + */ +static void +do_view_cmd (int normal) +{ + /* Directories are viewed by changing to them */ + if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel))) + { + if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked)) + { + if (query_dialog + (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2, + _("&Yes"), _("&No")) != 0) + { + return; + } + } + if (!do_cd (selection (current_panel)->fname, cd_exact)) + message (D_ERROR, MSG_ERROR, _("Cannot change directory")); + } + else + { + int dir, file_idx; + char *filename; + + file_idx = current_panel->selected; + while (1) + { + filename = current_panel->dir.list[file_idx].fname; + + dir = view_file (filename, normal, use_internal_view); + if (dir == 0) + break; + file_idx = scan_for_file (current_panel, file_idx, dir); + } + } + + repaint_screen (); +} + +/* --------------------------------------------------------------------------------------------- */ + +static inline void +do_edit (const char *what) +{ + do_edit_at_line (what, use_internal_edit, 0); +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +set_panel_filter_to (WPanel * p, char *allocated_filter_string) +{ + g_free (p->filter); + p->filter = 0; + + if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0)) + p->filter = allocated_filter_string; + else + g_free (allocated_filter_string); + reread_cmd (); +} + +/* --------------------------------------------------------------------------------------------- */ +/** Set a given panel filter expression */ + +static void +set_panel_filter (WPanel * p) +{ + char *reg_exp; + const char *x; + + x = p->filter ? p->filter : easy_patterns ? "*" : "."; + + reg_exp = input_dialog_help (_("Filter"), + _("Set expression for filtering filenames"), + "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x); + if (!reg_exp) + return; + set_panel_filter_to (p, reg_exp); +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +select_unselect_cmd (const char *title, const char *history_name, gboolean do_select) +{ + /* dialog sizes */ + const int DX = 50; + const int DY = 7; + + int files_only = (select_flags & SELECT_FILES_ONLY) != 0; + int case_sens = (select_flags & SELECT_MATCH_CASE) != 0; + int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0; + + char *reg_exp; + mc_search_t *search; + int i; + + QuickWidget quick_widgets[] = { + QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns), + QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens), + QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only), + QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, ®_exp), + QUICK_END + }; + + QuickDialog quick_dlg = { + DX, DY, -1, -1, title, + "[Select/Unselect Files]", quick_widgets, NULL, FALSE + }; + + if (quick_dialog (&quick_dlg) == B_CANCEL) + return; + + if (!reg_exp) + return; + if (!*reg_exp) + { + g_free (reg_exp); + return; + } + search = mc_search_new (reg_exp, -1); + search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX; + search->is_entire_line = TRUE; + search->is_case_sensitive = case_sens != 0; + + for (i = 0; i < current_panel->count; i++) + { + if (strcmp (current_panel->dir.list[i].fname, "..") == 0) + continue; + if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0) + continue; + + if (mc_search_run (search, current_panel->dir.list[i].fname, + 0, current_panel->dir.list[i].fnamelen, NULL)) + do_file_mark (current_panel, i, do_select); + } + + mc_search_free (search); + g_free (reg_exp); + + /* result flags */ + select_flags = 0; + if (case_sens != 0) + select_flags |= SELECT_MATCH_CASE; + if (files_only != 0) + select_flags |= SELECT_FILES_ONLY; + if (shell_patterns != 0) + select_flags |= SELECT_SHELL_PATTERNS; +} + +/* --------------------------------------------------------------------------------------------- */ + +static int +compare_files (char *name1, char *name2, off_t size) +{ + int file1, file2; + int result = -1; /* Different by default */ + + if (size == 0) + return 0; + + file1 = open (name1, O_RDONLY); + if (file1 >= 0) + { + file2 = open (name2, O_RDONLY); + if (file2 >= 0) + { +#ifdef HAVE_MMAP + char *data1, *data2; + /* Ugly if jungle */ + data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0); + if (data1 != (char *) -1) + { + data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0); + if (data2 != (char *) -1) + { + rotate_dash (); + result = memcmp (data1, data2, size); + munmap (data2, size); + } + munmap (data1, size); + } +#else + /* Don't have mmap() :( Even more ugly :) */ + char buf1[BUFSIZ], buf2[BUFSIZ]; + int n1, n2; + rotate_dash (); + do + { + while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR); + while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR); + } + while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ)); + result = (n1 != n2) || memcmp (buf1, buf2, n1); +#endif /* !HAVE_MMAP */ + close (file2); + } + close (file1); + } + return result; +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode) +{ + int i, j; + char *src_name, *dst_name; + + /* No marks by default */ + panel->marked = 0; + panel->total = 0; + panel->dirs_marked = 0; + + /* Handle all files in the panel */ + for (i = 0; i < panel->count; i++) + { + file_entry *source = &panel->dir.list[i]; + + /* Default: unmarked */ + file_mark (panel, i, 0); + + /* Skip directories */ + if (S_ISDIR (source->st.st_mode)) + continue; + + /* Search the corresponding entry from the other panel */ + for (j = 0; j < other->count; j++) + { + if (strcmp (source->fname, other->dir.list[j].fname) == 0) + break; + } + if (j >= other->count) + /* Not found -> mark */ + do_file_mark (panel, i, 1); + else + { + /* Found */ + file_entry *target = &other->dir.list[j]; + + if (mode != compare_size_only) + { + /* Older version is not marked */ + if (source->st.st_mtime < target->st.st_mtime) + continue; + } + + /* Newer version with different size is marked */ + if (source->st.st_size != target->st.st_size) + { + do_file_mark (panel, i, 1); + continue; + + } + if (mode == compare_size_only) + continue; + + if (mode == compare_quick) + { + /* Thorough compare off, compare only time stamps */ + /* Mark newer version, don't mark version with the same date */ + if (source->st.st_mtime > target->st.st_mtime) + { + do_file_mark (panel, i, 1); + } + continue; + } + + /* Thorough compare on, do byte-by-byte comparison */ + src_name = concat_dir_and_file (panel->cwd, source->fname); + dst_name = concat_dir_and_file (other->cwd, target->fname); + if (compare_files (src_name, dst_name, source->st.st_size)) + do_file_mark (panel, i, 1); + g_free (src_name); + g_free (dst_name); + } + } /* for (i ...) */ +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +do_link (link_type_t link_type, const char *fname) +{ + char *dest = NULL, *src = NULL; + + if (link_type == LINK_HARDLINK) + { + src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46)); + dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, ""); + if (!dest || !*dest) + goto cleanup; + save_cwds_stat (); + if (-1 == mc_link (fname, dest)) + message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno)); + } + else + { + char *s; + char *d; + + /* suggest the full path for symlink, and either the full or + relative path to the file it points to */ + s = concat_dir_and_file (current_panel->cwd, fname); + + if (get_other_type () == view_listing) + d = concat_dir_and_file (other_panel->cwd, fname); + else + d = g_strdup (fname); + + if (link_type == LINK_SYMLINK_RELATIVE) + s = diff_two_paths (other_panel->cwd, s); + + symlink_dialog (s, d, &dest, &src); + g_free (d); + g_free (s); + + if (!dest || !*dest || !src || !*src) + goto cleanup; + save_cwds_stat (); + if (-1 == mc_symlink (dest, src)) + message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno)); + } + + update_panels (UP_OPTIMIZE, UP_KEEPSEL); + repaint_screen (); + + cleanup: + g_free (src); + g_free (dest); +} + +/* --------------------------------------------------------------------------------------------- */ + +#if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET) +static void +nice_cd (const char *text, const char *xtext, const char *help, + const char *history_name, const char *prefix, int to_home) +{ + char *machine; + char *cd_path; + + if (!SELECTED_IS_PANEL) + return; + + machine = input_dialog_help (text, xtext, help, history_name, ""); + if (!machine) + return; + + to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is + ugly as hell and leads to problems in vfs layer */ + + if (strncmp (prefix, machine, strlen (prefix)) == 0) + cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); + else + cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); + + if (!do_panel_cd (MENU_PANEL, cd_path, cd_parse_command)) + message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); + g_free (cd_path); + g_free (machine); +} +#endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET */ + +/* --------------------------------------------------------------------------------------------- */ + +static void +configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status) +{ + p->user_mini_status = use_msformat; + p->list_type = list_type; + + if (list_type == list_user || use_msformat) + { + g_free (p->user_format); + p->user_format = user; + + g_free (p->user_status_format[list_type]); + p->user_status_format[list_type] = status; + + set_panel_formats (p); + } + else + { + g_free (user); + g_free (status); + } + + set_panel_formats (p); + do_refresh (); +} + +/* --------------------------------------------------------------------------------------------- */ + +static void +switch_to_listing (int panel_index) +{ + if (get_display_type (panel_index) != view_listing) + set_display_type (panel_index, view_listing); +} + +/* --------------------------------------------------------------------------------------------- */ +/** Handle the tree internal listing modes switching */ + +static gboolean +set_basic_panel_listing_to (int panel_index, int listing_mode) +{ + WPanel *p = (WPanel *) get_panel_widget (panel_index); + gboolean ok; + + switch_to_listing (panel_index); + p->list_type = listing_mode; + + ok = set_panel_formats (p) == 0; + + if (ok) + do_refresh (); + + return ok; +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + int view_file_at_line (const char *filename, int plain_view, int internal, int start_line) { @@ -205,7 +673,8 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start return move_dir; } -/* view_file (filename, plain_view, internal) +/* --------------------------------------------------------------------------------------------- */ +/** view_file (filename, plain_view, internal) * * Inputs: * filename: The file name to view @@ -213,87 +682,26 @@ view_file_at_line (const char *filename, int plain_view, int internal, int start * always invokes the internal viewer. * internal: If set uses the internal viewer, otherwise an external viewer. */ + int view_file (const char *filename, int plain_view, int internal) { return view_file_at_line (filename, plain_view, internal, 0); } -/* scan_for_file (panel, idx, direction) - * - * Inputs: - * panel: pointer to the panel on which we operate - * idx: starting file. - * direction: 1, or -1 - */ -static int -scan_for_file (WPanel * panel, int idx, int direction) -{ - int i = idx + direction; - while (i != idx) - { - if (i < 0) - i = panel->count - 1; - if (i == panel->count) - i = 0; - if (!S_ISDIR (panel->dir.list[i].st.st_mode)) - return i; - i += direction; - } - return i; -} +/* --------------------------------------------------------------------------------------------- */ +/** Run user's preferred viewer on the currently selected file */ -/* - * Run viewer (internal or external) on the currently selected file. - * If normal is 1, force internal viewer and raw mode (used for F13). - */ -static void -do_view_cmd (int normal) -{ - /* Directories are viewed by changing to them */ - if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel))) - { - if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked)) - { - if (query_dialog - (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2, - _("&Yes"), _("&No")) != 0) - { - return; - } - } - if (!do_cd (selection (current_panel)->fname, cd_exact)) - message (D_ERROR, MSG_ERROR, _("Cannot change directory")); - } - else - { - int dir, file_idx; - char *filename; - - file_idx = current_panel->selected; - while (1) - { - filename = current_panel->dir.list[file_idx].fname; - - dir = view_file (filename, normal, use_internal_view); - if (dir == 0) - break; - file_idx = scan_for_file (current_panel, file_idx, dir); - } - } - - repaint_screen (); -} - -/* Run user's preferred viewer on the currently selected file */ void view_cmd (void) { do_view_cmd (0); } -/* Ask for file and run user's preferred viewer on it */ +/* --------------------------------------------------------------------------------------------- */ +/** Ask for file and run user's preferred viewer on it */ + void view_file_cmd (void) { @@ -309,13 +717,16 @@ view_file_cmd (void) g_free (filename); } -/* Run plain internal viewer on the currently selected file */ +/* --------------------------------------------------------------------------------------------- */ +/** Run plain internal viewer on the currently selected file */ void view_simple_cmd (void) { do_view_cmd (1); } +/* --------------------------------------------------------------------------------------------- */ + void filtered_view_cmd (void) { @@ -334,6 +745,8 @@ filtered_view_cmd (void) } } +/* --------------------------------------------------------------------------------------------- */ + void do_edit_at_line (const char *what, gboolean internal, int start_line) { @@ -367,11 +780,7 @@ do_edit_at_line (const char *what, gboolean internal, int start_line) repaint_screen (); } -static inline void -do_edit (const char *what) -{ - do_edit_at_line (what, use_internal_edit, 0); -} +/* --------------------------------------------------------------------------------------------- */ void edit_cmd (void) @@ -380,6 +789,8 @@ edit_cmd (void) do_edit (selection (current_panel)->fname); } +/* --------------------------------------------------------------------------------------------- */ + #ifdef USE_INTERNAL_EDIT void edit_cmd_force_internal (void) @@ -389,6 +800,8 @@ edit_cmd_force_internal (void) } #endif +/* --------------------------------------------------------------------------------------------- */ + void edit_cmd_new (void) { @@ -398,7 +811,9 @@ edit_cmd_new (void) do_edit (NULL); } -/* Invoked by F5. Copy, default to the other panel. */ +/* --------------------------------------------------------------------------------------------- */ +/** Invoked by F5. Copy, default to the other panel. */ + void copy_cmd (void) { @@ -410,7 +825,9 @@ copy_cmd (void) } } -/* Invoked by F6. Move/rename, default to the other panel, ignore marks. */ +/* --------------------------------------------------------------------------------------------- */ +/** Invoked by F6. Move/rename, default to the other panel, ignore marks. */ + void rename_cmd (void) { @@ -422,7 +839,9 @@ rename_cmd (void) } } -/* Invoked by F15. Copy, default to the same panel, ignore marks. */ +/* --------------------------------------------------------------------------------------------- */ +/** Invoked by F15. Copy, default to the same panel, ignore marks. */ + void copy_cmd_local (void) { @@ -434,7 +853,9 @@ copy_cmd_local (void) } } -/* Invoked by F16. Move/rename, default to the same panel. */ +/* --------------------------------------------------------------------------------------------- */ +/** Invoked by F16. Move/rename, default to the same panel. */ + void rename_cmd_local (void) { @@ -446,6 +867,8 @@ rename_cmd_local (void) } } +/* --------------------------------------------------------------------------------------------- */ + void mkdir_cmd (void) { @@ -486,6 +909,8 @@ mkdir_cmd (void) g_free (dir); } +/* --------------------------------------------------------------------------------------------- */ + void delete_cmd (void) { @@ -498,7 +923,9 @@ delete_cmd (void) } } -/* Invoked by F18. Remove selected file, regardless of marked files. */ +/* --------------------------------------------------------------------------------------------- */ +/** Invoked by F18. Remove selected file, regardless of marked files. */ + void delete_cmd_local (void) { @@ -511,43 +938,17 @@ delete_cmd_local (void) } } +/* --------------------------------------------------------------------------------------------- */ + void find_cmd (void) { do_find (); } -static void -set_panel_filter_to (WPanel * p, char *allocated_filter_string) -{ - g_free (p->filter); - p->filter = 0; +/* --------------------------------------------------------------------------------------------- */ +/** Invoked from the left/right menus */ - if (!(allocated_filter_string[0] == '*' && allocated_filter_string[1] == 0)) - p->filter = allocated_filter_string; - else - g_free (allocated_filter_string); - reread_cmd (); -} - -/* Set a given panel filter expression */ -static void -set_panel_filter (WPanel * p) -{ - char *reg_exp; - const char *x; - - x = p->filter ? p->filter : easy_patterns ? "*" : "."; - - reg_exp = input_dialog_help (_("Filter"), - _("Set expression for filtering filenames"), - "[Filter...]", MC_HISTORY_FM_PANEL_FILTER, x); - if (!reg_exp) - return; - set_panel_filter_to (p, reg_exp); -} - -/* Invoked from the left/right menus */ void filter_cmd (void) { @@ -560,6 +961,8 @@ filter_cmd (void) set_panel_filter (p); } +/* --------------------------------------------------------------------------------------------- */ + void reread_cmd (void) { @@ -574,6 +977,8 @@ reread_cmd (void) repaint_screen (); } +/* --------------------------------------------------------------------------------------------- */ + void reverse_selection_cmd (void) { @@ -588,73 +993,7 @@ reverse_selection_cmd (void) } } -static void -select_unselect_cmd (const char *title, const char *history_name, gboolean do_select) -{ - /* dialog sizes */ - const int DX = 50; - const int DY = 7; - - int files_only = (select_flags & SELECT_FILES_ONLY) != 0; - int case_sens = (select_flags & SELECT_MATCH_CASE) != 0; - int shell_patterns = (select_flags & SELECT_SHELL_PATTERNS) != 0; - - char *reg_exp; - mc_search_t *search; - int i; - - QuickWidget quick_widgets[] = { - QUICK_CHECKBOX (3, DX, DY - 3, DY, N_("&Using shell patterns"), &shell_patterns), - QUICK_CHECKBOX (DX / 2 + 1, DX, DY - 4, DY, N_("&Case sensitive"), &case_sens), - QUICK_CHECKBOX (3, DX, DY - 4, DY, N_("&Files only"), &files_only), - QUICK_INPUT (3, DX, DY - 5, DY, INPUT_LAST_TEXT, DX - 6, 0, history_name, ®_exp), - QUICK_END - }; - - QuickDialog quick_dlg = { - DX, DY, -1, -1, title, - "[Select/Unselect Files]", quick_widgets, NULL, FALSE - }; - - if (quick_dialog (&quick_dlg) == B_CANCEL) - return; - - if (!reg_exp) - return; - if (!*reg_exp) - { - g_free (reg_exp); - return; - } - search = mc_search_new (reg_exp, -1); - search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX; - search->is_entire_line = TRUE; - search->is_case_sensitive = case_sens != 0; - - for (i = 0; i < current_panel->count; i++) - { - if (strcmp (current_panel->dir.list[i].fname, "..") == 0) - continue; - if (S_ISDIR (current_panel->dir.list[i].st.st_mode) && files_only != 0) - continue; - - if (mc_search_run (search, current_panel->dir.list[i].fname, - 0, current_panel->dir.list[i].fnamelen, NULL)) - do_file_mark (current_panel, i, do_select); - } - - mc_search_free (search); - g_free (reg_exp); - - /* result flags */ - select_flags = 0; - if (case_sens != 0) - select_flags |= SELECT_MATCH_CASE; - if (files_only != 0) - select_flags |= SELECT_FILES_ONLY; - if (shell_patterns != 0) - select_flags |= SELECT_SHELL_PATTERNS; -} +/* --------------------------------------------------------------------------------------------- */ void select_cmd (void) @@ -662,12 +1001,16 @@ select_cmd (void) select_unselect_cmd (_("Select"), ":select_cmd: Select ", TRUE); } +/* --------------------------------------------------------------------------------------------- */ + void unselect_cmd (void) { select_unselect_cmd (_("Unselect"), ":unselect_cmd: Unselect ", FALSE); } +/* --------------------------------------------------------------------------------------------- */ + void ext_cmd (void) { @@ -704,7 +1047,9 @@ ext_cmd (void) flush_extension_file (); } -/* edit file menu for mc */ +/* --------------------------------------------------------------------------------------------- */ +/** edit file menu for mc */ + void edit_mc_menu_cmd (void) { @@ -757,6 +1102,8 @@ edit_mc_menu_cmd (void) g_free (menufile); } +/* --------------------------------------------------------------------------------------------- */ + void edit_fhl_cmd (void) { @@ -797,6 +1144,8 @@ edit_fhl_cmd (void) mc_filehighlight = mc_fhl_new (TRUE); } +/* --------------------------------------------------------------------------------------------- */ + void quick_chdir_cmd (void) { @@ -833,136 +1182,7 @@ reselect_vfs (void) } #endif /* ENABLE_VFS */ -static int -compare_files (char *name1, char *name2, off_t size) -{ - int file1, file2; - int result = -1; /* Different by default */ - - if (size == 0) - return 0; - - file1 = open (name1, O_RDONLY); - if (file1 >= 0) - { - file2 = open (name2, O_RDONLY); - if (file2 >= 0) - { -#ifdef HAVE_MMAP - char *data1, *data2; - /* Ugly if jungle */ - data1 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file1, 0); - if (data1 != (char *) -1) - { - data2 = mmap (0, size, PROT_READ, MAP_FILE | MAP_PRIVATE, file2, 0); - if (data2 != (char *) -1) - { - rotate_dash (); - result = memcmp (data1, data2, size); - munmap (data2, size); - } - munmap (data1, size); - } -#else - /* Don't have mmap() :( Even more ugly :) */ - char buf1[BUFSIZ], buf2[BUFSIZ]; - int n1, n2; - rotate_dash (); - do - { - while ((n1 = read (file1, buf1, BUFSIZ)) == -1 && errno == EINTR); - while ((n2 = read (file2, buf2, BUFSIZ)) == -1 && errno == EINTR); - } - while (n1 == n2 && n1 == BUFSIZ && !memcmp (buf1, buf2, BUFSIZ)); - result = (n1 != n2) || memcmp (buf1, buf2, n1); -#endif /* !HAVE_MMAP */ - close (file2); - } - close (file1); - } - return result; -} - -enum CompareMode -{ - compare_quick, compare_size_only, compare_thourough -}; - -static void -compare_dir (WPanel * panel, WPanel * other, enum CompareMode mode) -{ - int i, j; - char *src_name, *dst_name; - - /* No marks by default */ - panel->marked = 0; - panel->total = 0; - panel->dirs_marked = 0; - - /* Handle all files in the panel */ - for (i = 0; i < panel->count; i++) - { - file_entry *source = &panel->dir.list[i]; - - /* Default: unmarked */ - file_mark (panel, i, 0); - - /* Skip directories */ - if (S_ISDIR (source->st.st_mode)) - continue; - - /* Search the corresponding entry from the other panel */ - for (j = 0; j < other->count; j++) - { - if (strcmp (source->fname, other->dir.list[j].fname) == 0) - break; - } - if (j >= other->count) - /* Not found -> mark */ - do_file_mark (panel, i, 1); - else - { - /* Found */ - file_entry *target = &other->dir.list[j]; - - if (mode != compare_size_only) - { - /* Older version is not marked */ - if (source->st.st_mtime < target->st.st_mtime) - continue; - } - - /* Newer version with different size is marked */ - if (source->st.st_size != target->st.st_size) - { - do_file_mark (panel, i, 1); - continue; - - } - if (mode == compare_size_only) - continue; - - if (mode == compare_quick) - { - /* Thorough compare off, compare only time stamps */ - /* Mark newer version, don't mark version with the same date */ - if (source->st.st_mtime > target->st.st_mtime) - { - do_file_mark (panel, i, 1); - } - continue; - } - - /* Thorough compare on, do byte-by-byte comparison */ - src_name = concat_dir_and_file (panel->cwd, source->fname); - dst_name = concat_dir_and_file (other->cwd, target->fname); - if (compare_files (src_name, dst_name, source->st.st_size)) - do_file_mark (panel, i, 1); - g_free (src_name); - g_free (dst_name); - } - } /* for (i ...) */ -} +/* --------------------------------------------------------------------------------------------- */ void compare_dirs_cmd (void) @@ -992,6 +1212,8 @@ compare_dirs_cmd (void) } } +/* --------------------------------------------------------------------------------------------- */ + #ifdef USE_DIFF_VIEW void diff_view_cmd (void) @@ -1005,6 +1227,8 @@ diff_view_cmd (void) } #endif +/* --------------------------------------------------------------------------------------------- */ + void history_cmd (void) { @@ -1012,6 +1236,8 @@ history_cmd (void) send_message (&cmdline->widget, WIDGET_COMMAND, CK_InputHistoryShow); } +/* --------------------------------------------------------------------------------------------- */ + void swap_cmd (void) { @@ -1020,6 +1246,8 @@ swap_cmd (void) repaint_screen (); } +/* --------------------------------------------------------------------------------------------- */ + void view_other_cmd (void) { @@ -1038,56 +1266,7 @@ view_other_cmd (void) } } -static void -do_link (link_type_t link_type, const char *fname) -{ - char *dest = NULL, *src = NULL; - - if (link_type == LINK_HARDLINK) - { - src = g_strdup_printf (_("Link %s to:"), str_trunc (fname, 46)); - dest = input_expand_dialog (_("Link"), src, MC_HISTORY_FM_LINK, ""); - if (!dest || !*dest) - goto cleanup; - save_cwds_stat (); - if (-1 == mc_link (fname, dest)) - message (D_ERROR, MSG_ERROR, _("link: %s"), unix_error_string (errno)); - } - else - { - char *s; - char *d; - - /* suggest the full path for symlink, and either the full or - relative path to the file it points to */ - s = concat_dir_and_file (current_panel->cwd, fname); - - if (get_other_type () == view_listing) - d = concat_dir_and_file (other_panel->cwd, fname); - else - d = g_strdup (fname); - - if (link_type == LINK_SYMLINK_RELATIVE) - s = diff_two_paths (other_panel->cwd, s); - - symlink_dialog (s, d, &dest, &src); - g_free (d); - g_free (s); - - if (!dest || !*dest || !src || !*src) - goto cleanup; - save_cwds_stat (); - if (-1 == mc_symlink (dest, src)) - message (D_ERROR, MSG_ERROR, _("symlink: %s"), unix_error_string (errno)); - } - - update_panels (UP_OPTIMIZE, UP_KEEPSEL); - repaint_screen (); - - cleanup: - g_free (src); - g_free (dest); -} +/* --------------------------------------------------------------------------------------------- */ void link_cmd (link_type_t link_type) @@ -1098,6 +1277,8 @@ link_cmd (link_type_t link_type) do_link (link_type, filename); } +/* --------------------------------------------------------------------------------------------- */ + void edit_symlink_cmd (void) { @@ -1148,6 +1329,8 @@ edit_symlink_cmd (void) } } +/* --------------------------------------------------------------------------------------------- */ + void help_cmd (void) { @@ -1157,15 +1340,19 @@ help_cmd (void) interactive_display (NULL, "[main]"); } +/* --------------------------------------------------------------------------------------------- */ + void user_file_menu_cmd (void) { user_menu_cmd (NULL); } -/* +/* --------------------------------------------------------------------------------------------- */ +/** * Return a random hint. If force is not 0, ignore the timeout. */ + char * get_random_hint (int force) { @@ -1219,41 +1406,9 @@ get_random_hint (int force) return result; } -#if defined(ENABLE_VFS_UNDELFS) || defined(ENABLE_VFS_NET) -static void -nice_cd (const char *text, const char *xtext, const char *help, - const char *history_name, const char *prefix, int to_home) -{ - char *machine; - char *cd_path; - - if (!SELECTED_IS_PANEL) - return; - - machine = input_dialog_help (text, xtext, help, history_name, ""); - if (!machine) - return; - - to_home = 0; /* FIXME: how to solve going to home nicely? /~/ is - ugly as hell and leads to problems in vfs layer */ - - if (strncmp (prefix, machine, strlen (prefix)) == 0) - cd_path = g_strconcat (machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); - else - cd_path = g_strconcat (prefix, machine, to_home ? "/~/" : (char *) NULL, (char *) NULL); - - if (!do_panel_cd (MENU_PANEL, cd_path, cd_parse_command)) - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\""), cd_path); - g_free (cd_path); - g_free (machine); -} -#endif /* ENABLE_VFS_UNDELFS || ENABLE_VFS_NET*/ - +/* --------------------------------------------------------------------------------------------- */ #ifdef ENABLE_VFS_NET - -static const char *machine_str = N_("Enter machine name (F1 for details):"); - #ifdef ENABLE_VFS_FTP void ftplink_cmd (void) @@ -1263,6 +1418,8 @@ ftplink_cmd (void) } #endif /* ENABLE_VFS_FTP */ +/* --------------------------------------------------------------------------------------------- */ + #ifdef ENABLE_VFS_FISH void fishlink_cmd (void) @@ -1273,6 +1430,8 @@ fishlink_cmd (void) } #endif /* ENABLE_VFS_FISH */ +/* --------------------------------------------------------------------------------------------- */ + #ifdef ENABLE_VFS_SMB void smblink_cmd (void) @@ -1283,6 +1442,8 @@ smblink_cmd (void) #endif /* ENABLE_VFS_SMB */ #endif /* ENABLE_VFS_NET */ +/* --------------------------------------------------------------------------------------------- */ + #ifdef ENABLE_VFS_UNDELFS void undelete_cmd (void) @@ -1293,6 +1454,8 @@ undelete_cmd (void) } #endif /* ENABLE_VFS_UNDELFS */ +/* --------------------------------------------------------------------------------------------- */ + void quick_cd_cmd (void) { @@ -1308,7 +1471,7 @@ quick_cd_cmd (void) g_free (p); } - +/* --------------------------------------------------------------------------------------------- */ /*! \brief calculate dirs sizes @@ -1318,6 +1481,7 @@ quick_cd_cmd (void) dir under cursor ".." = show size for all dirs, otherwise = show size for dir under cursor */ + void smart_dirsize_cmd (void) { @@ -1331,6 +1495,8 @@ smart_dirsize_cmd (void) single_dirsize_cmd (); } +/* --------------------------------------------------------------------------------------------- */ + void single_dirsize_cmd (void) { @@ -1368,6 +1534,8 @@ single_dirsize_cmd (void) panel->dirty = 1; } +/* --------------------------------------------------------------------------------------------- */ + void dirsizes_cmd (void) { @@ -1387,7 +1555,8 @@ dirsizes_cmd (void) total = 0.0l; if (compute_dir_size (panel->dir.list[i].fname, - ui, compute_dir_size_update_ui, &marked, &total, TRUE) != FILE_CONT) + ui, compute_dir_size_update_ui, &marked, &total, + TRUE) != FILE_CONT) break; panel->dir.list[i].st.st_size = (off_t) total; @@ -1404,6 +1573,8 @@ dirsizes_cmd (void) panel->dirty = 1; } +/* --------------------------------------------------------------------------------------------- */ + void save_setup_cmd (void) { @@ -1413,31 +1584,7 @@ save_setup_cmd (void) MC_USERCONF_DIR PATH_SEP_STR MC_CONFIG_FILE); } -static void -configure_panel_listing (WPanel * p, int list_type, int use_msformat, char *user, char *status) -{ - p->user_mini_status = use_msformat; - p->list_type = list_type; - - if (list_type == list_user || use_msformat) - { - g_free (p->user_format); - p->user_format = user; - - g_free (p->user_status_format[list_type]); - p->user_status_format[list_type] = status; - - set_panel_formats (p); - } - else - { - g_free (user); - g_free (status); - } - - set_panel_formats (p); - do_refresh (); -} +/* --------------------------------------------------------------------------------------------- */ void info_cmd_no_menu (void) @@ -1450,6 +1597,8 @@ info_cmd_no_menu (void) set_display_type (current_panel == left_panel ? 1 : 0, view_info); } +/* --------------------------------------------------------------------------------------------- */ + void quick_cmd_no_menu (void) { @@ -1461,12 +1610,7 @@ quick_cmd_no_menu (void) set_display_type (current_panel == left_panel ? 1 : 0, view_quick); } -static void -switch_to_listing (int panel_index) -{ - if (get_display_type (panel_index) != view_listing) - set_display_type (panel_index, view_listing); -} +/* --------------------------------------------------------------------------------------------- */ void listing_cmd (void) @@ -1474,6 +1618,8 @@ listing_cmd (void) switch_to_listing (MENU_PANEL_IDX); } +/* --------------------------------------------------------------------------------------------- */ + void change_listing_cmd (void) { @@ -1495,18 +1641,24 @@ change_listing_cmd (void) } } +/* --------------------------------------------------------------------------------------------- */ + void tree_cmd (void) { set_display_type (MENU_PANEL_IDX, view_tree); } +/* --------------------------------------------------------------------------------------------- */ + void info_cmd (void) { set_display_type (MENU_PANEL_IDX, view_info); } +/* --------------------------------------------------------------------------------------------- */ + void quick_view_cmd (void) { @@ -1515,23 +1667,7 @@ quick_view_cmd (void) set_display_type (MENU_PANEL_IDX, view_quick); } -/* Handle the tree internal listing modes switching */ -static gboolean -set_basic_panel_listing_to (int panel_index, int listing_mode) -{ - WPanel *p = (WPanel *) get_panel_widget (panel_index); - gboolean ok; - - switch_to_listing (panel_index); - p->list_type = listing_mode; - - ok = set_panel_formats (p) == 0; - - if (ok) - do_refresh (); - - return ok; -} +/* --------------------------------------------------------------------------------------------- */ void toggle_listing_cmd (void) @@ -1542,9 +1678,13 @@ toggle_listing_cmd (void) set_basic_panel_listing_to (current, (p->list_type + 1) % LIST_TYPES); } +/* --------------------------------------------------------------------------------------------- */ + void encoding_cmd (void) { if (SELECTED_IS_PANEL) panel_change_encoding (MENU_PANEL); } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/cmd.h b/src/cmd.h index c47cc98af..8a6e00ecc 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -1,15 +1,18 @@ - /** \file cmd.h * \brief Header: routines invoked by a function key * * They normally operate on the current panel. */ -#ifndef MC_CMD_H -#define MC_CMD_H +#ifndef MC__CMD_H +#define MC__CMD_H #include "lib/global.h" +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + typedef enum { LINK_HARDLINK = 0, @@ -17,6 +20,21 @@ typedef enum LINK_SYMLINK_RELATIVE } link_type_t; +/* selection flags */ +typedef enum +{ + SELECT_FILES_ONLY = 1 << 0, + SELECT_MATCH_CASE = 1 << 1, + SELECT_SHELL_PATTERNS = 1 << 2 +} select_flags_t; + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + + #ifdef ENABLE_VFS_FTP void ftplink_cmd (void); #endif @@ -31,8 +49,7 @@ void help_cmd (void); void smart_dirsize_cmd (void); void single_dirsize_cmd (void); void dirsizes_cmd (void); -int view_file_at_line (const char *filename, int plain_view, int internal, - int start_line); +int view_file_at_line (const char *filename, int plain_view, int internal, int start_line); int view_file (const char *filename, int normal, int internal); void view_cmd (void); void view_file_cmd (void); @@ -83,4 +100,5 @@ void quick_view_cmd (void); void toggle_listing_cmd (void); void encoding_cmd (void); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/cmddef.h b/src/cmddef.h index b6a95ca42..ff9635736 100644 --- a/src/cmddef.h +++ b/src/cmddef.h @@ -1,15 +1,16 @@ - /** \file * \brief Header: editor constants */ -#ifndef MC_CMD_DEF_H -#define MC_CMD_DEF_H +#ifndef MC__CMD_DEF_H +#define MC__CMD_DEF_H /** \todo In the distant future, keyboards will be invented with a * separate key for each one of these commands *sigh* */ +/*** typedefs(not structures) and defined constants **********************************************/ + /* special commands */ #define CK_Insert_Char -1 #define CK_Ignore_Key 0 @@ -514,4 +515,13 @@ #define CK_Macro(i) ((i) | (1 << 17)) #define IS_MACRO_COMMAND(i) ((i) & (1 << 17)) +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/*** inline functions ****************************************************************************/ #endif /* MC_CMD_DEF_H */ diff --git a/src/command.c b/src/command.c index 3029630a0..31020491c 100644 --- a/src/command.c +++ b/src/command.c @@ -20,7 +20,7 @@ with all the magic of the command input line, we depend on some help from the program's callback. -*/ + */ /** \file command.c * \brief Source: command line widget @@ -32,27 +32,38 @@ #include #include -#include "lib/global.h" /* home_dir */ +#include "lib/global.h" /* home_dir */ #include "lib/tty/tty.h" #include "lib/vfs/mc-vfs/vfs.h" #include "lib/strescape.h" -#include "widget.h" /* WInput */ +#include "widget.h" /* WInput */ #include "command.h" -#include "wtools.h" /* message () */ -#include "panel.h" /* view_tree enum. Also, needed by main.h */ -#include "main.h" /* do_cd */ -#include "layout.h" /* for command_prompt variable */ -#include "user.h" /* expand_format */ -#include "subshell.h" /* SUBSHELL_EXIT */ -#include "tree.h" /* for tree_chdir */ -#include "lib/skin.h" /* DEFAULT_COLOR */ -#include "execute.h" /* shell_execute */ +#include "wtools.h" /* message () */ +#include "panel.h" /* view_tree enum. Also, needed by main.h */ +#include "main.h" /* do_cd */ +#include "layout.h" /* for command_prompt variable */ +#include "user.h" /* expand_format */ +#include "subshell.h" /* SUBSHELL_EXIT */ +#include "tree.h" /* for tree_chdir */ +#include "lib/skin.h" /* DEFAULT_COLOR */ +#include "execute.h" /* shell_execute */ + +/*** global variables ****************************************************************************/ /* This holds the command line */ WInput *cmdline; -/* +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/** * Expand the argument to "cd" and change directory. First try tilde * expansion, then variable substitution. If the CDPATH variable is set * (e.g. CDPATH=".:~:/usr"), try all the paths contained there. @@ -62,6 +73,7 @@ WInput *cmdline; * Advanced users should be encouraged to use "\cd" instead of "cd" if * they want the behavior they are used to in the shell. */ + static int examine_cd (const char *_path) { @@ -71,7 +83,7 @@ examine_cd (const char *_path) const char *t; /* Tilde expansion */ - path = strutils_shell_unescape(_path); + path = strutils_shell_unescape (_path); path_tilde = tilde_expand (path); /* Leave space for further expansion */ @@ -79,67 +91,78 @@ examine_cd (const char *_path) q = g_malloc (qlen); /* Variable expansion */ - for (p = path_tilde, r = q; *p && r < q + MC_MAXPATHLEN;) { - if (*p != '$' || (p[1] == '[' || p[1] == '(')) - *(r++) = *(p++); - else { - p++; - if (*p == '{') { - p++; - s = strchr (p, '}'); - } else - s = NULL; - if (s == NULL) - s = strchr (p, PATH_SEP); - if (s == NULL) - s = strchr (p, 0); - c = *s; - *s = 0; - t = getenv (p); - *s = c; - if (t == NULL) { - *(r++) = '$'; - if (*(p - 1) != '$') - *(r++) = '{'; - } else { - if (r + strlen (t) < q + MC_MAXPATHLEN) { - strcpy (r, t); - r = strchr (r, 0); - } - if (*s == '}') - p = s + 1; - else - p = s; - } - } + for (p = path_tilde, r = q; *p && r < q + MC_MAXPATHLEN;) + { + if (*p != '$' || (p[1] == '[' || p[1] == '(')) + *(r++) = *(p++); + else + { + p++; + if (*p == '{') + { + p++; + s = strchr (p, '}'); + } + else + s = NULL; + if (s == NULL) + s = strchr (p, PATH_SEP); + if (s == NULL) + s = strchr (p, 0); + c = *s; + *s = 0; + t = getenv (p); + *s = c; + if (t == NULL) + { + *(r++) = '$'; + if (*(p - 1) != '$') + *(r++) = '{'; + } + else + { + if (r + strlen (t) < q + MC_MAXPATHLEN) + { + strcpy (r, t); + r = strchr (r, 0); + } + if (*s == '}') + p = s + 1; + else + p = s; + } + } } *r = 0; result = do_cd (q, cd_parse_command); /* CDPATH handling */ - if (*q != PATH_SEP && !result) { - char * const cdpath = g_strdup (getenv ("CDPATH")); - p = cdpath; - if (p == NULL) - c = 0; - else - c = ':'; - while (!result && c == ':') { - s = strchr (p, ':'); - if (s == NULL) - s = strchr (p, 0); - c = *s; - *s = 0; - if (*p) { - r = concat_dir_and_file (p, q); - result = do_cd (r, cd_parse_command); - g_free (r); - } - *s = c; - p = s + 1; - } - g_free (cdpath); + if (*q != PATH_SEP && !result) + { + char *const cdpath = g_strdup (getenv ("CDPATH")); + p = cdpath; + if (p == NULL) + c = 0; + else + c = ':'; + while (!result && c == ':') + { + s = strchr (p, ':'); + if (s == NULL) + s = strchr (p, 0); + c = *s; + *s = 0; + if (*p) + { + r = concat_dir_and_file (p, q); + result = do_cd (r, cd_parse_command); + g_free (r); + } + *s = c; + p = s + 1; + } + g_free (cdpath); } g_free (q); g_free (path_tilde); @@ -147,11 +170,137 @@ examine_cd (const char *_path) return result; } -/* Execute the cd command on the command line */ -void do_cd_command (char * orig_cmd) +/* --------------------------------------------------------------------------------------------- */ +/** Handle Enter on the command line */ + +static cb_ret_t +enter (WInput * lc_cmdline) +{ + char *cmd = lc_cmdline->buffer; + + if (!command_prompt) + return MSG_HANDLED; + + /* Any initial whitespace should be removed at this point */ + while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n') + cmd++; + + if (!*cmd) + return MSG_HANDLED; + + if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0) + { + do_cd_command (cmd); + new_input (lc_cmdline); + return MSG_HANDLED; + } + else if (strcmp (cmd, "exit") == 0) + { + assign_text (lc_cmdline, ""); + if (!quiet_quit_cmd ()) + return MSG_NOT_HANDLED; + } + else + { + char *command, *s; + size_t i, j, cmd_len; + + if (!vfs_current_is_local ()) + { + message (D_ERROR, MSG_ERROR, _("Cannot execute commands on non-local filesystems")); + return MSG_NOT_HANDLED; + } +#ifdef HAVE_SUBSHELL_SUPPORT + /* Check this early before we clean command line + * (will be checked again by shell_execute) */ + if (use_subshell && subshell_state != INACTIVE) + { + message (D_ERROR, MSG_ERROR, _("The shell is already running a command")); + return MSG_NOT_HANDLED; + } +#endif + cmd_len = strlen (cmd); + command = g_malloc (cmd_len + 1); + command[0] = 0; + for (i = j = 0; i < cmd_len; i++) + { + if (cmd[i] == '%') + { + i++; + s = expand_format (NULL, cmd[i], TRUE); + command = g_realloc (command, j + strlen (s) + cmd_len - i + 1); + strcpy (command + j, s); + g_free (s); + j = strlen (command); + } + else + { + command[j] = cmd[i]; + j++; + } + command[j] = 0; + } + new_input (lc_cmdline); + shell_execute (command, 0); + g_free (command); + +#ifdef HAVE_SUBSHELL_SUPPORT + if ((quit & SUBSHELL_EXIT) != 0) + { + if (quiet_quit_cmd ()) + return MSG_HANDLED; + + quit = 0; + /* restart subshell */ + if (use_subshell) + init_subshell (); + } + + if (use_subshell) + load_prompt (0, 0); +#endif + } + return MSG_HANDLED; +} + +/* --------------------------------------------------------------------------------------------- */ + +static cb_ret_t +command_callback (Widget * w, widget_msg_t msg, int parm) +{ + WInput *cmd = (WInput *) w; + + switch (msg) + { + case WIDGET_FOCUS: + /* Never accept focus, otherwise panels will be unselected */ + return MSG_NOT_HANDLED; + + case WIDGET_KEY: + /* Special case: we handle the enter key */ + if (parm == '\n') + { + return enter (cmd); + } + /* fall through */ + + default: + return input_callback (w, msg, parm); + } +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/** Execute the cd command on the command line */ + +void +do_cd_command (char *orig_cmd) { int len; - const char * cmd; + const char *cmd; /* Any final whitespace should be removed here (to see why, try "cd fred "). */ @@ -160,156 +309,62 @@ void do_cd_command (char * orig_cmd) /* FIXME: what about interpreting quoted strings like the shell. so one could type "cd M-a " and it would work. */ len = strlen (orig_cmd) - 1; - while (len >= 0 && - (orig_cmd [len] == ' ' || orig_cmd [len] == '\t' || orig_cmd [len] == '\n')){ - orig_cmd [len] = 0; - len --; + while (len >= 0 && (orig_cmd[len] == ' ' || orig_cmd[len] == '\t' || orig_cmd[len] == '\n')) + { + orig_cmd[len] = 0; + len--; } cmd = orig_cmd; - if (cmd [2] == 0) - cmd = "cd "; + if (cmd[2] == 0) + cmd = "cd "; - if (get_current_type () == view_tree){ - if (cmd [0] == 0){ - sync_tree (home_dir); - } else if (strcmp (cmd+3, "..") == 0){ - char *dir = current_panel->cwd; - len = strlen (dir); - while (len && dir [--len] != PATH_SEP); - dir [len] = 0; - if (len) - sync_tree (dir); - else - sync_tree (PATH_SEP_STR); - } else if (cmd [3] == PATH_SEP){ - sync_tree (cmd+3); - } else { - char *old = current_panel->cwd; - char *new; - new = concat_dir_and_file (old, cmd+3); - sync_tree (new); - g_free (new); - } - } else - if (!examine_cd (&cmd [3])) { - char *d = strip_password (g_strdup (&cmd [3]), 1); - message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), - d, unix_error_string (errno)); - g_free (d); - return; - } -} - -/* Handle Enter on the command line */ -static cb_ret_t -enter (WInput *lc_cmdline) -{ - char *cmd = lc_cmdline->buffer; - - if (!command_prompt) - return MSG_HANDLED; - - /* Any initial whitespace should be removed at this point */ - while (*cmd == ' ' || *cmd == '\t' || *cmd == '\n') - cmd++; - - if (!*cmd) - return MSG_HANDLED; - - if (strncmp (cmd, "cd ", 3) == 0 || strcmp (cmd, "cd") == 0) { - do_cd_command (cmd); - new_input (lc_cmdline); - return MSG_HANDLED; - } else if (strcmp (cmd, "exit") == 0) { - assign_text (lc_cmdline, ""); - if (!quiet_quit_cmd ()) - return MSG_NOT_HANDLED; - } else { - char *command, *s; - size_t i, j, cmd_len; - - if (!vfs_current_is_local ()) { - message (D_ERROR, MSG_ERROR, - _("Cannot execute commands on non-local filesystems")); - return MSG_NOT_HANDLED; - } -#ifdef HAVE_SUBSHELL_SUPPORT - /* Check this early before we clean command line - * (will be checked again by shell_execute) */ - if (use_subshell && subshell_state != INACTIVE) { - message (D_ERROR, MSG_ERROR, - _("The shell is already running a command")); - return MSG_NOT_HANDLED; - } -#endif - cmd_len = strlen (cmd); - command = g_malloc (cmd_len + 1); - command[0] = 0; - for (i = j = 0; i < cmd_len; i++) { - if (cmd[i] == '%') { - i++; - s = expand_format (NULL, cmd[i], TRUE); - command = g_realloc (command, j + strlen (s) + cmd_len - i + 1); - strcpy (command + j, s); - g_free (s); - j = strlen (command); - } else { - command[j] = cmd[i]; - j++; - } - command[j] = 0; - } - new_input (lc_cmdline); - shell_execute (command, 0); - g_free (command); - -#ifdef HAVE_SUBSHELL_SUPPORT - if ((quit & SUBSHELL_EXIT) != 0) { - if (quiet_quit_cmd ()) - return MSG_HANDLED; - - quit = 0; - /* restart subshell */ - if (use_subshell) - init_subshell (); - } - - if (use_subshell) - load_prompt (0, 0); -#endif + if (get_current_type () == view_tree) + { + if (cmd[0] == 0) + { + sync_tree (home_dir); + } + else if (strcmp (cmd + 3, "..") == 0) + { + char *dir = current_panel->cwd; + len = strlen (dir); + while (len && dir[--len] != PATH_SEP); + dir[len] = 0; + if (len) + sync_tree (dir); + else + sync_tree (PATH_SEP_STR); + } + else if (cmd[3] == PATH_SEP) + { + sync_tree (cmd + 3); + } + else + { + char *old = current_panel->cwd; + char *new; + new = concat_dir_and_file (old, cmd + 3); + sync_tree (new); + g_free (new); + } } - return MSG_HANDLED; -} - -static cb_ret_t -command_callback (Widget *w, widget_msg_t msg, int parm) -{ - WInput *cmd = (WInput *) w; - - switch (msg) { - case WIDGET_FOCUS: - /* Never accept focus, otherwise panels will be unselected */ - return MSG_NOT_HANDLED; - - case WIDGET_KEY: - /* Special case: we handle the enter key */ - if (parm == '\n') { - return enter (cmd); - } - /* fall through */ - - default: - return input_callback (w, msg, parm); + else if (!examine_cd (&cmd[3])) + { + char *d = strip_password (g_strdup (&cmd[3]), 1); + message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, unix_error_string (errno)); + g_free (d); + return; } } +/* --------------------------------------------------------------------------------------------- */ + WInput * command_new (int y, int x, int cols) { WInput *cmd; - const input_colors_t command_colors = - { + const input_colors_t command_colors = { DEFAULT_COLOR, COMMAND_MARK_COLOR, DEFAULT_COLOR, @@ -317,7 +372,8 @@ command_new (int y, int x, int cols) }; cmd = input_new (y, x, (int *) command_colors, cols, "", "cmdline", - INPUT_COMPLETE_DEFAULT | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS | INPUT_COMPLETE_SHELL_ESC); + INPUT_COMPLETE_DEFAULT | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS | + INPUT_COMPLETE_SHELL_ESC); /* Add our hooks */ cmd->widget.callback = command_callback; @@ -325,10 +381,12 @@ command_new (int y, int x, int cols) return cmd; } -/* +/* --------------------------------------------------------------------------------------------- */ +/** * Insert quoted text in input line. The function is meant for the * command line, so the percent sign is quoted as well. */ + void command_insert (WInput * in, const char *text, int insert_extra_space) { @@ -339,3 +397,4 @@ command_insert (WInput * in, const char *text, int insert_extra_space) g_free (quoted_text); } +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/command.h b/src/command.h index bee1c930c..c5240ab61 100644 --- a/src/command.h +++ b/src/command.h @@ -1,17 +1,27 @@ - /** \file command.h * \brief Header: command line widget */ -#ifndef MC_COMMAND_H -#define MC_COMMAND_H +#ifndef MC__COMMAND_H +#define MC__COMMAND_H #include "widget.h" +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + extern WInput *cmdline; +/*** declarations of public functions ************************************************************/ + WInput *command_new (int y, int x, int len); void do_cd_command (char *cmd); void command_insert (WInput * in, const char *text, int insert_extra_space); +/*** inline functions ****************************************************************************/ #endif diff --git a/src/complete.c b/src/complete.c index 582c7c2f2..947aa2710 100644 --- a/src/complete.c +++ b/src/complete.c @@ -49,11 +49,48 @@ #include "wtools.h" #include "main.h" /* show_all_if_ambiguous */ -typedef char *CompletionFunction (const char *text, int state, INPUT_COMPLETE_FLAGS flags); +/*** global variables ****************************************************************************/ + +/* Linux declares environ in , so don't repeat it here. */ +#if (!(defined(__linux__) && defined (__USE_GNU)) && !defined(__CYGWIN__)) +extern char **environ; +#endif + +/*** file scope macro definitions ****************************************************************/ /* #define DO_COMPLETION_DEBUG */ #ifdef DO_COMPLETION_DEBUG -/* +#define SHOW_C_CTX(func) fprintf(stderr, "%s: text='%s' flags=%s\n", func, text, show_c_flags(flags)) +#else +#define SHOW_C_CTX(func) +#endif /* DO_CMPLETION_DEBUG */ + +#define whitespace(c) ((c) == ' ' || (c) == '\t') +#define cr_whitespace(c) (whitespace (c) || (c) == '\n' || (c) == '\r') + +#define DO_INSERTION 1 +#define DO_QUERY 2 + +/*** file scope type declarations ****************************************************************/ + +typedef char *CompletionFunction (const char *text, int state, INPUT_COMPLETE_FLAGS flags); + +/*** file scope variables ************************************************************************/ + +static char **hosts = NULL; +static char **hosts_p = NULL; +static int hosts_alloclen = 0; + +static int query_height, query_width; +static WInput *input; +static int min_end; +static int start, end; + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +#ifdef DO_COMPLETION_DEBUG +/** * Useful to print/debug completion flags */ static const char * @@ -71,12 +108,10 @@ show_c_flags (INPUT_COMPLETE_FLAGS flags) return s_cf; } - -#define SHOW_C_CTX(func) fprintf(stderr, "%s: text='%s' flags=%s\n", func, text, show_c_flags(flags)) -#else -#define SHOW_C_CTX(func) #endif /* DO_CMPLETION_DEBUG */ +/* --------------------------------------------------------------------------------------------- */ + static char * filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags) { @@ -249,8 +284,10 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS } } -/* We assume here that text[0] == '~' , if you want to call it in another way, +/* --------------------------------------------------------------------------------------------- */ +/** We assume here that text[0] == '~' , if you want to call it in another way, you have to change the code */ + static char * username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags) { @@ -283,13 +320,10 @@ username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS return NULL; } -/* Linux declares environ in , so don't repeat it here. */ -#if (!(defined(__linux__) && defined (__USE_GNU)) && !defined(__CYGWIN__)) -extern char **environ; -#endif - -/* We assume text [0] == '$' and want to have a look at text [1], if it is +/* --------------------------------------------------------------------------------------------- */ +/** We assume text [0] == '$' and want to have a look at text [1], if it is equal to '{', so that we should append '}' at the end */ + static char * variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags) { @@ -334,12 +368,8 @@ variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS } } -#define whitespace(c) ((c) == ' ' || (c) == '\t') -#define cr_whitespace(c) (whitespace (c) || (c) == '\n' || (c) == '\r') +/* --------------------------------------------------------------------------------------------- */ -static char **hosts = NULL; -static char **hosts_p = NULL; -static int hosts_alloclen = 0; static void fetch_hosts (const char *filename) { @@ -423,6 +453,8 @@ fetch_hosts (const char *filename) fclose (file); } +/* --------------------------------------------------------------------------------------------- */ + static char * hostname_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags) { @@ -480,12 +512,14 @@ hostname_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS } } -/* +/* --------------------------------------------------------------------------------------------- */ +/** * This is the function to call when the word to complete is in a position * where a command word can be found. It looks around $PATH, looking for * commands that match. It also scans aliases, function names, and the * table of shell built-ins. */ + static char * command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS flags) { @@ -637,19 +671,23 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS return found; } +/* --------------------------------------------------------------------------------------------- */ + static int match_compare (const void *a, const void *b) { return strcmp (*(char **) a, *(char **) b); } -/* Returns an array of char * matches with the longest common denominator +/* --------------------------------------------------------------------------------------------- */ +/** Returns an array of char * matches with the longest common denominator in the 1st entry. Then a NULL terminated list of different possible completions follows. You have to supply your own CompletionFunction with the word you want to complete as the first argument and an count of previous matches as the second. In case no matches were found we return NULL. */ + static char ** completion_matches (const char *text, CompletionFunction entry_function, INPUT_COMPLETE_FLAGS flags) { @@ -748,7 +786,8 @@ completion_matches (const char *text, CompletionFunction entry_function, INPUT_C return match_list; } -/* Check if directory completion is needed */ +/* --------------------------------------------------------------------------------------------- */ +/** Check if directory completion is needed */ static int check_is_cd (const char *text, int start, INPUT_COMPLETE_FLAGS flags) { @@ -777,7 +816,8 @@ check_is_cd (const char *text, int start, INPUT_COMPLETE_FLAGS flags) return 0; } -/* Returns an array of matches, or NULL if none. */ +/* --------------------------------------------------------------------------------------------- */ +/** Returns an array of matches, or NULL if none. */ static char ** try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags) { @@ -938,23 +978,7 @@ try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags) return matches; } -void -free_completions (WInput * in) -{ - char **p; - - if (!in->completions) - return; - for (p = in->completions; *p; p++) - g_free (*p); - g_free (in->completions); - in->completions = NULL; -} - -static int query_height, query_width; -static WInput *input; -static int min_end; -static int start, end; +/* --------------------------------------------------------------------------------------------- */ static int insert_text (WInput * in, char *text, ssize_t size) @@ -995,6 +1019,8 @@ insert_text (WInput * in, char *text, ssize_t size) return size != 0; } +/* --------------------------------------------------------------------------------------------- */ + static cb_ret_t query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data) { @@ -1145,9 +1171,9 @@ query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *da } } -#define DO_INSERTION 1 -#define DO_QUERY 2 -/* Returns 1 if the user would like to see us again */ +/* --------------------------------------------------------------------------------------------- */ +/** Returns 1 if the user would like to see us again */ + static int complete_engine (WInput * in, int what_to_do) { @@ -1264,6 +1290,25 @@ complete_engine (WInput * in, int what_to_do) return 0; } +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +void +free_completions (WInput * in) +{ + char **p; + + if (!in->completions) + return; + for (p = in->completions; *p; p++) + g_free (*p); + g_free (in->completions); + in->completions = NULL; +} + +/* --------------------------------------------------------------------------------------------- */ + void complete (WInput * in) { @@ -1284,3 +1329,5 @@ complete (WInput * in) while (complete_engine (in, engine_flags)); } + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/cons.handler.c b/src/cons.handler.c index 2a2eded19..5e8d33b07 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -29,8 +29,8 @@ #include #include #ifdef __FreeBSD__ -# include -# include +#include +#include #endif #include @@ -42,17 +42,44 @@ #include "consaver/cons.saver.h" +/*** global variables ****************************************************************************/ + signed char console_flag = 0; #ifdef __linux__ +int cons_saver_pid = 1; +#endif /* __linux__ */ +/*** file scope macro definitions ****************************************************************/ + +#if defined(__FreeBSD__) +#define FD_OUT 1 +#define cursor_to(x, y) \ +do \ +{ \ + printf("\x1B[%d;%df", (y) + 1, (x) + 1); \ + fflush(stdout); \ +} while (0) +#endif /* __linux__ */ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +#ifdef __linux__ /* The cons saver can't have a pid of 1, used to prevent bunches of * #ifdef linux */ - -int cons_saver_pid = 1; static int pipefd1[2] = { -1, -1 }; static int pipefd2[2] = { -1, -1 }; +#elif defined(__FreeBSD__) +static struct scrshot screen_shot; +static struct vid_info screen_info; +#endif /* __linux__ */ +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +#ifdef __linux__ static void show_console_contents_linux (int starty, unsigned char begin_line, unsigned char end_line) { @@ -99,6 +126,8 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char ret = read (pipefd2[0], &message, 1); } +/* --------------------------------------------------------------------------------------------- */ + static void handle_console_linux (unsigned char action) { @@ -219,16 +248,12 @@ handle_console_linux (unsigned char action) #elif defined(__FreeBSD__) -/* +/* --------------------------------------------------------------------------------------------- */ +/** * FreeBSD support copyright (C) 2003 Alexander Serkov . * Support for screenmaps by Max Khon */ -#define FD_OUT 1 - -static struct scrshot screen_shot; -static struct vid_info screen_info; - static void console_init (void) { @@ -247,6 +272,8 @@ console_init (void) console_flag = 1; } +/* --------------------------------------------------------------------------------------------- */ + static void set_attr (unsigned attr) { @@ -264,12 +291,7 @@ set_attr (unsigned attr) color_map[tc & 7], color_map[bc & 7]); } -#define cursor_to(x, y) \ -do \ -{ \ - printf("\x1B[%d;%df", (y) + 1, (x) + 1); \ - fflush(stdout); \ -} while (0) +/* --------------------------------------------------------------------------------------------- */ static void console_restore (void) @@ -295,6 +317,8 @@ console_restore (void) fflush (stdout); } +/* --------------------------------------------------------------------------------------------- */ + static void console_shutdown (void) { @@ -306,6 +330,8 @@ console_shutdown (void) console_flag = 0; } +/* --------------------------------------------------------------------------------------------- */ + static void console_save (void) { @@ -351,11 +377,13 @@ console_save (void) for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++) { screen_shot.buf[i] = - (screen_shot.buf[i] & 0xff00) | (unsigned char) revmap. - scrmap[screen_shot.buf[i] & 0xff]; + (screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.scrmap[screen_shot. + buf[i] & 0xff]; } } +/* --------------------------------------------------------------------------------------------- */ + static void show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned char end_line) { @@ -376,6 +404,8 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch } } +/* --------------------------------------------------------------------------------------------- */ + static void handle_console_freebsd (unsigned char action) { @@ -400,6 +430,10 @@ handle_console_freebsd (unsigned char action) } #endif /* __FreeBSD__ */ +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line) { @@ -419,6 +453,8 @@ show_console_contents (int starty, unsigned char begin_line, unsigned char end_l #endif } +/* --------------------------------------------------------------------------------------------- */ + void handle_console (unsigned char action) { @@ -433,3 +469,5 @@ handle_console (unsigned char action) handle_console_freebsd (action); #endif } + +/* --------------------------------------------------------------------------------------------- */