Code indentation in lib directory

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Slava Zanko 2010-11-08 12:21:45 +02:00 committed by Andrew Borodin
parent 4a1a758c25
commit feb733663f
104 changed files with 9305 additions and 6737 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,3 @@
/** \file fileloc.h
* \brief Header: config files list
*
@ -14,65 +13,76 @@
#ifndef MC_FILELOC_H
#define MC_FILELOC_H
/*** typedefs(not structures) and defined constants **********************************************/
#ifndef MC_USERCONF_DIR
#define MC_USERCONF_DIR ".mc"
#define MC_USERCONF_DIR ".mc"
#endif
#define TAGS_NAME "TAGS"
#define TAGS_NAME "TAGS"
#define MC_GLOBAL_CONFIG_FILE "mc.lib"
#define MC_GLOBAL_MENU "mc.menu"
#define MC_LOCAL_MENU ".mc.menu"
#define MC_HINT "hints" PATH_SEP_STR "mc.hint"
#define MC_HELP "help" PATH_SEP_STR "mc.hlp"
#define GLOBAL_KEYMAP_FILE "mc.keymap"
#define CHARSETS_LIST "mc.charsets"
#define MC_LIB_EXT "mc.ext"
#define MC_GLOBAL_CONFIG_FILE "mc.lib"
#define MC_GLOBAL_MENU "mc.menu"
#define MC_LOCAL_MENU ".mc.menu"
#define MC_HINT "hints" PATH_SEP_STR "mc.hint"
#define MC_HELP "help" PATH_SEP_STR "mc.hlp"
#define GLOBAL_KEYMAP_FILE "mc.keymap"
#define CHARSETS_LIST "mc.charsets"
#define MC_LIB_EXT "mc.ext"
#define FISH_PREFIX "fish"
#define FISH_PREFIX "fish"
#define FISH_LS_FILE "ls"
#define FISH_EXISTS_FILE "fexists"
#define FISH_MKDIR_FILE "mkdir"
#define FISH_UNLINK_FILE "unlink"
#define FISH_CHOWN_FILE "chown"
#define FISH_CHMOD_FILE "chmod"
#define FISH_RMDIR_FILE "rmdir"
#define FISH_LN_FILE "ln"
#define FISH_MV_FILE "mv"
#define FISH_HARDLINK_FILE "hardlink"
#define FISH_GET_FILE "get"
#define FISH_SEND_FILE "send"
#define FISH_APPEND_FILE "append"
#define FISH_INFO_FILE "info"
#define FISH_LS_FILE "ls"
#define FISH_EXISTS_FILE "fexists"
#define FISH_MKDIR_FILE "mkdir"
#define FISH_UNLINK_FILE "unlink"
#define FISH_CHOWN_FILE "chown"
#define FISH_CHMOD_FILE "chmod"
#define FISH_RMDIR_FILE "rmdir"
#define FISH_LN_FILE "ln"
#define FISH_MV_FILE "mv"
#define FISH_HARDLINK_FILE "hardlink"
#define FISH_GET_FILE "get"
#define FISH_SEND_FILE "send"
#define FISH_APPEND_FILE "append"
#define FISH_INFO_FILE "info"
#define MC_EXTFS_DIR "extfs.d"
#define MC_EXTFS_DIR "extfs.d"
#define MC_BASHRC_FILE "bashrc"
#define MC_CONFIG_FILE "ini"
#define MC_FILEBIND_FILE "bindings"
#define MC_FILEPOS_FILE "filepos"
#define MC_HISTORY_FILE "history"
#define MC_HOTLIST_FILE "hotlist"
#define MC_USERMENU_FILE "menu"
#define MC_TREESTORE_FILE "Tree"
#define MC_PANELS_FILE "panels.ini"
#define MC_FHL_INI_FILE "filehighlight.ini"
#define MC_SKINS_SUBDIR "skins"
#define MC_BASHRC_FILE "bashrc"
#define MC_CONFIG_FILE "ini"
#define MC_FILEBIND_FILE "bindings"
#define MC_FILEPOS_FILE "filepos"
#define MC_HISTORY_FILE "history"
#define MC_HOTLIST_FILE "hotlist"
#define MC_USERMENU_FILE "menu"
#define MC_TREESTORE_FILE "Tree"
#define MC_PANELS_FILE "panels.ini"
#define MC_FHL_INI_FILE "filehighlight.ini"
#define MC_SKINS_SUBDIR "skins"
/* editor home directory */
#define EDIT_DIR MC_USERCONF_DIR PATH_SEP_STR "cedit"
#define EDIT_DIR MC_USERCONF_DIR PATH_SEP_STR "cedit"
/* file names */
#define EDIT_SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
#define EDIT_SYNTAX_FILE EDIT_DIR PATH_SEP_STR "Syntax"
#define EDIT_CLIP_FILE EDIT_DIR PATH_SEP_STR "cooledit.clip"
#define EDIT_MACRO_FILE EDIT_DIR PATH_SEP_STR "cooledit.macros"
#define EDIT_BLOCK_FILE EDIT_DIR PATH_SEP_STR "cooledit.block"
#define EDIT_TEMP_FILE EDIT_DIR PATH_SEP_STR "cooledit.temp"
#define EDIT_GLOBAL_MENU "cedit.menu"
#define EDIT_LOCAL_MENU ".cedit.menu"
#define EDIT_HOME_MENU EDIT_DIR PATH_SEP_STR "menu"
#define EDIT_GLOBAL_MENU "cedit.menu"
#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

View File

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

View File

@ -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
@ -50,10 +50,10 @@
#if ! GLIB_CHECK_VERSION (2, 13, 0)
/*
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.
*/
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)
{

View File

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

View File

@ -1,47 +1,47 @@
/** \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 */
#ifndef O_NONBLOCK
#ifdef O_NDELAY /* SYSV */
#ifdef O_NDELAY /* SYSV */
#define O_NONBLOCK O_NDELAY
#else /* BSD */
#define O_NONBLOCK FNDELAY
@ -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
@ -100,21 +98,19 @@ extern const char *home_dir;
#undef max
#endif
#define min(x, y) ((x) > (y) ? (y) : (x))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) > (y) ? (y) : (x))
#define max(x, y) ((x) > (y) ? (x) : (y))
/* Just for keeping Your's brains from invention a proper size of the buffer :-) */
#define BUF_10K 10240L
#define BUF_8K 8192L
#define BUF_4K 4096L
#define BUF_1K 1024L
#define BUF_10K 10240L
#define BUF_8K 8192L
#define BUF_4K 4096L
#define BUF_1K 1024L
#define BUF_LARGE BUF_1K
#define BUF_MEDIUM 512
#define BUF_SMALL 128
#define BUF_TINY 64
void refresh_screen (void *);
#define BUF_LARGE BUF_1K
#define BUF_MEDIUM 512
#define BUF_SMALL 128
#define BUF_TINY 64
/* AIX compiler doesn't understand '\e' */
#define ESC_CHAR '\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

View File

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

View File

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

View File

@ -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;
static gboolean logging_initialized = FALSE;
static gboolean logging_enabled = FALSE;
if (!logging_initialized) {
logging_enabled = mc_config_get_bool (mc_main_config,
CONFIG_APP_SECTION, "development.enable_logging", FALSE);
logging_initialized = TRUE;
}
return logging_enabled;
if (!logging_initialized)
{
logging_enabled = mc_config_get_bool (mc_main_config,
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;
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) {
f = fopen (logfilename, "a");
if (f != NULL) {
(void)vfprintf(f, fmt, args);
(void)fclose(f);
}
g_free(logfilename);
va_end(args);
}
}
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);
}
g_free (logfilename);
va_end (args);
}
}
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -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 *,
const gchar *, const gchar * const[], gsize);
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: */

View File

@ -44,15 +44,15 @@ mc_config_get_groups (mc_config_t * mc_config, gsize * len)
if (!mc_config)
{
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len=0;
return ret;
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len = 0;
return ret;
}
ret = g_key_file_get_groups (mc_config->handle, len);
if (ret == NULL)
{
ret = g_try_malloc0 (sizeof (gchar **));
ret = g_try_malloc0 (sizeof (gchar **));
}
return ret;
}
@ -66,15 +66,15 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
if (!mc_config || !group)
{
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len=0;
return ret;
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len = 0;
return ret;
}
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
if (ret == NULL)
{
ret = g_try_malloc0 (sizeof (gchar **));
ret = g_try_malloc0 (sizeof (gchar **));
}
return ret;
}
@ -83,26 +83,26 @@ mc_config_get_keys (mc_config_t * mc_config, const gchar * group, gsize * len)
gchar *
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
const gchar * param, const gchar * def)
{
GIConv conv;
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;
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;
mc_config_set_string (mc_config, group, param, def ? def : "");
return def ? g_strdup (def) : NULL;
}
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
if (!ret)
ret = def ? g_strdup (def) : NULL;
ret = def ? g_strdup (def) : NULL;
if (str_isutf8 (_system_codepage))
return ret;
@ -115,38 +115,38 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group,
if (str_convert (conv, ret, buffer) == ESTR_FAILURE)
{
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gchar *
mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
const gchar * param, const gchar * def)
{
gchar *ret;
if (!mc_config || !group || !param)
return def ? g_strdup (def) : NULL;
return def ? g_strdup (def) : NULL;
if (! mc_config_has_param(mc_config, group, param))
if (!mc_config_has_param (mc_config, group, param))
{
mc_config_set_string (mc_config, group, param, def ? def : "");
return def ? g_strdup (def) : NULL;
mc_config_set_string (mc_config, group, param, def ? def : "");
return def ? g_strdup (def) : NULL;
}
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
if (!ret)
ret = def ? g_strdup (def) : NULL;
ret = def ? g_strdup (def) : NULL;
return ret;
}
@ -154,16 +154,15 @@ 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;
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;
mc_config_set_bool (mc_config, group, param, def);
return def;
}
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
@ -172,16 +171,15 @@ mc_config_get_bool (mc_config_t * mc_config, const gchar * group,
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int
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;
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;
mc_config_set_int (mc_config, group, param, def);
return def;
}
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
@ -192,39 +190,36 @@ mc_config_get_int (mc_config_t * mc_config, const gchar * group,
gchar **
mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
gboolean *
mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
int *
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
const gchar * param, gsize * length)
{
if (!mc_config || !group || !param)
return NULL;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@ -72,46 +72,46 @@ mc_config_normalize_before_save(const gchar * value)
void
mc_config_direct_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
const gchar * param, const gchar * value)
{
gchar *buffer;
if (!mc_config || !group || !param || !value)
return;
return;
buffer = mc_config_normalize_before_save(value);
buffer = mc_config_normalize_before_save (value);
g_key_file_set_value (mc_config->handle, group, param, buffer);
g_free(buffer);
g_free (buffer);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * value)
const gchar * param, const gchar * value)
{
gchar *buffer;
if (!mc_config || !group || !param || !value)
return;
return;
buffer = mc_config_normalize_before_save(value);
buffer = mc_config_normalize_before_save (value);
g_key_file_set_string (mc_config->handle, group, param, buffer);
g_free(buffer);
g_free (buffer);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
const gchar * param, gboolean value)
const gchar * param, gboolean value)
{
if (!mc_config || !group || !param )
return;
if (!mc_config || !group || !param)
return;
g_key_file_set_boolean (mc_config->handle, group, param, value);
}
@ -119,11 +119,10 @@ mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
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 )
return;
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;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@ -148,26 +145,24 @@ mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
void
mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gboolean value[], gsize length)
const gchar * param, gboolean value[], gsize length)
{
if (!mc_config || !group || !param || !value || length == 0)
return;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
void
mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, int value[], gsize length)
const gchar * param, int value[], gsize length)
{
if (!mc_config || !group || !param || !value || length == 0)
return;
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);
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

View File

@ -3,12 +3,12 @@
#include <config.h>
#include "lib/global.h" /* <glib.h> */
#include "lib/global.h" /* <glib.h> */
#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);

View File

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

View File

@ -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,14 +268,12 @@ 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 */
if (num != NULL)
*num = (size_t) lc_index;
*num = (size_t) lc_index;
return ret;
}

View File

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

View File

@ -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,11 +305,11 @@ 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)
*num = sizeof (mc_search__list_types) / sizeof (mc_search__list_types[0]) - 1;
*num = sizeof (mc_search__list_types) / sizeof (mc_search__list_types[0]) - 1;
return mc_search__list_types;
}
@ -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;

View File

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

View File

@ -203,7 +203,7 @@ mc_skin_color_cache_init (void)
MARKED_COLOR = mc_skin_color_get ("core", "marked");
SELECTED_COLOR = mc_skin_color_get ("core", "selected");
MARKED_SELECTED_COLOR = mc_skin_color_get ("core", "markselect");
DISABLED_COLOR = mc_skin_color_get ("core", "disabled");
DISABLED_COLOR = mc_skin_color_get ("core", "disabled");
REVERSE_COLOR = mc_skin_color_get ("core", "reverse");
HEADER_COLOR = mc_skin_color_get ("core", "header");
COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark");

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
#include <config.h>
#include "lib/global.h" /* <glib.h> */
#include "lib/global.h" /* <glib.h> */
/*** typedefs(not structures) and defined constants **********************************************/

