mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-10 21:42:00 +03:00
Merge branch '2097_cleanup_master'
* 2097_cleanup_master: (23 commits) Fixed errors and warnings in compilation stage. More accuracy of Diff Viewer conditiona compilation. Type accuracy in feed_subshell() function. Fixed messages of PCRE check. Ticket #2097: ChangeLog in its current form does not strictly make any sense Ticket #2127: updated file extension for "sh" vfs_timeout and use_netrc variables were moved to vfs.h file. Set maximum width of help window to 80 symbols. Minor optimization of show_version() function. Removed unused src/ecs* files and related stuff. Minor optimization of tty_draw_box() function. Removed uneeded extra assignment of command line complete flags. Changed function argument names. Fixed formatting after indentation. Ticket #1949: complete initialization of structures in src/args.c. Ticket #2041: check return value of g_strdup_printf() in mc_log(). Ticket #2078: changed return value of init_translation_table() function. Use EXIT_FAILURE symbolic name as return code. Removed unneeded break after return. Ticket #2119: some trivial corrections. ...
This commit is contained in:
commit
f4e369c222
@ -1,2 +1,3 @@
|
||||
See
|
||||
git log
|
||||
For the major changes since the last release please see doc/NEWS. For
|
||||
the detailed commit log please refer to the output of 'git log' against
|
||||
a checked out copy of the repository.
|
||||
|
@ -135,14 +135,6 @@ aux*)
|
||||
;;
|
||||
esac
|
||||
|
||||
dnl Extended Character Sets
|
||||
dnl
|
||||
AC_ARG_ENABLE([extcharset],
|
||||
AC_HELP_STRING([--enable-extcharset], [Enable extended character sets]))
|
||||
if test x"$enable_extcharset" = x"yes"; then
|
||||
AC_DEFINE([EXTCHARSET_ENABLED], 1, [Enable extended character sets?])
|
||||
fi
|
||||
|
||||
AC_PROG_INSTALL
|
||||
AC_CHECK_HEADERS([unistd.h string.h memory.h limits.h malloc.h \
|
||||
utime.h fcntl.h sys/statfs.h sys/vfs.h sys/time.h \
|
||||
|
@ -115,7 +115,7 @@ mc_fhl_parse_get_regexp (mc_fhl_t * fhl, const gchar * group_name)
|
||||
mc_filter = g_new0 (mc_fhl_filter_t, 1);
|
||||
mc_filter->type = MC_FLHGH_T_FREGEXP;
|
||||
mc_filter->search_condition = mc_search_new (regexp, -1);
|
||||
mc_filter->search_condition->is_case_sentitive = TRUE;
|
||||
mc_filter->search_condition->is_case_sensitive = TRUE;
|
||||
mc_filter->search_condition->search_type = MC_SEARCH_T_REGEX;
|
||||
|
||||
mc_fhl_parse_fill_color_info (mc_filter, fhl, group_name);
|
||||
@ -165,7 +165,7 @@ mc_fhl_parse_get_extensions (mc_fhl_t * fhl, const gchar * group_name)
|
||||
mc_filter = g_new0 (mc_fhl_filter_t, 1);
|
||||
mc_filter->type = MC_FLHGH_T_FREGEXP;
|
||||
mc_filter->search_condition = mc_search_new (buf->str, -1);
|
||||
mc_filter->search_condition->is_case_sentitive =
|
||||
mc_filter->search_condition->is_case_sensitive =
|
||||
mc_config_get_bool (fhl->config, group_name, "extensions_case", TRUE);
|
||||
mc_filter->search_condition->search_type = MC_SEARCH_T_REGEX;
|
||||
|
||||
|
@ -67,11 +67,14 @@ mc_log(const char *fmt, ...)
|
||||
if (is_logging_enabled()) {
|
||||
va_start(args, fmt);
|
||||
logfilename = g_strdup_printf("%s/%s/log", home_dir, MC_USERCONF_DIR);
|
||||
if ((f = fopen(logfilename, "a")) != NULL) {
|
||||
if (logfilename != NULL) {
|
||||
f = fopen (logfilename, "a");
|
||||
if (f != NULL) {
|
||||
(void)vfprintf(f, fmt, args);
|
||||
(void)fclose(f);
|
||||
}
|
||||
g_free(logfilename);
|
||||
va_end(args);
|
||||
}
|
||||
g_free(logfilename);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
10
lib/search.h
10
lib/search.h
@ -58,8 +58,8 @@ typedef struct mc_search_struct {
|
||||
/* search in all charsets */
|
||||
gboolean is_all_charsets;
|
||||
|
||||
/* case sentitive search */
|
||||
gboolean is_case_sentitive;
|
||||
/* case sensitive search */
|
||||
gboolean is_case_sensitive;
|
||||
|
||||
/* search only once. Is this for replace? */
|
||||
gboolean is_once_only;
|
||||
@ -87,7 +87,7 @@ typedef struct mc_search_struct {
|
||||
|
||||
off_t start_buffer;
|
||||
/* some data for regexp */
|
||||
int num_rezults;
|
||||
int num_results;
|
||||
mc_search_matchinfo_t *regex_match_info;
|
||||
GString *regex_buffer;
|
||||
#ifdef SEARCH_TYPE_PCRE
|
||||
@ -140,7 +140,7 @@ gchar **mc_search_get_types_strings_array (size_t *num);
|
||||
|
||||
gboolean mc_search (const gchar *, const gchar *, mc_search_type_t);
|
||||
|
||||
int mc_search_getstart_rezult_by_num (mc_search_t *, int);
|
||||
int mc_search_getend_rezult_by_num (mc_search_t *, int);
|
||||
int mc_search_getstart_result_by_num (mc_search_t *, int);
|
||||
int mc_search_getend_result_by_num (mc_search_t *, int);
|
||||
|
||||
#endif
|
||||
|
@ -271,12 +271,12 @@ mc_search__regex_found_cond_one (mc_search_t * lc_mc_search, mc_search_regex_t *
|
||||
}
|
||||
return COND__NOT_FOUND;
|
||||
}
|
||||
lc_mc_search->num_rezults = g_match_info_get_match_count (lc_mc_search->regex_match_info);
|
||||
lc_mc_search->num_results = g_match_info_get_match_count (lc_mc_search->regex_match_info);
|
||||
#else /* SEARCH_TYPE_GLIB */
|
||||
lc_mc_search->num_rezults = pcre_exec (regex, lc_mc_search->regex_match_info,
|
||||
lc_mc_search->num_results = pcre_exec (regex, lc_mc_search->regex_match_info,
|
||||
search_str->str, search_str->len - 1, 0, 0,
|
||||
lc_mc_search->iovector, MC_SEARCH__NUM_REPLACE_ARGS);
|
||||
if (lc_mc_search->num_rezults < 0)
|
||||
if (lc_mc_search->num_results < 0)
|
||||
{
|
||||
return COND__NOT_FOUND;
|
||||
}
|
||||
@ -530,7 +530,7 @@ mc_search__cond_struct_new_init_regex (const char *charset, mc_search_t * lc_mc_
|
||||
int erroffset;
|
||||
#endif /* SEARCH_TYPE_GLIB */
|
||||
|
||||
if (!lc_mc_search->is_case_sentitive)
|
||||
if (!lc_mc_search->is_case_sensitive)
|
||||
{
|
||||
tmp = g_string_new_len (mc_search_cond->str->str, mc_search_cond->str->len);
|
||||
g_string_free (mc_search_cond->str, TRUE);
|
||||
@ -675,10 +675,10 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
|
||||
num_replace_tokens =
|
||||
mc_search_regex__get_max_num_of_replace_tokens (replace_str->str, replace_str->len);
|
||||
|
||||
if (lc_mc_search->num_rezults < 0)
|
||||
if (lc_mc_search->num_results < 0)
|
||||
return g_string_new_len (replace_str->str, replace_str->len);
|
||||
|
||||
if (num_replace_tokens > lc_mc_search->num_rezults - 1
|
||||
if (num_replace_tokens > lc_mc_search->num_results - 1
|
||||
|| num_replace_tokens > MC_SEARCH__NUM_REPLACE_ARGS)
|
||||
{
|
||||
lc_mc_search->error = MC_SEARCH_E_REGEX_REPLACE;
|
||||
@ -718,7 +718,7 @@ mc_search_regex_prepare_replace_str (mc_search_t * lc_mc_search, GString * repla
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lc_index > lc_mc_search->num_rezults)
|
||||
if (lc_index > lc_mc_search->num_results)
|
||||
{
|
||||
g_string_free (ret, TRUE);
|
||||
lc_mc_search->error = MC_SEARCH_E_REGEX_REPLACE;
|
||||
|
@ -376,7 +376,7 @@ mc_search (const gchar * pattern, const gchar * str, mc_search_type_t type)
|
||||
if (search == NULL)
|
||||
return FALSE;
|
||||
search->search_type = type;
|
||||
search->is_case_sentitive = TRUE;
|
||||
search->is_case_sensitive = TRUE;
|
||||
|
||||
if (type == MC_SEARCH_T_GLOB)
|
||||
search->is_entire_line = TRUE;
|
||||
@ -389,7 +389,7 @@ mc_search (const gchar * pattern, const gchar * str, mc_search_type_t type)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_search_getstart_rezult_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||
mc_search_getstart_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||
{
|
||||
if (!lc_mc_search)
|
||||
return 0;
|
||||
@ -411,7 +411,7 @@ mc_search_getstart_rezult_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
mc_search_getend_rezult_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||
mc_search_getend_result_by_num (mc_search_t * lc_mc_search, int lc_index)
|
||||
{
|
||||
if (!lc_mc_search)
|
||||
return 0;
|
||||
|
@ -1576,7 +1576,7 @@ get_key_code (int no_delay)
|
||||
if (this == NULL) {
|
||||
/* Shouldn't happen */
|
||||
fputs ("Internal error\n", stderr);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
goto nodelay_try_again;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ tty_init (gboolean slow, gboolean ugly_lines)
|
||||
fprintf (stderr,
|
||||
_("Screen size %dx%d is not supported.\n"
|
||||
"Check the TERM environment variable.\n"), COLS, LINES);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
tcgetattr (fileno (stdin), &boot_mode);
|
||||
@ -394,7 +394,7 @@ tty_lowlevel_getch (void)
|
||||
fprintf (stderr,
|
||||
"SLang_getkey returned SLANG_GETKEY_ERROR\n"
|
||||
"Assuming EOF on stdin and exiting\n");
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return c;
|
||||
|
@ -140,17 +140,20 @@ tty_print_one_vline (gboolean single)
|
||||
void
|
||||
tty_draw_box (int y, int x, int ys, int xs, gboolean single)
|
||||
{
|
||||
ys--;
|
||||
xs--;
|
||||
|
||||
tty_draw_vline (y, x, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
|
||||
tty_draw_vline (y, x + xs - 1, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
|
||||
tty_draw_vline (y, x + xs, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
|
||||
tty_draw_hline (y, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
|
||||
tty_draw_hline (y + ys - 1, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
|
||||
tty_draw_hline (y + ys, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
|
||||
tty_gotoyx (y, x);
|
||||
tty_print_alt_char (ACS_ULCORNER, single);
|
||||
tty_gotoyx (y + ys - 1, x);
|
||||
tty_gotoyx (y + ys, x);
|
||||
tty_print_alt_char (ACS_LLCORNER, single);
|
||||
tty_gotoyx (y, x + xs - 1);
|
||||
tty_gotoyx (y, x + xs);
|
||||
tty_print_alt_char (ACS_URCORNER, single);
|
||||
tty_gotoyx (y + ys - 1, x + xs - 1);
|
||||
tty_gotoyx (y + ys, x + xs);
|
||||
tty_print_alt_char (ACS_LRCORNER, single);
|
||||
}
|
||||
|
||||
|
12
lib/util.c
12
lib/util.c
@ -526,13 +526,15 @@ strip_password (char *p, int has_prefix)
|
||||
|
||||
if (has_prefix)
|
||||
{
|
||||
if ((q = strstr (p, prefixes[i].name)) == 0)
|
||||
q = strstr (p, prefixes[i].name);
|
||||
if (q == NULL)
|
||||
continue;
|
||||
else
|
||||
p = q + prefixes[i].len;
|
||||
}
|
||||
|
||||
if ((dir = strchr (p, PATH_SEP)) != NULL)
|
||||
dir = strchr (p, PATH_SEP);
|
||||
if (dir != NULL)
|
||||
*dir = '\0';
|
||||
|
||||
/* search for any possible user */
|
||||
@ -559,7 +561,8 @@ strip_home_and_password (const char *dir)
|
||||
size_t len;
|
||||
static char newdir[MC_MAXPATHLEN];
|
||||
|
||||
if (home_dir && !strncmp (dir, home_dir, len = strlen (home_dir)) &&
|
||||
len = strlen (home_dir);
|
||||
if (home_dir != NULL && strncmp (dir, home_dir, len) == 0 &&
|
||||
(dir[len] == PATH_SEP || dir[len] == '\0'))
|
||||
{
|
||||
newdir[0] = '~';
|
||||
@ -619,7 +622,8 @@ load_file (const char *filename)
|
||||
char *data;
|
||||
long read_size;
|
||||
|
||||
if ((data_file = fopen (filename, "r")) == NULL)
|
||||
data_file = fopen (filename, "r");
|
||||
if (data_file == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
11
lib/util.h
11
lib/util.h
@ -280,15 +280,16 @@ const char *Q_ (const char *s);
|
||||
* We can't use str*cpy funs here:
|
||||
* http://kerneltrap.org/mailarchive/openbsd-misc/2008/5/27/1951294
|
||||
*/
|
||||
static inline char * str_move(char * dest, const char * src)
|
||||
static inline char *
|
||||
str_move (char *dest, const char *src)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
assert (dest<=src);
|
||||
assert (dest <= src);
|
||||
|
||||
n = strlen (src) + 1; /* + '\0' */
|
||||
|
||||
return memmove (dest, src, n);
|
||||
return (char *) memmove (dest, src, n);
|
||||
}
|
||||
|
||||
gboolean mc_util_make_backup_if_possible (const char *, const char *);
|
||||
@ -297,6 +298,6 @@ 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)
|
||||
#define MC_PTR_FREE(ptr) do { g_free (ptr); (ptr) = NULL; } while (0)
|
||||
|
||||
#endif
|
||||
#endif /* MC_UTIL_H */
|
||||
|
@ -94,11 +94,12 @@ get_owner (int uid)
|
||||
char *name;
|
||||
static int uid_last;
|
||||
|
||||
if ((name = i_cache_match (uid, uid_cache, UID_CACHE_SIZE)) != NULL)
|
||||
name = i_cache_match (uid, uid_cache, UID_CACHE_SIZE);
|
||||
if (name != NULL)
|
||||
return name;
|
||||
|
||||
pwd = getpwuid (uid);
|
||||
if (pwd)
|
||||
if (pwd != NULL)
|
||||
{
|
||||
i_cache_add (uid, uid_cache, UID_CACHE_SIZE, pwd->pw_name, &uid_last);
|
||||
return pwd->pw_name;
|
||||
@ -118,11 +119,12 @@ get_group (int gid)
|
||||
char *name;
|
||||
static int gid_last;
|
||||
|
||||
if ((name = i_cache_match (gid, gid_cache, GID_CACHE_SIZE)) != NULL)
|
||||
name = i_cache_match (gid, gid_cache, GID_CACHE_SIZE);
|
||||
if (name != NULL)
|
||||
return name;
|
||||
|
||||
grp = getgrgid (gid);
|
||||
if (grp)
|
||||
if (grp != NULL)
|
||||
{
|
||||
i_cache_add (gid, gid_cache, GID_CACHE_SIZE, grp->gr_name, &gid_last);
|
||||
return grp->gr_name;
|
||||
@ -161,7 +163,8 @@ my_system (int flags, const char *shell, const char *command)
|
||||
/* handler messing the screen after the SIGCONT */
|
||||
sigaction (SIGTSTP, &startup_handler, &save_stop);
|
||||
|
||||
if ((pid = fork ()) < 0)
|
||||
pid = fork ();
|
||||
if (pid < 0)
|
||||
{
|
||||
fprintf (stderr, "\n\nfork () = -1\n");
|
||||
return -1;
|
||||
@ -179,12 +182,12 @@ my_system (int flags, const char *shell, const char *command)
|
||||
{
|
||||
gchar **shell_tokens;
|
||||
const gchar *only_cmd;
|
||||
shell_tokens = g_strsplit (shell, " ", 2);
|
||||
|
||||
shell_tokens = g_strsplit (shell, " ", 2);
|
||||
if (shell_tokens == NULL)
|
||||
only_cmd = shell;
|
||||
else
|
||||
only_cmd = (*shell_tokens) ? *shell_tokens : shell;
|
||||
only_cmd = (*shell_tokens != NULL) ? *shell_tokens : shell;
|
||||
|
||||
execlp (only_cmd, shell, command, (char *) NULL);
|
||||
|
||||
|
@ -165,7 +165,8 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
|
||||
mode_t mode;
|
||||
struct vfs_s_inode *root;
|
||||
|
||||
if ((fd = mc_open (name, O_RDONLY)) == -1) {
|
||||
fd = mc_open (name, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), name);
|
||||
return -1;
|
||||
}
|
||||
@ -181,7 +182,8 @@ cpio_open_cpio_file (struct vfs_class *me, struct vfs_s_super *super,
|
||||
|
||||
mc_close (fd);
|
||||
s = g_strconcat (name, decompress_extension (type), (char *) NULL);
|
||||
if ((fd = mc_open (s, O_RDONLY)) == -1) {
|
||||
fd = mc_open (s, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
message (D_ERROR, MSG_ERROR, _("Cannot open cpio archive\n%s"), s);
|
||||
g_free (s);
|
||||
return -1;
|
||||
@ -247,7 +249,8 @@ static int cpio_find_head(struct vfs_class *me, struct vfs_s_super *super)
|
||||
ptr -= top - 128;
|
||||
top = 128;
|
||||
}
|
||||
if((tmp = mc_read(super->u.arch.fd, buf, top)) == 0 || tmp == -1) {
|
||||
tmp = mc_read (super->u.arch.fd, buf, top);
|
||||
if (tmp == 0 || tmp == -1) {
|
||||
message (D_ERROR, MSG_ERROR, _("Premature end of cpio archive\n%s"), super->name);
|
||||
cpio_free_archive(me, super);
|
||||
return CPIO_UNKNOWN;
|
||||
@ -419,7 +422,8 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
|
||||
char *name;
|
||||
struct stat st;
|
||||
|
||||
if((len = mc_read(super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH)) < HEAD_LENGTH)
|
||||
len = mc_read (super->u.arch.fd, (char *)&u.buf, HEAD_LENGTH);
|
||||
if (len < HEAD_LENGTH)
|
||||
return STATUS_EOF;
|
||||
CPIO_POS(super) += len;
|
||||
if(super->u.arch.type == CPIO_BINRE) {
|
||||
@ -435,7 +439,8 @@ static ssize_t cpio_read_bin_head(struct vfs_class *me, struct vfs_s_super *supe
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
name = g_malloc(u.buf.c_namesize);
|
||||
if((len = mc_read(super->u.arch.fd, name, u.buf.c_namesize)) < u.buf.c_namesize) {
|
||||
len = mc_read (super->u.arch.fd, name, u.buf.c_namesize);
|
||||
if (len < u.buf.c_namesize) {
|
||||
g_free(name);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
@ -493,8 +498,8 @@ static ssize_t cpio_read_oldc_head(struct vfs_class *me, struct vfs_s_super *sup
|
||||
return STATUS_FAIL;
|
||||
}
|
||||
name = g_malloc(hd.c_namesize);
|
||||
if((len = mc_read(super->u.arch.fd, name, hd.c_namesize)) == -1 ||
|
||||
(unsigned long) len < hd.c_namesize) {
|
||||
len = mc_read (super->u.arch.fd, name, hd.c_namesize);
|
||||
if ((len == -1) || ((unsigned long) len < hd.c_namesize)) {
|
||||
g_free (name);
|
||||
return STATUS_EOF;
|
||||
}
|
||||
@ -669,7 +674,9 @@ static ssize_t cpio_read(void *fh, char *buffer, int count)
|
||||
|
||||
count = MIN(count, FH->ino->st.st_size - FH->pos);
|
||||
|
||||
if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
|
||||
count = mc_read (fd, buffer, count);
|
||||
if (count == -1)
|
||||
ERRNOR (errno, -1);
|
||||
|
||||
FH->pos += count;
|
||||
return count;
|
||||
|
@ -493,11 +493,14 @@ vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **
|
||||
|
||||
archive_name = inname;
|
||||
vfs_split (inname, &local, &op);
|
||||
retval = (local) ? local : "";
|
||||
retval = (local != NULL) ? local : "";
|
||||
|
||||
if (MEDATA->archive_check)
|
||||
if (!(cookie = MEDATA->archive_check (me, archive_name, op)))
|
||||
if (MEDATA->archive_check != NULL)
|
||||
{
|
||||
cookie = MEDATA->archive_check (me, archive_name, op);
|
||||
if (cookie == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (super = MEDATA->supers; super != NULL; super = super->next)
|
||||
{
|
||||
@ -686,7 +689,9 @@ static int
|
||||
vfs_s_chdir (struct vfs_class *me, const char *path)
|
||||
{
|
||||
void *data;
|
||||
if (!(data = vfs_s_opendir (me, path)))
|
||||
|
||||
data = vfs_s_opendir (me, path);
|
||||
if (data == NULL)
|
||||
return -1;
|
||||
vfs_s_closedir (data);
|
||||
return 0;
|
||||
@ -699,7 +704,8 @@ vfs_s_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, i
|
||||
{
|
||||
struct vfs_s_inode *ino;
|
||||
|
||||
if (!(ino = vfs_s_inode_from_path (me, path, flag)))
|
||||
ino = vfs_s_inode_from_path (me, path, flag);
|
||||
if (ino == NULL)
|
||||
return -1;
|
||||
*buf = ino->st;
|
||||
return 0;
|
||||
@ -757,7 +763,8 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, int mode)
|
||||
char *q;
|
||||
struct vfs_s_inode *ino;
|
||||
|
||||
if ((q = vfs_s_get_path (me, file, &super, 0)) == NULL)
|
||||
q = vfs_s_get_path (me, file, &super, 0);
|
||||
if (q == NULL)
|
||||
return NULL;
|
||||
ino = vfs_s_find_inode (me, super, q, LINK_FOLLOW, FL_NONE);
|
||||
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)))
|
||||
@ -1115,7 +1122,7 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
||||
{
|
||||
struct vfs_s_inode *ino = vfs_s_inode_from_path (me, path, 0);
|
||||
|
||||
if (!ino)
|
||||
if (ino == NULL)
|
||||
return 0;
|
||||
if (arg)
|
||||
ino->super->want_stale = 1;
|
||||
@ -1142,10 +1149,11 @@ vfs_s_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
||||
static vfsid
|
||||
vfs_s_getid (struct vfs_class *me, const char *path)
|
||||
{
|
||||
struct vfs_s_super *archive;
|
||||
struct vfs_s_super *archive = NULL;
|
||||
char *p;
|
||||
|
||||
if (!(p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN)))
|
||||
p = vfs_s_get_path (me, path, &archive, FL_NO_OPEN);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
g_free (p);
|
||||
return (vfsid) archive;
|
||||
|
@ -20,8 +20,7 @@
|
||||
# 2004: Whitespace(s) & single quote(s) in filename workaround
|
||||
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=64007
|
||||
# Slava Zanko <slavazanko@gmail.com>
|
||||
# 2009: Totally rewrited.
|
||||
# ALTLinux users have strange artefacts with single quote(s)
|
||||
# 2009: Totally rewritten.
|
||||
#
|
||||
# This file is part of the Midnight Commander.
|
||||
#
|
||||
|
@ -206,7 +206,9 @@ fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
||||
if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0))
|
||||
vfs_die ("Cannot pipe(): %m.");
|
||||
|
||||
if ((res = fork ()))
|
||||
res = fork ();
|
||||
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
vfs_die ("Cannot fork(): %m.");
|
||||
@ -828,18 +830,17 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo
|
||||
close (h);
|
||||
h = open ("/dev/zero", O_RDONLY);
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
if ((t = write (SUP.sockw, buffer, n)) != n)
|
||||
|
||||
t = write (SUP.sockw, buffer, n);
|
||||
if (t != n)
|
||||
{
|
||||
if (t == -1)
|
||||
{
|
||||
me->verrno = errno;
|
||||
}
|
||||
else
|
||||
{
|
||||
me->verrno = EIO;
|
||||
}
|
||||
goto error_return;
|
||||
}
|
||||
tty_disable_interrupt_key ();
|
||||
@ -923,14 +924,15 @@ fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
||||
do
|
||||
{
|
||||
n = MIN (8192, fh->u.fish.total - fh->u.fish.got);
|
||||
if (n)
|
||||
if (n != 0)
|
||||
{
|
||||
if ((n = read (SUP.sockr, buffer, n)) < 0)
|
||||
n = read (SUP.sockr, buffer, n);
|
||||
if (n < 0)
|
||||
return;
|
||||
fh->u.fish.got += n;
|
||||
}
|
||||
}
|
||||
while (n);
|
||||
while (n != 0);
|
||||
|
||||
if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
|
||||
print_vfs_message (_("Error reported after abort."));
|
||||
@ -955,9 +957,9 @@ fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, int len)
|
||||
|
||||
if (n > 0)
|
||||
fh->u.fish.got += n;
|
||||
if (n < 0)
|
||||
else if (n < 0)
|
||||
fish_linear_abort (me, fh);
|
||||
if ((!n) && ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)))
|
||||
else if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
|
||||
ERRNOR (E_REMOTE, -1);
|
||||
ERRNOR (errno, n);
|
||||
}
|
||||
@ -1018,17 +1020,18 @@ fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *
|
||||
const char *crpath; \
|
||||
char *rpath, *mpath = g_strdup (path); \
|
||||
struct vfs_s_super *super; \
|
||||
if (!(crpath = vfs_s_get_path_mangle (me, mpath, &super, 0))) \
|
||||
crpath = vfs_s_get_path_mangle (me, mpath, &super, 0); \
|
||||
if (crpath == NULL) \
|
||||
{ \
|
||||
g_free (mpath); \
|
||||
return -1; \
|
||||
} \
|
||||
rpath = strutils_shell_escape(crpath); \
|
||||
rpath = strutils_shell_escape (crpath); \
|
||||
g_free (mpath);
|
||||
|
||||
#define POSTFIX(flags) \
|
||||
g_free (rpath); \
|
||||
return fish_send_command(me, super, buf, flags);
|
||||
return fish_send_command (me, super, buf, flags);
|
||||
|
||||
static int
|
||||
fish_chmod (struct vfs_class *me, const char *path, int mode)
|
||||
@ -1055,12 +1058,14 @@ static int fish_##name (struct vfs_class *me, const char *path1, const char *pat
|
||||
const char *crpath1, *crpath2; \
|
||||
char *rpath1, *rpath2, *mpath1, *mpath2; \
|
||||
struct vfs_s_super *super1, *super2; \
|
||||
if (!(crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0))) \
|
||||
crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0); \
|
||||
if (crpath1 == NULL) \
|
||||
{ \
|
||||
g_free (mpath1); \
|
||||
return -1; \
|
||||
} \
|
||||
if (!(crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0))) \
|
||||
crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0); \
|
||||
if (crpath2 == NULL) \
|
||||
{ \
|
||||
g_free (mpath1); \
|
||||
g_free (mpath2); \
|
||||
@ -1119,10 +1124,12 @@ fish_chown (struct vfs_class *me, const char *path, int owner, int group)
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
|
||||
if ((pw = getpwuid (owner)) == NULL)
|
||||
pw = getpwuid (owner);
|
||||
if (pw == NULL)
|
||||
return 0;
|
||||
|
||||
if ((gr = getgrgid (group)) == NULL)
|
||||
gr = getgrgid (group);
|
||||
if (gr == NULL)
|
||||
return 0;
|
||||
|
||||
sowner = pw->pw_name;
|
||||
@ -1179,10 +1186,7 @@ fish_exists (struct vfs_class *me, const char *path)
|
||||
|
||||
g_free (rpath);
|
||||
|
||||
if (fish_send_command (me, super, buf, OPT_FLUSH) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return (fish_send_command (me, super, buf, OPT_FLUSH) == 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -227,8 +227,10 @@ ftpfs_translate_path (struct vfs_class *me, struct vfs_s_super *super, const cha
|
||||
memmove (p + 1, p + 2, strlen (p + 2) + 1);
|
||||
|
||||
/* strip trailing "/." */
|
||||
if ((p = strrchr (ret, '/')) && *(p + 1) == '.' && *(p + 2) == '\0')
|
||||
p = strrchr (ret, '/');
|
||||
if ((p != NULL) && (*(p + 1) == '.') && (*(p + 2) == '\0'))
|
||||
*p = '\0';
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@ -608,33 +610,37 @@ ftpfs_load_no_proxy_list (void)
|
||||
return;
|
||||
|
||||
mc_file = concat_dir_and_file (mc_home, "mc.no_proxy");
|
||||
if (exist_file (mc_file) && (npf = fopen (mc_file, "r")))
|
||||
if (exist_file (mc_file))
|
||||
{
|
||||
while (fgets (s, sizeof (s), npf))
|
||||
npf = fopen (mc_file, "r");
|
||||
if (npf != NULL)
|
||||
{
|
||||
if (!(p = strchr (s, '\n')))
|
||||
{ /* skip bogus entries */
|
||||
while ((c = fgetc (npf)) != EOF && c != '\n')
|
||||
;
|
||||
continue;
|
||||
while (fgets (s, sizeof (s), npf) != NULL)
|
||||
{
|
||||
p = strchr (s, '\n');
|
||||
if (p == NULL) /* skip bogus entries */
|
||||
{
|
||||
while ((c = fgetc (npf)) != EOF && c != '\n')
|
||||
;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p == s)
|
||||
continue;
|
||||
|
||||
*p = '\0';
|
||||
|
||||
np = g_new (struct no_proxy_entry, 1);
|
||||
np->domain = g_strdup (s);
|
||||
np->next = NULL;
|
||||
if (no_proxy)
|
||||
current->next = np;
|
||||
else
|
||||
no_proxy = np;
|
||||
current = np;
|
||||
}
|
||||
|
||||
if (p == s)
|
||||
continue;
|
||||
|
||||
*p = '\0';
|
||||
|
||||
np = g_new (struct no_proxy_entry, 1);
|
||||
np->domain = g_strdup (s);
|
||||
np->next = NULL;
|
||||
if (no_proxy)
|
||||
current->next = np;
|
||||
else
|
||||
no_proxy = np;
|
||||
current = np;
|
||||
fclose (npf);
|
||||
}
|
||||
|
||||
fclose (npf);
|
||||
}
|
||||
g_free (mc_file);
|
||||
}
|
||||
@ -1169,10 +1175,12 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
|
||||
{
|
||||
struct sockaddr_storage from;
|
||||
int s, j, data;
|
||||
socklen_t fromlen = sizeof (from);
|
||||
socklen_t fromlen = sizeof(from);
|
||||
|
||||
if ((s = ftpfs_initconn (me, super)) == -1)
|
||||
s = ftpfs_initconn (me, super);
|
||||
if (s == -1)
|
||||
return -1;
|
||||
|
||||
if (ftpfs_changetype (me, super, isbinary) == -1)
|
||||
return -1;
|
||||
if (reget > 0)
|
||||
@ -1191,6 +1199,7 @@ ftpfs_open_data_connection (struct vfs_class *me, struct vfs_s_super *super, con
|
||||
}
|
||||
else
|
||||
j = ftpfs_command (me, super, WAIT_REPLY, "%s", cmd);
|
||||
|
||||
if (j != PRELIM)
|
||||
ERRNOR (EPERM, -1);
|
||||
tty_enable_interrupt_key ();
|
||||
@ -1750,7 +1759,8 @@ ftpfs_send_command (struct vfs_class *me, const char *filename, const char *cmd,
|
||||
int r;
|
||||
int flush_directory_cache = (flags & OPT_FLUSH);
|
||||
|
||||
if (!(rpath = vfs_s_get_path_mangle (me, mpath, &super, 0)))
|
||||
rpath = vfs_s_get_path_mangle (me, mpath, &super, 0);
|
||||
if (rpath == NULL)
|
||||
{
|
||||
g_free (mpath);
|
||||
return -1;
|
||||
@ -2216,8 +2226,10 @@ ftpfs_netrc_lookup (const char *host, char **login, char **pass)
|
||||
|
||||
/* Find our own domain name */
|
||||
if (gethostname (hostname, sizeof (hostname)) < 0)
|
||||
*hostname = 0;
|
||||
if (!(domain = strchr (hostname, '.')))
|
||||
*hostname = '\0';
|
||||
|
||||
domain = strchr (hostname, '.');
|
||||
if (domain == NULL)
|
||||
domain = "";
|
||||
|
||||
/* Scan for "default" and matching "machine" keywords */
|
||||
|
@ -9,15 +9,14 @@
|
||||
|
||||
#include "vfs-impl.h"
|
||||
|
||||
struct vfs_stamping {
|
||||
struct vfs_stamping
|
||||
{
|
||||
struct vfs_class *v;
|
||||
vfsid id;
|
||||
struct vfs_stamping *next;
|
||||
struct timeval time;
|
||||
};
|
||||
|
||||
extern int vfs_timeout;
|
||||
|
||||
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);
|
||||
@ -29,4 +28,4 @@ void vfs_release_path (const char *dir);
|
||||
vfsid vfs_getid (struct vfs_class *vclass, const char *dir);
|
||||
void vfs_gc_done (void);
|
||||
|
||||
#endif /* __GC_H */
|
||||
#endif /* MC_VFS_GC_H */
|
||||
|
@ -212,7 +212,8 @@ mcfs_get_remote_port (struct sockaddr_in *sin, int *version)
|
||||
#ifdef HAVE_PMAP_GETPORT
|
||||
int port;
|
||||
for (*version = RPC_PROGVER; *version >= 1; (*version)--)
|
||||
if (port = pmap_getport (sin, RPC_PROGNUM, *version, IPPROTO_TCP))
|
||||
port = pmap_getport (sin, RPC_PROGNUM, *version, IPPROTO_TCP);
|
||||
if (port != NULL)
|
||||
return port;
|
||||
#endif /* HAVE_PMAP_GETPORT */
|
||||
*version = 1;
|
||||
@ -237,11 +238,13 @@ mcfs_create_tcp_link (const char *host, int *port, int *version, const char *cal
|
||||
server_address.sin_family = AF_INET;
|
||||
|
||||
/* Try to use the dotted decimal number */
|
||||
if ((inaddr = inet_addr (host)) != INADDR_NONE)
|
||||
inaddr = inet_addr (host);
|
||||
if (inaddr != INADDR_NONE) {
|
||||
memcpy ((char *) &server_address.sin_addr, (char *) &inaddr,
|
||||
sizeof (inaddr));
|
||||
else {
|
||||
if ((hp = gethostbyname (host)) == NULL) {
|
||||
} else {
|
||||
hp = gethostbyname (host);
|
||||
if (hp == NULL) {
|
||||
message (D_ERROR, caller, _(" Cannot locate hostname: %s "),
|
||||
host);
|
||||
return 0;
|
||||
@ -259,8 +262,8 @@ mcfs_create_tcp_link (const char *host, int *port, int *version, const char *cal
|
||||
*version = 1;
|
||||
|
||||
server_address.sin_port = htons (*port);
|
||||
|
||||
if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
my_socket = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (my_socket < 0) {
|
||||
message (D_ERROR, caller, _(" Cannot create socket: %s "),
|
||||
unix_error_string (errno));
|
||||
return 0;
|
||||
@ -340,10 +343,8 @@ mcfs_open_link (char *host, char *user, int *port, char *netrcpass)
|
||||
message (D_ERROR, MSG_ERROR, _(" Too many open connections "));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!
|
||||
(sock =
|
||||
mcfs_open_tcp_link (host, user, port, netrcpass, &version)))
|
||||
sock = mcfs_open_tcp_link (host, user, port, netrcpass, &version);
|
||||
if (sock == 0)
|
||||
return 0;
|
||||
|
||||
bucket = mcfs_get_free_bucket ();
|
||||
@ -394,12 +395,14 @@ mcfs_get_path (mcfs_connection **mc, const char *path)
|
||||
* remote portmapper to get the port number
|
||||
*/
|
||||
port = 0;
|
||||
if ((remote_path =
|
||||
mcfs_get_host_and_username (path, &host, &user, &port, &pass)))
|
||||
if (!(*mc = mcfs_open_link (host, user, &port, pass))) {
|
||||
remote_path = mcfs_get_host_and_username (path, &host, &user, &port, &pass);
|
||||
if (remote_path != NULL) {
|
||||
*mc = mcfs_open_link (host, user, &port, pass);
|
||||
if (*mc == NULL) {
|
||||
g_free (remote_path);
|
||||
remote_path = NULL;
|
||||
}
|
||||
}
|
||||
g_free (host);
|
||||
g_free (user);
|
||||
if (pass)
|
||||
@ -445,10 +448,12 @@ mcfs_rpc_two_paths (int command, const char *s1, const char *s2)
|
||||
mcfs_connection *mc;
|
||||
char *r1, *r2;
|
||||
|
||||
if ((r1 = mcfs_get_path (&mc, s1)) == 0)
|
||||
r1 = mcfs_get_path (&mc, s1);
|
||||
if (r1 == NULL)
|
||||
return -1;
|
||||
|
||||
if ((r2 = mcfs_get_path (&mc, s2)) == 0) {
|
||||
r2 = mcfs_get_path (&mc, s2);
|
||||
if (r2 == NULL) {
|
||||
g_free (r1);
|
||||
return -1;
|
||||
}
|
||||
@ -466,7 +471,8 @@ mcfs_rpc_path (int command, const char *path)
|
||||
mcfs_connection *mc;
|
||||
char *remote_file;
|
||||
|
||||
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
||||
remote_file = mcfs_get_path (&mc, path);
|
||||
if (remote_file == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock,
|
||||
@ -482,7 +488,8 @@ mcfs_rpc_path_int (int command, const char *path, int data)
|
||||
mcfs_connection *mc;
|
||||
char *remote_file;
|
||||
|
||||
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
||||
remote_file = mcfs_get_path (&mc, path);
|
||||
if (remote_file == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock,
|
||||
@ -499,7 +506,8 @@ mcfs_rpc_path_int_int (int command, const char *path, int n1, int n2)
|
||||
mcfs_connection *mc;
|
||||
char *remote_file;
|
||||
|
||||
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
||||
remote_file = mcfs_get_path (&mc, path);
|
||||
if (remote_file == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock,
|
||||
@ -537,7 +545,8 @@ mcfs_open (struct vfs_class *me, const char *file, int flags, int mode)
|
||||
|
||||
(void) me;
|
||||
|
||||
if (!(remote_file = mcfs_get_path (&mc, file)))
|
||||
remote_file = mcfs_get_path (&mc, file);
|
||||
if (remote_file == NULL)
|
||||
return 0;
|
||||
|
||||
rpc_send (mc->sock, RPC_INT, MC_OPEN, RPC_STRING, remote_file, RPC_INT,
|
||||
@ -661,8 +670,9 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
|
||||
(void) me;
|
||||
|
||||
if (!(remote_dir = mcfs_get_path (&mc, dirname)))
|
||||
return 0;
|
||||
remote_dir = mcfs_get_path (&mc, dirname);
|
||||
if (remote_dir == NULL)
|
||||
return NULL;
|
||||
|
||||
rpc_send (mc->sock, RPC_INT, MC_OPENDIR, RPC_STRING, remote_dir,
|
||||
RPC_END);
|
||||
@ -670,10 +680,10 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
|
||||
if (0 ==
|
||||
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error_num, RPC_END))
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
if (mcfs_is_error (result, error_num))
|
||||
return 0;
|
||||
return NULL;
|
||||
|
||||
handle = result;
|
||||
|
||||
@ -683,7 +693,7 @@ mcfs_opendir (struct vfs_class *me, const char *dirname)
|
||||
mcfs_info->entries = 0;
|
||||
mcfs_info->current = 0;
|
||||
|
||||
return mcfs_info;
|
||||
return (void *) mcfs_info;
|
||||
}
|
||||
|
||||
static int mcfs_get_stat_info (mcfs_connection * mc, struct stat *buf);
|
||||
@ -880,7 +890,8 @@ mcfs_stat_cmd (int cmd, const char *path, struct stat *buf)
|
||||
mcfs_connection *mc;
|
||||
int status, error;
|
||||
|
||||
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
||||
remote_file = mcfs_get_path (&mc, path);
|
||||
if (remote_file == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock, RPC_INT, cmd, RPC_STRING, remote_file, RPC_END);
|
||||
@ -970,7 +981,8 @@ mcfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
||||
|
||||
(void) me;
|
||||
|
||||
if (!(file = mcfs_get_path (&mc, path)))
|
||||
file = mcfs_get_path (&mc, path);
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
|
||||
status = 0;
|
||||
@ -1005,7 +1017,8 @@ mcfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
||||
|
||||
(void) me;
|
||||
|
||||
if (!(remote_file = mcfs_get_path (&mc, path)))
|
||||
remote_file = mcfs_get_path (&mc, path);
|
||||
if (remote_file == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock, RPC_INT, MC_READLINK, RPC_STRING, remote_file,
|
||||
@ -1062,7 +1075,8 @@ mcfs_chdir (struct vfs_class *me, const char *path)
|
||||
|
||||
(void) me;
|
||||
|
||||
if (!(remote_dir = mcfs_get_path (&mc, path)))
|
||||
remote_dir = mcfs_get_path (&mc, path);
|
||||
if (remote_dir == NULL)
|
||||
return -1;
|
||||
|
||||
rpc_send (mc->sock, RPC_INT, MC_CHDIR, RPC_STRING, remote_dir,
|
||||
@ -1137,12 +1151,11 @@ mcfs_forget (const char *path)
|
||||
return;
|
||||
|
||||
path += 5;
|
||||
if (path[0] == '/' && path[1] == '/')
|
||||
if ((path[0] == '/') && (path[1] == '/'))
|
||||
path += 2;
|
||||
|
||||
if ((p =
|
||||
mcfs_get_host_and_username (path, &host, &user, &port,
|
||||
&pass)) == 0) {
|
||||
p = mcfs_get_host_and_username (path, &host, &user, &port, &pass);
|
||||
if (p == NULL) {
|
||||
g_free (host);
|
||||
g_free (user);
|
||||
if (pass)
|
||||
|
@ -799,15 +799,22 @@ mc_pam_auth (const char *username, const char *password)
|
||||
up.password = password;
|
||||
conv.appdata_ptr = &up;
|
||||
|
||||
if ((status =
|
||||
pam_start ("mcserv", username, &conv, &pamh)) != PAM_SUCCESS)
|
||||
status = pam_start ("mcserv", username, &conv, &pamh);
|
||||
if (status != PAM_SUCCESS)
|
||||
goto failed_pam;
|
||||
if ((status = pam_authenticate (pamh, 0)) != PAM_SUCCESS)
|
||||
|
||||
status = pam_authenticate (pamh, 0);
|
||||
if (status != PAM_SUCCESS)
|
||||
goto failed_pam;
|
||||
if ((status = pam_acct_mgmt (pamh, 0)) != PAM_SUCCESS)
|
||||
|
||||
status = pam_acct_mgmt (pamh, 0);
|
||||
if (status != PAM_SUCCESS)
|
||||
goto failed_pam;
|
||||
if ((status = pam_setcred (pamh, PAM_ESTABLISH_CRED)) != PAM_SUCCESS)
|
||||
|
||||
status = pam_setcred (pamh, PAM_ESTABLISH_CRED);
|
||||
if (status != PAM_SUCCESS)
|
||||
goto failed_pam;
|
||||
|
||||
pam_end (pamh, status);
|
||||
return 0;
|
||||
|
||||
@ -866,11 +873,13 @@ do_ftp_auth (const char *username, const char *password)
|
||||
local_address.sin_port = htons (21);
|
||||
|
||||
/* Convert localhost to usable format */
|
||||
if ((inaddr = inet_addr ("127.0.0.1")) != INADDR_NONE)
|
||||
inaddr = inet_addr ("127.0.0.1");
|
||||
if (inaddr != INADDR_NONE)
|
||||
memcpy ((char *) &local_address.sin_addr, (char *) &inaddr,
|
||||
sizeof (inaddr));
|
||||
|
||||
if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
my_socket = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (my_socket < 0) {
|
||||
if (!isDaemon)
|
||||
fprintf (stderr, "do_auth: can't create socket\n");
|
||||
return 0;
|
||||
@ -916,14 +925,16 @@ do_classic_auth (const char *username, const char *password)
|
||||
struct spwd *spw;
|
||||
#endif
|
||||
|
||||
if ((pw = getpwnam (username)) == 0)
|
||||
pw = getpwnam (username);
|
||||
if (pw == NULL)
|
||||
return 0;
|
||||
|
||||
#ifdef HAVE_SHADOW
|
||||
setspent ();
|
||||
|
||||
/* Password expiration is not checked! */
|
||||
if ((spw = getspnam (username)) == NULL)
|
||||
spw = getspnam (username);
|
||||
if (spw == NULL)
|
||||
encr_pwd = "*";
|
||||
else
|
||||
encr_pwd = spw->sp_pwdp;
|
||||
@ -1200,7 +1211,8 @@ get_client (int port)
|
||||
struct sockaddr_in client_address, server_address;
|
||||
int yes = 1;
|
||||
|
||||
if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
sock = socket (AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0)
|
||||
return "Cannot create socket";
|
||||
|
||||
/* Use this to debug: */
|
||||
@ -1227,7 +1239,8 @@ get_client (int port)
|
||||
newsocket =
|
||||
accept (sock, (struct sockaddr *) &client_address, &clilen);
|
||||
|
||||
if (isDaemon && (child = fork ())) {
|
||||
child = fork ();
|
||||
if (isDaemon != 0 && child != 0) {
|
||||
int status;
|
||||
|
||||
close (newsocket);
|
||||
@ -1296,7 +1309,7 @@ register_port (int port, int abort_if_fail)
|
||||
else {
|
||||
fprintf (stderr, "Cannot register service with portmapper\n");
|
||||
if (abort_if_fail)
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
#else
|
||||
(void) port;
|
||||
@ -1373,10 +1386,12 @@ main (int argc, char *argv[])
|
||||
register_port (portnum, 0);
|
||||
if (verbose)
|
||||
printf ("Using port %d\n", portnum);
|
||||
if ((result = get_client (portnum)))
|
||||
|
||||
result = get_client (portnum);
|
||||
if (result != NULL)
|
||||
perror (result);
|
||||
#ifdef HAVE_PMAP_SET
|
||||
if (!isDaemon)
|
||||
if (isDaemon == 0)
|
||||
pmap_unset (RPC_PROGNUM, RPC_PROGVER);
|
||||
#endif
|
||||
}
|
||||
@ -1388,5 +1403,5 @@ void
|
||||
vfs_die (const char *m)
|
||||
{
|
||||
fputs (m, stderr);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ sfs_vfmake (struct vfs_class *me, const char *name, char *cache)
|
||||
|
||||
pname = g_strdup (name);
|
||||
vfs_split (pname, &inpath, &op);
|
||||
if ((w = (*me->which) (me, op)) == -1)
|
||||
w = (*me->which) (me, op);
|
||||
if (w == -1)
|
||||
vfs_die ("This cannot happen... Hopefully.\n");
|
||||
|
||||
if (!(sfs_flags[w] & F_1) && strcmp (pname, "/")) {
|
||||
@ -392,9 +393,11 @@ static int sfs_init (struct vfs_class *me)
|
||||
}
|
||||
if (!*c)
|
||||
goto invalid_line;
|
||||
|
||||
c++;
|
||||
*(semi+1) = 0;
|
||||
if ((semi = strchr (c, '\n')))
|
||||
semi = strchr (c, '\n');
|
||||
if (semi != NULL)
|
||||
*semi = 0;
|
||||
|
||||
sfs_prefix [sfs_no] = g_strdup (key);
|
||||
|
@ -666,7 +666,8 @@ tar_open_archive (struct vfs_class *me, struct vfs_s_super *archive,
|
||||
|
||||
current_tar_position = 0;
|
||||
/* Open for reading */
|
||||
if ((tard = tar_open_archive_int (me, name, archive)) == -1)
|
||||
tard = tar_open_archive_int (me, name, archive);
|
||||
if (tard == -1)
|
||||
return -1;
|
||||
|
||||
for (;;) {
|
||||
@ -772,7 +773,9 @@ static ssize_t tar_read (void *fh, char *buffer, int count)
|
||||
|
||||
count = MIN(count, FH->ino->st.st_size - FH->pos);
|
||||
|
||||
if ((count = mc_read (fd, buffer, count)) == -1) ERRNOR (errno, -1);
|
||||
count = mc_read (fd, buffer, count);
|
||||
if (count == -1)
|
||||
ERRNOR (errno, -1);
|
||||
|
||||
FH->pos += count;
|
||||
return count;
|
||||
|
@ -206,17 +206,18 @@ undelfs_loaddel (void)
|
||||
message (D_ERROR, undelfserr, _(" while allocating block buffer "));
|
||||
goto free_delarray;
|
||||
}
|
||||
if ((retval = ext2fs_open_inode_scan (fs, 0, &scan)))
|
||||
retval = ext2fs_open_inode_scan (fs, 0, &scan);
|
||||
if (retval != 0)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" open_inode_scan: %d "), retval);
|
||||
goto free_block_buf;
|
||||
}
|
||||
if ((retval = ext2fs_get_next_inode (scan, &ino, &inode)))
|
||||
retval = ext2fs_get_next_inode (scan, &ino, &inode);
|
||||
if (retval != 0)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" while starting inode scan %d "), retval);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
while (ino)
|
||||
{
|
||||
@ -674,7 +675,8 @@ undelfs_chdir (struct vfs_class *me, const char *path)
|
||||
/* We may use access because ext2 file systems are local */
|
||||
/* this could be fixed by making an ext2fs io manager to use */
|
||||
/* our vfs, but that is left as an excercise for the reader */
|
||||
if ((fd = open (file, O_RDONLY)) == -1)
|
||||
fd = open (file, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
message (D_ERROR, undelfserr, _(" Cannot open file %s "), file);
|
||||
g_free (f);
|
||||
|
@ -233,7 +233,8 @@ is_week (const char *str, struct tm *tim)
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if ((pos = strstr (week, str)) != NULL) {
|
||||
pos = strstr (week, str);
|
||||
if (pos != NULL) {
|
||||
if (tim != NULL)
|
||||
tim->tm_wday = (pos - week) / 3;
|
||||
return 1;
|
||||
@ -250,7 +251,8 @@ is_month (const char *str, struct tm *tim)
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if ((pos = strstr (month, str)) != NULL) {
|
||||
pos = strstr (month, str);
|
||||
if (pos != NULL) {
|
||||
if (tim != NULL)
|
||||
tim->tm_mon = (pos - month) / 3;
|
||||
return 1;
|
||||
@ -287,10 +289,12 @@ is_time (const char *str, struct tm *tim)
|
||||
{
|
||||
const char *p, *p2;
|
||||
|
||||
if (!str)
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
if ((p = strchr (str, ':')) && (p2 = strrchr (str, ':'))) {
|
||||
p = strchr (str, ':');
|
||||
p2 = strrchr (str, ':');
|
||||
if (p != NULL && p2 != NULL) {
|
||||
if (p != p2) {
|
||||
if (sscanf
|
||||
(str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min,
|
||||
@ -619,7 +623,8 @@ vfs_parse_filedate (int idx, time_t *t)
|
||||
|
||||
tim.tm_year--;
|
||||
|
||||
if (l10n || (*t = mktime (&tim)) < 0)
|
||||
*t = mktime (&tim);
|
||||
if (l10n || (*t < 0))
|
||||
*t = 0;
|
||||
return idx;
|
||||
}
|
||||
@ -814,7 +819,7 @@ void
|
||||
vfs_die (const char *m)
|
||||
{
|
||||
message (D_ERROR, _("Internal error:"), "%s", m);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -135,10 +135,6 @@ void vfs_fill_names (fill_names_f);
|
||||
/* vfs/direntry.c: */
|
||||
void *vfs_s_open (struct vfs_class *, const char *, int, int);
|
||||
|
||||
#ifdef USE_NETCODE
|
||||
extern int use_netrc;
|
||||
#endif
|
||||
|
||||
void init_cpiofs (void);
|
||||
void init_extfs (void);
|
||||
void init_fish (void);
|
||||
|
@ -197,7 +197,7 @@ static struct vfs_class *vfs_list;
|
||||
int
|
||||
vfs_register_class (struct vfs_class *vfs)
|
||||
{
|
||||
if (vfs->init) /* vfs has own initialization function */
|
||||
if (vfs->init != NULL) /* vfs has own initialization function */
|
||||
if (!(*vfs->init) (vfs)) /* but it failed */
|
||||
return 0;
|
||||
|
||||
@ -214,15 +214,15 @@ vfs_prefix_to_class (char *prefix)
|
||||
struct vfs_class *vfs;
|
||||
|
||||
/* Avoid last class (localfs) that would accept any prefix */
|
||||
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
|
||||
for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next)
|
||||
{
|
||||
if (vfs->which)
|
||||
if (vfs->which != NULL)
|
||||
{
|
||||
if ((*vfs->which) (vfs, prefix) == -1)
|
||||
continue;
|
||||
return vfs;
|
||||
}
|
||||
if (vfs->prefix && !strncmp (prefix, vfs->prefix, strlen (vfs->prefix)))
|
||||
if (vfs->prefix != NULL && strncmp (prefix, vfs->prefix, strlen (vfs->prefix)) == 0)
|
||||
return vfs;
|
||||
}
|
||||
return NULL;
|
||||
@ -239,24 +239,25 @@ vfs_strip_suffix_from_filename (const char *filename)
|
||||
char *semi;
|
||||
char *p;
|
||||
|
||||
if (!filename)
|
||||
if (filename == NULL)
|
||||
vfs_die ("vfs_strip_suffix_from_path got NULL: impossible");
|
||||
|
||||
p = g_strdup (filename);
|
||||
if (!(semi = strrchr (p, '#')))
|
||||
semi = strrchr (p, '#');
|
||||
if (semi == NULL)
|
||||
return p;
|
||||
|
||||
/* Avoid last class (localfs) that would accept any prefix */
|
||||
for (vfs = vfs_list; vfs->next; vfs = vfs->next)
|
||||
for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next)
|
||||
{
|
||||
if (vfs->which)
|
||||
if (vfs->which != NULL)
|
||||
{
|
||||
if ((*vfs->which) (vfs, semi + 1) == -1)
|
||||
continue;
|
||||
*semi = '\0'; /* Found valid suffix */
|
||||
return p;
|
||||
}
|
||||
if (vfs->prefix && !strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)))
|
||||
if (vfs->prefix != NULL && strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)) == 0)
|
||||
{
|
||||
*semi = '\0'; /* Found valid suffix */
|
||||
return p;
|
||||
@ -265,15 +266,12 @@ vfs_strip_suffix_from_filename (const char *filename)
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
path_magic (const char *path)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (!stat (path, &buf))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return (stat (path, &buf) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,37 +292,38 @@ vfs_split (char *path, char **inpath, char **op)
|
||||
char *slash;
|
||||
struct vfs_class *ret;
|
||||
|
||||
if (!path)
|
||||
if (path == NULL)
|
||||
vfs_die ("Cannot split NULL");
|
||||
|
||||
semi = strrchr (path, '#');
|
||||
if (!semi || !path_magic (path))
|
||||
if (semi == NULL || !path_magic (path))
|
||||
return NULL;
|
||||
|
||||
slash = strchr (semi, PATH_SEP);
|
||||
*semi = 0;
|
||||
*semi = '\0';
|
||||
|
||||
if (op)
|
||||
if (op != NULL)
|
||||
*op = NULL;
|
||||
|
||||
if (inpath)
|
||||
if (inpath != NULL)
|
||||
*inpath = NULL;
|
||||
|
||||
if (slash)
|
||||
*slash = 0;
|
||||
if (slash != NULL)
|
||||
*slash = '\0';
|
||||
|
||||
if ((ret = vfs_prefix_to_class (semi + 1)))
|
||||
ret = vfs_prefix_to_class (semi + 1);
|
||||
if (ret != NULL)
|
||||
{
|
||||
if (op)
|
||||
if (op != NULL)
|
||||
*op = semi + 1;
|
||||
if (inpath)
|
||||
*inpath = slash ? slash + 1 : NULL;
|
||||
if (inpath != NULL)
|
||||
*inpath = slash != NULL ? slash + 1 : NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
if (slash)
|
||||
if (slash != NULL)
|
||||
*slash = PATH_SEP;
|
||||
|
||||
ret = vfs_split (path, inpath, op);
|
||||
*semi = '#';
|
||||
return ret;
|
||||
@ -340,19 +339,19 @@ _vfs_get_class (char *path)
|
||||
g_return_val_if_fail (path, NULL);
|
||||
|
||||
semi = strrchr (path, '#');
|
||||
if (!semi || !path_magic (path))
|
||||
if (semi == NULL || !path_magic (path))
|
||||
return NULL;
|
||||
|
||||
slash = strchr (semi, PATH_SEP);
|
||||
*semi = 0;
|
||||
if (slash)
|
||||
*slash = 0;
|
||||
*semi = '\0';
|
||||
if (slash != NULL)
|
||||
*slash = '\0';
|
||||
|
||||
ret = vfs_prefix_to_class (semi + 1);
|
||||
|
||||
if (slash)
|
||||
if (slash != NULL)
|
||||
*slash = PATH_SEP;
|
||||
if (!ret)
|
||||
if (ret == NULL)
|
||||
ret = _vfs_get_class (path);
|
||||
|
||||
*semi = '#';
|
||||
@ -498,7 +497,6 @@ _vfs_translate_path (const char *path, int size, GIConv defcnv, GString * buffer
|
||||
errno = EINVAL;
|
||||
return ESTR_FAILURE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return ESTR_FAILURE;
|
||||
@ -561,44 +559,42 @@ ferrno (struct vfs_class *vfs)
|
||||
int
|
||||
mc_open (const char *filename, int flags, ...)
|
||||
{
|
||||
int mode;
|
||||
int mode = 0;
|
||||
void *info;
|
||||
va_list ap;
|
||||
char *file;
|
||||
struct vfs_class *vfs;
|
||||
|
||||
char *file = vfs_canon_and_translate (filename);
|
||||
if (file != NULL)
|
||||
{
|
||||
struct vfs_class *vfs = vfs_get_class (file);
|
||||
|
||||
/* Get the mode flag */
|
||||
if (flags & O_CREAT)
|
||||
{
|
||||
va_start (ap, flags);
|
||||
mode = va_arg (ap, int);
|
||||
va_end (ap);
|
||||
}
|
||||
else
|
||||
mode = 0;
|
||||
|
||||
if (!vfs->open)
|
||||
{
|
||||
g_free (file);
|
||||
errno = -EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
|
||||
g_free (file);
|
||||
if (!info)
|
||||
{
|
||||
errno = ferrno (vfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return vfs_new_handle (vfs, info);
|
||||
}
|
||||
else
|
||||
file = vfs_canon_and_translate (filename);
|
||||
if (file == NULL)
|
||||
return -1;
|
||||
|
||||
vfs = vfs_get_class (file);
|
||||
|
||||
/* Get the mode flag */
|
||||
if (flags & O_CREAT)
|
||||
{
|
||||
va_start (ap, flags);
|
||||
mode = va_arg (ap, int);
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
if (vfs->open == NULL)
|
||||
{
|
||||
g_free (file);
|
||||
errno = -EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
info = vfs->open (vfs, file, flags, mode); /* open must be supported */
|
||||
g_free (file);
|
||||
if (info == NULL)
|
||||
{
|
||||
errno = ferrno (vfs);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return vfs_new_handle (vfs, info);
|
||||
}
|
||||
|
||||
|
||||
@ -608,18 +604,18 @@ int mc_##name inarg \
|
||||
struct vfs_class *vfs; \
|
||||
int result; \
|
||||
char *mpath = vfs_canon_and_translate (path); \
|
||||
if (mpath != NULL) { \
|
||||
if (mpath == NULL) \
|
||||
return -1; \
|
||||
vfs = vfs_get_class (mpath); \
|
||||
if (vfs == NULL){ \
|
||||
g_free (mpath); \
|
||||
return -1; \
|
||||
} \
|
||||
result = vfs->name ? (*vfs->name)callarg : -1; \
|
||||
result = vfs->name != NULL ? vfs->name callarg : -1; \
|
||||
g_free (mpath); \
|
||||
if (result == -1) \
|
||||
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
|
||||
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
|
||||
return result; \
|
||||
} else return -1; \
|
||||
}
|
||||
|
||||
MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode))
|
||||
@ -630,7 +626,9 @@ MC_NAMEOP (unlink, (const char *path), (vfs, mpath))
|
||||
MC_NAMEOP (mkdir, (const char *path, mode_t mode), (vfs, mpath, mode))
|
||||
MC_NAMEOP (rmdir, (const char *path), (vfs, mpath))
|
||||
MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode, dev))
|
||||
int mc_symlink (const char *name1, const char *path)
|
||||
|
||||
int
|
||||
mc_symlink (const char *name1, const char *path)
|
||||
{
|
||||
struct vfs_class *vfs;
|
||||
int result;
|
||||
@ -639,25 +637,27 @@ MC_NAMEOP (mknod, (const char *path, mode_t mode, dev_t dev), (vfs, mpath, mode,
|
||||
char *tmp;
|
||||
|
||||
mpath = vfs_canon_and_translate (path);
|
||||
if (mpath != NULL)
|
||||
if (mpath == NULL)
|
||||
return -1;
|
||||
|
||||
tmp = g_strdup (name1);
|
||||
lpath = vfs_translate_path_n (tmp);
|
||||
g_free (tmp);
|
||||
|
||||
if (lpath != NULL)
|
||||
{
|
||||
tmp = g_strdup (name1);
|
||||
lpath = vfs_translate_path_n (tmp);
|
||||
g_free (tmp);
|
||||
|
||||
if (lpath != NULL)
|
||||
{
|
||||
vfs = vfs_get_class (mpath);
|
||||
result = vfs->symlink ? (*vfs->symlink) (vfs, lpath, mpath) : -1;
|
||||
g_free (lpath);
|
||||
g_free (mpath);
|
||||
|
||||
if (result == -1)
|
||||
errno = vfs->symlink ? ferrno (vfs) : E_NOTSUPP;
|
||||
return result;
|
||||
}
|
||||
vfs = vfs_get_class (mpath);
|
||||
result = vfs->symlink != NULL ? vfs->symlink (vfs, lpath, mpath) : -1;
|
||||
g_free (lpath);
|
||||
g_free (mpath);
|
||||
|
||||
if (result == -1)
|
||||
errno = vfs->symlink != NULL ? ferrno (vfs) : E_NOTSUPP;
|
||||
return result;
|
||||
}
|
||||
|
||||
g_free (mpath);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -667,18 +667,19 @@ ssize_t mc_##name inarg \
|
||||
struct vfs_class *vfs; \
|
||||
int result; \
|
||||
if (handle == -1) \
|
||||
return -1; \
|
||||
return -1; \
|
||||
vfs = vfs_op (handle); \
|
||||
if (vfs == NULL) \
|
||||
return -1; \
|
||||
result = vfs->name ? (*vfs->name)callarg : -1; \
|
||||
return -1; \
|
||||
result = vfs->name != NULL ? vfs->name callarg : -1; \
|
||||
if (result == -1) \
|
||||
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
|
||||
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
MC_HANDLEOP (read, (int handle, void *buffer, int count), (vfs_info (handle), buffer, count))
|
||||
MC_HANDLEOP (write, (int handle, const void *buf, int nbyte), (vfs_info (handle), buf, nbyte))
|
||||
|
||||
#define MC_RENAMEOP(name) \
|
||||
int mc_##name (const char *fname1, const char *fname2) \
|
||||
{ \
|
||||
@ -686,31 +687,33 @@ int mc_##name (const char *fname1, const char *fname2) \
|
||||
int result; \
|
||||
char *name2, *name1; \
|
||||
name1 = vfs_canon_and_translate (fname1); \
|
||||
if (name1 != NULL) { \
|
||||
name2 = vfs_canon_and_translate (fname2); \
|
||||
if (name2 != NULL) { \
|
||||
vfs = vfs_get_class (name1); \
|
||||
if (vfs != vfs_get_class (name2)){ \
|
||||
errno = EXDEV; \
|
||||
g_free (name1); \
|
||||
g_free (name2); \
|
||||
return -1; \
|
||||
} \
|
||||
result = vfs->name ? (*vfs->name)(vfs, name1, name2) : -1; \
|
||||
g_free (name1); \
|
||||
g_free (name2); \
|
||||
if (result == -1) \
|
||||
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
|
||||
return result; \
|
||||
} else { \
|
||||
if (name1 == NULL) \
|
||||
return -1; \
|
||||
name2 = vfs_canon_and_translate (fname2); \
|
||||
if (name2 == NULL) { \
|
||||
g_free (name1); \
|
||||
return -1; \
|
||||
} \
|
||||
} else return -1; \
|
||||
vfs = vfs_get_class (name1); \
|
||||
if (vfs != vfs_get_class (name2)) \
|
||||
{ \
|
||||
errno = EXDEV; \
|
||||
g_free (name1); \
|
||||
g_free (name2); \
|
||||
return -1; \
|
||||
} \
|
||||
result = vfs->name != NULL ? vfs->name (vfs, name1, name2) : -1; \
|
||||
g_free (name1); \
|
||||
g_free (name2); \
|
||||
if (result == -1) \
|
||||
errno = vfs->name != NULL ? ferrno (vfs) : E_NOTSUPP; \
|
||||
return result; \
|
||||
}
|
||||
MC_RENAMEOP (link) MC_RENAMEOP (rename)
|
||||
int
|
||||
mc_ctl (int handle, int ctlop, void *arg)
|
||||
|
||||
MC_RENAMEOP (link) MC_RENAMEOP (rename)
|
||||
|
||||
int
|
||||
mc_ctl (int handle, int ctlop, void *arg)
|
||||
{
|
||||
struct vfs_class *vfs = vfs_op (handle);
|
||||
|
||||
@ -724,22 +727,21 @@ int
|
||||
mc_setctl (const char *path, int ctlop, void *arg)
|
||||
{
|
||||
struct vfs_class *vfs;
|
||||
int result;
|
||||
int result = -1;
|
||||
char *mpath;
|
||||
|
||||
if (!path)
|
||||
if (path == NULL)
|
||||
vfs_die ("You don't want to pass NULL to mc_setctl.");
|
||||
|
||||
mpath = vfs_canon_and_translate (path);
|
||||
if (mpath != NULL)
|
||||
{
|
||||
vfs = vfs_get_class (mpath);
|
||||
result = vfs->setctl ? (*vfs->setctl) (vfs, mpath, ctlop, arg) : 0;
|
||||
result = vfs->setctl != NULL ? vfs->setctl (vfs, mpath, ctlop, arg) : 0;
|
||||
g_free (mpath);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
@ -1189,14 +1191,12 @@ vfs_file_class_flags (const char *filename)
|
||||
char *fname;
|
||||
|
||||
fname = vfs_canon_and_translate (filename);
|
||||
if (fname != NULL)
|
||||
{
|
||||
vfs = vfs_get_class (fname);
|
||||
g_free (fname);
|
||||
return vfs->flags;
|
||||
}
|
||||
else
|
||||
if (fname == NULL)
|
||||
return -1;
|
||||
|
||||
vfs = vfs_get_class (fname);
|
||||
g_free (fname);
|
||||
return vfs->flags;
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -1234,9 +1234,8 @@ mc_def_getlocalcopy (const char *filename)
|
||||
}
|
||||
|
||||
if (mc_stat (filename, &mystat) != -1)
|
||||
{
|
||||
chmod (tmp, mystat.st_mode);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
|
||||
fail:
|
||||
@ -1251,7 +1250,7 @@ mc_def_getlocalcopy (const char *filename)
|
||||
char *
|
||||
mc_getlocalcopy (const char *pathname)
|
||||
{
|
||||
char *result;
|
||||
char *result = NULL;
|
||||
char *path;
|
||||
|
||||
path = vfs_canon_and_translate (pathname);
|
||||
@ -1259,14 +1258,15 @@ mc_getlocalcopy (const char *pathname)
|
||||
{
|
||||
struct vfs_class *vfs = vfs_get_class (path);
|
||||
|
||||
result = vfs->getlocalcopy ? (*vfs->getlocalcopy) (vfs, path) : mc_def_getlocalcopy (path);
|
||||
result = vfs->getlocalcopy != NULL ?
|
||||
vfs->getlocalcopy (vfs, path) :
|
||||
mc_def_getlocalcopy (path);
|
||||
g_free (path);
|
||||
if (!result)
|
||||
if (result == NULL)
|
||||
errno = ferrno (vfs);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -1323,22 +1323,21 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename,
|
||||
int
|
||||
mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed)
|
||||
{
|
||||
int return_value = 0;
|
||||
int return_value = -1;
|
||||
char *path;
|
||||
|
||||
path = vfs_canon_and_translate (pathname);
|
||||
if (path != NULL)
|
||||
if (path == NULL)
|
||||
{
|
||||
struct vfs_class *vfs = vfs_get_class (path);
|
||||
|
||||
return_value = vfs->ungetlocalcopy ?
|
||||
(*vfs->ungetlocalcopy) (vfs, path, local, has_changed) :
|
||||
return_value = vfs->ungetlocalcopy != NULL ?
|
||||
vfs->ungetlocalcopy (vfs, path, local, has_changed) :
|
||||
mc_def_ungetlocalcopy (vfs, path, local, has_changed);
|
||||
g_free (path);
|
||||
return return_value;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,6 +18,12 @@
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
|
||||
extern int vfs_timeout;
|
||||
|
||||
#ifdef USE_NETCODE
|
||||
extern int use_netrc;
|
||||
#endif
|
||||
|
||||
void vfs_init (void);
|
||||
void vfs_shut (void);
|
||||
|
||||
|
@ -17,7 +17,7 @@ dnl @license GPLWithACException
|
||||
AC_DEFUN([AX_PATH_LIB_PCRE],[dnl
|
||||
AC_MSG_CHECKING([lib pcre])
|
||||
AC_ARG_WITH([pcre],
|
||||
AC_HELP_STRING([--with-pcre[[=prefix]]].[ compile pcre part (via libpcre check)]),
|
||||
AC_HELP_STRING([--with-pcre[[=prefix]]], [compile pcre part (via libpcre check)]),
|
||||
,
|
||||
[with_pcre="yes"]
|
||||
)
|
||||
@ -41,7 +41,7 @@ else
|
||||
AC_CHECK_LIB(pcre, pcre_compile)
|
||||
|
||||
if test x"$ac_cv_lib_pcre_pcre_compile" = x"yes" ; then
|
||||
AC_MSG_RESULT(.setting PCRE_LIBS -L$with_pcre/lib -lpcre)
|
||||
AC_MSG_RESULT(setting PCRE_LIBS -L$with_pcre/lib -lpcre)
|
||||
|
||||
PCRE_LIBS=$test_PCRE_LIBS
|
||||
test_PCRE_CFLAGS=$test_PCRE_CFLAGS
|
||||
|
@ -37,7 +37,7 @@ include diff.syntax
|
||||
file ..\*\\.lsm$ LSM\sFile
|
||||
include lsm.syntax
|
||||
|
||||
file .\*(bash_completion|profile|\\.(sh|bash_login|bash_profile|bash_logout|bash_aliases|bash_exports|bash_history|bash_userstuff|bashrc|profile))$ Shell\sScript ^#!\s\*/(.\*/|usr/bin/env\s)([a-z]?|ba|pdk)sh
|
||||
file .\*(bash_completion|profile|\\.(sh|bash_login|bash_profile|bash_logout|bash_aliases|bash_exports|bash_history|bashrc|profile))$ Shell\sScript ^#!\s\*/(.\*/|usr/bin/env\s)([a-z]?|ba|pdk)sh
|
||||
include sh.syntax
|
||||
|
||||
file ..\*\\.(pl|PL|pm|PM)$ Perl\sProgram ^#!.\*([\s/]perl|@PERL@)
|
||||
|
@ -84,16 +84,12 @@ SRC_mc_keybind = \
|
||||
keybind.c keybind.h \
|
||||
cmddef.h
|
||||
|
||||
SRC_mc_extended_charset = \
|
||||
ecs.c ecs.h
|
||||
|
||||
mc_SOURCES = \
|
||||
$(SRC_USE_charset) \
|
||||
$(SRC_mc_widgets) \
|
||||
$(SRC_mc_conssaver) \
|
||||
$(SRC_mc_options) \
|
||||
$(SRC_mc_keybind) \
|
||||
$(SRC_mc_extended_charset) \
|
||||
achown.c achown.h \
|
||||
args.c args.h \
|
||||
background.c background.h \
|
||||
@ -128,14 +124,6 @@ mc_SOURCES = \
|
||||
|
||||
EXTRA_DIST = man2hlp.c $(SRC_maintainer) $(SRC_charset)
|
||||
|
||||
# automated testing
|
||||
|
||||
TESTS = ecs-test
|
||||
|
||||
check_PROGRAMS = ecs-test
|
||||
ecs_test_SOURCES = ecs-test.c ecs.h ecs.c
|
||||
ecs_test_LDADD = $(GLIB_LIBS) $(INTLLIBS) $(MCLIBS)
|
||||
|
||||
# end of automated testing
|
||||
|
||||
install-exec-hook:
|
||||
|
76
src/args.c
76
src/args.c
@ -92,38 +92,44 @@ static gboolean mc_args__show_datadirs = FALSE;
|
||||
static GOptionGroup *main_group;
|
||||
|
||||
static const GOptionEntry argument_main_table[] = {
|
||||
/* *INDENT-OFF* */
|
||||
/* generic options */
|
||||
{
|
||||
"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
||||
&mc_args__version,
|
||||
N_("Displays the current version"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
/* options for wrappers */
|
||||
{
|
||||
"datadir", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
||||
&mc_args__show_datadirs,
|
||||
N_("Print data directory"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"printwd", 'P', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
||||
&mc_args__last_wd_file,
|
||||
N_("Print last working directory to specified file"),
|
||||
"<file>"},
|
||||
"<file>"
|
||||
},
|
||||
|
||||
#ifdef HAVE_SUBSHELL_SUPPORT
|
||||
{
|
||||
"subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
||||
&use_subshell,
|
||||
N_("Enables subshell support (default)"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"nosubshell", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
|
||||
&mc_args__nouse_subshell,
|
||||
N_("Disables subshell support"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
/* debug options */
|
||||
@ -132,13 +138,15 @@ static const GOptionEntry argument_main_table[] = {
|
||||
"ftplog", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
||||
&mc_args__netfs_logfile,
|
||||
N_("Log ftp dialog to specified file"),
|
||||
"<file>"},
|
||||
"<file>"
|
||||
},
|
||||
#ifdef ENABLE_VFS_SMB
|
||||
{
|
||||
"debuglevel", 'D', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT,
|
||||
&mc_args__debug_level,
|
||||
N_("Set debug level"),
|
||||
"<integer>"},
|
||||
"<integer>"
|
||||
},
|
||||
#endif /* ENABLE_VFS_SMB */
|
||||
#endif
|
||||
|
||||
@ -147,7 +155,8 @@ static const GOptionEntry argument_main_table[] = {
|
||||
"view", 'v', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
||||
&mc_run_param0,
|
||||
N_("Launches the file viewer on a file"),
|
||||
"<file>"},
|
||||
"<file>"
|
||||
},
|
||||
|
||||
{
|
||||
"edit", 'e', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING,
|
||||
@ -155,59 +164,72 @@ static const GOptionEntry argument_main_table[] = {
|
||||
N_("Edits one file"),
|
||||
"<file>"},
|
||||
|
||||
{NULL}
|
||||
{
|
||||
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
GOptionGroup *terminal_group;
|
||||
#define ARGS_TERM_OPTIONS 0
|
||||
static const GOptionEntry argument_terminal_table[] = {
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
/* terminal options */
|
||||
{
|
||||
"xterm", 'x', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__force_xterm,
|
||||
N_("Forces xterm features"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"nomouse", 'd', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__nomouse,
|
||||
N_("Disable mouse support in text version"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
#ifdef HAVE_SLANG
|
||||
{
|
||||
"termcap", 't', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&SLtt_Try_Termcap,
|
||||
N_("Tries to use termcap instead of terminfo"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
{
|
||||
"slow", 's', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__slow_terminal,
|
||||
N_("To run on slow terminals"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"stickchars", 'a', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__ugly_line_drawing,
|
||||
N_("Use stickchars to draw"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"resetsoft", 'k', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&reset_hp_softkeys,
|
||||
N_("Resets soft keys on HP terminals"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"keymap", 'K', ARGS_TERM_OPTIONS, G_OPTION_ARG_STRING,
|
||||
&mc_args__keymap_file,
|
||||
N_("Load definitions of key bindings from specified file"),
|
||||
"<file>"},
|
||||
"<file>"
|
||||
},
|
||||
|
||||
{NULL}
|
||||
{
|
||||
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#undef ARGS_TERM_OPTIONS
|
||||
@ -216,32 +238,40 @@ GOptionGroup *color_group;
|
||||
#define ARGS_COLOR_OPTIONS 0
|
||||
// #define ARGS_COLOR_OPTIONS G_OPTION_FLAG_IN_MAIN
|
||||
static const GOptionEntry argument_color_table[] = {
|
||||
/* *INDENT-OFF* */
|
||||
/* color options */
|
||||
{
|
||||
"nocolor", 'b', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__disable_colors,
|
||||
N_("Requests to run in black and white"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"color", 'c', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE,
|
||||
&mc_args__force_colors,
|
||||
N_("Request to run in color mode"),
|
||||
NULL},
|
||||
NULL
|
||||
},
|
||||
|
||||
{
|
||||
"colors", 'C', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
|
||||
&command_line_colors,
|
||||
N_("Specifies a color configuration"),
|
||||
"<string>"},
|
||||
"<string>"
|
||||
},
|
||||
|
||||
{
|
||||
"skin", 'S', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING,
|
||||
&mc_args__skin,
|
||||
N_("Show mc with specified skin"),
|
||||
"<string>"},
|
||||
"<string>"
|
||||
},
|
||||
|
||||
{ NULL }
|
||||
{
|
||||
NULL, '\0', 0, 0, NULL, NULL, NULL /* Complete struct initialization */
|
||||
}
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
#undef ARGS_COLOR_OPTIONS
|
||||
|
@ -150,9 +150,11 @@ do_background (struct FileOpContext *ctx, char *info)
|
||||
if (pipe (back_comm) == -1)
|
||||
return -1;
|
||||
|
||||
if ((pid = fork ()) == -1)
|
||||
pid = fork ();
|
||||
if (pid == -1)
|
||||
{
|
||||
int saved_errno = errno;
|
||||
|
||||
(void) close (comm[0]);
|
||||
(void) close (comm[1]);
|
||||
(void) close (back_comm[0]);
|
||||
@ -176,11 +178,15 @@ do_background (struct FileOpContext *ctx, char *info)
|
||||
close (1);
|
||||
close (2);
|
||||
|
||||
if ((nullfd = open ("/dev/null", O_RDWR)) != -1)
|
||||
nullfd = open ("/dev/null", O_RDWR);
|
||||
if (nullfd != -1)
|
||||
{
|
||||
while (dup2 (nullfd, 0) == -1 && errno == EINTR);
|
||||
while (dup2 (nullfd, 1) == -1 && errno == EINTR);
|
||||
while (dup2 (nullfd, 2) == -1 && errno == EINTR);
|
||||
while (dup2 (nullfd, 0) == -1 && errno == EINTR)
|
||||
;
|
||||
while (dup2 (nullfd, 1) == -1 && errno == EINTR)
|
||||
;
|
||||
while (dup2 (nullfd, 2) == -1 && errno == EINTR)
|
||||
;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
19
src/boxes.c
19
src/boxes.c
@ -42,12 +42,13 @@
|
||||
#include "lib/mcconfig.h" /* Load/save user formats */
|
||||
#include "lib/strutil.h"
|
||||
|
||||
#ifdef USE_NETCODE
|
||||
# include "lib/vfs/mc-vfs/ftpfs.h"
|
||||
#ifdef ENABLE_VFS
|
||||
#include "lib/vfs/mc-vfs/vfs.h" /* vfs_timeout */
|
||||
#include "lib/vfs/mc-vfs/vfs-impl.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
#include "lib/vfs/mc-vfs/gc.h"
|
||||
#ifdef USE_NETCODE
|
||||
# include "lib/vfs/mc-vfs/ftpfs.h"
|
||||
#endif
|
||||
|
||||
#include "dialog.h" /* The nice dialog manager */
|
||||
@ -623,12 +624,14 @@ display_bits_box (void)
|
||||
run_dlg (dbits_dlg);
|
||||
|
||||
if (dbits_dlg->ret_value == B_ENTER) {
|
||||
const char *errmsg;
|
||||
char *errmsg;
|
||||
|
||||
display_codepage = new_display_codepage;
|
||||
errmsg =
|
||||
init_translation_table (source_codepage, display_codepage);
|
||||
if (errmsg)
|
||||
errmsg = init_translation_table (source_codepage, display_codepage);
|
||||
if (errmsg != NULL) {
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
}
|
||||
#ifdef HAVE_SLANG
|
||||
tty_display_8bit (display_codepage != 0 && display_codepage != 1);
|
||||
#else
|
||||
|
@ -57,12 +57,14 @@ load_codepages_list (void)
|
||||
char *default_codepage = NULL;
|
||||
|
||||
fname = concat_dir_and_file (mc_home, CHARSETS_INDEX);
|
||||
if (!(f = fopen (fname, "r"))) {
|
||||
f = fopen (fname, "r");
|
||||
if (f == NULL) {
|
||||
fprintf (stderr, _("Warning: file %s not found\n"), fname);
|
||||
g_free (fname);
|
||||
|
||||
fname = concat_dir_and_file (mc_home_alt, CHARSETS_INDEX);
|
||||
if (!(f = fopen (fname, "r"))) {
|
||||
f = fopen (fname, "r");
|
||||
if (f == NULL) {
|
||||
fprintf (stderr, _("Warning: file %s not found\n"), fname);
|
||||
g_free (fname);
|
||||
|
||||
@ -177,15 +179,13 @@ translate_character (GIConv cd, char c)
|
||||
return ch;
|
||||
}
|
||||
|
||||
char errbuf[255];
|
||||
|
||||
/*
|
||||
* FIXME: This assumes that ASCII is always the first encoding
|
||||
* in mc.charsets
|
||||
*/
|
||||
#define CP_ASCII 0
|
||||
|
||||
const char *
|
||||
char *
|
||||
init_translation_table (int cpsource, int cpdisplay)
|
||||
{
|
||||
int i;
|
||||
@ -212,11 +212,8 @@ init_translation_table (int cpsource, int cpdisplay)
|
||||
/* display <- inpit table */
|
||||
|
||||
cd = g_iconv_open (cp_display, cp_source);
|
||||
if (cd == INVALID_CONV) {
|
||||
g_snprintf (errbuf, sizeof (errbuf),
|
||||
_("Cannot translate from %s to %s"), cp_source, cp_display);
|
||||
return errbuf;
|
||||
}
|
||||
if (cd == INVALID_CONV)
|
||||
return g_strdup_printf (_("Cannot translate from %s to %s"), cp_source, cp_display);
|
||||
|
||||
for (i = 128; i <= 255; ++i)
|
||||
conv_displ[i] = translate_character (cd, i);
|
||||
@ -226,11 +223,8 @@ init_translation_table (int cpsource, int cpdisplay)
|
||||
/* inpit <- display table */
|
||||
|
||||
cd = g_iconv_open (cp_source, cp_display);
|
||||
if (cd == INVALID_CONV) {
|
||||
g_snprintf (errbuf, sizeof (errbuf),
|
||||
_("Cannot translate from %s to %s"), cp_display, cp_source);
|
||||
return errbuf;
|
||||
}
|
||||
if (cd == INVALID_CONV)
|
||||
return g_strdup_printf (_("Cannot translate from %s to %s"), cp_display, cp_source);
|
||||
|
||||
for (i = 128; i <= 255; ++i) {
|
||||
unsigned char ch;
|
||||
|
@ -28,7 +28,7 @@ const char *get_codepage_id (const int n);
|
||||
int get_codepage_index (const char *id);
|
||||
int load_codepages_list (void);
|
||||
void free_codepages_list (void);
|
||||
const char *init_translation_table (int cpsource, int cpdisplay);
|
||||
char *init_translation_table (int cpsource, int cpdisplay);
|
||||
void convert_to_display (char *str);
|
||||
void convert_from_input (char *str);
|
||||
void convert_string (unsigned char *str);
|
||||
|
@ -592,7 +592,7 @@ select_unselect_cmd (const char *title, const char *history_name, gboolean do_se
|
||||
search = mc_search_new (reg_exp, -1);
|
||||
search->search_type = (shell_patterns != 0) ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
||||
search->is_entire_line = TRUE;
|
||||
search->is_case_sentitive = case_sens != 0;
|
||||
search->is_case_sensitive = case_sens != 0;
|
||||
|
||||
for (i = 0; i < current_panel->count; i++)
|
||||
{
|
||||
|
@ -311,7 +311,6 @@ command_new (int y, int x, int cols)
|
||||
|
||||
/* Add our hooks */
|
||||
cmd->widget.callback = command_callback;
|
||||
cmd->completion_flags |= INPUT_COMPLETE_COMMANDS;
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
}
|
||||
|
||||
/* If we're starting the match process, initialize us a bit. */
|
||||
if (!state)
|
||||
if (state == 0)
|
||||
{
|
||||
const char *temp;
|
||||
|
||||
@ -117,7 +117,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
g_free (filename);
|
||||
g_free (users_dirname);
|
||||
|
||||
if ((*text) && (temp = strrchr (text, PATH_SEP)))
|
||||
if ((*text != '\0') && (temp = strrchr (text, PATH_SEP)) != NULL)
|
||||
{
|
||||
filename = g_strdup (++temp);
|
||||
dirname = g_strndup (text, temp - text);
|
||||
@ -205,7 +205,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
break;
|
||||
}
|
||||
|
||||
if (!entry)
|
||||
if (entry == NULL)
|
||||
{
|
||||
if (directory)
|
||||
{
|
||||
@ -233,7 +233,7 @@ filename_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
if (users_dirname[dirlen - 1] != PATH_SEP)
|
||||
{
|
||||
temp[dirlen] = PATH_SEP;
|
||||
temp[dirlen + 1] = 0;
|
||||
temp[dirlen + 1] = '\0';
|
||||
}
|
||||
strcat (temp, entry->d_name);
|
||||
}
|
||||
@ -262,7 +262,7 @@ username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
|
||||
if (text[0] == '\\' && text[1] == '~')
|
||||
text++;
|
||||
if (!state)
|
||||
if (state == 0)
|
||||
{ /* Initialization stuff */
|
||||
setpwent ();
|
||||
userlen = strlen (text + 1);
|
||||
@ -276,7 +276,7 @@ username_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
break;
|
||||
}
|
||||
|
||||
if (entry)
|
||||
if (entry != NULL)
|
||||
return g_strconcat ("~", entry->pw_name, PATH_SEP_STR, (char *) NULL);
|
||||
|
||||
endpwent ();
|
||||
@ -300,7 +300,7 @@ variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
(void) flags;
|
||||
SHOW_C_CTX ("variable_completion_function");
|
||||
|
||||
if (!state)
|
||||
if (state == 0)
|
||||
{ /* Initialization stuff */
|
||||
isbrace = (text[1] == '{');
|
||||
varlen = strlen (text + 1 + isbrace);
|
||||
@ -315,9 +315,9 @@ variable_completion_function (const char *text, int state, INPUT_COMPLETE_FLAGS
|
||||
env_p++;
|
||||
}
|
||||
|
||||
if (!*env_p)
|
||||
if (*env_p == NULL)
|
||||
return NULL;
|
||||
else
|
||||
|
||||
{
|
||||
char *temp = g_malloc (2 + 2 * isbrace + p - *env_p);
|
||||
|
||||
@ -518,10 +518,11 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
|
||||
|
||||
if (!(flags & INPUT_COMPLETE_COMMANDS))
|
||||
return 0;
|
||||
|
||||
text = strutils_shell_unescape (_text);
|
||||
flags &= ~INPUT_COMPLETE_SHELL_ESC;
|
||||
|
||||
if (!state)
|
||||
if (state == 0)
|
||||
{ /* Initialize us a little bit */
|
||||
isabsolute = strchr (text, PATH_SEP) != NULL;
|
||||
if (!isabsolute)
|
||||
@ -529,13 +530,18 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
|
||||
words = bash_reserved;
|
||||
phase = 0;
|
||||
text_len = strlen (text);
|
||||
if (!path && (path = g_strdup (getenv ("PATH"))) != NULL)
|
||||
|
||||
if (path == NULL)
|
||||
{
|
||||
p = path;
|
||||
path_end = strchr (p, 0);
|
||||
while ((p = strchr (p, PATH_ENV_SEP)))
|
||||
path = g_strdup (getenv ("PATH"));
|
||||
if (path != NULL)
|
||||
{
|
||||
*p++ = 0;
|
||||
p = path;
|
||||
path_end = strchr (p, '\0');
|
||||
while ((p = strchr (p, PATH_ENV_SEP)) != NULL)
|
||||
{
|
||||
*p++ = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -545,7 +551,7 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
|
||||
{
|
||||
p = filename_completion_function (text, state, flags);
|
||||
|
||||
if (p)
|
||||
if (p != NULL)
|
||||
{
|
||||
char *temp_p = p;
|
||||
p = strutils_shell_escape (p);
|
||||
@ -616,11 +622,15 @@ command_completion_function (const char *_text, int state, INPUT_COMPLETE_FLAGS
|
||||
g_free (path);
|
||||
path = NULL;
|
||||
}
|
||||
else if ((p = strrchr (found, PATH_SEP)) != NULL)
|
||||
else
|
||||
{
|
||||
char *tmp = found;
|
||||
found = strutils_shell_escape (p + 1);
|
||||
g_free (tmp);
|
||||
p = strrchr (found, PATH_SEP);
|
||||
if (p != NULL)
|
||||
{
|
||||
char *tmp = found;
|
||||
found = strutils_shell_escape (p + 1);
|
||||
g_free (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (text);
|
||||
@ -1188,8 +1198,9 @@ complete_engine (WInput * in, int what_to_do)
|
||||
Dlg_head *query_dlg;
|
||||
WListbox *query_list;
|
||||
|
||||
for (p = in->completions + 1; *p; count++, p++)
|
||||
if ((i = str_term_width1 (*p)) > maxlen)
|
||||
for (p = in->completions + 1; *p != NULL; count++, p++)
|
||||
i = str_term_width1 (*p);
|
||||
if (i > maxlen)
|
||||
maxlen = i;
|
||||
start_x = in->widget.x;
|
||||
start_y = in->widget.y;
|
||||
|
@ -280,7 +280,7 @@ dview_search_cmd (WDiff * dview)
|
||||
|
||||
dview->search.handle->search_type = mcdiffview_search_options.type;
|
||||
dview->search.handle->is_all_charsets = mcdiffview_search_options.all_codepages;
|
||||
dview->search.handle->is_case_sentitive = mcdiffview_search_options.case_sens;
|
||||
dview->search.handle->is_case_sensitive = mcdiffview_search_options.case_sens;
|
||||
dview->search.handle->whole_words = mcdiffview_search_options.whole_words;
|
||||
|
||||
mcdiffview_do_search (dview);
|
||||
|
@ -829,7 +829,7 @@ scan_diff (FBUF * f, GArray * ops)
|
||||
}
|
||||
continue;
|
||||
}
|
||||
while (buf[sz - 1] != '\n' && (sz = f_gets (buf, sizeof (buf), f)))
|
||||
while (buf[sz - 1] != '\n' && (sz = f_gets (buf, sizeof (buf), f)) != 0)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -936,14 +936,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
|
||||
int n;
|
||||
op = &g_array_index (ops, DIFFCMD, i);
|
||||
n = op->F1 - (op->cmd != add_cmd);
|
||||
while (line < n && (sz = f_gets (buf, sizeof (buf), f)))
|
||||
while (line < n && (sz = f_gets (buf, sizeof (buf), f)) != 0)
|
||||
{
|
||||
line++;
|
||||
printer (ctx, EQU_CH, line, off, sz, buf);
|
||||
off += sz;
|
||||
while (buf[sz - 1] != '\n')
|
||||
{
|
||||
if (!(sz = f_gets (buf, sizeof (buf), f)))
|
||||
sz = f_gets (buf, sizeof (buf), f);
|
||||
if (sz == 0)
|
||||
{
|
||||
printer (ctx, 0, 0, 0, 1, "\n");
|
||||
break;
|
||||
@ -969,14 +970,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
|
||||
if (op->cmd == del_cmd)
|
||||
{
|
||||
n = op->F2 - op->F1 + 1;
|
||||
while (n && (sz = f_gets (buf, sizeof (buf), f)))
|
||||
while (n != 0 && (sz = f_gets (buf, sizeof (buf), f)) != 0)
|
||||
{
|
||||
line++;
|
||||
printer (ctx, ADD_CH, line, off, sz, buf);
|
||||
off += sz;
|
||||
while (buf[sz - 1] != '\n')
|
||||
{
|
||||
if (!(sz = f_gets (buf, sizeof (buf), f)))
|
||||
sz = f_gets (buf, sizeof (buf), f);
|
||||
if (sz == 0)
|
||||
{
|
||||
printer (ctx, 0, 0, 0, 1, "\n");
|
||||
break;
|
||||
@ -994,14 +996,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
|
||||
if (op->cmd == 'c')
|
||||
{
|
||||
n = op->F2 - op->F1 + 1;
|
||||
while (n && (sz = f_gets (buf, sizeof (buf), f)))
|
||||
while (n != 0 && (sz = f_gets (buf, sizeof (buf), f)) != 0)
|
||||
{
|
||||
line++;
|
||||
printer (ctx, CHG_CH, line, off, sz, buf);
|
||||
off += sz;
|
||||
while (buf[sz - 1] != '\n')
|
||||
{
|
||||
if (!(sz = f_gets (buf, sizeof (buf), f)))
|
||||
sz = f_gets (buf, sizeof (buf), f);
|
||||
if (sz == 0)
|
||||
{
|
||||
printer (ctx, 0, 0, 0, 1, "\n");
|
||||
break;
|
||||
@ -1028,14 +1031,15 @@ dff_reparse (int ord, const char *filename, const GArray * ops, DFUNC printer, v
|
||||
#undef F2
|
||||
#undef F1
|
||||
|
||||
while ((sz = f_gets (buf, sizeof (buf), f)))
|
||||
while ((sz = f_gets (buf, sizeof (buf), f)) != 0)
|
||||
{
|
||||
line++;
|
||||
printer (ctx, EQU_CH, line, off, sz, buf);
|
||||
off += sz;
|
||||
while (buf[sz - 1] != '\n')
|
||||
{
|
||||
if (!(sz = f_gets (buf, sizeof (buf), f)))
|
||||
sz = f_gets (buf, sizeof (buf), f);
|
||||
if (sz == 0)
|
||||
{
|
||||
printer (ctx, 0, 0, 0, 1, "\n");
|
||||
break;
|
||||
@ -1252,8 +1256,10 @@ hdiff_scan (const char *s, int m, const char *t, int n, int min, GArray * hdiff,
|
||||
BRACKET b;
|
||||
|
||||
/* dumbscan (single horizontal diff) -- does not compress whitespace */
|
||||
for (i = 0; i < m && i < n && s[i] == t[i]; i++);
|
||||
for (; m > i && n > i && s[m - 1] == t[n - 1]; m--, n--);
|
||||
for (i = 0; i < m && i < n && s[i] == t[i]; i++)
|
||||
;
|
||||
for (; m > i && n > i && s[m - 1] == t[n - 1]; m--, n--)
|
||||
;
|
||||
|
||||
b[0].off = i;
|
||||
b[0].len = m - i;
|
||||
@ -1315,7 +1321,7 @@ static int
|
||||
cvt_cpy (char *dst, const char *src, size_t srcsize, int base, int ts)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; srcsize; i++, src++, dst++, srcsize--)
|
||||
for (i = 0; srcsize != 0; i++, src++, dst++, srcsize--)
|
||||
{
|
||||
*dst = *src;
|
||||
if (*src == '\t')
|
||||
@ -1355,7 +1361,7 @@ cvt_ncpy (char *dst, int dstsize, const char **_src, size_t srcsize, int base, i
|
||||
{
|
||||
int i;
|
||||
const char *src = *_src;
|
||||
for (i = 0; i < dstsize && srcsize; i++, src++, dst++, srcsize--)
|
||||
for (i = 0; i < dstsize && srcsize != 0; i++, src++, dst++, srcsize--)
|
||||
{
|
||||
*dst = *src;
|
||||
if (*src == '\t')
|
||||
@ -1401,7 +1407,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
|
||||
int i;
|
||||
char *tmp = dst;
|
||||
const int base = 0;
|
||||
for (i = 0; dstsize && srcsize && *src != '\n'; i++, src++, srcsize--)
|
||||
for (i = 0; dstsize != 0 && srcsize != 0 && *src != '\n'; i++, src++, srcsize--)
|
||||
{
|
||||
if (*src == '\t')
|
||||
{
|
||||
@ -1413,7 +1419,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
|
||||
{
|
||||
skip--;
|
||||
}
|
||||
else if (dstsize)
|
||||
else if (dstsize != 0)
|
||||
{
|
||||
dstsize--;
|
||||
*dst++ = ' ';
|
||||
@ -1445,6 +1451,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
|
||||
int utf_ch = 0;
|
||||
gboolean res;
|
||||
int w;
|
||||
|
||||
skip--;
|
||||
utf_ch = dview_get_utf ((char *)src, &w, &res);
|
||||
if (w > 1)
|
||||
@ -1461,7 +1468,7 @@ cvt_mget (const char *src, size_t srcsize, char *dst, int dstsize, int skip, int
|
||||
}
|
||||
sz = dst - tmp;
|
||||
}
|
||||
while (dstsize)
|
||||
while (dstsize != 0)
|
||||
{
|
||||
dstsize--;
|
||||
*dst++ = ' ';
|
||||
@ -1498,7 +1505,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
||||
int i, k;
|
||||
char *tmp = dst;
|
||||
const int base = 0;
|
||||
for (i = 0, k = 0; dstsize && srcsize && *src != '\n'; i++, k++, src++, srcsize--)
|
||||
for (i = 0, k = 0; dstsize != 0 && srcsize != 0 && *src != '\n'; i++, k++, src++, srcsize--)
|
||||
{
|
||||
if (*src == '\t')
|
||||
{
|
||||
@ -1506,11 +1513,11 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
||||
i += j - 1;
|
||||
while (j-- > 0)
|
||||
{
|
||||
if (skip)
|
||||
if (skip != 0)
|
||||
{
|
||||
skip--;
|
||||
}
|
||||
else if (dstsize)
|
||||
else if (dstsize != 0)
|
||||
{
|
||||
dstsize--;
|
||||
*att++ = is_inside (k, hdiff, ord);
|
||||
@ -1520,7 +1527,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
||||
}
|
||||
else if (src[0] == '\r' && (srcsize == 1 || src[1] == '\n'))
|
||||
{
|
||||
if (!skip && show_cr)
|
||||
if (skip == 0 && show_cr)
|
||||
{
|
||||
if (dstsize > 1)
|
||||
{
|
||||
@ -1541,11 +1548,12 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
||||
}
|
||||
else
|
||||
{
|
||||
if (skip)
|
||||
if (skip != 0)
|
||||
{
|
||||
int utf_ch = 0;
|
||||
gboolean res;
|
||||
int w;
|
||||
|
||||
skip--;
|
||||
utf_ch = dview_get_utf ((char *) src, &w, &res);
|
||||
if (w > 1)
|
||||
@ -1563,7 +1571,7 @@ cvt_mgeta (const char *src, size_t srcsize, char *dst, int dstsize, int skip, in
|
||||
}
|
||||
sz = dst - tmp;
|
||||
}
|
||||
while (dstsize)
|
||||
while (dstsize != 0)
|
||||
{
|
||||
dstsize--;
|
||||
*att++ = 0;
|
||||
@ -1620,10 +1628,10 @@ cvt_fget (FBUF * f, off_t off, char *dst, size_t dstsize, int skip, int ts, int
|
||||
while (skip > base)
|
||||
{
|
||||
old_base = base;
|
||||
if (!(sz = f_gets (tmp, amount, f)))
|
||||
{
|
||||
sz = f_gets (tmp, amount, f);
|
||||
if (sz == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
base = cvt_cpy (cvt, tmp, sz, old_base, ts);
|
||||
if (cvt[base - old_base - 1] == '\n')
|
||||
{
|
||||
@ -1645,17 +1653,18 @@ cvt_fget (FBUF * f, off_t off, char *dst, size_t dstsize, int skip, int ts, int
|
||||
|
||||
if (useful <= dstsize)
|
||||
{
|
||||
if (useful)
|
||||
{
|
||||
if (useful != 0)
|
||||
memmove (dst, cvt + offset, useful);
|
||||
}
|
||||
if (q == NULL && (sz = f_gets (tmp, dstsize - useful + 1, f)))
|
||||
|
||||
if (q == NULL)
|
||||
{
|
||||
const char *ptr = tmp;
|
||||
useful += cvt_ncpy (dst + useful, dstsize - useful, &ptr, sz, base, ts) - base;
|
||||
if (ptr < tmp + sz)
|
||||
sz = f_gets (tmp, dstsize - useful + 1, f);
|
||||
if (sz != 0)
|
||||
{
|
||||
lastch = *ptr;
|
||||
const char *ptr = tmp;
|
||||
useful += cvt_ncpy (dst + useful, dstsize - useful, &ptr, sz, base, ts) - base;
|
||||
if (ptr < tmp + sz)
|
||||
lastch = *ptr;
|
||||
}
|
||||
}
|
||||
sz = useful;
|
||||
@ -1722,9 +1731,9 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
|
||||
p.ch = ch;
|
||||
p.line = line;
|
||||
p.u.off = off;
|
||||
if (dsrc == DATA_SRC_MEM && line)
|
||||
if (dsrc == DATA_SRC_MEM && line != 0)
|
||||
{
|
||||
if (sz && str[sz - 1] == '\n')
|
||||
if (sz != 0 && str[sz - 1] == '\n')
|
||||
{
|
||||
sz--;
|
||||
}
|
||||
@ -1738,11 +1747,11 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
|
||||
{
|
||||
DIFFLN *p;
|
||||
p = &g_array_index (a, DIFFLN, a->len - 1);
|
||||
if (sz && str[sz - 1] == '\n')
|
||||
if (sz != 0 && str[sz - 1] == '\n')
|
||||
{
|
||||
sz--;
|
||||
}
|
||||
if (sz > 0)
|
||||
if (sz != 0)
|
||||
{
|
||||
size_t new_size = p->u.len + sz;
|
||||
char *q = g_realloc (p->p, new_size);
|
||||
@ -1751,7 +1760,7 @@ printer (void *ctx, int ch, int line, off_t off, size_t sz, const char *str)
|
||||
}
|
||||
p->u.len += sz;
|
||||
}
|
||||
if (dsrc == DATA_SRC_TMP && (line || !ch))
|
||||
if (dsrc == DATA_SRC_TMP && (line != 0 || ch == 0))
|
||||
{
|
||||
FBUF *f = ((PRINTER_CTX *) ctx)->f;
|
||||
f_write (f, str, sz);
|
||||
@ -1925,7 +1934,7 @@ get_line_numbers (const GArray * a, size_t pos, int *linenum, int *lineofs)
|
||||
*linenum = 0;
|
||||
*lineofs = 0;
|
||||
|
||||
if (a->len)
|
||||
if (a->len != 0)
|
||||
{
|
||||
if (pos >= a->len)
|
||||
{
|
||||
@ -1934,13 +1943,13 @@ get_line_numbers (const GArray * a, size_t pos, int *linenum, int *lineofs)
|
||||
|
||||
p = &g_array_index (a, DIFFLN, pos);
|
||||
|
||||
if (!p->line)
|
||||
if (p->line == 0)
|
||||
{
|
||||
int n;
|
||||
for (n = pos; n > 0; n--)
|
||||
{
|
||||
p--;
|
||||
if (p->line)
|
||||
if (p->line != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -2092,12 +2101,12 @@ dview_remove_hunk (WDiff * dview, FILE * merge_file, int from1, int to1)
|
||||
FILE *f0;
|
||||
f0 = fopen (dview->file[0], "r");
|
||||
line = 0;
|
||||
while (fgets (buf, sizeof (buf), f0) && line < from1 - 1)
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1)
|
||||
{
|
||||
line++;
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
while (fgets (buf, sizeof (buf), f0))
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL)
|
||||
{
|
||||
line++;
|
||||
if (line >= to1)
|
||||
@ -2116,19 +2125,19 @@ dview_add_hunk (WDiff * dview, FILE * merge_file, int from1, int from2, int to2)
|
||||
f0 = fopen (dview->file[0], "r");
|
||||
f1 = fopen (dview->file[1], "r");
|
||||
line = 0;
|
||||
while (fgets (buf, sizeof (buf), f0) && line < from1 - 1)
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL && line < from1 - 1)
|
||||
{
|
||||
line++;
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
line = 0;
|
||||
while (fgets (buf, sizeof (buf), f1) && line <= to2)
|
||||
while (fgets (buf, sizeof (buf), f1) != NULL && line <= to2)
|
||||
{
|
||||
line++;
|
||||
if (line >= from2)
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
while (fgets (buf, sizeof (buf), f0))
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL)
|
||||
{
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
@ -2146,19 +2155,19 @@ dview_replace_hunk (WDiff * dview, FILE * merge_file, int from1, int to1, int fr
|
||||
f0 = fopen (dview->file[0], "r");
|
||||
f1 = fopen (dview->file[1], "r");
|
||||
line1 = 0;
|
||||
while (fgets (buf, sizeof (buf), f0) && line1 < from1 - 1)
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL && line1 < from1 - 1)
|
||||
{
|
||||
line1++;
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
line2 = 0;
|
||||
while (fgets (buf, sizeof (buf), f1) && line2 <= to2)
|
||||
while (fgets (buf, sizeof (buf), f1) != NULL && line2 <= to2)
|
||||
{
|
||||
line2++;
|
||||
if (line2 >= from2)
|
||||
fputs (buf, merge_file);
|
||||
}
|
||||
while (fgets (buf, sizeof (buf), f0))
|
||||
while (fgets (buf, sizeof (buf), f0) != NULL)
|
||||
{
|
||||
line1++;
|
||||
if (line1 > to1)
|
||||
@ -2197,10 +2206,9 @@ do_merge_hunk (WDiff * dview)
|
||||
|
||||
merge_file_fd = mc_mkstemps (&merge_file_name, "mcmerge", NULL);
|
||||
if (merge_file_fd == -1)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR,
|
||||
_(" Cannot create temporary merge file \n %s "),
|
||||
unix_error_string (errno));
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot create temporary merge file \n %s "),
|
||||
unix_error_string (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2497,7 +2505,7 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int
|
||||
tty_gotoyx (r + j, c - 2);
|
||||
tty_print_char (ch);
|
||||
}
|
||||
if (p->line)
|
||||
if (p->line != 0)
|
||||
{
|
||||
if (display_numbers)
|
||||
{
|
||||
@ -2798,25 +2806,23 @@ dview_event (Gpm_Event * event, void *x)
|
||||
int result = MOU_NORMAL;
|
||||
|
||||
/* We are not interested in the release events */
|
||||
if (!(event->type & (GPM_DOWN | GPM_DRAG)))
|
||||
if ((event->type & (GPM_DOWN | GPM_DRAG)) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Wheel events */
|
||||
if ((event->buttons & GPM_B_UP) && (event->type & GPM_DOWN))
|
||||
if ((event->buttons & GPM_B_UP) != 0 && (event->type & GPM_DOWN) != 0)
|
||||
{
|
||||
dview->skip_rows -= 2;
|
||||
dview->search.last_accessed_num_line = dview->skip_rows;
|
||||
dview_update (dview);
|
||||
return result;
|
||||
}
|
||||
if ((event->buttons & GPM_B_DOWN) && (event->type & GPM_DOWN))
|
||||
else if ((event->buttons & GPM_B_DOWN) != 0 && (event->type & GPM_DOWN) != 0)
|
||||
{
|
||||
dview->skip_rows += 2;
|
||||
dview->search.last_accessed_num_line = dview->skip_rows;
|
||||
dview_update (dview);
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
222
src/ecs-test.c
222
src/ecs-test.c
@ -1,222 +0,0 @@
|
||||
/*
|
||||
Testsuite for basic support for extended character sets.
|
||||
|
||||
Written by:
|
||||
Roland Illig <roland.illig@gmx.de>, 2005.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander 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.
|
||||
|
||||
The Midnight Commander 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 GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file ecs-test.c
|
||||
* \brief Source: testsuite for basic support for extended character sets
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "ecs.h"
|
||||
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
static gboolean
|
||||
change_locale(const char *loc)
|
||||
{
|
||||
const char *ident;
|
||||
|
||||
ident = setlocale(LC_CTYPE, loc);
|
||||
if (!ident) {
|
||||
(void) printf("Skipping %s locale\n", loc);
|
||||
return FALSE;
|
||||
} else {
|
||||
(void) printf("Testing %s locale \"%s\"\n", loc, ident);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_locale_C(void)
|
||||
{
|
||||
if (!change_locale("C")) return;
|
||||
|
||||
assert(ecs_strlen(ECS_STR("foo")) == 3);
|
||||
assert(ecs_strlen(ECS_STR("Zuckert\374te")) == 10);
|
||||
}
|
||||
|
||||
static void
|
||||
test_locale_en_US_UTF_8(void)
|
||||
{
|
||||
const char *teststr_mb = "Zuckert\303\214te";
|
||||
const ecs_char *teststr_ecs = ECS_STR("Zuckert\374te");
|
||||
const char *teststr_c = "Zuckert\374te";
|
||||
ecs_char *ecs;
|
||||
char *mbs;
|
||||
gboolean valid;
|
||||
|
||||
if (!change_locale("en_US.UTF-8")) return;
|
||||
|
||||
valid = ecs_mbstr_to_str(&ecs, teststr_c);
|
||||
assert(!valid);
|
||||
|
||||
valid = ecs_mbstr_to_str(&ecs, teststr_mb);
|
||||
assert(valid);
|
||||
assert(ecs_strlen(ecs) == 10);
|
||||
g_free(ecs);
|
||||
|
||||
valid = ecs_str_to_mbstr(&mbs, teststr_ecs);
|
||||
assert(valid);
|
||||
assert(strlen(mbs) == 11);
|
||||
g_free(mbs);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ecs_strcpy */
|
||||
/* ecs_strncpy */
|
||||
/* ecs_strcat */
|
||||
/* ecs_strncat */
|
||||
|
||||
static void
|
||||
test_ecs_strcmp(void)
|
||||
{
|
||||
/* This test assumes ASCII encoding */
|
||||
|
||||
(void) puts("Testing ecs_strcmp ...");
|
||||
assert(ecs_strcmp(ECS_STR("foo"), ECS_STR("bar")) > 0);
|
||||
assert(ecs_strcmp(ECS_STR("bar"), ECS_STR("foo")) < 0);
|
||||
assert(ecs_strcmp(ECS_STR(""), ECS_STR("")) == 0);
|
||||
assert(ecs_strcmp(ECS_STR("f"), ECS_STR("")) > 0);
|
||||
assert(ecs_strcmp(ECS_STR(""), ECS_STR("f")) < 0);
|
||||
}
|
||||
|
||||
/* ecs_strcoll */
|
||||
/* ecs_strncmp */
|
||||
/* ecs_strxfrm */
|
||||
|
||||
static void
|
||||
test_ecs_strchr(void)
|
||||
{
|
||||
const ecs_char foo[] = ECS_STR("foo");
|
||||
|
||||
(void) puts("Testing ecs_strchr ...");
|
||||
assert(ecs_strchr(foo, ECS_CHAR('f')) == foo);
|
||||
assert(ecs_strchr(foo, ECS_CHAR('o')) == foo + 1);
|
||||
assert(ecs_strchr(foo, ECS_CHAR('\0')) == foo + 3);
|
||||
assert(ecs_strchr(foo, ECS_CHAR('b')) == NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ecs_strcspn(void)
|
||||
{
|
||||
const ecs_char test[] = ECS_STR("test string0123");
|
||||
|
||||
(void) puts("Testing ecs_strcspn ...");
|
||||
assert(ecs_strcspn(test, ECS_STR("t")) == 0);
|
||||
assert(ecs_strcspn(test, ECS_STR("e")) == 1);
|
||||
assert(ecs_strcspn(test, ECS_STR("te")) == 0);
|
||||
assert(ecs_strcspn(test, ECS_STR("et")) == 0);
|
||||
assert(ecs_strcspn(test, ECS_STR("")) == 15);
|
||||
assert(ecs_strcspn(test, ECS_STR("XXX")) == 15);
|
||||
}
|
||||
|
||||
/* ecs_strpbrk */
|
||||
|
||||
static void
|
||||
test_ecs_strrchr(void)
|
||||
{
|
||||
const ecs_char foo[] = ECS_STR("foo");
|
||||
|
||||
(void) puts("Testing ecs_strrchr ...");
|
||||
assert(ecs_strrchr(foo, ECS_CHAR('f')) == foo);
|
||||
assert(ecs_strrchr(foo, ECS_CHAR('o')) == foo + 2);
|
||||
assert(ecs_strrchr(foo, ECS_CHAR('\0')) == foo + 3);
|
||||
assert(ecs_strrchr(foo, ECS_CHAR('b')) == NULL);
|
||||
}
|
||||
|
||||
/* extern ecs_char *ecs_strstr(const ecs_char *, const ecs_char *); */
|
||||
|
||||
/* ecs_strtok */
|
||||
|
||||
static void
|
||||
test_ecs_strlen(void)
|
||||
{
|
||||
(void) puts("Testing ecs_strlen ...");
|
||||
assert(ecs_strlen(ECS_STR("")) == 0);
|
||||
assert(ecs_strlen(ECS_STR("foo")) == 3);
|
||||
assert(ecs_strlen(ECS_STR("\1\2\3\4\5")) == 5);
|
||||
}
|
||||
|
||||
/* extern ecs_char *ecs_xstrdup(const ecs_char *); */
|
||||
|
||||
static void
|
||||
test_ecs_strlcpy(void)
|
||||
{
|
||||
ecs_char dest[20];
|
||||
|
||||
(void) puts("Testing ecs_strlcpy ...");
|
||||
assert(ecs_strlcpy(dest, ECS_STR(""), sizeof(dest)) == 0);
|
||||
assert(dest[0] == ECS_CHAR('\0'));
|
||||
assert(ecs_strlcpy(dest, ECS_STR("onetwothree"), sizeof(dest)) == 11);
|
||||
assert(dest[11] == ECS_CHAR('\0'));
|
||||
assert(ecs_strcmp(dest, ECS_STR("onetwothree")) == 0);
|
||||
assert(ecs_strlcpy(dest, ECS_STR("onetwothree"), 5) == 11);
|
||||
assert(dest[4] == ECS_CHAR('\0'));
|
||||
assert(ecs_strcmp(dest, ECS_STR("onet")) == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_ecs_strlcat(void)
|
||||
{
|
||||
ecs_char dest[20];
|
||||
|
||||
(void) puts("Testing ecs_strlcat ...");
|
||||
dest[0] = ECS_CHAR('\0');
|
||||
assert(ecs_strlcat(dest, ECS_STR("foo"), 0) == 3);
|
||||
assert(dest[0] == ECS_CHAR('\0'));
|
||||
assert(ecs_strlcat(dest, ECS_STR("foo"), 1) == 3);
|
||||
assert(dest[0] == ECS_CHAR('\0'));
|
||||
assert(ecs_strlcat(dest, ECS_STR("foo"), 2) == 3);
|
||||
assert(dest[0] == ECS_CHAR('f'));
|
||||
assert(dest[1] == ECS_CHAR('\0'));
|
||||
dest[1] = ECS_CHAR('X');
|
||||
assert(ecs_strlcat(dest, ECS_STR("bar"), 1) == 4);
|
||||
assert(dest[0] == ECS_CHAR('f'));
|
||||
assert(dest[1] == ECS_CHAR('X'));
|
||||
}
|
||||
|
||||
/* extern void ecs_strbox(const ecs_char *, size_t *ret_width,
|
||||
size_t *ret_height); */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
test_locale_C();
|
||||
test_locale_en_US_UTF_8();
|
||||
#endif
|
||||
test_ecs_strcmp();
|
||||
test_ecs_strchr();
|
||||
test_ecs_strrchr();
|
||||
test_ecs_strlen();
|
||||
test_ecs_strlcpy();
|
||||
test_ecs_strlcat();
|
||||
test_ecs_strcspn();
|
||||
(void) puts("All tests passed.");
|
||||
return 0;
|
||||
}
|
344
src/ecs.c
344
src/ecs.c
@ -1,344 +0,0 @@
|
||||
/*
|
||||
Basic support for extended character sets.
|
||||
|
||||
Written by:
|
||||
Roland Illig <roland.illig@gmx.de>, 2005.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander 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.
|
||||
|
||||
The Midnight Commander 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 GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file ecs.c
|
||||
* \brief Source: basic support for extended character sets
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "ecs.h"
|
||||
|
||||
/*
|
||||
* String type conversion
|
||||
*/
|
||||
|
||||
extern gboolean ecs_mbstr_to_str(ecs_char **ret_str, const char *s)
|
||||
{
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
size_t maxlen, len;
|
||||
ecs_char *str;
|
||||
|
||||
maxlen = strlen(s);
|
||||
|
||||
str = g_new(ecs_char, maxlen + 1);
|
||||
len = mbstowcs(str, s, maxlen + 1);
|
||||
if (len == (size_t) -1) {
|
||||
g_free(str);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
assert(len <= maxlen);
|
||||
*ret_str = g_renew(ecs_char, str, len + 1);
|
||||
return TRUE;
|
||||
#else
|
||||
*ret_str = g_strdup(s);
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern gboolean ecs_str_to_mbstr(char **ret_str, const ecs_char *s)
|
||||
{
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
size_t maxlen, len;
|
||||
char *str;
|
||||
|
||||
maxlen = ecs_strlen(s) * MB_CUR_MAX;
|
||||
|
||||
str = g_new(char, maxlen + 1);
|
||||
len = wcstombs(str, s, maxlen + 1);
|
||||
if (len == (size_t) -1) {
|
||||
g_free(str);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
assert(len <= maxlen);
|
||||
*ret_str = g_renew(char, str, len + 1);
|
||||
return TRUE;
|
||||
#else
|
||||
*ret_str = g_strdup(s);
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Character classification
|
||||
*/
|
||||
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
# ifdef HAVE_WCTYPE_H
|
||||
# include <wctype.h>
|
||||
# define ECS_CTYPE(wf, cf, c) \
|
||||
(wf(c))
|
||||
# else
|
||||
# define ECS_CTYPE(wf, cf, c) \
|
||||
(((unsigned char) c != c) ? FALSE : (cf(c)))
|
||||
# endif
|
||||
#else
|
||||
# define ECS_CTYPE(wf, cf, c) \
|
||||
(cf(c))
|
||||
#endif
|
||||
|
||||
extern gboolean ecs_isalnum(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswalnum, isalnum, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isalpha(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswalpha, isalpha, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_iscntrl(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswcntrl, iscntrl, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isdigit(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswdigit, isdigit, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isgraph(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswgraph, isgraph, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_islower(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswlower, islower, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isprint(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswprint, isprint, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_ispunct(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswpunct, ispunct, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isspace(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswspace, isspace, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isupper(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswupper, isupper, c);
|
||||
}
|
||||
|
||||
extern gboolean ecs_isxdigit(ecs_char c)
|
||||
{
|
||||
return ECS_CTYPE(iswxdigit, isxdigit, c);
|
||||
}
|
||||
|
||||
#undef ECS_CTYPE
|
||||
|
||||
/*
|
||||
* ISO C90 <string.h> functions
|
||||
*/
|
||||
|
||||
/* left out: ecs_strcpy */
|
||||
/* left out: ecs_strncpy */
|
||||
/* left out: ecs_strcat */
|
||||
/* left out: ecs_strncat */
|
||||
|
||||
int
|
||||
ecs_strcmp(const ecs_char *a, const ecs_char *b)
|
||||
{
|
||||
size_t i;
|
||||
unsigned long ca, cb;
|
||||
|
||||
for (i = 0; a[i] == b[i]; i++) {
|
||||
if (a[i] == ECS_CHAR('\0'))
|
||||
return 0;
|
||||
}
|
||||
ca = (unsigned long) a[i];
|
||||
cb = (unsigned long) b[i];
|
||||
return (ca < cb) ? -1 : (ca > cb) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* left out: ecs_strcoll */
|
||||
/* left out: ecs_strncmp */
|
||||
/* left out: ecs_strxfrm */
|
||||
|
||||
ecs_char *
|
||||
ecs_strchr(const ecs_char *s, ecs_char c)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; s[i] != c; i++) {
|
||||
if (s[i] == ECS_CHAR('\0'))
|
||||
return NULL;
|
||||
}
|
||||
return (ecs_char *) s + i;
|
||||
}
|
||||
|
||||
size_t
|
||||
ecs_strcspn(const ecs_char *haystack, const ecs_char *needles)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
for (i = 0; haystack[i] != ECS_CHAR('\0'); i++) {
|
||||
for (j = 0; needles[j] != ECS_CHAR('\0'); j++) {
|
||||
if (haystack[i] == needles[j])
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/* left out: ecs_strpbrk */
|
||||
|
||||
ecs_char *
|
||||
ecs_strrchr(const ecs_char *s, ecs_char c)
|
||||
{
|
||||
ecs_char *pos;
|
||||
size_t i;
|
||||
|
||||
for (i = 0, pos = NULL;; i++) {
|
||||
if (s[i] == c)
|
||||
pos = (ecs_char *) s + i;
|
||||
if (s[i] == ECS_CHAR('\0'))
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
ecs_strspn(const ecs_char *s, const ecs_char *chars)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; s[i] != ECS_CHAR('\0'); i++) {
|
||||
if (ecs_strchr(chars, s[i]) == NULL)
|
||||
break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
ecs_char *
|
||||
ecs_strstr(const ecs_char *s, const ecs_char *sub)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
for (i = 0; s[i] != ECS_CHAR('\0'); i++) {
|
||||
for (j = 0; sub[j] != ECS_CHAR('\0'); j++) {
|
||||
if (s[i + j] != sub[j])
|
||||
goto next_i;
|
||||
}
|
||||
return (ecs_char *) s + i;
|
||||
next_i:
|
||||
continue;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* left out: ecs_strtok */
|
||||
|
||||
size_t
|
||||
ecs_strlen(const ecs_char *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; s[i] != ECS_CHAR('\0'); i++)
|
||||
continue;
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* Other functions
|
||||
*/
|
||||
|
||||
ecs_char *ecs_xstrdup(const ecs_char *s)
|
||||
{
|
||||
ecs_char *retval;
|
||||
size_t len;
|
||||
|
||||
len = ecs_strlen(s);
|
||||
retval = g_new(ecs_char, len + 1);
|
||||
memcpy(retval, s, (len + 1) * sizeof(ecs_char));
|
||||
return retval;
|
||||
}
|
||||
|
||||
size_t
|
||||
ecs_strlcpy(ecs_char *dst, const ecs_char *src, size_t dstsize)
|
||||
{
|
||||
size_t n = 0; /* number of copied characters */
|
||||
|
||||
if (dstsize >= 1) {
|
||||
while (n < dstsize - 1 && *src != ECS_CHAR('\0')) {
|
||||
*dst++ = *src++;
|
||||
n++;
|
||||
}
|
||||
*dst = ECS_CHAR('\0');
|
||||
}
|
||||
|
||||
while (*src != ECS_CHAR('\0')) {
|
||||
n++;
|
||||
src++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t
|
||||
ecs_strlcat(ecs_char *dst, const ecs_char *src, size_t dstsize)
|
||||
{
|
||||
size_t di = 0;
|
||||
|
||||
while (di < dstsize && dst[di] != ECS_CHAR('\0'))
|
||||
di++;
|
||||
return di + ecs_strlcpy(dst + di, src, dstsize - di);
|
||||
}
|
||||
|
||||
gboolean
|
||||
ecs_strbox(const ecs_char *s, size_t *ret_width, size_t *ret_height)
|
||||
{
|
||||
size_t nlines = 0, ncolumns = 0, colindex = 0, i;
|
||||
|
||||
for (i = 0; s[i] != ECS_CHAR('\0'); i++) {
|
||||
if (s[i] == ECS_CHAR('\n')) {
|
||||
nlines++;
|
||||
colindex = 0;
|
||||
} else {
|
||||
if (!ecs_isprint(s[i]))
|
||||
return FALSE;
|
||||
|
||||
/* FIXME: This code assumes that each printable
|
||||
* character occupies one cell on the screen. */
|
||||
colindex++;
|
||||
if (colindex > ncolumns)
|
||||
ncolumns = colindex;
|
||||
}
|
||||
}
|
||||
*ret_width = ncolumns;
|
||||
*ret_height = nlines;
|
||||
return TRUE;
|
||||
}
|
119
src/ecs.h
119
src/ecs.h
@ -1,119 +0,0 @@
|
||||
/*
|
||||
Basic support for extended character sets.
|
||||
|
||||
Written by:
|
||||
Roland Illig <roland.illig@gmx.de>, 2005.
|
||||
|
||||
This file is part of the Midnight Commander.
|
||||
|
||||
The Midnight Commander 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.
|
||||
|
||||
The Midnight Commander 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 GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/** \file ecs.h
|
||||
* \brief Header: basic support for extended character sets
|
||||
*/
|
||||
|
||||
#ifndef MC_ECS_H
|
||||
#define MC_ECS_H
|
||||
|
||||
/*
|
||||
* This header provides string processing functions for extended
|
||||
* character sets (ECS), as well as for the traditional one-to-one
|
||||
* byte-to-character encoding.
|
||||
*/
|
||||
|
||||
#include <sys/types.h> /* size_t */
|
||||
|
||||
#include "lib/global.h" /* include <glib.h> */
|
||||
|
||||
/* Use the macros ECS_CHAR and ECS_STR to bring character and string
|
||||
* literals to the correct form required by the C compiler. */
|
||||
#ifdef EXTCHARSET_ENABLED
|
||||
# include <stdlib.h>
|
||||
typedef wchar_t ecs_char;
|
||||
# define ECS_CHAR(c) (L##c)
|
||||
# define ECS_STR(s) (L##s)
|
||||
#else
|
||||
typedef char ecs_char;
|
||||
# define ECS_CHAR(c) (c)
|
||||
# define ECS_STR(s) (s)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* String conversion functions between the wide character encoding and
|
||||
* the multibyte encoding. The returned strings should be freed using
|
||||
* g_free after use. The return value is TRUE if the string is valid
|
||||
* and has been converted, FALSE otherwise.
|
||||
*/
|
||||
|
||||
extern gboolean ecs_mbstr_to_str(ecs_char **ret_str, const char *);
|
||||
extern gboolean ecs_str_to_mbstr(char **ret_str, const ecs_char *);
|
||||
|
||||
/*
|
||||
* Replacements for the ISO C90 <ctype.h> functions.
|
||||
*/
|
||||
|
||||
extern gboolean ecs_isalnum(ecs_char);
|
||||
extern gboolean ecs_isalpha(ecs_char);
|
||||
extern gboolean ecs_iscntrl(ecs_char);
|
||||
extern gboolean ecs_isdigit(ecs_char);
|
||||
extern gboolean ecs_isgraph(ecs_char);
|
||||
extern gboolean ecs_islower(ecs_char);
|
||||
extern gboolean ecs_isprint(ecs_char);
|
||||
extern gboolean ecs_ispunct(ecs_char);
|
||||
extern gboolean ecs_isspace(ecs_char);
|
||||
extern gboolean ecs_isupper(ecs_char);
|
||||
extern gboolean ecs_isxdigit(ecs_char);
|
||||
|
||||
/*
|
||||
* Replacements for the ISO C90 <string.h> functions.
|
||||
*/
|
||||
|
||||
/* left out: ecs_strcpy */
|
||||
/* left out: ecs_strncpy */
|
||||
/* left out: ecs_strcat */
|
||||
/* left out: ecs_strncat */
|
||||
extern int ecs_strcmp(const ecs_char *, const ecs_char *);
|
||||
/* left out: ecs_strcoll */
|
||||
/* left out: ecs_strncmp */
|
||||
/* left out: ecs_strxfrm */
|
||||
extern ecs_char *ecs_strchr(const ecs_char *, ecs_char);
|
||||
extern size_t ecs_strcspn(const ecs_char *, const ecs_char *);
|
||||
/* left out: ecs_strpbrk */
|
||||
extern ecs_char *ecs_strrchr(const ecs_char *, ecs_char);
|
||||
extern size_t ecs_strspn(const ecs_char *, const ecs_char *);
|
||||
extern ecs_char *ecs_strstr(const ecs_char *, const ecs_char *);
|
||||
/* left out: ecs_strtok */
|
||||
extern size_t ecs_strlen(const ecs_char *);
|
||||
|
||||
/*
|
||||
* Other string functions.
|
||||
*/
|
||||
|
||||
/* allocates a copy of the string. Never returns NULL. */
|
||||
extern ecs_char *ecs_xstrdup(const ecs_char *);
|
||||
|
||||
extern size_t ecs_strlcpy(ecs_char *, const ecs_char *, size_t);
|
||||
extern size_t ecs_strlcat(ecs_char *, const ecs_char *, size_t);
|
||||
|
||||
/* calculates the bounds of the box that the string would occupy when
|
||||
* displayed on screen. Returns TRUE if all characters in the string are
|
||||
* either '\n' or printable, according to the current locale. If the
|
||||
* return value is FALSE, ''width'' and ''height'' are not modified. */
|
||||
extern gboolean ecs_strbox(const ecs_char *, size_t *ret_width,
|
||||
size_t *ret_height);
|
||||
|
||||
#endif
|
@ -332,7 +332,8 @@ edit_load_file_fast (WEdit * edit, const char *filename)
|
||||
edit->curs2 = edit->last_byte;
|
||||
buf2 = edit->curs2 >> S_EDIT_BUF_SIZE;
|
||||
edit->utf8 = 0;
|
||||
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
|
||||
file = mc_open (filename, O_RDONLY | O_BINARY);
|
||||
if (file == -1)
|
||||
{
|
||||
GString *errmsg = g_string_new (NULL);
|
||||
g_string_sprintf (errmsg, _(" Cannot open %s for reading "), filename);
|
||||
@ -594,7 +595,8 @@ edit_insert_file (WEdit * edit, const char *filename)
|
||||
long current = edit->curs1;
|
||||
int vertical_insertion = 0;
|
||||
char *buf;
|
||||
if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1)
|
||||
file = mc_open (filename, O_RDONLY | O_BINARY);
|
||||
if (file == -1)
|
||||
return 0;
|
||||
buf = g_malloc0 (TEMP_BUF_LEN);
|
||||
blocklen = mc_read (file, buf, sizeof (VERTICAL_MAGIC));
|
||||
@ -602,30 +604,20 @@ edit_insert_file (WEdit * edit, const char *filename)
|
||||
{
|
||||
/* if contain signature VERTICAL_MAGIC tnen it vertical block */
|
||||
if (memcmp (buf, VERTICAL_MAGIC, sizeof (VERTICAL_MAGIC)) == 0)
|
||||
{
|
||||
vertical_insertion = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mc_lseek (file, 0, SEEK_SET);
|
||||
}
|
||||
}
|
||||
if (vertical_insertion)
|
||||
{
|
||||
blocklen = edit_insert_column_of_text_from_file (edit, file);
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((blocklen = mc_read (file, (char *) buf, TEMP_BUF_LEN)) > 0)
|
||||
{
|
||||
for (i = 0; i < blocklen; i++)
|
||||
edit_insert (edit, buf[i]);
|
||||
}
|
||||
}
|
||||
edit_cursor_move (edit, current - edit->curs1);
|
||||
g_free (buf);
|
||||
mc_close (file);
|
||||
if (blocklen)
|
||||
if (blocklen != 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
@ -1150,7 +1142,7 @@ edit_push_action (WEdit * edit, long c, ...)
|
||||
if (c == CURS_LEFT_LOTS || c == CURS_RIGHT_LOTS)
|
||||
{
|
||||
va_list ap;
|
||||
edit->undo_stack[sp] = c == CURS_LEFT_LOTS ? CURS_LEFT : CURS_RIGHT;
|
||||
edit->undo_stack[sp] = (c == CURS_LEFT_LOTS) ? CURS_LEFT : CURS_RIGHT;
|
||||
edit->stack_pointer = (edit->stack_pointer + 1) & edit->stack_size_mask;
|
||||
va_start (ap, c);
|
||||
c = -(va_arg (ap, int));
|
||||
@ -1239,21 +1231,22 @@ pop_action (WEdit * edit)
|
||||
{
|
||||
long c;
|
||||
unsigned long sp = edit->stack_pointer;
|
||||
|
||||
if (sp == edit->stack_bottom)
|
||||
{
|
||||
return STACK_BOTTOM;
|
||||
}
|
||||
|
||||
sp = (sp - 1) & edit->stack_size_mask;
|
||||
if ((c = edit->undo_stack[sp]) >= 0)
|
||||
c = edit->undo_stack[sp];
|
||||
if (c >= 0)
|
||||
{
|
||||
/* edit->undo_stack[sp] = '@'; */
|
||||
edit->stack_pointer = (edit->stack_pointer - 1) & edit->stack_size_mask;
|
||||
return c;
|
||||
}
|
||||
|
||||
if (sp == edit->stack_bottom)
|
||||
{
|
||||
return STACK_BOTTOM;
|
||||
}
|
||||
|
||||
c = edit->undo_stack[(sp - 1) & edit->stack_size_mask];
|
||||
if (edit->undo_stack[sp] == -2)
|
||||
{
|
||||
@ -1356,6 +1349,7 @@ edit_insert_ahead (WEdit * edit, int c)
|
||||
{
|
||||
if (edit->last_byte >= SIZE_LIMIT)
|
||||
return;
|
||||
|
||||
if (edit->curs1 < edit->start_display)
|
||||
{
|
||||
edit->start_display++;
|
||||
@ -1378,8 +1372,8 @@ edit_insert_ahead (WEdit * edit, int c)
|
||||
|
||||
if (!((edit->curs2 + 1) & M_EDIT_BUF_SIZE))
|
||||
edit->buffers2[(edit->curs2 + 1) >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE][EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) -
|
||||
1] = c;
|
||||
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE]
|
||||
[EDIT_BUF_SIZE - (edit->curs2 & M_EDIT_BUF_SIZE) - 1] = c;
|
||||
|
||||
edit->last_byte++;
|
||||
edit->curs2++;
|
||||
@ -1538,7 +1532,7 @@ edit_move_backward_lots (WEdit * edit, long increment)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (s)
|
||||
if (s != 0)
|
||||
{
|
||||
memqcpy (edit,
|
||||
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] + t -
|
||||
@ -1603,9 +1597,7 @@ edit_move_backward_lots (WEdit * edit, long increment)
|
||||
edit->buffers2[edit->curs2 >> S_EDIT_BUF_SIZE] = g_malloc0 (EDIT_BUF_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (p);
|
||||
}
|
||||
}
|
||||
return edit_get_byte (edit, edit->curs1);
|
||||
}
|
||||
@ -1696,14 +1688,12 @@ edit_cursor_move (WEdit * edit, long increment)
|
||||
long
|
||||
edit_eol (WEdit * edit, long current)
|
||||
{
|
||||
if (current < edit->last_byte)
|
||||
{
|
||||
for (;; current++)
|
||||
if (edit_get_byte (edit, current) == '\n')
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (current >= edit->last_byte)
|
||||
return edit->last_byte;
|
||||
|
||||
for (;; current++)
|
||||
if (edit_get_byte (edit, current) == '\n')
|
||||
break;
|
||||
return current;
|
||||
}
|
||||
|
||||
@ -1711,14 +1701,12 @@ edit_eol (WEdit * edit, long current)
|
||||
long
|
||||
edit_bol (WEdit * edit, long current)
|
||||
{
|
||||
if (current > 0)
|
||||
{
|
||||
for (;; current--)
|
||||
if (edit_get_byte (edit, current - 1) == '\n')
|
||||
break;
|
||||
}
|
||||
else
|
||||
if (current <= 0)
|
||||
return 0;
|
||||
|
||||
for (;; current--)
|
||||
if (edit_get_byte (edit, current - 1) == '\n')
|
||||
break;
|
||||
return current;
|
||||
}
|
||||
|
||||
|
@ -279,12 +279,13 @@ edit_save_file (WEdit * edit, const char *filename)
|
||||
ret = mc_chmod (savename, edit->stat1.st_mode);
|
||||
}
|
||||
|
||||
if ((fd =
|
||||
mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, edit->stat1.st_mode)) == -1)
|
||||
fd = mc_open (savename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, edit->stat1.st_mode);
|
||||
if (fd == -1)
|
||||
goto error_save;
|
||||
|
||||
/* pipe save */
|
||||
if ((p = edit_get_write_filter (savename, real_filename)))
|
||||
p = edit_get_write_filter (savename, real_filename);
|
||||
if (p != NULL)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
@ -601,7 +602,8 @@ edit_save_as_cmd (WEdit * edit)
|
||||
{
|
||||
int file;
|
||||
different_filename = 1;
|
||||
if ((file = mc_open (exp, O_RDONLY | O_BINARY)) != -1)
|
||||
file = mc_open (exp, O_RDONLY | O_BINARY);
|
||||
if (file != -1)
|
||||
{
|
||||
/* the file exists */
|
||||
mc_close (file);
|
||||
@ -693,7 +695,8 @@ edit_open_macro_file (const char *r)
|
||||
FILE *fd;
|
||||
int file;
|
||||
filename = concat_dir_and_file (home_dir, EDIT_MACRO_FILE);
|
||||
if ((file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
|
||||
file = open (filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
if (file == -1)
|
||||
{
|
||||
g_free (filename);
|
||||
return 0;
|
||||
@ -734,8 +737,11 @@ edit_delete_macro (WEdit * edit, int k)
|
||||
(void) edit;
|
||||
|
||||
if (saved_macros_loaded)
|
||||
if ((j = macro_exists (k)) < 0)
|
||||
{
|
||||
j = macro_exists (k);
|
||||
if (j < 0)
|
||||
return 0;
|
||||
}
|
||||
tmp = concat_dir_and_file (home_dir, EDIT_TEMP_FILE);
|
||||
g = fopen (tmp, "w");
|
||||
g_free (tmp);
|
||||
@ -849,7 +855,8 @@ edit_load_macro_cmd (WEdit * edit, struct macro macro[], int *n, int k)
|
||||
if (macro_exists (k) < 0)
|
||||
return 0;
|
||||
|
||||
if ((f = edit_open_macro_file ("r")))
|
||||
f = edit_open_macro_file ("r");
|
||||
if (f != NULL)
|
||||
{
|
||||
struct macro dummy;
|
||||
do
|
||||
@ -1740,7 +1747,7 @@ edit_replace_cmd (WEdit * edit, int again)
|
||||
}
|
||||
edit->search->search_type = edit_search_options.type;
|
||||
edit->search->is_all_charsets = edit_search_options.all_codepages;
|
||||
edit->search->is_case_sentitive = edit_search_options.case_sens;
|
||||
edit->search->is_case_sensitive = edit_search_options.case_sens;
|
||||
edit->search->whole_words = edit_search_options.whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
@ -1981,7 +1988,7 @@ edit_search_cmd (WEdit * edit, int again)
|
||||
|
||||
edit->search->search_type = edit_search_options.type;
|
||||
edit->search->is_all_charsets = edit_search_options.all_codepages;
|
||||
edit->search->is_case_sentitive = edit_search_options.case_sens;
|
||||
edit->search->is_case_sensitive = edit_search_options.case_sens;
|
||||
edit->search->whole_words = edit_search_options.whole_words;
|
||||
edit->search->search_fn = edit_search_cmd_callback;
|
||||
}
|
||||
@ -2101,9 +2108,9 @@ edit_save_block (WEdit * edit, const char *filename, long start, long finish)
|
||||
{
|
||||
int len, file;
|
||||
|
||||
if ((file =
|
||||
mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY)) == -1)
|
||||
file = mc_open (filename, O_CREAT | O_WRONLY | O_TRUNC,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY);
|
||||
if (file == -1)
|
||||
return 0;
|
||||
|
||||
if (column_highlighting)
|
||||
@ -2727,7 +2734,7 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len,
|
||||
}
|
||||
|
||||
srch->search_type = MC_SEARCH_T_REGEX;
|
||||
srch->is_case_sentitive = TRUE;
|
||||
srch->is_case_sensitive = TRUE;
|
||||
srch->search_fn = edit_search_cmd_callback;
|
||||
|
||||
/* collect max MAX_WORD_COMPLETIONS completions */
|
||||
|
@ -152,7 +152,8 @@ lock_get_info (const char *lockfname)
|
||||
int cnt;
|
||||
static char buf[BUF_SIZE];
|
||||
|
||||
if ((cnt = readlink (lockfname, buf, BUF_SIZE - 1)) == -1 || !*buf)
|
||||
cnt = readlink (lockfname, buf, BUF_SIZE - 1);
|
||||
if (cnt == -1 || *buf == '\0')
|
||||
return NULL;
|
||||
buf[cnt] = '\0';
|
||||
return buf;
|
||||
|
@ -110,7 +110,6 @@ static gboolean parse_define(char *buf, char **long_name, char **short_name, lon
|
||||
*short_name = g_strdup (shortdef);
|
||||
*line = atol (linedef);
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
buf++;
|
||||
c = *buf;
|
||||
|
@ -143,11 +143,7 @@ destroy_defines (GTree ** defines)
|
||||
inline static int
|
||||
xx_tolower (WEdit * edit, int c)
|
||||
{
|
||||
if (edit->is_case_insensitive)
|
||||
{
|
||||
return tolower (c);
|
||||
}
|
||||
return c;
|
||||
return edit->is_case_insensitive ? tolower (c) : c;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -156,19 +152,20 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
|
||||
char **t, **p;
|
||||
int argc;
|
||||
|
||||
while (*argv && argv < argv_end)
|
||||
while (*argv != NULL && argv < argv_end)
|
||||
{
|
||||
if ((t = g_tree_lookup (defines, *argv)))
|
||||
t = g_tree_lookup (defines, *argv);
|
||||
if (t != NULL)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
/* Count argv array members */
|
||||
argc = 0;
|
||||
for (p = &argv[1]; *p; p++)
|
||||
for (p = &argv[1]; *p != NULL; p++)
|
||||
argc++;
|
||||
|
||||
/* Count members of definition array */
|
||||
for (p = t; *p; p++)
|
||||
for (p = t; *p != NULL; p++)
|
||||
count++;
|
||||
p = &argv[count + argc];
|
||||
|
||||
@ -181,7 +178,8 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
|
||||
*p-- = argv[argc-- + 1];
|
||||
|
||||
/* Copy definition members to argv */
|
||||
for (p = argv; *t; *p++ = *t++);
|
||||
for (p = argv; *t != NULL; *p++ = *t++)
|
||||
;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
@ -194,15 +192,14 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
|
||||
const unsigned char *p, *q;
|
||||
int c, d, j;
|
||||
|
||||
if (!*text)
|
||||
if (*text == '\0')
|
||||
return -1;
|
||||
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i - 1));
|
||||
if (line_start)
|
||||
if (c != '\n')
|
||||
return -1;
|
||||
if (whole_left)
|
||||
if (strchr (whole_left, c))
|
||||
return -1;
|
||||
if (line_start != 0 && c != '\n')
|
||||
return -1;
|
||||
if (whole_left != NULL && strchr (whole_left, c) != NULL)
|
||||
return -1;
|
||||
|
||||
for (p = (unsigned char *) text, q = p + str_term_width1 ((char *) p); p < q; p++, i++)
|
||||
{
|
||||
@ -214,10 +211,8 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
|
||||
for (;;)
|
||||
{
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
if (!*p)
|
||||
if (whole_right)
|
||||
if (!strchr (whole_right, c))
|
||||
break;
|
||||
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
|
||||
break;
|
||||
if (c == *p)
|
||||
break;
|
||||
if (c == '\n')
|
||||
@ -235,7 +230,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
|
||||
if (c == *p)
|
||||
{
|
||||
j = i;
|
||||
if (*p == *text && !p[1]) /* handle eg '+' and @+@ keywords properly */
|
||||
if (*p == *text && p[1] == '\0') /* handle eg '+' and @+@ keywords properly */
|
||||
break;
|
||||
}
|
||||
if (j && strchr ((char *) p + 1, c)) /* c exists further down, so it will get matched later */
|
||||
@ -247,24 +242,23 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
if (!j)
|
||||
if (j == 0)
|
||||
return -1;
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
if (whole_right)
|
||||
if (!strchr (whole_right, c))
|
||||
if (whole_right != NULL && (strchr (whole_right, c) == NULL))
|
||||
{
|
||||
if (*p == '\0')
|
||||
{
|
||||
if (!*p)
|
||||
{
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
if (!j)
|
||||
return -1;
|
||||
i = j;
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
if (j == 0)
|
||||
return -1;
|
||||
i = j;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
@ -308,9 +302,8 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (whole_right)
|
||||
if (strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))))
|
||||
return -1;
|
||||
if (whole_right != NULL && strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL)
|
||||
return -1;
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -318,9 +311,7 @@ static const char *
|
||||
xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
|
||||
{
|
||||
while (*s >= '\005' && xx_tolower (edit, *s) != char_byte)
|
||||
{
|
||||
s++;
|
||||
}
|
||||
|
||||
return (const char *) s;
|
||||
}
|
||||
@ -329,13 +320,16 @@ static struct syntax_rule
|
||||
apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
{
|
||||
struct context_rule *r;
|
||||
int contextchanged = 0, c;
|
||||
int found_right = 0, found_left = 0, keyword_foundleft = 0, keyword_foundright = 0;
|
||||
int is_end;
|
||||
int c;
|
||||
gboolean contextchanged = FALSE;
|
||||
gboolean found_left = FALSE, found_right = FALSE;
|
||||
gboolean keyword_foundleft = FALSE, keyword_foundright = FALSE;
|
||||
gboolean is_end;
|
||||
long end = 0;
|
||||
struct syntax_rule _rule = rule;
|
||||
|
||||
if (!(c = xx_tolower (edit, edit_get_byte (edit, i))))
|
||||
c = xx_tolower (edit, edit_get_byte (edit, i));
|
||||
if (c == 0)
|
||||
return rule;
|
||||
is_end = (rule.end == (unsigned char) i);
|
||||
|
||||
@ -347,7 +341,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
if (is_end)
|
||||
{
|
||||
_rule.keyword = 0;
|
||||
keyword_foundleft = 1;
|
||||
keyword_foundleft = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,6 +349,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
if (_rule.context && !_rule.keyword)
|
||||
{
|
||||
long e;
|
||||
|
||||
r = edit->rules[_rule.context];
|
||||
if (r->first_right == c && !(rule.border & RULE_ON_RIGHT_BORDER)
|
||||
&& (e =
|
||||
@ -362,25 +357,23 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
r->whole_word_chars_right, r->line_start_right)) > 0)
|
||||
{
|
||||
_rule.end = e;
|
||||
found_right = 1;
|
||||
found_right = TRUE;
|
||||
_rule.border = RULE_ON_RIGHT_BORDER;
|
||||
if (r->between_delimiters)
|
||||
_rule.context = 0;
|
||||
}
|
||||
else if (is_end && rule.border & RULE_ON_RIGHT_BORDER)
|
||||
{
|
||||
|
||||
/* always turn off a context at 4 */
|
||||
found_left = 1;
|
||||
found_left = TRUE;
|
||||
_rule.border = 0;
|
||||
if (!keyword_foundleft)
|
||||
_rule.context = 0;
|
||||
}
|
||||
else if (is_end && rule.border & RULE_ON_LEFT_BORDER)
|
||||
{
|
||||
|
||||
/* never turn off a context at 2 */
|
||||
found_left = 1;
|
||||
found_left = TRUE;
|
||||
_rule.border = 0;
|
||||
}
|
||||
}
|
||||
@ -390,9 +383,11 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
p = (r = edit->rules[_rule.context])->keyword_first_chars;
|
||||
if (p)
|
||||
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)))
|
||||
r = edit->rules[_rule.context];
|
||||
p = r->keyword_first_chars;
|
||||
|
||||
if (p != NULL)
|
||||
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0')
|
||||
{
|
||||
struct key_word *k;
|
||||
int count;
|
||||
@ -407,11 +402,12 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
end = e;
|
||||
_rule.end = e;
|
||||
_rule.keyword = count;
|
||||
keyword_foundright = 1;
|
||||
keyword_foundright = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* check to turn on a context */
|
||||
if (!_rule.context)
|
||||
{
|
||||
@ -421,7 +417,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
{
|
||||
_rule.border = 0;
|
||||
_rule.context = 0;
|
||||
contextchanged = 1;
|
||||
contextchanged = TRUE;
|
||||
_rule.keyword = 0;
|
||||
|
||||
}
|
||||
@ -431,20 +427,24 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
_rule.border = 0;
|
||||
if (r->between_delimiters)
|
||||
{
|
||||
long e;
|
||||
_rule.context = _rule._context;
|
||||
contextchanged = 1;
|
||||
contextchanged = TRUE;
|
||||
_rule.keyword = 0;
|
||||
if (r->first_right == c
|
||||
&& (e =
|
||||
compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
|
||||
r->whole_word_chars_right,
|
||||
r->line_start_right)) >= end)
|
||||
|
||||
if (r->first_right == c)
|
||||
{
|
||||
_rule.end = e;
|
||||
found_right = 1;
|
||||
_rule.border = RULE_ON_RIGHT_BORDER;
|
||||
_rule.context = 0;
|
||||
long e;
|
||||
|
||||
e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
|
||||
r->whole_word_chars_right,
|
||||
r->line_start_right);
|
||||
if (e >= end)
|
||||
{
|
||||
_rule.end = e;
|
||||
found_right = TRUE;
|
||||
_rule.border = RULE_ON_RIGHT_BORDER;
|
||||
_rule.context = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -467,15 +467,14 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
if (e >= end && (!_rule.keyword || keyword_foundright))
|
||||
{
|
||||
_rule.end = e;
|
||||
found_right = 1;
|
||||
found_right = TRUE;
|
||||
_rule.border = RULE_ON_LEFT_BORDER;
|
||||
_rule._context = count;
|
||||
if (!r->between_delimiters)
|
||||
if (!_rule.keyword)
|
||||
{
|
||||
_rule.context = count;
|
||||
contextchanged = 1;
|
||||
}
|
||||
if (!r->between_delimiters && !_rule.keyword)
|
||||
{
|
||||
_rule.context = count;
|
||||
contextchanged = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -488,8 +487,10 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
p = (r = edit->rules[_rule.context])->keyword_first_chars;
|
||||
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)))
|
||||
r = edit->rules[_rule.context];
|
||||
p = r->keyword_first_chars;
|
||||
|
||||
while (*(p = xx_strchr (edit, (unsigned char *) p + 1, c)) != '\0')
|
||||
{
|
||||
struct key_word *k;
|
||||
int count;
|
||||
@ -507,6 +508,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _rule;
|
||||
}
|
||||
|
||||
@ -714,12 +716,13 @@ get_args (char *l, char **args, int args_size)
|
||||
while (argc < args_size)
|
||||
{
|
||||
char *p = l;
|
||||
while (*p && whiteness (*p))
|
||||
while (*p != '\0' && whiteness (*p))
|
||||
p++;
|
||||
if (!*p)
|
||||
if (*p == '\0')
|
||||
break;
|
||||
for (l = p + 1; *l && !whiteness (*l); l++);
|
||||
if (*l)
|
||||
for (l = p + 1; *l != '\0' && !whiteness (*l); l++)
|
||||
;
|
||||
if (*l != '\0')
|
||||
*l++ = '\0';
|
||||
args[argc++] = convert (p);
|
||||
}
|
||||
@ -737,32 +740,30 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
|
||||
{
|
||||
char f[80], b[80], *p;
|
||||
|
||||
if (bg)
|
||||
if (!*bg)
|
||||
bg = 0;
|
||||
if (fg)
|
||||
if (!*fg)
|
||||
fg = 0;
|
||||
if (fg)
|
||||
if (bg != NULL && *bg == '\0')
|
||||
bg = NULL;
|
||||
if (fg != NULL && *fg == '\0')
|
||||
fg = NULL;
|
||||
if (fg != NULL)
|
||||
{
|
||||
g_strlcpy (f, fg, sizeof (f));
|
||||
p = strchr (f, '/');
|
||||
if (p)
|
||||
if (p != NULL)
|
||||
*p = '\0';
|
||||
fg = f;
|
||||
}
|
||||
if (bg)
|
||||
if (bg != NULL)
|
||||
{
|
||||
g_strlcpy (b, bg, sizeof (b));
|
||||
p = strchr (b, '/');
|
||||
if (p)
|
||||
if (p != NULL)
|
||||
*p = '\0';
|
||||
bg = b;
|
||||
}
|
||||
return tty_try_alloc_color_pair (fg, bg);
|
||||
}
|
||||
|
||||
static char *error_file_name = 0;
|
||||
static char *error_file_name = NULL;
|
||||
|
||||
static FILE *
|
||||
open_include_file (const char *filename)
|
||||
@ -771,21 +772,21 @@ open_include_file (const char *filename)
|
||||
|
||||
MC_PTR_FREE (error_file_name);
|
||||
error_file_name = g_strdup (filename);
|
||||
if (*filename == PATH_SEP)
|
||||
if (g_path_is_absolute (filename))
|
||||
return fopen (filename, "r");
|
||||
|
||||
g_free (error_file_name);
|
||||
error_file_name = g_strconcat (home_dir, PATH_SEP_STR EDIT_DIR PATH_SEP_STR,
|
||||
filename, (char *) NULL);
|
||||
f = fopen (error_file_name, "r");
|
||||
if (f)
|
||||
if (f != NULL)
|
||||
return f;
|
||||
|
||||
g_free (error_file_name);
|
||||
error_file_name = g_strconcat (mc_home, PATH_SEP_STR, "syntax", PATH_SEP_STR,
|
||||
filename, (char *) NULL);
|
||||
f = fopen (error_file_name, "r");
|
||||
if (f)
|
||||
if (f != NULL)
|
||||
return f;
|
||||
|
||||
g_free (error_file_name);
|
||||
@ -826,7 +827,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
|
||||
alloc_words_per_context = MAX_WORDS_PER_CONTEXT,
|
||||
max_alloc_words_per_context = MAX_WORDS_PER_CONTEXT;
|
||||
|
||||
args[0] = 0;
|
||||
args[0] = NULL;
|
||||
edit->is_case_insensitive = FALSE;
|
||||
|
||||
strcpy (whole_left, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_01234567890");
|
||||
@ -1095,20 +1096,18 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
|
||||
|
||||
if (argc < 3)
|
||||
break_a;
|
||||
if ((argv = g_tree_lookup (edit->defines, key)))
|
||||
{
|
||||
argv = g_tree_lookup (edit->defines, key);
|
||||
if (argv != NULL)
|
||||
mc_defines_destroy (NULL, argv, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
key = g_strdup (key);
|
||||
}
|
||||
|
||||
argv = g_new (char *, argc - 1);
|
||||
g_tree_insert (edit->defines, key, argv);
|
||||
while (*a)
|
||||
while (*a != NULL)
|
||||
{
|
||||
*argv++ = g_strdup (*a++);
|
||||
};
|
||||
}
|
||||
*argv = NULL;
|
||||
}
|
||||
else
|
||||
@ -1220,20 +1219,20 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
int result = 0;
|
||||
int count = 0;
|
||||
char *lib_file;
|
||||
int found = 0;
|
||||
gboolean found = FALSE;
|
||||
char **tmpnames = NULL;
|
||||
|
||||
f = fopen (syntax_file, "r");
|
||||
if (!f)
|
||||
if (f == NULL)
|
||||
{
|
||||
lib_file = concat_dir_and_file (mc_home, "Syntax");
|
||||
f = fopen (lib_file, "r");
|
||||
g_free (lib_file);
|
||||
if (!f)
|
||||
if (f == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
args[0] = 0;
|
||||
args[0] = NULL;
|
||||
for (;;)
|
||||
{
|
||||
line++;
|
||||
@ -1241,14 +1240,15 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
if (read_one_line (&l, f) == 0)
|
||||
break;
|
||||
(void) get_args (l, args, 1023); /* Final NULL */
|
||||
if (!args[0])
|
||||
if (args[0] == NULL)
|
||||
continue;
|
||||
|
||||
/* Looking for `include ...` lines before first `file ...` ones */
|
||||
if (!found && !strcmp (args[0], "include"))
|
||||
if (!found && strcmp (args[0], "include") == 0)
|
||||
{
|
||||
if (g)
|
||||
if (g != NULL)
|
||||
continue;
|
||||
|
||||
if (!args[1] || !(g = open_include_file (args[1])))
|
||||
{
|
||||
result = line;
|
||||
@ -1258,11 +1258,10 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
}
|
||||
|
||||
/* looking for `file ...' lines only */
|
||||
if (strcmp (args[0], "file"))
|
||||
{
|
||||
if (strcmp (args[0], "file") != 0)
|
||||
continue;
|
||||
}
|
||||
found = 1;
|
||||
|
||||
found = TRUE;
|
||||
|
||||
/* must have two args or report error */
|
||||
if (!args[1] || !args[2])
|
||||
@ -1272,7 +1271,6 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
}
|
||||
if (pnames && *pnames)
|
||||
{
|
||||
|
||||
/* 1: just collecting a list of names of rule sets */
|
||||
/* Reallocate the list if required */
|
||||
if (count % NENTRIES == 0)
|
||||
@ -1288,16 +1286,15 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
}
|
||||
else if (type)
|
||||
{
|
||||
|
||||
/* 2: rule set was explicitly specified by the caller */
|
||||
if (!strcmp (type, args[2]))
|
||||
if (strcmp (type, args[2]) == 0)
|
||||
goto found_type;
|
||||
}
|
||||
else if (editor_file && edit)
|
||||
{
|
||||
|
||||
/* 3: auto-detect rule set from regular expressions */
|
||||
int q;
|
||||
|
||||
q = mc_search (args[1], editor_file, MC_SEARCH_T_REGEX);
|
||||
/* does filename match arg 1 ? */
|
||||
if (!q && args[3])
|
||||
@ -1331,15 +1328,12 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (g)
|
||||
{
|
||||
fclose (g);
|
||||
g = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (g == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
fclose (g);
|
||||
g = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1409,17 +1403,14 @@ edit_load_syntax (WEdit * edit, char ***pnames, const char *type)
|
||||
message (D_ERROR, _(" Load syntax file "),
|
||||
_(" Cannot open file %s \n %s "), f, unix_error_string (errno));
|
||||
}
|
||||
else if (r)
|
||||
else if (r != 0)
|
||||
{
|
||||
edit_free_syntax_rules (edit);
|
||||
message (D_ERROR, _(" Load syntax file "),
|
||||
_(" Error in file %s on line %d "), error_file_name ? error_file_name : f, r);
|
||||
MC_PTR_FREE (error_file_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* succeeded */
|
||||
}
|
||||
|
||||
g_free (f);
|
||||
}
|
||||
|
||||
|
123
src/ext.c
123
src/ext.c
@ -118,17 +118,19 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
|
||||
unix_error_string (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
cmd_file = fdopen (cmd_file_fd, "w");
|
||||
fputs ("#! /bin/sh\n", cmd_file);
|
||||
|
||||
lc_prompt[0] = 0;
|
||||
for (; *lc_data && *lc_data != '\n'; lc_data++) {
|
||||
lc_prompt[0] = '\0';
|
||||
for (; *lc_data != '\0' && *lc_data != '\n'; lc_data++) {
|
||||
if (parameter_found) {
|
||||
if (*lc_data == '}') {
|
||||
char *parameter;
|
||||
|
||||
parameter_found = 0;
|
||||
parameter = input_dialog (_(" Parameter "), lc_prompt, MC_HISTORY_EXT_PARAMETER, "");
|
||||
if (!parameter) {
|
||||
if (parameter == NULL) {
|
||||
/* User canceled */
|
||||
fclose (cmd_file);
|
||||
unlink (file_name);
|
||||
@ -147,7 +149,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
|
||||
|
||||
if (len < sizeof (lc_prompt) - 1) {
|
||||
lc_prompt[len] = *lc_data;
|
||||
lc_prompt[len + 1] = 0;
|
||||
lc_prompt[len + 1] = '\0';
|
||||
}
|
||||
}
|
||||
} else if (expand_prefix_found) {
|
||||
@ -155,66 +157,73 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
|
||||
if (*lc_data == '{')
|
||||
parameter_found = 1;
|
||||
else {
|
||||
int i = check_format_view (lc_data);
|
||||
int i;
|
||||
char *v;
|
||||
|
||||
if (i) {
|
||||
i = check_format_view (lc_data);
|
||||
if (i != 0) {
|
||||
lc_data += i - 1;
|
||||
run_view = 1;
|
||||
} else if ((i = check_format_cd (lc_data)) > 0) {
|
||||
is_cd = 1;
|
||||
quote_func = fake_name_quote;
|
||||
do_local_copy = 0;
|
||||
p = buffer;
|
||||
lc_data += i - 1;
|
||||
} else if ((i = check_format_var (lc_data, &v)) > 0 && v) {
|
||||
fputs (v, cmd_file);
|
||||
g_free (v);
|
||||
lc_data += i;
|
||||
} else {
|
||||
char *text;
|
||||
|
||||
if (*lc_data == 'f') {
|
||||
if (do_local_copy) {
|
||||
localcopy = mc_getlocalcopy (filename);
|
||||
if (localcopy == NULL) {
|
||||
fclose (cmd_file);
|
||||
unlink (file_name);
|
||||
g_free (file_name);
|
||||
return;
|
||||
}
|
||||
mc_stat (localcopy, &mystat);
|
||||
localmtime = mystat.st_mtime;
|
||||
text = (*quote_func) (localcopy, 0);
|
||||
} else {
|
||||
fn = vfs_canon_and_translate (filename);
|
||||
text = (*quote_func) (fn, 0);
|
||||
g_free (fn);
|
||||
}
|
||||
i = check_format_cd (lc_data);
|
||||
if (i > 0) {
|
||||
is_cd = 1;
|
||||
quote_func = fake_name_quote;
|
||||
do_local_copy = 0;
|
||||
p = buffer;
|
||||
lc_data += i - 1;
|
||||
} else {
|
||||
text = expand_format (NULL, *lc_data, !is_cd);
|
||||
}
|
||||
if (!is_cd)
|
||||
fputs (text, cmd_file);
|
||||
else {
|
||||
strcpy (p, text);
|
||||
p = strchr (p, 0);
|
||||
i = check_format_var (lc_data, &v);
|
||||
if (i > 0 && v != NULL) {
|
||||
fputs (v, cmd_file);
|
||||
g_free (v);
|
||||
lc_data += i;
|
||||
} else {
|
||||
char *text;
|
||||
|
||||
if (*lc_data != 'f')
|
||||
text = expand_format (NULL, *lc_data, !is_cd);
|
||||
else {
|
||||
if (do_local_copy) {
|
||||
localcopy = mc_getlocalcopy (filename);
|
||||
if (localcopy == NULL) {
|
||||
fclose (cmd_file);
|
||||
unlink (file_name);
|
||||
g_free (file_name);
|
||||
return;
|
||||
}
|
||||
mc_stat (localcopy, &mystat);
|
||||
localmtime = mystat.st_mtime;
|
||||
text = quote_func (localcopy, 0);
|
||||
} else {
|
||||
fn = vfs_canon_and_translate (filename);
|
||||
text = quote_func (fn, 0);
|
||||
g_free (fn);
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_cd)
|
||||
fputs (text, cmd_file);
|
||||
else {
|
||||
strcpy (p, text);
|
||||
p = strchr (p, 0);
|
||||
}
|
||||
|
||||
g_free (text);
|
||||
written_nonspace = 1;
|
||||
}
|
||||
}
|
||||
g_free (text);
|
||||
written_nonspace = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (*lc_data == '%')
|
||||
expand_prefix_found = 1;
|
||||
else {
|
||||
if (*lc_data != ' ' && *lc_data != '\t')
|
||||
written_nonspace = 1;
|
||||
if (is_cd)
|
||||
*(p++) = *lc_data;
|
||||
else
|
||||
fputc (*lc_data, cmd_file);
|
||||
}
|
||||
} else if (*lc_data == '%')
|
||||
expand_prefix_found = 1;
|
||||
else {
|
||||
if (*lc_data != ' ' && *lc_data != '\t')
|
||||
written_nonspace = 1;
|
||||
if (is_cd)
|
||||
*(p++) = *lc_data;
|
||||
else
|
||||
fputc (*lc_data, cmd_file);
|
||||
}
|
||||
} /* for */
|
||||
|
||||
@ -223,9 +232,8 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
|
||||
* Don't do it for the viewer - it may need to rerun the script,
|
||||
* so we clean up after calling view().
|
||||
*/
|
||||
if (!run_view) {
|
||||
if (!run_view)
|
||||
fprintf (cmd_file, "\n/bin/rm -f %s\n", file_name);
|
||||
}
|
||||
|
||||
fclose (cmd_file);
|
||||
|
||||
@ -285,7 +293,6 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir,
|
||||
LINES - keybar_visible -
|
||||
output_lines - 1,
|
||||
LINES - keybar_visible - 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1153,7 +1153,8 @@ move_file_file (FileOpTotalContext * tctx, FileOpContext * ctx, const char *s, c
|
||||
{
|
||||
if (S_ISLNK (src_stats.st_mode) && ctx->stable_symlinks)
|
||||
{
|
||||
if ((return_status = make_symlink (ctx, s, d)) == FILE_CONT)
|
||||
return_status = make_symlink (ctx, s, d);
|
||||
if (return_status == FILE_CONT)
|
||||
goto retry_src_remove;
|
||||
else
|
||||
return return_status;
|
||||
|
@ -660,60 +660,45 @@ overwrite_query_dialog (FileOpContext * ctx, enum OperationMode mode)
|
||||
int value; /* 0 for labels */
|
||||
} rd_widgets[] =
|
||||
{
|
||||
/* *INDENT-OFF* */
|
||||
/* 0 */
|
||||
{
|
||||
N_("Target file already exists!"), 3, 4, 0},
|
||||
/* 1 */
|
||||
{
|
||||
"%s", 4, 4, 0},
|
||||
{ N_("Target file already exists!"), 3, 4, 0 },
|
||||
/* 1 */
|
||||
{ "%s", 4, 4, 0 },
|
||||
#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || (defined _LARGE_FILES && _LARGE_FILES)
|
||||
/* 2 */
|
||||
{
|
||||
N_("Source date: %s, size %llu"), 6, 4, 0},
|
||||
/* 3 */
|
||||
{
|
||||
N_("Target date: %s, size %llu"), 7, 4, 0},
|
||||
/* 2 */
|
||||
{ N_("Source date: %s, size %llu"), 6, 4, 0 },
|
||||
/* 3 */
|
||||
{ N_("Target date: %s, size %llu"), 7, 4, 0 },
|
||||
#else
|
||||
/* 2 */
|
||||
{
|
||||
N_("Source date: %s, size %u"), 6, 4, 0},
|
||||
/* 3 */
|
||||
{
|
||||
N_("Target date: %s, size %u"), 7, 4, 0},
|
||||
/* 2 */
|
||||
{ N_("Source date: %s, size %u"), 6, 4, 0 },
|
||||
/* 3 */
|
||||
{ N_("Target date: %s, size %u"), 7, 4, 0 },
|
||||
#endif
|
||||
/* 4 */
|
||||
{
|
||||
N_("&Abort"), 14, 25, REPLACE_ABORT},
|
||||
/* 5 */
|
||||
{
|
||||
N_("If &size differs"), 12, 28, REPLACE_SIZE},
|
||||
/* 6 */
|
||||
{
|
||||
N_("Non&e"), 11, 47, REPLACE_NEVER},
|
||||
/* 7 */
|
||||
{
|
||||
N_("&Update"), 11, 36, REPLACE_UPDATE},
|
||||
/* 8 */
|
||||
{
|
||||
N_("A&ll"), 11, 28, REPLACE_ALWAYS},
|
||||
/* 9 */
|
||||
{
|
||||
N_("Overwrite all targets?"), 11, 4, 0},
|
||||
/* 10 */
|
||||
{
|
||||
N_("&Reget"), 10, 28, REPLACE_REGET},
|
||||
/* 11 */
|
||||
{
|
||||
N_("A&ppend"), 9, 45, REPLACE_APPEND},
|
||||
/* 12 */
|
||||
{
|
||||
N_("&No"), 9, 37, REPLACE_NO},
|
||||
/* 13 */
|
||||
{
|
||||
N_("&Yes"), 9, 28, REPLACE_YES},
|
||||
/* 14 */
|
||||
{
|
||||
N_("Overwrite this target?"), 9, 4, 0}
|
||||
/* 4 */
|
||||
{ N_("&Abort"), 14, 25, REPLACE_ABORT },
|
||||
/* 5 */
|
||||
{ N_("If &size differs"), 12, 28, REPLACE_SIZE },
|
||||
/* 6 */
|
||||
{ N_("Non&e"), 11, 47, REPLACE_NEVER },
|
||||
/* 7 */
|
||||
{ N_("&Update"), 11, 36, REPLACE_UPDATE },
|
||||
/* 8 */
|
||||
{ N_("A&ll"), 11, 28, REPLACE_ALWAYS },
|
||||
/* 9 */
|
||||
{ N_("Overwrite all targets?"), 11, 4, 0 },
|
||||
/* 10 */
|
||||
{ N_("&Reget"), 10, 28, REPLACE_REGET },
|
||||
/* 11 */
|
||||
{ N_("A&ppend"), 9, 45, REPLACE_APPEND },
|
||||
/* 12 */
|
||||
{ N_("&No"), 9, 37, REPLACE_NO },
|
||||
/* 13 */
|
||||
{ N_("&Yes"), 9, 28, REPLACE_YES },
|
||||
/* 14 */
|
||||
{ N_("Overwrite this target?"), 9, 4, 0 }
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
const int num = sizeof (rd_widgets) / sizeof (rd_widgets[0]);
|
||||
@ -1112,7 +1097,7 @@ file_mask_dialog (FileOpContext * ctx, FileOperation operation,
|
||||
g_free (def_text_secure);
|
||||
g_free (source_mask);
|
||||
|
||||
ctx->search_handle->is_case_sentitive = TRUE;
|
||||
ctx->search_handle->is_case_sensitive = TRUE;
|
||||
if (source_easy_patterns)
|
||||
ctx->search_handle->search_type = MC_SEARCH_T_GLOB;
|
||||
else
|
||||
|
@ -76,7 +76,8 @@ my_mkdir_rec (char *s, mode_t mode)
|
||||
q = vfs_canon (p);
|
||||
g_free (p);
|
||||
|
||||
if (!(result = my_mkdir_rec (q, mode)))
|
||||
result = my_mkdir_rec (q, mode);
|
||||
if (result == 0)
|
||||
result = mc_mkdir (s, mode);
|
||||
|
||||
g_free (q);
|
||||
|
@ -882,13 +882,13 @@ do_search (struct Dlg_head *h)
|
||||
{
|
||||
search_content_handle->search_type =
|
||||
options.content_regexp ? MC_SEARCH_T_REGEX : MC_SEARCH_T_NORMAL;
|
||||
search_content_handle->is_case_sentitive = options.content_case_sens;
|
||||
search_content_handle->is_case_sensitive = options.content_case_sens;
|
||||
search_content_handle->whole_words = options.content_whole_words;
|
||||
search_content_handle->is_all_charsets = options.content_all_charsets;
|
||||
}
|
||||
search_file_handle = mc_search_new (find_pattern, -1);
|
||||
search_file_handle->search_type = options.file_pattern ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX;
|
||||
search_file_handle->is_case_sentitive = options.file_case_sens;
|
||||
search_file_handle->is_case_sensitive = options.file_case_sens;
|
||||
search_file_handle->is_all_charsets = options.file_all_charsets;
|
||||
search_file_handle->is_entire_line = options.file_pattern;
|
||||
|
||||
|
@ -71,7 +71,7 @@ const global_keymap_t *help_map;
|
||||
|
||||
#define MAXLINKNAME 80
|
||||
#define HISTORY_SIZE 20
|
||||
#define HELP_WINDOW_WIDTH (COLS - 16)
|
||||
#define HELP_WINDOW_WIDTH min(80, COLS - 16)
|
||||
|
||||
#define STRING_LINK_START "\01"
|
||||
#define STRING_LINK_POINTER "\02"
|
||||
|
@ -1327,11 +1327,14 @@ hot_next_token (void)
|
||||
while ((c = getc (hotlist_file)) != EOF && c != '"')
|
||||
{
|
||||
if (c == '\\')
|
||||
if ((c = getc (hotlist_file)) == EOF)
|
||||
{
|
||||
c = getc (hotlist_file);
|
||||
if (c == EOF)
|
||||
{
|
||||
g_string_free (tkn_buf, TRUE);
|
||||
return TKN_EOF;
|
||||
}
|
||||
}
|
||||
g_string_append_c (tkn_buf, c == '\n' ? ' ' : c);
|
||||
}
|
||||
if (c == EOF)
|
||||
@ -1340,7 +1343,8 @@ hot_next_token (void)
|
||||
ret = TKN_STRING;
|
||||
break;
|
||||
case '\\':
|
||||
if ((c = getc (hotlist_file)) == EOF)
|
||||
c = getc (hotlist_file);
|
||||
if (c == EOF)
|
||||
{
|
||||
g_string_free (tkn_buf, TRUE);
|
||||
return TKN_EOF;
|
||||
@ -1380,7 +1384,8 @@ while ((_tkn = hot_next_token ()) != TKN_EOF && _tkn != TKN_EOL) ; \
|
||||
}
|
||||
|
||||
#define CHECK_TOKEN(_TKN_) \
|
||||
if ((tkn = hot_next_token ()) != _TKN_) { \
|
||||
tkn = hot_next_token (); \
|
||||
if (tkn != _TKN_) { \
|
||||
hotlist_state.readonly = 1; \
|
||||
hotlist_state.file_error = 1; \
|
||||
while (tkn != TKN_EOL && tkn != TKN_EOF) \
|
||||
@ -1537,7 +1542,8 @@ load_hotlist (void)
|
||||
*/
|
||||
hotlist->directory = g_strdup ("Hotlist");
|
||||
|
||||
if ((hotlist_file = fopen (hotlist_file_name, "r")) == 0)
|
||||
hotlist_file = fopen (hotlist_file_name, "r");
|
||||
if (hotlist_file == NULL)
|
||||
{
|
||||
int result;
|
||||
|
||||
@ -1649,7 +1655,8 @@ save_hotlist (void)
|
||||
{
|
||||
mc_util_make_backup_if_possible (hotlist_file_name, ".bak");
|
||||
|
||||
if ((hotlist_file = fopen (hotlist_file_name, "w")) != 0)
|
||||
hotlist_file = fopen (hotlist_file_name, "w");
|
||||
if (hotlist_file != NULL)
|
||||
{
|
||||
hot_save_group (hotlist);
|
||||
fclose (hotlist_file);
|
||||
|
37
src/main.c
37
src/main.c
@ -440,14 +440,24 @@ directory_history_add (struct WPanel *panel, const char *dir)
|
||||
static const char *
|
||||
get_parent_dir_name (const char *cwd, const char *lwd)
|
||||
{
|
||||
const char *p;
|
||||
if (strlen (lwd) > strlen (cwd))
|
||||
if ((p = strrchr (lwd, PATH_SEP)) && !strncmp (cwd, lwd, p - lwd) &&
|
||||
((gsize) strlen (cwd) == (gsize) p - (gsize) lwd || (p == lwd && cwd[0] == PATH_SEP &&
|
||||
cwd[1] == '\0')))
|
||||
{
|
||||
size_t llen, clen;
|
||||
|
||||
llen = strlen (lwd);
|
||||
clen = strlen (cwd);
|
||||
|
||||
if (llen > clen)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
p = strrchr (lwd, PATH_SEP);
|
||||
|
||||
if ((p != NULL)
|
||||
&& (strncmp (cwd, lwd, (size_t) (p - lwd)) == 0)
|
||||
&& (clen == (size_t) (p - lwd)
|
||||
|| ((p == lwd) && (cwd[0] == PATH_SEP) && (cwd[1] == '\0'))))
|
||||
return (p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1442,7 +1452,7 @@ init_xterm_support (void)
|
||||
if (!termvalue || !(*termvalue))
|
||||
{
|
||||
fputs (_("The TERM environment variable is unset!\n"), stderr);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Check mouse capabilities */
|
||||
@ -2215,19 +2225,20 @@ mc_main__setup_by_args (int argc, char *argv[])
|
||||
else
|
||||
{
|
||||
fputs ("No arguments given to the viewer\n", stderr);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
mc_run_mode = MC_RUN_VIEWER;
|
||||
#ifdef USE_DIFF_VIEW
|
||||
}
|
||||
#ifdef USE_DIFF_VIEW
|
||||
else if (!STRNCOMP (base, "mcd", 3) || !STRCOMP (base, "diff"))
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
fputs ("There 2 files are required to diffviewer\n", stderr);
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
else if (tmp != NULL)
|
||||
|
||||
if (tmp != NULL)
|
||||
{
|
||||
mc_run_param0 = g_strdup (tmp);
|
||||
tmp = (argc > 1) ? argv[2] : NULL;
|
||||
@ -2235,8 +2246,8 @@ mc_main__setup_by_args (int argc, char *argv[])
|
||||
mc_run_param1 = g_strdup (tmp);
|
||||
mc_run_mode = MC_RUN_DIFFVIEWER;
|
||||
}
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
}
|
||||
#endif /* USE_DIFF_VIEW */
|
||||
else
|
||||
{
|
||||
/* sets the current dir and the other dir */
|
||||
|
@ -668,7 +668,8 @@ read_filesystem_list (int need_fs_type, int all_fs)
|
||||
if (!getcwd (dir, _POSIX_PATH_MAX))
|
||||
return (NULL);
|
||||
|
||||
if ((fd = open (dir, O_RDONLY)) == -1)
|
||||
fd = open (dir, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return (NULL);
|
||||
|
||||
i = disk_get_entry (fd, &de);
|
||||
@ -756,7 +757,7 @@ void
|
||||
my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
#ifdef HAVE_INFOMOUNT_LIST
|
||||
int i, len = 0;
|
||||
size_t i, len = 0;
|
||||
struct mount_entry *entry = NULL;
|
||||
struct mount_entry *temp = mount_list;
|
||||
struct fs_usage fs_use;
|
||||
@ -765,7 +766,7 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
{
|
||||
i = strlen (temp->me_mountdir);
|
||||
if (i > len && (strncmp (path, temp->me_mountdir, i) == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == 0))
|
||||
if (!entry || (path[i] == PATH_SEP || path[i] == '\0'))
|
||||
{
|
||||
len = i;
|
||||
entry = temp;
|
||||
@ -800,7 +801,8 @@ my_statfs (struct my_statfs *myfs_stats, const char *path)
|
||||
struct mount_entry *entry;
|
||||
struct fs_usage fs_use;
|
||||
|
||||
if ((entry = read_filesystem_list (0, 0)) != NULL)
|
||||
entry = read_filesystem_list (0, 0);
|
||||
if (entry != NULL)
|
||||
{
|
||||
get_fs_usage (entry->me_mountdir, &fs_use);
|
||||
|
||||
|
@ -81,7 +81,7 @@ typedef struct WPanel {
|
||||
|
||||
int dirty; /* Should we redisplay the panel? */
|
||||
|
||||
int user_mini_status; /* Is user_status_format used */
|
||||
int user_mini_status; /* Is user_status_format used */
|
||||
char *user_format; /* User format */
|
||||
char *user_status_format[LIST_TYPES];/* User format for status line */
|
||||
|
||||
@ -140,8 +140,8 @@ void select_item (WPanel *panel);
|
||||
extern Hook *select_file_hook;
|
||||
|
||||
void recalculate_panel_summary (WPanel *panel);
|
||||
void file_mark (WPanel *panel, int index, int val);
|
||||
void do_file_mark (WPanel *panel, int index, int val);
|
||||
void file_mark (WPanel *panel, int idx, int val);
|
||||
void do_file_mark (WPanel *panel, int idx, int val);
|
||||
|
||||
void directory_history_next (WPanel *panel);
|
||||
void directory_history_prev (WPanel *panel);
|
||||
@ -158,4 +158,4 @@ const char **panel_get_user_possible_fields(gsize *);
|
||||
void panel_init(void);
|
||||
void panel_deinit(void);
|
||||
|
||||
#endif
|
||||
#endif /* MC_PANEL_H */
|
||||
|
13
src/screen.c
13
src/screen.c
@ -2421,13 +2421,13 @@ do_search (WPanel * panel, int c_code)
|
||||
switch (quick_search_case_sensitive)
|
||||
{
|
||||
case QSEARCH_CASE_SENSITIVE:
|
||||
search->is_case_sentitive = TRUE;
|
||||
search->is_case_sensitive = TRUE;
|
||||
break;
|
||||
case QSEARCH_CASE_INSENSITIVE:
|
||||
search->is_case_sentitive = FALSE;
|
||||
search->is_case_sensitive = FALSE;
|
||||
break;
|
||||
default:
|
||||
search->is_case_sentitive = panel->case_sensitive;
|
||||
search->is_case_sensitive = panel->case_sensitive;
|
||||
break;
|
||||
}
|
||||
sel = panel->selected;
|
||||
@ -3428,7 +3428,7 @@ set_panel_encoding (WPanel * panel)
|
||||
const char *encoding = NULL;
|
||||
char *cd_path;
|
||||
#ifdef HAVE_CHARSET
|
||||
const char *errmsg;
|
||||
char *errmsg;
|
||||
int r;
|
||||
|
||||
r = select_charset (-1, -1, default_source_codepage, FALSE);
|
||||
@ -3439,7 +3439,7 @@ set_panel_encoding (WPanel * panel)
|
||||
if (r == SELECT_CHARSET_NO_TRANSLATE)
|
||||
{
|
||||
/* No translation */
|
||||
errmsg = init_translation_table (display_codepage, display_codepage);
|
||||
g_free (init_translation_table (display_codepage, display_codepage));
|
||||
cd_path = remove_encoding_from_path (panel->cwd);
|
||||
do_panel_cd (panel, cd_path, 0);
|
||||
g_free (cd_path);
|
||||
@ -3449,9 +3449,10 @@ set_panel_encoding (WPanel * panel)
|
||||
source_codepage = r;
|
||||
|
||||
errmsg = init_translation_table (source_codepage, display_codepage);
|
||||
if (errmsg)
|
||||
if (errmsg != NULL)
|
||||
{
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,16 +115,21 @@ select_charset (int center_y, int center_x, int current_charset, gboolean seldis
|
||||
gboolean
|
||||
do_set_codepage (int codepage)
|
||||
{
|
||||
const char *errmsg = NULL;
|
||||
char *errmsg;
|
||||
gboolean ret;
|
||||
|
||||
source_codepage = codepage;
|
||||
errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ?
|
||||
display_codepage : source_codepage,
|
||||
display_codepage);
|
||||
if (errmsg != NULL)
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
ret = errmsg == NULL;
|
||||
|
||||
return (errmsg == NULL);
|
||||
if (!ret) {
|
||||
message (D_ERROR, MSG_ERROR, "%s", errmsg);
|
||||
g_free (errmsg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Show menu selecting codepage */
|
||||
|
@ -36,16 +36,13 @@
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
#include "lib/mcconfig.h"
|
||||
#include "lib/fileloc.h"
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
#include "lib/vfs/mc-vfs/gc.h"
|
||||
#endif
|
||||
#include "lib/strutil.h" /* str_isutf8 () */
|
||||
|
||||
#ifdef USE_NETCODE
|
||||
# include "lib/vfs/mc-vfs/ftpfs.h"
|
||||
# include "lib/vfs/mc-vfs/fish.h"
|
||||
#endif
|
||||
#include "lib/strutil.h" /* str_isutf8 () */
|
||||
|
||||
|
||||
#include "args.h"
|
||||
#include "dir.h"
|
||||
@ -868,7 +865,7 @@ load_setup (void)
|
||||
if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off")))
|
||||
is_autodetect_codeset_enabled = TRUE;
|
||||
|
||||
init_translation_table (source_codepage, display_codepage);
|
||||
g_free (init_translation_table (source_codepage, display_codepage));
|
||||
if (get_codepage_id (display_codepage))
|
||||
utf8_display = str_isutf8 (get_codepage_id (display_codepage));
|
||||
#endif /* HAVE_CHARSET */
|
||||
|
@ -73,7 +73,7 @@ static char tcsh_fifo[128];
|
||||
|
||||
/* Local functions */
|
||||
static void init_raw_mode (void);
|
||||
static int feed_subshell (int how, int fail_on_error);
|
||||
static gboolean feed_subshell (int how, int fail_on_error);
|
||||
static void synchronize (void);
|
||||
static int pty_open_master (char *pty_name);
|
||||
static int pty_open_slave (const char *pty_name);
|
||||
@ -494,11 +494,12 @@ init_subshell (void)
|
||||
fprintf (stderr, "Cannot spawn the subshell process: %s\r\n", unix_error_string (errno));
|
||||
/* We exit here because, if the process table is full, the */
|
||||
/* other method of running user commands won't work either */
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (subshell_pid == 0)
|
||||
{ /* We are in the child process */
|
||||
{
|
||||
/* We are in the child process */
|
||||
init_subshell_child (pty_name);
|
||||
}
|
||||
|
||||
@ -650,7 +651,7 @@ read_subshell_prompt (void)
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "select (FD_SETSIZE, &tmp...): %s\r\n", unix_error_string (errno));
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -990,7 +991,7 @@ sigchld_handler (int sig)
|
||||
|
||||
|
||||
/* Feed the subshell our keyboard input until it says it's finished */
|
||||
static int
|
||||
static gboolean
|
||||
feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
fd_set read_set; /* For `select' */
|
||||
@ -1006,7 +1007,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
wtime.tv_usec = 0;
|
||||
wptr = fail_on_error ? &wtime : NULL;
|
||||
|
||||
while (1)
|
||||
while (TRUE)
|
||||
{
|
||||
if (!subshell_alive)
|
||||
return FALSE;
|
||||
@ -1032,7 +1033,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "select (FD_SETSIZE, &read_set...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (FD_ISSET (subshell_pty, &read_set))
|
||||
@ -1053,7 +1054,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
{
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pty...): %s\r\n", unix_error_string (errno));
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (how == VISIBLY)
|
||||
@ -1062,7 +1063,6 @@ feed_subshell (int how, int fail_on_error)
|
||||
|
||||
else if (FD_ISSET (subshell_pipe[READ], &read_set))
|
||||
/* Read the subshell's CWD and capture its prompt */
|
||||
|
||||
{
|
||||
bytes = read (subshell_pipe[READ], subshell_cwd, MC_MAXPATHLEN + 1);
|
||||
if (bytes <= 0)
|
||||
@ -1070,7 +1070,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr, "read (subshell_pipe[READ]...): %s\r\n",
|
||||
unix_error_string (errno));
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
subshell_cwd[bytes - 1] = 0; /* Squash the final '\n' */
|
||||
@ -1081,7 +1081,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
if (subshell_state == RUNNING_COMMAND)
|
||||
{
|
||||
subshell_state = INACTIVE;
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1094,7 +1094,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
tcsetattr (STDOUT_FILENO, TCSANOW, &shell_mode);
|
||||
fprintf (stderr,
|
||||
"read (STDIN_FILENO, pty_buffer...): %s\r\n", unix_error_string (errno));
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < bytes; ++i)
|
||||
@ -1112,9 +1112,7 @@ feed_subshell (int how, int fail_on_error)
|
||||
subshell_ready = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1254,20 +1252,20 @@ pty_open_master (char *pty_name)
|
||||
for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1; ++ptr1)
|
||||
{
|
||||
pty_name[8] = *ptr1;
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2; ++ptr2)
|
||||
for (ptr2 = "0123456789abcdef"; *ptr2 != '\0'; ++ptr2)
|
||||
{
|
||||
pty_name[9] = *ptr2;
|
||||
|
||||
/* Try to open master */
|
||||
if ((pty_master = open (pty_name, O_RDWR)) == -1)
|
||||
pty_master = open (pty_name, O_RDWR);
|
||||
if (pty_master == -1)
|
||||
{
|
||||
if (errno == ENOENT) /* Different from EIO */
|
||||
return -1; /* Out of pty devices */
|
||||
else
|
||||
continue; /* Try next pty device */
|
||||
continue; /* Try next pty device */
|
||||
}
|
||||
pty_name[5] = 't'; /* Change "pty" to "tty" */
|
||||
if (access (pty_name, 6))
|
||||
if (access (pty_name, 6) != 0)
|
||||
{
|
||||
close (pty_master);
|
||||
pty_name[5] = 'p';
|
||||
@ -1293,7 +1291,8 @@ pty_open_slave (const char *pty_name)
|
||||
/* chown (pty_name, getuid (), group_info->gr_gid); FIXME */
|
||||
/* chmod (pty_name, S_IRUSR | S_IWUSR | S_IWGRP); FIXME */
|
||||
}
|
||||
if ((pty_slave = open (pty_name, O_RDWR)) == -1)
|
||||
pty_slave = open (pty_name, O_RDWR);
|
||||
if (pty_slave == -1)
|
||||
fprintf (stderr, "open (pty_name, O_RDWR): %s\r\n", pty_name);
|
||||
fcntl (pty_slave, F_SETFD, FD_CLOEXEC);
|
||||
return pty_slave;
|
||||
|
@ -26,11 +26,9 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "ecs.h"
|
||||
#include "src/textconf.h"
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
@ -116,35 +114,30 @@ static const char *const features[] = {
|
||||
void
|
||||
show_version (void)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
printf (_("GNU Midnight Commander %s\n"), VERSION);
|
||||
|
||||
#ifdef ENABLE_VFS
|
||||
printf (_("Virtual File System:"));
|
||||
for (i = 0; vfs_supported[i]; i++) {
|
||||
if (i == 0)
|
||||
printf (" ");
|
||||
else
|
||||
printf (", ");
|
||||
printf (_("Virtual File Systems:"));
|
||||
for (i = 0; vfs_supported[i] != NULL; i++)
|
||||
printf ("%s %s", i == 0 ? "" : ",", _(vfs_supported[i]));
|
||||
|
||||
printf ("%s", _(vfs_supported[i]));
|
||||
}
|
||||
printf ("\n");
|
||||
#endif /* ENABLE_VFS */
|
||||
|
||||
for (i = 0; features[i]; i++)
|
||||
for (i = 0; features[i] != NULL; i++)
|
||||
printf ("%s", _(features[i]));
|
||||
|
||||
(void)printf("Data types:");
|
||||
(void)printf(_("Data types:"));
|
||||
#define TYPE_INFO(T) \
|
||||
(void)printf(" %s %d", #T, (int) (CHAR_BIT * sizeof(T)))
|
||||
(void)printf(" %s: %d;", #T, (int) (CHAR_BIT * sizeof(T)))
|
||||
TYPE_INFO(char);
|
||||
TYPE_INFO(int);
|
||||
TYPE_INFO(long);
|
||||
TYPE_INFO(void *);
|
||||
TYPE_INFO(size_t);
|
||||
TYPE_INFO(off_t);
|
||||
TYPE_INFO(ecs_char);
|
||||
#undef TYPE_INFO
|
||||
(void)printf("\n");
|
||||
}
|
||||
|
@ -403,7 +403,8 @@ tree_store_save (void)
|
||||
name = g_build_filename (home_dir, MC_USERCONF_DIR, MC_TREESTORE_FILE, NULL);
|
||||
mc_util_make_backup_if_possible (name, ".tmp");
|
||||
|
||||
if ((retval = tree_store_save_to (name)) != 0)
|
||||
retval = tree_store_save_to (name);
|
||||
if (retval != 0)
|
||||
{
|
||||
mc_util_restore_from_backup_if_possible (name, ".tmp");
|
||||
g_free (name);
|
||||
|
@ -301,8 +301,8 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
|
||||
*block = 0;
|
||||
for (i = 0; i < panel->count; i++)
|
||||
if (panel->dir.list[i].f.marked) {
|
||||
strcat (block, tmp =
|
||||
(*quote_func) (panel->dir.list[i].fname, 0));
|
||||
tmp = (*quote_func) (panel->dir.list[i].fname, 0);
|
||||
strcat (block, tmp);
|
||||
g_free (tmp);
|
||||
strcat (block, " ");
|
||||
if (c_lc == 'u')
|
||||
@ -784,7 +784,8 @@ user_menu_cmd (struct WEdit *edit_widget)
|
||||
}
|
||||
}
|
||||
|
||||
if ((data = load_file (menu)) == NULL){
|
||||
data = load_file (menu);
|
||||
if (data == NULL) {
|
||||
message (D_ERROR, MSG_ERROR, _(" Cannot open file %s \n %s "),
|
||||
menu, unix_error_string (errno));
|
||||
g_free (menu);
|
||||
|
@ -122,7 +122,7 @@ mcview_continue_search_cmd (mcview_t * view)
|
||||
{
|
||||
view->search->search_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = mcview_search_options.case_sens;
|
||||
view->search->is_case_sensitive = mcview_search_options.case_sens;
|
||||
view->search->whole_words = mcview_search_options.whole_words;
|
||||
view->search->search_fn = mcview_search_cmd_callback;
|
||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
||||
|
@ -373,7 +373,8 @@ mcview_load_command_output (mcview_t * view, const char *command)
|
||||
mcview_close_datasource (view);
|
||||
|
||||
open_error_pipe ();
|
||||
if ((fp = popen (command, "r")) == NULL)
|
||||
fp = popen (command, "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
/* Avoid two messages. Message from stderr has priority. */
|
||||
mcview_display (view);
|
||||
|
@ -147,7 +147,7 @@ mcview_dialog_search (mcview_t * view)
|
||||
{
|
||||
view->search->search_type = mcview_search_options.type;
|
||||
view->search->is_all_charsets = mcview_search_options.all_codepages;
|
||||
view->search->is_case_sentitive = mcview_search_options.case_sens;
|
||||
view->search->is_case_sensitive = mcview_search_options.case_sens;
|
||||
view->search->whole_words = mcview_search_options.whole_words;
|
||||
view->search->search_fn = mcview_search_cmd_callback;
|
||||
view->search->update_fn = mcview_search_update_cmd_callback;
|
||||
|
@ -347,7 +347,8 @@ mcview_load (mcview_t * view, const char *command, const char *file, int start_l
|
||||
else if (file != NULL && file[0] != '\0')
|
||||
{
|
||||
/* Open the file */
|
||||
if ((fd = mc_open (file, O_RDONLY | O_NONBLOCK)) == -1)
|
||||
fd = mc_open (file, O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1)
|
||||
{
|
||||
g_snprintf (tmp, sizeof (tmp), _(" Cannot open \"%s\"\n %s "),
|
||||
file, unix_error_string (errno));
|
||||
|
@ -1422,7 +1422,7 @@ input_destroy (WInput * in)
|
||||
if (in == NULL)
|
||||
{
|
||||
fprintf (stderr, "Internal error: null Input *\n");
|
||||
exit (1);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
new_input (in);
|
||||
|
Loading…
Reference in New Issue
Block a user