Merge branch '2888_cleanup'

* 2888_cleanup: (30 commits)
  Refactoring of endless loops and some type accuracy.
  Refactoring of subshell support.
  Remove stub environment file from tests
  make internal library for testing purposes
  remove src/main.h file
  Move global variables to an appropriate place
  move do_load_prompt() and load_prompt() from src/main.c to src/filemanager/layout.c
  move do_cd from src/main.c to src/filemanager/panel.c
  mcedit: type accuracy in block operation routines.
  Fix of sys/ioctl.h includes: use HAVE_SYS_IOCTL_H guard.
  Optimization of SIGWINCH handling.
  src/filemanager/Makefile.am: cleanup source file list.
  Clarify of i18n initialization.
  Rename _syntax_marker to syntax_marker_t and reimplement it using GSList.
  (compare_word_to_right): minor refactoring.
  Fix types for line numbers and byte offsets in syntax highlighting engine.
  Many editor functions: take editor as constant object.
  (get_first_editor_line): minor refactoring.
  (edit_get_syntax_color): return color directly.
  Rename syntax_rule to edit_syntax_rule_t.
  ...
This commit is contained in:
Andrew Borodin 2012-10-22 10:09:17 +04:00
commit 0668e878eb
68 changed files with 953 additions and 1377 deletions

View File

@ -12,6 +12,7 @@ m4_include([m4.include/mc-with-x.m4])
m4_include([m4.include/mc-use-termcap.m4])
m4_include([m4.include/mc-with-screen.m4])
m4_include([m4.include/mc-with-edit.m4])
m4_include([m4.include/mc-subshell.m4])
m4_include([m4.include/mc-background.m4])
m4_include([m4.include/ac-glib.m4])
m4_include([m4.include/mc-vfs.m4])

View File

@ -56,6 +56,8 @@ PKG_PROG_PKG_CONFIG
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PATH_PROG([PERL], [perl], [/usr/bin/perl])
AC_PATH_PROG([PYTHON], [python], [/usr/bin/python])
AC_PATH_PROG([RUBY], [ruby], [/usr/bin/ruby])
dnl Check nroff and the options it supports
AC_CHECK_PROG(HAVE_nroff, nroff, true, false)
@ -388,36 +390,10 @@ else
diff_msg="no"
fi
AC_MSG_CHECKING([for subshell support])
AC_ARG_WITH(subshell,
[ --with-subshell Compile in concurrent subshell [[yes]]
--with-subshell=optional Don't run concurrent shell by default [[no]]],
[result=no
if test x$withval = xoptional
then
AC_DEFINE(SUBSHELL_OPTIONAL, 1,
[Define to make subshell support optional])
result="optional"
fi
if test x$withval = xyes
then
result="yes"
fi],
[dnl Default: enable the subshell support
result="yes"
])
if test "x$result" != xno; then
AC_DEFINE(HAVE_SUBSHELL_SUPPORT, 1,
[Define to enable subshell support])
fi
AC_MSG_RESULT([$result])
subshell="$result"
MC_SUBSHELL
MC_BACKGROUND
AC_MC_VFS_CHECKS
dnl ############################################################################
dnl Directories
dnl ############################################################################
@ -564,6 +540,7 @@ src/vfs/extfs/helpers/ualz
src/vfs/extfs/helpers/uar
src/vfs/extfs/helpers/uarc
src/vfs/extfs/helpers/uarj
src/vfs/extfs/helpers/uc1541
src/vfs/extfs/helpers/ucab
src/vfs/extfs/helpers/uha
src/vfs/extfs/helpers/ulha
@ -603,6 +580,7 @@ lib/vfs/Makefile
lib/widget/Makefile
misc/syntax/Makefile
misc/syntax/Syntax
doc/Makefile
doc/hints/Makefile
@ -638,10 +616,10 @@ tests/src/filemanager/Makefile
])
fi
AC_OUTPUT
echo "
AC_MSG_NOTICE([
Configuration:
Source code location: ${srcdir}
@ -658,4 +636,4 @@ Configuration:
Diff viewer: ${diff_msg}
Support for charset: ${charset_msg}
Search type: ${SEARCH_TYPE}
"
])

View File

@ -5,7 +5,7 @@ SED_PARAMETERS = \
-e "s{%sysconfdir%{@sysconfdir@{g"
MAN_DATE_CMD = \
LC_ALL=$(DATE_LANG) perl -MPOSIX -e '\
LC_ALL=$(DATE_LANG) @PERL@ -MPOSIX -e '\
@fi=lstat("'$${MAN_FILE}'"); \
print POSIX::strftime("$(DATE_FORMAT)", localtime($$fi[9]));' 2>/dev/null

View File

@ -33,15 +33,15 @@
#include "global.h"
/* *INDENT-OFF* */
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
# ifdef SUBSHELL_OPTIONAL
# define SUBSHELL_USE FALSE
# else /* SUBSHELL_OPTIONAL */
# define SUBSHELL_USE TRUE
# endif /* SUBSHELL_OPTIONAL */
#else /* !HAVE_SUBSHELL_SUPPORT */
#else /* !ENABLE_SUBSHELL */
# define SUBSHELL_USE FALSE
#endif /* !HAVE_SUBSHELL_SUPPORT */
#endif /* !ENABLE_SUBSHELL */
/* *INDENT-ON* */
/*** global variables ****************************************************************************/
@ -90,9 +90,9 @@ mc_global_t mc_global = {
.use_subshell = SUBSHELL_USE,
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
.subshell_pty = 0,
#endif /* !HAVE_SUBSHELL_SUPPORT */
#endif /* !ENABLE_SUBSHELL */
.xterm_flag = FALSE,
.disable_x11 = FALSE,

View File

@ -128,6 +128,10 @@
#define OS_SORT_CASE_SENSITIVE_DEFAULT 1
#define UTF8_CHAR_LEN 6
/* Used to distinguish between a normal MC termination and */
/* one caused by typing `exit' or `logout' in the subshell */
#define SUBSHELL_EXIT 128
/* C++ style type casts */
#define const_cast(m_type, m_expr) ((m_type) (m_expr))
@ -228,10 +232,10 @@ typedef struct
#endif /* !LINUX_CONS_SAVER_C */
/* If using a subshell for evaluating commands this is true */
gboolean use_subshell;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/* File descriptors of the pseudoterminal used by the subshell */
int subshell_pty;
#endif /* !HAVE_SUBSHELL_SUPPORT */
#endif /* !ENABLE_SUBSHELL */
/* This flag is set by xterm detection routine in function main() */
/* It is used by function view_other_cmd() */

View File

@ -63,12 +63,16 @@
#else
#include <termios.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#endif /* __linux__ */
#ifdef __CYGWIN__
#include <termios.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#endif /* __CYGWIN__ */
#ifdef __QNXNTO__
@ -2223,7 +2227,7 @@ learn_key (void)
endtime.tv_sec++;
}
tty_nodelay (TRUE);
for (;;)
while (TRUE)
{
while ((c = tty_lowlevel_getch ()) == -1)
{

View File

@ -34,6 +34,10 @@
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/strutil.h" /* str_term_form */
@ -224,6 +228,36 @@ tty_shutdown (void)
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
#if defined(TIOCGWINSZ) && NCURSES_VERSION_MAJOR >= 4
struct winsize winsz;
winsz.ws_col = winsz.ws_row = 0;
#ifndef NCURSES_VERSION
tty_noraw_mode ();
tty_reset_screen ();
#endif
/* Ioctl on the STDIN_FILENO */
ioctl (fileno (stdout), TIOCGWINSZ, &winsz);
if (winsz.ws_col != 0 && winsz.ws_row != 0)
{
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
resizeterm (winsz.ws_row, winsz.ws_col);
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
#else
COLS = winsz.ws_col;
LINES = winsz.ws_row;
#endif
}
#endif /* defined(TIOCGWINSZ) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */
void
tty_reset_prog_mode (void)
{

View File

@ -34,10 +34,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/types.h> /* size_t */
#include <unistd.h>
#include <signal.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/strutil.h" /* str_term_form */
@ -153,7 +156,6 @@ sigwinch_handler (int dummy)
{
(void) dummy;
tty_change_screen_size ();
mc_global.tty.winch_flag = TRUE;
}
@ -372,6 +374,19 @@ tty_shutdown (void)
}
}
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
SLtt_get_screen_size ();
SLsmg_reinit_smg ();
do_enter_ca_mode ();
tty_keypad (TRUE);
tty_nodelay (FALSE);
}
/* --------------------------------------------------------------------------------------------- */
/* Done each time we come back from done mode */

View File