View File

@ -1,7 +1,7 @@
#ifndef MC_STRUTIL_H
#define MC_STRUTIL_H
#include "lib/global.h" /* include glib.h */
#include "lib/global.h" /* include glib.h */
/* Header file for strutil.c, strutilascii.c, strutil8bit.c, strutilutf8.c.
* There are two sort of functions:
@ -12,7 +12,7 @@
* (implemented separately in strutilascii.c, strutil8bit.c, strutilutf8.c)
* documentation is made for UTF-8 version of functions.
*/
/* invalid strings
* function, that works with invalid strings are marked with "I"
* in documentation
@ -20,7 +20,7 @@
* are displayed as questionmarks, I-maked comparing functions try to keep
* the original value of these bytes.
*/
/* combining characters
* displaynig: all handled as zero with characters, expect combing character
* at the begin of string, this character has with one (space add before),
@ -36,43 +36,107 @@
* 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
* replaced with questionmark). So is impossible convert string back.
*/
/* 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
* of input string)
*/
/* failure means, that conversion is not possible (example: wrong encoding
* of input string)
*/
ESTR_FAILURE = 2
} estr_t;
/* alignment strings on terminal
*/
typedef enum {
J_LEFT = 0x01,
J_RIGHT = 0x02,
J_CENTER = 0x03,
typedef enum
{
J_LEFT = 0x01,
J_RIGHT = 0x02,
J_CENTER = 0x03,
/* if there is enough space for string on terminal,
* string is centered otherwise is aligned to left */
J_CENTER_LEFT = 0x04,
J_CENTER_LEFT = 0x04,
/* fit alignment, if string is to long, is truncated with '~' */
J_LEFT_FIT = 0x11,
J_RIGHT_FIT = 0x12,
J_CENTER_FIT = 0x13,
J_CENTER_LEFT_FIT = 0x14
J_LEFT_FIT = 0x11,
J_RIGHT_FIT = 0x12,
J_CENTER_FIT = 0x13,
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);
@ -159,7 +172,7 @@ void str_close_conv (GIConv);
/* convert string using coder, result of conversion is appended at end of buffer
* return ESTR_SUCCESS if there was no problem.
* otherwise return ESTR_PROBLEM or ESTR_FAILURE
*/
*/
estr_t str_convert (GIConv, const char *, GString *);
estr_t str_nconvert (GIConv, const char *, int, GString *);
@ -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
*/
@ -209,8 +221,8 @@ void str_uninit_strings (void);
* ESTR_PROBLEM if ch contains only part of characters,
* ESTR_FAILURE if conversion is not possible
*/
estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
char *output, size_t out_size);
estr_t str_translate_char (GIConv conv, const char *ch, size_t ch_size,
char *output, size_t out_size);
/* test, if text is valid in terminal encoding
* I
@ -223,7 +235,7 @@ int str_is_valid_string (const char *text);
* multibyte character
* I
*/
int str_is_valid_char (const char *ch, size_t size);
int str_is_valid_char (const char *ch, size_t size);
/* return next characters after text, do not call on the end of string
*/
@ -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 '.'
@ -364,7 +376,7 @@ void str_fix_string (char* text);
* returned string do not need to be freed
* I
*/
const char *str_term_form (const char *text);
const char *str_term_form (const char *text);
/* like str_term_form, but text can be alignment to width
* alignment is specified in just_mode (J_LEFT, J_LEFT_FIT, ...)
@ -389,7 +401,7 @@ void str_msg_term_size (const char *text, int *lines, int *columns);
* start - column (position) on terminal, where substring begin
* result is completed with spaces to width
* I
*/
*/
const char *str_term_substring (const char *text, int start, int width);
/* return width, that will be text occupied on terminal
@ -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 */

View File

@ -35,12 +35,12 @@
/*names, that are used for utf-8 */
static const char *str_utf8_encodings[] = {
"utf-8",
"utf8",
NULL
"utf-8",
"utf8",
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,28 +79,27 @@ 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
str_crt_conv_from (const char *from_enc)
{
return (!str_test_not_convert (from_enc))
? g_iconv_open (codeset, from_enc) : str_cnv_not_convert;
? g_iconv_open (codeset, from_enc) : str_cnv_not_convert;
}
void
str_close_conv (GIConv conv)
{
if (conv != str_cnv_not_convert)
g_iconv_close (conv);
g_iconv_close (conv);
}
static estr_t
_str_convert (GIConv coder, const char *string, int size, GString * buffer)
{
estr_t state = ESTR_SUCCESS;
estr_t state = ESTR_SUCCESS;
gchar *tmp_buff = NULL;
gssize left;
gsize bytes_read = 0;
@ -109,26 +108,26 @@ _str_convert (GIConv coder, const char *string, int size, GString * buffer)
errno = 0;
if (coder == INVALID_CONV)
return ESTR_FAILURE;
return ESTR_FAILURE;
if (string == NULL || buffer == NULL)
return ESTR_FAILURE;
return ESTR_FAILURE;
/*
if (! used_class.is_valid_string (string))
{
return ESTR_FAILURE;
}
*/
/*
if (! used_class.is_valid_string (string))
{
return ESTR_FAILURE;
}
*/
if (size < 0)
{
size = strlen (string);
size = strlen (string);
}
else
{
left = strlen (string);
if (left < size)
size = left;
left = strlen (string);
if (left < size)
size = left;
}
left = size;
@ -136,100 +135,96 @@ _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);
if (error)
{
int code = error->code;
tmp_buff = g_convert_with_iconv ((const gchar *) string,
left, coder, &bytes_read, &bytes_written, &error);
if (error)
{
int code = error->code;
g_error_free (error);
error = NULL;
g_error_free (error);
error = NULL;
switch (code)
{
case G_CONVERT_ERROR_NO_CONVERSION:
/* Conversion between the requested character sets is not supported. */
tmp_buff = g_strnfill (strlen (string), '?');
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
return ESTR_FAILURE;
switch (code)
{
case G_CONVERT_ERROR_NO_CONVERSION:
/* Conversion between the requested character sets is not supported. */
tmp_buff = g_strnfill (strlen (string), '?');
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
return ESTR_FAILURE;
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
/* Invalid byte sequence in conversion input. */
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);
case G_CONVERT_ERROR_ILLEGAL_SEQUENCE:
/* Invalid byte sequence in conversion input. */
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);
if (tmp_buff != NULL)
{
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
}
if (tmp_buff != NULL)
{
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
}
if ((int)bytes_read < left)
{
string += bytes_read + 1;
size -= (bytes_read + 1);
left -= (bytes_read + 1);
g_string_append_c (buffer, *(string-1));
}
else
{
return ESTR_PROBLEM;
}
state = ESTR_PROBLEM;
break;
if ((int) bytes_read < left)
{
string += bytes_read + 1;
size -= (bytes_read + 1);
left -= (bytes_read + 1);
g_string_append_c (buffer, *(string - 1));
}
else
{
return ESTR_PROBLEM;
}
state = ESTR_PROBLEM;
break;
case G_CONVERT_ERROR_PARTIAL_INPUT:
/* Partial character sequence at end of input. */
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
if ((int)bytes_read < left)
{
left = left - bytes_read;
tmp_buff = g_strnfill (left, '?');
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
}
return ESTR_PROBLEM;
case G_CONVERT_ERROR_PARTIAL_INPUT:
/* Partial character sequence at end of input. */
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
if ((int) bytes_read < left)
{
left = left - bytes_read;
tmp_buff = g_strnfill (left, '?');
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
}
return ESTR_PROBLEM;
case G_CONVERT_ERROR_BAD_URI: /* Don't know how handle this error :( */
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
default:
g_free (tmp_buff);
return ESTR_FAILURE;
}
}
else
{
if (tmp_buff != NULL)
{
if (*tmp_buff)
{
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
string += bytes_read;
left -= bytes_read;
}
else
{
g_free (tmp_buff);
g_string_append (buffer, string);
return state;
}
}
else
{
g_string_append (buffer, string);
return ESTR_PROBLEM;
}
}
case G_CONVERT_ERROR_BAD_URI: /* Don't know how handle this error :( */
case G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: /* Don't know how handle this error :( */
case G_CONVERT_ERROR_FAILED: /* Conversion failed for some reason. */
default:
g_free (tmp_buff);
return ESTR_FAILURE;
}
}
else
{
if (tmp_buff != NULL)
{
if (*tmp_buff)
{
g_string_append (buffer, tmp_buff);
g_free (tmp_buff);
string += bytes_read;
left -= bytes_read;
}
else
{
g_free (tmp_buff);
g_string_append (buffer, string);
return state;
}
}
else
{
g_string_append (buffer, string);
return ESTR_PROBLEM;
}
}
}
return state;
}
@ -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);
}
@ -259,18 +254,17 @@ str_vfs_convert_from (GIConv coder, const char *string, GString * buffer)
if (coder == str_cnv_not_convert)
{
g_string_append (buffer, string != NULL ? string : "");
result = ESTR_SUCCESS;
g_string_append (buffer, string != NULL ? string : "");
result = ESTR_SUCCESS;
}
else
result = _str_convert (coder, string, -1, buffer);
result = _str_convert (coder, string, -1, buffer);
return result;
}
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);
}
@ -284,10 +278,10 @@ str_printf (GString * buffer, const char *format, ...)
g_string_append_vprintf (buffer, format, ap);
#else
{
gchar *tmp;
tmp = g_strdup_vprintf (format, ap);
g_string_append (buffer, tmp);
g_free(tmp);
gchar *tmp;
tmp = g_strdup_vprintf (format, ap);
g_string_append (buffer, 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;
}
@ -347,15 +342,15 @@ str_choose_str_functions ()
{
if (str_test_encoding_class (codeset, str_utf8_encodings))
{
used_class = str_utf8_init ();
used_class = str_utf8_init ();
}
else if (str_test_encoding_class (codeset, str_8bit_encodings))
{
used_class = str_8bit_init ();
used_class = str_8bit_init ();
}
else
{
used_class = str_ascii_init ();
used_class = str_ascii_init ();
}
}
@ -365,7 +360,7 @@ str_isutf8 (const char *codeset_name)
int result = 0;
if (str_test_encoding_class (codeset_name, str_utf8_encodings))
{
result = 1;
result = 1;
}
return result;
}
@ -373,26 +368,24 @@ 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)
{
if (termenc != NULL)
{
g_free (codeset);
codeset = g_strdup (str_detect_termencoding ());
str_cnv_not_convert = g_iconv_open (codeset, codeset);
}
if (termenc != NULL)
{
g_free (codeset);
codeset = g_strdup (str_detect_termencoding ());
str_cnv_not_convert = g_iconv_open (codeset, codeset);
}
if (str_cnv_not_convert == INVALID_CONV)
{
g_free (codeset);
codeset = g_strdup ("ascii");
str_cnv_not_convert = g_iconv_open (codeset, codeset);
}
if (str_cnv_not_convert == INVALID_CONV)
{
g_free (codeset);
codeset = g_strdup ("ascii");
str_cnv_not_convert = g_iconv_open (codeset, codeset);
}
}
str_cnv_to_term = str_cnv_not_convert;
@ -405,7 +398,7 @@ void
str_uninit_strings (void)
{
if (str_cnv_not_convert != INVALID_CONV)
g_iconv_close (str_cnv_not_convert);
g_iconv_close (str_cnv_not_convert);
g_free (codeset);
}
@ -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

View File

