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)*****************************************/
|
||||
|
||||
typedef struct mc_fhl_struct {
|
||||
typedef struct mc_fhl_struct
|
||||
{
|
||||
mc_config_t *config;
|
||||
GPtrArray *filters;
|
||||
} 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 *);
|
||||
void mc_fhl_clear (mc_fhl_t *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -82,12 +82,14 @@ mc_fhl_new (gboolean need_auto_fill)
|
||||
if (!need_auto_fill)
|
||||
return fhl;
|
||||
|
||||
if (!mc_fhl_init_from_standard_files (fhl)) {
|
||||
if (!mc_fhl_init_from_standard_files (fhl))
|
||||
{
|
||||
g_free (fhl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!mc_fhl_parse_ini_file (fhl)) {
|
||||
if (!mc_fhl_parse_ini_file (fhl))
|
||||
{
|
||||
mc_fhl_free (&fhl);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*inline functions*/
|
||||
/*inline functions */
|
||||
inline static gboolean
|
||||
mc_fhl_is_file (file_entry * fe)
|
||||
{
|
||||
@ -141,8 +141,8 @@ inline static gboolean
|
||||
mc_fhl_is_special (file_entry * fe)
|
||||
{
|
||||
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;
|
||||
(void) fhl;
|
||||
|
||||
switch (mc_filter->file_type) {
|
||||
switch (mc_filter->file_type)
|
||||
{
|
||||
case MC_FLHGH_FTYPE_T_FILE:
|
||||
if (mc_fhl_is_file (fe))
|
||||
my_color = TRUE;
|
||||
@ -254,9 +255,11 @@ mc_fhl_get_color (mc_fhl_t * fhl, file_entry * fe)
|
||||
if (fhl == NULL)
|
||||
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);
|
||||
switch (mc_filter->type) {
|
||||
switch (mc_filter->type)
|
||||
{
|
||||
case MC_FLHGH_T_FTYPE:
|
||||
ret = mc_fhl_get_color_filetype (mc_filter, fhl, fe);
|
||||
if (ret > 0)
|
||||
|
@ -77,12 +77,14 @@ mc_fhl_parse_get_file_type_id (mc_fhl_t * fhl, const gchar * group_name)
|
||||
int i;
|
||||
gchar *param_type = mc_config_get_string (fhl->config, group_name, "type", "");
|
||||
|
||||
if (*param_type == '\0') {
|
||||
if (*param_type == '\0')
|
||||
{
|
||||
g_free (param_type);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; types[i] != NULL; i++) {
|
||||
for (i = 0; types[i] != NULL; i++)
|
||||
{
|
||||
if (strcmp (types[i], param_type) == 0)
|
||||
break;
|
||||
}
|
||||
@ -107,7 +109,8 @@ mc_fhl_parse_get_regexp (mc_fhl_t * fhl, const gchar * group_name)
|
||||
mc_fhl_filter_t *mc_filter;
|
||||
gchar *regexp = mc_config_get_string (fhl->config, group_name, "regexp", "");
|
||||
|
||||
if (*regexp == '\0') {
|
||||
if (*regexp == '\0')
|
||||
{
|
||||
g_free (regexp);
|
||||
return FALSE;
|
||||
}
|
||||
@ -201,7 +204,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
||||
|
||||
/* ${datadir}/mc/filehighlight.ini */
|
||||
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);
|
||||
return FALSE;
|
||||
}
|
||||
@ -209,7 +213,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
||||
|
||||
/* ${sysconfdir}/mc/filehighlight.ini */
|
||||
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);
|
||||
return FALSE;
|
||||
}
|
||||
@ -218,7 +223,8 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl)
|
||||
/* ~/.mc/filehighlight.ini */
|
||||
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);
|
||||
return FALSE;
|
||||
}
|
||||
@ -242,17 +248,21 @@ mc_fhl_parse_ini_file (mc_fhl_t * fhl)
|
||||
if (group_names == NULL)
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
mc_fhl_parse_get_extensions (fhl, *group_names);
|
||||
}
|
||||
|
@ -5,13 +5,15 @@
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_FLHGH_T_FTYPE,
|
||||
MC_FLHGH_T_EXT,
|
||||
MC_FLHGH_T_FREGEXP
|
||||
} mc_flhgh_filter_type;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_FLHGH_FTYPE_T_FILE,
|
||||
MC_FLHGH_FTYPE_T_FILE_EXE,
|
||||
MC_FLHGH_FTYPE_T_DIR,
|
||||
@ -31,7 +33,8 @@ typedef enum {
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct mc_fhl_filter_struct {
|
||||
typedef struct mc_fhl_filter_struct
|
||||
{
|
||||
|
||||
int color_pair_index;
|
||||
gchar *fgcolor;
|
||||
@ -51,5 +54,5 @@ void mc_fhl_array_free (mc_fhl_t *);
|
||||
|
||||
gboolean mc_fhl_init_from_standard_files (mc_fhl_t *);
|
||||
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file fileloc.h
|
||||
* \brief Header: config files list
|
||||
*
|
||||
@ -14,11 +13,12 @@
|
||||
#ifndef MC_FILELOC_H
|
||||
#define MC_FILELOC_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#ifndef MC_USERCONF_DIR
|
||||
#define MC_USERCONF_DIR ".mc"
|
||||
#endif
|
||||
|
||||
|
||||
#define TAGS_NAME "TAGS"
|
||||
|
||||
#define MC_GLOBAL_CONFIG_FILE "mc.lib"
|
||||
@ -75,4 +75,14 @@
|
||||
#define EDIT_LOCAL_MENU ".cedit.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
|
||||
|
14
lib/fs.h
14
lib/fs.h
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file fs.h
|
||||
* \brief Header: fs compatibility definitions
|
||||
*/
|
||||
@ -11,7 +10,9 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Replacement for permission bits missing in sys/stat.h */
|
||||
#ifndef S_ISLNK
|
||||
@ -52,7 +53,6 @@
|
||||
#endif
|
||||
|
||||
/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
|
||||
#include <dirent.h>
|
||||
#define NLENGTH(dirent) (strlen ((dirent)->d_name))
|
||||
#define DIRENT_LENGTH_COMPUTED 1
|
||||
|
||||
@ -62,6 +62,16 @@
|
||||
# define MC_MAXFILENAMELEN MAXNAMLEN
|
||||
#endif
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
static inline void
|
||||
compute_namelen (struct dirent *dent __attribute__ ((unused)))
|
||||
{
|
||||
|
@ -21,7 +21,7 @@
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
/** \file glibcompat.c
|
||||
* \brief Source: compatibility with older versions of glib
|
||||
@ -53,7 +53,7 @@
|
||||
This is incomplete copy of same glib-function.
|
||||
For older glib (less than 2.13) functional is enought.
|
||||
For full version of glib welcome to glib update.
|
||||
*/
|
||||
*/
|
||||
gboolean
|
||||
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 **);
|
||||
#endif /* ! GLIB_CHECK_VERSION (2, 7, 0) */
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC_GLIBCOMPAT_H */
|
||||
|
79
lib/global.h
79
lib/global.h
@ -1,42 +1,42 @@
|
||||
|
||||
/** \file global.h
|
||||
* \brief Header: %global definitions for compatibility
|
||||
*
|
||||
* This file should be included after all system includes and before all local includes.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MC_GLOBAL_H
|
||||
#define MC_GLOBAL_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 */
|
||||
# if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
|
||||
# include <memory.h>
|
||||
# endif /* !STDC_HEADERS & HAVE_MEMORY_H */
|
||||
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
|
||||
#include <memory.h>
|
||||
#endif /* !STDC_HEADERS & HAVE_MEMORY_H */
|
||||
|
||||
#else /* !STDC_HEADERS & !HAVE_STRING_H */
|
||||
# include <strings.h>
|
||||
#include <strings.h>
|
||||
/* memory and strings.h conflict on other systems */
|
||||
#endif /* !STDC_HEADERS & !HAVE_STRING_H */
|
||||
|
||||
#ifdef HAVE_SYS_PARAM_H
|
||||
# include <sys/param.h>
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* The O_BINARY definition was taken from gettext */
|
||||
#if !defined O_BINARY && defined _O_BINARY
|
||||
/* For MSC-compatible compilers. */
|
||||
# define O_BINARY _O_BINARY
|
||||
#define O_BINARY _O_BINARY
|
||||
#endif
|
||||
#ifdef __BEOS__
|
||||
/* BeOS 5 has O_BINARY, but is has no effect. */
|
||||
# undef O_BINARY
|
||||
#undef O_BINARY
|
||||
#endif
|
||||
/* On reasonable systems, binary I/O is the default. */
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/* Replacement for O_NONBLOCK */
|
||||
@ -49,38 +49,38 @@
|
||||
#endif /* !O_NONBLOCK */
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#if defined(__QNX__) && !defined(__QNXNTO__)
|
||||
/* exec*() from <process.h> */
|
||||
# include <unix.h>
|
||||
#include <unix.h>
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
#include "glibcompat.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
# define __attribute__(x)
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# define _(String) gettext (String)
|
||||
# ifdef gettext_noop
|
||||
# define N_(String) gettext_noop (String)
|
||||
# else
|
||||
# define N_(String) (String)
|
||||
# endif
|
||||
#include <libintl.h>
|
||||
#define _(String) gettext (String)
|
||||
#ifdef gettext_noop
|
||||
#define N_(String) gettext_noop (String)
|
||||
#else
|
||||
#define N_(String) (String)
|
||||
#endif
|
||||
#else /* Stubs that do something close enough. */
|
||||
# define textdomain(String)
|
||||
# define gettext(String) (String)
|
||||
# define ngettext(String1,String2,Num) (((Num) == 1) ? (String1) : (String2))
|
||||
# define dgettext(Domain,Message) (Message)
|
||||
# define dcgettext(Domain,Message,Type) (Message)
|
||||
# define bindtextdomain(Domain,Directory)
|
||||
# define _(String) (String)
|
||||
# define N_(String) (String)
|
||||
#define textdomain(String)
|
||||
#define gettext(String) (String)
|
||||
#define ngettext(String1,String2,Num) (((Num) == 1) ? (String1) : (String2))
|
||||
#define dgettext(Domain,Message) (Message)
|
||||
#define dcgettext(Domain,Message,Type) (Message)
|
||||
#define bindtextdomain(Domain,Directory)
|
||||
#define _(String) (String)
|
||||
#define N_(String) (String)
|
||||
#endif /* !ENABLE_NLS */
|
||||
|
||||
#include "fs.h"
|
||||
@ -90,8 +90,6 @@
|
||||
#include "lib/logging.h"
|
||||
#endif
|
||||
|
||||
extern const char *home_dir;
|
||||
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
@ -114,8 +112,6 @@ extern const char *home_dir;
|
||||
#define BUF_SMALL 128
|
||||
#define BUF_TINY 64
|
||||
|
||||
void refresh_screen (void *);
|
||||
|
||||
/* AIX compiler doesn't understand '\e' */
|
||||
#define ESC_CHAR '\033'
|
||||
#define ESC_STR "\033"
|
||||
@ -125,14 +121,27 @@ void refresh_screen (void *);
|
||||
|
||||
#if 0
|
||||
#ifdef MC_ENABLE_DEBUGGING_CODE
|
||||
# undef NDEBUG
|
||||
#undef NDEBUG
|
||||
#else
|
||||
# define NDEBUG
|
||||
#define NDEBUG
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#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);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
39
lib/lock.c
39
lib/lock.c
@ -59,19 +59,30 @@
|
||||
|
||||
#include "src/wtools.h" /* query_dialog() */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define BUF_SIZE 255
|
||||
#define PID_BUF_SIZE 10
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct lock_s
|
||||
{
|
||||
char *who;
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** \fn static char * lock_build_name (void)
|
||||
* \brief builds user@host.domain.pid string (need to be freed)
|
||||
* \return a pointer to lock filename
|
||||
*/
|
||||
|
||||
static char *
|
||||
lock_build_name (void)
|
||||
{
|
||||
@ -98,6 +109,8 @@ lock_build_name (void)
|
||||
return g_strdup_printf ("%s@%s.%d", user, host, (int) getpid ());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
lock_build_symlink_name (const char *fname)
|
||||
{
|
||||
@ -116,7 +129,11 @@ lock_build_symlink_name (const char *fname)
|
||||
return symlink_name;
|
||||
}
|
||||
|
||||
/* Extract pid from user@host.domain.pid string */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Extract pid from user@host.domain.pid string
|
||||
*/
|
||||
|
||||
static struct lock_s *
|
||||
lock_extract_info (const char *str)
|
||||
{
|
||||
@ -148,7 +165,11 @@ lock_extract_info (const char *str)
|
||||
return &lock;
|
||||
}
|
||||
|
||||
/* Extract user@host.domain.pid from lock file (static string) */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Extract user@host.domain.pid from lock file (static string)
|
||||
*/
|
||||
|
||||
static char *
|
||||
lock_get_info (const char *lockfname)
|
||||
{
|
||||
@ -162,10 +183,14 @@ lock_get_info (const char *lockfname)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Tries to raise file lock
|
||||
Returns 1 on success, 0 on failure, -1 if abort
|
||||
Warning: Might do screen refresh and lose edit->force */
|
||||
|
||||
int
|
||||
lock_file (const char *fname)
|
||||
{
|
||||
@ -237,8 +262,12 @@ lock_file (const char *fname)
|
||||
return symlink_ok ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Lowers file lock if possible
|
||||
Always returns 0 */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Lowers file lock if possible
|
||||
* @returns Always 0
|
||||
*/
|
||||
|
||||
int
|
||||
unlock_file (const char *fname)
|
||||
{
|
||||
@ -279,3 +308,5 @@ unlock_file (const char *fname)
|
||||
g_free (lockfname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
12
lib/lock.h
12
lib/lock.h
@ -9,7 +9,19 @@
|
||||
#ifndef 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 unlock_file (const char *fname);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC_LOCK_H */
|
||||
|
@ -39,42 +39,61 @@
|
||||
|
||||
#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
|
||||
is_logging_enabled(void)
|
||||
is_logging_enabled (void)
|
||||
{
|
||||
static gboolean logging_initialized = 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);
|
||||
CONFIG_APP_SECTION, "development.enable_logging",
|
||||
FALSE);
|
||||
logging_initialized = TRUE;
|
||||
}
|
||||
return logging_enabled;
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
mc_log(const char *fmt, ...)
|
||||
mc_log (const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
FILE *f;
|
||||
char *logfilename;
|
||||
|
||||
if (is_logging_enabled()) {
|
||||
va_start(args, fmt);
|
||||
logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
||||
if (logfilename != NULL) {
|
||||
if (is_logging_enabled ())
|
||||
{
|
||||
va_start (args, fmt);
|
||||
logfilename = g_strdup_printf ("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
||||
if (logfilename != NULL)
|
||||
{
|
||||
f = fopen (logfilename, "a");
|
||||
if (f != NULL) {
|
||||
(void)vfprintf(f, fmt, args);
|
||||
(void)fclose(f);
|
||||
if (f != NULL)
|
||||
{
|
||||
(void) vfprintf (f, fmt, args);
|
||||
(void) fclose (f);
|
||||
}
|
||||
g_free(logfilename);
|
||||
va_end(args);
|
||||
g_free (logfilename);
|
||||
va_end (args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file logging.h
|
||||
* \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.
|
||||
*/
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define mc_log_mark() mc_log("%s:%d\n",__FILE__,__LINE__)
|
||||
|
||||
extern void mc_log(const char *, ...)
|
||||
__attribute__((__format__(__printf__,1,2)));
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** 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
|
||||
|
@ -9,7 +9,8 @@
|
||||
|
||||
/*** structures declarations (and typedefs of structures)***************/
|
||||
|
||||
typedef struct mc_config_struct {
|
||||
typedef struct mc_config_struct
|
||||
{
|
||||
GKeyFile *handle;
|
||||
gchar *ini_path;
|
||||
} 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_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,
|
||||
GError **error);
|
||||
gboolean mc_config_save_to_file (mc_config_t * config, const gchar * filename, GError ** error);
|
||||
|
||||
/* mcconfig/get.c: */
|
||||
|
||||
@ -64,26 +64,21 @@ int *mc_config_get_int_list (mc_config_t *, const gchar *, const gchar *, gsize
|
||||
|
||||
/* mcconfig/set.c: */
|
||||
|
||||
void
|
||||
mc_config_direct_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||
void mc_config_direct_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||
|
||||
void
|
||||
mc_config_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||
void mc_config_set_string (mc_config_t *, const gchar *, const gchar *, const gchar *);
|
||||
|
||||
void
|
||||
mc_config_set_bool (mc_config_t *, const gchar *, const gchar *, gboolean);
|
||||
void 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_string_list (mc_config_t *, const gchar *,
|
||||
mc_config_set_string_list (mc_config_t *, const gchar *,
|
||||
const gchar *, const gchar * const[], gsize);
|
||||
|
||||
void
|
||||
mc_config_set_bool_list (mc_config_t *, const gchar *, const gchar *, gboolean[], gsize);
|
||||
void mc_config_set_bool_list (mc_config_t *, const gchar *, const gchar *, gboolean[], gsize);
|
||||
|
||||
void
|
||||
mc_config_set_int_list (mc_config_t *, const gchar *, const gchar *, int[], gsize);
|
||||
void mc_config_set_int_list (mc_config_t *, const gchar *, const gchar *, int[], gsize);
|
||||
|
||||
|
||||
/* mcconfig/dialog.c: */
|
||||
|
@ -46,7 +46,7 @@ mc_config_get_groups (mc_config_t * mc_config, gsize * len)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
if (len != NULL)
|
||||
*len=0;
|
||||
*len = 0;
|
||||
return ret;
|
||||
}
|
||||
ret = g_key_file_get_groups (mc_config->handle, len);
|
||||
@ -68,7 +68,7 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
|
||||
{
|
||||
ret = g_try_malloc0 (sizeof (gchar **));
|
||||
if (len != NULL)
|
||||
*len=0;
|
||||
*len = 0;
|
||||
return ret;
|
||||
}
|
||||
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
|
||||
@ -88,12 +88,12 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group,
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
gchar *ret;
|
||||
const char *_system_codepage = str_detect_termencoding();
|
||||
const char *_system_codepage = str_detect_termencoding ();
|
||||
|
||||
if (!mc_config || !group || !param)
|
||||
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 : "");
|
||||
return def ? g_strdup (def) : NULL;
|
||||
@ -115,15 +115,15 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group,
|
||||
|
||||
if (str_convert (conv, ret, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free(buffer, TRUE);
|
||||
g_string_free (buffer, TRUE);
|
||||
str_close_conv (conv);
|
||||
return ret;
|
||||
}
|
||||
str_close_conv (conv);
|
||||
|
||||
g_free(ret);
|
||||
g_free (ret);
|
||||
|
||||
return g_string_free(buffer, FALSE);
|
||||
return g_string_free (buffer, FALSE);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -137,7 +137,7 @@ mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param)
|
||||
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 : "");
|
||||
return def ? g_strdup (def) : NULL;
|
||||
@ -154,13 +154,12 @@ mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
gboolean
|
||||
mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
|
||||
const gchar * param, gboolean def)
|
||||
mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
|
||||
{
|
||||
if (!mc_config || !group || !param)
|
||||
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);
|
||||
return def;
|
||||
@ -172,13 +171,12 @@ mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
int
|
||||
mc_config_get_int (mc_config_t * mc_config, const gchar * group,
|
||||
const gchar * param, int def)
|
||||
mc_config_get_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int def)
|
||||
{
|
||||
if (!mc_config || !group || !param)
|
||||
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);
|
||||
return def;
|
||||
@ -197,8 +195,7 @@ mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param)
|
||||
return NULL;
|
||||
|
||||
return g_key_file_get_string_list (mc_config->handle, group, param,
|
||||
length, NULL);
|
||||
return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -210,8 +207,7 @@ mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param)
|
||||
return NULL;
|
||||
|
||||
return g_key_file_get_boolean_list (mc_config->handle, group, param,
|
||||
length, NULL);
|
||||
return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -223,8 +219,7 @@ mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param)
|
||||
return NULL;
|
||||
|
||||
return g_key_file_get_integer_list (mc_config->handle, group, param,
|
||||
length, NULL);
|
||||
return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
@ -37,33 +37,33 @@ extern int utf8_display;
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
static gchar *
|
||||
mc_config_normalize_before_save(const gchar * value)
|
||||
mc_config_normalize_before_save (const gchar * value)
|
||||
{
|
||||
GIConv conv;
|
||||
GString *buffer;
|
||||
|
||||
if (utf8_display)
|
||||
{
|
||||
buffer = g_string_new(value);
|
||||
buffer = g_string_new (value);
|
||||
}
|
||||
else
|
||||
{
|
||||
conv = str_crt_conv_to ("UTF-8");
|
||||
if (conv == INVALID_CONV)
|
||||
return g_strdup(value);
|
||||
return g_strdup (value);
|
||||
|
||||
buffer = g_string_new ("");
|
||||
|
||||
if (str_convert (conv, value, buffer) == ESTR_FAILURE)
|
||||
{
|
||||
g_string_free(buffer, TRUE);
|
||||
buffer = g_string_new(value);
|
||||
g_string_free (buffer, TRUE);
|
||||
buffer = g_string_new (value);
|
||||
}
|
||||
|
||||
str_close_conv (conv);
|
||||
}
|
||||
|
||||
return g_string_free(buffer, FALSE);
|
||||
return g_string_free (buffer, FALSE);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -79,11 +79,11 @@ mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param || !value)
|
||||
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_free(buffer);
|
||||
g_free (buffer);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -97,11 +97,11 @@ mc_config_set_string (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param || !value)
|
||||
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_free(buffer);
|
||||
g_free (buffer);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -110,7 +110,7 @@ void
|
||||
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
||||
const gchar * param, gboolean value)
|
||||
{
|
||||
if (!mc_config || !group || !param )
|
||||
if (!mc_config || !group || !param)
|
||||
return;
|
||||
|
||||
g_key_file_set_boolean (mc_config->handle, group, param, value);
|
||||
@ -119,10 +119,9 @@ mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
void
|
||||
mc_config_set_int (mc_config_t * mc_config, const gchar * group,
|
||||
const gchar * param, int value)
|
||||
mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
|
||||
{
|
||||
if (!mc_config || !group || !param )
|
||||
if (!mc_config || !group || !param)
|
||||
return;
|
||||
|
||||
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
|
||||
mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
|
||||
const gchar * param, const gchar * const value[],
|
||||
gsize length)
|
||||
const gchar * param, const gchar * const value[], gsize length)
|
||||
{
|
||||
if (!mc_config || !group || !param || !value || length == 0)
|
||||
return;
|
||||
|
||||
g_key_file_set_string_list (mc_config->handle, group, param, value,
|
||||
length);
|
||||
g_key_file_set_string_list (mc_config->handle, group, param, value, length);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -153,8 +150,7 @@ mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param || !value || length == 0)
|
||||
return;
|
||||
|
||||
g_key_file_set_boolean_list (mc_config->handle, group, param, value,
|
||||
length);
|
||||
g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
@ -166,8 +162,7 @@ mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
|
||||
if (!mc_config || !group || !param || !value || length == 0)
|
||||
return;
|
||||
|
||||
g_key_file_set_integer_list (mc_config->handle, group, param, value,
|
||||
length);
|
||||
g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
|
||||
}
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
31
lib/search.h
31
lib/search.h
@ -8,7 +8,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef SEARCH_TYPE_PCRE
|
||||
# include <pcre.h>
|
||||
#include <pcre.h>
|
||||
#endif
|
||||
|
||||
/*** 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
|
||||
|
||||
#ifdef SEARCH_TYPE_GLIB
|
||||
# define mc_search_matchinfo_t GMatchInfo
|
||||
#define mc_search_matchinfo_t GMatchInfo
|
||||
#else
|
||||
# define mc_search_matchinfo_t pcre_extra
|
||||
#define mc_search_matchinfo_t pcre_extra
|
||||
#endif
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_SEARCH_E_OK,
|
||||
MC_SEARCH_E_INPUT,
|
||||
MC_SEARCH_E_REGEX_COMPILE,
|
||||
@ -34,14 +35,16 @@ typedef enum {
|
||||
MC_SEARCH_E_NOTFOUND
|
||||
} mc_search_error_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_SEARCH_T_NORMAL,
|
||||
MC_SEARCH_T_REGEX,
|
||||
MC_SEARCH_T_HEX,
|
||||
MC_SEARCH_T_GLOB
|
||||
} mc_search_type_t;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
MC_SEARCH_CB_OK = 0,
|
||||
MC_SEARCH_CB_INVALID = -1,
|
||||
MC_SEARCH_CB_ABORT = -2,
|
||||
@ -51,9 +54,10 @@ typedef enum {
|
||||
|
||||
/*** 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 */
|
||||
gboolean is_all_charsets;
|
||||
@ -80,7 +84,7 @@ typedef struct mc_search_struct {
|
||||
mc_search_type_t search_type;
|
||||
|
||||
|
||||
/* public output data */
|
||||
/* public output data */
|
||||
|
||||
/* some data for normal */
|
||||
off_t normal_offset;
|
||||
@ -94,7 +98,7 @@ typedef struct mc_search_struct {
|
||||
int iovector[MC_SEARCH__NUM_REPLACE_ARGS * 2];
|
||||
#endif /* SEARCH_TYPE_PCRE */
|
||||
|
||||
/* private data */
|
||||
/* private data */
|
||||
|
||||
/* prepared conditions */
|
||||
GPtrArray *conditions;
|
||||
@ -109,7 +113,8 @@ typedef struct mc_search_struct {
|
||||
|
||||
} mc_search_t;
|
||||
|
||||
typedef struct mc_search_type_str_struct {
|
||||
typedef struct mc_search_type_str_struct
|
||||
{
|
||||
const char *str;
|
||||
mc_search_type_t type;
|
||||
} 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);
|
||||
|
||||
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);
|
||||
char *mc_search_prepare_replace_str2 (mc_search_t *, char *);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
COND__NOT_FOUND,
|
||||
COND__NOT_ALL_FOUND,
|
||||
COND__FOUND_CHAR,
|
||||
@ -22,7 +23,8 @@ typedef enum {
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct mc_search_cond_struct {
|
||||
typedef struct mc_search_cond_struct
|
||||
{
|
||||
GString *str;
|
||||
GString *upper;
|
||||
GString *lower;
|
||||
@ -32,12 +34,12 @@ typedef struct mc_search_cond_struct {
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern const char * STR_E_NOTFOUND;
|
||||
extern const char * STR_E_UNKNOWN_TYPE;
|
||||
extern const char * STR_E_RPL_NOT_EQ_TO_FOUND;
|
||||
extern const char * STR_E_RPL_INVALID_TOKEN;
|
||||
/*** declarations of public functions ************************************************************/
|
||||
extern const char *STR_E_NOTFOUND;
|
||||
extern const char *STR_E_UNKNOWN_TYPE;
|
||||
extern const char *STR_E_RPL_NOT_EQ_TO_FOUND;
|
||||
extern const char *STR_E_RPL_INVALID_TOKEN;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/* 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 *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif
|
||||
|
@ -39,10 +39,11 @@
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
const char * STR_E_NOTFOUND = N_("Search string not found");
|
||||
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_INVALID_TOKEN = N_("Invalid token number %d");
|
||||
const char *STR_E_NOTFOUND = N_("Search string not found");
|
||||
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_INVALID_TOKEN = N_("Invalid token number %d");
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
@ -62,13 +63,15 @@ mc_search__recode_str (const char *str, gsize str_len,
|
||||
gsize bytes_read;
|
||||
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;
|
||||
return g_strndup (str, str_len);
|
||||
}
|
||||
|
||||
conv = g_iconv_open (charset_to, charset_from);
|
||||
if (conv == INVALID_CONV) {
|
||||
if (conv == INVALID_CONV)
|
||||
{
|
||||
*bytes_written = 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);
|
||||
g_iconv_close (conv);
|
||||
|
||||
if (ret == NULL) {
|
||||
if (ret == NULL)
|
||||
{
|
||||
*bytes_written = 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 =
|
||||
mc_search__recode_str (converted_str, tmp_len, cp_display, charset, &converted_str_len);
|
||||
#endif
|
||||
if (just_letters) {
|
||||
if (just_letters)
|
||||
{
|
||||
if (str_isalnum (converted_str) && !str_isdigit (converted_str))
|
||||
*just_letters = TRUE;
|
||||
else
|
||||
@ -250,7 +255,7 @@ mc_search__toupper_case_str (const char *charset, const char *str, gsize str_len
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gchar **
|
||||
mc_search_get_types_strings_array (size_t *num)
|
||||
mc_search_get_types_strings_array (size_t * num)
|
||||
{
|
||||
gchar **ret;
|
||||
int lc_index;
|
||||
@ -263,9 +268,7 @@ mc_search_get_types_strings_array (size_t *num)
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
for (lc_index = 0, type_str = types_str;
|
||||
type_str->str != NULL;
|
||||
type_str++, lc_index++)
|
||||
for (lc_index = 0, type_str = types_str; type_str->str != NULL; type_str++, lc_index++)
|
||||
ret[lc_index] = g_strdup (type_str->str);
|
||||
|
||||
/* don't count last NULL item */
|
||||
|
@ -58,7 +58,8 @@ typedef enum
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
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;
|
||||
gsize spec_chr_len;
|
||||
@ -194,7 +195,7 @@ mc_search__cond_struct_new_regex_accum_append (const char *charset, GString * st
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
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]);
|
||||
loop++;
|
||||
@ -317,7 +319,7 @@ mc_search_regex__get_max_num_of_replace_tokens (const gchar * str, gsize len)
|
||||
gsize 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]))
|
||||
continue;
|
||||
@ -418,7 +420,7 @@ mc_search_regex__process_replace_str (const GString * replace_str, const gsize c
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( g_ascii_isdigit(*(curr_str + 1)))
|
||||
if (g_ascii_isdigit (*(curr_str + 1)))
|
||||
{
|
||||
ret = g_ascii_digit_value (*(curr_str + 1));
|
||||
*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;
|
||||
}
|
||||
|
||||
static void
|
||||
mc_search_regex__process_append_str (GString * dest_str, const char *from, gsize len,
|
||||
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->charset = g_strdup (charset);
|
||||
|
||||
switch (lc_mc_search->search_type) {
|
||||
switch (lc_mc_search->search_type)
|
||||
{
|
||||
case MC_SEARCH_T_GLOB:
|
||||
mc_search__cond_struct_new_init_glob (charset, lc_mc_search, mc_search_cond);
|
||||
break;
|
||||
@ -117,7 +118,8 @@ mc_search__conditions_free (GPtrArray * array)
|
||||
gsize loop1;
|
||||
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);
|
||||
mc_search__cond_struct_free (lc_mc_search);
|
||||
}
|
||||
@ -137,7 +139,8 @@ mc_search_new (const gchar * original, gsize str_len)
|
||||
if (!original)
|
||||
return NULL;
|
||||
|
||||
if ((gssize) str_len == -1) {
|
||||
if ((gssize) str_len == -1)
|
||||
{
|
||||
str_len = strlen (original);
|
||||
if (str_len == 0)
|
||||
return NULL;
|
||||
@ -184,30 +187,37 @@ mc_search_prepare (mc_search_t * lc_mc_search)
|
||||
GPtrArray *ret;
|
||||
ret = g_ptr_array_new ();
|
||||
#ifdef HAVE_CHARSET
|
||||
if (lc_mc_search->is_all_charsets) {
|
||||
if (lc_mc_search->is_all_charsets)
|
||||
{
|
||||
gsize loop1, recoded_str_len;
|
||||
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;
|
||||
if (!g_ascii_strcasecmp (id, cp_source)) {
|
||||
if (!g_ascii_strcasecmp (id, cp_source))
|
||||
{
|
||||
g_ptr_array_add (ret,
|
||||
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;
|
||||
}
|
||||
|
||||
buffer =
|
||||
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len, cp_source,
|
||||
id, &recoded_str_len);
|
||||
mc_search__recode_str (lc_mc_search->original, lc_mc_search->original_len,
|
||||
cp_source, id, &recoded_str_len);
|
||||
|
||||
g_ptr_array_add (ret,
|
||||
mc_search__cond_struct_new (lc_mc_search, buffer,
|
||||
recoded_str_len, id));
|
||||
g_free (buffer);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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,
|
||||
cp_source));
|
||||
}
|
||||
@ -232,13 +242,15 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
||||
|
||||
if (!lc_mc_search)
|
||||
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_str = g_strdup (_(STR_E_UNKNOWN_TYPE));
|
||||
return FALSE;
|
||||
}
|
||||
#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);
|
||||
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;
|
||||
|
||||
|
||||
switch (lc_mc_search->search_type) {
|
||||
switch (lc_mc_search->search_type)
|
||||
{
|
||||
case MC_SEARCH_T_NORMAL:
|
||||
ret = mc_search__run_normal (lc_mc_search, user_data, start_search, end_search, found_len);
|
||||
break;
|
||||
@ -276,7 +289,8 @@ mc_search_run (mc_search_t * lc_mc_search, const void *user_data,
|
||||
gboolean
|
||||
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_NORMAL:
|
||||
case MC_SEARCH_T_REGEX:
|
||||
@ -291,7 +305,7 @@ mc_search_is_type_avail (mc_search_type_t search_type)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
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 */
|
||||
if (num != NULL)
|
||||
@ -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)
|
||||
return g_string_new ("");
|
||||
|
||||
switch (lc_mc_search->search_type) {
|
||||
switch (lc_mc_search->search_type)
|
||||
{
|
||||
case MC_SEARCH_T_REGEX:
|
||||
ret = mc_search_regex_prepare_replace_str (lc_mc_search, replace_str);
|
||||
break;
|
||||
@ -354,7 +369,8 @@ mc_search_is_fixed_search_str (mc_search_t * lc_mc_search)
|
||||
{
|
||||
if (lc_mc_search == NULL)
|
||||
return FALSE;
|
||||
switch (lc_mc_search->search_type) {
|
||||
switch (lc_mc_search->search_type)
|
||||
{
|
||||
case MC_SEARCH_T_REGEX:
|
||||
case MC_SEARCH_T_GLOB:
|
||||
return FALSE;
|
||||
|
@ -12,7 +12,7 @@
|
||||
/* Beware! When using Slang with color, not all the indexes are free.
|
||||
See color-slang.h (A_*) */
|
||||
|
||||
/* cache often used colors*/
|
||||
/* cache often used colors */
|
||||
#define DEFAULT_COLOR mc_skin_color__cache[0]
|
||||
#define NORMAL_COLOR mc_skin_color__cache[1]
|
||||
#define MARKED_COLOR mc_skin_color__cache[2]
|
||||
@ -102,7 +102,8 @@
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct mc_skin_struct {
|
||||
typedef struct mc_skin_struct
|
||||
{
|
||||
gchar *name;
|
||||
gchar *description;
|
||||
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 *);
|
||||
|
||||
gchar *mc_skin_get(const gchar *, const gchar *, const gchar *);
|
||||
gchar *mc_skin_get (const gchar *, const gchar *, const gchar *);
|
||||
|
||||
#endif /* MC_SKIN_H */
|
||||
|
@ -85,8 +85,7 @@ mc_skin_reinit (void)
|
||||
mc_skin_deinit ();
|
||||
mc_skin__default.name = mc_skin_get_default_name ();
|
||||
mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
mc_skin_hash_destroy_value);
|
||||
g_free, mc_skin_hash_destroy_value);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -97,7 +96,8 @@ mc_skin_try_to_load_default (void)
|
||||
mc_skin_reinit ();
|
||||
g_free (mc_skin__default.name);
|
||||
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_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.colors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free,
|
||||
mc_skin_hash_destroy_value);
|
||||
g_free, 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,
|
||||
_("Unable to load '%s' skin.\nDefault skin has been loaded"),
|
||||
mc_skin__default.name);
|
||||
@ -129,7 +129,8 @@ mc_skin_init (GError ** error)
|
||||
}
|
||||
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)
|
||||
*error = g_error_new (MC_ERROR, 0,
|
||||
_("Unable to parse '%s' skin.\nDefault skin has been loaded"),
|
||||
@ -166,12 +167,13 @@ mc_skin_deinit (void)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
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) {
|
||||
return g_strdup(default_value);
|
||||
if (mc_args__ugly_line_drawing)
|
||||
{
|
||||
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;
|
||||
|
||||
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);
|
||||
g_free (file_name);
|
||||
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);
|
||||
g_free (file_name2);
|
||||
|
||||
if (exist_file (file_name)) {
|
||||
if (exist_file (file_name))
|
||||
{
|
||||
mc_skin->config = mc_config_init (file_name);
|
||||
g_free (file_name);
|
||||
return (mc_skin->config != NULL);
|
||||
@ -84,7 +86,8 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
||||
if (file_name == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (strcmp (file_name, mc_skin->name) != 0) {
|
||||
if (strcmp (file_name, mc_skin->name) != 0)
|
||||
{
|
||||
g_free (file_name);
|
||||
if (!g_path_is_absolute (mc_skin->name))
|
||||
return FALSE;
|
||||
@ -95,7 +98,8 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin)
|
||||
|
||||
/* ~/.mc/skins/ */
|
||||
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);
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct mc_skin_color_struct {
|
||||
typedef struct mc_skin_color_struct
|
||||
{
|
||||
gchar *fgcolor;
|
||||
gchar *bgcolor;
|
||||
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 *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
161
lib/strutil.h
161
lib/strutil.h
@ -36,17 +36,28 @@
|
||||
* 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
|
||||
*/
|
||||
typedef enum {
|
||||
/* success means, that convertion has been finished successully
|
||||
typedef enum
|
||||
{
|
||||
/* success means, that convertion has been finished successully
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
ESTR_FAILURE = 2
|
||||
@ -54,7 +65,8 @@ typedef enum {
|
||||
|
||||
/* alignment strings on terminal
|
||||
*/
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
J_LEFT = 0x01,
|
||||
J_RIGHT = 0x02,
|
||||
J_CENTER = 0x03,
|
||||
@ -68,11 +80,63 @@ typedef enum {
|
||||
J_CENTER_LEFT_FIT = 0x14
|
||||
} 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 */
|
||||
extern GIConv str_cnv_to_term;
|
||||
@ -80,58 +144,7 @@ extern GIConv str_cnv_from_term;
|
||||
/* from terminal encoding to terminal encoding */
|
||||
extern GIConv str_cnv_not_convert;
|
||||
|
||||
/* 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*/
|
||||
};
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
struct str_class str_utf8_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
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
void
|
||||
str_printf (GString *, const char *, ...);
|
||||
void str_printf (GString *, const char *, ...);
|
||||
|
||||
/* add standard replacement character in terminal encoding
|
||||
*/
|
||||
@ -324,23 +336,23 @@ int str_iscombiningmark (const char *ch);
|
||||
* decrase remain by size of returned characters
|
||||
* 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
|
||||
* decrase remain by size of returned characters
|
||||
* 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
|
||||
* I
|
||||
*/
|
||||
int str_length (const char* text);
|
||||
int str_length (const char *text);
|
||||
|
||||
/* return length of text in characters, limit to size
|
||||
* I
|
||||
*/
|
||||
int str_length2 (const char* text, int size);
|
||||
int str_length2 (const char *text, int size);
|
||||
|
||||
/* return length of one char
|
||||
* I
|
||||
@ -350,13 +362,13 @@ int str_length_char (const char *);
|
||||
/* return length of text in characters, count only noncombining characters
|
||||
* I
|
||||
*/
|
||||
int str_length_noncomb (const char* text);
|
||||
int str_length_noncomb (const char *text);
|
||||
|
||||
/* replace all invalid characters in text with questionmark
|
||||
* after return, text is valid string in terminal encoding
|
||||
* I
|
||||
*/
|
||||
void str_fix_string (char* text);
|
||||
void str_fix_string (char *text);
|
||||
|
||||
/* replace all invalid characters in text with questionmark
|
||||
* 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
|
||||
* 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
|
||||
* I
|
||||
@ -508,5 +520,8 @@ int str_isutf8 (const char *codeset_name);
|
||||
|
||||
const char *str_detect_termencoding (void);
|
||||
|
||||
int str_verscmp(const char *s1, const char *s2);
|
||||
#endif /* MC_STRUTIL_H*/
|
||||
int str_verscmp (const char *s1, const char *s2);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC_STRUTIL_H */
|
||||
|
@ -40,7 +40,7 @@ static const char *str_utf8_encodings[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* standard 8bit encodings, no wide or multibytes characters*/
|
||||
/* standard 8bit encodings, no wide or multibytes characters */
|
||||
static const char *str_8bit_encodings[] = {
|
||||
"cp-1251",
|
||||
"cp1251",
|
||||
@ -60,16 +60,16 @@ static const char *str_8bit_encodings[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
/* terminal encoding*/
|
||||
/* terminal encoding */
|
||||
static char *codeset = NULL;
|
||||
/* function for encoding specific operations*/
|
||||
/* function for encoding specific operations */
|
||||
static struct str_class used_class;
|
||||
|
||||
GIConv str_cnv_to_term;
|
||||
GIConv str_cnv_from_term;
|
||||
GIConv str_cnv_not_convert;
|
||||
|
||||
/* if enc is same encoding like on terminal*/
|
||||
/* if enc is same encoding like on terminal */
|
||||
static int
|
||||
str_test_not_convert (const char *enc)
|
||||
{
|
||||
@ -79,8 +79,7 @@ str_test_not_convert (const char *enc)
|
||||
GIConv
|
||||
str_crt_conv_to (const char *to_enc)
|
||||
{
|
||||
return (!str_test_not_convert (to_enc))
|
||||
? g_iconv_open (to_enc, codeset) : str_cnv_not_convert;
|
||||
return (!str_test_not_convert (to_enc)) ? g_iconv_open (to_enc, codeset) : str_cnv_not_convert;
|
||||
}
|
||||
|
||||
GIConv
|
||||
@ -114,12 +113,12 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
if (string == NULL || buffer == NULL)
|
||||
return ESTR_FAILURE;
|
||||
|
||||
/*
|
||||
/*
|
||||
if (! used_class.is_valid_string (string))
|
||||
{
|
||||
return ESTR_FAILURE;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
if (size < 0)
|
||||
{
|
||||
size = strlen (string);
|
||||
@ -137,10 +136,7 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
while (left)
|
||||
{
|
||||
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
||||
left,
|
||||
coder,
|
||||
&bytes_read,
|
||||
&bytes_written, &error);
|
||||
left, coder, &bytes_read, &bytes_written, &error);
|
||||
if (error)
|
||||
{
|
||||
int code = error->code;
|
||||
@ -162,8 +158,7 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
if ((tmp_buff == NULL) && (bytes_read != 0))
|
||||
/* recode valid byte sequence */
|
||||
tmp_buff = g_convert_with_iconv ((const gchar *) string,
|
||||
bytes_read,
|
||||
coder, NULL, NULL, NULL);
|
||||
bytes_read, coder, NULL, NULL, NULL);
|
||||
|
||||
if (tmp_buff != NULL)
|
||||
{
|
||||
@ -171,12 +166,12 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
g_free (tmp_buff);
|
||||
}
|
||||
|
||||
if ((int)bytes_read < left)
|
||||
if ((int) bytes_read < left)
|
||||
{
|
||||
string += bytes_read + 1;
|
||||
size -= (bytes_read + 1);
|
||||
left -= (bytes_read + 1);
|
||||
g_string_append_c (buffer, *(string-1));
|
||||
g_string_append_c (buffer, *(string - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -189,7 +184,7 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
/* Partial character sequence at end of input. */
|
||||
g_string_append (buffer, tmp_buff);
|
||||
g_free (tmp_buff);
|
||||
if ((int)bytes_read < left)
|
||||
if ((int) bytes_read < left)
|
||||
{
|
||||
left = left - bytes_read;
|
||||
tmp_buff = g_strnfill (left, '?');
|
||||
@ -247,7 +242,7 @@ str_nconvert (GIConv coder, const char *string, int size, GString * buffer)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -269,8 +264,7 @@ str_vfs_convert_from (GIConv coder, const char *string, GString * buffer)
|
||||
}
|
||||
|
||||
estr_t
|
||||
str_vfs_convert_to (GIConv coder, const char *string, int size,
|
||||
GString * buffer)
|
||||
str_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||
{
|
||||
return used_class.vfs_convert_to (coder, string, size, buffer);
|
||||
}
|
||||
@ -287,7 +281,7 @@ str_printf (GString * buffer, const char *format, ...)
|
||||
gchar *tmp;
|
||||
tmp = g_strdup_vprintf (format, ap);
|
||||
g_string_append (buffer, tmp);
|
||||
g_free(tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
#endif
|
||||
va_end (ap);
|
||||
@ -300,8 +294,7 @@ str_insert_replace_char (GString * buffer)
|
||||
}
|
||||
|
||||
estr_t
|
||||
str_translate_char (GIConv conv, const char *keys, size_t ch_size,
|
||||
char *output, size_t out_size)
|
||||
str_translate_char (GIConv conv, const char *keys, size_t ch_size, char *output, size_t out_size)
|
||||
{
|
||||
size_t left;
|
||||
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;
|
||||
|
||||
cnv = g_iconv (conv, (gchar **) &keys, &left, &output, &out_size);
|
||||
if (cnv == (size_t)(-1)) {
|
||||
cnv = g_iconv (conv, (gchar **) & keys, &left, &output, &out_size);
|
||||
if (cnv == (size_t) (-1))
|
||||
{
|
||||
return (errno == EINVAL) ? ESTR_PROBLEM : ESTR_FAILURE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
output[0] = '\0';
|
||||
return ESTR_SUCCESS;
|
||||
}
|
||||
@ -331,13 +327,12 @@ str_test_encoding_class (const char *encoding, const char **table)
|
||||
{
|
||||
int t;
|
||||
int result = 0;
|
||||
if ( encoding == NULL )
|
||||
if (encoding == NULL)
|
||||
return result;
|
||||
|
||||
for (t = 0; table[t] != NULL; t++)
|
||||
{
|
||||
result += (g_ascii_strncasecmp (encoding, table[t],
|
||||
strlen (table[t])) == 0);
|
||||
result += (g_ascii_strncasecmp (encoding, table[t], strlen (table[t])) == 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -373,9 +368,7 @@ str_isutf8 (const char *codeset_name)
|
||||
void
|
||||
str_init_strings (const char *termenc)
|
||||
{
|
||||
codeset = g_strdup ((termenc != NULL)
|
||||
? termenc
|
||||
: str_detect_termencoding ());
|
||||
codeset = g_strdup ((termenc != NULL) ? termenc : str_detect_termencoding ());
|
||||
|
||||
str_cnv_not_convert = g_iconv_open (codeset, codeset);
|
||||
if (str_cnv_not_convert == INVALID_CONV)
|
||||
@ -450,7 +443,7 @@ str_get_next_char (char *text)
|
||||
const char *
|
||||
str_cget_next_char (const char *text)
|
||||
{
|
||||
used_class.cnext_char(&text);
|
||||
used_class.cnext_char (&text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@ -607,7 +600,7 @@ str_length (const char *text)
|
||||
int
|
||||
str_length_char (const char *text)
|
||||
{
|
||||
return str_cget_next_char_safe (text)-text;
|
||||
return str_cget_next_char_safe (text) - text;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -52,24 +52,21 @@ static inline int char_##func_name(char c) \
|
||||
return func_name((int)(unsigned char)c); \
|
||||
}
|
||||
|
||||
DECLARE_CTYPE_WRAPPER(isalnum)
|
||||
DECLARE_CTYPE_WRAPPER(isalpha)
|
||||
DECLARE_CTYPE_WRAPPER(isascii)
|
||||
DECLARE_CTYPE_WRAPPER(isblank)
|
||||
DECLARE_CTYPE_WRAPPER(iscntrl)
|
||||
DECLARE_CTYPE_WRAPPER(isdigit)
|
||||
DECLARE_CTYPE_WRAPPER(isgraph)
|
||||
DECLARE_CTYPE_WRAPPER(islower)
|
||||
DECLARE_CTYPE_WRAPPER(isprint)
|
||||
DECLARE_CTYPE_WRAPPER(ispunct)
|
||||
DECLARE_CTYPE_WRAPPER(isspace)
|
||||
DECLARE_CTYPE_WRAPPER(isupper)
|
||||
DECLARE_CTYPE_WRAPPER(isxdigit)
|
||||
DECLARE_CTYPE_WRAPPER(toupper)
|
||||
DECLARE_CTYPE_WRAPPER(tolower)
|
||||
|
||||
static void
|
||||
str_8bit_insert_replace_char (GString * buffer)
|
||||
DECLARE_CTYPE_WRAPPER (isalnum)
|
||||
DECLARE_CTYPE_WRAPPER (isalpha)
|
||||
DECLARE_CTYPE_WRAPPER (isascii)
|
||||
DECLARE_CTYPE_WRAPPER (isblank)
|
||||
DECLARE_CTYPE_WRAPPER (iscntrl)
|
||||
DECLARE_CTYPE_WRAPPER (isdigit)
|
||||
DECLARE_CTYPE_WRAPPER (isgraph)
|
||||
DECLARE_CTYPE_WRAPPER (islower)
|
||||
DECLARE_CTYPE_WRAPPER (isprint)
|
||||
DECLARE_CTYPE_WRAPPER (ispunct)
|
||||
DECLARE_CTYPE_WRAPPER (isspace)
|
||||
DECLARE_CTYPE_WRAPPER (isupper)
|
||||
DECLARE_CTYPE_WRAPPER (isxdigit) DECLARE_CTYPE_WRAPPER (toupper) DECLARE_CTYPE_WRAPPER (tolower)
|
||||
static void
|
||||
str_8bit_insert_replace_char (GString * buffer)
|
||||
{
|
||||
g_string_append_c (buffer, replch);
|
||||
}
|
||||
@ -193,11 +190,11 @@ str_8bit_length (const char *text)
|
||||
static int
|
||||
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 *
|
||||
str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
||||
str_8bit_conv_gerror_message (GError * error, const char *def_msg)
|
||||
{
|
||||
GIConv conv;
|
||||
gchar *ret;
|
||||
@ -207,15 +204,19 @@ str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
||||
|
||||
if (conv == INVALID_CONV)
|
||||
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
||||
else {
|
||||
else
|
||||
{
|
||||
GString *buf;
|
||||
|
||||
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;
|
||||
g_string_free (buf, FALSE);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = g_strdup (def_msg != NULL ? def_msg : "");
|
||||
g_string_free (buf, TRUE);
|
||||
}
|
||||
@ -227,8 +228,7 @@ str_8bit_conv_gerror_message (GError *error, const char *def_msg)
|
||||
}
|
||||
|
||||
static estr_t
|
||||
str_8bit_vfs_convert_to (GIConv coder, const char *string,
|
||||
int size, GString * buffer)
|
||||
str_8bit_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||
{
|
||||
estr_t result;
|
||||
|
||||
@ -280,7 +280,7 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
actual = result;
|
||||
remain = sizeof (result);
|
||||
|
||||
if ((int)length <= width)
|
||||
if ((int) length <= width)
|
||||
{
|
||||
ident = 0;
|
||||
switch (HIDE_FIT (just_mode))
|
||||
@ -294,7 +294,7 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int)remain <= ident)
|
||||
if ((int) remain <= ident)
|
||||
goto finally;
|
||||
memset (actual, ' ', ident);
|
||||
actual += ident;
|
||||
@ -317,8 +317,7 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
{
|
||||
if (IS_FIT (just_mode))
|
||||
{
|
||||
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] : '.';
|
||||
@ -351,8 +350,7 @@ str_8bit_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
}
|
||||
|
||||
pos += ident;
|
||||
for (; pos < (gsize)(ident + width) && remain > 1;
|
||||
pos++, actual++, remain--)
|
||||
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
|
||||
{
|
||||
|
||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||
@ -378,7 +376,7 @@ str_8bit_term_trim (const char *text, int width)
|
||||
actual = result;
|
||||
remain = sizeof (result);
|
||||
|
||||
if (width < (int)length)
|
||||
if (width < (int) length)
|
||||
{
|
||||
if (width <= 3)
|
||||
{
|
||||
@ -415,8 +413,7 @@ str_8bit_term_trim (const char *text, int width)
|
||||
static int
|
||||
str_8bit_term_width2 (const char *text, size_t length)
|
||||
{
|
||||
return (length != (size_t) (-1))
|
||||
? min (strlen (text), length) : strlen (text);
|
||||
return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -443,7 +440,7 @@ str_8bit_msg_term_size (const char *text, int *lines, int *columns)
|
||||
|
||||
(*lines) = 1;
|
||||
(*columns) = 0;
|
||||
tmp = g_strdup ((char *)text);
|
||||
tmp = g_strdup ((char *) text);
|
||||
p = tmp;
|
||||
for (;;)
|
||||
{
|
||||
@ -480,11 +477,10 @@ str_8bit_term_substring (const char *text, int start, int width)
|
||||
remain = sizeof (result);
|
||||
length = strlen (text);
|
||||
|
||||
if (start < (int)length)
|
||||
if (start < (int) length)
|
||||
{
|
||||
pos += start;
|
||||
for (; pos < length && width > 0 && remain > 1;
|
||||
pos++, width--, actual++, remain--)
|
||||
for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--)
|
||||
{
|
||||
|
||||
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
|
||||
@ -513,9 +509,9 @@ str_8bit_trunc (const char *text, int width)
|
||||
remain = sizeof (result);
|
||||
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] : '.';
|
||||
}
|
||||
@ -557,7 +553,7 @@ static int
|
||||
str_8bit_column_to_pos (const char *text, size_t pos)
|
||||
{
|
||||
(void) text;
|
||||
return (int)pos;
|
||||
return (int) pos;
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -677,15 +673,15 @@ str_8bit_casecmp (const char *s1, const char *s2)
|
||||
/* According to A. Cox, some platforms have islower's that
|
||||
* don't work right on non-uppercase
|
||||
*/
|
||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
||||
c1 = isupper ((guchar) * s1) ? tolower ((guchar) * s1) : *s1;
|
||||
c2 = isupper ((guchar) * s2) ? tolower ((guchar) * s2) : *s2;
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
|
||||
return (((gint)(guchar) *s1) - ((gint)(guchar) *s2));
|
||||
return (((gint) (guchar) * s1) - ((gint) (guchar) * s2));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -712,8 +708,8 @@ str_8bit_ncasecmp (const char *s1, const char *s2)
|
||||
/* According to A. Cox, some platforms have islower's that
|
||||
* don't work right on non-uppercase
|
||||
*/
|
||||
c1 = isupper ((guchar) *s1) ? tolower ((guchar) *s1) : *s1;
|
||||
c2 = isupper ((guchar) *s2) ? tolower ((guchar) *s2) : *s2;
|
||||
c1 = isupper ((guchar) * s1) ? tolower ((guchar) * s1) : *s1;
|
||||
c2 = isupper ((guchar) * s2) ? tolower ((guchar) * s2) : *s2;
|
||||
if (c1 != c2)
|
||||
return (c1 - c2);
|
||||
s1++;
|
||||
@ -721,7 +717,7 @@ str_8bit_ncasecmp (const char *s1, const char *s2)
|
||||
}
|
||||
|
||||
if (n != 0)
|
||||
return (((gint) (guchar) *s1) - ((gint) (guchar) *s2));
|
||||
return (((gint) (guchar) * s1) - ((gint) (guchar) * s2));
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
|
@ -165,7 +165,7 @@ str_ascii_length2 (const char *text, int size)
|
||||
}
|
||||
|
||||
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() */
|
||||
if ((error != NULL) && (error->message != NULL))
|
||||
@ -175,8 +175,7 @@ str_ascii_conv_gerror_message (GError *error, const char *def_msg)
|
||||
}
|
||||
|
||||
static estr_t
|
||||
str_ascii_vfs_convert_to (GIConv coder, const char *string,
|
||||
int size, GString * buffer)
|
||||
str_ascii_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||
{
|
||||
(void) coder;
|
||||
g_string_append_len (buffer, string, size);
|
||||
@ -222,7 +221,7 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
actual = result;
|
||||
remain = sizeof (result);
|
||||
|
||||
if ((int)length <= width)
|
||||
if ((int) length <= width)
|
||||
{
|
||||
ident = 0;
|
||||
switch (HIDE_FIT (just_mode))
|
||||
@ -237,14 +236,14 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
}
|
||||
|
||||
/* add space before text */
|
||||
if ((int)remain <= ident)
|
||||
if ((int) remain <= ident)
|
||||
goto finally;
|
||||
memset (actual, ' ', ident);
|
||||
actual += ident;
|
||||
remain -= ident;
|
||||
|
||||
/* 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] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
@ -265,13 +264,10 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
if (IS_FIT (just_mode))
|
||||
{
|
||||
/* copy prefix of text, that is not wider than width / 2 */
|
||||
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] = g_ascii_isprint ((gchar) actual[0])
|
||||
? actual[0] : '.';
|
||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
}
|
||||
|
||||
if (remain <= 1)
|
||||
@ -285,10 +281,8 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
/* copy suffix of text */
|
||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||
{
|
||||
actual[0] = isascii ((unsigned char) text[pos])
|
||||
? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||
? actual[0] : '.';
|
||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -307,13 +301,10 @@ str_ascii_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
/* copy substring text, substring start from ident and take width
|
||||
* characters from text */
|
||||
pos += ident;
|
||||
for (; pos < (gsize)(ident + width) && remain > 1;
|
||||
pos++, actual++, remain--)
|
||||
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
|
||||
{
|
||||
actual[0] = isascii ((unsigned char) text[pos])
|
||||
? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||
? actual[0] : '.';
|
||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
}
|
||||
|
||||
}
|
||||
@ -336,7 +327,7 @@ str_ascii_term_trim (const char *text, int width)
|
||||
actual = result;
|
||||
remain = sizeof (result);
|
||||
|
||||
if (width < (int)length)
|
||||
if (width < (int) length)
|
||||
{
|
||||
if (width <= 3)
|
||||
{
|
||||
@ -355,10 +346,8 @@ str_ascii_term_trim (const char *text, int width)
|
||||
/* copy suffix of text */
|
||||
for (; pos < length && remain > 1; pos++, actual++, remain--)
|
||||
{
|
||||
actual[0] = isascii ((unsigned char) text[pos])
|
||||
? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0])
|
||||
? actual[0] : '.';
|
||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,8 +368,7 @@ str_ascii_term_trim (const char *text, int width)
|
||||
static int
|
||||
str_ascii_term_width2 (const char *text, size_t length)
|
||||
{
|
||||
return (length != (size_t) (-1))
|
||||
? min (strlen (text), length) : strlen (text);
|
||||
return (length != (size_t) (-1)) ? min (strlen (text), length) : strlen (text);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -445,12 +433,11 @@ str_ascii_term_substring (const char *text, int start, int width)
|
||||
remain = sizeof (result);
|
||||
length = strlen (text);
|
||||
|
||||
if (start < (int)length)
|
||||
if (start < (int) length)
|
||||
{
|
||||
pos += start;
|
||||
/* copy at most width characters from text from start */
|
||||
for (; pos < length && width > 0 && remain > 1;
|
||||
pos++, width--, actual++, remain--)
|
||||
for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--)
|
||||
{
|
||||
|
||||
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
|
||||
@ -481,10 +468,10 @@ str_ascii_trunc (const char *text, int width)
|
||||
remain = sizeof (result);
|
||||
length = strlen (text);
|
||||
|
||||
if ((int)length > width)
|
||||
if ((int) length > width)
|
||||
{
|
||||
/* 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] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
|
||||
@ -531,7 +518,7 @@ static int
|
||||
str_ascii_column_to_pos (const char *text, size_t pos)
|
||||
{
|
||||
(void) text;
|
||||
return (int)pos;
|
||||
return (int) pos;
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -670,8 +657,7 @@ str_ascii_caseprefix (const char *text, const char *prefix)
|
||||
{
|
||||
int result;
|
||||
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
|
||||
&& g_ascii_toupper (text[result]) ==
|
||||
g_ascii_toupper (prefix[result]); result++);
|
||||
&& g_ascii_toupper (text[result]) == g_ascii_toupper (prefix[result]); result++);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,7 @@ str_unichar_iscombiningmark (gunichar uni)
|
||||
{
|
||||
int type = g_unichar_type (uni);
|
||||
return (type == G_UNICODE_COMBINING_MARK)
|
||||
|| (type == G_UNICODE_ENCLOSING_MARK)
|
||||
|| (type == G_UNICODE_NON_SPACING_MARK);
|
||||
|| (type == G_UNICODE_ENCLOSING_MARK) || (type == G_UNICODE_NON_SPACING_MARK);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -319,19 +318,20 @@ str_utf8_length_noncomb (const char *text)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
static void
|
||||
str_utf8_questmark_sustb (char **string, size_t * left, GString * buffer)
|
||||
{
|
||||
static void
|
||||
str_utf8_questmark_sustb (char **string, size_t * left, GString * buffer)
|
||||
{
|
||||
char *next = g_utf8_next_char (*string);
|
||||
(*left) -= next - (*string);
|
||||
(*string) = next;
|
||||
g_string_append_c (buffer, '?');
|
||||
}
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
||||
static gchar *
|
||||
str_utf8_conv_gerror_message (GError *error, const char *def_msg)
|
||||
str_utf8_conv_gerror_message (GError * error, const char *def_msg)
|
||||
{
|
||||
if ((error != NULL) && (error->message != NULL))
|
||||
return g_strdup (error->message);
|
||||
@ -340,8 +340,7 @@ str_utf8_conv_gerror_message (GError *error, const char *def_msg)
|
||||
}
|
||||
|
||||
static estr_t
|
||||
str_utf8_vfs_convert_to (GIConv coder, const char *string,
|
||||
int size, GString * buffer)
|
||||
str_utf8_vfs_convert_to (GIConv coder, const char *string, int size, GString * buffer)
|
||||
{
|
||||
estr_t result;
|
||||
|
||||
@ -395,30 +394,43 @@ str_utf8_make_make_term_form (const char *text, size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
while (length != 0 && text[0] != '\0') {
|
||||
while (length != 0 && text[0] != '\0')
|
||||
{
|
||||
uni = g_utf8_get_char_validated (text, -1);
|
||||
if ((uni != (gunichar)(-1)) && (uni != (gunichar)(-2))) {
|
||||
if (g_unichar_isprint(uni)) {
|
||||
if ((uni != (gunichar) (-1)) && (uni != (gunichar) (-2)))
|
||||
{
|
||||
if (g_unichar_isprint (uni))
|
||||
{
|
||||
left = g_unichar_to_utf8 (uni, actual);
|
||||
actual+= left;
|
||||
if (!str_unichar_iscombiningmark (uni)) {
|
||||
actual += left;
|
||||
if (!str_unichar_iscombiningmark (uni))
|
||||
{
|
||||
result.width++;
|
||||
if (g_unichar_iswide(uni)) result.width++;
|
||||
} else result.compose = 1;
|
||||
} else {
|
||||
if (g_unichar_iswide (uni))
|
||||
result.width++;
|
||||
}
|
||||
else
|
||||
result.compose = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
actual[0] = '.';
|
||||
actual++;
|
||||
result.width++;
|
||||
}
|
||||
text = g_utf8_next_char (text);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
text++;
|
||||
/*actual[0] = '?';*/
|
||||
/*actual[0] = '?'; */
|
||||
memcpy (actual, replch, strlen (replch));
|
||||
actual+= strlen (replch);
|
||||
actual += strlen (replch);
|
||||
result.width++;
|
||||
}
|
||||
if (length != (size_t) (-1)) length--; }
|
||||
if (length != (size_t) (-1))
|
||||
length--;
|
||||
}
|
||||
actual[0] = '\0';
|
||||
|
||||
return &result;
|
||||
@ -434,9 +446,7 @@ str_utf8_term_form (const char *text)
|
||||
pre_form = str_utf8_make_make_term_form (text, (size_t) (-1));
|
||||
if (pre_form->compose)
|
||||
{
|
||||
composed =
|
||||
g_utf8_normalize (pre_form->text, -1,
|
||||
G_NORMALIZE_DEFAULT_COMPOSE);
|
||||
composed = g_utf8_normalize (pre_form->text, -1, G_NORMALIZE_DEFAULT_COMPOSE);
|
||||
g_strlcpy (result, composed, sizeof (result));
|
||||
g_free (composed);
|
||||
}
|
||||
@ -576,8 +586,7 @@ utf8_tool_skip_chars_to (struct utf8_tool *tool, int to_ident)
|
||||
static void
|
||||
utf8_tool_compose (char *buffer, size_t size)
|
||||
{
|
||||
char *composed =
|
||||
g_utf8_normalize (buffer, -1, G_NORMALIZE_DEFAULT_COMPOSE);
|
||||
char *composed = g_utf8_normalize (buffer, -1, G_NORMALIZE_DEFAULT_COMPOSE);
|
||||
g_strlcpy (buffer, composed, size);
|
||||
g_free (composed);
|
||||
}
|
||||
@ -596,7 +605,7 @@ str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
tool.remain = sizeof (result);
|
||||
tool.compose = 0;
|
||||
|
||||
if (pre_form->width <= (gsize)width)
|
||||
if (pre_form->width <= (gsize) width)
|
||||
{
|
||||
tool.ident = 0;
|
||||
switch (HIDE_FIT (just_mode))
|
||||
@ -625,9 +634,7 @@ str_utf8_fit_to_term (const char *text, int width, align_crt_t just_mode)
|
||||
tool.ident = 0;
|
||||
utf8_tool_skip_chars_to (&tool, pre_form->width - width + 1);
|
||||
utf8_tool_copy_chars_to_end (&tool);
|
||||
utf8_tool_insert_space (&tool,
|
||||
width - (pre_form->width - tool.ident +
|
||||
1));
|
||||
utf8_tool_insert_space (&tool, width - (pre_form->width - tool.ident + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -669,7 +676,7 @@ str_utf8_term_trim (const char *text, int width)
|
||||
tool.remain = sizeof (result);
|
||||
tool.compose = 0;
|
||||
|
||||
if ((gsize)width < pre_form->width)
|
||||
if ((gsize) width < pre_form->width)
|
||||
{
|
||||
if (width <= 3)
|
||||
{
|
||||
@ -718,8 +725,7 @@ static int
|
||||
str_utf8_term_char_width (const char *text)
|
||||
{
|
||||
gunichar uni = g_utf8_get_char_validated (text, -1);
|
||||
return (str_unichar_iscombiningmark (uni)) ? 0
|
||||
: ((g_unichar_iswide (uni)) ? 2 : 1);
|
||||
return (str_unichar_iscombiningmark (uni)) ? 0 : ((g_unichar_iswide (uni)) ? 2 : 1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -800,7 +806,7 @@ str_utf8_trunc (const char *text, int width)
|
||||
tool.remain = sizeof (result);
|
||||
tool.compose = 0;
|
||||
|
||||
if (pre_form->width > (gsize)width)
|
||||
if (pre_form->width > (gsize) width)
|
||||
{
|
||||
tool.ident = 0;
|
||||
utf8_tool_copy_chars_to (&tool, width / 2);
|
||||
@ -873,7 +879,7 @@ str_utf8_column_to_pos (const char *text, size_t pos)
|
||||
text++;
|
||||
width++;
|
||||
}
|
||||
if ((gsize)width > pos)
|
||||
if ((gsize) width > pos)
|
||||
return result;
|
||||
|
||||
result++;
|
||||
@ -1220,13 +1226,16 @@ str_utf8_caseprefix (const char *text, const char *prefix)
|
||||
|
||||
static char *
|
||||
str_utf8_create_key_gen (const char *text, int case_sen,
|
||||
gchar * (*keygen) (const gchar *text, gssize size))
|
||||
gchar * (*keygen) (const gchar * text, gssize size))
|
||||
{
|
||||
char *result;
|
||||
|
||||
if (case_sen) {
|
||||
if (case_sen)
|
||||
{
|
||||
result = str_utf8_normalize (text);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
gboolean dot;
|
||||
GString *fixed;
|
||||
const char *start, *end;
|
||||
@ -1299,8 +1308,7 @@ str_utf8_create_key (const char *text, int case_sen)
|
||||
static char *
|
||||
str_utf8_create_key_for_filename (const char *text, int case_sen)
|
||||
{
|
||||
return str_utf8_create_key_gen (text, case_sen,
|
||||
g_utf8_collate_key_for_filename);
|
||||
return str_utf8_create_key_gen (text, case_sen, g_utf8_collate_key_for_filename);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -40,12 +40,13 @@
|
||||
/* Compare S1 and S2 as strings holding indices/version numbers,
|
||||
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).
|
||||
*/
|
||||
*/
|
||||
|
||||
int str_verscmp (const char *s1, const char *s2)
|
||||
int
|
||||
str_verscmp (const char *s1, const char *s2)
|
||||
{
|
||||
#ifdef HAVE_STRVERSCMP
|
||||
return strverscmp(s1, s2);
|
||||
return strverscmp (s1, s2);
|
||||
#else /* HAVE_STRVERSCMP */
|
||||
unsigned char *p1 = (unsigned char *) s1;
|
||||
unsigned char *p2 = (unsigned char *) s2;
|
||||
@ -55,8 +56,7 @@ int str_verscmp (const char *s1, const char *s2)
|
||||
|
||||
/* Symbol(s) 0 [1-9] others (padding)
|
||||
Transition (10) 0 (01) d (00) x (11) - */
|
||||
static const unsigned int next_state[] =
|
||||
{
|
||||
static const unsigned int next_state[] = {
|
||||
/* state x d 0 - */
|
||||
/* S_N */ S_N, S_I, S_Z, S_N,
|
||||
/* S_I */ S_N, S_I, S_I, S_I,
|
||||
@ -64,8 +64,7 @@ int str_verscmp (const char *s1, const char *s2)
|
||||
/* 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/-
|
||||
0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
|
||||
|
||||
|
@ -3,12 +3,15 @@
|
||||
* \brief Header: time formating macroses
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_TIMEFMT_H
|
||||
#define __UTIL_TIMEFMT_H
|
||||
#ifndef MC__UTIL_TIMEFMT_H
|
||||
#define MC__UTIL_TIMEFMT_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
|
||||
#define INVALID_TIME_TEXT "(invalid)"
|
||||
|
||||
/* safe localtime formatting - strftime()-using version */
|
||||
@ -34,4 +37,14 @@
|
||||
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
|
||||
}
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* !__UTIL_H */
|
||||
|
@ -39,7 +39,8 @@ gboolean mc_tty_color_disable;
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
typedef struct mc_tty_color_table_struct {
|
||||
typedef struct mc_tty_color_table_struct
|
||||
{
|
||||
const char *name;
|
||||
int value;
|
||||
} mc_tty_color_table_t;
|
||||
@ -47,30 +48,30 @@ typedef struct mc_tty_color_table_struct {
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
mc_tty_color_table_t const color_table[] = {
|
||||
{ "black", COLOR_BLACK },
|
||||
{ "gray", COLOR_BLACK | A_BOLD },
|
||||
{ "red", COLOR_RED },
|
||||
{ "brightred", COLOR_RED | A_BOLD },
|
||||
{ "green", COLOR_GREEN },
|
||||
{ "brightgreen", COLOR_GREEN | A_BOLD },
|
||||
{ "brown", COLOR_YELLOW },
|
||||
{ "yellow", COLOR_YELLOW | A_BOLD },
|
||||
{ "blue", COLOR_BLUE },
|
||||
{ "brightblue", COLOR_BLUE | A_BOLD },
|
||||
{ "magenta", COLOR_MAGENTA },
|
||||
{ "brightmagenta", COLOR_MAGENTA | A_BOLD },
|
||||
{ "cyan", COLOR_CYAN },
|
||||
{ "brightcyan", COLOR_CYAN | A_BOLD },
|
||||
{ "lightgray", COLOR_WHITE },
|
||||
{ "white", COLOR_WHITE | A_BOLD },
|
||||
{ "default", -1 }, /* default color of the terminal */
|
||||
{"black", COLOR_BLACK},
|
||||
{"gray", COLOR_BLACK | A_BOLD},
|
||||
{"red", COLOR_RED},
|
||||
{"brightred", COLOR_RED | A_BOLD},
|
||||
{"green", COLOR_GREEN},
|
||||
{"brightgreen", COLOR_GREEN | A_BOLD},
|
||||
{"brown", COLOR_YELLOW},
|
||||
{"yellow", COLOR_YELLOW | A_BOLD},
|
||||
{"blue", COLOR_BLUE},
|
||||
{"brightblue", COLOR_BLUE | A_BOLD},
|
||||
{"magenta", COLOR_MAGENTA},
|
||||
{"brightmagenta", COLOR_MAGENTA | A_BOLD},
|
||||
{"cyan", COLOR_CYAN},
|
||||
{"brightcyan", COLOR_CYAN | A_BOLD},
|
||||
{"lightgray", COLOR_WHITE},
|
||||
{"white", COLOR_WHITE | A_BOLD},
|
||||
{"default", -1}, /* default color of the terminal */
|
||||
/* special colors */
|
||||
{ "A_REVERSE", SPEC_A_REVERSE },
|
||||
{ "A_BOLD", SPEC_A_BOLD},
|
||||
{ "A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE },
|
||||
{ "A_UNDERLINE", SPEC_A_UNDERLINE },
|
||||
{"A_REVERSE", SPEC_A_REVERSE},
|
||||
{"A_BOLD", SPEC_A_BOLD},
|
||||
{"A_BOLD_REVERSE", SPEC_A_BOLD_REVERSE},
|
||||
{"A_UNDERLINE", SPEC_A_UNDERLINE},
|
||||
/* End of list */
|
||||
{ NULL, 0}
|
||||
{NULL, 0}
|
||||
};
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
@ -3,21 +3,33 @@
|
||||
* \brief Header: Internal stuff of color setup
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_INTERNAL_H
|
||||
#define MC_COLOR_INTERNAL_H
|
||||
#ifndef MC__COLOR_INTERNAL_H
|
||||
#define MC__COLOR_INTERNAL_H
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "tty-slang.h"
|
||||
#include "tty-slang.h"
|
||||
#else
|
||||
# include "tty-ncurses.h"
|
||||
#include "tty-ncurses.h"
|
||||
#endif /* HAVE_SLANG */
|
||||
|
||||
extern gboolean use_colors;
|
||||
extern gboolean mc_tty_color_disable;
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** 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
|
||||
{
|
||||
@ -29,14 +41,12 @@ typedef struct mc_color_pair_struct
|
||||
gboolean is_temp;
|
||||
} tty_color_pair_t;
|
||||
|
||||
/* *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* */
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern gboolean use_colors;
|
||||
extern gboolean mc_tty_color_disable;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
const char *tty_color_get_valid_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 *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_COLOR_INTERNAL_H */
|
||||
|
@ -67,7 +67,8 @@ mc_tty_color_save_attr_lib (int color_pair, int color_attr)
|
||||
return color_attr;
|
||||
|
||||
key = g_try_new (int, 1);
|
||||
if (key == NULL) {
|
||||
if (key == NULL)
|
||||
{
|
||||
g_free (attr);
|
||||
return color_attr;
|
||||
}
|
||||
@ -115,7 +116,8 @@ tty_color_init_lib (gboolean disable, gboolean force)
|
||||
{
|
||||
(void) force;
|
||||
|
||||
if (has_colors () && !disable) {
|
||||
if (has_colors () && !disable)
|
||||
{
|
||||
use_colors = TRUE;
|
||||
start_color ();
|
||||
use_default_colors ();
|
||||
@ -139,8 +141,10 @@ tty_color_deinit_lib (void)
|
||||
void
|
||||
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
||||
{
|
||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) {
|
||||
switch (mc_color_pair->ifg) {
|
||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
|
||||
{
|
||||
switch (mc_color_pair->ifg)
|
||||
{
|
||||
case SPEC_A_REVERSE:
|
||||
mc_tty_color_pair_init_special (mc_color_pair,
|
||||
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);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
|
||||
|
@ -38,6 +38,17 @@
|
||||
|
||||
#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
|
||||
has_colors (gboolean disable, gboolean force)
|
||||
{
|
||||
@ -46,7 +57,8 @@ has_colors (gboolean disable, gboolean force)
|
||||
if (force || (getenv ("COLORTERM") != NULL))
|
||||
SLtt_Use_Ansi_Colors = 1;
|
||||
|
||||
if (!mc_tty_color_disable) {
|
||||
if (!mc_tty_color_disable)
|
||||
{
|
||||
const char *terminal = getenv ("TERM");
|
||||
const size_t len = strlen (terminal);
|
||||
|
||||
@ -55,13 +67,15 @@ has_colors (gboolean disable, gboolean force)
|
||||
size_t i;
|
||||
|
||||
/* check color_terminal_string */
|
||||
while (*cts != '\0') {
|
||||
while (*cts != '\0')
|
||||
{
|
||||
while (*cts == ' ' || *cts == '\t')
|
||||
cts++;
|
||||
s = cts;
|
||||
i = 0;
|
||||
|
||||
while (*cts != '\0' && *cts != ',') {
|
||||
while (*cts != '\0' && *cts != ',')
|
||||
{
|
||||
cts++;
|
||||
i++;
|
||||
}
|
||||
@ -76,43 +90,62 @@ has_colors (gboolean disable, gboolean force)
|
||||
return SLtt_Use_Ansi_Colors;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
|
||||
const char *fg1, const char *bg1,
|
||||
const char *fg2, const char *bg2, SLtt_Char_Type mask)
|
||||
{
|
||||
if (SLtt_Use_Ansi_Colors != 0) {
|
||||
if (!mc_tty_color_disable) {
|
||||
if (SLtt_Use_Ansi_Colors != 0)
|
||||
{
|
||||
if (!mc_tty_color_disable)
|
||||
{
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
SLtt_set_mono (mc_color_pair->pair_index, NULL, mask);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_color_init_lib (gboolean disable, gboolean force)
|
||||
{
|
||||
/* FIXME: if S-Lang is used, has_colors() must be called regardless
|
||||
of whether we are interested in its result */
|
||||
if (has_colors (disable, force) && !disable) {
|
||||
if (has_colors (disable, force) && !disable)
|
||||
{
|
||||
use_colors = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_color_deinit_lib (void)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
|
||||
{
|
||||
const char *fg, *bg;
|
||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE) {
|
||||
switch (mc_color_pair->ifg) {
|
||||
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
|
||||
{
|
||||
switch (mc_color_pair->ifg)
|
||||
{
|
||||
case SPEC_A_REVERSE:
|
||||
mc_tty_color_pair_init_special (mc_color_pair,
|
||||
"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);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
fg = (mc_color_pair->cfg) ? mc_color_pair->cfg : "default";
|
||||
bg = (mc_color_pair->cbg) ? mc_color_pair->cbg : "default";
|
||||
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_setcolor (int 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
|
||||
tty_lowlevel_setcolor (int color)
|
||||
{
|
||||
SLsmg_set_color (color & 0x7F);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_set_normal_attrs (void)
|
||||
{
|
||||
SLsmg_normal_video ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -3,12 +3,25 @@
|
||||
* \brief Header: S-Lang-specific color setup
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_SLANG_H
|
||||
#define MC_COLOR_SLANG_H
|
||||
#ifndef MC__COLOR_SLANG_H
|
||||
#define MC__COLOR_SLANG_H
|
||||
|
||||
#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_RED,
|
||||
COLOR_GREEN,
|
||||
@ -19,12 +32,11 @@ enum {
|
||||
COLOR_WHITE
|
||||
};
|
||||
|
||||
/* When using Slang with color, we have all the indexes free but
|
||||
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
|
||||
*/
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
#ifndef A_BOLD
|
||||
#define A_BOLD SLTT_BOLD_MASK
|
||||
#endif /* A_BOLD */
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_COLOR_SLANG_H */
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file color.h
|
||||
* \brief Header: color setup
|
||||
*
|
||||
@ -9,20 +8,32 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MC_COLOR_H
|
||||
#define MC_COLOR_H
|
||||
#ifndef MC__COLOR_H
|
||||
#define MC__COLOR_H
|
||||
|
||||
#include "lib/global.h" /* glib.h */
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "color-slang.h"
|
||||
#include "color-slang.h"
|
||||
#else
|
||||
# include "tty-ncurses.h"
|
||||
#include "tty-ncurses.h"
|
||||
#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 */
|
||||
extern char *command_line_colors;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void tty_init_colors (gboolean disable, gboolean force);
|
||||
void tty_colors_done (void);
|
||||
|
||||
@ -39,6 +50,5 @@ void tty_set_normal_attrs (void);
|
||||
|
||||
void tty_color_set_defaults (const char *, const char *);
|
||||
|
||||
#define ALLOC_COLOR_PAIR_INDEX 1
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_COLOR_H */
|
||||
|
819
lib/tty/key.c
819
lib/tty/key.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
101
lib/tty/key.h
101
lib/tty/key.h
@ -1,39 +1,14 @@
|
||||
|
||||
/** \file key.h
|
||||
* \brief Header: keyboard support routines
|
||||
*/
|
||||
|
||||
#ifndef MC_KEY_H
|
||||
#define MC_KEY_H
|
||||
#ifndef MC__KEY_H
|
||||
#define MC__KEY_H
|
||||
|
||||
#include "lib/global.h" /* <glib.h> */
|
||||
|
||||
#include "tty.h" /* KEY_F macro */
|
||||
|
||||
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);
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Possible return values from tty_get_event: */
|
||||
#define EV_MOUSE -2
|
||||
@ -48,12 +23,57 @@ int tty_getch (void);
|
||||
#define KEY_M_CTRL 0x4000
|
||||
#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 double_click_speed;
|
||||
extern int old_esc_mode;
|
||||
extern int use_8th_bit_as_meta;
|
||||
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 */
|
||||
typedef int (*select_fn) (int fd, void *info);
|
||||
|
||||
@ -66,23 +86,6 @@ void remove_select_channel (int fd);
|
||||
void channels_up (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 */
|
||||
void load_xtra_key_defines (void);
|
||||
|
||||
@ -96,4 +99,12 @@ int get_key_code (int nodelay);
|
||||
void numeric_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 */
|
||||
|
@ -91,6 +91,11 @@
|
||||
* 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_catab __TK("ktbc", "ka", 56, _ky_catab )
|
||||
#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 */
|
||||
|
||||
#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 xtra_key_define_t qnx_key_define_t
|
||||
|
||||
#endif /* __USE_QNX_TI */
|
||||
|
||||
#endif /* HAVE_QNX_KEYS */
|
||||
|
||||
|
||||
#ifdef xtra_key_define_t
|
||||
|
||||
#ifndef FORCE_BASE_KEY_DEFS
|
||||
#define FORCE_BASE_KEY_DEFS 0
|
||||
#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 */
|
||||
xtra_key_define_t xtra_key_defines[] = {
|
||||
@ -372,21 +394,22 @@ xtra_key_define_t xtra_key_defines[] = {
|
||||
|
||||
#endif /* xtra_key_define_t */
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#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))
|
||||
|
||||
void
|
||||
load_qnx_key_defines (void)
|
||||
{
|
||||
static int _qnx_keys_defined = 0;
|
||||
|
||||
if (!_qnx_keys_defined) {
|
||||
if (!_qnx_keys_defined)
|
||||
{
|
||||
int idx, str_idx;
|
||||
int term_setup_ok;
|
||||
|
||||
@ -394,10 +417,13 @@ load_qnx_key_defines (void)
|
||||
if (term_setup_ok != 1)
|
||||
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;
|
||||
if (__QTISOFFS (str_idx)) {
|
||||
if (*__QTISSTR (str_idx)) {
|
||||
if (__QTISOFFS (str_idx))
|
||||
{
|
||||
if (*__QTISSTR (str_idx))
|
||||
{
|
||||
define_sequence (xtra_key_defines[idx].mc_code,
|
||||
__QTISSTR (str_idx), MCKEY_NOACTION);
|
||||
}
|
||||
@ -406,13 +432,12 @@ load_qnx_key_defines (void)
|
||||
_qnx_keys_defined = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __USE_QNX_TI */
|
||||
|
||||
#endif /* HAVE_QNX_KEYS */
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* called from key.c/init_key() */
|
||||
|
||||
void
|
||||
load_xtra_key_defines (void)
|
||||
{
|
||||
@ -420,3 +445,5 @@ load_xtra_key_defines (void)
|
||||
load_qnx_key_defines ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -38,9 +38,24 @@
|
||||
#include "mouse.h"
|
||||
#include "key.h" /* define sequence */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
gboolean mouse_enabled = FALSE;
|
||||
const char *xmouse_seq;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
show_mouse_pointer (int x, int y)
|
||||
{
|
||||
@ -53,10 +68,13 @@ show_mouse_pointer (int x, int y)
|
||||
#endif /* HAVE_LIBGPM */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_mouse (void)
|
||||
{
|
||||
switch (use_mouse_p) {
|
||||
switch (use_mouse_p)
|
||||
{
|
||||
#ifdef HAVE_LIBGPM
|
||||
case MOUSE_NONE:
|
||||
use_mouse_p = MOUSE_GPM;
|
||||
@ -75,13 +93,16 @@ init_mouse (void)
|
||||
enable_mouse ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
enable_mouse (void)
|
||||
{
|
||||
if (mouse_enabled)
|
||||
return;
|
||||
|
||||
switch (use_mouse_p) {
|
||||
switch (use_mouse_p)
|
||||
{
|
||||
#ifdef HAVE_LIBGPM
|
||||
case MOUSE_GPM:
|
||||
{
|
||||
@ -94,7 +115,8 @@ enable_mouse (void)
|
||||
conn.maxMod = 0;
|
||||
|
||||
mouse_d = Gpm_Open (&conn, 0);
|
||||
if (mouse_d == -1) {
|
||||
if (mouse_d == -1)
|
||||
{
|
||||
use_mouse_p = MOUSE_NONE;
|
||||
return;
|
||||
}
|
||||
@ -130,6 +152,8 @@ enable_mouse (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
disable_mouse (void)
|
||||
{
|
||||
@ -138,7 +162,8 @@ disable_mouse (void)
|
||||
|
||||
mouse_enabled = FALSE;
|
||||
|
||||
switch (use_mouse_p) {
|
||||
switch (use_mouse_p)
|
||||
{
|
||||
#ifdef HAVE_LIBGPM
|
||||
case MOUSE_GPM:
|
||||
Gpm_Close ();
|
||||
@ -166,3 +191,5 @@ disable_mouse (void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
130
lib/tty/mouse.h
130
lib/tty/mouse.h
@ -5,16 +5,18 @@
|
||||
* Events received by clients of this library have their coordinates 0 based
|
||||
*/
|
||||
|
||||
#ifndef MC_MOUSE_H
|
||||
#define MC_MOUSE_H
|
||||
#ifndef MC__MOUSE_H
|
||||
#define MC__MOUSE_H
|
||||
|
||||
#ifdef HAVE_LIBGPM
|
||||
|
||||
/* GPM mouse support include file */
|
||||
#include <gpm.h>
|
||||
#endif /* !HAVE_LIBGPM */
|
||||
|
||||
#else
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#ifndef HAVE_LIBGPM
|
||||
/* Equivalent definitions for non-GPM mouse support */
|
||||
/* These lines are modified version from the lines appearing in the */
|
||||
/* gpm.h include file of the Linux General Purpose Mouse server */
|
||||
@ -23,60 +25,9 @@
|
||||
#define GPM_B_MIDDLE (1 << 1)
|
||||
#define GPM_B_RIGHT (1 << 0)
|
||||
|
||||
/* Xterm mouse support supports only GPM_DOWN and GPM_UP */
|
||||
/* If you use others make sure your code also works without them */
|
||||
enum Gpm_Etype {
|
||||
GPM_MOVE = 1,
|
||||
GPM_DRAG = 2, /* exactly one in four is active at a time */
|
||||
GPM_DOWN = 4,
|
||||
GPM_UP = 8,
|
||||
|
||||
#define GPM_BARE_EVENTS(ev) ((ev)&0xF)
|
||||
|
||||
GPM_SINGLE = 16, /* at most one in three is set */
|
||||
GPM_DOUBLE = 32,
|
||||
GPM_TRIPLE = 64,
|
||||
|
||||
GPM_MFLAG = 128, /* motion during click? */
|
||||
GPM_HARD = 256 /* if set in the defaultMask, force an already
|
||||
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 */
|
||||
|
||||
/* General (i.e. both for xterm and gpm) mouse support definitions */
|
||||
|
||||
/* Constants returned from the mouse callback */
|
||||
enum { MOU_NORMAL, MOU_REPEAT };
|
||||
|
||||
/* Mouse callback */
|
||||
typedef int (*mouse_h) (Gpm_Event *, void *);
|
||||
|
||||
/* Type of mouse support */
|
||||
typedef enum {
|
||||
MOUSE_NONE, /* Not detected yet */
|
||||
MOUSE_DISABLED, /* Explicitly disabled by -d */
|
||||
MOUSE_GPM, /* Support using GPM on Linux */
|
||||
MOUSE_XTERM, /* Support using xterm-style mouse reporting */
|
||||
MOUSE_XTERM_NORMAL_TRACKING = MOUSE_XTERM,
|
||||
MOUSE_XTERM_BUTTON_EVENT_TRACKING
|
||||
} Mouse_Type;
|
||||
|
||||
/* Type of the currently used mouse */
|
||||
extern Mouse_Type use_mouse_p;
|
||||
|
||||
/* String indicating that a mouse event has occured, usually "\E[M" */
|
||||
extern const char *xmouse_seq;
|
||||
|
||||
void init_mouse (void);
|
||||
void enable_mouse (void);
|
||||
void disable_mouse (void);
|
||||
|
||||
/* Mouse wheel events */
|
||||
#ifndef GPM_B_DOWN
|
||||
#define GPM_B_DOWN (1 << 5)
|
||||
@ -86,6 +37,75 @@ void disable_mouse (void);
|
||||
#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 */
|
||||
/* If you use others make sure your code also works without them */
|
||||
enum Gpm_Etype
|
||||
{
|
||||
GPM_MOVE = 1,
|
||||
GPM_DRAG = 2, /* exactly one in four is active at a time */
|
||||
GPM_DOWN = 4,
|
||||
GPM_UP = 8,
|
||||
|
||||
|
||||
GPM_SINGLE = 16, /* at most one in three is set */
|
||||
GPM_DOUBLE = 32,
|
||||
GPM_TRIPLE = 64,
|
||||
|
||||
GPM_MFLAG = 128, /* motion during click? */
|
||||
GPM_HARD = 256 /* if set in the defaultMask, force an already
|
||||
used event to pass over to another handler */
|
||||
};
|
||||
#endif /* !HAVE_LIBGPM */
|
||||
|
||||
/* Constants returned from the mouse callback */
|
||||
enum
|
||||
{ MOU_NORMAL, MOU_REPEAT };
|
||||
|
||||
/* Type of mouse support */
|
||||
typedef enum
|
||||
{
|
||||
MOUSE_NONE, /* Not detected yet */
|
||||
MOUSE_DISABLED, /* Explicitly disabled by -d */
|
||||
MOUSE_GPM, /* Support using GPM on Linux */
|
||||
MOUSE_XTERM, /* Support using xterm-style mouse reporting */
|
||||
MOUSE_XTERM_NORMAL_TRACKING = MOUSE_XTERM,
|
||||
MOUSE_XTERM_BUTTON_EVENT_TRACKING
|
||||
} 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 */
|
||||
extern Mouse_Type use_mouse_p;
|
||||
|
||||
/* String indicating that a mouse event has occured, usually "\E[M" */
|
||||
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 enable_mouse (void);
|
||||
void disable_mouse (void);
|
||||
|
||||
void show_mouse_pointer (int x, int y);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_MOUSE_H */
|
||||
|
@ -3,21 +3,29 @@
|
||||
* \brief Header: internal suff of the terminal controlling library
|
||||
*/
|
||||
|
||||
#ifndef MC_TTY_INTERNAL_H
|
||||
#define MC_TTY_INTERNAL_H
|
||||
#ifndef MC__TTY_INTERNAL_H
|
||||
#define MC__TTY_INTERNAL_H
|
||||
|
||||
#include "lib/global.h" /* include <glib.h> */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* Taken from S-Lang's slutty.c */
|
||||
#ifdef ultrix /* Ultrix gets _POSIX_VDISABLE wrong! */
|
||||
# define NULL_VALUE -1
|
||||
#define NULL_VALUE -1
|
||||
#else
|
||||
# ifdef _POSIX_VDISABLE
|
||||
# define NULL_VALUE _POSIX_VDISABLE
|
||||
# else
|
||||
# define NULL_VALUE 255
|
||||
# endif
|
||||
#ifdef _POSIX_VDISABLE
|
||||
#define NULL_VALUE _POSIX_VDISABLE
|
||||
#else
|
||||
#define NULL_VALUE 255
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/* If true lines are shown by spaces */
|
||||
extern gboolean slow_tty;
|
||||
@ -28,6 +36,9 @@ extern gboolean ugly_line_drawing;
|
||||
/* The mouse is currently: TRUE - enabled, FALSE - disabled */
|
||||
extern gboolean mouse_enabled;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
char *mc_tty_normalize_from_utf8 (const char *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_TTY_INTERNAL_H */
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "src/main.h"
|
||||
|
||||
#ifndef WANT_TERM_H
|
||||
# define WANT_TERM_H
|
||||
#define WANT_TERM_H
|
||||
#endif
|
||||
|
||||
#include "tty-internal.h" /* slow_tty */
|
||||
@ -53,30 +53,31 @@
|
||||
/* include at last !!! */
|
||||
#ifdef WANT_TERM_H
|
||||
#ifdef HAVE_NCURSES_TERM_H
|
||||
# include <ncurses/term.h>
|
||||
#include <ncurses/term.h>
|
||||
#else
|
||||
# include <term.h>
|
||||
#include <term.h>
|
||||
#endif /* HAVE_NCURSES_TERM_H */
|
||||
#endif /* WANT_TERM_H */
|
||||
|
||||
/*** global variables **************************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#if defined(_AIX) && !defined(CTRL)
|
||||
# define CTRL(x) ((x) & 0x1f)
|
||||
#define CTRL(x) ((x) & 0x1f)
|
||||
#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
|
||||
@ -137,7 +138,6 @@ mc_tty_normalize_lines_char (const char *ch)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
void
|
||||
tty_init (gboolean slow, gboolean ugly_lines)
|
||||
{
|
||||
@ -174,24 +174,32 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
||||
nodelay (stdscr, FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_shutdown (void)
|
||||
{
|
||||
endwin ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_reset_prog_mode (void)
|
||||
{
|
||||
reset_prog_mode ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_reset_shell_mode (void)
|
||||
{
|
||||
reset_shell_mode ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_raw_mode (void)
|
||||
{
|
||||
@ -199,6 +207,8 @@ tty_raw_mode (void)
|
||||
cbreak ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_noraw_mode (void)
|
||||
{
|
||||
@ -206,67 +216,89 @@ tty_noraw_mode (void)
|
||||
noraw ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_noecho (void)
|
||||
{
|
||||
noecho ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_flush_input (void)
|
||||
{
|
||||
return flushinp ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_keypad (gboolean set)
|
||||
{
|
||||
keypad (stdscr, (bool) set);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_nodelay (gboolean set)
|
||||
{
|
||||
nodelay (stdscr, (bool) set);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_baudrate (void)
|
||||
{
|
||||
return baudrate ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_lowlevel_getch (void)
|
||||
{
|
||||
return getch ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_reset_screen (void)
|
||||
{
|
||||
return endwin ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_touch_screen (void)
|
||||
{
|
||||
touchwin (stdscr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_gotoyx (int y, int x)
|
||||
{
|
||||
move (y, x);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_getyx (int *py, int *px)
|
||||
{
|
||||
getyx (stdscr, *py, *px);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* if x < 0 or y < 0, draw line starting from current position */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* if x < 0 or y < 0, draw line starting from current position */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_set_alt_charset (gboolean alt_charset)
|
||||
{
|
||||
(void) alt_charset;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_display_8bit (gboolean what)
|
||||
{
|
||||
meta (stdscr, (int) what);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_char (int c)
|
||||
{
|
||||
addch (c);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_anychar (int c)
|
||||
{
|
||||
@ -369,6 +413,8 @@ tty_print_anychar (int c)
|
||||
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_alt_char (int c, gboolean single)
|
||||
{
|
||||
@ -394,12 +440,16 @@ tty_print_alt_char (int c, gboolean single)
|
||||
addch (c);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_string (const char *s)
|
||||
{
|
||||
addstr (str_term_form (s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_printf (const char *fmt, ...)
|
||||
{
|
||||
@ -410,6 +460,8 @@ tty_printf (const char *fmt, ...)
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
tty_tgetstr (const char *cap)
|
||||
{
|
||||
@ -417,6 +469,8 @@ tty_tgetstr (const char *cap)
|
||||
return tgetstr ((char *) cap, &unused);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_refresh (void)
|
||||
{
|
||||
@ -424,6 +478,8 @@ tty_refresh (void)
|
||||
doupdate ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_setup_sigwinch (void (*handler) (int))
|
||||
{
|
||||
@ -439,8 +495,12 @@ tty_setup_sigwinch (void (*handler) (int))
|
||||
#endif /* SIGWINCH */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_beep (void)
|
||||
{
|
||||
beep ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,25 +1,37 @@
|
||||
|
||||
#ifndef MC_TTY_NCURSES_H
|
||||
#define MC_TTY_NCURSES_H
|
||||
#ifndef MC__TTY_NCURSES_H
|
||||
#define MC__TTY_NCURSES_H
|
||||
|
||||
#ifdef USE_NCURSES
|
||||
# ifdef HAVE_NCURSES_CURSES_H
|
||||
# include <ncurses/curses.h>
|
||||
# elif HAVE_NCURSES_NCURSES_H
|
||||
# include <ncurses/ncurses.h>
|
||||
# elif HAVE_NCURSESW_CURSES_H
|
||||
# include <ncursesw/curses.h>
|
||||
# elif HAVE_NCURSES_HCURSES_H
|
||||
# include <ncurses.h>
|
||||
# elif HAVE_NCURSES_H
|
||||
# include <ncurses.h>
|
||||
# else
|
||||
# include <curses.h>
|
||||
# endif
|
||||
#ifdef HAVE_NCURSES_CURSES_H
|
||||
#include <ncurses/curses.h>
|
||||
#elif HAVE_NCURSES_NCURSES_H
|
||||
#include <ncurses/ncurses.h>
|
||||
#elif HAVE_NCURSESW_CURSES_H
|
||||
#include <ncursesw/curses.h>
|
||||
#elif HAVE_NCURSES_HCURSES_H
|
||||
#include <ncurses.h>
|
||||
#elif HAVE_NCURSES_H
|
||||
#include <ncurses.h>
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif
|
||||
#endif /* USE_NCURSES */
|
||||
|
||||
#ifdef USE_NCURSESW
|
||||
# include <ncursesw/curses.h>
|
||||
#include <ncursesw/curses.h>
|
||||
#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 */
|
||||
|
@ -51,14 +51,14 @@
|
||||
#include "win.h"
|
||||
|
||||
|
||||
/*** global variables **************************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
extern int reset_hp_softkeys;
|
||||
|
||||
/*** file scope macro definitions **************************************/
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef SA_RESTART
|
||||
# define SA_RESTART 0
|
||||
#define SA_RESTART 0
|
||||
#endif
|
||||
|
||||
#ifndef SLTT_MAX_SCREEN_COLS
|
||||
@ -69,9 +69,9 @@ extern int reset_hp_softkeys;
|
||||
#define SLTT_MAX_SCREEN_ROWS 512
|
||||
#endif
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* Various saved termios settings that we control here */
|
||||
static struct termios boot_mode;
|
||||
@ -126,7 +126,8 @@ static const struct
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* HP Terminals have capabilities (pfkey, pfloc, pfx) to program function keys.
|
||||
elm 2.4pl15 invoked with the -K option utilizes these softkeys and the
|
||||
@ -164,6 +165,8 @@ slang_reset_softkeys (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_terminfo_keys (void)
|
||||
{
|
||||
@ -184,7 +189,7 @@ load_terminfo_keys (void)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions **************************************************/
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
@ -233,6 +238,7 @@ mc_tty_normalize_lines_char (const char *str)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_init (gboolean slow, gboolean ugly_lines)
|
||||
{
|
||||
@ -297,6 +303,8 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
||||
tty_nodelay (FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_shutdown (void)
|
||||
{
|
||||
@ -318,7 +326,9 @@ tty_shutdown (void)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Done each time we come back from done mode */
|
||||
|
||||
void
|
||||
tty_reset_prog_mode (void)
|
||||
{
|
||||
@ -327,35 +337,47 @@ tty_reset_prog_mode (void)
|
||||
SLsmg_touch_lines (0, LINES);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Called each time we want to shutdown slang screen manager */
|
||||
|
||||
void
|
||||
tty_reset_shell_mode (void)
|
||||
{
|
||||
tcsetattr (SLang_TT_Read_FD, TCSANOW, &boot_mode);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_raw_mode (void)
|
||||
{
|
||||
tcsetattr (SLang_TT_Read_FD, TCSANOW, &new_mode);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_noraw_mode (void)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_noecho (void)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_flush_input (void)
|
||||
{
|
||||
return 0; /* OK */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_keypad (gboolean set)
|
||||
{
|
||||
@ -368,18 +390,24 @@ tty_keypad (gboolean set)
|
||||
slang_reset_softkeys ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_nodelay (gboolean set)
|
||||
{
|
||||
no_slang_delay = set;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_baudrate (void)
|
||||
{
|
||||
return SLang_TT_Baud_Rate;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_lowlevel_getch (void)
|
||||
{
|
||||
@ -400,6 +428,8 @@ tty_lowlevel_getch (void)
|
||||
return c;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
tty_reset_screen (void)
|
||||
{
|
||||
@ -407,18 +437,24 @@ tty_reset_screen (void)
|
||||
return 0; /* OK */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_touch_screen (void)
|
||||
{
|
||||
SLsmg_touch_lines (0, LINES);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_gotoyx (int y, int x)
|
||||
{
|
||||
SLsmg_gotorc (y, x);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_getyx (int *py, int *px)
|
||||
{
|
||||
@ -426,7 +462,9 @@ tty_getyx (int *py, int *px)
|
||||
*px = SLsmg_get_column ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* if x < 0 or y < 0, draw line staring from current position */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* if x < 0 or y < 0, draw line staring from current position */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
|
||||
{
|
||||
SLsmg_fill_region (y, x, rows, cols, ch);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_set_alt_charset (gboolean alt_charset)
|
||||
{
|
||||
SLsmg_set_char_set ((int) alt_charset);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_display_8bit (gboolean what)
|
||||
{
|
||||
SLsmg_Display_Eight_Bit = what ? 128 : 160;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_char (int c)
|
||||
{
|
||||
SLsmg_write_char ((SLwchar_Type) ((unsigned int) c));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_alt_char (int c, gboolean single)
|
||||
{
|
||||
@ -553,6 +603,8 @@ tty_print_alt_char (int c, gboolean single)
|
||||
#undef DRAW
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_anychar (int c)
|
||||
{
|
||||
@ -578,12 +630,16 @@ tty_print_anychar (int c)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_string (const char *s)
|
||||
{
|
||||
SLsmg_write_string ((char *) str_term_form (s));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_printf (const char *fmt, ...)
|
||||
{
|
||||
@ -594,18 +650,24 @@ tty_printf (const char *fmt, ...)
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
tty_tgetstr (const char *cap)
|
||||
{
|
||||
return SLtt_tgetstr ((char *) cap);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_refresh (void)
|
||||
{
|
||||
SLsmg_refresh ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_setup_sigwinch (void (*handler) (int))
|
||||
{
|
||||
@ -621,8 +683,12 @@ tty_setup_sigwinch (void (*handler) (int))
|
||||
#endif /* SIGWINCH */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_beep (void)
|
||||
{
|
||||
SLtt_beep ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,19 +1,14 @@
|
||||
|
||||
#ifndef MC_TTY_SLANG_H
|
||||
#define MC_TTY_SLANG_H
|
||||
#ifndef MC__TTY_SLANG_H
|
||||
#define MC__TTY_SLANG_H
|
||||
|
||||
#ifdef HAVE_SLANG_SLANG_H
|
||||
# include <slang/slang.h>
|
||||
#include <slang/slang.h>
|
||||
#else
|
||||
# include <slang.h>
|
||||
#include <slang.h>
|
||||
#endif /* HAVE_SLANG_SLANG_H */
|
||||
|
||||
enum {
|
||||
KEY_BACKSPACE = 400,
|
||||
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
||||
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
||||
};
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define KEY_F(x) (1000 + x)
|
||||
|
||||
@ -30,4 +25,22 @@ enum {
|
||||
#define COLS SLtt_Screen_Cols
|
||||
#define LINES SLtt_Screen_Rows
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
enum
|
||||
{
|
||||
KEY_BACKSPACE = 400,
|
||||
KEY_END, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_HOME, KEY_A1, KEY_C1, KEY_NPAGE, KEY_PPAGE, KEY_IC,
|
||||
KEY_ENTER, KEY_DC, KEY_SCANCEL, KEY_BTAB
|
||||
};
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif /* MC_TTY_SLANG_H */
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include "tty-internal.h"
|
||||
|
||||
|
||||
/*** global variables **************************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* 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
|
||||
@ -56,15 +56,16 @@ gboolean ugly_line_drawing = FALSE;
|
||||
|
||||
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;
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
sigintr_handler (int signo)
|
||||
@ -73,7 +74,9 @@ sigintr_handler (int signo)
|
||||
got_interrupt = 1;
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern gboolean
|
||||
tty_is_slow (void)
|
||||
@ -81,6 +84,8 @@ tty_is_slow (void)
|
||||
return slow_tty;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern void
|
||||
tty_start_interrupt_key (void)
|
||||
{
|
||||
@ -92,6 +97,8 @@ tty_start_interrupt_key (void)
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern void
|
||||
tty_enable_interrupt_key (void)
|
||||
{
|
||||
@ -104,6 +111,8 @@ tty_enable_interrupt_key (void)
|
||||
got_interrupt = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern void
|
||||
tty_disable_interrupt_key (void)
|
||||
{
|
||||
@ -115,6 +124,8 @@ tty_disable_interrupt_key (void)
|
||||
sigaction (SIGINT, &act, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern gboolean
|
||||
tty_got_interrupt (void)
|
||||
{
|
||||
@ -125,18 +136,24 @@ tty_got_interrupt (void)
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_one_hline (gboolean single)
|
||||
{
|
||||
tty_print_alt_char (ACS_HLINE, single);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tty_print_one_vline (gboolean single)
|
||||
{
|
||||
tty_print_alt_char (ACS_VLINE, single);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
100
lib/tty/tty.h
100
lib/tty/tty.h
@ -8,17 +8,68 @@
|
||||
* files small.
|
||||
*/
|
||||
|
||||
#ifndef MC_TTY_H
|
||||
#define MC_TTY_H
|
||||
#ifndef MC__TTY_H
|
||||
#define MC__TTY_H
|
||||
|
||||
#include "lib/global.h" /* include <glib.h> */
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
# include "tty-slang.h"
|
||||
#include "tty-slang.h"
|
||||
#else
|
||||
# include "tty-ncurses.h"
|
||||
#include "tty-ncurses.h"
|
||||
#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 }}} */
|
||||
|
||||
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_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_setup_sigwinch (void (*handler) (int));
|
||||
|
||||
extern int mc_tty_normalize_lines_char (const char *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_TTY_H */
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "win.h"
|
||||
#include "src/consaver/cons.saver.h" /* console_flag */
|
||||
|
||||
/*** global variables **************************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* This flag is set by xterm detection routine in function main() */
|
||||
/* It is used by function view_other_cmd() */
|
||||
@ -45,15 +45,16 @@ int xterm_flag = 0;
|
||||
|
||||
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;
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* my own wierd protocol base 16 - paul */
|
||||
static int
|
||||
@ -71,6 +72,8 @@ rxvt_getc (void)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
anything_ready (void)
|
||||
{
|
||||
@ -84,26 +87,34 @@ anything_ready (void)
|
||||
return select (1, &fds, 0, 0, &tv);
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
do_enter_ca_mode (void)
|
||||
{
|
||||
if (xterm_flag) {
|
||||
if (xterm_flag)
|
||||
{
|
||||
fprintf (stdout, /* ESC_STR ")0" */ ESC_STR "7" ESC_STR "[?47h");
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
do_exit_ca_mode (void)
|
||||
{
|
||||
if (xterm_flag) {
|
||||
if (xterm_flag)
|
||||
{
|
||||
fprintf (stdout, ESC_STR "[?47l" ESC_STR "8" ESC_STR "[m");
|
||||
fflush (stdout);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
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 ())
|
||||
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');
|
||||
|
||||
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
|
||||
j = 0;
|
||||
k = g_malloc (bytes);
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
int c;
|
||||
c = rxvt_getc ();
|
||||
if (c < 0)
|
||||
break;
|
||||
if (j < bytes)
|
||||
k[j++] = c;
|
||||
for (cols = 1;; cols++) {
|
||||
for (cols = 1;; cols++)
|
||||
{
|
||||
c = rxvt_getc ();
|
||||
if (c < 0)
|
||||
break;
|
||||
@ -136,7 +149,8 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
|
||||
k[j++] = c;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < j; i++) {
|
||||
for (i = 0; i < j; i++)
|
||||
{
|
||||
if ((i % cols) == 0)
|
||||
tty_gotoyx (starty + (i / cols), 0);
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
look_for_rxvt_extensions (void)
|
||||
{
|
||||
static gboolean been_called = FALSE;
|
||||
|
||||
if (!been_called) {
|
||||
if (!been_called)
|
||||
{
|
||||
const char *e = getenv ("RXVT_EXT");
|
||||
rxvt_extensions = ((e != NULL) && (strcmp (e, "1.0") == 0));
|
||||
been_called = TRUE;
|
||||
@ -160,3 +177,5 @@ look_for_rxvt_extensions (void)
|
||||
|
||||
return rxvt_extensions;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,19 +1,29 @@
|
||||
|
||||
/** \file win.h
|
||||
* \brief Header: X terminal management: xterm and rxvt
|
||||
*/
|
||||
|
||||
#ifndef MC_WIN_H
|
||||
#define MC_WIN_H
|
||||
#ifndef MC__WIN_H
|
||||
#define MC__WIN_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;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void do_enter_ca_mode (void);
|
||||
void do_exit_ca_mode (void);
|
||||
|
||||
void show_rxvt_contents (int starty, unsigned char y1, unsigned char y2);
|
||||
gboolean look_for_rxvt_extensions (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_WIN_H */
|
||||
|
@ -36,40 +36,39 @@ typedef int dummy; /* C99 forbids empty compilation unit */
|
||||
#include <setjmp.h>
|
||||
#include <X11/Xlib.h>
|
||||
#ifdef HAVE_GMODULE
|
||||
# include <gmodule.h>
|
||||
#include <gmodule.h>
|
||||
#endif
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "x11conn.h"
|
||||
|
||||
/*** file scope type declarations **************************************/
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
typedef int (*mc_XErrorHandler_callback) (Display *, XErrorEvent *);
|
||||
typedef int (*mc_XIOErrorHandler_callback) (Display *);
|
||||
|
||||
/*** file scope variables **********************************************/
|
||||
|
||||
#ifdef HAVE_GMODULE
|
||||
|
||||
static Display *(*func_XOpenDisplay) (_Xconst char *);
|
||||
static int (*func_XCloseDisplay) (Display *);
|
||||
static mc_XErrorHandler_callback (*func_XSetErrorHandler)
|
||||
(mc_XErrorHandler_callback);
|
||||
static mc_XIOErrorHandler_callback (*func_XSetIOErrorHandler)
|
||||
(mc_XIOErrorHandler_callback);
|
||||
static Bool (*func_XQueryPointer) (Display *, Window, Window *, Window *,
|
||||
int *, int *, int *, int *, unsigned int *);
|
||||
|
||||
static GModule *x11_module;
|
||||
|
||||
#else
|
||||
/*** 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_XIOErrorHandler_callback) (Display *);
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
#ifdef HAVE_GMODULE
|
||||
static Display *(*func_XOpenDisplay) (_Xconst char *);
|
||||
static int (*func_XCloseDisplay) (Display *);
|
||||
static mc_XErrorHandler_callback (*func_XSetErrorHandler) (mc_XErrorHandler_callback);
|
||||
static mc_XIOErrorHandler_callback (*func_XSetIOErrorHandler) (mc_XIOErrorHandler_callback);
|
||||
static Bool (*func_XQueryPointer) (Display *, Window, Window *, Window *,
|
||||
int *, int *, int *, int *, unsigned int *);
|
||||
static GModule *x11_module;
|
||||
#endif
|
||||
|
||||
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 gboolean longjmp_allowed = FALSE;
|
||||
|
||||
/*** file private functions ********************************************/
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
x_io_error_handler (Display * dpy)
|
||||
@ -90,13 +90,16 @@ x_io_error_handler (Display * dpy)
|
||||
(void) dpy;
|
||||
|
||||
lost_connection = TRUE;
|
||||
if (longjmp_allowed) {
|
||||
if (longjmp_allowed)
|
||||
{
|
||||
longjmp_allowed = FALSE;
|
||||
longjmp (x11_exception, 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
x_error_handler (Display * dpy, XErrorEvent * ee)
|
||||
{
|
||||
@ -105,6 +108,8 @@ x_error_handler (Display * dpy, XErrorEvent * ee)
|
||||
return x_io_error_handler (dpy);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
install_error_handlers (void)
|
||||
{
|
||||
@ -116,6 +121,8 @@ install_error_handlers (void)
|
||||
handlers_installed = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
x11_available (void)
|
||||
{
|
||||
@ -167,15 +174,19 @@ x11_available (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Display *
|
||||
mc_XOpenDisplay (const char *displayname)
|
||||
{
|
||||
Display *retval;
|
||||
|
||||
if (x11_available ()) {
|
||||
if (setjmp (x11_exception) == 0) {
|
||||
if (x11_available ())
|
||||
{
|
||||
if (setjmp (x11_exception) == 0)
|
||||
{
|
||||
longjmp_allowed = TRUE;
|
||||
retval = func_XOpenDisplay (displayname);
|
||||
longjmp_allowed = FALSE;
|
||||
@ -185,13 +196,17 @@ mc_XOpenDisplay (const char *displayname)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_XCloseDisplay (Display * display)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (x11_available ()) {
|
||||
if (setjmp (x11_exception) == 0) {
|
||||
if (x11_available ())
|
||||
{
|
||||
if (setjmp (x11_exception) == 0)
|
||||
{
|
||||
longjmp_allowed = TRUE;
|
||||
retval = func_XCloseDisplay (display);
|
||||
longjmp_allowed = FALSE;
|
||||
@ -201,6 +216,8 @@ mc_XCloseDisplay (Display * display)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
Bool
|
||||
mc_XQueryPointer (Display * display, Window win, Window * root_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;
|
||||
|
||||
if (x11_available ()) {
|
||||
if (setjmp (x11_exception) == 0) {
|
||||
if (x11_available ())
|
||||
{
|
||||
if (setjmp (x11_exception) == 0)
|
||||
{
|
||||
longjmp_allowed = TRUE;
|
||||
retval = func_XQueryPointer (display, win, root_return,
|
||||
child_return, root_x_return, root_y_return,
|
||||
@ -228,4 +247,6 @@ mc_XQueryPointer (Display * display, Window win, Window * root_return,
|
||||
return False;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#endif /* HAVE_TEXTMODE_X11_SUPPORT */
|
||||
|
@ -1,12 +1,11 @@
|
||||
|
||||
/** \file x11conn.h
|
||||
* \brief Header: X11 support
|
||||
* \warning This code uses setjmp() and longjmp(). Before you modify _anything_ here,
|
||||
* please read the relevant sections of the C standard.
|
||||
*/
|
||||
|
||||
#ifndef MC_X11CONN_H
|
||||
#define MC_X11CONN_H
|
||||
#ifndef MC__X11CONN_H
|
||||
#define MC__X11CONN_H
|
||||
|
||||
/*
|
||||
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
|
||||
will be suppressed, and the functions will return reasonable default
|
||||
values.
|
||||
*/
|
||||
*/
|
||||
|
||||
#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 int mc_XCloseDisplay (Display *);
|
||||
|
||||
extern Bool mc_XQueryPointer (Display *, Window, Window *, Window *,
|
||||
int *, int *, int *, int *, unsigned int *);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file unixcompat.h
|
||||
* \brief Header: collects differences between the various Unix
|
||||
*
|
||||
@ -14,27 +13,41 @@
|
||||
|
||||
#include <sys/types.h> /* BSD */
|
||||
#ifdef HAVE_SYS_MKDEV_H
|
||||
# include <sys/mkdev.h> /* Solaris 9 */
|
||||
#include <sys/mkdev.h> /* Solaris 9 */
|
||||
#endif
|
||||
#if defined(_AIX) && defined(HAVE_SYS_SYSMACROS_H)
|
||||
# include <sys/sysmacros.h> /* AIX */
|
||||
#include <sys/sysmacros.h> /* AIX */
|
||||
#endif
|
||||
|
||||
#if defined(_AIX)
|
||||
# include <time.h> /* AIX for tm */
|
||||
#include <time.h> /* AIX for tm */
|
||||
#endif
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#ifndef major
|
||||
# warning major() is undefined. Device numbers will not be shown correctly.
|
||||
# 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))
|
||||
#warning major() is undefined. Device numbers will not be shown correctly.
|
||||
#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
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif
|
||||
|
477
lib/util.c
477
lib/util.c
@ -55,11 +55,33 @@
|
||||
#include "src/main.h" /* eight_bit_clean */
|
||||
#endif
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int easy_patterns = 1;
|
||||
|
||||
char *user_recent_timeformat = NULL; /* time format string for recent 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,
|
||||
* 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;
|
||||
|
||||
/*** 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
|
||||
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
|
||||
is_printable (int c)
|
||||
@ -121,7 +260,12 @@ is_printable (int c)
|
||||
#endif /* !HAVE_CHARSET */
|
||||
}
|
||||
|
||||
/* Calculates the message dimensions (lines and columns) */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Calculates the message dimensions (lines and columns)
|
||||
*
|
||||
*/
|
||||
|
||||
void
|
||||
msglen (const char *text, int *lines, int *columns)
|
||||
{
|
||||
@ -148,11 +292,13 @@ msglen (const char *text, int *lines, int *columns)
|
||||
*columns = ncolumns;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Copy from s to d, and trim the beginning if necessary, and prepend
|
||||
* "..." in this case. The destination string can have at most len
|
||||
* bytes, not counting trailing 0.
|
||||
*/
|
||||
|
||||
char *
|
||||
trim (const char *s, char *d, int len)
|
||||
{
|
||||
@ -185,7 +331,8 @@ trim (const char *s, char *d, int len)
|
||||
return d;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Quote the filename for the purpose of inserting it into the command
|
||||
* line. If quote_percent is 1, replace "%" with "%%" - the percent is
|
||||
* processed by the mc command line.
|
||||
@ -247,6 +394,8 @@ name_quote (const char *s, int quote_percent)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Remove the middle part of the string to fit given length.
|
||||
* Use "~" to show where the string was truncated.
|
||||
* Return static buffer, no need to free() it.
|
||||
*/
|
||||
|
||||
const char *
|
||||
name_trunc (const char *txt, size_t trunc_len)
|
||||
{
|
||||
return str_trunc (txt, trunc_len);
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* path_trunc() is the same as name_trunc() above but
|
||||
* it deletes possible password from path for security
|
||||
* reasons.
|
||||
*/
|
||||
|
||||
const char *
|
||||
path_trunc (const char *path, size_t trunc_len)
|
||||
{
|
||||
@ -281,6 +434,8 @@ path_trunc (const char *path, size_t trunc_len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
size_trunc (double size, gboolean use_si)
|
||||
{
|
||||
@ -302,6 +457,8 @@ size_trunc (double size, gboolean use_si)
|
||||
return x;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
size_trunc_sep (double size, gboolean use_si)
|
||||
{
|
||||
@ -331,7 +488,8 @@ size_trunc_sep (double size, gboolean use_si)
|
||||
return d;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Print file SIZE to BUFFER, but don't exceed LEN characters,
|
||||
* not including trailing 0. BUFFER should be at least LEN+1 long.
|
||||
* 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)
|
||||
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
|
||||
*/
|
||||
|
||||
void
|
||||
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
|
||||
is_exe (mode_t mode)
|
||||
{
|
||||
@ -411,7 +572,7 @@ is_exe (mode_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define ismode(n,m) ((n & m) == m)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
string_perm (mode_t mode_bits)
|
||||
@ -468,15 +629,18 @@ string_perm (mode_t mode_bits)
|
||||
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
|
||||
(user[:pass]@]machine[:port][remote-dir). Delete
|
||||
the password.
|
||||
has_prefix = 1: Search p for known url prefixes. If found delete
|
||||
the password from the url.
|
||||
Caveat: only the first url is found
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* 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
|
||||
* (user[:pass]@]machine[:port][remote-dir). Delete
|
||||
* the password.
|
||||
* 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 *
|
||||
strip_password (char *p, int has_prefix)
|
||||
{
|
||||
@ -536,6 +700,8 @@ strip_password (char *p, int has_prefix)
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
strip_home_and_password (const char *dir)
|
||||
{
|
||||
@ -558,6 +724,8 @@ strip_home_and_password (const char *dir)
|
||||
return newdir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
extension (const char *filename)
|
||||
{
|
||||
@ -565,12 +733,16 @@ extension (const char *filename)
|
||||
return (d != NULL) ? d + 1 : "";
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
exist_file (const char *name)
|
||||
{
|
||||
return access (name, R_OK) == 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
load_file (const char *filename)
|
||||
@ -627,6 +799,8 @@ load_file (const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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
|
||||
i18n_checktimelength (void)
|
||||
{
|
||||
@ -695,10 +872,11 @@ i18n_checktimelength (void)
|
||||
lt->tm_sec = lt->tm_min = lt->tm_hour = lt->tm_mday = 10;
|
||||
|
||||
/* Loop through all months to find out the longest one */
|
||||
for (lt->tm_mon = 0; lt->tm_mon < 12; lt->tm_mon++) {
|
||||
strftime (buf, sizeof(buf) - 1, user_recent_timeformat, lt);
|
||||
for (lt->tm_mon = 0; lt->tm_mon < 12; lt->tm_mon++)
|
||||
{
|
||||
strftime (buf, sizeof (buf) - 1, user_recent_timeformat, lt);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -715,6 +893,8 @@ i18n_checktimelength (void)
|
||||
return i18n_timelength_cache;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
file_date (time_t when)
|
||||
{
|
||||
@ -740,6 +920,8 @@ file_date (time_t when)
|
||||
return timebuf;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
extract_line (const char *s, const char *top)
|
||||
{
|
||||
@ -752,7 +934,11 @@ extract_line (const char *s, const char *top)
|
||||
return tmp_line;
|
||||
}
|
||||
|
||||
/* The basename routine */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* The basename routine
|
||||
*/
|
||||
|
||||
const char *
|
||||
x_basename (const char *s)
|
||||
{
|
||||
@ -760,6 +946,7 @@ x_basename (const char *s)
|
||||
return ((where = strrchr (s, PATH_SEP))) ? where + 1 : s;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
unix_error_string (int error_num)
|
||||
@ -774,6 +961,8 @@ unix_error_string (int error_num)
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
skip_separators (const char *s)
|
||||
{
|
||||
@ -786,6 +975,8 @@ skip_separators (const char *s)
|
||||
return su;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
skip_numbers (const char *s)
|
||||
{
|
||||
@ -798,7 +989,9 @@ skip_numbers (const char *s)
|
||||
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-seq = Esc non-'['
|
||||
@ -883,6 +1076,8 @@ strip_ctrl_codes (char *s)
|
||||
return s;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
enum compression_type
|
||||
get_compression_type (int fd, const char *name)
|
||||
{
|
||||
@ -961,6 +1156,8 @@ get_compression_type (int fd, const char *name)
|
||||
return COMPRESSION_NONE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
decompress_extension (int type)
|
||||
{
|
||||
@ -982,7 +1179,9 @@ decompress_extension (int type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Hooks */
|
||||
|
||||
void
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
execute_hooks (Hook * hook_list)
|
||||
{
|
||||
@ -1026,6 +1227,8 @@ execute_hooks (Hook * hook_list)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
||||
{
|
||||
@ -1055,6 +1260,8 @@ hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
wipe_password (char *passwd)
|
||||
{
|
||||
@ -1067,8 +1274,12 @@ wipe_password (char *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 *
|
||||
convert_controls (const char *p)
|
||||
{
|
||||
@ -1114,108 +1325,12 @@ convert_controls (const char *p)
|
||||
return valcopy;
|
||||
}
|
||||
|
||||
static char *
|
||||
resolve_symlinks (const char *path)
|
||||
{
|
||||
char *buf, *buf2, *q, *r, c;
|
||||
int len;
|
||||
struct stat mybuf;
|
||||
const char *p;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
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 *
|
||||
diff_two_paths (const char *first, const char *second)
|
||||
{
|
||||
@ -1283,7 +1398,11 @@ diff_two_paths (const char *first, const char *second)
|
||||
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 *
|
||||
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);
|
||||
}
|
||||
|
||||
/* Append text to GList, remove all entries with the same text */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Append text to GList, remove all entries with the same text
|
||||
*/
|
||||
|
||||
GList *
|
||||
list_append_unique (GList * list, char *text)
|
||||
{
|
||||
@ -1329,13 +1452,8 @@ list_append_unique (GList * list, char *text)
|
||||
return list;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* 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:
|
||||
* 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:
|
||||
* handle of the open file or -1 if couldn't open any.
|
||||
*/
|
||||
|
||||
int
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Read and restore position for the given filename.
|
||||
* If there is no stored data, return line 1 and col 0.
|
||||
*/
|
||||
|
||||
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;
|
||||
FILE *f;
|
||||
@ -1503,10 +1625,13 @@ load_file_position (const char *filename, long *line, long *column, off_t * offs
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
/* Save position for the given file */
|
||||
#define TMP_SUFFIX ".tmp"
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Save position for the given file
|
||||
*/
|
||||
|
||||
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;
|
||||
char *fn, *tmp_fn;
|
||||
@ -1556,7 +1681,8 @@ save_file_position (const char *filename, long line, long column, off_t offset,
|
||||
i = 1;
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
#undef TMP_SUFFIX
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern const char *
|
||||
cstrcasestr (const char *haystack, const char *needle)
|
||||
{
|
||||
@ -1589,22 +1716,23 @@ cstrcasestr (const char *haystack, const char *needle)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
cstrstr (const char *haystack, const char *needle)
|
||||
{
|
||||
return strstr (haystack, needle);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
extern char *
|
||||
str_unconst (const 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
|
||||
ascii_alpha_to_cntrl (int ch)
|
||||
@ -1616,6 +1744,8 @@ ascii_alpha_to_cntrl (int ch)
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
const char *
|
||||
Q_ (const char *s)
|
||||
{
|
||||
@ -1626,6 +1756,7 @@ Q_ (const char *s)
|
||||
return (sep != NULL) ? sep + 1 : result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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 *
|
||||
guess_message_value (void)
|
||||
{
|
||||
@ -1722,3 +1861,5 @@ guess_message_value (void)
|
||||
|
||||
return g_strdup (locale);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
217
lib/util.h
217
lib/util.h
@ -1,4 +1,3 @@
|
||||
|
||||
/** \file util.h
|
||||
* \brief Header: various utilities
|
||||
*/
|
||||
@ -14,9 +13,119 @@
|
||||
#include <sys/stat.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_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
|
||||
* intended to pass strings to legacy libraries that don't know yet
|
||||
* 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_owner (int);
|
||||
|
||||
#define MAX_I18NTIMELENGTH 20
|
||||
#define MIN_I18NTIMELENGTH 10
|
||||
#define STD_I18NTIMELENGTH 12
|
||||
|
||||
size_t i18n_checktimelength (void);
|
||||
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 */
|
||||
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 */
|
||||
void open_error_pipe (void);
|
||||
void check_error_pipe (void);
|
||||
@ -144,21 +240,10 @@ int close_error_pipe (int error, const char *text);
|
||||
/* Process spawning */
|
||||
int my_system (int flags, const char *shell, const char *command);
|
||||
void save_stop_handler (void);
|
||||
extern struct sigaction startup_handler;
|
||||
|
||||
/* Tilde expansion */
|
||||
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 canonicalize_pathname (char *);
|
||||
|
||||
@ -170,38 +255,12 @@ int my_rmdir (const char *s);
|
||||
const char *mc_tmpdir (void);
|
||||
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
|
||||
#define mc_realpath realpath
|
||||
#else
|
||||
char *mc_realpath (const char *path, char *resolved_path);
|
||||
#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
|
||||
* compression type. Side effect: modifies the file position. */
|
||||
enum compression_type get_compression_type (int fd, const char *);
|
||||
@ -209,12 +268,6 @@ const char *decompress_extension (int type);
|
||||
|
||||
/* 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 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);
|
||||
|
||||
/* Position saving and restoring */
|
||||
#define MAX_SAVED_BOOKMARKS 10
|
||||
/* Load position for the given filename */
|
||||
void load_file_position (const char *filename, long *line, long *column, off_t * offset,
|
||||
GArray **bookmarks);
|
||||
@ -233,39 +285,6 @@ void save_file_position (const char *filename, long line, long column, off_t off
|
||||
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,
|
||||
* else returns the argument. */
|
||||
extern int ascii_alpha_to_cntrl (int ch);
|
||||
@ -273,7 +292,14 @@ extern int ascii_alpha_to_cntrl (int ch);
|
||||
#undef Q_
|
||||
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
|
||||
@ -298,12 +324,5 @@ str_move (char *dest, const char *src)
|
||||
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 */
|
||||
|
@ -42,7 +42,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.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
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
@ -57,20 +60,38 @@
|
||||
#include "src/charsets.h"
|
||||
#endif
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
struct sigaction startup_handler;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define UID_CACHE_SIZE 200
|
||||
#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
|
||||
{
|
||||
int index;
|
||||
char *string;
|
||||
} int_cache;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static int_cache uid_cache[UID_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 *
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
get_owner (int uid)
|
||||
{
|
||||
@ -116,6 +143,8 @@ get_owner (int uid)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
char *
|
||||
get_group (int gid)
|
||||
{
|
||||
@ -141,15 +170,19 @@ get_group (int gid)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Since ncurses uses a handler that automatically refreshes the */
|
||||
/* screen after a SIGCONT, and we don't want this behavior when */
|
||||
/* spawning a child, we save the original handler here */
|
||||
|
||||
void
|
||||
save_stop_handler (void)
|
||||
{
|
||||
sigaction (SIGTSTP, NULL, &startup_handler);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
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)
|
||||
{
|
||||
status = WEXITSTATUS(status);
|
||||
status = WEXITSTATUS (status);
|
||||
break;
|
||||
}
|
||||
if (errno != EINTR)
|
||||
@ -231,10 +264,12 @@ my_system (int flags, const char *shell, const char *command)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Perform tilde expansion if possible.
|
||||
* Always return a newly allocated string, even if it's unchanged.
|
||||
*/
|
||||
|
||||
char *
|
||||
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 the directory where mc should keep its temporary files.
|
||||
* This directory is (in Bourne shell terms) "${TMPDIR=/tmp}/mc-$USER"
|
||||
* When called the first time, the directory is created if needed.
|
||||
* The first call should be done early, since we are using fprintf()
|
||||
* and not message() to report possible problems.
|
||||
*/
|
||||
|
||||
const char *
|
||||
mc_tmpdir (void)
|
||||
{
|
||||
@ -384,17 +421,13 @@ mc_tmpdir (void)
|
||||
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
|
||||
open_error_pipe (void)
|
||||
{
|
||||
@ -436,11 +469,13 @@ open_error_pipe (void)
|
||||
error_pipe[1] = -1;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Returns true if an error was displayed
|
||||
* error: -1 - ignore errors, 0 - display warning, 1 - display error
|
||||
* text is prepended to the error message from the pipe
|
||||
*/
|
||||
|
||||
int
|
||||
close_error_pipe (int error, const char *text)
|
||||
{
|
||||
@ -489,7 +524,8 @@ close_error_pipe (int error, const char *text)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Canonicalize path, and return a new path. Do everything in place.
|
||||
* The new path differs from path in:
|
||||
* Multiple `/'s are collapsed to a single `/'.
|
||||
@ -499,6 +535,7 @@ close_error_pipe (int error, const char *text)
|
||||
* portions of the path.
|
||||
* Well formed UNC paths are modified only in the local part.
|
||||
*/
|
||||
|
||||
void
|
||||
custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
||||
{
|
||||
@ -689,15 +726,17 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
canonicalize_pathname (char *path)
|
||||
{
|
||||
custom_canonicalize_pathname (path, CANON_PATH_ALL);
|
||||
}
|
||||
|
||||
#ifdef HAVE_GET_PROCESS_STATS
|
||||
# include <sys/procstats.h>
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef HAVE_GET_PROCESS_STATS
|
||||
int
|
||||
gettimeofday (struct timeval *tp, void *tzp)
|
||||
{
|
||||
@ -705,6 +744,8 @@ gettimeofday (struct timeval *tp, void *tzp)
|
||||
}
|
||||
#endif /* HAVE_GET_PROCESS_STATS */
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef HAVE_REALPATH
|
||||
char *
|
||||
mc_realpath (const char *path, char *resolved_path)
|
||||
@ -847,7 +888,12 @@ mc_realpath (const char *path, char *resolved_path)
|
||||
}
|
||||
#endif /* HAVE_REALPATH */
|
||||
|
||||
/* Return the index of the permissions triplet */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Return the index of the permissions triplet
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
get_user_permissions (struct stat *st)
|
||||
{
|
||||
@ -894,3 +940,5 @@ get_user_permissions (struct stat *st)
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -39,7 +39,28 @@
|
||||
#include "xdirentry.h"
|
||||
#include "gc.h" /* vfs_rmstamp */
|
||||
|
||||
enum {
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define CPIO_POS(super) cpio_position
|
||||
/* If some time reentrancy should be needed change it to */
|
||||
/* #define CPIO_POS(super) (super)->u.arch.fd */
|
||||
|
||||
#define CPIO_SEEK_SET(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) = (where), SEEK_SET)
|
||||
#define CPIO_SEEK_CUR(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) += (where), SEEK_SET)
|
||||
|
||||
#define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */
|
||||
#define SEEKBACK CPIO_SEEK_CUR(super, ptr - top)
|
||||
#define RETURN(x) return(super->u.arch.type = (x))
|
||||
#define TYPEIS(x) ((super->u.arch.type == CPIO_UNKNOWN) || (super->u.arch.type == (x)))
|
||||
|
||||
#define HEAD_LENGTH (26)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum
|
||||
{
|
||||
STATUS_START,
|
||||
STATUS_OK,
|
||||
STATUS_TRAIL,
|
||||
@ -47,7 +68,8 @@ enum {
|
||||
STATUS_EOF
|
||||
};
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CPIO_UNKNOWN = 0, /* Not determined yet */
|
||||
CPIO_BIN, /* Binary format */
|
||||
CPIO_BINRE, /* Binary format, reverse endianity */
|
||||
@ -56,8 +78,6 @@ enum {
|
||||
CPIO_CRC /* New ASCII format + CRC */
|
||||
};
|
||||
|
||||
static struct vfs_class vfs_cpiofs_ops;
|
||||
|
||||
struct old_cpio_header
|
||||
{
|
||||
unsigned short c_magic;
|
||||
@ -91,28 +111,31 @@ struct new_cpio_header
|
||||
unsigned long c_chksum;
|
||||
};
|
||||
|
||||
struct defer_inode {
|
||||
struct defer_inode
|
||||
{
|
||||
struct defer_inode *next;
|
||||
unsigned long inumber;
|
||||
unsigned short device;
|
||||
struct vfs_s_inode *inode;
|
||||
};
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct vfs_class vfs_cpiofs_ops;
|
||||
|
||||
/* FIXME: should be off_t instead of int. */
|
||||
static int cpio_position;
|
||||
|
||||
static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_crc_head(struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read(void *fh, char *buffer, size_t count);
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#define CPIO_POS(super) cpio_position
|
||||
/* If some time reentrancy should be needed change it to */
|
||||
/* #define CPIO_POS(super) (super)->u.arch.fd */
|
||||
static int cpio_find_head (struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_oldc_head (struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super);
|
||||
static ssize_t cpio_read (void *fh, char *buffer, size_t count);
|
||||
|
||||
#define CPIO_SEEK_SET(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) = (where), SEEK_SET)
|
||||
#define CPIO_SEEK_CUR(super, where) mc_lseek((super)->u.arch.fd, CPIO_POS(super) += (where), SEEK_SET)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct defer_inode *
|
||||
cpio_defer_find (struct defer_inode *l, struct defer_inode *i)
|
||||
@ -122,49 +145,59 @@ cpio_defer_find (struct defer_inode *l, struct defer_inode *i)
|
||||
return l;
|
||||
}
|
||||
|
||||
static int cpio_skip_padding(struct vfs_s_super *super)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_skip_padding (struct vfs_s_super *super)
|
||||
{
|
||||
switch(super->u.arch.type) {
|
||||
switch (super->u.arch.type)
|
||||
{
|
||||
case CPIO_BIN:
|
||||
case CPIO_BINRE:
|
||||
return CPIO_SEEK_CUR(super, (2 - (CPIO_POS(super) % 2)) % 2);
|
||||
return CPIO_SEEK_CUR (super, (2 - (CPIO_POS (super) % 2)) % 2);
|
||||
case CPIO_NEWC:
|
||||
case CPIO_CRC:
|
||||
return CPIO_SEEK_CUR(super, (4 - (CPIO_POS(super) % 4)) % 4);
|
||||
return CPIO_SEEK_CUR (super, (4 - (CPIO_POS (super) % 4)) % 4);
|
||||
case CPIO_OLDC:
|
||||
return CPIO_POS(super);
|
||||
return CPIO_POS (super);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
g_assert_not_reached ();
|
||||
return 42; /* & the compiler is happy :-) */
|
||||
}
|
||||
}
|
||||
|
||||
static void cpio_free_archive(struct vfs_class *me, struct vfs_s_super *super)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
struct defer_inode *l, *lnext;
|
||||
|
||||
(void) me;
|
||||
|
||||
if(super->u.arch.fd != -1)
|
||||
mc_close(super->u.arch.fd);
|
||||
if (super->u.arch.fd != -1)
|
||||
mc_close (super->u.arch.fd);
|
||||
super->u.arch.fd = -1;
|
||||
for (l = super->u.arch.deferred; l; l = lnext) {
|
||||
for (l = super->u.arch.deferred; l; l = lnext)
|
||||
{
|
||||
lnext = l->next;
|
||||
g_free (l);
|
||||
}
|
||||
super->u.arch.deferred = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
|
||||
const char *name)
|
||||
cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super, const char *name)
|
||||
{
|
||||
int fd, type;
|
||||
mode_t mode;
|
||||
struct vfs_s_inode *root;
|
||||
|
||||
fd = mc_open (name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
|
||||
return -1;
|
||||
}
|
||||
@ -175,13 +208,15 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
|
||||
super->u.arch.type = CPIO_UNKNOWN;
|
||||
|
||||
type = get_compression_type (fd, name);
|
||||
if (type != COMPRESSION_NONE) {
|
||||
if (type != COMPRESSION_NONE)
|
||||
{
|
||||
char *s;
|
||||
|
||||
mc_close (fd);
|
||||
s = g_strconcat (name, decompress_extension (type), (char *) NULL);
|
||||
fd = mc_open (s, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
if (fd == -1)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
|
||||
g_free (s);
|
||||
return -1;
|
||||
@ -207,30 +242,33 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return fd;
|
||||
}
|
||||
|
||||
static ssize_t cpio_read_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
cpio_read_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
switch(cpio_find_head(me, super)) {
|
||||
switch (cpio_find_head (me, super))
|
||||
{
|
||||
case CPIO_UNKNOWN:
|
||||
return -1;
|
||||
case CPIO_BIN:
|
||||
case CPIO_BINRE:
|
||||
return cpio_read_bin_head(me, super);
|
||||
return cpio_read_bin_head (me, super);
|
||||
case CPIO_OLDC:
|
||||
return cpio_read_oldc_head(me, super);
|
||||
return cpio_read_oldc_head (me, super);
|
||||
case CPIO_NEWC:
|
||||
case CPIO_CRC:
|
||||
return cpio_read_crc_head(me, super);
|
||||
return cpio_read_crc_head (me, super);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
g_assert_not_reached ();
|
||||
return 42; /* & the compiler is happy :-) */
|
||||
}
|
||||
}
|
||||
|
||||
#define MAGIC_LENGTH (6) /* How many bytes we have to read ahead */
|
||||
#define SEEKBACK CPIO_SEEK_CUR(super, ptr - top)
|
||||
#define RETURN(x) return(super->u.arch.type = (x))
|
||||
#define TYPEIS(x) ((super->u.arch.type == CPIO_UNKNOWN) || (super->u.arch.type == (x)))
|
||||
static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_find_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
char buf[256];
|
||||
int ptr = 0;
|
||||
@ -240,48 +278,67 @@ static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
top = mc_read (super->u.arch.fd, buf, 256);
|
||||
if (top > 0)
|
||||
CPIO_POS (super) += top;
|
||||
for(;;) {
|
||||
if(ptr + MAGIC_LENGTH >= top) {
|
||||
if(top > 128) {
|
||||
memmove(buf, buf + top - 128, 128);
|
||||
for (;;)
|
||||
{
|
||||
if (ptr + MAGIC_LENGTH >= top)
|
||||
{
|
||||
if (top > 128)
|
||||
{
|
||||
memmove (buf, buf + top - 128, 128);
|
||||
ptr -= top - 128;
|
||||
top = 128;
|
||||
}
|
||||
tmp = mc_read (super->u.arch.fd, buf, top);
|
||||
if (tmp == 0 || tmp == -1) {
|
||||
if (tmp == 0 || tmp == -1)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
|
||||
cpio_free_archive(me, super);
|
||||
cpio_free_archive (me, super);
|
||||
return CPIO_UNKNOWN;
|
||||
}
|
||||
top += tmp;
|
||||
}
|
||||
if(TYPEIS(CPIO_BIN) && ((*(unsigned short *)(buf + ptr)) == 070707)) {
|
||||
SEEKBACK; RETURN(CPIO_BIN);
|
||||
} else if(TYPEIS(CPIO_BINRE) && ((*(unsigned short *)(buf + ptr)) == GUINT16_SWAP_LE_BE_CONSTANT(070707))) {
|
||||
SEEKBACK; RETURN(CPIO_BINRE);
|
||||
} else if(TYPEIS(CPIO_OLDC) && (!strncmp(buf + ptr, "070707", 6))) {
|
||||
SEEKBACK; RETURN(CPIO_OLDC);
|
||||
} else if(TYPEIS(CPIO_NEWC) && (!strncmp(buf + ptr, "070701", 6))) {
|
||||
SEEKBACK; RETURN(CPIO_NEWC);
|
||||
} else if(TYPEIS(CPIO_CRC) && (!strncmp(buf + ptr, "070702", 6))) {
|
||||
SEEKBACK; RETURN(CPIO_CRC);
|
||||
if (TYPEIS (CPIO_BIN) && ((*(unsigned short *) (buf + ptr)) == 070707))
|
||||
{
|
||||
SEEKBACK;
|
||||
RETURN (CPIO_BIN);
|
||||
}
|
||||
else if (TYPEIS (CPIO_BINRE)
|
||||
&& ((*(unsigned short *) (buf + ptr)) == GUINT16_SWAP_LE_BE_CONSTANT (070707)))
|
||||
{
|
||||
SEEKBACK;
|
||||
RETURN (CPIO_BINRE);
|
||||
}
|
||||
else if (TYPEIS (CPIO_OLDC) && (!strncmp (buf + ptr, "070707", 6)))
|
||||
{
|
||||
SEEKBACK;
|
||||
RETURN (CPIO_OLDC);
|
||||
}
|
||||
else if (TYPEIS (CPIO_NEWC) && (!strncmp (buf + ptr, "070701", 6)))
|
||||
{
|
||||
SEEKBACK;
|
||||
RETURN (CPIO_NEWC);
|
||||
}
|
||||
else if (TYPEIS (CPIO_CRC) && (!strncmp (buf + ptr, "070702", 6)))
|
||||
{
|
||||
SEEKBACK;
|
||||
RETURN (CPIO_CRC);
|
||||
};
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
#undef RETURN
|
||||
#undef SEEKBACK
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
struct stat *st, char *name)
|
||||
cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super, struct stat *st, char *name)
|
||||
{
|
||||
struct vfs_s_inode *inode = NULL;
|
||||
struct vfs_s_inode *root = super->root;
|
||||
struct vfs_s_entry *entry = NULL;
|
||||
char *tn;
|
||||
|
||||
switch (st->st_mode & S_IFMT) { /* For case of HP/UX archives */
|
||||
switch (st->st_mode & S_IFMT)
|
||||
{ /* For case of HP/UX archives */
|
||||
case S_IFCHR:
|
||||
case S_IFBLK:
|
||||
#ifdef S_IFSOCK
|
||||
@ -293,7 +350,8 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
#ifdef S_IFNAM
|
||||
case S_IFNAM:
|
||||
#endif
|
||||
if ((st->st_size != 0) && (st->st_rdev == 0x0001)) {
|
||||
if ((st->st_size != 0) && (st->st_rdev == 0x0001))
|
||||
{
|
||||
/* FIXME: representation of major/minor differs between */
|
||||
/* different operating systems. */
|
||||
st->st_rdev = (unsigned) st->st_size;
|
||||
@ -305,23 +363,25 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
}
|
||||
|
||||
if ((st->st_nlink > 1)
|
||||
&& ((super->u.arch.type == CPIO_NEWC)
|
||||
|| (super->u.arch.type == CPIO_CRC))) { /* For case of hardlinked files */
|
||||
&& ((super->u.arch.type == CPIO_NEWC) || (super->u.arch.type == CPIO_CRC)))
|
||||
{ /* For case of hardlinked files */
|
||||
struct defer_inode i, *l;
|
||||
i.inumber = st->st_ino;
|
||||
i.device = st->st_dev;
|
||||
i.inode = NULL;
|
||||
|
||||
l = cpio_defer_find (super->u.arch.deferred, &i);
|
||||
if (l != NULL) {
|
||||
if (l != NULL)
|
||||
{
|
||||
inode = l->inode;
|
||||
if (inode->st.st_size != 0 && st->st_size != 0
|
||||
&& (inode->st.st_size != st->st_size)) {
|
||||
if (inode->st.st_size != 0 && st->st_size != 0 && (inode->st.st_size != st->st_size))
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR,
|
||||
_("Inconsistent hardlinks of\n%s\nin cpio archive\n%s"),
|
||||
name, super->name);
|
||||
inode = NULL;
|
||||
} else if (inode->st.st_size == 0)
|
||||
}
|
||||
else if (inode->st.st_size == 0)
|
||||
inode->st.st_size = st->st_size;
|
||||
}
|
||||
}
|
||||
@ -333,10 +393,13 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
tn = strrchr (name, PATH_SEP);
|
||||
if (tn == NULL)
|
||||
tn = name;
|
||||
else if (tn == name + 1) {
|
||||
else if (tn == name + 1)
|
||||
{
|
||||
/* started with "./" -- directory in the root of archive */
|
||||
tn++;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*tn = '\0';
|
||||
root = vfs_s_find_inode (me, super, name, LINK_FOLLOW, FL_MKDIR);
|
||||
*tn = PATH_SEP;
|
||||
@ -345,17 +408,20 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
|
||||
entry = MEDATA->find_entry (me, root, tn, LINK_FOLLOW, FL_NONE); /* In case entry is already there */
|
||||
|
||||
if (entry != NULL) {
|
||||
if (entry != NULL)
|
||||
{
|
||||
/* This shouldn't happen! (well, it can happen if there is a record for a
|
||||
file and than a record for a directory it is in; cpio would die with
|
||||
'No such file or directory' is such case) */
|
||||
|
||||
if (!S_ISDIR (entry->ino->st.st_mode)) {
|
||||
if (!S_ISDIR (entry->ino->st.st_mode))
|
||||
{
|
||||
/* This can be considered archive inconsistency */
|
||||
message (D_ERROR, MSG_ERROR,
|
||||
_("%s contains duplicate entries! Skipping!"),
|
||||
super->name);
|
||||
} else {
|
||||
_("%s contains duplicate entries! Skipping!"), super->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry->ino->st.st_mode = st->st_mode;
|
||||
entry->ino->st.st_uid = st->st_uid;
|
||||
entry->ino->st.st_gid = st->st_gid;
|
||||
@ -365,12 +431,15 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
}
|
||||
|
||||
g_free (name);
|
||||
} else { /* !entry */
|
||||
if (inode == NULL) {
|
||||
}
|
||||
else
|
||||
{ /* !entry */
|
||||
if (inode == NULL)
|
||||
{
|
||||
inode = vfs_s_new_inode (me, super, st);
|
||||
if ((st->st_nlink > 0)
|
||||
&& ((super->u.arch.type == CPIO_NEWC)
|
||||
|| (super->u.arch.type == CPIO_CRC))) {
|
||||
&& ((super->u.arch.type == CPIO_NEWC) || (super->u.arch.type == CPIO_CRC)))
|
||||
{
|
||||
/* For case of hardlinked files */
|
||||
struct defer_inode *i;
|
||||
i = g_new (struct defer_inode, 1);
|
||||
@ -392,10 +461,12 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
|
||||
if (!S_ISLNK (st->st_mode))
|
||||
CPIO_SEEK_CUR (super, st->st_size);
|
||||
else {
|
||||
else
|
||||
{
|
||||
inode->linkname = g_malloc (st->st_size + 1);
|
||||
|
||||
if (mc_read (super->u.arch.fd, inode->linkname, st->st_size) < st->st_size) {
|
||||
if (mc_read (super->u.arch.fd, inode->linkname, st->st_size) < st->st_size)
|
||||
{
|
||||
inode->linkname[0] = '\0';
|
||||
return STATUS_EOF;
|
||||
}
|
||||
@ -409,10 +480,13 @@ cpio_create_entry (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return STATUS_OK;
|
||||
}
|
||||
|
||||
#define HEAD_LENGTH (26)
|
||||
static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
cpio_read_bin_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct old_cpio_header buf;
|
||||
short shorts[HEAD_LENGTH >> 1];
|
||||
} u;
|
||||
@ -420,34 +494,36 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
|
||||
char *name;
|
||||
struct stat st;
|
||||
|
||||
len = mc_read (super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH);
|
||||
len = mc_read (super->u.arch.fd, (char *) &u.buf, HEAD_LENGTH);
|
||||
if (len < HEAD_LENGTH)
|
||||
return STATUS_EOF;
|
||||
CPIO_POS(super) += len;
|
||||
if(super->u.arch.type == CPIO_BINRE) {
|
||||
CPIO_POS (super) += len;
|
||||
if (super->u.arch.type == CPIO_BINRE)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < (HEAD_LENGTH >> 1); i++)
|
||||
u.shorts[i] = GUINT16_SWAP_LE_BE_CONSTANT(u.shorts[i]);
|
||||
for (i = 0; i < (HEAD_LENGTH >> 1); i++)
|
||||
u.shorts[i] = GUINT16_SWAP_LE_BE_CONSTANT (u.shorts[i]);
|
||||
}
|
||||
|
||||
if (u.buf.c_magic != 070707 ||
|
||||
u.buf.c_namesize == 0 || u.buf.c_namesize > MC_MAXPATHLEN) {
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
|
||||
super->name);
|
||||
if (u.buf.c_magic != 070707 || u.buf.c_namesize == 0 || u.buf.c_namesize > MC_MAXPATHLEN)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"), super->name);
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
name = g_malloc(u.buf.c_namesize);
|
||||
name = g_malloc (u.buf.c_namesize);
|
||||
len = mc_read (super->u.arch.fd, name, u.buf.c_namesize);
|
||||
if (len < u.buf.c_namesize) {
|
||||
g_free(name);
|
||||
if (len < u.buf.c_namesize)
|
||||
{
|
||||
g_free (name);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
name[u.buf.c_namesize - 1] = '\0';
|
||||
CPIO_POS(super) += len;
|
||||
cpio_skip_padding(super);
|
||||
CPIO_POS (super) += len;
|
||||
cpio_skip_padding (super);
|
||||
|
||||
if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
|
||||
g_free(name);
|
||||
if (!strcmp ("TRAILER!!!", name))
|
||||
{ /* We got to the last record */
|
||||
g_free (name);
|
||||
return STATUS_TRAIL;
|
||||
}
|
||||
|
||||
@ -461,15 +537,20 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
|
||||
st.st_size = (u.buf.c_filesizes[0] << 16) | u.buf.c_filesizes[1];
|
||||
st.st_atime = st.st_mtime = st.st_ctime = (u.buf.c_mtimes[0] << 16) | u.buf.c_mtimes[1];
|
||||
|
||||
return cpio_create_entry(me, super, &st, name);
|
||||
return cpio_create_entry (me, super, &st, name);
|
||||
}
|
||||
#undef HEAD_LENGTH
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#undef HEAD_LENGTH
|
||||
#define HEAD_LENGTH (76)
|
||||
static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
|
||||
static ssize_t
|
||||
cpio_read_oldc_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
struct new_cpio_header hd;
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct stat st;
|
||||
char buf[HEAD_LENGTH + 1];
|
||||
} u;
|
||||
@ -482,31 +563,33 @@ static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *sup
|
||||
u.buf[HEAD_LENGTH] = 0;
|
||||
|
||||
if (sscanf (u.buf, "070707%6lo%6lo%6lo%6lo%6lo%6lo%6lo%11lo%6lo%11lo",
|
||||
(unsigned long *)&hd.c_dev, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
|
||||
&hd.c_nlink, (unsigned long *)&hd.c_rdev, &hd.c_mtime,
|
||||
&hd.c_namesize, &hd.c_filesize) < 10) {
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
|
||||
super->name);
|
||||
(unsigned long *) &hd.c_dev, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
|
||||
&hd.c_nlink, (unsigned long *) &hd.c_rdev, &hd.c_mtime,
|
||||
&hd.c_namesize, &hd.c_filesize) < 10)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"), super->name);
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
|
||||
super->name);
|
||||
if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"), super->name);
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
name = g_malloc(hd.c_namesize);
|
||||
name = g_malloc (hd.c_namesize);
|
||||
len = mc_read (super->u.arch.fd, name, hd.c_namesize);
|
||||
if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
|
||||
if ((len == -1) || ((unsigned long) len < hd.c_namesize))
|
||||
{
|
||||
g_free (name);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
name[hd.c_namesize - 1] = '\0';
|
||||
CPIO_POS(super) += len;
|
||||
cpio_skip_padding(super);
|
||||
CPIO_POS (super) += len;
|
||||
cpio_skip_padding (super);
|
||||
|
||||
if(!strcmp("TRAILER!!!", name)) { /* We got to the last record */
|
||||
g_free(name);
|
||||
if (!strcmp ("TRAILER!!!", name))
|
||||
{ /* We got to the last record */
|
||||
g_free (name);
|
||||
return STATUS_TRAIL;
|
||||
}
|
||||
|
||||
@ -522,14 +605,18 @@ static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *sup
|
||||
|
||||
return cpio_create_entry (me, super, &u.st, name);
|
||||
}
|
||||
#undef HEAD_LENGTH
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#undef HEAD_LENGTH
|
||||
#define HEAD_LENGTH (110)
|
||||
|
||||
static ssize_t
|
||||
cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
struct new_cpio_header hd;
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct stat st;
|
||||
char buf[HEAD_LENGTH + 1];
|
||||
} u;
|
||||
@ -545,37 +632,39 @@ cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
if (sscanf (u.buf, "%6ho%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx%8lx",
|
||||
&hd.c_magic, &hd.c_ino, &hd.c_mode, &hd.c_uid, &hd.c_gid,
|
||||
&hd.c_nlink, &hd.c_mtime, &hd.c_filesize,
|
||||
(unsigned long *)&hd.c_dev, (unsigned long *)&hd.c_devmin,
|
||||
(unsigned long *)&hd.c_rdev, (unsigned long *)&hd.c_rdevmin,
|
||||
&hd.c_namesize, &hd.c_chksum) < 14) {
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
|
||||
super->name);
|
||||
(unsigned long *) &hd.c_dev, (unsigned long *) &hd.c_devmin,
|
||||
(unsigned long *) &hd.c_rdev, (unsigned long *) &hd.c_rdevmin,
|
||||
&hd.c_namesize, &hd.c_chksum) < 14)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"), super->name);
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
if((super->u.arch.type == CPIO_NEWC && hd.c_magic != 070701) ||
|
||||
if ((super->u.arch.type == CPIO_NEWC && hd.c_magic != 070701) ||
|
||||
(super->u.arch.type == CPIO_CRC && hd.c_magic != 070702))
|
||||
return STATUS_FAIL;
|
||||
|
||||
if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN) {
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"),
|
||||
super->name);
|
||||
if (hd.c_namesize == 0 || hd.c_namesize > MC_MAXPATHLEN)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Corrupted cpio header encountered in\n%s"), super->name);
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
|
||||
name = g_malloc(hd.c_namesize);
|
||||
name = g_malloc (hd.c_namesize);
|
||||
len = mc_read (super->u.arch.fd, name, hd.c_namesize);
|
||||
|
||||
if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
|
||||
if ((len == -1) || ((unsigned long) len < hd.c_namesize))
|
||||
{
|
||||
g_free (name);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
name[hd.c_namesize - 1] = '\0';
|
||||
CPIO_POS(super) += len;
|
||||
cpio_skip_padding(super);
|
||||
CPIO_POS (super) += len;
|
||||
cpio_skip_padding (super);
|
||||
|
||||
if (strcmp ("TRAILER!!!", name) == 0) { /* We got to the last record */
|
||||
g_free(name);
|
||||
if (strcmp ("TRAILER!!!", name) == 0)
|
||||
{ /* We got to the last record */
|
||||
g_free (name);
|
||||
return STATUS_TRAIL;
|
||||
}
|
||||
|
||||
@ -592,11 +681,11 @@ cpio_read_crc_head (struct vfs_class *me, struct vfs_s_super *super)
|
||||
return cpio_create_entry (me, super, &u.st, name);
|
||||
}
|
||||
|
||||
/* Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Need to CPIO_SEEK_CUR to skip the file at the end of add entry!!!! */
|
||||
|
||||
static int
|
||||
cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
const char *name, char *op)
|
||||
cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super, const char *name, char *op)
|
||||
{
|
||||
int status = STATUS_START;
|
||||
|
||||
@ -605,10 +694,12 @@ cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
if (cpio_open_cpio_file (me, super, name) == -1)
|
||||
return -1;
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
status = cpio_read_head (me, super);
|
||||
|
||||
switch (status) {
|
||||
switch (status)
|
||||
{
|
||||
case STATUS_EOF:
|
||||
message (D_ERROR, MSG_ERROR, _("Unexpected end of file\n%s"), name);
|
||||
return 0;
|
||||
@ -623,7 +714,9 @@ cpio_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remaining functions are exactly same as for tarfs (and were in fact just copied) */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Remaining functions are exactly same as for tarfs (and were in fact just copied) */
|
||||
|
||||
static void *
|
||||
cpio_super_check (struct vfs_class *me, const char *archive_name, char *op)
|
||||
{
|
||||
@ -637,6 +730,8 @@ cpio_super_check (struct vfs_class *me, const char *archive_name, char *op)
|
||||
return &sb;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
const char *archive_name, char *op, void *cookie)
|
||||
@ -650,7 +745,8 @@ cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
return 0;
|
||||
|
||||
/* Has the cached archive been changed on the disk? */
|
||||
if (parc->u.arch.st.st_mtime < archive_stat->st_mtime) {
|
||||
if (parc->u.arch.st.st_mtime < archive_stat->st_mtime)
|
||||
{
|
||||
/* Yes, reload! */
|
||||
(*vfs_cpiofs_ops.free) ((vfsid) parc);
|
||||
vfs_rmstamp (&vfs_cpiofs_ops, (vfsid) parc);
|
||||
@ -661,17 +757,20 @@ cpio_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ssize_t cpio_read(void *fh, char *buffer, size_t count)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
cpio_read (void *fh, char *buffer, size_t count)
|
||||
{
|
||||
off_t begin = FH->ino->data_offset;
|
||||
int fd = FH_SUPER->u.arch.fd;
|
||||
struct vfs_class *me = FH_SUPER->me;
|
||||
ssize_t res;
|
||||
|
||||
if (mc_lseek (fd, begin + FH->pos, SEEK_SET) !=
|
||||
begin + FH->pos) ERRNOR (EIO, -1);
|
||||
if (mc_lseek (fd, begin + FH->pos, SEEK_SET) != begin + FH->pos)
|
||||
ERRNOR (EIO, -1);
|
||||
|
||||
count = MIN(count, (size_t)(FH->ino->st.st_size - FH->pos));
|
||||
count = MIN (count, (size_t) (FH->ino->st.st_size - FH->pos));
|
||||
|
||||
res = mc_read (fd, buffer, count);
|
||||
if (res == -1)
|
||||
@ -681,15 +780,23 @@ static ssize_t cpio_read(void *fh, char *buffer, size_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int cpio_fh_open(struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
cpio_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||
{
|
||||
(void) fh;
|
||||
(void) mode;
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
|
||||
if ((flags & O_ACCMODE) != O_RDONLY)
|
||||
ERRNOR (EROFS, -1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_cpiofs (void)
|
||||
{
|
||||
@ -709,3 +816,5 @@ init_cpiofs (void)
|
||||
vfs_cpiofs_ops.setctl = NULL;
|
||||
vfs_register_class (&vfs_cpiofs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -57,9 +57,19 @@
|
||||
#include "utilvfs.h"
|
||||
#include "gc.h" /* vfs_rmstamp */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
GArray *extfs_plugins = NULL;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#undef ERRNOR
|
||||
#define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
|
||||
|
||||
#define RECORDSIZE 512
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
struct inode
|
||||
{
|
||||
nlink_t nlink;
|
||||
@ -116,19 +126,24 @@ typedef struct
|
||||
gboolean need_archive;
|
||||
} extfs_plugin_info_t;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static gboolean errloop;
|
||||
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_free (vfsid id);
|
||||
static void extfs_free_entry (struct entry *e);
|
||||
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
|
||||
extfs_make_dots (struct entry *ent)
|
||||
@ -164,6 +179,8 @@ extfs_make_dots (struct entry *ent)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct entry *
|
||||
extfs_generate_entry (struct archive *archive,
|
||||
const char *name, struct entry *parentry, mode_t mode)
|
||||
@ -208,6 +225,8 @@ extfs_generate_entry (struct archive *archive,
|
||||
return entry;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct entry *
|
||||
extfs_find_entry_int (struct entry *dir, char *name, GSList * list,
|
||||
gboolean make_dirs, gboolean make_file)
|
||||
@ -291,6 +310,8 @@ extfs_find_entry_int (struct entry *dir, char *name, GSList * list,
|
||||
return pent;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct entry *
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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
|
||||
extfs_free_archive (struct archive *archive)
|
||||
{
|
||||
@ -347,6 +372,8 @@ extfs_free_archive (struct archive *archive)
|
||||
g_free (archive);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static FILE *
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Main loop for reading an archive.
|
||||
* Return 0 on success, -1 on error.
|
||||
*/
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_which (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -602,10 +633,12 @@ extfs_which (struct vfs_class *me, const char *path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Dissect the path and create corresponding superblock. Note that inname
|
||||
* can be changed and the result may point inside the original string.
|
||||
*/
|
||||
|
||||
static char *
|
||||
extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive,
|
||||
gboolean do_not_open)
|
||||
@ -649,10 +682,12 @@ extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **arch
|
||||
return local;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Dissect the path and create corresponding superblock.
|
||||
* The result should be freed.
|
||||
*/
|
||||
|
||||
static char *
|
||||
extfs_get_path (struct vfs_class *me, const char *inname,
|
||||
struct archive **archive, gboolean do_not_open)
|
||||
@ -666,7 +701,9 @@ extfs_get_path (struct vfs_class *me, const char *inname,
|
||||
return res2;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Return allocated path (without leading slash) inside the archive */
|
||||
|
||||
static char *
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct entry *
|
||||
extfs_resolve_symlinks_int (struct entry *entry, GSList * list)
|
||||
{
|
||||
@ -713,6 +752,8 @@ extfs_resolve_symlinks_int (struct entry *entry, GSList * list)
|
||||
return pent;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static struct entry *
|
||||
extfs_resolve_symlinks (struct entry *entry)
|
||||
{
|
||||
@ -731,6 +772,8 @@ extfs_resolve_symlinks (struct entry *entry)
|
||||
return res;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
extfs_get_archive_name (struct archive *archive)
|
||||
{
|
||||
@ -747,7 +790,9 @@ extfs_get_archive_name (struct archive *archive)
|
||||
return archive_name;
|
||||
}
|
||||
|
||||
/* Don't pass localname as NULL */
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Don't pass localname as NULL */
|
||||
|
||||
static int
|
||||
extfs_cmd (const char *str_extfs_cmd, struct archive *archive,
|
||||
struct entry *entry, const char *localname)
|
||||
@ -780,6 +825,8 @@ extfs_cmd (const char *str_extfs_cmd, struct archive *archive,
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_close (void *data)
|
||||
{
|
||||
@ -921,6 +974,8 @@ extfs_close (void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_errno (struct vfs_class *me)
|
||||
{
|
||||
@ -928,6 +983,8 @@ extfs_errno (struct vfs_class *me)
|
||||
return my_errno;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
extfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
{
|
||||
@ -956,6 +1013,8 @@ extfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
return info;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
extfs_readdir (void *data)
|
||||
{
|
||||
@ -973,6 +1032,8 @@ extfs_readdir (void *data)
|
||||
return (void *) &dir;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_closedir (void *data)
|
||||
{
|
||||
@ -980,7 +1041,7 @@ extfs_closedir (void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RECORDSIZE 512
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||
{
|
||||
return extfs_internal_stat (me, path, buf, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||
{
|
||||
return extfs_internal_stat (me, path, buf, FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_fstat (void *data, struct stat *buf)
|
||||
{
|
||||
@ -1056,6 +1125,8 @@ extfs_fstat (void *data, struct stat *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_unlink (struct vfs_class *me, const char *file)
|
||||
{
|
||||
@ -1153,6 +1232,8 @@ extfs_unlink (struct vfs_class *me, const char *file)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_rmdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -1235,6 +1318,8 @@ extfs_rmdir (struct vfs_class *me, const char *path)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_chdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -1257,6 +1342,8 @@ extfs_chdir (struct vfs_class *me, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static off_t
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static vfsid
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_nothingisopen (vfsid id)
|
||||
{
|
||||
return (((struct archive *) id)->fd_usage <= 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
extfs_remove_entry (struct entry *e)
|
||||
{
|
||||
@ -1327,6 +1420,8 @@ extfs_remove_entry (struct entry *e)
|
||||
g_free (e);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
extfs_free_entry (struct entry *e)
|
||||
{
|
||||
@ -1355,6 +1450,8 @@ extfs_free_entry (struct entry *e)
|
||||
g_free (e);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
extfs_free (vfsid id)
|
||||
{
|
||||
@ -1377,6 +1474,8 @@ extfs_free (vfsid id)
|
||||
extfs_free_archive (archive);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -1397,6 +1496,8 @@ extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
||||
return p;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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
|
||||
extfs_get_plugins (const char *where, gboolean silent)
|
||||
{
|
||||
@ -1520,6 +1623,7 @@ extfs_get_plugins (const char *where, gboolean silent)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
extfs_init (struct vfs_class *me)
|
||||
@ -1539,6 +1643,8 @@ extfs_init (struct vfs_class *me)
|
||||
return (d1 || d2 ? 1 : 0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
extfs_done (struct vfs_class *me)
|
||||
{
|
||||
@ -1564,6 +1670,8 @@ extfs_done (struct vfs_class *me)
|
||||
g_array_free (extfs_plugins, TRUE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_extfs (void)
|
||||
{
|
||||
@ -1612,3 +1724,5 @@ init_extfs (void)
|
||||
vfs_extfs_ops.setctl = extfs_setctl;
|
||||
vfs_register_class (&vfs_extfs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -76,8 +76,12 @@
|
||||
#include "fishdef.h"
|
||||
#include "src/execute.h" /* pre_exec, post_exec */
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
int fish_directory_timeout = 900;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#define DO_RESOLVE_SYMLINK 1
|
||||
#define DO_OPEN 2
|
||||
#define DO_FREE_RESOURCE 4
|
||||
@ -111,10 +115,33 @@ int fish_directory_timeout = 900;
|
||||
#define FISH_HAVE_DATE_MDYT 32
|
||||
#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 struct vfs_class vfs_fish_ops;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
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 */
|
||||
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_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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_decode_reply (char *s, int was_garbage)
|
||||
{
|
||||
@ -157,7 +187,9 @@ fish_decode_reply (char *s, int was_garbage)
|
||||
return code / 100;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||
|
||||
static int
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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 *
|
||||
fish_set_env (int flags)
|
||||
{
|
||||
@ -323,6 +361,8 @@ fish_set_env (int flags)
|
||||
return g_string_free (tmp, FALSE);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
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 */
|
||||
|
||||
static char *
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
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_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_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_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);
|
||||
@ -538,6 +589,8 @@ fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return fish_open_archive_int (me, super);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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."));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_ctl (void *fh, int ctlop, void *arg)
|
||||
{
|
||||
@ -1022,6 +1089,8 @@ fish_ctl (void *fh, int ctlop, void *arg)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
#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
|
||||
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 (rpath1);
|
||||
g_free (rpath2);
|
||||
return fish_send_command(me, super2, buf, OPT_FLUSH);
|
||||
return fish_send_command (me, super2, buf, OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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
|
||||
fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
||||
{
|
||||
@ -1156,6 +1216,8 @@ fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_chmod (struct vfs_class *me, const char *path, int mode)
|
||||
{
|
||||
@ -1169,6 +1231,8 @@ fish_chmod (struct vfs_class *me, const char *path, int mode)
|
||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||
{
|
||||
@ -1203,6 +1267,8 @@ fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_unlink (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -1216,12 +1282,15 @@ fish_unlink (struct vfs_class *me, const char *path)
|
||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_exists (struct vfs_class *me, const char *path)
|
||||
{
|
||||
gchar *shell_commands = NULL;
|
||||
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_free (shell_commands);
|
||||
g_free (rpath);
|
||||
@ -1230,14 +1299,15 @@ fish_exists (struct vfs_class *me, const char *path)
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
||||
{
|
||||
gchar *shell_commands = NULL;
|
||||
int ret_code;
|
||||
|
||||
PREFIX
|
||||
(void) mode;
|
||||
PREFIX (void) mode;
|
||||
|
||||
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_mkdir, (char *) NULL);
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
fish_rmdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
gchar *shell_commands = NULL;
|
||||
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_free (shell_commands);
|
||||
g_free (rpath);
|
||||
return fish_send_command (me, super, buf, OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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 *
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_fish (void)
|
||||
{
|
||||
@ -1377,3 +1460,5 @@ init_fish (void)
|
||||
vfs_fish_ops.ctl = fish_ctl;
|
||||
vfs_register_class (&vfs_fish_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -6,9 +6,21 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MC_VFS_FISH_H
|
||||
#define MC_VFS_FISH_H
|
||||
#ifndef 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;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
|
||||
#endif
|
||||
|
@ -4,8 +4,10 @@
|
||||
* \brief Header: FISH script defaults
|
||||
*/
|
||||
|
||||
#ifndef MC_FISH_DEF_H
|
||||
#define MC_FISH_DEF_H
|
||||
#ifndef MC__FISH_DEF_H
|
||||
#define MC__FISH_DEF_H
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/* default 'ls' script */
|
||||
#define FISH_LS_DEF_CONTENT "" \
|
||||
@ -205,5 +207,13 @@
|
||||
"echo $res\n" \
|
||||
"echo \"### 200\"\n"
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -103,33 +103,7 @@ What to do with this?
|
||||
|
||||
#include "ftpfs.h"
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
# 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;
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/* Delay to retry a connection */
|
||||
int ftpfs_retry_seconds = 30;
|
||||
@ -163,18 +137,92 @@ int ftpfs_always_use_proxy = 0;
|
||||
|
||||
int ftpfs_ignore_chattr_errors = 1;
|
||||
|
||||
#ifdef FIXME_LATER_ALIGATOR
|
||||
static struct linklist *connections_list;
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#ifndef MAXHOSTNAMELEN
|
||||
#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
|
||||
|
||||
/* ftpfs_command wait_flag: */
|
||||
#define NONE 0x00
|
||||
#define WAIT_REPLY 0x01
|
||||
#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 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)
|
||||
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
|
||||
@ -198,6 +246,8 @@ static int ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super,
|
||||
const char *netrcpass);
|
||||
static int ftpfs_netrc_lookup (const char *host, char **login, char **pass);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
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.:
|
||||
* 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
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
||||
|
||||
static int
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* 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
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* This routine logs the user in */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
static struct no_proxy_entry
|
||||
{
|
||||
char *domain;
|
||||
void *next;
|
||||
} *no_proxy;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
ftpfs_load_no_proxy_list (void)
|
||||
@ -654,7 +701,9 @@ ftpfs_load_no_proxy_list (void)
|
||||
g_free (mc_file);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Return 1 if FTP proxy should be used for this host, 0 otherwise */
|
||||
|
||||
static int
|
||||
ftpfs_check_proxy (const char *host)
|
||||
{
|
||||
@ -698,6 +747,8 @@ ftpfs_check_proxy (const char *host)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* The returned directory should always contain a trailing slash */
|
||||
|
||||
static char *
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Setup Passive PASV FTP connection */
|
||||
|
||||
static int
|
||||
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 n[6];
|
||||
@ -1019,10 +1082,12 @@ ftpfs_setup_passive_pasv (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Setup Passive EPSV FTP connection */
|
||||
|
||||
static int
|
||||
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;
|
||||
int port;
|
||||
@ -1060,10 +1125,12 @@ ftpfs_setup_passive_epsv (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Setup Passive ftp connection, we use it for source routed connections */
|
||||
|
||||
static int
|
||||
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 */
|
||||
if (sa->ss_family == AF_INET)
|
||||
@ -1083,7 +1150,9 @@ ftpfs_setup_passive (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Setup Active PORT or EPRT FTP connection */
|
||||
|
||||
static int
|
||||
ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
||||
struct sockaddr_storage data_addr, socklen_t data_addrlen)
|
||||
@ -1153,10 +1222,12 @@ ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Initialize a socket for FTP DATA connection */
|
||||
|
||||
static int
|
||||
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;
|
||||
|
||||
@ -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));
|
||||
return -1;
|
||||
} else
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Initialize FTP DATA connection */
|
||||
|
||||
static int
|
||||
ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
|
||||
{
|
||||
@ -1253,13 +1327,15 @@ ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, const char *cmd,
|
||||
const char *remote, int isbinary, int reget)
|
||||
{
|
||||
struct sockaddr_storage from;
|
||||
int s, j, data;
|
||||
socklen_t fromlen = sizeof(from);
|
||||
socklen_t fromlen = sizeof (from);
|
||||
|
||||
s = ftpfs_initconn (me, super);
|
||||
if (s == -1)
|
||||
@ -1304,7 +1380,8 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
|
||||
return data;
|
||||
}
|
||||
|
||||
#define ABORT_TIMEOUT 5
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#if 0
|
||||
static void
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super,
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
||||
{
|
||||
@ -1756,6 +1843,8 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_ctl (void *fh, int ctlop, void *arg)
|
||||
{
|
||||
@ -1834,6 +1929,8 @@ ftpfs_ctl (void *fh, int ctlop, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_unlink (struct vfs_class *me, const char *path)
|
||||
{
|
||||
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 */
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_rmdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
return ftpfs_send_command (me, path, "RMD /%s", OPT_FLUSH);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
ftpfs_done (struct vfs_class *me)
|
||||
{
|
||||
@ -2084,6 +2184,8 @@ ftpfs_done (struct vfs_class *me)
|
||||
g_free (ftpfs_proxy_host);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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
|
||||
ftpfs_netrc_next (void)
|
||||
@ -2172,6 +2258,8 @@ ftpfs_netrc_next (void)
|
||||
return NETRC_UNKNOWN;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
ftpfs_netrc_bad_mode (const char *netrcname)
|
||||
{
|
||||
@ -2191,10 +2279,12 @@ ftpfs_netrc_bad_mode (const char *netrcname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Scan .netrc until we find matching "machine" or "default"
|
||||
* domain is used for additional matching
|
||||
* No search is done after "default" in compliance with "man netrc"
|
||||
* Return 0 if found, -1 otherwise */
|
||||
|
||||
static int
|
||||
ftpfs_find_machine (const char *host, const char *domain)
|
||||
{
|
||||
@ -2255,9 +2345,11 @@ ftpfs_find_machine (const char *host, const char *domain)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Extract login and password from .netrc for the host.
|
||||
* pass may be NULL.
|
||||
* Returns 0 for success, -1 for error */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** 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
|
||||
init_ftpfs (void)
|
||||
{
|
||||
@ -2439,3 +2556,5 @@ init_ftpfs (void)
|
||||
vfs_ftpfs_ops.ctl = ftpfs_ctl;
|
||||
vfs_register_class (&vfs_ftpfs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,11 +1,24 @@
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief Header: Virtual File System: FTP file system
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_FTPFS_H
|
||||
#define MC_VFS_FTPFS_H
|
||||
#ifndef 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 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_first_cd_then_ls;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void ftpfs_init_passwd (void);
|
||||
void init_ftpfs (void);
|
||||
|
||||
#define FTP_INET 1
|
||||
#define FTP_INET6 2
|
||||
|
||||
#define OPT_FLUSH 1
|
||||
#define OPT_IGNORE_ERROR 2
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -52,19 +52,33 @@
|
||||
|
||||
#include "gc.h"
|
||||
|
||||
/*** 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;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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;
|
||||
|
||||
for (stamp = stamps; stamp != NULL; stamp = stamp->next) {
|
||||
if (stamp->v == v && stamp->id == id) {
|
||||
for (stamp = stamps; stamp != NULL; stamp = stamp->next)
|
||||
{
|
||||
if (stamp->v == v && stamp->id == id)
|
||||
{
|
||||
gettimeofday (&(stamp->time), NULL);
|
||||
return;
|
||||
}
|
||||
@ -77,16 +91,32 @@ vfs_addstamp (struct vfs_class *v, vfsid id)
|
||||
gettimeofday (&(stamp->time), NULL);
|
||||
stamp->next = 0;
|
||||
|
||||
if (stamps) {
|
||||
if (stamps)
|
||||
{
|
||||
/* Add to the end */
|
||||
last_stamp->next = stamp;
|
||||
} else {
|
||||
}
|
||||
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
|
||||
vfs_stamp (struct vfs_class *v, vfsid id)
|
||||
@ -94,24 +124,29 @@ vfs_stamp (struct vfs_class *v, vfsid id)
|
||||
struct vfs_stamping *stamp;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
vfs_rmstamp (struct vfs_class *v, vfsid id)
|
||||
{
|
||||
struct vfs_stamping *stamp, *st1;
|
||||
|
||||
for (stamp = stamps, st1 = NULL; stamp != NULL;
|
||||
st1 = stamp, stamp = stamp->next)
|
||||
if (stamp->v == v && stamp->id == id) {
|
||||
if (st1 == NULL) {
|
||||
for (stamp = stamps, st1 = NULL; stamp != NULL; st1 = stamp, stamp = stamp->next)
|
||||
if (stamp->v == v && stamp->id == id)
|
||||
{
|
||||
if (st1 == NULL)
|
||||
{
|
||||
stamps = stamp->next;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
st1->next = stamp->next;
|
||||
}
|
||||
g_free (stamp);
|
||||
@ -120,6 +155,7 @@ vfs_rmstamp (struct vfs_class *v, vfsid id)
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
vfs_stamp_path (const char *path)
|
||||
@ -132,10 +168,11 @@ vfs_stamp_path (const char *path)
|
||||
vfs_addstamp (vfs, id);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Create a new timestamp item by VFS class and VFS id.
|
||||
*/
|
||||
|
||||
void
|
||||
vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
||||
{
|
||||
@ -154,26 +191,33 @@ vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
||||
nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
|
||||
vfs_rmstamp (nvfs, nvfsid);
|
||||
|
||||
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL) {
|
||||
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL)
|
||||
{
|
||||
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);
|
||||
if (n2vfs == oldvfs && n2vfsid == oldvfsid)
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
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);
|
||||
if (n3vfs == oldvfs && n3vfsid == oldvfsid)
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
n3vfs = NULL;
|
||||
n3vfsid = NULL;
|
||||
}
|
||||
@ -184,18 +228,10 @@ vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
|
||||
vfs_addstamp (oldvfs, oldvfsid);
|
||||
}
|
||||
|
||||
/* 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)));
|
||||
}
|
||||
|
||||
|
||||
/* This is called from timeout handler with now = 0, or can be called
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** 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 */
|
||||
|
||||
void
|
||||
vfs_expire (int now)
|
||||
{
|
||||
@ -212,31 +248,36 @@ vfs_expire (int now)
|
||||
gettimeofday (&lc_time, NULL);
|
||||
lc_time.tv_sec -= vfs_timeout;
|
||||
|
||||
for (stamp = stamps; stamp != NULL;) {
|
||||
if (now || (timeoutcmp (&stamp->time, &lc_time))) {
|
||||
for (stamp = stamps; stamp != NULL;)
|
||||
{
|
||||
if (now || (timeoutcmp (&stamp->time, &lc_time)))
|
||||
{
|
||||
st = stamp->next;
|
||||
if (stamp->v->free)
|
||||
(*stamp->v->free) (stamp->id);
|
||||
vfs_rmstamp (stamp->v, stamp->id);
|
||||
stamp = st;
|
||||
} else
|
||||
}
|
||||
else
|
||||
stamp = stamp->next;
|
||||
}
|
||||
locked = 0;
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*
|
||||
* Return the number of seconds remaining to the vfs timeout.
|
||||
* FIXME: The code should be improved to actually return the number of
|
||||
* seconds until the next item times out.
|
||||
*/
|
||||
|
||||
int
|
||||
vfs_timeouts ()
|
||||
{
|
||||
return stamps ? 10 : 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
vfs_timeout_handler (void)
|
||||
@ -244,6 +285,7 @@ vfs_timeout_handler (void)
|
||||
vfs_expire (0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
vfs_release_path (const char *dir)
|
||||
@ -256,14 +298,16 @@ vfs_release_path (const char *dir)
|
||||
vfs_stamp_create (oldvfs, oldvfsid);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Free all data */
|
||||
|
||||
void
|
||||
vfs_gc_done (void)
|
||||
{
|
||||
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);
|
||||
st = stamp->next;
|
||||
@ -274,3 +318,5 @@ vfs_gc_done (void)
|
||||
if (stamps)
|
||||
vfs_rmstamp (stamps->v, stamps->id);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,14 +1,19 @@
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief Header: Virtual File System: garbage collection code
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_GC_H
|
||||
#define MC_VFS_GC_H
|
||||
#ifndef MC__VFS_GC_H
|
||||
#define MC__VFS_GC_H
|
||||
|
||||
#include "vfs-impl.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct vfs_stamping
|
||||
{
|
||||
struct vfs_class *v;
|
||||
@ -17,10 +22,15 @@ struct vfs_stamping
|
||||
struct timeval time;
|
||||
};
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void vfs_stamp (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);
|
||||
vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
|
||||
void vfs_gc_done (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_VFS_GC_H */
|
||||
|
@ -19,13 +19,27 @@
|
||||
|
||||
#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
|
||||
* reason: exactly same functions would have to appear in sfs.c. This
|
||||
* saves both computer's memory and my work. <pavel@ucw.cz>
|
||||
*/
|
||||
|
||||
static struct vfs_class vfs_local_ops;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
||||
@ -45,45 +59,7 @@ local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
|
||||
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 *
|
||||
local_opendir (struct vfs_class *me, const char *dirname)
|
||||
@ -103,22 +79,28 @@ local_opendir (struct vfs_class *me, const char *dirname)
|
||||
return local_info;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
local_readdir (void *data)
|
||||
{
|
||||
return readdir (*(DIR **) data);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
local_closedir (void *data)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = closedir (* (DIR **) data);
|
||||
i = closedir (*(DIR **) data);
|
||||
g_free (data);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||
{
|
||||
(void) me;
|
||||
|
||||
#ifndef HAVE_STATLSTAT
|
||||
return lstat (path,buf);
|
||||
return lstat (path, buf);
|
||||
#else
|
||||
return statlstat (path, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
local_fstat (void *data, struct stat *buf)
|
||||
{
|
||||
/* FIXME: avoid type cast */
|
||||
return fstat (*((int *) data), buf);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
local_write (void *data, const char *buf, size_t nbyte)
|
||||
{
|
||||
@ -203,19 +194,24 @@ local_write (void *data, const char *buf, size_t nbyte)
|
||||
if (!data)
|
||||
return -1;
|
||||
|
||||
fd = * (int *) data;
|
||||
while ((n = write (fd, buf, nbyte)) == -1){
|
||||
fd = *(int *) data;
|
||||
while ((n = write (fd, buf, nbyte)) == -1)
|
||||
{
|
||||
#ifdef EAGAIN
|
||||
if (errno == EAGAIN) continue;
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
if (errno == EINTR) continue;
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
off_t
|
||||
local_lseek (void *data, off_t offset, int whence)
|
||||
{
|
||||
int fd = * (int *) data;
|
||||
|
||||
return lseek (fd, offset, whence);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
local_ungetlocalcopy (struct vfs_class *me, const char *path,
|
||||
const char *local, int has_changed)
|
||||
local_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
||||
{
|
||||
(void) me;
|
||||
(void) path;
|
||||
@ -292,6 +293,8 @@ local_ungetlocalcopy (struct vfs_class *me, const char *path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
local_which (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -301,6 +304,78 @@ local_which (struct vfs_class *me, const char *path)
|
||||
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
|
||||
init_localfs (void)
|
||||
{
|
||||
@ -335,3 +410,5 @@ init_localfs (void)
|
||||
vfs_local_ops.rmdir = local_rmdir;
|
||||
vfs_register_class (&vfs_local_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -1,14 +1,23 @@
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief Header: local FS
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_LOCAL_H
|
||||
#define MC_VFS_LOCAL_H
|
||||
#ifndef MC__VFS_LOCAL_H
|
||||
#define MC__VFS_LOCAL_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);
|
||||
|
||||
/* 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 off_t local_lseek (void *data, off_t offset, int whence);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -31,8 +31,19 @@
|
||||
|
||||
#include "netutil.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
volatile sig_atomic_t got_sigpipe = 0;
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
sig_pipe (int unused)
|
||||
{
|
||||
@ -40,6 +51,10 @@ sig_pipe (int unused)
|
||||
got_sigpipe = 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
tcp_init (void)
|
||||
{
|
||||
@ -57,3 +72,5 @@ tcp_init (void)
|
||||
|
||||
initialized = TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -4,12 +4,23 @@
|
||||
* \brief Header: Virtual File System: Network utilities
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_NETUTIL_H
|
||||
#define MC_VFS_NETUTIL_H
|
||||
#ifndef MC__VFS_NETUTIL_H
|
||||
#define MC__VFS_NETUTIL_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;
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void tcp_init (void);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_VFS_NETUTIL_H */
|
||||
|
@ -52,60 +52,17 @@
|
||||
#include "local.h"
|
||||
#include "gc.h" /* vfs_stamp_create */
|
||||
|
||||
struct cachedfile {
|
||||
char *name, *cache;
|
||||
struct cachedfile *next;
|
||||
};
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
static struct cachedfile *head;
|
||||
static struct vfs_class vfs_sfs_ops;
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
#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_2 2
|
||||
#define F_NOLOCALCOPY 4
|
||||
#define F_FULLMATCH 8
|
||||
|
||||
static int
|
||||
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
{
|
||||
char *inpath, *op;
|
||||
int w;
|
||||
char pad[10240];
|
||||
char *s, *t = pad;
|
||||
int was_percent = 0;
|
||||
char *pname; /* name of parent archive */
|
||||
char *pqname; /* name of parent archive, quoted */
|
||||
|
||||
pname = g_strdup (name);
|
||||
vfs_split (pname, &inpath, &op);
|
||||
w = (*me->which) (me, op);
|
||||
if (w == -1)
|
||||
vfs_die ("This cannot happen... Hopefully.\n");
|
||||
|
||||
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/")) {
|
||||
g_free (pname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */
|
||||
if (!(sfs_flags[w] & F_NOLOCALCOPY)) {
|
||||
s = mc_getlocalcopy (pname);
|
||||
if (!s) {
|
||||
g_free (pname);
|
||||
return -1;
|
||||
}
|
||||
pqname = name_quote (s, 0);
|
||||
g_free (s);
|
||||
} else {
|
||||
pqname = name_quote (pname, 0);
|
||||
}
|
||||
g_free (pname);
|
||||
|
||||
#define COPY_CHAR \
|
||||
if ((size_t) (t-pad) > sizeof(pad)) { \
|
||||
g_free (pqname); \
|
||||
@ -123,13 +80,79 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
t+= strlen(a); \
|
||||
}
|
||||
|
||||
for (s = sfs_command[w]; *s; s++) {
|
||||
if (was_percent) {
|
||||
/*** 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
|
||||
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
{
|
||||
char *inpath, *op;
|
||||
int w;
|
||||
char pad[10240];
|
||||
char *s, *t = pad;
|
||||
int was_percent = 0;
|
||||
char *pname; /* name of parent archive */
|
||||
char *pqname; /* name of parent archive, quoted */
|
||||
|
||||
pname = g_strdup (name);
|
||||
vfs_split (pname, &inpath, &op);
|
||||
w = (*me->which) (me, op);
|
||||
if (w == -1)
|
||||
vfs_die ("This cannot happen... Hopefully.\n");
|
||||
|
||||
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/"))
|
||||
{
|
||||
g_free (pname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if ((sfs_flags[w] & F_2) || (!inpath) || (!*inpath)); else return -1; */
|
||||
if (!(sfs_flags[w] & F_NOLOCALCOPY))
|
||||
{
|
||||
s = mc_getlocalcopy (pname);
|
||||
if (!s)
|
||||
{
|
||||
g_free (pname);
|
||||
return -1;
|
||||
}
|
||||
pqname = name_quote (s, 0);
|
||||
g_free (s);
|
||||
}
|
||||
else
|
||||
{
|
||||
pqname = name_quote (pname, 0);
|
||||
}
|
||||
g_free (pname);
|
||||
|
||||
|
||||
for (s = sfs_command[w]; *s; s++)
|
||||
{
|
||||
if (was_percent)
|
||||
{
|
||||
|
||||
const char *ptr = NULL;
|
||||
was_percent = 0;
|
||||
|
||||
switch (*s) {
|
||||
switch (*s)
|
||||
{
|
||||
case '1':
|
||||
ptr = pqname;
|
||||
break;
|
||||
@ -144,7 +167,9 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
continue;
|
||||
}
|
||||
COPY_STRING (ptr);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*s == '%')
|
||||
was_percent = 1;
|
||||
else
|
||||
@ -154,7 +179,8 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
|
||||
g_free (pqname);
|
||||
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;
|
||||
}
|
||||
@ -163,6 +189,8 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
return 0; /* OK */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
sfs_redirect (struct vfs_class *me, const char *name)
|
||||
{
|
||||
@ -170,8 +198,10 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
||||
char *cache;
|
||||
int handle;
|
||||
|
||||
while (cur) {
|
||||
if (!strcmp (name, cur->name)) {
|
||||
while (cur)
|
||||
{
|
||||
if (!strcmp (name, cur->name))
|
||||
{
|
||||
vfs_stamp (&vfs_sfs_ops, cur);
|
||||
return cur->cache;
|
||||
}
|
||||
@ -180,13 +210,15 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
||||
|
||||
handle = vfs_mkstemps (&cache, "sfs", name);
|
||||
|
||||
if (handle == -1) {
|
||||
if (handle == -1)
|
||||
{
|
||||
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
|
||||
}
|
||||
|
||||
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->cache = cache;
|
||||
@ -203,6 +235,8 @@ sfs_redirect (struct vfs_class *me, const char *name)
|
||||
return "/I_MUST_NOT_EXIST";
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
||||
{
|
||||
@ -220,13 +254,19 @@ sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
|
||||
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);
|
||||
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);
|
||||
#ifndef HAVE_STATLSTAT
|
||||
@ -236,24 +276,35 @@ static int sfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
||||
#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);
|
||||
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);
|
||||
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);
|
||||
return utime (path, times);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static vfsid
|
||||
sfs_getid (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -268,7 +321,8 @@ sfs_getid (struct vfs_class *me, const char *path)
|
||||
|
||||
(void) me;
|
||||
|
||||
while (cur) {
|
||||
while (cur)
|
||||
{
|
||||
if (!strcmp (path, cur->name))
|
||||
break;
|
||||
cur = cur->next;
|
||||
@ -277,7 +331,10 @@ sfs_getid (struct vfs_class *me, const char *path)
|
||||
return (vfsid) cur;
|
||||
}
|
||||
|
||||
static void sfs_free (vfsid id)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
sfs_free (vfsid id)
|
||||
{
|
||||
struct cachedfile *which = (struct cachedfile *) id;
|
||||
struct cachedfile *cur, *prev;
|
||||
@ -285,7 +342,7 @@ static void sfs_free (vfsid id)
|
||||
for (cur = head, prev = 0; cur && cur != which; prev = cur, cur = cur->next)
|
||||
;
|
||||
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);
|
||||
|
||||
if (prev)
|
||||
@ -298,19 +355,26 @@ static void sfs_free (vfsid id)
|
||||
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;
|
||||
|
||||
(void) me;
|
||||
|
||||
while (cur){
|
||||
(*func)(cur->name);
|
||||
while (cur)
|
||||
{
|
||||
(*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
|
||||
the other VFSs (see fd_usage in extfs) -- Norbert */
|
||||
@ -318,6 +382,8 @@ static int sfs_nothingisopen (vfsid id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static char *
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
sfs_ungetlocalcopy (struct vfs_class *me, const char *path,
|
||||
const char *local, int has_changed)
|
||||
sfs_ungetlocalcopy (struct vfs_class *me, const char *path, const char *local, int has_changed)
|
||||
{
|
||||
(void) me;
|
||||
(void) path;
|
||||
@ -336,7 +403,10 @@ sfs_ungetlocalcopy (struct vfs_class *me, const char *path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sfs_init (struct vfs_class *me)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
sfs_init (struct vfs_class *me)
|
||||
{
|
||||
char *mc_sfsini;
|
||||
FILE *cfg;
|
||||
@ -347,7 +417,8 @@ static int sfs_init (struct vfs_class *me)
|
||||
mc_sfsini = g_build_filename (mc_home, "sfs.ini", (char *) NULL);
|
||||
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);
|
||||
return 0;
|
||||
@ -355,38 +426,48 @@ static int sfs_init (struct vfs_class *me)
|
||||
g_free (mc_sfsini);
|
||||
|
||||
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;
|
||||
|
||||
if (*key == '#' || *key == '\n')
|
||||
continue;
|
||||
|
||||
for (c = key; *c; c++)
|
||||
if ((*c == ':') || (*c == '/')){
|
||||
if ((*c == ':') || (*c == '/'))
|
||||
{
|
||||
semi = c;
|
||||
if (*c == '/'){
|
||||
if (*c == '/')
|
||||
{
|
||||
*c = 0;
|
||||
flags |= F_FULLMATCH;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!semi){
|
||||
if (!semi)
|
||||
{
|
||||
invalid_line:
|
||||
fprintf (stderr, _("Warning: Invalid line in %s:\n%s\n"),
|
||||
"sfs.ini", key);
|
||||
fprintf (stderr, _("Warning: Invalid line in %s:\n%s\n"), "sfs.ini", key);
|
||||
continue;
|
||||
}
|
||||
|
||||
c = semi + 1;
|
||||
while (*c && (*c != ' ') && (*c != '\t')) {
|
||||
switch (*c) {
|
||||
case '1': flags |= F_1; break;
|
||||
case '2': flags |= F_2; break;
|
||||
case 'R': flags |= F_NOLOCALCOPY; break;
|
||||
while (*c && (*c != ' ') && (*c != '\t'))
|
||||
{
|
||||
switch (*c)
|
||||
{
|
||||
case '1':
|
||||
flags |= F_1;
|
||||
break;
|
||||
case '2':
|
||||
flags |= F_2;
|
||||
break;
|
||||
case 'R':
|
||||
flags |= F_NOLOCALCOPY;
|
||||
break;
|
||||
default:
|
||||
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"),
|
||||
*c, "sfs.ini", key);
|
||||
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"), *c, "sfs.ini", key);
|
||||
}
|
||||
c++;
|
||||
}
|
||||
@ -394,20 +475,22 @@ static int sfs_init (struct vfs_class *me)
|
||||
goto invalid_line;
|
||||
|
||||
c++;
|
||||
*(semi+1) = 0;
|
||||
*(semi + 1) = 0;
|
||||
semi = strchr (c, '\n');
|
||||
if (semi != NULL)
|
||||
*semi = 0;
|
||||
|
||||
sfs_prefix [sfs_no] = g_strdup (key);
|
||||
sfs_command [sfs_no] = g_strdup (c);
|
||||
sfs_flags [sfs_no] = flags;
|
||||
sfs_prefix[sfs_no] = g_strdup (key);
|
||||
sfs_command[sfs_no] = g_strdup (c);
|
||||
sfs_flags[sfs_no] = flags;
|
||||
sfs_no++;
|
||||
}
|
||||
fclose (cfg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
sfs_done (struct vfs_class *me)
|
||||
{
|
||||
@ -415,14 +498,17 @@ sfs_done (struct vfs_class *me)
|
||||
|
||||
(void) me;
|
||||
|
||||
for (i = 0; i < sfs_no; i++){
|
||||
g_free (sfs_prefix [i]);
|
||||
g_free (sfs_command [i]);
|
||||
sfs_prefix [i] = sfs_command [i] = NULL;
|
||||
for (i = 0; i < sfs_no; i++)
|
||||
{
|
||||
g_free (sfs_prefix[i]);
|
||||
g_free (sfs_command[i]);
|
||||
sfs_prefix[i] = sfs_command[i] = NULL;
|
||||
}
|
||||
sfs_no = 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
sfs_which (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -431,16 +517,21 @@ sfs_which (struct vfs_class *me, const char *path)
|
||||
(void) me;
|
||||
|
||||
for (i = 0; i < sfs_no; i++)
|
||||
if (sfs_flags [i] & F_FULLMATCH) {
|
||||
if (!strcmp (path, sfs_prefix [i]))
|
||||
if (sfs_flags[i] & F_FULLMATCH)
|
||||
{
|
||||
if (!strcmp (path, sfs_prefix[i]))
|
||||
return i;
|
||||
} else
|
||||
if (!strncmp (path, sfs_prefix [i], strlen (sfs_prefix [i])))
|
||||
}
|
||||
else if (!strncmp (path, sfs_prefix[i], strlen (sfs_prefix[i])))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_sfs (void)
|
||||
{
|
||||
@ -468,3 +559,5 @@ init_sfs (void)
|
||||
vfs_sfs_ops.ungetlocalcopy = sfs_ungetlocalcopy;
|
||||
vfs_register_class (&vfs_sfs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -4,12 +4,14 @@
|
||||
* \brief Header: Virtual File System: smb file system
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_SMBFS_H
|
||||
#define MC_VFS_SMBFS_H
|
||||
#ifndef MC__VFS_SMBFS_H
|
||||
#define MC__VFS_SMBFS_H
|
||||
|
||||
void init_smbfs (void);
|
||||
void smbfs_set_debug (int arg);
|
||||
void smbfs_set_debugf (const char *filename);
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct smb_authinfo
|
||||
{
|
||||
@ -20,16 +22,24 @@ typedef struct smb_authinfo
|
||||
char *password;
|
||||
} 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,
|
||||
const char *share,
|
||||
const char *domain,
|
||||
const char *user,
|
||||
const char *pass);
|
||||
const char *domain, const char *user, const char *pass);
|
||||
|
||||
/* src/boxes.c */
|
||||
smb_authinfo *vfs_smb_get_authinfo (const char *host,
|
||||
const char *share,
|
||||
const char *domain,
|
||||
const char *user);
|
||||
const char *share, const char *domain, const char *user);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_VFS_SMBFS_H */
|
||||
|
@ -49,15 +49,9 @@
|
||||
#include "xdirentry.h"
|
||||
#include "gc.h" /* vfs_rmstamp */
|
||||
|
||||
static struct vfs_class vfs_tarfs_ops;
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
enum {
|
||||
TAR_UNKNOWN = 0,
|
||||
TAR_V7,
|
||||
TAR_USTAR,
|
||||
TAR_POSIX,
|
||||
TAR_GNU
|
||||
};
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*
|
||||
* Header block on tape.
|
||||
@ -75,61 +69,6 @@ enum {
|
||||
#define SPARSE_EXT_HDR 21
|
||||
#define SPARSE_IN_HDR 4
|
||||
|
||||
struct sparse {
|
||||
char offset[12];
|
||||
char numbytes[12];
|
||||
};
|
||||
|
||||
struct sp_array {
|
||||
int offset;
|
||||
int numbytes;
|
||||
};
|
||||
|
||||
union record {
|
||||
char charptr[RECORDSIZE];
|
||||
struct header {
|
||||
char arch_name[NAMSIZ];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
char chksum[8];
|
||||
char linkflag;
|
||||
char arch_linkname[NAMSIZ];
|
||||
char magic[8];
|
||||
char uname[TUNMLEN];
|
||||
char gname[TGNMLEN];
|
||||
char devmajor[8];
|
||||
char devminor[8];
|
||||
/* The following bytes of the tar header record were originally unused.
|
||||
|
||||
Archives following the ustar specification use almost all of those
|
||||
bytes to support pathnames of 256 characters in length.
|
||||
|
||||
GNU tar archives use the "unused" space to support incremental
|
||||
archives and sparse files. */
|
||||
union unused {
|
||||
char prefix[PREFIX_SIZE];
|
||||
/* GNU extensions to the ustar (POSIX.1-1988) archive format. */
|
||||
struct oldgnu {
|
||||
char atime[12];
|
||||
char ctime[12];
|
||||
char offset[12];
|
||||
char longnames[4];
|
||||
char pad;
|
||||
struct sparse sp[SPARSE_IN_HDR];
|
||||
char isextended;
|
||||
char realsize[12]; /* true size of the sparse file */
|
||||
} oldgnu;
|
||||
} unused;
|
||||
} header;
|
||||
struct extended_header {
|
||||
struct sparse sp[21];
|
||||
char isextended;
|
||||
} ext_hdr;
|
||||
};
|
||||
|
||||
/* The checksum field is filled with this while the checksum is computed. */
|
||||
#define CHKBLANKS " " /* 8 blanks, no null */
|
||||
|
||||
@ -185,22 +124,117 @@ union record {
|
||||
|
||||
#define isodigit(c) ( ((c) >= '0') && ((c) <= '7') )
|
||||
|
||||
/*
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
enum
|
||||
{
|
||||
TAR_UNKNOWN = 0,
|
||||
TAR_V7,
|
||||
TAR_USTAR,
|
||||
TAR_POSIX,
|
||||
TAR_GNU
|
||||
};
|
||||
|
||||
struct sparse
|
||||
{
|
||||
char offset[12];
|
||||
char numbytes[12];
|
||||
};
|
||||
|
||||
struct sp_array
|
||||
{
|
||||
int offset;
|
||||
int numbytes;
|
||||
};
|
||||
|
||||
union record
|
||||
{
|
||||
char charptr[RECORDSIZE];
|
||||
struct header
|
||||
{
|
||||
char arch_name[NAMSIZ];
|
||||
char mode[8];
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char size[12];
|
||||
char mtime[12];
|
||||
char chksum[8];
|
||||
char linkflag;
|
||||
char arch_linkname[NAMSIZ];
|
||||
char magic[8];
|
||||
char uname[TUNMLEN];
|
||||
char gname[TGNMLEN];
|
||||
char devmajor[8];
|
||||
char devminor[8];
|
||||
/* The following bytes of the tar header record were originally unused.
|
||||
|
||||
Archives following the ustar specification use almost all of those
|
||||
bytes to support pathnames of 256 characters in length.
|
||||
|
||||
GNU tar archives use the "unused" space to support incremental
|
||||
archives and sparse files. */
|
||||
union unused
|
||||
{
|
||||
char prefix[PREFIX_SIZE];
|
||||
/* GNU extensions to the ustar (POSIX.1-1988) archive format. */
|
||||
struct oldgnu
|
||||
{
|
||||
char atime[12];
|
||||
char ctime[12];
|
||||
char offset[12];
|
||||
char longnames[4];
|
||||
char pad;
|
||||
struct sparse sp[SPARSE_IN_HDR];
|
||||
char isextended;
|
||||
char realsize[12]; /* true size of the sparse file */
|
||||
} oldgnu;
|
||||
} unused;
|
||||
} header;
|
||||
struct extended_header
|
||||
{
|
||||
struct sparse sp[21];
|
||||
char isextended;
|
||||
} ext_hdr;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
STATUS_BADCHECKSUM,
|
||||
STATUS_SUCCESS,
|
||||
STATUS_EOFMARK,
|
||||
STATUS_EOF
|
||||
} ReadStatus;
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static struct vfs_class vfs_tarfs_ops;
|
||||
|
||||
/* As we open one archive at a time, it is safe to have this static */
|
||||
static int current_tar_position = 0;
|
||||
|
||||
static union record rec_buf;
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Quick and dirty octal conversion.
|
||||
*
|
||||
* Result is -1 if the field is invalid (all blank, or nonoctal).
|
||||
*/
|
||||
static long tar_from_oct (int digs, char *where)
|
||||
static long
|
||||
tar_from_oct (int digs, char *where)
|
||||
{
|
||||
register long value;
|
||||
|
||||
while (isspace ((unsigned char) *where)) { /* Skip spaces */
|
||||
while (isspace ((unsigned char) *where))
|
||||
{ /* Skip spaces */
|
||||
where++;
|
||||
if (--digs <= 0)
|
||||
return -1; /* All blank field */
|
||||
}
|
||||
value = 0;
|
||||
while (digs > 0 && isodigit (*where)) { /* Scan till nonoctal */
|
||||
while (digs > 0 && isodigit (*where))
|
||||
{ /* Scan till nonoctal */
|
||||
value = (value << 3) | (*where++ - '0');
|
||||
--digs;
|
||||
}
|
||||
@ -211,28 +245,30 @@ static long tar_from_oct (int digs, char *where)
|
||||
return value;
|
||||
}
|
||||
|
||||
static void tar_free_archive (struct vfs_class *me, struct vfs_s_super *archive)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tar_free_archive (struct vfs_class *me, struct vfs_s_super *archive)
|
||||
{
|
||||
(void) me;
|
||||
|
||||
if (archive->u.arch.fd != -1)
|
||||
mc_close(archive->u.arch.fd);
|
||||
mc_close (archive->u.arch.fd);
|
||||
}
|
||||
|
||||
/* As we open one archive at a time, it is safe to have this static */
|
||||
static int current_tar_position = 0;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* Returns fd of the open tar file */
|
||||
static int
|
||||
tar_open_archive_int (struct vfs_class *me, const char *name,
|
||||
struct vfs_s_super *archive)
|
||||
tar_open_archive_int (struct vfs_class *me, const char *name, struct vfs_s_super *archive)
|
||||
{
|
||||
int result, type;
|
||||
mode_t mode;
|
||||
struct vfs_s_inode *root;
|
||||
|
||||
result = mc_open (name, O_RDONLY);
|
||||
if (result == -1) {
|
||||
if (result == -1)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot open tar archive\n%s"), name);
|
||||
ERRNOR (ENOENT, -1);
|
||||
}
|
||||
@ -245,7 +281,8 @@ tar_open_archive_int (struct vfs_class *me, const char *name,
|
||||
/* Find out the method to handle this tar file */
|
||||
type = get_compression_type (result, name);
|
||||
mc_lseek (result, 0, SEEK_SET);
|
||||
if (type != COMPRESSION_NONE) {
|
||||
if (type != COMPRESSION_NONE)
|
||||
{
|
||||
char *s;
|
||||
mc_close (result);
|
||||
s = g_strconcat (archive->name, decompress_extension (type), (char *) NULL);
|
||||
@ -278,7 +315,7 @@ tar_open_archive_int (struct vfs_class *me, const char *name,
|
||||
return result;
|
||||
}
|
||||
|
||||
static union record rec_buf;
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static union record *
|
||||
tar_get_next_record (struct vfs_s_super *archive, int tard)
|
||||
@ -294,7 +331,10 @@ tar_get_next_record (struct vfs_s_super *archive, int tard)
|
||||
return &rec_buf;
|
||||
}
|
||||
|
||||
static void tar_skip_n_records (struct vfs_s_super *archive, int tard, int n)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tar_skip_n_records (struct vfs_s_super *archive, int tard, int n)
|
||||
{
|
||||
(void) archive;
|
||||
|
||||
@ -302,9 +342,10 @@ static void tar_skip_n_records (struct vfs_s_super *archive, int tard, int n)
|
||||
current_tar_position += n * RECORDSIZE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *header,
|
||||
size_t h_size)
|
||||
tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *header, size_t h_size)
|
||||
{
|
||||
st->st_mode = tar_from_oct (8, header->header.mode);
|
||||
|
||||
@ -313,37 +354,45 @@ tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *heade
|
||||
* know about the other modes but I think I cause no new
|
||||
* problem when I adjust them, too. -- Norbert.
|
||||
*/
|
||||
if (header->header.linkflag == LF_DIR) {
|
||||
if (header->header.linkflag == LF_DIR)
|
||||
{
|
||||
st->st_mode |= S_IFDIR;
|
||||
} else if (header->header.linkflag == LF_SYMLINK) {
|
||||
}
|
||||
else if (header->header.linkflag == LF_SYMLINK)
|
||||
{
|
||||
st->st_mode |= S_IFLNK;
|
||||
} else if (header->header.linkflag == LF_CHR) {
|
||||
}
|
||||
else if (header->header.linkflag == LF_CHR)
|
||||
{
|
||||
st->st_mode |= S_IFCHR;
|
||||
} else if (header->header.linkflag == LF_BLK) {
|
||||
}
|
||||
else if (header->header.linkflag == LF_BLK)
|
||||
{
|
||||
st->st_mode |= S_IFBLK;
|
||||
} else if (header->header.linkflag == LF_FIFO) {
|
||||
}
|
||||
else if (header->header.linkflag == LF_FIFO)
|
||||
{
|
||||
st->st_mode |= S_IFIFO;
|
||||
} else
|
||||
}
|
||||
else
|
||||
st->st_mode |= S_IFREG;
|
||||
|
||||
st->st_rdev = 0;
|
||||
switch (archive->u.arch.type) {
|
||||
switch (archive->u.arch.type)
|
||||
{
|
||||
case TAR_USTAR:
|
||||
case TAR_POSIX:
|
||||
case TAR_GNU:
|
||||
st->st_uid =
|
||||
*header->header.uname ? vfs_finduid (header->header.
|
||||
uname) : tar_from_oct (8,
|
||||
header->
|
||||
header.
|
||||
*header->header.uname ? vfs_finduid (header->header.uname) : tar_from_oct (8,
|
||||
header->header.
|
||||
uid);
|
||||
st->st_gid =
|
||||
*header->header.gname ? vfs_findgid (header->header.
|
||||
gname) : tar_from_oct (8,
|
||||
header->
|
||||
header.
|
||||
*header->header.gname ? vfs_findgid (header->header.gname) : tar_from_oct (8,
|
||||
header->header.
|
||||
gid);
|
||||
switch (header->header.linkflag) {
|
||||
switch (header->header.linkflag)
|
||||
{
|
||||
case LF_BLK:
|
||||
case LF_CHR:
|
||||
st->st_rdev =
|
||||
@ -358,29 +407,21 @@ tar_fill_stat (struct vfs_s_super *archive, struct stat *st, union record *heade
|
||||
st->st_mtime = tar_from_oct (1 + 12, header->header.mtime);
|
||||
st->st_atime = 0;
|
||||
st->st_ctime = 0;
|
||||
if (archive->u.arch.type == TAR_GNU) {
|
||||
st->st_atime = tar_from_oct (1 + 12,
|
||||
header->header.unused.oldgnu.atime);
|
||||
st->st_ctime = tar_from_oct (1 + 12,
|
||||
header->header.unused.oldgnu.ctime);
|
||||
if (archive->u.arch.type == TAR_GNU)
|
||||
{
|
||||
st->st_atime = tar_from_oct (1 + 12, header->header.unused.oldgnu.atime);
|
||||
st->st_ctime = tar_from_oct (1 + 12, header->header.unused.oldgnu.ctime);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef enum {
|
||||
STATUS_BADCHECKSUM,
|
||||
STATUS_SUCCESS,
|
||||
STATUS_EOFMARK,
|
||||
STATUS_EOF
|
||||
} ReadStatus;
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Return 1 for success, 0 if the checksum is bad, EOF on eof,
|
||||
* 2 for a record full of zeros (EOF marker).
|
||||
*
|
||||
*/
|
||||
static ReadStatus
|
||||
tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
int tard, size_t *h_size)
|
||||
tar_read_header (struct vfs_class *me, struct vfs_s_super *archive, int tard, size_t * h_size)
|
||||
{
|
||||
register int i;
|
||||
register long sum, signed_sum, recsum;
|
||||
@ -399,7 +440,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
sum = 0;
|
||||
signed_sum = 0;
|
||||
p = header->charptr;
|
||||
for (i = sizeof (*header); --i >= 0;) {
|
||||
for (i = sizeof (*header); --i >= 0;)
|
||||
{
|
||||
/*
|
||||
* We can't use unsigned char here because of old compilers,
|
||||
* e.g. V7.
|
||||
@ -409,7 +451,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
}
|
||||
|
||||
/* Adjust checksum to count the "chksum" field as blanks. */
|
||||
for (i = sizeof (header->header.chksum); --i >= 0;) {
|
||||
for (i = sizeof (header->header.chksum); --i >= 0;)
|
||||
{
|
||||
sum -= 0xFF & header->header.chksum[i];
|
||||
signed_sum -= (char) header->header.chksum[i];
|
||||
}
|
||||
@ -429,13 +472,17 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
/*
|
||||
* Try to determine the archive format.
|
||||
*/
|
||||
if (archive->u.arch.type == TAR_UNKNOWN) {
|
||||
if (!strcmp (header->header.magic, TMAGIC)) {
|
||||
if (archive->u.arch.type == TAR_UNKNOWN)
|
||||
{
|
||||
if (!strcmp (header->header.magic, TMAGIC))
|
||||
{
|
||||
if (header->header.linkflag == LF_GLOBAL_EXTHDR)
|
||||
archive->u.arch.type = TAR_POSIX;
|
||||
else
|
||||
archive->u.arch.type = TAR_USTAR;
|
||||
} else if (!strcmp (header->header.magic, OLDGNU_MAGIC)) {
|
||||
}
|
||||
else if (!strcmp (header->header.magic, OLDGNU_MAGIC))
|
||||
{
|
||||
archive->u.arch.type = TAR_GNU;
|
||||
}
|
||||
}
|
||||
@ -443,7 +490,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
/*
|
||||
* linkflag on BSDI tar (pax) always '\000'
|
||||
*/
|
||||
if (header->header.linkflag == '\000') {
|
||||
if (header->header.linkflag == '\000')
|
||||
{
|
||||
if (header->header.arch_name[NAMSIZ - 1] != '\0')
|
||||
i = NAMSIZ;
|
||||
else
|
||||
@ -456,8 +504,7 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
/*
|
||||
* Good record. Decode file size and return.
|
||||
*/
|
||||
if (header->header.linkflag == LF_LINK
|
||||
|| header->header.linkflag == LF_DIR)
|
||||
if (header->header.linkflag == LF_LINK || header->header.linkflag == LF_DIR)
|
||||
*h_size = 0; /* Links 0 size on tape */
|
||||
else
|
||||
*h_size = tar_from_oct (1 + 12, header->header.size);
|
||||
@ -466,7 +513,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
* Skip over directory snapshot info records that
|
||||
* are stored in incremental tar archives.
|
||||
*/
|
||||
if (header->header.linkflag == LF_DUMPDIR) {
|
||||
if (header->header.linkflag == LF_DUMPDIR)
|
||||
{
|
||||
if (archive->u.arch.type == TAR_UNKNOWN)
|
||||
archive->u.arch.type = TAR_GNU;
|
||||
return STATUS_SUCCESS;
|
||||
@ -476,15 +524,15 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
* Skip over pax extended header and global extended
|
||||
* header records.
|
||||
*/
|
||||
if (header->header.linkflag == LF_EXTHDR ||
|
||||
header->header.linkflag == LF_GLOBAL_EXTHDR) {
|
||||
if (header->header.linkflag == LF_EXTHDR || header->header.linkflag == LF_GLOBAL_EXTHDR)
|
||||
{
|
||||
if (archive->u.arch.type == TAR_UNKNOWN)
|
||||
archive->u.arch.type = TAR_POSIX;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (header->header.linkflag == LF_LONGNAME
|
||||
|| header->header.linkflag == LF_LONGLINK) {
|
||||
if (header->header.linkflag == LF_LONGNAME || header->header.linkflag == LF_LONGLINK)
|
||||
{
|
||||
char **longp;
|
||||
char *bp, *data;
|
||||
int size, written;
|
||||
@ -492,24 +540,25 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
if (archive->u.arch.type == TAR_UNKNOWN)
|
||||
archive->u.arch.type = TAR_GNU;
|
||||
|
||||
if (*h_size > MC_MAXPATHLEN) {
|
||||
if (*h_size > MC_MAXPATHLEN)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Inconsistent tar archive"));
|
||||
return STATUS_BADCHECKSUM;
|
||||
}
|
||||
|
||||
longp = ((header->header.linkflag == LF_LONGNAME)
|
||||
? &next_long_name : &next_long_link);
|
||||
longp = ((header->header.linkflag == LF_LONGNAME) ? &next_long_name : &next_long_link);
|
||||
|
||||
g_free (*longp);
|
||||
bp = *longp = g_malloc (*h_size + 1);
|
||||
|
||||
for (size = *h_size; size > 0; size -= written) {
|
||||
for (size = *h_size; size > 0; size -= written)
|
||||
{
|
||||
data = tar_get_next_record (archive, tard)->charptr;
|
||||
if (data == NULL) {
|
||||
if (data == NULL)
|
||||
{
|
||||
g_free (*longp);
|
||||
*longp = NULL;
|
||||
message (D_ERROR, MSG_ERROR,
|
||||
_("Unexpected EOF on archive file"));
|
||||
message (D_ERROR, MSG_ERROR, _("Unexpected EOF on archive file"));
|
||||
return STATUS_BADCHECKSUM;
|
||||
}
|
||||
written = RECORDSIZE;
|
||||
@ -520,7 +569,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
bp += written;
|
||||
}
|
||||
|
||||
if (bp - *longp == MC_MAXPATHLEN && bp[-1] != '\0') {
|
||||
if (bp - *longp == MC_MAXPATHLEN && bp[-1] != '\0')
|
||||
{
|
||||
g_free (*longp);
|
||||
*longp = NULL;
|
||||
message (D_ERROR, MSG_ERROR, _("Inconsistent tar archive"));
|
||||
@ -528,7 +578,9 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
}
|
||||
*bp = 0;
|
||||
goto recurse;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
struct stat st;
|
||||
struct vfs_s_entry *entry;
|
||||
struct vfs_s_inode *inode = NULL, *parent;
|
||||
@ -538,14 +590,14 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
char *current_file_name, *current_link_name;
|
||||
|
||||
current_link_name =
|
||||
(next_long_link ? next_long_link :
|
||||
g_strndup (header->header.arch_linkname, NAMSIZ));
|
||||
(next_long_link ? next_long_link : g_strndup (header->header.arch_linkname, NAMSIZ));
|
||||
len = strlen (current_link_name);
|
||||
if (len > 1 && current_link_name[len - 1] == '/')
|
||||
current_link_name[len - 1] = 0;
|
||||
|
||||
current_file_name = NULL;
|
||||
switch (archive->u.arch.type) {
|
||||
switch (archive->u.arch.type)
|
||||
{
|
||||
case TAR_USTAR:
|
||||
case TAR_POSIX:
|
||||
/* The ustar archive format supports pathnames of upto 256
|
||||
@ -558,12 +610,12 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
* If the `prefix' field contains an empty string i.e. its
|
||||
* first characters is '\0' the prefix field is ignored.
|
||||
*/
|
||||
if (header->header.unused.prefix[0] != '\0') {
|
||||
if (header->header.unused.prefix[0] != '\0')
|
||||
{
|
||||
char *temp_name, *temp_prefix;
|
||||
|
||||
temp_name = g_strndup (header->header.arch_name, NAMSIZ);
|
||||
temp_prefix = g_strndup (header->header.unused.prefix,
|
||||
PREFIX_SIZE);
|
||||
temp_prefix = g_strndup (header->header.unused.prefix, PREFIX_SIZE);
|
||||
current_file_name = g_strconcat (temp_prefix, PATH_SEP_STR,
|
||||
temp_name, (char *) NULL);
|
||||
g_free (temp_name);
|
||||
@ -587,28 +639,33 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
data_position = current_tar_position;
|
||||
|
||||
p = strrchr (current_file_name, '/');
|
||||
if (p == NULL) {
|
||||
if (p == NULL)
|
||||
{
|
||||
p = current_file_name;
|
||||
q = current_file_name + len; /* "" */
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*(p++) = 0;
|
||||
q = current_file_name;
|
||||
}
|
||||
|
||||
parent =
|
||||
vfs_s_find_inode (me, archive, q, LINK_NO_FOLLOW, FL_MKDIR);
|
||||
if (parent == NULL) {
|
||||
parent = vfs_s_find_inode (me, archive, q, LINK_NO_FOLLOW, FL_MKDIR);
|
||||
if (parent == NULL)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Inconsistent tar archive"));
|
||||
return STATUS_BADCHECKSUM;
|
||||
}
|
||||
|
||||
if (header->header.linkflag == LF_LINK) {
|
||||
inode =
|
||||
vfs_s_find_inode (me, archive, current_link_name,
|
||||
LINK_NO_FOLLOW, 0);
|
||||
if (inode == NULL) {
|
||||
if (header->header.linkflag == LF_LINK)
|
||||
{
|
||||
inode = vfs_s_find_inode (me, archive, current_link_name, LINK_NO_FOLLOW, 0);
|
||||
if (inode == NULL)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _("Inconsistent tar archive"));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
entry = vfs_s_new_entry (me, p, inode);
|
||||
vfs_s_insert_entry (me, parent, entry);
|
||||
g_free (current_link_name);
|
||||
@ -617,7 +674,8 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
}
|
||||
|
||||
tar_fill_stat (archive, &st, header, *h_size);
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if (S_ISDIR (st.st_mode))
|
||||
{
|
||||
entry = MEDATA->find_entry (me, parent, p, LINK_NO_FOLLOW, FL_NONE);
|
||||
if (entry)
|
||||
goto done;
|
||||
@ -625,9 +683,12 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
inode = vfs_s_new_inode (me, archive, &st);
|
||||
|
||||
inode->data_offset = data_position;
|
||||
if (*current_link_name) {
|
||||
if (*current_link_name)
|
||||
{
|
||||
inode->linkname = current_link_name;
|
||||
} else if (current_link_name != next_long_link) {
|
||||
}
|
||||
else if (current_link_name != next_long_link)
|
||||
{
|
||||
g_free (current_link_name);
|
||||
}
|
||||
entry = vfs_s_new_entry (me, p, inode);
|
||||
@ -638,23 +699,22 @@ tar_read_header (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
done:
|
||||
next_long_link = next_long_name = NULL;
|
||||
|
||||
if (archive->u.arch.type == TAR_GNU &&
|
||||
header->header.unused.oldgnu.isextended) {
|
||||
while (tar_get_next_record (archive, tard)->ext_hdr.
|
||||
isextended);
|
||||
if (archive->u.arch.type == TAR_GNU && header->header.unused.oldgnu.isextended)
|
||||
{
|
||||
while (tar_get_next_record (archive, tard)->ext_hdr.isextended);
|
||||
inode->data_offset = current_tar_position;
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Main loop for reading an archive.
|
||||
* Returns 0 on success, -1 on error.
|
||||
*/
|
||||
static int
|
||||
tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
const char *name, char *op)
|
||||
tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive, const char *name, char *op)
|
||||
{
|
||||
/* Initial status at start of archive */
|
||||
ReadStatus status = STATUS_EOFMARK;
|
||||
@ -669,18 +729,18 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
if (tard == -1)
|
||||
return -1;
|
||||
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
size_t h_size;
|
||||
|
||||
prev_status = status;
|
||||
status = tar_read_header (me, archive, tard, &h_size);
|
||||
|
||||
switch (status) {
|
||||
switch (status)
|
||||
{
|
||||
|
||||
case STATUS_SUCCESS:
|
||||
tar_skip_n_records (archive, tard,
|
||||
(h_size + RECORDSIZE -
|
||||
1) / RECORDSIZE);
|
||||
tar_skip_n_records (archive, tard, (h_size + RECORDSIZE - 1) / RECORDSIZE);
|
||||
continue;
|
||||
|
||||
/*
|
||||
@ -690,14 +750,12 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
* that we are skipping bad ones.
|
||||
*/
|
||||
case STATUS_BADCHECKSUM:
|
||||
switch (prev_status) {
|
||||
switch (prev_status)
|
||||
{
|
||||
|
||||
/* Error on first record */
|
||||
case STATUS_EOFMARK:
|
||||
message (D_ERROR, MSG_ERROR,
|
||||
_
|
||||
("%s\ndoesn't look like a tar archive."),
|
||||
name);
|
||||
message (D_ERROR, MSG_ERROR, _("%s\ndoesn't look like a tar archive."), name);
|
||||
/* FALL THRU */
|
||||
|
||||
/* Error after header rec */
|
||||
@ -724,6 +782,8 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
tar_super_check (struct vfs_class *me, const char *archive_name, char *op)
|
||||
{
|
||||
@ -737,6 +797,8 @@ tar_super_check (struct vfs_class *me, const char *archive_name, char *op)
|
||||
return &stat_buf;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
tar_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
const char *archive_name, char *op, void *cookie)
|
||||
@ -750,7 +812,8 @@ tar_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
return 0;
|
||||
|
||||
/* Has the cached archive been changed on the disk? */
|
||||
if (parc->u.arch.st.st_mtime < archive_stat->st_mtime) {
|
||||
if (parc->u.arch.st.st_mtime < archive_stat->st_mtime)
|
||||
{
|
||||
/* Yes, reload! */
|
||||
(*vfs_tarfs_ops.free) ((vfsid) parc);
|
||||
vfs_rmstamp (&vfs_tarfs_ops, (vfsid) parc);
|
||||
@ -761,17 +824,20 @@ tar_super_same (struct vfs_class *me, struct vfs_s_super *parc,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static ssize_t tar_read (void *fh, char *buffer, size_t count)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
tar_read (void *fh, char *buffer, size_t count)
|
||||
{
|
||||
off_t begin = FH->ino->data_offset;
|
||||
int fd = FH_SUPER->u.arch.fd;
|
||||
struct vfs_class *me = FH_SUPER->me;
|
||||
ssize_t res;
|
||||
|
||||
if (mc_lseek (fd, begin + FH->pos, SEEK_SET) !=
|
||||
begin + FH->pos) ERRNOR (EIO, -1);
|
||||
if (mc_lseek (fd, begin + FH->pos, SEEK_SET) != begin + FH->pos)
|
||||
ERRNOR (EIO, -1);
|
||||
|
||||
count = MIN (count, (size_t)(FH->ino->st.st_size - FH->pos));
|
||||
count = MIN (count, (size_t) (FH->ino->st.st_size - FH->pos));
|
||||
|
||||
res = mc_read (fd, buffer, count);
|
||||
if (res == -1)
|
||||
@ -781,15 +847,23 @@ static ssize_t tar_read (void *fh, char *buffer, size_t count)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int tar_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
tar_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, mode_t mode)
|
||||
{
|
||||
(void) fh;
|
||||
(void) mode;
|
||||
|
||||
if ((flags & O_ACCMODE) != O_RDONLY) ERRNOR (EROFS, -1);
|
||||
if ((flags & O_ACCMODE) != O_RDONLY)
|
||||
ERRNOR (EROFS, -1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
init_tarfs (void)
|
||||
{
|
||||
@ -809,3 +883,5 @@ init_tarfs (void)
|
||||
vfs_tarfs_ops.setctl = NULL;
|
||||
vfs_register_class (&vfs_tarfs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -64,6 +64,17 @@
|
||||
#include "utilvfs.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
|
||||
{
|
||||
ext2_ino_t ino;
|
||||
@ -84,6 +95,25 @@ struct lsdel_struct
|
||||
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 */
|
||||
static char *ext2_fname;
|
||||
static ext2_filsys fs = NULL;
|
||||
@ -96,8 +126,8 @@ static int readdir_ptr;
|
||||
static int undelfs_usage;
|
||||
static struct vfs_class vfs_undelfs_ops;
|
||||
|
||||
/* To generate the . and .. entries use -2 */
|
||||
#define READDIR_PTR_INIT 0
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
undelfs_shutdown (void)
|
||||
@ -113,6 +143,8 @@ undelfs_shutdown (void)
|
||||
block_buf = NULL;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Load information about deleted files.
|
||||
* Don't abort if there is not enough memory - load as much as we can.
|
||||
*/
|
||||
|
||||
static int
|
||||
undelfs_loaddel (void)
|
||||
{
|
||||
@ -291,24 +327,7 @@ undelfs_loaddel (void)
|
||||
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 *
|
||||
undelfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
@ -364,6 +383,7 @@ undelfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void *
|
||||
undelfs_readdir (void *vfs_info)
|
||||
@ -390,6 +410,8 @@ undelfs_readdir (void *vfs_info)
|
||||
return &undelfs_readdir_data;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
undelfs_closedir (void *vfs_info)
|
||||
{
|
||||
@ -397,24 +419,9 @@ undelfs_closedir (void *vfs_info)
|
||||
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 */
|
||||
|
||||
static void *
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
undelfs_close (void *vfs_info)
|
||||
{
|
||||
@ -484,6 +493,8 @@ undelfs_close (void *vfs_info)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static ssize_t
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static long
|
||||
undelfs_getindex (char *path)
|
||||
{
|
||||
@ -595,6 +610,8 @@ undelfs_getindex (char *path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
undelfs_stat_int (int inode_index, struct stat *buf)
|
||||
{
|
||||
@ -611,6 +628,8 @@ undelfs_stat_int (int inode_index, struct stat *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
#define undelfs_stat undelfs_lstat
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
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);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
undelfs_chdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
@ -690,6 +711,8 @@ undelfs_chdir (struct vfs_class *me, const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/* this has to stay here for now: vfs layer does not know how to emulate it */
|
||||
static off_t
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static vfsid
|
||||
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;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static int
|
||||
undelfs_nothingisopen (vfsid id)
|
||||
{
|
||||
@ -724,6 +751,8 @@ undelfs_nothingisopen (vfsid id)
|
||||
return !undelfs_usage;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
undelfs_free (vfsid id)
|
||||
{
|
||||
@ -732,6 +761,8 @@ undelfs_free (vfsid id)
|
||||
undelfs_shutdown ();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef ENABLE_NLS
|
||||
static int
|
||||
undelfs_init (struct vfs_class *me)
|
||||
@ -745,6 +776,30 @@ undelfs_init (struct vfs_class *me)
|
||||
#define undelfs_init NULL
|
||||
#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
|
||||
init_undelfs (void)
|
||||
{
|
||||
@ -767,3 +822,5 @@ init_undelfs (void)
|
||||
vfs_undelfs_ops.free = undelfs_free;
|
||||
vfs_register_class (&vfs_undelfs_ops);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -13,16 +13,27 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/** Bit flags for vfs_split_url()
|
||||
*
|
||||
* Modify parsing parameters according to flag meaning.
|
||||
* @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_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_findgid (const char *name);
|
||||
|
||||
@ -34,19 +45,15 @@ int vfs_mkstemps (char **pname, const char *prefix, const char *basename);
|
||||
void vfs_die (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,
|
||||
mode_t *ret_type);
|
||||
gboolean vfs_parse_fileperms (const char *s, size_t *ret_skipped,
|
||||
mode_t *ret_perms);
|
||||
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);
|
||||
gboolean vfs_parse_filetype (const char *s, size_t * ret_skipped, mode_t * ret_type);
|
||||
gboolean vfs_parse_fileperms (const char *s, size_t * ret_skipped, mode_t * ret_perms);
|
||||
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,
|
||||
char **linkname);
|
||||
int vfs_parse_filedate (int idx, time_t *t);
|
||||
int vfs_parse_ls_lga (const char *p, struct stat *s, char **filename, char **linkname);
|
||||
int vfs_parse_filedate (int idx, time_t * t);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -4,8 +4,8 @@
|
||||
* \brief Header: VFS implemntation (?)
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_IMPL_H
|
||||
#define MC_VFS_IMPL_H
|
||||
#ifndef MC__VFS_IMPL_H
|
||||
#define MC__VFS_IMPL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@ -18,10 +18,18 @@
|
||||
#include "vfs.h"
|
||||
#include "lib/fs.h" /* MC_MAXPATHLEN */
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
typedef void *vfsid;
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
struct vfs_stamping;
|
||||
|
||||
struct vfs_class {
|
||||
struct vfs_class
|
||||
{
|
||||
struct vfs_class *next;
|
||||
const char *name; /* "FIles over SHell" */
|
||||
vfs_class_flags_t flags;
|
||||
@ -29,77 +37,79 @@ struct vfs_class {
|
||||
void *data; /* this is for filesystem's own use */
|
||||
int verrno; /* can't use errno because glibc2 might define errno as function */
|
||||
|
||||
int (*init) (struct vfs_class *me);
|
||||
void (*done) (struct vfs_class *me);
|
||||
int (*init) (struct vfs_class * me);
|
||||
void (*done) (struct vfs_class * me);
|
||||
|
||||
/**
|
||||
* The fill_names method shall call the callback function for every
|
||||
* 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
|
||||
* 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,
|
||||
mode_t mode);
|
||||
void *(*open) (struct vfs_class * me, const char *fname, int flags, mode_t mode);
|
||||
int (*close) (void *vfs_info);
|
||||
ssize_t (*read) (void *vfs_info, char *buffer, 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);
|
||||
int (*closedir) (void *vfs_info);
|
||||
|
||||
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 (*stat) (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 (*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 (*utime) (struct vfs_class *me, const char *path,
|
||||
struct utimbuf * times);
|
||||
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 (*utime) (struct vfs_class * me, const char *path, struct utimbuf * times);
|
||||
|
||||
int (*readlink) (struct vfs_class *me, const char *path, char *buf,
|
||||
size_t size);
|
||||
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 (*unlink) (struct vfs_class *me, const char *path);
|
||||
int (*rename) (struct vfs_class *me, const char *p1, const char *p2);
|
||||
int (*chdir) (struct vfs_class *me, const char *path);
|
||||
int (*ferrno) (struct vfs_class *me);
|
||||
int (*readlink) (struct vfs_class * me, const char *path, char *buf, size_t size);
|
||||
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 (*unlink) (struct vfs_class * me, const char *path);
|
||||
int (*rename) (struct vfs_class * me, const char *p1, const char *p2);
|
||||
int (*chdir) (struct vfs_class * me, const char *path);
|
||||
int (*ferrno) (struct vfs_class * me);
|
||||
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);
|
||||
void (*free) (vfsid id);
|
||||
|
||||
char *(*getlocalcopy) (struct vfs_class *me, const char *filename);
|
||||
int (*ungetlocalcopy) (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,
|
||||
const char *local, int has_changed);
|
||||
|
||||
int (*mkdir) (struct vfs_class *me, const char *path, mode_t mode);
|
||||
int (*rmdir) (struct vfs_class *me, const char *path);
|
||||
int (*mkdir) (struct vfs_class * me, const char *path, mode_t mode);
|
||||
int (*rmdir) (struct vfs_class * me, const char *path);
|
||||
|
||||
int (*ctl) (void *vfs_info, int ctlop, void *arg);
|
||||
int (*setctl) (struct vfs_class *me, const char *path, int ctlop,
|
||||
void *arg);
|
||||
int (*setctl) (struct vfs_class * me, const char *path, int ctlop, void *arg);
|
||||
};
|
||||
|
||||
/*
|
||||
* This union is used to ensure that there is enough space for the
|
||||
* filename (d_name) when the dirent structure is created.
|
||||
*/
|
||||
union vfs_dirent {
|
||||
union vfs_dirent
|
||||
{
|
||||
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 */
|
||||
int vfs_register_class (struct vfs_class *vfs);
|
||||
|
||||
@ -133,4 +143,5 @@ void init_ftpfs (void);
|
||||
void init_fish (void);
|
||||
#endif
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_VFS_IMPL_H */
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -4,8 +4,8 @@
|
||||
* \brief Header: Virtual File System switch code
|
||||
*/
|
||||
|
||||
#ifndef MC_VFS_VFS_H
|
||||
#define MC_VFS_VFS_H
|
||||
#ifndef MC__VFS_VFS_H
|
||||
#define MC__VFS_VFS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@ -14,18 +14,7 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
struct vfs_class;
|
||||
|
||||
/* 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);
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
|
||||
#define ENABLE_VFS_NET 1
|
||||
@ -37,101 +26,15 @@ void vfs_shut (void);
|
||||
* See also:
|
||||
* vfs_fill_names().
|
||||
*/
|
||||
typedef void (*fill_names_f) (const char *);
|
||||
|
||||
extern int vfs_timeout;
|
||||
|
||||
#ifdef ENABLE_VFS_NET
|
||||
extern int use_netrc;
|
||||
#endif
|
||||
|
||||
void vfs_timeout_handler (void);
|
||||
int vfs_timeouts (void);
|
||||
void vfs_expire (int now);
|
||||
|
||||
gboolean vfs_current_is_local (void);
|
||||
gboolean vfs_file_is_local (const char *filename);
|
||||
ssize_t mc_read (int handle, void *buffer, size_t count);
|
||||
ssize_t mc_write (int handle, const void *buffer, size_t count);
|
||||
int mc_utime (const char *path, struct utimbuf *times);
|
||||
int mc_readlink (const char *path, char *buf, size_t bufsiz);
|
||||
int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
|
||||
int mc_close (int handle);
|
||||
off_t mc_lseek (int fd, off_t offset, int whence);
|
||||
DIR *mc_opendir (const char *dirname);
|
||||
struct dirent *mc_readdir (DIR * dirp);
|
||||
int mc_closedir (DIR * dir);
|
||||
int mc_stat (const char *path, struct stat *buf);
|
||||
int mc_mknod (const char *path, mode_t mode, dev_t dev);
|
||||
int mc_link (const char *name1, const char *name2);
|
||||
int mc_mkdir (const char *path, mode_t mode);
|
||||
int mc_rmdir (const char *path);
|
||||
int mc_fstat (int fd, struct stat *buf);
|
||||
int mc_lstat (const char *path, struct stat *buf);
|
||||
int mc_symlink (const char *name1, const char *name2);
|
||||
int mc_rename (const char *original, const char *target);
|
||||
int mc_chmod (const char *path, mode_t mode);
|
||||
int mc_chown (const char *path, uid_t owner, gid_t group);
|
||||
int mc_chdir (const char *path);
|
||||
int mc_unlink (const char *path);
|
||||
int mc_ctl (int fd, int ctlop, void *arg);
|
||||
int mc_setctl (const char *path, int ctlop, void *arg);
|
||||
int mc_open (const char *filename, int flags, ...);
|
||||
char *mc_get_current_wd (char *buffer, size_t bufsize);
|
||||
char *vfs_canon (const char *path);
|
||||
char *mc_getlocalcopy (const char *pathname);
|
||||
char *vfs_strip_suffix_from_filename (const char *filename);
|
||||
char *vfs_translate_url (const char *url);
|
||||
|
||||
struct vfs_class *vfs_get_class (const char *path);
|
||||
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 static buffer */
|
||||
const char *vfs_get_encoding (const char *path);
|
||||
|
||||
/* return new string */
|
||||
char *vfs_translate_path_n (const char *path);
|
||||
|
||||
/* canonize and translate path, return new string */
|
||||
char *vfs_canon_and_translate (const char *path);
|
||||
|
||||
void vfs_stamp_path (const char *path);
|
||||
|
||||
void vfs_release_path (const char *dir);
|
||||
|
||||
void vfs_fill_names (fill_names_f);
|
||||
|
||||
char *vfs_get_current_dir (void);
|
||||
/* translate path back to terminal encoding, remove all #enc:
|
||||
* every invalid character is replaced with question mark
|
||||
* return static buffer */
|
||||
char *vfs_translate_path (const char *path);
|
||||
|
||||
/* 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
|
||||
};
|
||||
|
||||
#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"
|
||||
#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
|
||||
@ -182,4 +85,117 @@ enum {
|
||||
#define E_PROTO EIO
|
||||
#endif
|
||||
|
||||
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;
|
||||
|
||||
#ifdef ENABLE_VFS_NET
|
||||
extern int use_netrc;
|
||||
#endif
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void vfs_init (void);
|
||||
void vfs_shut (void);
|
||||
|
||||
|
||||
void vfs_timeout_handler (void);
|
||||
int vfs_timeouts (void);
|
||||
void vfs_expire (int now);
|
||||
|
||||
gboolean vfs_current_is_local (void);
|
||||
gboolean vfs_file_is_local (const char *filename);
|
||||
ssize_t mc_read (int handle, void *buffer, size_t count);
|
||||
ssize_t mc_write (int handle, const void *buffer, size_t count);
|
||||
int mc_utime (const char *path, struct utimbuf *times);
|
||||
int mc_readlink (const char *path, char *buf, size_t bufsiz);
|
||||
int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
|
||||
int mc_close (int handle);
|
||||
off_t mc_lseek (int fd, off_t offset, int whence);
|
||||
DIR *mc_opendir (const char *dirname);
|
||||
struct dirent *mc_readdir (DIR * dirp);
|
||||
int mc_closedir (DIR * dir);
|
||||
int mc_stat (const char *path, struct stat *buf);
|
||||
int mc_mknod (const char *path, mode_t mode, dev_t dev);
|
||||
int mc_link (const char *name1, const char *name2);
|
||||
int mc_mkdir (const char *path, mode_t mode);
|
||||
int mc_rmdir (const char *path);
|
||||
int mc_fstat (int fd, struct stat *buf);
|
||||
int mc_lstat (const char *path, struct stat *buf);
|
||||
int mc_symlink (const char *name1, const char *name2);
|
||||
int mc_rename (const char *original, const char *target);
|
||||
int mc_chmod (const char *path, mode_t mode);
|
||||
int mc_chown (const char *path, uid_t owner, gid_t group);
|
||||
int mc_chdir (const char *path);
|
||||
int mc_unlink (const char *path);
|
||||
int mc_ctl (int fd, int ctlop, void *arg);
|
||||
int mc_setctl (const char *path, int ctlop, void *arg);
|
||||
int mc_open (const char *filename, int flags, ...);
|
||||
char *mc_get_current_wd (char *buffer, size_t bufsize);
|
||||
char *vfs_canon (const char *path);
|
||||
char *mc_getlocalcopy (const char *pathname);
|
||||
char *vfs_strip_suffix_from_filename (const char *filename);
|
||||
char *vfs_translate_url (const char *url);
|
||||
|
||||
struct vfs_class *vfs_get_class (const char *path);
|
||||
vfs_class_flags_t vfs_file_class_flags (const char *filename);
|
||||
|
||||
/* return encoding after last #enc: or NULL, if part does not contain #enc:
|
||||
* return static buffer */
|
||||
const char *vfs_get_encoding (const char *path);
|
||||
|
||||
/* return new string */
|
||||
char *vfs_translate_path_n (const char *path);
|
||||
|
||||
/* canonize and translate path, return new string */
|
||||
char *vfs_canon_and_translate (const char *path);
|
||||
|
||||
void vfs_stamp_path (const char *path);
|
||||
|
||||
void vfs_release_path (const char *dir);
|
||||
|
||||
void vfs_fill_names (fill_names_f);
|
||||
|
||||
char *vfs_get_current_dir (void);
|
||||
/* translate path back to terminal encoding, remove all #enc:
|
||||
* every invalid character is replaced with question mark
|
||||
* return static buffer */
|
||||
char *vfs_translate_path (const char *path);
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif /* MC_VFS_VFS_H */
|
||||
|
@ -5,12 +5,14 @@
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MC_VFS_XDIRENTRY_H
|
||||
#define MC_VFS_XDIRENTRY_H
|
||||
#ifndef MC__VFS_XDIRENTRY_H
|
||||
#define MC__VFS_XDIRENTRY_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
#define LINK_FOLLOW 15
|
||||
#define LINK_NO_FOLLOW -1
|
||||
|
||||
@ -31,6 +33,21 @@
|
||||
#define VFS_S_REMOTE 1
|
||||
#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 */
|
||||
struct vfs_s_super
|
||||
@ -198,6 +215,9 @@ struct vfs_s_subclass
|
||||
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 */
|
||||
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 */
|
||||
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)
|
||||
|
||||
#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
|
||||
|
||||
/*** inline functions ****************************************************************************/
|
||||
#endif
|
||||
|
@ -264,7 +264,9 @@ set_attr (unsigned attr)
|
||||
color_map[tc & 7], color_map[bc & 7]);
|
||||
}
|
||||
|
||||
#define cursor_to(x, y) do { \
|
||||
#define cursor_to(x, y) \
|
||||
do \
|
||||
{ \
|
||||
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
|
||||
fflush(stdout); \
|
||||
} while (0)
|
||||
|
@ -88,11 +88,12 @@ do { \
|
||||
#define HDIFF_DEPTH 10
|
||||
|
||||
#define FILE_DIRTY(fs) \
|
||||
do { \
|
||||
do \
|
||||
{ \
|
||||
(fs)->pos = 0; \
|
||||
(fs)->len = 0; \
|
||||
} while (0)
|
||||
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
@ -3307,33 +3308,41 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
#define GET_FILE_AND_STAMP(n) \
|
||||
do { \
|
||||
do \
|
||||
{ \
|
||||
use_copy##n = 0; \
|
||||
real_file##n = file##n; \
|
||||
if (!vfs_file_is_local(file##n)) { \
|
||||
real_file##n = mc_getlocalcopy(file##n); \
|
||||
if (real_file##n != NULL) { \
|
||||
if (!vfs_file_is_local (file##n)) \
|
||||
{ \
|
||||
real_file##n = mc_getlocalcopy (file##n); \
|
||||
if (real_file##n != NULL) \
|
||||
{ \
|
||||
use_copy##n = 1; \
|
||||
if (mc_stat(real_file##n, &st##n) != 0) { \
|
||||
if (mc_stat (real_file##n, &st##n) != 0) \
|
||||
use_copy##n = -1; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#define UNGET_FILE(n) \
|
||||
do { \
|
||||
if (use_copy##n) { \
|
||||
do \
|
||||
{ \
|
||||
if (use_copy##n) \
|
||||
{ \
|
||||
int changed = 0; \
|
||||
if (use_copy##n > 0) { \
|
||||
time_t mtime = st##n.st_mtime; \
|
||||
if (mc_stat(real_file##n, &st##n) == 0) { \
|
||||
if (use_copy##n > 0) \
|
||||
{ \
|
||||
time_t mtime; \
|
||||
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); \
|
||||
} \
|
||||
mc_ungetlocalcopy(file##n, real_file##n, changed); \
|
||||
g_free(real_file##n); \
|
||||
} \
|
||||
} while (0)
|
||||
} \
|
||||
while (0)
|
||||
|
||||
void
|
||||
dview_diff_cmd (void)
|
||||
|
@ -3,8 +3,8 @@
|
||||
* \brief Header: defines history section names
|
||||
*/
|
||||
|
||||
#ifndef __MC_HISTORY_H
|
||||
#define __MC_HISTORY_H
|
||||
#ifndef MC_HISTORY_H
|
||||
#define MC_HISTORY_H
|
||||
|
||||
/* history section names */
|
||||
|
||||
@ -45,4 +45,4 @@
|
||||
|
||||
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
|
||||
|
||||
#endif
|
||||
#endif /* MC_HISTORY_H */
|
||||
|
@ -233,12 +233,14 @@ update_path_name (void)
|
||||
}
|
||||
|
||||
#define CHECK_BUFFER \
|
||||
do { \
|
||||
int i; \
|
||||
\
|
||||
if ((i = strlen (current->label) + 3) > buflen) { \
|
||||
do \
|
||||
{ \
|
||||
size_t i; \
|
||||
i = strlen (current->label); \
|
||||
if (i + 3 > buflen) { \
|
||||
g_free (buf); \
|
||||
buf = g_malloc (buflen = 1024 * (i/1024 + 1)); \
|
||||
buflen = 1024 * (i/1024 + 1); \
|
||||
buf = g_malloc (buflen); \
|
||||
} \
|
||||
buf[0] = '\0'; \
|
||||
} while (0)
|
||||
@ -1384,19 +1386,21 @@ hot_next_token (void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SKIP_TO_EOL { \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
#define SKIP_TO_EOL \
|
||||
{ \
|
||||
int _tkn; \
|
||||
while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) { \
|
||||
if (tkn != _TKN_) \
|
||||
{ \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
tkn = hot_next_token (); \
|
||||
break; \
|
||||
break; \
|
||||
}
|
||||
|
||||
static void
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user