@ -252,38 +252,6 @@ tty_resize (int fd)
/* --------------------------------------------------------------------------------------------- */
void
tty_change_screen_size (void)
{
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
#if defined TIOCGWINSZ
struct winsize winsz;
winsz.ws_col = winsz.ws_row = 0;
/* Ioctl on the STDIN_FILENO */
ioctl (0, TIOCGWINSZ, &winsz);
if (winsz.ws_col && winsz.ws_row)
{
#if defined(NCURSES_VERSION) && defined(HAVE_RESIZETERM)
resizeterm (winsz.ws_row, winsz.ws_col);
clearok (stdscr, TRUE); /* sigwinch's should use a semaphore! */
#else
COLS = winsz.ws_col;
LINES = winsz.ws_row;
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
if (!mc_global.tty.use_subshell)
return;
tty_resize (mc_global.tty.subshell_pty);
#endif
}
#endif /* TIOCGWINSZ */
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */
void
tty_init_xterm_support (gboolean is_xterm)
{

View File

@ -135,9 +135,10 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2)
bytes = (y2 - y1) * (COLS + 1) + 1; /* *should* be the number of bytes read */
j = 0;
k = g_malloc (bytes);
for (;;)
while (TRUE)
{
int c;
c = rxvt_getc ();
if (c < 0)
break;

View File

@ -991,32 +991,32 @@ diff_two_paths (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
{
p = my_first;
q = my_second;
for (;;)
while (TRUE)
{
r = strchr (p, PATH_SEP);
s = strchr (q, PATH_SEP);
if (!r || !s)
if (r == NULL || s == NULL)
break;
*r = 0;
*s = 0;
if (strcmp (p, q))
*r = '\0';
*s = '\0';
if (strcmp (p, q) != 0)
{
*r = PATH_SEP;
*s = PATH_SEP;
break;
}
else
{
*r = PATH_SEP;
*s = PATH_SEP;
}
*r = PATH_SEP;
*s = PATH_SEP;
p = r + 1;
q = s + 1;
}
p--;
for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++);
for (i = 0; (p = strchr (p + 1, PATH_SEP)) != NULL; i++)
;
currlen = (i + 1) * 3 + strlen (q) + 1;
if (j)
if (j != 0)
{
if (currlen < prevlen)
g_free (buf);

View File

@ -777,72 +777,32 @@ mc_lseek (int fd, off_t offset, int whence)
int
mc_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *suffix)
{
static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static unsigned long value;
struct timeval tv;
char *tmpbase;
char *tmpname;
char *XXXXXX;
char *ret_path;
int count;
char *p1, *p2;
int fd;
if (strchr (prefix, PATH_SEP) == NULL)
{
/* Add prefix first to find the position of XXXXXX */
tmpbase = g_build_filename (mc_tmpdir (), prefix, NULL);
}
if (strchr (prefix, PATH_SEP) != NULL)
p1 = g_strdup (prefix);
else
{
tmpbase = g_strdup (prefix);
/* Add prefix first to find the position of XXXXXX */
p1 = g_build_filename (mc_tmpdir (), prefix, (char *) NULL);
}
tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, (char *) NULL);
ret_path = tmpname;
XXXXXX = &tmpname[strlen (tmpbase)];
g_free (tmpbase);
p2 = g_strconcat (p1, "XXXXXX", suffix, (char *) NULL);
g_free (p1);
/* Get some more or less random data. */
gettimeofday (&tv, NULL);
value += (tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
for (count = 0; count < TMP_MAX; ++count)
fd = g_mkstemp (p2);
if (fd >= 0)
*pname_vpath = vfs_path_from_str (p2);
else
{
unsigned long v = value;
int fd;
/* Fill in the random bits. */
XXXXXX[0] = letters[v % 62];
v /= 62;
XXXXXX[1] = letters[v % 62];
v /= 62;
XXXXXX[2] = letters[v % 62];
v /= 62;
XXXXXX[3] = letters[v % 62];
v /= 62;
XXXXXX[4] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
fd = open (tmpname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR);
if (fd >= 0)
{
/* Successfully created. */
*pname_vpath = vfs_path_from_str (ret_path);
g_free (ret_path);
return fd;
}
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
with (module 2^32). */
value += 7777;
*pname_vpath = NULL;
fd = -1;
}
/* Unsuccessful. Free the filename. */
g_free (ret_path);
*pname_vpath = NULL;
g_free (p2);
return -1;
return fd;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -32,16 +32,8 @@
#include <config.h>
/* If TIOCGWINSZ supported, make it available here, because window resizing code
* depends on it... */
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <termios.h>
#include "lib/global.h"
#include "lib/tty/tty.h" /* LINES, COLS */
#include "lib/tty/win.h" /* do_enter_ca_mode() */
#include "lib/tty/color.h" /* tty_set_normal_attrs() */
#include "lib/widget.h"
#include "lib/event.h"
@ -121,7 +113,6 @@ dialog_switch_goto (GList * dlg)
/* --------------------------------------------------------------------------------------------- */
#if defined TIOCGWINSZ
static void
dlg_resize_cb (void *data, void *user_data)
{
@ -133,7 +124,6 @@ dlg_resize_cb (void *data, void *user_data)
else
d->winch_pending = TRUE;
}
#endif
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
@ -374,25 +364,12 @@ void
dialog_change_screen_size (void)
{
mc_global.tty.winch_flag = FALSE;
#if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4
#if defined TIOCGWINSZ
#ifndef NCURSES_VERSION
tty_noraw_mode ();
tty_reset_screen ();
#endif
tty_change_screen_size ();
#ifdef HAVE_SLANG
/* XSI Curses spec states that portable applications shall not invoke
* initscr() more than once. This kludge could be done within the scope
* of the specification by using endwin followed by a refresh (in fact,
* more than one curses implementation does this); it is guaranteed to work
* only with slang.
*/
SLsmg_init_smg ();
do_enter_ca_mode ();
tty_keypad (TRUE);
tty_nodelay (FALSE);
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
tty_resize (mc_global.tty.subshell_pty);
#endif
/* Inform all suspending dialogs */
@ -402,9 +379,6 @@ dialog_change_screen_size (void)
/* Now, force the redraw */
repaint_screen ();
#endif /* TIOCGWINSZ */
#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */
}
/* --------------------------------------------------------------------------------------------- */

33
m4.include/mc-subshell.m4 Normal file
View File

@ -0,0 +1,33 @@
dnl
dnl Subshell support.
dnl
AC_DEFUN([MC_SUBSHELL], [
AC_MSG_CHECKING([for subshell support])
AC_ARG_WITH(subshell,
[ --with-subshell Compile in concurrent subshell @<:@yes@:>@
--with-subshell=optional Don't run concurrent shell by default @<:@no@:>@],
[
result=no
if test x$withval = xoptional; then
AC_DEFINE(SUBSHELL_OPTIONAL, 1, [Define to make subshell support optional])
result="optional"
fi
if test x$withval = xyes; then
result="yes"
fi
],
[
dnl Default: enable the subshell support
result="yes"
])
if test "x$result" != xno; then
AC_DEFINE(ENABLE_SUBSHELL, 1, [Define to enable subshell support])
fi
AC_MSG_RESULT([$result])
subshell="$result"
AM_CONDITIONAL(ENABLE_SUBSHELL, [test "x$result" != xno])
])

View File

@ -24,8 +24,8 @@ staroffice_console() {
}
get_ooffice_executable() {
which libreoffice >/dev/null 2>&1 && \
echo "libreoffice" || \
which loffice >/dev/null 2>&1 && \
echo "loffice" || \
echo "ooffice"
}

View File

@ -432,7 +432,7 @@ include/image
### Sound files ###
regex/i/\.(wav|snd|voc|au|smp|aiff|snd|m4a|ape|aac|wvm4a)$
regex/i/\.(wav|snd|voc|au|smp|aiff|snd|m4a|ape|aac|wv)$
Open=@EXTHELPERSDIR@/sound.sh open common
regex/i/\.(mod|s3m|xm|it|mtm|669|stm|ult|far)$

View File

@ -1,5 +1,8 @@
SYNTAX_IN = Syntax.in
SYNTAX_OUT = Syntax
SYNTAXFILES = \
Syntax \
PKGBUILD.syntax \
ada95.syntax \
as.syntax \
@ -76,7 +79,9 @@ SYNTAXFILES = \
if USE_EDIT
syntaxdir = $(pkgdatadir)/syntax
syntax_DATA = $(SYNTAXFILES)
syntax_DATA = $(SYNTAX_OUT) \
$(SYNTAXFILES)
endif
EXTRA_DIST = $(SYNTAXFILES)
EXTRA_DIST = $(SYNTAX_IN) \
$(SYNTAXFILES)

View File

@ -171,7 +171,7 @@ include po.syntax
file ..\*\\.([Aa][Ss][Mm]|s|S)$ ASM\sProgram
include assembler.syntax
file ..\*\\.([Pp][Oo][Vv])$ POV\sScript
include povray.syntax

View File

@ -8,6 +8,8 @@ if USE_DIFF
SUBDIRS += diffviewer
endif
noinst_LTLIBRARIES = libinternal.la
AM_CPPFLAGS = \
-DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" \
-DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\" \
@ -35,11 +37,14 @@ if USE_DIFF
DIFFLIB = diffviewer/libdiffviewer.la
endif
mc_LDADD = \
libinternal_la_LIBADD = \
filemanager/libmcfilemanager.la \
vfs/libmc-vfs.la \
viewer/libmcviewer.la \
filemanager/libmcfilemanager.la \
$(DIFFLIB) $(EDITLIB) \
$(DIFFLIB) $(EDITLIB)
mc_LDADD = \
libinternal.la \
$(top_builddir)/lib/libmc.la
if ENABLE_VFS_SMB
@ -51,6 +56,9 @@ SRC_mc_conssaver = \
cons.handler.c consaver/cons.saver.h
mc_SOURCES = \
main.c
libinternal_la_SOURCES = \
$(SRC_mc_conssaver) \
args.c args.h \
clipboard.c clipboard.h \
@ -60,18 +68,20 @@ mc_SOURCES = \
history.h \
keybind-defaults.c keybind-defaults.h \
learn.c learn.h \
main.c main.h \
setup.c setup.h \
subshell.c subshell.h \
textconf.c textconf.h \
util.c util.h
if CHARSET
mc_SOURCES += selcodepage.c selcodepage.h
libinternal_la_SOURCES += selcodepage.c selcodepage.h
endif
if ENABLE_SUBSHELL
libinternal_la_SOURCES += subshell.c subshell.h
endif
if ENABLE_BACKGROUND
mc_SOURCES += background.c background.h
libinternal_la_SOURCES += background.c background.h
endif
EXTRA_DIST = $(SRC_maintainer) $(SRC_charset)

View File

@ -38,7 +38,6 @@
#include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */
#endif
#include "src/main.h"
#include "src/textconf.h"
#include "src/args.h"
@ -72,6 +71,9 @@ char *mc_args__keymap_file = NULL;
/* Debug level */
int mc_args__debug_level = 0;
void *mc_run_param0 = NULL;
char *mc_run_param1 = NULL;
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
@ -86,9 +88,9 @@ static gboolean parse_mc_v_argument (const gchar * option_name, const gchar * va
static GOptionContext *context;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
static gboolean mc_args__nouse_subshell = FALSE;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
static gboolean mc_args__show_datadirs = FALSE;
static gboolean mc_args__show_datadirs_extended = FALSE;
static gboolean mc_args__show_configure_opts = FALSE;
@ -136,7 +138,7 @@ static const GOptionEntry argument_main_table[] = {
"<file>"
},
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
{
"subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE,
&mc_global.tty.use_subshell,
@ -704,10 +706,10 @@ mc_setup_by_args (int argc, char **argv, GError ** error)
if (mc_args__force_colors)
mc_global.tty.disable_colors = FALSE;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_args__nouse_subshell)
mc_global.tty.use_subshell = FALSE;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
#ifdef ENABLE_VFS_SMB
if (mc_args__debug_level != 0)

View File

@ -27,6 +27,21 @@ extern char *mc_args__netfs_logfile;
extern char *mc_args__keymap_file;
extern int mc_args__debug_level;
/*
* MC_RUN_FULL: dir for left panel
* MC_RUN_EDITOR: list of files to edit
* MC_RUN_VIEWER: file to view
* MC_RUN_DIFFVIEWER: first file to compare
*/
extern void *mc_run_param0;
/*
* MC_RUN_FULL: dir for right panel
* MC_RUN_EDITOR: unused
* MC_RUN_VIEWER: unused
* MC_RUN_DIFFVIEWER: second file to compare
*/
extern char *mc_run_param1;
/*** declarations of public functions ************************************************************/
gboolean mc_args_parse (int *argc, char ***argv, const char *translation_domain, GError ** error);

View File

@ -36,7 +36,7 @@
#include "lib/vfs/vfs.h"
#include "main.h"
#include "setup.h"
#include "src/execute.h"
#include "clipboard.h"

View File

@ -35,8 +35,10 @@
#include <sys/types.h>
#ifdef __FreeBSD__
#include <sys/consio.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#endif
#include <unistd.h>
#include "lib/global.h"

View File

@ -54,6 +54,7 @@
#include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */
#include "src/keybind-defaults.h"
#include "src/setup.h"
#include "src/history.h"
#ifdef HAVE_CHARSET
#include "src/selcodepage.h"

View File

@ -62,8 +62,8 @@
appended after each other and the last one is always the one found
by book_mark_found() i.e. last in is the one seen */
static struct _book_mark *
double_marks (WEdit * edit, struct _book_mark *p)
static edit_book_mark_t *
double_marks (WEdit * edit, edit_book_mark_t *p)
{
(void) edit;
@ -76,15 +76,15 @@ double_marks (WEdit * edit, struct _book_mark *p)
/* --------------------------------------------------------------------------------------------- */
/** returns the first bookmark on or before this line */
struct _book_mark *
edit_book_mark_t *
book_mark_find (WEdit * edit, long line)
{
struct _book_mark *p;
edit_book_mark_t *p;
if (edit->book_mark == NULL)
{
/* must have an imaginary top bookmark at line -1 to make things less complicated */
edit->book_mark = g_malloc0 (sizeof (struct _book_mark));
edit->book_mark = g_new0 (edit_book_mark_t, 1);
edit->book_mark->line = -1;
return edit->book_mark;
}
@ -139,24 +139,32 @@ book_mark_find (WEdit * edit, long line)
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/** returns true if a bookmark exists at this line of color c */
/**
* Check if bookmark bookmark exists at this line of this color
*
* @param edit editor object
* @param line line where book mark is
* @param c color of book mark
* @returns TRUE if bookmark exists at this line of color c, FALSE otherwise
*/
int
gboolean
book_mark_query_color (WEdit * edit, long line, int c)
{
struct _book_mark *p;
if (edit->book_mark == NULL)
return 0;
for (p = book_mark_find (edit, line); p != NULL; p = p->prev)
if (edit->book_mark != NULL)
{
if (p->line != line)
return 0;
if (p->c == c)
return 1;
edit_book_mark_t *p;
for (p = book_mark_find (edit, line); p != NULL; p = p->prev)
{
if (p->line != line)
return FALSE;
if (p->c == c)
return TRUE;
}
}
return 0;
return FALSE;
}
/* --------------------------------------------------------------------------------------------- */
@ -165,7 +173,7 @@ book_mark_query_color (WEdit * edit, long line, int c)
void
book_mark_insert (WEdit * edit, long line, int c)
{
struct _book_mark *p, *q;
edit_book_mark_t *p, *q;
p = book_mark_find (edit, line);
#if 0
@ -181,7 +189,7 @@ book_mark_insert (WEdit * edit, long line, int c)
}
#endif
/* create list entry */
q = g_malloc0 (sizeof (struct _book_mark));
q = g_new (edit_book_mark_t, 1);
q->line = line;
q->c = c;
q->next = p->next;
@ -195,15 +203,20 @@ book_mark_insert (WEdit * edit, long line, int c)
}
/* --------------------------------------------------------------------------------------------- */
/** remove a bookmark if there is one at this line matching this color - c of -1 clear all
* @returns non-zero on not-found
/**
* Remove a bookmark if there is one at this line matching this color - c of -1 clear all
*
* @param edit editor object
* @param line line where book mark is
* @param c color of book mark or -1 to clear all book marks on this line
* @returns FALSE if not found, TRUE otherwise
*/
int
gboolean
book_mark_clear (WEdit * edit, long line, int c)
{
struct _book_mark *p, *q;
int r = 1;
edit_book_mark_t *p, *q;
gboolean r = FALSE;
if (edit->book_mark == NULL)
return r;
@ -213,7 +226,7 @@ book_mark_clear (WEdit * edit, long line, int c)
q = p->prev;
if (p->line == line && (p->c == c || c == -1))
{
r = 0;
r = TRUE;
edit->book_mark = p->prev;
p->prev->next = p->next;
if (p->next != NULL)
@ -224,7 +237,7 @@ book_mark_clear (WEdit * edit, long line, int c)
}
}
/* if there is only our dummy book mark left, clear it for speed */
if (edit->book_mark->line == -1 && !edit->book_mark->next)
if (edit->book_mark->line == -1 && edit->book_mark->next == NULL)
{
g_free (edit->book_mark);
edit->book_mark = NULL;
@ -238,7 +251,7 @@ book_mark_clear (WEdit * edit, long line, int c)
void
book_mark_flush (WEdit * edit, int c)
{
struct _book_mark *p, *q;
edit_book_mark_t *p, *q;
if (edit->book_mark == NULL)
return;
@ -274,7 +287,7 @@ book_mark_inc (WEdit * edit, long line)
{
if (edit->book_mark != NULL)
{
struct _book_mark *p;
edit_book_mark_t *p;
p = book_mark_find (edit, line);
for (p = p->next; p != NULL; p = p->next)
@ -290,7 +303,7 @@ book_mark_dec (WEdit * edit, long line)
{
if (edit->book_mark != NULL)
{
struct _book_mark *p;
edit_book_mark_t *p;
p = book_mark_find (edit, line);
for (p = p->next; p != NULL; p = p->next)
@ -304,13 +317,13 @@ book_mark_dec (WEdit * edit, long line)
void
book_mark_serialize (WEdit * edit, int color)
{
struct _book_mark *p;
if (edit->serialized_bookmarks != NULL)
g_array_set_size (edit->serialized_bookmarks, 0);
if (edit->book_mark != NULL)
{
edit_book_mark_t *p;
if (edit->serialized_bookmarks == NULL)
edit->serialized_bookmarks = g_array_sized_new (FALSE, FALSE, sizeof (size_t),
MAX_SAVED_BOOKMARKS);

View File

@ -182,12 +182,12 @@ void user_menu (WEdit * edit, const char *menu_file, int selected_entry);
void edit_init_menu (struct WMenuBar *menubar);
void edit_save_mode_cmd (void);
gboolean edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch);
int edit_get_byte (WEdit * edit, off_t byte_index);
int edit_get_utf (WEdit * edit, off_t byte_index, int *char_width);
long edit_count_lines (WEdit * edit, off_t current, off_t upto);
off_t edit_move_forward (WEdit * edit, off_t current, long lines, off_t upto);
off_t edit_move_forward3 (WEdit * edit, off_t current, long cols, off_t upto);
off_t edit_move_backward (WEdit * edit, off_t current, long lines);
int edit_get_byte (const WEdit * edit, off_t byte_index);
int edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width);
long edit_count_lines (const WEdit * edit, off_t current, off_t upto);
off_t edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto);
off_t edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto);
off_t edit_move_backward (const WEdit * edit, off_t current, long lines);
void edit_scroll_screen_over_cursor (WEdit * edit);
void edit_render_keypress (WEdit * edit);
void edit_scroll_upward (WEdit * edit, long i);
@ -197,9 +197,9 @@ void edit_scroll_left (WEdit * edit, long i);
void edit_move_up (WEdit * edit, long i, gboolean do_scroll);
void edit_move_down (WEdit * edit, long i, gboolean do_scroll);
void edit_move_to_prev_col (WEdit * edit, off_t p);
long edit_get_col (WEdit * edit);
off_t edit_bol (WEdit * edit, off_t current);
off_t edit_eol (WEdit * edit, off_t current);
long edit_get_col (const WEdit * edit);
off_t edit_bol (const WEdit * edit, off_t current);
off_t edit_eol (const WEdit * edit, off_t current);
void edit_update_curs_row (WEdit * edit);
void edit_update_curs_col (WEdit * edit);
void edit_find_bracket (WEdit * edit);
@ -211,8 +211,8 @@ void edit_block_move_cmd (WEdit * edit);
int edit_block_delete_cmd (WEdit * edit);
void edit_delete_line (WEdit * edit);
int edit_delete (WEdit * edit, const int byte_delete);
int edit_backspace (WEdit * edit, const int byte_delete);
int edit_delete (WEdit * edit, gboolean byte_delete);
int edit_backspace (WEdit * edit, gboolean byte_delete);
void edit_insert (WEdit * edit, int c);
void edit_cursor_move (WEdit * edit, off_t increment);
void edit_push_undo_action (WEdit * edit, long c);
@ -258,7 +258,7 @@ off_t edit_insert_column_of_text_from_file (WEdit * edit, int file,
off_t * start_pos, off_t * end_pos, long *col1,
long *col2);
char *edit_get_word_from_pos (WEdit * edit, off_t start_pos, off_t * start, gsize * len,
char *edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len,
gsize * cut);
long edit_insert_file (WEdit * edit, const vfs_path_t * filename_vpath);
gboolean edit_load_back_cmd (WEdit * edit);
@ -305,22 +305,21 @@ void edit_set_filename (WEdit * edit, const vfs_path_t * name_vpath);
void edit_load_syntax (WEdit * edit, char ***pnames, const char *type);
void edit_free_syntax_rules (WEdit * edit);
void edit_get_syntax_color (WEdit * edit, off_t byte_index, int *color);
int edit_get_syntax_color (WEdit * edit, off_t byte_index);
void book_mark_insert (WEdit * edit, long line, int c);
int book_mark_query_color (WEdit * edit, long line, int c);
int book_mark_query_all (WEdit * edit, long line, int *c);
struct _book_mark *book_mark_find (WEdit * edit, long line);
int book_mark_clear (WEdit * edit, long line, int c);
gboolean book_mark_query_color (WEdit * edit, long line, int c);
struct edit_book_mark_t *book_mark_find (WEdit * edit, long line);
gboolean book_mark_clear (WEdit * edit, long line, int c);
void book_mark_flush (WEdit * edit, int c);
void book_mark_inc (WEdit * edit, long line);
void book_mark_dec (WEdit * edit, long line);
void book_mark_serialize (WEdit * edit, int color);
void book_mark_restore (WEdit * edit, int color);
gboolean line_is_blank (WEdit * edit, long line);
gboolean edit_line_is_blank (WEdit * edit, long line);
gboolean is_break_char (char c);
long edit_indent_width (WEdit * edit, off_t p);
long edit_indent_width (const WEdit * edit, off_t p);
void edit_insert_indent (WEdit * edit, int indent);
void edit_options_dialog (Dlg_head * h);
void edit_syntax_dialog (WEdit * edit);

View File

@ -64,7 +64,6 @@
#include "src/filemanager/usermenu.h" /* user_menu_cmd() */
#include "src/setup.h" /* option_tab_spacing */
#include "src/main.h" /* macro_index */
#include "src/learn.h" /* learn_keys */
#include "src/keybind-defaults.h"
@ -654,7 +653,7 @@ edit_modification (WEdit * edit)
#ifdef HAVE_CHARSET
static char *
edit_get_byte_ptr (WEdit * edit, off_t byte_index)
edit_get_byte_ptr (const WEdit * edit, off_t byte_index)
{
if (byte_index >= (edit->curs1 + edit->curs2) || byte_index < 0)
return NULL;
@ -677,7 +676,7 @@ edit_get_byte_ptr (WEdit * edit, off_t byte_index)
#ifdef HAVE_CHARSET
static int
edit_get_prev_utf (WEdit * edit, off_t byte_index, int *char_width)
edit_get_prev_utf (const WEdit * edit, off_t byte_index, int *char_width)
{
int i, res;
gchar utf8_buf[3 * UTF8_CHAR_LEN + 1];
@ -731,7 +730,7 @@ edit_get_prev_utf (WEdit * edit, off_t byte_index, int *char_width)
*/
static gboolean
is_in_indent (WEdit * edit)
is_in_indent (const WEdit * edit)
{
off_t p;
@ -752,7 +751,7 @@ is_in_indent (WEdit * edit)
*/
static gboolean
is_blank (WEdit * edit, off_t offset)
is_blank (const WEdit * edit, off_t offset)
{
off_t s, f;
int c;
@ -831,16 +830,16 @@ edit_move_up_paragraph (WEdit * edit, gboolean do_scroll)
if (edit->curs_line > 1)
{
if (!line_is_blank (edit, edit->curs_line))
if (!edit_line_is_blank (edit, edit->curs_line))
{
for (i = edit->curs_line - 1; i != 0; i--)
if (line_is_blank (edit, i))
if (edit_line_is_blank (edit, i))
break;
}
else if (line_is_blank (edit, edit->curs_line - 1))
else if (edit_line_is_blank (edit, edit->curs_line - 1))
{
for (i = edit->curs_line - 1; i != 0; i--)
if (!line_is_blank (edit, i))
if (!edit_line_is_blank (edit, i))
{
i++;
break;
@ -849,7 +848,7 @@ edit_move_up_paragraph (WEdit * edit, gboolean do_scroll)
else
{
for (i = edit->curs_line - 1; i != 0; i--)
if (line_is_blank (edit, i))
if (edit_line_is_blank (edit, i))
break;
}
}
@ -868,16 +867,16 @@ edit_move_down_paragraph (WEdit * edit, gboolean do_scroll)
if (edit->curs_line >= edit->total_lines - 1)
i = edit->total_lines;
else if (!line_is_blank (edit, edit->curs_line))
else if (!edit_line_is_blank (edit, edit->curs_line))
{
for (i = edit->curs_line + 1; i != 0; i++)
if (line_is_blank (edit, i) || i >= edit->total_lines)
if (edit_line_is_blank (edit, i) || i >= edit->total_lines)
break;
}
else if (line_is_blank (edit, edit->curs_line + 1))
else if (edit_line_is_blank (edit, edit->curs_line + 1))
{
for (i = edit->curs_line + 1; i != 0; i++)
if (!line_is_blank (edit, i) || i > edit->total_lines)
if (!edit_line_is_blank (edit, i) || i > edit->total_lines)
{
i--;
break;
@ -886,7 +885,7 @@ edit_move_down_paragraph (WEdit * edit, gboolean do_scroll)
else
{
for (i = edit->curs_line + 1; i != 0; i++)
if (line_is_blank (edit, i) || i >= edit->total_lines)
if (edit_line_is_blank (edit, i) || i >= edit->total_lines)
break;
}
edit_move_down (edit, i - edit->curs_line, do_scroll);
@ -978,7 +977,7 @@ my_type_of (int c)
const char option_chars_move_whole_word[] =
"!=&|<>^~ !:;, !'!`!.?!\"!( !) !{ !} !Aa0 !+-*/= |<> ![ !] !\\#! ";
if (!c)
if (c == 0)
return 0;
if (c == '!')
{
@ -1015,27 +1014,27 @@ my_type_of (int c)
static void
edit_left_word_move (WEdit * edit, int s)
{
for (;;)
while (TRUE)
{
int c1, c2;
if (edit->column_highlight
&& edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_bol (edit, edit->curs1))
break;
edit_cursor_move (edit, -1);
if (!edit->curs1)
if (edit->curs1 == 0)
break;
c1 = edit_get_byte (edit, edit->curs1 - 1);
c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n')
break;
if (!(my_type_of (c1) & my_type_of (c2)))
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
if (isspace (c1) && !isspace (c2))
break;
if (s)
if (!isspace (c1) && isspace (c2))
break;
if (s != 0 && !isspace (c1) && isspace (c2))
break;
}
}
@ -1053,9 +1052,10 @@ edit_left_word_move_cmd (WEdit * edit)
static void
edit_right_word_move (WEdit * edit, int s)
{
for (;;)
while (TRUE)
{
int c1, c2;
if (edit->column_highlight
&& edit->mark1 != edit->mark2
&& edit->over_col == 0 && edit->curs1 == edit_eol (edit, edit->curs1))
@ -1067,13 +1067,12 @@ edit_right_word_move (WEdit * edit, int s)
c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n')
break;
if (!(my_type_of (c1) & my_type_of (c2)))
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
if (isspace (c1) && !isspace (c2))
break;
if (s)
if (!isspace (c1) && isspace (c2))
break;
if (s != 0 && !isspace (c1) && isspace (c2))
break;
}
}
@ -1195,18 +1194,17 @@ edit_move_updown (WEdit * edit, long lines, gboolean do_scroll, gboolean directi
static void
edit_right_delete_word (WEdit * edit)
{
int c1, c2;
for (;;)
while (edit->curs1 < edit->last_byte)
{
if (edit->curs1 >= edit->last_byte)
break;
c1 = edit_delete (edit, 1);
int c1, c2;
c1 = edit_delete (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1);
if (c1 == '\n' || c2 == '\n')
break;
if ((isspace (c1) == 0) != (isspace (c2) == 0))
break;
if (!(my_type_of (c1) & my_type_of (c2)))
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
}
}
@ -1216,18 +1214,17 @@ edit_right_delete_word (WEdit * edit)
static void
edit_left_delete_word (WEdit * edit)
{
int c1, c2;
for (;;)
while (edit->curs1 > 0)
{
if (edit->curs1 <= 0)
break;
c1 = edit_backspace (edit, 1);
int c1, c2;
c1 = edit_backspace (edit, TRUE);
c2 = edit_get_byte (edit, edit->curs1 - 1);
if (c1 == '\n' || c2 == '\n')
break;
if ((isspace (c1) == 0) != (isspace (c2) == 0))
break;
if (!(my_type_of (c1) & my_type_of (c2)))
if ((my_type_of (c1) & my_type_of (c2)) == 0)
break;
}
}
@ -1260,11 +1257,11 @@ edit_do_undo (WEdit * edit)
break;
case BACKSPACE:
case BACKSPACE_BR:
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
break;
case DELCHAR:
case DELCHAR_BR:
edit_delete (edit, 1);
edit_delete (edit, TRUE);
break;
case COLUMN_ON:
edit->column_highlight = 1;
@ -1340,10 +1337,10 @@ edit_do_redo (WEdit * edit)
edit_cursor_move (edit, -1);
break;
case BACKSPACE:
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
break;
case DELCHAR:
edit_delete (edit, 1);
edit_delete (edit, TRUE);
break;
case COLUMN_ON:
edit->column_highlight = 1;
@ -1417,7 +1414,7 @@ static void
edit_delete_to_line_end (WEdit * edit)
{
while (edit_get_byte (edit, edit->curs1) != '\n' && edit->curs2 != 0)
edit_delete (edit, 1);
edit_delete (edit, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@ -1426,7 +1423,7 @@ static void
edit_delete_to_line_begin (WEdit * edit)
{
while (edit_get_byte (edit, edit->curs1 - 1) != '\n' && edit->curs1 != 0)
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@ -1474,11 +1471,12 @@ edit_auto_indent (WEdit * edit)
{
off_t p;
char c;
p = edit->curs1;
/* use the previous line as a template */
p = edit_move_backward (edit, p, 1);
/* copy the leading whitespace of the line */
for (;;)
while (TRUE)
{ /* no range check - the line _is_ \n-terminated */
c = edit_get_byte (edit, p++);
if (c != ' ' && c != '\t')
@ -1535,7 +1533,7 @@ edit_tab_cmd (WEdit * edit)
int i;
for (i = 1; i <= HALF_TAB_SIZE; i++)
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
edit_insert (edit, '\t');
}
}
@ -1559,7 +1557,7 @@ check_and_wrap_line (WEdit * edit)
if (edit->curs_col < option_word_wrap_line_length)
return;
curs = edit->curs1;
for (;;)
while (TRUE)
{
curs--;
c = edit_get_byte (edit, curs);
@ -1672,7 +1670,7 @@ edit_move_block_to_right (WEdit * edit)
do
{
edit_cursor_move (edit, cur_bol - edit->curs1);
if (!line_is_blank (edit, edit->curs_line))
if (!edit_line_is_blank (edit, edit->curs_line))
{
if (option_fill_tabs_with_spaces)
insert_spaces_tab (edit, option_fake_half_tabs);
@ -1720,12 +1718,12 @@ edit_move_block_to_left (WEdit * edit)
next_char = edit_get_byte (edit, edit->curs1);
if (next_char == '\t')
edit_delete (edit, 1);
edit_delete (edit, TRUE);
else if (next_char == ' ')
for (i = 1; i <= del_tab_width; i++)
{
if (next_char == ' ')
edit_delete (edit, 1);
edit_delete (edit, TRUE);
next_char = edit_get_byte (edit, edit->curs1);
}
@ -1815,7 +1813,7 @@ user_menu (WEdit * edit, const char *menu_file, int selected_entry)
/* --------------------------------------------------------------------------------------------- */
int
edit_get_byte (WEdit * edit, off_t byte_index)
edit_get_byte (const WEdit * edit, off_t byte_index)
{
off_t p;
@ -1835,7 +1833,7 @@ edit_get_byte (WEdit * edit, off_t byte_index)
#ifdef HAVE_CHARSET
int
edit_get_utf (WEdit * edit, off_t byte_index, int *char_width)
edit_get_utf (const WEdit * edit, off_t byte_index, int *char_width)
{
gchar *str = NULL;
int res = -1;
@ -2028,7 +2026,7 @@ is_break_char (char c)
/* --------------------------------------------------------------------------------------------- */
char *
edit_get_word_from_pos (WEdit * edit, off_t start_pos, off_t * start, gsize * len, gsize * cut)
edit_get_word_from_pos (const WEdit * edit, off_t start_pos, off_t * start, gsize * len, gsize * cut)
{
off_t word_start;
long cut_len = 0;
@ -2273,10 +2271,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
edit->modified = 0;
edit->locked = 0;
edit_load_syntax (edit, NULL, NULL);
{
int color;
edit_get_syntax_color (edit, -1, &color);
}
edit_get_syntax_color (edit, -1);
/* load saved cursor position */
if ((line == 0) && option_save_position)
@ -2726,7 +2721,7 @@ edit_insert_ahead (WEdit * edit, int c)
/* --------------------------------------------------------------------------------------------- */
int
edit_delete (WEdit * edit, const int byte_delete)
edit_delete (WEdit * edit, gboolean byte_delete)
{
int p = 0;
int cw = 1;
@ -2736,8 +2731,8 @@ edit_delete (WEdit * edit, const int byte_delete)
return 0;
#ifdef HAVE_CHARSET
/* if byte_delete = 1 then delete only one byte not multibyte char */
if (edit->utf8 && byte_delete == 0)
/* if byte_delete == TRUE then delete only one byte not multibyte char */
if (edit->utf8 && !byte_delete)
{
edit_get_utf (edit, edit->curs1, &cw);
if (cw < 1)
@ -2796,7 +2791,7 @@ edit_delete (WEdit * edit, const int byte_delete)
/* --------------------------------------------------------------------------------------------- */
int
edit_backspace (WEdit * edit, const int byte_delete)
edit_backspace (WEdit * edit, gboolean byte_delete)
{
int p = 0;
int cw = 1;
@ -2809,7 +2804,7 @@ edit_backspace (WEdit * edit, const int byte_delete)
edit_push_markers (edit);
#ifdef HAVE_CHARSET
if (edit->utf8 && byte_delete == 0)
if (edit->utf8 && !byte_delete)
{
edit_get_prev_utf (edit, edit->curs1, &cw);
if (cw < 1)
@ -2939,7 +2934,7 @@ edit_cursor_move (WEdit * edit, off_t increment)
/** returns index of last char on line + 1 */
off_t
edit_eol (WEdit * edit, off_t current)
edit_eol (const WEdit * edit, off_t current)
{
if (current >= edit->last_byte)
return edit->last_byte;
@ -2954,7 +2949,7 @@ edit_eol (WEdit * edit, off_t current)
/** returns index of first char on line */
off_t
edit_bol (WEdit * edit, off_t current)
edit_bol (const WEdit * edit, off_t current)
{
if (current <= 0)
return 0;
@ -2968,9 +2963,10 @@ edit_bol (WEdit * edit, off_t current)
/* --------------------------------------------------------------------------------------------- */
long
edit_count_lines (WEdit * edit, off_t current, off_t upto)
edit_count_lines (const WEdit * edit, off_t current, off_t upto)
{
long lines = 0;
if (upto > edit->last_byte)
upto = edit->last_byte;
if (current < 0)
@ -2986,7 +2982,7 @@ edit_count_lines (WEdit * edit, off_t current, off_t upto)
/* If upto is zero returns index of lines forward current. */
off_t
edit_move_forward (WEdit * edit, off_t current, long lines, off_t upto)
edit_move_forward (const WEdit * edit, off_t current, long lines, off_t upto)
{
if (upto != 0)
{
@ -3013,7 +3009,7 @@ edit_move_forward (WEdit * edit, off_t current, long lines, off_t upto)
/** Returns offset of 'lines' lines up from current */
off_t
edit_move_backward (WEdit * edit, off_t current, long lines)
edit_move_backward (const WEdit * edit, off_t current, long lines)
{
if (lines < 0)
lines = 0;
@ -3028,7 +3024,7 @@ edit_move_backward (WEdit * edit, off_t current, long lines)
/* If upto is zero returns index of cols across from current. */
off_t
edit_move_forward3 (WEdit * edit, off_t current, long cols, off_t upto)
edit_move_forward3 (const WEdit * edit, off_t current, long cols, off_t upto)
{
off_t p, q;
long col;
@ -3098,7 +3094,7 @@ edit_move_forward3 (WEdit * edit, off_t current, long cols, off_t upto)
/** returns the current column position of the cursor */
long
edit_get_col (WEdit * edit)
edit_get_col (const WEdit * edit)
{
return (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0, edit->curs1);
}
@ -3229,7 +3225,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
else
{
edit->over_col = 0;
if (is_in_indent (edit) && option_fake_half_tabs)
if (option_fake_half_tabs && is_in_indent (edit))
{
edit_update_curs_col (edit);
if (space_width != 0 && edit->curs_col % (HALF_TAB_SIZE * space_width) != 0)
@ -3258,7 +3254,7 @@ edit_move_to_prev_col (WEdit * edit, off_t p)
*/
gboolean
line_is_blank (WEdit * edit, long line)
edit_line_is_blank (WEdit * edit, long line)
{
return is_blank (edit, edit_find_line (edit, line));
}
@ -3399,27 +3395,27 @@ edit_delete_line (WEdit * edit)
* beyond EOF.
*/
while (edit_get_byte (edit, edit->curs1) != '\n')
(void) edit_delete (edit, 1);
(void) edit_delete (edit, TRUE);
/*
* Delete '\n' char.
* Note that edit_delete() will not corrupt anything if called while
* cursor position is EOF.
*/
(void) edit_delete (edit, 1);
(void) edit_delete (edit, TRUE);
/*
* Delete left part of the line.
* Note, that edit_get_byte() returns '\n' when byte position is < 0.
*/
while (edit_get_byte (edit, edit->curs1 - 1) != '\n')
(void) edit_backspace (edit, 1);
(void) edit_backspace (edit, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
long
edit_indent_width (WEdit * edit, off_t p)
edit_indent_width (const WEdit * edit, off_t p)
{
off_t q = p;
@ -3637,7 +3633,7 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
#endif
if (edit_get_byte (edit, edit->curs1) != '\n')
edit_delete (edit, 0);
edit_delete (edit, FALSE);
}
if (option_cursor_beyond_eol && edit->over_col > 0)
edit_insert_over (edit);
@ -3745,17 +3741,17 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
else if (option_backspace_through_tabs && is_in_indent (edit))
{
while (edit_get_byte (edit, edit->curs1 - 1) != '\n' && edit->curs1 > 0)
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
}
else if (option_fake_half_tabs && is_in_indent (edit) && right_of_four_spaces (edit))
{
int i;
for (i = 0; i < HALF_TAB_SIZE; i++)
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
}
else
edit_backspace (edit, 0);
edit_backspace (edit, FALSE);
break;
case CK_Delete:
/* if non persistent selection and text selected */
@ -3771,10 +3767,10 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
int i;
for (i = 1; i <= HALF_TAB_SIZE; i++)
edit_delete (edit, 1);
edit_delete (edit, TRUE);
}
else
edit_delete (edit, 0);
edit_delete (edit, FALSE);
}
break;
case CK_DeleteToWordBegin:
@ -3995,11 +3991,11 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
edit->force |= REDRAW_PAGE;
break;
case CK_BookmarkNext:
if (edit->book_mark)
if (edit->book_mark != NULL)
{
struct _book_mark *p;
edit_book_mark_t *p;
p = (struct _book_mark *) book_mark_find (edit, edit->curs_line);
p = book_mark_find (edit, edit->curs_line);
if (p->next != NULL)
{
p = p->next;
@ -4010,11 +4006,11 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
}
break;
case CK_BookmarkPrev:
if (edit->book_mark)
if (edit->book_mark != NULL)
{
struct _book_mark *p;
edit_book_mark_t *p;
p = (struct _book_mark *) book_mark_find (edit, edit->curs_line);
p = book_mark_find (edit, edit->curs_line);
while (p->line == edit->curs_line)
if (p->prev != NULL)
p = p->prev;

View File

@ -68,7 +68,6 @@
#include "src/history.h"
#include "src/setup.h" /* option_tab_spacing */
#include "src/main.h" /* mactos_t */
#ifdef HAVE_CHARSET
#include "src/selcodepage.h"
#endif
@ -549,7 +548,7 @@ edit_delete_column_of_text (WEdit * edit)
{
/* delete line between margins */
if (edit_get_byte (edit, edit->curs1) != '\n')
edit_delete (edit, 1);
edit_delete (edit, TRUE);
q--;
}
if (n)
@ -564,9 +563,8 @@ edit_delete_column_of_text (WEdit * edit)
static int
edit_block_delete (WEdit * edit)
{
off_t count;
off_t start_mark, end_mark;
int curs_pos;
off_t curs_pos;
long curs_line, c1, c2;
if (eval_marks (edit, &start_mark, &end_mark))
@ -599,12 +597,12 @@ edit_block_delete (WEdit * edit)
/* move cursor to start of selection */
edit_cursor_move (edit, start_mark - edit->curs1);
edit_scroll_screen_over_cursor (edit);
count = start_mark;
if (start_mark < end_mark)
{
if (edit->column_highlight)
{
long line_width;
off_t line_width;
if (edit->mark2 < 0)
edit_mark_cmd (edit, FALSE);
@ -612,18 +610,17 @@ edit_block_delete (WEdit * edit)
/* move cursor to the saved position */
edit_move_to_line (edit, curs_line);
/* calculate line width and cursor position before cut */
line_width = (long) edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
edit_eol (edit, edit->curs1));
line_width = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
edit_eol (edit, edit->curs1));
if (option_cursor_beyond_eol && curs_pos > line_width)
edit->over_col = curs_pos - line_width;
}
else
{
while (count < end_mark)
{
edit_delete (edit, 1);
count++;
}
off_t count;
for (count = start_mark; count < end_mark; count++)
edit_delete (edit, TRUE);
}
}
edit_set_markers (edit, 0, 0, 0, 0);
@ -1017,9 +1014,10 @@ edit_search (WEdit * edit)
/** Return a null terminated length of text. Result must be g_free'd */
static unsigned char *
edit_get_block (WEdit * edit, off_t start, off_t finish, int *l)
edit_get_block (WEdit * edit, off_t start, off_t finish, off_t *l)
{
unsigned char *s, *r;
r = s = g_malloc0 (finish - start + 1);
if (edit->column_highlight)
{
@ -1047,7 +1045,7 @@ edit_get_block (WEdit * edit, off_t start, off_t finish, int *l)
while (start < finish)
*s++ = edit_get_byte (edit, start++);
}
*s = 0;
*s = '\0';
return r;
}
@ -1300,11 +1298,11 @@ edit_collect_completions (WEdit * edit, off_t word_start, gsize word_len,
/* --------------------------------------------------------------------------------------------- */
static void
edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int width,
off_t * start_pos, off_t * end_pos, int *col1, int *col2)
edit_insert_column_of_text (WEdit * edit, unsigned char *data, off_t size, long width,
off_t * start_pos, off_t * end_pos, long *col1, long *col2)
{
off_t cursor;
long i, col;
off_t i, cursor;
long col;
cursor = edit->curs1;
col = edit_get_col (edit);
@ -1315,17 +1313,13 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
edit_insert (edit, data[i]);
else
{ /* fill in and move to next line */
int l;
long l;
off_t p;
if (edit_get_byte (edit, edit->curs1) != '\n')
{
l = width - (edit_get_col (edit) - col);
while (l > 0)
{
for (l = width - (edit_get_col (edit) - col); l > 0; l -= space_width)
edit_insert (edit, ' ');
l -= space_width;
}
}
for (p = edit->curs1;; p++)
{
@ -1343,12 +1337,9 @@ edit_insert_column_of_text (WEdit * edit, unsigned char *data, int size, int wid
}
}
edit_cursor_move (edit, edit_move_forward3 (edit, p, col, 0) - edit->curs1);
l = col - edit_get_col (edit);
while (l >= space_width)
{
for (l = col - edit_get_col (edit); l >= space_width; l -= space_width)
edit_insert (edit, ' ');
l -= space_width;
}
}
}
@ -2399,8 +2390,8 @@ edit_block_copy_cmd (WEdit * edit)
off_t start_mark, end_mark, current = edit->curs1;
long col_delta = 0;
off_t mark1, mark2;
int c1, c2;
int size;
long c1, c2;
off_t size;
unsigned char *copy_buf;
edit_update_curs_col (edit);
@ -2449,6 +2440,9 @@ edit_block_move_cmd (WEdit * edit)
if (eval_marks (edit, &start_mark, &end_mark))
return;
if (!edit->column_highlight && edit->curs1 > start_mark && edit->curs1 < end_mark)
return;
line = edit->curs_line;
if (edit->mark2 < 0)
edit_mark_cmd (edit, FALSE);
@ -2457,14 +2451,13 @@ edit_block_move_cmd (WEdit * edit)
if (edit->column_highlight)
{
off_t mark1, mark2;
int size;
int b_width = 0;
int c1, c2;
int x, x2;
off_t size;
long c1, c2, b_width;
long x, x2;
c1 = min (edit->column1, edit->column2);
c2 = max (edit->column1, edit->column2);
b_width = (c2 - c1);
b_width = c2 - c1;
edit_update_curs_col (edit);
@ -2472,7 +2465,7 @@ edit_block_move_cmd (WEdit * edit)
x2 = x + edit->over_col;
/* do nothing when cursor inside first line of selected area */
if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && (x2 > c1 && x2 <= c2))
if ((edit_eol (edit, edit->curs1) == edit_eol (edit, start_mark)) && x2 > c1 && x2 <= c2)
return;
if (edit->curs1 > start_mark && edit->curs1 < edit_eol (edit, end_mark))
@ -2509,12 +2502,10 @@ edit_block_move_cmd (WEdit * edit)
copy_buf = g_malloc0 (end_mark - start_mark);
edit_cursor_move (edit, start_mark - edit->curs1);
edit_scroll_screen_over_cursor (edit);
count = start_mark;
while (count < end_mark)
{
copy_buf[end_mark - count - 1] = edit_delete (edit, 1);
count++;
}
for (count = start_mark; count < end_mark; count++)
copy_buf[end_mark - count - 1] = edit_delete (edit, TRUE);
edit_scroll_screen_over_cursor (edit);
edit_cursor_move (edit,
current - edit->curs1 -
@ -2721,7 +2712,7 @@ edit_replace_cmd (WEdit * edit, int again)
/* delete then insert new */
for (i = 0; i < len; i++)
edit_delete (edit, 1);
edit_delete (edit, TRUE);
for (i = 0; i < repl_str->len; i++)
edit_insert (edit, repl_str->str[i]);
@ -2919,7 +2910,8 @@ edit_ok_to_exit (WEdit * edit)
gboolean
edit_save_block (WEdit * edit, const char *filename, off_t start, off_t finish)
{
int len = 1, file;
int file;
off_t len = 1;
vfs_path_t *vpath;
vpath = vfs_path_from_str (filename);
@ -3642,7 +3634,7 @@ edit_suggest_current_word (WEdit * edit)
#endif
cp_word = new_word;
for (i = 0; i < word_len; i++)
edit_backspace (edit, 1);
edit_backspace (edit, TRUE);
for (; *new_word; new_word++)
edit_insert (edit, *new_word);
g_free (cp_word);

View File

@ -36,7 +36,6 @@
#include "lib/charsets.h"
#endif
#include "src/main.h"
#include "src/history.h"
#include "src/editor/editwidget.h"

View File

@ -54,7 +54,6 @@
#endif
#include "src/setup.h" /* edit_tab_spacing */
#include "src/main.h" /* macro_index */
#include "edit-impl.h"
#include "editwidget.h"
@ -537,7 +536,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
end_col--;
}
edit_get_syntax_color (edit, b - 1, &color);
color = edit_get_syntax_color (edit, b - 1);
q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
@ -621,7 +620,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
}
else
{
edit_get_syntax_color (edit, q, &color);
color = edit_get_syntax_color (edit, q);
p->style |= color << 16;
}
switch (c)

View File

@ -56,7 +56,7 @@
#include "lib/event.h" /* mc_event_raise() */
#include "src/keybind-defaults.h"
#include "src/main.h" /* home_dir */
#include "src/setup.h" /* home_dir */
#include "src/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */
#include "src/learn.h" /* learn_keys() */
#include "src/args.h" /* mcedit_arg_t */

View File

@ -28,18 +28,20 @@ typedef enum
/*** structures declarations (and typedefs of structures)*****************************************/
struct _book_mark
typedef struct edit_book_mark_t edit_book_mark_t;
struct edit_book_mark_t
{
long line; /* line number */
int c; /* color */
struct _book_mark *next;
struct _book_mark *prev;
edit_book_mark_t *next;
edit_book_mark_t *prev;
};
struct syntax_rule
typedef struct edit_syntax_rule_t edit_syntax_rule_t;
struct edit_syntax_rule_t
{
unsigned short keyword;
unsigned char end;
off_t end;
unsigned char context;
unsigned char _context;
unsigned char border;
@ -132,7 +134,7 @@ struct WEdit
long line_numbers[N_LINE_CACHES];
off_t line_offsets[N_LINE_CACHES];
struct _book_mark *book_mark;
edit_book_mark_t *book_mark;
GArray *serialized_bookmarks;
/* undo stack and pointers */
@ -154,10 +156,10 @@ struct WEdit
unsigned int skip_detach_prompt:1; /* Do not prompt whether to detach a file anymore */
/* syntax higlighting */
struct _syntax_marker *syntax_marker;
GSList *syntax_marker;
struct context_rule **rules;
long last_get_rule;
struct syntax_rule rule;
off_t last_get_rule;
edit_syntax_rule_t rule;
char *syntax_type; /* description of syntax highlighting type being used */
GTree *defines; /* List of defines */
gboolean is_case_insensitive; /* selects language case sensitivity */

View File

@ -102,7 +102,7 @@ struct key_word
unsigned char first;
char *whole_word_chars_left;
char *whole_word_chars_right;
int line_start;
long line_start;
int color;
};
@ -118,17 +118,16 @@ struct context_rule
char *whole_word_chars_left;
char *whole_word_chars_right;
char *keyword_first_chars;
int spelling;
gboolean spelling;
/* first word is word[1] */
struct key_word **keyword;
};
struct _syntax_marker
typedef struct
{
long offset;
struct syntax_rule rule;
struct _syntax_marker *next;
};
off_t offset;
edit_syntax_rule_t rule;
} syntax_marker_t;
/*** file scope variables ************************************************************************/
@ -167,7 +166,7 @@ destroy_defines (GTree ** defines)
/** Wrapper for case insensitive mode */
inline static int
xx_tolower (WEdit * edit, int c)
xx_tolower (const WEdit * edit, int c)
{
return edit->is_case_insensitive ? tolower (c) : c;
}
@ -215,9 +214,9 @@ subst_defines (GTree * defines, char **argv, char **argv_end)
/* --------------------------------------------------------------------------------------------- */
static long
compare_word_to_right (WEdit * edit, long i, const char *text,
const char *whole_left, const char *whole_right, int line_start)
static off_t
compare_word_to_right (const WEdit * edit, off_t i, const char *text,
const char *whole_left, const char *whole_right, long line_start)
{
const unsigned char *p, *q;
int c, d, j;
@ -226,9 +225,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
return -1;
c = xx_tolower (edit, edit_get_byte (edit, i - 1));
if (line_start != 0 && c != '\n')
return -1;
if (whole_left != NULL && strchr (whole_left, c) != NULL)
if ((line_start != 0 && c != '\n') || (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++)
@ -238,7 +235,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
case SYNTAX_TOKEN_STAR:
if (++p > q)
return -1;
for (;;)
while (TRUE)
{
c = xx_tolower (edit, edit_get_byte (edit, i));
if (*p == '\0' && whole_right != NULL && strchr (whole_right, c) == NULL)
@ -254,7 +251,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
if (++p > q)
return -1;
j = 0;
for (;;)
while (TRUE)
{
c = xx_tolower (edit, edit_get_byte (edit, i));
if (c == *p)
@ -263,21 +260,10 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
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 */
if (j != 0 && strchr ((char *) p + 1, c) != NULL) /* c exists further down, so it will get matched later */
break;
if (c == '\n' || c == '\t' || c == ' ')
{
if (!*p)
{
i--;
break;
}
if (j == 0)
return -1;
i = j;
break;
}
if (whole_right != NULL && (strchr (whole_right, c) == NULL))
if (c == '\n' || c == '\t' || c == ' ' ||
(whole_right != NULL && strchr (whole_right, c) == NULL))
{
if (*p == '\0')
{
@ -296,7 +282,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
if (++p > q)
return -1;
c = -1;
for (;; i++)
while (TRUE)
{
d = c;
c = xx_tolower (edit, edit_get_byte (edit, i));
@ -305,7 +291,7 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
goto found_char2;
break;
found_char2:
; /* dummy command */
i++;
}
i--;
while (*p != SYNTAX_TOKEN_BRACKET && p <= q)
@ -332,16 +318,14 @@ compare_word_to_right (WEdit * edit, long i, const char *text,
return -1;
}
}
if (whole_right != NULL
&& strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL)
return -1;
return i;
return (whole_right != NULL &&
strchr (whole_right, xx_tolower (edit, edit_get_byte (edit, i))) != NULL) ? -1 : i;
}
/* --------------------------------------------------------------------------------------------- */
static const char *
xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
xx_strchr (const WEdit * edit, const unsigned char *s, int char_byte)
{
while (*s >= '\005' && xx_tolower (edit, *s) != char_byte)
s++;
@ -351,8 +335,8 @@ xx_strchr (WEdit * edit, const unsigned char *s, int char_byte)
/* --------------------------------------------------------------------------------------------- */
static struct syntax_rule
apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
static edit_syntax_rule_t
apply_rules_going_right (WEdit * edit, off_t i, edit_syntax_rule_t rule)
{
struct context_rule *r;
int c;
@ -360,13 +344,13 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
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;
off_t end = 0;
edit_syntax_rule_t _rule = rule;
c = xx_tolower (edit, edit_get_byte (edit, i));
if (c == 0)
return rule;
is_end = (rule.end == (unsigned char) i);
is_end = (rule.end == i);
/* check to turn off a keyword */
if (_rule.keyword)
@ -383,7 +367,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
/* check to turn off a context */
if (_rule.context && !_rule.keyword)
{
long e;
off_t e;
r = edit->rules[_rule.context];
if (r->first_right == c && !(rule.border & RULE_ON_RIGHT_BORDER)
@ -426,7 +410,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
struct key_word *k;
int count;
long e;
off_t e;
count = p - r->keyword_first_chars;
k = r->keyword[count];
@ -468,7 +452,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
if (r->first_right == c)
{
long e;
off_t e;
e = compare_word_to_right (edit, i, r->right, r->whole_word_chars_left,
r->whole_word_chars_right, r->line_start_right);
@ -494,7 +478,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
r = rules[count];
if (r->first_left == c)
{
long e;
off_t e;
e = compare_word_to_right (edit, i, r->left, r->whole_word_chars_left,
r->whole_word_chars_right, r->line_start_left);
@ -528,7 +512,7 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
{
struct key_word *k;
int count;
long e;
off_t e;
count = p - r->keyword_first_chars;
k = r->keyword[count];
@ -548,53 +532,59 @@ apply_rules_going_right (WEdit * edit, long i, struct syntax_rule rule)
/* --------------------------------------------------------------------------------------------- */
static struct syntax_rule
static edit_syntax_rule_t
edit_get_rule (WEdit * edit, off_t byte_index)
{
long i;
off_t i;
if (byte_index > edit->last_get_rule)
{
for (i = edit->last_get_rule + 1; i <= byte_index; i++)
{
edit->rule = apply_rules_going_right (edit, i, edit->rule);
if (i >
(edit->syntax_marker ? edit->syntax_marker->offset +
SYNTAX_MARKER_DENSITY : SYNTAX_MARKER_DENSITY))
{
struct _syntax_marker *s;
off_t d = SYNTAX_MARKER_DENSITY;
s = edit->syntax_marker;
edit->syntax_marker = g_malloc (sizeof (struct _syntax_marker));
edit->syntax_marker->next = s;
edit->syntax_marker->offset = i;
edit->syntax_marker->rule = edit->rule;
edit->rule = apply_rules_going_right (edit, i, edit->rule);
if (edit->syntax_marker != NULL)
d += ((syntax_marker_t *) edit->syntax_marker->data)->offset;
if (i > d)
{
syntax_marker_t *s;
s = g_new (syntax_marker_t, 1);
s->offset = i;
s->rule = edit->rule;
edit->syntax_marker = g_slist_prepend (edit->syntax_marker, s);
}
}
}
else if (byte_index < edit->last_get_rule)
{
struct _syntax_marker *s;
for (;;)
while (TRUE)
{
if (!edit->syntax_marker)
syntax_marker_t *s;
if (edit->syntax_marker == NULL)
{
memset (&edit->rule, 0, sizeof (edit->rule));
for (i = -1; i <= byte_index; i++)
edit->rule = apply_rules_going_right (edit, i, edit->rule);
break;
}
if (byte_index >= edit->syntax_marker->offset)
s = (syntax_marker_t *) edit->syntax_marker->data;
if (byte_index >= s->offset)
{
edit->rule = edit->syntax_marker->rule;
for (i = edit->syntax_marker->offset + 1; i <= byte_index; i++)
edit->rule = s->rule;
for (i = s->offset + 1; i <= byte_index; i++)
edit->rule = apply_rules_going_right (edit, i, edit->rule);
break;
}
s = edit->syntax_marker->next;
g_free (edit->syntax_marker);
edit->syntax_marker = s;
g_free (s);
edit->syntax_marker = g_slist_delete_link (edit->syntax_marker, edit->syntax_marker);
}
}
edit->last_get_rule = byte_index;
@ -603,13 +593,12 @@ edit_get_rule (WEdit * edit, off_t byte_index)
/* --------------------------------------------------------------------------------------------- */
static inline void
translate_rule_to_color (WEdit * edit, struct syntax_rule rule, int *color)
static inline int
translate_rule_to_color (const WEdit * edit, edit_syntax_rule_t rule)
{
*color = edit->rules[rule.context]->keyword[rule.keyword]->color;
return edit->rules[rule.context]->keyword[rule.keyword]->color;
}
/* --------------------------------------------------------------------------------------------- */
/**
Returns 0 on error/eof or a count of the number of bytes read
@ -626,7 +615,7 @@ read_one_line (char **line, FILE * f)
/* not reallocate string too often */
p = g_string_sized_new (64);
for (;;)
while (TRUE)
{
int c;
@ -917,7 +906,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (!edit->defines)
edit->defines = g_tree_new ((GCompareFunc) strcmp);
for (;;)
while (TRUE)
{
char **a;
size_t len;
@ -926,47 +915,41 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
l = 0;
len = read_one_line (&l, f);
if (len == 0)
{
if (g)
{
fclose (f);
f = g;
g = 0;
line = save_line + 1;
MC_PTR_FREE (error_file_name);
MC_PTR_FREE (l);
len = read_one_line (&l, f);
if (len == 0)
break;
else
xx_lowerize_line (edit, l, len);
}
else
{
break;
}
}
if (len != 0)
xx_lowerize_line (edit, l, len);
else
{
if (g == NULL)
break;
fclose (f);
f = g;
g = NULL;
line = save_line + 1;
MC_PTR_FREE (error_file_name);
MC_PTR_FREE (l);
len = read_one_line (&l, f);
if (len == 0)
break;
xx_lowerize_line (edit, l, len);
}
argc = get_args (l, args, args_size);
a = args + 1;
if (!args[0])
if (args[0] == NULL)
{
/* do nothing */
}
else if (!strcmp (args[0], "include"))
else if (strcmp (args[0], "include") == 0)
{
if (g || argc != 2)
if (g != NULL || argc != 2)
{
result = line;
break;
}
g = f;
f = open_include_file (args[1]);
if (!f)
if (f == NULL)
{
MC_PTR_FREE (error_file_name);
result = line;
@ -975,19 +958,19 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
save_line = line;
line = 0;
}
else if (!strcmp (args[0], "caseinsensitive"))
else if (strcmp (args[0], "caseinsensitive") == 0)
{
edit->is_case_insensitive = TRUE;
}
else if (!strcmp (args[0], "wholechars"))
else if (strcmp (args[0], "wholechars") == 0)
{
check_a;
if (!strcmp (*a, "left"))
if (strcmp (*a, "left") == 0)
{
a++;
g_strlcpy (whole_left, *a, sizeof (whole_left));
}
else if (!strcmp (*a, "right"))
else if (strcmp (*a, "right") == 0)
{
a++;
g_strlcpy (whole_right, *a, sizeof (whole_right));
@ -1000,12 +983,12 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
a++;
check_not_a;
}
else if (!strcmp (args[0], "context"))
else if (strcmp (args[0], "context") == 0)
{
check_a;
if (num_contexts == -1)
{
if (strcmp (*a, "default"))
if (strcmp (*a, "default") != 0)
{ /* first context is the default */
break_a;
}
@ -1020,30 +1003,30 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
/* Terminate previous context. */
r[num_contexts - 1]->keyword[num_words] = NULL;
c = r[num_contexts] = g_malloc0 (sizeof (struct context_rule));
if (!strcmp (*a, "exclusive"))
if (strcmp (*a, "exclusive") == 0)
{
a++;
c->between_delimiters = 1;
}
check_a;
if (!strcmp (*a, "whole"))
if (strcmp (*a, "whole") == 0)
{
a++;
c->whole_word_chars_left = g_strdup (whole_left);
c->whole_word_chars_right = g_strdup (whole_right);
}
else if (!strcmp (*a, "wholeleft"))
else if (strcmp (*a, "wholeleft") == 0)
{
a++;
c->whole_word_chars_left = g_strdup (whole_left);
}
else if (!strcmp (*a, "wholeright"))
else if (strcmp (*a, "wholeright") == 0)
{
a++;
c->whole_word_chars_right = g_strdup (whole_right);
}
check_a;
if (!strcmp (*a, "linestart"))
if (strcmp (*a, "linestart") == 0)
{
a++;
c->line_start_left = 1;
@ -1051,7 +1034,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
check_a;
c->left = g_strdup (*a++);
check_a;
if (!strcmp (*a, "linestart"))
if (strcmp (*a, "linestart") == 0)
{
a++;
c->line_start_right = 1;
@ -1066,17 +1049,17 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
c->keyword[0] = g_malloc0 (sizeof (struct key_word));
subst_defines (edit->defines, a, &args[1024]);
fg = *a;
if (*a)
if (*a != '\0')
a++;
bg = *a;
if (*a)
if (*a != '\0')
a++;
attrs = *a;
if (*a)
if (*a != '\0')
a++;
g_strlcpy (last_fg, fg ? fg : "", sizeof (last_fg));
g_strlcpy (last_bg, bg ? bg : "", sizeof (last_bg));
g_strlcpy (last_attrs, attrs ? attrs : "", sizeof (last_attrs));
g_strlcpy (last_fg, fg != NULL ? fg : "", sizeof (last_fg));
g_strlcpy (last_bg, bg != NULL ? bg : "", sizeof (last_bg));
g_strlcpy (last_attrs, attrs != NULL ? attrs : "", sizeof (last_attrs));
c->keyword[0]->color = this_try_alloc_color_pair (fg, bg, attrs);
c->keyword[0]->keyword = g_strdup (" ");
check_not_a;
@ -1091,16 +1074,16 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
r = tmp;
}
}
else if (!strcmp (args[0], "spellcheck"))
else if (strcmp (args[0], "spellcheck") == 0)
{
if (!c)
if (c == NULL)
{
result = line;
break;
}
c->spelling = 1;
c->spelling = TRUE;
}
else if (!strcmp (args[0], "keyword"))
else if (strcmp (args[0], "keyword") == 0)
{
struct key_word *k;
@ -1108,30 +1091,30 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
break_a;
check_a;
k = r[num_contexts - 1]->keyword[num_words] = g_malloc0 (sizeof (struct key_word));
if (!strcmp (*a, "whole"))
if (strcmp (*a, "whole") == 0)
{
a++;
k->whole_word_chars_left = g_strdup (whole_left);
k->whole_word_chars_right = g_strdup (whole_right);
}
else if (!strcmp (*a, "wholeleft"))
else if (strcmp (*a, "wholeleft") == 0)
{
a++;
k->whole_word_chars_left = g_strdup (whole_left);
}
else if (!strcmp (*a, "wholeright"))
else if (strcmp (*a, "wholeright") == 0)
{
a++;
k->whole_word_chars_right = g_strdup (whole_right);
}
check_a;
if (!strcmp (*a, "linestart"))
if (strcmp (*a, "linestart") == 0)
{
a++;
k->line_start = 1;
}
check_a;
if (!strcmp (*a, "whole"))
if (strcmp (*a, "whole") == 0)
{
break_a;
}
@ -1139,19 +1122,19 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
k->first = *k->keyword;
subst_defines (edit->defines, a, &args[1024]);
fg = *a;
if (*a)
if (*a != '\0')
a++;
bg = *a;
if (*a)
if (*a != '\0')
a++;
attrs = *a;
if (*a)
if (*a != '\0')
a++;
if (!fg)
if (fg == NULL)
fg = last_fg;
if (!bg)
if (bg == NULL)
bg = last_bg;
if (!attrs)
if (attrs == NULL)
attrs = last_attrs;
k->color = this_try_alloc_color_pair (fg, bg, attrs);
check_not_a;
@ -1173,11 +1156,11 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
{
/* do nothing for comment */
}
else if (!strcmp (args[0], "file"))
else if (strcmp (args[0], "file") == 0)
{
break;
}
else if (!strcmp (args[0], "define"))
else if (strcmp (args[0], "define") == 0)
{
char *key = *a++;
char **argv;
@ -1193,9 +1176,7 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
argv = g_new (char *, argc - 1);
g_tree_insert (edit->defines, key, argv);
while (*a != NULL)
{
*argv++ = g_strdup (*a++);
}
*argv = NULL;
}
else
@ -1215,28 +1196,24 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
r[num_contexts] = NULL;
}
if (!edit->rules[0])
if (edit->rules[0] == NULL)
MC_PTR_FREE (edit->rules);
if (result)
return result;
if (num_contexts == -1)
{
return line;
}
if (result == 0)
{
char *first_chars, *p;
if (num_contexts == -1)
return line;
first_chars = g_malloc0 (max_alloc_words_per_context + 2);
for (i = 0; edit->rules[i]; i++)
for (i = 0; edit->rules[i] != NULL; i++)
{
c = edit->rules[i];
p = first_chars;
*p++ = (char) 1;
for (j = 1; c->keyword[j]; j++)
for (j = 1; c->keyword[j] != NULL; j++)
*p++ = c->keyword[j]->first;
*p = '\0';
c->keyword_first_chars = g_strdup (first_chars);
@ -1276,7 +1253,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
}
args[0] = NULL;
for (;;)
while (TRUE)
{
line++;
MC_PTR_FREE (l);
@ -1387,26 +1364,30 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file,
/* --------------------------------------------------------------------------------------------- */
static char *
static const char *
get_first_editor_line (WEdit * edit)
{
size_t i;
static char s[256];
s[0] = '\0';
if (edit == NULL)
return s;
for (i = 0; i < sizeof (s) - 1; i++)
if (edit != NULL)
{
s[i] = edit_get_byte (edit, i);
if (s[i] == '\n')
size_t i;
for (i = 0; i < sizeof (s) - 1; i++)
{
s[i] = '\0';
break;
s[i] = edit_get_byte (edit, i);
if (s[i] == '\n')
{
s[i] = '\0';
break;
}
}
s[sizeof (s) - 1] = '\0';
}
s[sizeof (s) - 1] = '\0';
return s;
}
@ -1414,15 +1395,16 @@ get_first_editor_line (WEdit * edit)
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
void
edit_get_syntax_color (WEdit * edit, off_t byte_index, int *color)
int
edit_get_syntax_color (WEdit * edit, off_t byte_index)
{
if (!tty_use_colors ())
*color = 0;
else if (edit->rules && byte_index < edit->last_byte && option_syntax_highlighting)
translate_rule_to_color (edit, edit_get_rule (edit, byte_index), color);
else
*color = EDITOR_NORMAL_COLOR;
return 0;
if (edit->rules != NULL && byte_index < edit->last_byte && option_syntax_highlighting)
return translate_rule_to_color (edit, edit_get_rule (edit, byte_index));
return EDITOR_NORMAL_COLOR;
}
/* --------------------------------------------------------------------------------------------- */
@ -1463,13 +1445,9 @@ edit_free_syntax_rules (WEdit * edit)
MC_PTR_FREE (edit->rules[i]);
}
while (edit->syntax_marker)
{
struct _syntax_marker *s = edit->syntax_marker->next;
g_free (edit->syntax_marker);
edit->syntax_marker = s;
}
g_slist_foreach (edit->syntax_marker, (GFunc) g_free, NULL);
g_slist_free (edit->syntax_marker);
edit->syntax_marker = NULL;
MC_PTR_FREE (edit->rules);
tty_color_free_all_tmp ();
}

View File

@ -126,7 +126,7 @@ begin_paragraph (WEdit * edit, int force)
long i;
for (i = edit->curs_line - 1; i >= 0; i--)
{
if (line_is_blank (edit, i))
if (edit_line_is_blank (edit, i))
{
i++;
break;
@ -155,7 +155,7 @@ end_paragraph (WEdit * edit, int force)
long i;
for (i = edit->curs_line + 1; i <= edit->total_lines; i++)
{
if (line_is_blank (edit, i))
if (edit_line_is_blank (edit, i))
{
i--;
break;
@ -230,7 +230,8 @@ static inline int
line_pixel_length (unsigned char *t, long b, int l)
{
int x = 0, c, xn = 0;
for (;;)
while (TRUE)
{
c = t[b];
switch (c)
@ -286,12 +287,15 @@ static inline int
word_start (unsigned char *t, int q, int size)
{
int i = q;
if (t[q] == ' ' || t[q] == '\t')
return next_word_start (t, q, size);
for (;;)
while (TRUE)
{
int c;
if (!i)
if (i == 0)
return -1;
c = t[i - 1];
if (c == '\n')
@ -309,13 +313,15 @@ static inline void
format_this (unsigned char *t, int size, int indent)
{
int q = 0, ww;
strip_newlines (t, size);
ww = option_word_wrap_line_length * FONT_MEAN_WIDTH - indent;
if (ww < FONT_MEAN_WIDTH * 2)
ww = FONT_MEAN_WIDTH * 2;
for (;;)
while (TRUE)
{
int p;
q = line_pixel_length (t, q, ww);
if (q > size)
break;
@ -330,7 +336,7 @@ format_this (unsigned char *t, int size, int indent)
q = p;
if (q == -1) /* end of paragraph */
break;
if (q)
if (q != 0)
t[q - 1] = '\n';
}
}
@ -341,7 +347,7 @@ static inline void
replace_at (WEdit * edit, long q, int c)
{
edit_cursor_move (edit, q - edit->curs1);
edit_delete (edit, 1);
edit_delete (edit, TRUE);
edit_insert_ahead (edit, c);
}
@ -353,6 +359,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
{
long cursor;
int i, c = 0;
cursor = edit->curs1;
if (indent)
while (strchr ("\t ", edit_get_byte (edit, p)))
@ -381,7 +388,7 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
edit_cursor_move (edit, p - edit->curs1);
while (strchr ("\t ", edit_get_byte (edit, p)))
{
edit_delete (edit, 1);
edit_delete (edit, TRUE);
if (cursor > edit->curs1)
cursor--;
}
@ -398,12 +405,14 @@ put_paragraph (WEdit * edit, unsigned char *t, off_t p, int indent, int size)
/* --------------------------------------------------------------------------------------------- */
static inline int
test_indent (WEdit * edit, off_t p, off_t q)
test_indent (const WEdit * edit, off_t p, off_t q)
{
int indent;
indent = edit_indent_width (edit, p++);
if (!indent)
if (indent == 0)
return 0;
for (; p < q; p++)
if (edit_get_byte (edit, p - 1) == '\n')
if (indent != edit_indent_width (edit, p))
@ -424,7 +433,7 @@ format_paragraph (WEdit * edit, int force)
int indent = 0;
if (option_word_wrap_line_length < 2)
return;
if (line_is_blank (edit, edit->curs_line))
if (edit_line_is_blank (edit, edit->curs_line))
return;
p = begin_paragraph (edit, force);
q = end_paragraph (edit, force);

View File

@ -43,7 +43,9 @@
#include "filemanager/midnight.h"
#include "filemanager/layout.h" /* use_dash() */
#include "consaver/cons.saver.h"
#ifdef ENABLE_SUBSHELL
#include "subshell.h"
#endif
#include "setup.h" /* clear_before_exec */
#include "execute.h"
@ -111,7 +113,7 @@ edition_pre_exec (void)
/* --------------------------------------------------------------------------------------------- */
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
static void
do_possible_cd (const vfs_path_t * new_dir_vpath)
{
@ -122,16 +124,16 @@ do_possible_cd (const vfs_path_t * new_dir_vpath)
"deleted your working directory, or given yourself\n"
"extra access permissions with the \"su\" command?"));
}
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
/* --------------------------------------------------------------------------------------------- */
static void
do_execute (const char *lc_shell, const char *command, int flags)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
vfs_path_t *new_dir_vpath = NULL;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
vfs_path_t *old_vfs_dir_vpath = NULL;
@ -149,7 +151,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
printf ("%s%s\n", mc_prompt, command);
fflush (stdout);
}
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell && !(flags & EXECUTE_INTERNAL))
{
do_update_prompt ();
@ -158,7 +160,7 @@ do_execute (const char *lc_shell, const char *command, int flags)
invoke_subshell (command, VISIBLY, old_vfs_dir_vpath != NULL ? NULL : &new_dir_vpath);
}
else
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
my_system (flags, lc_shell, command);
if (!(flags & EXECUTE_INTERNAL))
@ -166,9 +168,9 @@ do_execute (const char *lc_shell, const char *command, int flags)
if ((pause_after_run == pause_always
|| (pause_after_run == pause_on_dumb_terminals && !mc_global.tty.xterm_flag
&& mc_global.tty.console_flag == '\0')) && quit == 0
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
&& subshell_state != RUNNING_COMMAND
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
)
{
printf (_("Press any key to continue..."));
@ -192,14 +194,14 @@ do_execute (const char *lc_shell, const char *command, int flags)
handle_console (CONSOLE_SAVE);
edition_post_exec ();
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (new_dir_vpath != NULL)
{
do_possible_cd (new_dir_vpath);
vfs_path_free (new_dir_vpath);
}
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
if (old_vfs_dir_vpath != NULL)
{
@ -286,14 +288,14 @@ shell_execute (const char *command, int flags)
flags ^= EXECUTE_HIDE;
}
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
if (subshell_state == INACTIVE)
do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL);
else
message (D_ERROR, MSG_ERROR, _("The shell is already running a command"));
else
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL);
g_free (cmd);
@ -312,10 +314,10 @@ exec_shell (void)
void
toggle_panels (void)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
vfs_path_t *new_dir_vpath = NULL;
vfs_path_t **new_dir_p;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
channels_down ();
disable_mouse ();
@ -337,14 +339,14 @@ toggle_panels (void)
if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_RESTORE);
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
{
new_dir_p = vfs_current_is_local ()? &new_dir_vpath : NULL;
invoke_subshell (NULL, VISIBLY, new_dir_p);
}
else
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
{
if (output_starts_shell)
{
@ -374,11 +376,11 @@ toggle_panels (void)
return;
quit = 0;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/* restart subshell */
if (mc_global.tty.use_subshell)
init_subshell ();
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
}
enable_mouse ();
@ -386,7 +388,7 @@ toggle_panels (void)
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
{
do_load_prompt ();
@ -399,7 +401,7 @@ toggle_panels (void)
}
vfs_path_free (new_dir_vpath);
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
if (mc_global.mc_run_mode == MC_RUN_FULL)
{

View File

@ -18,8 +18,8 @@ libmcfilemanager_la_SOURCES = \
hotlist.c hotlist.h \
info.c info.h \
layout.c layout.h \
listmode.c listmode.h \
midnight.h midnight.c \
mountlist.c mountlist.h \
option.c option.h \
panelize.c panelize.h \
panel.c panel.h \
@ -27,9 +27,8 @@ libmcfilemanager_la_SOURCES = \
treestore.c treestore.h \
usermenu.c usermenu.h
#if USE_MOUNTLIST
libmcfilemanager_la_SOURCES += mountlist.c mountlist.h
#endif
# Unmaintained, unsupported, etc
# listmode.c listmode.h
AM_CFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(PCRE_CFLAGS)

View File

@ -42,8 +42,10 @@
#include "lib/util.h"
#include "lib/widget.h"
#include "src/main.h" /* do_cd */
#include "src/subshell.h" /* SUBSHELL_EXIT */
#include "src/setup.h" /* quit */
#ifdef ENABLE_SUBSHELL
#include "src/subshell.h"
#endif
#include "src/execute.h" /* shell_execute */
#include "midnight.h" /* current_panel */
@ -264,7 +266,7 @@ enter (WInput * lc_cmdline)
message (D_ERROR, MSG_ERROR, _("Cannot execute commands on non-local filesystems"));
return MSG_NOT_HANDLED;
}
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/* Check this early before we clean command line
* (will be checked again by shell_execute) */
if (mc_global.tty.use_subshell && subshell_state != INACTIVE)
@ -298,7 +300,7 @@ enter (WInput * lc_cmdline)
shell_execute (command, 0);
g_free (command);
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if ((quit & SUBSHELL_EXIT) != 0)
{
if (quiet_quit_cmd ())

View File

@ -53,7 +53,6 @@
#include "src/setup.h" /* use_file_to_check_type */
#include "src/execute.h"
#include "src/history.h"
#include "src/main.h" /* do_cd */
#include "src/consaver/cons.saver.h"
#include "src/viewer/mcviewer.h"
@ -62,6 +61,7 @@
#include "src/selcodepage.h" /* do_set_codepage */
#endif
#include "panel.h" /* do_cd */
#include "usermenu.h"
#include "ext.h"

View File

@ -51,7 +51,6 @@
#include "src/setup.h" /* verbose */
#include "src/history.h" /* MC_HISTORY_SHARED_SEARCH */
#include "src/main.h" /* do_cd */
#include "dir.h"
#include "cmd.h" /* view_file_at_line */
@ -894,7 +893,7 @@ get_line_at (int file_fd, char *buf, int buf_size, int *pos, int *n_read, gboole
char ch = 0;
int i = 0;
for (;;)
while (TRUE)
{
if (*pos >= *n_read)
{

View File

@ -31,6 +31,7 @@
#include <config.h>
#include <pwd.h> /* for username in xterm title */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -51,8 +52,7 @@
#include "src/consaver/cons.saver.h"
#include "src/viewer/mcviewer.h" /* The view widget */
#include "src/setup.h"
#ifdef HAVE_SUBSHELL_SUPPORT
#include "src/main.h" /* do_load_prompt() */
#ifdef ENABLE_SUBSHELL
#include "src/subshell.h"
#endif
@ -718,7 +718,7 @@ setup_panels (void)
if (command_prompt)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (!mc_global.tty.use_subshell || !do_load_prompt ())
#endif
setup_cmdline ();
@ -812,7 +812,7 @@ setup_cmdline (void)
int y;
char *tmp_prompt = NULL;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
tmp_prompt = strip_ctrl_codes (subshell_prompt);
if (tmp_prompt == NULL)
@ -1287,3 +1287,96 @@ get_panel_dir_for (const WPanel * widget)
}
/* --------------------------------------------------------------------------------------------- */
#ifdef ENABLE_SUBSHELL
gboolean
do_load_prompt (void)
{
gboolean ret = FALSE;
if (!read_subshell_prompt ())
return ret;
/* Don't actually change the prompt if it's invisible */
if (top_dlg != NULL && ((Dlg_head *) top_dlg->data == midnight_dlg) && command_prompt)
{
setup_cmdline ();
/* since the prompt has changed, and we are called from one of the
* tty_get_event channels, the prompt updating does not take place
* automatically: force a cursor update and a screen refresh
*/
update_cursor (midnight_dlg);
mc_refresh ();
ret = TRUE;
}
update_subshell_prompt = TRUE;
return ret;
}
/* --------------------------------------------------------------------------------------------- */
int
load_prompt (int fd, void *unused)
{
(void) fd;
(void) unused;
do_load_prompt ();
return 0;
}
#endif /* ENABLE_SUBSHELL */
/* --------------------------------------------------------------------------------------------- */
void
title_path_prepare (char **path, char **login)
{
char host[BUF_TINY];
struct passwd *pw = NULL;
int res = 0;
*path =
vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
res = gethostname (host, sizeof (host));
if (res != 0)
host[0] = '\0';
else
host[sizeof (host) - 1] = '\0';
pw = getpwuid (getuid ());
if (pw != NULL)
*login = g_strdup_printf ("%s@%s", pw->pw_name, host);
else
*login = g_strdup (host);
}
/* --------------------------------------------------------------------------------------------- */
/** Show current directory in the xterm title */
void
update_xterm_title_path (void)
{
if (mc_global.tty.xterm_flag && xterm_title)
{
char *p;
char *path;
char *login;
title_path_prepare (&path, &login);
p = g_strdup_printf ("mc [%s]:%s", login, path);
g_free (login);
g_free (path);
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
g_free (p);
if (!mc_global.tty.alternate_plus_minus)
numeric_keypad_mode ();
(void) fflush (stdout);
}
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -81,6 +81,15 @@ void set_hintbar (const char *str);
void use_dash (gboolean flag); /* Disable/Enable rotate_dash routines */
void rotate_dash (void);
#ifdef ENABLE_SUBSHELL
gboolean do_load_prompt (void);
int load_prompt (int fd, void *unused);
#endif
void update_xterm_title_path (void);
void title_path_prepare (char **path, char **login);
/*** inline functions ****************************************************************************/
#endif /* MC__LAYOUT_H */

View File

@ -55,7 +55,9 @@
#include "lib/vfs/vfs.h"
#include "src/args.h"
#ifdef ENABLE_SUBSHELL
#include "src/subshell.h"
#endif
#include "src/setup.h" /* variables */
#include "src/learn.h" /* learn_keys() */
#include "src/keybind-defaults.h"
@ -872,10 +874,10 @@ setup_mc (void)
#endif /* HAVE_CHARSET */
#endif /* HAVE_SLANG */
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0);
#endif /* !HAVE_SUBSHELL_SUPPORT */
#endif /* !ENABLE_SUBSHELL */
if ((tty_baudrate () < 9600) || mc_global.tty.slow_terminal)
verbose = 0;
@ -1049,7 +1051,7 @@ quit_cmd_internal (int quiet)
if (q != 0)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (!mc_global.tty.use_subshell)
stop_dialogs ();
else if ((q = exit_subshell ()))

View File

@ -1269,9 +1269,11 @@ safe_read (int fd, void *buf, size_t count)
enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };
/* *INDENT-ON* */
for (;;)
while (TRUE)
{
ssize_t result = read (fd, buf, count);
ssize_t result;
result = read (fd, buf, count);
if (0 <= result)
return result;

View File

@ -62,7 +62,9 @@
#include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */
#endif
#include "src/keybind-defaults.h" /* global_keymap_t */
#ifdef ENABLE_SUBSHELL
#include "src/subshell.h" /* do_subshell_chdir() */
#endif
#include "dir.h"
#include "boxes.h"
@ -3012,12 +3014,12 @@ get_parent_dir_name (const char *cwd, const char *lwd)
static void
subshell_chdir (const vfs_path_t * vpath)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell && vfs_current_is_local ())
do_subshell_chdir (vpath, FALSE, TRUE);
#else /* HAVE_SUBSHELL_SUPPORT */
#else /* ENABLE_SUBSHELL */
(void) vpath;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
}
/* --------------------------------------------------------------------------------------------- */
@ -4788,3 +4790,38 @@ panel_deinit (void)
}
/* --------------------------------------------------------------------------------------------- */
gboolean
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum exact)
{
gboolean res;
const vfs_path_t *_new_dir_vpath = new_dir_vpath;
if (current_panel->is_panelized)
{
size_t new_vpath_len;
new_vpath_len = vfs_path_len (new_dir_vpath);
if (vfs_path_ncmp (new_dir_vpath, panelized_panel.root_vpath, new_vpath_len) == 0)
_new_dir_vpath = panelized_panel.root_vpath;
}
res = do_panel_cd (current_panel, _new_dir_vpath, exact);
#ifdef HAVE_CHARSET
if (res)
{
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (current_panel->cwd_vpath, -1);
if (path_element->encoding != NULL)
current_panel->codepage = get_codepage_index (path_element->encoding);
else
current_panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
}
#endif /* HAVE_CHARSET */
return res;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -12,8 +12,6 @@
#include "lib/strutil.h"
#include "lib/widget.h" /* Widget */
#include "src/main.h" /* cd_enum */
#include "dir.h" /* dir_list */
/*** typedefs(not structures) and defined constants **********************************************/
@ -48,6 +46,14 @@ typedef enum
UP_ONLY_CURRENT = 2
} panel_update_flags_t;
/* run mode and params */
enum cd_enum
{
cd_parse_command,
cd_exact
};
/*** structures declarations (and typedefs of structures)*****************************************/
struct format_e;
@ -182,6 +188,7 @@ void panel_set_lwd (WPanel * panel, const char *path_str);
void panel_init (void);
void panel_deinit (void);
gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
/*** inline functions ****************************************************************************/
#endif /* MC__PANEL_H */

View File

@ -69,7 +69,6 @@
#include "keybind-defaults.h"
#include "keybind-defaults.h"
#include "help.h"
#include "main.h"
/*** global variables ****************************************************************************/

View File

@ -35,11 +35,11 @@
#include <ctype.h>
#include <errno.h>
#include <locale.h>
#include <pwd.h> /* for username in xterm title */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <pwd.h> /* for username in xterm title */
#include <signal.h>
#include "lib/global.h"
@ -65,7 +65,9 @@
#include "events_init.h"
#include "args.h"
#ifdef ENABLE_SUBSHELL
#include "subshell.h"
#endif
#include "setup.h" /* load_setup() */
#ifdef HAVE_CHARSET
@ -75,50 +77,8 @@
#include "consaver/cons.saver.h" /* cons_saver_pid */
#include "main.h"
/*** global variables ****************************************************************************/
mc_fhl_t *mc_filehighlight;
/* Set when main loop should be terminated */
int quit = 0;
#ifdef HAVE_CHARSET
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
int default_source_codepage = -1;
char *autodetect_codeset = NULL;
gboolean is_autodetect_codeset_enabled = FALSE;
#endif /* !HAVE_CHARSET */
/* If true use the internal viewer */
int use_internal_view = 1;
/* If set, use the builtin editor */
int use_internal_edit = 1;
void *mc_run_param0 = NULL;
char *mc_run_param1 = NULL;
/* The user's shell */
char *shell = NULL;
/* The prompt */
const char *mc_prompt = NULL;
/* Set to TRUE to suppress printing the last directory */
int print_last_revert = FALSE;
/* If set, then print to the given file the last directory we were at */
char *last_wd_string = NULL;
/* index to record_macro_buf[], -1 if not recording a macro */
int macro_index = -1;
/* macro stuff */
struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
GArray *macros_list;
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
@ -245,9 +205,9 @@ init_sigchld (void)
struct sigaction sigchld_action;
sigchld_action.sa_handler =
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
mc_global.tty.use_subshell ? sigchld_handler :
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
sigchld_handler_no_subshell;
sigemptyset (&sigchld_action.sa_mask);
@ -260,13 +220,13 @@ init_sigchld (void)
if (sigaction (SIGCHLD, &sigchld_action, NULL) == -1)
{
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/*
* This may happen on QNX Neutrino 6, where SA_RESTART
* is defined but not implemented. Fallback to no subshell.
*/
mc_global.tty.use_subshell = FALSE;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
}
}
@ -274,142 +234,6 @@ init_sigchld (void)
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
gboolean
do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum exact)
{
gboolean res;
const vfs_path_t *_new_dir_vpath = new_dir_vpath;
if (current_panel->is_panelized)
{
size_t new_vpath_len;
new_vpath_len = vfs_path_len (new_dir_vpath);
if (vfs_path_ncmp (new_dir_vpath, panelized_panel.root_vpath, new_vpath_len) == 0)
_new_dir_vpath = panelized_panel.root_vpath;
}
res = do_panel_cd (current_panel, _new_dir_vpath, exact);
#ifdef HAVE_CHARSET
if (res)
{
const vfs_path_element_t *path_element;
path_element = vfs_path_get_by_index (current_panel->cwd_vpath, -1);
if (path_element->encoding != NULL)
current_panel->codepage = get_codepage_index (path_element->encoding);
else
current_panel->codepage = SELECT_CHARSET_NO_TRANSLATE;
}
#endif /* HAVE_CHARSET */
return res;
}
/* --------------------------------------------------------------------------------------------- */
#ifdef HAVE_SUBSHELL_SUPPORT
gboolean
do_load_prompt (void)
{
gboolean ret = FALSE;
if (!read_subshell_prompt ())
return ret;
/* Don't actually change the prompt if it's invisible */
if (top_dlg != NULL && ((Dlg_head *) top_dlg->data == midnight_dlg) && command_prompt)
{
setup_cmdline ();
/* since the prompt has changed, and we are called from one of the
* tty_get_event channels, the prompt updating does not take place
* automatically: force a cursor update and a screen refresh
*/
update_cursor (midnight_dlg);
mc_refresh ();
ret = TRUE;
}
update_subshell_prompt = TRUE;
return ret;
}
/* --------------------------------------------------------------------------------------------- */
int
load_prompt (int fd, void *unused)
{
(void) fd;
(void) unused;
do_load_prompt ();
return 0;
}
#endif /* HAVE_SUBSHELL_SUPPORT */
/* --------------------------------------------------------------------------------------------- */
void
title_path_prepare (char **path, char **login)
{
char host[BUF_TINY];
struct passwd *pw = NULL;
int res = 0;
*login = NULL;
*path =
vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD);
res = gethostname (host, sizeof (host));
if (res)
{ /* On success, res = 0 */
host[0] = '\0';
}
else
{
host[sizeof (host) - 1] = '\0';
}
pw = getpwuid (getuid ());
if (pw)
{
*login = g_strdup_printf ("%s@%s", pw->pw_name, host);
}
else
{
*login = g_strdup (host);
}
}
/* --------------------------------------------------------------------------------------------- */
/** Show current directory in the xterm title */
void
update_xterm_title_path (void)
{
char *p;
char *path;
char *login;
if (!(mc_global.tty.xterm_flag && xterm_title))
return;
title_path_prepare (&path, &login);
p = g_strdup_printf ("mc [%s]:%s", login, path);
fprintf (stdout, "\33]0;%s\7", str_term_form (p));
g_free (login);
g_free (p);
if (!mc_global.tty.alternate_plus_minus)
numeric_keypad_mode ();
(void) fflush (stdout);
g_free (path);
}
/* --------------------------------------------------------------------------------------------- */
int
main (int argc, char *argv[])
{
@ -417,9 +241,11 @@ main (int argc, char *argv[])
int exit_code = EXIT_FAILURE;
/* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */
#ifdef HAVE_SETLOCALE
(void) setlocale (LC_ALL, "");
(void) bindtextdomain ("mc", LOCALEDIR);
(void) textdomain ("mc");
#endif
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
/* do this before args parsing */
str_init_strings (NULL);
@ -490,14 +316,14 @@ main (int argc, char *argv[])
/* Must be done before installing the SIGCHLD handler [[FIXME]] */
handle_console (CONSOLE_INIT);
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/* Don't use subshell when invoked as viewer or editor */
if (mc_global.mc_run_mode != MC_RUN_FULL)
mc_global.tty.use_subshell = FALSE;
if (mc_global.tty.use_subshell)
subshell_get_console_attributes ();
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
/* Install the SIGCHLD handler; must be done before init_subshell() */
init_sigchld ();
@ -534,13 +360,13 @@ main (int argc, char *argv[])
mc_filehighlight = mc_fhl_new (TRUE);
dlg_set_default_colors ();
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
/* Done here to ensure that the subshell doesn't */
/* inherit the file descriptors opened below, etc */
if (mc_global.tty.use_subshell)
init_subshell ();
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
/* Also done after init_subshell, to save any shell init file messages */
if (mc_global.tty.console_flag != '\0')
@ -549,7 +375,7 @@ main (int argc, char *argv[])
if (mc_global.tty.alternate_plus_minus)
application_keypad_mode ();
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
if (mc_global.tty.use_subshell)
{
mc_prompt = strip_ctrl_codes (subshell_prompt);
@ -557,7 +383,7 @@ main (int argc, char *argv[])
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
}
else
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
/* Program main loop */

View File

@ -1,100 +0,0 @@
/** \file main.h
* \brief Header: this is a main module header
*/
#ifndef MC__MAIN_H
#define MC__MAIN_H
#include "lib/global.h"
#include "lib/vfs/vfs.h"
/*** typedefs(not structures) and defined constants **********************************************/
#define MAX_MACRO_LENGTH 1024
/*** enums ***************************************************************************************/
/* run mode and params */
enum cd_enum
{
cd_parse_command,
cd_exact
};
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct macro_action_t
{
unsigned long action;
int ch;
} macro_action_t;
typedef struct macros_t
{
int hotkey;
GArray *macro;
} macros_t;
struct mc_fhl_struct;
/*** global variables defined in .c file *********************************************************/
/*
* MC_RUN_FULL: dir for left panel
* MC_RUN_EDITOR: list of files to edit
* MC_RUN_VIEWER: file to view
* MC_RUN_DIFFVIEWER: first file to compare
*/
extern void *mc_run_param0;
/*
* MC_RUN_FULL: dir for right panel
* MC_RUN_EDITOR: unused
* MC_RUN_VIEWER: unused
* MC_RUN_DIFFVIEWER: second file to compare
*/
extern char *mc_run_param1;
extern int quit;
/* Set to TRUE to suppress printing the last directory */
extern gboolean print_last_revert;
/* If set, then print to the given file the last directory we were at */
extern char *last_wd_string;
extern struct mc_fhl_struct *mc_filehighlight;
extern int use_internal_view;
extern int use_internal_edit;
#ifdef HAVE_CHARSET
extern int default_source_codepage;
extern char *autodetect_codeset;
extern gboolean is_autodetect_codeset_enabled;
#endif /* !HAVE_CHARSET */
extern char *shell;
extern const char *mc_prompt;
/* index to record_macro_buf[], -1 if not recording a macro */
extern int macro_index;
/* macro stuff */
extern struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
extern GArray *macros_list;
/*** declarations of public functions ************************************************************/
#ifdef HAVE_SUBSHELL_SUPPORT
gboolean do_load_prompt (void);
int load_prompt (int fd, void *unused);
#endif
gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type);
void update_xterm_title_path (void);
void title_path_prepare (char **path, char **login);
/*** inline functions ****************************************************************************/
#endif /* MC__MAIN_H */

View File

@ -38,7 +38,7 @@
#include "lib/widget.h"
#include "lib/charsets.h"
#include "main.h"
#include "setup.h"
#include "selcodepage.h"

View File

@ -35,6 +35,7 @@
#include "lib/global.h"
#include "lib/filehighlight.h"
#include "lib/tty/tty.h"
#include "lib/tty/key.h"
#include "lib/mcconfig.h"
@ -175,6 +176,43 @@ int verbose = 1;
*/
int file_op_compute_totals = 1;
/* If true use the internal viewer */
int use_internal_view = 1;
/* If set, use the builtin editor */
int use_internal_edit = 1;
#ifdef HAVE_CHARSET
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
int default_source_codepage = -1;
char *autodetect_codeset = NULL;
gboolean is_autodetect_codeset_enabled = FALSE;
#endif /* !HAVE_CHARSET */
/* If set, then print to the given file the last directory we were at */
char *last_wd_string = NULL;
mc_fhl_t *mc_filehighlight;
/* Set when main loop should be terminated */
int quit = 0;
/* The user's shell */
char *shell = NULL;
/* The prompt */
const char *mc_prompt = NULL;
/* Set to TRUE to suppress printing the last directory */
int print_last_revert = FALSE;
/* index to record_macro_buf[], -1 if not recording a macro */
int macro_index = -1;
/* macro stuff */
struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
GArray *macros_list;
/*** file scope macro definitions ****************************************************************/
/* In order to use everywhere the same setup for the locale we use defines */

View File

@ -16,6 +16,8 @@
/* TAB length for editor and viewer */
#define DEFAULT_TAB_SPACING 8
#define MAX_MACRO_LENGTH 1024
/*** enums ***************************************************************************************/
typedef enum
@ -54,6 +56,20 @@ typedef struct
struct WPanel;
typedef struct macro_action_t
{
unsigned long action;
int ch;
} macro_action_t;
typedef struct macros_t
{
int hotkey;
GArray *macro;
} macros_t;
struct mc_fhl_struct;
/*** global variables defined in .c file *********************************************************/
/* global paremeters */
@ -88,6 +104,34 @@ extern panels_options_t panels_options;
extern panel_view_mode_t startup_left_mode;
extern panel_view_mode_t startup_right_mode;
extern gboolean boot_current_is_left;
extern int use_internal_view;
extern int use_internal_edit;
#ifdef HAVE_CHARSET
extern int default_source_codepage;
extern char *autodetect_codeset;
extern gboolean is_autodetect_codeset_enabled;
#endif /* !HAVE_CHARSET */
/* If set, then print to the given file the last directory we were at */
extern char *last_wd_string;
extern int quit;
/* Set to TRUE to suppress printing the last directory */
extern gboolean print_last_revert;
extern struct mc_fhl_struct *mc_filehighlight;
extern char *shell;
extern const char *mc_prompt;
/* index to record_macro_buf[], -1 if not recording a macro */
extern int macro_index;
/* macro stuff */
extern struct macro_action_t record_macro_buf[MAX_MACRO_LENGTH];
extern GArray *macros_list;
/*** declarations of public functions ************************************************************/

View File

@ -27,8 +27,6 @@
#include <config.h>
#ifdef HAVE_SUBSHELL_SUPPORT
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
@ -65,6 +63,7 @@
#include "filemanager/midnight.h" /* current_panel */
#include "consaver/cons.saver.h" /* handle_console() */
#include "setup.h"
#include "subshell.h"
/*** global variables ****************************************************************************/
@ -1345,5 +1344,3 @@ sigchld_handler (int sig)
}
/* --------------------------------------------------------------------------------------------- */
#endif /* HAVE_SUBSHELL_SUPPORT */

View File

@ -7,12 +7,6 @@
/*** typedefs(not structures) and defined constants **********************************************/
/* Used to distinguish between a normal MC termination and */
/* one caused by typing `exit' or `logout' in the subshell */
#define SUBSHELL_EXIT 128
#ifdef HAVE_SUBSHELL_SUPPORT
/*** enums ***************************************************************************************/
/* State of the subshell; see subshell.c for an explanation */
@ -53,8 +47,6 @@ void do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboole
void subshell_get_console_attributes (void);
void sigchld_handler (int sig);
#endif /* HAVE_SUBSHELL_SUPPORT */
/*** inline functions ****************************************************************************/
#endif /* MC__SUBSHELL_H */

View File

@ -92,13 +92,13 @@ static const char *const features[] = {
N_("With builtin Editor\n"),
#endif
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
#ifdef SUBSHELL_OPTIONAL
N_("With optional subshell support\n"),
#else
N_("With subshell support as default\n"),
#endif
#endif /* !HAVE_SUBSHELL_SUPPORT */
#endif /* !ENABLE_SUBSHELL */
#ifdef ENABLE_BACKGROUND
N_("With support for background operations\n"),

View File

@ -58,7 +58,7 @@
#include "lib/util.h"
#include "lib/widget.h" /* message() */
#include "src/main.h" /* shell */
#include "src/setup.h" /* shell */
#include "src/execute.h" /* For shell_execute */
#include "lib/vfs/vfs.h"

View File

@ -6,7 +6,7 @@ EXTFSCONFFILES = sfs.ini
EXTFS_MISC = README README.extfs
# Scripts hat don't need adaptation to the local system
EXTFS_CONST = bpp changesetfs gitfs+ patchsetfs rpm trpm uc1541 u7z
EXTFS_CONST = bpp changesetfs gitfs+ patchsetfs rpm trpm u7z
# Scripts that need adaptation to the local system - source files
EXTFS_IN = \
@ -29,6 +29,7 @@ EXTFS_IN = \
uar.in \
uarc.in \
uarj.in \
uc1541.in \
ucab.in \
uha.in \
ulha.in \
@ -58,6 +59,7 @@ EXTFS_OUT = \
uar \
uarc \
uarj \
uc1541 \
ucab \
uha \
ulha \

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#! @PYTHON@
# -*- coding: utf-8 -*-
#

View File

@ -1,4 +1,4 @@
#! /usr/bin/env python
#! @PYTHON@
"""
UC1541 Virtual filesystem

View File

@ -192,16 +192,17 @@ fish_load_script_from_file (const char *hostname, const char *script_name, const
/* --------------------------------------------------------------------------------------------- */
static int
fish_decode_reply (char *s, int was_garbage)
fish_decode_reply (char *s, gboolean was_garbage)
{
int code;
if (!sscanf (s, "%d", &code))
if (sscanf (s, "%d", &code) == 0)
{
code = 500;
return 5;
}
if (code < 100)
return was_garbage ? ERROR : (!code ? COMPLETE : PRELIM);
return was_garbage ? ERROR : (code == 0 ? COMPLETE : PRELIM);
return code / 100;
}
@ -212,25 +213,23 @@ static int
fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
{
char answer[BUF_1K];
int was_garbage = 0;
gboolean was_garbage = FALSE;
for (;;)
while (TRUE)
{
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{
if (string_buf)
*string_buf = 0;
if (string_buf != NULL)
*string_buf = '\0';
return 4;
}
if (strncmp (answer, "### ", 4))
{
was_garbage = 1;
if (string_buf)
g_strlcpy (string_buf, answer, string_len);
}
else
return fish_decode_reply (answer + 4, was_garbage);
if (strncmp (answer, "### ", 4) == 0)
return fish_decode_reply (answer + 4, was_garbage ? 1 : 0);
was_garbage = TRUE;
if (string_buf != NULL)
g_strlcpy (string_buf, answer, string_len);
}
}

View File

@ -377,31 +377,31 @@ ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_le
char answer[BUF_1K];
int i;
for (;;)
while (TRUE)
{
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{
if (string_buf)
*string_buf = 0;
if (string_buf != NULL)
*string_buf = '\0';
code = 421;
return 4;
}
switch (sscanf (answer, "%d", &code))
switch (sscanf (answer, "%d", &code) != 0)
{
case 0:
if (string_buf)
if (string_buf != NULL)
g_strlcpy (string_buf, answer, string_len);
code = 500;
return 5;
case 1:
if (answer[3] == '-')
{
while (1)
while (TRUE)
{
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
{
if (string_buf)
*string_buf = 0;
if (string_buf != NULL)
*string_buf = '\0';
code = 421;
return 4;
}
@ -409,7 +409,7 @@ ftpfs_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_le
break;
}
}
if (string_buf)
if (string_buf != NULL)
g_strlcpy (string_buf, answer, string_len);
return code / 100;
}
@ -432,7 +432,6 @@ ftpfs_reconnect (struct vfs_class *me, struct vfs_s_super *super)
SUP->sock = sock;
SUP->current_dir = NULL;
if (ftpfs_login_server (me, super, super->path_element->password) != 0)
{
if (cwdir == NULL)

View File

@ -765,7 +765,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
if (tard == -1)
return -1;
for (;;)
while (TRUE)
{
size_t h_size;
@ -774,7 +774,6 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
switch (status)
{
case STATUS_SUCCESS:
tar_skip_n_records (archive, tard, (h_size + RECORDSIZE - 1) / RECORDSIZE);
continue;
@ -788,7 +787,6 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
case STATUS_BADCHECKSUM:
switch (prev_status)
{
/* Error on first record */
case STATUS_EOFMARK:
{
@ -818,7 +816,7 @@ tar_open_archive (struct vfs_s_super *archive, const vfs_path_t * vpath,
break;
}
break;
};
}
return 0;
}

View File

@ -49,7 +49,6 @@
#endif
#include "src/setup.h" /* panels_options */
#include "src/main.h"
#include "src/keybind-defaults.h"
#include "internal.h"

View File

@ -48,7 +48,6 @@
#include "lib/charsets.h"
#endif
#include "src/main.h"
#ifdef HAVE_CHARSET
#include "src/selcodepage.h"
#endif

View File

@ -46,8 +46,6 @@
#include "lib/util.h" /* load_file_position() */
#include "lib/widget.h"
#include "src/main.h"
#include "src/filemanager/layout.h" /* menubar_visible */
#include "src/filemanager/midnight.h" /* the_menubar */

View File

@ -3,7 +3,14 @@ AM_CFLAGS = -I$(top_srcdir)/lib/vfs $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS
AM_LDFLAGS = -Wl,-z,muldefs
LIBS=@CHECK_LIBS@ \
$(top_builddir)/lib/libmc.la
$(top_builddir)/src/libinternal.la \
$(top_builddir)/lib/libmc.la
if ENABLE_VFS_SMB
# this is a hack for linking with own samba library in simple way
LIBS += $(top_builddir)/src/vfs/smbfs/helpers/libsamba.a
endif
TESTS = \
do_panel_cd \
@ -16,5 +23,3 @@ do_panel_cd_SOURCES = \
examine_cd_SOURCES = \
examine_cd.c
EXTRA_DIST = do_panel_cd_stub_env.c

View File

@ -30,12 +30,45 @@
#include <check.h>
#include "lib/global.h"
#include "src/main.h"
#include "src/vfs/local/local.c"
#include "src/filemanager/panel.c"
#include "do_panel_cd_stub_env.c"
/* --------------------------------------------------------------------------------------------- */
/* mocked functions */
#ifdef ENABLE_SUBSHELL
void
do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt)
{
(void) vpath;
(void) update_prompt;
(void) reset_prompt;
}
#endif
int
do_load_dir (const vfs_path_t *vpath, dir_list * list, sortfn * sort, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff, const char *fltr)
{
(void) vpath;
(void) list;
(void) sort;
(void) reverse;
(void) case_sensitive;
(void) exec_ff;
(void) fltr;
return 0;
}
void
load_hint (gboolean force)
{
(void) force;
}
/* --------------------------------------------------------------------------------------------- */
static void
setup (void)

View File

@ -1,398 +0,0 @@
#include "src/subshell.h"
#include "src/setup.h"
panels_options_t panels_options;
struct mc_fhl_struct *mc_filehighlight;
int confirm_execute = 0;
int auto_save_setup = 0;
int free_space = 0;
int horizontal_split = 0;
int first_panel_size = 0;
int default_source_codepage = 0;
int menubar_visible = 1;
WPanel *current_panel;
WInput *cmdline;
WMenuBar *the_menubar;
const global_keymap_t *panel_map;
gboolean command_prompt;
int saving_setup;
panels_layout_t panels_layout = {
.horizontal_split = 0,
.vertical_equal = 1,
.left_panel_size = 0,
.horizontal_equal = 1,
.top_panel_size = 0
};
WInput *
command_new (int y, int x, int cols)
{
WInput *cmd;
const input_colors_t command_colors = {
DEFAULT_COLOR,
COMMAND_MARK_COLOR,
DEFAULT_COLOR,
COMMAND_HISTORY_COLOR
};
cmd = input_new (y, x, (int *) command_colors, cols, "", "cmdline",
INPUT_COMPLETE_DEFAULT | INPUT_COMPLETE_CD | INPUT_COMPLETE_COMMANDS |
INPUT_COMPLETE_SHELL_ESC);
/* Add our hooks */
cmd->widget.callback = NULL;
return cmd;
}
int
do_cd (const vfs_path_t *new_dir, enum cd_enum exact)
{
(void) new_dir;
(void) exact;
return 0;
}
void
do_subshell_chdir (const vfs_path_t * vpath, gboolean update_prompt, gboolean reset_prompt)
{
(void) vpath;
(void) update_prompt;
(void) reset_prompt;
}
void
shell_execute (const char *command, int flags)
{
(void) command;
(void) flags;
}
void
panel_load_setup (WPanel * panel, const char *section)
{
(void) panel;
(void) section;
}
void
panel_save_setup (WPanel * panel, const char *section)
{
(void) panel;
(void) section;
}
void
free_my_statfs (void)
{
}
#ifdef HAVE_CHARSET
int
select_charset (int center_y, int center_x, int current_charset, gboolean seldisplay)
{
(void) center_y;
(void) center_x;
(void) current_charset;
(void) seldisplay;
return 0;
}
#endif
void
update_xterm_title_path (void)
{
}
void
init_my_statfs (void)
{
}
void
my_statfs (struct my_statfs *myfs_stats, const char *path)
{
(void) myfs_stats;
(void) path;
}
void
clean_dir (dir_list * list, int count)
{
(void) list;
(void) count;
}
struct Widget *
get_panel_widget (int idx)
{
(void) idx;
return NULL;
}
int
do_load_dir (const vfs_path_t *vpath, dir_list * list, sortfn * sort, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff, const char *fltr)
{
(void) vpath;
(void) list;
(void) sort;
(void) reverse;
(void) case_sensitive;
(void) exec_ff;
(void) fltr;
return 0;
}
int
do_reload_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, int count,
gboolean reverse, gboolean case_sensitive, gboolean exec_ff, const char *fltr)
{
(void) vpath;
(void) list;
(void) sort;
(void) count;
(void) reverse;
(void) case_sensitive;
(void) exec_ff;
(void) fltr;
return 0;
}
void
do_sort (dir_list * list, sortfn * sort, int top, gboolean reverse,
gboolean case_sensitive, gboolean exec_ff)
{
(void) list;
(void) sort;
(void) top;
(void) reverse;
(void) case_sensitive;
(void) exec_ff;
}
int
regex_command (const vfs_path_t *filename, const char *action)
{
(void) filename;
(void) action;
return 0;
}
gboolean
if_link_is_exe (const vfs_path_t *full_name, const file_entry * file)
{
(void) full_name;
(void) file;
return TRUE;
}
void
change_panel (void)
{
}
gboolean
set_zero_dir (dir_list * list)
{
(void) list;
return TRUE;
}
void
load_hint (gboolean force)
{
(void) force;
}
panel_view_mode_t
get_display_type (int idx)
{
(void) idx;
return view_listing;
}
panel_view_mode_t
get_current_type (void)
{
return view_listing;
}
panel_view_mode_t
get_other_type (void)
{
return view_listing;
}
int
get_current_index (void)
{
return 0;
}
int
get_other_index (void)
{
return 1;
}
int
unsorted (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_name (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_vers (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_ext (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_time (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_atime (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_ctime (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_size (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
int
sort_inode (file_entry * a, file_entry * b)
{
(void) a;
(void) b;
return 0;
}
void
set_display_type (int num, panel_view_mode_t type)
{
(void) num;
(void) type;
}
void
copy_cmd_local (void)
{
}
void
delete_cmd_local (void)
{
}
void
view_raw_cmd (void)
{
}
void
edit_cmd_new (void)
{
}
void
rename_cmd_local (void)
{
}
void
select_invert_cmd (void)
{
}
void
unselect_cmd (void)
{
}
void
select_cmd (void)
{
}
struct WPanel *
get_other_panel (void)
{
return NULL;
}
const panel_field_t *
sort_box (panel_sort_info_t * info)
{
(void) info;
return NULL;
}
void
midnight_set_buttonbar (WButtonBar * b)
{
(void) b;
}

View File

@ -36,18 +36,18 @@
#include "src/filemanager/layout.h"
#include "src/filemanager/midnight.h"
#include "src/filemanager/tree.h"
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
#include "src/subshell.h"
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
#include "src/filemanager/command.c"
/* --------------------------------------------------------------------------------------------- */
gboolean command_prompt = FALSE;
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
enum subshell_state_enum subshell_state = INACTIVE;
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
int quit = 0;
WPanel *current_panel = NULL;
@ -82,7 +82,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
return NULL;
}
#ifdef HAVE_SUBSHELL_SUPPORT
#ifdef ENABLE_SUBSHELL
void
init_subshell (void)
{
@ -93,7 +93,7 @@ do_load_prompt (void)
{
return TRUE;
}
#endif /* HAVE_SUBSHELL_SUPPORT */
#endif /* ENABLE_SUBSHELL */
void
shell_execute (const char *command, int flags)