@ -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);
}
@ -106,11 +103,11 @@ str_8bit_cnext_noncomb_char (const char **text)
{
if (*text[0] != '\0')
{
(*text)++;
return 1;
(*text)++;
return 1;
}
else
return 0;
return 0;
}
static int
@ -118,11 +115,11 @@ str_8bit_cprev_noncomb_char (const char **text, const char *begin)
{
if ((*text) != begin)
{
(*text)--;
return 1;
(*text)--;
return 1;
}
else
return 0;
return 0;
}
static int
@ -166,7 +163,7 @@ static int
str_8bit_toupper (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return 0;
(*out)[0] = char_toupper (text[0]);
(*out)++;
(*remain)--;
@ -177,7 +174,7 @@ static int
str_8bit_tolower (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return 0;
(*out)[0] = char_tolower (text[0]);
(*out)++;
(*remain)--;
@ -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,18 +228,17 @@ 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;
if (coder == str_cnv_not_convert)
{
g_string_append_len (buffer, string, size);
result = ESTR_SUCCESS;
g_string_append_len (buffer, string, size);
result = ESTR_SUCCESS;
}
else
result = str_nconvert (coder, (char *) string, size, buffer);
result = str_nconvert (coder, (char *) string, size, buffer);
return result;
}
@ -259,7 +259,7 @@ str_8bit_term_form (const char *text)
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
actual[0] = '\0';
@ -280,85 +280,83 @@ 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))
{
case J_CENTER_LEFT:
case J_CENTER:
ident = (width - length) / 2;
break;
case J_RIGHT:
ident = width - length;
break;
}
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER_LEFT:
case J_CENTER:
ident = (width - length) / 2;
break;
case J_RIGHT:
ident = width - length;
break;
}
if ((int)remain <= ident)
goto finally;
memset (actual, ' ', ident);
actual += ident;
remain -= ident;
if ((int) remain <= ident)
goto finally;
memset (actual, ' ', ident);
actual += ident;
remain -= ident;
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
if (width - length - ident > 0)
{
if (remain <= width - length - ident)
goto finally;
memset (actual, ' ', width - length - ident);
actual += width - length - ident;
remain -= width - length - ident;
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
if (width - length - ident > 0)
{
if (remain <= width - length - ident)
goto finally;
memset (actual, ' ', width - length - ident);
actual += width - length - ident;
remain -= width - length - ident;
}
}
else
{
if (IS_FIT (just_mode))
{
for (; pos + 1 <= (gsize)width / 2 && remain > 1;
actual++, pos++, remain--)
{
if (IS_FIT (just_mode))
{
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
pos += length - width + 1;
pos += length - width + 1;
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
else
{
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER:
ident = (length - width) / 2;
break;
case J_RIGHT:
ident = length - width;
break;
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
else
{
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER:
ident = (length - width) / 2;
break;
case J_RIGHT:
ident = length - width;
break;
}
pos += ident;
for (; pos < (gsize)(ident + width) && remain > 1;
pos++, actual++, remain--)
{
pos += ident;
for (; pos < (gsize) (ident + width) && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
}
}
finally:
actual[0] = '\0';
@ -378,34 +376,34 @@ 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)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
if (width <= 3)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
pos += length - width + 3;
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
}
else
{
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
actual[0] = '\0';
@ -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,26 +440,26 @@ 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 (;;)
{
q = strchr (p, '\n');
if (q != NULL)
{
c = q[0];
q[0] = '\0';
}
q = strchr (p, '\n');
if (q != NULL)
{
c = q[0];
q[0] = '\0';
}
width = str_8bit_term_width1 (p);
if (width > (*columns))
(*columns) = width;
width = str_8bit_term_width1 (p);
if (width > (*columns))
(*columns) = width;
if (q == NULL)
break;
q[0] = c;
p = q + 1;
(*lines)++;
if (q == NULL)
break;
q[0] = c;
p = q + 1;
(*lines)++;
}
g_free (tmp);
}
@ -480,20 +477,19 @@ 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--)
{
pos += start;
for (; pos < length && width > 0 && remain > 1; pos++, width--, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
for (; width > 0 && remain > 1; actual++, remain--, width--)
{
actual[0] = ' ';
actual[0] = ' ';
}
actual[0] = '\0';
@ -513,32 +509,32 @@ 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--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
for (; pos + 1 <= (gsize) width / 2 && remain > 1; actual++, pos++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
pos += length - width + 1;
pos += length - width + 1;
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
else
{
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
for (; pos < length && remain > 1; pos++, actual++, remain--)
{
actual[0] = char_isprint (text[pos]) ? text[pos] : '.';
}
}
finally:
@ -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 *
@ -604,14 +600,14 @@ str_8bit_search_first (const char *text, const char *search, int case_sen)
match = g_strstr_len (fold_text, -1, fold_search);
if (match != NULL)
{
offsset = match - fold_text;
match = text + offsset;
offsset = match - fold_text;
match = text + offsset;
}
if (!case_sen)
{
g_free (fold_text);
g_free (fold_search);
g_free (fold_text);
g_free (fold_search);
}
return match;
@ -631,14 +627,14 @@ str_8bit_search_last (const char *text, const char *search, int case_sen)
match = g_strrstr_len (fold_text, -1, fold_search);
if (match != NULL)
{
offsset = match - fold_text;
match = text + offsset;
offsset = match - fold_text;
match = text + offsset;
}
if (!case_sen)
{
g_free (fold_text);
g_free (fold_search);
g_free (fold_text);
g_free (fold_search);
}
return match;
@ -677,15 +673,15 @@ str_8bit_casecmp (const char *s1, const char *s2)
/* According to A. Cox, some platforms have islower's that
* 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
@ -732,7 +728,7 @@ str_8bit_prefix (const char *text, const char *prefix)
{
int result;
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
&& text[result] == prefix[result]; result++);
&& text[result] == prefix[result]; result++);
return result;
}
@ -741,7 +737,7 @@ str_8bit_caseprefix (const char *text, const char *prefix)
{
int result;
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
&& char_toupper (text[result]) == char_toupper (prefix[result]); result++);
&& char_toupper (text[result]) == char_toupper (prefix[result]); result++);
return result;
}
@ -763,16 +759,16 @@ static int
str_8bit_key_collate (const char *t1, const char *t2, int case_sen)
{
if (case_sen)
return strcmp (t1, t2);
return strcmp (t1, t2);
else
return strcoll (t1, t2);
return strcoll (t1, t2);
}
static void
str_8bit_release_key (char *key, int case_sen)
{
if (!case_sen)
g_free (key);
g_free (key);
}
struct str_class

View File

@ -74,11 +74,11 @@ str_ascii_cnext_noncomb_char (const char **text)
{
if (*text[0] != '\0')
{
(*text)++;
return 1;
(*text)++;
return 1;
}
else
return 0;
return 0;
}
static int
@ -86,11 +86,11 @@ str_ascii_cprev_noncomb_char (const char **text, const char *begin)
{
if ((*text) != begin)
{
(*text)--;
return 1;
(*text)--;
return 1;
}
else
return 0;
return 0;
}
static int
@ -134,7 +134,7 @@ static int
str_ascii_toupper (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return 0;
(*out)[0] = (char) g_ascii_toupper ((gchar) text[0]);
(*out)++;
(*remain)--;
@ -145,7 +145,7 @@ static int
str_ascii_tolower (const char *text, char **out, size_t * remain)
{
if (*remain <= 1)
return 0;
return 0;
(*out)[0] = (char) g_ascii_tolower ((gchar) text[0]);
(*out)++;
(*remain)--;
@ -165,18 +165,17 @@ 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))
return g_strdup (error->message);
return g_strdup (error->message);
return g_strdup (def_msg != NULL ? 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);
@ -200,8 +199,8 @@ str_ascii_term_form (const char *text)
/* go throw all characters and check, if they are ascii and printable */
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] : '.';
}
actual[0] = '\0';
@ -222,101 +221,93 @@ 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))
{
case J_CENTER_LEFT:
case J_CENTER:
ident = (width - length) / 2;
break;
case J_RIGHT:
ident = width - length;
break;
}
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER_LEFT:
case J_CENTER:
ident = (width - length) / 2;
break;
case J_RIGHT:
ident = width - length;
break;
}
/* add space before text */
if ((int)remain <= ident)
goto finally;
memset (actual, ' ', ident);
actual += ident;
remain -= ident;
/* add space before text */
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--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
/* copy all characters */
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] : '.';
}
/* add space after text */
if (width - length - ident > 0)
{
if (remain <= width - length - ident)
goto finally;
memset (actual, ' ', width - length - ident);
actual += width - length - ident;
remain -= width - length - ident;
}
/* add space after text */
if (width - length - ident > 0)
{
if (remain <= width - length - ident)
goto finally;
memset (actual, ' ', width - length - ident);
actual += width - length - ident;
remain -= width - length - ident;
}
}
else
{
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--)
{
actual[0] = isascii ((unsigned char) text[pos])
? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0])
? actual[0] : '.';
}
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--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
pos += length - width + 1;
pos += length - width + 1;
/* 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] : '.';
}
}
else
{
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER:
ident = (length - width) / 2;
break;
case J_RIGHT:
ident = length - width;
break;
}
/* 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] : '.';
}
}
else
{
ident = 0;
switch (HIDE_FIT (just_mode))
{
case J_CENTER:
ident = (length - width) / 2;
break;
case J_RIGHT:
ident = length - width;
break;
}
/* 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--)
{
actual[0] = isascii ((unsigned char) text[pos])
? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0])
? actual[0] : '.';
}
/* 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--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
}
}
}
finally:
actual[0] = '\0';
@ -336,40 +327,38 @@ 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)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
if (width <= 3)
{
memset (actual, '.', width);
actual += width;
remain -= width;
}
else
{
memset (actual, '.', 3);
actual += 3;
remain -= 3;
pos += length - width + 3;
pos += length - width + 3;
/* 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] : '.';
}
}
/* 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] : '.';
}
}
}
else
{
/* copy all characters */
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] : '.';
}
/* copy all characters */
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] = '\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
@ -412,22 +400,22 @@ str_ascii_msg_term_size (const char *text, int *lines, int *columns)
for (;;)
{
q = strchr (p, '\n');
if (q != NULL)
{
c = q[0];
q[0] = '\0';
}
q = strchr (p, '\n');
if (q != NULL)
{
c = q[0];
q[0] = '\0';
}
width = str_ascii_term_width1 (p);
if (width > (*columns))
(*columns) = width;
width = str_ascii_term_width1 (p);
if (width > (*columns))
(*columns) = width;
if (q == NULL)
break;
q[0] = c;
p = q + 1;
(*lines)++;
if (q == NULL)
break;
q[0] = c;
p = q + 1;
(*lines)++;
}
g_free (tmp);
}
@ -445,23 +433,22 @@ 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--)
{
pos += start;
/* copy at most width characters from text from start */
for (; pos < length && width > 0 && remain > 1; pos++, width--, 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] : '.';
}
}
/* if text is shorter then width, add space to the end */
for (; width > 0 && remain > 1; actual++, remain--, width--)
{
actual[0] = ' ';
actual[0] = ' ';
}
actual[0] = '\0';
@ -481,38 +468,38 @@ 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--)
{
actual[0] = isascii ((unsigned char) text[pos]) ? text[pos] : '?';
actual[0] = g_ascii_isprint ((gchar) actual[0]) ? actual[0] : '.';
}
/* copy prefix of text */
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] : '.';
}
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
if (remain <= 1)
goto finally;
actual[0] = '~';
actual++;
remain--;
pos += length - width + 1;
pos += length - width + 1;
/* 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] : '.';
}
/* 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] : '.';
}
}
else
{
/* copy all characters */
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] : '.';
}
/* copy all characters */
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] : '.';
}
}
finally:
@ -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 *
@ -563,14 +550,14 @@ str_ascii_search_first (const char *text, const char *search, int case_sen)
match = g_strstr_len (fold_text, -1, fold_search);
if (match != NULL)
{
offset = match - fold_text;
match = text + offset;
offset = match - fold_text;
match = text + offset;
}
if (!case_sen)
{
g_free (fold_text);
g_free (fold_search);
g_free (fold_text);
g_free (fold_search);
}
return match;
@ -590,14 +577,14 @@ str_ascii_search_last (const char *text, const char *search, int case_sen)
match = g_strrstr_len (fold_text, -1, fold_search);
if (match != NULL)
{
offset = match - fold_text;
match = text + offset;
offset = match - fold_text;
match = text + offset;
}
if (!case_sen)
{
g_free (fold_text);
g_free (fold_search);
g_free (fold_text);
g_free (fold_search);
}
return match;
@ -632,7 +619,7 @@ str_ascii_fix_string (char *text)
{
for (; text[0] != '\0'; text++)
{
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
text[0] = ((unsigned char) text[0] < 128) ? text[0] : '?';
}
}
@ -661,7 +648,7 @@ str_ascii_prefix (const char *text, const char *prefix)
{
int result;
for (result = 0; text[result] != '\0' && prefix[result] != '\0'
&& text[result] == prefix[result]; result++);
&& text[result] == prefix[result]; result++);
return result;
}
@ -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;
}

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@
#include "lib/strutil.h"
/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
fractionnal parts, S_Z: idem but with leading Zeroes only */
fractionnal parts, S_Z: idem but with leading Zeroes only */
#define S_N 0x0
#define S_I 0x4
#define S_F 0x8
@ -40,78 +40,77 @@
/* 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;
unsigned char c1, c2;
int state;
int diff;
unsigned char *p1 = (unsigned char *) s1;
unsigned char *p2 = (unsigned char *) s2;
unsigned char c1, c2;
int state;
int diff;
/* Symbol(s) 0 [1-9] others (padding)
Transition (10) 0 (01) d (00) x (11) - */
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,
/* S_F */ S_N, S_F, S_F, S_F,
/* S_Z */ S_N, S_F, S_Z, S_Z
};
/* Symbol(s) 0 [1-9] others (padding)
Transition (10) 0 (01) d (00) x (11) - */
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,
/* S_F */ S_N, S_F, S_F, S_F,
/* S_Z */ S_N, S_F, S_Z, S_Z
};
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 -/- */
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 -/- */
/* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
/* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
+1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
/* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
/* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
-1, CMP, CMP, CMP
};
/* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
/* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP,
+1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
/* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
/* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP,
-1, CMP, CMP, CMP
};
if (p1 == p2)
return 0;
if (p1 == p2)
return 0;
c1 = *p1++;
c2 = *p2++;
/* Hint: '0' is a digit too. */
state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
c1 = *p1++;
c2 = *p2++;
/* Hint: '0' is a digit too. */
state = S_N | ((c1 == '0') + (isdigit (c1) != 0));
while ((diff = c1 - c2) == 0 && c1 != '\0')
while ((diff = c1 - c2) == 0 && c1 != '\0')
{
state = next_state[state];
c1 = *p1++;
c2 = *p2++;
state |= (c1 == '0') + (isdigit (c1) != 0);
state = next_state[state];
c1 = *p1++;
c2 = *p2++;
state |= (c1 == '0') + (isdigit (c1) != 0);
}
state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))];
state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))];
switch (state)
{
switch (state)
{
case CMP:
return diff;
return diff;
case LEN:
while (isdigit (*p1++))
if (!isdigit (*p2++))
return 1;
while (isdigit (*p1++))
if (!isdigit (*p2++))
return 1;
return isdigit (*p2) ? -1 : diff;
return isdigit (*p2) ? -1 : diff;
default:
return state;
}
return state;
}
#endif /* HAVE_STRVERSCMP */
}

