Code indentation in lib directory
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Этот коммит содержится в:
родитель
4a1a758c25
Коммит
feb733663f
@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_fhl_struct {
|
typedef struct mc_fhl_struct
|
||||||
|
{
|
||||||
mc_config_t *config;
|
mc_config_t *config;
|
||||||
GPtrArray *filters;
|
GPtrArray *filters;
|
||||||
} mc_fhl_t;
|
} mc_fhl_t;
|
||||||
@ -29,4 +30,5 @@ gboolean mc_fhl_read_ini_file (mc_fhl_t *, const gchar *);
|
|||||||
gboolean mc_fhl_parse_ini_file (mc_fhl_t *);
|
gboolean mc_fhl_parse_ini_file (mc_fhl_t *);
|
||||||
void mc_fhl_clear (mc_fhl_t *);
|
void mc_fhl_clear (mc_fhl_t *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -82,12 +82,14 @@ mc_fhl_new (gboolean need_auto_fill)
|
|||||||
if (!need_auto_fill)
|
if (!need_auto_fill)
|
||||||
return fhl;
|
return fhl;
|
||||||
|
|
||||||
if (!mc_fhl_init_from_standard_files (fhl)) {
|
if (!mc_fhl_init_from_standard_files (fhl))
|
||||||
|
{
|
||||||
g_free (fhl);
|
g_free (fhl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mc_fhl_parse_ini_file (fhl)) {
|
if (!mc_fhl_parse_ini_file (fhl))
|
||||||
|
{
|
||||||
mc_fhl_free (&fhl);
|
mc_fhl_free (&fhl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*inline functions*/
|
/*inline functions */
|
||||||
inline static gboolean
|
inline static gboolean
|
||||||
mc_fhl_is_file (file_entry * fe)
|
mc_fhl_is_file (file_entry * fe)
|
||||||
{
|
{
|
||||||
@ -141,8 +141,8 @@ inline static gboolean
|
|||||||
mc_fhl_is_special (file_entry * fe)
|
mc_fhl_is_special (file_entry * fe)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
(mc_fhl_is_special_socket (fe) || mc_fhl_is_special_fifo (fe) || mc_fhl_is_special_door (fe)
|
(mc_fhl_is_special_socket (fe) || mc_fhl_is_special_fifo (fe)
|
||||||
);
|
|| mc_fhl_is_special_door (fe));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -154,7 +154,8 @@ mc_fhl_get_color_filetype (mc_fhl_filter_t * mc_filter, mc_fhl_t * fhl, file_ent
|
|||||||
gboolean my_color = FALSE;
|
gboolean my_color = FALSE;
|
||||||
(void) fhl;
|
(void) fhl;
|
||||||
|
|
||||||
switch (mc_filter->file_type) {
|
switch (mc_filter->file_type)
|
||||||
|
{
|
||||||
case MC_FLHGH_FTYPE_T_FILE:
|
case MC_FLHGH_FTYPE_T_FILE:
|
||||||
if (mc_fhl_is_file (fe))
|
if (mc_fhl_is_file (fe))
|
||||||
my_color = TRUE;
|
my_color = TRUE;
|
||||||
@ -254,9 +255,11 @@ mc_fhl_get_color (mc_fhl_t * fhl, file_entry * fe)
|
|||||||
if (fhl == NULL)
|
if (fhl == NULL)
|
||||||
return NORMAL_COLOR;
|
return NORMAL_COLOR;
|
||||||
|
|
||||||
for (i = 0; i < fhl->filters->len; i++) {
|
for (i = 0; i < fhl->filters->len; i++)
|
||||||
|
{
|
||||||
mc_filter = (mc_fhl_filter_t *) g_ptr_array_index (fhl->filters, i);
|
mc_filter = (mc_fhl_filter_t *) g_ptr_array_index (fhl->filters, i);
|
||||||
switch (mc_filter->type) {
|
switch (mc_filter->type)
|
||||||
|
{
|
||||||
case MC_FLHGH_T_FTYPE:
|
case MC_FLHGH_T_FTYPE:
|
||||||
ret = mc_fhl_get_color_filetype (mc_filter, fhl, fe);
|
ret = mc_fhl_get_color_filetype (mc_filter, fhl, fe);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
|
@ -77,12 +77,14 @@ mc_fhl_parse_get_file_type_id (mc_fhl_t * fhl, const gchar * group_name)
|
|||||||
int i;
|
int i;
|
||||||
gchar *param_type = mc_config_get_string (fhl->config, group_name, "type", "");
|
gchar *param_type = mc_config_get_string (fhl->config, group_name, "type", "");
|
||||||
|
|
||||||
if (*param_type == '\0') {
|
if (*param_type == '\0')
|
||||||
|
{
|
||||||
g_free (param_type);
|
g_free (param_type);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; types[i] != NULL; i++) {
|
for (i = 0; types[i] != NULL; i++)
|
||||||
|
{
|
||||||
if (strcmp (types[i], param_type) == 0)
|
if (strcmp (types[i], param_type) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -107,7 +109,8 @@ mc_fhl_parse_get_regexp (mc_fhl_t * fhl, const gchar * group_name)
|
|||||||
mc_fhl_filter_t *mc_filter;
|
mc_fhl_filter_t *mc_filter;
|
||||||
gchar *regexp = mc_config_get_string (fhl->config, group_name, "regexp", "");
|
gchar *regexp = mc_config_get_string (fhl->config, group_name, "regexp", "");
|
||||||
|
|
||||||
if (*regexp == '\0') {
|
if (*regexp == '\0')
|
||||||
|
{
|
||||||
g_free (regexp);
|
g_free (regexp);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -201,7 +204,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
|||||||
|
|
||||||
/* ${datadir}/mc/filehighlight.ini */
|
/* ${datadir}/mc/filehighlight.ini */
|
||||||
name = concat_dir_and_file (mc_home_alt, MC_FHL_INI_FILE);
|
name = concat_dir_and_file (mc_home_alt, MC_FHL_INI_FILE);
|
||||||
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
|
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name)))
|
||||||
|
{
|
||||||
g_free (name);
|
g_free (name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -209,7 +213,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
|||||||
|
|
||||||
/* ${sysconfdir}/mc/filehighlight.ini */
|
/* ${sysconfdir}/mc/filehighlight.ini */
|
||||||
name = concat_dir_and_file (mc_home, MC_FHL_INI_FILE);
|
name = concat_dir_and_file (mc_home, MC_FHL_INI_FILE);
|
||||||
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
|
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name)))
|
||||||
|
{
|
||||||
g_free (name);
|
g_free (name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -218,7 +223,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
|||||||
/* ~/.mc/filehighlight.ini */
|
/* ~/.mc/filehighlight.ini */
|
||||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FHL_INI_FILE, NULL);
|
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_FHL_INI_FILE, NULL);
|
||||||
|
|
||||||
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name))) {
|
if (exist_file (name) && (!mc_fhl_read_ini_file (fhl, name)))
|
||||||
|
{
|
||||||
g_free (name);
|
g_free (name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -242,17 +248,21 @@ mc_fhl_parse_ini_file (mc_fhl_t * fhl)
|
|||||||
if (group_names == NULL)
|
if (group_names == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while (*group_names) {
|
while (*group_names)
|
||||||
|
{
|
||||||
|
|
||||||
if (mc_config_has_param (fhl->config, *group_names, "type")) {
|
if (mc_config_has_param (fhl->config, *group_names, "type"))
|
||||||
|
{
|
||||||
/* parse filetype filter */
|
/* parse filetype filter */
|
||||||
mc_fhl_parse_get_file_type_id (fhl, *group_names);
|
mc_fhl_parse_get_file_type_id (fhl, *group_names);
|
||||||
}
|
}
|
||||||
if (mc_config_has_param (fhl->config, *group_names, "regexp")) {
|
if (mc_config_has_param (fhl->config, *group_names, "regexp"))
|
||||||
|
{
|
||||||
/* parse regexp filter */
|
/* parse regexp filter */
|
||||||
mc_fhl_parse_get_regexp (fhl, *group_names);
|
mc_fhl_parse_get_regexp (fhl, *group_names);
|
||||||
}
|
}
|
||||||
if (mc_config_has_param (fhl->config, *group_names, "extensions")) {
|
if (mc_config_has_param (fhl->config, *group_names, "extensions"))
|
||||||
|
{
|
||||||
/* parse extensions filter */
|
/* parse extensions filter */
|
||||||
mc_fhl_parse_get_extensions (fhl, *group_names);
|
mc_fhl_parse_get_extensions (fhl, *group_names);
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,15 @@
|
|||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MC_FLHGH_T_FTYPE,
|
MC_FLHGH_T_FTYPE,
|
||||||
MC_FLHGH_T_EXT,
|
MC_FLHGH_T_EXT,
|
||||||
MC_FLHGH_T_FREGEXP
|
MC_FLHGH_T_FREGEXP
|
||||||
} mc_flhgh_filter_type;
|
} mc_flhgh_filter_type;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MC_FLHGH_FTYPE_T_FILE,
|
MC_FLHGH_FTYPE_T_FILE,
|
||||||
MC_FLHGH_FTYPE_T_FILE_EXE,
|
MC_FLHGH_FTYPE_T_FILE_EXE,
|
||||||
MC_FLHGH_FTYPE_T_DIR,
|
MC_FLHGH_FTYPE_T_DIR,
|
||||||
@ -31,7 +33,8 @@ typedef enum {
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_fhl_filter_struct {
|
typedef struct mc_fhl_filter_struct
|
||||||
|
{
|
||||||
|
|
||||||
int color_pair_index;
|
int color_pair_index;
|
||||||
gchar *fgcolor;
|
gchar *fgcolor;
|
||||||
@ -51,5 +54,5 @@ void mc_fhl_array_free (mc_fhl_t *);
|
|||||||
|
|
||||||
gboolean mc_fhl_init_from_standard_files (mc_fhl_t *);
|
gboolean mc_fhl_init_from_standard_files (mc_fhl_t *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
106
lib/fileloc.h
106
lib/fileloc.h
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file fileloc.h
|
/** \file fileloc.h
|
||||||
* \brief Header: config files list
|
* \brief Header: config files list
|
||||||
*
|
*
|
||||||
@ -14,65 +13,76 @@
|
|||||||
#ifndef MC_FILELOC_H
|
#ifndef MC_FILELOC_H
|
||||||
#define MC_FILELOC_H
|
#define MC_FILELOC_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#ifndef MC_USERCONF_DIR
|
#ifndef MC_USERCONF_DIR
|
||||||
#define MC_USERCONF_DIR ".mc"
|
#define MC_USERCONF_DIR ".mc"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define TAGS_NAME "TAGS"
|
||||||
|
|
||||||
#define TAGS_NAME "TAGS"
|
#define MC_GLOBAL_CONFIG_FILE "mc.lib"
|
||||||
|
#define MC_GLOBAL_MENU "mc.menu"
|
||||||
|
#define MC_LOCAL_MENU ".mc.menu"
|
||||||
|
#define MC_HINT "hints" PATH_SEP_STR "mc.hint"
|
||||||
|
#define MC_HELP "help" PATH_SEP_STR "mc.hlp"
|
||||||
|
#define GLOBAL_KEYMAP_FILE "mc.keymap"
|
||||||
|
#define CHARSETS_LIST "mc.charsets"
|
||||||
|
#define MC_LIB_EXT "mc.ext"
|
||||||
|
|
||||||
#define MC_GLOBAL_CONFIG_FILE "mc.lib"
|
#define FISH_PREFIX "fish"
|
||||||
#define MC_GLOBAL_MENU "mc.menu"
|
|
||||||
#define MC_LOCAL_MENU ".mc.menu"
|
|
||||||
#define MC_HINT "hints" PATH_SEP_STR "mc.hint"
|
|
||||||
#define MC_HELP "help" PATH_SEP_STR "mc.hlp"
|
|
||||||
#define GLOBAL_KEYMAP_FILE "mc.keymap"
|
|
||||||
#define CHARSETS_LIST "mc.charsets"
|
|
||||||
#define MC_LIB_EXT "mc.ext"
|
|
||||||
|
|
||||||
#define FISH_PREFIX "fish"
|
#define FISH_LS_FILE "ls"
|
||||||
|
#define FISH_EXISTS_FILE "fexists"
|
||||||
|
#define FISH_MKDIR_FILE "mkdir"
|
||||||
|
#define FISH_UNLINK_FILE "unlink"
|
||||||
|
#define FISH_CHOWN_FILE "chown"
|
||||||
|
#define FISH_CHMOD_FILE "chmod"
|
||||||
|
#define FISH_RMDIR_FILE "rmdir"
|
||||||
|
#define FISH_LN_FILE "ln"
|
||||||
|
#define FISH_MV_FILE "mv"
|
||||||
|
#define FISH_HARDLINK_FILE "hardlink"
|
||||||
|
#define FISH_GET_FILE "get"
|
||||||
|
#define FISH_SEND_FILE "send"
|
||||||
|
#define FISH_APPEND_FILE "append"
|
||||||
|
#define FISH_INFO_FILE "info"
|
||||||
|
|
||||||
#define FISH_LS_FILE "ls"
|
#define MC_EXTFS_DIR "extfs.d"
|
||||||
#define FISH_EXISTS_FILE "fexists"
|
|
||||||
#define FISH_MKDIR_FILE "mkdir"
|
|
||||||
#define FISH_UNLINK_FILE "unlink"
|
|
||||||
#define FISH_CHOWN_FILE "chown"
|
|
||||||
#define FISH_CHMOD_FILE "chmod"
|
|
||||||
#define FISH_RMDIR_FILE "rmdir"
|
|
||||||
#define FISH_LN_FILE "ln"
|
|
||||||
#define FISH_MV_FILE "mv"
|
|
||||||
#define FISH_HARDLINK_FILE "hardlink"
|
|
||||||
#define FISH_GET_FILE "get"
|
|
||||||
#define FISH_SEND_FILE "send"
|
|
||||||
#define FISH_APPEND_FILE "append"
|
|
||||||
#define FISH_INFO_FILE "info"
|
|
||||||
|
|
||||||
#define MC_EXTFS_DIR "extfs.d"
|
#define MC_BASHRC_FILE "bashrc"
|
||||||
|
#define MC_CONFIG_FILE "ini"
|
||||||
#define MC_BASHRC_FILE "bashrc"
|
#define MC_FILEBIND_FILE "bindings"
|
||||||
#define MC_CONFIG_FILE "ini"
|
#define MC_FILEPOS_FILE "filepos"
|
||||||
#define MC_FILEBIND_FILE "bindings"
|
#define MC_HISTORY_FILE "history"
|
||||||
#define MC_FILEPOS_FILE "filepos"
|
#define MC_HOTLIST_FILE "hotlist"
|
||||||
#define MC_HISTORY_FILE "history"
|
#define MC_USERMENU_FILE "menu"
|
||||||
#define MC_HOTLIST_FILE "hotlist"
|
#define MC_TREESTORE_FILE "Tree"
|
||||||
#define MC_USERMENU_FILE "menu"
|
#define MC_PANELS_FILE "panels.ini"
|
||||||
#define MC_TREESTORE_FILE "Tree"
|
#define MC_FHL_INI_FILE "filehighlight.ini"
|
||||||
#define MC_PANELS_FILE "panels.ini"
|
#define MC_SKINS_SUBDIR "skins"
|
||||||
#define MC_FHL_INI_FILE "filehighlight.ini"
|
|
||||||
#define MC_SKINS_SUBDIR "skins"
|
|
||||||
|
|
||||||
/* editor home directory */
|
/* editor home directory */
|
||||||
#define EDIT_DIR MC_USERCONF_DIR PATH_SEP_STR "cedit"
|
#define EDIT_DIR MC_USERCONF_DIR PATH_SEP_STR "cedit"
|
||||||
|
|
||||||
/* file names */
|
/* file names */
|
||||||
#define EDIT_SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
|
#define EDIT_SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
|
||||||
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
|
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
|
||||||
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
|
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
|
||||||
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
|
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
|
||||||
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
|
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
|
||||||
|
|
||||||
#define EDIT_GLOBAL_MENU "cedit.menu"
|
#define EDIT_GLOBAL_MENU "cedit.menu"
|
||||||
#define EDIT_LOCAL_MENU ".cedit.menu"
|
#define EDIT_LOCAL_MENU ".cedit.menu"
|
||||||
#define EDIT_HOME_MENU EDIT_DIR PATH_SEP_STR "menu"
|
#define EDIT_HOME_MENU EDIT_DIR PATH_SEP_STR "menu"
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
14
lib/fs.h
14
lib/fs.h
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file fs.h
|
/** \file fs.h
|
||||||
* \brief Header: fs compatibility definitions
|
* \brief Header: fs compatibility definitions
|
||||||
*/
|
*/
|
||||||
@ -11,7 +10,9 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* Replacement for permission bits missing in sys/stat.h */
|
/* Replacement for permission bits missing in sys/stat.h */
|
||||||
#ifndef S_ISLNK
|
#ifndef S_ISLNK
|
||||||
@ -52,7 +53,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
|
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
|
||||||
#include <dirent.h>
|
|
||||||
#define NLENGTH(dirent) (strlen ((dirent)->d_name))
|
#define NLENGTH(dirent) (strlen ((dirent)->d_name))
|
||||||
#define DIRENT_LENGTH_COMPUTED 1
|
#define DIRENT_LENGTH_COMPUTED 1
|
||||||
|
|
||||||
@ -62,6 +62,16 @@
|
|||||||
# define MC_MAXFILENAMELEN MAXNAMLEN
|
# define MC_MAXFILENAMELEN MAXNAMLEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
compute_namelen (struct dirent *dent __attribute__ ((unused)))
|
compute_namelen (struct dirent *dent __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
MA 02110-1301, USA.
|
MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** \file glibcompat.c
|
/** \file glibcompat.c
|
||||||
* \brief Source: compatibility with older versions of glib
|
* \brief Source: compatibility with older versions of glib
|
||||||
@ -50,10 +50,10 @@
|
|||||||
|
|
||||||
#if ! GLIB_CHECK_VERSION (2, 13, 0)
|
#if ! GLIB_CHECK_VERSION (2, 13, 0)
|
||||||
/*
|
/*
|
||||||
This is incomplete copy of same glib-function.
|
This is incomplete copy of same glib-function.
|
||||||
For older glib (less than 2.13) functional is enought.
|
For older glib (less than 2.13) functional is enought.
|
||||||
For full version of glib welcome to glib update.
|
For full version of glib welcome to glib update.
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
g_unichar_iszerowidth (gunichar c)
|
g_unichar_iszerowidth (gunichar c)
|
||||||
{
|
{
|
||||||
|
@ -19,5 +19,6 @@ gboolean g_unichar_iszerowidth (gunichar);
|
|||||||
gboolean g_file_set_contents (const gchar *, const gchar *, gssize, GError **);
|
gboolean g_file_set_contents (const gchar *, const gchar *, gssize, GError **);
|
||||||
#endif /* ! GLIB_CHECK_VERSION (2, 7, 0) */
|
#endif /* ! GLIB_CHECK_VERSION (2, 7, 0) */
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif /* MC_GLIBCOMPAT_H */
|
#endif /* MC_GLIBCOMPAT_H */
|
||||||
|
101
lib/global.h
101
lib/global.h
@ -1,47 +1,47 @@
|
|||||||
|
|
||||||
/** \file global.h
|
/** \file global.h
|
||||||
* \brief Header: %global definitions for compatibility
|
* \brief Header: %global definitions for compatibility
|
||||||
*
|
*
|
||||||
* This file should be included after all system includes and before all local includes.
|
* This file should be included after all system includes and before all local includes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MC_GLOBAL_H
|
#ifndef MC_GLOBAL_H
|
||||||
#define MC_GLOBAL_H
|
#define MC_GLOBAL_H
|
||||||
|
|
||||||
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
|
||||||
# include <string.h>
|
#include <string.h>
|
||||||
/* An ANSI string.h and pre-ANSI memory.h might conflict */
|
/* An ANSI string.h and pre-ANSI memory.h might conflict */
|
||||||
# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
|
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
|
||||||
# include <memory.h>
|
#include <memory.h>
|
||||||
# endif /* !STDC_HEADERS & HAVE_MEMORY_H */
|
#endif /* !STDC_HEADERS & HAVE_MEMORY_H */
|
||||||
|
|
||||||
#else /* !STDC_HEADERS & !HAVE_STRING_H */
|
#else /* !STDC_HEADERS & !HAVE_STRING_H */
|
||||||
# include <strings.h>
|
#include <strings.h>
|
||||||
/* memory and strings.h conflict on other systems */
|
/* memory and strings.h conflict on other systems */
|
||||||
#endif /* !STDC_HEADERS & !HAVE_STRING_H */
|
#endif /* !STDC_HEADERS & !HAVE_STRING_H */
|
||||||
|
|
||||||
#ifdef HAVE_SYS_PARAM_H
|
#ifdef HAVE_SYS_PARAM_H
|
||||||
# include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* The O_BINARY definition was taken from gettext */
|
/* The O_BINARY definition was taken from gettext */
|
||||||
#if !defined O_BINARY && defined _O_BINARY
|
#if !defined O_BINARY && defined _O_BINARY
|
||||||
/* For MSC-compatible compilers. */
|
/* For MSC-compatible compilers. */
|
||||||
# define O_BINARY _O_BINARY
|
#define O_BINARY _O_BINARY
|
||||||
#endif
|
#endif
|
||||||
#ifdef __BEOS__
|
#ifdef __BEOS__
|
||||||
/* BeOS 5 has O_BINARY, but is has no effect. */
|
/* BeOS 5 has O_BINARY, but is has no effect. */
|
||||||
# undef O_BINARY
|
#undef O_BINARY
|
||||||
#endif
|
#endif
|
||||||
/* On reasonable systems, binary I/O is the default. */
|
/* On reasonable systems, binary I/O is the default. */
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
# define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Replacement for O_NONBLOCK */
|
/* Replacement for O_NONBLOCK */
|
||||||
#ifndef O_NONBLOCK
|
#ifndef O_NONBLOCK
|
||||||
#ifdef O_NDELAY /* SYSV */
|
#ifdef O_NDELAY /* SYSV */
|
||||||
#define O_NONBLOCK O_NDELAY
|
#define O_NONBLOCK O_NDELAY
|
||||||
#else /* BSD */
|
#else /* BSD */
|
||||||
#define O_NONBLOCK FNDELAY
|
#define O_NONBLOCK FNDELAY
|
||||||
@ -49,38 +49,38 @@
|
|||||||
#endif /* !O_NONBLOCK */
|
#endif /* !O_NONBLOCK */
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SELECT_H
|
#ifdef HAVE_SYS_SELECT_H
|
||||||
# include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__QNX__) && !defined(__QNXNTO__)
|
#if defined(__QNX__) && !defined(__QNXNTO__)
|
||||||
/* exec*() from <process.h> */
|
/* exec*() from <process.h> */
|
||||||
# include <unix.h>
|
#include <unix.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "glibcompat.h"
|
#include "glibcompat.h"
|
||||||
|
|
||||||
#ifndef __GNUC__
|
#ifndef __GNUC__
|
||||||
# define __attribute__(x)
|
#define __attribute__(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
# include <libintl.h>
|
#include <libintl.h>
|
||||||
# define _(String) gettext (String)
|
#define _(String) gettext (String)
|
||||||
# ifdef gettext_noop
|
#ifdef gettext_noop
|
||||||
# define N_(String) gettext_noop (String)
|
#define N_(String) gettext_noop (String)
|
||||||
# else
|
#else
|
||||||
# define N_(String) (String)
|
#define N_(String) (String)
|
||||||
# endif
|
#endif
|
||||||
#else /* Stubs that do something close enough. */
|
#else /* Stubs that do something close enough. */
|
||||||
# define textdomain(String)
|
#define textdomain(String)
|
||||||
# define gettext(String) (String)
|
#define gettext(String) (String)
|
||||||
# define ngettext(String1,String2,Num) (((Num) == 1) ? (String1) : (String2))
|
#define ngettext(String1,String2,Num) (((Num) == 1) ? (String1) : (String2))
|
||||||
# define dgettext(Domain,Message) (Message)
|
#define dgettext(Domain,Message) (Message)
|
||||||
# define dcgettext(Domain,Message,Type) (Message)
|
#define dcgettext(Domain,Message,Type) (Message)
|
||||||
# define bindtextdomain(Domain,Directory)
|
#define bindtextdomain(Domain,Directory)
|
||||||
# define _(String) (String)
|
#define _(String) (String)
|
||||||
# define N_(String) (String)
|
#define N_(String) (String)
|
||||||
#endif /* !ENABLE_NLS */
|
#endif /* !ENABLE_NLS */
|
||||||
|
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
@ -90,8 +90,6 @@
|
|||||||
#include "lib/logging.h"
|
#include "lib/logging.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char *home_dir;
|
|
||||||
|
|
||||||
#ifdef min
|
#ifdef min
|
||||||
#undef min
|
#undef min
|
||||||
#endif
|
#endif
|
||||||
@ -100,21 +98,19 @@ extern const char *home_dir;
|
|||||||
#undef max
|
#undef max
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define min(x, y) ((x) > (y) ? (y) : (x))
|
#define min(x, y) ((x) > (y) ? (y) : (x))
|
||||||
#define max(x, y) ((x) > (y) ? (x) : (y))
|
#define max(x, y) ((x) > (y) ? (x) : (y))
|
||||||
|
|
||||||
/* Just for keeping Your's brains from invention a proper size of the buffer :-) */
|
/* Just for keeping Your's brains from invention a proper size of the buffer :-) */
|
||||||
#define BUF_10K 10240L
|
#define BUF_10K 10240L
|
||||||
#define BUF_8K 8192L
|
#define BUF_8K 8192L
|
||||||
#define BUF_4K 4096L
|
#define BUF_4K 4096L
|
||||||
#define BUF_1K 1024L
|
#define BUF_1K 1024L
|
||||||
|
|
||||||
#define BUF_LARGE BUF_1K
|
#define BUF_LARGE BUF_1K
|
||||||
#define BUF_MEDIUM 512
|
#define BUF_MEDIUM 512
|
||||||
#define BUF_SMALL 128
|
#define BUF_SMALL 128
|
||||||
#define BUF_TINY 64
|
#define BUF_TINY 64
|
||||||
|
|
||||||
void refresh_screen (void *);
|
|
||||||
|
|
||||||
/* AIX compiler doesn't understand '\e' */
|
/* AIX compiler doesn't understand '\e' */
|
||||||
#define ESC_CHAR '\033'
|
#define ESC_CHAR '\033'
|
||||||
@ -125,14 +121,27 @@ void refresh_screen (void *);
|
|||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#ifdef MC_ENABLE_DEBUGGING_CODE
|
#ifdef MC_ENABLE_DEBUGGING_CODE
|
||||||
# undef NDEBUG
|
#undef NDEBUG
|
||||||
#else
|
#else
|
||||||
# define NDEBUG
|
#define NDEBUG
|
||||||
#endif
|
#endif
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MC_ERROR mc_main_error_quark ()
|
#define MC_ERROR mc_main_error_quark ()
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
extern const char *home_dir;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
void refresh_screen (void *);
|
||||||
GQuark mc_main_error_quark (void);
|
GQuark mc_main_error_quark (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
39
lib/lock.c
39
lib/lock.c
@ -59,19 +59,30 @@
|
|||||||
|
|
||||||
#include "src/wtools.h" /* query_dialog() */
|
#include "src/wtools.h" /* query_dialog() */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define BUF_SIZE 255
|
#define BUF_SIZE 255
|
||||||
#define PID_BUF_SIZE 10
|
#define PID_BUF_SIZE 10
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
struct lock_s
|
struct lock_s
|
||||||
{
|
{
|
||||||
char *who;
|
char *who;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/** \fn static char * lock_build_name (void)
|
/** \fn static char * lock_build_name (void)
|
||||||
* \brief builds user@host.domain.pid string (need to be freed)
|
* \brief builds user@host.domain.pid string (need to be freed)
|
||||||
* \return a pointer to lock filename
|
* \return a pointer to lock filename
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
lock_build_name (void)
|
lock_build_name (void)
|
||||||
{
|
{
|
||||||
@ -98,6 +109,8 @@ lock_build_name (void)
|
|||||||
return g_strdup_printf ("%s@%s.%d", user, host, (int) getpid ());
|
return g_strdup_printf ("%s@%s.%d", user, host, (int) getpid ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
lock_build_symlink_name (const char *fname)
|
lock_build_symlink_name (const char *fname)
|
||||||
{
|
{
|
||||||
@ -116,7 +129,11 @@ lock_build_symlink_name (const char *fname)
|
|||||||
return symlink_name;
|
return symlink_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract pid from user@host.domain.pid string */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Extract pid from user@host.domain.pid string
|
||||||
|
*/
|
||||||
|
|
||||||
static struct lock_s *
|
static struct lock_s *
|
||||||
lock_extract_info (const char *str)
|
lock_extract_info (const char *str)
|
||||||
{
|
{
|
||||||
@ -148,7 +165,11 @@ lock_extract_info (const char *str)
|
|||||||
return &lock;
|
return &lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract user@host.domain.pid from lock file (static string) */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Extract user@host.domain.pid from lock file (static string)
|
||||||
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
lock_get_info (const char *lockfname)
|
lock_get_info (const char *lockfname)
|
||||||
{
|
{
|
||||||
@ -162,10 +183,14 @@ lock_get_info (const char *lockfname)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* Tries to raise file lock
|
/* Tries to raise file lock
|
||||||
Returns 1 on success, 0 on failure, -1 if abort
|
Returns 1 on success, 0 on failure, -1 if abort
|
||||||
Warning: Might do screen refresh and lose edit->force */
|
Warning: Might do screen refresh and lose edit->force */
|
||||||
|
|
||||||
int
|
int
|
||||||
lock_file (const char *fname)
|
lock_file (const char *fname)
|
||||||
{
|
{
|
||||||
@ -237,8 +262,12 @@ lock_file (const char *fname)
|
|||||||
return symlink_ok ? 1 : 0;
|
return symlink_ok ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lowers file lock if possible
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
Always returns 0 */
|
/**
|
||||||
|
* Lowers file lock if possible
|
||||||
|
* @returns Always 0
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
unlock_file (const char *fname)
|
unlock_file (const char *fname)
|
||||||
{
|
{
|
||||||
@ -279,3 +308,5 @@ unlock_file (const char *fname)
|
|||||||
g_free (lockfname);
|
g_free (lockfname);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
12
lib/lock.h
12
lib/lock.h
@ -9,7 +9,19 @@
|
|||||||
#ifndef MC_LOCK_H
|
#ifndef MC_LOCK_H
|
||||||
#define MC_LOCK_H
|
#define MC_LOCK_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
int lock_file (const char *fname);
|
int lock_file (const char *fname);
|
||||||
int unlock_file (const char *fname);
|
int unlock_file (const char *fname);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif /* MC_LOCK_H */
|
#endif /* MC_LOCK_H */
|
||||||
|
@ -39,42 +39,61 @@
|
|||||||
|
|
||||||
#include "src/setup.h"
|
#include "src/setup.h"
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
is_logging_enabled(void)
|
is_logging_enabled (void)
|
||||||
{
|
{
|
||||||
static gboolean logging_initialized = FALSE;
|
static gboolean logging_initialized = FALSE;
|
||||||
static gboolean logging_enabled = FALSE;
|
static gboolean logging_enabled = FALSE;
|
||||||
|
|
||||||
if (!logging_initialized) {
|
if (!logging_initialized)
|
||||||
logging_enabled = mc_config_get_bool (mc_main_config,
|
{
|
||||||
CONFIG_APP_SECTION, "development.enable_logging", FALSE);
|
logging_enabled = mc_config_get_bool (mc_main_config,
|
||||||
logging_initialized = TRUE;
|
CONFIG_APP_SECTION, "development.enable_logging",
|
||||||
}
|
FALSE);
|
||||||
return logging_enabled;
|
logging_initialized = TRUE;
|
||||||
|
}
|
||||||
|
return logging_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** public functions **************************************************/
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_log(const char *fmt, ...)
|
mc_log (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char *logfilename;
|
char *logfilename;
|
||||||
|
|
||||||
if (is_logging_enabled()) {
|
if (is_logging_enabled ())
|
||||||
va_start(args, fmt);
|
{
|
||||||
logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
va_start (args, fmt);
|
||||||
if (logfilename != NULL) {
|
logfilename = g_strdup_printf ("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
||||||
f = fopen (logfilename, "a");
|
if (logfilename != NULL)
|
||||||
if (f != NULL) {
|
{
|
||||||
(void)vfprintf(f, fmt, args);
|
f = fopen (logfilename, "a");
|
||||||
(void)fclose(f);
|
if (f != NULL)
|
||||||
}
|
{
|
||||||
g_free(logfilename);
|
(void) vfprintf (f, fmt, args);
|
||||||
va_end(args);
|
(void) fclose (f);
|
||||||
}
|
}
|
||||||
}
|
g_free (logfilename);
|
||||||
|
va_end (args);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file logging.h
|
/** \file logging.h
|
||||||
* \brief Header: provides a log file to ease tracing the program
|
* \brief Header: provides a log file to ease tracing the program
|
||||||
*/
|
*/
|
||||||
@ -11,9 +10,20 @@
|
|||||||
events into a central log file that can be used for debugging.
|
events into a central log file that can be used for debugging.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#define mc_log_mark() mc_log("%s:%d\n",__FILE__,__LINE__)
|
#define mc_log_mark() mc_log("%s:%d\n",__FILE__,__LINE__)
|
||||||
|
|
||||||
extern void mc_log(const char *, ...)
|
/*** enums ***************************************************************************************/
|
||||||
__attribute__((__format__(__printf__,1,2)));
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
extern void mc_log (const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)***************/
|
/*** structures declarations (and typedefs of structures)***************/
|
||||||
|
|
||||||
typedef struct mc_config_struct {
|
typedef struct mc_config_struct
|
||||||
|
{
|
||||||
GKeyFile *handle;
|
GKeyFile *handle;
|
||||||
gchar *ini_path;
|
gchar *ini_path;
|
||||||
} mc_config_t;
|
} mc_config_t;
|
||||||
@ -35,10 +36,9 @@ gboolean mc_config_has_group (mc_config_t *, const char *);
|
|||||||
|
|
||||||
gboolean mc_config_read_file (mc_config_t *, const gchar *);
|
gboolean mc_config_read_file (mc_config_t *, const gchar *);
|
||||||
|
|
||||||
gboolean mc_config_save_file (mc_config_t * config, GError **error);
|
gboolean mc_config_save_file (mc_config_t * config, GError ** error);
|
||||||
|
|
||||||
gboolean mc_config_save_to_file (mc_config_t * config, const gchar * filename,
|
gboolean mc_config_save_to_file (mc_config_t * config, const gchar * filename, GError ** error);
|
||||||
GError **error);
|
|
||||||
|
|
||||||
/* mcconfig/get.c: */
|
/* mcconfig/get.c: */
|
||||||
|
|
||||||
@ -64,26 +64,21 @@ int *mc_config_get_int_list (mc_config_t *, const gchar *, const gchar *, gsize
|
|||||||
|
|
||||||
/* mcconfig/set.c: */
|
/* mcconfig/set.c: */
|
||||||
|
|
||||||
void
|
void mc_config_direct_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||||
mc_config_direct_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
|
||||||
|
|
||||||
void
|
void mc_config_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||||
mc_config_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
|
||||||
|
|
||||||
void
|
void mc_config_set_bool (mc_config_t *, const gchar *, const gchar *, gboolean);
|
||||||
mc_config_set_bool (mc_config_t *, const gchar *, const gchar *, gboolean);
|
|
||||||
|
|
||||||
void mc_config_set_int (mc_config_t *, const gchar *, const gchar *, int);
|
void mc_config_set_int (mc_config_t *, const gchar *, const gchar *, int);
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_string_list (mc_config_t *, const gchar *,
|
mc_config_set_string_list (mc_config_t *, const gchar *,
|
||||||
const gchar *, const gchar * const[], gsize);
|
const gchar *, const gchar * const[], gsize);
|
||||||
|
|
||||||
void
|
void mc_config_set_bool_list (mc_config_t *, const gchar *, const gchar *, gboolean[], gsize);
|
||||||
mc_config_set_bool_list (mc_config_t *, const gchar *, const gchar *, gboolean[], gsize);
|
|
||||||
|
|
||||||
void
|
void mc_config_set_int_list (mc_config_t *, const gchar *, const gchar *, int[], gsize);
|
||||||
mc_config_set_int_list (mc_config_t *, const gchar *, const gchar *, int[], gsize);
|
|
||||||
|
|
||||||
|
|
||||||
/* mcconfig/dialog.c: */
|
/* mcconfig/dialog.c: */
|
||||||
|
@ -44,15 +44,15 @@ mc_config_get_groups (mc_config_t * mc_config, gsize * len)
|
|||||||
|
|
||||||
if (!mc_config)
|
if (!mc_config)
|
||||||
{
|
{
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
ret = g_try_malloc0 (sizeof (gchar **));
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
*len=0;
|
*len = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = g_key_file_get_groups (mc_config->handle, len);
|
ret = g_key_file_get_groups (mc_config->handle, len);
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
ret = g_try_malloc0 (sizeof (gchar **));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -66,15 +66,15 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
|
|||||||
|
|
||||||
if (!mc_config || !group)
|
if (!mc_config || !group)
|
||||||
{
|
{
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
ret = g_try_malloc0 (sizeof (gchar **));
|
||||||
if (len != NULL)
|
if (len != NULL)
|
||||||
*len=0;
|
*len = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
{
|
{
|
||||||
ret = g_try_malloc0 (sizeof (gchar **));
|
ret = g_try_malloc0 (sizeof (gchar **));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -83,26 +83,26 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
|
|||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, const gchar * def)
|
const gchar * param, const gchar * def)
|
||||||
{
|
{
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
GString *buffer;
|
GString *buffer;
|
||||||
gchar *ret;
|
gchar *ret;
|
||||||
const char *_system_codepage = str_detect_termencoding();
|
const char *_system_codepage = str_detect_termencoding ();
|
||||||
|
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return def ? g_strdup (def) : NULL;
|
return def ? g_strdup (def) : NULL;
|
||||||
|
|
||||||
if (! mc_config_has_param(mc_config, group, param))
|
if (!mc_config_has_param (mc_config, group, param))
|
||||||
{
|
{
|
||||||
mc_config_set_string (mc_config, group, param, def ? def : "");
|
mc_config_set_string (mc_config, group, param, def ? def : "");
|
||||||
return def ? g_strdup (def) : NULL;
|
return def ? g_strdup (def) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
|
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = def ? g_strdup (def) : NULL;
|
ret = def ? g_strdup (def) : NULL;
|
||||||
|
|
||||||
if (str_isutf8 (_system_codepage))
|
if (str_isutf8 (_system_codepage))
|
||||||
return ret;
|
return ret;
|
||||||
@ -115,38 +115,38 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group,
|
|||||||
|
|
||||||
if (str_convert (conv, ret, buffer) == ESTR_FAILURE)
|
if (str_convert (conv, ret, buffer) == ESTR_FAILURE)
|
||||||
{
|
{
|
||||||
g_string_free(buffer, TRUE);
|
g_string_free (buffer, TRUE);
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
|
|
||||||
g_free(ret);
|
g_free (ret);
|
||||||
|
|
||||||
return g_string_free(buffer, FALSE);
|
return g_string_free (buffer, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, const gchar * def)
|
const gchar * param, const gchar * def)
|
||||||
{
|
{
|
||||||
gchar *ret;
|
gchar *ret;
|
||||||
|
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return def ? g_strdup (def) : NULL;
|
return def ? g_strdup (def) : NULL;
|
||||||
|
|
||||||
if (! mc_config_has_param(mc_config, group, param))
|
if (!mc_config_has_param (mc_config, group, param))
|
||||||
{
|
{
|
||||||
mc_config_set_string (mc_config, group, param, def ? def : "");
|
mc_config_set_string (mc_config, group, param, def ? def : "");
|
||||||
return def ? g_strdup (def) : NULL;
|
return def ? g_strdup (def) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
|
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
|
||||||
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = def ? g_strdup (def) : NULL;
|
ret = def ? g_strdup (def) : NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -154,16 +154,15 @@ mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
|
|||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
|
||||||
const gchar * param, gboolean def)
|
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
if (! mc_config_has_param(mc_config, group, param))
|
if (!mc_config_has_param (mc_config, group, param))
|
||||||
{
|
{
|
||||||
mc_config_set_bool (mc_config, group, param, def);
|
mc_config_set_bool (mc_config, group, param, def);
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
|
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
|
||||||
@ -172,16 +171,15 @@ mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
|
|||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
int
|
int
|
||||||
mc_config_get_int (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int def)
|
||||||
const gchar * param, int def)
|
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
if (! mc_config_has_param(mc_config, group, param))
|
if (!mc_config_has_param (mc_config, group, param))
|
||||||
{
|
{
|
||||||
mc_config_set_int (mc_config, group, param, def);
|
mc_config_set_int (mc_config, group, param, def);
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
|
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
|
||||||
@ -192,39 +190,36 @@ mc_config_get_int (mc_config_t * mc_config, const gchar * group,
|
|||||||
|
|
||||||
gchar **
|
gchar **
|
||||||
mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, gsize * length)
|
const gchar * param, gsize * length)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return g_key_file_get_string_list (mc_config->handle, group, param,
|
return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
|
||||||
length, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
gboolean *
|
gboolean *
|
||||||
mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, gsize * length)
|
const gchar * param, gsize * length)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return g_key_file_get_boolean_list (mc_config->handle, group, param,
|
return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
|
||||||
length, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
int *
|
int *
|
||||||
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, gsize * length)
|
const gchar * param, gsize * length)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param)
|
if (!mc_config || !group || !param)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return g_key_file_get_integer_list (mc_config->handle, group, param,
|
return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
|
||||||
length, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
@ -37,33 +37,33 @@ extern int utf8_display;
|
|||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
mc_config_normalize_before_save(const gchar * value)
|
mc_config_normalize_before_save (const gchar * value)
|
||||||
{
|
{
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
GString *buffer;
|
GString *buffer;
|
||||||
|
|
||||||
if (utf8_display)
|
if (utf8_display)
|
||||||
{
|
{
|
||||||
buffer = g_string_new(value);
|
buffer = g_string_new (value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
conv = str_crt_conv_to ("UTF-8");
|
conv = str_crt_conv_to ("UTF-8");
|
||||||
if (conv == INVALID_CONV)
|
if (conv == INVALID_CONV)
|
||||||
return g_strdup(value);
|
return g_strdup (value);
|
||||||
|
|
||||||
buffer = g_string_new ("");
|
buffer = g_string_new ("");
|
||||||
|
|
||||||
if (str_convert (conv, value, buffer) == ESTR_FAILURE)
|
if (str_convert (conv, value, buffer) == ESTR_FAILURE)
|
||||||
{
|
{
|
||||||
g_string_free(buffer, TRUE);
|
g_string_free (buffer, TRUE);
|
||||||
buffer = g_string_new(value);
|
buffer = g_string_new (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
str_close_conv (conv);
|
str_close_conv (conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_string_free(buffer, FALSE);
|
return g_string_free (buffer, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
@ -72,46 +72,46 @@ mc_config_normalize_before_save(const gchar * value)
|
|||||||
|
|
||||||
void
|
void
|
||||||
mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
|
mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, const gchar * value)
|
const gchar * param, const gchar * value)
|
||||||
{
|
{
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
|
|
||||||
if (!mc_config || !group || !param || !value)
|
if (!mc_config || !group || !param || !value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buffer = mc_config_normalize_before_save(value);
|
buffer = mc_config_normalize_before_save (value);
|
||||||
|
|
||||||
g_key_file_set_value (mc_config->handle, group, param, buffer);
|
g_key_file_set_value (mc_config->handle, group, param, buffer);
|
||||||
|
|
||||||
g_free(buffer);
|
g_free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, const gchar * value)
|
const gchar * param, const gchar * value)
|
||||||
{
|
{
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
|
|
||||||
if (!mc_config || !group || !param || !value)
|
if (!mc_config || !group || !param || !value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
buffer = mc_config_normalize_before_save(value);
|
buffer = mc_config_normalize_before_save (value);
|
||||||
|
|
||||||
g_key_file_set_string (mc_config->handle, group, param, buffer);
|
g_key_file_set_string (mc_config->handle, group, param, buffer);
|
||||||
|
|
||||||
g_free(buffer);
|
g_free (buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, gboolean value)
|
const gchar * param, gboolean value)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param )
|
if (!mc_config || !group || !param)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_key_file_set_boolean (mc_config->handle, group, param, value);
|
g_key_file_set_boolean (mc_config->handle, group, param, value);
|
||||||
}
|
}
|
||||||
@ -119,11 +119,10 @@ mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
|||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_int (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
|
||||||
const gchar * param, int value)
|
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param )
|
if (!mc_config || !group || !param)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_key_file_set_integer (mc_config->handle, group, param, value);
|
g_key_file_set_integer (mc_config->handle, group, param, value);
|
||||||
}
|
}
|
||||||
@ -133,14 +132,12 @@ mc_config_set_int (mc_config_t * mc_config, const gchar * group,
|
|||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, const gchar * const value[],
|
const gchar * param, const gchar * const value[], gsize length)
|
||||||
gsize length)
|
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param || !value || length == 0)
|
if (!mc_config || !group || !param || !value || length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_key_file_set_string_list (mc_config->handle, group, param, value,
|
g_key_file_set_string_list (mc_config->handle, group, param, value, length);
|
||||||
length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
@ -148,26 +145,24 @@ mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
|
|||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, gboolean value[], gsize length)
|
const gchar * param, gboolean value[], gsize length)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param || !value || length == 0)
|
if (!mc_config || !group || !param || !value || length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_key_file_set_boolean_list (mc_config->handle, group, param, value,
|
g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
|
||||||
length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
|
||||||
void
|
void
|
||||||
mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
|
mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
|
||||||
const gchar * param, int value[], gsize length)
|
const gchar * param, int value[], gsize length)
|
||||||
{
|
{
|
||||||
if (!mc_config || !group || !param || !value || length == 0)
|
if (!mc_config || !group || !param || !value || length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_key_file_set_integer_list (mc_config->handle, group, param, value,
|
g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
|
||||||
length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
|
33
lib/search.h
33
lib/search.h
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "lib/global.h" /* <glib.h> */
|
#include "lib/global.h" /* <glib.h> */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#ifdef SEARCH_TYPE_PCRE
|
#ifdef SEARCH_TYPE_PCRE
|
||||||
# include <pcre.h>
|
#include <pcre.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** typedefs(not structures) and defined constants **********************************************/
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
@ -18,14 +18,15 @@ typedef int (*mc_search_fn) (const void *user_data, gsize char_offset);
|
|||||||
#define MC_SEARCH__NUM_REPLACE_ARGS 64
|
#define MC_SEARCH__NUM_REPLACE_ARGS 64
|
||||||
|
|
||||||
#ifdef SEARCH_TYPE_GLIB
|
#ifdef SEARCH_TYPE_GLIB
|
||||||
# define mc_search_matchinfo_t GMatchInfo
|
#define mc_search_matchinfo_t GMatchInfo
|
||||||
#else
|
#else
|
||||||
# define mc_search_matchinfo_t pcre_extra
|
#define mc_search_matchinfo_t pcre_extra
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MC_SEARCH_E_OK,
|
MC_SEARCH_E_OK,
|
||||||
MC_SEARCH_E_INPUT,
|
MC_SEARCH_E_INPUT,
|
||||||
MC_SEARCH_E_REGEX_COMPILE,
|
MC_SEARCH_E_REGEX_COMPILE,
|
||||||
@ -34,14 +35,16 @@ typedef enum {
|
|||||||
MC_SEARCH_E_NOTFOUND
|
MC_SEARCH_E_NOTFOUND
|
||||||
} mc_search_error_t;
|
} mc_search_error_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MC_SEARCH_T_NORMAL,
|
MC_SEARCH_T_NORMAL,
|
||||||
MC_SEARCH_T_REGEX,
|
MC_SEARCH_T_REGEX,
|
||||||
MC_SEARCH_T_HEX,
|
MC_SEARCH_T_HEX,
|
||||||
MC_SEARCH_T_GLOB
|
MC_SEARCH_T_GLOB
|
||||||
} mc_search_type_t;
|
} mc_search_type_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MC_SEARCH_CB_OK = 0,
|
MC_SEARCH_CB_OK = 0,
|
||||||
MC_SEARCH_CB_INVALID = -1,
|
MC_SEARCH_CB_INVALID = -1,
|
||||||
MC_SEARCH_CB_ABORT = -2,
|
MC_SEARCH_CB_ABORT = -2,
|
||||||
@ -51,9 +54,10 @@ typedef enum {
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_search_struct {
|
typedef struct mc_search_struct
|
||||||
|
{
|
||||||
|
|
||||||
/* public input data */
|
/* public input data */
|
||||||
|
|
||||||
/* search in all charsets */
|
/* search in all charsets */
|
||||||
gboolean is_all_charsets;
|
gboolean is_all_charsets;
|
||||||
@ -80,7 +84,7 @@ typedef struct mc_search_struct {
|
|||||||
mc_search_type_t search_type;
|
mc_search_type_t search_type;
|
||||||
|
|
||||||
|
|
||||||
/* public output data */
|
/* public output data */
|
||||||
|
|
||||||
/* some data for normal */
|
/* some data for normal */
|
||||||
off_t normal_offset;
|
off_t normal_offset;
|
||||||
@ -94,7 +98,7 @@ typedef struct mc_search_struct {
|
|||||||
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
|
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
|
||||||
#endif /* SEARCH_TYPE_PCRE */
|
#endif /* SEARCH_TYPE_PCRE */
|
||||||
|
|
||||||
/* private data */
|
/* private data */
|
||||||
|
|
||||||
/* prepared conditions */
|
/* prepared conditions */
|
||||||
GPtrArray *conditions;
|
GPtrArray *conditions;
|
||||||
@ -109,7 +113,8 @@ typedef struct mc_search_struct {
|
|||||||
|
|
||||||
} mc_search_t;
|
} mc_search_t;
|
||||||
|
|
||||||
typedef struct mc_search_type_str_struct {
|
typedef struct mc_search_type_str_struct
|
||||||
|
{
|
||||||
const char *str;
|
const char *str;
|
||||||
mc_search_type_t type;
|
mc_search_type_t type;
|
||||||
} mc_search_type_str_t;
|
} mc_search_type_str_t;
|
||||||
@ -129,14 +134,14 @@ gboolean mc_search_run (mc_search_t * mc_search, const void *user_data, gsize st
|
|||||||
|
|
||||||
gboolean mc_search_is_type_avail (mc_search_type_t);
|
gboolean mc_search_is_type_avail (mc_search_type_t);
|
||||||
|
|
||||||
const mc_search_type_str_t *mc_search_types_list_get (size_t *num);
|
const mc_search_type_str_t *mc_search_types_list_get (size_t * num);
|
||||||
|
|
||||||
GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
|
GString *mc_search_prepare_replace_str (mc_search_t * mc_search, GString * replace_str);
|
||||||
char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
|
char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
|
||||||
|
|
||||||
gboolean mc_search_is_fixed_search_str (mc_search_t *);
|
gboolean mc_search_is_fixed_search_str (mc_search_t *);
|
||||||
|
|
||||||
gchar **mc_search_get_types_strings_array (size_t *num);
|
gchar **mc_search_get_types_strings_array (size_t * num);
|
||||||
|
|
||||||
gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
|
gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
|
||||||
|
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
COND__NOT_FOUND,
|
COND__NOT_FOUND,
|
||||||
COND__NOT_ALL_FOUND,
|
COND__NOT_ALL_FOUND,
|
||||||
COND__FOUND_CHAR,
|
COND__FOUND_CHAR,
|
||||||
@ -22,7 +23,8 @@ typedef enum {
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_search_cond_struct {
|
typedef struct mc_search_cond_struct
|
||||||
|
{
|
||||||
GString *str;
|
GString *str;
|
||||||
GString *upper;
|
GString *upper;
|
||||||
GString *lower;
|
GString *lower;
|
||||||
@ -32,12 +34,12 @@ typedef struct mc_search_cond_struct {
|
|||||||
|
|
||||||
/*** global variables defined in .c file *********************************************************/
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern const char * STR_E_NOTFOUND;
|
extern const char *STR_E_NOTFOUND;
|
||||||
extern const char * STR_E_UNKNOWN_TYPE;
|
extern const char *STR_E_UNKNOWN_TYPE;
|
||||||
extern const char * STR_E_RPL_NOT_EQ_TO_FOUND;
|
extern const char *STR_E_RPL_NOT_EQ_TO_FOUND;
|
||||||
extern const char * STR_E_RPL_INVALID_TOKEN;
|
extern const char *STR_E_RPL_INVALID_TOKEN;
|
||||||
/*** declarations of public functions ************************************************************/
|
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
/* search/lib.c : */
|
/* search/lib.c : */
|
||||||
|
|
||||||
@ -83,4 +85,6 @@ gboolean mc_search__run_hex (mc_search_t *, const void *, gsize, gsize, gsize *)
|
|||||||
|
|
||||||
GString *mc_search_hex_prepare_replace_str (mc_search_t *, GString *);
|
GString *mc_search_hex_prepare_replace_str (mc_search_t *, GString *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,10 +39,11 @@
|
|||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
const char * STR_E_NOTFOUND = N_("Search string not found");
|
const char *STR_E_NOTFOUND = N_("Search string not found");
|
||||||
const char * STR_E_UNKNOWN_TYPE = N_("Not implemented yet");
|
const char *STR_E_UNKNOWN_TYPE = N_("Not implemented yet");
|
||||||
const char * STR_E_RPL_NOT_EQ_TO_FOUND = N_("Num of replace tokens not equal to num of found tokens");
|
const char *STR_E_RPL_NOT_EQ_TO_FOUND =
|
||||||
const char * STR_E_RPL_INVALID_TOKEN = N_("Invalid token number %d");
|
N_("Num of replace tokens not equal to num of found tokens");
|
||||||
|
const char *STR_E_RPL_INVALID_TOKEN = N_("Invalid token number %d");
|
||||||
|
|
||||||
/*** file scope macro definitions ****************************************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
@ -62,13 +63,15 @@ mc_search__recode_str (const char *str, gsize str_len,
|
|||||||
gsize bytes_read;
|
gsize bytes_read;
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
|
|
||||||
if (charset_from == NULL || charset_to == NULL || !strcmp (charset_to, charset_from)) {
|
if (charset_from == NULL || charset_to == NULL || !strcmp (charset_to, charset_from))
|
||||||
|
{
|
||||||
*bytes_written = str_len;
|
*bytes_written = str_len;
|
||||||
return g_strndup (str, str_len);
|
return g_strndup (str, str_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
conv = g_iconv_open (charset_to, charset_from);
|
conv = g_iconv_open (charset_to, charset_from);
|
||||||
if (conv == INVALID_CONV) {
|
if (conv == INVALID_CONV)
|
||||||
|
{
|
||||||
*bytes_written = str_len;
|
*bytes_written = str_len;
|
||||||
return g_strndup (str, str_len);
|
return g_strndup (str, str_len);
|
||||||
}
|
}
|
||||||
@ -76,7 +79,8 @@ mc_search__recode_str (const char *str, gsize str_len,
|
|||||||
ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL);
|
ret = g_convert_with_iconv (str, str_len, conv, &bytes_read, bytes_written, NULL);
|
||||||
g_iconv_close (conv);
|
g_iconv_close (conv);
|
||||||
|
|
||||||
if (ret == NULL) {
|
if (ret == NULL)
|
||||||
|
{
|
||||||
*bytes_written = str_len;
|
*bytes_written = str_len;
|
||||||
return g_strndup (str, str_len);
|
return g_strndup (str, str_len);
|
||||||
}
|
}
|
||||||
@ -118,7 +122,8 @@ mc_search__get_one_symbol (const char *charset, const char *str, gsize str_len,
|
|||||||
converted_str2 =
|
converted_str2 =
|
||||||
mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len);
|
mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len);
|
||||||
#endif
|
#endif
|
||||||
if (just_letters) {
|
if (just_letters)
|
||||||
|
{
|
||||||
if (str_isalnum (converted_str) && !str_isdigit (converted_str))
|
if (str_isalnum (converted_str) && !str_isdigit (converted_str))
|
||||||
*just_letters = TRUE;
|
*just_letters = TRUE;
|
||||||
else
|
else
|
||||||
@ -250,7 +255,7 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gchar **
|
gchar **
|
||||||
mc_search_get_types_strings_array (size_t *num)
|
mc_search_get_types_strings_array (size_t * num)
|
||||||
{
|
{
|
||||||
gchar **ret;
|
gchar **ret;
|
||||||
int lc_index;
|
int lc_index;
|
||||||
@ -263,14 +268,12 @@ mc_search_get_types_strings_array (size_t *num)
|
|||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (lc_index = 0, type_str = types_str;
|
for (lc_index = 0, type_str = types_str; type_str->str != NULL; type_str++, lc_index++)
|
||||||
type_str->str != NULL;
|
|
||||||
type_str++, lc_index++)
|
|
||||||
ret[lc_index] = g_strdup (type_str->str);
|
ret[lc_index] = g_strdup (type_str->str);
|
||||||
|
|
||||||
/* don't count last NULL item */
|
/* don't count last NULL item */
|
||||||
if (num != NULL)
|
if (num != NULL)
|
||||||
*num = (size_t) lc_index;
|
*num = (size_t) lc_index;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ typedef enum
|
|||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
mc_search__regex_str_append_if_special (GString * copy_to, const GString * regex_str, gsize * offset)
|
mc_search__regex_str_append_if_special (GString * copy_to, const GString * regex_str,
|
||||||
|
gsize * offset)
|
||||||
{
|
{
|
||||||
char *tmp_regex_str;
|
char *tmp_regex_str;
|
||||||
gsize spec_chr_len;
|
gsize spec_chr_len;
|
||||||
@ -194,7 +195,7 @@ mc_search__cond_struct_new_regex_accum_append (const char *charset, GString * st
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static GString *
|
static GString *
|
||||||
mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *astr)
|
mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString * astr)
|
||||||
{
|
{
|
||||||
GString *accumulator, *spec_char, *ret_str;
|
GString *accumulator, *spec_char, *ret_str;
|
||||||
gsize loop;
|
gsize loop;
|
||||||
@ -219,7 +220,8 @@ mc_search__cond_struct_new_regex_ci_str (const char *charset, const GString *ast
|
|||||||
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
|
mc_search__cond_struct_new_regex_accum_append (charset, ret_str, accumulator);
|
||||||
|
|
||||||
while (loop < astr->len && !(astr->str[loop] == ']'
|
while (loop < astr->len && !(astr->str[loop] == ']'
|
||||||
&& !strutils_is_char_escaped (astr->str, &(astr->str[loop]))))
|
&& !strutils_is_char_escaped (astr->str,
|
||||||
|
&(astr->str[loop]))))
|
||||||
{
|
{
|
||||||
g_string_append_c (ret_str, astr->str[loop]);
|
g_string_append_c (ret_str, astr->str[loop]);
|
||||||
loop++;
|
loop++;
|
||||||
@ -317,7 +319,7 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
|
|||||||
gsize loop;
|
gsize loop;
|
||||||
for (loop = 0; loop < len - 1; loop++)
|
for (loop = 0; loop < len - 1; loop++)
|
||||||
{
|
{
|
||||||
if (str[loop] == '\\' && g_ascii_isdigit(str[loop + 1]) )
|
if (str[loop] == '\\' && g_ascii_isdigit (str[loop + 1]))
|
||||||
{
|
{
|
||||||
if (strutils_is_char_escaped (str, &str[loop]))
|
if (strutils_is_char_escaped (str, &str[loop]))
|
||||||
continue;
|
continue;
|
||||||
@ -418,7 +420,7 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( g_ascii_isdigit(*(curr_str + 1)))
|
if (g_ascii_isdigit (*(curr_str + 1)))
|
||||||
{
|
{
|
||||||
ret = g_ascii_digit_value (*(curr_str + 1));
|
ret = g_ascii_digit_value (*(curr_str + 1));
|
||||||
*skip_len = 2; /* \\ and one digit */
|
*skip_len = 2; /* \\ and one digit */
|
||||||
@ -452,6 +454,7 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len,
|
mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len,
|
||||||
replace_transform_type_t * replace_flags)
|
replace_transform_type_t * replace_flags)
|
||||||
|
@ -66,7 +66,8 @@ mc_search__cond_struct_new (mc_search_t * lc_mc_search, const char *str,
|
|||||||
mc_search_cond->str = g_string_new_len (str, str_len);
|
mc_search_cond->str = g_string_new_len (str, str_len);
|
||||||
mc_search_cond->charset = g_strdup (charset);
|
mc_search_cond->charset = g_strdup (charset);
|
||||||
|
|
||||||
switch (lc_mc_search->search_type) {
|
switch (lc_mc_search->search_type)
|
||||||
|
{
|
||||||
case MC_SEARCH_T_GLOB:
|
case MC_SEARCH_T_GLOB:
|
||||||
mc_search__cond_struct_new_init_glob (charset, lc_mc_search, mc_search_cond);
|
mc_search__cond_struct_new_init_glob (charset, lc_mc_search, mc_search_cond);
|
||||||
break;
|
break;
|
||||||
@ -117,7 +118,8 @@ mc_search__conditions_free (GPtrArray * array)
|
|||||||
gsize loop1;
|
gsize loop1;
|
||||||
mc_search_cond_t *lc_mc_search;
|
mc_search_cond_t *lc_mc_search;
|
||||||
|
|
||||||
for (loop1 = 0; loop1 < array->len; loop1++) {
|
for (loop1 = 0; loop1 < array->len; loop1++)
|
||||||
|
{
|
||||||
lc_mc_search = (mc_search_cond_t *) g_ptr_array_index (array, loop1);
|
lc_mc_search = (mc_search_cond_t *) g_ptr_array_index (array, loop1);
|
||||||
mc_search__cond_struct_free (lc_mc_search);
|
mc_search__cond_struct_free (lc_mc_search);
|
||||||
}
|
}
|
||||||
@ -137,7 +139,8 @@ mc_search_new (const gchar * original, gsize str_len)
|
|||||||
if (!original)
|
if (!original)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((gssize) str_len == -1) {
|
if ((gssize) str_len == -1)
|
||||||
|
{
|
||||||
str_len = strlen (original);
|
str_len = strlen (original);
|
||||||
if (str_len == 0)
|
if (str_len == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -184,30 +187,37 @@ mc_search_prepare (mc_search_t * lc_mc_search)
|
|||||||
GPtrArray *ret;
|
GPtrArray *ret;
|
||||||
ret = g_ptr_array_new ();
|
ret = g_ptr_array_new ();
|
||||||
#ifdef HAVE_CHARSET
|
#ifdef HAVE_CHARSET
|
||||||
if (lc_mc_search->is_all_charsets) {
|
if (lc_mc_search->is_all_charsets)
|
||||||
|
{
|
||||||
gsize loop1, recoded_str_len;
|
gsize loop1, recoded_str_len;
|
||||||
gchar *buffer;
|
gchar *buffer;
|
||||||
for (loop1 = 0; loop1 < codepages->len; loop1++) {
|
for (loop1 = 0; loop1 < codepages->len; loop1++)
|
||||||
|
{
|
||||||
const char *id = ((codepage_desc *) g_ptr_array_index (codepages, loop1))->id;
|
const char *id = ((codepage_desc *) g_ptr_array_index (codepages, loop1))->id;
|
||||||
if (!g_ascii_strcasecmp (id, cp_source)) {
|
if (!g_ascii_strcasecmp (id, cp_source))
|
||||||
|
{
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
||||||
lc_mc_search->original_len, cp_source));
|
lc_mc_search->original_len,
|
||||||
|
cp_source));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer =
|
buffer =
|
||||||
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len, cp_source,
|
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len,
|
||||||
id, &recoded_str_len);
|
cp_source, id, &recoded_str_len);
|
||||||
|
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
mc_search__cond_struct_new (lc_mc_search, buffer,
|
mc_search__cond_struct_new (lc_mc_search, buffer,
|
||||||
recoded_str_len, id));
|
recoded_str_len, id));
|
||||||
g_free (buffer);
|
g_free (buffer);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
g_ptr_array_add (ret,
|
g_ptr_array_add (ret,
|
||||||
(gpointer) mc_search__cond_struct_new (lc_mc_search, lc_mc_search->original,
|
(gpointer) mc_search__cond_struct_new (lc_mc_search,
|
||||||
|
lc_mc_search->original,
|
||||||
lc_mc_search->original_len,
|
lc_mc_search->original_len,
|
||||||
cp_source));
|
cp_source));
|
||||||
}
|
}
|
||||||
@ -232,13 +242,15 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
|||||||
|
|
||||||
if (!lc_mc_search)
|
if (!lc_mc_search)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (!mc_search_is_type_avail (lc_mc_search->search_type)) {
|
if (!mc_search_is_type_avail (lc_mc_search->search_type))
|
||||||
|
{
|
||||||
lc_mc_search->error = MC_SEARCH_E_INPUT;
|
lc_mc_search->error = MC_SEARCH_E_INPUT;
|
||||||
lc_mc_search->error_str = g_strdup (_(STR_E_UNKNOWN_TYPE));
|
lc_mc_search->error_str = g_strdup (_(STR_E_UNKNOWN_TYPE));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#ifdef SEARCH_TYPE_GLIB
|
#ifdef SEARCH_TYPE_GLIB
|
||||||
if (lc_mc_search->regex_match_info) {
|
if (lc_mc_search->regex_match_info)
|
||||||
|
{
|
||||||
g_match_info_free (lc_mc_search->regex_match_info);
|
g_match_info_free (lc_mc_search->regex_match_info);
|
||||||
lc_mc_search->regex_match_info = NULL;
|
lc_mc_search->regex_match_info = NULL;
|
||||||
}
|
}
|
||||||
@ -252,7 +264,8 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
||||||
switch (lc_mc_search->search_type) {
|
switch (lc_mc_search->search_type)
|
||||||
|
{
|
||||||
case MC_SEARCH_T_NORMAL:
|
case MC_SEARCH_T_NORMAL:
|
||||||
ret = mc_search__run_normal (lc_mc_search, user_data, start_search, end_search, found_len);
|
ret = mc_search__run_normal (lc_mc_search, user_data, start_search, end_search, found_len);
|
||||||
break;
|
break;
|
||||||
@ -276,7 +289,8 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
|||||||
gboolean
|
gboolean
|
||||||
mc_search_is_type_avail (mc_search_type_t search_type)
|
mc_search_is_type_avail (mc_search_type_t search_type)
|
||||||
{
|
{
|
||||||
switch (search_type) {
|
switch (search_type)
|
||||||
|
{
|
||||||
case MC_SEARCH_T_GLOB:
|
case MC_SEARCH_T_GLOB:
|
||||||
case MC_SEARCH_T_NORMAL:
|
case MC_SEARCH_T_NORMAL:
|
||||||
case MC_SEARCH_T_REGEX:
|
case MC_SEARCH_T_REGEX:
|
||||||
@ -291,11 +305,11 @@ mc_search_is_type_avail (mc_search_type_t search_type)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const mc_search_type_str_t *
|
const mc_search_type_str_t *
|
||||||
mc_search_types_list_get (size_t *num)
|
mc_search_types_list_get (size_t * num)
|
||||||
{
|
{
|
||||||
/* don't count last NULL item */
|
/* don't count last NULL item */
|
||||||
if (num != NULL)
|
if (num != NULL)
|
||||||
*num = sizeof (mc_search__list_types) / sizeof (mc_search__list_types[0]) - 1;
|
*num = sizeof (mc_search__list_types) / sizeof (mc_search__list_types[0]) - 1;
|
||||||
|
|
||||||
return mc_search__list_types;
|
return mc_search__list_types;
|
||||||
}
|
}
|
||||||
@ -313,7 +327,8 @@ mc_search_prepare_replace_str (mc_search_t * lc_mc_search, GString * replace_str
|
|||||||
if (replace_str == NULL || replace_str->str == NULL || replace_str->len == 0)
|
if (replace_str == NULL || replace_str->str == NULL || replace_str->len == 0)
|
||||||
return g_string_new ("");
|
return g_string_new ("");
|
||||||
|
|
||||||
switch (lc_mc_search->search_type) {
|
switch (lc_mc_search->search_type)
|
||||||
|
{
|
||||||
case MC_SEARCH_T_REGEX:
|
case MC_SEARCH_T_REGEX:
|
||||||
ret = mc_search_regex_prepare_replace_str (lc_mc_search, replace_str);
|
ret = mc_search_regex_prepare_replace_str (lc_mc_search, replace_str);
|
||||||
break;
|
break;
|
||||||
@ -354,7 +369,8 @@ mc_search_is_fixed_search_str (mc_search_t * lc_mc_search)
|
|||||||
{
|
{
|
||||||
if (lc_mc_search == NULL)
|
if (lc_mc_search == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
switch (lc_mc_search->search_type) {
|
switch (lc_mc_search->search_type)
|
||||||
|
{
|
||||||
case MC_SEARCH_T_REGEX:
|
case MC_SEARCH_T_REGEX:
|
||||||
case MC_SEARCH_T_GLOB:
|
case MC_SEARCH_T_GLOB:
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
/* Beware! When using Slang with color, not all the indexes are free.
|
/* Beware! When using Slang with color, not all the indexes are free.
|
||||||
See color-slang.h (A_*) */
|
See color-slang.h (A_*) */
|
||||||
|
|
||||||
/* cache often used colors*/
|
/* cache often used colors */
|
||||||
#define DEFAULT_COLOR mc_skin_color__cache[0]
|
#define DEFAULT_COLOR mc_skin_color__cache[0]
|
||||||
#define NORMAL_COLOR mc_skin_color__cache[1]
|
#define NORMAL_COLOR mc_skin_color__cache[1]
|
||||||
#define MARKED_COLOR mc_skin_color__cache[2]
|
#define MARKED_COLOR mc_skin_color__cache[2]
|
||||||
@ -102,7 +102,8 @@
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_skin_struct {
|
typedef struct mc_skin_struct
|
||||||
|
{
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *description;
|
gchar *description;
|
||||||
mc_config_t *config;
|
mc_config_t *config;
|
||||||
@ -123,6 +124,6 @@ int mc_skin_color_get (const gchar *, const gchar *);
|
|||||||
|
|
||||||
void mc_skin_lines_parse_ini_file (mc_skin_t *);
|
void mc_skin_lines_parse_ini_file (mc_skin_t *);
|
||||||
|
|
||||||
gchar *mc_skin_get(const gchar *, const gchar *, const gchar *);
|
gchar *mc_skin_get (const gchar *, const gchar *, const gchar *);
|
||||||
|
|
||||||
#endif /* MC_SKIN_H */
|
#endif /* MC_SKIN_H */
|
||||||
|
@ -203,7 +203,7 @@ mc_skin_color_cache_init (void)
|
|||||||
MARKED_COLOR = mc_skin_color_get ("core", "marked");
|
MARKED_COLOR = mc_skin_color_get ("core", "marked");
|
||||||
SELECTED_COLOR = mc_skin_color_get ("core", "selected");
|
SELECTED_COLOR = mc_skin_color_get ("core", "selected");
|
||||||
MARKED_SELECTED_COLOR = mc_skin_color_get ("core", "markselect");
|
MARKED_SELECTED_COLOR = mc_skin_color_get ("core", "markselect");
|
||||||
DISABLED_COLOR = mc_skin_color_get ("core", "disabled");
|
DISABLED_COLOR = mc_skin_color_get ("core", "disabled");
|
||||||
REVERSE_COLOR = mc_skin_color_get ("core", "reverse");
|
REVERSE_COLOR = mc_skin_color_get ("core", "reverse");
|
||||||
HEADER_COLOR = mc_skin_color_get ("core", "header");
|
HEADER_COLOR = mc_skin_color_get ("core", "header");
|
||||||
COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark");
|
COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark");
|
||||||
|
@ -85,8 +85,7 @@ mc_skin_reinit (void)
|
|||||||
mc_skin_deinit ();
|
mc_skin_deinit ();
|
||||||
mc_skin__default.name = mc_skin_get_default_name ();
|
mc_skin__default.name = mc_skin_get_default_name ();
|
||||||
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free,
|
g_free, mc_skin_hash_destroy_value);
|
||||||
mc_skin_hash_destroy_value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -97,7 +96,8 @@ mc_skin_try_to_load_default (void)
|
|||||||
mc_skin_reinit ();
|
mc_skin_reinit ();
|
||||||
g_free (mc_skin__default.name);
|
g_free (mc_skin__default.name);
|
||||||
mc_skin__default.name = g_strdup ("default");
|
mc_skin__default.name = g_strdup ("default");
|
||||||
if (!mc_skin_ini_file_load (&mc_skin__default)) {
|
if (!mc_skin_ini_file_load (&mc_skin__default))
|
||||||
|
{
|
||||||
mc_skin_reinit ();
|
mc_skin_reinit ();
|
||||||
mc_skin_set_hardcoded_skin (&mc_skin__default);
|
mc_skin_set_hardcoded_skin (&mc_skin__default);
|
||||||
}
|
}
|
||||||
@ -116,10 +116,10 @@ mc_skin_init (GError ** error)
|
|||||||
mc_skin__default.name = mc_skin_get_default_name ();
|
mc_skin__default.name = mc_skin_get_default_name ();
|
||||||
|
|
||||||
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free,
|
g_free, mc_skin_hash_destroy_value);
|
||||||
mc_skin_hash_destroy_value);
|
|
||||||
|
|
||||||
if (!mc_skin_ini_file_load (&mc_skin__default)) {
|
if (!mc_skin_ini_file_load (&mc_skin__default))
|
||||||
|
{
|
||||||
*error = g_error_new (MC_ERROR, 0,
|
*error = g_error_new (MC_ERROR, 0,
|
||||||
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
|
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
|
||||||
mc_skin__default.name);
|
mc_skin__default.name);
|
||||||
@ -129,7 +129,8 @@ mc_skin_init (GError ** error)
|
|||||||
}
|
}
|
||||||
mc_skin_colors_old_configure (&mc_skin__default);
|
mc_skin_colors_old_configure (&mc_skin__default);
|
||||||
|
|
||||||
if (!mc_skin_ini_file_parse (&mc_skin__default)) {
|
if (!mc_skin_ini_file_parse (&mc_skin__default))
|
||||||
|
{
|
||||||
if (*error == NULL)
|
if (*error == NULL)
|
||||||
*error = g_error_new (MC_ERROR, 0,
|
*error = g_error_new (MC_ERROR, 0,
|
||||||
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
|
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
|
||||||
@ -166,12 +167,13 @@ mc_skin_deinit (void)
|
|||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
mc_skin_get(const gchar *group, const gchar *key, const gchar *default_value)
|
mc_skin_get (const gchar * group, const gchar * key, const gchar * default_value)
|
||||||
{
|
{
|
||||||
if (mc_args__ugly_line_drawing) {
|
if (mc_args__ugly_line_drawing)
|
||||||
return g_strdup(default_value);
|
{
|
||||||
|
return g_strdup (default_value);
|
||||||
}
|
}
|
||||||
return mc_config_get_string(mc_skin__default.config, group, key, default_value);
|
return mc_config_get_string (mc_skin__default.config, group, key, default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -51,7 +51,8 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
|
|||||||
char *file_name, *file_name2;
|
char *file_name, *file_name2;
|
||||||
|
|
||||||
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
|
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, mc_skin->name, NULL);
|
||||||
if (exist_file (file_name)) {
|
if (exist_file (file_name))
|
||||||
|
{
|
||||||
mc_skin->config = mc_config_init (file_name);
|
mc_skin->config = mc_config_init (file_name);
|
||||||
g_free (file_name);
|
g_free (file_name);
|
||||||
return (mc_skin->config != NULL);
|
return (mc_skin->config != NULL);
|
||||||
@ -62,7 +63,8 @@ mc_skin_ini_file_load_search_in_dir (mc_skin_t * mc_skin, const gchar * base_dir
|
|||||||
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, file_name2, NULL);
|
file_name = g_build_filename (base_dir, MC_SKINS_SUBDIR, file_name2, NULL);
|
||||||
g_free (file_name2);
|
g_free (file_name2);
|
||||||
|
|
||||||
if (exist_file (file_name)) {
|
if (exist_file (file_name))
|
||||||
|
{
|
||||||
mc_skin->config = mc_config_init (file_name);
|
mc_skin->config = mc_config_init (file_name);
|
||||||
g_free (file_name);
|
g_free (file_name);
|
||||||
return (mc_skin->config != NULL);
|
return (mc_skin->config != NULL);
|
||||||
@ -84,7 +86,8 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
|||||||
if (file_name == NULL)
|
if (file_name == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (strcmp (file_name, mc_skin->name) != 0) {
|
if (strcmp (file_name, mc_skin->name) != 0)
|
||||||
|
{
|
||||||
g_free (file_name);
|
g_free (file_name);
|
||||||
if (!g_path_is_absolute (mc_skin->name))
|
if (!g_path_is_absolute (mc_skin->name))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -95,7 +98,8 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
|||||||
|
|
||||||
/* ~/.mc/skins/ */
|
/* ~/.mc/skins/ */
|
||||||
user_home_dir = concat_dir_and_file (home_dir, MC_USERCONF_DIR);
|
user_home_dir = concat_dir_and_file (home_dir, MC_USERCONF_DIR);
|
||||||
if (mc_skin_ini_file_load_search_in_dir (mc_skin, user_home_dir)) {
|
if (mc_skin_ini_file_load_search_in_dir (mc_skin, user_home_dir))
|
||||||
|
{
|
||||||
g_free (user_home_dir);
|
g_free (user_home_dir);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_skin_color_struct {
|
typedef struct mc_skin_color_struct
|
||||||
|
{
|
||||||
gchar *fgcolor;
|
gchar *fgcolor;
|
||||||
gchar *bgcolor;
|
gchar *bgcolor;
|
||||||
int pair_index;
|
int pair_index;
|
||||||
@ -35,4 +36,5 @@ void mc_skin_hardcoded_blackwhite_colors (mc_skin_t *);
|
|||||||
|
|
||||||
void mc_skin_colors_old_configure (mc_skin_t *);
|
void mc_skin_colors_old_configure (mc_skin_t *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "lib/global.h" /* <glib.h> */
|
#include "lib/global.h" /* <glib.h> */
|
||||||
|
|
||||||
/*** typedefs(not structures) and defined constants **********************************************/
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
191
lib/strutil.h
191
lib/strutil.h
@ -1,7 +1,7 @@
|
|||||||
#ifndef MC_STRUTIL_H
|
#ifndef MC_STRUTIL_H
|
||||||
#define MC_STRUTIL_H
|
#define MC_STRUTIL_H
|
||||||
|
|
||||||
#include "lib/global.h" /* include glib.h */
|
#include "lib/global.h" /* include glib.h */
|
||||||
|
|
||||||
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
|
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
|
||||||
* There are two sort of functions:
|
* There are two sort of functions:
|
||||||
@ -36,43 +36,107 @@
|
|||||||
* decompose form. (used in do_search (screen.c))
|
* decompose form. (used in do_search (screen.c))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define IS_FIT(x) ((x) & 0x0010)
|
||||||
|
#define MAKE_FIT(x) ((x) | 0x0010)
|
||||||
|
#define HIDE_FIT(x) ((x) & 0x000f)
|
||||||
|
|
||||||
|
#define INVALID_CONV ((GIConv) (-1))
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
/* results of conversion function
|
/* results of conversion function
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum
|
||||||
/* success means, that convertion has been finished successully
|
{
|
||||||
*/
|
/* success means, that convertion has been finished successully
|
||||||
|
*/
|
||||||
ESTR_SUCCESS = 0,
|
ESTR_SUCCESS = 0,
|
||||||
/* problem means, that not every characters was successfully converted (They are
|
/* problem means, that not every characters was successfully converted (They are
|
||||||
* replaced with questionmark). So is impossible convert string back.
|
* replaced with questionmark). So is impossible convert string back.
|
||||||
*/
|
*/
|
||||||
ESTR_PROBLEM = 1,
|
ESTR_PROBLEM = 1,
|
||||||
/* failure means, that conversion is not possible (example: wrong encoding
|
/* failure means, that conversion is not possible (example: wrong encoding
|
||||||
* of input string)
|
* of input string)
|
||||||
*/
|
*/
|
||||||
ESTR_FAILURE = 2
|
ESTR_FAILURE = 2
|
||||||
} estr_t;
|
} estr_t;
|
||||||
|
|
||||||
/* alignment strings on terminal
|
/* alignment strings on terminal
|
||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum
|
||||||
J_LEFT = 0x01,
|
{
|
||||||
J_RIGHT = 0x02,
|
J_LEFT = 0x01,
|
||||||
J_CENTER = 0x03,
|
J_RIGHT = 0x02,
|
||||||
|
J_CENTER = 0x03,
|
||||||
/* if there is enough space for string on terminal,
|
/* if there is enough space for string on terminal,
|
||||||
* string is centered otherwise is aligned to left */
|
* string is centered otherwise is aligned to left */
|
||||||
J_CENTER_LEFT = 0x04,
|
J_CENTER_LEFT = 0x04,
|
||||||
/* fit alignment, if string is to long, is truncated with '~' */
|
/* fit alignment, if string is to long, is truncated with '~' */
|
||||||
J_LEFT_FIT = 0x11,
|
J_LEFT_FIT = 0x11,
|
||||||
J_RIGHT_FIT = 0x12,
|
J_RIGHT_FIT = 0x12,
|
||||||
J_CENTER_FIT = 0x13,
|
J_CENTER_FIT = 0x13,
|
||||||
J_CENTER_LEFT_FIT = 0x14
|
J_CENTER_LEFT_FIT = 0x14
|
||||||
} align_crt_t;
|
} align_crt_t;
|
||||||
|
|
||||||
#define IS_FIT(x) ((x) & 0x0010)
|
|
||||||
#define MAKE_FIT(x) ((x) | 0x0010)
|
|
||||||
#define HIDE_FIT(x) ((x) & 0x000f)
|
|
||||||
|
|
||||||
#define INVALID_CONV ((GIConv) (-1))
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/* all functions in str_class must be defined for every encoding */
|
||||||
|
struct str_class
|
||||||
|
{
|
||||||
|
gchar *(*conv_gerror_message) (GError * error, const char *def_msg);
|
||||||
|
/*I*/ estr_t (*vfs_convert_to) (GIConv coder, const char *string, int size, GString * buffer);
|
||||||
|
/*I*/ void (*insert_replace_char) (GString * buffer);
|
||||||
|
int (*is_valid_string) (const char *);
|
||||||
|
/*I*/ int (*is_valid_char) (const char *, size_t);
|
||||||
|
/*I*/ void (*cnext_char) (const char **);
|
||||||
|
void (*cprev_char) (const char **);
|
||||||
|
void (*cnext_char_safe) (const char **);
|
||||||
|
/*I*/ void (*cprev_char_safe) (const char **);
|
||||||
|
/*I*/ int (*cnext_noncomb_char) (const char **text);
|
||||||
|
/*I*/ int (*cprev_noncomb_char) (const char **text, const char *begin);
|
||||||
|
/*I*/ int (*isspace) (const char *);
|
||||||
|
/*I*/ int (*ispunct) (const char *);
|
||||||
|
/*I*/ int (*isalnum) (const char *);
|
||||||
|
/*I*/ int (*isdigit) (const char *);
|
||||||
|
/*I*/ int (*isprint) (const char *);
|
||||||
|
/*I*/ int (*iscombiningmark) (const char *);
|
||||||
|
/*I*/ int (*length) (const char *);
|
||||||
|
/*I*/ int (*length2) (const char *, int);
|
||||||
|
/*I*/ int (*length_noncomb) (const char *);
|
||||||
|
/*I*/ int (*toupper) (const char *, char **, size_t *);
|
||||||
|
int (*tolower) (const char *, char **, size_t *);
|
||||||
|
void (*fix_string) (char *);
|
||||||
|
/*I*/ const char *(*term_form) (const char *);
|
||||||
|
/*I*/ const char *(*fit_to_term) (const char *, int, align_crt_t);
|
||||||
|
/*I*/ const char *(*term_trim) (const char *text, int width);
|
||||||
|
/*I*/ void (*msg_term_size) (const char *, int *, int *);
|
||||||
|
/*I*/ const char *(*term_substring) (const char *, int, int);
|
||||||
|
/*I*/ int (*term_width1) (const char *);
|
||||||
|
/*I*/ int (*term_width2) (const char *, size_t);
|
||||||
|
/*I*/ int (*term_char_width) (const char *);
|
||||||
|
/*I*/ const char *(*trunc) (const char *, int);
|
||||||
|
/*I*/ int (*offset_to_pos) (const char *, size_t);
|
||||||
|
/*I*/ int (*column_to_pos) (const char *, size_t);
|
||||||
|
/*I*/ char *(*create_search_needle) (const char *, int);
|
||||||
|
void (*release_search_needle) (char *, int);
|
||||||
|
const char *(*search_first) (const char *, const char *, int);
|
||||||
|
const char *(*search_last) (const char *, const char *, int);
|
||||||
|
int (*compare) (const char *, const char *);
|
||||||
|
/*I*/ int (*ncompare) (const char *, const char *);
|
||||||
|
/*I*/ int (*casecmp) (const char *, const char *);
|
||||||
|
/*I*/ int (*ncasecmp) (const char *, const char *);
|
||||||
|
/*I*/ int (*prefix) (const char *, const char *);
|
||||||
|
/*I*/ int (*caseprefix) (const char *, const char *);
|
||||||
|
/*I*/ char *(*create_key) (const char *text, int case_sen);
|
||||||
|
/*I*/ char *(*create_key_for_filename) (const char *text, int case_sen);
|
||||||
|
/*I*/ int (*key_collate) (const char *t1, const char *t2, int case_sen);
|
||||||
|
/*I*/ void (*release_key) (char *key, int case_sen);
|
||||||
|
/*I*/};
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
/* standard convertors */
|
/* standard convertors */
|
||||||
extern GIConv str_cnv_to_term;
|
extern GIConv str_cnv_to_term;
|
||||||
@ -80,58 +144,7 @@ extern GIConv str_cnv_from_term;
|
|||||||
/* from terminal encoding to terminal encoding */
|
/* from terminal encoding to terminal encoding */
|
||||||
extern GIConv str_cnv_not_convert;
|
extern GIConv str_cnv_not_convert;
|
||||||
|
|
||||||
/* all functions in str_class must be defined for every encoding */
|
/*** declarations of public functions ************************************************************/
|
||||||
struct str_class {
|
|
||||||
gchar *(*conv_gerror_message) (GError *error, const char *def_msg); /*I*/
|
|
||||||
estr_t (*vfs_convert_to) (GIConv coder, const char *string,
|
|
||||||
int size, GString *buffer); /*I*/
|
|
||||||
void (*insert_replace_char) (GString *buffer);
|
|
||||||
int (*is_valid_string) (const char *); /*I*/
|
|
||||||
int (*is_valid_char) (const char *, size_t); /*I*/
|
|
||||||
void (*cnext_char) (const char **);
|
|
||||||
void (*cprev_char) (const char **);
|
|
||||||
void (*cnext_char_safe) (const char **); /*I*/
|
|
||||||
void (*cprev_char_safe) (const char **); /*I*/
|
|
||||||
int (*cnext_noncomb_char) (const char **text); /*I*/
|
|
||||||
int (*cprev_noncomb_char) (const char **text, const char *begin); /*I*/
|
|
||||||
int (*isspace) (const char *); /*I*/
|
|
||||||
int (*ispunct) (const char *); /*I*/
|
|
||||||
int (*isalnum) (const char *); /*I*/
|
|
||||||
int (*isdigit) (const char *); /*I*/
|
|
||||||
int (*isprint) (const char *); /*I*/
|
|
||||||
int (*iscombiningmark) (const char *); /*I*/
|
|
||||||
int (*length) (const char *); /*I*/
|
|
||||||
int (*length2) (const char *, int); /*I*/
|
|
||||||
int (*length_noncomb) (const char *); /*I*/
|
|
||||||
int (*toupper) (const char *, char **, size_t *);
|
|
||||||
int (*tolower) (const char *, char **, size_t *);
|
|
||||||
void (*fix_string) (char *); /*I*/
|
|
||||||
const char *(*term_form) (const char *); /*I*/
|
|
||||||
const char *(*fit_to_term) (const char *, int, align_crt_t); /*I*/
|
|
||||||
const char *(*term_trim) (const char *text, int width); /*I*/
|
|
||||||
void (*msg_term_size) (const char *, int *, int *); /*I*/
|
|
||||||
const char *(*term_substring) (const char *, int, int); /*I*/
|
|
||||||
int (*term_width1) (const char *); /*I*/
|
|
||||||
int (*term_width2) (const char *, size_t); /*I*/
|
|
||||||
int (*term_char_width) (const char *); /*I*/
|
|
||||||
const char *(*trunc) (const char *, int); /*I*/
|
|
||||||
int (*offset_to_pos) (const char *, size_t); /*I*/
|
|
||||||
int (*column_to_pos) (const char *, size_t); /*I*/
|
|
||||||
char *(*create_search_needle) (const char *, int);
|
|
||||||
void (*release_search_needle) (char *, int);
|
|
||||||
const char *(*search_first) (const char *, const char *, int);
|
|
||||||
const char *(*search_last) (const char *, const char *, int);
|
|
||||||
int (*compare) (const char *, const char *); /*I*/
|
|
||||||
int (*ncompare) (const char *, const char *); /*I*/
|
|
||||||
int (*casecmp) (const char *, const char *); /*I*/
|
|
||||||
int (*ncasecmp) (const char *, const char *); /*I*/
|
|
||||||
int (*prefix) (const char *, const char *); /*I*/
|
|
||||||
int (*caseprefix) (const char *, const char *); /*I*/
|
|
||||||
char *(*create_key) (const char *text, int case_sen); /*I*/
|
|
||||||
char *(*create_key_for_filename) (const char *text, int case_sen); /*I*/
|
|
||||||
int (*key_collate) (const char *t1, const char *t2, int case_sen); /*I*/
|
|
||||||
void (*release_key) (char *key, int case_sen); /*I*/
|
|
||||||
};
|
|
||||||
|
|
||||||
struct str_class str_utf8_init (void);
|
struct str_class str_utf8_init (void);
|
||||||
struct str_class str_8bit_init (void);
|
struct str_class str_8bit_init (void);
|
||||||
@ -168,7 +181,7 @@ estr_t str_nconvert (GIConv, const char *, int, GString *);
|
|||||||
* return new allocated null-terminated string, which is need to be freed
|
* return new allocated null-terminated string, which is need to be freed
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
gchar *str_conv_gerror_message (GError *error, const char *def_msg);
|
gchar *str_conv_gerror_message (GError * error, const char *def_msg);
|
||||||
|
|
||||||
/* return only ESTR_SUCCESS or ESTR_FAILURE, because vfs must be able to convert
|
/* return only ESTR_SUCCESS or ESTR_FAILURE, because vfs must be able to convert
|
||||||
* result to original string. (so no replace with questionmark)
|
* result to original string. (so no replace with questionmark)
|
||||||
@ -185,8 +198,7 @@ estr_t str_vfs_convert_to (GIConv, const char *, int, GString *);
|
|||||||
|
|
||||||
/* printf functin for str_buffer, append result of printf at the end of buffer
|
/* printf functin for str_buffer, append result of printf at the end of buffer
|
||||||
*/
|
*/
|
||||||
void
|
void str_printf (GString *, const char *, ...);
|
||||||
str_printf (GString *, const char *, ...);
|
|
||||||
|
|
||||||
/* add standard replacement character in terminal encoding
|
/* add standard replacement character in terminal encoding
|
||||||
*/
|
*/
|
||||||
@ -210,7 +222,7 @@ void str_uninit_strings (void);
|
|||||||
* ESTR_FAILURE if conversion is not possible
|
* ESTR_FAILURE if conversion is not possible
|
||||||
*/
|
*/
|
||||||
estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
|
estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
|
||||||
char *output, size_t out_size);
|
char *output, size_t out_size);
|
||||||
|
|
||||||
/* test, if text is valid in terminal encoding
|
/* test, if text is valid in terminal encoding
|
||||||
* I
|
* I
|
||||||
@ -324,23 +336,23 @@ int str_iscombiningmark (const char *ch);
|
|||||||
* decrase remain by size of returned characters
|
* decrase remain by size of returned characters
|
||||||
* if out is not big enough, do nothing
|
* if out is not big enough, do nothing
|
||||||
*/
|
*/
|
||||||
int str_toupper (const char *ch, char **out, size_t *remain);
|
int str_toupper (const char *ch, char **out, size_t * remain);
|
||||||
|
|
||||||
/* write upper from of fisrt characters in ch into out
|
/* write upper from of fisrt characters in ch into out
|
||||||
* decrase remain by size of returned characters
|
* decrase remain by size of returned characters
|
||||||
* if out is not big enough, do nothing
|
* if out is not big enough, do nothing
|
||||||
*/
|
*/
|
||||||
int str_tolower (const char *ch, char **out, size_t *remain);
|
int str_tolower (const char *ch, char **out, size_t * remain);
|
||||||
|
|
||||||
/* return length of text in characters
|
/* return length of text in characters
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
int str_length (const char* text);
|
int str_length (const char *text);
|
||||||
|
|
||||||
/* return length of text in characters, limit to size
|
/* return length of text in characters, limit to size
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
int str_length2 (const char* text, int size);
|
int str_length2 (const char *text, int size);
|
||||||
|
|
||||||
/* return length of one char
|
/* return length of one char
|
||||||
* I
|
* I
|
||||||
@ -350,13 +362,13 @@ int str_length_char (const char *);
|
|||||||
/* return length of text in characters, count only noncombining characters
|
/* return length of text in characters, count only noncombining characters
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
int str_length_noncomb (const char* text);
|
int str_length_noncomb (const char *text);
|
||||||
|
|
||||||
/* replace all invalid characters in text with questionmark
|
/* replace all invalid characters in text with questionmark
|
||||||
* after return, text is valid string in terminal encoding
|
* after return, text is valid string in terminal encoding
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
void str_fix_string (char* text);
|
void str_fix_string (char *text);
|
||||||
|
|
||||||
/* replace all invalid characters in text with questionmark
|
/* replace all invalid characters in text with questionmark
|
||||||
* replace all unprintable characters with '.'
|
* replace all unprintable characters with '.'
|
||||||
@ -412,7 +424,7 @@ int str_term_char_width (const char *text);
|
|||||||
/* convert position in characters to position in bytes
|
/* convert position in characters to position in bytes
|
||||||
* I
|
* I
|
||||||
*/
|
*/
|
||||||
int str_offset_to_pos (const char* text, size_t length);
|
int str_offset_to_pos (const char *text, size_t length);
|
||||||
|
|
||||||
/* convert position on terminal to position in characters
|
/* convert position on terminal to position in characters
|
||||||
* I
|
* I
|
||||||
@ -508,5 +520,8 @@ int str_isutf8 (const char *codeset_name);
|
|||||||
|
|
||||||
const char *str_detect_termencoding (void);
|
const char *str_detect_termencoding (void);
|
||||||
|
|
||||||
int str_verscmp(const char *s1, const char *s2);
|
int str_verscmp (const char *s1, const char *s2);
|
||||||
#endif /* MC_STRUTIL_H*/
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* MC_STRUTIL_H */
|
||||||
|
@ -35,12 +35,12 @@
|
|||||||
|
|
||||||
/*names, that are used for utf-8 */
|
/*names, that are used for utf-8 */
|
||||||
static const char *str_utf8_encodings[] = {
|
static const char *str_utf8_encodings[] = {
|
||||||
"utf-8",
|
"utf-8",
|
||||||
"utf8",
|
"utf8",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* standard 8bit encodings, no wide or multibytes characters*/
|
/* standard 8bit encodings, no wide or multibytes characters */
|
||||||
static const char *str_8bit_encodings[] = {
|
static const char *str_8bit_encodings[] = {
|
||||||
"cp-1251",
|
"cp-1251",
|
||||||
"cp1251",
|
"cp1251",
|
||||||
@ -60,16 +60,16 @@ static const char *str_8bit_encodings[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* terminal encoding*/
|
/* terminal encoding */
|
||||||
static char *codeset = NULL;
|
static char *codeset = NULL;
|
||||||
/* function for encoding specific operations*/
|
/* function for encoding specific operations */
|
||||||
static struct str_class used_class;
|
static struct str_class used_class;
|
||||||
|
|
||||||
GIConv str_cnv_to_term;
|
GIConv str_cnv_to_term;
|
||||||
GIConv str_cnv_from_term;
|
GIConv str_cnv_from_term;
|
||||||
GIConv str_cnv_not_convert;
|
GIConv str_cnv_not_convert;
|
||||||
|
|
||||||
/* if enc is same encoding like on terminal*/
|
/* if enc is same encoding like on terminal */
|
||||||
static int
|
static int
|
||||||
str_test_not_convert (const char *enc)
|
str_test_not_convert (const char *enc)
|
||||||
{
|
{
|
||||||
@ -79,28 +79,27 @@ str_test_not_convert (const char *enc)
|
|||||||
GIConv
|
GIConv
|
||||||
str_crt_conv_to (const char *to_enc)
|
str_crt_conv_to (const char *to_enc)
|
||||||
{
|
{
|
||||||
return (!str_test_not_convert (to_enc))
|
return (!str_test_not_convert (to_enc)) ? g_iconv_open (to_enc, codeset) : str_cnv_not_convert;
|
||||||
? g_iconv_open (to_enc, codeset) : str_cnv_not_convert;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GIConv
|
GIConv
|
||||||
str_crt_conv_from (const char *from_enc)
|
str_crt_conv_from (const char *from_enc)
|
||||||
{
|
{
|
||||||
return (!str_test_not_convert (from_enc))
|
return (!str_test_not_convert (from_enc))
|
||||||
? g_iconv_open (codeset, from_enc) : str_cnv_not_convert;
|
? g_iconv_open (codeset, from_enc) : str_cnv_not_convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
str_close_conv (GIConv conv)
|
str_close_conv (GIConv conv)
|
||||||
{
|
{
|
||||||
if (conv != str_cnv_not_convert)
|
if (conv != str_cnv_not_convert)
|
||||||
g_iconv_close (conv);
|
g_iconv_close (conv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static estr_t
|
static estr_t
|
||||||
_str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
_str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||||
{
|
{
|
||||||
estr_t state = ESTR_SUCCESS;
|
estr_t state = ESTR_SUCCESS;
|
||||||
gchar *tmp_buff = NULL;
|
gchar *tmp_buff = NULL;
|
||||||
gssize left;
|
gssize left;
|
||||||
gsize bytes_read = 0;
|
gsize bytes_read = 0;
|
||||||
@ -109,26 +108,26 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
if (coder == INVALID_CONV)
|
if (coder == INVALID_CONV)
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
|
|
||||||
if (string == NULL || buffer == NULL)
|
if (string == NULL || buffer == NULL)
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (! used_class.is_valid_string (string))
|
if (! used_class.is_valid_string (string))
|
||||||
{
|
{
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
{
|
{
|
||||||
size = strlen (string);
|
size = strlen (string);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
left = strlen (string);
|
left = strlen (string);
|
||||||
if (left < size)
|
if (left < size)
|
||||||
size = left;
|
size = left;
|
||||||
}
|
}
|
||||||
|
|
||||||
left = size;
|
left = size;
|
||||||
@ -136,100 +135,96 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
|||||||
|
|
||||||
while (left)
|
while (left)
|
||||||
{
|
{
|
||||||
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
||||||
left,
|
left, coder, &bytes_read, &bytes_written, &error);
|
||||||
coder,
|
if (error)
|
||||||
&bytes_read,
|
{
|
||||||
&bytes_written, &error);
|
int code = error->code;
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
int code = error->code;
|
|
||||||
|
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
error = NULL;
|
error = NULL;
|
||||||
|
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
case G_CONVERT_ERROR_NO_CONVERSION:
|
case G_CONVERT_ERROR_NO_CONVERSION:
|
||||||
/* Conversion between the requested character sets is not supported. */
|
/* Conversion between the requested character sets is not supported. */
|
||||||
tmp_buff = g_strnfill (strlen (string), '?');
|
tmp_buff = g_strnfill (strlen (string), '?');
|
||||||
g_string_append (buffer, tmp_buff);
|
g_string_append (buffer, tmp_buff);
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
|
|
||||||
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
|
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
|
||||||
/* Invalid byte sequence in conversion input. */
|
/* Invalid byte sequence in conversion input. */
|
||||||
if ((tmp_buff == NULL) && (bytes_read != 0))
|
if ((tmp_buff == NULL) && (bytes_read != 0))
|
||||||
/* recode valid byte sequence */
|
/* recode valid byte sequence */
|
||||||
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
||||||
bytes_read,
|
bytes_read, coder, NULL, NULL, NULL);
|
||||||
coder, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
if (tmp_buff != NULL)
|
if (tmp_buff != NULL)
|
||||||
{
|
{
|
||||||
g_string_append (buffer, tmp_buff);
|
g_string_append (buffer, tmp_buff);
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)bytes_read < left)
|
if ((int) bytes_read < left)
|
||||||
{
|
{
|
||||||
string += bytes_read + 1;
|
string += bytes_read + 1;
|
||||||
size -= (bytes_read + 1);
|
size -= (bytes_read + 1);
|
||||||
left -= (bytes_read + 1);
|
left -= (bytes_read + 1);
|
||||||
g_string_append_c (buffer, *(string-1));
|
g_string_append_c (buffer, *(string - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ESTR_PROBLEM;
|
return ESTR_PROBLEM;
|
||||||
}
|
}
|
||||||
state = ESTR_PROBLEM;
|
state = ESTR_PROBLEM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G_CONVERT_ERROR_PARTIAL_INPUT:
|
case G_CONVERT_ERROR_PARTIAL_INPUT:
|
||||||
/* Partial character sequence at end of input. */
|
/* Partial character sequence at end of input. */
|
||||||
g_string_append (buffer, tmp_buff);
|
g_string_append (buffer, tmp_buff);
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
if ((int)bytes_read < left)
|
if ((int) bytes_read < left)
|
||||||
{
|
{
|
||||||
left = left - bytes_read;
|
left = left - bytes_read;
|
||||||
tmp_buff = g_strnfill (left, '?');
|
tmp_buff = g_strnfill (left, '?');
|
||||||
g_string_append (buffer, tmp_buff);
|
g_string_append (buffer, tmp_buff);
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
}
|
}
|
||||||
return ESTR_PROBLEM;
|
return ESTR_PROBLEM;
|
||||||
|
|
||||||
case G_CONVERT_ERROR_BAD_URI: /* Don't know how handle this error :( */
|
case G_CONVERT_ERROR_BAD_URI: /* Don't know how handle this error :( */
|
||||||
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
|
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
|
||||||
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
|
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
|
||||||
default:
|
default:
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
return ESTR_FAILURE;
|
return ESTR_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tmp_buff != NULL)
|
if (tmp_buff != NULL)
|
||||||
{
|
{
|
||||||
if (*tmp_buff)
|
if (*tmp_buff)
|
||||||
{
|
{
|
||||||
g_string_append (buffer, tmp_buff);
|
g_string_append (buffer, tmp_buff);
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
string += bytes_read;
|
string += bytes_read;
|
||||||
left -= bytes_read;
|
left -= bytes_read;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_free (tmp_buff);
|
g_free (tmp_buff);
|
||||||
g_string_append (buffer, string);
|
g_string_append (buffer, string);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_string_append (buffer, string);
|
g_string_append (buffer, string);
|
||||||
return ESTR_PROBLEM;
|
return ESTR_PROBLEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -247,7 +242,7 @@ str_nconvert (GIConv coder, const char *string, int size, GString * buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
str_conv_gerror_message (GError *error, const char *def_msg)
|
str_conv_gerror_message (GError * error, const char *def_msg)
|
||||||
{
|
{
|
||||||
return used_class.conv_gerror_message (error, def_msg);
|
return used_class.conv_gerror_message (error, def_msg);
|
||||||
}
|
}
|
||||||
@ -259,18 +254,17 @@ str_vfs_convert_from (GIConv coder, const char *string, GString * buffer)
|
|||||||
|
|
||||||
if (coder == str_cnv_not_convert)
|
if (coder == str_cnv_not_convert)
|
||||||
{
|
{
|
||||||
g_string_append (buffer, string != NULL ? string : "");
|
g_string_append (buffer, string != NULL ? string : "");
|
||||||
result = ESTR_SUCCESS;
|
result = ESTR_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = _str_convert (coder, string, -1, buffer);
|
result = _str_convert (coder, string, -1, buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
estr_t
|
estr_t
|
||||||
str_vfs_convert_to (GIConv coder, const char *string, int size,
|
str_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||||
GString * buffer)
|
|
||||||
{
|
{
|
||||||
return used_class.vfs_convert_to (coder, string, size, buffer);
|
return used_class.vfs_convert_to (coder, string, size, buffer);
|
||||||
}
|
}
|
||||||
@ -284,10 +278,10 @@ str_printf (GString * buffer, const char *format, ...)
|
|||||||
g_string_append_vprintf (buffer, format, ap);
|
g_string_append_vprintf (buffer, format, ap);
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
tmp = g_strdup_vprintf (format, ap);
|
tmp = g_strdup_vprintf (format, ap);
|
||||||
g_string_append (buffer, tmp);
|
g_string_append (buffer, tmp);
|
||||||
g_free(tmp);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
@ -300,8 +294,7 @@ str_insert_replace_char (GString * buffer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
estr_t
|
estr_t
|
||||||
str_translate_char (GIConv conv, const char *keys, size_t ch_size,
|
str_translate_char (GIConv conv, const char *keys, size_t ch_size, char *output, size_t out_size)
|
||||||
char *output, size_t out_size)
|
|
||||||
{
|
{
|
||||||
size_t left;
|
size_t left;
|
||||||
size_t cnv;
|
size_t cnv;
|
||||||
@ -310,10 +303,13 @@ str_translate_char (GIConv conv, const char *keys, size_t ch_size,
|
|||||||
|
|
||||||
left = (ch_size == (size_t) (-1)) ? strlen (keys) : ch_size;
|
left = (ch_size == (size_t) (-1)) ? strlen (keys) : ch_size;
|
||||||
|
|
||||||
cnv = g_iconv (conv, (gchar **) &keys, &left, &output, &out_size);
|
cnv = g_iconv (conv, (gchar **) & keys, &left, &output, &out_size);
|
||||||
if (cnv == (size_t)(-1)) {
|
if (cnv == (size_t) (-1))
|
||||||
|
{
|
||||||
return (errno == EINVAL) ? ESTR_PROBLEM : ESTR_FAILURE;
|
return (errno == EINVAL) ? ESTR_PROBLEM : ESTR_FAILURE;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
output[0] = '\0';
|
output[0] = '\0';
|
||||||
return ESTR_SUCCESS;
|
return ESTR_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -331,13 +327,12 @@ str_test_encoding_class (const char *encoding, const char **table)
|
|||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if ( encoding == NULL )
|
if (encoding == NULL)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
for (t = 0; table[t] != NULL; t++)
|
for (t = 0; table[t] != NULL; t++)
|
||||||
{
|
{
|
||||||
result += (g_ascii_strncasecmp (encoding, table[t],
|
result += (g_ascii_strncasecmp (encoding, table[t], strlen (table[t])) == 0);
|
||||||
strlen (table[t])) == 0);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -347,15 +342,15 @@ str_choose_str_functions ()
|
|||||||
{
|
{
|
||||||
if (str_test_encoding_class (codeset, str_utf8_encodings))
|
if (str_test_encoding_class (codeset, str_utf8_encodings))
|
||||||
{
|
{
|
||||||
used_class = str_utf8_init ();
|
used_class = str_utf8_init ();
|
||||||
}
|
}
|
||||||
else if (str_test_encoding_class (codeset, str_8bit_encodings))
|
else if (str_test_encoding_class (codeset, str_8bit_encodings))
|
||||||
{
|
{
|
||||||
used_class = str_8bit_init ();
|
used_class = str_8bit_init ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
used_class = str_ascii_init ();
|
used_class = str_ascii_init ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +360,7 @@ str_isutf8 (const char *codeset_name)
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
if (str_test_encoding_class (codeset_name, str_utf8_encodings))
|
if (str_test_encoding_class (codeset_name, str_utf8_encodings))
|
||||||
{
|
{
|
||||||
result = 1;
|
result = 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -373,26 +368,24 @@ str_isutf8 (const char *codeset_name)
|
|||||||
void
|
void
|
||||||
str_init_strings (const char *termenc)
|
str_init_strings (const char *termenc)
|
||||||
{
|
{
|
||||||
codeset = g_strdup ((termenc != NULL)
|
codeset = g_strdup ((termenc != NULL) ? termenc : str_detect_termencoding ());
|
||||||
? termenc
|
|
||||||
: str_detect_termencoding ());
|
|
||||||
|
|
||||||
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
||||||
if (str_cnv_not_convert == INVALID_CONV)
|
if (str_cnv_not_convert == INVALID_CONV)
|
||||||
{
|
{
|
||||||
if (termenc != NULL)
|
if (termenc != NULL)
|
||||||
{
|
{
|
||||||
g_free (codeset);
|
g_free (codeset);
|
||||||
codeset = g_strdup (str_detect_termencoding ());
|
codeset = g_strdup (str_detect_termencoding ());
|
||||||
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_cnv_not_convert == INVALID_CONV)
|
if (str_cnv_not_convert == INVALID_CONV)
|
||||||
{
|
{
|
||||||
g_free (codeset);
|
g_free (codeset);
|
||||||
codeset = g_strdup ("ascii");
|
codeset = g_strdup ("ascii");
|
||||||
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
str_cnv_to_term = str_cnv_not_convert;
|
str_cnv_to_term = str_cnv_not_convert;
|
||||||
@ -405,7 +398,7 @@ void
|
|||||||
str_uninit_strings (void)
|
str_uninit_strings (void)
|
||||||
{
|
{
|
||||||
if (str_cnv_not_convert != INVALID_CONV)
|
if (str_cnv_not_convert != INVALID_CONV)
|
||||||
g_iconv_close (str_cnv_not_convert);
|
g_iconv_close (str_cnv_not_convert);
|
||||||
g_free (codeset);
|
g_free (codeset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,7 +443,7 @@ str_get_next_char (char *text)
|
|||||||
const char *
|
const char *
|
||||||
str_cget_next_char (const char *text)
|
str_cget_next_char (const char *text)
|
||||||
{
|
{
|
||||||
used_class.cnext_char(&text);
|
used_class.cnext_char (&text);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +600,7 @@ str_length (const char *text)
|
|||||||
int
|
int
|
||||||
str_length_char (const char *text)
|
str_length_char (const char *text)
|
||||||
{
|
{
|
||||||
return str_cget_next_char_safe (text)-text;
|
return str_cget_next_char_safe (text) - text;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -52,24 +52,21 @@ static inline int char_##func_name(char c) \
|
|||||||
return func_name((int)(unsigned char)c); \
|
return func_name((int)(unsigned char)c); \
|
||||||
}
|
}
|
||||||
|
|
||||||
DECLARE_CTYPE_WRAPPER(isalnum)
|
DECLARE_CTYPE_WRAPPER (isalnum)
|
||||||
DECLARE_CTYPE_WRAPPER(isalpha)
|
DECLARE_CTYPE_WRAPPER (isalpha)
|
||||||
DECLARE_CTYPE_WRAPPER(isascii)
|
DECLARE_CTYPE_WRAPPER (isascii)
|
||||||
DECLARE_CTYPE_WRAPPER(isblank)
|
DECLARE_CTYPE_WRAPPER (isblank)
|
||||||
DECLARE_CTYPE_WRAPPER(iscntrl)
|
DECLARE_CTYPE_WRAPPER (iscntrl)
|
||||||
DECLARE_CTYPE_WRAPPER(isdigit)
|
DECLARE_CTYPE_WRAPPER (isdigit)
|
||||||
DECLARE_CTYPE_WRAPPER(isgraph)
|
DECLARE_CTYPE_WRAPPER (isgraph)
|
||||||
DECLARE_CTYPE_WRAPPER(islower)
|
DECLARE_CTYPE_WRAPPER (islower)
|
||||||
DECLARE_CTYPE_WRAPPER(isprint)
|
DECLARE_CTYPE_WRAPPER (isprint)
|
||||||
DECLARE_CTYPE_WRAPPER(ispunct)
|
DECLARE_CTYPE_WRAPPER (ispunct)
|
||||||
DECLARE_CTYPE_WRAPPER(isspace)
|
DECLARE_CTYPE_WRAPPER (isspace)
|
||||||
DECLARE_CTYPE_WRAPPER(isupper)
|
DECLARE_CTYPE_WRAPPER (isupper)
|
||||||
DECLARE_CTYPE_WRAPPER(isxdigit)
|
DECLARE_CTYPE_WRAPPER (isxdigit) DECLARE_CTYPE_WRAPPER (toupper) DECLARE_CTYPE_WRAPPER (tolower)
|
||||||
DECLARE_CTYPE_WRAPPER(toupper)
|
static void
|
||||||
DECLARE_CTYPE_WRAPPER(tolower)
|
str_8bit_insert_replace_char (GString * buffer)
|
||||||
|
|
||||||
static void
|
|
||||||
str_8bit_insert_replace_char (GString * buffer)
|
|
||||||
{
|
{
|
||||||
g_string_append_c (buffer, replch);
|
g_string_append_c (buffer, replch);
|
||||||
}
|
}
|
||||||
@ -106,11 +103,11 @@ str_8bit_cnext_noncomb_char (const char **text)
|
|||||||
{
|
{
|
||||||
if (*text[0] != '\0')
|
if (*text[0] != '\0')
|
||||||
{
|
{
|
||||||
(*text)++;
|
(*text)++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -118,11 +115,11 @@ str_8bit_cprev_noncomb_char (const char **text, const char *begin)
|
|||||||
{
|
{
|
||||||
if ((*text) != begin)
|
if ((*text) != begin)
|
||||||
{
|
{
|
||||||
(*text)--;
|
(*text)--;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -166,7 +163,7 @@ static int
|
|||||||
str_8bit_toupper (const char *text, char **out, size_t * remain)
|
str_8bit_toupper (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1)
|
if (*remain <= 1)
|
||||||
return 0;
|
return 0;
|
||||||
(*out)[0] = char_toupper (text[0]);
|
(*out)[0] = char_toupper (text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -177,7 +174,7 @@ static int
|
|||||||
str_8bit_tolower (const char *text, char **out, size_t * remain)
|
str_8bit_tolower (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1)
|
if (*remain <= 1)
|
||||||
return 0;
|
return 0;
|
||||||
(*out)[0] = char_tolower (text[0]);
|
(*out)[0] = char_tolower (text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -193,11 +190,11 @@ str_8bit_length (const char *text)
|
|||||||
static int
|
static int
|
||||||
str_8bit_length2 (const char *text, int size)
|
str_8bit_length2 (const char *text, int size)
|
||||||
{
|
{
|
||||||
return (size >= 0) ? min (strlen (text), (gsize)size) : strlen (text);
|
return (size >= 0) ? min (strlen (text), (gsize) size) : strlen (text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
str_8bit_conv_gerror_message (GError * error, const char *def_msg)
|
||||||
{
|
{
|
||||||
GIConv conv;
|
GIConv conv;
|
||||||
gchar *ret;
|
gchar *ret;
|
||||||
@ -207,15 +204,19 @@ str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
|||||||
|
|
||||||
if (conv == INVALID_CONV)
|
if (conv == INVALID_CONV)
|
||||||
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
GString *buf;
|
GString *buf;
|
||||||
|
|
||||||
buf = g_string_new ("");
|
buf = g_string_new ("");
|
||||||
|
|
||||||
if (str_convert (conv, error->message, buf) != ESTR_FAILURE) {
|
if (str_convert (conv, error->message, buf) != ESTR_FAILURE)
|
||||||
|
{
|
||||||
ret = buf->str;
|
ret = buf->str;
|
||||||
g_string_free (buf, FALSE);
|
g_string_free (buf, FALSE);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
||||||
g_string_free (buf, TRUE);
|
g_string_free (buf, TRUE);
|
||||||
}
|
}
|
||||||
@ -227,18 +228,17 @@ str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static estr_t
|
static estr_t
|
||||||
str_8bit_vfs_convert_to (GIConv coder, const char *string,
|
str_8bit_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||||
int size, GString * buffer)
|
|
||||||
{
|
{
|
||||||
estr_t result;
|
estr_t result;
|
||||||
|
|
||||||
if (coder == str_cnv_not_convert)
|
if (coder == str_cnv_not_convert)
|
||||||
{
|
{
|
||||||
g_string_append_len (buffer, string, size);
|
g_string_append_len (buffer, string, size);
|
||||||
result = ESTR_SUCCESS;
|
result = ESTR_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result = str_nconvert (coder, (char *) string, size, buffer);
|
result = str_nconvert (coder, (char *) string, size, buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ str_8bit_term_form (const char *text)
|
|||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -280,85 +280,83 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if ((int)length <= width)
|
if ((int) length <= width)
|
||||||
{
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode))
|
switch (HIDE_FIT (just_mode))
|
||||||
{
|
{
|
||||||
case J_CENTER_LEFT:
|
case J_CENTER_LEFT:
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (width - length) / 2;
|
ident = (width - length) / 2;
|
||||||
break;
|
break;
|
||||||
case J_RIGHT:
|
case J_RIGHT:
|
||||||
ident = width - length;
|
ident = width - length;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int)remain <= ident)
|
if ((int) remain <= ident)
|
||||||
goto finally;
|
goto finally;
|
||||||
memset (actual, ' ', ident);
|
memset (actual, ' ', ident);
|
||||||
actual += ident;
|
actual += ident;
|
||||||
remain -= ident;
|
remain -= ident;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
if (width - length - ident > 0)
|
if (width - length - ident > 0)
|
||||||
{
|
{
|
||||||
if (remain <= width - length - ident)
|
if (remain <= width - length - ident)
|
||||||
goto finally;
|
goto finally;
|
||||||
memset (actual, ' ', width - length - ident);
|
memset (actual, ' ', width - length - ident);
|
||||||
actual += width - length - ident;
|
actual += width - length - ident;
|
||||||
remain -= width - length - ident;
|
remain -= width - length - ident;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IS_FIT (just_mode))
|
if (IS_FIT (just_mode))
|
||||||
{
|
{
|
||||||
for (; pos + 1 <= (gsize)width / 2 && remain > 1;
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
actual++, pos++, remain--)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1)
|
if (remain <= 1)
|
||||||
goto finally;
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode))
|
switch (HIDE_FIT (just_mode))
|
||||||
{
|
{
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (length - width) / 2;
|
ident = (length - width) / 2;
|
||||||
break;
|
break;
|
||||||
case J_RIGHT:
|
case J_RIGHT:
|
||||||
ident = length - width;
|
ident = length - width;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos += ident;
|
pos += ident;
|
||||||
for (; pos < (gsize)(ident + width) && remain > 1;
|
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
|
||||||
pos++, actual++, remain--)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -378,34 +376,34 @@ str_8bit_term_trim (const char *text, int width)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (width < (int)length)
|
if (width < (int) length)
|
||||||
{
|
{
|
||||||
if (width <= 3)
|
if (width <= 3)
|
||||||
{
|
{
|
||||||
memset (actual, '.', width);
|
memset (actual, '.', width);
|
||||||
actual += width;
|
actual += width;
|
||||||
remain -= width;
|
remain -= width;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset (actual, '.', 3);
|
memset (actual, '.', 3);
|
||||||
actual += 3;
|
actual += 3;
|
||||||
remain -= 3;
|
remain -= 3;
|
||||||
|
|
||||||
pos += length - width + 3;
|
pos += length - width + 3;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -415,8 +413,7 @@ str_8bit_term_trim (const char *text, int width)
|
|||||||
static int
|
static int
|
||||||
str_8bit_term_width2 (const char *text, size_t length)
|
str_8bit_term_width2 (const char *text, size_t length)
|
||||||
{
|
{
|
||||||
return (length != (size_t) (-1))
|
return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text);
|
||||||
? min (strlen (text), length) : strlen (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -443,26 +440,26 @@ str_8bit_msg_term_size (const char *text, int *lines, int *columns)
|
|||||||
|
|
||||||
(*lines) = 1;
|
(*lines) = 1;
|
||||||
(*columns) = 0;
|
(*columns) = 0;
|
||||||
tmp = g_strdup ((char *)text);
|
tmp = g_strdup ((char *) text);
|
||||||
p = tmp;
|
p = tmp;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
q = strchr (p, '\n');
|
q = strchr (p, '\n');
|
||||||
if (q != NULL)
|
if (q != NULL)
|
||||||
{
|
{
|
||||||
c = q[0];
|
c = q[0];
|
||||||
q[0] = '\0';
|
q[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
width = str_8bit_term_width1 (p);
|
width = str_8bit_term_width1 (p);
|
||||||
if (width > (*columns))
|
if (width > (*columns))
|
||||||
(*columns) = width;
|
(*columns) = width;
|
||||||
|
|
||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
break;
|
break;
|
||||||
q[0] = c;
|
q[0] = c;
|
||||||
p = q + 1;
|
p = q + 1;
|
||||||
(*lines)++;
|
(*lines)++;
|
||||||
}
|
}
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
@ -480,20 +477,19 @@ str_8bit_term_substring (const char *text, int start, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (start < (int)length)
|
if (start < (int) length)
|
||||||
{
|
{
|
||||||
pos += start;
|
pos += start;
|
||||||
for (; pos < length && width > 0 && remain > 1;
|
for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--)
|
||||||
pos++, width--, actual++, remain--)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
||||||
{
|
{
|
||||||
actual[0] = ' ';
|
actual[0] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -513,32 +509,32 @@ str_8bit_trunc (const char *text, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if ((int)length > width)
|
if ((int) length > width)
|
||||||
{
|
{
|
||||||
for (; pos + 1 <= (gsize)width / 2 && remain > 1; actual++, pos++, remain--)
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1)
|
if (remain <= 1)
|
||||||
goto finally;
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -557,7 +553,7 @@ static int
|
|||||||
str_8bit_column_to_pos (const char *text, size_t pos)
|
str_8bit_column_to_pos (const char *text, size_t pos)
|
||||||
{
|
{
|
||||||
(void) text;
|
(void) text;
|
||||||
return (int)pos;
|
return (int) pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -604,14 +600,14 @@ str_8bit_search_first (const char *text, const char *search, int case_sen)
|
|||||||
match = g_strstr_len (fold_text, -1, fold_search);
|
match = g_strstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL)
|
if (match != NULL)
|
||||||
{
|
{
|
||||||
offsset = match - fold_text;
|
offsset = match - fold_text;
|
||||||
match = text + offsset;
|
match = text + offsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen)
|
if (!case_sen)
|
||||||
{
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
@ -631,14 +627,14 @@ str_8bit_search_last (const char *text, const char *search, int case_sen)
|
|||||||
match = g_strrstr_len (fold_text, -1, fold_search);
|
match = g_strrstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL)
|
if (match != NULL)
|
||||||
{
|
{
|
||||||
offsset = match - fold_text;
|
offsset = match - fold_text;
|
||||||
match = text + offsset;
|
match = text + offsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen)
|
if (!case_sen)
|
||||||
{
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
@ -677,15 +673,15 @@ str_8bit_casecmp (const char *s1, const char *s2)
|
|||||||
/* According to A. Cox, some platforms have islower's that
|
/* According to A. Cox, some platforms have islower's that
|
||||||
* don't work right on non-uppercase
|
* don't work right on non-uppercase
|
||||||
*/
|
*/
|
||||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
c1 = isupper ((guchar) * s1) ? tolower ((guchar) * s1) : *s1;
|
||||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
c2 = isupper ((guchar) * s2) ? tolower ((guchar) * s2) : *s2;
|
||||||
if (c1 != c2)
|
if (c1 != c2)
|
||||||
return (c1 - c2);
|
return (c1 - c2);
|
||||||
s1++;
|
s1++;
|
||||||
s2++;
|
s2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
return (((gint) (guchar) * s1) - ((gint) (guchar) * s2));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -712,8 +708,8 @@ str_8bit_ncasecmp (const char *s1, const char *s2)
|
|||||||
/* According to A. Cox, some platforms have islower's that
|
/* According to A. Cox, some platforms have islower's that
|
||||||
* don't work right on non-uppercase
|
* don't work right on non-uppercase
|
||||||
*/
|
*/
|
||||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
c1 = isupper ((guchar) * s1) ? tolower ((guchar) * s1) : *s1;
|
||||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
c2 = isupper ((guchar) * s2) ? tolower ((guchar) * s2) : *s2;
|
||||||
if (c1 != c2)
|
if (c1 != c2)
|
||||||
return (c1 - c2);
|
return (c1 - c2);
|
||||||
s1++;
|
s1++;
|
||||||
@ -721,7 +717,7 @@ str_8bit_ncasecmp (const char *s1, const char *s2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
return (((gint) (guchar) *s1) - ((gint) (guchar) *s2));
|
return (((gint) (guchar) * s1) - ((gint) (guchar) * s2));
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
@ -732,7 +728,7 @@ str_8bit_prefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& text[result] == prefix[result]; result++);
|
&& text[result] == prefix[result]; result++);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -741,7 +737,7 @@ str_8bit_caseprefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& char_toupper (text[result]) == char_toupper (prefix[result]); result++);
|
&& char_toupper (text[result]) == char_toupper (prefix[result]); result++);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,16 +759,16 @@ static int
|
|||||||
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
|
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
|
||||||
{
|
{
|
||||||
if (case_sen)
|
if (case_sen)
|
||||||
return strcmp (t1, t2);
|
return strcmp (t1, t2);
|
||||||
else
|
else
|
||||||
return strcoll (t1, t2);
|
return strcoll (t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
str_8bit_release_key (char *key, int case_sen)
|
str_8bit_release_key (char *key, int case_sen)
|
||||||
{
|
{
|
||||||
if (!case_sen)
|
if (!case_sen)
|
||||||
g_free (key);
|
g_free (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_class
|
struct str_class
|
||||||
|
@ -74,11 +74,11 @@ str_ascii_cnext_noncomb_char (const char **text)
|
|||||||
{
|
{
|
||||||
if (*text[0] != '\0')
|
if (*text[0] != '\0')
|
||||||
{
|
{
|
||||||
(*text)++;
|
(*text)++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -86,11 +86,11 @@ str_ascii_cprev_noncomb_char (const char **text, const char *begin)
|
|||||||
{
|
{
|
||||||
if ((*text) != begin)
|
if ((*text) != begin)
|
||||||
{
|
{
|
||||||
(*text)--;
|
(*text)--;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -134,7 +134,7 @@ static int
|
|||||||
str_ascii_toupper (const char *text, char **out, size_t * remain)
|
str_ascii_toupper (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1)
|
if (*remain <= 1)
|
||||||
return 0;
|
return 0;
|
||||||
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
|
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -145,7 +145,7 @@ static int
|
|||||||
str_ascii_tolower (const char *text, char **out, size_t * remain)
|
str_ascii_tolower (const char *text, char **out, size_t * remain)
|
||||||
{
|
{
|
||||||
if (*remain <= 1)
|
if (*remain <= 1)
|
||||||
return 0;
|
return 0;
|
||||||
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
|
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
|
||||||
(*out)++;
|
(*out)++;
|
||||||
(*remain)--;
|
(*remain)--;
|
||||||
@ -165,18 +165,17 @@ str_ascii_length2 (const char *text, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
str_ascii_conv_gerror_message (GError *error, const char *def_msg)
|
str_ascii_conv_gerror_message (GError * error, const char *def_msg)
|
||||||
{
|
{
|
||||||
/* the same as str_utf8_conv_gerror_message() */
|
/* the same as str_utf8_conv_gerror_message() */
|
||||||
if ((error != NULL) && (error->message != NULL))
|
if ((error != NULL) && (error->message != NULL))
|
||||||
return g_strdup (error->message);
|
return g_strdup (error->message);
|
||||||
|
|
||||||
return g_strdup (def_msg != NULL ? def_msg : "");
|
return g_strdup (def_msg != NULL ? def_msg : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static estr_t
|
static estr_t
|
||||||
str_ascii_vfs_convert_to (GIConv coder, const char *string,
|
str_ascii_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||||
int size, GString * buffer)
|
|
||||||
{
|
{
|
||||||
(void) coder;
|
(void) coder;
|
||||||
g_string_append_len (buffer, string, size);
|
g_string_append_len (buffer, string, size);
|
||||||
@ -200,8 +199,8 @@ str_ascii_term_form (const char *text)
|
|||||||
/* go throw all characters and check, if they are ascii and printable */
|
/* go throw all characters and check, if they are ascii and printable */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -222,101 +221,93 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if ((int)length <= width)
|
if ((int) length <= width)
|
||||||
{
|
{
|
||||||
ident = 0;
|
ident = 0;
|
||||||
switch (HIDE_FIT (just_mode))
|
switch (HIDE_FIT (just_mode))
|
||||||
{
|
{
|
||||||
case J_CENTER_LEFT:
|
case J_CENTER_LEFT:
|
||||||
case J_CENTER:
|
case J_CENTER:
|
||||||
ident = (width - length) / 2;
|
ident = (width - length) / 2;
|
||||||
break;
|
break;
|
||||||
case J_RIGHT:
|
case J_RIGHT:
|
||||||
ident = width - length;
|
ident = width - length;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add space before text */
|
/* add space before text */
|
||||||
if ((int)remain <= ident)
|
if ((int) remain <= ident)
|
||||||
goto finally;
|
goto finally;
|
||||||
memset (actual, ' ', ident);
|
memset (actual, ' ', ident);
|
||||||
actual += ident;
|
actual += ident;
|
||||||
remain -= ident;
|
remain -= ident;
|
||||||
|
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < (gsize)length && remain > 1; pos++, actual++, remain--)
|
for (; pos < (gsize) length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add space after text */
|
/* add space after text */
|
||||||
if (width - length - ident > 0)
|
if (width - length - ident > 0)
|
||||||
{
|
{
|
||||||
if (remain <= width - length - ident)
|
if (remain <= width - length - ident)
|
||||||
goto finally;
|
goto finally;
|
||||||
memset (actual, ' ', width - length - ident);
|
memset (actual, ' ', width - length - ident);
|
||||||
actual += width - length - ident;
|
actual += width - length - ident;
|
||||||
remain -= width - length - ident;
|
remain -= width - length - ident;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (IS_FIT (just_mode))
|
if (IS_FIT (just_mode))
|
||||||
{
|
{
|
||||||
/* copy prefix of text, that is not wider than width / 2 */
|
/* copy prefix of text, that is not wider than width / 2 */
|
||||||
for (; pos + 1 <= (gsize)width / 2 && remain > 1;
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
actual++, pos++, remain--)
|
{
|
||||||
{
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
? text[pos] : '?';
|
}
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
|
||||||
? actual[0] : '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remain <= 1)
|
if (remain <= 1)
|
||||||
goto finally;
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
? text[pos] : '?';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
}
|
||||||
? actual[0] : '.';
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
else
|
ident = 0;
|
||||||
{
|
switch (HIDE_FIT (just_mode))
|
||||||
ident = 0;
|
{
|
||||||
switch (HIDE_FIT (just_mode))
|
case J_CENTER:
|
||||||
{
|
ident = (length - width) / 2;
|
||||||
case J_CENTER:
|
break;
|
||||||
ident = (length - width) / 2;
|
case J_RIGHT:
|
||||||
break;
|
ident = length - width;
|
||||||
case J_RIGHT:
|
break;
|
||||||
ident = length - width;
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy substring text, substring start from ident and take width
|
/* copy substring text, substring start from ident and take width
|
||||||
* characters from text */
|
* characters from text */
|
||||||
pos += ident;
|
pos += ident;
|
||||||
for (; pos < (gsize)(ident + width) && remain > 1;
|
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
|
||||||
pos++, actual++, remain--)
|
{
|
||||||
{
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
? text[pos] : '?';
|
}
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
|
||||||
? actual[0] : '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally:
|
finally:
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -336,40 +327,38 @@ str_ascii_term_trim (const char *text, int width)
|
|||||||
actual = result;
|
actual = result;
|
||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
|
|
||||||
if (width < (int)length)
|
if (width < (int) length)
|
||||||
{
|
{
|
||||||
if (width <= 3)
|
if (width <= 3)
|
||||||
{
|
{
|
||||||
memset (actual, '.', width);
|
memset (actual, '.', width);
|
||||||
actual += width;
|
actual += width;
|
||||||
remain -= width;
|
remain -= width;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
memset (actual, '.', 3);
|
memset (actual, '.', 3);
|
||||||
actual += 3;
|
actual += 3;
|
||||||
remain -= 3;
|
remain -= 3;
|
||||||
|
|
||||||
pos += length - width + 3;
|
pos += length - width + 3;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos])
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
? text[pos] : '?';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
}
|
||||||
? actual[0] : '.';
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -379,8 +368,7 @@ str_ascii_term_trim (const char *text, int width)
|
|||||||
static int
|
static int
|
||||||
str_ascii_term_width2 (const char *text, size_t length)
|
str_ascii_term_width2 (const char *text, size_t length)
|
||||||
{
|
{
|
||||||
return (length != (size_t) (-1))
|
return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text);
|
||||||
? min (strlen (text), length) : strlen (text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -412,22 +400,22 @@ str_ascii_msg_term_size (const char *text, int *lines, int *columns)
|
|||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
q = strchr (p, '\n');
|
q = strchr (p, '\n');
|
||||||
if (q != NULL)
|
if (q != NULL)
|
||||||
{
|
{
|
||||||
c = q[0];
|
c = q[0];
|
||||||
q[0] = '\0';
|
q[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
width = str_ascii_term_width1 (p);
|
width = str_ascii_term_width1 (p);
|
||||||
if (width > (*columns))
|
if (width > (*columns))
|
||||||
(*columns) = width;
|
(*columns) = width;
|
||||||
|
|
||||||
if (q == NULL)
|
if (q == NULL)
|
||||||
break;
|
break;
|
||||||
q[0] = c;
|
q[0] = c;
|
||||||
p = q + 1;
|
p = q + 1;
|
||||||
(*lines)++;
|
(*lines)++;
|
||||||
}
|
}
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
}
|
}
|
||||||
@ -445,23 +433,22 @@ str_ascii_term_substring (const char *text, int start, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if (start < (int)length)
|
if (start < (int) length)
|
||||||
{
|
{
|
||||||
pos += start;
|
pos += start;
|
||||||
/* copy at most width characters from text from start */
|
/* copy at most width characters from text from start */
|
||||||
for (; pos < length && width > 0 && remain > 1;
|
for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--)
|
||||||
pos++, width--, actual++, remain--)
|
{
|
||||||
{
|
|
||||||
|
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if text is shorter then width, add space to the end */
|
/* if text is shorter then width, add space to the end */
|
||||||
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
for (; width > 0 && remain > 1; actual++, remain--, width--)
|
||||||
{
|
{
|
||||||
actual[0] = ' ';
|
actual[0] = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
actual[0] = '\0';
|
actual[0] = '\0';
|
||||||
@ -481,38 +468,38 @@ str_ascii_trunc (const char *text, int width)
|
|||||||
remain = sizeof (result);
|
remain = sizeof (result);
|
||||||
length = strlen (text);
|
length = strlen (text);
|
||||||
|
|
||||||
if ((int)length > width)
|
if ((int) length > width)
|
||||||
{
|
{
|
||||||
/* copy prefix of text */
|
/* copy prefix of text */
|
||||||
for (; pos + 1 <= (gsize)width / 2 && remain > 1; actual++, pos++, remain--)
|
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remain <= 1)
|
if (remain <= 1)
|
||||||
goto finally;
|
goto finally;
|
||||||
actual[0] = '~';
|
actual[0] = '~';
|
||||||
actual++;
|
actual++;
|
||||||
remain--;
|
remain--;
|
||||||
|
|
||||||
pos += length - width + 1;
|
pos += length - width + 1;
|
||||||
|
|
||||||
/* copy suffix of text */
|
/* copy suffix of text */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* copy all characters */
|
/* copy all characters */
|
||||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||||
{
|
{
|
||||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@ -531,7 +518,7 @@ static int
|
|||||||
str_ascii_column_to_pos (const char *text, size_t pos)
|
str_ascii_column_to_pos (const char *text, size_t pos)
|
||||||
{
|
{
|
||||||
(void) text;
|
(void) text;
|
||||||
return (int)pos;
|
return (int) pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -563,14 +550,14 @@ str_ascii_search_first (const char *text, const char *search, int case_sen)
|
|||||||
match = g_strstr_len (fold_text, -1, fold_search);
|
match = g_strstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL)
|
if (match != NULL)
|
||||||
{
|
{
|
||||||
offset = match - fold_text;
|
offset = match - fold_text;
|
||||||
match = text + offset;
|
match = text + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen)
|
if (!case_sen)
|
||||||
{
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
@ -590,14 +577,14 @@ str_ascii_search_last (const char *text, const char *search, int case_sen)
|
|||||||
match = g_strrstr_len (fold_text, -1, fold_search);
|
match = g_strrstr_len (fold_text, -1, fold_search);
|
||||||
if (match != NULL)
|
if (match != NULL)
|
||||||
{
|
{
|
||||||
offset = match - fold_text;
|
offset = match - fold_text;
|
||||||
match = text + offset;
|
match = text + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!case_sen)
|
if (!case_sen)
|
||||||
{
|
{
|
||||||
g_free (fold_text);
|
g_free (fold_text);
|
||||||
g_free (fold_search);
|
g_free (fold_search);
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
@ -632,7 +619,7 @@ str_ascii_fix_string (char *text)
|
|||||||
{
|
{
|
||||||
for (; text[0] != '\0'; text++)
|
for (; text[0] != '\0'; text++)
|
||||||
{
|
{
|
||||||
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
|
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +648,7 @@ str_ascii_prefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& text[result] == prefix[result]; result++);
|
&& text[result] == prefix[result]; result++);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,8 +657,7 @@ str_ascii_caseprefix (const char *text, const char *prefix)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||||
&& g_ascii_toupper (text[result]) ==
|
&& g_ascii_toupper (text[result]) == g_ascii_toupper (prefix[result]); result++);
|
||||||
g_ascii_toupper (prefix[result]); result++);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -26,7 +26,7 @@
|
|||||||
#include "lib/strutil.h"
|
#include "lib/strutil.h"
|
||||||
|
|
||||||
/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
|
/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
|
||||||
fractionnal parts, S_Z: idem but with leading Zeroes only */
|
fractionnal parts, S_Z: idem but with leading Zeroes only */
|
||||||
#define S_N 0x0
|
#define S_N 0x0
|
||||||
#define S_I 0x4
|
#define S_I 0x4
|
||||||
#define S_F 0x8
|
#define S_F 0x8
|
||||||
@ -40,78 +40,77 @@
|
|||||||
/* Compare S1 and S2 as strings holding indices/version numbers,
|
/* Compare S1 and S2 as strings holding indices/version numbers,
|
||||||
returning less than, equal to or greater than zero if S1 is less than,
|
returning less than, equal to or greater than zero if S1 is less than,
|
||||||
equal to or greater than S2 (for more info, see the texinfo doc).
|
equal to or greater than S2 (for more info, see the texinfo doc).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int str_verscmp (const char *s1, const char *s2)
|
int
|
||||||
|
str_verscmp (const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_STRVERSCMP
|
#ifdef HAVE_STRVERSCMP
|
||||||
return strverscmp(s1, s2);
|
return strverscmp (s1, s2);
|
||||||
#else /* HAVE_STRVERSCMP */
|
#else /* HAVE_STRVERSCMP */
|
||||||
unsigned char *p1 = (unsigned char *) s1;
|
unsigned char *p1 = (unsigned char *) s1;
|
||||||
unsigned char *p2 = (unsigned char *) s2;
|
unsigned char *p2 = (unsigned char *) s2;
|
||||||
unsigned char c1, c2;
|
unsigned char c1, c2;
|
||||||
int state;
|
int state;
|
||||||
int diff;
|
int diff;
|
||||||
|
|
||||||
/* Symbol(s) 0 [1-9] others (padding)
|
/* Symbol(s) 0 [1-9] others (padding)
|
||||||
Transition (10) 0 (01) d (00) x (11) - */
|
Transition (10) 0 (01) d (00) x (11) - */
|
||||||
static const unsigned int next_state[] =
|
static const unsigned int next_state[] = {
|
||||||
{
|
/* state x d 0 - */
|
||||||
/* state x d 0 - */
|
/* S_N */ S_N, S_I, S_Z, S_N,
|
||||||
/* S_N */ S_N, S_I, S_Z, S_N,
|
/* S_I */ S_N, S_I, S_I, S_I,
|
||||||
/* S_I */ S_N, S_I, S_I, S_I,
|
/* S_F */ S_N, S_F, S_F, S_F,
|
||||||
/* S_F */ S_N, S_F, S_F, S_F,
|
/* S_Z */ S_N, S_F, S_Z, S_Z
|
||||||
/* S_Z */ S_N, S_F, S_Z, S_Z
|
};
|
||||||
};
|
|
||||||
|
|
||||||
static const int result_type[] =
|
static const int result_type[] = {
|
||||||
{
|
/* state x/x x/d x/0 x/- d/x d/d d/0 d/-
|
||||||
/* state x/x x/d x/0 x/- d/x d/d d/0 d/-
|
0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
|
||||||
0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
|
|
||||||
|
|
||||||
/* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
/* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
||||||
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
||||||
/* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
|
/* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
|
||||||
+1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
|
+1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
|
||||||
/* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
/* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
|
||||||
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
|
||||||
/* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
|
/* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
|
||||||
-1, CMP, CMP, CMP
|
-1, CMP, CMP, CMP
|
||||||
};
|
};
|
||||||
|
|
||||||
if (p1 == p2)
|
if (p1 == p2)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
c1 = *p1++;
|
c1 = *p1++;
|
||||||
c2 = *p2++;
|
c2 = *p2++;
|
||||||
/* Hint: '0' is a digit too. */
|
/* Hint: '0' is a digit too. */
|
||||||
state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
|
state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
|
||||||
|
|
||||||
while ((diff = c1 - c2) == 0 && c1 != '\0')
|
while ((diff = c1 - c2) == 0 && c1 != '\0')
|
||||||
{
|
{
|
||||||
state = next_state[state];
|
state = next_state[state];
|
||||||
c1 = *p1++;
|
c1 = *p1++;
|
||||||
c2 = *p2++;
|
c2 = *p2++;
|
||||||
state |= (c1 == '0') + (isdigit (c1) != 0);
|
state |= (c1 == '0') + (isdigit (c1) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))];
|
state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))];
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case CMP:
|
case CMP:
|
||||||
return diff;
|
return diff;
|
||||||
|
|
||||||
case LEN:
|
case LEN:
|
||||||
while (isdigit (*p1++))
|
while (isdigit (*p1++))
|
||||||
if (!isdigit (*p2++))
|
if (!isdigit (*p2++))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
return isdigit (*p2) ? -1 : diff;
|
return isdigit (*p2) ? -1 : diff;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_STRVERSCMP */
|
#endif /* HAVE_STRVERSCMP */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,35 +3,48 @@
|
|||||||
* \brief Header: time formating macroses
|
* \brief Header: time formating macroses
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __UTIL_TIMEFMT_H
|
#ifndef MC__UTIL_TIMEFMT_H
|
||||||
#define __UTIL_TIMEFMT_H
|
#define MC__UTIL_TIMEFMT_H
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define INVALID_TIME_TEXT "(invalid)"
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#define INVALID_TIME_TEXT "(invalid)"
|
||||||
|
|
||||||
/* safe localtime formatting - strftime()-using version */
|
/* safe localtime formatting - strftime()-using version */
|
||||||
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
|
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
|
||||||
{ \
|
{ \
|
||||||
struct tm *whentm; \
|
struct tm *whentm; \
|
||||||
whentm = localtime(&when); \
|
whentm = localtime(&when); \
|
||||||
if (whentm == NULL) \
|
if (whentm == NULL) \
|
||||||
{ \
|
{ \
|
||||||
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
|
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
|
||||||
buffer[bufsize-1] = 0; \
|
buffer[bufsize-1] = 0; \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
{ \
|
{ \
|
||||||
strftime(buffer, bufsize, fmt, whentm); \
|
strftime(buffer, bufsize, fmt, whentm); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
|
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
|
||||||
{ \
|
{ \
|
||||||
time_t __current_time; \
|
time_t __current_time; \
|
||||||
time(&__current_time); \
|
time(&__current_time); \
|
||||||
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
|
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* !__UTIL_H */
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
#endif /* !__UTIL_H */
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <string.h> /* strcmp */
|
#include <string.h> /* strcmp */
|
||||||
|
|
||||||
#include "color.h" /* colors and attributes */
|
#include "color.h" /* colors and attributes */
|
||||||
#include "color-internal.h"
|
#include "color-internal.h"
|
||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
@ -39,7 +39,8 @@ gboolean mc_tty_color_disable;
|
|||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
typedef struct mc_tty_color_table_struct {
|
typedef struct mc_tty_color_table_struct
|
||||||
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
int value;
|
int value;
|
||||||
} mc_tty_color_table_t;
|
} mc_tty_color_table_t;
|
||||||
@ -47,30 +48,30 @@ typedef struct mc_tty_color_table_struct {
|
|||||||
/*** file scope variables ************************************************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
mc_tty_color_table_t const color_table[] = {
|
mc_tty_color_table_t const color_table[] = {
|
||||||
{ "black", COLOR_BLACK },
|
{"black", COLOR_BLACK},
|
||||||
{ "gray", COLOR_BLACK | A_BOLD },
|
{"gray", COLOR_BLACK | A_BOLD},
|
||||||
{ "red", COLOR_RED },
|
{"red", COLOR_RED},
|
||||||
{ "brightred", COLOR_RED | A_BOLD },
|
{"brightred", COLOR_RED | A_BOLD},
|
||||||
{ "green", COLOR_GREEN },
|
{"green", COLOR_GREEN},
|
||||||
{ "brightgreen", COLOR_GREEN | A_BOLD },
|
{"brightgreen", COLOR_GREEN | A_BOLD},
|
||||||
{ "brown", COLOR_YELLOW },
|
{"brown", COLOR_YELLOW},
|
||||||
{ "yellow", COLOR_YELLOW | A_BOLD },
|
{"yellow", COLOR_YELLOW | A_BOLD},
|
||||||
{ "blue", COLOR_BLUE },
|
{"blue", COLOR_BLUE},
|
||||||
{ "brightblue", COLOR_BLUE | A_BOLD },
|
{"brightblue", COLOR_BLUE | A_BOLD},
|
||||||
{ "magenta", COLOR_MAGENTA },
|
{"magenta", COLOR_MAGENTA},
|
||||||
{ "brightmagenta", COLOR_MAGENTA | A_BOLD },
|
{"brightmagenta", COLOR_MAGENTA | A_BOLD},
|
||||||
{ "cyan", COLOR_CYAN },
|
{"cyan", COLOR_CYAN},
|
||||||
{ "brightcyan", COLOR_CYAN | A_BOLD },
|
{"brightcyan", COLOR_CYAN | A_BOLD},
|
||||||
{ "lightgray", COLOR_WHITE },
|
{"lightgray", COLOR_WHITE},
|
||||||
{ "white", COLOR_WHITE | A_BOLD },
|
{"white", COLOR_WHITE | A_BOLD},
|
||||||
{ "default", -1 }, /* default color of the terminal */
|
{"default", -1}, /* default color of the terminal */
|
||||||
/* special colors */
|
/* special colors */
|
||||||
{ "A_REVERSE", SPEC_A_REVERSE },
|
{"A_REVERSE", SPEC_A_REVERSE},
|
||||||
{ "A_BOLD", SPEC_A_BOLD},
|
{"A_BOLD", SPEC_A_BOLD},
|
||||||
{ "A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE },
|
{"A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE},
|
||||||
{ "A_UNDERLINE", SPEC_A_UNDERLINE },
|
{"A_UNDERLINE", SPEC_A_UNDERLINE},
|
||||||
/* End of list */
|
/* End of list */
|
||||||
{ NULL, 0}
|
{NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** file scope functions ************************************************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
@ -3,21 +3,33 @@
|
|||||||
* \brief Header: Internal stuff of color setup
|
* \brief Header: Internal stuff of color setup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_COLOR_INTERNAL_H
|
#ifndef MC__COLOR_INTERNAL_H
|
||||||
#define MC_COLOR_INTERNAL_H
|
#define MC__COLOR_INTERNAL_H
|
||||||
|
|
||||||
#include <sys/types.h> /* size_t */
|
#include <sys/types.h> /* size_t */
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#ifdef HAVE_SLANG
|
#ifdef HAVE_SLANG
|
||||||
# include "tty-slang.h"
|
#include "tty-slang.h"
|
||||||
#else
|
#else
|
||||||
# include "tty-ncurses.h"
|
#include "tty-ncurses.h"
|
||||||
#endif /* HAVE_SLANG */
|
#endif /* HAVE_SLANG */
|
||||||
|
|
||||||
extern gboolean use_colors;
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
extern gboolean mc_tty_color_disable;
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
typedef enum {
|
||||||
|
SPEC_A_REVERSE = -100,
|
||||||
|
SPEC_A_BOLD = -101,
|
||||||
|
SPEC_A_BOLD_REVERSE = -102,
|
||||||
|
SPEC_A_UNDERLINE = -103
|
||||||
|
} tty_special_color_t;
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct mc_color_pair_struct
|
typedef struct mc_color_pair_struct
|
||||||
{
|
{
|
||||||
@ -29,14 +41,12 @@ typedef struct mc_color_pair_struct
|
|||||||
gboolean is_temp;
|
gboolean is_temp;
|
||||||
} tty_color_pair_t;
|
} tty_color_pair_t;
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/*** global variables defined in .c file *********************************************************/
|
||||||
typedef enum {
|
|
||||||
SPEC_A_REVERSE = -100,
|
extern gboolean use_colors;
|
||||||
SPEC_A_BOLD = -101,
|
extern gboolean mc_tty_color_disable;
|
||||||
SPEC_A_BOLD_REVERSE = -102,
|
|
||||||
SPEC_A_UNDERLINE = -103
|
/*** declarations of public functions ************************************************************/
|
||||||
} tty_special_color_t;
|
|
||||||
/* *INDENT-ON* */
|
|
||||||
|
|
||||||
const char *tty_color_get_valid_name (const char *);
|
const char *tty_color_get_valid_name (const char *);
|
||||||
int tty_color_get_index_by_name (const char *);
|
int tty_color_get_index_by_name (const char *);
|
||||||
@ -46,4 +56,5 @@ void tty_color_deinit_lib (void);
|
|||||||
|
|
||||||
void tty_color_try_alloc_pair_lib (tty_color_pair_t *);
|
void tty_color_try_alloc_pair_lib (tty_color_pair_t *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_COLOR_INTERNAL_H */
|
#endif /* MC_COLOR_INTERNAL_H */
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "tty-ncurses.h"
|
#include "tty-ncurses.h"
|
||||||
#include "color.h" /* variables */
|
#include "color.h" /* variables */
|
||||||
#include "color-internal.h"
|
#include "color-internal.h"
|
||||||
|
|
||||||
/*** global variables ****************************************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
@ -67,7 +67,8 @@ mc_tty_color_save_attr_lib (int color_pair, int color_attr)
|
|||||||
return color_attr;
|
return color_attr;
|
||||||
|
|
||||||
key = g_try_new (int, 1);
|
key = g_try_new (int, 1);
|
||||||
if (key == NULL) {
|
if (key == NULL)
|
||||||
|
{
|
||||||
g_free (attr);
|
g_free (attr);
|
||||||
return color_attr;
|
return color_attr;
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ color_get_attr (int color_pair)
|
|||||||
int *fnd = NULL;
|
int *fnd = NULL;
|
||||||
|
|
||||||
if (mc_tty_color_color_pair_attrs != NULL)
|
if (mc_tty_color_color_pair_attrs != NULL)
|
||||||
fnd = (int *) g_hash_table_lookup (mc_tty_color_color_pair_attrs, (gpointer) & color_pair);
|
fnd = (int *) g_hash_table_lookup (mc_tty_color_color_pair_attrs, (gpointer) & color_pair);
|
||||||
return (fnd != NULL) ? *fnd : 0;
|
return (fnd != NULL) ? *fnd : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,10 +101,10 @@ mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
|
|||||||
{
|
{
|
||||||
if (has_colors () && !mc_tty_color_disable)
|
if (has_colors () && !mc_tty_color_disable)
|
||||||
init_pair (mc_color_pair->pair_index,
|
init_pair (mc_color_pair->pair_index,
|
||||||
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg1 | mask), bg1);
|
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg1 | mask), bg1);
|
||||||
else
|
else
|
||||||
init_pair (mc_color_pair->pair_index,
|
init_pair (mc_color_pair->pair_index,
|
||||||
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg2 | mask), bg2);
|
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg2 | mask), bg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
@ -115,7 +116,8 @@ tty_color_init_lib (gboolean disable, gboolean force)
|
|||||||
{
|
{
|
||||||
(void) force;
|
(void) force;
|
||||||
|
|
||||||
if (has_colors () && !disable) {
|
if (has_colors () && !disable)
|
||||||
|
{
|
||||||
use_colors = TRUE;
|
use_colors = TRUE;
|
||||||
start_color ();
|
start_color ();
|
||||||
use_default_colors ();
|
use_default_colors ();
|
||||||
@ -139,8 +141,10 @@ tty_color_deinit_lib (void)
|
|||||||
void
|
void
|
||||||
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
||||||
{
|
{
|
||||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) {
|
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
|
||||||
switch (mc_color_pair->ifg) {
|
{
|
||||||
|
switch (mc_color_pair->ifg)
|
||||||
|
{
|
||||||
case SPEC_A_REVERSE:
|
case SPEC_A_REVERSE:
|
||||||
mc_tty_color_pair_init_special (mc_color_pair,
|
mc_tty_color_pair_init_special (mc_color_pair,
|
||||||
COLOR_BLACK, COLOR_WHITE,
|
COLOR_BLACK, COLOR_WHITE,
|
||||||
@ -162,7 +166,9 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
|||||||
COLOR_WHITE, COLOR_BLACK, A_UNDERLINE);
|
COLOR_WHITE, COLOR_BLACK, A_UNDERLINE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
int mask_fg = (mc_color_pair->ifg == -1) ? mc_color_pair->ifg : 0xff;
|
int mask_fg = (mc_color_pair->ifg == -1) ? mc_color_pair->ifg : 0xff;
|
||||||
int mask_bg = (mc_color_pair->ibg == -1) ? mc_color_pair->ibg : 0xff;
|
int mask_bg = (mc_color_pair->ibg == -1) ? mc_color_pair->ibg : 0xff;
|
||||||
|
|
||||||
|
@ -33,10 +33,21 @@
|
|||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "tty-slang.h"
|
#include "tty-slang.h"
|
||||||
#include "color.h" /* variables */
|
#include "color.h" /* variables */
|
||||||
#include "color-internal.h"
|
#include "color-internal.h"
|
||||||
|
|
||||||
#include "src/setup.h" /* color_terminal_string */
|
#include "src/setup.h" /* color_terminal_string */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
has_colors (gboolean disable, gboolean force)
|
has_colors (gboolean disable, gboolean force)
|
||||||
@ -46,7 +57,8 @@ has_colors (gboolean disable, gboolean force)
|
|||||||
if (force || (getenv ("COLORTERM") != NULL))
|
if (force || (getenv ("COLORTERM") != NULL))
|
||||||
SLtt_Use_Ansi_Colors = 1;
|
SLtt_Use_Ansi_Colors = 1;
|
||||||
|
|
||||||
if (!mc_tty_color_disable) {
|
if (!mc_tty_color_disable)
|
||||||
|
{
|
||||||
const char *terminal = getenv ("TERM");
|
const char *terminal = getenv ("TERM");
|
||||||
const size_t len = strlen (terminal);
|
const size_t len = strlen (terminal);
|
||||||
|
|
||||||
@ -55,13 +67,15 @@ has_colors (gboolean disable, gboolean force)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* check color_terminal_string */
|
/* check color_terminal_string */
|
||||||
while (*cts != '\0') {
|
while (*cts != '\0')
|
||||||
|
{
|
||||||
while (*cts == ' ' || *cts == '\t')
|
while (*cts == ' ' || *cts == '\t')
|
||||||
cts++;
|
cts++;
|
||||||
s = cts;
|
s = cts;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while (*cts != '\0' && *cts != ',') {
|
while (*cts != '\0' && *cts != ',')
|
||||||
|
{
|
||||||
cts++;
|
cts++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -76,43 +90,62 @@ has_colors (gboolean disable, gboolean force)
|
|||||||
return SLtt_Use_Ansi_Colors;
|
return SLtt_Use_Ansi_Colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
|
mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
|
||||||
const char *fg1, const char *bg1,
|
const char *fg1, const char *bg1,
|
||||||
const char *fg2, const char *bg2, SLtt_Char_Type mask)
|
const char *fg2, const char *bg2, SLtt_Char_Type mask)
|
||||||
{
|
{
|
||||||
if (SLtt_Use_Ansi_Colors != 0) {
|
if (SLtt_Use_Ansi_Colors != 0)
|
||||||
if (!mc_tty_color_disable) {
|
{
|
||||||
|
if (!mc_tty_color_disable)
|
||||||
|
{
|
||||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg1, (char *) bg1);
|
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg1, (char *) bg1);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg2, (char *) bg2);
|
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg2, (char *) bg2);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SLtt_set_mono (mc_color_pair->pair_index, NULL, mask);
|
SLtt_set_mono (mc_color_pair->pair_index, NULL, mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_color_init_lib (gboolean disable, gboolean force)
|
tty_color_init_lib (gboolean disable, gboolean force)
|
||||||
{
|
{
|
||||||
/* FIXME: if S-Lang is used, has_colors() must be called regardless
|
/* FIXME: if S-Lang is used, has_colors() must be called regardless
|
||||||
of whether we are interested in its result */
|
of whether we are interested in its result */
|
||||||
if (has_colors (disable, force) && !disable) {
|
if (has_colors (disable, force) && !disable)
|
||||||
|
{
|
||||||
use_colors = TRUE;
|
use_colors = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_color_deinit_lib (void)
|
tty_color_deinit_lib (void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
||||||
{
|
{
|
||||||
const char *fg, *bg;
|
const char *fg, *bg;
|
||||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) {
|
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
|
||||||
switch (mc_color_pair->ifg) {
|
{
|
||||||
|
switch (mc_color_pair->ifg)
|
||||||
|
{
|
||||||
case SPEC_A_REVERSE:
|
case SPEC_A_REVERSE:
|
||||||
mc_tty_color_pair_init_special (mc_color_pair,
|
mc_tty_color_pair_init_special (mc_color_pair,
|
||||||
"black", "white", "black", "lightgray", SLTT_REV_MASK);
|
"black", "white", "black", "lightgray", SLTT_REV_MASK);
|
||||||
@ -132,28 +165,40 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
|||||||
"white", "black", "white", "black", SLTT_ULINE_MASK);
|
"white", "black", "white", "black", SLTT_ULINE_MASK);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
fg = (mc_color_pair->cfg) ? mc_color_pair->cfg : "default";
|
fg = (mc_color_pair->cfg) ? mc_color_pair->cfg : "default";
|
||||||
bg = (mc_color_pair->cbg) ? mc_color_pair->cbg : "default";
|
bg = (mc_color_pair->cbg) ? mc_color_pair->cbg : "default";
|
||||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg);
|
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_setcolor (int color)
|
tty_setcolor (int color)
|
||||||
{
|
{
|
||||||
SLsmg_set_color (color);
|
SLsmg_set_color (color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set colorpair by index, don't interpret S-Lang "emulated attributes" */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Set colorpair by index, don't interpret S-Lang "emulated attributes"
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_lowlevel_setcolor (int color)
|
tty_lowlevel_setcolor (int color)
|
||||||
{
|
{
|
||||||
SLsmg_set_color (color & 0x7F);
|
SLsmg_set_color (color & 0x7F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_set_normal_attrs (void)
|
tty_set_normal_attrs (void)
|
||||||
{
|
{
|
||||||
SLsmg_normal_video ();
|
SLsmg_normal_video ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -3,12 +3,25 @@
|
|||||||
* \brief Header: S-Lang-specific color setup
|
* \brief Header: S-Lang-specific color setup
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_COLOR_SLANG_H
|
#ifndef MC__COLOR_SLANG_H
|
||||||
#define MC_COLOR_SLANG_H
|
#define MC__COLOR_SLANG_H
|
||||||
|
|
||||||
#include "tty-slang.h" /* S-Lang headers */
|
#include "tty-slang.h" /* S-Lang headers */
|
||||||
|
|
||||||
enum {
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/* When using Slang with color, we have all the indexes free but
|
||||||
|
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef A_BOLD
|
||||||
|
#define A_BOLD SLTT_BOLD_MASK
|
||||||
|
#endif /* A_BOLD */
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
COLOR_BLACK = 0,
|
COLOR_BLACK = 0,
|
||||||
COLOR_RED,
|
COLOR_RED,
|
||||||
COLOR_GREEN,
|
COLOR_GREEN,
|
||||||
@ -19,12 +32,11 @@ enum {
|
|||||||
COLOR_WHITE
|
COLOR_WHITE
|
||||||
};
|
};
|
||||||
|
|
||||||
/* When using Slang with color, we have all the indexes free but
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef A_BOLD
|
/*** global variables defined in .c file *********************************************************/
|
||||||
#define A_BOLD SLTT_BOLD_MASK
|
|
||||||
#endif /* A_BOLD */
|
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_COLOR_SLANG_H */
|
#endif /* MC_COLOR_SLANG_H */
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file color.h
|
/** \file color.h
|
||||||
* \brief Header: color setup
|
* \brief Header: color setup
|
||||||
*
|
*
|
||||||
@ -9,20 +8,32 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_COLOR_H
|
#ifndef MC__COLOR_H
|
||||||
#define MC_COLOR_H
|
#define MC__COLOR_H
|
||||||
|
|
||||||
#include "lib/global.h" /* glib.h */
|
#include "lib/global.h" /* glib.h */
|
||||||
|
|
||||||
#ifdef HAVE_SLANG
|
#ifdef HAVE_SLANG
|
||||||
# include "color-slang.h"
|
#include "color-slang.h"
|
||||||
#else
|
#else
|
||||||
# include "tty-ncurses.h"
|
#include "tty-ncurses.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define ALLOC_COLOR_PAIR_INDEX 1
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
/* colors specified on the command line: they override any other setting */
|
/* colors specified on the command line: they override any other setting */
|
||||||
extern char *command_line_colors;
|
extern char *command_line_colors;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
void tty_init_colors (gboolean disable, gboolean force);
|
void tty_init_colors (gboolean disable, gboolean force);
|
||||||
void tty_colors_done (void);
|
void tty_colors_done (void);
|
||||||
|
|
||||||
@ -39,6 +50,5 @@ void tty_set_normal_attrs (void);
|
|||||||
|
|
||||||
void tty_color_set_defaults (const char *, const char *);
|
void tty_color_set_defaults (const char *, const char *);
|
||||||
|
|
||||||
#define ALLOC_COLOR_PAIR_INDEX 1
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif /* MC_COLOR_H */
|
#endif /* MC_COLOR_H */
|
||||||
|
925
lib/tty/key.c
925
lib/tty/key.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
105
lib/tty/key.h
105
lib/tty/key.h
@ -1,39 +1,14 @@
|
|||||||
|
|
||||||
/** \file key.h
|
/** \file key.h
|
||||||
* \brief Header: keyboard support routines
|
* \brief Header: keyboard support routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_KEY_H
|
#ifndef MC__KEY_H
|
||||||
#define MC_KEY_H
|
#define MC__KEY_H
|
||||||
|
|
||||||
#include "lib/global.h" /* <glib.h> */
|
#include "lib/global.h" /* <glib.h> */
|
||||||
|
#include "tty.h" /* KEY_F macro */
|
||||||
|
|
||||||
#include "tty.h" /* KEY_F macro */
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
gboolean define_sequence (int code, const char *seq, int action);
|
|
||||||
|
|
||||||
void init_key (void);
|
|
||||||
void init_key_input_fd (void);
|
|
||||||
void done_key (void);
|
|
||||||
|
|
||||||
long lookup_key (const char *name, char **label);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int code;
|
|
||||||
const char *name;
|
|
||||||
const char *longname;
|
|
||||||
const char *shortcut;
|
|
||||||
} key_code_name_t;
|
|
||||||
|
|
||||||
extern const key_code_name_t key_name_conv_tab[];
|
|
||||||
|
|
||||||
extern int old_esc_mode_timeout;
|
|
||||||
|
|
||||||
/* mouse support */
|
|
||||||
struct Gpm_Event;
|
|
||||||
int tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block);
|
|
||||||
gboolean is_idle (void);
|
|
||||||
int tty_getch (void);
|
|
||||||
|
|
||||||
/* Possible return values from tty_get_event: */
|
/* Possible return values from tty_get_event: */
|
||||||
#define EV_MOUSE -2
|
#define EV_MOUSE -2
|
||||||
@ -48,12 +23,57 @@ int tty_getch (void);
|
|||||||
#define KEY_M_CTRL 0x4000
|
#define KEY_M_CTRL 0x4000
|
||||||
#define KEY_M_MASK 0x7000
|
#define KEY_M_MASK 0x7000
|
||||||
|
|
||||||
|
#define XCTRL(x) (KEY_M_CTRL | ((x) & 0x1F))
|
||||||
|
#define ALT(x) (KEY_M_ALT | (unsigned int)(x))
|
||||||
|
|
||||||
|
/* To define sequences and return codes */
|
||||||
|
#define MCKEY_NOACTION 0
|
||||||
|
#define MCKEY_ESCAPE 1
|
||||||
|
|
||||||
|
/* Return code for the mouse sequence */
|
||||||
|
#define MCKEY_MOUSE -2
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int code;
|
||||||
|
const char *name;
|
||||||
|
const char *longname;
|
||||||
|
const char *shortcut;
|
||||||
|
} key_code_name_t;
|
||||||
|
|
||||||
|
struct Gpm_Event;
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
extern const key_code_name_t key_name_conv_tab[];
|
||||||
|
|
||||||
|
extern int old_esc_mode_timeout;
|
||||||
|
|
||||||
extern int alternate_plus_minus;
|
extern int alternate_plus_minus;
|
||||||
extern int double_click_speed;
|
extern int double_click_speed;
|
||||||
extern int old_esc_mode;
|
extern int old_esc_mode;
|
||||||
extern int use_8th_bit_as_meta;
|
extern int use_8th_bit_as_meta;
|
||||||
extern int mou_auto_repeat;
|
extern int mou_auto_repeat;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
gboolean define_sequence (int code, const char *seq, int action);
|
||||||
|
|
||||||
|
void init_key (void);
|
||||||
|
void init_key_input_fd (void);
|
||||||
|
void done_key (void);
|
||||||
|
|
||||||
|
long lookup_key (const char *name, char **label);
|
||||||
|
|
||||||
|
/* mouse support */
|
||||||
|
int tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block);
|
||||||
|
gboolean is_idle (void);
|
||||||
|
int tty_getch (void);
|
||||||
|
|
||||||
/* While waiting for input, the program can select on more than one file */
|
/* While waiting for input, the program can select on more than one file */
|
||||||
typedef int (*select_fn) (int fd, void *info);
|
typedef int (*select_fn) (int fd, void *info);
|
||||||
|
|
||||||
@ -66,23 +86,6 @@ void remove_select_channel (int fd);
|
|||||||
void channels_up (void);
|
void channels_up (void);
|
||||||
void channels_down (void);
|
void channels_down (void);
|
||||||
|
|
||||||
#define XCTRL(x) (KEY_M_CTRL | ((x) & 0x1F))
|
|
||||||
#define ALT(x) (KEY_M_ALT | (unsigned int)(x))
|
|
||||||
|
|
||||||
static inline gboolean
|
|
||||||
is_abort_char (int c)
|
|
||||||
{
|
|
||||||
return ((c == ESC_CHAR) || (c == KEY_F (10)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To define sequences and return codes */
|
|
||||||
#define MCKEY_NOACTION 0
|
|
||||||
#define MCKEY_ESCAPE 1
|
|
||||||
|
|
||||||
/* Return code for the mouse sequence */
|
|
||||||
#define MCKEY_MOUSE -2
|
|
||||||
|
|
||||||
|
|
||||||
/* internally used in key.c, defined in keyxtra.c */
|
/* internally used in key.c, defined in keyxtra.c */
|
||||||
void load_xtra_key_defines (void);
|
void load_xtra_key_defines (void);
|
||||||
|
|
||||||
@ -96,4 +99,12 @@ int get_key_code (int nodelay);
|
|||||||
void numeric_keypad_mode (void);
|
void numeric_keypad_mode (void);
|
||||||
void application_keypad_mode (void);
|
void application_keypad_mode (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
static inline gboolean
|
||||||
|
is_abort_char (int c)
|
||||||
|
{
|
||||||
|
return ((c == ESC_CHAR) || (c == KEY_F (10)));
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* MC_KEY_H */
|
#endif /* MC_KEY_H */
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "mouse.h" /* required before key.h */
|
#include "mouse.h" /* required before key.h */
|
||||||
#include "key.h"
|
#include "key.h"
|
||||||
|
|
||||||
#if defined (__QNX__) && !defined (__QNXNTO__)
|
#if defined (__QNX__) && !defined (__QNXNTO__)
|
||||||
@ -91,6 +91,11 @@
|
|||||||
* field name in the QNX terminfo strings struct
|
* field name in the QNX terminfo strings struct
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#define Key_backspace __TK("kbs", "kb", 55, _ky_backspace )
|
#define Key_backspace __TK("kbs", "kb", 55, _ky_backspace )
|
||||||
#define Key_catab __TK("ktbc", "ka", 56, _ky_catab )
|
#define Key_catab __TK("ktbc", "ka", 56, _ky_catab )
|
||||||
#define Key_clear __TK("kclr", "kC", 57, _ky_clear )
|
#define Key_clear __TK("kclr", "kC", 57, _ky_clear )
|
||||||
@ -283,26 +288,43 @@
|
|||||||
#define Key_alt_enter Key_ctl_enter /* map ALT-ENTER to CTRL-ENTER */
|
#define Key_alt_enter Key_ctl_enter /* map ALT-ENTER to CTRL-ENTER */
|
||||||
|
|
||||||
#ifdef __USE_QNX_TI
|
#ifdef __USE_QNX_TI
|
||||||
|
|
||||||
/* OS/implementation specific key-define struct */
|
|
||||||
typedef const struct qnx_key_define_s {
|
|
||||||
int mc_code;
|
|
||||||
int str_idx;
|
|
||||||
} qnx_key_define_t;
|
|
||||||
|
|
||||||
/* define current xtra_key_define_t (enable OS/implementation) */
|
/* define current xtra_key_define_t (enable OS/implementation) */
|
||||||
#define xtra_key_define_t qnx_key_define_t
|
#define xtra_key_define_t qnx_key_define_t
|
||||||
|
|
||||||
#endif /* __USE_QNX_TI */
|
#endif /* __USE_QNX_TI */
|
||||||
|
|
||||||
#endif /* HAVE_QNX_KEYS */
|
#endif /* HAVE_QNX_KEYS */
|
||||||
|
|
||||||
|
|
||||||
#ifdef xtra_key_define_t
|
#ifdef xtra_key_define_t
|
||||||
|
|
||||||
#ifndef FORCE_BASE_KEY_DEFS
|
#ifndef FORCE_BASE_KEY_DEFS
|
||||||
#define FORCE_BASE_KEY_DEFS 0
|
#define FORCE_BASE_KEY_DEFS 0
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* xtra_key_define_t */
|
||||||
|
|
||||||
|
#ifdef HAVE_QNX_KEYS
|
||||||
|
#ifdef __USE_QNX_TI
|
||||||
|
#define __CT (__cur_term)
|
||||||
|
#define __QTISOFFS(_qtisx) (((charoffset*)(&__CT->_strs))[_qtisx])
|
||||||
|
#define __QTISSTR(_qtisx) (&__CT->_strtab[0]+__QTISOFFS(_qtisx))
|
||||||
|
#endif /* __USE_QNX_TI */
|
||||||
|
#endif /* HAVE_QNX_KEYS */
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
#ifdef HAVE_QNX_KEYS
|
||||||
|
#ifdef __USE_QNX_TI
|
||||||
|
/* OS/implementation specific key-define struct */
|
||||||
|
typedef const struct qnx_key_define_s
|
||||||
|
{
|
||||||
|
int mc_code;
|
||||||
|
int str_idx;
|
||||||
|
} qnx_key_define_t;
|
||||||
|
#endif /* __USE_QNX_TI */
|
||||||
|
#endif /* HAVE_QNX_KEYS */
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef xtra_key_define_t
|
||||||
|
|
||||||
/* general key define table */
|
/* general key define table */
|
||||||
xtra_key_define_t xtra_key_defines[] = {
|
xtra_key_define_t xtra_key_defines[] = {
|
||||||
@ -372,21 +394,22 @@ xtra_key_define_t xtra_key_defines[] = {
|
|||||||
|
|
||||||
#endif /* xtra_key_define_t */
|
#endif /* xtra_key_define_t */
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef HAVE_QNX_KEYS
|
#ifdef HAVE_QNX_KEYS
|
||||||
|
|
||||||
#ifdef __USE_QNX_TI
|
#ifdef __USE_QNX_TI
|
||||||
|
|
||||||
#define __CT (__cur_term)
|
|
||||||
#define __QTISOFFS(_qtisx) (((charoffset*)(&__CT->_strs))[_qtisx])
|
|
||||||
#define __QTISSTR(_qtisx) (&__CT->_strtab[0]+__QTISOFFS(_qtisx))
|
|
||||||
|
|
||||||
void
|
void
|
||||||
load_qnx_key_defines (void)
|
load_qnx_key_defines (void)
|
||||||
{
|
{
|
||||||
static int _qnx_keys_defined = 0;
|
static int _qnx_keys_defined = 0;
|
||||||
|
|
||||||
if (!_qnx_keys_defined) {
|
if (!_qnx_keys_defined)
|
||||||
|
{
|
||||||
int idx, str_idx;
|
int idx, str_idx;
|
||||||
int term_setup_ok;
|
int term_setup_ok;
|
||||||
|
|
||||||
@ -394,10 +417,13 @@ load_qnx_key_defines (void)
|
|||||||
if (term_setup_ok != 1)
|
if (term_setup_ok != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (idx = 0; idx < sizeof (xtra_key_defines) / sizeof (xtra_key_defines[0]); idx++) {
|
for (idx = 0; idx < sizeof (xtra_key_defines) / sizeof (xtra_key_defines[0]); idx++)
|
||||||
|
{
|
||||||
str_idx = xtra_key_defines[idx].str_idx;
|
str_idx = xtra_key_defines[idx].str_idx;
|
||||||
if (__QTISOFFS (str_idx)) {
|
if (__QTISOFFS (str_idx))
|
||||||
if (*__QTISSTR (str_idx)) {
|
{
|
||||||
|
if (*__QTISSTR (str_idx))
|
||||||
|
{
|
||||||
define_sequence (xtra_key_defines[idx].mc_code,
|
define_sequence (xtra_key_defines[idx].mc_code,
|
||||||
__QTISSTR (str_idx), MCKEY_NOACTION);
|
__QTISSTR (str_idx), MCKEY_NOACTION);
|
||||||
}
|
}
|
||||||
@ -406,13 +432,12 @@ load_qnx_key_defines (void)
|
|||||||
_qnx_keys_defined = 1;
|
_qnx_keys_defined = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __USE_QNX_TI */
|
#endif /* __USE_QNX_TI */
|
||||||
|
|
||||||
#endif /* HAVE_QNX_KEYS */
|
#endif /* HAVE_QNX_KEYS */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* called from key.c/init_key() */
|
/* called from key.c/init_key() */
|
||||||
|
|
||||||
void
|
void
|
||||||
load_xtra_key_defines (void)
|
load_xtra_key_defines (void)
|
||||||
{
|
{
|
||||||
@ -420,3 +445,5 @@ load_xtra_key_defines (void)
|
|||||||
load_qnx_key_defines ();
|
load_qnx_key_defines ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -34,13 +34,28 @@
|
|||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "tty.h"
|
#include "tty.h"
|
||||||
#include "tty-internal.h" /* mouse_enabled */
|
#include "tty-internal.h" /* mouse_enabled */
|
||||||
#include "mouse.h"
|
#include "mouse.h"
|
||||||
#include "key.h" /* define sequence */
|
#include "key.h" /* define sequence */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
gboolean mouse_enabled = FALSE;
|
gboolean mouse_enabled = FALSE;
|
||||||
const char *xmouse_seq;
|
const char *xmouse_seq;
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
show_mouse_pointer (int x, int y)
|
show_mouse_pointer (int x, int y)
|
||||||
{
|
{
|
||||||
@ -53,10 +68,13 @@ show_mouse_pointer (int x, int y)
|
|||||||
#endif /* HAVE_LIBGPM */
|
#endif /* HAVE_LIBGPM */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_mouse (void)
|
init_mouse (void)
|
||||||
{
|
{
|
||||||
switch (use_mouse_p) {
|
switch (use_mouse_p)
|
||||||
|
{
|
||||||
#ifdef HAVE_LIBGPM
|
#ifdef HAVE_LIBGPM
|
||||||
case MOUSE_NONE:
|
case MOUSE_NONE:
|
||||||
use_mouse_p = MOUSE_GPM;
|
use_mouse_p = MOUSE_GPM;
|
||||||
@ -75,31 +93,35 @@ init_mouse (void)
|
|||||||
enable_mouse ();
|
enable_mouse ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
enable_mouse (void)
|
enable_mouse (void)
|
||||||
{
|
{
|
||||||
if (mouse_enabled)
|
if (mouse_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (use_mouse_p) {
|
switch (use_mouse_p)
|
||||||
|
{
|
||||||
#ifdef HAVE_LIBGPM
|
#ifdef HAVE_LIBGPM
|
||||||
case MOUSE_GPM:
|
case MOUSE_GPM:
|
||||||
{
|
{
|
||||||
int mouse_d;
|
int mouse_d;
|
||||||
Gpm_Connect conn;
|
Gpm_Connect conn;
|
||||||
|
|
||||||
conn.eventMask = ~GPM_MOVE;
|
conn.eventMask = ~GPM_MOVE;
|
||||||
conn.defaultMask = GPM_MOVE;
|
conn.defaultMask = GPM_MOVE;
|
||||||
conn.minMod = 0;
|
conn.minMod = 0;
|
||||||
conn.maxMod = 0;
|
conn.maxMod = 0;
|
||||||
|
|
||||||
mouse_d = Gpm_Open (&conn, 0);
|
mouse_d = Gpm_Open (&conn, 0);
|
||||||
if (mouse_d == -1) {
|
if (mouse_d == -1)
|
||||||
use_mouse_p = MOUSE_NONE;
|
{
|
||||||
return;
|
use_mouse_p = MOUSE_NONE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mouse_enabled = 1;
|
||||||
}
|
}
|
||||||
mouse_enabled = 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
#endif /* HAVE_LIBGPM */
|
#endif /* HAVE_LIBGPM */
|
||||||
|
|
||||||
@ -130,6 +152,8 @@ enable_mouse (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
disable_mouse (void)
|
disable_mouse (void)
|
||||||
{
|
{
|
||||||
@ -138,7 +162,8 @@ disable_mouse (void)
|
|||||||
|
|
||||||
mouse_enabled = FALSE;
|
mouse_enabled = FALSE;
|
||||||
|
|
||||||
switch (use_mouse_p) {
|
switch (use_mouse_p)
|
||||||
|
{
|
||||||
#ifdef HAVE_LIBGPM
|
#ifdef HAVE_LIBGPM
|
||||||
case MOUSE_GPM:
|
case MOUSE_GPM:
|
||||||
Gpm_Close ();
|
Gpm_Close ();
|
||||||
@ -166,3 +191,5 @@ disable_mouse (void)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -5,33 +5,53 @@
|
|||||||
* Events received by clients of this library have their coordinates 0 based
|
* Events received by clients of this library have their coordinates 0 based
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_MOUSE_H
|
#ifndef MC__MOUSE_H
|
||||||
#define MC_MOUSE_H
|
#define MC__MOUSE_H
|
||||||
|
|
||||||
#ifdef HAVE_LIBGPM
|
#ifdef HAVE_LIBGPM
|
||||||
|
|
||||||
/* GPM mouse support include file */
|
/* GPM mouse support include file */
|
||||||
#include <gpm.h>
|
#include <gpm.h>
|
||||||
|
#endif /* !HAVE_LIBGPM */
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBGPM
|
||||||
/* Equivalent definitions for non-GPM mouse support */
|
/* Equivalent definitions for non-GPM mouse support */
|
||||||
/* These lines are modified version from the lines appearing in the */
|
/* These lines are modified version from the lines appearing in the */
|
||||||
/* gpm.h include file of the Linux General Purpose Mouse server */
|
/* gpm.h include file of the Linux General Purpose Mouse server */
|
||||||
|
|
||||||
#define GPM_B_LEFT (1 << 2)
|
#define GPM_B_LEFT (1 << 2)
|
||||||
#define GPM_B_MIDDLE (1 << 1)
|
#define GPM_B_MIDDLE (1 << 1)
|
||||||
#define GPM_B_RIGHT (1 << 0)
|
#define GPM_B_RIGHT (1 << 0)
|
||||||
|
|
||||||
|
#define GPM_BARE_EVENTS(ev) ((ev)&0xF)
|
||||||
|
#endif /* !HAVE_LIBGPM */
|
||||||
|
|
||||||
|
/* Mouse wheel events */
|
||||||
|
#ifndef GPM_B_DOWN
|
||||||
|
#define GPM_B_DOWN (1 << 5)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef GPM_B_UP
|
||||||
|
#define GPM_B_UP (1 << 4)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Mouse callback */
|
||||||
|
typedef int (*mouse_h) (Gpm_Event *, void *);
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBGPM
|
||||||
/* Xterm mouse support supports only GPM_DOWN and GPM_UP */
|
/* Xterm mouse support supports only GPM_DOWN and GPM_UP */
|
||||||
/* If you use others make sure your code also works without them */
|
/* If you use others make sure your code also works without them */
|
||||||
enum Gpm_Etype {
|
enum Gpm_Etype
|
||||||
|
{
|
||||||
GPM_MOVE = 1,
|
GPM_MOVE = 1,
|
||||||
GPM_DRAG = 2, /* exactly one in four is active at a time */
|
GPM_DRAG = 2, /* exactly one in four is active at a time */
|
||||||
GPM_DOWN = 4,
|
GPM_DOWN = 4,
|
||||||
GPM_UP = 8,
|
GPM_UP = 8,
|
||||||
|
|
||||||
#define GPM_BARE_EVENTS(ev) ((ev)&0xF)
|
|
||||||
|
|
||||||
GPM_SINGLE = 16, /* at most one in three is set */
|
GPM_SINGLE = 16, /* at most one in three is set */
|
||||||
GPM_DOUBLE = 32,
|
GPM_DOUBLE = 32,
|
||||||
@ -41,24 +61,15 @@ enum Gpm_Etype {
|
|||||||
GPM_HARD = 256 /* if set in the defaultMask, force an already
|
GPM_HARD = 256 /* if set in the defaultMask, force an already
|
||||||
used event to pass over to another handler */
|
used event to pass over to another handler */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Gpm_Event {
|
|
||||||
int buttons, x, y;
|
|
||||||
enum Gpm_Etype type;
|
|
||||||
} Gpm_Event;
|
|
||||||
|
|
||||||
#endif /* !HAVE_LIBGPM */
|
#endif /* !HAVE_LIBGPM */
|
||||||
|
|
||||||
/* General (i.e. both for xterm and gpm) mouse support definitions */
|
|
||||||
|
|
||||||
/* Constants returned from the mouse callback */
|
/* Constants returned from the mouse callback */
|
||||||
enum { MOU_NORMAL, MOU_REPEAT };
|
enum
|
||||||
|
{ MOU_NORMAL, MOU_REPEAT };
|
||||||
/* Mouse callback */
|
|
||||||
typedef int (*mouse_h) (Gpm_Event *, void *);
|
|
||||||
|
|
||||||
/* Type of mouse support */
|
/* Type of mouse support */
|
||||||
typedef enum {
|
typedef enum
|
||||||
|
{
|
||||||
MOUSE_NONE, /* Not detected yet */
|
MOUSE_NONE, /* Not detected yet */
|
||||||
MOUSE_DISABLED, /* Explicitly disabled by -d */
|
MOUSE_DISABLED, /* Explicitly disabled by -d */
|
||||||
MOUSE_GPM, /* Support using GPM on Linux */
|
MOUSE_GPM, /* Support using GPM on Linux */
|
||||||
@ -67,25 +78,34 @@ typedef enum {
|
|||||||
MOUSE_XTERM_BUTTON_EVENT_TRACKING
|
MOUSE_XTERM_BUTTON_EVENT_TRACKING
|
||||||
} Mouse_Type;
|
} Mouse_Type;
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
#ifndef HAVE_LIBGPM
|
||||||
|
typedef struct Gpm_Event
|
||||||
|
{
|
||||||
|
int buttons, x, y;
|
||||||
|
enum Gpm_Etype type;
|
||||||
|
} Gpm_Event;
|
||||||
|
#endif /* !HAVE_LIBGPM */
|
||||||
|
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
/* Type of the currently used mouse */
|
/* Type of the currently used mouse */
|
||||||
extern Mouse_Type use_mouse_p;
|
extern Mouse_Type use_mouse_p;
|
||||||
|
|
||||||
/* String indicating that a mouse event has occured, usually "\E[M" */
|
/* String indicating that a mouse event has occured, usually "\E[M" */
|
||||||
extern const char *xmouse_seq;
|
extern const char *xmouse_seq;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/* General (i.e. both for xterm and gpm) mouse support definitions */
|
||||||
|
|
||||||
void init_mouse (void);
|
void init_mouse (void);
|
||||||
void enable_mouse (void);
|
void enable_mouse (void);
|
||||||
void disable_mouse (void);
|
void disable_mouse (void);
|
||||||
|
|
||||||
/* Mouse wheel events */
|
|
||||||
#ifndef GPM_B_DOWN
|
|
||||||
#define GPM_B_DOWN (1 << 5)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef GPM_B_UP
|
|
||||||
#define GPM_B_UP (1 << 4)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void show_mouse_pointer (int x, int y);
|
void show_mouse_pointer (int x, int y);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_MOUSE_H */
|
#endif /* MC_MOUSE_H */
|
||||||
|
@ -3,21 +3,29 @@
|
|||||||
* \brief Header: internal suff of the terminal controlling library
|
* \brief Header: internal suff of the terminal controlling library
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_TTY_INTERNAL_H
|
#ifndef MC__TTY_INTERNAL_H
|
||||||
#define MC_TTY_INTERNAL_H
|
#define MC__TTY_INTERNAL_H
|
||||||
|
|
||||||
#include "lib/global.h" /* include <glib.h> */
|
#include "lib/global.h" /* include <glib.h> */
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* Taken from S-Lang's slutty.c */
|
/* Taken from S-Lang's slutty.c */
|
||||||
#ifdef ultrix /* Ultrix gets _POSIX_VDISABLE wrong! */
|
#ifdef ultrix /* Ultrix gets _POSIX_VDISABLE wrong! */
|
||||||
# define NULL_VALUE -1
|
#define NULL_VALUE -1
|
||||||
#else
|
#else
|
||||||
# ifdef _POSIX_VDISABLE
|
#ifdef _POSIX_VDISABLE
|
||||||
# define NULL_VALUE _POSIX_VDISABLE
|
#define NULL_VALUE _POSIX_VDISABLE
|
||||||
# else
|
#else
|
||||||
# define NULL_VALUE 255
|
#define NULL_VALUE 255
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
/* If true lines are shown by spaces */
|
/* If true lines are shown by spaces */
|
||||||
extern gboolean slow_tty;
|
extern gboolean slow_tty;
|
||||||
@ -28,6 +36,9 @@ extern gboolean ugly_line_drawing;
|
|||||||
/* The mouse is currently: TRUE - enabled, FALSE - disabled */
|
/* The mouse is currently: TRUE - enabled, FALSE - disabled */
|
||||||
extern gboolean mouse_enabled;
|
extern gboolean mouse_enabled;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
char *mc_tty_normalize_from_utf8 (const char *);
|
char *mc_tty_normalize_from_utf8 (const char *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_TTY_INTERNAL_H */
|
#endif /* MC_TTY_INTERNAL_H */
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
#include "src/main.h"
|
#include "src/main.h"
|
||||||
|
|
||||||
#ifndef WANT_TERM_H
|
#ifndef WANT_TERM_H
|
||||||
# define WANT_TERM_H
|
#define WANT_TERM_H
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tty-internal.h" /* slow_tty */
|
#include "tty-internal.h" /* slow_tty */
|
||||||
@ -53,30 +53,31 @@
|
|||||||
/* include at last !!! */
|
/* include at last !!! */
|
||||||
#ifdef WANT_TERM_H
|
#ifdef WANT_TERM_H
|
||||||
#ifdef HAVE_NCURSES_TERM_H
|
#ifdef HAVE_NCURSES_TERM_H
|
||||||
# include <ncurses/term.h>
|
#include <ncurses/term.h>
|
||||||
#else
|
#else
|
||||||
# include <term.h>
|
#include <term.h>
|
||||||
#endif /* HAVE_NCURSES_TERM_H */
|
#endif /* HAVE_NCURSES_TERM_H */
|
||||||
#endif /* WANT_TERM_H */
|
#endif /* WANT_TERM_H */
|
||||||
|
|
||||||
/*** global variables **************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
/*** file scope macro definitions **************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#if defined(_AIX) && !defined(CTRL)
|
#if defined(_AIX) && !defined(CTRL)
|
||||||
# define CTRL(x) ((x) & 0x1f)
|
#define CTRL(x) ((x) & 0x1f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** global variables **************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
/*** file scope type declarations **************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
/*** file scope variables **********************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*** public functions **************************************************/
|
/*** public functions ****************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -137,7 +138,6 @@ mc_tty_normalize_lines_char (const char *ch)
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_init (gboolean slow, gboolean ugly_lines)
|
tty_init (gboolean slow, gboolean ugly_lines)
|
||||||
{
|
{
|
||||||
@ -174,24 +174,32 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
|||||||
nodelay (stdscr, FALSE);
|
nodelay (stdscr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_shutdown (void)
|
tty_shutdown (void)
|
||||||
{
|
{
|
||||||
endwin ();
|
endwin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_reset_prog_mode (void)
|
tty_reset_prog_mode (void)
|
||||||
{
|
{
|
||||||
reset_prog_mode ();
|
reset_prog_mode ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_reset_shell_mode (void)
|
tty_reset_shell_mode (void)
|
||||||
{
|
{
|
||||||
reset_shell_mode ();
|
reset_shell_mode ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_raw_mode (void)
|
tty_raw_mode (void)
|
||||||
{
|
{
|
||||||
@ -199,6 +207,8 @@ tty_raw_mode (void)
|
|||||||
cbreak ();
|
cbreak ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_noraw_mode (void)
|
tty_noraw_mode (void)
|
||||||
{
|
{
|
||||||
@ -206,67 +216,89 @@ tty_noraw_mode (void)
|
|||||||
noraw ();
|
noraw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_noecho (void)
|
tty_noecho (void)
|
||||||
{
|
{
|
||||||
noecho ();
|
noecho ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_flush_input (void)
|
tty_flush_input (void)
|
||||||
{
|
{
|
||||||
return flushinp ();
|
return flushinp ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_keypad (gboolean set)
|
tty_keypad (gboolean set)
|
||||||
{
|
{
|
||||||
keypad (stdscr, (bool) set);
|
keypad (stdscr, (bool) set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_nodelay (gboolean set)
|
tty_nodelay (gboolean set)
|
||||||
{
|
{
|
||||||
nodelay (stdscr, (bool) set);
|
nodelay (stdscr, (bool) set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_baudrate (void)
|
tty_baudrate (void)
|
||||||
{
|
{
|
||||||
return baudrate ();
|
return baudrate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_lowlevel_getch (void)
|
tty_lowlevel_getch (void)
|
||||||
{
|
{
|
||||||
return getch ();
|
return getch ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_reset_screen (void)
|
tty_reset_screen (void)
|
||||||
{
|
{
|
||||||
return endwin ();
|
return endwin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_touch_screen (void)
|
tty_touch_screen (void)
|
||||||
{
|
{
|
||||||
touchwin (stdscr);
|
touchwin (stdscr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_gotoyx (int y, int x)
|
tty_gotoyx (int y, int x)
|
||||||
{
|
{
|
||||||
move (y, x);
|
move (y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_getyx (int *py, int *px)
|
tty_getyx (int *py, int *px)
|
||||||
{
|
{
|
||||||
getyx (stdscr, *py, *px);
|
getyx (stdscr, *py, *px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* if x < 0 or y < 0, draw line starting from current position */
|
/* if x < 0 or y < 0, draw line starting from current position */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_hline (int y, int x, int ch, int len)
|
tty_draw_hline (int y, int x, int ch, int len)
|
||||||
{
|
{
|
||||||
@ -278,7 +310,9 @@ tty_draw_hline (int y, int x, int ch, int len)
|
|||||||
hline (ch, len);
|
hline (ch, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* if x < 0 or y < 0, draw line starting from current position */
|
/* if x < 0 or y < 0, draw line starting from current position */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_vline (int y, int x, int ch, int len)
|
tty_draw_vline (int y, int x, int ch, int len)
|
||||||
{
|
{
|
||||||
@ -290,6 +324,8 @@ tty_draw_vline (int y, int x, int ch, int len)
|
|||||||
vline (ch, len);
|
vline (ch, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
||||||
{
|
{
|
||||||
@ -329,24 +365,32 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
|||||||
move (y, x);
|
move (y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_set_alt_charset (gboolean alt_charset)
|
tty_set_alt_charset (gboolean alt_charset)
|
||||||
{
|
{
|
||||||
(void) alt_charset;
|
(void) alt_charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_display_8bit (gboolean what)
|
tty_display_8bit (gboolean what)
|
||||||
{
|
{
|
||||||
meta (stdscr, (int) what);
|
meta (stdscr, (int) what);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_char (int c)
|
tty_print_char (int c)
|
||||||
{
|
{
|
||||||
addch (c);
|
addch (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_anychar (int c)
|
tty_print_anychar (int c)
|
||||||
{
|
{
|
||||||
@ -369,6 +413,8 @@ tty_print_anychar (int c)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_alt_char (int c, gboolean single)
|
tty_print_alt_char (int c, gboolean single)
|
||||||
{
|
{
|
||||||
@ -394,12 +440,16 @@ tty_print_alt_char (int c, gboolean single)
|
|||||||
addch (c);
|
addch (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_string (const char *s)
|
tty_print_string (const char *s)
|
||||||
{
|
{
|
||||||
addstr (str_term_form (s));
|
addstr (str_term_form (s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_printf (const char *fmt, ...)
|
tty_printf (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -410,6 +460,8 @@ tty_printf (const char *fmt, ...)
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
tty_tgetstr (const char *cap)
|
tty_tgetstr (const char *cap)
|
||||||
{
|
{
|
||||||
@ -417,6 +469,8 @@ tty_tgetstr (const char *cap)
|
|||||||
return tgetstr ((char *) cap, &unused);
|
return tgetstr ((char *) cap, &unused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_refresh (void)
|
tty_refresh (void)
|
||||||
{
|
{
|
||||||
@ -424,6 +478,8 @@ tty_refresh (void)
|
|||||||
doupdate ();
|
doupdate ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_setup_sigwinch (void (*handler) (int))
|
tty_setup_sigwinch (void (*handler) (int))
|
||||||
{
|
{
|
||||||
@ -439,8 +495,12 @@ tty_setup_sigwinch (void (*handler) (int))
|
|||||||
#endif /* SIGWINCH */
|
#endif /* SIGWINCH */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_beep (void)
|
tty_beep (void)
|
||||||
{
|
{
|
||||||
beep ();
|
beep ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,25 +1,37 @@
|
|||||||
|
|
||||||
#ifndef MC_TTY_NCURSES_H
|
#ifndef MC__TTY_NCURSES_H
|
||||||
#define MC_TTY_NCURSES_H
|
#define MC__TTY_NCURSES_H
|
||||||
|
|
||||||
#ifdef USE_NCURSES
|
#ifdef USE_NCURSES
|
||||||
# ifdef HAVE_NCURSES_CURSES_H
|
#ifdef HAVE_NCURSES_CURSES_H
|
||||||
# include <ncurses/curses.h>
|
#include <ncurses/curses.h>
|
||||||
# elif HAVE_NCURSES_NCURSES_H
|
#elif HAVE_NCURSES_NCURSES_H
|
||||||
# include <ncurses/ncurses.h>
|
#include <ncurses/ncurses.h>
|
||||||
# elif HAVE_NCURSESW_CURSES_H
|
#elif HAVE_NCURSESW_CURSES_H
|
||||||
# include <ncursesw/curses.h>
|
#include <ncursesw/curses.h>
|
||||||
# elif HAVE_NCURSES_HCURSES_H
|
#elif HAVE_NCURSES_HCURSES_H
|
||||||
# include <ncurses.h>
|
#include <ncurses.h>
|
||||||
# elif HAVE_NCURSES_H
|
#elif HAVE_NCURSES_H
|
||||||
# include <ncurses.h>
|
#include <ncurses.h>
|
||||||
# else
|
#else
|
||||||
# include <curses.h>
|
#include <curses.h>
|
||||||
# endif
|
#endif
|
||||||
#endif /* USE_NCURSES */
|
#endif /* USE_NCURSES */
|
||||||
|
|
||||||
#ifdef USE_NCURSESW
|
#ifdef USE_NCURSESW
|
||||||
# include <ncursesw/curses.h>
|
#include <ncursesw/curses.h>
|
||||||
#endif /* USE_NCURSESW */
|
#endif /* USE_NCURSESW */
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif /* MC_TTY_NCURSES_H */
|
#endif /* MC_TTY_NCURSES_H */
|
||||||
|
@ -51,14 +51,14 @@
|
|||||||
#include "win.h"
|
#include "win.h"
|
||||||
|
|
||||||
|
|
||||||
/*** global variables **************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
extern int reset_hp_softkeys;
|
extern int reset_hp_softkeys;
|
||||||
|
|
||||||
/*** file scope macro definitions **************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#ifndef SA_RESTART
|
#ifndef SA_RESTART
|
||||||
# define SA_RESTART 0
|
#define SA_RESTART 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SLTT_MAX_SCREEN_COLS
|
#ifndef SLTT_MAX_SCREEN_COLS
|
||||||
@ -69,9 +69,9 @@ extern int reset_hp_softkeys;
|
|||||||
#define SLTT_MAX_SCREEN_ROWS 512
|
#define SLTT_MAX_SCREEN_ROWS 512
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*** file scope type declarations **************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
/*** file scope variables **********************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
/* Various saved termios settings that we control here */
|
/* Various saved termios settings that we control here */
|
||||||
static struct termios boot_mode;
|
static struct termios boot_mode;
|
||||||
@ -126,7 +126,8 @@ static const struct
|
|||||||
/* *INDENT-ON* */
|
/* *INDENT-ON* */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
||||||
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
||||||
@ -164,6 +165,8 @@ slang_reset_softkeys (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_define_key (int code, const char *strcap)
|
do_define_key (int code, const char *strcap)
|
||||||
{
|
{
|
||||||
@ -174,6 +177,8 @@ do_define_key (int code, const char *strcap)
|
|||||||
define_sequence (code, seq, MCKEY_NOACTION);
|
define_sequence (code, seq, MCKEY_NOACTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_terminfo_keys (void)
|
load_terminfo_keys (void)
|
||||||
{
|
{
|
||||||
@ -184,7 +189,7 @@ load_terminfo_keys (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*** public functions **************************************************/
|
/*** public functions ****************************************************************************/
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -233,6 +238,7 @@ mc_tty_normalize_lines_char (const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_init (gboolean slow, gboolean ugly_lines)
|
tty_init (gboolean slow, gboolean ugly_lines)
|
||||||
{
|
{
|
||||||
@ -297,6 +303,8 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
|||||||
tty_nodelay (FALSE);
|
tty_nodelay (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_shutdown (void)
|
tty_shutdown (void)
|
||||||
{
|
{
|
||||||
@ -318,7 +326,9 @@ tty_shutdown (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Done each time we come back from done mode */
|
/* Done each time we come back from done mode */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_reset_prog_mode (void)
|
tty_reset_prog_mode (void)
|
||||||
{
|
{
|
||||||
@ -327,35 +337,47 @@ tty_reset_prog_mode (void)
|
|||||||
SLsmg_touch_lines (0, LINES);
|
SLsmg_touch_lines (0, LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Called each time we want to shutdown slang screen manager */
|
/* Called each time we want to shutdown slang screen manager */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_reset_shell_mode (void)
|
tty_reset_shell_mode (void)
|
||||||
{
|
{
|
||||||
tcsetattr (SLang_TT_Read_FD, TCSANOW, &boot_mode);
|
tcsetattr (SLang_TT_Read_FD, TCSANOW, &boot_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_raw_mode (void)
|
tty_raw_mode (void)
|
||||||
{
|
{
|
||||||
tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
|
tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_noraw_mode (void)
|
tty_noraw_mode (void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_noecho (void)
|
tty_noecho (void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_flush_input (void)
|
tty_flush_input (void)
|
||||||
{
|
{
|
||||||
return 0; /* OK */
|
return 0; /* OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_keypad (gboolean set)
|
tty_keypad (gboolean set)
|
||||||
{
|
{
|
||||||
@ -368,18 +390,24 @@ tty_keypad (gboolean set)
|
|||||||
slang_reset_softkeys ();
|
slang_reset_softkeys ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_nodelay (gboolean set)
|
tty_nodelay (gboolean set)
|
||||||
{
|
{
|
||||||
no_slang_delay = set;
|
no_slang_delay = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_baudrate (void)
|
tty_baudrate (void)
|
||||||
{
|
{
|
||||||
return SLang_TT_Baud_Rate;
|
return SLang_TT_Baud_Rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_lowlevel_getch (void)
|
tty_lowlevel_getch (void)
|
||||||
{
|
{
|
||||||
@ -400,6 +428,8 @@ tty_lowlevel_getch (void)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
tty_reset_screen (void)
|
tty_reset_screen (void)
|
||||||
{
|
{
|
||||||
@ -407,18 +437,24 @@ tty_reset_screen (void)
|
|||||||
return 0; /* OK */
|
return 0; /* OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_touch_screen (void)
|
tty_touch_screen (void)
|
||||||
{
|
{
|
||||||
SLsmg_touch_lines (0, LINES);
|
SLsmg_touch_lines (0, LINES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_gotoyx (int y, int x)
|
tty_gotoyx (int y, int x)
|
||||||
{
|
{
|
||||||
SLsmg_gotorc (y, x);
|
SLsmg_gotorc (y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_getyx (int *py, int *px)
|
tty_getyx (int *py, int *px)
|
||||||
{
|
{
|
||||||
@ -426,7 +462,9 @@ tty_getyx (int *py, int *px)
|
|||||||
*px = SLsmg_get_column ();
|
*px = SLsmg_get_column ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* if x < 0 or y < 0, draw line staring from current position */
|
/* if x < 0 or y < 0, draw line staring from current position */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_hline (int y, int x, int ch, int len)
|
tty_draw_hline (int y, int x, int ch, int len)
|
||||||
{
|
{
|
||||||
@ -453,7 +491,9 @@ tty_draw_hline (int y, int x, int ch, int len)
|
|||||||
SLsmg_gotorc (y, x);
|
SLsmg_gotorc (y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* if x < 0 or y < 0, draw line staring from current position */
|
/* if x < 0 or y < 0, draw line staring from current position */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_vline (int y, int x, int ch, int len)
|
tty_draw_vline (int y, int x, int ch, int len)
|
||||||
{
|
{
|
||||||
@ -488,30 +528,40 @@ tty_draw_vline (int y, int x, int ch, int len)
|
|||||||
SLsmg_gotorc (y, x);
|
SLsmg_gotorc (y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
||||||
{
|
{
|
||||||
SLsmg_fill_region (y, x, rows, cols, ch);
|
SLsmg_fill_region (y, x, rows, cols, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_set_alt_charset (gboolean alt_charset)
|
tty_set_alt_charset (gboolean alt_charset)
|
||||||
{
|
{
|
||||||
SLsmg_set_char_set ((int) alt_charset);
|
SLsmg_set_char_set ((int) alt_charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_display_8bit (gboolean what)
|
tty_display_8bit (gboolean what)
|
||||||
{
|
{
|
||||||
SLsmg_Display_Eight_Bit = what ? 128 : 160;
|
SLsmg_Display_Eight_Bit = what ? 128 : 160;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_char (int c)
|
tty_print_char (int c)
|
||||||
{
|
{
|
||||||
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_alt_char (int c, gboolean single)
|
tty_print_alt_char (int c, gboolean single)
|
||||||
{
|
{
|
||||||
@ -553,6 +603,8 @@ tty_print_alt_char (int c, gboolean single)
|
|||||||
#undef DRAW
|
#undef DRAW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_anychar (int c)
|
tty_print_anychar (int c)
|
||||||
{
|
{
|
||||||
@ -578,12 +630,16 @@ tty_print_anychar (int c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_string (const char *s)
|
tty_print_string (const char *s)
|
||||||
{
|
{
|
||||||
SLsmg_write_string ((char *) str_term_form (s));
|
SLsmg_write_string ((char *) str_term_form (s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_printf (const char *fmt, ...)
|
tty_printf (const char *fmt, ...)
|
||||||
{
|
{
|
||||||
@ -594,18 +650,24 @@ tty_printf (const char *fmt, ...)
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
tty_tgetstr (const char *cap)
|
tty_tgetstr (const char *cap)
|
||||||
{
|
{
|
||||||
return SLtt_tgetstr ((char *) cap);
|
return SLtt_tgetstr ((char *) cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_refresh (void)
|
tty_refresh (void)
|
||||||
{
|
{
|
||||||
SLsmg_refresh ();
|
SLsmg_refresh ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_setup_sigwinch (void (*handler) (int))
|
tty_setup_sigwinch (void (*handler) (int))
|
||||||
{
|
{
|
||||||
@ -621,8 +683,12 @@ tty_setup_sigwinch (void (*handler) (int))
|
|||||||
#endif /* SIGWINCH */
|
#endif /* SIGWINCH */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_beep (void)
|
tty_beep (void)
|
||||||
{
|
{
|
||||||
SLtt_beep ();
|
SLtt_beep ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,33 +1,46 @@
|
|||||||
|
|
||||||
#ifndef MC_TTY_SLANG_H
|
#ifndef MC__TTY_SLANG_H
|
||||||
#define MC_TTY_SLANG_H
|
#define MC__TTY_SLANG_H
|
||||||
|
|
||||||
#ifdef HAVE_SLANG_SLANG_H
|
#ifdef HAVE_SLANG_SLANG_H
|
||||||
# include <slang/slang.h>
|
#include <slang/slang.h>
|
||||||
#else
|
#else
|
||||||
# include <slang.h>
|
#include <slang.h>
|
||||||
#endif /* HAVE_SLANG_SLANG_H */
|
#endif /* HAVE_SLANG_SLANG_H */
|
||||||
|
|
||||||
enum {
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define KEY_F(x) (1000 + x)
|
||||||
|
|
||||||
|
#define ACS_VLINE SLSMG_VLINE_CHAR
|
||||||
|
#define ACS_HLINE SLSMG_HLINE_CHAR
|
||||||
|
#define ACS_LTEE SLSMG_LTEE_CHAR
|
||||||
|
#define ACS_RTEE SLSMG_RTEE_CHAR
|
||||||
|
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
|
||||||
|
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
|
||||||
|
#define ACS_URCORNER SLSMG_URCORN_CHAR
|
||||||
|
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
|
||||||
|
#define ACS_PLUS SLSMG_PLUS_CHAR
|
||||||
|
|
||||||
|
#define COLS SLtt_Screen_Cols
|
||||||
|
#define LINES SLtt_Screen_Rows
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
KEY_BACKSPACE = 400,
|
KEY_BACKSPACE = 400,
|
||||||
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||||
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
||||||
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
||||||
};
|
};
|
||||||
|
|
||||||
#define KEY_F(x) (1000 + x)
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
#define ACS_VLINE SLSMG_VLINE_CHAR
|
/*** global variables defined in .c file *********************************************************/
|
||||||
#define ACS_HLINE SLSMG_HLINE_CHAR
|
|
||||||
#define ACS_LTEE SLSMG_LTEE_CHAR
|
|
||||||
#define ACS_RTEE SLSMG_RTEE_CHAR
|
|
||||||
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
|
|
||||||
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
|
|
||||||
#define ACS_URCORNER SLSMG_URCORN_CHAR
|
|
||||||
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
|
|
||||||
#define ACS_PLUS SLSMG_PLUS_CHAR
|
|
||||||
|
|
||||||
#define COLS SLtt_Screen_Cols
|
/*** declarations of public functions ************************************************************/
|
||||||
#define LINES SLtt_Screen_Rows
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif /* MC_TTY_SLANG_H */
|
#endif /* MC_TTY_SLANG_H */
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "tty-internal.h"
|
#include "tty-internal.h"
|
||||||
|
|
||||||
|
|
||||||
/*** global variables **************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
/* If true program softkeys (HP terminals only) on startup and after every
|
/* If true program softkeys (HP terminals only) on startup and after every
|
||||||
command ran in the subshell to the description found in the termcap/terminfo
|
command ran in the subshell to the description found in the termcap/terminfo
|
||||||
@ -56,15 +56,16 @@ gboolean ugly_line_drawing = FALSE;
|
|||||||
|
|
||||||
int mc_tty_frm[MC_TTY_FRM_MAX];
|
int mc_tty_frm[MC_TTY_FRM_MAX];
|
||||||
|
|
||||||
/*** file scope macro definitions **************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
/*** file scope type declarations **************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
/*** file scope variables **********************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static volatile sig_atomic_t got_interrupt = 0;
|
static volatile sig_atomic_t got_interrupt = 0;
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sigintr_handler (int signo)
|
sigintr_handler (int signo)
|
||||||
@ -73,7 +74,9 @@ sigintr_handler (int signo)
|
|||||||
got_interrupt = 1;
|
got_interrupt = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** public functions **************************************************/
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern gboolean
|
extern gboolean
|
||||||
tty_is_slow (void)
|
tty_is_slow (void)
|
||||||
@ -81,6 +84,8 @@ tty_is_slow (void)
|
|||||||
return slow_tty;
|
return slow_tty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
tty_start_interrupt_key (void)
|
tty_start_interrupt_key (void)
|
||||||
{
|
{
|
||||||
@ -92,6 +97,8 @@ tty_start_interrupt_key (void)
|
|||||||
sigaction (SIGINT, &act, NULL);
|
sigaction (SIGINT, &act, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
tty_enable_interrupt_key (void)
|
tty_enable_interrupt_key (void)
|
||||||
{
|
{
|
||||||
@ -104,6 +111,8 @@ tty_enable_interrupt_key (void)
|
|||||||
got_interrupt = 0;
|
got_interrupt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
tty_disable_interrupt_key (void)
|
tty_disable_interrupt_key (void)
|
||||||
{
|
{
|
||||||
@ -115,6 +124,8 @@ tty_disable_interrupt_key (void)
|
|||||||
sigaction (SIGINT, &act, NULL);
|
sigaction (SIGINT, &act, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern gboolean
|
extern gboolean
|
||||||
tty_got_interrupt (void)
|
tty_got_interrupt (void)
|
||||||
{
|
{
|
||||||
@ -125,18 +136,24 @@ tty_got_interrupt (void)
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_one_hline (gboolean single)
|
tty_print_one_hline (gboolean single)
|
||||||
{
|
{
|
||||||
tty_print_alt_char (ACS_HLINE, single);
|
tty_print_alt_char (ACS_HLINE, single);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_print_one_vline (gboolean single)
|
tty_print_one_vline (gboolean single)
|
||||||
{
|
{
|
||||||
tty_print_alt_char (ACS_VLINE, single);
|
tty_print_alt_char (ACS_VLINE, single);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tty_draw_box (int y, int x, int ys, int xs, gboolean single)
|
tty_draw_box (int y, int x, int ys, int xs, gboolean single)
|
||||||
{
|
{
|
||||||
@ -157,6 +174,8 @@ tty_draw_box (int y, int x, int ys, int xs, gboolean single)
|
|||||||
tty_print_alt_char (ACS_LRCORNER, single);
|
tty_print_alt_char (ACS_LRCORNER, single);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
mc_tty_normalize_from_utf8 (const char *str)
|
mc_tty_normalize_from_utf8 (const char *str)
|
||||||
{
|
{
|
||||||
@ -183,3 +202,5 @@ mc_tty_normalize_from_utf8 (const char *str)
|
|||||||
|
|
||||||
return g_string_free (buffer, FALSE);
|
return g_string_free (buffer, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
100
lib/tty/tty.h
100
lib/tty/tty.h
@ -8,17 +8,68 @@
|
|||||||
* files small.
|
* files small.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_TTY_H
|
#ifndef MC__TTY_H
|
||||||
#define MC_TTY_H
|
#define MC__TTY_H
|
||||||
|
|
||||||
#include "lib/global.h" /* include <glib.h> */
|
#include "lib/global.h" /* include <glib.h> */
|
||||||
|
|
||||||
#ifdef HAVE_SLANG
|
#ifdef HAVE_SLANG
|
||||||
# include "tty-slang.h"
|
#include "tty-slang.h"
|
||||||
#else
|
#else
|
||||||
# include "tty-ncurses.h"
|
#include "tty-ncurses.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define KEY_KP_ADD 4001
|
||||||
|
#define KEY_KP_SUBTRACT 4002
|
||||||
|
#define KEY_KP_MULTIPLY 4003
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
/* single lines */
|
||||||
|
MC_TTY_FRM_VERT,
|
||||||
|
MC_TTY_FRM_HORIZ,
|
||||||
|
MC_TTY_FRM_LEFTTOP,
|
||||||
|
MC_TTY_FRM_RIGHTTOP,
|
||||||
|
MC_TTY_FRM_LEFTBOTTOM,
|
||||||
|
MC_TTY_FRM_RIGHTBOTTOM,
|
||||||
|
MC_TTY_FRM_TOPMIDDLE,
|
||||||
|
MC_TTY_FRM_BOTTOMMIDDLE,
|
||||||
|
MC_TTY_FRM_LEFTMIDDLE,
|
||||||
|
MC_TTY_FRM_RIGHTMIDDLE,
|
||||||
|
MC_TTY_FRM_CROSS,
|
||||||
|
|
||||||
|
/* double lines */
|
||||||
|
MC_TTY_FRM_DVERT,
|
||||||
|
MC_TTY_FRM_DHORIZ,
|
||||||
|
MC_TTY_FRM_DLEFTTOP,
|
||||||
|
MC_TTY_FRM_DRIGHTTOP,
|
||||||
|
MC_TTY_FRM_DLEFTBOTTOM,
|
||||||
|
MC_TTY_FRM_DRIGHTBOTTOM,
|
||||||
|
MC_TTY_FRM_DTOPMIDDLE,
|
||||||
|
MC_TTY_FRM_DBOTTOMMIDDLE,
|
||||||
|
MC_TTY_FRM_DLEFTMIDDLE,
|
||||||
|
MC_TTY_FRM_DRIGHTMIDDLE,
|
||||||
|
|
||||||
|
MC_TTY_FRM_MAX
|
||||||
|
} mc_tty_frm_t;
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
extern int mc_tty_frm[];
|
||||||
|
|
||||||
|
extern char *tty_tgetstr (const char *name);
|
||||||
|
|
||||||
|
extern void tty_beep (void);
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/* {{{ Input }}} */
|
/* {{{ Input }}} */
|
||||||
|
|
||||||
extern int reset_hp_softkeys;
|
extern int reset_hp_softkeys;
|
||||||
@ -78,49 +129,10 @@ extern void tty_draw_vline (int y, int x, int ch, int len);
|
|||||||
extern void tty_draw_box (int y, int x, int rows, int cols, gboolean single);
|
extern void tty_draw_box (int y, int x, int rows, int cols, gboolean single);
|
||||||
extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch);
|
extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch);
|
||||||
|
|
||||||
extern int mc_tty_frm[];
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
/* single lines */
|
|
||||||
MC_TTY_FRM_VERT,
|
|
||||||
MC_TTY_FRM_HORIZ,
|
|
||||||
MC_TTY_FRM_LEFTTOP,
|
|
||||||
MC_TTY_FRM_RIGHTTOP,
|
|
||||||
MC_TTY_FRM_LEFTBOTTOM,
|
|
||||||
MC_TTY_FRM_RIGHTBOTTOM,
|
|
||||||
MC_TTY_FRM_TOPMIDDLE,
|
|
||||||
MC_TTY_FRM_BOTTOMMIDDLE,
|
|
||||||
MC_TTY_FRM_LEFTMIDDLE,
|
|
||||||
MC_TTY_FRM_RIGHTMIDDLE,
|
|
||||||
MC_TTY_FRM_CROSS,
|
|
||||||
|
|
||||||
/* double lines */
|
|
||||||
MC_TTY_FRM_DVERT,
|
|
||||||
MC_TTY_FRM_DHORIZ,
|
|
||||||
MC_TTY_FRM_DLEFTTOP,
|
|
||||||
MC_TTY_FRM_DRIGHTTOP,
|
|
||||||
MC_TTY_FRM_DLEFTBOTTOM,
|
|
||||||
MC_TTY_FRM_DRIGHTBOTTOM,
|
|
||||||
MC_TTY_FRM_DTOPMIDDLE,
|
|
||||||
MC_TTY_FRM_DBOTTOMMIDDLE,
|
|
||||||
MC_TTY_FRM_DLEFTMIDDLE,
|
|
||||||
MC_TTY_FRM_DRIGHTMIDDLE,
|
|
||||||
|
|
||||||
MC_TTY_FRM_MAX
|
|
||||||
} mc_tty_frm_t;
|
|
||||||
|
|
||||||
extern char *tty_tgetstr (const char *name);
|
|
||||||
|
|
||||||
extern void tty_beep (void);
|
|
||||||
|
|
||||||
#define KEY_KP_ADD 4001
|
|
||||||
#define KEY_KP_SUBTRACT 4002
|
|
||||||
#define KEY_KP_MULTIPLY 4003
|
|
||||||
|
|
||||||
extern void tty_refresh (void);
|
extern void tty_refresh (void);
|
||||||
extern void tty_setup_sigwinch (void (*handler) (int));
|
extern void tty_setup_sigwinch (void (*handler) (int));
|
||||||
|
|
||||||
extern int mc_tty_normalize_lines_char (const char *);
|
extern int mc_tty_normalize_lines_char (const char *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_TTY_H */
|
#endif /* MC_TTY_H */
|
||||||
|
@ -33,11 +33,11 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "tty.h" /* tty_gotoyx, tty_print_char */
|
#include "tty.h" /* tty_gotoyx, tty_print_char */
|
||||||
#include "win.h"
|
#include "win.h"
|
||||||
#include "src/consaver/cons.saver.h" /* console_flag */
|
#include "src/consaver/cons.saver.h" /* console_flag */
|
||||||
|
|
||||||
/*** global variables **************************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
/* This flag is set by xterm detection routine in function main() */
|
/* This flag is set by xterm detection routine in function main() */
|
||||||
/* It is used by function view_other_cmd() */
|
/* It is used by function view_other_cmd() */
|
||||||
@ -45,15 +45,16 @@ int xterm_flag = 0;
|
|||||||
|
|
||||||
extern int keybar_visible;
|
extern int keybar_visible;
|
||||||
|
|
||||||
/*** file scope macro definitions **************************************/
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
/*** file scope type declarations **************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
/*** file scope variables **********************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static gboolean rxvt_extensions = FALSE;
|
static gboolean rxvt_extensions = FALSE;
|
||||||
|
|
||||||
/*** file scope functions **********************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* my own wierd protocol base 16 - paul */
|
/* my own wierd protocol base 16 - paul */
|
||||||
static int
|
static int
|
||||||
@ -71,6 +72,8 @@ rxvt_getc (void)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
anything_ready (void)
|
anything_ready (void)
|
||||||
{
|
{
|
||||||
@ -84,26 +87,34 @@ anything_ready (void)
|
|||||||
return select (1, &fds, 0, 0, &tv);
|
return select (1, &fds, 0, 0, &tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** public functions **************************************************/
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
do_enter_ca_mode (void)
|
do_enter_ca_mode (void)
|
||||||
{
|
{
|
||||||
if (xterm_flag) {
|
if (xterm_flag)
|
||||||
|
{
|
||||||
fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
|
fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
do_exit_ca_mode (void)
|
do_exit_ca_mode (void)
|
||||||
{
|
{
|
||||||
if (xterm_flag) {
|
if (xterm_flag)
|
||||||
|
{
|
||||||
fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
|
fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
|
||||||
fflush (stdout);
|
fflush (stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
||||||
{
|
{
|
||||||
@ -115,20 +126,22 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
|||||||
while (anything_ready ())
|
while (anything_ready ())
|
||||||
tty_lowlevel_getch ();
|
tty_lowlevel_getch ();
|
||||||
|
|
||||||
/* my own wierd protocol base 26 - paul */
|
/* my own wierd protocol base 26 - paul */
|
||||||
printf ("\033CL%c%c%c%c\n", (y1 / 26) + 'A', (y1 % 26) + 'A', (y2 / 26) + 'A', (y2 % 26) + 'A');
|
printf ("\033CL%c%c%c%c\n", (y1 / 26) + 'A', (y1 % 26) + 'A', (y2 / 26) + 'A', (y2 % 26) + 'A');
|
||||||
|
|
||||||
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
|
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
|
||||||
j = 0;
|
j = 0;
|
||||||
k = g_malloc (bytes);
|
k = g_malloc (bytes);
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
int c;
|
int c;
|
||||||
c = rxvt_getc ();
|
c = rxvt_getc ();
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
if (j < bytes)
|
if (j < bytes)
|
||||||
k[j++] = c;
|
k[j++] = c;
|
||||||
for (cols = 1;; cols++) {
|
for (cols = 1;; cols++)
|
||||||
|
{
|
||||||
c = rxvt_getc ();
|
c = rxvt_getc ();
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
@ -136,7 +149,8 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
|||||||
k[j++] = c;
|
k[j++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < j; i++) {
|
for (i = 0; i < j; i++)
|
||||||
|
{
|
||||||
if ((i % cols) == 0)
|
if ((i % cols) == 0)
|
||||||
tty_gotoyx (starty + (i / cols), 0);
|
tty_gotoyx (starty + (i / cols), 0);
|
||||||
tty_print_char (is_printable (k[i]) ? k[i] : ' ');
|
tty_print_char (is_printable (k[i]) ? k[i] : ' ');
|
||||||
@ -144,12 +158,15 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
|||||||
g_free (k);
|
g_free (k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
look_for_rxvt_extensions (void)
|
look_for_rxvt_extensions (void)
|
||||||
{
|
{
|
||||||
static gboolean been_called = FALSE;
|
static gboolean been_called = FALSE;
|
||||||
|
|
||||||
if (!been_called) {
|
if (!been_called)
|
||||||
|
{
|
||||||
const char *e = getenv ("RXVT_EXT");
|
const char *e = getenv ("RXVT_EXT");
|
||||||
rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0));
|
rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0));
|
||||||
been_called = TRUE;
|
been_called = TRUE;
|
||||||
@ -160,3 +177,5 @@ look_for_rxvt_extensions (void)
|
|||||||
|
|
||||||
return rxvt_extensions;
|
return rxvt_extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
|
|
||||||
/** \file win.h
|
/** \file win.h
|
||||||
* \brief Header: X terminal management: xterm and rxvt
|
* \brief Header: X terminal management: xterm and rxvt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_WIN_H
|
#ifndef MC__WIN_H
|
||||||
#define MC_WIN_H
|
#define MC__WIN_H
|
||||||
|
|
||||||
#include "lib/global.h" /* <glib.h> */
|
#include "lib/global.h" /* <glib.h> */
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern int xterm_flag;
|
extern int xterm_flag;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
void do_enter_ca_mode (void);
|
void do_enter_ca_mode (void);
|
||||||
void do_exit_ca_mode (void);
|
void do_exit_ca_mode (void);
|
||||||
|
|
||||||
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2);
|
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2);
|
||||||
gboolean look_for_rxvt_extensions (void);
|
gboolean look_for_rxvt_extensions (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_WIN_H */
|
#endif /* MC_WIN_H */
|
||||||
|
@ -36,40 +36,39 @@ typedef int dummy; /* C99 forbids empty compilation unit */
|
|||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#ifdef HAVE_GMODULE
|
#ifdef HAVE_GMODULE
|
||||||
# include <gmodule.h>
|
#include <gmodule.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
#include "x11conn.h"
|
#include "x11conn.h"
|
||||||
|
|
||||||
/*** file scope type declarations **************************************/
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
#ifndef HAVE_GMODULE
|
||||||
|
#define func_XOpenDisplay XOpenDisplay
|
||||||
|
#define func_XCloseDisplay XCloseDisplay
|
||||||
|
#define func_XSetErrorHandler XSetErrorHandler
|
||||||
|
#define func_XSetIOErrorHandler XSetIOErrorHandler
|
||||||
|
#define func_XQueryPointer XQueryPointer
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
typedef int (*mc_XErrorHandler_callback) (Display *, XErrorEvent *);
|
typedef int (*mc_XErrorHandler_callback) (Display *, XErrorEvent *);
|
||||||
typedef int (*mc_XIOErrorHandler_callback) (Display *);
|
typedef int (*mc_XIOErrorHandler_callback) (Display *);
|
||||||
|
|
||||||
/*** file scope variables **********************************************/
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
#ifdef HAVE_GMODULE
|
#ifdef HAVE_GMODULE
|
||||||
|
|
||||||
static Display *(*func_XOpenDisplay) (_Xconst char *);
|
static Display *(*func_XOpenDisplay) (_Xconst char *);
|
||||||
static int (*func_XCloseDisplay) (Display *);
|
static int (*func_XCloseDisplay) (Display *);
|
||||||
static mc_XErrorHandler_callback (*func_XSetErrorHandler)
|
static mc_XErrorHandler_callback (*func_XSetErrorHandler) (mc_XErrorHandler_callback);
|
||||||
(mc_XErrorHandler_callback);
|
static mc_XIOErrorHandler_callback (*func_XSetIOErrorHandler) (mc_XIOErrorHandler_callback);
|
||||||
static mc_XIOErrorHandler_callback (*func_XSetIOErrorHandler)
|
|
||||||
(mc_XIOErrorHandler_callback);
|
|
||||||
static Bool (*func_XQueryPointer) (Display *, Window, Window *, Window *,
|
static Bool (*func_XQueryPointer) (Display *, Window, Window *, Window *,
|
||||||
int *, int *, int *, int *, unsigned int *);
|
int *, int *, int *, int *, unsigned int *);
|
||||||
|
|
||||||
static GModule *x11_module;
|
static GModule *x11_module;
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define func_XOpenDisplay XOpenDisplay
|
|
||||||
#define func_XCloseDisplay XCloseDisplay
|
|
||||||
#define func_XSetErrorHandler XSetErrorHandler
|
|
||||||
#define func_XSetIOErrorHandler XSetIOErrorHandler
|
|
||||||
#define func_XQueryPointer XQueryPointer
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static gboolean handlers_installed = FALSE;
|
static gboolean handlers_installed = FALSE;
|
||||||
@ -82,7 +81,8 @@ static gboolean lost_connection = FALSE;
|
|||||||
static jmp_buf x11_exception; /* FIXME: get a better name */
|
static jmp_buf x11_exception; /* FIXME: get a better name */
|
||||||
static gboolean longjmp_allowed = FALSE;
|
static gboolean longjmp_allowed = FALSE;
|
||||||
|
|
||||||
/*** file private functions ********************************************/
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x_io_error_handler (Display * dpy)
|
x_io_error_handler (Display * dpy)
|
||||||
@ -90,13 +90,16 @@ x_io_error_handler (Display * dpy)
|
|||||||
(void) dpy;
|
(void) dpy;
|
||||||
|
|
||||||
lost_connection = TRUE;
|
lost_connection = TRUE;
|
||||||
if (longjmp_allowed) {
|
if (longjmp_allowed)
|
||||||
|
{
|
||||||
longjmp_allowed = FALSE;
|
longjmp_allowed = FALSE;
|
||||||
longjmp (x11_exception, 1);
|
longjmp (x11_exception, 1);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
x_error_handler (Display * dpy, XErrorEvent * ee)
|
x_error_handler (Display * dpy, XErrorEvent * ee)
|
||||||
{
|
{
|
||||||
@ -105,6 +108,8 @@ x_error_handler (Display * dpy, XErrorEvent * ee)
|
|||||||
return x_io_error_handler (dpy);
|
return x_io_error_handler (dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
install_error_handlers (void)
|
install_error_handlers (void)
|
||||||
{
|
{
|
||||||
@ -116,6 +121,8 @@ install_error_handlers (void)
|
|||||||
handlers_installed = TRUE;
|
handlers_installed = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
x11_available (void)
|
x11_available (void)
|
||||||
{
|
{
|
||||||
@ -167,15 +174,19 @@ x11_available (void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** public functions **************************************************/
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Display *
|
Display *
|
||||||
mc_XOpenDisplay (const char *displayname)
|
mc_XOpenDisplay (const char *displayname)
|
||||||
{
|
{
|
||||||
Display *retval;
|
Display *retval;
|
||||||
|
|
||||||
if (x11_available ()) {
|
if (x11_available ())
|
||||||
if (setjmp (x11_exception) == 0) {
|
{
|
||||||
|
if (setjmp (x11_exception) == 0)
|
||||||
|
{
|
||||||
longjmp_allowed = TRUE;
|
longjmp_allowed = TRUE;
|
||||||
retval = func_XOpenDisplay (displayname);
|
retval = func_XOpenDisplay (displayname);
|
||||||
longjmp_allowed = FALSE;
|
longjmp_allowed = FALSE;
|
||||||
@ -185,13 +196,17 @@ mc_XOpenDisplay (const char *displayname)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
mc_XCloseDisplay (Display * display)
|
mc_XCloseDisplay (Display * display)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (x11_available ()) {
|
if (x11_available ())
|
||||||
if (setjmp (x11_exception) == 0) {
|
{
|
||||||
|
if (setjmp (x11_exception) == 0)
|
||||||
|
{
|
||||||
longjmp_allowed = TRUE;
|
longjmp_allowed = TRUE;
|
||||||
retval = func_XCloseDisplay (display);
|
retval = func_XCloseDisplay (display);
|
||||||
longjmp_allowed = FALSE;
|
longjmp_allowed = FALSE;
|
||||||
@ -201,6 +216,8 @@ mc_XCloseDisplay (Display * display)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
mc_XQueryPointer (Display * display, Window win, Window * root_return,
|
mc_XQueryPointer (Display * display, Window win, Window * root_return,
|
||||||
Window * child_return, int *root_x_return, int *root_y_return,
|
Window * child_return, int *root_x_return, int *root_y_return,
|
||||||
@ -208,8 +225,10 @@ mc_XQueryPointer (Display * display, Window win, Window * root_return,
|
|||||||
{
|
{
|
||||||
Bool retval;
|
Bool retval;
|
||||||
|
|
||||||
if (x11_available ()) {
|
if (x11_available ())
|
||||||
if (setjmp (x11_exception) == 0) {
|
{
|
||||||
|
if (setjmp (x11_exception) == 0)
|
||||||
|
{
|
||||||
longjmp_allowed = TRUE;
|
longjmp_allowed = TRUE;
|
||||||
retval = func_XQueryPointer (display, win, root_return,
|
retval = func_XQueryPointer (display, win, root_return,
|
||||||
child_return, root_x_return, root_y_return,
|
child_return, root_x_return, root_y_return,
|
||||||
@ -228,4 +247,6 @@ mc_XQueryPointer (Display * display, Window win, Window * root_return,
|
|||||||
return False;
|
return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
|
|
||||||
/** \file x11conn.h
|
/** \file x11conn.h
|
||||||
* \brief Header: X11 support
|
* \brief Header: X11 support
|
||||||
* \warning This code uses setjmp() and longjmp(). Before you modify _anything_ here,
|
* \warning This code uses setjmp() and longjmp(). Before you modify _anything_ here,
|
||||||
* please read the relevant sections of the C standard.
|
* please read the relevant sections of the C standard.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_X11CONN_H
|
#ifndef MC__X11CONN_H
|
||||||
#define MC_X11CONN_H
|
#define MC__X11CONN_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This module provides support for some X11 functions. The functions
|
This module provides support for some X11 functions. The functions
|
||||||
@ -15,14 +14,25 @@
|
|||||||
error or a connection error, all further traffic to the X server
|
error or a connection error, all further traffic to the X server
|
||||||
will be suppressed, and the functions will return reasonable default
|
will be suppressed, and the functions will return reasonable default
|
||||||
values.
|
values.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
extern Display *mc_XOpenDisplay (const char *);
|
extern Display *mc_XOpenDisplay (const char *);
|
||||||
extern int mc_XCloseDisplay (Display *);
|
extern int mc_XCloseDisplay (Display *);
|
||||||
|
|
||||||
extern Bool mc_XQueryPointer (Display *, Window, Window *, Window *,
|
extern Bool mc_XQueryPointer (Display *, Window, Window *, Window *,
|
||||||
int *, int *, int *, int *, unsigned int *);
|
int *, int *, int *, int *, unsigned int *);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file unixcompat.h
|
/** \file unixcompat.h
|
||||||
* \brief Header: collects differences between the various Unix
|
* \brief Header: collects differences between the various Unix
|
||||||
*
|
*
|
||||||
@ -12,29 +11,43 @@
|
|||||||
#ifndef MC_UNIXCOMPAT_H
|
#ifndef MC_UNIXCOMPAT_H
|
||||||
#define MC_UNIXCOMPAT_H
|
#define MC_UNIXCOMPAT_H
|
||||||
|
|
||||||
#include <sys/types.h> /* BSD */
|
#include <sys/types.h> /* BSD */
|
||||||
#ifdef HAVE_SYS_MKDEV_H
|
#ifdef HAVE_SYS_MKDEV_H
|
||||||
# include <sys/mkdev.h> /* Solaris 9 */
|
#include <sys/mkdev.h> /* Solaris 9 */
|
||||||
#endif
|
#endif
|
||||||
#if defined(_AIX) && defined(HAVE_SYS_SYSMACROS_H)
|
#if defined(_AIX) && defined(HAVE_SYS_SYSMACROS_H)
|
||||||
# include <sys/sysmacros.h> /* AIX */
|
#include <sys/sysmacros.h> /* AIX */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_AIX)
|
#if defined(_AIX)
|
||||||
# include <time.h> /* AIX for tm */
|
#include <time.h> /* AIX for tm */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#ifndef major
|
#ifndef major
|
||||||
# warning major() is undefined. Device numbers will not be shown correctly.
|
#warning major() is undefined. Device numbers will not be shown correctly.
|
||||||
# define major(devnum) (((devnum) >> 8) & 0xff)
|
#define major(devnum) (((devnum) >> 8) & 0xff)
|
||||||
#endif
|
|
||||||
#ifndef minor
|
|
||||||
# warning minor() is undefined. Device numbers will not be shown correctly.
|
|
||||||
# define minor(devnum) (((devnum) & 0xff))
|
|
||||||
#endif
|
|
||||||
#ifndef makedev
|
|
||||||
# warning makedev() is undefined. Device numbers will not be shown correctly.
|
|
||||||
# define makedev(major,minor) ((((major) & 0xff) << 8) | ((minor) & 0xff))
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef minor
|
||||||
|
#warning minor() is undefined. Device numbers will not be shown correctly.
|
||||||
|
#define minor(devnum) (((devnum) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef makedev
|
||||||
|
#warning makedev() is undefined. Device numbers will not be shown correctly.
|
||||||
|
#define makedev(major,minor) ((((major) & 0xff) << 8) | ((minor) & 0xff))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
477
lib/util.c
477
lib/util.c
@ -55,11 +55,33 @@
|
|||||||
#include "src/main.h" /* eight_bit_clean */
|
#include "src/main.h" /* eight_bit_clean */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
int easy_patterns = 1;
|
int easy_patterns = 1;
|
||||||
|
|
||||||
char *user_recent_timeformat = NULL; /* time format string for recent dates */
|
char *user_recent_timeformat = NULL; /* time format string for recent dates */
|
||||||
char *user_old_timeformat = NULL; /* time format string for older dates */
|
char *user_old_timeformat = NULL; /* time format string for older dates */
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
#define ismode(n,m) ((n & m) == m)
|
||||||
|
|
||||||
|
/* Number of attempts to create a temporary file */
|
||||||
|
#ifndef TMP_MAX
|
||||||
|
#define TMP_MAX 16384
|
||||||
|
#endif /* !TMP_MAX */
|
||||||
|
|
||||||
|
#define TMP_SUFFIX ".tmp"
|
||||||
|
|
||||||
|
#define ASCII_A (0x40 + 1)
|
||||||
|
#define ASCII_Z (0x40 + 26)
|
||||||
|
#define ASCII_a (0x60 + 1)
|
||||||
|
#define ASCII_z (0x60 + 26)
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Cache variable for the i18n_checktimelength function,
|
* Cache variable for the i18n_checktimelength function,
|
||||||
* initially set to a clearly invalid value to show that
|
* initially set to a clearly invalid value to show that
|
||||||
@ -67,6 +89,143 @@ char *user_old_timeformat = NULL; /* time format string for older dates */
|
|||||||
*/
|
*/
|
||||||
static size_t i18n_timelength_cache = MAX_I18NTIMELENGTH + 1;
|
static size_t i18n_timelength_cache = MAX_I18NTIMELENGTH + 1;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
is_7bit_printable (unsigned char c)
|
||||||
|
{
|
||||||
|
return (c > 31 && c < 127);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
is_iso_printable (unsigned char c)
|
||||||
|
{
|
||||||
|
return ((c > 31 && c < 127) || c >= 160);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
is_8bit_printable (unsigned char c)
|
||||||
|
{
|
||||||
|
/* "Full 8 bits output" doesn't work on xterm */
|
||||||
|
if (xterm_flag)
|
||||||
|
return is_iso_printable (c);
|
||||||
|
|
||||||
|
return (c > 31 && c != 127 && c != 155);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
resolve_symlinks (const char *path)
|
||||||
|
{
|
||||||
|
char *buf, *buf2, *q, *r, c;
|
||||||
|
int len;
|
||||||
|
struct stat mybuf;
|
||||||
|
const char *p;
|
||||||
|
|
||||||
|
if (*path != PATH_SEP)
|
||||||
|
return NULL;
|
||||||
|
r = buf = g_malloc (MC_MAXPATHLEN);
|
||||||
|
buf2 = g_malloc (MC_MAXPATHLEN);
|
||||||
|
*r++ = PATH_SEP;
|
||||||
|
*r = 0;
|
||||||
|
p = path;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
q = strchr (p + 1, PATH_SEP);
|
||||||
|
if (!q)
|
||||||
|
{
|
||||||
|
q = strchr (p + 1, 0);
|
||||||
|
if (q == p + 1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c = *q;
|
||||||
|
*q = 0;
|
||||||
|
if (mc_lstat (path, &mybuf) < 0)
|
||||||
|
{
|
||||||
|
g_free (buf);
|
||||||
|
g_free (buf2);
|
||||||
|
*q = c;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!S_ISLNK (mybuf.st_mode))
|
||||||
|
strcpy (r, p + 1);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = mc_readlink (path, buf2, MC_MAXPATHLEN - 1);
|
||||||
|
if (len < 0)
|
||||||
|
{
|
||||||
|
g_free (buf);
|
||||||
|
g_free (buf2);
|
||||||
|
*q = c;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
buf2[len] = 0;
|
||||||
|
if (*buf2 == PATH_SEP)
|
||||||
|
strcpy (buf, buf2);
|
||||||
|
else
|
||||||
|
strcpy (r, buf2);
|
||||||
|
}
|
||||||
|
canonicalize_pathname (buf);
|
||||||
|
r = strchr (buf, 0);
|
||||||
|
if (!*r || *(r - 1) != PATH_SEP)
|
||||||
|
{
|
||||||
|
*r++ = PATH_SEP;
|
||||||
|
*r = 0;
|
||||||
|
}
|
||||||
|
*q = c;
|
||||||
|
p = q;
|
||||||
|
if (!c)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!*buf)
|
||||||
|
strcpy (buf, PATH_SEP_STR);
|
||||||
|
else if (*(r - 1) == PATH_SEP && r != buf + 1)
|
||||||
|
*(r - 1) = 0;
|
||||||
|
g_free (buf2);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
mc_util_write_backup_content (const char *from_file_name, const char *to_file_name)
|
||||||
|
{
|
||||||
|
FILE *backup_fd;
|
||||||
|
char *contents;
|
||||||
|
gsize length;
|
||||||
|
gboolean ret1 = TRUE;
|
||||||
|
|
||||||
|
if (!g_file_get_contents (from_file_name, &contents, &length, NULL))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
backup_fd = fopen (to_file_name, "w");
|
||||||
|
if (backup_fd == NULL)
|
||||||
|
{
|
||||||
|
g_free (contents);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwrite ((const void *) contents, 1, length, backup_fd) != length)
|
||||||
|
ret1 = FALSE;
|
||||||
|
{
|
||||||
|
int ret2;
|
||||||
|
ret2 = fflush (backup_fd);
|
||||||
|
ret2 = fclose (backup_fd);
|
||||||
|
}
|
||||||
|
g_free (contents);
|
||||||
|
return ret1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
str_replace (char *s, char from, char to)
|
str_replace (char *s, char from, char to)
|
||||||
{
|
{
|
||||||
@ -77,27 +236,7 @@ str_replace (char *s, char from, char to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
is_7bit_printable (unsigned char c)
|
|
||||||
{
|
|
||||||
return (c > 31 && c < 127);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
is_iso_printable (unsigned char c)
|
|
||||||
{
|
|
||||||
return ((c > 31 && c < 127) || c >= 160);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int
|
|
||||||
is_8bit_printable (unsigned char c)
|
|
||||||
{
|
|
||||||
/* "Full 8 bits output" doesn't work on xterm */
|
|
||||||
if (xterm_flag)
|
|
||||||
return is_iso_printable (c);
|
|
||||||
|
|
||||||
return (c > 31 && c != 127 && c != 155);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
is_printable (int c)
|
is_printable (int c)
|
||||||
@ -121,7 +260,12 @@ is_printable (int c)
|
|||||||
#endif /* !HAVE_CHARSET */
|
#endif /* !HAVE_CHARSET */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculates the message dimensions (lines and columns) */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Calculates the message dimensions (lines and columns)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
msglen (const char *text, int *lines, int *columns)
|
msglen (const char *text, int *lines, int *columns)
|
||||||
{
|
{
|
||||||
@ -148,11 +292,13 @@ msglen (const char *text, int *lines, int *columns)
|
|||||||
*columns = ncolumns;
|
*columns = ncolumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Copy from s to d, and trim the beginning if necessary, and prepend
|
* Copy from s to d, and trim the beginning if necessary, and prepend
|
||||||
* "..." in this case. The destination string can have at most len
|
* "..." in this case. The destination string can have at most len
|
||||||
* bytes, not counting trailing 0.
|
* bytes, not counting trailing 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
trim (const char *s, char *d, int len)
|
trim (const char *s, char *d, int len)
|
||||||
{
|
{
|
||||||
@ -185,7 +331,8 @@ trim (const char *s, char *d, int len)
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Quote the filename for the purpose of inserting it into the command
|
* Quote the filename for the purpose of inserting it into the command
|
||||||
* line. If quote_percent is 1, replace "%" with "%%" - the percent is
|
* line. If quote_percent is 1, replace "%" with "%%" - the percent is
|
||||||
* processed by the mc command line.
|
* processed by the mc command line.
|
||||||
@ -247,6 +394,8 @@ name_quote (const char *s, int quote_percent)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
fake_name_quote (const char *s, int quote_percent)
|
fake_name_quote (const char *s, int quote_percent)
|
||||||
{
|
{
|
||||||
@ -254,22 +403,26 @@ fake_name_quote (const char *s, int quote_percent)
|
|||||||
return g_strdup (s);
|
return g_strdup (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Remove the middle part of the string to fit given length.
|
* Remove the middle part of the string to fit given length.
|
||||||
* Use "~" to show where the string was truncated.
|
* Use "~" to show where the string was truncated.
|
||||||
* Return static buffer, no need to free() it.
|
* Return static buffer, no need to free() it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
name_trunc (const char *txt, size_t trunc_len)
|
name_trunc (const char *txt, size_t trunc_len)
|
||||||
{
|
{
|
||||||
return str_trunc (txt, trunc_len);
|
return str_trunc (txt, trunc_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* path_trunc() is the same as name_trunc() above but
|
* path_trunc() is the same as name_trunc() above but
|
||||||
* it deletes possible password from path for security
|
* it deletes possible password from path for security
|
||||||
* reasons.
|
* reasons.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
path_trunc (const char *path, size_t trunc_len)
|
path_trunc (const char *path, size_t trunc_len)
|
||||||
{
|
{
|
||||||
@ -281,6 +434,8 @@ path_trunc (const char *path, size_t trunc_len)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
size_trunc (double size, gboolean use_si)
|
size_trunc (double size, gboolean use_si)
|
||||||
{
|
{
|
||||||
@ -302,6 +457,8 @@ size_trunc (double size, gboolean use_si)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
size_trunc_sep (double size, gboolean use_si)
|
size_trunc_sep (double size, gboolean use_si)
|
||||||
{
|
{
|
||||||
@ -331,7 +488,8 @@ size_trunc_sep (double size, gboolean use_si)
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Print file SIZE to BUFFER, but don't exceed LEN characters,
|
* Print file SIZE to BUFFER, but don't exceed LEN characters,
|
||||||
* not including trailing 0. BUFFER should be at least LEN+1 long.
|
* not including trailing 0. BUFFER should be at least LEN+1 long.
|
||||||
* This function is called for every file on panels, so avoid
|
* This function is called for every file on panels, so avoid
|
||||||
@ -340,6 +498,7 @@ size_trunc_sep (double size, gboolean use_si)
|
|||||||
* Units: size units (filesystem sizes are 1K blocks)
|
* Units: size units (filesystem sizes are 1K blocks)
|
||||||
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
|
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
size_trunc_len (char *buffer, unsigned int len, off_t size, int units, gboolean use_si)
|
size_trunc_len (char *buffer, unsigned int len, off_t size, int units, gboolean use_si)
|
||||||
{
|
{
|
||||||
@ -403,6 +562,8 @@ size_trunc_len (char *buffer, unsigned int len, off_t size, int units, gboolean
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
is_exe (mode_t mode)
|
is_exe (mode_t mode)
|
||||||
{
|
{
|
||||||
@ -411,7 +572,7 @@ is_exe (mode_t mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ismode(n,m) ((n & m) == m)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
string_perm (mode_t mode_bits)
|
string_perm (mode_t mode_bits)
|
||||||
@ -468,15 +629,18 @@ string_perm (mode_t mode_bits)
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* p: string which might contain an url with a password (this parameter is
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
modified in place).
|
/**
|
||||||
has_prefix = 0: The first parameter is an url without a prefix
|
* p: string which might contain an url with a password (this parameter is
|
||||||
(user[:pass]@]machine[:port][remote-dir). Delete
|
* modified in place).
|
||||||
the password.
|
* has_prefix = 0: The first parameter is an url without a prefix
|
||||||
has_prefix = 1: Search p for known url prefixes. If found delete
|
* (user[:pass]@]machine[:port][remote-dir). Delete
|
||||||
the password from the url.
|
* the password.
|
||||||
Caveat: only the first url is found
|
* has_prefix = 1: Search p for known url prefixes. If found delete
|
||||||
|
* the password from the url.
|
||||||
|
* Caveat: only the first url is found
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
strip_password (char *p, int has_prefix)
|
strip_password (char *p, int has_prefix)
|
||||||
{
|
{
|
||||||
@ -536,6 +700,8 @@ strip_password (char *p, int has_prefix)
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
strip_home_and_password (const char *dir)
|
strip_home_and_password (const char *dir)
|
||||||
{
|
{
|
||||||
@ -558,6 +724,8 @@ strip_home_and_password (const char *dir)
|
|||||||
return newdir;
|
return newdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
extension (const char *filename)
|
extension (const char *filename)
|
||||||
{
|
{
|
||||||
@ -565,12 +733,16 @@ extension (const char *filename)
|
|||||||
return (d != NULL) ? d + 1 : "";
|
return (d != NULL) ? d + 1 : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
exist_file (const char *name)
|
exist_file (const char *name)
|
||||||
{
|
{
|
||||||
return access (name, R_OK) == 0;
|
return access (name, R_OK) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
check_for_default (const char *default_file, const char *file)
|
check_for_default (const char *default_file, const char *file)
|
||||||
{
|
{
|
||||||
@ -593,7 +765,7 @@ check_for_default (const char *default_file, const char *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
load_file (const char *filename)
|
load_file (const char *filename)
|
||||||
@ -627,6 +799,8 @@ load_file (const char *filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
load_mc_home_file (const char *from, const char *filename, char **allocated_filename)
|
load_mc_home_file (const char *from, const char *filename, char **allocated_filename)
|
||||||
{
|
{
|
||||||
@ -670,8 +844,11 @@ load_mc_home_file (const char *from, const char *filename, char **allocated_file
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check strftime() results. Some systems (i.e. Solaris) have different
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
short-month and month name sizes for different locales */
|
/**
|
||||||
|
* Check strftime() results. Some systems (i.e. Solaris) have different
|
||||||
|
* short-month and month name sizes for different locales
|
||||||
|
*/
|
||||||
size_t
|
size_t
|
||||||
i18n_checktimelength (void)
|
i18n_checktimelength (void)
|
||||||
{
|
{
|
||||||
@ -695,10 +872,11 @@ i18n_checktimelength (void)
|
|||||||
lt->tm_sec = lt->tm_min = lt->tm_hour = lt->tm_mday = 10;
|
lt->tm_sec = lt->tm_min = lt->tm_hour = lt->tm_mday = 10;
|
||||||
|
|
||||||
/* Loop through all months to find out the longest one */
|
/* Loop through all months to find out the longest one */
|
||||||
for (lt->tm_mon = 0; lt->tm_mon < 12; lt->tm_mon++) {
|
for (lt->tm_mon = 0; lt->tm_mon < 12; lt->tm_mon++)
|
||||||
strftime (buf, sizeof(buf) - 1, user_recent_timeformat, lt);
|
{
|
||||||
|
strftime (buf, sizeof (buf) - 1, user_recent_timeformat, lt);
|
||||||
length = max ((size_t) str_term_width1 (buf), length);
|
length = max ((size_t) str_term_width1 (buf), length);
|
||||||
strftime (buf, sizeof(buf) - 1, user_old_timeformat, lt);
|
strftime (buf, sizeof (buf) - 1, user_old_timeformat, lt);
|
||||||
length = max ((size_t) str_term_width1 (buf), length);
|
length = max ((size_t) str_term_width1 (buf), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,6 +893,8 @@ i18n_checktimelength (void)
|
|||||||
return i18n_timelength_cache;
|
return i18n_timelength_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
file_date (time_t when)
|
file_date (time_t when)
|
||||||
{
|
{
|
||||||
@ -740,6 +920,8 @@ file_date (time_t when)
|
|||||||
return timebuf;
|
return timebuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
extract_line (const char *s, const char *top)
|
extract_line (const char *s, const char *top)
|
||||||
{
|
{
|
||||||
@ -752,7 +934,11 @@ extract_line (const char *s, const char *top)
|
|||||||
return tmp_line;
|
return tmp_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The basename routine */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* The basename routine
|
||||||
|
*/
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
x_basename (const char *s)
|
x_basename (const char *s)
|
||||||
{
|
{
|
||||||
@ -760,6 +946,7 @@ x_basename (const char *s)
|
|||||||
return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
|
return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
unix_error_string (int error_num)
|
unix_error_string (int error_num)
|
||||||
@ -774,6 +961,8 @@ unix_error_string (int error_num)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
skip_separators (const char *s)
|
skip_separators (const char *s)
|
||||||
{
|
{
|
||||||
@ -786,6 +975,8 @@ skip_separators (const char *s)
|
|||||||
return su;
|
return su;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
skip_numbers (const char *s)
|
skip_numbers (const char *s)
|
||||||
{
|
{
|
||||||
@ -798,7 +989,9 @@ skip_numbers (const char *s)
|
|||||||
return su;
|
return su;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove all control sequences from the argument string. We define
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Remove all control sequences from the argument string. We define
|
||||||
* "control sequence", in a sort of pidgin BNF, as follows:
|
* "control sequence", in a sort of pidgin BNF, as follows:
|
||||||
*
|
*
|
||||||
* control-seq = Esc non-'['
|
* control-seq = Esc non-'['
|
||||||
@ -883,6 +1076,8 @@ strip_ctrl_codes (char *s)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
enum compression_type
|
enum compression_type
|
||||||
get_compression_type (int fd, const char *name)
|
get_compression_type (int fd, const char *name)
|
||||||
{
|
{
|
||||||
@ -961,6 +1156,8 @@ get_compression_type (int fd, const char *name)
|
|||||||
return COMPRESSION_NONE;
|
return COMPRESSION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
decompress_extension (int type)
|
decompress_extension (int type)
|
||||||
{
|
{
|
||||||
@ -982,7 +1179,9 @@ decompress_extension (int type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Hooks */
|
/* Hooks */
|
||||||
|
|
||||||
void
|
void
|
||||||
add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data)
|
add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data)
|
||||||
{
|
{
|
||||||
@ -995,6 +1194,8 @@ add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data)
|
|||||||
*hook_list = new_hook;
|
*hook_list = new_hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
execute_hooks (Hook * hook_list)
|
execute_hooks (Hook * hook_list)
|
||||||
{
|
{
|
||||||
@ -1026,6 +1227,8 @@ execute_hooks (Hook * hook_list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
delete_hook (Hook ** hook_list, void (*hook_fn) (void *))
|
delete_hook (Hook ** hook_list, void (*hook_fn) (void *))
|
||||||
{
|
{
|
||||||
@ -1044,6 +1247,8 @@ delete_hook (Hook ** hook_list, void (*hook_fn) (void *))
|
|||||||
*hook_list = new_list;
|
*hook_list = new_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
||||||
{
|
{
|
||||||
@ -1055,6 +1260,8 @@ hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
wipe_password (char *passwd)
|
wipe_password (char *passwd)
|
||||||
{
|
{
|
||||||
@ -1067,8 +1274,12 @@ wipe_password (char *passwd)
|
|||||||
g_free (passwd);
|
g_free (passwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert "\E" -> esc character and ^x to control-x key and ^^ to ^ key */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Returns a newly allocated string */
|
/**
|
||||||
|
* Convert "\E" -> esc character and ^x to control-x key and ^^ to ^ key
|
||||||
|
* @returns a newly allocated string
|
||||||
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
convert_controls (const char *p)
|
convert_controls (const char *p)
|
||||||
{
|
{
|
||||||
@ -1114,108 +1325,12 @@ convert_controls (const char *p)
|
|||||||
return valcopy;
|
return valcopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
resolve_symlinks (const char *path)
|
/**
|
||||||
{
|
* Finds out a relative path from first to second, i.e. goes as many ..
|
||||||
char *buf, *buf2, *q, *r, c;
|
* as needed up in first and then goes down using second
|
||||||
int len;
|
*/
|
||||||
struct stat mybuf;
|
|
||||||
const char *p;
|
|
||||||
|
|
||||||
if (*path != PATH_SEP)
|
|
||||||
return NULL;
|
|
||||||
r = buf = g_malloc (MC_MAXPATHLEN);
|
|
||||||
buf2 = g_malloc (MC_MAXPATHLEN);
|
|
||||||
*r++ = PATH_SEP;
|
|
||||||
*r = 0;
|
|
||||||
p = path;
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
q = strchr (p + 1, PATH_SEP);
|
|
||||||
if (!q)
|
|
||||||
{
|
|
||||||
q = strchr (p + 1, 0);
|
|
||||||
if (q == p + 1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c = *q;
|
|
||||||
*q = 0;
|
|
||||||
if (mc_lstat (path, &mybuf) < 0)
|
|
||||||
{
|
|
||||||
g_free (buf);
|
|
||||||
g_free (buf2);
|
|
||||||
*q = c;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!S_ISLNK (mybuf.st_mode))
|
|
||||||
strcpy (r, p + 1);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
len = mc_readlink (path, buf2, MC_MAXPATHLEN - 1);
|
|
||||||
if (len < 0)
|
|
||||||
{
|
|
||||||
g_free (buf);
|
|
||||||
g_free (buf2);
|
|
||||||
*q = c;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
buf2[len] = 0;
|
|
||||||
if (*buf2 == PATH_SEP)
|
|
||||||
strcpy (buf, buf2);
|
|
||||||
else
|
|
||||||
strcpy (r, buf2);
|
|
||||||
}
|
|
||||||
canonicalize_pathname (buf);
|
|
||||||
r = strchr (buf, 0);
|
|
||||||
if (!*r || *(r - 1) != PATH_SEP)
|
|
||||||
{
|
|
||||||
*r++ = PATH_SEP;
|
|
||||||
*r = 0;
|
|
||||||
}
|
|
||||||
*q = c;
|
|
||||||
p = q;
|
|
||||||
if (!c)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (!*buf)
|
|
||||||
strcpy (buf, PATH_SEP_STR);
|
|
||||||
else if (*(r - 1) == PATH_SEP && r != buf + 1)
|
|
||||||
*(r - 1) = 0;
|
|
||||||
g_free (buf2);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
mc_util_write_backup_content (const char *from_file_name, const char *to_file_name)
|
|
||||||
{
|
|
||||||
FILE *backup_fd;
|
|
||||||
char *contents;
|
|
||||||
gsize length;
|
|
||||||
gboolean ret1 = TRUE;
|
|
||||||
|
|
||||||
if (!g_file_get_contents (from_file_name, &contents, &length, NULL))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
backup_fd = fopen (to_file_name, "w");
|
|
||||||
if (backup_fd == NULL)
|
|
||||||
{
|
|
||||||
g_free (contents);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fwrite ((const void *) contents, 1, length, backup_fd) != length)
|
|
||||||
ret1 = FALSE;
|
|
||||||
{
|
|
||||||
int ret2;
|
|
||||||
ret2 = fflush (backup_fd);
|
|
||||||
ret2 = fclose (backup_fd);
|
|
||||||
}
|
|
||||||
g_free (contents);
|
|
||||||
return ret1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Finds out a relative path from first to second, i.e. goes as many ..
|
|
||||||
* as needed up in first and then goes down using second */
|
|
||||||
char *
|
char *
|
||||||
diff_two_paths (const char *first, const char *second)
|
diff_two_paths (const char *first, const char *second)
|
||||||
{
|
{
|
||||||
@ -1283,7 +1398,11 @@ diff_two_paths (const char *first, const char *second)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If filename is NULL, then we just append PATH_SEP to the dir */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* If filename is NULL, then we just append PATH_SEP to the dir
|
||||||
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
concat_dir_and_file (const char *dir, const char *file)
|
concat_dir_and_file (const char *dir, const char *file)
|
||||||
{
|
{
|
||||||
@ -1295,7 +1414,11 @@ concat_dir_and_file (const char *dir, const char *file)
|
|||||||
return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL);
|
return g_strconcat (dir, PATH_SEP_STR, file, (char *) NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append text to GList, remove all entries with the same text */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Append text to GList, remove all entries with the same text
|
||||||
|
*/
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
list_append_unique (GList * list, char *text)
|
list_append_unique (GList * list, char *text)
|
||||||
{
|
{
|
||||||
@ -1329,13 +1452,8 @@ list_append_unique (GList * list, char *text)
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Following code heavily borrows from libiberty, mkstemps.c */
|
/* Following code heavily borrows from libiberty, mkstemps.c */
|
||||||
|
|
||||||
/* Number of attempts to create a temporary file */
|
|
||||||
#ifndef TMP_MAX
|
|
||||||
#define TMP_MAX 16384
|
|
||||||
#endif /* !TMP_MAX */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Arguments:
|
* Arguments:
|
||||||
* pname (output) - pointer to the name of the temp file (needs g_free).
|
* pname (output) - pointer to the name of the temp file (needs g_free).
|
||||||
@ -1347,6 +1465,7 @@ list_append_unique (GList * list, char *text)
|
|||||||
* Result:
|
* Result:
|
||||||
* handle of the open file or -1 if couldn't open any.
|
* handle of the open file or -1 if couldn't open any.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
mc_mkstemps (char **pname, const char *prefix, const char *suffix)
|
mc_mkstemps (char **pname, const char *prefix, const char *suffix)
|
||||||
{
|
{
|
||||||
@ -1415,12 +1534,15 @@ mc_mkstemps (char **pname, const char *prefix, const char *suffix)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Read and restore position for the given filename.
|
* Read and restore position for the given filename.
|
||||||
* If there is no stored data, return line 1 and col 0.
|
* If there is no stored data, return line 1 and col 0.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
load_file_position (const char *filename, long *line, long *column, off_t * offset, GArray **bookmarks)
|
load_file_position (const char *filename, long *line, long *column, off_t * offset,
|
||||||
|
GArray ** bookmarks)
|
||||||
{
|
{
|
||||||
char *fn;
|
char *fn;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
@ -1503,10 +1625,13 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
|
|||||||
fclose (f);
|
fclose (f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save position for the given file */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
#define TMP_SUFFIX ".tmp"
|
/**
|
||||||
|
* Save position for the given file
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
save_file_position (const char *filename, long line, long column, off_t offset, GArray *bookmarks)
|
save_file_position (const char *filename, long line, long column, off_t offset, GArray * bookmarks)
|
||||||
{
|
{
|
||||||
static size_t filepos_max_saved_entries = 0;
|
static size_t filepos_max_saved_entries = 0;
|
||||||
char *fn, *tmp_fn;
|
char *fn, *tmp_fn;
|
||||||
@ -1556,7 +1681,8 @@ save_file_position (const char *filename, long line, long column, off_t offset,
|
|||||||
i = 1;
|
i = 1;
|
||||||
while (fgets (buf, sizeof (buf), tmp_f) != NULL)
|
while (fgets (buf, sizeof (buf), tmp_f) != NULL)
|
||||||
{
|
{
|
||||||
if (buf[len] == ' ' && strncmp (buf, filename, len) == 0 && strchr (&buf[len + 1], ' ') == NULL)
|
if (buf[len] == ' ' && strncmp (buf, filename, len) == 0
|
||||||
|
&& strchr (&buf[len + 1], ' ') == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fprintf (f, "%s", buf);
|
fprintf (f, "%s", buf);
|
||||||
@ -1579,7 +1705,8 @@ save_file_position (const char *filename, long line, long column, off_t offset,
|
|||||||
g_array_free (bookmarks, TRUE);
|
g_array_free (bookmarks, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef TMP_SUFFIX
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern const char *
|
extern const char *
|
||||||
cstrcasestr (const char *haystack, const char *needle)
|
cstrcasestr (const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
@ -1589,22 +1716,23 @@ cstrcasestr (const char *haystack, const char *needle)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
cstrstr (const char *haystack, const char *needle)
|
cstrstr (const char *haystack, const char *needle)
|
||||||
{
|
{
|
||||||
return strstr (haystack, needle);
|
return strstr (haystack, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern char *
|
extern char *
|
||||||
str_unconst (const char *s)
|
str_unconst (const char *s)
|
||||||
{
|
{
|
||||||
return (char *) s;
|
return (char *) s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ASCII_A (0x40 + 1)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
#define ASCII_Z (0x40 + 26)
|
|
||||||
#define ASCII_a (0x60 + 1)
|
|
||||||
#define ASCII_z (0x60 + 26)
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
ascii_alpha_to_cntrl (int ch)
|
ascii_alpha_to_cntrl (int ch)
|
||||||
@ -1616,6 +1744,8 @@ ascii_alpha_to_cntrl (int ch)
|
|||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
Q_ (const char *s)
|
Q_ (const char *s)
|
||||||
{
|
{
|
||||||
@ -1626,6 +1756,7 @@ Q_ (const char *s)
|
|||||||
return (sep != NULL) ? sep + 1 : result;
|
return (sep != NULL) ? sep + 1 : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mc_util_make_backup_if_possible (const char *file_name, const char *backup_suffix)
|
mc_util_make_backup_if_possible (const char *file_name, const char *backup_suffix)
|
||||||
@ -1657,6 +1788,8 @@ mc_util_make_backup_if_possible (const char *file_name, const char *backup_suffi
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mc_util_restore_from_backup_if_possible (const char *file_name, const char *backup_suffix)
|
mc_util_restore_from_backup_if_possible (const char *file_name, const char *backup_suffix)
|
||||||
{
|
{
|
||||||
@ -1673,6 +1806,8 @@ mc_util_restore_from_backup_if_possible (const char *file_name, const char *back
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mc_util_unlink_backup_if_possible (const char *file_name, const char *backup_suffix)
|
mc_util_unlink_backup_if_possible (const char *file_name, const char *backup_suffix)
|
||||||
{
|
{
|
||||||
@ -1689,8 +1824,12 @@ mc_util_unlink_backup_if_possible (const char *file_name, const char *backup_suf
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* partly taken from dcigettext.c, returns "" for default locale */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* value should be freed by calling function g_free() */
|
/**
|
||||||
|
* partly taken from dcigettext.c, returns "" for default locale
|
||||||
|
* value should be freed by calling function g_free()
|
||||||
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
guess_message_value (void)
|
guess_message_value (void)
|
||||||
{
|
{
|
||||||
@ -1722,3 +1861,5 @@ guess_message_value (void)
|
|||||||
|
|
||||||
return g_strdup (locale);
|
return g_strdup (locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
217
lib/util.h
217
lib/util.h
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/** \file util.h
|
/** \file util.h
|
||||||
* \brief Header: various utilities
|
* \brief Header: various utilities
|
||||||
*/
|
*/
|
||||||
@ -14,9 +13,119 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define MAX_I18NTIMELENGTH 20
|
||||||
|
#define MIN_I18NTIMELENGTH 10
|
||||||
|
#define STD_I18NTIMELENGTH 12
|
||||||
|
|
||||||
|
#ifndef PATH_MAX
|
||||||
|
#ifdef _POSIX_VERSION
|
||||||
|
#define PATH_MAX _POSIX_PATH_MAX
|
||||||
|
#else
|
||||||
|
#ifdef MAXPATHLEN
|
||||||
|
#define PATH_MAX MAXPATHLEN
|
||||||
|
#else
|
||||||
|
#define PATH_MAX 1024
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef MAXSYMLINKS
|
||||||
|
#define MAXSYMLINKS 32
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAX_SAVED_BOOKMARKS 10
|
||||||
|
|
||||||
|
/* OS specific defines */
|
||||||
|
#define PATH_SEP '/'
|
||||||
|
#define PATH_SEP_STR "/"
|
||||||
|
#define PATH_ENV_SEP ':'
|
||||||
|
#define TMPDIR_DEFAULT "/tmp"
|
||||||
|
#define SCRIPT_SUFFIX ""
|
||||||
|
#define get_default_editor() "vi"
|
||||||
|
#define OS_SORT_CASE_SENSITIVE_DEFAULT 1
|
||||||
|
#define STRCOMP strcmp
|
||||||
|
#define STRNCOMP strncmp
|
||||||
|
#define MC_ARCH_FLAGS 0
|
||||||
|
|
||||||
|
/* taken from regex.c: */
|
||||||
|
/* Jim Meyering writes:
|
||||||
|
|
||||||
|
"... Some ctype macros are valid only for character codes that
|
||||||
|
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
|
||||||
|
using /bin/cc or gcc but without giving an ansi option). So, all
|
||||||
|
ctype uses should be through macros like ISPRINT... If
|
||||||
|
STDC_HEADERS is defined, then autoconf has verified that the ctype
|
||||||
|
macros don't need to be guarded with references to isascii. ...
|
||||||
|
Defining isascii to 1 should let any compiler worth its salt
|
||||||
|
eliminate the && through constant folding." */
|
||||||
|
|
||||||
|
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
||||||
|
#define ISASCII(c) 1
|
||||||
|
#else
|
||||||
|
#define ISASCII(c) isascii(c)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* usage: str_cmp ("foo", !=, "bar") */
|
||||||
|
#define str_cmp(a,rel,b) (strcmp ((a), (b)) rel 0)
|
||||||
|
|
||||||
|
#define str_dup_range(s_start, s_bound) (g_strndup(s_start, s_bound - s_start))
|
||||||
|
|
||||||
|
#define MC_PTR_FREE(ptr) do { g_free (ptr); (ptr) = NULL; } while (0)
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/* Matching */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
match_file, /* match a filename, use easy_patterns */
|
||||||
|
match_normal, /* match pattern, use easy_patterns */
|
||||||
|
match_regex /* match pattern, force using regex */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Pathname canonicalization */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
CANON_PATH_JOINSLASHES = 1L << 0, /* Multiple `/'s are collapsed to a single `/'. */
|
||||||
|
CANON_PATH_REMSLASHDOTS = 1L << 1, /* Leading `./'s, `/'s and trailing `/.'s are removed. */
|
||||||
|
CANON_PATH_REMDOUBLEDOTS = 1L << 3, /* Non-leading `../'s and trailing `..'s are handled by removing */
|
||||||
|
CANON_PATH_GUARDUNC = 1L << 4, /* Detect and preserve UNC paths: //server/... */
|
||||||
|
CANON_PATH_ALL = CANON_PATH_JOINSLASHES
|
||||||
|
| CANON_PATH_REMSLASHDOTS | CANON_PATH_REMDOUBLEDOTS | CANON_PATH_GUARDUNC
|
||||||
|
} CANON_PATH_FLAGS;
|
||||||
|
|
||||||
|
enum compression_type
|
||||||
|
{
|
||||||
|
COMPRESSION_NONE,
|
||||||
|
COMPRESSION_GZIP,
|
||||||
|
COMPRESSION_BZIP,
|
||||||
|
COMPRESSION_BZIP2,
|
||||||
|
COMPRESSION_LZMA,
|
||||||
|
COMPRESSION_XZ
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
typedef struct hook
|
||||||
|
{
|
||||||
|
void (*hook_fn) (void *);
|
||||||
|
void *hook_data;
|
||||||
|
struct hook *next;
|
||||||
|
} Hook;
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern char *user_recent_timeformat; /* time format string for recent dates */
|
extern char *user_recent_timeformat; /* time format string for recent dates */
|
||||||
extern char *user_old_timeformat; /* time format string for older dates */
|
extern char *user_old_timeformat; /* time format string for older dates */
|
||||||
|
|
||||||
|
extern int easy_patterns;
|
||||||
|
|
||||||
|
extern struct sigaction startup_handler;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
/* Returns its argument as a "modifiable" string. This function is
|
/* Returns its argument as a "modifiable" string. This function is
|
||||||
* intended to pass strings to legacy libraries that don't know yet
|
* intended to pass strings to legacy libraries that don't know yet
|
||||||
* about the "const" modifier. The return value of this function
|
* about the "const" modifier. The return value of this function
|
||||||
@ -111,9 +220,6 @@ void init_uid_gid_cache (void);
|
|||||||
char *get_group (int);
|
char *get_group (int);
|
||||||
char *get_owner (int);
|
char *get_owner (int);
|
||||||
|
|
||||||
#define MAX_I18NTIMELENGTH 20
|
|
||||||
#define MIN_I18NTIMELENGTH 10
|
|
||||||
#define STD_I18NTIMELENGTH 12
|
|
||||||
|
|
||||||
size_t i18n_checktimelength (void);
|
size_t i18n_checktimelength (void);
|
||||||
const char *file_date (time_t);
|
const char *file_date (time_t);
|
||||||
@ -126,16 +232,6 @@ int check_for_default (const char *default_file, const char *file);
|
|||||||
/* Returns a copy of *s until a \n is found and is below top */
|
/* Returns a copy of *s until a \n is found and is below top */
|
||||||
const char *extract_line (const char *s, const char *top);
|
const char *extract_line (const char *s, const char *top);
|
||||||
|
|
||||||
/* Matching */
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
match_file, /* match a filename, use easy_patterns */
|
|
||||||
match_normal, /* match pattern, use easy_patterns */
|
|
||||||
match_regex /* match pattern, force using regex */
|
|
||||||
};
|
|
||||||
|
|
||||||
extern int easy_patterns;
|
|
||||||
|
|
||||||
/* Error pipes */
|
/* Error pipes */
|
||||||
void open_error_pipe (void);
|
void open_error_pipe (void);
|
||||||
void check_error_pipe (void);
|
void check_error_pipe (void);
|
||||||
@ -144,21 +240,10 @@ int close_error_pipe (int error, const char *text);
|
|||||||
/* Process spawning */
|
/* Process spawning */
|
||||||
int my_system (int flags, const char *shell, const char *command);
|
int my_system (int flags, const char *shell, const char *command);
|
||||||
void save_stop_handler (void);
|
void save_stop_handler (void);
|
||||||
extern struct sigaction startup_handler;
|
|
||||||
|
|
||||||
/* Tilde expansion */
|
/* Tilde expansion */
|
||||||
char *tilde_expand (const char *);
|
char *tilde_expand (const char *);
|
||||||
|
|
||||||
/* Pathname canonicalization */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
CANON_PATH_JOINSLASHES = 1L << 0, /* Multiple `/'s are collapsed to a single `/'. */
|
|
||||||
CANON_PATH_REMSLASHDOTS = 1L << 1, /* Leading `./'s, `/'s and trailing `/.'s are removed. */
|
|
||||||
CANON_PATH_REMDOUBLEDOTS = 1L << 3, /* Non-leading `../'s and trailing `..'s are handled by removing */
|
|
||||||
CANON_PATH_GUARDUNC = 1L << 4, /* Detect and preserve UNC paths: //server/... */
|
|
||||||
CANON_PATH_ALL = CANON_PATH_JOINSLASHES
|
|
||||||
| CANON_PATH_REMSLASHDOTS | CANON_PATH_REMDOUBLEDOTS | CANON_PATH_GUARDUNC
|
|
||||||
} CANON_PATH_FLAGS;
|
|
||||||
void custom_canonicalize_pathname (char *, CANON_PATH_FLAGS);
|
void custom_canonicalize_pathname (char *, CANON_PATH_FLAGS);
|
||||||
void canonicalize_pathname (char *);
|
void canonicalize_pathname (char *);
|
||||||
|
|
||||||
@ -170,38 +255,12 @@ int my_rmdir (const char *s);
|
|||||||
const char *mc_tmpdir (void);
|
const char *mc_tmpdir (void);
|
||||||
int mc_mkstemps (char **pname, const char *prefix, const char *suffix);
|
int mc_mkstemps (char **pname, const char *prefix, const char *suffix);
|
||||||
|
|
||||||
#ifndef PATH_MAX
|
|
||||||
#ifdef _POSIX_VERSION
|
|
||||||
#define PATH_MAX _POSIX_PATH_MAX
|
|
||||||
#else
|
|
||||||
#ifdef MAXPATHLEN
|
|
||||||
#define PATH_MAX MAXPATHLEN
|
|
||||||
#else
|
|
||||||
#define PATH_MAX 1024
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MAXSYMLINKS
|
|
||||||
#define MAXSYMLINKS 32
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_REALPATH
|
#ifdef HAVE_REALPATH
|
||||||
#define mc_realpath realpath
|
#define mc_realpath realpath
|
||||||
#else
|
#else
|
||||||
char *mc_realpath (const char *path, char *resolved_path);
|
char *mc_realpath (const char *path, char *resolved_path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum compression_type
|
|
||||||
{
|
|
||||||
COMPRESSION_NONE,
|
|
||||||
COMPRESSION_GZIP,
|
|
||||||
COMPRESSION_BZIP,
|
|
||||||
COMPRESSION_BZIP2,
|
|
||||||
COMPRESSION_LZMA,
|
|
||||||
COMPRESSION_XZ
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Looks for ``magic'' bytes at the start of the VFS file to guess the
|
/* Looks for ``magic'' bytes at the start of the VFS file to guess the
|
||||||
* compression type. Side effect: modifies the file position. */
|
* compression type. Side effect: modifies the file position. */
|
||||||
enum compression_type get_compression_type (int fd, const char *);
|
enum compression_type get_compression_type (int fd, const char *);
|
||||||
@ -209,12 +268,6 @@ const char *decompress_extension (int type);
|
|||||||
|
|
||||||
/* Hook functions */
|
/* Hook functions */
|
||||||
|
|
||||||
typedef struct hook
|
|
||||||
{
|
|
||||||
void (*hook_fn) (void *);
|
|
||||||
void *hook_data;
|
|
||||||
struct hook *next;
|
|
||||||
} Hook;
|
|
||||||
|
|
||||||
void add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data);
|
void add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data);
|
||||||
void execute_hooks (Hook * hook_list);
|
void execute_hooks (Hook * hook_list);
|
||||||
@ -224,7 +277,6 @@ int hook_present (Hook * hook_list, void (*hook_fn) (void *));
|
|||||||
GList *list_append_unique (GList * list, char *text);
|
GList *list_append_unique (GList * list, char *text);
|
||||||
|
|
||||||
/* Position saving and restoring */
|
/* Position saving and restoring */
|
||||||
#define MAX_SAVED_BOOKMARKS 10
|
|
||||||
/* Load position for the given filename */
|
/* Load position for the given filename */
|
||||||
void load_file_position (const char *filename, long *line, long *column, off_t * offset,
|
void load_file_position (const char *filename, long *line, long *column, off_t * offset,
|
||||||
GArray **bookmarks);
|
GArray **bookmarks);
|
||||||
@ -233,39 +285,6 @@ void save_file_position (const char *filename, long line, long column, off_t off
|
|||||||
GArray *bookmarks);
|
GArray *bookmarks);
|
||||||
|
|
||||||
|
|
||||||
/* OS specific defines */
|
|
||||||
#define PATH_SEP '/'
|
|
||||||
#define PATH_SEP_STR "/"
|
|
||||||
#define PATH_ENV_SEP ':'
|
|
||||||
#define TMPDIR_DEFAULT "/tmp"
|
|
||||||
#define SCRIPT_SUFFIX ""
|
|
||||||
#define get_default_editor() "vi"
|
|
||||||
#define OS_SORT_CASE_SENSITIVE_DEFAULT 1
|
|
||||||
#define STRCOMP strcmp
|
|
||||||
#define STRNCOMP strncmp
|
|
||||||
#define MC_ARCH_FLAGS 0
|
|
||||||
|
|
||||||
/* taken from regex.c: */
|
|
||||||
/* Jim Meyering writes:
|
|
||||||
|
|
||||||
"... Some ctype macros are valid only for character codes that
|
|
||||||
isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when
|
|
||||||
using /bin/cc or gcc but without giving an ansi option). So, all
|
|
||||||
ctype uses should be through macros like ISPRINT... If
|
|
||||||
STDC_HEADERS is defined, then autoconf has verified that the ctype
|
|
||||||
macros don't need to be guarded with references to isascii. ...
|
|
||||||
Defining isascii to 1 should let any compiler worth its salt
|
|
||||||
eliminate the && through constant folding." */
|
|
||||||
|
|
||||||
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
|
|
||||||
#define ISASCII(c) 1
|
|
||||||
#else
|
|
||||||
#define ISASCII(c) isascii(c)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* usage: str_cmp ("foo", !=, "bar") */
|
|
||||||
#define str_cmp(a,rel,b) (strcmp ((a), (b)) rel 0)
|
|
||||||
|
|
||||||
/* if ch is in [A-Za-z], returns the corresponding control character,
|
/* if ch is in [A-Za-z], returns the corresponding control character,
|
||||||
* else returns the argument. */
|
* else returns the argument. */
|
||||||
extern int ascii_alpha_to_cntrl (int ch);
|
extern int ascii_alpha_to_cntrl (int ch);
|
||||||
@ -273,7 +292,14 @@ extern int ascii_alpha_to_cntrl (int ch);
|
|||||||
#undef Q_
|
#undef Q_
|
||||||
const char *Q_ (const char *s);
|
const char *Q_ (const char *s);
|
||||||
|
|
||||||
#define str_dup_range(s_start, s_bound) (g_strndup(s_start, s_bound - s_start))
|
gboolean mc_util_make_backup_if_possible (const char *, const char *);
|
||||||
|
gboolean mc_util_restore_from_backup_if_possible (const char *, const char *);
|
||||||
|
gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
|
||||||
|
|
||||||
|
char *guess_message_value (void);
|
||||||
|
|
||||||
|
|
||||||
|
/*** inline functions **************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
|
* strcpy is unsafe on overlapping memory areas, so define memmove-alike
|
||||||
@ -298,12 +324,5 @@ str_move (char *dest, const char *src)
|
|||||||
return (char *) memmove (dest, src, n);
|
return (char *) memmove (dest, src, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean mc_util_make_backup_if_possible (const char *, const char *);
|
|
||||||
gboolean mc_util_restore_from_backup_if_possible (const char *, const char *);
|
|
||||||
gboolean mc_util_unlink_backup_if_possible (const char *, const char *);
|
|
||||||
|
|
||||||
char *guess_message_value (void);
|
|
||||||
|
|
||||||
#define MC_PTR_FREE(ptr) do { g_free (ptr); (ptr) = NULL; } while (0)
|
|
||||||
|
|
||||||
#endif /* MC_UTIL_H */
|
#endif /* MC_UTIL_H */
|
||||||
|
@ -42,7 +42,10 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
#ifdef HAVE_SYS_IOCTL_H
|
||||||
# include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_GET_PROCESS_STATS
|
||||||
|
#include <sys/procstats.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@ -57,20 +60,38 @@
|
|||||||
#include "src/charsets.h"
|
#include "src/charsets.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
struct sigaction startup_handler;
|
struct sigaction startup_handler;
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define UID_CACHE_SIZE 200
|
#define UID_CACHE_SIZE 200
|
||||||
#define GID_CACHE_SIZE 30
|
#define GID_CACHE_SIZE 30
|
||||||
|
|
||||||
|
/* Pipes are guaranteed to be able to hold at least 4096 bytes */
|
||||||
|
/* More than that would be unportable */
|
||||||
|
#define MAX_PIPE_SIZE 4096
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
char *string;
|
char *string;
|
||||||
} int_cache;
|
} int_cache;
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static int_cache uid_cache[UID_CACHE_SIZE];
|
static int_cache uid_cache[UID_CACHE_SIZE];
|
||||||
static int_cache gid_cache[GID_CACHE_SIZE];
|
static int_cache gid_cache[GID_CACHE_SIZE];
|
||||||
|
|
||||||
|
static int error_pipe[2]; /* File descriptors of error pipe */
|
||||||
|
static int old_error; /* File descriptor of old standard error */
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
i_cache_match (int id, int_cache * cache, int size)
|
i_cache_match (int id, int_cache * cache, int size)
|
||||||
{
|
{
|
||||||
@ -82,6 +103,8 @@ i_cache_match (int id, int_cache * cache, int size)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
i_cache_add (int id, int_cache * cache, int size, char *text, int *last)
|
i_cache_add (int id, int_cache * cache, int size, char *text, int *last)
|
||||||
{
|
{
|
||||||
@ -91,6 +114,10 @@ i_cache_add (int id, int_cache * cache, int size, char *text, int *last)
|
|||||||
*last = ((*last) + 1) % size;
|
*last = ((*last) + 1) % size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_owner (int uid)
|
get_owner (int uid)
|
||||||
{
|
{
|
||||||
@ -116,6 +143,8 @@ get_owner (int uid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
char *
|
char *
|
||||||
get_group (int gid)
|
get_group (int gid)
|
||||||
{
|
{
|
||||||
@ -141,15 +170,19 @@ get_group (int gid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Since ncurses uses a handler that automatically refreshes the */
|
/* Since ncurses uses a handler that automatically refreshes the */
|
||||||
/* screen after a SIGCONT, and we don't want this behavior when */
|
/* screen after a SIGCONT, and we don't want this behavior when */
|
||||||
/* spawning a child, we save the original handler here */
|
/* spawning a child, we save the original handler here */
|
||||||
|
|
||||||
void
|
void
|
||||||
save_stop_handler (void)
|
save_stop_handler (void)
|
||||||
{
|
{
|
||||||
sigaction (SIGTSTP, NULL, &startup_handler);
|
sigaction (SIGTSTP, NULL, &startup_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
my_system (int flags, const char *shell, const char *command)
|
my_system (int flags, const char *shell, const char *command)
|
||||||
{
|
{
|
||||||
@ -213,7 +246,7 @@ my_system (int flags, const char *shell, const char *command)
|
|||||||
{
|
{
|
||||||
if (waitpid (pid, &status, 0) > 0)
|
if (waitpid (pid, &status, 0) > 0)
|
||||||
{
|
{
|
||||||
status = WEXITSTATUS(status);
|
status = WEXITSTATUS (status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
@ -231,10 +264,12 @@ my_system (int flags, const char *shell, const char *command)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Perform tilde expansion if possible.
|
* Perform tilde expansion if possible.
|
||||||
* Always return a newly allocated string, even if it's unchanged.
|
* Always return a newly allocated string, even if it's unchanged.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *
|
char *
|
||||||
tilde_expand (const char *directory)
|
tilde_expand (const char *directory)
|
||||||
{
|
{
|
||||||
@ -276,13 +311,15 @@ tilde_expand (const char *directory)
|
|||||||
return g_strconcat (passwd->pw_dir, PATH_SEP_STR, q, (char *) NULL);
|
return g_strconcat (passwd->pw_dir, PATH_SEP_STR, q, (char *) NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Return the directory where mc should keep its temporary files.
|
* Return the directory where mc should keep its temporary files.
|
||||||
* This directory is (in Bourne shell terms) "${TMPDIR=/tmp}/mc-$USER"
|
* This directory is (in Bourne shell terms) "${TMPDIR=/tmp}/mc-$USER"
|
||||||
* When called the first time, the directory is created if needed.
|
* When called the first time, the directory is created if needed.
|
||||||
* The first call should be done early, since we are using fprintf()
|
* The first call should be done early, since we are using fprintf()
|
||||||
* and not message() to report possible problems.
|
* and not message() to report possible problems.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
mc_tmpdir (void)
|
mc_tmpdir (void)
|
||||||
{
|
{
|
||||||
@ -384,17 +421,13 @@ mc_tmpdir (void)
|
|||||||
return tmpdir;
|
return tmpdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Creates a pipe to hold standard error for a later analysis.
|
||||||
|
* The pipe can hold 4096 bytes. Make sure no more is written
|
||||||
|
* or a deadlock might occur.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Pipes are guaranteed to be able to hold at least 4096 bytes */
|
|
||||||
/* More than that would be unportable */
|
|
||||||
#define MAX_PIPE_SIZE 4096
|
|
||||||
|
|
||||||
static int error_pipe[2]; /* File descriptors of error pipe */
|
|
||||||
static int old_error; /* File descriptor of old standard error */
|
|
||||||
|
|
||||||
/* Creates a pipe to hold standard error for a later analysis. */
|
|
||||||
/* The pipe can hold 4096 bytes. Make sure no more is written */
|
|
||||||
/* or a deadlock might occur. */
|
|
||||||
void
|
void
|
||||||
open_error_pipe (void)
|
open_error_pipe (void)
|
||||||
{
|
{
|
||||||
@ -436,11 +469,13 @@ open_error_pipe (void)
|
|||||||
error_pipe[1] = -1;
|
error_pipe[1] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Returns true if an error was displayed
|
* Returns true if an error was displayed
|
||||||
* error: -1 - ignore errors, 0 - display warning, 1 - display error
|
* error: -1 - ignore errors, 0 - display warning, 1 - display error
|
||||||
* text is prepended to the error message from the pipe
|
* text is prepended to the error message from the pipe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
close_error_pipe (int error, const char *text)
|
close_error_pipe (int error, const char *text)
|
||||||
{
|
{
|
||||||
@ -489,7 +524,8 @@ close_error_pipe (int error, const char *text)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Canonicalize path, and return a new path. Do everything in place.
|
* Canonicalize path, and return a new path. Do everything in place.
|
||||||
* The new path differs from path in:
|
* The new path differs from path in:
|
||||||
* Multiple `/'s are collapsed to a single `/'.
|
* Multiple `/'s are collapsed to a single `/'.
|
||||||
@ -499,6 +535,7 @@ close_error_pipe (int error, const char *text)
|
|||||||
* portions of the path.
|
* portions of the path.
|
||||||
* Well formed UNC paths are modified only in the local part.
|
* Well formed UNC paths are modified only in the local part.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
||||||
{
|
{
|
||||||
@ -662,7 +699,7 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
|||||||
s[0] = 0;
|
s[0] = 0;
|
||||||
#if HAVE_CHARSET
|
#if HAVE_CHARSET
|
||||||
else if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
|
else if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
|
||||||
&& (is_supported_encoding (s + enc_prefix_len)))
|
&& (is_supported_encoding (s + enc_prefix_len)))
|
||||||
{
|
{
|
||||||
/* special case: remove encoding */
|
/* special case: remove encoding */
|
||||||
s[0] = '.';
|
s[0] = '.';
|
||||||
@ -689,15 +726,17 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
canonicalize_pathname (char *path)
|
canonicalize_pathname (char *path)
|
||||||
{
|
{
|
||||||
custom_canonicalize_pathname (path, CANON_PATH_ALL);
|
custom_canonicalize_pathname (path, CANON_PATH_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GET_PROCESS_STATS
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
# include <sys/procstats.h>
|
|
||||||
|
|
||||||
|
#ifdef HAVE_GET_PROCESS_STATS
|
||||||
int
|
int
|
||||||
gettimeofday (struct timeval *tp, void *tzp)
|
gettimeofday (struct timeval *tp, void *tzp)
|
||||||
{
|
{
|
||||||
@ -705,6 +744,8 @@ gettimeofday (struct timeval *tp, void *tzp)
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_GET_PROCESS_STATS */
|
#endif /* HAVE_GET_PROCESS_STATS */
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifndef HAVE_REALPATH
|
#ifndef HAVE_REALPATH
|
||||||
char *
|
char *
|
||||||
mc_realpath (const char *path, char *resolved_path)
|
mc_realpath (const char *path, char *resolved_path)
|
||||||
@ -847,7 +888,12 @@ mc_realpath (const char *path, char *resolved_path)
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_REALPATH */
|
#endif /* HAVE_REALPATH */
|
||||||
|
|
||||||
/* Return the index of the permissions triplet */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* Return the index of the permissions triplet
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
get_user_permissions (struct stat *st)
|
get_user_permissions (struct stat *st)
|
||||||
{
|
{
|
||||||
@ -894,3 +940,5 @@ get_user_permissions (struct stat *st)
|
|||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -57,9 +57,19 @@
|
|||||||
#include "utilvfs.h"
|
#include "utilvfs.h"
|
||||||
#include "gc.h" /* vfs_rmstamp */
|
#include "gc.h" /* vfs_rmstamp */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
GArray *extfs_plugins = NULL;
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#undef ERRNOR
|
#undef ERRNOR
|
||||||
#define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
|
#define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
|
||||||
|
|
||||||
|
#define RECORDSIZE 512
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
struct inode
|
struct inode
|
||||||
{
|
{
|
||||||
nlink_t nlink;
|
nlink_t nlink;
|
||||||
@ -116,19 +126,24 @@ typedef struct
|
|||||||
gboolean need_archive;
|
gboolean need_archive;
|
||||||
} extfs_plugin_info_t;
|
} extfs_plugin_info_t;
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static gboolean errloop;
|
static gboolean errloop;
|
||||||
static gboolean notadir;
|
static gboolean notadir;
|
||||||
|
|
||||||
|
static struct vfs_class vfs_extfs_ops;
|
||||||
|
static struct archive *first_archive = NULL;
|
||||||
|
static int my_errno = 0;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void extfs_remove_entry (struct entry *e);
|
static void extfs_remove_entry (struct entry *e);
|
||||||
static void extfs_free (vfsid id);
|
static void extfs_free (vfsid id);
|
||||||
static void extfs_free_entry (struct entry *e);
|
static void extfs_free_entry (struct entry *e);
|
||||||
static struct entry *extfs_resolve_symlinks_int (struct entry *entry, GSList * list);
|
static struct entry *extfs_resolve_symlinks_int (struct entry *entry, GSList * list);
|
||||||
|
|
||||||
static struct vfs_class vfs_extfs_ops;
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
static struct archive *first_archive = NULL;
|
|
||||||
static int my_errno = 0;
|
|
||||||
|
|
||||||
GArray *extfs_plugins = NULL;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_make_dots (struct entry *ent)
|
extfs_make_dots (struct entry *ent)
|
||||||
@ -164,6 +179,8 @@ extfs_make_dots (struct entry *ent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct entry *
|
static struct entry *
|
||||||
extfs_generate_entry (struct archive *archive,
|
extfs_generate_entry (struct archive *archive,
|
||||||
const char *name, struct entry *parentry, mode_t mode)
|
const char *name, struct entry *parentry, mode_t mode)
|
||||||
@ -208,6 +225,8 @@ extfs_generate_entry (struct archive *archive,
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct entry *
|
static struct entry *
|
||||||
extfs_find_entry_int (struct entry *dir, char *name, GSList * list,
|
extfs_find_entry_int (struct entry *dir, char *name, GSList * list,
|
||||||
gboolean make_dirs, gboolean make_file)
|
gboolean make_dirs, gboolean make_file)
|
||||||
@ -291,6 +310,8 @@ extfs_find_entry_int (struct entry *dir, char *name, GSList * list,
|
|||||||
return pent;
|
return pent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct entry *
|
static struct entry *
|
||||||
extfs_find_entry (struct entry *dir, char *name, gboolean make_dirs, gboolean make_file)
|
extfs_find_entry (struct entry *dir, char *name, gboolean make_dirs, gboolean make_file)
|
||||||
{
|
{
|
||||||
@ -310,6 +331,8 @@ extfs_find_entry (struct entry *dir, char *name, gboolean make_dirs, gboolean ma
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_fill_names (struct vfs_class *me, fill_names_f func)
|
extfs_fill_names (struct vfs_class *me, fill_names_f func)
|
||||||
{
|
{
|
||||||
@ -330,6 +353,8 @@ extfs_fill_names (struct vfs_class *me, fill_names_f func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_free_archive (struct archive *archive)
|
extfs_free_archive (struct archive *archive)
|
||||||
{
|
{
|
||||||
@ -347,6 +372,8 @@ extfs_free_archive (struct archive *archive)
|
|||||||
g_free (archive);
|
g_free (archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static FILE *
|
static FILE *
|
||||||
extfs_open_archive (int fstype, const char *name, struct archive **pparc)
|
extfs_open_archive (int fstype, const char *name, struct archive **pparc)
|
||||||
{
|
{
|
||||||
@ -432,10 +459,12 @@ extfs_open_archive (int fstype, const char *name, struct archive **pparc)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Main loop for reading an archive.
|
* Main loop for reading an archive.
|
||||||
* Return 0 on success, -1 on error.
|
* Return 0 on success, -1 on error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_read_archive (int fstype, const char *name, struct archive **pparc)
|
extfs_read_archive (int fstype, const char *name, struct archive **pparc)
|
||||||
{
|
{
|
||||||
@ -579,6 +608,8 @@ extfs_read_archive (int fstype, const char *name, struct archive **pparc)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_which (struct vfs_class *me, const char *path)
|
extfs_which (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -602,10 +633,12 @@ extfs_which (struct vfs_class *me, const char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Dissect the path and create corresponding superblock. Note that inname
|
* Dissect the path and create corresponding superblock. Note that inname
|
||||||
* can be changed and the result may point inside the original string.
|
* can be changed and the result may point inside the original string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive,
|
extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive,
|
||||||
gboolean do_not_open)
|
gboolean do_not_open)
|
||||||
@ -649,10 +682,12 @@ extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **arch
|
|||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Dissect the path and create corresponding superblock.
|
* Dissect the path and create corresponding superblock.
|
||||||
* The result should be freed.
|
* The result should be freed.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
extfs_get_path (struct vfs_class *me, const char *inname,
|
extfs_get_path (struct vfs_class *me, const char *inname,
|
||||||
struct archive **archive, gboolean do_not_open)
|
struct archive **archive, gboolean do_not_open)
|
||||||
@ -666,7 +701,9 @@ extfs_get_path (struct vfs_class *me, const char *inname,
|
|||||||
return res2;
|
return res2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Return allocated path (without leading slash) inside the archive */
|
/* Return allocated path (without leading slash) inside the archive */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
extfs_get_path_from_entry (struct entry *entry)
|
extfs_get_path_from_entry (struct entry *entry)
|
||||||
{
|
{
|
||||||
@ -685,6 +722,8 @@ extfs_get_path_from_entry (struct entry *entry)
|
|||||||
return g_string_free (localpath, FALSE);
|
return g_string_free (localpath, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct entry *
|
static struct entry *
|
||||||
extfs_resolve_symlinks_int (struct entry *entry, GSList * list)
|
extfs_resolve_symlinks_int (struct entry *entry, GSList * list)
|
||||||
{
|
{
|
||||||
@ -713,6 +752,8 @@ extfs_resolve_symlinks_int (struct entry *entry, GSList * list)
|
|||||||
return pent;
|
return pent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static struct entry *
|
static struct entry *
|
||||||
extfs_resolve_symlinks (struct entry *entry)
|
extfs_resolve_symlinks (struct entry *entry)
|
||||||
{
|
{
|
||||||
@ -731,6 +772,8 @@ extfs_resolve_symlinks (struct entry *entry)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
extfs_get_archive_name (struct archive *archive)
|
extfs_get_archive_name (struct archive *archive)
|
||||||
{
|
{
|
||||||
@ -747,7 +790,9 @@ extfs_get_archive_name (struct archive *archive)
|
|||||||
return archive_name;
|
return archive_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't pass localname as NULL */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/** Don't pass localname as NULL */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_cmd (const char *str_extfs_cmd, struct archive *archive,
|
extfs_cmd (const char *str_extfs_cmd, struct archive *archive,
|
||||||
struct entry *entry, const char *localname)
|
struct entry *entry, const char *localname)
|
||||||
@ -780,6 +825,8 @@ extfs_cmd (const char *str_extfs_cmd, struct archive *archive,
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_run (struct vfs_class *me, const char *file)
|
extfs_run (struct vfs_class *me, const char *file)
|
||||||
{
|
{
|
||||||
@ -803,6 +850,8 @@ extfs_run (struct vfs_class *me, const char *file)
|
|||||||
g_free (cmd);
|
g_free (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
extfs_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
extfs_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -879,6 +928,8 @@ extfs_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
|||||||
return extfs_info;
|
return extfs_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
extfs_read (void *data, char *buffer, size_t count)
|
extfs_read (void *data, char *buffer, size_t count)
|
||||||
{
|
{
|
||||||
@ -887,6 +938,8 @@ extfs_read (void *data, char *buffer, size_t count)
|
|||||||
return read (file->local_handle, buffer, count);
|
return read (file->local_handle, buffer, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_close (void *data)
|
extfs_close (void *data)
|
||||||
{
|
{
|
||||||
@ -921,6 +974,8 @@ extfs_close (void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_errno (struct vfs_class *me)
|
extfs_errno (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
@ -928,6 +983,8 @@ extfs_errno (struct vfs_class *me)
|
|||||||
return my_errno;
|
return my_errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
extfs_opendir (struct vfs_class *me, const char *dirname)
|
extfs_opendir (struct vfs_class *me, const char *dirname)
|
||||||
{
|
{
|
||||||
@ -956,6 +1013,8 @@ extfs_opendir (struct vfs_class *me, const char *dirname)
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
extfs_readdir (void *data)
|
extfs_readdir (void *data)
|
||||||
{
|
{
|
||||||
@ -973,6 +1032,8 @@ extfs_readdir (void *data)
|
|||||||
return (void *) &dir;
|
return (void *) &dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_closedir (void *data)
|
extfs_closedir (void *data)
|
||||||
{
|
{
|
||||||
@ -980,7 +1041,7 @@ extfs_closedir (void *data)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RECORDSIZE 512
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_stat_move (struct stat *buf, const struct inode *inode)
|
extfs_stat_move (struct stat *buf, const struct inode *inode)
|
||||||
@ -1006,6 +1067,8 @@ extfs_stat_move (struct stat *buf, const struct inode *inode)
|
|||||||
buf->st_ctime = inode->ctime;
|
buf->st_ctime = inode->ctime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, gboolean resolve)
|
extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, gboolean resolve)
|
||||||
{
|
{
|
||||||
@ -1035,18 +1098,24 @@ extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, g
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
extfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
return extfs_internal_stat (me, path, buf, TRUE);
|
return extfs_internal_stat (me, path, buf, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
extfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
return extfs_internal_stat (me, path, buf, FALSE);
|
return extfs_internal_stat (me, path, buf, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_fstat (void *data, struct stat *buf)
|
extfs_fstat (void *data, struct stat *buf)
|
||||||
{
|
{
|
||||||
@ -1056,6 +1125,8 @@ extfs_fstat (void *data, struct stat *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
@ -1089,6 +1160,8 @@ extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
extfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
@ -1099,6 +1172,8 @@ extfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_chmod (struct vfs_class *me, const char *path, int mode)
|
extfs_chmod (struct vfs_class *me, const char *path, int mode)
|
||||||
{
|
{
|
||||||
@ -1108,6 +1183,8 @@ extfs_chmod (struct vfs_class *me, const char *path, int mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
extfs_write (void *data, const char *buf, size_t nbyte)
|
extfs_write (void *data, const char *buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
@ -1117,6 +1194,8 @@ extfs_write (void *data, const char *buf, size_t nbyte)
|
|||||||
return write (file->local_handle, buf, nbyte);
|
return write (file->local_handle, buf, nbyte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_unlink (struct vfs_class *me, const char *file)
|
extfs_unlink (struct vfs_class *me, const char *file)
|
||||||
{
|
{
|
||||||
@ -1153,6 +1232,8 @@ extfs_unlink (struct vfs_class *me, const char *file)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -1198,6 +1279,8 @@ extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_rmdir (struct vfs_class *me, const char *path)
|
extfs_rmdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -1235,6 +1318,8 @@ extfs_rmdir (struct vfs_class *me, const char *path)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_chdir (struct vfs_class *me, const char *path)
|
extfs_chdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -1257,6 +1342,8 @@ extfs_chdir (struct vfs_class *me, const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static off_t
|
static off_t
|
||||||
extfs_lseek (void *data, off_t offset, int whence)
|
extfs_lseek (void *data, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
@ -1265,6 +1352,8 @@ extfs_lseek (void *data, off_t offset, int whence)
|
|||||||
return lseek (file->local_handle, offset, whence);
|
return lseek (file->local_handle, offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static vfsid
|
static vfsid
|
||||||
extfs_getid (struct vfs_class *me, const char *path)
|
extfs_getid (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -1278,12 +1367,16 @@ extfs_getid (struct vfs_class *me, const char *path)
|
|||||||
return (vfsid) archive;
|
return (vfsid) archive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_nothingisopen (vfsid id)
|
extfs_nothingisopen (vfsid id)
|
||||||
{
|
{
|
||||||
return (((struct archive *) id)->fd_usage <= 0);
|
return (((struct archive *) id)->fd_usage <= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_remove_entry (struct entry *e)
|
extfs_remove_entry (struct entry *e)
|
||||||
{
|
{
|
||||||
@ -1327,6 +1420,8 @@ extfs_remove_entry (struct entry *e)
|
|||||||
g_free (e);
|
g_free (e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_free_entry (struct entry *e)
|
extfs_free_entry (struct entry *e)
|
||||||
{
|
{
|
||||||
@ -1355,6 +1450,8 @@ extfs_free_entry (struct entry *e)
|
|||||||
g_free (e);
|
g_free (e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_free (vfsid id)
|
extfs_free (vfsid id)
|
||||||
{
|
{
|
||||||
@ -1377,6 +1474,8 @@ extfs_free (vfsid id)
|
|||||||
extfs_free_archive (archive);
|
extfs_free_archive (archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -1397,6 +1496,8 @@ extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
extfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
||||||
{
|
{
|
||||||
@ -1422,6 +1523,8 @@ extfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
extfs_get_plugins (const char *where, gboolean silent)
|
extfs_get_plugins (const char *where, gboolean silent)
|
||||||
{
|
{
|
||||||
@ -1520,6 +1623,7 @@ extfs_get_plugins (const char *where, gboolean silent)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_init (struct vfs_class *me)
|
extfs_init (struct vfs_class *me)
|
||||||
@ -1539,6 +1643,8 @@ extfs_init (struct vfs_class *me)
|
|||||||
return (d1 || d2 ? 1 : 0);
|
return (d1 || d2 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
extfs_done (struct vfs_class *me)
|
extfs_done (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
@ -1564,6 +1670,8 @@ extfs_done (struct vfs_class *me)
|
|||||||
g_array_free (extfs_plugins, TRUE);
|
g_array_free (extfs_plugins, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
||||||
{
|
{
|
||||||
@ -1577,6 +1685,10 @@ extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_extfs (void)
|
init_extfs (void)
|
||||||
{
|
{
|
||||||
@ -1612,3 +1724,5 @@ init_extfs (void)
|
|||||||
vfs_extfs_ops.setctl = extfs_setctl;
|
vfs_extfs_ops.setctl = extfs_setctl;
|
||||||
vfs_register_class (&vfs_extfs_ops);
|
vfs_register_class (&vfs_extfs_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
Written by: 1998 Pavel Machek
|
Written by: 1998 Pavel Machek
|
||||||
Spaces fix: 2000 Michal Svec
|
Spaces fix: 2000 Michal Svec
|
||||||
2010 Andrew Borodin
|
2010 Andrew Borodin
|
||||||
2010 Slava Zanko
|
2010 Slava Zanko
|
||||||
2010 Ilia Maslakov
|
2010 Ilia Maslakov
|
||||||
|
|
||||||
Derived from ftpfs.c.
|
Derived from ftpfs.c.
|
||||||
|
|
||||||
@ -76,8 +76,12 @@
|
|||||||
#include "fishdef.h"
|
#include "fishdef.h"
|
||||||
#include "src/execute.h" /* pre_exec, post_exec */
|
#include "src/execute.h" /* pre_exec, post_exec */
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
int fish_directory_timeout = 900;
|
int fish_directory_timeout = 900;
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
#define DO_RESOLVE_SYMLINK 1
|
#define DO_RESOLVE_SYMLINK 1
|
||||||
#define DO_OPEN 2
|
#define DO_OPEN 2
|
||||||
#define DO_FREE_RESOURCE 4
|
#define DO_FREE_RESOURCE 4
|
||||||
@ -111,10 +115,33 @@ int fish_directory_timeout = 900;
|
|||||||
#define FISH_HAVE_DATE_MDYT 32
|
#define FISH_HAVE_DATE_MDYT 32
|
||||||
#define FISH_HAVE_TAIL 64
|
#define FISH_HAVE_TAIL 64
|
||||||
|
|
||||||
|
#define SUP super->u.fish
|
||||||
|
|
||||||
|
#define PREFIX \
|
||||||
|
char buf[BUF_LARGE]; \
|
||||||
|
const char *crpath; \
|
||||||
|
char *rpath, *mpath; \
|
||||||
|
struct vfs_s_super *super; \
|
||||||
|
mpath = g_strdup (path); \
|
||||||
|
crpath = vfs_s_get_path_mangle (me, mpath, &super, 0); \
|
||||||
|
if (crpath == NULL) \
|
||||||
|
{ \
|
||||||
|
g_free (mpath); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
rpath = strutils_shell_escape (crpath); \
|
||||||
|
g_free (mpath);
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static char reply_str[80];
|
static char reply_str[80];
|
||||||
|
|
||||||
static struct vfs_class vfs_fish_ops;
|
static struct vfs_class vfs_fish_ops;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
fish_load_script_from_file (const char *hostname, const char *script_name, const char *def_content)
|
fish_load_script_from_file (const char *hostname, const char *script_name, const char *def_content)
|
||||||
@ -132,7 +159,8 @@ fish_load_script_from_file (const char *hostname, const char *script_name, const
|
|||||||
/* 2nd: scan system dir */
|
/* 2nd: scan system dir */
|
||||||
if (scr_content == NULL)
|
if (scr_content == NULL)
|
||||||
{
|
{
|
||||||
scr_filename = g_build_path (PATH_SEP_STR, LIBEXECDIR, FISH_PREFIX, script_name, (char *) NULL);
|
scr_filename =
|
||||||
|
g_build_path (PATH_SEP_STR, LIBEXECDIR, FISH_PREFIX, script_name, (char *) NULL);
|
||||||
g_file_get_contents (scr_filename, &scr_content, &scr_len, NULL);
|
g_file_get_contents (scr_filename, &scr_content, &scr_len, NULL);
|
||||||
g_free (scr_filename);
|
g_free (scr_filename);
|
||||||
}
|
}
|
||||||
@ -143,6 +171,8 @@ fish_load_script_from_file (const char *hostname, const char *script_name, const
|
|||||||
return g_strdup (def_content);
|
return g_strdup (def_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_decode_reply (char *s, int was_garbage)
|
fish_decode_reply (char *s, int was_garbage)
|
||||||
{
|
{
|
||||||
@ -157,7 +187,9 @@ fish_decode_reply (char *s, int was_garbage)
|
|||||||
return code / 100;
|
return code / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
|
fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
|
||||||
{
|
{
|
||||||
@ -184,7 +216,7 @@ fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SUP super->u.fish
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...)
|
fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...)
|
||||||
@ -222,6 +254,8 @@ fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, c
|
|||||||
return COMPLETE;
|
return COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -254,6 +288,8 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
g_free (SUP.scr_env);
|
g_free (SUP.scr_env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
||||||
{
|
{
|
||||||
@ -291,6 +327,8 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
fish_set_env (int flags)
|
fish_set_env (int flags)
|
||||||
{
|
{
|
||||||
@ -323,6 +361,8 @@ fish_set_env (int flags)
|
|||||||
return g_string_free (tmp, FALSE);
|
return g_string_free (tmp, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fish_info (struct vfs_class *me, struct vfs_s_super *super)
|
fish_info (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -345,7 +385,9 @@ fish_info (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* The returned directory should always contain a trailing slash */
|
/* The returned directory should always contain a trailing slash */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
|
fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -355,6 +397,8 @@ fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_open_archive_pipeopen (struct vfs_s_super *super)
|
fish_open_archive_pipeopen (struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -399,6 +443,8 @@ fish_open_archive_pipeopen (struct vfs_s_super *super)
|
|||||||
fish_pipeopen (super, xsh, argv);
|
fish_pipeopen (super, xsh, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
|
fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -443,6 +489,8 @@ fish_open_archive_talk (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -499,6 +547,8 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
const char *archive_name, char *op)
|
const char *archive_name, char *op)
|
||||||
@ -530,7 +580,8 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
SUP.scr_rmdir = fish_load_script_from_file (host, FISH_RMDIR_FILE, FISH_RMDIR_DEF_CONTENT);
|
SUP.scr_rmdir = fish_load_script_from_file (host, FISH_RMDIR_FILE, FISH_RMDIR_DEF_CONTENT);
|
||||||
SUP.scr_ln = fish_load_script_from_file (host, FISH_LN_FILE, FISH_LN_DEF_CONTENT);
|
SUP.scr_ln = fish_load_script_from_file (host, FISH_LN_FILE, FISH_LN_DEF_CONTENT);
|
||||||
SUP.scr_mv = fish_load_script_from_file (host, FISH_MV_FILE, FISH_MV_DEF_CONTENT);
|
SUP.scr_mv = fish_load_script_from_file (host, FISH_MV_FILE, FISH_MV_DEF_CONTENT);
|
||||||
SUP.scr_hardlink = fish_load_script_from_file (host, FISH_HARDLINK_FILE, FISH_HARDLINK_DEF_CONTENT);
|
SUP.scr_hardlink =
|
||||||
|
fish_load_script_from_file (host, FISH_HARDLINK_FILE, FISH_HARDLINK_DEF_CONTENT);
|
||||||
SUP.scr_get = fish_load_script_from_file (host, FISH_GET_FILE, FISH_GET_DEF_CONTENT);
|
SUP.scr_get = fish_load_script_from_file (host, FISH_GET_FILE, FISH_GET_DEF_CONTENT);
|
||||||
SUP.scr_send = fish_load_script_from_file (host, FISH_SEND_FILE, FISH_SEND_DEF_CONTENT);
|
SUP.scr_send = fish_load_script_from_file (host, FISH_SEND_FILE, FISH_SEND_DEF_CONTENT);
|
||||||
SUP.scr_append = fish_load_script_from_file (host, FISH_APPEND_FILE, FISH_APPEND_DEF_CONTENT);
|
SUP.scr_append = fish_load_script_from_file (host, FISH_APPEND_FILE, FISH_APPEND_DEF_CONTENT);
|
||||||
@ -538,6 +589,8 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return fish_open_archive_int (me, super);
|
return fish_open_archive_int (me, super);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
const char *archive_name, char *op, void *cookie)
|
const char *archive_name, char *op, void *cookie)
|
||||||
@ -567,6 +620,8 @@ fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
||||||
{
|
{
|
||||||
@ -772,6 +827,8 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
||||||
{
|
{
|
||||||
@ -892,6 +949,8 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
||||||
{
|
{
|
||||||
@ -934,6 +993,8 @@ fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||||
{
|
{
|
||||||
@ -961,6 +1022,8 @@ fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
|||||||
print_vfs_message (_("Aborted transfer would be successful."));
|
print_vfs_message (_("Aborted transfer would be successful."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t len)
|
fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
@ -985,6 +1048,8 @@ fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t l
|
|||||||
ERRNOR (errno, n);
|
ERRNOR (errno, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
fish_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||||
{
|
{
|
||||||
@ -992,6 +1057,8 @@ fish_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
|||||||
fish_linear_abort (me, fh);
|
fish_linear_abort (me, fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_ctl (void *fh, int ctlop, void *arg)
|
fish_ctl (void *fh, int ctlop, void *arg)
|
||||||
{
|
{
|
||||||
@ -1022,6 +1089,8 @@ fish_ctl (void *fh, int ctlop, void *arg)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags)
|
fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags)
|
||||||
{
|
{
|
||||||
@ -1036,20 +1105,7 @@ fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PREFIX \
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
char buf[BUF_LARGE]; \
|
|
||||||
const char *crpath; \
|
|
||||||
char *rpath, *mpath; \
|
|
||||||
struct vfs_s_super *super; \
|
|
||||||
mpath = g_strdup (path); \
|
|
||||||
crpath = vfs_s_get_path_mangle (me, mpath, &super, 0); \
|
|
||||||
if (crpath == NULL) \
|
|
||||||
{ \
|
|
||||||
g_free (mpath); \
|
|
||||||
return -1; \
|
|
||||||
} \
|
|
||||||
rpath = strutils_shell_escape (crpath); \
|
|
||||||
g_free (mpath);
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_rename (struct vfs_class *me, const char *path1, const char *path2)
|
fish_rename (struct vfs_class *me, const char *path1, const char *path2)
|
||||||
@ -1085,9 +1141,11 @@ fish_rename (struct vfs_class *me, const char *path1, const char *path2)
|
|||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
g_free (rpath1);
|
g_free (rpath1);
|
||||||
g_free (rpath2);
|
g_free (rpath2);
|
||||||
return fish_send_command(me, super2, buf, OPT_FLUSH);
|
return fish_send_command (me, super2, buf, OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_link (struct vfs_class *me, const char *path1, const char *path2)
|
fish_link (struct vfs_class *me, const char *path1, const char *path2)
|
||||||
{
|
{
|
||||||
@ -1126,6 +1184,8 @@ fish_link (struct vfs_class *me, const char *path1, const char *path2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
||||||
{
|
{
|
||||||
@ -1156,19 +1216,23 @@ fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
|||||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_chmod (struct vfs_class *me, const char *path, int mode)
|
fish_chmod (struct vfs_class *me, const char *path, int mode)
|
||||||
{
|
{
|
||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
PREFIX
|
PREFIX
|
||||||
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
|
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
|
||||||
SUP.scr_chmod, (char *) NULL);
|
SUP.scr_chmod, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath, mode & 07777);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath, mode & 07777);
|
||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
g_free (rpath);
|
g_free (rpath);
|
||||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
@ -1190,9 +1254,9 @@ fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
|||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
|
|
||||||
PREFIX
|
PREFIX
|
||||||
shell_commands = g_strconcat (SUP.scr_env,
|
shell_commands = g_strconcat (SUP.scr_env,
|
||||||
"FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n",
|
"FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n",
|
||||||
SUP.scr_chown, (char *) NULL);
|
SUP.scr_chown, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath, sowner, sgroup);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath, sowner, sgroup);
|
||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
fish_send_command (me, super, buf, OPT_FLUSH);
|
fish_send_command (me, super, buf, OPT_FLUSH);
|
||||||
@ -1203,12 +1267,14 @@ fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_unlink (struct vfs_class *me, const char *path)
|
fish_unlink (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
PREFIX
|
PREFIX
|
||||||
shell_commands =
|
shell_commands =
|
||||||
g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_unlink, (char *) NULL);
|
g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_unlink, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
@ -1216,12 +1282,15 @@ fish_unlink (struct vfs_class *me, const char *path)
|
|||||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_exists (struct vfs_class *me, const char *path)
|
fish_exists (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
PREFIX
|
PREFIX
|
||||||
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_exists, (char *) NULL);
|
shell_commands =
|
||||||
|
g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_exists, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
g_free (rpath);
|
g_free (rpath);
|
||||||
@ -1230,14 +1299,15 @@ fish_exists (struct vfs_class *me, const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
int ret_code;
|
int ret_code;
|
||||||
|
|
||||||
PREFIX
|
PREFIX (void) mode;
|
||||||
(void) mode;
|
|
||||||
|
|
||||||
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_mkdir, (char *) NULL);
|
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_mkdir, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
||||||
@ -1256,18 +1326,23 @@ fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_rmdir (struct vfs_class *me, const char *path)
|
fish_rmdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
gchar *shell_commands = NULL;
|
gchar *shell_commands = NULL;
|
||||||
PREFIX
|
PREFIX
|
||||||
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_rmdir, (char *) NULL);
|
shell_commands =
|
||||||
|
g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_rmdir, (char *) NULL);
|
||||||
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
|
||||||
g_free (shell_commands);
|
g_free (shell_commands);
|
||||||
g_free (rpath);
|
g_free (rpath);
|
||||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -1296,6 +1371,8 @@ fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fish_fill_names (struct vfs_class *me, fill_names_f func)
|
fish_fill_names (struct vfs_class *me, fill_names_f func)
|
||||||
{
|
{
|
||||||
@ -1332,6 +1409,8 @@ fish_fill_names (struct vfs_class *me, fill_names_f func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
fish_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
fish_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -1343,6 +1422,10 @@ fish_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
|||||||
return vfs_s_open (me, file, flags, mode);
|
return vfs_s_open (me, file, flags, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_fish (void)
|
init_fish (void)
|
||||||
{
|
{
|
||||||
@ -1377,3 +1460,5 @@ init_fish (void)
|
|||||||
vfs_fish_ops.ctl = fish_ctl;
|
vfs_fish_ops.ctl = fish_ctl;
|
||||||
vfs_register_class (&vfs_fish_ops);
|
vfs_register_class (&vfs_fish_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -6,9 +6,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MC_VFS_FISH_H
|
#ifndef MC__VFS_FISH_H
|
||||||
#define MC_VFS_FISH_H
|
#define MC__VFS_FISH_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern int fish_directory_timeout;
|
extern int fish_directory_timeout;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,8 +4,10 @@
|
|||||||
* \brief Header: FISH script defaults
|
* \brief Header: FISH script defaults
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_FISH_DEF_H
|
#ifndef MC__FISH_DEF_H
|
||||||
#define MC_FISH_DEF_H
|
#define MC__FISH_DEF_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* default 'ls' script */
|
/* default 'ls' script */
|
||||||
#define FISH_LS_DEF_CONTENT "" \
|
#define FISH_LS_DEF_CONTENT "" \
|
||||||
@ -205,5 +207,13 @@
|
|||||||
"echo $res\n" \
|
"echo $res\n" \
|
||||||
"echo \"### 200\"\n"
|
"echo \"### 200\"\n"
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
2006, 2007 Free Software Foundation, Inc.
|
2006, 2007 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by:
|
Written by:
|
||||||
1995 Ching Hui
|
1995 Ching Hui
|
||||||
1995 Jakub Jelinek
|
1995 Jakub Jelinek
|
||||||
1995, 1996, 1997 Miguel de Icaza
|
1995, 1996, 1997 Miguel de Icaza
|
||||||
1997 Norbert Warmuth
|
1997 Norbert Warmuth
|
||||||
1998 Pavel Machek
|
1998 Pavel Machek
|
||||||
2010 Yury V. Zaytsev
|
2010 Yury V. Zaytsev
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Library General Public License
|
modify it under the terms of the GNU Library General Public License
|
||||||
@ -103,33 +103,7 @@ What to do with this?
|
|||||||
|
|
||||||
#include "ftpfs.h"
|
#include "ftpfs.h"
|
||||||
|
|
||||||
#ifndef MAXHOSTNAMELEN
|
/*** global variables ****************************************************************************/
|
||||||
# define MAXHOSTNAMELEN 64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UPLOAD_ZERO_LENGTH_FILE
|
|
||||||
#define SUP super->u.ftp
|
|
||||||
#define FH_SOCK fh->u.ftp.sock
|
|
||||||
|
|
||||||
#ifndef INADDR_NONE
|
|
||||||
#define INADDR_NONE 0xffffffff
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* for uclibc < 0.9.29 */
|
|
||||||
#ifndef AI_ADDRCONFIG
|
|
||||||
#define AI_ADDRCONFIG 0x0020
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define RFC_AUTODETECT 0
|
|
||||||
#define RFC_DARING 1
|
|
||||||
#define RFC_STRICT 2
|
|
||||||
|
|
||||||
#ifndef HAVE_SOCKLEN_T
|
|
||||||
typedef int socklen_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int ftpfs_errno;
|
|
||||||
static int code;
|
|
||||||
|
|
||||||
/* Delay to retry a connection */
|
/* Delay to retry a connection */
|
||||||
int ftpfs_retry_seconds = 30;
|
int ftpfs_retry_seconds = 30;
|
||||||
@ -163,18 +137,92 @@ int ftpfs_always_use_proxy = 0;
|
|||||||
|
|
||||||
int ftpfs_ignore_chattr_errors = 1;
|
int ftpfs_ignore_chattr_errors = 1;
|
||||||
|
|
||||||
#ifdef FIXME_LATER_ALIGATOR
|
/*** file scope macro definitions ****************************************************************/
|
||||||
static struct linklist *connections_list;
|
|
||||||
|
#ifndef MAXHOSTNAMELEN
|
||||||
|
#define MAXHOSTNAMELEN 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define UPLOAD_ZERO_LENGTH_FILE
|
||||||
|
#define SUP super->u.ftp
|
||||||
|
#define FH_SOCK fh->u.ftp.sock
|
||||||
|
|
||||||
|
#ifndef INADDR_NONE
|
||||||
|
#define INADDR_NONE 0xffffffff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* for uclibc < 0.9.29 */
|
||||||
|
#ifndef AI_ADDRCONFIG
|
||||||
|
#define AI_ADDRCONFIG 0x0020
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RFC_AUTODETECT 0
|
||||||
|
#define RFC_DARING 1
|
||||||
|
#define RFC_STRICT 2
|
||||||
|
|
||||||
/* ftpfs_command wait_flag: */
|
/* ftpfs_command wait_flag: */
|
||||||
#define NONE 0x00
|
#define NONE 0x00
|
||||||
#define WAIT_REPLY 0x01
|
#define WAIT_REPLY 0x01
|
||||||
#define WANT_STRING 0x02
|
#define WANT_STRING 0x02
|
||||||
|
|
||||||
|
#define FTP_COMMAND_PORT 21
|
||||||
|
|
||||||
|
/* some defines only used by ftpfs_changetype */
|
||||||
|
/* These two are valid values for the second parameter */
|
||||||
|
#define TYPE_ASCII 0
|
||||||
|
#define TYPE_BINARY 1
|
||||||
|
|
||||||
|
/* This one is only used to initialize bucket->isbinary, don't use it as
|
||||||
|
second parameter to ftpfs_changetype. */
|
||||||
|
#define TYPE_UNKNOWN -1
|
||||||
|
|
||||||
|
#define ABORT_TIMEOUT 5
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
#ifndef HAVE_SOCKLEN_T
|
||||||
|
typedef int socklen_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This should match the keywords[] array below */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
NETRC_NONE = 0,
|
||||||
|
NETRC_DEFAULT,
|
||||||
|
NETRC_MACHINE,
|
||||||
|
NETRC_LOGIN,
|
||||||
|
NETRC_PASSWORD,
|
||||||
|
NETRC_PASSWD,
|
||||||
|
NETRC_ACCOUNT,
|
||||||
|
NETRC_MACDEF,
|
||||||
|
NETRC_UNKNOWN
|
||||||
|
} keyword_t;
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
static int ftpfs_errno;
|
||||||
|
static int code;
|
||||||
|
|
||||||
|
#ifdef FIXME_LATER_ALIGATOR
|
||||||
|
static struct linklist *connections_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
static char reply_str[80];
|
static char reply_str[80];
|
||||||
|
|
||||||
static struct vfs_class vfs_ftpfs_ops;
|
static struct vfs_class vfs_ftpfs_ops;
|
||||||
|
|
||||||
|
static struct no_proxy_entry
|
||||||
|
{
|
||||||
|
char *domain;
|
||||||
|
void *next;
|
||||||
|
} *no_proxy;
|
||||||
|
|
||||||
|
static char buffer[BUF_MEDIUM];
|
||||||
|
static char *netrc;
|
||||||
|
static const char *netrcp;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* char *ftpfs_translate_path (struct ftpfs_connection *bucket, char *remote_path)
|
/* char *ftpfs_translate_path (struct ftpfs_connection *bucket, char *remote_path)
|
||||||
Translate a Unix path, i.e. MC's internal path representation (e.g.
|
Translate a Unix path, i.e. MC's internal path representation (e.g.
|
||||||
/somedir/somefile) to a path valid for the remote server. Every path
|
/somedir/somefile) to a path valid for the remote server. Every path
|
||||||
@ -198,6 +246,8 @@ static int ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
const char *netrcpass);
|
const char *netrcpass);
|
||||||
static int ftpfs_netrc_lookup (const char *host, char **login, char **pass);
|
static int ftpfs_netrc_lookup (const char *host, char **login, char **pass);
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path)
|
ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path)
|
||||||
{
|
{
|
||||||
@ -240,8 +290,8 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the hostname and username from the path */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/** Extract the hostname and username from the path */
|
||||||
/*
|
/*
|
||||||
* path is in the form: [user@]hostname:port/remote-dir, e.g.:
|
* path is in the form: [user@]hostname:port/remote-dir, e.g.:
|
||||||
* ftp://sunsite.unc.edu/pub/linux
|
* ftp://sunsite.unc.edu/pub/linux
|
||||||
@ -253,8 +303,6 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FTP_COMMAND_PORT 21
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_split_url (char *path, char **host, char **user, int *port, char **pass)
|
ftpfs_split_url (char *path, char **host, char **user, int *port, char **pass)
|
||||||
{
|
{
|
||||||
@ -291,7 +339,9 @@ ftpfs_split_url (char *path, char **host, char **user, int *port, char **pass)
|
|||||||
g_free (p);
|
g_free (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
|
ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
|
||||||
{
|
{
|
||||||
@ -337,6 +387,8 @@ ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_le
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -360,6 +412,8 @@ ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt,
|
ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt,
|
||||||
...)
|
...)
|
||||||
@ -449,6 +503,8 @@ ftpfs_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply,
|
|||||||
return COMPLETE;
|
return COMPLETE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -464,14 +520,7 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
g_free (SUP.password);
|
g_free (SUP.password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* some defines only used by ftpfs_changetype */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* These two are valid values for the second parameter */
|
|
||||||
#define TYPE_ASCII 0
|
|
||||||
#define TYPE_BINARY 1
|
|
||||||
|
|
||||||
/* This one is only used to initialize bucket->isbinary, don't use it as
|
|
||||||
second parameter to ftpfs_changetype. */
|
|
||||||
#define TYPE_UNKNOWN -1
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_changetype (struct vfs_class *me, struct vfs_s_super *super, int binary)
|
ftpfs_changetype (struct vfs_class *me, struct vfs_s_super *super, int binary)
|
||||||
@ -485,7 +534,9 @@ ftpfs_changetype (struct vfs_class *me, struct vfs_s_super *super, int binary)
|
|||||||
return binary;
|
return binary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* This routine logs the user in */
|
/* This routine logs the user in */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char *netrcpass)
|
ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char *netrcpass)
|
||||||
{
|
{
|
||||||
@ -598,11 +649,7 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char
|
|||||||
ERRNOR (EPERM, 0);
|
ERRNOR (EPERM, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct no_proxy_entry
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
{
|
|
||||||
char *domain;
|
|
||||||
void *next;
|
|
||||||
} *no_proxy;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_load_no_proxy_list (void)
|
ftpfs_load_no_proxy_list (void)
|
||||||
@ -627,7 +674,7 @@ ftpfs_load_no_proxy_list (void)
|
|||||||
while (fgets (s, sizeof (s), npf) != NULL)
|
while (fgets (s, sizeof (s), npf) != NULL)
|
||||||
{
|
{
|
||||||
p = strchr (s, '\n');
|
p = strchr (s, '\n');
|
||||||
if (p == NULL) /* skip bogus entries */
|
if (p == NULL) /* skip bogus entries */
|
||||||
{
|
{
|
||||||
while ((c = fgetc (npf)) != EOF && c != '\n')
|
while ((c = fgetc (npf)) != EOF && c != '\n')
|
||||||
;
|
;
|
||||||
@ -641,7 +688,7 @@ ftpfs_load_no_proxy_list (void)
|
|||||||
|
|
||||||
np = g_new (struct no_proxy_entry, 1);
|
np = g_new (struct no_proxy_entry, 1);
|
||||||
np->domain = g_strdup (s);
|
np->domain = g_strdup (s);
|
||||||
np->next = NULL;
|
np->next = NULL;
|
||||||
if (no_proxy)
|
if (no_proxy)
|
||||||
current->next = np;
|
current->next = np;
|
||||||
else
|
else
|
||||||
@ -654,7 +701,9 @@ ftpfs_load_no_proxy_list (void)
|
|||||||
g_free (mc_file);
|
g_free (mc_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Return 1 if FTP proxy should be used for this host, 0 otherwise */
|
/* Return 1 if FTP proxy should be used for this host, 0 otherwise */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_check_proxy (const char *host)
|
ftpfs_check_proxy (const char *host)
|
||||||
{
|
{
|
||||||
@ -698,6 +747,8 @@ ftpfs_check_proxy (const char *host)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_get_proxy_host_and_port (const char *proxy, char **host, int *port)
|
ftpfs_get_proxy_host_and_port (const char *proxy, char **host, int *port)
|
||||||
{
|
{
|
||||||
@ -708,6 +759,8 @@ ftpfs_get_proxy_host_and_port (const char *proxy, char **host, int *port)
|
|||||||
g_free (dir);
|
g_free (dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -820,6 +873,8 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return my_socket;
|
return my_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -882,6 +937,8 @@ ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
const char *archive_name, char *op)
|
const char *archive_name, char *op)
|
||||||
@ -911,6 +968,8 @@ ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return ftpfs_open_archive_int (me, super);
|
return ftpfs_open_archive_int (me, super);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
const char *archive_name, char *op, void *cookie)
|
const char *archive_name, char *op, void *cookie)
|
||||||
@ -932,7 +991,9 @@ ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* The returned directory should always contain a trailing slash */
|
/* The returned directory should always contain a trailing slash */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -981,10 +1042,12 @@ ftpfs_get_current_directory (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Setup Passive PASV FTP connection */
|
/* Setup Passive PASV FTP connection */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_setup_passive_pasv (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_setup_passive_pasv (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
int my_socket, struct sockaddr_storage *sa, socklen_t *salen)
|
int my_socket, struct sockaddr_storage *sa, socklen_t * salen)
|
||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
char n[6];
|
char n[6];
|
||||||
@ -1019,10 +1082,12 @@ ftpfs_setup_passive_pasv (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Setup Passive EPSV FTP connection */
|
/* Setup Passive EPSV FTP connection */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_setup_passive_epsv (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_setup_passive_epsv (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
int my_socket, struct sockaddr_storage *sa, socklen_t *salen)
|
int my_socket, struct sockaddr_storage *sa, socklen_t * salen)
|
||||||
{
|
{
|
||||||
char *c;
|
char *c;
|
||||||
int port;
|
int port;
|
||||||
@ -1060,10 +1125,12 @@ ftpfs_setup_passive_epsv (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Setup Passive ftp connection, we use it for source routed connections */
|
/* Setup Passive ftp connection, we use it for source routed connections */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_setup_passive (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_setup_passive (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
int my_socket, struct sockaddr_storage *sa, socklen_t *salen)
|
int my_socket, struct sockaddr_storage *sa, socklen_t * salen)
|
||||||
{
|
{
|
||||||
/* It's IPV4, so try PASV first, some servers and ALGs get confused by EPSV */
|
/* It's IPV4, so try PASV first, some servers and ALGs get confused by EPSV */
|
||||||
if (sa->ss_family == AF_INET)
|
if (sa->ss_family == AF_INET)
|
||||||
@ -1083,7 +1150,9 @@ ftpfs_setup_passive (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Setup Active PORT or EPRT FTP connection */
|
/* Setup Active PORT or EPRT FTP connection */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
struct sockaddr_storage data_addr, socklen_t data_addrlen)
|
struct sockaddr_storage data_addr, socklen_t data_addrlen)
|
||||||
@ -1102,7 +1171,7 @@ ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
af = FTP_INET6;
|
af = FTP_INET6;
|
||||||
port = ((struct sockaddr_in6 *) &data_addr)->sin6_port;
|
port = ((struct sockaddr_in6 *) &data_addr)->sin6_port;
|
||||||
break;
|
break;
|
||||||
/* Not implemented */
|
/* Not implemented */
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1153,10 +1222,12 @@ ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Initialize a socket for FTP DATA connection */
|
/* Initialize a socket for FTP DATA connection */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_init_data_socket (struct vfs_class *me, struct vfs_s_super *super,
|
ftpfs_init_data_socket (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
struct sockaddr_storage *data_addr, socklen_t *data_addrlen)
|
struct sockaddr_storage *data_addr, socklen_t * data_addrlen)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
@ -1190,11 +1261,14 @@ ftpfs_init_data_socket (struct vfs_class *me, struct vfs_s_super *super,
|
|||||||
{
|
{
|
||||||
print_vfs_message (_("ftpfs: could not create socket: %s"), unix_error_string (errno));
|
print_vfs_message (_("ftpfs: could not create socket: %s"), unix_error_string (errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Initialize FTP DATA connection */
|
/* Initialize FTP DATA connection */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
|
ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
|
||||||
{
|
{
|
||||||
@ -1247,19 +1321,21 @@ ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
|
|||||||
|
|
||||||
/* Restore the initial value of use_passive_connection (for subsequent retries) */
|
/* Restore the initial value of use_passive_connection (for subsequent retries) */
|
||||||
SUP.use_passive_connection = SUP.proxy ? ftpfs_use_passive_connections_over_proxy :
|
SUP.use_passive_connection = SUP.proxy ? ftpfs_use_passive_connections_over_proxy :
|
||||||
ftpfs_use_passive_connections;
|
ftpfs_use_passive_connections;
|
||||||
|
|
||||||
ftpfs_errno = EIO;
|
ftpfs_errno = EIO;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, const char *cmd,
|
ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, const char *cmd,
|
||||||
const char *remote, int isbinary, int reget)
|
const char *remote, int isbinary, int reget)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage from;
|
struct sockaddr_storage from;
|
||||||
int s, j, data;
|
int s, j, data;
|
||||||
socklen_t fromlen = sizeof(from);
|
socklen_t fromlen = sizeof (from);
|
||||||
|
|
||||||
s = ftpfs_initconn (me, super);
|
s = ftpfs_initconn (me, super);
|
||||||
if (s == -1)
|
if (s == -1)
|
||||||
@ -1304,7 +1380,8 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ABORT_TIMEOUT 5
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
ftpfs_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||||
{
|
{
|
||||||
@ -1359,6 +1436,8 @@ ftpfs_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
|||||||
ftpfs_get_reply (me, SUP.sock, NULL, 0);
|
ftpfs_get_reply (me, SUP.sock, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void
|
static void
|
||||||
resolve_symlink_without_ls_options (struct vfs_class *me, struct vfs_s_super *super,
|
resolve_symlink_without_ls_options (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
@ -1435,6 +1514,8 @@ resolve_symlink_without_ls_options (struct vfs_class *me, struct vfs_s_super *su
|
|||||||
dir->symlink_status = FTPFS_RESOLVED_SYMLINKS;
|
dir->symlink_status = FTPFS_RESOLVED_SYMLINKS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super,
|
resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super,
|
||||||
struct vfs_s_inode *dir)
|
struct vfs_s_inode *dir)
|
||||||
@ -1526,6 +1607,8 @@ resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super
|
|||||||
ftpfs_get_reply (me, SUP.sock, NULL, 0);
|
ftpfs_get_reply (me, SUP.sock, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resolve_symlink (struct vfs_class *me, struct vfs_s_super *super, struct vfs_s_inode *dir)
|
resolve_symlink (struct vfs_class *me, struct vfs_s_super *super, struct vfs_s_inode *dir)
|
||||||
{
|
{
|
||||||
@ -1538,6 +1621,8 @@ resolve_symlink (struct vfs_class *me, struct vfs_s_super *super, struct vfs_s_i
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
||||||
{
|
{
|
||||||
@ -1668,6 +1753,8 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path
|
|||||||
ERRNOR (EACCES, -1);
|
ERRNOR (EACCES, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
||||||
{
|
{
|
||||||
@ -1740,7 +1827,7 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l
|
|||||||
n_read -= n_written;
|
n_read -= n_written;
|
||||||
}
|
}
|
||||||
print_vfs_message (_("ftpfs: storing file %ju (%ju)"),
|
print_vfs_message (_("ftpfs: storing file %ju (%ju)"),
|
||||||
(uintmax_t) n_stored, (uintmax_t) s.st_size);
|
(uintmax_t) n_stored, (uintmax_t) s.st_size);
|
||||||
}
|
}
|
||||||
tty_disable_interrupt_key ();
|
tty_disable_interrupt_key ();
|
||||||
close (sock);
|
close (sock);
|
||||||
@ -1756,6 +1843,8 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
ftpfs_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
||||||
{
|
{
|
||||||
@ -1773,6 +1862,8 @@ ftpfs_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t len)
|
ftpfs_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t len)
|
||||||
{
|
{
|
||||||
@ -1801,6 +1892,8 @@ ftpfs_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, size_t
|
|||||||
ERRNOR (errno, n);
|
ERRNOR (errno, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
ftpfs_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||||
{
|
{
|
||||||
@ -1808,6 +1901,8 @@ ftpfs_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
|||||||
ftpfs_linear_abort (me, fh);
|
ftpfs_linear_abort (me, fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_ctl (void *fh, int ctlop, void *arg)
|
ftpfs_ctl (void *fh, int ctlop, void *arg)
|
||||||
{
|
{
|
||||||
@ -1834,6 +1929,8 @@ ftpfs_ctl (void *fh, int ctlop, void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_send_command (struct vfs_class *me, const char *filename, const char *cmd, int flags)
|
ftpfs_send_command (struct vfs_class *me, const char *filename, const char *cmd, int flags)
|
||||||
{
|
{
|
||||||
@ -1867,24 +1964,7 @@ ftpfs_send_command (struct vfs_class *me, const char *filename, const char *cmd,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This routine is called as the last step in load_setup */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
void
|
|
||||||
ftpfs_init_passwd (void)
|
|
||||||
{
|
|
||||||
ftpfs_anonymous_passwd = load_anon_passwd ();
|
|
||||||
if (ftpfs_anonymous_passwd)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* If there is no anonymous ftp password specified
|
|
||||||
* then we'll just use anonymous@
|
|
||||||
* We don't send any other thing because:
|
|
||||||
* - We want to remain anonymous
|
|
||||||
* - We want to stop SPAM
|
|
||||||
* - We don't want to let ftp sites to discriminate by the user,
|
|
||||||
* host or country.
|
|
||||||
*/
|
|
||||||
ftpfs_anonymous_passwd = g_strdup ("anonymous@");
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_chmod (struct vfs_class *me, const char *path, int mode)
|
ftpfs_chmod (struct vfs_class *me, const char *path, int mode)
|
||||||
@ -1899,6 +1979,8 @@ ftpfs_chmod (struct vfs_class *me, const char *path, int mode)
|
|||||||
return ftpfs_ignore_chattr_errors ? 0 : ret;
|
return ftpfs_ignore_chattr_errors ? 0 : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
ftpfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
@ -1916,12 +1998,16 @@ ftpfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_unlink (struct vfs_class *me, const char *path)
|
ftpfs_unlink (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
return ftpfs_send_command (me, path, "DELE /%s", OPT_FLUSH);
|
return ftpfs_send_command (me, path, "DELE /%s", OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* Return 1 if path is the same directory as the one we are in now */
|
/* Return 1 if path is the same directory as the one we are in now */
|
||||||
static int
|
static int
|
||||||
ftpfs_is_same_dir (struct vfs_class *me, struct vfs_s_super *super, const char *path)
|
ftpfs_is_same_dir (struct vfs_class *me, struct vfs_s_super *super, const char *path)
|
||||||
@ -1935,6 +2021,8 @@ ftpfs_is_same_dir (struct vfs_class *me, struct vfs_s_super *super, const char *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path)
|
ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const char *remote_path)
|
||||||
{
|
{
|
||||||
@ -1961,6 +2049,8 @@ ftpfs_chdir_internal (struct vfs_class *me, struct vfs_s_super *super, const cha
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_rename (struct vfs_class *me, const char *path1, const char *path2)
|
ftpfs_rename (struct vfs_class *me, const char *path1, const char *path2)
|
||||||
{
|
{
|
||||||
@ -1968,6 +2058,8 @@ ftpfs_rename (struct vfs_class *me, const char *path1, const char *path2)
|
|||||||
return ftpfs_send_command (me, path2, "RNTO /%s", OPT_FLUSH);
|
return ftpfs_send_command (me, path2, "RNTO /%s", OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
ftpfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -1976,12 +2068,16 @@ ftpfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
|||||||
return ftpfs_send_command (me, path, "MKD /%s", OPT_FLUSH);
|
return ftpfs_send_command (me, path, "MKD /%s", OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_rmdir (struct vfs_class *me, const char *path)
|
ftpfs_rmdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
return ftpfs_send_command (me, path, "RMD /%s", OPT_FLUSH);
|
return ftpfs_send_command (me, path, "RMD /%s", OPT_FLUSH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
ftpfs_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -2048,6 +2144,8 @@ ftpfs_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_fh_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
ftpfs_fh_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||||
{
|
{
|
||||||
@ -2066,6 +2164,8 @@ ftpfs_fh_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_done (struct vfs_class *me)
|
ftpfs_done (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
@ -2084,6 +2184,8 @@ ftpfs_done (struct vfs_class *me)
|
|||||||
g_free (ftpfs_proxy_host);
|
g_free (ftpfs_proxy_host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ftpfs_fill_names (struct vfs_class *me, fill_names_f func)
|
ftpfs_fill_names (struct vfs_class *me, fill_names_f func)
|
||||||
{
|
{
|
||||||
@ -2099,23 +2201,7 @@ ftpfs_fill_names (struct vfs_class *me, fill_names_f func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char buffer[BUF_MEDIUM];
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
static char *netrc;
|
|
||||||
static const char *netrcp;
|
|
||||||
|
|
||||||
/* This should match the keywords[] array below */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
NETRC_NONE = 0,
|
|
||||||
NETRC_DEFAULT,
|
|
||||||
NETRC_MACHINE,
|
|
||||||
NETRC_LOGIN,
|
|
||||||
NETRC_PASSWORD,
|
|
||||||
NETRC_PASSWD,
|
|
||||||
NETRC_ACCOUNT,
|
|
||||||
NETRC_MACDEF,
|
|
||||||
NETRC_UNKNOWN
|
|
||||||
} keyword_t;
|
|
||||||
|
|
||||||
static keyword_t
|
static keyword_t
|
||||||
ftpfs_netrc_next (void)
|
ftpfs_netrc_next (void)
|
||||||
@ -2172,6 +2258,8 @@ ftpfs_netrc_next (void)
|
|||||||
return NETRC_UNKNOWN;
|
return NETRC_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_netrc_bad_mode (const char *netrcname)
|
ftpfs_netrc_bad_mode (const char *netrcname)
|
||||||
{
|
{
|
||||||
@ -2191,10 +2279,12 @@ ftpfs_netrc_bad_mode (const char *netrcname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Scan .netrc until we find matching "machine" or "default"
|
/* Scan .netrc until we find matching "machine" or "default"
|
||||||
* domain is used for additional matching
|
* domain is used for additional matching
|
||||||
* No search is done after "default" in compliance with "man netrc"
|
* No search is done after "default" in compliance with "man netrc"
|
||||||
* Return 0 if found, -1 otherwise */
|
* Return 0 if found, -1 otherwise */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_find_machine (const char *host, const char *domain)
|
ftpfs_find_machine (const char *host, const char *domain)
|
||||||
{
|
{
|
||||||
@ -2255,9 +2345,11 @@ ftpfs_find_machine (const char *host, const char *domain)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Extract login and password from .netrc for the host.
|
/* Extract login and password from .netrc for the host.
|
||||||
* pass may be NULL.
|
* pass may be NULL.
|
||||||
* Returns 0 for success, -1 for error */
|
* Returns 0 for success, -1 for error */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ftpfs_netrc_lookup (const char *host, char **login, char **pass)
|
ftpfs_netrc_lookup (const char *host, char **login, char **pass)
|
||||||
{
|
{
|
||||||
@ -2405,6 +2497,31 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/** This routine is called as the last step in load_setup */
|
||||||
|
void
|
||||||
|
ftpfs_init_passwd (void)
|
||||||
|
{
|
||||||
|
ftpfs_anonymous_passwd = load_anon_passwd ();
|
||||||
|
if (ftpfs_anonymous_passwd)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* If there is no anonymous ftp password specified
|
||||||
|
* then we'll just use anonymous@
|
||||||
|
* We don't send any other thing because:
|
||||||
|
* - We want to remain anonymous
|
||||||
|
* - We want to stop SPAM
|
||||||
|
* - We don't want to let ftp sites to discriminate by the user,
|
||||||
|
* host or country.
|
||||||
|
*/
|
||||||
|
ftpfs_anonymous_passwd = g_strdup ("anonymous@");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_ftpfs (void)
|
init_ftpfs (void)
|
||||||
{
|
{
|
||||||
@ -2439,3 +2556,5 @@ init_ftpfs (void)
|
|||||||
vfs_ftpfs_ops.ctl = ftpfs_ctl;
|
vfs_ftpfs_ops.ctl = ftpfs_ctl;
|
||||||
vfs_register_class (&vfs_ftpfs_ops);
|
vfs_register_class (&vfs_ftpfs_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief Header: Virtual File System: FTP file system
|
* \brief Header: Virtual File System: FTP file system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_FTPFS_H
|
#ifndef MC__VFS_FTPFS_H
|
||||||
#define MC_VFS_FTPFS_H
|
#define MC__VFS_FTPFS_H
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
#define FTP_INET 1
|
||||||
|
#define FTP_INET6 2
|
||||||
|
|
||||||
|
#define OPT_FLUSH 1
|
||||||
|
#define OPT_IGNORE_ERROR 2
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern int ftpfs_use_netrc;
|
extern int ftpfs_use_netrc;
|
||||||
extern char *ftpfs_anonymous_passwd;
|
extern char *ftpfs_anonymous_passwd;
|
||||||
@ -20,13 +33,10 @@ extern int ftpfs_use_passive_connections_over_proxy;
|
|||||||
extern int ftpfs_use_unix_list_options;
|
extern int ftpfs_use_unix_list_options;
|
||||||
extern int ftpfs_first_cd_then_ls;
|
extern int ftpfs_first_cd_then_ls;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
void ftpfs_init_passwd (void);
|
void ftpfs_init_passwd (void);
|
||||||
void init_ftpfs (void);
|
void init_ftpfs (void);
|
||||||
|
|
||||||
#define FTP_INET 1
|
/*** inline functions ****************************************************************************/
|
||||||
#define FTP_INET6 2
|
|
||||||
|
|
||||||
#define OPT_FLUSH 1
|
|
||||||
#define OPT_IGNORE_ERROR 2
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,9 +2,9 @@
|
|||||||
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
|
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Written by: 1995 Miguel de Icaza
|
Written by: 1995 Miguel de Icaza
|
||||||
1995 Jakub Jelinek
|
1995 Jakub Jelinek
|
||||||
1998 Pavel Machek
|
1998 Pavel Machek
|
||||||
2003 Pavel Roskin
|
2003 Pavel Roskin
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU Library General Public License
|
modify it under the terms of the GNU Library General Public License
|
||||||
@ -34,59 +34,89 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h> /* For atol() */
|
#include <stdlib.h> /* For atol() */
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <ctype.h> /* is_digit() */
|
#include <ctype.h> /* is_digit() */
|
||||||
#include <sys/time.h> /* gettimeofday() */
|
#include <sys/time.h> /* gettimeofday() */
|
||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "src/panel.h" /* current_panel */
|
#include "src/panel.h" /* current_panel */
|
||||||
#include "src/layout.h" /* get_current_type(), get_other_type() */
|
#include "src/layout.h" /* get_current_type(), get_other_type() */
|
||||||
|
|
||||||
#include "vfs-impl.h"
|
#include "vfs-impl.h"
|
||||||
#include "utilvfs.h"
|
#include "utilvfs.h"
|
||||||
|
|
||||||
#include "gc.h"
|
#include "gc.h"
|
||||||
|
|
||||||
int vfs_timeout = 60; /* VFS timeout in seconds */
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
int vfs_timeout = 60; /* VFS timeout in seconds */
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
static struct vfs_stamping *stamps;
|
static struct vfs_stamping *stamps;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vfs_addstamp (struct vfs_class *v, vfsid id)
|
vfs_addstamp (struct vfs_class *v, vfsid id)
|
||||||
{
|
{
|
||||||
if (!(v->flags & VFSF_LOCAL) && id != NULL) {
|
if (!(v->flags & VFSF_LOCAL) && id != NULL)
|
||||||
struct vfs_stamping *stamp;
|
{
|
||||||
struct vfs_stamping *last_stamp = NULL;
|
struct vfs_stamping *stamp;
|
||||||
|
struct vfs_stamping *last_stamp = NULL;
|
||||||
|
|
||||||
for (stamp = stamps; stamp != NULL; stamp = stamp->next) {
|
for (stamp = stamps; stamp != NULL; stamp = stamp->next)
|
||||||
if (stamp->v == v && stamp->id == id) {
|
{
|
||||||
gettimeofday (&(stamp->time), NULL);
|
if (stamp->v == v && stamp->id == id)
|
||||||
return;
|
{
|
||||||
}
|
gettimeofday (&(stamp->time), NULL);
|
||||||
last_stamp = stamp;
|
return;
|
||||||
}
|
}
|
||||||
stamp = g_new (struct vfs_stamping, 1);
|
last_stamp = stamp;
|
||||||
stamp->v = v;
|
}
|
||||||
stamp->id = id;
|
stamp = g_new (struct vfs_stamping, 1);
|
||||||
|
stamp->v = v;
|
||||||
|
stamp->id = id;
|
||||||
|
|
||||||
gettimeofday (&(stamp->time), NULL);
|
gettimeofday (&(stamp->time), NULL);
|
||||||
stamp->next = 0;
|
stamp->next = 0;
|
||||||
|
|
||||||
if (stamps) {
|
if (stamps)
|
||||||
/* Add to the end */
|
{
|
||||||
last_stamp->next = stamp;
|
/* Add to the end */
|
||||||
} else {
|
last_stamp->next = stamp;
|
||||||
/* Add first element */
|
}
|
||||||
stamps = stamp;
|
else
|
||||||
}
|
{
|
||||||
|
/* Add first element */
|
||||||
|
stamps = stamp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/** Compare two timeval structures. Return 0 is t1 is less than t2. */
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
timeoutcmp (struct timeval *t1, struct timeval *t2)
|
||||||
|
{
|
||||||
|
return ((t1->tv_sec < t2->tv_sec)
|
||||||
|
|| ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec <= t2->tv_usec)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_stamp (struct vfs_class *v, vfsid id)
|
vfs_stamp (struct vfs_class *v, vfsid id)
|
||||||
@ -94,32 +124,38 @@ vfs_stamp (struct vfs_class *v, vfsid id)
|
|||||||
struct vfs_stamping *stamp;
|
struct vfs_stamping *stamp;
|
||||||
|
|
||||||
for (stamp = stamps; stamp != NULL; stamp = stamp->next)
|
for (stamp = stamps; stamp != NULL; stamp = stamp->next)
|
||||||
if (stamp->v == v && stamp->id == id) {
|
if (stamp->v == v && stamp->id == id)
|
||||||
gettimeofday (&(stamp->time), NULL);
|
{
|
||||||
return;
|
gettimeofday (&(stamp->time), NULL);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_rmstamp (struct vfs_class *v, vfsid id)
|
vfs_rmstamp (struct vfs_class *v, vfsid id)
|
||||||
{
|
{
|
||||||
struct vfs_stamping *stamp, *st1;
|
struct vfs_stamping *stamp, *st1;
|
||||||
|
|
||||||
for (stamp = stamps, st1 = NULL; stamp != NULL;
|
for (stamp = stamps, st1 = NULL; stamp != NULL; st1 = stamp, stamp = stamp->next)
|
||||||
st1 = stamp, stamp = stamp->next)
|
if (stamp->v == v && stamp->id == id)
|
||||||
if (stamp->v == v && stamp->id == id) {
|
{
|
||||||
if (st1 == NULL) {
|
if (st1 == NULL)
|
||||||
stamps = stamp->next;
|
{
|
||||||
} else {
|
stamps = stamp->next;
|
||||||
st1->next = stamp->next;
|
}
|
||||||
}
|
else
|
||||||
g_free (stamp);
|
{
|
||||||
|
st1->next = stamp->next;
|
||||||
|
}
|
||||||
|
g_free (stamp);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_stamp_path (const char *path)
|
vfs_stamp_path (const char *path)
|
||||||
@ -132,10 +168,11 @@ vfs_stamp_path (const char *path)
|
|||||||
vfs_addstamp (vfs, id);
|
vfs_addstamp (vfs, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*
|
/**
|
||||||
* Create a new timestamp item by VFS class and VFS id.
|
* Create a new timestamp item by VFS class and VFS id.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
||||||
{
|
{
|
||||||
@ -148,54 +185,53 @@ vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
|||||||
same, it's possible that all three are different -- Norbert */
|
same, it's possible that all three are different -- Norbert */
|
||||||
|
|
||||||
if (!current_panel)
|
if (!current_panel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
nvfs = vfs_get_class (vfs_get_current_dir ());
|
nvfs = vfs_get_class (vfs_get_current_dir ());
|
||||||
nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
|
nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
|
||||||
vfs_rmstamp (nvfs, nvfsid);
|
vfs_rmstamp (nvfs, nvfsid);
|
||||||
|
|
||||||
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL) {
|
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL)
|
||||||
return;
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_current_type () == view_listing) {
|
if (get_current_type () == view_listing)
|
||||||
n2vfs = vfs_get_class (current_panel->cwd);
|
{
|
||||||
n2vfsid = vfs_getid (n2vfs, current_panel->cwd);
|
n2vfs = vfs_get_class (current_panel->cwd);
|
||||||
if (n2vfs == oldvfs && n2vfsid == oldvfsid)
|
n2vfsid = vfs_getid (n2vfs, current_panel->cwd);
|
||||||
return;
|
if (n2vfs == oldvfs && n2vfsid == oldvfsid)
|
||||||
} else {
|
return;
|
||||||
n2vfs = NULL;
|
}
|
||||||
n2vfsid = NULL;
|
else
|
||||||
|
{
|
||||||
|
n2vfs = NULL;
|
||||||
|
n2vfsid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_other_type () == view_listing) {
|
if (get_other_type () == view_listing)
|
||||||
n3vfs = vfs_get_class (other_panel->cwd);
|
{
|
||||||
n3vfsid = vfs_getid (n3vfs, other_panel->cwd);
|
n3vfs = vfs_get_class (other_panel->cwd);
|
||||||
if (n3vfs == oldvfs && n3vfsid == oldvfsid)
|
n3vfsid = vfs_getid (n3vfs, other_panel->cwd);
|
||||||
return;
|
if (n3vfs == oldvfs && n3vfsid == oldvfsid)
|
||||||
} else {
|
return;
|
||||||
n3vfs = NULL;
|
}
|
||||||
n3vfsid = NULL;
|
else
|
||||||
|
{
|
||||||
|
n3vfs = NULL;
|
||||||
|
n3vfsid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid))
|
if (!oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
vfs_addstamp (oldvfs, oldvfsid);
|
vfs_addstamp (oldvfs, oldvfsid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compare two timeval structures. Return 0 is t1 is less than t2. */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
static inline int
|
/** This is called from timeout handler with now = 0, or can be called
|
||||||
timeoutcmp (struct timeval *t1, struct timeval *t2)
|
|
||||||
{
|
|
||||||
return ((t1->tv_sec < t2->tv_sec)
|
|
||||||
|| ((t1->tv_sec == t2->tv_sec)
|
|
||||||
&& (t1->tv_usec <= t2->tv_usec)));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* This is called from timeout handler with now = 0, or can be called
|
|
||||||
with now = 1 to force freeing all filesystems that are not in use */
|
with now = 1 to force freeing all filesystems that are not in use */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_expire (int now)
|
vfs_expire (int now)
|
||||||
{
|
{
|
||||||
@ -206,37 +242,42 @@ vfs_expire (int now)
|
|||||||
/* Avoid recursive invocation, e.g. when one of the free functions
|
/* Avoid recursive invocation, e.g. when one of the free functions
|
||||||
calls message */
|
calls message */
|
||||||
if (locked)
|
if (locked)
|
||||||
return;
|
return;
|
||||||
locked = 1;
|
locked = 1;
|
||||||
|
|
||||||
gettimeofday (&lc_time, NULL);
|
gettimeofday (&lc_time, NULL);
|
||||||
lc_time.tv_sec -= vfs_timeout;
|
lc_time.tv_sec -= vfs_timeout;
|
||||||
|
|
||||||
for (stamp = stamps; stamp != NULL;) {
|
for (stamp = stamps; stamp != NULL;)
|
||||||
if (now || (timeoutcmp (&stamp->time, &lc_time))) {
|
{
|
||||||
st = stamp->next;
|
if (now || (timeoutcmp (&stamp->time, &lc_time)))
|
||||||
if (stamp->v->free)
|
{
|
||||||
(*stamp->v->free) (stamp->id);
|
st = stamp->next;
|
||||||
vfs_rmstamp (stamp->v, stamp->id);
|
if (stamp->v->free)
|
||||||
stamp = st;
|
(*stamp->v->free) (stamp->id);
|
||||||
} else
|
vfs_rmstamp (stamp->v, stamp->id);
|
||||||
stamp = stamp->next;
|
stamp = st;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
stamp = stamp->next;
|
||||||
}
|
}
|
||||||
locked = 0;
|
locked = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*
|
/*
|
||||||
* Return the number of seconds remaining to the vfs timeout.
|
* Return the number of seconds remaining to the vfs timeout.
|
||||||
* FIXME: The code should be improved to actually return the number of
|
* FIXME: The code should be improved to actually return the number of
|
||||||
* seconds until the next item times out.
|
* seconds until the next item times out.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
vfs_timeouts ()
|
vfs_timeouts ()
|
||||||
{
|
{
|
||||||
return stamps ? 10 : 0;
|
return stamps ? 10 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_timeout_handler (void)
|
vfs_timeout_handler (void)
|
||||||
@ -244,6 +285,7 @@ vfs_timeout_handler (void)
|
|||||||
vfs_expire (0);
|
vfs_expire (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_release_path (const char *dir)
|
vfs_release_path (const char *dir)
|
||||||
@ -256,21 +298,25 @@ vfs_release_path (const char *dir)
|
|||||||
vfs_stamp_create (oldvfs, oldvfsid);
|
vfs_stamp_create (oldvfs, oldvfsid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/* Free all data */
|
/* Free all data */
|
||||||
|
|
||||||
void
|
void
|
||||||
vfs_gc_done (void)
|
vfs_gc_done (void)
|
||||||
{
|
{
|
||||||
struct vfs_stamping *stamp, *st;
|
struct vfs_stamping *stamp, *st;
|
||||||
|
|
||||||
for (stamp = stamps, stamps = 0; stamp != NULL;) {
|
for (stamp = stamps, stamps = 0; stamp != NULL;)
|
||||||
if (stamp->v->free)
|
{
|
||||||
(*stamp->v->free) (stamp->id);
|
if (stamp->v->free)
|
||||||
st = stamp->next;
|
(*stamp->v->free) (stamp->id);
|
||||||
g_free (stamp);
|
st = stamp->next;
|
||||||
stamp = st;
|
g_free (stamp);
|
||||||
|
stamp = st;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stamps)
|
if (stamps)
|
||||||
vfs_rmstamp (stamps->v, stamps->id);
|
vfs_rmstamp (stamps->v, stamps->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief Header: Virtual File System: garbage collection code
|
* \brief Header: Virtual File System: garbage collection code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_GC_H
|
#ifndef MC__VFS_GC_H
|
||||||
#define MC_VFS_GC_H
|
#define MC__VFS_GC_H
|
||||||
|
|
||||||
#include "vfs-impl.h"
|
#include "vfs-impl.h"
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
struct vfs_stamping
|
struct vfs_stamping
|
||||||
{
|
{
|
||||||
struct vfs_class *v;
|
struct vfs_class *v;
|
||||||
@ -17,10 +22,15 @@ struct vfs_stamping
|
|||||||
struct timeval time;
|
struct timeval time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
void vfs_stamp (struct vfs_class *vclass, vfsid id);
|
void vfs_stamp (struct vfs_class *vclass, vfsid id);
|
||||||
void vfs_rmstamp (struct vfs_class *vclass, vfsid id);
|
void vfs_rmstamp (struct vfs_class *vclass, vfsid id);
|
||||||
void vfs_stamp_create (struct vfs_class *vclass, vfsid id);
|
void vfs_stamp_create (struct vfs_class *vclass, vfsid id);
|
||||||
vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
|
vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
|
||||||
void vfs_gc_done (void);
|
void vfs_gc_done (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_VFS_GC_H */
|
#endif /* MC_VFS_GC_H */
|
||||||
|
@ -19,13 +19,27 @@
|
|||||||
|
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
static struct vfs_class vfs_local_ops;
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: Some of this functions are not static. This has rather good
|
* Note: Some of this functions are not static. This has rather good
|
||||||
* reason: exactly same functions would have to appear in sfs.c. This
|
* reason: exactly same functions would have to appear in sfs.c. This
|
||||||
* saves both computer's memory and my work. <pavel@ucw.cz>
|
* saves both computer's memory and my work. <pavel@ucw.cz>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct vfs_class vfs_local_ops;
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
||||||
@ -37,7 +51,7 @@ local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
|||||||
|
|
||||||
fd = open (file, NO_LINEAR (flags), mode);
|
fd = open (file, NO_LINEAR (flags), mode);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
local_info = g_new (int, 1);
|
local_info = g_new (int, 1);
|
||||||
*local_info = fd;
|
*local_info = fd;
|
||||||
@ -45,45 +59,7 @@ local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
|||||||
return local_info;
|
return local_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
local_read (void *data, char *buffer, size_t count)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
if (!data)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
while ((n = read (*((int *) data), buffer, count)) == -1){
|
|
||||||
#ifdef EAGAIN
|
|
||||||
if (errno == EAGAIN) continue;
|
|
||||||
#endif
|
|
||||||
#ifdef EINTR
|
|
||||||
if (errno == EINTR) continue;
|
|
||||||
#endif
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
local_close (void *data)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (!data)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
fd = *(int *) data;
|
|
||||||
g_free (data);
|
|
||||||
return close (fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
local_errno (struct vfs_class *me)
|
|
||||||
{
|
|
||||||
(void) me;
|
|
||||||
return errno;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
local_opendir (struct vfs_class *me, const char *dirname)
|
local_opendir (struct vfs_class *me, const char *dirname)
|
||||||
@ -95,7 +71,7 @@ local_opendir (struct vfs_class *me, const char *dirname)
|
|||||||
|
|
||||||
dir = opendir (dirname);
|
dir = opendir (dirname);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
local_info = (DIR **) g_new (DIR *, 1);
|
local_info = (DIR **) g_new (DIR *, 1);
|
||||||
*local_info = dir;
|
*local_info = dir;
|
||||||
@ -103,22 +79,28 @@ local_opendir (struct vfs_class *me, const char *dirname)
|
|||||||
return local_info;
|
return local_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
local_readdir (void *data)
|
local_readdir (void *data)
|
||||||
{
|
{
|
||||||
return readdir (*(DIR **) data);
|
return readdir (*(DIR **) data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_closedir (void *data)
|
local_closedir (void *data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = closedir (* (DIR **) data);
|
i = closedir (*(DIR **) data);
|
||||||
g_free (data);
|
g_free (data);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
local_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
@ -127,24 +109,21 @@ local_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
|||||||
return stat (path, buf);
|
return stat (path, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
(void) me;
|
(void) me;
|
||||||
|
|
||||||
#ifndef HAVE_STATLSTAT
|
#ifndef HAVE_STATLSTAT
|
||||||
return lstat (path,buf);
|
return lstat (path, buf);
|
||||||
#else
|
#else
|
||||||
return statlstat (path, buf);
|
return statlstat (path, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
local_fstat (void *data, struct stat *buf)
|
|
||||||
{
|
|
||||||
/* FIXME: avoid type cast */
|
|
||||||
return fstat (*((int *) data), buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_chmod (struct vfs_class *me, const char *path, int mode)
|
local_chmod (struct vfs_class *me, const char *path, int mode)
|
||||||
@ -154,6 +133,8 @@ local_chmod (struct vfs_class *me, const char *path, int mode)
|
|||||||
return chmod (path, mode);
|
return chmod (path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
local_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
@ -162,6 +143,8 @@ local_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
|||||||
return chown (path, owner, group);
|
return chown (path, owner, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
||||||
{
|
{
|
||||||
@ -170,6 +153,8 @@ local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
|||||||
return utime (path, times);
|
return utime (path, times);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
@ -178,6 +163,8 @@ local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
|||||||
return readlink (path, buf, size);
|
return readlink (path, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_unlink (struct vfs_class *me, const char *path)
|
local_unlink (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -186,6 +173,8 @@ local_unlink (struct vfs_class *me, const char *path)
|
|||||||
return unlink (path);
|
return unlink (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_symlink (struct vfs_class *me, const char *n1, const char *n2)
|
local_symlink (struct vfs_class *me, const char *n1, const char *n2)
|
||||||
{
|
{
|
||||||
@ -194,6 +183,8 @@ local_symlink (struct vfs_class *me, const char *n1, const char *n2)
|
|||||||
return symlink (n1, n2);
|
return symlink (n1, n2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
local_write (void *data, const char *buf, size_t nbyte)
|
local_write (void *data, const char *buf, size_t nbyte)
|
||||||
{
|
{
|
||||||
@ -201,21 +192,26 @@ local_write (void *data, const char *buf, size_t nbyte)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fd = * (int *) data;
|
fd = *(int *) data;
|
||||||
while ((n = write (fd, buf, nbyte)) == -1){
|
while ((n = write (fd, buf, nbyte)) == -1)
|
||||||
|
{
|
||||||
#ifdef EAGAIN
|
#ifdef EAGAIN
|
||||||
if (errno == EAGAIN) continue;
|
if (errno == EAGAIN)
|
||||||
|
continue;
|
||||||
#endif
|
#endif
|
||||||
#ifdef EINTR
|
#ifdef EINTR
|
||||||
if (errno == EINTR) continue;
|
if (errno == EINTR)
|
||||||
|
continue;
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_rename (struct vfs_class *me, const char *a, const char *b)
|
local_rename (struct vfs_class *me, const char *a, const char *b)
|
||||||
{
|
{
|
||||||
@ -224,6 +220,8 @@ local_rename (struct vfs_class *me, const char *a, const char *b)
|
|||||||
return rename (a, b);
|
return rename (a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_chdir (struct vfs_class *me, const char *path)
|
local_chdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -232,13 +230,7 @@ local_chdir (struct vfs_class *me, const char *path)
|
|||||||
return chdir (path);
|
return chdir (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
local_lseek (void *data, off_t offset, int whence)
|
|
||||||
{
|
|
||||||
int fd = * (int *) data;
|
|
||||||
|
|
||||||
return lseek (fd, offset, whence);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_mknod (struct vfs_class *me, const char *path, mode_t mode, dev_t dev)
|
local_mknod (struct vfs_class *me, const char *path, mode_t mode, dev_t dev)
|
||||||
@ -248,6 +240,8 @@ local_mknod (struct vfs_class *me, const char *path, mode_t mode, dev_t dev)
|
|||||||
return mknod (path, mode, dev);
|
return mknod (path, mode, dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_link (struct vfs_class *me, const char *p1, const char *p2)
|
local_link (struct vfs_class *me, const char *p1, const char *p2)
|
||||||
{
|
{
|
||||||
@ -256,6 +250,8 @@ local_link (struct vfs_class *me, const char *p1, const char *p2)
|
|||||||
return link (p1, p2);
|
return link (p1, p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -264,6 +260,8 @@ local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
|||||||
return mkdir (path, mode);
|
return mkdir (path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_rmdir (struct vfs_class *me, const char *path)
|
local_rmdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -272,6 +270,8 @@ local_rmdir (struct vfs_class *me, const char *path)
|
|||||||
return rmdir (path);
|
return rmdir (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
local_getlocalcopy (struct vfs_class *me, const char *path)
|
local_getlocalcopy (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -280,9 +280,10 @@ local_getlocalcopy (struct vfs_class *me, const char *path)
|
|||||||
return g_strdup (path);
|
return g_strdup (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_ungetlocalcopy (struct vfs_class *me, const char *path,
|
local_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
||||||
const char *local, int has_changed)
|
|
||||||
{
|
{
|
||||||
(void) me;
|
(void) me;
|
||||||
(void) path;
|
(void) path;
|
||||||
@ -292,15 +293,89 @@ local_ungetlocalcopy (struct vfs_class *me, const char *path,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
local_which (struct vfs_class *me, const char *path)
|
local_which (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
(void) me;
|
(void) me;
|
||||||
(void) path;
|
(void) path;
|
||||||
|
|
||||||
return 0; /* Every path which other systems do not like is expected to be ours */
|
return 0; /* Every path which other systems do not like is expected to be ours */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
ssize_t
|
||||||
|
local_read (void *data, char *buffer, size_t count)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
while ((n = read (*((int *) data), buffer, count)) == -1)
|
||||||
|
{
|
||||||
|
#ifdef EAGAIN
|
||||||
|
if (errno == EAGAIN)
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
#ifdef EINTR
|
||||||
|
if (errno == EINTR)
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int
|
||||||
|
local_close (void *data)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (!data)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fd = *(int *) data;
|
||||||
|
g_free (data);
|
||||||
|
return close (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int
|
||||||
|
local_errno (struct vfs_class *me)
|
||||||
|
{
|
||||||
|
(void) me;
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
int
|
||||||
|
local_fstat (void *data, struct stat *buf)
|
||||||
|
{
|
||||||
|
/* FIXME: avoid type cast */
|
||||||
|
return fstat (*((int *) data), buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
off_t
|
||||||
|
local_lseek (void *data, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
int fd = *(int *) data;
|
||||||
|
|
||||||
|
return lseek (fd, offset, whence);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_localfs (void)
|
init_localfs (void)
|
||||||
{
|
{
|
||||||
@ -335,3 +410,5 @@ init_localfs (void)
|
|||||||
vfs_local_ops.rmdir = local_rmdir;
|
vfs_local_ops.rmdir = local_rmdir;
|
||||||
vfs_register_class (&vfs_local_ops);
|
vfs_register_class (&vfs_local_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \file
|
* \file
|
||||||
* \brief Header: local FS
|
* \brief Header: local FS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_LOCAL_H
|
#ifndef MC__VFS_LOCAL_H
|
||||||
#define MC_VFS_LOCAL_H
|
#define MC__VFS_LOCAL_H
|
||||||
|
|
||||||
#include "vfs-impl.h"
|
#include "vfs-impl.h"
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
extern void init_localfs (void);
|
extern void init_localfs (void);
|
||||||
|
|
||||||
/* these functions are used by other filesystems, so they are
|
/* these functions are used by other filesystems, so they are
|
||||||
@ -19,4 +28,5 @@ extern int local_fstat (void *data, struct stat *buf);
|
|||||||
extern int local_errno (struct vfs_class *me);
|
extern int local_errno (struct vfs_class *me);
|
||||||
extern off_t local_lseek (void *data, off_t offset, int whence);
|
extern off_t local_lseek (void *data, off_t offset, int whence);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,8 +31,19 @@
|
|||||||
|
|
||||||
#include "netutil.h"
|
#include "netutil.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
volatile sig_atomic_t got_sigpipe = 0;
|
volatile sig_atomic_t got_sigpipe = 0;
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sig_pipe (int unused)
|
sig_pipe (int unused)
|
||||||
{
|
{
|
||||||
@ -40,6 +51,10 @@ sig_pipe (int unused)
|
|||||||
got_sigpipe = 1;
|
got_sigpipe = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
tcp_init (void)
|
tcp_init (void)
|
||||||
{
|
{
|
||||||
@ -57,3 +72,5 @@ tcp_init (void)
|
|||||||
|
|
||||||
initialized = TRUE;
|
initialized = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -4,12 +4,23 @@
|
|||||||
* \brief Header: Virtual File System: Network utilities
|
* \brief Header: Virtual File System: Network utilities
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_NETUTIL_H
|
#ifndef MC__VFS_NETUTIL_H
|
||||||
#define MC_VFS_NETUTIL_H
|
#define MC__VFS_NETUTIL_H
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern volatile sig_atomic_t got_sigpipe;
|
extern volatile sig_atomic_t got_sigpipe;
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
void tcp_init (void);
|
void tcp_init (void);
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_VFS_NETUTIL_H */
|
#endif /* MC_VFS_NETUTIL_H */
|
||||||
|
@ -43,33 +43,64 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
#include "src/wtools.h" /* D_ERROR, D_NORMAL */
|
#include "src/wtools.h" /* D_ERROR, D_NORMAL */
|
||||||
#include "src/main.h" /* mc_home */
|
#include "src/main.h" /* mc_home */
|
||||||
#include "src/execute.h" /* EXECUTE_AS_SHELL */
|
#include "src/execute.h" /* EXECUTE_AS_SHELL */
|
||||||
|
|
||||||
#include "vfs-impl.h"
|
#include "vfs-impl.h"
|
||||||
#include "utilvfs.h"
|
#include "utilvfs.h"
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
#include "gc.h" /* vfs_stamp_create */
|
#include "gc.h" /* vfs_stamp_create */
|
||||||
|
|
||||||
struct cachedfile {
|
/*** global variables ****************************************************************************/
|
||||||
char *name, *cache;
|
|
||||||
struct cachedfile *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct cachedfile *head;
|
/*** file scope macro definitions ****************************************************************/
|
||||||
static struct vfs_class vfs_sfs_ops;
|
|
||||||
|
|
||||||
#define MAXFS 32
|
#define MAXFS 32
|
||||||
static int sfs_no = 0;
|
|
||||||
static char *sfs_prefix[ MAXFS ];
|
|
||||||
static char *sfs_command[ MAXFS ];
|
|
||||||
static int sfs_flags[ MAXFS ];
|
|
||||||
#define F_1 1
|
#define F_1 1
|
||||||
#define F_2 2
|
#define F_2 2
|
||||||
#define F_NOLOCALCOPY 4
|
#define F_NOLOCALCOPY 4
|
||||||
#define F_FULLMATCH 8
|
#define F_FULLMATCH 8
|
||||||
|
|
||||||
|
#define COPY_CHAR \
|
||||||
|
if ((size_t) (t-pad) > sizeof(pad)) { \
|
||||||
|
g_free (pqname); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
*t++ = *s;
|
||||||
|
|
||||||
|
#define COPY_STRING(a) \
|
||||||
|
if ((t-pad)+strlen(a)>sizeof(pad)) { \
|
||||||
|
g_free (pqname); \
|
||||||
|
return -1; \
|
||||||
|
} else { \
|
||||||
|
strcpy (t, a); \
|
||||||
|
t+= strlen(a); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
|
struct cachedfile
|
||||||
|
{
|
||||||
|
char *name, *cache;
|
||||||
|
struct cachedfile *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
|
static struct cachedfile *head;
|
||||||
|
static struct vfs_class vfs_sfs_ops;
|
||||||
|
|
||||||
|
static int sfs_no = 0;
|
||||||
|
static char *sfs_prefix[MAXFS];
|
||||||
|
static char *sfs_command[MAXFS];
|
||||||
|
static int sfs_flags[MAXFS];
|
||||||
|
|
||||||
|
/*** file scope functions ************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||||
{
|
{
|
||||||
@ -78,91 +109,88 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
|||||||
char pad[10240];
|
char pad[10240];
|
||||||
char *s, *t = pad;
|
char *s, *t = pad;
|
||||||
int was_percent = 0;
|
int was_percent = 0;
|
||||||
char *pname; /* name of parent archive */
|
char *pname; /* name of parent archive */
|
||||||
char *pqname; /* name of parent archive, quoted */
|
char *pqname; /* name of parent archive, quoted */
|
||||||
|
|
||||||
pname = g_strdup (name);
|
pname = g_strdup (name);
|
||||||
vfs_split (pname, &inpath, &op);
|
vfs_split (pname, &inpath, &op);
|
||||||
w = (*me->which) (me, op);
|
w = (*me->which) (me, op);
|
||||||
if (w == -1)
|
if (w == -1)
|
||||||
vfs_die ("This cannot happen... Hopefully.\n");
|
vfs_die ("This cannot happen... Hopefully.\n");
|
||||||
|
|
||||||
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/")) {
|
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/"))
|
||||||
g_free (pname);
|
{
|
||||||
return -1;
|
g_free (pname);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */
|
/* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */
|
||||||
if (!(sfs_flags[w] & F_NOLOCALCOPY)) {
|
if (!(sfs_flags[w] & F_NOLOCALCOPY))
|
||||||
s = mc_getlocalcopy (pname);
|
{
|
||||||
if (!s) {
|
s = mc_getlocalcopy (pname);
|
||||||
g_free (pname);
|
if (!s)
|
||||||
return -1;
|
{
|
||||||
}
|
g_free (pname);
|
||||||
pqname = name_quote (s, 0);
|
return -1;
|
||||||
g_free (s);
|
}
|
||||||
} else {
|
pqname = name_quote (s, 0);
|
||||||
pqname = name_quote (pname, 0);
|
g_free (s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pqname = name_quote (pname, 0);
|
||||||
}
|
}
|
||||||
g_free (pname);
|
g_free (pname);
|
||||||
|
|
||||||
#define COPY_CHAR \
|
|
||||||
if ((size_t) (t-pad) > sizeof(pad)) { \
|
|
||||||
g_free (pqname); \
|
|
||||||
return -1; \
|
|
||||||
} \
|
|
||||||
else \
|
|
||||||
*t++ = *s;
|
|
||||||
|
|
||||||
#define COPY_STRING(a) \
|
for (s = sfs_command[w]; *s; s++)
|
||||||
if ((t-pad)+strlen(a)>sizeof(pad)) { \
|
{
|
||||||
g_free (pqname); \
|
if (was_percent)
|
||||||
return -1; \
|
{
|
||||||
} else { \
|
|
||||||
strcpy (t, a); \
|
|
||||||
t+= strlen(a); \
|
|
||||||
}
|
|
||||||
|
|
||||||
for (s = sfs_command[w]; *s; s++) {
|
const char *ptr = NULL;
|
||||||
if (was_percent) {
|
was_percent = 0;
|
||||||
|
|
||||||
const char *ptr = NULL;
|
switch (*s)
|
||||||
was_percent = 0;
|
{
|
||||||
|
case '1':
|
||||||
switch (*s) {
|
ptr = pqname;
|
||||||
case '1':
|
break;
|
||||||
ptr = pqname;
|
case '2':
|
||||||
break;
|
ptr = op + strlen (sfs_prefix[w]);
|
||||||
case '2':
|
break;
|
||||||
ptr = op + strlen (sfs_prefix[w]);
|
case '3':
|
||||||
break;
|
ptr = cache;
|
||||||
case '3':
|
break;
|
||||||
ptr = cache;
|
case '%':
|
||||||
break;
|
COPY_CHAR;
|
||||||
case '%':
|
continue;
|
||||||
COPY_CHAR;
|
}
|
||||||
continue;
|
COPY_STRING (ptr);
|
||||||
}
|
}
|
||||||
COPY_STRING (ptr);
|
else
|
||||||
} else {
|
{
|
||||||
if (*s == '%')
|
if (*s == '%')
|
||||||
was_percent = 1;
|
was_percent = 1;
|
||||||
else
|
else
|
||||||
COPY_CHAR;
|
COPY_CHAR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (pqname);
|
g_free (pqname);
|
||||||
open_error_pipe ();
|
open_error_pipe ();
|
||||||
if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad)) {
|
if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad))
|
||||||
close_error_pipe (D_ERROR, NULL);
|
{
|
||||||
return -1;
|
close_error_pipe (D_ERROR, NULL);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
close_error_pipe (D_NORMAL, NULL);
|
close_error_pipe (D_NORMAL, NULL);
|
||||||
return 0; /* OK */
|
return 0; /* OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
sfs_redirect (struct vfs_class *me, const char *name)
|
sfs_redirect (struct vfs_class *me, const char *name)
|
||||||
{
|
{
|
||||||
@ -170,32 +198,36 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
|||||||
char *cache;
|
char *cache;
|
||||||
int handle;
|
int handle;
|
||||||
|
|
||||||
while (cur) {
|
while (cur)
|
||||||
if (!strcmp (name, cur->name)) {
|
{
|
||||||
vfs_stamp (&vfs_sfs_ops, cur);
|
if (!strcmp (name, cur->name))
|
||||||
return cur->cache;
|
{
|
||||||
}
|
vfs_stamp (&vfs_sfs_ops, cur);
|
||||||
cur = cur->next;
|
return cur->cache;
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
handle = vfs_mkstemps (&cache, "sfs", name);
|
handle = vfs_mkstemps (&cache, "sfs", name);
|
||||||
|
|
||||||
if (handle == -1) {
|
if (handle == -1)
|
||||||
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
|
{
|
||||||
|
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
|
||||||
}
|
}
|
||||||
|
|
||||||
close (handle);
|
close (handle);
|
||||||
|
|
||||||
if (!sfs_vfmake (me, name, cache)) {
|
if (!sfs_vfmake (me, name, cache))
|
||||||
cur = g_new (struct cachedfile, 1);
|
{
|
||||||
cur->name = g_strdup (name);
|
cur = g_new (struct cachedfile, 1);
|
||||||
cur->cache = cache;
|
cur->name = g_strdup (name);
|
||||||
cur->next = head;
|
cur->cache = cache;
|
||||||
head = cur;
|
cur->next = head;
|
||||||
|
head = cur;
|
||||||
|
|
||||||
vfs_stamp_create (&vfs_sfs_ops, head);
|
vfs_stamp_create (&vfs_sfs_ops, head);
|
||||||
|
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink (cache);
|
unlink (cache);
|
||||||
@ -203,6 +235,8 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
|||||||
return "/I_MUST_NOT_EXIST";
|
return "/I_MUST_NOT_EXIST";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -212,7 +246,7 @@ sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
|||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
fd = open (path, NO_LINEAR (flags), mode);
|
fd = open (path, NO_LINEAR (flags), mode);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
sfs_info = g_new (int, 1);
|
sfs_info = g_new (int, 1);
|
||||||
*sfs_info = fd;
|
*sfs_info = fd;
|
||||||
@ -220,13 +254,19 @@ sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
|||||||
return sfs_info;
|
return sfs_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
return stat (path, buf);
|
return stat (path, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
#ifndef HAVE_STATLSTAT
|
#ifndef HAVE_STATLSTAT
|
||||||
@ -236,24 +276,35 @@ static int sfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_chmod (struct vfs_class *me, const char *path, int mode)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_chmod (struct vfs_class *me, const char *path, int mode)
|
||||||
{
|
{
|
||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
return chmod (path, mode);
|
return chmod (path, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||||
{
|
{
|
||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
return chown (path, owner, group);
|
return chown (path, owner, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
||||||
{
|
{
|
||||||
path = sfs_redirect (me, path);
|
path = sfs_redirect (me, path);
|
||||||
return utime (path, times);
|
return utime (path, times);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
sfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
||||||
{
|
{
|
||||||
@ -261,6 +312,8 @@ sfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
|||||||
return readlink (path, buf, size);
|
return readlink (path, buf, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static vfsid
|
static vfsid
|
||||||
sfs_getid (struct vfs_class *me, const char *path)
|
sfs_getid (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -268,49 +321,60 @@ sfs_getid (struct vfs_class *me, const char *path)
|
|||||||
|
|
||||||
(void) me;
|
(void) me;
|
||||||
|
|
||||||
while (cur) {
|
while (cur)
|
||||||
if (!strcmp (path, cur->name))
|
{
|
||||||
break;
|
if (!strcmp (path, cur->name))
|
||||||
cur = cur->next;
|
break;
|
||||||
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (vfsid) cur;
|
return (vfsid) cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sfs_free (vfsid id)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
sfs_free (vfsid id)
|
||||||
{
|
{
|
||||||
struct cachedfile *which = (struct cachedfile *) id;
|
struct cachedfile *which = (struct cachedfile *) id;
|
||||||
struct cachedfile *cur, *prev;
|
struct cachedfile *cur, *prev;
|
||||||
|
|
||||||
for (cur = head, prev = 0; cur && cur != which; prev = cur, cur = cur->next)
|
for (cur = head, prev = 0; cur && cur != which; prev = cur, cur = cur->next)
|
||||||
;
|
;
|
||||||
if (!cur)
|
if (!cur)
|
||||||
vfs_die( "Free of thing which is unknown to me\n" );
|
vfs_die ("Free of thing which is unknown to me\n");
|
||||||
unlink (cur->cache);
|
unlink (cur->cache);
|
||||||
|
|
||||||
if (prev)
|
if (prev)
|
||||||
prev->next = cur->next;
|
prev->next = cur->next;
|
||||||
else
|
else
|
||||||
head = cur->next;
|
head = cur->next;
|
||||||
|
|
||||||
g_free (cur->cache);
|
g_free (cur->cache);
|
||||||
g_free (cur->name);
|
g_free (cur->name);
|
||||||
g_free (cur);
|
g_free (cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sfs_fill_names (struct vfs_class *me, fill_names_f func)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
sfs_fill_names (struct vfs_class *me, fill_names_f func)
|
||||||
{
|
{
|
||||||
struct cachedfile *cur = head;
|
struct cachedfile *cur = head;
|
||||||
|
|
||||||
(void) me;
|
(void) me;
|
||||||
|
|
||||||
while (cur){
|
while (cur)
|
||||||
(*func)(cur->name);
|
{
|
||||||
cur = cur->next;
|
(*func) (cur->name);
|
||||||
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_nothingisopen (vfsid id)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_nothingisopen (vfsid id)
|
||||||
{
|
{
|
||||||
/* FIXME: Investigate whether have to guard this like in
|
/* FIXME: Investigate whether have to guard this like in
|
||||||
the other VFSs (see fd_usage in extfs) -- Norbert */
|
the other VFSs (see fd_usage in extfs) -- Norbert */
|
||||||
@ -318,6 +382,8 @@ static int sfs_nothingisopen (vfsid id)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
sfs_getlocalcopy (struct vfs_class *me, const char *path)
|
sfs_getlocalcopy (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -325,9 +391,10 @@ sfs_getlocalcopy (struct vfs_class *me, const char *path)
|
|||||||
return g_strdup (path);
|
return g_strdup (path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sfs_ungetlocalcopy (struct vfs_class *me, const char *path,
|
sfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
||||||
const char *local, int has_changed)
|
|
||||||
{
|
{
|
||||||
(void) me;
|
(void) me;
|
||||||
(void) path;
|
(void) path;
|
||||||
@ -336,7 +403,10 @@ sfs_ungetlocalcopy (struct vfs_class *me, const char *path,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sfs_init (struct vfs_class *me)
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
static int
|
||||||
|
sfs_init (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
char *mc_sfsini;
|
char *mc_sfsini;
|
||||||
FILE *cfg;
|
FILE *cfg;
|
||||||
@ -347,67 +417,80 @@ static int sfs_init (struct vfs_class *me)
|
|||||||
mc_sfsini = g_build_filename (mc_home, "sfs.ini", (char *) NULL);
|
mc_sfsini = g_build_filename (mc_home, "sfs.ini", (char *) NULL);
|
||||||
cfg = fopen (mc_sfsini, "r");
|
cfg = fopen (mc_sfsini, "r");
|
||||||
|
|
||||||
if (cfg == NULL) {
|
if (cfg == NULL)
|
||||||
fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini);
|
{
|
||||||
g_free (mc_sfsini);
|
fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini);
|
||||||
return 0;
|
g_free (mc_sfsini);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
g_free (mc_sfsini);
|
g_free (mc_sfsini);
|
||||||
|
|
||||||
sfs_no = 0;
|
sfs_no = 0;
|
||||||
while (sfs_no < MAXFS && fgets (key, sizeof (key), cfg)) {
|
while (sfs_no < MAXFS && fgets (key, sizeof (key), cfg))
|
||||||
char *c, *semi = NULL, flags = 0;
|
{
|
||||||
|
char *c, *semi = NULL, flags = 0;
|
||||||
|
|
||||||
if (*key == '#' || *key == '\n')
|
if (*key == '#' || *key == '\n')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (c = key; *c; c++)
|
for (c = key; *c; c++)
|
||||||
if ((*c == ':') || (*c == '/')){
|
if ((*c == ':') || (*c == '/'))
|
||||||
semi = c;
|
{
|
||||||
if (*c == '/'){
|
semi = c;
|
||||||
*c = 0;
|
if (*c == '/')
|
||||||
flags |= F_FULLMATCH;
|
{
|
||||||
}
|
*c = 0;
|
||||||
break;
|
flags |= F_FULLMATCH;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!semi){
|
if (!semi)
|
||||||
invalid_line:
|
{
|
||||||
fprintf (stderr, _("Warning: Invalid line in %s:\n%s\n"),
|
invalid_line:
|
||||||
"sfs.ini", key);
|
fprintf (stderr, _("Warning: Invalid line in %s:\n%s\n"), "sfs.ini", key);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = semi + 1;
|
c = semi + 1;
|
||||||
while (*c && (*c != ' ') && (*c != '\t')) {
|
while (*c && (*c != ' ') && (*c != '\t'))
|
||||||
switch (*c) {
|
{
|
||||||
case '1': flags |= F_1; break;
|
switch (*c)
|
||||||
case '2': flags |= F_2; break;
|
{
|
||||||
case 'R': flags |= F_NOLOCALCOPY; break;
|
case '1':
|
||||||
default:
|
flags |= F_1;
|
||||||
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"),
|
break;
|
||||||
*c, "sfs.ini", key);
|
case '2':
|
||||||
}
|
flags |= F_2;
|
||||||
c++;
|
break;
|
||||||
}
|
case 'R':
|
||||||
if (!*c)
|
flags |= F_NOLOCALCOPY;
|
||||||
goto invalid_line;
|
break;
|
||||||
|
default:
|
||||||
|
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"), *c, "sfs.ini", key);
|
||||||
|
}
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
if (!*c)
|
||||||
|
goto invalid_line;
|
||||||
|
|
||||||
c++;
|
c++;
|
||||||
*(semi+1) = 0;
|
*(semi + 1) = 0;
|
||||||
semi = strchr (c, '\n');
|
semi = strchr (c, '\n');
|
||||||
if (semi != NULL)
|
if (semi != NULL)
|
||||||
*semi = 0;
|
*semi = 0;
|
||||||
|
|
||||||
sfs_prefix [sfs_no] = g_strdup (key);
|
sfs_prefix[sfs_no] = g_strdup (key);
|
||||||
sfs_command [sfs_no] = g_strdup (c);
|
sfs_command[sfs_no] = g_strdup (c);
|
||||||
sfs_flags [sfs_no] = flags;
|
sfs_flags[sfs_no] = flags;
|
||||||
sfs_no++;
|
sfs_no++;
|
||||||
}
|
}
|
||||||
fclose (cfg);
|
fclose (cfg);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sfs_done (struct vfs_class *me)
|
sfs_done (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
@ -415,14 +498,17 @@ sfs_done (struct vfs_class *me)
|
|||||||
|
|
||||||
(void) me;
|
(void) me;
|
||||||
|
|
||||||
for (i = 0; i < sfs_no; i++){
|
for (i = 0; i < sfs_no; i++)
|
||||||
g_free (sfs_prefix [i]);
|
{
|
||||||
g_free (sfs_command [i]);
|
g_free (sfs_prefix[i]);
|
||||||
sfs_prefix [i] = sfs_command [i] = NULL;
|
g_free (sfs_command[i]);
|
||||||
|
sfs_prefix[i] = sfs_command[i] = NULL;
|
||||||
}
|
}
|
||||||
sfs_no = 0;
|
sfs_no = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sfs_which (struct vfs_class *me, const char *path)
|
sfs_which (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -431,16 +517,21 @@ sfs_which (struct vfs_class *me, const char *path)
|
|||||||
(void) me;
|
(void) me;
|
||||||
|
|
||||||
for (i = 0; i < sfs_no; i++)
|
for (i = 0; i < sfs_no; i++)
|
||||||
if (sfs_flags [i] & F_FULLMATCH) {
|
if (sfs_flags[i] & F_FULLMATCH)
|
||||||
if (!strcmp (path, sfs_prefix [i]))
|
{
|
||||||
return i;
|
if (!strcmp (path, sfs_prefix[i]))
|
||||||
} else
|
return i;
|
||||||
if (!strncmp (path, sfs_prefix [i], strlen (sfs_prefix [i])))
|
}
|
||||||
return i;
|
else if (!strncmp (path, sfs_prefix[i], strlen (sfs_prefix[i])))
|
||||||
|
return i;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_sfs (void)
|
init_sfs (void)
|
||||||
{
|
{
|
||||||
@ -468,3 +559,5 @@ init_sfs (void)
|
|||||||
vfs_sfs_ops.ungetlocalcopy = sfs_ungetlocalcopy;
|
vfs_sfs_ops.ungetlocalcopy = sfs_ungetlocalcopy;
|
||||||
vfs_register_class (&vfs_sfs_ops);
|
vfs_register_class (&vfs_sfs_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -4,12 +4,14 @@
|
|||||||
* \brief Header: Virtual File System: smb file system
|
* \brief Header: Virtual File System: smb file system
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_SMBFS_H
|
#ifndef MC__VFS_SMBFS_H
|
||||||
#define MC_VFS_SMBFS_H
|
#define MC__VFS_SMBFS_H
|
||||||
|
|
||||||
void init_smbfs (void);
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
void smbfs_set_debug (int arg);
|
|
||||||
void smbfs_set_debugf (const char *filename);
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
typedef struct smb_authinfo
|
typedef struct smb_authinfo
|
||||||
{
|
{
|
||||||
@ -20,16 +22,24 @@ typedef struct smb_authinfo
|
|||||||
char *password;
|
char *password;
|
||||||
} smb_authinfo;
|
} smb_authinfo;
|
||||||
|
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void init_smbfs (void);
|
||||||
|
void smbfs_set_debug (int arg);
|
||||||
|
void smbfs_set_debugf (const char *filename);
|
||||||
|
|
||||||
smb_authinfo *vfs_smb_authinfo_new (const char *host,
|
smb_authinfo *vfs_smb_authinfo_new (const char *host,
|
||||||
const char *share,
|
const char *share,
|
||||||
const char *domain,
|
const char *domain, const char *user, const char *pass);
|
||||||
const char *user,
|
|
||||||
const char *pass);
|
|
||||||
|
|
||||||
/* src/boxes.c */
|
/* src/boxes.c */
|
||||||
smb_authinfo *vfs_smb_get_authinfo (const char *host,
|
smb_authinfo *vfs_smb_get_authinfo (const char *host,
|
||||||
const char *share,
|
const char *share, const char *domain, const char *user);
|
||||||
const char *domain,
|
|
||||||
const char *user);
|
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_VFS_SMBFS_H */
|
#endif /* MC_VFS_SMBFS_H */
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -64,6 +64,17 @@
|
|||||||
#include "utilvfs.h"
|
#include "utilvfs.h"
|
||||||
#include "vfs-impl.h"
|
#include "vfs-impl.h"
|
||||||
|
|
||||||
|
/*** global variables ****************************************************************************/
|
||||||
|
|
||||||
|
/*** file scope macro definitions ****************************************************************/
|
||||||
|
|
||||||
|
/* To generate the . and .. entries use -2 */
|
||||||
|
#define READDIR_PTR_INIT 0
|
||||||
|
|
||||||
|
#define undelfs_stat undelfs_lstat
|
||||||
|
|
||||||
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
struct deleted_info
|
struct deleted_info
|
||||||
{
|
{
|
||||||
ext2_ino_t ino;
|
ext2_ino_t ino;
|
||||||
@ -84,6 +95,25 @@ struct lsdel_struct
|
|||||||
int bad_blocks;
|
int bad_blocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int f_index; /* file index into delarray */
|
||||||
|
char *buf;
|
||||||
|
int error_code; /* */
|
||||||
|
off_t pos; /* file position */
|
||||||
|
off_t current; /* used to determine current position in itereate */
|
||||||
|
gboolean finished;
|
||||||
|
ext2_ino_t inode;
|
||||||
|
int bytes_read;
|
||||||
|
off_t size;
|
||||||
|
|
||||||
|
/* Used by undelfs_read: */
|
||||||
|
char *dest_buffer; /* destination buffer */
|
||||||
|
size_t count; /* bytes to read */
|
||||||
|
} undelfs_file;
|
||||||
|
|
||||||
|
/*** file scope variables ************************************************************************/
|
||||||
|
|
||||||
/* We only allow one opened ext2fs */
|
/* We only allow one opened ext2fs */
|
||||||
static char *ext2_fname;
|
static char *ext2_fname;
|
||||||
static ext2_filsys fs = NULL;
|
static ext2_filsys fs = NULL;
|
||||||
@ -96,8 +126,8 @@ static int readdir_ptr;
|
|||||||
static int undelfs_usage;
|
static int undelfs_usage;
|
||||||
static struct vfs_class vfs_undelfs_ops;
|
static struct vfs_class vfs_undelfs_ops;
|
||||||
|
|
||||||
/* To generate the . and .. entries use -2 */
|
/*** file scope functions ************************************************************************/
|
||||||
#define READDIR_PTR_INIT 0
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
undelfs_shutdown (void)
|
undelfs_shutdown (void)
|
||||||
@ -113,6 +143,8 @@ undelfs_shutdown (void)
|
|||||||
block_buf = NULL;
|
block_buf = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
undelfs_get_path (const char *dirname, char **fsname, char **file)
|
undelfs_get_path (const char *dirname, char **fsname, char **file)
|
||||||
{
|
{
|
||||||
@ -162,6 +194,8 @@ undelfs_get_path (const char *dirname, char **fsname, char **file)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_lsdel_proc (ext2_filsys _fs, blk_t * block_nr, int blockcnt, void *private)
|
undelfs_lsdel_proc (ext2_filsys _fs, blk_t * block_nr, int blockcnt, void *private)
|
||||||
{
|
{
|
||||||
@ -181,10 +215,12 @@ undelfs_lsdel_proc (ext2_filsys _fs, blk_t * block_nr, int blockcnt, void *priva
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
* Load information about deleted files.
|
* Load information about deleted files.
|
||||||
* Don't abort if there is not enough memory - load as much as we can.
|
* Don't abort if there is not enough memory - load as much as we can.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_loaddel (void)
|
undelfs_loaddel (void)
|
||||||
{
|
{
|
||||||
@ -291,24 +327,7 @@ undelfs_loaddel (void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
/*
|
|
||||||
* This function overrides com_err() from libcom_err library.
|
|
||||||
* It is used in libext2fs to report errors.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
com_err (const char *whoami, long err_code, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
va_start (ap, fmt);
|
|
||||||
str = g_strdup_vprintf (fmt, ap);
|
|
||||||
va_end (ap);
|
|
||||||
|
|
||||||
message (D_ERROR, _("Ext2lib error"), "%s (%s: %ld)", str, whoami, err_code);
|
|
||||||
g_free (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
undelfs_opendir (struct vfs_class *me, const char *dirname)
|
undelfs_opendir (struct vfs_class *me, const char *dirname)
|
||||||
@ -364,6 +383,7 @@ undelfs_opendir (struct vfs_class *me, const char *dirname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
undelfs_readdir (void *vfs_info)
|
undelfs_readdir (void *vfs_info)
|
||||||
@ -390,6 +410,8 @@ undelfs_readdir (void *vfs_info)
|
|||||||
return &undelfs_readdir_data;
|
return &undelfs_readdir_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_closedir (void *vfs_info)
|
undelfs_closedir (void *vfs_info)
|
||||||
{
|
{
|
||||||
@ -397,24 +419,9 @@ undelfs_closedir (void *vfs_info)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
{
|
|
||||||
int f_index; /* file index into delarray */
|
|
||||||
char *buf;
|
|
||||||
int error_code; /* */
|
|
||||||
off_t pos; /* file position */
|
|
||||||
off_t current; /* used to determine current position in itereate */
|
|
||||||
gboolean finished;
|
|
||||||
ext2_ino_t inode;
|
|
||||||
int bytes_read;
|
|
||||||
off_t size;
|
|
||||||
|
|
||||||
/* Used by undelfs_read: */
|
|
||||||
char *dest_buffer; /* destination buffer */
|
|
||||||
size_t count; /* bytes to read */
|
|
||||||
} undelfs_file;
|
|
||||||
|
|
||||||
/* We do not support lseek */
|
/* We do not support lseek */
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
undelfs_open (struct vfs_class *me, const char *fname, int flags, mode_t mode)
|
undelfs_open (struct vfs_class *me, const char *fname, int flags, mode_t mode)
|
||||||
{
|
{
|
||||||
@ -474,6 +481,8 @@ undelfs_open (struct vfs_class *me, const char *fname, int flags, mode_t mode)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_close (void *vfs_info)
|
undelfs_close (void *vfs_info)
|
||||||
{
|
{
|
||||||
@ -484,6 +493,8 @@ undelfs_close (void *vfs_info)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_dump_read (ext2_filsys param_fs, blk_t * blocknr, int blockcnt, void *private)
|
undelfs_dump_read (ext2_filsys param_fs, blk_t * blocknr, int blockcnt, void *private)
|
||||||
{
|
{
|
||||||
@ -554,6 +565,8 @@ undelfs_dump_read (ext2_filsys param_fs, blk_t * blocknr, int blockcnt, void *pr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static ssize_t
|
static ssize_t
|
||||||
undelfs_read (void *vfs_info, char *buffer, size_t count)
|
undelfs_read (void *vfs_info, char *buffer, size_t count)
|
||||||
{
|
{
|
||||||
@ -581,6 +594,8 @@ undelfs_read (void *vfs_info, char *buffer, size_t count)
|
|||||||
return p->dest_buffer - buffer;
|
return p->dest_buffer - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static long
|
static long
|
||||||
undelfs_getindex (char *path)
|
undelfs_getindex (char *path)
|
||||||
{
|
{
|
||||||
@ -595,6 +610,8 @@ undelfs_getindex (char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_stat_int (int inode_index, struct stat *buf)
|
undelfs_stat_int (int inode_index, struct stat *buf)
|
||||||
{
|
{
|
||||||
@ -611,6 +628,8 @@ undelfs_stat_int (int inode_index, struct stat *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
undelfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||||
{
|
{
|
||||||
@ -652,7 +671,7 @@ undelfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
|||||||
return undelfs_stat_int (inode_index, buf);
|
return undelfs_stat_int (inode_index, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define undelfs_stat undelfs_lstat
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_fstat (void *vfs_info, struct stat *buf)
|
undelfs_fstat (void *vfs_info, struct stat *buf)
|
||||||
@ -662,6 +681,8 @@ undelfs_fstat (void *vfs_info, struct stat *buf)
|
|||||||
return undelfs_stat_int (p->f_index, buf);
|
return undelfs_stat_int (p->f_index, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_chdir (struct vfs_class *me, const char *path)
|
undelfs_chdir (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -690,6 +711,8 @@ undelfs_chdir (struct vfs_class *me, const char *path)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* this has to stay here for now: vfs layer does not know how to emulate it */
|
/* this has to stay here for now: vfs layer does not know how to emulate it */
|
||||||
static off_t
|
static off_t
|
||||||
undelfs_lseek (void *vfs_info, off_t offset, int whence)
|
undelfs_lseek (void *vfs_info, off_t offset, int whence)
|
||||||
@ -701,6 +724,8 @@ undelfs_lseek (void *vfs_info, off_t offset, int whence)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static vfsid
|
static vfsid
|
||||||
undelfs_getid (struct vfs_class *me, const char *path)
|
undelfs_getid (struct vfs_class *me, const char *path)
|
||||||
{
|
{
|
||||||
@ -716,6 +741,8 @@ undelfs_getid (struct vfs_class *me, const char *path)
|
|||||||
return (vfsid) fs;
|
return (vfsid) fs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
undelfs_nothingisopen (vfsid id)
|
undelfs_nothingisopen (vfsid id)
|
||||||
{
|
{
|
||||||
@ -724,6 +751,8 @@ undelfs_nothingisopen (vfsid id)
|
|||||||
return !undelfs_usage;
|
return !undelfs_usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
undelfs_free (vfsid id)
|
undelfs_free (vfsid id)
|
||||||
{
|
{
|
||||||
@ -732,7 +761,9 @@ undelfs_free (vfsid id)
|
|||||||
undelfs_shutdown ();
|
undelfs_shutdown ();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#ifdef ENABLE_NLS
|
||||||
static int
|
static int
|
||||||
undelfs_init (struct vfs_class *me)
|
undelfs_init (struct vfs_class *me)
|
||||||
{
|
{
|
||||||
@ -742,9 +773,33 @@ undelfs_init (struct vfs_class *me)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define undelfs_init NULL
|
#define undelfs_init NULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/*** public functions ****************************************************************************/
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
/**
|
||||||
|
* This function overrides com_err() from libcom_err library.
|
||||||
|
* It is used in libext2fs to report errors.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
com_err (const char *whoami, long err_code, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
va_start (ap, fmt);
|
||||||
|
str = g_strdup_vprintf (fmt, ap);
|
||||||
|
va_end (ap);
|
||||||
|
|
||||||
|
message (D_ERROR, _("Ext2lib error"), "%s (%s: %ld)", str, whoami, err_code);
|
||||||
|
g_free (str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
void
|
void
|
||||||
init_undelfs (void)
|
init_undelfs (void)
|
||||||
{
|
{
|
||||||
@ -767,3 +822,5 @@ init_undelfs (void)
|
|||||||
vfs_undelfs_ops.free = undelfs_free;
|
vfs_undelfs_ops.free = undelfs_free;
|
||||||
vfs_register_class (&vfs_undelfs_ops);
|
vfs_register_class (&vfs_undelfs_ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -13,40 +13,47 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
/** Bit flags for vfs_split_url()
|
/** Bit flags for vfs_split_url()
|
||||||
*
|
*
|
||||||
* Modify parsing parameters according to flag meaning.
|
* Modify parsing parameters according to flag meaning.
|
||||||
* @see vfs_split_url()
|
* @see vfs_split_url()
|
||||||
*/
|
*/
|
||||||
enum VFS_URL_FLAGS {
|
enum VFS_URL_FLAGS
|
||||||
|
{
|
||||||
URL_USE_ANONYMOUS = 1, /**< if set, empty *user will contain NULL instead of current */
|
URL_USE_ANONYMOUS = 1, /**< if set, empty *user will contain NULL instead of current */
|
||||||
URL_NOSLASH = 2 /**< if set, 'proto://' part in url is not searched */
|
URL_NOSLASH = 2 /**< if set, 'proto://' part in url is not searched */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
int vfs_finduid (const char *name);
|
int vfs_finduid (const char *name);
|
||||||
int vfs_findgid (const char *name);
|
int vfs_findgid (const char *name);
|
||||||
|
|
||||||
char *vfs_split_url (const char *path, char **host, char **user, int *port,
|
char *vfs_split_url (const char *path, char **host, char **user, int *port,
|
||||||
char **pass, int default_port, enum VFS_URL_FLAGS flags);
|
char **pass, int default_port, enum VFS_URL_FLAGS flags);
|
||||||
int vfs_split_text (char *p);
|
int vfs_split_text (char *p);
|
||||||
|
|
||||||
int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
|
int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
|
||||||
void vfs_die (const char *msg);
|
void vfs_die (const char *msg);
|
||||||
char *vfs_get_password (const char *msg);
|
char *vfs_get_password (const char *msg);
|
||||||
|
|
||||||
char * vfs_get_local_username(void);
|
char *vfs_get_local_username (void);
|
||||||
|
|
||||||
gboolean vfs_parse_filetype (const char *s, size_t *ret_skipped,
|
gboolean vfs_parse_filetype (const char *s, size_t * ret_skipped, mode_t * ret_type);
|
||||||
mode_t *ret_type);
|
gboolean vfs_parse_fileperms (const char *s, size_t * ret_skipped, mode_t * ret_perms);
|
||||||
gboolean vfs_parse_fileperms (const char *s, size_t *ret_skipped,
|
gboolean vfs_parse_filemode (const char *s, size_t * ret_skipped, mode_t * ret_mode);
|
||||||
mode_t *ret_perms);
|
gboolean vfs_parse_raw_filemode (const char *s, size_t * ret_skipped, mode_t * ret_mode);
|
||||||
gboolean vfs_parse_filemode (const char *s, size_t *ret_skipped,
|
|
||||||
mode_t *ret_mode);
|
|
||||||
gboolean vfs_parse_raw_filemode (const char *s, size_t *ret_skipped,
|
|
||||||
mode_t *ret_mode);
|
|
||||||
|
|
||||||
int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
|
int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
|
||||||
char **linkname);
|
int vfs_parse_filedate (int idx, time_t * t);
|
||||||
int vfs_parse_filedate (int idx, time_t *t);
|
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
* \brief Header: VFS implemntation (?)
|
* \brief Header: VFS implemntation (?)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_IMPL_H
|
#ifndef MC__VFS_IMPL_H
|
||||||
#define MC_VFS_IMPL_H
|
#define MC__VFS_IMPL_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -16,90 +16,100 @@
|
|||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
|
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
typedef void *vfsid;
|
typedef void *vfsid;
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
struct vfs_stamping;
|
struct vfs_stamping;
|
||||||
|
|
||||||
struct vfs_class {
|
struct vfs_class
|
||||||
|
{
|
||||||
struct vfs_class *next;
|
struct vfs_class *next;
|
||||||
const char *name; /* "FIles over SHell" */
|
const char *name; /* "FIles over SHell" */
|
||||||
vfs_class_flags_t flags;
|
vfs_class_flags_t flags;
|
||||||
const char *prefix; /* "fish:" */
|
const char *prefix; /* "fish:" */
|
||||||
void *data; /* this is for filesystem's own use */
|
void *data; /* this is for filesystem's own use */
|
||||||
int verrno; /* can't use errno because glibc2 might define errno as function */
|
int verrno; /* can't use errno because glibc2 might define errno as function */
|
||||||
|
|
||||||
int (*init) (struct vfs_class *me);
|
int (*init) (struct vfs_class * me);
|
||||||
void (*done) (struct vfs_class *me);
|
void (*done) (struct vfs_class * me);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The fill_names method shall call the callback function for every
|
* The fill_names method shall call the callback function for every
|
||||||
* filesystem name that this vfs module supports.
|
* filesystem name that this vfs module supports.
|
||||||
*/
|
*/
|
||||||
void (*fill_names) (struct vfs_class *me, fill_names_f);
|
void (*fill_names) (struct vfs_class * me, fill_names_f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The which() method shall return the index of the vfs subsystem
|
* The which() method shall return the index of the vfs subsystem
|
||||||
* or -1 if this vfs cannot handle the given pathname.
|
* or -1 if this vfs cannot handle the given pathname.
|
||||||
*/
|
*/
|
||||||
int (*which) (struct vfs_class *me, const char *path);
|
int (*which) (struct vfs_class * me, const char *path);
|
||||||
|
|
||||||
void *(*open) (struct vfs_class *me, const char *fname, int flags,
|
void *(*open) (struct vfs_class * me, const char *fname, int flags, mode_t mode);
|
||||||
mode_t mode);
|
|
||||||
int (*close) (void *vfs_info);
|
int (*close) (void *vfs_info);
|
||||||
ssize_t (*read) (void *vfs_info, char *buffer, size_t count);
|
ssize_t (*read) (void *vfs_info, char *buffer, size_t count);
|
||||||
ssize_t (*write) (void *vfs_info, const char *buf, size_t count);
|
ssize_t (*write) (void *vfs_info, const char *buf, size_t count);
|
||||||
|
|
||||||
void *(*opendir) (struct vfs_class *me, const char *dirname);
|
void *(*opendir) (struct vfs_class * me, const char *dirname);
|
||||||
void *(*readdir) (void *vfs_info);
|
void *(*readdir) (void *vfs_info);
|
||||||
int (*closedir) (void *vfs_info);
|
int (*closedir) (void *vfs_info);
|
||||||
|
|
||||||
int (*stat) (struct vfs_class *me, const char *path, struct stat * buf);
|
int (*stat) (struct vfs_class * me, const char *path, struct stat * buf);
|
||||||
int (*lstat) (struct vfs_class *me, const char *path, struct stat * buf);
|
int (*lstat) (struct vfs_class * me, const char *path, struct stat * buf);
|
||||||
int (*fstat) (void *vfs_info, struct stat * buf);
|
int (*fstat) (void *vfs_info, struct stat * buf);
|
||||||
|
|
||||||
int (*chmod) (struct vfs_class *me, const char *path, int mode);
|
int (*chmod) (struct vfs_class * me, const char *path, int mode);
|
||||||
int (*chown) (struct vfs_class *me, const char *path, uid_t owner, gid_t group);
|
int (*chown) (struct vfs_class * me, const char *path, uid_t owner, gid_t group);
|
||||||
int (*utime) (struct vfs_class *me, const char *path,
|
int (*utime) (struct vfs_class * me, const char *path, struct utimbuf * times);
|
||||||
struct utimbuf * times);
|
|
||||||
|
|
||||||
int (*readlink) (struct vfs_class *me, const char *path, char *buf,
|
int (*readlink) (struct vfs_class * me, const char *path, char *buf, size_t size);
|
||||||
size_t size);
|
int (*symlink) (struct vfs_class * me, const char *n1, const char *n2);
|
||||||
int (*symlink) (struct vfs_class *me, const char *n1, const char *n2);
|
int (*link) (struct vfs_class * me, const char *p1, const char *p2);
|
||||||
int (*link) (struct vfs_class *me, const char *p1, const char *p2);
|
int (*unlink) (struct vfs_class * me, const char *path);
|
||||||
int (*unlink) (struct vfs_class *me, const char *path);
|
int (*rename) (struct vfs_class * me, const char *p1, const char *p2);
|
||||||
int (*rename) (struct vfs_class *me, const char *p1, const char *p2);
|
int (*chdir) (struct vfs_class * me, const char *path);
|
||||||
int (*chdir) (struct vfs_class *me, const char *path);
|
int (*ferrno) (struct vfs_class * me);
|
||||||
int (*ferrno) (struct vfs_class *me);
|
off_t (*lseek) (void *vfs_info, off_t offset, int whence);
|
||||||
off_t (*lseek) (void *vfs_info, off_t offset, int whence);
|
int (*mknod) (struct vfs_class * me, const char *path, mode_t mode, dev_t dev);
|
||||||
int (*mknod) (struct vfs_class *me, const char *path, mode_t mode, dev_t dev);
|
|
||||||
|
|
||||||
vfsid (*getid) (struct vfs_class *me, const char *path);
|
vfsid (*getid) (struct vfs_class * me, const char *path);
|
||||||
|
|
||||||
int (*nothingisopen) (vfsid id);
|
int (*nothingisopen) (vfsid id);
|
||||||
void (*free) (vfsid id);
|
void (*free) (vfsid id);
|
||||||
|
|
||||||
char *(*getlocalcopy) (struct vfs_class *me, const char *filename);
|
char *(*getlocalcopy) (struct vfs_class * me, const char *filename);
|
||||||
int (*ungetlocalcopy) (struct vfs_class *me, const char *filename,
|
int (*ungetlocalcopy) (struct vfs_class * me, const char *filename,
|
||||||
const char *local, int has_changed);
|
const char *local, int has_changed);
|
||||||
|
|
||||||
int (*mkdir) (struct vfs_class *me, const char *path, mode_t mode);
|
int (*mkdir) (struct vfs_class * me, const char *path, mode_t mode);
|
||||||
int (*rmdir) (struct vfs_class *me, const char *path);
|
int (*rmdir) (struct vfs_class * me, const char *path);
|
||||||
|
|
||||||
int (*ctl) (void *vfs_info, int ctlop, void *arg);
|
int (*ctl) (void *vfs_info, int ctlop, void *arg);
|
||||||
int (*setctl) (struct vfs_class *me, const char *path, int ctlop,
|
int (*setctl) (struct vfs_class * me, const char *path, int ctlop, void *arg);
|
||||||
void *arg);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This union is used to ensure that there is enough space for the
|
* This union is used to ensure that there is enough space for the
|
||||||
* filename (d_name) when the dirent structure is created.
|
* filename (d_name) when the dirent structure is created.
|
||||||
*/
|
*/
|
||||||
union vfs_dirent {
|
union vfs_dirent
|
||||||
|
{
|
||||||
struct dirent dent;
|
struct dirent dent;
|
||||||
char _extra_buffer[offsetof(struct dirent, d_name) + MC_MAXPATHLEN + 1];
|
char _extra_buffer[offsetof (struct dirent, d_name) + MC_MAXPATHLEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/* Register a file system class */
|
/* Register a file system class */
|
||||||
int vfs_register_class (struct vfs_class *vfs);
|
int vfs_register_class (struct vfs_class *vfs);
|
||||||
|
|
||||||
@ -133,4 +143,5 @@ void init_ftpfs (void);
|
|||||||
void init_fish (void);
|
void init_fish (void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** inline functions ****************************************************************************/
|
||||||
#endif /* MC_VFS_IMPL_H */
|
#endif /* MC_VFS_IMPL_H */
|
||||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -4,8 +4,8 @@
|
|||||||
* \brief Header: Virtual File System switch code
|
* \brief Header: Virtual File System switch code
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MC_VFS_VFS_H
|
#ifndef MC__VFS_VFS_H
|
||||||
#define MC_VFS_VFS_H
|
#define MC__VFS_VFS_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
@ -14,18 +14,7 @@
|
|||||||
|
|
||||||
#include "lib/global.h"
|
#include "lib/global.h"
|
||||||
|
|
||||||
struct vfs_class;
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
/* Flags of VFS classes */
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
VFSF_UNKNOWN = 0,
|
|
||||||
VFSF_LOCAL = 1 << 0, /* Class is local (not virtual) filesystem */
|
|
||||||
VFSF_NOLINKS = 1 << 1 /* Hard links not supported */
|
|
||||||
} vfs_class_flags_t;
|
|
||||||
|
|
||||||
void vfs_init (void);
|
|
||||||
void vfs_shut (void);
|
|
||||||
|
|
||||||
#if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
|
#if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
|
||||||
#define ENABLE_VFS_NET 1
|
#define ENABLE_VFS_NET 1
|
||||||
@ -37,14 +26,114 @@ void vfs_shut (void);
|
|||||||
* See also:
|
* See also:
|
||||||
* vfs_fill_names().
|
* vfs_fill_names().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define VFS_ENCODING_PREFIX "#enc:"
|
||||||
|
|
||||||
|
#define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
|
||||||
|
/* Midnight commander code should _not_ use other flags than those
|
||||||
|
listed above and O_APPEND */
|
||||||
|
|
||||||
|
#if (O_ALL & O_APPEND)
|
||||||
|
#warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
|
||||||
|
#define O_LINEAR 0
|
||||||
|
#define IS_LINEAR(a) 0
|
||||||
|
#define NO_LINEAR(a) a
|
||||||
|
#else
|
||||||
|
#define O_LINEAR O_APPEND
|
||||||
|
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
|
||||||
|
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* O_LINEAR is strange beast, be careful. If you open file asserting
|
||||||
|
* O_RDONLY | O_LINEAR, you promise:
|
||||||
|
*
|
||||||
|
* a) to read file linearly from beginning to the end
|
||||||
|
* b) not to open another file before you close this one
|
||||||
|
* (this will likely go away in future)
|
||||||
|
* as a special gift, you may
|
||||||
|
* c) lseek() immediately after open(), giving ftpfs chance to
|
||||||
|
* reget. Be warned that this lseek() can fail, and you _have_
|
||||||
|
* to handle that gratefully.
|
||||||
|
*
|
||||||
|
* O_LINEAR allows filesystems not to create temporary file in some
|
||||||
|
* cases (ftp transfer). -- pavel@ucw.cz
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* And now some defines for our errors. */
|
||||||
|
|
||||||
|
#ifdef ENOSYS
|
||||||
|
#define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
|
||||||
|
#else
|
||||||
|
#define E_NOTSUPP EFAULT /* Does this happen? */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENOMSG
|
||||||
|
#define E_UNKNOWN ENOMSG /* if we do not know what error happened */
|
||||||
|
#else
|
||||||
|
#define E_UNKNOWN EIO /* if we do not know what error happened */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef EREMOTEIO
|
||||||
|
#define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
|
||||||
|
#else
|
||||||
|
#define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef EPROTO
|
||||||
|
#define E_PROTO EPROTO /* if other side fails to follow protocol */
|
||||||
|
#else
|
||||||
|
#define E_PROTO EIO
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef void (*fill_names_f) (const char *);
|
typedef void (*fill_names_f) (const char *);
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/* Flags of VFS classes */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
VFSF_UNKNOWN = 0,
|
||||||
|
VFSF_LOCAL = 1 << 0, /* Class is local (not virtual) filesystem */
|
||||||
|
VFSF_NOLINKS = 1 << 1 /* Hard links not supported */
|
||||||
|
} vfs_class_flags_t;
|
||||||
|
|
||||||
|
/* Operations for mc_ctl - on open file */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
VFS_CTL_IS_NOTREADY
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Operations for mc_setctl - on path */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
VFS_SETCTL_FORGET,
|
||||||
|
VFS_SETCTL_RUN,
|
||||||
|
VFS_SETCTL_LOGFILE,
|
||||||
|
VFS_SETCTL_FLUSH, /* invalidate directory cache */
|
||||||
|
|
||||||
|
/* Setting this makes vfs layer give out potentially incorrect data,
|
||||||
|
but it also makes some operations much faster. Use with caution. */
|
||||||
|
VFS_SETCTL_STALE_DATA
|
||||||
|
};
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
|
struct vfs_class;
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
extern int vfs_timeout;
|
extern int vfs_timeout;
|
||||||
|
|
||||||
#ifdef ENABLE_VFS_NET
|
#ifdef ENABLE_VFS_NET
|
||||||
extern int use_netrc;
|
extern int use_netrc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
|
void vfs_init (void);
|
||||||
|
void vfs_shut (void);
|
||||||
|
|
||||||
|
|
||||||
void vfs_timeout_handler (void);
|
void vfs_timeout_handler (void);
|
||||||
int vfs_timeouts (void);
|
int vfs_timeouts (void);
|
||||||
void vfs_expire (int now);
|
void vfs_expire (int now);
|
||||||
@ -86,7 +175,6 @@ char *vfs_translate_url (const char *url);
|
|||||||
struct vfs_class *vfs_get_class (const char *path);
|
struct vfs_class *vfs_get_class (const char *path);
|
||||||
vfs_class_flags_t vfs_file_class_flags (const char *filename);
|
vfs_class_flags_t vfs_file_class_flags (const char *filename);
|
||||||
|
|
||||||
#define VFS_ENCODING_PREFIX "#enc:"
|
|
||||||
/* return encoding after last #enc: or NULL, if part does not contain #enc:
|
/* return encoding after last #enc: or NULL, if part does not contain #enc:
|
||||||
* return static buffer */
|
* return static buffer */
|
||||||
const char *vfs_get_encoding (const char *path);
|
const char *vfs_get_encoding (const char *path);
|
||||||
@ -109,77 +197,5 @@ char *vfs_get_current_dir (void);
|
|||||||
* return static buffer */
|
* return static buffer */
|
||||||
char *vfs_translate_path (const char *path);
|
char *vfs_translate_path (const char *path);
|
||||||
|
|
||||||
/* Operations for mc_ctl - on open file */
|
/*** inline functions ****************************************************************************/
|
||||||
enum {
|
|
||||||
VFS_CTL_IS_NOTREADY
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Operations for mc_setctl - on path */
|
|
||||||
enum {
|
|
||||||
VFS_SETCTL_FORGET,
|
|
||||||
VFS_SETCTL_RUN,
|
|
||||||
VFS_SETCTL_LOGFILE,
|
|
||||||
VFS_SETCTL_FLUSH, /* invalidate directory cache */
|
|
||||||
|
|
||||||
/* Setting this makes vfs layer give out potentially incorrect data,
|
|
||||||
but it also makes some operations much faster. Use with caution. */
|
|
||||||
VFS_SETCTL_STALE_DATA
|
|
||||||
};
|
|
||||||
|
|
||||||
#define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
|
|
||||||
/* Midnight commander code should _not_ use other flags than those
|
|
||||||
listed above and O_APPEND */
|
|
||||||
|
|
||||||
#if (O_ALL & O_APPEND)
|
|
||||||
#warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
|
|
||||||
#define O_LINEAR 0
|
|
||||||
#define IS_LINEAR(a) 0
|
|
||||||
#define NO_LINEAR(a) a
|
|
||||||
#else
|
|
||||||
#define O_LINEAR O_APPEND
|
|
||||||
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
|
|
||||||
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* O_LINEAR is strange beast, be careful. If you open file asserting
|
|
||||||
* O_RDONLY | O_LINEAR, you promise:
|
|
||||||
*
|
|
||||||
* a) to read file linearly from beginning to the end
|
|
||||||
* b) not to open another file before you close this one
|
|
||||||
* (this will likely go away in future)
|
|
||||||
* as a special gift, you may
|
|
||||||
* c) lseek() immediately after open(), giving ftpfs chance to
|
|
||||||
* reget. Be warned that this lseek() can fail, and you _have_
|
|
||||||
* to handle that gratefully.
|
|
||||||
*
|
|
||||||
* O_LINEAR allows filesystems not to create temporary file in some
|
|
||||||
* cases (ftp transfer). -- pavel@ucw.cz
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* And now some defines for our errors. */
|
|
||||||
|
|
||||||
#ifdef ENOSYS
|
|
||||||
#define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
|
|
||||||
#else
|
|
||||||
#define E_NOTSUPP EFAULT /* Does this happen? */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENOMSG
|
|
||||||
#define E_UNKNOWN ENOMSG /* if we do not know what error happened */
|
|
||||||
#else
|
|
||||||
#define E_UNKNOWN EIO /* if we do not know what error happened */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EREMOTEIO
|
|
||||||
#define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
|
|
||||||
#else
|
|
||||||
#define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef EPROTO
|
|
||||||
#define E_PROTO EPROTO /* if other side fails to follow protocol */
|
|
||||||
#else
|
|
||||||
#define E_PROTO EIO
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* MC_VFS_VFS_H */
|
#endif /* MC_VFS_VFS_H */
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef MC_VFS_XDIRENTRY_H
|
#ifndef MC__VFS_XDIRENTRY_H
|
||||||
#define MC_VFS_XDIRENTRY_H
|
#define MC__VFS_XDIRENTRY_H
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/*** typedefs(not structures) and defined constants **********************************************/
|
||||||
|
|
||||||
#define LINK_FOLLOW 15
|
#define LINK_FOLLOW 15
|
||||||
#define LINK_NO_FOLLOW -1
|
#define LINK_NO_FOLLOW -1
|
||||||
|
|
||||||
@ -31,6 +33,21 @@
|
|||||||
#define VFS_S_REMOTE 1
|
#define VFS_S_REMOTE 1
|
||||||
#define VFS_S_READONLY 2
|
#define VFS_S_READONLY 2
|
||||||
|
|
||||||
|
#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
|
||||||
|
|
||||||
|
#define MEDATA ((struct vfs_s_subclass *) me->data)
|
||||||
|
|
||||||
|
#define FH ((struct vfs_s_fh *) fh)
|
||||||
|
#define FH_SUPER FH->ino->super
|
||||||
|
|
||||||
|
#define LS_NOT_LINEAR 0
|
||||||
|
#define LS_LINEAR_CLOSED 1
|
||||||
|
#define LS_LINEAR_OPEN 2
|
||||||
|
#define LS_LINEAR_PREOPEN 3
|
||||||
|
|
||||||
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||||
|
|
||||||
/* Single connection or archive */
|
/* Single connection or archive */
|
||||||
struct vfs_s_super
|
struct vfs_s_super
|
||||||
@ -70,7 +87,7 @@ struct vfs_s_super
|
|||||||
int host_flags;
|
int host_flags;
|
||||||
char *scr_env;
|
char *scr_env;
|
||||||
} fish;
|
} fish;
|
||||||
#endif /* ENABLE_VFS_FISH */
|
#endif /* ENABLE_VFS_FISH */
|
||||||
#ifdef ENABLE_VFS_FTP
|
#ifdef ENABLE_VFS_FTP
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -80,29 +97,29 @@ struct vfs_s_super
|
|||||||
char *password;
|
char *password;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
char *proxy; /* proxy server, NULL if no proxy */
|
char *proxy; /* proxy server, NULL if no proxy */
|
||||||
int failed_on_login; /* used to pass the failure reason to upper levels */
|
int failed_on_login; /* used to pass the failure reason to upper levels */
|
||||||
int use_passive_connection;
|
int use_passive_connection;
|
||||||
int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
|
int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
|
||||||
int isbinary;
|
int isbinary;
|
||||||
int cwd_deferred; /* current_directory was changed but CWD command hasn't
|
int cwd_deferred; /* current_directory was changed but CWD command hasn't
|
||||||
been sent yet */
|
been sent yet */
|
||||||
int strict; /* ftp server doesn't understand
|
int strict; /* ftp server doesn't understand
|
||||||
* "LIST -la <path>"; use "CWD <path>"/
|
* "LIST -la <path>"; use "CWD <path>"/
|
||||||
* "LIST" instead
|
* "LIST" instead
|
||||||
*/
|
*/
|
||||||
int ctl_connection_busy;
|
int ctl_connection_busy;
|
||||||
} ftp;
|
} ftp;
|
||||||
#endif /* ENABLE_VFS_FTP */
|
#endif /* ENABLE_VFS_FTP */
|
||||||
#if defined(ENABLE_VFS_CPIO) || defined(ENABLE_VFS_TAR)
|
#if defined(ENABLE_VFS_CPIO) || defined(ENABLE_VFS_TAR)
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int type; /* Type of the archive */
|
int type; /* Type of the archive */
|
||||||
struct defer_inode *deferred; /* List of inodes for which another entries may appear */
|
struct defer_inode *deferred; /* List of inodes for which another entries may appear */
|
||||||
} arch;
|
} arch;
|
||||||
#endif /* ENABLE_VFS_CPIO || ENABLE_VFS_TAR */
|
#endif /* ENABLE_VFS_CPIO || ENABLE_VFS_TAR */
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -149,13 +166,13 @@ struct vfs_s_fh
|
|||||||
off_t got, total;
|
off_t got, total;
|
||||||
int append;
|
int append;
|
||||||
} fish;
|
} fish;
|
||||||
#endif /* ENABLE_VFS_FISH */
|
#endif /* ENABLE_VFS_FISH */
|
||||||
#ifdef ENABLE_VFS_FTP
|
#ifdef ENABLE_VFS_FTP
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int sock, append;
|
int sock, append;
|
||||||
} ftp;
|
} ftp;
|
||||||
#endif /* ENABLE_VFS_FTP */
|
#endif /* ENABLE_VFS_FTP */
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -198,6 +215,9 @@ struct vfs_s_subclass
|
|||||||
void (*linear_close) (struct vfs_class * me, struct vfs_s_fh * fh);
|
void (*linear_close) (struct vfs_class * me, struct vfs_s_fh * fh);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*** global variables defined in .c file *********************************************************/
|
||||||
|
|
||||||
|
/*** declarations of public functions ************************************************************/
|
||||||
|
|
||||||
/* entries and inodes */
|
/* entries and inodes */
|
||||||
struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
|
struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
|
||||||
@ -229,16 +249,5 @@ int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size,
|
|||||||
/* misc */
|
/* misc */
|
||||||
int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
|
int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
|
||||||
|
|
||||||
#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
#define MEDATA ((struct vfs_s_subclass *) me->data)
|
|
||||||
|
|
||||||
#define FH ((struct vfs_s_fh *) fh)
|
|
||||||
#define FH_SUPER FH->ino->super
|
|
||||||
|
|
||||||
#define LS_NOT_LINEAR 0
|
|
||||||
#define LS_LINEAR_CLOSED 1
|
|
||||||
#define LS_LINEAR_OPEN 2
|
|
||||||
#define LS_LINEAR_PREOPEN 3
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
324
src/cmddef.h
324
src/cmddef.h
@ -11,194 +11,194 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* special commands */
|
/* special commands */
|
||||||
#define CK_Insert_Char -1
|
#define CK_Insert_Char -1
|
||||||
#define CK_Ignore_Key 0
|
#define CK_Ignore_Key 0
|
||||||
|
|
||||||
/* cursor movements */
|
/* cursor movements */
|
||||||
#define CK_BackSpace 1
|
#define CK_BackSpace 1
|
||||||
#define CK_Delete 2
|
#define CK_Delete 2
|
||||||
#define CK_Enter 3
|
#define CK_Enter 3
|
||||||
#define CK_Page_Up 4
|
#define CK_Page_Up 4
|
||||||
#define CK_Page_Down 5
|
#define CK_Page_Down 5
|
||||||
#define CK_Left 6
|
#define CK_Left 6
|
||||||
#define CK_Right 7
|
#define CK_Right 7
|
||||||
#define CK_Word_Left 8
|
#define CK_Word_Left 8
|
||||||
#define CK_Word_Right 9
|
#define CK_Word_Right 9
|
||||||
#define CK_Up 10
|
#define CK_Up 10
|
||||||
#define CK_Down 11
|
#define CK_Down 11
|
||||||
#define CK_Home 12
|
#define CK_Home 12
|
||||||
#define CK_End 13
|
#define CK_End 13
|
||||||
#define CK_Tab 14
|
#define CK_Tab 14
|
||||||
#define CK_Undo 15
|
#define CK_Undo 15
|
||||||
#define CK_Beginning_Of_Text 16
|
#define CK_Beginning_Of_Text 16
|
||||||
#define CK_End_Of_Text 17
|
#define CK_End_Of_Text 17
|
||||||
#define CK_Scroll_Up 18
|
#define CK_Scroll_Up 18
|
||||||
#define CK_Scroll_Down 19
|
#define CK_Scroll_Down 19
|
||||||
#define CK_Return 20
|
#define CK_Return 20
|
||||||
#define CK_Begin_Page 21
|
#define CK_Begin_Page 21
|
||||||
#define CK_End_Page 22
|
#define CK_End_Page 22
|
||||||
#define CK_Delete_Word_Left 23
|
#define CK_Delete_Word_Left 23
|
||||||
#define CK_Delete_Word_Right 24
|
#define CK_Delete_Word_Right 24
|
||||||
#define CK_Paragraph_Up 25
|
#define CK_Paragraph_Up 25
|
||||||
#define CK_Paragraph_Down 26
|
#define CK_Paragraph_Down 26
|
||||||
|
|
||||||
/* file commands */
|
/* file commands */
|
||||||
#define CK_Save 101
|
#define CK_Save 101
|
||||||
#define CK_Load 102
|
#define CK_Load 102
|
||||||
#define CK_New 103
|
#define CK_New 103
|
||||||
#define CK_Save_As 104
|
#define CK_Save_As 104
|
||||||
#define CK_Load_Prev_File 111
|
#define CK_Load_Prev_File 111
|
||||||
#define CK_Load_Next_File 112
|
#define CK_Load_Next_File 112
|
||||||
#define CK_Load_Syntax_File 121
|
#define CK_Load_Syntax_File 121
|
||||||
#define CK_Load_Menu_File 122
|
#define CK_Load_Menu_File 122
|
||||||
#define CK_Menu 123
|
#define CK_Menu 123
|
||||||
|
|
||||||
/* block commands */
|
/* block commands */
|
||||||
#define CK_Mark 201
|
#define CK_Mark 201
|
||||||
#define CK_Copy 202
|
#define CK_Copy 202
|
||||||
#define CK_Move 203
|
#define CK_Move 203
|
||||||
#define CK_Remove 204
|
#define CK_Remove 204
|
||||||
#define CK_Unmark 206
|
#define CK_Unmark 206
|
||||||
#define CK_Save_Block 207
|
#define CK_Save_Block 207
|
||||||
#define CK_Column_Mark 208
|
#define CK_Column_Mark 208
|
||||||
#define CK_Shift_Block_Left 211
|
#define CK_Shift_Block_Left 211
|
||||||
#define CK_Shift_Block_Right 212
|
#define CK_Shift_Block_Right 212
|
||||||
#define CK_Mark_All 213
|
#define CK_Mark_All 213
|
||||||
|
|
||||||
/* search and replace */
|
/* search and replace */
|
||||||
#define CK_Find 301
|
#define CK_Find 301
|
||||||
#define CK_Find_Again 302
|
#define CK_Find_Again 302
|
||||||
#define CK_Replace 303
|
#define CK_Replace 303
|
||||||
#define CK_Replace_Again 304
|
#define CK_Replace_Again 304
|
||||||
#define CK_Complete_Word 305
|
#define CK_Complete_Word 305
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* debugger commands */
|
/* debugger commands */
|
||||||
#define CK_Debug_Start 350
|
#define CK_Debug_Start 350
|
||||||
#define CK_Debug_Stop 351
|
#define CK_Debug_Stop 351
|
||||||
#define CK_Debug_Toggle_Break 352
|
#define CK_Debug_Toggle_Break 352
|
||||||
#define CK_Debug_Clear 353
|
#define CK_Debug_Clear 353
|
||||||
#define CK_Debug_Next 354
|
#define CK_Debug_Next 354
|
||||||
#define CK_Debug_Step 355
|
#define CK_Debug_Step 355
|
||||||
#define CK_Debug_Back_Trace 356
|
#define CK_Debug_Back_Trace 356
|
||||||
#define CK_Debug_Continue 357
|
#define CK_Debug_Continue 357
|
||||||
#define CK_Debug_Enter_Command 358
|
#define CK_Debug_Enter_Command 358
|
||||||
#define CK_Debug_Until_Curser 359
|
#define CK_Debug_Until_Curser 359
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* misc */
|
/* misc */
|
||||||
#define CK_Insert_File 401
|
#define CK_Insert_File 401
|
||||||
#define CK_Quit 402
|
#define CK_Quit 402
|
||||||
#define CK_Toggle_Insert 403
|
#define CK_Toggle_Insert 403
|
||||||
#define CK_Help 404
|
#define CK_Help 404
|
||||||
#define CK_Date 405
|
#define CK_Date 405
|
||||||
#define CK_Refresh 406
|
#define CK_Refresh 406
|
||||||
#define CK_Goto 407
|
#define CK_Goto 407
|
||||||
#define CK_Delete_Line 408
|
#define CK_Delete_Line 408
|
||||||
#define CK_Delete_To_Line_End 409
|
#define CK_Delete_To_Line_End 409
|
||||||
#define CK_Delete_To_Line_Begin 410
|
#define CK_Delete_To_Line_Begin 410
|
||||||
#define CK_Man_Page 411
|
#define CK_Man_Page 411
|
||||||
#define CK_Sort 412
|
#define CK_Sort 412
|
||||||
#define CK_Mail 413
|
#define CK_Mail 413
|
||||||
#define CK_Cancel 414
|
#define CK_Cancel 414
|
||||||
#define CK_Complete 415
|
#define CK_Complete 415
|
||||||
#define CK_Paragraph_Format 416
|
#define CK_Paragraph_Format 416
|
||||||
#define CK_Util 417
|
#define CK_Util 417
|
||||||
#define CK_Type_Load_Python 418
|
#define CK_Type_Load_Python 418
|
||||||
#define CK_Find_File 419
|
#define CK_Find_File 419
|
||||||
#define CK_Ctags 420
|
#define CK_Ctags 420
|
||||||
#define CK_Match_Bracket 421
|
#define CK_Match_Bracket 421
|
||||||
#define CK_Terminal 422
|
#define CK_Terminal 422
|
||||||
#define CK_Terminal_App 423
|
#define CK_Terminal_App 423
|
||||||
#define CK_ExtCmd 424
|
#define CK_ExtCmd 424
|
||||||
#define CK_User_Menu 425
|
#define CK_User_Menu 425
|
||||||
#define CK_Find_Definition 426
|
#define CK_Find_Definition 426
|
||||||
#define CK_Edit_Options 427
|
#define CK_Edit_Options 427
|
||||||
#define CK_Edit_Save_Mode 428
|
#define CK_Edit_Save_Mode 428
|
||||||
#define CK_Choose_Syntax 429
|
#define CK_Choose_Syntax 429
|
||||||
#define CK_About 430
|
#define CK_About 430
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* application control */
|
/* application control */
|
||||||
#define CK_Save_Desktop 451
|
#define CK_Save_Desktop 451
|
||||||
#define CK_New_Window 452
|
#define CK_New_Window 452
|
||||||
#define CK_Cycle 453
|
#define CK_Cycle 453
|
||||||
#define CK_Save_And_Quit 455
|
#define CK_Save_And_Quit 455
|
||||||
#define CK_Run_Another 456
|
#define CK_Run_Another 456
|
||||||
#define CK_Check_Save_And_Quit 457
|
#define CK_Check_Save_And_Quit 457
|
||||||
#define CK_Maximize 458
|
#define CK_Maximize 458
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CK_Toggle_Show_Margin 460
|
#define CK_Toggle_Show_Margin 460
|
||||||
#define CK_Toggle_Tab_TWS 470
|
#define CK_Toggle_Tab_TWS 470
|
||||||
#define CK_Toggle_Syntax 480
|
#define CK_Toggle_Syntax 480
|
||||||
#define CK_Toggle_Line_State 490
|
#define CK_Toggle_Line_State 490
|
||||||
|
|
||||||
/* macro */
|
/* macro */
|
||||||
#define CK_Begin_Record_Macro 501
|
#define CK_Begin_Record_Macro 501
|
||||||
#define CK_End_Record_Macro 502
|
#define CK_End_Record_Macro 502
|
||||||
#define CK_Delete_Macro 503
|
#define CK_Delete_Macro 503
|
||||||
|
|
||||||
/* book mark */
|
/* book mark */
|
||||||
#define CK_Toggle_Bookmark 550
|
#define CK_Toggle_Bookmark 550
|
||||||
#define CK_Flush_Bookmarks 551
|
#define CK_Flush_Bookmarks 551
|
||||||
#define CK_Next_Bookmark 552
|
#define CK_Next_Bookmark 552
|
||||||
#define CK_Prev_Bookmark 553
|
#define CK_Prev_Bookmark 553
|
||||||
|
|
||||||
/* highlight commands */
|
/* highlight commands */
|
||||||
#define CK_Page_Up_Highlight 604
|
#define CK_Page_Up_Highlight 604
|
||||||
#define CK_Page_Down_Highlight 605
|
#define CK_Page_Down_Highlight 605
|
||||||
#define CK_Left_Highlight 606
|
#define CK_Left_Highlight 606
|
||||||
#define CK_Right_Highlight 607
|
#define CK_Right_Highlight 607
|
||||||
#define CK_Word_Left_Highlight 608
|
#define CK_Word_Left_Highlight 608
|
||||||
#define CK_Word_Right_Highlight 609
|
#define CK_Word_Right_Highlight 609
|
||||||
#define CK_Up_Highlight 610
|
#define CK_Up_Highlight 610
|
||||||
#define CK_Down_Highlight 611
|
#define CK_Down_Highlight 611
|
||||||
#define CK_Home_Highlight 612
|
#define CK_Home_Highlight 612
|
||||||
#define CK_End_Highlight 613
|
#define CK_End_Highlight 613
|
||||||
#define CK_Beginning_Of_Text_Highlight 614
|
#define CK_Beginning_Of_Text_Highlight 614
|
||||||
#define CK_End_Of_Text_Highlight 615
|
#define CK_End_Of_Text_Highlight 615
|
||||||
#define CK_Begin_Page_Highlight 616
|
#define CK_Begin_Page_Highlight 616
|
||||||
#define CK_End_Page_Highlight 617
|
#define CK_End_Page_Highlight 617
|
||||||
#define CK_Scroll_Up_Highlight 618
|
#define CK_Scroll_Up_Highlight 618
|
||||||
#define CK_Scroll_Down_Highlight 619
|
#define CK_Scroll_Down_Highlight 619
|
||||||
#define CK_Paragraph_Up_Highlight 620
|
#define CK_Paragraph_Up_Highlight 620
|
||||||
#define CK_Paragraph_Down_Highlight 621
|
#define CK_Paragraph_Down_Highlight 621
|
||||||
|
|
||||||
/* alt highlight commands */
|
/* alt highlight commands */
|
||||||
#define CK_Page_Up_Alt_Highlight 654
|
#define CK_Page_Up_Alt_Highlight 654
|
||||||
#define CK_Page_Down_Alt_Highlight 655
|
#define CK_Page_Down_Alt_Highlight 655
|
||||||
#define CK_Left_Alt_Highlight 656
|
#define CK_Left_Alt_Highlight 656
|
||||||
#define CK_Right_Alt_Highlight 657
|
#define CK_Right_Alt_Highlight 657
|
||||||
#define CK_Word_Left_Alt_Highlight 658
|
#define CK_Word_Left_Alt_Highlight 658
|
||||||
#define CK_Word_Right_Alt_Highlight 659
|
#define CK_Word_Right_Alt_Highlight 659
|
||||||
#define CK_Up_Alt_Highlight 660
|
#define CK_Up_Alt_Highlight 660
|
||||||
#define CK_Down_Alt_Highlight 661
|
#define CK_Down_Alt_Highlight 661
|
||||||
#define CK_Home_Alt_Highlight 662
|
#define CK_Home_Alt_Highlight 662
|
||||||
#define CK_End_Alt_Highlight 663
|
#define CK_End_Alt_Highlight 663
|
||||||
#define CK_Beginning_Of_Text_Alt_Highlight 664
|
#define CK_Beginning_Of_Text_Alt_Highlight 664
|
||||||
#define CK_End_Of_Text_Alt_Highlight 665
|
#define CK_End_Of_Text_Alt_Highlight 665
|
||||||
#define CK_Begin_Page_Alt_Highlight 666
|
#define CK_Begin_Page_Alt_Highlight 666
|
||||||
#define CK_End_Page_Alt_Highlight 667
|
#define CK_End_Page_Alt_Highlight 667
|
||||||
#define CK_Scroll_Up_Alt_Highlight 668
|
#define CK_Scroll_Up_Alt_Highlight 668
|
||||||
#define CK_Scroll_Down_Alt_Highlight 669
|
#define CK_Scroll_Down_Alt_Highlight 669
|
||||||
#define CK_Paragraph_Up_Alt_Highlight 670
|
#define CK_Paragraph_Up_Alt_Highlight 670
|
||||||
#define CK_Paragraph_Down_Alt_Highlight 671
|
#define CK_Paragraph_Down_Alt_Highlight 671
|
||||||
|
|
||||||
/* X clipboard operations */
|
/* X clipboard operations */
|
||||||
#define CK_XStore 701
|
#define CK_XStore 701
|
||||||
#define CK_XCut 702
|
#define CK_XCut 702
|
||||||
#define CK_XPaste 703
|
#define CK_XPaste 703
|
||||||
#define CK_Selection_History 704
|
#define CK_Selection_History 704
|
||||||
|
|
||||||
#define CK_Shell 801
|
#define CK_Shell 801
|
||||||
|
|
||||||
/* C-x or similar */
|
/* C-x or similar */
|
||||||
#define CK_Ext_Mode 820
|
#define CK_Ext_Mode 820
|
||||||
|
|
||||||
#define CK_Insert_Literal 851
|
#define CK_Insert_Literal 851
|
||||||
#define CK_Execute_Macro 852
|
#define CK_Execute_Macro 852
|
||||||
#define CK_Begin_End_Macro 853
|
#define CK_Begin_End_Macro 853
|
||||||
|
|
||||||
/* help */
|
/* help */
|
||||||
#define CK_HelpHelp 1001
|
#define CK_HelpHelp 1001
|
||||||
@ -503,15 +503,15 @@
|
|||||||
TODO: bring up a viewer to display the error message instead of inserting
|
TODO: bring up a viewer to display the error message instead of inserting
|
||||||
it into the text, which is annoying.
|
it into the text, which is annoying.
|
||||||
*/
|
*/
|
||||||
#define CK_Pipe_Block(i) (1000+(i))
|
#define CK_Pipe_Block(i) (1000+(i))
|
||||||
#define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0 }
|
#define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0 }
|
||||||
#define CK_Macro(i) (2000+(i))
|
#define CK_Macro(i) (2000+(i))
|
||||||
#define CK_Last_Macro CK_Macro(0x7FFF)
|
#define CK_Last_Macro CK_Macro(0x7FFF)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define CK_User_Command(i) ((i) | (1 << 16))
|
#define CK_User_Command(i) ((i) | (1 << 16))
|
||||||
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
|
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
|
||||||
#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))
|
||||||
|
|
||||||
#endif /* MC_CMD_DEF_H */
|
#endif /* MC_CMD_DEF_H */
|
||||||
|
@ -264,9 +264,11 @@ 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 { \
|
#define cursor_to(x, y) \
|
||||||
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
|
do \
|
||||||
fflush(stdout); \
|
{ \
|
||||||
|
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
|
||||||
|
fflush(stdout); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -72,27 +72,28 @@ do { \
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define FILE_READ_BUF 4096
|
#define FILE_READ_BUF 4096
|
||||||
#define FILE_FLAG_TEMP (1 << 0)
|
#define FILE_FLAG_TEMP (1 << 0)
|
||||||
|
|
||||||
#define OPTX 56
|
#define OPTX 56
|
||||||
#define OPTY 17
|
#define OPTY 17
|
||||||
|
|
||||||
#define ADD_CH '+'
|
#define ADD_CH '+'
|
||||||
#define DEL_CH '-'
|
#define DEL_CH '-'
|
||||||
#define CHG_CH '*'
|
#define CHG_CH '*'
|
||||||
#define EQU_CH ' '
|
#define EQU_CH ' '
|
||||||
|
|
||||||
#define HDIFF_ENABLE 1
|
#define HDIFF_ENABLE 1
|
||||||
#define HDIFF_MINCTX 5
|
#define HDIFF_MINCTX 5
|
||||||
#define HDIFF_DEPTH 10
|
#define HDIFF_DEPTH 10
|
||||||
|
|
||||||
#define FILE_DIRTY(fs) \
|
|
||||||
do { \
|
|
||||||
(fs)->pos = 0; \
|
|
||||||
(fs)->len = 0; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
|
#define FILE_DIRTY(fs) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
(fs)->pos = 0; \
|
||||||
|
(fs)->len = 0; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
/*** file scope type declarations ****************************************************************/
|
/*** file scope type declarations ****************************************************************/
|
||||||
|
|
||||||
@ -3306,34 +3307,42 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
|||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------- */
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
|
||||||
#define GET_FILE_AND_STAMP(n) \
|
#define GET_FILE_AND_STAMP(n) \
|
||||||
do { \
|
do \
|
||||||
use_copy##n = 0; \
|
{ \
|
||||||
real_file##n = file##n; \
|
use_copy##n = 0; \
|
||||||
if (!vfs_file_is_local(file##n)) { \
|
real_file##n = file##n; \
|
||||||
real_file##n = mc_getlocalcopy(file##n); \
|
if (!vfs_file_is_local (file##n)) \
|
||||||
if (real_file##n != NULL) { \
|
{ \
|
||||||
use_copy##n = 1; \
|
real_file##n = mc_getlocalcopy (file##n); \
|
||||||
if (mc_stat(real_file##n, &st##n) != 0) { \
|
if (real_file##n != NULL) \
|
||||||
use_copy##n = -1; \
|
{ \
|
||||||
} \
|
use_copy##n = 1; \
|
||||||
} \
|
if (mc_stat (real_file##n, &st##n) != 0) \
|
||||||
} \
|
use_copy##n = -1; \
|
||||||
} while (0)
|
} \
|
||||||
#define UNGET_FILE(n) \
|
} \
|
||||||
do { \
|
} \
|
||||||
if (use_copy##n) { \
|
while (0)
|
||||||
int changed = 0; \
|
|
||||||
if (use_copy##n > 0) { \
|
#define UNGET_FILE(n) \
|
||||||
time_t mtime = st##n.st_mtime; \
|
do \
|
||||||
if (mc_stat(real_file##n, &st##n) == 0) { \
|
{ \
|
||||||
changed = (mtime != st##n.st_mtime); \
|
if (use_copy##n) \
|
||||||
} \
|
{ \
|
||||||
} \
|
int changed = 0; \
|
||||||
mc_ungetlocalcopy(file##n, real_file##n, changed); \
|
if (use_copy##n > 0) \
|
||||||
g_free(real_file##n); \
|
{ \
|
||||||
} \
|
time_t mtime; \
|
||||||
} while (0)
|
mtime = st##n.st_mtime; \
|
||||||
|
if (mc_stat (real_file##n, &st##n) == 0) \
|
||||||
|
changed = (mtime != st##n.st_mtime); \
|
||||||
|
} \
|
||||||
|
mc_ungetlocalcopy (file##n, real_file##n, changed); \
|
||||||
|
g_free (real_file##n); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
void
|
void
|
||||||
dview_diff_cmd (void)
|
dview_diff_cmd (void)
|
||||||
|
@ -95,26 +95,26 @@
|
|||||||
#define START_STACK_SIZE 32
|
#define START_STACK_SIZE 32
|
||||||
|
|
||||||
/* Some codes that may be pushed onto or returned from the undo stack */
|
/* Some codes that may be pushed onto or returned from the undo stack */
|
||||||
#define CURS_LEFT 601
|
#define CURS_LEFT 601
|
||||||
#define CURS_RIGHT 602
|
#define CURS_RIGHT 602
|
||||||
#define DELCHAR 603
|
#define DELCHAR 603
|
||||||
#define BACKSPACE 604
|
#define BACKSPACE 604
|
||||||
#define STACK_BOTTOM 605
|
#define STACK_BOTTOM 605
|
||||||
#define CURS_LEFT_LOTS 606
|
#define CURS_LEFT_LOTS 606
|
||||||
#define CURS_RIGHT_LOTS 607
|
#define CURS_RIGHT_LOTS 607
|
||||||
#define COLUMN_ON 608
|
#define COLUMN_ON 608
|
||||||
#define COLUMN_OFF 609
|
#define COLUMN_OFF 609
|
||||||
#define MARK_1 1000
|
#define MARK_1 1000
|
||||||
#define MARK_2 700000000
|
#define MARK_2 700000000
|
||||||
#define KEY_PRESS 1400000000
|
#define KEY_PRESS 1400000000
|
||||||
|
|
||||||
/* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
|
/* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
|
||||||
#define TAB_SIZE option_tab_spacing
|
#define TAB_SIZE option_tab_spacing
|
||||||
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
|
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
|
||||||
|
|
||||||
/* max count stack files */
|
/* max count stack files */
|
||||||
#define MAX_HISTORY_MOVETO 50
|
#define MAX_HISTORY_MOVETO 50
|
||||||
#define LINE_STATE_WIDTH 8
|
#define LINE_STATE_WIDTH 8
|
||||||
|
|
||||||
/* search/replace options */
|
/* search/replace options */
|
||||||
typedef struct edit_search_options_t
|
typedef struct edit_search_options_t
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
#include <sys/types.h> /* size_t */
|
#include <sys/types.h> /* size_t */
|
||||||
#include "lib/global.h" /* include <glib.h> */
|
#include "lib/global.h" /* include <glib.h> */
|
||||||
|
|
||||||
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
|
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
|
||||||
#define MAX_DEFINITIONS 60 /* count found entries show */
|
#define MAX_DEFINITIONS 60 /* count found entries show */
|
||||||
#define SHORT_DEF_LEN 30
|
#define SHORT_DEF_LEN 30
|
||||||
#define LONG_DEF_LEN 40
|
#define LONG_DEF_LEN 40
|
||||||
#define LINE_DEF_LEN 16
|
#define LINE_DEF_LEN 16
|
||||||
|
@ -7,9 +7,9 @@
|
|||||||
#define MC_EXECUTE_H
|
#define MC_EXECUTE_H
|
||||||
|
|
||||||
/* flags for shell_execute */
|
/* flags for shell_execute */
|
||||||
#define EXECUTE_INTERNAL (1 << 0)
|
#define EXECUTE_INTERNAL (1 << 0)
|
||||||
#define EXECUTE_AS_SHELL (1 << 2)
|
#define EXECUTE_AS_SHELL (1 << 2)
|
||||||
#define EXECUTE_HIDE (1 << 3)
|
#define EXECUTE_HIDE (1 << 3)
|
||||||
|
|
||||||
/* Execute functions that use the shell to execute */
|
/* Execute functions that use the shell to execute */
|
||||||
void shell_execute (const char *command, int flags);
|
void shell_execute (const char *command, int flags);
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#define MC_HELP_H
|
#define MC_HELP_H
|
||||||
|
|
||||||
/* Markers used in the help files */
|
/* Markers used in the help files */
|
||||||
#define CHAR_LINK_START '\01' /* Ctrl-A */
|
#define CHAR_LINK_START '\01' /* Ctrl-A */
|
||||||
#define CHAR_LINK_POINTER '\02' /* Ctrl-B */
|
#define CHAR_LINK_POINTER '\02' /* Ctrl-B */
|
||||||
#define CHAR_LINK_END '\03' /* Ctrl-C */
|
#define CHAR_LINK_END '\03' /* Ctrl-C */
|
||||||
#define CHAR_NODE_END '\04' /* Ctrl-D */
|
#define CHAR_NODE_END '\04' /* Ctrl-D */
|
||||||
|
@ -3,46 +3,46 @@
|
|||||||
* \brief Header: defines history section names
|
* \brief Header: defines history section names
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MC_HISTORY_H
|
#ifndef MC_HISTORY_H
|
||||||
#define __MC_HISTORY_H
|
#define MC_HISTORY_H
|
||||||
|
|
||||||
/* history section names */
|
/* history section names */
|
||||||
|
|
||||||
#define MC_HISTORY_EDIT_SAVE_AS "mc.edit.save-as"
|
#define MC_HISTORY_EDIT_SAVE_AS "mc.edit.save-as"
|
||||||
#define MC_HISTORY_EDIT_LOAD "mc.edit.load"
|
#define MC_HISTORY_EDIT_LOAD "mc.edit.load"
|
||||||
#define MC_HISTORY_EDIT_SAVE_BLOCK "mc.edit.save-block"
|
#define MC_HISTORY_EDIT_SAVE_BLOCK "mc.edit.save-block"
|
||||||
#define MC_HISTORY_EDIT_INSERT_FILE "mc.edit.insert-file"
|
#define MC_HISTORY_EDIT_INSERT_FILE "mc.edit.insert-file"
|
||||||
#define MC_HISTORY_EDIT_GOTO_LINE "mc.edit.goto-line"
|
#define MC_HISTORY_EDIT_GOTO_LINE "mc.edit.goto-line"
|
||||||
#define MC_HISTORY_EDIT_SORT "mc.edit.sort"
|
#define MC_HISTORY_EDIT_SORT "mc.edit.sort"
|
||||||
#define MC_HISTORY_EDIT_PASTE_EXTCMD "mc.edit.paste-extcmd"
|
#define MC_HISTORY_EDIT_PASTE_EXTCMD "mc.edit.paste-extcmd"
|
||||||
|
|
||||||
#define MC_HISTORY_FM_VIEW_FILE "mc.fm.view-file"
|
#define MC_HISTORY_FM_VIEW_FILE "mc.fm.view-file"
|
||||||
#define MC_HISTORY_FM_MKDIR "mc.fm.mkdir"
|
#define MC_HISTORY_FM_MKDIR "mc.fm.mkdir"
|
||||||
#define MC_HISTORY_FM_LINK "mc.fm.link"
|
#define MC_HISTORY_FM_LINK "mc.fm.link"
|
||||||
#define MC_HISTORY_FM_EDIT_LINK "mc.fm.edit-link"
|
#define MC_HISTORY_FM_EDIT_LINK "mc.fm.edit-link"
|
||||||
#define MC_HISTORY_FM_TREE_COPY "mc.fm.tree-copy"
|
#define MC_HISTORY_FM_TREE_COPY "mc.fm.tree-copy"
|
||||||
#define MC_HISTORY_FM_TREE_MOVE "mc.fm.tree-move"
|
#define MC_HISTORY_FM_TREE_MOVE "mc.fm.tree-move"
|
||||||
#define MC_HISTORY_FM_PANELIZE_ADD "mc.fm.panelize.add"
|
#define MC_HISTORY_FM_PANELIZE_ADD "mc.fm.panelize.add"
|
||||||
#define MC_HISTORY_FM_FILTERED_VIEW "mc.fm.filtered-view"
|
#define MC_HISTORY_FM_FILTERED_VIEW "mc.fm.filtered-view"
|
||||||
#define MC_HISTORY_FM_PANEL_FILTER "mc.fm.panel-filter"
|
#define MC_HISTORY_FM_PANEL_FILTER "mc.fm.panel-filter"
|
||||||
#define MC_HISTORY_FM_MENU_EXEC_PARAM "mc.fm.menu.exec.parameter"
|
#define MC_HISTORY_FM_MENU_EXEC_PARAM "mc.fm.menu.exec.parameter"
|
||||||
|
|
||||||
#define MC_HISTORY_ESC_TIMEOUT "mc.esc.timeout"
|
#define MC_HISTORY_ESC_TIMEOUT "mc.esc.timeout"
|
||||||
|
|
||||||
#define MC_HISTORY_VIEW_GOTO "mc.view.goto"
|
#define MC_HISTORY_VIEW_GOTO "mc.view.goto"
|
||||||
#define MC_HISTORY_VIEW_GOTO_LINE "mc.view.goto-line"
|
#define MC_HISTORY_VIEW_GOTO_LINE "mc.view.goto-line"
|
||||||
#define MC_HISTORY_VIEW_GOTO_ADDR "mc.view.goto-addr"
|
#define MC_HISTORY_VIEW_GOTO_ADDR "mc.view.goto-addr"
|
||||||
#define MC_HISTORY_VIEW_SEARCH_REGEX "mc.view.search.regex"
|
#define MC_HISTORY_VIEW_SEARCH_REGEX "mc.view.search.regex"
|
||||||
|
|
||||||
#define MC_HISTORY_FTPFS_ACCOUNT "mc.vfs.ftp.account"
|
#define MC_HISTORY_FTPFS_ACCOUNT "mc.vfs.ftp.account"
|
||||||
#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password"
|
#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password"
|
||||||
|
|
||||||
#define MC_HISTORY_EXT_PARAMETER "mc.ext.parameter"
|
#define MC_HISTORY_EXT_PARAMETER "mc.ext.parameter"
|
||||||
|
|
||||||
#define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add"
|
#define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add"
|
||||||
|
|
||||||
#define MC_HISTORY_SHARED_SEARCH "mc.shared.search"
|
#define MC_HISTORY_SHARED_SEARCH "mc.shared.search"
|
||||||
|
|
||||||
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
|
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
|
||||||
|
|
||||||
#endif
|
#endif /* MC_HISTORY_H */
|
||||||
|
@ -65,22 +65,22 @@
|
|||||||
#define UY 2
|
#define UY 2
|
||||||
|
|
||||||
#define BX UX
|
#define BX UX
|
||||||
#define BY (LINES - 6)
|
#define BY (LINES - 6)
|
||||||
|
|
||||||
#define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
|
#define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
|
||||||
#define LABELS 3
|
#define LABELS 3
|
||||||
#define B_ADD_CURRENT B_USER
|
#define B_ADD_CURRENT B_USER
|
||||||
#define B_REMOVE (B_USER + 1)
|
#define B_REMOVE (B_USER + 1)
|
||||||
#define B_NEW_GROUP (B_USER + 2)
|
#define B_NEW_GROUP (B_USER + 2)
|
||||||
#define B_NEW_ENTRY (B_USER + 3)
|
#define B_NEW_ENTRY (B_USER + 3)
|
||||||
#define B_UP_GROUP (B_USER + 4)
|
#define B_UP_GROUP (B_USER + 4)
|
||||||
#define B_INSERT (B_USER + 5)
|
#define B_INSERT (B_USER + 5)
|
||||||
#define B_APPEND (B_USER + 6)
|
#define B_APPEND (B_USER + 6)
|
||||||
#define B_MOVE (B_USER + 7)
|
#define B_MOVE (B_USER + 7)
|
||||||
|
|
||||||
#ifdef ENABLE_VFS
|
#ifdef ENABLE_VFS
|
||||||
#define B_FREE_ALL_VFS (B_USER + 8)
|
#define B_FREE_ALL_VFS (B_USER + 8)
|
||||||
#define B_REFRESH_VFS (B_USER + 9)
|
#define B_REFRESH_VFS (B_USER + 9)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int hotlist_has_dot_dot = 1;
|
int hotlist_has_dot_dot = 1;
|
||||||
@ -232,13 +232,15 @@ update_path_name (void)
|
|||||||
dlg_redraw (dlg);
|
dlg_redraw (dlg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_BUFFER \
|
#define CHECK_BUFFER \
|
||||||
do { \
|
do \
|
||||||
int i; \
|
{ \
|
||||||
\
|
size_t i; \
|
||||||
if ((i = strlen (current->label) + 3) > buflen) { \
|
i = strlen (current->label); \
|
||||||
|
if (i + 3 > buflen) { \
|
||||||
g_free (buf); \
|
g_free (buf); \
|
||||||
buf = g_malloc (buflen = 1024 * (i/1024 + 1)); \
|
buflen = 1024 * (i/1024 + 1); \
|
||||||
|
buf = g_malloc (buflen); \
|
||||||
} \
|
} \
|
||||||
buf[0] = '\0'; \
|
buf[0] = '\0'; \
|
||||||
} while (0)
|
} while (0)
|
||||||
@ -933,9 +935,9 @@ static int
|
|||||||
add_new_entry_input (const char *header, const char *text1, const char *text2,
|
add_new_entry_input (const char *header, const char *text1, const char *text2,
|
||||||
const char *help, char **r1, char **r2)
|
const char *help, char **r1, char **r2)
|
||||||
{
|
{
|
||||||
#define RELATIVE_Y_BUTTONS 4
|
#define RELATIVE_Y_BUTTONS 4
|
||||||
#define RELATIVE_Y_LABEL_PTH 3
|
#define RELATIVE_Y_LABEL_PTH 3
|
||||||
#define RELATIVE_Y_INPUT_PTH 4
|
#define RELATIVE_Y_INPUT_PTH 4
|
||||||
|
|
||||||
QuickWidget quick_widgets[] = {
|
QuickWidget quick_widgets[] = {
|
||||||
/* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), B_CANCEL, NULL),
|
/* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), B_CANCEL, NULL),
|
||||||
@ -1278,11 +1280,11 @@ load_group (struct hotlist *grp)
|
|||||||
#define TKN_ENTRY 1
|
#define TKN_ENTRY 1
|
||||||
#define TKN_STRING 2
|
#define TKN_STRING 2
|
||||||
#define TKN_URL 3
|
#define TKN_URL 3
|
||||||
#define TKN_ENDGROUP 4
|
#define TKN_ENDGROUP 4
|
||||||
#define TKN_COMMENT 5
|
#define TKN_COMMENT 5
|
||||||
#define TKN_EOL 125
|
#define TKN_EOL 125
|
||||||
#define TKN_EOF 126
|
#define TKN_EOF 126
|
||||||
#define TKN_UNKNOWN 127
|
#define TKN_UNKNOWN 127
|
||||||
|
|
||||||
static GString *tkn_buf = NULL;
|
static GString *tkn_buf = NULL;
|
||||||
|
|
||||||
@ -1384,19 +1386,21 @@ hot_next_token (void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SKIP_TO_EOL { \
|
#define SKIP_TO_EOL \
|
||||||
int _tkn; \
|
{ \
|
||||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
int _tkn; \
|
||||||
|
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_TOKEN(_TKN_) \
|
#define CHECK_TOKEN(_TKN_) \
|
||||||
tkn = hot_next_token (); \
|
tkn = hot_next_token (); \
|
||||||
if (tkn != _TKN_) { \
|
if (tkn != _TKN_) \
|
||||||
|
{ \
|
||||||
hotlist_state.readonly = 1; \
|
hotlist_state.readonly = 1; \
|
||||||
hotlist_state.file_error = 1; \
|
hotlist_state.file_error = 1; \
|
||||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||||
tkn = hot_next_token (); \
|
tkn = hot_next_token (); \
|
||||||
break; \
|
break; \
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
#ifndef MC_HOTLIST_H
|
#ifndef MC_HOTLIST_H
|
||||||
#define MC_HOTLIST_H
|
#define MC_HOTLIST_H
|
||||||
|
|
||||||
#define LIST_VFSLIST 0x01
|
#define LIST_VFSLIST 0x01
|
||||||
#define LIST_HOTLIST 0x02
|
#define LIST_HOTLIST 0x02
|
||||||
#define LIST_MOVELIST 0x04
|
#define LIST_MOVELIST 0x04
|
||||||
|
|
||||||
void add2hotlist_cmd (void);
|
void add2hotlist_cmd (void);
|
||||||
char *hotlist_cmd (int list_vfs);
|
char *hotlist_cmd (int list_vfs);
|
||||||
|
@ -17,7 +17,7 @@ typedef struct key_config_t {
|
|||||||
} key_config_t;
|
} key_config_t;
|
||||||
|
|
||||||
/* The global keymaps are of this type */
|
/* The global keymaps are of this type */
|
||||||
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
|
||||||
typedef struct global_keymap_t {
|
typedef struct global_keymap_t {
|
||||||
long key;
|
long key;
|
||||||
unsigned long command;
|
unsigned long command;
|
||||||
|
12
src/learn.c
12
src/learn.c
@ -49,15 +49,15 @@
|
|||||||
#include "learn.h"
|
#include "learn.h"
|
||||||
#include "wtools.h"
|
#include "wtools.h"
|
||||||
|
|
||||||
#define UX 4
|
#define UX 4
|
||||||
#define UY 3
|
#define UY 3
|
||||||
|
|
||||||
#define BY UY + 17
|
#define BY UY + 17
|
||||||
|
|
||||||
#define ROWS 13
|
#define ROWS 13
|
||||||
#define COLSHIFT 23
|
#define COLSHIFT 23
|
||||||
|
|
||||||
#define BUTTONS 2
|
#define BUTTONS 2
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int ret_cmd, flags, y, x;
|
int ret_cmd, flags, y, x;
|
||||||
|
@ -51,14 +51,14 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "listmode.h"
|
#include "listmode.h"
|
||||||
|
|
||||||
#define UX 5
|
#define UX 5
|
||||||
#define UY 2
|
#define UY 2
|
||||||
|
|
||||||
#define BX 5
|
#define BX 5
|
||||||
#define BY 18
|
#define BY 18
|
||||||
|
|
||||||
#define B_ADD B_USER
|
#define B_ADD B_USER
|
||||||
#define B_REMOVE (B_USER + 1)
|
#define B_REMOVE (B_USER + 1)
|
||||||
|
|
||||||
static WListbox *l_listmode;
|
static WListbox *l_listmode;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#define selection(p) (&(p->dir.list[p->selected]))
|
#define selection(p) (&(p->dir.list[p->selected]))
|
||||||
#define DEFAULT_USER_FORMAT "half type name | size | perm"
|
#define DEFAULT_USER_FORMAT "half type name | size | perm"
|
||||||
|
|
||||||
#define LIST_TYPES 4
|
#define LIST_TYPES 4
|
||||||
|
|
||||||
enum list_types {
|
enum list_types {
|
||||||
list_full, /* Name, size, perm/date */
|
list_full, /* Name, size, perm/date */
|
||||||
@ -116,9 +116,9 @@ void panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order);
|
|||||||
void panel_re_sort (WPanel *panel);
|
void panel_re_sort (WPanel *panel);
|
||||||
void panel_change_encoding (WPanel * panel);
|
void panel_change_encoding (WPanel * panel);
|
||||||
|
|
||||||
#define UP_OPTIMIZE 0
|
#define UP_OPTIMIZE 0
|
||||||
#define UP_RELOAD 1
|
#define UP_RELOAD 1
|
||||||
#define UP_ONLY_CURRENT 2
|
#define UP_ONLY_CURRENT 2
|
||||||
|
|
||||||
#define UP_KEEPSEL ((char *) -1)
|
#define UP_KEEPSEL ((char *) -1)
|
||||||
|
|
||||||
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
x
Ссылка в новой задаче
Block a user