Code indentation in src directory

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2010-11-09 13:02:28 +02:00 committed by Andrew Borodin
parent 34c1e1a38a
commit c2754de8aa
23 changed files with 1926 additions and 1222 deletions

View File

@ -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 ();
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

View File

@ -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;

View File

@ -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 */

View File

@ -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 */

View File

@ -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 <sys/types.h> /* pid_t */
#include <sys/types.h> /* 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 */

View File

@ -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 */
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

View File

@ -30,12 +30,14 @@
#include <string.h>
#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 */

View File

@ -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 */

View File

@ -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 ();
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

View File

@ -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 ();
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

View File

@ -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;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

1052
src/cmd.c

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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 */

View File

@ -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 <errno.h>
#include <string.h>
#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 <tab> M-a <enter>" 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);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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

View File

@ -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 <unistd.h>, 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 <unistd.h>, 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));
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -29,8 +29,8 @@
#include <fcntl.h>
#include <sys/types.h>
#ifdef __FreeBSD__
# include <sys/consio.h>
# include <sys/ioctl.h>
#include <sys/consio.h>
#include <sys/ioctl.h>
#endif
#include <unistd.h>
@ -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 <serkov@ukrpost.net>.
* Support for screenmaps by Max Khon <fjoe@FreeBSD.org>
*/
#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
}
/* --------------------------------------------------------------------------------------------- */