View File

@ -3,35 +3,48 @@
* \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>
#define INVALID_TIME_TEXT "(invalid)"
/*** typedefs(not structures) and defined constants **********************************************/
#define INVALID_TIME_TEXT "(invalid)"
/* safe localtime formatting - strftime()-using version */
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
{ \
struct tm *whentm; \
whentm = localtime(&when); \
if (whentm == NULL) \
{ \
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
buffer[bufsize-1] = 0; \
} \
else \
{ \
strftime(buffer, bufsize, fmt, whentm); \
} \
} \
#define FMT_LOCALTIME(buffer, bufsize, fmt, when) \
{ \
struct tm *whentm; \
whentm = localtime(&when); \
if (whentm == NULL) \
{ \
strncpy(buffer, INVALID_TIME_TEXT, bufsize); \
buffer[bufsize-1] = 0; \
} \
else \
{ \
strftime(buffer, bufsize, fmt, whentm); \
} \
} \
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
{ \
time_t __current_time; \
time(&__current_time); \
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
#define FMT_LOCALTIME_CURRENT(buffer, bufsize, fmt) \
{ \
time_t __current_time; \
time(&__current_time); \
FMT_LOCALTIME(buffer,bufsize,fmt,__current_time); \
}
#endif /* !__UTIL_H */
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
/*** inline functions ****************************************************************************/
#endif /* !__UTIL_H */

View File

@ -1,11 +1,11 @@
/* Internal stuff of color setup
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@ -28,7 +28,7 @@
#include <string.h> /* strcmp */
#include "color.h" /* colors and attributes */
#include "color.h" /* colors and attributes */
#include "color-internal.h"
/*** global variables ****************************************************************************/
@ -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 ************************************************************************/

View File

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

View File

@ -1,10 +1,10 @@
/* Color setup for NCurses screen library
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@ -33,7 +33,7 @@
#include "lib/global.h"
#include "tty-ncurses.h"
#include "color.h" /* variables */
#include "color.h" /* variables */
#include "color-internal.h"
/*** global variables ****************************************************************************/
@ -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;
}
@ -88,7 +89,7 @@ color_get_attr (int color_pair)
int *fnd = NULL;
if (mc_tty_color_color_pair_attrs != NULL)
fnd = (int *) g_hash_table_lookup (mc_tty_color_color_pair_attrs, (gpointer) & color_pair);
fnd = (int *) g_hash_table_lookup (mc_tty_color_color_pair_attrs, (gpointer) & color_pair);
return (fnd != NULL) ? *fnd : 0;
}
@ -100,10 +101,10 @@ mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
{
if (has_colors () && !mc_tty_color_disable)
init_pair (mc_color_pair->pair_index,
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg1 | mask), bg1);
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg1 | mask), bg1);
else
init_pair (mc_color_pair->pair_index,
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg2 | mask), bg2);
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg2 | mask), bg2);
}
/* --------------------------------------------------------------------------------------------- */
@ -115,7 +116,8 @@ tty_color_init_lib (gboolean disable, gboolean force)
{
(void) force;
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;

View File

@ -1,10 +1,10 @@
/* Color setup for S_Lang screen library
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@ -33,10 +33,21 @@
#include "lib/global.h"
#include "tty-slang.h"
#include "color.h" /* variables */
#include "color.h" /* variables */
#include "color-internal.h"
#include "src/setup.h" /* color_terminal_string */
#include "src/setup.h" /* color_terminal_string */
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static int
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 ();
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -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 "lib/global.h" /* <glib.h> */
#include "tty.h" /* KEY_F macro */
#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 */

View File

@ -5,12 +5,12 @@
Copyright (C) 1998, 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
Written by: 1998, Gyorgy Tamasi
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -44,7 +44,7 @@
#include "lib/global.h"
#include "tty.h"
#include "mouse.h" /* required before key.h */
#include "mouse.h" /* required before key.h */
#include "key.h"
#if defined (__QNX__) && !defined (__QNXNTO__)
@ -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
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1,15 +1,15 @@
/* Mouse managing
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006,
2007, 2009 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -34,13 +34,28 @@
#include "lib/global.h"
#include "tty.h"
#include "tty-internal.h" /* mouse_enabled */
#include "tty-internal.h" /* mouse_enabled */
#include "mouse.h"
#include "key.h" /* define sequence */
#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,31 +93,35 @@ 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:
{
int mouse_d;
Gpm_Connect conn;
{
int mouse_d;
Gpm_Connect conn;
conn.eventMask = ~GPM_MOVE;
conn.defaultMask = GPM_MOVE;
conn.minMod = 0;
conn.maxMod = 0;
conn.eventMask = ~GPM_MOVE;
conn.defaultMask = GPM_MOVE;
conn.minMod = 0;
conn.maxMod = 0;
mouse_d = Gpm_Open (&conn, 0);
if (mouse_d == -1) {
use_mouse_p = MOUSE_NONE;
return;
mouse_d = Gpm_Open (&conn, 0);
if (mouse_d == -1)
{
use_mouse_p = MOUSE_NONE;
return;
}
mouse_enabled = 1;
}
mouse_enabled = 1;
}
break;
#endif /* HAVE_LIBGPM */
@ -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;
}
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -5,33 +5,53 @@
* 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 */
#define GPM_B_LEFT (1 << 2)
#define GPM_B_LEFT (1 << 2)
#define GPM_B_MIDDLE (1 << 1)
#define GPM_B_RIGHT (1 << 0)
#define GPM_BARE_EVENTS(ev) ((ev)&0xF)
#endif /* !HAVE_LIBGPM */
/* Mouse wheel events */
#ifndef GPM_B_DOWN
#define GPM_B_DOWN (1 << 5)
#endif
#ifndef GPM_B_UP
#define GPM_B_UP (1 << 4)
#endif
/* Mouse callback */
typedef int (*mouse_h) (Gpm_Event *, void *);
/*** enums ***************************************************************************************/
#ifndef HAVE_LIBGPM
/* Xterm mouse support supports only GPM_DOWN and GPM_UP */
/* If you use others make sure your code also works without them */
enum Gpm_Etype {
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,
@ -41,24 +61,15 @@ enum Gpm_Etype {
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 *);
enum
{ MOU_NORMAL, MOU_REPEAT };
/* Type of mouse support */
typedef enum {
typedef enum
{
MOUSE_NONE, /* Not detected yet */
MOUSE_DISABLED, /* Explicitly disabled by -d */
MOUSE_GPM, /* Support using GPM on Linux */
@ -67,25 +78,34 @@ typedef enum {
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);
/* Mouse wheel events */
#ifndef GPM_B_DOWN
#define GPM_B_DOWN (1 << 5)
#endif
#ifndef GPM_B_UP
#define GPM_B_UP (1 << 4)
#endif
void show_mouse_pointer (int x, int y);
/*** inline functions ****************************************************************************/
#endif /* MC_MOUSE_H */

View File

@ -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> */
#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
#ifdef ultrix /* Ultrix gets _POSIX_VDISABLE wrong! */
#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 */

View File

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

View File

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

View File

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

View File

@ -1,33 +1,46 @@
#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 {
/*** typedefs(not structures) and defined constants **********************************************/
#define KEY_F(x) (1000 + x)
#define ACS_VLINE SLSMG_VLINE_CHAR
#define ACS_HLINE SLSMG_HLINE_CHAR
#define ACS_LTEE SLSMG_LTEE_CHAR
#define ACS_RTEE SLSMG_RTEE_CHAR
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
#define ACS_URCORNER SLSMG_URCORN_CHAR
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
#define ACS_PLUS SLSMG_PLUS_CHAR
#define COLS SLtt_Screen_Cols
#define LINES SLtt_Screen_Rows
/*** enums ***************************************************************************************/
enum
{
KEY_BACKSPACE = 400,
KEY_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
};
#define KEY_F(x) (1000 + x)
/*** structures declarations (and typedefs of structures)*****************************************/
#define ACS_VLINE SLSMG_VLINE_CHAR
#define ACS_HLINE SLSMG_HLINE_CHAR
#define ACS_LTEE SLSMG_LTEE_CHAR
#define ACS_RTEE SLSMG_RTEE_CHAR
#define ACS_ULCORNER SLSMG_ULCORN_CHAR
#define ACS_LLCORNER SLSMG_LLCORN_CHAR
#define ACS_URCORNER SLSMG_URCORN_CHAR
#define ACS_LRCORNER SLSMG_LRCORN_CHAR
#define ACS_PLUS SLSMG_PLUS_CHAR
/*** global variables defined in .c file *********************************************************/
#define COLS SLtt_Screen_Cols
#define LINES SLtt_Screen_Rows
/*** declarations of public functions ************************************************************/
/*** inline functions ****************************************************************************/
#endif /* MC_TTY_SLANG_H */

View File

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

View File

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

View File

@ -1,10 +1,10 @@
/* Terminal management xterm and rxvt support
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2009 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
@ -33,11 +33,11 @@
#include <unistd.h>
#include "lib/global.h"
#include "tty.h" /* tty_gotoyx, tty_print_char */
#include "tty.h" /* tty_gotoyx, tty_print_char */
#include "win.h"
#include "src/consaver/cons.saver.h" /* console_flag */
#include "src/consaver/cons.saver.h" /* console_flag */
/*** global variables **************************************************/
/*** global variables ****************************************************************************/
/* This flag is set by xterm detection routine in function main() */
/* 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;
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -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 ****************************************************************************/
/*** 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 **********************************************/
/*** 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 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
#define func_XOpenDisplay XOpenDisplay
#define func_XCloseDisplay XCloseDisplay
#define func_XSetErrorHandler XSetErrorHandler
#define func_XSetIOErrorHandler XSetIOErrorHandler
#define func_XQueryPointer XQueryPointer
#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 */

View File

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

View File

@ -1,4 +1,3 @@
/** \file unixcompat.h
* \brief Header: collects differences between the various Unix
*
@ -12,29 +11,43 @@
#ifndef MC_UNIXCOMPAT_H
#define MC_UNIXCOMPAT_H
#include <sys/types.h> /* BSD */
#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

View File

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

View File

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

View File

@ -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)
{
@ -662,7 +699,7 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
s[0] = 0;
#if HAVE_CHARSET
else if ((strncmp (s, VFS_ENCODING_PREFIX, enc_prefix_len) == 0)
&& (is_supported_encoding (s + enc_prefix_len)))
&& (is_supported_encoding (s + enc_prefix_len)))
{
/* special case: remove encoding */
s[0] = '.';
@ -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;
}
/* --------------------------------------------------------------------------------------------- */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -6,9 +6,9 @@
Written by: 1998 Pavel Machek
Spaces fix: 2000 Michal Svec
2010 Andrew Borodin
2010 Slava Zanko
2010 Ilia Maslakov
2010 Andrew Borodin
2010 Slava Zanko
2010 Ilia Maslakov
Derived from ftpfs.c.
@ -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,19 +1216,23 @@ 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)
{
gchar *shell_commands = NULL;
PREFIX
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
SUP.scr_chmod, (char *) NULL);
shell_commands = g_strconcat (SUP.scr_env, "FISH_FILENAME=%s FISH_FILEMODE=%4.4o;\n",
SUP.scr_chmod, (char *) NULL);
g_snprintf (buf, sizeof (buf), shell_commands, rpath, mode & 07777);
g_free (shell_commands);
g_free (rpath);
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)
{
@ -1190,9 +1254,9 @@ fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
gchar *shell_commands = NULL;
PREFIX
shell_commands = g_strconcat (SUP.scr_env,
"FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n",
SUP.scr_chown, (char *) NULL);
shell_commands = g_strconcat (SUP.scr_env,
"FISH_FILENAME=%s FISH_FILEOWNER=%s FISH_FILEGROUP=%s;\n",
SUP.scr_chown, (char *) NULL);
g_snprintf (buf, sizeof (buf), shell_commands, rpath, sowner, sgroup);
g_free (shell_commands);
fish_send_command (me, super, buf, OPT_FLUSH);
@ -1203,12 +1267,14 @@ fish_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
}
}
/* --------------------------------------------------------------------------------------------- */
static int
fish_unlink (struct vfs_class *me, const char *path)
{
gchar *shell_commands = NULL;
PREFIX
shell_commands =
shell_commands =
g_strconcat (SUP.scr_env, "FISH_FILENAME=%s;\n", SUP.scr_unlink, (char *) NULL);
g_snprintf (buf, sizeof (buf), shell_commands, rpath);
g_free (shell_commands);
@ -1216,12 +1282,15 @@ fish_unlink (struct vfs_class *me, const char *path)
return fish_send_command (me, super, buf, OPT_FLUSH);
}
/* --------------------------------------------------------------------------------------------- */
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);
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

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

