mirror of https://github.com/MidnightCommander/mc
Code indentation in src directory
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
parent
34c1e1a38a
commit
c2754de8aa
54
src/achown.c
54
src/achown.c
|
@ -52,6 +52,10 @@
|
||||||
#include "layout.h" /* repaint_screen() */
|
#include "layout.h" /* repaint_screen() */
|
||||||
#include "achown.h"
|
#include "achown.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define BX 5
|
#define BX 5
|
||||||
#define BY 6
|
#define BY 6
|
||||||
|
|
||||||
|
@ -69,6 +73,10 @@
|
||||||
#define B_OUSER (B_USER + 6)
|
#define B_OUSER (B_USER + 6)
|
||||||
#define B_OGROUP (B_USER + 7)
|
#define B_OGROUP (B_USER + 7)
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static struct Dlg_head *ch_dlg;
|
static struct Dlg_head *ch_dlg;
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
|
@ -106,6 +114,9 @@ static int current_file;
|
||||||
static int single_set;
|
static int single_set;
|
||||||
static char *fname;
|
static char *fname;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_ownership (void)
|
update_ownership (void)
|
||||||
{
|
{
|
||||||
|
@ -113,6 +124,7 @@ update_ownership (void)
|
||||||
button_set_text (b_group, get_group (sf_stat->st_gid));
|
button_set_text (b_group, get_group (sf_stat->st_gid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
inc_flag_pos (int f_pos)
|
inc_flag_pos (int f_pos)
|
||||||
|
@ -128,6 +140,8 @@ inc_flag_pos (int f_pos)
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
dec_flag_pos (int f_pos)
|
dec_flag_pos (int f_pos)
|
||||||
{
|
{
|
||||||
|
@ -142,6 +156,8 @@ dec_flag_pos (int f_pos)
|
||||||
return MSG_HANDLED;
|
return MSG_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_perm_by_flags (char *s, int f_p)
|
set_perm_by_flags (char *s, int f_p)
|
||||||
{
|
{
|
||||||
|
@ -158,6 +174,8 @@ set_perm_by_flags (char *s, int f_p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_permissions (void)
|
update_permissions (void)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +184,8 @@ update_permissions (void)
|
||||||
set_perm_by_flags (b_att[2]->text.start, 6);
|
set_perm_by_flags (b_att[2]->text.start, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static mode_t
|
static mode_t
|
||||||
get_perm (char *s, int base)
|
get_perm (char *s, int base)
|
||||||
{
|
{
|
||||||
|
@ -183,6 +203,8 @@ get_perm (char *s, int base)
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static mode_t
|
static mode_t
|
||||||
get_mode (void)
|
get_mode (void)
|
||||||
{
|
{
|
||||||
|
@ -196,6 +218,8 @@ get_mode (void)
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_flags (void)
|
print_flags (void)
|
||||||
{
|
{
|
||||||
|
@ -235,6 +259,8 @@ print_flags (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_mode (Dlg_head * h)
|
update_mode (Dlg_head * h)
|
||||||
{
|
{
|
||||||
|
@ -245,6 +271,8 @@ update_mode (Dlg_head * h)
|
||||||
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
chl_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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
|
static void
|
||||||
do_enter_key (Dlg_head * h, int f_pos)
|
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);
|
while (chl_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chown_refresh (void)
|
chown_refresh (void)
|
||||||
{
|
{
|
||||||
|
@ -412,6 +444,8 @@ chown_refresh (void)
|
||||||
print_flags ();
|
print_flags ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chown_info_update (void)
|
chown_info_update (void)
|
||||||
{
|
{
|
||||||
|
@ -428,6 +462,8 @@ chown_info_update (void)
|
||||||
update_permissions ();
|
update_permissions ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
b_setpos (int f_pos)
|
b_setpos (int f_pos)
|
||||||
{
|
{
|
||||||
|
@ -437,6 +473,8 @@ b_setpos (int f_pos)
|
||||||
b_att[f_pos]->hotpos = (flag_pos % 3);
|
b_att[f_pos]->hotpos = (flag_pos % 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
advanced_chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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
|
static void
|
||||||
init_chown_advanced (void)
|
init_chown_advanced (void)
|
||||||
{
|
{
|
||||||
|
@ -646,6 +686,8 @@ init_chown_advanced (void)
|
||||||
add_widget (ch_dlg, b_att[0]);
|
add_widget (ch_dlg, b_att[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chown_advanced_done (void)
|
chown_advanced_done (void)
|
||||||
{
|
{
|
||||||
|
@ -655,6 +697,8 @@ chown_advanced_done (void)
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void
|
static void
|
||||||
do_chown (uid_t u, gid_t g)
|
do_chown (uid_t u, gid_t g)
|
||||||
|
@ -664,6 +708,8 @@ do_chown (uid_t u, gid_t g)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
next_file (void)
|
next_file (void)
|
||||||
{
|
{
|
||||||
|
@ -673,6 +719,8 @@ next_file (void)
|
||||||
return current_panel->dir.list[current_file].fname;
|
return current_panel->dir.list[current_file].fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
apply_advanced_chowns (struct stat *sf)
|
apply_advanced_chowns (struct stat *sf)
|
||||||
{
|
{
|
||||||
|
@ -713,6 +761,10 @@ apply_advanced_chowns (struct stat *sf)
|
||||||
while (current_panel->marked);
|
while (current_panel->marked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
chown_advanced_cmd (void)
|
chown_advanced_cmd (void)
|
||||||
{
|
{
|
||||||
|
@ -779,3 +831,5 @@ chown_advanced_cmd (void)
|
||||||
|
|
||||||
chown_advanced_done ();
|
chown_advanced_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
16
src/achown.h
16
src/achown.h
|
@ -1,11 +1,21 @@
|
||||||
|
|
||||||
/** \file achown.h
|
/** \file achown.h
|
||||||
* \brief Header: Contains functions for advanced chowning
|
* \brief Header: Contains functions for advanced chowning
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_ACHOWN_H
|
#ifndef MC__ACHOWN_H
|
||||||
#define 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);
|
void chown_advanced_cmd (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
18
src/args.c
18
src/args.c
|
@ -35,7 +35,7 @@
|
||||||
#include "lib/strutil.h"
|
#include "lib/strutil.h"
|
||||||
#include "lib/vfs/mc-vfs/vfs.h"
|
#include "lib/vfs/mc-vfs/vfs.h"
|
||||||
#ifdef ENABLE_VFS_SMB
|
#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
|
#endif
|
||||||
|
|
||||||
#include "src/main.h"
|
#include "src/main.h"
|
||||||
|
@ -92,10 +92,10 @@ int mc_args__debug_level = 0;
|
||||||
/*** file scope variables ************************************************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
/* forward declarations */
|
/* forward declarations */
|
||||||
static gboolean parse_mc_e_argument (const gchar *option_name, const gchar *value,
|
static gboolean parse_mc_e_argument (const gchar * option_name, const gchar * value,
|
||||||
gpointer data, GError **error);
|
gpointer data, GError ** error);
|
||||||
static gboolean parse_mc_v_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);
|
gpointer data, GError ** error);
|
||||||
|
|
||||||
static GOptionContext *context;
|
static GOptionContext *context;
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ mc_setup_by_args (int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
char *end, *p;
|
char *end, *p;
|
||||||
|
|
||||||
end = tmp + strlen (tmp);\
|
end = tmp + strlen (tmp);
|
||||||
p = end;
|
p = end;
|
||||||
|
|
||||||
if (p > tmp && p[-1] == ':')
|
if (p > tmp && p[-1] == ':')
|
||||||
|
@ -601,8 +601,7 @@ mc_args__convert_help_to_syscharset (const gchar * charset, const gchar * error_
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_mc_e_argument (const gchar *option_name, const gchar *value,
|
parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||||
gpointer data, GError **error)
|
|
||||||
{
|
{
|
||||||
(void) option_name;
|
(void) option_name;
|
||||||
(void) data;
|
(void) data;
|
||||||
|
@ -617,8 +616,7 @@ parse_mc_e_argument (const gchar *option_name, const gchar *value,
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_mc_v_argument (const gchar *option_name, const gchar *value,
|
parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer data, GError ** error)
|
||||||
gpointer data, GError **error)
|
|
||||||
{
|
{
|
||||||
(void) option_name;
|
(void) option_name;
|
||||||
(void) data;
|
(void) data;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef MC__ARGS_H
|
#ifndef MC__ARGS_H
|
||||||
#define MC__ARGS_H
|
#define MC__ARGS_H
|
||||||
|
|
||||||
#include "lib/global.h" /* gboolean */
|
#include "lib/global.h" /* gboolean */
|
||||||
|
|
||||||
/*** typedefs(not structures) and defined constants **********************************************/
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ extern int mc_args__debug_level;
|
||||||
|
|
||||||
/*** declarations of public functions ************************************************************/
|
/*** 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 */
|
#endif /* MC__ARGS_H */
|
||||||
|
|
210
src/background.c
210
src/background.c
|
@ -50,14 +50,24 @@
|
||||||
#include "fileopctx.h" /* FileOpContext */
|
#include "fileopctx.h" /* FileOpContext */
|
||||||
#include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */
|
#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
|
enum ReturnType
|
||||||
{
|
{
|
||||||
Return_String,
|
Return_String,
|
||||||
Return_Integer
|
Return_Integer
|
||||||
};
|
};
|
||||||
|
|
||||||
/* If true, this is a background process */
|
/*** file scope variables ************************************************************************/
|
||||||
int we_are_background = 0;
|
|
||||||
|
|
||||||
/* File descriptor for talking to our parent */
|
/* File descriptor for talking to our parent */
|
||||||
static int parent_fd;
|
static int parent_fd;
|
||||||
|
@ -65,12 +75,13 @@ static int parent_fd;
|
||||||
/* File descriptor for messages from our parent */
|
/* File descriptor for messages from our parent */
|
||||||
static int from_parent_fd;
|
static int from_parent_fd;
|
||||||
|
|
||||||
#define MAXCALLARGS 4 /* Number of arguments supported */
|
|
||||||
|
|
||||||
struct TaskList *task_list = NULL;
|
struct TaskList *task_list = NULL;
|
||||||
|
|
||||||
static int background_attention (int fd, void *closure);
|
static int background_attention (int fd, void *closure);
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
register_task_running (FileOpContext * ctx, pid_t pid, int fd, int to_child, char *info)
|
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);
|
add_select_channel (fd, background_attention, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
destroy_task_and_return_fd (pid_t pid)
|
destroy_task_and_return_fd (pid_t pid)
|
||||||
{
|
{
|
||||||
|
@ -114,91 +127,7 @@ destroy_task_and_return_fd (pid_t pid)
|
||||||
return -1;
|
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 handlers */
|
||||||
|
|
||||||
/* Parent/child protocol
|
/* Parent/child protocol
|
||||||
|
@ -236,7 +165,7 @@ do_background (struct FileOpContext *ctx, char *info)
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* Receive requests from background process and invoke the
|
* Receive requests from background process and invoke the
|
||||||
* specified routine
|
* specified routine
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -453,6 +382,7 @@ background_attention (int fd, void *closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ client RPC routines */
|
/* {{{ 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
|
* operation context is not NULL, then it requests that the first parameter of
|
||||||
* the call be a file operation context.
|
* the call be a file operation context.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext * ctx)
|
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));
|
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
|
int
|
||||||
parent_call (void *routine, struct FileOpContext *ctx, int argc, ...)
|
parent_call (void *routine, struct FileOpContext *ctx, int argc, ...)
|
||||||
{
|
{
|
||||||
|
@ -505,6 +531,8 @@ parent_call (void *routine, struct FileOpContext *ctx, int argc, ...)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
parent_call_string (void *routine, int argc, ...)
|
parent_call_string (void *routine, int argc, ...)
|
||||||
{
|
{
|
||||||
|
@ -539,4 +567,6 @@ parent_call_string (void *routine, int argc, ...)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#endif /* WITH_BACKGROUND */
|
#endif /* WITH_BACKGROUND */
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
|
|
||||||
/** \file background.h
|
/** \file background.h
|
||||||
* \brief Header: Background support
|
* \brief Header: Background support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_BACKGROUND_H
|
#ifndef MC__BACKGROUND_H
|
||||||
#define MC_BACKGROUND_H
|
#define MC__BACKGROUND_H
|
||||||
|
|
||||||
#ifdef WITH_BACKGROUND
|
#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_Running,
|
||||||
Task_Stopped
|
Task_Stopped
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct TaskList {
|
typedef struct TaskList
|
||||||
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int to_child_fd;
|
int to_child_fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
@ -24,17 +27,29 @@ typedef struct TaskList {
|
||||||
struct TaskList *next;
|
struct TaskList *next;
|
||||||
} TaskList;
|
} TaskList;
|
||||||
|
|
||||||
|
struct FileOpContext;
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern struct TaskList *task_list;
|
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 do_background (struct FileOpContext *ctx, char *info);
|
||||||
int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...);
|
int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...);
|
||||||
char *parent_call_string (void *routine, int argc, ...);
|
char *parent_call_string (void *routine, int argc, ...);
|
||||||
|
|
||||||
void unregister_task_running (pid_t pid, int fd);
|
void unregister_task_running (pid_t pid, int fd);
|
||||||
void unregister_task_with_pid (pid_t pid);
|
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 */
|
||||||
|
|
552
src/boxes.c
552
src/boxes.c
|
@ -69,6 +69,31 @@
|
||||||
|
|
||||||
#include "boxes.h"
|
#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 WRadio *display_radio;
|
||||||
static WInput *display_user_format;
|
static WInput *display_user_format;
|
||||||
static WInput *display_mini_status;
|
static WInput *display_mini_status;
|
||||||
|
@ -76,6 +101,50 @@ static WCheck *display_check_status;
|
||||||
static char **displays_status;
|
static char **displays_status;
|
||||||
static int display_user_hotkey = 'u';
|
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
|
static cb_ret_t
|
||||||
display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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 *
|
static Dlg_head *
|
||||||
display_init (int radio_sel, char *init_text, int _check_status, char **_status)
|
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, cancel_button);
|
||||||
add_widget (dd, ok_button);
|
add_widget (dd, ok_button);
|
||||||
|
|
||||||
display_mini_status = input_new (10, 8, input_get_default_colors(), dlg_width - 12, _status[radio_sel],
|
display_mini_status =
|
||||||
"mini-input", INPUT_COMPLETE_DEFAULT);
|
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);
|
add_widget (dd, display_mini_status);
|
||||||
|
|
||||||
display_check_status = check_new (9, 4, _check_status, user_mini_status);
|
display_check_status = check_new (9, 4, _check_status, user_mini_status);
|
||||||
add_widget (dd, display_check_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);
|
"user-fmt-input", INPUT_COMPLETE_DEFAULT);
|
||||||
add_widget (dd, display_user_format);
|
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;
|
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 */
|
/* return list type */
|
||||||
int
|
int
|
||||||
display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int num)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const panel_field_t *
|
const panel_field_t *
|
||||||
sort_box (const panel_field_t * sort_format, int *reverse, int *case_sensitive, int *exec_first)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
confirm_box (void)
|
confirm_box (void)
|
||||||
|
@ -469,6 +751,7 @@ confirm_box (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifndef HAVE_CHARSET
|
#ifndef HAVE_CHARSET
|
||||||
void
|
void
|
||||||
|
@ -563,80 +846,9 @@ display_bits_box (void) /* AB:FIXME: test dialog */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
#else /* HAVE_CHARSET */
|
#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
|
void
|
||||||
display_bits_box (void)
|
display_bits_box (void)
|
||||||
{
|
{
|
||||||
|
@ -669,33 +881,11 @@ display_bits_box (void)
|
||||||
destroy_dlg (dbits_dlg);
|
destroy_dlg (dbits_dlg);
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_CHARSET */
|
#endif /* HAVE_CHARSET */
|
||||||
|
|
||||||
static cb_ret_t
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
/** Show tree in a box, not on a panel */
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Show tree in a box, not on a panel */
|
|
||||||
char *
|
char *
|
||||||
tree_box (const char *current_dir)
|
tree_box (const char *current_dir)
|
||||||
{
|
{
|
||||||
|
@ -727,53 +917,12 @@ tree_box (const char *current_dir)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef ENABLE_VFS
|
#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
|
void
|
||||||
configure_vfs (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];
|
char buffer2[BUF_TINY];
|
||||||
#ifdef ENABLE_VFS_FTP
|
#ifdef ENABLE_VFS_FTP
|
||||||
char buffer3[BUF_TINY];
|
char buffer3[BUF_TINY];
|
||||||
|
@ -849,6 +998,8 @@ configure_vfs (void)
|
||||||
|
|
||||||
#endif /* ENABLE_VFS */
|
#endif /* ENABLE_VFS */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
cd_dialog (void)
|
cd_dialog (void)
|
||||||
{
|
{
|
||||||
|
@ -882,6 +1033,8 @@ cd_dialog (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
symlink_dialog (const char *existing, const char *new, char **ret_existing, char **ret_new)
|
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
|
#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
|
void
|
||||||
jobs_cmd (void)
|
jobs_cmd (void)
|
||||||
{
|
{
|
||||||
|
@ -1058,6 +1119,8 @@ jobs_cmd (void)
|
||||||
}
|
}
|
||||||
#endif /* WITH_BACKGROUND */
|
#endif /* WITH_BACKGROUND */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef ENABLE_VFS_SMB
|
#ifdef ENABLE_VFS_SMB
|
||||||
struct smb_authinfo *
|
struct smb_authinfo *
|
||||||
vfs_smb_get_authinfo (const char *host, const char *share, const char *domain, const char *user)
|
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;
|
Dlg_head *auth_dlg;
|
||||||
struct smb_authinfo *return_value = NULL;
|
struct smb_authinfo *return_value = NULL;
|
||||||
|
|
||||||
const int input_colors[3] =
|
const int input_colors[3] = {
|
||||||
{
|
|
||||||
INPUT_COLOR,
|
INPUT_COLOR,
|
||||||
INPUT_UNCHANGED_COLOR,
|
INPUT_UNCHANGED_COLOR,
|
||||||
INPUT_MARK_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);
|
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);
|
add_widget (auth_dlg, in_user);
|
||||||
|
|
||||||
in_domain =
|
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, in_domain);
|
||||||
add_widget (auth_dlg, button_new (9, b2, B_CANCEL, NORMAL_BUTTON, buts[1], 0));
|
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));
|
add_widget (auth_dlg, button_new (9, b0, B_ENTER, DEFPUSH_BUTTON, buts[0], 0));
|
||||||
|
|
||||||
in_password =
|
in_password =
|
||||||
input_new (7, istart, input_get_default_colors(), ilen, "", "auth_password", INPUT_COMPLETE_DEFAULT);
|
input_new (7, istart, input_get_default_colors (), ilen, "", "auth_password",
|
||||||
|
INPUT_COMPLETE_DEFAULT);
|
||||||
|
|
||||||
in_password->completion_flags = 0;
|
in_password->completion_flags = 0;
|
||||||
in_password->is_password = 1;
|
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;
|
return return_value;
|
||||||
}
|
}
|
||||||
#endif /* ENABLE_VFS_SMB */
|
#endif /* ENABLE_VFS_SMB */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
38
src/boxes.h
38
src/boxes.h
|
@ -1,25 +1,33 @@
|
||||||
|
|
||||||
/** \file boxes.h
|
/** \file boxes.h
|
||||||
* \brief Header: Some misc dialog boxes for the program
|
* \brief Header: Some misc dialog boxes for the program
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_BOXES_H
|
#ifndef MC__BOXES_H
|
||||||
#define MC_BOXES_H
|
#define MC__BOXES_H
|
||||||
|
|
||||||
#include "dir.h"
|
#include "dir.h"
|
||||||
#include "panel.h"
|
#include "panel.h"
|
||||||
|
|
||||||
int display_box (WPanel *p, char **user, char **mini,
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
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);
|
|
||||||
|
|
||||||
|
/*** 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
|
#endif
|
||||||
|
|
229
src/charsets.c
229
src/charsets.c
|
@ -30,12 +30,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "lib/strutil.h" /* utf-8 functions */
|
#include "lib/strutil.h" /* utf-8 functions */
|
||||||
#include "lib/fileloc.h"
|
#include "lib/fileloc.h"
|
||||||
|
|
||||||
#include "charsets.h"
|
#include "charsets.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
GPtrArray *codepages = NULL;
|
GPtrArray *codepages = NULL;
|
||||||
|
|
||||||
unsigned char conv_displ[256];
|
unsigned char conv_displ[256];
|
||||||
|
@ -44,6 +46,23 @@ unsigned char conv_input[256];
|
||||||
const char *cp_display = NULL;
|
const char *cp_display = NULL;
|
||||||
const char *cp_source = 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 *
|
static codepage_desc *
|
||||||
new_codepage_desc (const char *id, const char *name)
|
new_codepage_desc (const char *id, const char *name)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +75,8 @@ new_codepage_desc (const char *id, const char *name)
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_codepage_desc (gpointer data, gpointer user_data)
|
free_codepage_desc (gpointer data, gpointer user_data)
|
||||||
{
|
{
|
||||||
|
@ -67,9 +88,11 @@ free_codepage_desc (gpointer data, gpointer user_data)
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* returns display codepage */
|
/* returns display codepage */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_codepages_list_from_file (GPtrArray **list, const char *fname)
|
load_codepages_list_from_file (GPtrArray ** list, const char *fname)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
guint i;
|
guint i;
|
||||||
|
@ -80,7 +103,7 @@ load_codepages_list_from_file (GPtrArray **list, const char *fname)
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
return;
|
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 */
|
/* split string into id and cpname */
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
@ -148,6 +171,29 @@ load_codepages_list_from_file (GPtrArray **list, const char *fname)
|
||||||
fclose (f);
|
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
|
void
|
||||||
load_codepages_list (void)
|
load_codepages_list (void)
|
||||||
{
|
{
|
||||||
|
@ -173,6 +219,8 @@ load_codepages_list (void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
free_codepages_list (void)
|
free_codepages_list (void)
|
||||||
{
|
{
|
||||||
|
@ -180,7 +228,7 @@ free_codepages_list (void)
|
||||||
g_ptr_array_free (codepages, TRUE);
|
g_ptr_array_free (codepages, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OTHER_8BIT "Other_8_bit"
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
get_codepage_id (const int n)
|
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;
|
return (n < 0) ? OTHER_8BIT : ((codepage_desc *) g_ptr_array_index (codepages, n))->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
get_codepage_index (const char *id)
|
get_codepage_index (const char *id)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
if (strcmp (id, OTHER_8BIT) == 0)
|
if (strcmp (id, OTHER_8BIT) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (codepages == NULL)
|
if (codepages == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
for (i = 0; i < codepages->len; i++)
|
for (i = 0; i < codepages->len; i++)
|
||||||
if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0)
|
if (strcmp (id, ((codepage_desc *) g_ptr_array_index (codepages, i))->id) == 0)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/** Check if specified encoding can be used in mc.
|
/** Check if specified encoding can be used in mc.
|
||||||
* @param encoding name of encoding
|
* @param encoding name of encoding
|
||||||
* @returns TRUE if encoding has supported by mc, FALSE otherwise
|
* @returns TRUE if encoding has supported by mc, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
is_supported_encoding (const char *encoding)
|
is_supported_encoding (const char *encoding)
|
||||||
{
|
{
|
||||||
|
@ -221,28 +273,7 @@ is_supported_encoding (const char *encoding)
|
||||||
return result;
|
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 *
|
char *
|
||||||
init_translation_table (int cpsource, int cpdisplay)
|
init_translation_table (int cpsource, int cpdisplay)
|
||||||
|
@ -252,18 +283,21 @@ init_translation_table (int cpsource, int cpdisplay)
|
||||||
|
|
||||||
/* Fill inpit <-> display tables */
|
/* Fill inpit <-> display tables */
|
||||||
|
|
||||||
if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay) {
|
if (cpsource < 0 || cpdisplay < 0 || cpsource == cpdisplay)
|
||||||
for (i = 0; i <= 255; ++i) {
|
{
|
||||||
conv_displ[i] = i;
|
for (i = 0; i <= 255; ++i)
|
||||||
conv_input[i] = i;
|
{
|
||||||
cp_source = cp_display;
|
conv_displ[i] = i;
|
||||||
}
|
conv_input[i] = i;
|
||||||
return NULL;
|
cp_source = cp_display;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i <= 127; ++i) {
|
for (i = 0; i <= 127; ++i)
|
||||||
conv_displ[i] = i;
|
{
|
||||||
conv_input[i] = i;
|
conv_displ[i] = i;
|
||||||
|
conv_input[i] = i;
|
||||||
}
|
}
|
||||||
cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id;
|
cp_source = ((codepage_desc *) g_ptr_array_index (codepages, cpsource))->id;
|
||||||
cp_display = ((codepage_desc *) g_ptr_array_index (codepages, cpdisplay))->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);
|
cd = g_iconv_open (cp_display, cp_source);
|
||||||
if (cd == INVALID_CONV)
|
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)
|
for (i = 128; i <= 255; ++i)
|
||||||
conv_displ[i] = translate_character (cd, i);
|
conv_displ[i] = translate_character (cd, i);
|
||||||
|
|
||||||
g_iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
|
||||||
|
@ -283,12 +317,13 @@ init_translation_table (int cpsource, int cpdisplay)
|
||||||
|
|
||||||
cd = g_iconv_open (cp_source, cp_display);
|
cd = g_iconv_open (cp_source, cp_display);
|
||||||
if (cd == INVALID_CONV)
|
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) {
|
for (i = 128; i <= 255; ++i)
|
||||||
unsigned char ch;
|
{
|
||||||
ch = translate_character (cd, i);
|
unsigned char ch;
|
||||||
conv_input[i] = (ch == UNKNCHAR) ? i : ch;
|
ch = translate_character (cd, i);
|
||||||
|
conv_input[i] = (ch == UNKNCHAR) ? i : ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
@ -296,18 +331,23 @@ init_translation_table (int cpsource, int cpdisplay)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
convert_to_display (char *str)
|
convert_to_display (char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (*str) {
|
while (*str)
|
||||||
*str = conv_displ[(unsigned char) *str];
|
{
|
||||||
str++;
|
*str = conv_displ[(unsigned char) *str];
|
||||||
|
str++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
str_convert_to_display (char *str)
|
str_convert_to_display (char *str)
|
||||||
{
|
{
|
||||||
|
@ -315,6 +355,8 @@ str_convert_to_display (char *str)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
str_nconvert_to_display (char *str, int len)
|
str_nconvert_to_display (char *str, int len)
|
||||||
{
|
{
|
||||||
|
@ -322,37 +364,44 @@ str_nconvert_to_display (char *str, int len)
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
|
|
||||||
if (!str)
|
if (!str)
|
||||||
return g_string_new("");
|
return g_string_new ("");
|
||||||
|
|
||||||
if (cp_display == cp_source)
|
if (cp_display == cp_source)
|
||||||
return g_string_new(str);
|
return g_string_new (str);
|
||||||
|
|
||||||
conv = str_crt_conv_from (cp_source);
|
conv = str_crt_conv_from (cp_source);
|
||||||
|
|
||||||
buff = g_string_new("");
|
buff = g_string_new ("");
|
||||||
str_nconvert (conv, str, len, buff);
|
str_nconvert (conv, str, len, buff);
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
convert_from_input (char *str)
|
convert_from_input (char *str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (*str) {
|
while (*str)
|
||||||
*str = conv_input[(unsigned char) *str];
|
{
|
||||||
str++;
|
*str = conv_input[(unsigned char) *str];
|
||||||
|
str++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
str_convert_to_input (char *str)
|
str_convert_to_input (char *str)
|
||||||
{
|
{
|
||||||
return str_nconvert_to_input (str, -1);
|
return str_nconvert_to_input (str, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
GString *
|
GString *
|
||||||
str_nconvert_to_input (char *str, int len)
|
str_nconvert_to_input (char *str, int len)
|
||||||
{
|
{
|
||||||
|
@ -360,19 +409,21 @@ str_nconvert_to_input (char *str, int len)
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
|
|
||||||
if (!str)
|
if (!str)
|
||||||
return g_string_new("");
|
return g_string_new ("");
|
||||||
|
|
||||||
if (cp_display == cp_source)
|
if (cp_display == cp_source)
|
||||||
return g_string_new(str);
|
return g_string_new (str);
|
||||||
|
|
||||||
conv = str_crt_conv_to (cp_source);
|
conv = str_crt_conv_to (cp_source);
|
||||||
|
|
||||||
buff = g_string_new("");
|
buff = g_string_new ("");
|
||||||
str_nconvert (conv, str, len, buff);
|
str_nconvert (conv, str, len, buff);
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
unsigned char
|
unsigned char
|
||||||
convert_from_utf_to_current (const char *str)
|
convert_from_utf_to_current (const char *str)
|
||||||
{
|
{
|
||||||
|
@ -384,11 +435,13 @@ convert_from_utf_to_current (const char *str)
|
||||||
if (!str)
|
if (!str)
|
||||||
return '.';
|
return '.';
|
||||||
|
|
||||||
cp_to = get_codepage_id ( source_codepage );
|
cp_to = get_codepage_id (source_codepage);
|
||||||
conv = str_crt_conv_to ( cp_to );
|
conv = str_crt_conv_to (cp_to);
|
||||||
|
|
||||||
if (conv != INVALID_CONV) {
|
if (conv != INVALID_CONV)
|
||||||
switch (str_translate_char (conv, str, -1, (char *)buf_ch, sizeof(buf_ch))) {
|
{
|
||||||
|
switch (str_translate_char (conv, str, -1, (char *) buf_ch, sizeof (buf_ch)))
|
||||||
|
{
|
||||||
case ESTR_SUCCESS:
|
case ESTR_SUCCESS:
|
||||||
ch = buf_ch[0];
|
ch = buf_ch[0];
|
||||||
break;
|
break;
|
||||||
|
@ -404,6 +457,8 @@ convert_from_utf_to_current (const char *str)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
unsigned char
|
unsigned char
|
||||||
convert_from_utf_to_current_c (const int input_char, GIConv conv)
|
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;
|
int res = 0;
|
||||||
|
|
||||||
res = g_unichar_to_utf8 (input_char, (char *)str);
|
res = g_unichar_to_utf8 (input_char, (char *) str);
|
||||||
if ( res == 0 ) {
|
if (res == 0)
|
||||||
|
{
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
str[res] = '\0';
|
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:
|
case ESTR_SUCCESS:
|
||||||
ch = buf_ch[0];
|
ch = buf_ch[0];
|
||||||
break;
|
break;
|
||||||
|
@ -431,6 +488,8 @@ convert_from_utf_to_current_c (const int input_char, GIConv conv)
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
convert_from_8bit_to_utf_c (const char input_char, GIConv conv)
|
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[0] = (unsigned char) input_char;
|
||||||
str[1] = '\0';
|
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:
|
case ESTR_SUCCESS:
|
||||||
res = g_utf8_get_char_validated ((char *)buf_ch, -1);
|
res = g_utf8_get_char_validated ((char *) buf_ch, -1);
|
||||||
if ( res < 0 ) {
|
if (res < 0)
|
||||||
|
{
|
||||||
ch = buf_ch[0];
|
ch = buf_ch[0];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ch = res;
|
ch = res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -459,6 +522,8 @@ convert_from_8bit_to_utf_c (const char input_char, GIConv conv)
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
convert_from_8bit_to_utf_c2 (const char input_char)
|
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[0] = (unsigned char) input_char;
|
||||||
str[1] = '\0';
|
str[1] = '\0';
|
||||||
|
|
||||||
cp_from = get_codepage_id ( source_codepage );
|
cp_from = get_codepage_id (source_codepage);
|
||||||
conv = str_crt_conv_to (cp_from);
|
conv = str_crt_conv_to (cp_from);
|
||||||
|
|
||||||
if (conv != INVALID_CONV) {
|
if (conv != INVALID_CONV)
|
||||||
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:
|
case ESTR_SUCCESS:
|
||||||
res = g_utf8_get_char_validated ((char *) buf_ch, -1);
|
res = g_utf8_get_char_validated ((char *) buf_ch, -1);
|
||||||
if ( res < 0 ) {
|
if (res < 0)
|
||||||
|
{
|
||||||
ch = buf_ch[0];
|
ch = buf_ch[0];
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ch = res;
|
ch = res;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -495,4 +565,7 @@ convert_from_8bit_to_utf_c2 (const char input_char)
|
||||||
return ch;
|
return ch;
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif /* HAVE_CHARSET */
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#endif /* HAVE_CHARSET */
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
|
|
||||||
/** \file charsets.h
|
/** \file charsets.h
|
||||||
* \brief Header: Text conversion from one charset to another
|
* \brief Header: Text conversion from one charset to another
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CHARSETS_H
|
#ifndef MC__CHARSETS_H
|
||||||
#define MC_CHARSETS_H
|
#define MC__CHARSETS_H
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
|
|
||||||
#define UNKNCHAR '\001'
|
#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];
|
/*** enums ***************************************************************************************/
|
||||||
extern unsigned char conv_input[256];
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
#ifdef HAVE_CHARSET
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -21,10 +30,17 @@ typedef struct
|
||||||
char *name;
|
char *name;
|
||||||
} codepage_desc;
|
} 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_display;
|
||||||
extern const char *cp_source;
|
extern const char *cp_source;
|
||||||
extern GPtrArray *codepages;
|
extern GPtrArray *codepages;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
const char *get_codepage_id (const int n);
|
const char *get_codepage_id (const int n);
|
||||||
int get_codepage_index (const char *id);
|
int get_codepage_index (const char *id);
|
||||||
void load_codepages_list (void);
|
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_to_display (char *str);
|
||||||
void convert_from_input (char *str);
|
void convert_from_input (char *str);
|
||||||
void convert_string (unsigned char *str);
|
void convert_string (unsigned char *str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converter from utf to selected codepage
|
* Converter from utf to selected codepage
|
||||||
* param str, utf char
|
* param str, utf char
|
||||||
* return char in needle codepage (by global int source_codepage)
|
* return char in needle codepage (by global int source_codepage)
|
||||||
*/
|
*/
|
||||||
unsigned char convert_from_utf_to_current (const char *str);
|
unsigned char convert_from_utf_to_current (const char *str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converter from utf to selected codepage
|
* Converter from utf to selected codepage
|
||||||
* param input_char, gunichar
|
* param input_char, gunichar
|
||||||
* return char in needle codepage (by global int source_codepage)
|
* return char in needle codepage (by global int source_codepage)
|
||||||
*/
|
*/
|
||||||
unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv);
|
unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converter from selected codepage 8-bit
|
* Converter from selected codepage 8-bit
|
||||||
* param char input_char, GIConv converter
|
* param char input_char, GIConv converter
|
||||||
* return int utf char
|
* return int utf char
|
||||||
*/
|
*/
|
||||||
int convert_from_8bit_to_utf_c (const char input_char, GIConv conv);
|
int convert_from_8bit_to_utf_c (const char input_char, GIConv conv);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Converter from display codepage 8-bit to utf-8
|
* Converter from display codepage 8-bit to utf-8
|
||||||
* param char input_char, GIConv converter
|
* param char input_char, GIConv converter
|
||||||
* return int utf char
|
* return int utf char
|
||||||
*/
|
*/
|
||||||
int convert_from_8bit_to_utf_c2 (const char input_char);
|
int convert_from_8bit_to_utf_c2 (const char input_char);
|
||||||
|
|
||||||
GString *str_convert_to_input (char *str);
|
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_convert_to_display (char *str);
|
||||||
GString *str_nconvert_to_display (char *str, int len);
|
GString *str_nconvert_to_display (char *str, int len);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
/* Convert single characters */
|
/* Convert single characters */
|
||||||
static inline int
|
static inline int
|
||||||
convert_to_display_c (int c)
|
convert_to_display_c (int c)
|
||||||
{
|
{
|
||||||
if (c < 0 || c >= 256)
|
if (c < 0 || c >= 256)
|
||||||
return c;
|
return c;
|
||||||
return conv_displ[c];
|
return conv_displ[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,17 +100,10 @@ static inline int
|
||||||
convert_from_input_c (int c)
|
convert_from_input_c (int c)
|
||||||
{
|
{
|
||||||
if (c < 0 || c >= 256)
|
if (c < 0 || c >= 256)
|
||||||
return c;
|
return c;
|
||||||
return conv_input[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 /* HAVE_CHARSET */
|
||||||
|
|
||||||
#endif /* MC_CHARSETS_H */
|
#endif /* MC_CHARSETS_H */
|
||||||
|
|
35
src/chmod.c
35
src/chmod.c
|
@ -46,7 +46,9 @@
|
||||||
#include "layout.h" /* repaint_screen() */
|
#include "layout.h" /* repaint_screen() */
|
||||||
#include "chmod.h"
|
#include "chmod.h"
|
||||||
|
|
||||||
static int single_set;
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define PX 5
|
#define PX 5
|
||||||
#define PY 2
|
#define PY 2
|
||||||
|
@ -68,6 +70,12 @@ static int single_set;
|
||||||
#define B_SETMRK (B_USER+2)
|
#define B_SETMRK (B_USER+2)
|
||||||
#define B_CLRMRK (B_USER+3)
|
#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 mode_change, need_update;
|
||||||
static int c_file, end_chmod;
|
static int c_file, end_chmod;
|
||||||
|
|
||||||
|
@ -121,6 +129,9 @@ static struct
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chmod_toggle_select (Dlg_head * h, int Id)
|
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);
|
dlg_move (h, PY + PERMISSIONS - Id, PX + 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chmod_refresh (Dlg_head * h)
|
chmod_refresh (Dlg_head * h)
|
||||||
{
|
{
|
||||||
|
@ -158,6 +171,8 @@ chmod_refresh (Dlg_head * h)
|
||||||
tty_print_string (_("and T or INS to mark"));
|
tty_print_string (_("and T or INS to mark"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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 *
|
static Dlg_head *
|
||||||
init_chmod (void)
|
init_chmod (void)
|
||||||
{
|
{
|
||||||
|
@ -230,11 +247,13 @@ init_chmod (void)
|
||||||
add_widget (ch_dlg, check_perm[i].check);
|
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;
|
return ch_dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chmod_done (void)
|
chmod_done (void)
|
||||||
{
|
{
|
||||||
|
@ -243,6 +262,8 @@ chmod_done (void)
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
next_file (void)
|
next_file (void)
|
||||||
{
|
{
|
||||||
|
@ -252,6 +273,8 @@ next_file (void)
|
||||||
return current_panel->dir.list[c_file].fname;
|
return current_panel->dir.list[c_file].fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_chmod (struct stat *sf)
|
do_chmod (struct stat *sf)
|
||||||
{
|
{
|
||||||
|
@ -264,6 +287,8 @@ do_chmod (struct stat *sf)
|
||||||
do_file_mark (current_panel, c_file, 0);
|
do_file_mark (current_panel, c_file, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
apply_mask (struct stat *sf)
|
apply_mask (struct stat *sf)
|
||||||
{
|
{
|
||||||
|
@ -284,6 +309,10 @@ apply_mask (struct stat *sf)
|
||||||
while (current_panel->marked);
|
while (current_panel->marked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
chmod_cmd (void)
|
chmod_cmd (void)
|
||||||
{
|
{
|
||||||
|
@ -403,3 +432,5 @@ chmod_cmd (void)
|
||||||
|
|
||||||
chmod_done ();
|
chmod_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
16
src/chmod.h
16
src/chmod.h
|
@ -1,11 +1,21 @@
|
||||||
|
|
||||||
/** \file chmod.h
|
/** \file chmod.h
|
||||||
* \brief Header: chmod command
|
* \brief Header: chmod command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CHMOD_H
|
#ifndef MC__CHMOD_H
|
||||||
#define 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);
|
void chmod_cmd (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
34
src/chown.c
34
src/chown.c
|
@ -50,6 +50,10 @@
|
||||||
#include "wtools.h" /* init_box_colors() */
|
#include "wtools.h" /* init_box_colors() */
|
||||||
#include "setup.h" /* panels_options */
|
#include "setup.h" /* panels_options */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define UX 5
|
#define UX 5
|
||||||
#define UY 2
|
#define UY 2
|
||||||
|
|
||||||
|
@ -68,6 +72,14 @@
|
||||||
#define B_SETUSR (B_USER + 1)
|
#define B_SETUSR (B_USER + 1)
|
||||||
#define B_SETGRP (B_USER + 2)
|
#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 need_update, end_chown;
|
||||||
static int current_file;
|
static int current_file;
|
||||||
static int single_set;
|
static int single_set;
|
||||||
|
@ -86,7 +98,6 @@ static struct
|
||||||
{ B_SETALL, NORMAL_BUTTON, 0, 0, N_("Set &all") },
|
{ B_SETALL, NORMAL_BUTTON, 0, 0, N_("Set &all") },
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LABELS 5
|
|
||||||
static struct {
|
static struct {
|
||||||
int y, x;
|
int y, x;
|
||||||
WLabel *l;
|
WLabel *l;
|
||||||
|
@ -99,6 +110,9 @@ static struct {
|
||||||
};
|
};
|
||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chown_refresh (Dlg_head * h)
|
chown_refresh (Dlg_head * h)
|
||||||
{
|
{
|
||||||
|
@ -118,6 +132,8 @@ chown_refresh (Dlg_head * h)
|
||||||
tty_print_string (_("Permission"));
|
tty_print_string (_("Permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
next_file (void)
|
next_file (void)
|
||||||
{
|
{
|
||||||
|
@ -127,6 +143,8 @@ next_file (void)
|
||||||
return current_panel->dir.list[current_file].fname;
|
return current_panel->dir.list[current_file].fname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
chown_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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 *
|
static Dlg_head *
|
||||||
init_chown (void)
|
init_chown (void)
|
||||||
{
|
{
|
||||||
|
@ -204,6 +224,8 @@ init_chown (void)
|
||||||
return ch_dlg;
|
return ch_dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
chown_done (void)
|
chown_done (void)
|
||||||
{
|
{
|
||||||
|
@ -212,6 +234,8 @@ chown_done (void)
|
||||||
repaint_screen ();
|
repaint_screen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_chown (uid_t u, gid_t g)
|
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);
|
do_file_mark (current_panel, current_file, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
apply_chowns (uid_t u, gid_t g)
|
apply_chowns (uid_t u, gid_t g)
|
||||||
{
|
{
|
||||||
|
@ -239,7 +265,9 @@ apply_chowns (uid_t u, gid_t g)
|
||||||
while (current_panel->marked);
|
while (current_panel->marked);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define chown_label(n,txt) label_set_text (chown_label [n].l, txt)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
chown_cmd (void)
|
chown_cmd (void)
|
||||||
|
@ -354,3 +382,5 @@ chown_cmd (void)
|
||||||
|
|
||||||
chown_done ();
|
chown_done ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
16
src/chown.h
16
src/chown.h
|
@ -1,11 +1,21 @@
|
||||||
|
|
||||||
/** \file chown.h
|
/** \file chown.h
|
||||||
* \brief Header: chown command
|
* \brief Header: chown command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CHOWN_H
|
#ifndef MC__CHOWN_H
|
||||||
#define 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);
|
void chown_cmd (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,6 +37,21 @@
|
||||||
|
|
||||||
#include "clipboard.h"
|
#include "clipboard.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
copy_file_to_ext_clip (void)
|
copy_file_to_ext_clip (void)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +59,7 @@ copy_file_to_ext_clip (void)
|
||||||
int res = 0;
|
int res = 0;
|
||||||
const char *d = getenv ("DISPLAY");
|
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;
|
return FALSE;
|
||||||
|
|
||||||
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
|
tmp = concat_dir_and_file (home_dir, EDIT_CLIP_FILE);
|
||||||
|
@ -58,6 +73,8 @@ copy_file_to_ext_clip (void)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
paste_to_file_from_ext_clip (void)
|
paste_to_file_from_ext_clip (void)
|
||||||
{
|
{
|
||||||
|
@ -78,3 +95,5 @@ paste_to_file_from_ext_clip (void)
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
|
@ -1,12 +1,22 @@
|
||||||
|
|
||||||
/** \file clipboard.h
|
/** \file clipboard.h
|
||||||
* \brief Header: Util for external clipboard
|
* \brief Header: Util for external clipboard
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CLIPBOARD_H
|
#ifndef MC__CLIPBOARD_H
|
||||||
#define 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 copy_file_to_ext_clip (void);
|
||||||
gboolean paste_to_file_from_ext_clip (void);
|
gboolean paste_to_file_from_ext_clip (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
28
src/cmd.h
28
src/cmd.h
|
@ -1,15 +1,18 @@
|
||||||
|
|
||||||
/** \file cmd.h
|
/** \file cmd.h
|
||||||
* \brief Header: routines invoked by a function key
|
* \brief Header: routines invoked by a function key
|
||||||
*
|
*
|
||||||
* They normally operate on the current panel.
|
* They normally operate on the current panel.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CMD_H
|
#ifndef MC__CMD_H
|
||||||
#define MC_CMD_H
|
#define MC__CMD_H
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
LINK_HARDLINK = 0,
|
LINK_HARDLINK = 0,
|
||||||
|
@ -17,6 +20,21 @@ typedef enum
|
||||||
LINK_SYMLINK_RELATIVE
|
LINK_SYMLINK_RELATIVE
|
||||||
} link_type_t;
|
} 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
|
#ifdef ENABLE_VFS_FTP
|
||||||
void ftplink_cmd (void);
|
void ftplink_cmd (void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,8 +49,7 @@ void help_cmd (void);
|
||||||
void smart_dirsize_cmd (void);
|
void smart_dirsize_cmd (void);
|
||||||
void single_dirsize_cmd (void);
|
void single_dirsize_cmd (void);
|
||||||
void dirsizes_cmd (void);
|
void dirsizes_cmd (void);
|
||||||
int view_file_at_line (const char *filename, int plain_view, int internal,
|
int view_file_at_line (const char *filename, int plain_view, int internal, int start_line);
|
||||||
int start_line);
|
|
||||||
int view_file (const char *filename, int normal, int internal);
|
int view_file (const char *filename, int normal, int internal);
|
||||||
void view_cmd (void);
|
void view_cmd (void);
|
||||||
void view_file_cmd (void);
|
void view_file_cmd (void);
|
||||||
|
@ -83,4 +100,5 @@ void quick_view_cmd (void);
|
||||||
void toggle_listing_cmd (void);
|
void toggle_listing_cmd (void);
|
||||||
void encoding_cmd (void);
|
void encoding_cmd (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
16
src/cmddef.h
16
src/cmddef.h
|
@ -1,15 +1,16 @@
|
||||||
|
|
||||||
/** \file
|
/** \file
|
||||||
* \brief Header: editor constants
|
* \brief Header: editor constants
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_CMD_DEF_H
|
#ifndef MC__CMD_DEF_H
|
||||||
#define MC_CMD_DEF_H
|
#define MC__CMD_DEF_H
|
||||||
|
|
||||||
/** \todo In the distant future, keyboards will be invented with a
|
/** \todo In the distant future, keyboards will be invented with a
|
||||||
* separate key for each one of these commands *sigh*
|
* separate key for each one of these commands *sigh*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* special commands */
|
/* special commands */
|
||||||
#define CK_Insert_Char -1
|
#define CK_Insert_Char -1
|
||||||
#define CK_Ignore_Key 0
|
#define CK_Ignore_Key 0
|
||||||
|
@ -514,4 +515,13 @@
|
||||||
#define CK_Macro(i) ((i) | (1 << 17))
|
#define CK_Macro(i) ((i) | (1 << 17))
|
||||||
#define IS_MACRO_COMMAND(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 */
|
#endif /* MC_CMD_DEF_H */
|
||||||
|
|
483
src/command.c
483
src/command.c
|
@ -20,7 +20,7 @@
|
||||||
with all the magic of the command input line, we depend on some
|
with all the magic of the command input line, we depend on some
|
||||||
help from the program's callback.
|
help from the program's callback.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file command.c
|
/** \file command.c
|
||||||
* \brief Source: command line widget
|
* \brief Source: command line widget
|
||||||
|
@ -32,27 +32,38 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "lib/global.h" /* home_dir */
|
#include "lib/global.h" /* home_dir */
|
||||||
#include "lib/tty/tty.h"
|
#include "lib/tty/tty.h"
|
||||||
#include "lib/vfs/mc-vfs/vfs.h"
|
#include "lib/vfs/mc-vfs/vfs.h"
|
||||||
#include "lib/strescape.h"
|
#include "lib/strescape.h"
|
||||||
|
|
||||||
#include "widget.h" /* WInput */
|
#include "widget.h" /* WInput */
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "wtools.h" /* message () */
|
#include "wtools.h" /* message () */
|
||||||
#include "panel.h" /* view_tree enum. Also, needed by main.h */
|
#include "panel.h" /* view_tree enum. Also, needed by main.h */
|
||||||
#include "main.h" /* do_cd */
|
#include "main.h" /* do_cd */
|
||||||
#include "layout.h" /* for command_prompt variable */
|
#include "layout.h" /* for command_prompt variable */
|
||||||
#include "user.h" /* expand_format */
|
#include "user.h" /* expand_format */
|
||||||
#include "subshell.h" /* SUBSHELL_EXIT */
|
#include "subshell.h" /* SUBSHELL_EXIT */
|
||||||
#include "tree.h" /* for tree_chdir */
|
#include "tree.h" /* for tree_chdir */
|
||||||
#include "lib/skin.h" /* DEFAULT_COLOR */
|
#include "lib/skin.h" /* DEFAULT_COLOR */
|
||||||
#include "execute.h" /* shell_execute */
|
#include "execute.h" /* shell_execute */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
/* This holds the command line */
|
/* This holds the command line */
|
||||||
WInput *cmdline;
|
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
|
* Expand the argument to "cd" and change directory. First try tilde
|
||||||
* expansion, then variable substitution. If the CDPATH variable is set
|
* expansion, then variable substitution. If the CDPATH variable is set
|
||||||
* (e.g. CDPATH=".:~:/usr"), try all the paths contained there.
|
* (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
|
* Advanced users should be encouraged to use "\cd" instead of "cd" if
|
||||||
* they want the behavior they are used to in the shell.
|
* they want the behavior they are used to in the shell.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
examine_cd (const char *_path)
|
examine_cd (const char *_path)
|
||||||
{
|
{
|
||||||
|
@ -71,7 +83,7 @@ examine_cd (const char *_path)
|
||||||
const char *t;
|
const char *t;
|
||||||
|
|
||||||
/* Tilde expansion */
|
/* Tilde expansion */
|
||||||
path = strutils_shell_unescape(_path);
|
path = strutils_shell_unescape (_path);
|
||||||
path_tilde = tilde_expand (path);
|
path_tilde = tilde_expand (path);
|
||||||
|
|
||||||
/* Leave space for further expansion */
|
/* Leave space for further expansion */
|
||||||
|
@ -79,67 +91,78 @@ examine_cd (const char *_path)
|
||||||
q = g_malloc (qlen);
|
q = g_malloc (qlen);
|
||||||
|
|
||||||
/* Variable expansion */
|
/* Variable expansion */
|
||||||
for (p = path_tilde, r = q; *p && r < q + MC_MAXPATHLEN;) {
|
for (p = path_tilde, r = q; *p && r < q + MC_MAXPATHLEN;)
|
||||||
if (*p != '$' || (p[1] == '[' || p[1] == '('))
|
{
|
||||||
*(r++) = *(p++);
|
if (*p != '$' || (p[1] == '[' || p[1] == '('))
|
||||||
else {
|
*(r++) = *(p++);
|
||||||
p++;
|
else
|
||||||
if (*p == '{') {
|
{
|
||||||
p++;
|
p++;
|
||||||
s = strchr (p, '}');
|
if (*p == '{')
|
||||||
} else
|
{
|
||||||
s = NULL;
|
p++;
|
||||||
if (s == NULL)
|
s = strchr (p, '}');
|
||||||
s = strchr (p, PATH_SEP);
|
}
|
||||||
if (s == NULL)
|
else
|
||||||
s = strchr (p, 0);
|
s = NULL;
|
||||||
c = *s;
|
if (s == NULL)
|
||||||
*s = 0;
|
s = strchr (p, PATH_SEP);
|
||||||
t = getenv (p);
|
if (s == NULL)
|
||||||
*s = c;
|
s = strchr (p, 0);
|
||||||
if (t == NULL) {
|
c = *s;
|
||||||
*(r++) = '$';
|
*s = 0;
|
||||||
if (*(p - 1) != '$')
|
t = getenv (p);
|
||||||
*(r++) = '{';
|
*s = c;
|
||||||
} else {
|
if (t == NULL)
|
||||||
if (r + strlen (t) < q + MC_MAXPATHLEN) {
|
{
|
||||||
strcpy (r, t);
|
*(r++) = '$';
|
||||||
r = strchr (r, 0);
|
if (*(p - 1) != '$')
|
||||||
}
|
*(r++) = '{';
|
||||||
if (*s == '}')
|
}
|
||||||
p = s + 1;
|
else
|
||||||
else
|
{
|
||||||
p = s;
|
if (r + strlen (t) < q + MC_MAXPATHLEN)
|
||||||
}
|
{
|
||||||
}
|
strcpy (r, t);
|
||||||
|
r = strchr (r, 0);
|
||||||
|
}
|
||||||
|
if (*s == '}')
|
||||||
|
p = s + 1;
|
||||||
|
else
|
||||||
|
p = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*r = 0;
|
*r = 0;
|
||||||
|
|
||||||
result = do_cd (q, cd_parse_command);
|
result = do_cd (q, cd_parse_command);
|
||||||
|
|
||||||
/* CDPATH handling */
|
/* CDPATH handling */
|
||||||
if (*q != PATH_SEP && !result) {
|
if (*q != PATH_SEP && !result)
|
||||||
char * const cdpath = g_strdup (getenv ("CDPATH"));
|
{
|
||||||
p = cdpath;
|
char *const cdpath = g_strdup (getenv ("CDPATH"));
|
||||||
if (p == NULL)
|
p = cdpath;
|
||||||
c = 0;
|
if (p == NULL)
|
||||||
else
|
c = 0;
|
||||||
c = ':';
|
else
|
||||||
while (!result && c == ':') {
|
c = ':';
|
||||||
s = strchr (p, ':');
|
while (!result && c == ':')
|
||||||
if (s == NULL)
|
{
|
||||||
s = strchr (p, 0);
|
s = strchr (p, ':');
|
||||||
c = *s;
|
if (s == NULL)
|
||||||
*s = 0;
|
s = strchr (p, 0);
|
||||||
if (*p) {
|
c = *s;
|
||||||
r = concat_dir_and_file (p, q);
|
*s = 0;
|
||||||
result = do_cd (r, cd_parse_command);
|
if (*p)
|
||||||
g_free (r);
|
{
|
||||||
}
|
r = concat_dir_and_file (p, q);
|
||||||
*s = c;
|
result = do_cd (r, cd_parse_command);
|
||||||
p = s + 1;
|
g_free (r);
|
||||||
}
|
}
|
||||||
g_free (cdpath);
|
*s = c;
|
||||||
|
p = s + 1;
|
||||||
|
}
|
||||||
|
g_free (cdpath);
|
||||||
}
|
}
|
||||||
g_free (q);
|
g_free (q);
|
||||||
g_free (path_tilde);
|
g_free (path_tilde);
|
||||||
|
@ -147,11 +170,137 @@ examine_cd (const char *_path)
|
||||||
return result;
|
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;
|
int len;
|
||||||
const char * cmd;
|
const char *cmd;
|
||||||
|
|
||||||
/* Any final whitespace should be removed here
|
/* Any final whitespace should be removed here
|
||||||
(to see why, try "cd fred "). */
|
(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.
|
/* FIXME: what about interpreting quoted strings like the shell.
|
||||||
so one could type "cd <tab> M-a <enter>" and it would work. */
|
so one could type "cd <tab> M-a <enter>" and it would work. */
|
||||||
len = strlen (orig_cmd) - 1;
|
len = strlen (orig_cmd) - 1;
|
||||||
while (len >= 0 &&
|
while (len >= 0 && (orig_cmd[len] == ' ' || orig_cmd[len] == '\t' || orig_cmd[len] == '\n'))
|
||||||
(orig_cmd [len] == ' ' || orig_cmd [len] == '\t' || orig_cmd [len] == '\n')){
|
{
|
||||||
orig_cmd [len] = 0;
|
orig_cmd[len] = 0;
|
||||||
len --;
|
len--;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = orig_cmd;
|
cmd = orig_cmd;
|
||||||
if (cmd [2] == 0)
|
if (cmd[2] == 0)
|
||||||
cmd = "cd ";
|
cmd = "cd ";
|
||||||
|
|
||||||
if (get_current_type () == view_tree){
|
if (get_current_type () == view_tree)
|
||||||
if (cmd [0] == 0){
|
{
|
||||||
sync_tree (home_dir);
|
if (cmd[0] == 0)
|
||||||
} else if (strcmp (cmd+3, "..") == 0){
|
{
|
||||||
char *dir = current_panel->cwd;
|
sync_tree (home_dir);
|
||||||
len = strlen (dir);
|
}
|
||||||
while (len && dir [--len] != PATH_SEP);
|
else if (strcmp (cmd + 3, "..") == 0)
|
||||||
dir [len] = 0;
|
{
|
||||||
if (len)
|
char *dir = current_panel->cwd;
|
||||||
sync_tree (dir);
|
len = strlen (dir);
|
||||||
else
|
while (len && dir[--len] != PATH_SEP);
|
||||||
sync_tree (PATH_SEP_STR);
|
dir[len] = 0;
|
||||||
} else if (cmd [3] == PATH_SEP){
|
if (len)
|
||||||
sync_tree (cmd+3);
|
sync_tree (dir);
|
||||||
} else {
|
else
|
||||||
char *old = current_panel->cwd;
|
sync_tree (PATH_SEP_STR);
|
||||||
char *new;
|
}
|
||||||
new = concat_dir_and_file (old, cmd+3);
|
else if (cmd[3] == PATH_SEP)
|
||||||
sync_tree (new);
|
{
|
||||||
g_free (new);
|
sync_tree (cmd + 3);
|
||||||
}
|
}
|
||||||
} else
|
else
|
||||||
if (!examine_cd (&cmd [3])) {
|
{
|
||||||
char *d = strip_password (g_strdup (&cmd [3]), 1);
|
char *old = current_panel->cwd;
|
||||||
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"),
|
char *new;
|
||||||
d, unix_error_string (errno));
|
new = concat_dir_and_file (old, cmd + 3);
|
||||||
g_free (d);
|
sync_tree (new);
|
||||||
return;
|
g_free (new);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
else if (!examine_cd (&cmd[3]))
|
||||||
}
|
{
|
||||||
|
char *d = strip_password (g_strdup (&cmd[3]), 1);
|
||||||
static cb_ret_t
|
message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, unix_error_string (errno));
|
||||||
command_callback (Widget *w, widget_msg_t msg, int parm)
|
g_free (d);
|
||||||
{
|
return;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
WInput *
|
WInput *
|
||||||
command_new (int y, int x, int cols)
|
command_new (int y, int x, int cols)
|
||||||
{
|
{
|
||||||
WInput *cmd;
|
WInput *cmd;
|
||||||
const input_colors_t command_colors =
|
const input_colors_t command_colors = {
|
||||||
{
|
|
||||||
DEFAULT_COLOR,
|
DEFAULT_COLOR,
|
||||||
COMMAND_MARK_COLOR,
|
COMMAND_MARK_COLOR,
|
||||||
DEFAULT_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",
|
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 */
|
/* Add our hooks */
|
||||||
cmd->widget.callback = command_callback;
|
cmd->widget.callback = command_callback;
|
||||||
|
@ -325,10 +381,12 @@ command_new (int y, int x, int cols)
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Insert quoted text in input line. The function is meant for the
|
* Insert quoted text in input line. The function is meant for the
|
||||||
* command line, so the percent sign is quoted as well.
|
* command line, so the percent sign is quoted as well.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
command_insert (WInput * in, const char *text, int insert_extra_space)
|
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);
|
g_free (quoted_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
|
@ -1,17 +1,27 @@
|
||||||
|
|
||||||
/** \file command.h
|
/** \file command.h
|
||||||
* \brief Header: command line widget
|
* \brief Header: command line widget
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_COMMAND_H
|
#ifndef MC__COMMAND_H
|
||||||
#define MC_COMMAND_H
|
#define MC__COMMAND_H
|
||||||
|
|
||||||
#include "widget.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;
|
extern WInput *cmdline;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
WInput *command_new (int y, int x, int len);
|
WInput *command_new (int y, int x, int len);
|
||||||
void do_cd_command (char *cmd);
|
void do_cd_command (char *cmd);
|
||||||
void command_insert (WInput * in, const char *text, int insert_extra_space);
|
void command_insert (WInput * in, const char *text, int insert_extra_space);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
|
131
src/complete.c
131
src/complete.c
|
@ -49,11 +49,48 @@
|
||||||
#include "wtools.h"
|
#include "wtools.h"
|
||||||
#include "main.h" /* show_all_if_ambiguous */
|
#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 */
|
/* #define DO_COMPLETION_DEBUG */
|
||||||
#ifdef 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
|
* Useful to print/debug completion flags
|
||||||
*/
|
*/
|
||||||
static const char *
|
static const char *
|
||||||
|
@ -71,12 +108,10 @@ show_c_flags (INPUT_COMPLETE_FLAGS flags)
|
||||||
|
|
||||||
return s_cf;
|
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 */
|
#endif /* DO_CMPLETION_DEBUG */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags)
|
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 */
|
you have to change the code */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags)
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Linux declares environ in <unistd.h>, so don't repeat it here. */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
#if (!(defined(__linux__) && defined (__USE_GNU)) && !defined(__CYGWIN__))
|
/** We assume text [0] == '$' and want to have a look at text [1], if it is
|
||||||
extern char **environ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* 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 */
|
equal to '{', so that we should append '}' at the end */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags)
|
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
|
static void
|
||||||
fetch_hosts (const char *filename)
|
fetch_hosts (const char *filename)
|
||||||
{
|
{
|
||||||
|
@ -423,6 +453,8 @@ fetch_hosts (const char *filename)
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
hostname_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS flags)
|
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
|
* 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
|
* where a command word can be found. It looks around $PATH, looking for
|
||||||
* commands that match. It also scans aliases, function names, and the
|
* commands that match. It also scans aliases, function names, and the
|
||||||
* table of shell built-ins.
|
* table of shell built-ins.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS flags)
|
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;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
match_compare (const void *a, const void *b)
|
match_compare (const void *a, const void *b)
|
||||||
{
|
{
|
||||||
return strcmp (*(char **) a, *(char **) 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
|
in the 1st entry. Then a NULL terminated list of different possible
|
||||||
completions follows.
|
completions follows.
|
||||||
You have to supply your own CompletionFunction with the word you
|
You have to supply your own CompletionFunction with the word you
|
||||||
want to complete as the first argument and an count of previous matches
|
want to complete as the first argument and an count of previous matches
|
||||||
as the second.
|
as the second.
|
||||||
In case no matches were found we return NULL. */
|
In case no matches were found we return NULL. */
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
completion_matches (const char *text, CompletionFunction entry_function, INPUT_COMPLETE_FLAGS flags)
|
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;
|
return match_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if directory completion is needed */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/** Check if directory completion is needed */
|
||||||
static int
|
static int
|
||||||
check_is_cd (const char *text, int start, INPUT_COMPLETE_FLAGS flags)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns an array of matches, or NULL if none. */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/** Returns an array of matches, or NULL if none. */
|
||||||
static char **
|
static char **
|
||||||
try_complete (char *text, int *start, int *end, INPUT_COMPLETE_FLAGS flags)
|
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;
|
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
|
static int
|
||||||
insert_text (WInput * in, char *text, ssize_t size)
|
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;
|
return size != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static cb_ret_t
|
static cb_ret_t
|
||||||
query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
|
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
|
static int
|
||||||
complete_engine (WInput * in, int what_to_do)
|
complete_engine (WInput * in, int what_to_do)
|
||||||
{
|
{
|
||||||
|
@ -1264,6 +1290,25 @@ complete_engine (WInput * in, int what_to_do)
|
||||||
return 0;
|
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
|
void
|
||||||
complete (WInput * in)
|
complete (WInput * in)
|
||||||
{
|
{
|
||||||
|
@ -1284,3 +1329,5 @@ complete (WInput * in)
|
||||||
|
|
||||||
while (complete_engine (in, engine_flags));
|
while (complete_engine (in, engine_flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
# include <sys/consio.h>
|
#include <sys/consio.h>
|
||||||
# include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -42,17 +42,44 @@
|
||||||
|
|
||||||
#include "consaver/cons.saver.h"
|
#include "consaver/cons.saver.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
signed char console_flag = 0;
|
signed char console_flag = 0;
|
||||||
|
|
||||||
#ifdef __linux__
|
#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
|
/* The cons saver can't have a pid of 1, used to prevent bunches of
|
||||||
* #ifdef linux */
|
* #ifdef linux */
|
||||||
|
|
||||||
int cons_saver_pid = 1;
|
|
||||||
static int pipefd1[2] = { -1, -1 };
|
static int pipefd1[2] = { -1, -1 };
|
||||||
static int pipefd2[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
|
static void
|
||||||
show_console_contents_linux (int starty, unsigned char begin_line, unsigned char end_line)
|
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);
|
ret = read (pipefd2[0], &message, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_console_linux (unsigned char action)
|
handle_console_linux (unsigned char action)
|
||||||
{
|
{
|
||||||
|
@ -219,16 +248,12 @@ handle_console_linux (unsigned char action)
|
||||||
|
|
||||||
#elif defined(__FreeBSD__)
|
#elif defined(__FreeBSD__)
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* FreeBSD support copyright (C) 2003 Alexander Serkov <serkov@ukrpost.net>.
|
* FreeBSD support copyright (C) 2003 Alexander Serkov <serkov@ukrpost.net>.
|
||||||
* Support for screenmaps by Max Khon <fjoe@FreeBSD.org>
|
* 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
|
static void
|
||||||
console_init (void)
|
console_init (void)
|
||||||
{
|
{
|
||||||
|
@ -247,6 +272,8 @@ console_init (void)
|
||||||
console_flag = 1;
|
console_flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_attr (unsigned attr)
|
set_attr (unsigned attr)
|
||||||
{
|
{
|
||||||
|
@ -264,12 +291,7 @@ set_attr (unsigned attr)
|
||||||
color_map[tc & 7], color_map[bc & 7]);
|
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
|
static void
|
||||||
console_restore (void)
|
console_restore (void)
|
||||||
|
@ -295,6 +317,8 @@ console_restore (void)
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
console_shutdown (void)
|
console_shutdown (void)
|
||||||
{
|
{
|
||||||
|
@ -306,6 +330,8 @@ console_shutdown (void)
|
||||||
console_flag = 0;
|
console_flag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
console_save (void)
|
console_save (void)
|
||||||
{
|
{
|
||||||
|
@ -351,11 +377,13 @@ console_save (void)
|
||||||
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
|
for (i = 0; i < screen_shot.xsize * screen_shot.ysize; i++)
|
||||||
{
|
{
|
||||||
screen_shot.buf[i] =
|
screen_shot.buf[i] =
|
||||||
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.
|
(screen_shot.buf[i] & 0xff00) | (unsigned char) revmap.scrmap[screen_shot.
|
||||||
scrmap[screen_shot.buf[i] & 0xff];
|
buf[i] & 0xff];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned char end_line)
|
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
|
static void
|
||||||
handle_console_freebsd (unsigned char action)
|
handle_console_freebsd (unsigned char action)
|
||||||
{
|
{
|
||||||
|
@ -400,6 +430,10 @@ handle_console_freebsd (unsigned char action)
|
||||||
}
|
}
|
||||||
#endif /* __FreeBSD__ */
|
#endif /* __FreeBSD__ */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_console (unsigned char action)
|
handle_console (unsigned char action)
|
||||||
{
|
{
|
||||||
|
@ -433,3 +469,5 @@ handle_console (unsigned char action)
|
||||||
handle_console_freebsd (action);
|
handle_console_freebsd (action);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
Loading…
Reference in New Issue