View File

@ -3,12 +3,12 @@
2006, 2007 Free Software Foundation, Inc.
Written by:
1995 Ching Hui
1995 Jakub Jelinek
1995, 1996, 1997 Miguel de Icaza
1997 Norbert Warmuth
1998 Pavel Machek
2010 Yury V. Zaytsev
1995 Ching Hui
1995 Jakub Jelinek
1995, 1996, 1997 Miguel de Icaza
1997 Norbert Warmuth
1998 Pavel Machek
2010 Yury V. Zaytsev
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
@ -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;
@ -140,8 +114,8 @@ int ftpfs_use_passive_connections_over_proxy = 0;
/* Method used to get directory listings:
* 1: try 'LIST -la <path>', if it fails
* fall back to CWD <path>; LIST
* 0: always use CWD <path>; LIST
* fall back to CWD <path>; LIST
* 0: always use CWD <path>; LIST
*/
int ftpfs_use_unix_list_options = 1;
@ -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)
@ -627,7 +674,7 @@ ftpfs_load_no_proxy_list (void)
while (fgets (s, sizeof (s), npf) != NULL)
{
p = strchr (s, '\n');
if (p == NULL) /* skip bogus entries */
if (p == NULL) /* skip bogus entries */
{
while ((c = fgetc (npf)) != EOF && c != '\n')
;
@ -641,7 +688,7 @@ ftpfs_load_no_proxy_list (void)
np = g_new (struct no_proxy_entry, 1);
np->domain = g_strdup (s);
np->next = NULL;
np->next = NULL;
if (no_proxy)
current->next = np;
else
@ -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)
@ -1102,7 +1171,7 @@ ftpfs_setup_active (struct vfs_class *me, struct vfs_s_super *super,
af = FTP_INET6;
port = ((struct sockaddr_in6 *) &data_addr)->sin6_port;
break;
/* Not implemented */
/* Not implemented */
default:
return 0;
}
@ -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)
{
@ -1247,19 +1321,21 @@ ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super)
/* Restore the initial value of use_passive_connection (for subsequent retries) */
SUP.use_passive_connection = SUP.proxy ? ftpfs_use_passive_connections_over_proxy :
ftpfs_use_passive_connections;
ftpfs_use_passive_connections;
ftpfs_errno = EIO;
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)
{
@ -1740,7 +1827,7 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l
n_read -= n_written;
}
print_vfs_message (_("ftpfs: storing file %ju (%ju)"),
(uintmax_t) n_stored, (uintmax_t) s.st_size);
(uintmax_t) n_stored, (uintmax_t) s.st_size);
}
tty_disable_interrupt_key ();
close (sock);
@ -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);
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -2,9 +2,9 @@
Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
Written by: 1995 Miguel de Icaza
1995 Jakub Jelinek
1998 Pavel Machek
2003 Pavel Roskin
1995 Jakub Jelinek
1998 Pavel Machek
2003 Pavel Roskin
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
@ -34,59 +34,89 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h> /* For atol() */
#include <stdlib.h> /* For atol() */
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <ctype.h> /* is_digit() */
#include <sys/time.h> /* gettimeofday() */
#include <ctype.h> /* is_digit() */
#include <sys/time.h> /* gettimeofday() */
#include "lib/global.h"
#include "src/panel.h" /* current_panel */
#include "src/layout.h" /* get_current_type(), get_other_type() */
#include "src/panel.h" /* current_panel */
#include "src/layout.h" /* get_current_type(), get_other_type() */
#include "vfs-impl.h"
#include "utilvfs.h"
#include "gc.h"
int vfs_timeout = 60; /* VFS timeout in seconds */
/*** global variables ****************************************************************************/
int vfs_timeout = 60; /* VFS timeout in seconds */
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
static struct vfs_stamping *stamps;
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static void
vfs_addstamp (struct vfs_class *v, vfsid id)
{
if (!(v->flags & VFSF_LOCAL) && id != NULL) {
struct vfs_stamping *stamp;
struct vfs_stamping *last_stamp = 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) {
gettimeofday (&(stamp->time), NULL);
return;
}
last_stamp = stamp;
}
stamp = g_new (struct vfs_stamping, 1);
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;
}
last_stamp = stamp;
}
stamp = g_new (struct vfs_stamping, 1);
stamp->v = v;
stamp->id = id;
gettimeofday (&(stamp->time), NULL);
stamp->next = 0;
gettimeofday (&(stamp->time), NULL);
stamp->next = 0;
if (stamps) {
/* Add to the end */
last_stamp->next = stamp;
} else {
/* Add first element */
stamps = stamp;
}
if (stamps)
{
/* Add to the end */
last_stamp->next = stamp;
}
else
{
/* Add first element */
stamps = stamp;
}
}
}
/* --------------------------------------------------------------------------------------------- */
/** Compare two timeval structures. Return 0 is t1 is less than t2. */
static inline int
timeoutcmp (struct timeval *t1, struct timeval *t2)
{
return ((t1->tv_sec < t2->tv_sec)
|| ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec <= t2->tv_usec)));
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
vfs_stamp (struct vfs_class *v, vfsid id)
@ -94,32 +124,38 @@ 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) {
gettimeofday (&(stamp->time), NULL);
return;
}
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) {
stamps = stamp->next;
} else {
st1->next = stamp->next;
}
g_free (stamp);
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
{
st1->next = stamp->next;
}
g_free (stamp);
return;
}
return;
}
}
/* --------------------------------------------------------------------------------------------- */
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)
{
@ -148,54 +185,53 @@ vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
same, it's possible that all three are different -- Norbert */
if (!current_panel)
return;
return;
nvfs = vfs_get_class (vfs_get_current_dir ());
nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
vfs_rmstamp (nvfs, nvfsid);
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL) {
return;
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL)
{
return;
}
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 {
n2vfs = NULL;
n2vfsid = NULL;
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
{
n2vfs = NULL;
n2vfsid = NULL;
}
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 {
n3vfs = NULL;
n3vfsid = NULL;
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
{
n3vfs = NULL;
n3vfsid = NULL;
}
if (!oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid))
return;
return;
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)
{
@ -206,37 +242,42 @@ vfs_expire (int now)
/* Avoid recursive invocation, e.g. when one of the free functions
calls message */
if (locked)
return;
return;
locked = 1;
gettimeofday (&lc_time, NULL);
lc_time.tv_sec -= vfs_timeout;
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
stamp = stamp->next;
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
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,21 +298,25 @@ 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;) {
if (stamp->v->free)
(*stamp->v->free) (stamp->id);
st = stamp->next;
g_free (stamp);
stamp = st;
for (stamp = stamps, stamps = 0; stamp != NULL;)
{
if (stamp->v->free)
(*stamp->v->free) (stamp->id);
st = stamp->next;
g_free (stamp);
stamp = st;
}
if (stamps)
vfs_rmstamp (stamps->v, stamps->id);
vfs_rmstamp (stamps->v, stamps->id);
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -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)
@ -37,7 +51,7 @@ local_open (struct vfs_class *me, const char *file, int flags, mode_t mode)
fd = open (file, NO_LINEAR (flags), mode);
if (fd == -1)
return 0;
return 0;
local_info = g_new (int, 1);
*local_info = fd;
@ -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)
@ -95,30 +71,36 @@ local_opendir (struct vfs_class *me, const char *dirname)
dir = opendir (dirname);
if (!dir)
return 0;
return 0;
local_info = (DIR **) g_new (DIR *, 1);
*local_info = dir;
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)
{
@ -201,21 +192,26 @@ local_write (void *data, const char *buf, size_t nbyte)
int n;
if (!data)
return -1;
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;
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,15 +293,89 @@ local_ungetlocalcopy (struct vfs_class *me, const char *path,
return 0;
}
/* --------------------------------------------------------------------------------------------- */
static int
local_which (struct vfs_class *me, const char *path)
{
(void) me;
(void) path;
return 0; /* Every path which other systems do not like is expected to be ours */
return 0; /* Every path which other systems do not like is expected to be ours */
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
ssize_t
local_read (void *data, char *buffer, size_t count)
{
int n;
if (!data)
return -1;
while ((n = read (*((int *) data), buffer, count)) == -1)
{
#ifdef EAGAIN
if (errno == EAGAIN)
continue;
#endif
#ifdef EINTR
if (errno == EINTR)
continue;
#endif
return -1;
}
return n;
}
/* --------------------------------------------------------------------------------------------- */
int
local_close (void *data)
{
int fd;
if (!data)
return -1;
fd = *(int *) data;
g_free (data);
return close (fd);
}
/* --------------------------------------------------------------------------------------------- */
int
local_errno (struct vfs_class *me)
{
(void) me;
return errno;
}
/* --------------------------------------------------------------------------------------------- */
int
local_fstat (void *data, struct stat *buf)
{
/* FIXME: avoid type cast */
return fstat (*((int *) data), buf);
}
/* --------------------------------------------------------------------------------------------- */
off_t
local_lseek (void *data, off_t offset, int whence)
{
int fd = *(int *) data;
return lseek (fd, offset, whence);
}
/* --------------------------------------------------------------------------------------------- */
void
init_localfs (void)
{
@ -335,3 +410,5 @@ init_localfs (void)
vfs_local_ops.rmdir = local_rmdir;
vfs_register_class (&vfs_local_ops);
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -1,13 +1,13 @@
/* Network utilities for the Midnight Commander Virtual File System.
Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2005, 2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@ -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;
}
/* --------------------------------------------------------------------------------------------- */

View File

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

View File

@ -43,33 +43,64 @@
#include "lib/global.h"
#include "src/wtools.h" /* D_ERROR, D_NORMAL */
#include "src/main.h" /* mc_home */
#include "src/execute.h" /* EXECUTE_AS_SHELL */
#include "src/wtools.h" /* D_ERROR, D_NORMAL */
#include "src/main.h" /* mc_home */
#include "src/execute.h" /* EXECUTE_AS_SHELL */
#include "vfs-impl.h"
#include "utilvfs.h"
#include "local.h"
#include "gc.h" /* vfs_stamp_create */
#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
#define COPY_CHAR \
if ((size_t) (t-pad) > sizeof(pad)) { \
g_free (pqname); \
return -1; \
} \
else \
*t++ = *s;
#define COPY_STRING(a) \
if ((t-pad)+strlen(a)>sizeof(pad)) { \
g_free (pqname); \
return -1; \
} else { \
strcpy (t, a); \
t+= strlen(a); \
}
/*** file scope type declarations ****************************************************************/
struct cachedfile
{
char *name, *cache;
struct cachedfile *next;
};
/*** file scope variables ************************************************************************/
static struct cachedfile *head;
static struct vfs_class vfs_sfs_ops;
static int sfs_no = 0;
static char *sfs_prefix[MAXFS];
static char *sfs_command[MAXFS];
static int sfs_flags[MAXFS];
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static int
sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
{
@ -78,91 +109,88 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
char pad[10240];
char *s, *t = pad;
int was_percent = 0;
char *pname; /* name of parent archive */
char *pqname; /* name of parent archive, quoted */
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");
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_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);
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); \
return -1; \
} \
else \
*t++ = *s;
#define COPY_STRING(a) \
if ((t-pad)+strlen(a)>sizeof(pad)) { \
g_free (pqname); \
return -1; \
} else { \
strcpy (t, a); \
t+= strlen(a); \
}
for (s = sfs_command[w]; *s; s++)
{
if (was_percent)
{
for (s = sfs_command[w]; *s; s++) {
if (was_percent) {
const char *ptr = NULL;
was_percent = 0;
const char *ptr = NULL;
was_percent = 0;
switch (*s) {
case '1':
ptr = pqname;
break;
case '2':
ptr = op + strlen (sfs_prefix[w]);
break;
case '3':
ptr = cache;
break;
case '%':
COPY_CHAR;
continue;
}
COPY_STRING (ptr);
} else {
if (*s == '%')
was_percent = 1;
else
COPY_CHAR;
}
switch (*s)
{
case '1':
ptr = pqname;
break;
case '2':
ptr = op + strlen (sfs_prefix[w]);
break;
case '3':
ptr = cache;
break;
case '%':
COPY_CHAR;
continue;
}
COPY_STRING (ptr);
}
else
{
if (*s == '%')
was_percent = 1;
else
COPY_CHAR;
}
}
g_free (pqname);
open_error_pipe ();
if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad)) {
close_error_pipe (D_ERROR, NULL);
return -1;
if (my_system (EXECUTE_AS_SHELL, "/bin/sh", pad))
{
close_error_pipe (D_ERROR, NULL);
return -1;
}
close_error_pipe (D_NORMAL, NULL);
return 0; /* OK */
return 0; /* OK */
}
/* --------------------------------------------------------------------------------------------- */
static const char *
sfs_redirect (struct vfs_class *me, const char *name)
{
@ -170,32 +198,36 @@ sfs_redirect (struct vfs_class *me, const char *name)
char *cache;
int handle;
while (cur) {
if (!strcmp (name, cur->name)) {
vfs_stamp (&vfs_sfs_ops, cur);
return cur->cache;
}
cur = cur->next;
while (cur)
{
if (!strcmp (name, cur->name))
{
vfs_stamp (&vfs_sfs_ops, cur);
return cur->cache;
}
cur = cur->next;
}
handle = vfs_mkstemps (&cache, "sfs", name);
if (handle == -1) {
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
if (handle == -1)
{
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";
}
close (handle);
if (!sfs_vfmake (me, name, cache)) {
cur = g_new (struct cachedfile, 1);
cur->name = g_strdup (name);
cur->cache = cache;
cur->next = head;
head = cur;
if (!sfs_vfmake (me, name, cache))
{
cur = g_new (struct cachedfile, 1);
cur->name = g_strdup (name);
cur->cache = cache;
cur->next = head;
head = cur;
vfs_stamp_create (&vfs_sfs_ops, head);
vfs_stamp_create (&vfs_sfs_ops, head);
return cache;
return cache;
}
unlink (cache);
@ -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)
{
@ -212,7 +246,7 @@ sfs_open (struct vfs_class *me, const char *path, int flags, mode_t mode)
path = sfs_redirect (me, path);
fd = open (path, NO_LINEAR (flags), mode);
if (fd == -1)
return 0;
return 0;
sfs_info = g_new (int, 1);
*sfs_info = fd;
@ -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,49 +321,60 @@ sfs_getid (struct vfs_class *me, const char *path)
(void) me;
while (cur) {
if (!strcmp (path, cur->name))
break;
cur = cur->next;
while (cur)
{
if (!strcmp (path, cur->name))
break;
cur = cur->next;
}
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;
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)
prev->next = cur->next;
prev->next = cur->next;
else
head = cur->next;
head = cur->next;
g_free (cur->cache);
g_free (cur->name);
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);
cur = cur->next;
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,67 +417,80 @@ 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) {
fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini);
g_free (mc_sfsini);
return 0;
if (cfg == NULL)
{
fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini);
g_free (mc_sfsini);
return 0;
}
g_free (mc_sfsini);
sfs_no = 0;
while (sfs_no < MAXFS && fgets (key, sizeof (key), cfg)) {
char *c, *semi = NULL, flags = 0;
while (sfs_no < MAXFS && fgets (key, sizeof (key), cfg))
{
char *c, *semi = NULL, flags = 0;
if (*key == '#' || *key == '\n')
continue;
if (*key == '#' || *key == '\n')
continue;
for (c = key; *c; c++)
if ((*c == ':') || (*c == '/')){
semi = c;
if (*c == '/'){
*c = 0;
flags |= F_FULLMATCH;
}
break;
}
for (c = key; *c; c++)
if ((*c == ':') || (*c == '/'))
{
semi = c;
if (*c == '/')
{
*c = 0;
flags |= F_FULLMATCH;
}
break;
}
if (!semi){
invalid_line:
fprintf (stderr, _("Warning: Invalid line in %s:\n%s\n"),
"sfs.ini", key);
continue;
}
if (!semi)
{
invalid_line:
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;
default:
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"),
*c, "sfs.ini", key);
}
c++;
}
if (!*c)
goto invalid_line;
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;
default:
fprintf (stderr, _("Warning: Invalid flag %c in %s:\n%s\n"), *c, "sfs.ini", key);
}
c++;
}
if (!*c)
goto invalid_line;
c++;
*(semi+1) = 0;
semi = strchr (c, '\n');
if (semi != NULL)
*semi = 0;
c++;
*(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_no++;
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]))
return i;
} else
if (!strncmp (path, sfs_prefix [i], strlen (sfs_prefix [i])))
return 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])))
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);
}
/* --------------------------------------------------------------------------------------------- */

File diff suppressed because it is too large Load Diff

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -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)
{
@ -137,7 +169,7 @@ undelfs_get_path (const char *dirname, char **fsname, char **file)
p = dirname + strlen (dirname);
#if 0
/* Strip trailing ./
/* Strip trailing ./
*/
if (p - dirname > 2 && *(p - 1) == '/' && *(p - 2) == '.')
*(p = p - 2) = 0;
@ -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,7 +761,9 @@ undelfs_free (vfsid id)
undelfs_shutdown ();
}
#ifdef ENABLE_NLS
/* --------------------------------------------------------------------------------------------- */
#ifdef ENABLE_NLS
static int
undelfs_init (struct vfs_class *me)
{
@ -742,9 +773,33 @@ undelfs_init (struct vfs_class *me)
return 1;
}
#else
#define undelfs_init NULL
#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);
}
/* --------------------------------------------------------------------------------------------- */

File diff suppressed because it is too large Load Diff

View File

@ -13,40 +13,47 @@
#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 */
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);
char *vfs_split_url (const char *path, char **host, char **user, int *port,
char **pass, int default_port, enum VFS_URL_FLAGS flags);
char **pass, int default_port, enum VFS_URL_FLAGS flags);
int vfs_split_text (char *p);
int vfs_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

View File

@ -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>
@ -16,90 +16,100 @@
#include <utime.h>
#include "vfs.h"
#include "lib/fs.h" /* MC_MAXPATHLEN */
#include "lib/fs.h" /* MC_MAXPATHLEN */
/*** typedefs(not structures) and defined constants **********************************************/
typedef void *vfsid;
/*** 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" */
const char *name; /* "FIles over SHell" */
vfs_class_flags_t flags;
const char *prefix; /* "fish:" */
void *data; /* this is for filesystem's own use */
int verrno; /* can't use errno because glibc2 might define errno as function */
const char *prefix; /* "fish:" */
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);
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);
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 (*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);
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,
const char *local, int has_changed);
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 */

File diff suppressed because it is too large Load Diff

View File

@ -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,14 +26,114 @@ void vfs_shut (void);
* See also:
* vfs_fill_names().
*/
#define VFS_ENCODING_PREFIX "#enc:"
#define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
/* Midnight commander code should _not_ use other flags than those
listed above and O_APPEND */
#if (O_ALL & O_APPEND)
#warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
#define O_LINEAR 0
#define IS_LINEAR(a) 0
#define NO_LINEAR(a) a
#else
#define O_LINEAR O_APPEND
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
#endif
/* O_LINEAR is strange beast, be careful. If you open file asserting
* O_RDONLY | O_LINEAR, you promise:
*
* a) to read file linearly from beginning to the end
* b) not to open another file before you close this one
* (this will likely go away in future)
* as a special gift, you may
* c) lseek() immediately after open(), giving ftpfs chance to
* reget. Be warned that this lseek() can fail, and you _have_
* to handle that gratefully.
*
* O_LINEAR allows filesystems not to create temporary file in some
* cases (ftp transfer). -- pavel@ucw.cz
*/
/* And now some defines for our errors. */
#ifdef ENOSYS
#define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
#else
#define E_NOTSUPP EFAULT /* Does this happen? */
#endif
#ifdef ENOMSG
#define E_UNKNOWN ENOMSG /* if we do not know what error happened */
#else
#define E_UNKNOWN EIO /* if we do not know what error happened */
#endif
#ifdef EREMOTEIO
#define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
#else
#define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
#endif
#ifdef EPROTO
#define E_PROTO EPROTO /* if other side fails to follow protocol */
#else
#define E_PROTO EIO
#endif
typedef void (*fill_names_f) (const char *);
/*** 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);
@ -86,7 +175,6 @@ 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);
@ -109,77 +197,5 @@ char *vfs_get_current_dir (void);
* 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"
#define O_LINEAR 0
#define IS_LINEAR(a) 0
#define NO_LINEAR(a) a
#else
#define O_LINEAR O_APPEND
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
#endif
/* O_LINEAR is strange beast, be careful. If you open file asserting
* O_RDONLY | O_LINEAR, you promise:
*
* a) to read file linearly from beginning to the end
* b) not to open another file before you close this one
* (this will likely go away in future)
* as a special gift, you may
* c) lseek() immediately after open(), giving ftpfs chance to
* reget. Be warned that this lseek() can fail, and you _have_
* to handle that gratefully.
*
* O_LINEAR allows filesystems not to create temporary file in some
* cases (ftp transfer). -- pavel@ucw.cz
*/
/* And now some defines for our errors. */
#ifdef ENOSYS
#define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
#else
#define E_NOTSUPP EFAULT /* Does this happen? */
#endif
#ifdef ENOMSG
#define E_UNKNOWN ENOMSG /* if we do not know what error happened */
#else
#define E_UNKNOWN EIO /* if we do not know what error happened */
#endif
#ifdef EREMOTEIO
#define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
#else
#define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
#endif
#ifdef EPROTO
#define E_PROTO EPROTO /* if other side fails to follow protocol */
#else
#define E_PROTO EIO
#endif
/*** inline functions ****************************************************************************/
#endif /* MC_VFS_VFS_H */

View File

@ -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
@ -70,7 +87,7 @@ struct vfs_s_super
int host_flags;
char *scr_env;
} fish;
#endif /* ENABLE_VFS_FISH */
#endif /* ENABLE_VFS_FISH */
#ifdef ENABLE_VFS_FTP
struct
{
@ -80,29 +97,29 @@ struct vfs_s_super
char *password;
int port;
char *proxy; /* proxy server, NULL if no proxy */
char *proxy; /* proxy server, NULL if no proxy */
int failed_on_login; /* used to pass the failure reason to upper levels */
int use_passive_connection;
int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
int isbinary;
int cwd_deferred; /* current_directory was changed but CWD command hasn't
been sent yet */
int strict; /* ftp server doesn't understand
* "LIST -la <path>"; use "CWD <path>"/
* "LIST" instead
*/
int cwd_deferred; /* current_directory was changed but CWD command hasn't
been sent yet */
int strict; /* ftp server doesn't understand
* "LIST -la <path>"; use "CWD <path>"/
* "LIST" instead
*/
int ctl_connection_busy;
} ftp;
#endif /* ENABLE_VFS_FTP */
#endif /* ENABLE_VFS_FTP */
#if defined(ENABLE_VFS_CPIO) || defined(ENABLE_VFS_TAR)
struct
{
int fd;
struct stat st;
int type; /* Type of the archive */
struct defer_inode *deferred; /* List of inodes for which another entries may appear */
int type; /* Type of the archive */
struct defer_inode *deferred; /* List of inodes for which another entries may appear */
} arch;
#endif /* ENABLE_VFS_CPIO || ENABLE_VFS_TAR */
#endif /* ENABLE_VFS_CPIO || ENABLE_VFS_TAR */
} u;
};
@ -149,13 +166,13 @@ struct vfs_s_fh
off_t got, total;
int append;
} fish;
#endif /* ENABLE_VFS_FISH */
#endif /* ENABLE_VFS_FISH */
#ifdef ENABLE_VFS_FTP
struct
{
int sock, append;
} ftp;
#endif /* ENABLE_VFS_FTP */
#endif /* ENABLE_VFS_FTP */
} u;
};
@ -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

View File

@ -11,194 +11,194 @@
*/
/* special commands */
#define CK_Insert_Char -1
#define CK_Ignore_Key 0
#define CK_Insert_Char -1
#define CK_Ignore_Key 0
/* cursor movements */
#define CK_BackSpace 1
#define CK_Delete 2
#define CK_Enter 3
#define CK_Page_Up 4
#define CK_Page_Down 5
#define CK_Left 6
#define CK_Right 7
#define CK_Word_Left 8
#define CK_Word_Right 9
#define CK_Up 10
#define CK_Down 11
#define CK_Home 12
#define CK_End 13
#define CK_Tab 14
#define CK_Undo 15
#define CK_Beginning_Of_Text 16
#define CK_End_Of_Text 17
#define CK_Scroll_Up 18
#define CK_Scroll_Down 19
#define CK_Return 20
#define CK_Begin_Page 21
#define CK_End_Page 22
#define CK_Delete_Word_Left 23
#define CK_Delete_Word_Right 24
#define CK_Paragraph_Up 25
#define CK_Paragraph_Down 26
#define CK_BackSpace 1
#define CK_Delete 2
#define CK_Enter 3
#define CK_Page_Up 4
#define CK_Page_Down 5
#define CK_Left 6
#define CK_Right 7
#define CK_Word_Left 8
#define CK_Word_Right 9
#define CK_Up 10
#define CK_Down 11
#define CK_Home 12
#define CK_End 13
#define CK_Tab 14
#define CK_Undo 15
#define CK_Beginning_Of_Text 16
#define CK_End_Of_Text 17
#define CK_Scroll_Up 18
#define CK_Scroll_Down 19
#define CK_Return 20
#define CK_Begin_Page 21
#define CK_End_Page 22
#define CK_Delete_Word_Left 23
#define CK_Delete_Word_Right 24
#define CK_Paragraph_Up 25
#define CK_Paragraph_Down 26
/* file commands */
#define CK_Save 101
#define CK_Load 102
#define CK_New 103
#define CK_Save_As 104
#define CK_Load_Prev_File 111
#define CK_Load_Next_File 112
#define CK_Load_Syntax_File 121
#define CK_Load_Menu_File 122
#define CK_Menu 123
#define CK_Save 101
#define CK_Load 102
#define CK_New 103
#define CK_Save_As 104
#define CK_Load_Prev_File 111
#define CK_Load_Next_File 112
#define CK_Load_Syntax_File 121
#define CK_Load_Menu_File 122
#define CK_Menu 123
/* block commands */
#define CK_Mark 201
#define CK_Copy 202
#define CK_Move 203
#define CK_Remove 204
#define CK_Unmark 206
#define CK_Save_Block 207
#define CK_Column_Mark 208
#define CK_Shift_Block_Left 211
#define CK_Shift_Block_Right 212
#define CK_Mark_All 213
#define CK_Mark 201
#define CK_Copy 202
#define CK_Move 203
#define CK_Remove 204
#define CK_Unmark 206
#define CK_Save_Block 207
#define CK_Column_Mark 208
#define CK_Shift_Block_Left 211
#define CK_Shift_Block_Right 212
#define CK_Mark_All 213
/* search and replace */
#define CK_Find 301
#define CK_Find_Again 302
#define CK_Replace 303
#define CK_Replace_Again 304
#define CK_Complete_Word 305
#define CK_Find 301
#define CK_Find_Again 302
#define CK_Replace 303
#define CK_Replace_Again 304
#define CK_Complete_Word 305
#if 0
/* debugger commands */
#define CK_Debug_Start 350
#define CK_Debug_Stop 351
#define CK_Debug_Toggle_Break 352
#define CK_Debug_Clear 353
#define CK_Debug_Next 354
#define CK_Debug_Step 355
#define CK_Debug_Back_Trace 356
#define CK_Debug_Continue 357
#define CK_Debug_Enter_Command 358
#define CK_Debug_Until_Curser 359
#define CK_Debug_Start 350
#define CK_Debug_Stop 351
#define CK_Debug_Toggle_Break 352
#define CK_Debug_Clear 353
#define CK_Debug_Next 354
#define CK_Debug_Step 355
#define CK_Debug_Back_Trace 356
#define CK_Debug_Continue 357
#define CK_Debug_Enter_Command 358
#define CK_Debug_Until_Curser 359
#endif
/* misc */
#define CK_Insert_File 401
#define CK_Quit 402
#define CK_Insert_File 401
#define CK_Quit 402
#define CK_Toggle_Insert 403
#define CK_Help 404
#define CK_Date 405
#define CK_Refresh 406
#define CK_Goto 407
#define CK_Delete_Line 408
#define CK_Delete_To_Line_End 409
#define CK_Delete_To_Line_Begin 410
#define CK_Man_Page 411
#define CK_Sort 412
#define CK_Mail 413
#define CK_Cancel 414
#define CK_Complete 415
#define CK_Paragraph_Format 416
#define CK_Util 417
#define CK_Type_Load_Python 418
#define CK_Find_File 419
#define CK_Ctags 420
#define CK_Match_Bracket 421
#define CK_Terminal 422
#define CK_Terminal_App 423
#define CK_ExtCmd 424
#define CK_User_Menu 425
#define CK_Find_Definition 426
#define CK_Edit_Options 427
#define CK_Edit_Save_Mode 428
#define CK_Choose_Syntax 429
#define CK_About 430
#define CK_Help 404
#define CK_Date 405
#define CK_Refresh 406
#define CK_Goto 407
#define CK_Delete_Line 408
#define CK_Delete_To_Line_End 409
#define CK_Delete_To_Line_Begin 410
#define CK_Man_Page 411
#define CK_Sort 412
#define CK_Mail 413
#define CK_Cancel 414
#define CK_Complete 415
#define CK_Paragraph_Format 416
#define CK_Util 417
#define CK_Type_Load_Python 418
#define CK_Find_File 419
#define CK_Ctags 420
#define CK_Match_Bracket 421
#define CK_Terminal 422
#define CK_Terminal_App 423
#define CK_ExtCmd 424
#define CK_User_Menu 425
#define CK_Find_Definition 426
#define CK_Edit_Options 427
#define CK_Edit_Save_Mode 428
#define CK_Choose_Syntax 429
#define CK_About 430
#if 0
/* application control */
#define CK_Save_Desktop 451
#define CK_New_Window 452
#define CK_Cycle 453
#define CK_Save_And_Quit 455
#define CK_Run_Another 456
#define CK_Check_Save_And_Quit 457
#define CK_Maximize 458
#define CK_Save_Desktop 451
#define CK_New_Window 452
#define CK_Cycle 453
#define CK_Save_And_Quit 455
#define CK_Run_Another 456
#define CK_Check_Save_And_Quit 457
#define CK_Maximize 458
#endif
#define CK_Toggle_Show_Margin 460
#define CK_Toggle_Tab_TWS 470
#define CK_Toggle_Syntax 480
#define CK_Toggle_Line_State 490
#define CK_Toggle_Show_Margin 460
#define CK_Toggle_Tab_TWS 470
#define CK_Toggle_Syntax 480
#define CK_Toggle_Line_State 490
/* macro */
#define CK_Begin_Record_Macro 501
#define CK_End_Record_Macro 502
#define CK_Delete_Macro 503
#define CK_Begin_Record_Macro 501
#define CK_End_Record_Macro 502
#define CK_Delete_Macro 503
/* book mark */
#define CK_Toggle_Bookmark 550
#define CK_Flush_Bookmarks 551
#define CK_Next_Bookmark 552
#define CK_Prev_Bookmark 553
#define CK_Toggle_Bookmark 550
#define CK_Flush_Bookmarks 551
#define CK_Next_Bookmark 552
#define CK_Prev_Bookmark 553
/* highlight commands */
#define CK_Page_Up_Highlight 604
#define CK_Page_Down_Highlight 605
#define CK_Left_Highlight 606
#define CK_Right_Highlight 607
#define CK_Word_Left_Highlight 608
#define CK_Word_Right_Highlight 609
#define CK_Up_Highlight 610
#define CK_Down_Highlight 611
#define CK_Home_Highlight 612
#define CK_End_Highlight 613
#define CK_Beginning_Of_Text_Highlight 614
#define CK_End_Of_Text_Highlight 615
#define CK_Begin_Page_Highlight 616
#define CK_End_Page_Highlight 617
#define CK_Scroll_Up_Highlight 618
#define CK_Scroll_Down_Highlight 619
#define CK_Paragraph_Up_Highlight 620
#define CK_Paragraph_Down_Highlight 621
#define CK_Page_Up_Highlight 604
#define CK_Page_Down_Highlight 605
#define CK_Left_Highlight 606
#define CK_Right_Highlight 607
#define CK_Word_Left_Highlight 608
#define CK_Word_Right_Highlight 609
#define CK_Up_Highlight 610
#define CK_Down_Highlight 611
#define CK_Home_Highlight 612
#define CK_End_Highlight 613
#define CK_Beginning_Of_Text_Highlight 614
#define CK_End_Of_Text_Highlight 615
#define CK_Begin_Page_Highlight 616
#define CK_End_Page_Highlight 617
#define CK_Scroll_Up_Highlight 618
#define CK_Scroll_Down_Highlight 619
#define CK_Paragraph_Up_Highlight 620
#define CK_Paragraph_Down_Highlight 621
/* alt highlight commands */
#define CK_Page_Up_Alt_Highlight 654
#define CK_Page_Down_Alt_Highlight 655
#define CK_Left_Alt_Highlight 656
#define CK_Right_Alt_Highlight 657
#define CK_Word_Left_Alt_Highlight 658
#define CK_Word_Right_Alt_Highlight 659
#define CK_Up_Alt_Highlight 660
#define CK_Down_Alt_Highlight 661
#define CK_Home_Alt_Highlight 662
#define CK_End_Alt_Highlight 663
#define CK_Beginning_Of_Text_Alt_Highlight 664
#define CK_End_Of_Text_Alt_Highlight 665
#define CK_Begin_Page_Alt_Highlight 666
#define CK_End_Page_Alt_Highlight 667
#define CK_Scroll_Up_Alt_Highlight 668
#define CK_Scroll_Down_Alt_Highlight 669
#define CK_Paragraph_Up_Alt_Highlight 670
#define CK_Paragraph_Down_Alt_Highlight 671
#define CK_Page_Up_Alt_Highlight 654
#define CK_Page_Down_Alt_Highlight 655
#define CK_Left_Alt_Highlight 656
#define CK_Right_Alt_Highlight 657
#define CK_Word_Left_Alt_Highlight 658
#define CK_Word_Right_Alt_Highlight 659
#define CK_Up_Alt_Highlight 660
#define CK_Down_Alt_Highlight 661
#define CK_Home_Alt_Highlight 662
#define CK_End_Alt_Highlight 663
#define CK_Beginning_Of_Text_Alt_Highlight 664
#define CK_End_Of_Text_Alt_Highlight 665
#define CK_Begin_Page_Alt_Highlight 666
#define CK_End_Page_Alt_Highlight 667
#define CK_Scroll_Up_Alt_Highlight 668
#define CK_Scroll_Down_Alt_Highlight 669
#define CK_Paragraph_Up_Alt_Highlight 670
#define CK_Paragraph_Down_Alt_Highlight 671
/* X clipboard operations */
#define CK_XStore 701
#define CK_XCut 702
#define CK_XPaste 703
#define CK_Selection_History 704
#define CK_XStore 701
#define CK_XCut 702
#define CK_XPaste 703
#define CK_Selection_History 704
#define CK_Shell 801
#define CK_Shell 801
/* C-x or similar */
#define CK_Ext_Mode 820
#define CK_Ext_Mode 820
#define CK_Insert_Literal 851
#define CK_Execute_Macro 852
#define CK_Begin_End_Macro 853
#define CK_Insert_Literal 851
#define CK_Execute_Macro 852
#define CK_Begin_End_Macro 853
/* help */
#define CK_HelpHelp 1001
@ -503,15 +503,15 @@
TODO: bring up a viewer to display the error message instead of inserting
it into the text, which is annoying.
*/
#define CK_Pipe_Block(i) (1000+(i))
#define CK_Pipe_Block(i) (1000+(i))
#define SHELL_COMMANDS_i {"/edit.indent.rc", "/edit.spell.rc", /* and so on */ 0 }
#define CK_Macro(i) (2000+(i))
#define CK_Last_Macro CK_Macro(0x7FFF)
#define CK_Macro(i) (2000+(i))
#define CK_Last_Macro CK_Macro(0x7FFF)
#else
#define CK_User_Command(i) ((i) | (1 << 16))
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
#define CK_Macro(i) ((i) | (1 << 17))
#define IS_MACRO_COMMAND(i) ((i) & (1 << 17))
#define CK_User_Command(i) ((i) | (1 << 16))
#define IS_USER_COMMAND(i) ((i) & (1 << 16))
#define CK_Macro(i) ((i) | (1 << 17))
#define IS_MACRO_COMMAND(i) ((i) & (1 << 17))
#endif /* MC_CMD_DEF_H */
#endif /* MC_CMD_DEF_H */

View File

@ -264,9 +264,11 @@ set_attr (unsigned attr)
color_map[tc & 7], color_map[bc & 7]);
}
#define cursor_to(x, y) do { \
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
fflush(stdout); \
#define cursor_to(x, y) \
do \
{ \
printf("\x1B[%d;%df", (y) + 1, (x) + 1); \
fflush(stdout); \
} while (0)
static void

View File

@ -72,27 +72,28 @@ do { \
} \
} while (0)
#define FILE_READ_BUF 4096
#define FILE_FLAG_TEMP (1 << 0)
#define FILE_READ_BUF 4096
#define FILE_FLAG_TEMP (1 << 0)
#define OPTX 56
#define OPTY 17
#define ADD_CH '+'
#define DEL_CH '-'
#define CHG_CH '*'
#define EQU_CH ' '
#define ADD_CH '+'
#define DEL_CH '-'
#define CHG_CH '*'
#define EQU_CH ' '
#define HDIFF_ENABLE 1
#define HDIFF_MINCTX 5
#define HDIFF_DEPTH 10
#define FILE_DIRTY(fs) \
do { \
(fs)->pos = 0; \
(fs)->len = 0; \
} while (0)
#define HDIFF_ENABLE 1
#define HDIFF_MINCTX 5
#define HDIFF_DEPTH 10
#define FILE_DIRTY(fs) \
do \
{ \
(fs)->pos = 0; \
(fs)->len = 0; \
} \
while (0)
/*** file scope type declarations ****************************************************************/
@ -3306,34 +3307,42 @@ diff_view (const char *file1, const char *file2, const char *label1, const char
/* --------------------------------------------------------------------------------------------- */
#define GET_FILE_AND_STAMP(n) \
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) { \
use_copy##n = 1; \
if (mc_stat(real_file##n, &st##n) != 0) { \
use_copy##n = -1; \
} \
} \
} \
} while (0)
#define UNGET_FILE(n) \
do { \
if (use_copy##n) { \
int changed = 0; \
if (use_copy##n > 0) { \
time_t mtime = st##n.st_mtime; \
if (mc_stat(real_file##n, &st##n) == 0) { \
changed = (mtime != st##n.st_mtime); \
} \
} \
mc_ungetlocalcopy(file##n, real_file##n, changed); \
g_free(real_file##n); \
} \
} while (0)
#define GET_FILE_AND_STAMP(n) \
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) \
{ \
use_copy##n = 1; \
if (mc_stat (real_file##n, &st##n) != 0) \
use_copy##n = -1; \
} \
} \
} \
while (0)
#define UNGET_FILE(n) \
do \
{ \
if (use_copy##n) \
{ \
int changed = 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); \
} \
} \
while (0)
void
dview_diff_cmd (void)

View File

@ -95,26 +95,26 @@
#define START_STACK_SIZE 32
/* Some codes that may be pushed onto or returned from the undo stack */
#define CURS_LEFT 601
#define CURS_RIGHT 602
#define DELCHAR 603
#define BACKSPACE 604
#define STACK_BOTTOM 605
#define CURS_LEFT_LOTS 606
#define CURS_RIGHT_LOTS 607
#define COLUMN_ON 608
#define COLUMN_OFF 609
#define MARK_1 1000
#define MARK_2 700000000
#define KEY_PRESS 1400000000
#define CURS_LEFT 601
#define CURS_RIGHT 602
#define DELCHAR 603
#define BACKSPACE 604
#define STACK_BOTTOM 605
#define CURS_LEFT_LOTS 606
#define CURS_RIGHT_LOTS 607
#define COLUMN_ON 608
#define COLUMN_OFF 609
#define MARK_1 1000
#define MARK_2 700000000
#define KEY_PRESS 1400000000
/* Tabs spaces: (sofar only HALF_TAB_SIZE is used: */
#define TAB_SIZE option_tab_spacing
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
#define TAB_SIZE option_tab_spacing
#define HALF_TAB_SIZE ((int) option_tab_spacing / 2)
/* max count stack files */
#define MAX_HISTORY_MOVETO 50
#define LINE_STATE_WIDTH 8
#define LINE_STATE_WIDTH 8
/* search/replace options */
typedef struct edit_search_options_t

View File

@ -4,8 +4,8 @@
#include <sys/types.h> /* size_t */
#include "lib/global.h" /* include <glib.h> */
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
#define MAX_DEFINITIONS 60 /* count found entries show */
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
#define MAX_DEFINITIONS 60 /* count found entries show */
#define SHORT_DEF_LEN 30
#define LONG_DEF_LEN 40
#define LINE_DEF_LEN 16

View File

@ -7,9 +7,9 @@
#define MC_EXECUTE_H
/* flags for shell_execute */
#define EXECUTE_INTERNAL (1 << 0)
#define EXECUTE_AS_SHELL (1 << 2)
#define EXECUTE_HIDE (1 << 3)
#define EXECUTE_INTERNAL (1 << 0)
#define EXECUTE_AS_SHELL (1 << 2)
#define EXECUTE_HIDE (1 << 3)
/* Execute functions that use the shell to execute */
void shell_execute (const char *command, int flags);

View File

@ -30,7 +30,7 @@
#define MC_HELP_H
/* Markers used in the help files */
#define CHAR_LINK_START '\01' /* Ctrl-A */
#define CHAR_LINK_START '\01' /* Ctrl-A */
#define CHAR_LINK_POINTER '\02' /* Ctrl-B */
#define CHAR_LINK_END '\03' /* Ctrl-C */
#define CHAR_NODE_END '\04' /* Ctrl-D */

View File

@ -3,46 +3,46 @@
* \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 */
#define MC_HISTORY_EDIT_SAVE_AS "mc.edit.save-as"
#define MC_HISTORY_EDIT_LOAD "mc.edit.load"
#define MC_HISTORY_EDIT_SAVE_BLOCK "mc.edit.save-block"
#define MC_HISTORY_EDIT_INSERT_FILE "mc.edit.insert-file"
#define MC_HISTORY_EDIT_GOTO_LINE "mc.edit.goto-line"
#define MC_HISTORY_EDIT_SORT "mc.edit.sort"
#define MC_HISTORY_EDIT_PASTE_EXTCMD "mc.edit.paste-extcmd"
#define MC_HISTORY_EDIT_SAVE_AS "mc.edit.save-as"
#define MC_HISTORY_EDIT_LOAD "mc.edit.load"
#define MC_HISTORY_EDIT_SAVE_BLOCK "mc.edit.save-block"
#define MC_HISTORY_EDIT_INSERT_FILE "mc.edit.insert-file"
#define MC_HISTORY_EDIT_GOTO_LINE "mc.edit.goto-line"
#define MC_HISTORY_EDIT_SORT "mc.edit.sort"
#define MC_HISTORY_EDIT_PASTE_EXTCMD "mc.edit.paste-extcmd"
#define MC_HISTORY_FM_VIEW_FILE "mc.fm.view-file"
#define MC_HISTORY_FM_MKDIR "mc.fm.mkdir"
#define MC_HISTORY_FM_LINK "mc.fm.link"
#define MC_HISTORY_FM_EDIT_LINK "mc.fm.edit-link"
#define MC_HISTORY_FM_TREE_COPY "mc.fm.tree-copy"
#define MC_HISTORY_FM_TREE_MOVE "mc.fm.tree-move"
#define MC_HISTORY_FM_PANELIZE_ADD "mc.fm.panelize.add"
#define MC_HISTORY_FM_FILTERED_VIEW "mc.fm.filtered-view"
#define MC_HISTORY_FM_PANEL_FILTER "mc.fm.panel-filter"
#define MC_HISTORY_FM_MENU_EXEC_PARAM "mc.fm.menu.exec.parameter"
#define MC_HISTORY_FM_VIEW_FILE "mc.fm.view-file"
#define MC_HISTORY_FM_MKDIR "mc.fm.mkdir"
#define MC_HISTORY_FM_LINK "mc.fm.link"
#define MC_HISTORY_FM_EDIT_LINK "mc.fm.edit-link"
#define MC_HISTORY_FM_TREE_COPY "mc.fm.tree-copy"
#define MC_HISTORY_FM_TREE_MOVE "mc.fm.tree-move"
#define MC_HISTORY_FM_PANELIZE_ADD "mc.fm.panelize.add"
#define MC_HISTORY_FM_FILTERED_VIEW "mc.fm.filtered-view"
#define MC_HISTORY_FM_PANEL_FILTER "mc.fm.panel-filter"
#define MC_HISTORY_FM_MENU_EXEC_PARAM "mc.fm.menu.exec.parameter"
#define MC_HISTORY_ESC_TIMEOUT "mc.esc.timeout"
#define MC_HISTORY_ESC_TIMEOUT "mc.esc.timeout"
#define MC_HISTORY_VIEW_GOTO "mc.view.goto"
#define MC_HISTORY_VIEW_GOTO_LINE "mc.view.goto-line"
#define MC_HISTORY_VIEW_GOTO_ADDR "mc.view.goto-addr"
#define MC_HISTORY_VIEW_SEARCH_REGEX "mc.view.search.regex"
#define MC_HISTORY_VIEW_GOTO "mc.view.goto"
#define MC_HISTORY_VIEW_GOTO_LINE "mc.view.goto-line"
#define MC_HISTORY_VIEW_GOTO_ADDR "mc.view.goto-addr"
#define MC_HISTORY_VIEW_SEARCH_REGEX "mc.view.search.regex"
#define MC_HISTORY_FTPFS_ACCOUNT "mc.vfs.ftp.account"
#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password"
#define MC_HISTORY_FTPFS_ACCOUNT "mc.vfs.ftp.account"
#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password"
#define MC_HISTORY_EXT_PARAMETER "mc.ext.parameter"
#define MC_HISTORY_EXT_PARAMETER "mc.ext.parameter"
#define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add"
#define MC_HISTORY_HOTLIST_ADD "mc.hotlist.add"
#define MC_HISTORY_SHARED_SEARCH "mc.shared.search"
#define MC_HISTORY_SHARED_SEARCH "mc.shared.search"
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
#define MC_HISTORY_YDIFF_GOTO_LINE "mc.ydiff.goto-line"
#endif
#endif /* MC_HISTORY_H */

View File

@ -65,22 +65,22 @@
#define UY 2
#define BX UX
#define BY (LINES - 6)
#define BY (LINES - 6)
#define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
#define BUTTONS (sizeof(hotlist_but)/sizeof(struct _hotlist_but))
#define LABELS 3
#define B_ADD_CURRENT B_USER
#define B_ADD_CURRENT B_USER
#define B_REMOVE (B_USER + 1)
#define B_NEW_GROUP (B_USER + 2)
#define B_NEW_ENTRY (B_USER + 3)
#define B_UP_GROUP (B_USER + 4)
#define B_INSERT (B_USER + 5)
#define B_APPEND (B_USER + 6)
#define B_MOVE (B_USER + 7)
#define B_NEW_GROUP (B_USER + 2)
#define B_NEW_ENTRY (B_USER + 3)
#define B_UP_GROUP (B_USER + 4)
#define B_INSERT (B_USER + 5)
#define B_APPEND (B_USER + 6)
#define B_MOVE (B_USER + 7)
#ifdef ENABLE_VFS
#define B_FREE_ALL_VFS (B_USER + 8)
#define B_REFRESH_VFS (B_USER + 9)
#define B_FREE_ALL_VFS (B_USER + 8)
#define B_REFRESH_VFS (B_USER + 9)
#endif
int hotlist_has_dot_dot = 1;
@ -232,13 +232,15 @@ update_path_name (void)
dlg_redraw (dlg);
}
#define CHECK_BUFFER \
do { \
int i; \
\
if ((i = strlen (current->label) + 3) > buflen) { \
#define CHECK_BUFFER \
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)
@ -933,9 +935,9 @@ static int
add_new_entry_input (const char *header, const char *text1, const char *text2,
const char *help, char **r1, char **r2)
{
#define RELATIVE_Y_BUTTONS 4
#define RELATIVE_Y_LABEL_PTH 3
#define RELATIVE_Y_INPUT_PTH 4
#define RELATIVE_Y_BUTTONS 4
#define RELATIVE_Y_LABEL_PTH 3
#define RELATIVE_Y_INPUT_PTH 4
QuickWidget quick_widgets[] = {
/* 0 */ QUICK_BUTTON (55, 80, RELATIVE_Y_BUTTONS, 0, N_("&Cancel"), B_CANCEL, NULL),
@ -1278,11 +1280,11 @@ load_group (struct hotlist *grp)
#define TKN_ENTRY 1
#define TKN_STRING 2
#define TKN_URL 3
#define TKN_ENDGROUP 4
#define TKN_COMMENT 5
#define TKN_EOL 125
#define TKN_EOF 126
#define TKN_UNKNOWN 127
#define TKN_ENDGROUP 4
#define TKN_COMMENT 5
#define TKN_EOL 125
#define TKN_EOF 126
#define TKN_UNKNOWN 127
static GString *tkn_buf = NULL;
@ -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

View File

@ -6,9 +6,9 @@
#ifndef MC_HOTLIST_H
#define MC_HOTLIST_H
#define LIST_VFSLIST 0x01
#define LIST_HOTLIST 0x02
#define LIST_MOVELIST 0x04
#define LIST_VFSLIST 0x01
#define LIST_HOTLIST 0x02
#define LIST_MOVELIST 0x04
void add2hotlist_cmd (void);
char *hotlist_cmd (int list_vfs);

View File

@ -17,7 +17,7 @@ typedef struct key_config_t {
} key_config_t;
/* The global keymaps are of this type */
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
#define KEYMAP_SHORTCUT_LENGTH 32 /* FIXME: is 32 bytes enough for shortcut? */
typedef struct global_keymap_t {
long key;
unsigned long command;

View File

@ -49,15 +49,15 @@
#include "learn.h"
#include "wtools.h"
#define UX 4
#define UY 3
#define UX 4
#define UY 3
#define BY UY + 17
#define BY UY + 17
#define ROWS 13
#define COLSHIFT 23
#define ROWS 13
#define COLSHIFT 23
#define BUTTONS 2
#define BUTTONS 2
static struct {
int ret_cmd, flags, y, x;

View File

@ -51,14 +51,14 @@
#include "main.h"
#include "listmode.h"
#define UX 5
#define UY 2
#define UX 5
#define UY 2
#define BX 5
#define BY 18
#define BX 5
#define BY 18
#define B_ADD B_USER
#define B_REMOVE (B_USER + 1)
#define B_ADD B_USER
#define B_REMOVE (B_USER + 1)
static WListbox *l_listmode;

View File

@ -17,7 +17,7 @@
#define selection(p) (&(p->dir.list[p->selected]))
#define DEFAULT_USER_FORMAT "half type name | size | perm"
#define LIST_TYPES 4
#define LIST_TYPES 4
enum list_types {
list_full, /* Name, size, perm/date */
@ -116,9 +116,9 @@ void panel_set_sort_order (WPanel *panel, const panel_field_t *sort_order);
void panel_re_sort (WPanel *panel);
void panel_change_encoding (WPanel * panel);
#define UP_OPTIMIZE 0
#define UP_RELOAD 1
#define UP_ONLY_CURRENT 2
#define UP_OPTIMIZE 0
#define UP_RELOAD 1
#define UP_ONLY_CURRENT 2
#define UP_KEEPSEL ((char *) -1)

Some files were not shown because too many files have changed in this diff Show More