From fc7142d2a088bd99bd5c3b071f51408519823c63 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 15 Feb 2011 12:42:51 +0200 Subject: [PATCH 01/25] Ticket #2501: 'lib' should be independ to 'src' directory Added base support for unit tests (see http://check.sourceforge.net/ for details). Signed-off-by: Slava Zanko --- acinclude.m4 | 1 + configure.ac | 2 ++ m4.include/mc-tests.m4 | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 m4.include/mc-tests.m4 diff --git a/acinclude.m4 b/acinclude.m4 index 5edcda5eb..2a800371b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -9,3 +9,4 @@ m4_include([m4.include/mc-with-screen.m4]) m4_include([m4.include/ac-g-module-supported.m4]) m4_include([m4.include/mc-vfs.m4]) m4_include([m4.include/mc-version.m4]) +m4_include([m4.include/mc-tests.m4]) diff --git a/configure.ac b/configure.ac index ec77113d5..b428bf26a 100644 --- a/configure.ac +++ b/configure.ac @@ -489,6 +489,8 @@ if test "x$enable_werror" = xyes; then fi CFLAGS="$mc_configured_cflags $CFLAGS_OPTS $CFLAGS" +MC_UNIT_TESTS + AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(LDFLAGS) diff --git a/m4.include/mc-tests.m4 b/m4.include/mc-tests.m4 new file mode 100644 index 000000000..6e14a3056 --- /dev/null +++ b/m4.include/mc-tests.m4 @@ -0,0 +1,25 @@ +dnl @synopsis MC_UNIT_TESTS +dnl +dnl Check if unit tests enabled +dnl +dnl @author Slava Zanko +dnl @version 2011-02-10 +dnl @license GPL +dnl @copyright Free Software Foundation, Inc. + +AC_DEFUN([MC_UNIT_TESTS],[ + + AC_ARG_ENABLE( + [tests], + AC_HELP_STRING([--enable-tests], [Enable unit tests (see http://check.sourceforge.net/)] ) + ) + + if test x$enable_tests != xno; then + PKG_CHECK_MODULES( + CHECK, + [check >= 0.9.0], + [have_check=yes], + [AC_MSG_WARN(['Check' utility not found. Check your environment])]) + fi + AM_CONDITIONAL(HAVE_TESTS, test x"$have_check" = "xyes") +]) From a5195d285a9a76f4212595f897f25f558c193f1e Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 17 Jan 2011 00:01:38 +0200 Subject: [PATCH 02/25] Added new engine for universal event system. Example: gboolean mkdir_callback(const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data) { ... /* some action for handle event */ return TRUE; /* got chance to run other callbacks for this event or */ return FALSE; /* break execution for other callbacks */ } mc_event_add ("filesystem", "mkdir", mkdir_callback, "some init data", NULL); mc_event_add ("filesystem", "mkdir", mkdir_log_callback, "some init data", NULL); mc_event_add ("filesystem", "mkdir", third_callback, NULL, NULL); /* Last add - first run. In this case execution order is * third_callback * mkdir_log_callback * mkdir_callback if third_callback fuctions will return FALSE, then other callbacks (mkdir_log_callback and mkdir_callback) never run! */ ... /* some code */ /* for example, after pressing F7 */ mc_event_raise("filesystem", "mkdir", "some event_data... path to directory"); Signed-off-by: Slava Zanko --- configure.ac | 1 + lib/Makefile.am | 4 +- lib/event.h | 43 ++++++++ lib/event/Makefile.am | 12 +++ lib/event/event.c | 135 +++++++++++++++++++++++++ lib/event/internal.h | 31 ++++++ lib/event/manage.c | 224 ++++++++++++++++++++++++++++++++++++++++++ lib/event/raise.c | 76 ++++++++++++++ 8 files changed, 525 insertions(+), 1 deletion(-) create mode 100644 lib/event.h create mode 100644 lib/event/Makefile.am create mode 100644 lib/event/event.c create mode 100644 lib/event/internal.h create mode 100644 lib/event/manage.c create mode 100644 lib/event/raise.c diff --git a/configure.ac b/configure.ac index b428bf26a..354ed9069 100644 --- a/configure.ac +++ b/configure.ac @@ -543,6 +543,7 @@ src/diffviewer/Makefile src/filemanager/Makefile lib/Makefile +lib/event/Makefile lib/filehighlight/Makefile lib/mcconfig/Makefile lib/search/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index 302ebe28e..b1655834c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,8 +1,9 @@ -SUBDIRS = filehighlight mcconfig search skin tty vfs strutil widget +SUBDIRS = event filehighlight mcconfig search skin tty vfs strutil widget noinst_LTLIBRARIES = libmc.la SUBLIB_includes = \ + event.h \ filehighlight.h \ mcconfig.h \ search.h \ @@ -40,6 +41,7 @@ endif libmc_la_CFLAGS= $(GLIB_CFLAGS) -I$(top_srcdir) $(PCRE_CFLAGS) libmc_la_LIBADD = \ + event/libmcevent.la \ filehighlight/libmcfilehighlight.la \ mcconfig/libmcconfig.la \ search/libsearch.la \ diff --git a/lib/event.h b/lib/event.h new file mode 100644 index 000000000..dc53dcda4 --- /dev/null +++ b/lib/event.h @@ -0,0 +1,43 @@ +#ifndef MC__EVENT_H +#define MC__EVENT_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +typedef gboolean (*mc_event_callback_func_t) (const gchar *, const gchar *, gpointer, gpointer); + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +typedef struct +{ + const char *event_group_name; + const char *event_name; + mc_event_callback_func_t cb; + gpointer init_data; +} event_init_t; + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/* event.c: */ +gboolean mc_event_init (GError **); +gboolean mc_event_deinit (GError **); + + +/* manage.c: */ +gboolean mc_event_add (const gchar *, const gchar *, mc_event_callback_func_t, gpointer, GError **); +void mc_event_del (const gchar *, const gchar *, mc_event_callback_func_t); +void mc_event_destroy (const gchar *, const gchar *); +void mc_event_group_del (const gchar *); +gboolean mc_event_present (const gchar *, const gchar *); +gboolean mc_event_mass_add (event_init_t *, GError **); + +/* raise.c: */ +gboolean mc_event_raise (const gchar *, const gchar *, gpointer); + + +/*** inline functions ****************************************************************************/ + +#endif /* MC__EVENT_H */ diff --git a/lib/event/Makefile.am b/lib/event/Makefile.am new file mode 100644 index 000000000..7893ef5e4 --- /dev/null +++ b/lib/event/Makefile.am @@ -0,0 +1,12 @@ + +noinst_LTLIBRARIES = libmcevent.la + +libmcevent_la_SOURCES = \ + event.c \ + internal.h \ + manage.c \ + raise.c + +libmcevent_la_CFLAGS=-I$(top_srcdir) \ + $(GLIB_CFLAGS) $(PCRE_CFLAGS) \ + -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" diff --git a/lib/event/event.c b/lib/event/event.c new file mode 100644 index 000000000..f91967e72 --- /dev/null +++ b/lib/event/event.c @@ -0,0 +1,135 @@ +/* + Handle events in application. + Interface functions: init/deinit; start/stop + + Copyright (C) 2011 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "lib/global.h" +#include "lib/event.h" + +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +GTree *mc_event_grouplist = NULL; + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_init (GError ** mcerror) +{ + if (mc_event_grouplist != NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 1, + _("Event system already initialized"))); + return FALSE; + } + + mc_event_grouplist = + g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp, + NULL, (GDestroyNotify) g_free, (GDestroyNotify) g_tree_destroy); + + if (mc_event_grouplist == NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 2, + _("Failed to initialize event system"))); + return FALSE; + } + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_deinit (GError ** mcerror) +{ + if (mc_event_grouplist == NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 1, + _("Event system not initialized"))); + return FALSE; + } + + g_tree_destroy (mc_event_grouplist); + mc_event_grouplist = NULL; + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_mass_add (event_init_t * events, GError ** mcerror) +{ + size_t array_index; + + for (array_index = 0; events[array_index].event_group_name != NULL; array_index++) + { + if (!mc_event_add (events[array_index].event_group_name, + events[array_index].event_name, + events[array_index].cb, events[array_index].init_data, mcerror)) + { + return FALSE; + } + } + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_present (const gchar *event_group_name, const gchar *event_name) +{ + GTree *event_group; + GPtrArray *callbacks; + + if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL) + return FALSE; + + event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL); + if (event_group == NULL) + return FALSE; + + callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL); + if (callbacks == NULL) + return FALSE; + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/event/internal.h b/lib/event/internal.h new file mode 100644 index 000000000..6a21402b8 --- /dev/null +++ b/lib/event/internal.h @@ -0,0 +1,31 @@ +#ifndef MC_EVENT_INTERNAL_H +#define MC_EVENT_INTERNAL_H + +/*** typedefs(not structures) and defined constants ********************/ + +/*** enums *************************************************************/ + +/*** structures declarations (and typedefs of structures)***************/ + +typedef struct mc_event_callback_struct +{ + gpointer init_data; + mc_event_callback_func_t callback; +} mc_event_callback_t; + + +/*** global variables defined in .c file *******************************/ + +extern GTree *mc_event_grouplist; + +/*** declarations of public functions **********************************/ + +GTree *mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean create_new, + GError ** mcerror); +GPtrArray *mc_event_get_event_by_name (GTree * event_group, const gchar * event_name, + gboolean create_new, GError ** mcerror); +mc_event_callback_t *mc_event_is_callback_in_array (GPtrArray * callbacks, + mc_event_callback_func_t event_callback); + +/*** inline functions ****************************************************************************/ +#endif /* MC_EVENT_INTERNAL_H */ diff --git a/lib/event/manage.c b/lib/event/manage.c new file mode 100644 index 000000000..f5e9c3f8e --- /dev/null +++ b/lib/event/manage.c @@ -0,0 +1,224 @@ +/* + Handle any events in application. + Manage events: add, delete, destroy, search + + Copyright (C) 2011 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "lib/global.h" +#include "lib/event.h" + +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +static void +mc_event_group_destroy_value (gpointer data) +{ + GPtrArray *callbacks; + + callbacks = (GPtrArray *) data; + g_ptr_array_foreach (callbacks, (GFunc) g_free, NULL); + g_ptr_array_free (callbacks, TRUE); +} + +/* --------------------------------------------------------------------------------------------- */ + + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_add (const gchar * event_group_name, const gchar * event_name, + mc_event_callback_func_t event_callback, gpointer event_init_data, GError ** mcerror) +{ + + GTree *event_group; + GPtrArray *callbacks; + mc_event_callback_t *cb; + + if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL + || event_callback == NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 1, + _("Check input data! Some of parameters are NULL!"))); + return FALSE; + } + + event_group = mc_event_get_event_group_by_name (event_group_name, TRUE, mcerror); + if (event_group == NULL) + return FALSE; + + callbacks = mc_event_get_event_by_name (event_group, event_name, TRUE, mcerror); + if (callbacks == NULL) + return FALSE; + + cb = mc_event_is_callback_in_array (callbacks, event_callback); + if (cb == NULL) + { + cb = g_new0 (mc_event_callback_t, 1); + cb->callback = event_callback; + g_ptr_array_add (callbacks, (gpointer) cb); + } + cb->init_data = event_init_data; + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +void +mc_event_del (const gchar * event_group_name, const gchar * event_name, + mc_event_callback_func_t event_callback) +{ + GTree *event_group; + GPtrArray *callbacks; + mc_event_callback_t *cb; + + if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL + || event_callback == NULL) + return; + + event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL); + if (event_group == NULL) + return; + + callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL); + if (callbacks == NULL) + return; + + cb = mc_event_is_callback_in_array (callbacks, event_callback); + + if (cb == NULL) + return; + + g_ptr_array_remove (callbacks, (gpointer) cb); + g_free ((gpointer) cb); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +mc_event_destroy (const gchar * event_group_name, const gchar * event_name) +{ + GTree *event_group; + + if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL) + return; + + event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL); + g_tree_remove (event_group, (gconstpointer) event_name); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +mc_event_group_del (const gchar * event_group_name) +{ + + if (mc_event_grouplist != NULL && event_group_name != NULL) + g_tree_remove (mc_event_grouplist, (gconstpointer) event_group_name); +} + +/* --------------------------------------------------------------------------------------------- */ + +GTree * +mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean create_new, + GError ** mcerror) +{ + GTree *event_group; + + event_group = (GTree *) g_tree_lookup (mc_event_grouplist, (gconstpointer) event_group_name); + if (event_group == NULL && create_new) + { + event_group = + g_tree_new_full ((GCompareDataFunc) g_ascii_strcasecmp, + NULL, + (GDestroyNotify) g_free, + (GDestroyNotify) mc_event_group_destroy_value); + if (event_group == NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 1, + _("Unable to create group '%s' for events!"), + event_group_name)); + return NULL; + } + g_tree_insert (mc_event_grouplist, g_strdup (event_group_name), (gpointer) event_group); + } + return event_group; +} + +/* --------------------------------------------------------------------------------------------- */ + +GPtrArray * +mc_event_get_event_by_name (GTree * event_group, const gchar * event_name, gboolean create_new, + GError ** mcerror) +{ + GPtrArray *callbacks; + + callbacks = (GPtrArray *) g_tree_lookup (event_group, (gconstpointer) event_name); + if (callbacks == NULL && create_new) + { + callbacks = g_ptr_array_new (); + if (callbacks == NULL) + { + g_propagate_error (mcerror, + g_error_new (mc_main_error_quark (), 1, + _("Unable to create event '%s'!"), event_name)); + return NULL; + } + g_tree_insert (event_group, g_strdup (event_name), (gpointer) callbacks); + } + return callbacks; +} + +/* --------------------------------------------------------------------------------------------- */ + +mc_event_callback_t * +mc_event_is_callback_in_array (GPtrArray * callbacks, mc_event_callback_func_t event_callback) +{ + guint array_index; + + for (array_index = 0; array_index < callbacks->len; array_index++) + { + mc_event_callback_t *cb = g_ptr_array_index (callbacks, array_index); + if (cb->callback == event_callback) + return cb; + } + return NULL; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/event/raise.c b/lib/event/raise.c new file mode 100644 index 000000000..d2f076293 --- /dev/null +++ b/lib/event/raise.c @@ -0,0 +1,76 @@ +/* + Handle any events in application. + Raise events. + + Copyright (C) 2011 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +#include + +#include "lib/global.h" +#include "lib/event.h" + +#include "internal.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +gboolean +mc_event_raise (const gchar * event_group_name, const gchar * event_name, gpointer event_data) +{ + GTree *event_group; + GPtrArray *callbacks; + guint array_index; + + if (mc_event_grouplist == NULL || event_group_name == NULL || event_name == NULL) + return FALSE; + + event_group = mc_event_get_event_group_by_name (event_group_name, FALSE, NULL); + if (event_group == NULL) + return FALSE; + + callbacks = mc_event_get_event_by_name (event_group, event_name, FALSE, NULL); + if (callbacks == NULL) + return FALSE; + + for (array_index = callbacks->len; array_index > 0; array_index--) + { + mc_event_callback_t *cb = g_ptr_array_index (callbacks, array_index - 1); + if (!(*cb->callback) (event_group_name, event_name, cb->init_data, event_data)) + break; + } + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ From d512649b333fabc95aa22a1b81883ae76cba489b Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 17 Jan 2011 11:44:25 +0200 Subject: [PATCH 03/25] Prepare to initialize application events. Signed-off-by: Slava Zanko --- lib/Makefile.am | 2 +- lib/event-types.h | 23 +++++++++++++++++ lib/event.h | 2 ++ src/Makefile.am | 1 + src/events_init.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ src/events_init.h | 19 ++++++++++++++ src/main.c | 18 +++++++++++++ 7 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 lib/event-types.h create mode 100644 src/events_init.c create mode 100644 src/events_init.h diff --git a/lib/Makefile.am b/lib/Makefile.am index b1655834c..c538010cc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -3,7 +3,7 @@ SUBDIRS = event filehighlight mcconfig search skin tty vfs strutil widget noinst_LTLIBRARIES = libmc.la SUBLIB_includes = \ - event.h \ + event.h event-types.h \ filehighlight.h \ mcconfig.h \ search.h \ diff --git a/lib/event-types.h b/lib/event-types.h new file mode 100644 index 000000000..2eb40113d --- /dev/null +++ b/lib/event-types.h @@ -0,0 +1,23 @@ +#ifndef MC__EVENT_TYPES_H +#define MC__EVENT_TYPES_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/* Event groups for main modules */ +#define MCEVENT_GROUP_CORE "Core" +#define MCEVENT_GROUP_DIFFVIEWER "DiffViewer" +#define MCEVENT_GROUP_EDITOR "Editor" +#define MCEVENT_GROUP_FILEMANAGER "FileManager" +#define MCEVENT_GROUP_VIEWER "Viewer" + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/*** inline functions ****************************************************************************/ + +#endif /* MC__EVENT_TYPES_H */ diff --git a/lib/event.h b/lib/event.h index dc53dcda4..a3417b4eb 100644 --- a/lib/event.h +++ b/lib/event.h @@ -1,6 +1,8 @@ #ifndef MC__EVENT_H #define MC__EVENT_H +#include "event-types.h" + /*** typedefs(not structures) and defined constants **********************************************/ typedef gboolean (*mc_event_callback_func_t) (const gchar *, const gchar *, gpointer, gpointer); diff --git a/src/Makefile.am b/src/Makefile.am index 2da86c380..1a3992d25 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,6 +62,7 @@ mc_SOURCES = \ args.c args.h \ background.c background.h \ clipboard.c clipboard.h \ + events_init.c events_init.h \ execute.c execute.h \ help.c help.h \ history.h \ diff --git a/src/events_init.c b/src/events_init.c new file mode 100644 index 000000000..cfc4f7459 --- /dev/null +++ b/src/events_init.c @@ -0,0 +1,64 @@ +/* Event callbacks initialization + + Copyright (C) 2011 Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011. + + This file is part of the Midnight Commander. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +#include "lib/global.h" + +#include "lib/event.h" + +#include "events_init.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +gboolean +events_init (GError ** error) +{ + /* *INDENT-OFF* */ + event_init_t standard_events[] = + { + {NULL, NULL, NULL, NULL} + }; + /* *INDENT-ON* */ + + if (!mc_event_init (error)) + return FALSE; + + return mc_event_mass_add (standard_events, error); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/events_init.h b/src/events_init.h new file mode 100644 index 000000000..750891038 --- /dev/null +++ b/src/events_init.h @@ -0,0 +1,19 @@ +#ifndef MC__EVENTS_INIT_H +#define MC__EVENTS_INIT_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + + +/*** declarations of public functions ************************************************************/ + +gboolean events_init (GError **); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__EVENTS_INIT_H */ diff --git a/src/main.c b/src/main.c index caf2af4b4..088915d4a 100644 --- a/src/main.c +++ b/src/main.c @@ -41,6 +41,7 @@ #include "lib/global.h" +#include "lib/event.h" #include "lib/tty/tty.h" #include "lib/tty/key.h" /* For init_key() */ #include "lib/tty/win.h" /* xterm_flag */ @@ -57,6 +58,7 @@ #include "filemanager/ext.h" /* flush_extension_file() */ #include "filemanager/command.h" /* cmdline */ +#include "events_init.h" #include "args.h" #include "subshell.h" #include "setup.h" /* load_setup() */ @@ -427,6 +429,13 @@ main (int argc, char *argv[]) bindtextdomain ("mc", LOCALEDIR); textdomain ("mc"); + if (!events_init (&error)) + { + fprintf (stderr, _("Failed to run:\n%s\n"), error->message); + g_error_free (error); + (void) mc_event_deinit (NULL); + exit (EXIT_FAILURE); + } /* Set up temporary directory */ mc_tmpdir (); @@ -612,8 +621,17 @@ main (int argc, char *argv[]) g_free (mc_run_param0); g_free (mc_run_param1); + mc_event_deinit (&error); + mc_config_deinit_config_paths (); + if (error != NULL) + { + fprintf (stderr, _("\nFailed while close:\n%s\n"), error->message); + g_error_free (error); + exit (EXIT_FAILURE); + } + putchar ('\n'); /* Hack to make shell's prompt start at left of screen */ return 0; From 6c5f5bf768a60e36777eaae0f645ec298badc2a0 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 15 Feb 2011 15:44:17 +0200 Subject: [PATCH 04/25] VFS structure changes: * moved from lib/vfs/mc-vfs to lib/vfs; * split by directories for VFS-plugins and moved to src/vfs; * lib/vfs/vfs-impl.h was merged into lib/vfs/vfs.h. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- autogen.sh | 8 +- configure.ac | 77 ++- lib/Makefile.am | 2 +- lib/lock.c | 2 +- lib/mcconfig/common.c | 2 +- lib/mcconfig/paths.c | 2 +- lib/tty/key.c | 2 +- lib/util.c | 2 +- lib/utilunix.c | 2 +- lib/vfs/{mc-vfs => }/COPYING.LGPL | 6 +- lib/vfs/{mc-vfs => }/HACKING | 2 +- lib/vfs/Makefile.am | 16 +- lib/vfs/{mc-vfs => }/README | 0 lib/vfs/{mc-vfs => }/direntry.c | 2 +- lib/vfs/{mc-vfs => }/gc.c | 2 +- lib/vfs/{mc-vfs => }/gc.h | 2 +- lib/vfs/mc-vfs/.gitignore | 11 - lib/vfs/mc-vfs/Makefile.am | 152 ------ lib/vfs/mc-vfs/fish/README.fish~HEAD | 178 ------- lib/vfs/mc-vfs/vfs-impl.h | 147 ------ lib/vfs/{mc-vfs => }/netutil.c | 0 lib/vfs/{mc-vfs => }/netutil.h | 0 lib/vfs/{mc-vfs => }/utilvfs.c | 2 +- lib/vfs/{mc-vfs => }/utilvfs.h | 0 lib/vfs/{mc-vfs => }/vfs.c | 146 +++--- lib/vfs/{mc-vfs => }/vfs.h | 111 +++- lib/vfs/{mc-vfs => }/xdirentry.h | 0 lib/widget/input.c | 2 +- m4.include/vfs/mc-vfs-samba.m4 | 2 +- src/Makefile.am | 5 +- src/args.c | 9 +- src/diffviewer/ydiff.c | 2 +- src/editor/edit.c | 2 +- src/editor/editcmd.c | 2 +- src/execute.c | 2 +- src/filemanager/achown.c | 2 +- src/filemanager/boxes.c | 6 +- src/filemanager/chmod.c | 2 +- src/filemanager/chown.c | 2 +- src/filemanager/cmd.c | 2 +- src/filemanager/command.c | 2 +- src/filemanager/complete.c | 2 +- src/filemanager/dir.c | 2 +- src/filemanager/ext.c | 2 +- src/filemanager/file.c | 2 +- src/filemanager/filegui.c | 2 +- src/filemanager/filenot.c | 2 +- src/filemanager/fileopctx.c | 2 +- src/filemanager/find.c | 2 +- src/filemanager/hotlist.c | 2 +- src/filemanager/layout.c | 2 +- src/filemanager/midnight.c | 2 +- src/filemanager/panel.c | 2 +- src/filemanager/panelize.c | 2 +- src/filemanager/tree.c | 2 +- src/filemanager/treestore.c | 2 +- src/filemanager/usermenu.c | 2 +- src/main.c | 6 +- src/setup.c | 6 +- src/subshell.c | 2 +- src/vfs/COPYING.LGPL | 489 ++++++++++++++++++ src/vfs/Makefile.am | 47 ++ src/vfs/cpio/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/cpio}/cpio.c | 10 +- src/vfs/cpio/cpio.h | 18 + src/vfs/extfs/Makefile.am | 10 + {lib/vfs/mc-vfs => src/vfs/extfs}/extfs.c | 8 +- src/vfs/extfs/extfs.h | 18 + .../vfs/extfs/helpers}/.gitignore | 0 .../vfs/extfs/helpers}/Makefile.am | 0 .../extfs => src/vfs/extfs/helpers}/README | 0 .../vfs/extfs/helpers}/README.extfs | 0 .../extfs => src/vfs/extfs/helpers}/README.it | 0 .../vfs/extfs/helpers}/README.uzip | 0 .../extfs => src/vfs/extfs/helpers}/a+.in | 0 .../extfs => src/vfs/extfs/helpers}/apt+.in | 0 .../extfs => src/vfs/extfs/helpers}/audio.in | 0 .../extfs => src/vfs/extfs/helpers}/bpp | 0 .../extfs => src/vfs/extfs/helpers}/deb.in | 0 .../extfs => src/vfs/extfs/helpers}/deba.in | 0 .../extfs => src/vfs/extfs/helpers}/debd.in | 0 .../extfs => src/vfs/extfs/helpers}/dpkg+.in | 0 .../extfs => src/vfs/extfs/helpers}/hp48+.in | 0 .../vfs/extfs/helpers}/iso9660.in | 0 .../extfs => src/vfs/extfs/helpers}/lslR.in | 0 .../extfs => src/vfs/extfs/helpers}/mailfs.in | 0 .../vfs/extfs/helpers}/patchfs.in | 0 .../extfs => src/vfs/extfs/helpers}/rpm | 0 .../extfs => src/vfs/extfs/helpers}/rpms+.in | 0 .../extfs => src/vfs/extfs/helpers}/s3+.in | 0 .../extfs => src/vfs/extfs/helpers}/sfs.ini | 0 .../extfs => src/vfs/extfs/helpers}/trpm | 0 .../extfs => src/vfs/extfs/helpers}/u7z | 0 .../extfs => src/vfs/extfs/helpers}/uace.in | 0 .../extfs => src/vfs/extfs/helpers}/ualz.in | 0 .../extfs => src/vfs/extfs/helpers}/uar.in | 0 .../extfs => src/vfs/extfs/helpers}/uarc.in | 0 .../extfs => src/vfs/extfs/helpers}/uarj.in | 0 .../extfs => src/vfs/extfs/helpers}/uc1541.in | 0 .../extfs => src/vfs/extfs/helpers}/ucab | 0 .../extfs => src/vfs/extfs/helpers}/uha.in | 0 .../extfs => src/vfs/extfs/helpers}/ulha.in | 0 .../extfs => src/vfs/extfs/helpers}/urar.in | 0 .../extfs => src/vfs/extfs/helpers}/uzip.in | 0 .../extfs => src/vfs/extfs/helpers}/uzoo.in | 0 src/vfs/fish/Makefile.am | 11 + {lib/vfs/mc-vfs => src/vfs/fish}/fish.c | 10 +- {lib/vfs/mc-vfs => src/vfs/fish}/fish.h | 2 + {lib/vfs/mc-vfs => src/vfs/fish}/fishdef.h | 0 .../fish => src/vfs/fish/helpers}/Makefile.am | 0 .../fish => src/vfs/fish/helpers}/README.fish | 0 .../fish => src/vfs/fish/helpers}/append | 0 .../fish => src/vfs/fish/helpers}/chmod | 0 .../fish => src/vfs/fish/helpers}/chown | 0 .../fish => src/vfs/fish/helpers}/fexists | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/get | 0 .../fish => src/vfs/fish/helpers}/hardlink | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/info | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/ln | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/ls | 0 .../fish => src/vfs/fish/helpers}/mkdir | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/mv | 0 .../fish => src/vfs/fish/helpers}/rmdir | 0 .../mc-vfs/fish => src/vfs/fish/helpers}/send | 0 .../fish => src/vfs/fish/helpers}/unlink | 0 src/vfs/ftpfs/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/ftpfs}/ftpfs.c | 10 +- {lib/vfs/mc-vfs => src/vfs/ftpfs}/ftpfs.h | 0 src/vfs/local/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/local}/local.c | 3 +- {lib/vfs/mc-vfs => src/vfs/local}/local.h | 2 +- src/vfs/plugins_init.c | 125 +++++ src/vfs/plugins_init.h | 18 + src/vfs/sfs/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/sfs}/sfs.c | 10 +- src/vfs/sfs/sfs.h | 18 + src/vfs/smbfs/Makefile.am | 84 +++ .../vfs/smbfs/helpers}/Makefile.in | 0 .../vfs/smbfs/helpers}/aclocal.m4 | 0 .../vfs/smbfs/helpers}/configure.ac | 0 .../vfs/smbfs/helpers}/include/byteorder.h | 0 .../vfs/smbfs/helpers}/include/charset.h | 0 .../vfs/smbfs/helpers}/include/client.h | 0 .../vfs/smbfs/helpers}/include/includes.h | 0 .../vfs/smbfs/helpers}/include/kanji.h | 0 .../vfs/smbfs/helpers}/include/local.h | 0 .../vfs/smbfs/helpers}/include/nameserv.h | 0 .../vfs/smbfs/helpers}/include/nterr.h | 0 .../vfs/smbfs/helpers}/include/proto.h | 0 .../vfs/smbfs/helpers}/include/smb.h | 0 .../vfs/smbfs/helpers}/include/trans2.h | 0 .../vfs/smbfs/helpers}/include/version.h | 0 .../vfs/smbfs/helpers}/internals.doc | 0 .../vfs/smbfs/helpers}/lib/charcnv.c | 0 .../vfs/smbfs/helpers}/lib/charset.c | 0 .../vfs/smbfs/helpers}/lib/debug.c | 0 .../vfs/smbfs/helpers}/lib/interface.c | 0 .../vfs/smbfs/helpers}/lib/kanji.c | 0 .../samba => src/vfs/smbfs/helpers}/lib/md4.c | 0 .../vfs/smbfs/helpers}/lib/netmask.c | 0 .../vfs/smbfs/helpers}/lib/slprintf.c | 0 .../vfs/smbfs/helpers}/lib/system.c | 0 .../vfs/smbfs/helpers}/lib/time.c | 0 .../vfs/smbfs/helpers}/lib/username.c | 0 .../vfs/smbfs/helpers}/lib/util.c | 0 .../vfs/smbfs/helpers}/lib/util_file.c | 0 .../vfs/smbfs/helpers}/lib/util_sock.c | 0 .../vfs/smbfs/helpers}/lib/util_str.c | 0 .../vfs/smbfs/helpers}/libsmb/clientgen.c | 0 .../vfs/smbfs/helpers}/libsmb/namequery.c | 0 .../vfs/smbfs/helpers}/libsmb/nmblib.c | 0 .../vfs/smbfs/helpers}/libsmb/nterr.c | 0 .../vfs/smbfs/helpers}/libsmb/pwd_cache.c | 0 .../vfs/smbfs/helpers}/libsmb/smbdes.c | 0 .../vfs/smbfs/helpers}/libsmb/smbencrypt.c | 0 .../vfs/smbfs/helpers}/libsmb/smberr.c | 0 .../vfs/smbfs/helpers}/param/loadparm.c | 0 .../vfs/smbfs/helpers}/param/params.c | 0 .../vfs/smbfs/helpers}/parsing.doc | 0 {lib/vfs/mc-vfs => src/vfs/smbfs}/smbfs.c | 11 +- {lib/vfs/mc-vfs => src/vfs/smbfs}/smbfs.h | 0 src/vfs/tar/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/tar}/tar.c | 10 +- src/vfs/tar/tar.h | 18 + src/vfs/undelfs/Makefile.am | 7 + {lib/vfs/mc-vfs => src/vfs/undelfs}/undelfs.c | 6 +- src/vfs/undelfs/undelfs.h | 18 + src/viewer/datasource.c | 2 +- src/viewer/growbuf.c | 2 +- src/viewer/hex.c | 2 +- src/viewer/lib.c | 2 +- src/viewer/mcviewer.c | 2 +- 192 files changed, 1259 insertions(+), 713 deletions(-) rename lib/vfs/{mc-vfs => }/COPYING.LGPL (99%) rename lib/vfs/{mc-vfs => }/HACKING (99%) rename lib/vfs/{mc-vfs => }/README (100%) rename lib/vfs/{mc-vfs => }/direntry.c (99%) rename lib/vfs/{mc-vfs => }/gc.c (99%) rename lib/vfs/{mc-vfs => }/gc.h (98%) delete mode 100644 lib/vfs/mc-vfs/.gitignore delete mode 100644 lib/vfs/mc-vfs/Makefile.am delete mode 100644 lib/vfs/mc-vfs/fish/README.fish~HEAD delete mode 100644 lib/vfs/mc-vfs/vfs-impl.h rename lib/vfs/{mc-vfs => }/netutil.c (100%) rename lib/vfs/{mc-vfs => }/netutil.h (100%) rename lib/vfs/{mc-vfs => }/utilvfs.c (99%) rename lib/vfs/{mc-vfs => }/utilvfs.h (100%) rename lib/vfs/{mc-vfs => }/vfs.c (94%) rename lib/vfs/{mc-vfs => }/vfs.h (63%) rename lib/vfs/{mc-vfs => }/xdirentry.h (100%) create mode 100644 src/vfs/COPYING.LGPL create mode 100644 src/vfs/Makefile.am create mode 100644 src/vfs/cpio/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/cpio}/cpio.c (99%) create mode 100644 src/vfs/cpio/cpio.h create mode 100644 src/vfs/extfs/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/extfs}/extfs.c (99%) create mode 100644 src/vfs/extfs/extfs.h rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/.gitignore (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/Makefile.am (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/README (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/README.extfs (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/README.it (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/README.uzip (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/a+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/apt+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/audio.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/bpp (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/deb.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/deba.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/debd.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/dpkg+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/hp48+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/iso9660.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/lslR.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/mailfs.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/patchfs.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/rpm (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/rpms+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/s3+.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/sfs.ini (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/trpm (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/u7z (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uace.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/ualz.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uar.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uarc.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uarj.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uc1541.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/ucab (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uha.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/ulha.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/urar.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uzip.in (100%) rename {lib/vfs/mc-vfs/extfs => src/vfs/extfs/helpers}/uzoo.in (100%) create mode 100644 src/vfs/fish/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/fish}/fish.c (99%) rename {lib/vfs/mc-vfs => src/vfs/fish}/fish.h (97%) rename {lib/vfs/mc-vfs => src/vfs/fish}/fishdef.h (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/Makefile.am (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/README.fish (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/append (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/chmod (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/chown (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/fexists (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/get (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/hardlink (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/info (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/ln (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/ls (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/mkdir (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/mv (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/rmdir (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/send (100%) rename {lib/vfs/mc-vfs/fish => src/vfs/fish/helpers}/unlink (100%) create mode 100644 src/vfs/ftpfs/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/ftpfs}/ftpfs.c (99%) rename {lib/vfs/mc-vfs => src/vfs/ftpfs}/ftpfs.h (100%) create mode 100644 src/vfs/local/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/local}/local.c (99%) rename {lib/vfs/mc-vfs => src/vfs/local}/local.h (97%) create mode 100644 src/vfs/plugins_init.c create mode 100644 src/vfs/plugins_init.h create mode 100644 src/vfs/sfs/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/sfs}/sfs.c (98%) create mode 100644 src/vfs/sfs/sfs.h create mode 100644 src/vfs/smbfs/Makefile.am rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/Makefile.in (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/aclocal.m4 (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/configure.ac (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/byteorder.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/charset.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/client.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/includes.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/kanji.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/local.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/nameserv.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/nterr.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/proto.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/smb.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/trans2.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/include/version.h (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/internals.doc (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/charcnv.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/charset.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/debug.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/interface.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/kanji.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/md4.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/netmask.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/slprintf.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/system.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/time.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/username.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/util.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/util_file.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/util_sock.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/lib/util_str.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/clientgen.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/namequery.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/nmblib.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/nterr.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/pwd_cache.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/smbdes.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/smbencrypt.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/libsmb/smberr.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/param/loadparm.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/param/params.c (100%) rename {lib/vfs/mc-vfs/samba => src/vfs/smbfs/helpers}/parsing.doc (100%) rename {lib/vfs/mc-vfs => src/vfs/smbfs}/smbfs.c (99%) rename {lib/vfs/mc-vfs => src/vfs/smbfs}/smbfs.h (100%) create mode 100644 src/vfs/tar/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/tar}/tar.c (99%) create mode 100644 src/vfs/tar/tar.h create mode 100644 src/vfs/undelfs/Makefile.am rename {lib/vfs/mc-vfs => src/vfs/undelfs}/undelfs.c (99%) create mode 100644 src/vfs/undelfs/undelfs.h diff --git a/autogen.sh b/autogen.sh index cc4a88437..f1453c32e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -29,7 +29,7 @@ fi cd "$srcdir" # The autoconf cache (version after 2.52) is not reliable yet. -rm -rf autom4te.cache lib/vfs/mc-vfs/samba/autom4te.cache +rm -rf autom4te.cache src/vfs/smbfs/helpers/autom4te.cache if test ! -d config; then mkdir config @@ -72,16 +72,16 @@ $AUTOMAKE -a test -f Makefile.in || \ { echo "automake failed to generate Makefile.in" >&2; exit 1; } -cd lib/vfs/mc-vfs/samba +cd src/vfs/smbfs/helpers date -u >include/stamp-h.in $AUTOHEADER test -f include/config.h.in || \ - { echo "autoheader failed to generate lib/vfs/mc-vfs/samba/include/config.h.in" >&2; exit 1; } + { echo "autoheader failed to generate src/vfs/smbfs/helpers/include/config.h.in" >&2; exit 1; } $AUTOCONF test -f configure || \ - { echo "autoconf failed to generate lib/vfs/mc-vfs/samba/configure" >&2; exit 1; } + { echo "autoconf failed to generate src/vfs/smbfs/helpers/configure" >&2; exit 1; } ) || exit 1 $srcdir/maint/version.sh "$srcdir" diff --git a/configure.ac b/configure.ac index 354ed9069..24a297ec4 100644 --- a/configure.ac +++ b/configure.ac @@ -542,6 +542,53 @@ src/viewer/Makefile src/diffviewer/Makefile src/filemanager/Makefile +src/vfs/Makefile + +src/vfs/cpio/Makefile + +src/vfs/extfs/Makefile +src/vfs/extfs/helpers/Makefile +src/vfs/extfs/helpers/a+ +src/vfs/extfs/helpers/apt+ +src/vfs/extfs/helpers/audio +src/vfs/extfs/helpers/deb +src/vfs/extfs/helpers/deba +src/vfs/extfs/helpers/debd +src/vfs/extfs/helpers/dpkg+ +src/vfs/extfs/helpers/iso9660 +src/vfs/extfs/helpers/hp48+ +src/vfs/extfs/helpers/lslR +src/vfs/extfs/helpers/mailfs +src/vfs/extfs/helpers/patchfs +src/vfs/extfs/helpers/rpms+ +src/vfs/extfs/helpers/s3+ +src/vfs/extfs/helpers/uace +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/uha +src/vfs/extfs/helpers/ulha +src/vfs/extfs/helpers/urar +src/vfs/extfs/helpers/uzip +src/vfs/extfs/helpers/uzoo + +src/vfs/fish/Makefile +src/vfs/fish/helpers/Makefile + +src/vfs/ftpfs/Makefile + +src/vfs/local/Makefile + +src/vfs/sfs/Makefile + +src/vfs/smbfs/Makefile + +src/vfs/tar/Makefile + +src/vfs/undelfs/Makefile + lib/Makefile lib/event/Makefile lib/filehighlight/Makefile @@ -550,35 +597,9 @@ lib/search/Makefile lib/skin/Makefile lib/strutil/Makefile lib/tty/Makefile + lib/vfs/Makefile -lib/vfs/mc-vfs/Makefile -lib/vfs/mc-vfs/extfs/Makefile -lib/vfs/mc-vfs/extfs/a+ -lib/vfs/mc-vfs/extfs/apt+ -lib/vfs/mc-vfs/extfs/audio -lib/vfs/mc-vfs/extfs/deb -lib/vfs/mc-vfs/extfs/deba -lib/vfs/mc-vfs/extfs/debd -lib/vfs/mc-vfs/extfs/dpkg+ -lib/vfs/mc-vfs/extfs/iso9660 -lib/vfs/mc-vfs/extfs/hp48+ -lib/vfs/mc-vfs/extfs/lslR -lib/vfs/mc-vfs/extfs/mailfs -lib/vfs/mc-vfs/extfs/patchfs -lib/vfs/mc-vfs/extfs/rpms+ -lib/vfs/mc-vfs/extfs/s3+ -lib/vfs/mc-vfs/extfs/uace -lib/vfs/mc-vfs/extfs/ualz -lib/vfs/mc-vfs/extfs/uar -lib/vfs/mc-vfs/extfs/uarc -lib/vfs/mc-vfs/extfs/uarj -lib/vfs/mc-vfs/extfs/uc1541 -lib/vfs/mc-vfs/extfs/uha -lib/vfs/mc-vfs/extfs/ulha -lib/vfs/mc-vfs/extfs/urar -lib/vfs/mc-vfs/extfs/uzip -lib/vfs/mc-vfs/extfs/uzoo -lib/vfs/mc-vfs/fish/Makefile + lib/widget/Makefile misc/syntax/Makefile diff --git a/lib/Makefile.am b/lib/Makefile.am index c538010cc..9a99991d7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -48,5 +48,5 @@ libmc_la_LIBADD = \ strutil/libmcstrutil.la \ skin/libmcskin.la \ tty/libmctty.la \ - vfs/mc-vfs/libvfs-mc.la \ + vfs/libmcvfs.la \ widget/libmcwidget.la diff --git a/lib/lock.c b/lib/lock.c index 4d32d464c..e9f39a1b9 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -53,7 +53,7 @@ #include #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" /* tilde_expand() */ #include "lib/lock.h" #include "lib/widget.h" /* query_dialog() */ diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index a411af0ca..893a2ab02 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -26,7 +26,7 @@ #include /* extern int errno */ #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" /* mc_stat */ +#include "lib/vfs/vfs.h" /* mc_stat */ #include "lib/util.h" #include "lib/mcconfig.h" diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index dba27ee31..abcf9decc 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -32,7 +32,7 @@ #include "lib/global.h" #include "lib/mcconfig.h" #include "lib/fileloc.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" /*** global variables ****************************************************************************/ diff --git a/lib/tty/key.c b/lib/tty/key.c index 90ba5a70a..23910149f 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -40,7 +40,7 @@ #include "lib/global.h" #include "lib/strutil.h" /* str_casecmp */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "tty.h" #include "tty-internal.h" /* mouse_enabled */ diff --git a/lib/util.c b/lib/util.c index dcca29dd8..7bd8b46e5 100644 --- a/lib/util.c +++ b/lib/util.c @@ -44,7 +44,7 @@ #include "lib/tty/win.h" /* xterm_flag */ #include "lib/mcconfig.h" #include "lib/fileloc.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/lib/utilunix.c b/lib/utilunix.c index 5d0a207b8..b81be0896 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -52,7 +52,7 @@ #include #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" /* VFS_ENCODING_PREFIX */ +#include "lib/vfs/vfs.h" /* VFS_ENCODING_PREFIX */ #include "lib/strutil.h" /* str_move() */ #include "lib/util.h" #include "lib/widget.h" /* message() */ diff --git a/lib/vfs/mc-vfs/COPYING.LGPL b/lib/vfs/COPYING.LGPL similarity index 99% rename from lib/vfs/mc-vfs/COPYING.LGPL rename to lib/vfs/COPYING.LGPL index aaf66af27..c0c8d1303 100644 --- a/lib/vfs/mc-vfs/COPYING.LGPL +++ b/lib/vfs/COPYING.LGPL @@ -9,7 +9,7 @@ covered by the terms of the GNU GPL. Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -470,8 +470,8 @@ convey the exclusion of warranty; and each file should have at least the Library General Public License for more details. You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + License along with this library; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. diff --git a/lib/vfs/mc-vfs/HACKING b/lib/vfs/HACKING similarity index 99% rename from lib/vfs/mc-vfs/HACKING rename to lib/vfs/HACKING index 9d616bb92..4916a47cb 100644 --- a/lib/vfs/mc-vfs/HACKING +++ b/lib/vfs/HACKING @@ -84,7 +84,7 @@ smbfs no yes no no undelfs no yes no yes -"*" means that this property should change during further development. +"*" means that this property should change during further development. Mapping from inode to entry prevents implementing hard links. It is permissible for directories, which cannot be hardlinked. Not loading the full tree speeds up access to large archives and conserves memory. diff --git a/lib/vfs/Makefile.am b/lib/vfs/Makefile.am index 95587f654..8a1686f87 100644 --- a/lib/vfs/Makefile.am +++ b/lib/vfs/Makefile.am @@ -1 +1,15 @@ -SUBDIRS = mc-vfs +noinst_LTLIBRARIES = libmcvfs.la + +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) + +libmcvfs_la_SOURCES = \ + vfs.c vfs.h \ + direntry.c xdirentry.h \ + utilvfs.c utilvfs.h \ + gc.c gc.h + +if ENABLE_VFS_NET +libmcvfs_la_SOURCES += netutil.c netutil.h +endif + +EXTRA_DIST = HACKING README diff --git a/lib/vfs/mc-vfs/README b/lib/vfs/README similarity index 100% rename from lib/vfs/mc-vfs/README rename to lib/vfs/README diff --git a/lib/vfs/mc-vfs/direntry.c b/lib/vfs/direntry.c similarity index 99% rename from lib/vfs/mc-vfs/direntry.c rename to lib/vfs/direntry.c index 314696be1..4cdabd2e0 100644 --- a/lib/vfs/mc-vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -47,7 +47,7 @@ #include "src/filemanager/layout.h" /* print_vfs_message */ -#include "vfs-impl.h" +#include "vfs.h" #include "utilvfs.h" #include "xdirentry.h" #include "gc.h" /* vfs_rmstamp */ diff --git a/lib/vfs/mc-vfs/gc.c b/lib/vfs/gc.c similarity index 99% rename from lib/vfs/mc-vfs/gc.c rename to lib/vfs/gc.c index d789c3a54..952c1e268 100644 --- a/lib/vfs/mc-vfs/gc.c +++ b/lib/vfs/gc.c @@ -47,7 +47,7 @@ #include "src/filemanager/midnight.h" /* current_panel */ #include "src/filemanager/layout.h" /* get_current_type(), get_other_type() */ -#include "vfs-impl.h" +#include "vfs.h" #include "utilvfs.h" #include "gc.h" diff --git a/lib/vfs/mc-vfs/gc.h b/lib/vfs/gc.h similarity index 98% rename from lib/vfs/mc-vfs/gc.h rename to lib/vfs/gc.h index 8d6262d72..ef851224e 100644 --- a/lib/vfs/mc-vfs/gc.h +++ b/lib/vfs/gc.h @@ -6,7 +6,7 @@ #ifndef MC__VFS_GC_H #define MC__VFS_GC_H -#include "vfs-impl.h" +#include "vfs.h" /*** typedefs(not structures) and defined constants **********************************************/ diff --git a/lib/vfs/mc-vfs/.gitignore b/lib/vfs/mc-vfs/.gitignore deleted file mode 100644 index e6be0ac64..000000000 --- a/lib/vfs/mc-vfs/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -Makefile -Makefile.in -mcserv -mcservx -rar -cpio -zoo -zip -lha -.deps -*.sor diff --git a/lib/vfs/mc-vfs/Makefile.am b/lib/vfs/mc-vfs/Makefile.am deleted file mode 100644 index f890b0de7..000000000 --- a/lib/vfs/mc-vfs/Makefile.am +++ /dev/null @@ -1,152 +0,0 @@ -if ENABLE_VFS_SMB -SAMBA_CFLAGS = -DCONFIGDIR=\""@smbconfigdir@"\" -SAMBA_SUBDIRS = samba -endif - -DIST_SUBDIRS = extfs fish - -SUBDIRS = $(SAMBA_SUBDIRS) -if ENABLE_VFS_EXTFS -SUBDIRS += extfs -endif -if ENABLE_VFS_FISH -SUBDIRS += fish -endif - -AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) $(SAMBA_CFLAGS) - -AM_CPPFLAGS = -DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\" - -BASICFILES = \ - vfs.c vfs.h vfs-impl.h \ - direntry.c xdirentry.h \ - utilvfs.c utilvfs.h \ - gc.c gc.h \ - local.c local.h - -CPIOFILES = cpio.c -TARFILES = tar.c -SFSFILES = sfs.c -EXTFSFILES = extfs.c -UNDELFILES = undelfs.c - -NETFILES = netutil.c netutil.h - -FTPFILES = ftpfs.c ftpfs.h -FISHFILES = fish.c fish.h fishdef.h -SMBFILES = smbfs.c smbfs.h - -libvfs_mc_la_SOURCES = $(BASICFILES) -if ENABLE_VFS_CPIO -libvfs_mc_la_SOURCES += $(CPIOFILES) -endif -if ENABLE_VFS_TAR -libvfs_mc_la_SOURCES += $(TARFILES) -endif -if ENABLE_VFS_SFS -libvfs_mc_la_SOURCES += $(SFSFILES) -endif -if ENABLE_VFS_EXTFS -libvfs_mc_la_SOURCES += $(EXTFSFILES) -endif -if ENABLE_VFS_UNDELFS -libvfs_mc_la_SOURCES += $(UNDELFILES) -endif -if ENABLE_VFS_NET -libvfs_mc_la_SOURCES += $(NETFILES) -endif -if ENABLE_VFS_FTP -libvfs_mc_la_SOURCES += $(FTPFILES) -endif -if ENABLE_VFS_FISH -libvfs_mc_la_SOURCES += $(FISHFILES) -endif -if ENABLE_VFS_SMB -libvfs_mc_la_SOURCES += $(SMBFILES) -endif - -EXTRA_DIST = HACKING README \ - $(BASICFILES) \ - $(CPIOFILES) \ - $(TARFILES) \ - $(SFSFILES) \ - $(EXTFSFILES) \ - $(UNDELFILES) \ - $(NETFILES) \ - $(FTPFILES) \ - $(FISHFILES) \ - $(SMBFILES) - -dist-hook: - $(mkinstalldirs) $(distdir)/samba - $(mkinstalldirs) $(distdir)/samba/include - $(mkinstalldirs) $(distdir)/samba/lib - $(mkinstalldirs) $(distdir)/samba/libsmb - $(mkinstalldirs) $(distdir)/samba/param - for I in $(SAMBA_DIST); do \ - cp -p $(srcdir)/samba/$$I $(distdir)/samba/$$I || exit 1; \ - done - -mostlyclean-local: - if test -f samba/Makefile; then \ - (cd samba && $(MAKE) mostlyclean) \ - else :; fi - -clean-local: - if test -f samba/Makefile; then \ - (cd samba && $(MAKE) clean) \ - else :; fi - -distclean-local: - if test -f samba/Makefile; then \ - (cd samba && $(MAKE) distclean) \ - else :; fi - -noinst_LTLIBRARIES = libvfs-mc.la - -SAMBA_DIST = \ - Makefile.in \ - aclocal.m4 \ - configure.ac \ - configure \ - internals.doc \ - parsing.doc \ - include/byteorder.h \ - include/charset.h \ - include/client.h \ - include/config.h.in \ - include/includes.h \ - include/kanji.h \ - include/local.h \ - include/nameserv.h \ - include/nterr.h \ - include/proto.h \ - include/smb.h \ - include/stamp-h.in \ - include/trans2.h \ - include/version.h \ - lib/charcnv.c \ - lib/charset.c \ - lib/debug.c \ - lib/interface.c \ - lib/kanji.c \ - lib/md4.c \ - lib/netmask.c \ - lib/slprintf.c \ - lib/system.c \ - lib/time.c \ - lib/username.c \ - lib/util.c \ - lib/util_file.c \ - lib/util_sock.c \ - lib/util_str.c \ - libsmb/clientgen.c \ - libsmb/namequery.c \ - libsmb/nmblib.c \ - libsmb/nterr.c \ - libsmb/pwd_cache.c \ - libsmb/smbdes.c \ - libsmb/smbencrypt.c \ - libsmb/smberr.c \ - param/loadparm.c \ - param/params.c diff --git a/lib/vfs/mc-vfs/fish/README.fish~HEAD b/lib/vfs/mc-vfs/fish/README.fish~HEAD deleted file mode 100644 index 10b07770f..000000000 --- a/lib/vfs/mc-vfs/fish/README.fish~HEAD +++ /dev/null @@ -1,178 +0,0 @@ - - FIles transferred over SHell protocol (V 0.0.2) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -This protocol was designed for transferring files over a remote shell -connection (rsh and compatibles). It can be as well used for transfers over -rsh, and there may be other uses. - -Client sends requests of following form: - -#FISH_COMMAND -equivalent shell commands, -which may be multiline - -Only fish commands are defined here, shell equivalents are for your -information only and will probably vary from implementation to -implementation. Fish commands always have priority: server is -expected to execute fish command if it understands it. If it does not, -however, it can try the luck and execute shell command. - -Server's reply is multiline, but always ends with - -### 000 - -line. ### is prefix to mark this line, 000 is return code. Return -codes are superset to those used in ftp. - -There are few new exit codes defined: - -000 don't know; if there were no previous lines, this marks COMPLETE -success, if they were, it marks failure. - -001 don't know; if there were no previous lines, this marks -PRELIMinary success, if they were, it marks failure - - Connecting - ~~~~~~~~~~ -Client uses "echo FISH:;/bin/sh" as command executed on remote -machine. This should make it possible for server to distinguish FISH -connections from normal rsh/ssh. - - Commands - ~~~~~~~~ -#FISH -echo; start_fish_server; echo '### 200' - -This command is sent at the beginning. It marks that client wishes to -talk via FISH protocol. #VER command must follow. If server -understands FISH protocol, it has option to put FISH server somewhere -on system path and name it start_fish_server. - -#VER 0.0.2 <...> -echo '### 000' - -This command is the second one. It sends client version and extensions -to the server. Server should reply with protocol version to be used, -and list of extensions accepted. - -VER 0.0.0 -### 200 - -#PWD -pwd; echo '### 200' - -Server should reply with current directory (in form /abc/def/ghi) -followed by line indicating success. - -#LIST /directory -ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g -S$s -d$m $d $y -:$n -"; done ) -ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g -E$a$i -dD$m $d $y -:$n -"; done ) -echo '### 200' - -This allows client to list directory or get status information about -single file. Output is in following form (any line except : -may be omitted): - -P . -S -d<3-letters month name> -D [.1234] -E, -: -L - - -Unix permissions are of form X--------- where X is type of -file. Currently, '-' means regular file, 'd' means directory, 'c', 'b' -means character and block device, 'l' means symbolic link, 'p' means -FIFO and 's' means socket. - -'d' has three fields: month (one of strings Jan Feb Mar Apr May Jun -Jul Aug Sep Oct Nov Dec), day of month, and third is either single -number indicating year, or HH:MM field (assume current year in such -case). As you've probably noticed, this is pretty broken; it is for -compatibility with ls listing. - -#RETR /some/name -ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200' - -Server sends line with filesize on it, followed by line with ### 100 -indicating partial success, then it sends binary data (exactly -filesize bytes) and follows them with (with no preceding newline) ### -200. - -Note that there's no way to abort running RETR command - except -closing the connection. - -#STOR /file/name -> /file/name; echo '### 001'; ( dd bs=4096 count=; dd bs= count=1 ) 2>/dev/null | ( cat > %s; cat > /dev/null ); echo '### 200' - -This command is for storing /file/name, which is exactly size bytes -big. You probably think I went crazy. Well, I did not: that strange -cat > /dev/null has purpose to discard any extra data which was not -written to disk (due to for example out of space condition). - -[Why? Imagine uploading file with "rm -rf /" line in it.] - -#CWD /somewhere -cd /somewhere; echo '### 000' - -It is specified here, but I'm not sure how wise idea is to use this -one: it breaks stateless-ness of the protocol. - -Following commands should be rather self-explanatory: - -#CHMOD 1234 file -chmod 1234 file; echo '### 000' - -#DELE /some/path -rm -f /some/path; echo '### 000' - -#MKD /some/path -mkdir /some/path; echo '### 000' - -#RMD /some/path -rmdir /some/path; echo '### 000' - -#RENAME /path/a /path/b -mv /path/a /path/b; echo '### 000' - -#LINK /path/a /path/b -ln /path/a /path/b; echo '### 000' - -#SYMLINK /path/a /path/b -ln -s /path/a /path/b; echo '### 000' - -#CHOWN user /file/name -chown user /file/name; echo '### 000' - -#CHGRP group /file/name -chgrp group /file/name; echo '### 000' - -#READ /path/and/filename -cat /path/and/filename | ( dd bs=4096 count= > /dev/null; -dd bs= count=1 > /dev/null; -dd bs=4096 count=; -dd bs= count=1; ) - -Returns ### 200 on successful exit, ### 291 on successful exit when -reading ended at eof, ### 292 on successfull exit when reading did not -end at eof. - -#WRITE /path/and/filename - -Hmm, shall we define these ones if we know our client is not going to -use them? - - -That's all, folks! - pavel@ucw.cz diff --git a/lib/vfs/mc-vfs/vfs-impl.h b/lib/vfs/mc-vfs/vfs-impl.h deleted file mode 100644 index 235aa4acc..000000000 --- a/lib/vfs/mc-vfs/vfs-impl.h +++ /dev/null @@ -1,147 +0,0 @@ - -/** - * \file - * \brief Header: VFS implemntation (?) - */ - -#ifndef MC__VFS_IMPL_H -#define MC__VFS_IMPL_H - -#include -#include -#include -#include -#include -#include -#include - -#include "vfs.h" -#include "lib/fs.h" /* MC_MAXPATHLEN */ - -/*** typedefs(not structures) and defined constants **********************************************/ - -typedef void *vfsid; - -/*** enums ***************************************************************************************/ - -/*** structures declarations (and typedefs of structures)*****************************************/ - -struct vfs_stamping; - -struct vfs_class -{ - struct vfs_class *next; - const char *name; /* "FIles over SHell" */ - vfs_class_flags_t flags; - const char *prefix; /* "fish:" */ - void *data; /* this is for filesystem's own use */ - int verrno; /* can't use errno because glibc2 might define errno as function */ - - int (*init) (struct vfs_class * me); - void (*done) (struct vfs_class * me); - - /** - * The fill_names method shall call the callback function for every - * filesystem name that this vfs module supports. - */ - void (*fill_names) (struct vfs_class * me, fill_names_f); - - /** - * The which() method shall return the index of the vfs subsystem - * or -1 if this vfs cannot handle the given pathname. - */ - int (*which) (struct vfs_class * me, const char *path); - - void *(*open) (struct vfs_class * me, const char *fname, int flags, mode_t mode); - int (*close) (void *vfs_info); - ssize_t (*read) (void *vfs_info, char *buffer, size_t count); - ssize_t (*write) (void *vfs_info, const char *buf, size_t count); - - void *(*opendir) (struct vfs_class * me, const char *dirname); - void *(*readdir) (void *vfs_info); - int (*closedir) (void *vfs_info); - - int (*stat) (struct vfs_class * me, const char *path, struct stat * buf); - int (*lstat) (struct vfs_class * me, const char *path, struct stat * buf); - int (*fstat) (void *vfs_info, struct stat * buf); - - int (*chmod) (struct vfs_class * me, const char *path, int mode); - int (*chown) (struct vfs_class * me, const char *path, uid_t owner, gid_t group); - int (*utime) (struct vfs_class * me, const char *path, struct utimbuf * times); - - int (*readlink) (struct vfs_class * me, const char *path, char *buf, size_t size); - int (*symlink) (struct vfs_class * me, const char *n1, const char *n2); - int (*link) (struct vfs_class * me, const char *p1, const char *p2); - int (*unlink) (struct vfs_class * me, const char *path); - int (*rename) (struct vfs_class * me, const char *p1, const char *p2); - int (*chdir) (struct vfs_class * me, const char *path); - int (*ferrno) (struct vfs_class * me); - off_t (*lseek) (void *vfs_info, off_t offset, int whence); - int (*mknod) (struct vfs_class * me, const char *path, mode_t mode, dev_t dev); - - vfsid (*getid) (struct vfs_class * me, const char *path); - - int (*nothingisopen) (vfsid id); - void (*free) (vfsid id); - - char *(*getlocalcopy) (struct vfs_class * me, const char *filename); - int (*ungetlocalcopy) (struct vfs_class * me, const char *filename, - const char *local, int has_changed); - - int (*mkdir) (struct vfs_class * me, const char *path, mode_t mode); - int (*rmdir) (struct vfs_class * me, const char *path); - - int (*ctl) (void *vfs_info, int ctlop, void *arg); - int (*setctl) (struct vfs_class * me, const char *path, int ctlop, void *arg); -}; - -/* - * This union is used to ensure that there is enough space for the - * filename (d_name) when the dirent structure is created. - */ -union vfs_dirent -{ - struct dirent dent; - char _extra_buffer[offsetof (struct dirent, d_name) + MC_MAXPATHLEN + 1]; -}; - -/*** global variables defined in .c file *********************************************************/ - -/*** declarations of public functions ************************************************************/ - - -/* Register a file system class */ -int vfs_register_class (struct vfs_class *vfs); - -struct vfs_class *vfs_split (char *path, char **inpath, char **op); -char *vfs_path (const char *path); - -/* vfs/direntry.c: */ -void *vfs_s_open (struct vfs_class *me, const char *file, int flags, mode_t mode); - -vfsid vfs_getid (struct vfs_class *vclass, const char *dir); - -#ifdef ENABLE_VFS_CPIO -void init_cpiofs (void); -#endif -#ifdef ENABLE_VFS_TAR -void init_tarfs (void); -#endif -#ifdef ENABLE_VFS_SFS -void init_sfs (void); -#endif -#ifdef ENABLE_VFS_EXTFS -void init_extfs (void); -#endif -#ifdef ENABLE_VFS_UNDELFS -void init_undelfs (void); -#endif -#ifdef ENABLE_VFS_FTP -void init_ftpfs (void); -#endif -#ifdef ENABLE_VFS_FISH -void init_fish (void); -#endif - -/*** inline functions ****************************************************************************/ -#endif /* MC_VFS_IMPL_H */ diff --git a/lib/vfs/mc-vfs/netutil.c b/lib/vfs/netutil.c similarity index 100% rename from lib/vfs/mc-vfs/netutil.c rename to lib/vfs/netutil.c diff --git a/lib/vfs/mc-vfs/netutil.h b/lib/vfs/netutil.h similarity index 100% rename from lib/vfs/mc-vfs/netutil.h rename to lib/vfs/netutil.h diff --git a/lib/vfs/mc-vfs/utilvfs.c b/lib/vfs/utilvfs.c similarity index 99% rename from lib/vfs/mc-vfs/utilvfs.c rename to lib/vfs/utilvfs.c index ab4cbdf3a..3d2ba162e 100644 --- a/lib/vfs/mc-vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -42,7 +42,7 @@ #include "src/history.h" -#include "vfs-impl.h" +#include "vfs.h" #include "utilvfs.h" /*** global variables ****************************************************************************/ diff --git a/lib/vfs/mc-vfs/utilvfs.h b/lib/vfs/utilvfs.h similarity index 100% rename from lib/vfs/mc-vfs/utilvfs.h rename to lib/vfs/utilvfs.h diff --git a/lib/vfs/mc-vfs/vfs.c b/lib/vfs/vfs.c similarity index 94% rename from lib/vfs/mc-vfs/vfs.c rename to lib/vfs/vfs.c index a539a4343..aa02bde5f 100644 --- a/lib/vfs/mc-vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -60,22 +60,10 @@ #endif #include "src/setup.h" /* cd_symlinks */ -#include "vfs-impl.h" +#include "vfs.h" #include "utilvfs.h" #include "gc.h" -#ifdef ENABLE_VFS_NET -#include "netutil.h" -#endif -#ifdef ENABLE_VFS_FTP -#include "ftpfs.h" -#endif -#ifdef ENABLE_VFS_SMB -#include "smbfs.h" -#endif - -#include "local.h" - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -112,10 +100,9 @@ static char *current_dir; static GPtrArray *vfs_openfiles; static long vfs_free_handle_list = -1; -static struct vfs_class *localfs_class; static GString *vfs_str_buffer; -static struct vfs_class *vfs_list; +static GPtrArray *vfs_list = NULL; static struct dirent *mc_readdir_result = NULL; @@ -240,20 +227,23 @@ vfs_free_handle (int handle) static struct vfs_class * vfs_prefix_to_class (char *prefix) { - struct vfs_class *vfs; + guint i; - /* Avoid last class (localfs) that would accept any prefix */ - for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next) + /* Avoid first class (localfs) that would accept any prefix */ + for (i = 1; i < vfs_list->len; i++) { + struct vfs_class *vfs = (struct vfs_class *) g_ptr_array_index (vfs_list, i); if (vfs->which != NULL) { - if ((*vfs->which) (vfs, prefix) == -1) + if (vfs->which (vfs, prefix) == -1) continue; return vfs; } + if (vfs->prefix != NULL && strncmp (prefix, vfs->prefix, strlen (vfs->prefix)) == 0) return vfs; } + return NULL; } @@ -444,20 +434,6 @@ _vfs_get_cwd (void) /* --------------------------------------------------------------------------------------------- */ -static void -vfs_setup_wd (void) -{ - current_dir = g_strdup (PATH_SEP_STR); - _vfs_get_cwd (); - - if (strlen (current_dir) > MC_MAXPATHLEN - 2) - vfs_die ("Current dir too long.\n"); - - current_vfs = vfs_get_class (current_dir); -} - -/* --------------------------------------------------------------------------------------------- */ - static char * mc_def_getlocalcopy (const char *filename) { @@ -562,17 +538,16 @@ mc_def_ungetlocalcopy (struct vfs_class *vfs, const char *filename, /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -int -vfs_register_class (struct vfs_class *vfs) +gboolean +vfs_register_class (struct vfs_class * vfs) { if (vfs->init != NULL) /* vfs has own initialization function */ - if (!(*vfs->init) (vfs)) /* but it failed */ - return 0; + if (!vfs->init (vfs)) /* but it failed */ + return FALSE; - vfs->next = vfs_list; - vfs_list = vfs; + g_ptr_array_add (vfs_list, vfs); - return 1; + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -584,7 +559,7 @@ vfs_register_class (struct vfs_class *vfs) char * vfs_strip_suffix_from_filename (const char *filename) { - struct vfs_class *vfs; + guint i; char *semi; char *p; @@ -596,20 +571,23 @@ vfs_strip_suffix_from_filename (const char *filename) if (semi == NULL) return p; - /* Avoid last class (localfs) that would accept any prefix */ - for (vfs = vfs_list; vfs->next != NULL; vfs = vfs->next) + /* Avoid first class (localfs) that would accept any prefix */ + for (i = 1; i < vfs_list->len; i++) { + struct vfs_class *vfs = (struct vfs_class *) g_ptr_array_index (vfs_list, i); + if (vfs->which != NULL) { - if ((*vfs->which) (vfs, semi + 1) == -1) + if (vfs->which (vfs, semi + 1) == -1) continue; *semi = '\0'; /* Found valid suffix */ - return p; + break; } + if (vfs->prefix != NULL && strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix)) == 0) { *semi = '\0'; /* Found valid suffix */ - return p; + break; } } return p; @@ -678,14 +656,15 @@ vfs_split (char *path, char **inpath, char **op) struct vfs_class * vfs_get_class (const char *pathname) { + char *path; struct vfs_class *vfs; - char *path = g_strdup (pathname); + path = g_strdup (pathname); vfs = _vfs_get_class (path); g_free (path); - if (!vfs) - vfs = localfs_class; + if (vfs == NULL) + vfs = g_ptr_array_index (vfs_list, 0); /* localfs */ return vfs; } @@ -1440,42 +1419,28 @@ mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed) void vfs_init (void) { + /* create the VFS handle arrays */ + vfs_list = g_ptr_array_new (); + /* create the VFS handle array */ vfs_openfiles = g_ptr_array_new (); vfs_str_buffer = g_string_new (""); - /* localfs needs to be the first one */ - init_localfs (); - /* fallback value for vfs_get_class() */ - localfs_class = vfs_list; -#ifdef ENABLE_VFS_CPIO - init_cpiofs (); -#endif /* ENABLE_VFS_CPIO */ -#ifdef ENABLE_VFS_TAR - init_tarfs (); -#endif /* ENABLE_VFS_TAR */ -#ifdef ENABLE_VFS_SFS - init_sfs (); -#endif /* ENABLE_VFS_SFS */ -#ifdef ENABLE_VFS_EXTFS - init_extfs (); -#endif /* ENABLE_VFS_EXTFS */ -#ifdef ENABLE_VFS_UNDELFS - init_undelfs (); -#endif /* ENABLE_VFS_UNDELFS */ +} -#ifdef ENABLE_VFS_FTP - init_ftpfs (); -#endif /* ENABLE_VFS_FTP */ -#ifdef ENABLE_VFS_FISH - init_fish (); -#endif /* ENABLE_VFS_FISH */ -#ifdef ENABLE_VFS_SMB - init_smbfs (); -#endif /* ENABLE_VFS_SMB */ +/* --------------------------------------------------------------------------------------------- */ - vfs_setup_wd (); +void +vfs_setup_work_dir (void) +{ + current_dir = g_strdup (PATH_SEP_STR); + _vfs_get_cwd (); + + if (strlen (current_dir) > MC_MAXPATHLEN - 2) + vfs_die ("Current dir too long.\n"); + + current_vfs = vfs_get_class (current_dir); } /* --------------------------------------------------------------------------------------------- */ @@ -1483,17 +1448,22 @@ vfs_init (void) void vfs_shut (void) { - struct vfs_class *vfs; + guint i; vfs_gc_done (); g_free (current_dir); - for (vfs = vfs_list; vfs; vfs = vfs->next) - if (vfs->done) - (*vfs->done) (vfs); + for (i = 0; i < vfs_list->len; i++) + { + struct vfs_class *vfs = (struct vfs_class *) g_ptr_array_index (vfs_list, i); + + if (vfs->done != NULL) + vfs->done (vfs); + } g_ptr_array_free (vfs_openfiles, TRUE); + g_ptr_array_free (vfs_list, TRUE); g_string_free (vfs_str_buffer, TRUE); g_free (mc_readdir_result); } @@ -1507,11 +1477,15 @@ vfs_shut (void) void vfs_fill_names (fill_names_f func) { - struct vfs_class *vfs; + guint i; - for (vfs = vfs_list; vfs; vfs = vfs->next) - if (vfs->fill_names) - (*vfs->fill_names) (vfs, func); + for (i = 0; i < vfs_list->len; i++) + { + struct vfs_class *vfs = (struct vfs_class *) g_ptr_array_index (vfs_list, i); + + if (vfs->fill_names != NULL) + vfs->fill_names (vfs, func); + } } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/mc-vfs/vfs.h b/lib/vfs/vfs.h similarity index 63% rename from lib/vfs/mc-vfs/vfs.h rename to lib/vfs/vfs.h index 3d236ee25..cfc554e6d 100644 --- a/lib/vfs/mc-vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -8,11 +8,16 @@ #define MC__VFS_VFS_H #include +#include #include #include #include +#include +#include +#include #include "lib/global.h" +#include "lib/fs.h" /* MC_MAXPATHLEN */ /*** typedefs(not structures) and defined constants **********************************************/ @@ -87,6 +92,8 @@ typedef void (*fill_names_f) (const char *); +typedef void *vfsid; + /*** enums ***************************************************************************************/ /* Flags of VFS classes */ @@ -118,7 +125,81 @@ enum /*** structures declarations (and typedefs of structures)*****************************************/ -struct vfs_class; +typedef struct vfs_class +{ + const char *name; /* "FIles over SHell" */ + vfs_class_flags_t flags; + const char *prefix; /* "fish:" */ + void *data; /* this is for filesystem's own use */ + int verrno; /* can't use errno because glibc2 might define errno as function */ + + int (*init) (struct vfs_class * me); + void (*done) (struct vfs_class * me); + + /** + * The fill_names method shall call the callback function for every + * filesystem name that this vfs module supports. + */ + void (*fill_names) (struct vfs_class * me, fill_names_f); + + /** + * The which() method shall return the index of the vfs subsystem + * or -1 if this vfs cannot handle the given pathname. + */ + int (*which) (struct vfs_class * me, const char *path); + + void *(*open) (struct vfs_class * me, const char *fname, int flags, mode_t mode); + int (*close) (void *vfs_info); + ssize_t (*read) (void *vfs_info, char *buffer, size_t count); + ssize_t (*write) (void *vfs_info, const char *buf, size_t count); + + void *(*opendir) (struct vfs_class * me, const char *dirname); + void *(*readdir) (void *vfs_info); + int (*closedir) (void *vfs_info); + + int (*stat) (struct vfs_class * me, const char *path, struct stat * buf); + int (*lstat) (struct vfs_class * me, const char *path, struct stat * buf); + int (*fstat) (void *vfs_info, struct stat * buf); + + int (*chmod) (struct vfs_class * me, const char *path, int mode); + int (*chown) (struct vfs_class * me, const char *path, uid_t owner, gid_t group); + int (*utime) (struct vfs_class * me, const char *path, struct utimbuf * times); + + int (*readlink) (struct vfs_class * me, const char *path, char *buf, size_t size); + int (*symlink) (struct vfs_class * me, const char *n1, const char *n2); + int (*link) (struct vfs_class * me, const char *p1, const char *p2); + int (*unlink) (struct vfs_class * me, const char *path); + int (*rename) (struct vfs_class * me, const char *p1, const char *p2); + int (*chdir) (struct vfs_class * me, const char *path); + int (*ferrno) (struct vfs_class * me); + off_t (*lseek) (void *vfs_info, off_t offset, int whence); + int (*mknod) (struct vfs_class * me, const char *path, mode_t mode, dev_t dev); + + vfsid (*getid) (struct vfs_class * me, const char *path); + + int (*nothingisopen) (vfsid id); + void (*free) (vfsid id); + + char *(*getlocalcopy) (struct vfs_class * me, const char *filename); + int (*ungetlocalcopy) (struct vfs_class * me, const char *filename, + const char *local, int has_changed); + + int (*mkdir) (struct vfs_class * me, const char *path, mode_t mode); + int (*rmdir) (struct vfs_class * me, const char *path); + + int (*ctl) (void *vfs_info, int ctlop, void *arg); + int (*setctl) (struct vfs_class * me, const char *path, int ctlop, void *arg); +} vfs_class; + +/* + * This union is used to ensure that there is enough space for the + * filename (d_name) when the dirent structure is created. + */ +union vfs_dirent +{ + struct dirent dent; + char _extra_buffer[offsetof (struct dirent, d_name) + MC_MAXPATHLEN + 1]; +}; /*** global variables defined in .c file *********************************************************/ @@ -130,16 +211,26 @@ extern int use_netrc; /*** declarations of public functions ************************************************************/ +/* lib/vfs/direntry.c: */ +void *vfs_s_open (struct vfs_class *me, const char *file, int flags, mode_t mode); + +vfsid vfs_getid (struct vfs_class *vclass, const char *dir); + void vfs_init (void); void vfs_shut (void); +/* Register a file system class */ +gboolean vfs_register_class (struct vfs_class *vfs); +void vfs_setup_work_dir (void); void vfs_timeout_handler (void); int vfs_timeouts (void); void vfs_expire (int now); +char *vfs_get_current_dir (void); gboolean vfs_current_is_local (void); gboolean vfs_file_is_local (const char *filename); + ssize_t mc_read (int handle, void *buffer, size_t count); ssize_t mc_write (int handle, const void *buffer, size_t count); int mc_utime (const char *path, struct utimbuf *times); @@ -172,6 +263,9 @@ char *mc_getlocalcopy (const char *pathname); char *vfs_strip_suffix_from_filename (const char *filename); char *vfs_translate_url (const char *url); +struct vfs_class *vfs_split (char *path, char **inpath, char **op); +char *vfs_path (const char *path); + struct vfs_class *vfs_get_class (const char *path); vfs_class_flags_t vfs_file_class_flags (const char *filename); @@ -179,11 +273,14 @@ vfs_class_flags_t vfs_file_class_flags (const char *filename); * return static buffer */ const char *vfs_get_encoding (const char *path); -/* return new string */ -char *vfs_translate_path_n (const char *path); - /* canonize and translate path, return new string */ char *vfs_canon_and_translate (const char *path); +/* translate path back to terminal encoding, remove all #enc: + * every invalid character is replaced with question mark + * return static buffer */ +char *vfs_translate_path (const char *path); +/* return new string */ +char *vfs_translate_path_n (const char *path); void vfs_stamp_path (const char *path); @@ -191,11 +288,5 @@ void vfs_release_path (const char *dir); void vfs_fill_names (fill_names_f); -char *vfs_get_current_dir (void); -/* translate path back to terminal encoding, remove all #enc: - * every invalid character is replaced with question mark - * return static buffer */ -char *vfs_translate_path (const char *path); - /*** inline functions ****************************************************************************/ #endif /* MC_VFS_VFS_H */ diff --git a/lib/vfs/mc-vfs/xdirentry.h b/lib/vfs/xdirentry.h similarity index 100% rename from lib/vfs/mc-vfs/xdirentry.h rename to lib/vfs/xdirentry.h diff --git a/lib/widget/input.c b/lib/widget/input.c index ddd3afd88..47f6512d7 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -42,7 +42,7 @@ #include "lib/tty/tty.h" #include "lib/tty/mouse.h" #include "lib/tty/key.h" /* XCTRL and ALT macros */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/fileloc.h" #include "lib/skin.h" #include "lib/strutil.h" diff --git a/m4.include/vfs/mc-vfs-samba.m4 b/m4.include/vfs/mc-vfs-samba.m4 index ae3d6190b..b0812139e 100644 --- a/m4.include/vfs/mc-vfs-samba.m4 +++ b/m4.include/vfs/mc-vfs-samba.m4 @@ -19,7 +19,7 @@ AC_DEFUN([AC_MC_VFS_SMB], fi if test "$enable_vfs_smb" = "yes"; then - AC_CONFIG_SUBDIRS([lib/vfs/mc-vfs/samba]) + AC_CONFIG_SUBDIRS([src/vfs/smbfs/helpers]) AM_CONDITIONAL([ENABLE_VFS_SMB], [test "1" = "1"]) diff --git a/src/Makefile.am b/src/Makefile.am index 1a3992d25..2e36f2eac 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = filemanager man2hlp viewer +SUBDIRS = filemanager man2hlp vfs viewer if USE_EDIT SUBDIRS += editor @@ -34,6 +34,7 @@ DIFFLIB = diffviewer/libdiffviewer.la endif mc_LDADD = \ + vfs/libmc-vfs.la \ viewer/libmcviewer.la \ filemanager/libmcfilemanager.la \ $(DIFFLIB) $(EDITLIB) \ @@ -41,7 +42,7 @@ mc_LDADD = \ if ENABLE_VFS_SMB # this is a hack for linking with own samba library in simple way -mc_LDADD += ../lib/vfs/mc-vfs/samba/libsamba.a +mc_LDADD += vfs/smbfs/helpers/libsamba.a endif mc_LDADD += $(MCLIBS) $(SLANGLIB) diff --git a/src/args.c b/src/args.c index 9e4c81260..f08256985 100644 --- a/src/args.c +++ b/src/args.c @@ -33,12 +33,13 @@ #include "lib/tty/color.h" /* command_line_colors */ #include "lib/tty/mouse.h" #include "lib/strutil.h" -#include "lib/vfs/mc-vfs/vfs.h" -#ifdef ENABLE_VFS_SMB -#include "lib/vfs/mc-vfs/smbfs.h" /* smbfs_set_debugf() */ -#endif +#include "lib/vfs/vfs.h" #include "lib/util.h" /* x_basename() */ +#ifdef ENABLE_VFS_SMB +#include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */ +#endif + #include "src/main.h" #include "src/textconf.h" #include "src/subshell.h" /* use_subshell */ diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index dde6457a9..c02a9c377 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -38,7 +38,7 @@ #include "lib/tty/color.h" #include "lib/tty/key.h" #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ -#include "lib/vfs/mc-vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */ +#include "lib/vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */ #include "lib/util.h" #include "lib/widget.h" #include "lib/charsets.h" diff --git a/src/editor/edit.c b/src/editor/edit.c index 8513a9261..97008f62f 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -46,7 +46,7 @@ #include "lib/tty/tty.h" /* attrset() */ #include "lib/tty/key.h" /* is_idle() */ #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" /* utf string functions */ #include "lib/util.h" /* load_file_position(), save_file_position() */ #include "lib/timefmt.h" /* time formatting */ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index f537db5fc..13487d96e 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -53,7 +53,7 @@ #include "lib/strutil.h" /* utf string functions */ #include "lib/lock.h" #include "lib/util.h" /* tilde_expand() */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/widget.h" #include "lib/charsets.h" diff --git a/src/execute.c b/src/execute.c index 9d87ae571..bbdeba803 100644 --- a/src/execute.c +++ b/src/execute.c @@ -30,7 +30,7 @@ #include "lib/tty/tty.h" #include "lib/tty/key.h" #include "lib/tty/win.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index f390c5446..ae014ce9a 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -39,7 +39,7 @@ #include "lib/tty/key.h" /* XCTRL and ALT macros */ #include "lib/skin.h" #include "lib/strutil.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 2e0188ddc..6c7a53995 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -42,12 +42,12 @@ #include "lib/mcconfig.h" /* Load/save user formats */ #include "lib/strutil.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #ifdef ENABLE_VFS_FTP -#include "lib/vfs/mc-vfs/ftpfs.h" +#include "src/vfs/ftpfs/ftpfs.h" #endif /* ENABLE_VFS_FTP */ #ifdef ENABLE_VFS_SMB -#include "lib/vfs/mc-vfs/smbfs.h" +#include "src/vfs/smbfs/smbfs.h" #endif /* ENABLE_VFS_SMB */ #include "lib/util.h" /* Q_() */ diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index f81dc6d91..a2c611992 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -35,7 +35,7 @@ #include "lib/tty/tty.h" #include "lib/skin.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index 5ea070d8d..422450cc4 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -36,7 +36,7 @@ #include "lib/tty/tty.h" #include "lib/skin.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index e8e2ee774..4027f5079 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -53,7 +53,7 @@ #include "lib/mcconfig.h" #include "lib/search.h" #include "lib/filehighlight.h" /* MC_FHL_INI_FILE */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/fileloc.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/src/filemanager/command.c b/src/filemanager/command.c index 42a55909a..f05e83778 100644 --- a/src/filemanager/command.c +++ b/src/filemanager/command.c @@ -34,7 +34,7 @@ #include "lib/global.h" /* home_dir */ #include "lib/tty/tty.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strescape.h" #include "lib/skin.h" /* DEFAULT_COLOR */ #include "lib/util.h" diff --git a/src/filemanager/complete.c b/src/filemanager/complete.c index 2a8691df1..5d238d7be 100644 --- a/src/filemanager/complete.c +++ b/src/filemanager/complete.c @@ -40,7 +40,7 @@ #include "lib/tty/tty.h" #include "lib/tty/key.h" /* XCTRL and ALT macros */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strescape.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/src/filemanager/dir.c b/src/filemanager/dir.c index 9c1ad5cc2..4104b3ff8 100644 --- a/src/filemanager/dir.c +++ b/src/filemanager/dir.c @@ -30,7 +30,7 @@ #include "lib/global.h" #include "lib/tty/tty.h" #include "lib/search.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/fs.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 4cc998ee8..0f371ad4c 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -38,7 +38,7 @@ #include "lib/fileloc.h" #include "lib/mcconfig.h" #include "lib/util.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/widget.h" #include "lib/charsets.h" /* get_codepage_index */ diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 6d20ed0f2..e87eddc25 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -62,7 +62,7 @@ #include "lib/strescape.h" #include "lib/strutil.h" #include "lib/util.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/widget.h" #include "src/setup.h" diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index 3408ab157..131e5df3b 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -81,7 +81,7 @@ #include "lib/tty/key.h" /* tty_get_event */ #include "lib/mcconfig.h" #include "lib/search.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strescape.h" #include "lib/strutil.h" #include "lib/timefmt.h" /* file_date() */ diff --git a/src/filemanager/filenot.c b/src/filemanager/filenot.c index c9c24bb69..fde7f66ca 100644 --- a/src/filemanager/filenot.c +++ b/src/filemanager/filenot.c @@ -37,7 +37,7 @@ #include "lib/global.h" #include "lib/fs.h" #include "lib/util.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" /*** global variables ****************************************************************************/ diff --git a/src/filemanager/fileopctx.c b/src/filemanager/fileopctx.c index d12e18f00..1ffaf624e 100644 --- a/src/filemanager/fileopctx.c +++ b/src/filemanager/fileopctx.c @@ -36,7 +36,7 @@ #include "fileopctx.h" #include "filegui.h" #include "lib/search.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" /*** global variables ****************************************************************************/ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 1cba493cb..e5913a321 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -39,9 +39,9 @@ #include "lib/skin.h" #include "lib/search.h" #include "lib/mcconfig.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/widget.h" -#include "lib/vfs/mc-vfs/vfs.h" #include "lib/util.h" /* canonicalize_pathname() */ #include "src/setup.h" /* verbose */ diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index 30db4e2a0..72020ceab 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -48,7 +48,7 @@ #include "lib/mcconfig.h" /* Load/save directories hotlist */ #include "lib/fileloc.h" #include "lib/strutil.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index c84f13904..5c1f61949 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -51,7 +51,7 @@ #include "lib/tty/mouse.h" #include "lib/tty/win.h" /* do_enter_ca_mode() */ #include "lib/mcconfig.h" -#include "lib/vfs/mc-vfs/vfs.h" /* For vfs_translate_url() */ +#include "lib/vfs/vfs.h" /* For vfs_translate_url() */ #include "lib/strutil.h" #include "lib/widget.h" diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index d0f22128f..8a615f268 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -49,7 +49,7 @@ #include "lib/skin.h" #include "lib/util.h" -#include "lib/vfs/mc-vfs/vfs.h" /* vfs_translate_url() */ +#include "lib/vfs/vfs.h" /* vfs_translate_url() */ #include "src/args.h" #include "src/subshell.h" diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 86b87f805..c02ee3d0a 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -40,7 +40,7 @@ #include "lib/strescape.h" #include "lib/filehighlight.h" #include "lib/mcconfig.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/unixcompat.h" #include "lib/timefmt.h" #include "lib/util.h" diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 93bb955ca..4636a1ebb 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -36,7 +36,7 @@ #include "lib/global.h" #include "lib/skin.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/mcconfig.h" /* Load/save directories panelize */ #include "lib/strutil.h" #include "lib/util.h" diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index 40c2f3035..c639611ec 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -45,7 +45,7 @@ #include "lib/tty/mouse.h" #include "lib/tty/key.h" #include "lib/skin.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/fileloc.h" #include "lib/strutil.h" #include "lib/util.h" diff --git a/src/filemanager/treestore.c b/src/filemanager/treestore.c index 57cdf2e80..a89f44f4c 100644 --- a/src/filemanager/treestore.c +++ b/src/filemanager/treestore.c @@ -49,7 +49,7 @@ #include "lib/global.h" #include "lib/mcconfig.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/fileloc.h" #include "lib/hook.h" #include "lib/util.h" diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index aae5ade57..b46956d1b 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -32,7 +32,7 @@ #include "lib/tty/tty.h" #include "lib/skin.h" #include "lib/search.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" #include "lib/widget.h" diff --git a/src/main.c b/src/main.c index 088915d4a..b54a0a2c6 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,7 @@ #include "lib/fileloc.h" #include "lib/strutil.h" #include "lib/util.h" -#include "lib/vfs/mc-vfs/vfs.h" /* vfs_init(), vfs_shut() */ +#include "lib/vfs/vfs.h" /* vfs_init(), vfs_shut() */ #include "filemanager/midnight.h" /* current_panel */ #include "filemanager/treestore.h" /* tree_store_save */ @@ -58,6 +58,8 @@ #include "filemanager/ext.h" /* flush_extension_file() */ #include "filemanager/command.h" /* cmdline */ +#include "vfs/plugins_init.h" + #include "events_init.h" #include "args.h" #include "subshell.h" @@ -445,6 +447,8 @@ main (int argc, char *argv[]) str_init_strings (NULL); vfs_init (); + vfs_plugins_init(); + vfs_setup_work_dir (); if (!mc_args_handle (argc, argv, "mc")) exit (EXIT_FAILURE); diff --git a/src/setup.c b/src/setup.c index 31b504854..544165886 100644 --- a/src/setup.c +++ b/src/setup.c @@ -36,13 +36,13 @@ #include "lib/fileloc.h" #include "lib/timefmt.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #ifdef ENABLE_VFS_FTP -#include "lib/vfs/mc-vfs/ftpfs.h" +#include "src/vfs/ftpfs/ftpfs.h" #endif #ifdef ENABLE_VFS_FISH -#include "lib/vfs/mc-vfs/fish.h" +#include "src/vfs/fish/fish.h" #endif #include "lib/util.h" diff --git a/src/subshell.c b/src/subshell.c index c04c6163e..f753a138a 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -51,7 +51,7 @@ #include "lib/tty/tty.h" /* LINES */ #include "lib/tty/key.h" /* XCTRL */ -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/mcconfig.h" #include "lib/util.h" diff --git a/src/vfs/COPYING.LGPL b/src/vfs/COPYING.LGPL new file mode 100644 index 000000000..c0c8d1303 --- /dev/null +++ b/src/vfs/COPYING.LGPL @@ -0,0 +1,489 @@ + +Please note that the VFS code when *not* linked with SAMBA is released +under the GNU LGPL license. + +If you link your VFS with the SAMBA sources, the resulting library is +covered by the terms of the GNU GPL. + + GNU LIBRARY GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the library GPL. It is + numbered 2 because it goes with version 2 of the ordinary GPL.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Library General Public License, applies to some +specially designated Free Software Foundation software, and to any +other libraries whose authors decide to use it. You can use it for +your libraries, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if +you distribute copies of the library, or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link a program with the library, you must provide +complete object files to the recipients so that they can relink them +with the library, after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + Our method of protecting your rights has two steps: (1) copyright +the library, and (2) offer you this license which gives you legal +permission to copy, distribute and/or modify the library. + + Also, for each distributor's protection, we want to make certain +that everyone understands that there is no warranty for this free +library. If the library is modified by someone else and passed on, we +want its recipients to know that what they have is not the original +version, so that any problems introduced by others will not reflect on +the original authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that companies distributing free +software will individually obtain patent licenses, thus in effect +transforming the program into proprietary software. To prevent this, +we have made it clear that any patent must be licensed for everyone's +free use or not licensed at all. + + Most GNU software, including some libraries, is covered by the ordinary +GNU General Public License, which was designed for utility programs. This +license, the GNU Library General Public License, applies to certain +designated libraries. This license is quite different from the ordinary +one; be sure to read it in full, and don't assume that anything in it is +the same as in the ordinary license. + + The reason we have a separate public license for some libraries is that +they blur the distinction we usually make between modifying or adding to a +program and simply using it. Linking a program with a library, without +changing the library, is in some sense simply using the library, and is +analogous to running a utility program or application program. However, in +a textual and legal sense, the linked executable is a combined work, a +derivative of the original library, and the ordinary General Public License +treats it as such. + + Because of this blurred distinction, using the ordinary General +Public License for libraries did not effectively promote software +sharing, because most developers did not use the libraries. We +concluded that weaker conditions might promote sharing better. + + However, unrestricted linking of non-free programs would deprive the +users of those programs of all benefit from the free status of the +libraries themselves. This Library General Public License is intended to +permit developers of non-free programs to use free libraries, while +preserving your freedom as a user of such programs to change the free +libraries that are incorporated in them. (We have not seen how to achieve +this as regards changes in header files, but we have achieved it as regards +changes in the actual functions of the Library.) The hope is that this +will lead to faster development of free libraries. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, while the latter only +works together with the library. + + Note that it is possible for a library to be covered by the ordinary +General Public License rather than by this special one. + + GNU LIBRARY GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library which +contains a notice placed by the copyright holder or other authorized +party saying it may be distributed under the terms of this Library +General Public License (also called "this License"). Each licensee is +addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also compile or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + c) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + d) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the source code distributed need not include anything that is normally +distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Library General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/src/vfs/Makefile.am b/src/vfs/Makefile.am new file mode 100644 index 000000000..7418bddf1 --- /dev/null +++ b/src/vfs/Makefile.am @@ -0,0 +1,47 @@ +noinst_LTLIBRARIES = libmc-vfs.la + +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +libmc_vfs_la_SOURCES = plugins_init.c plugins_init.h + +SUBDIRS = local +libmc_vfs_la_LIBADD = local/libvfs-local.la + +if ENABLE_VFS_CPIO +SUBDIRS += cpio +libmc_vfs_la_LIBADD += cpio/libvfs-cpio.la +endif + +if ENABLE_VFS_EXTFS +SUBDIRS += extfs +libmc_vfs_la_LIBADD += extfs/libvfs-extfs.la +endif + +if ENABLE_VFS_FISH +SUBDIRS += fish +libmc_vfs_la_LIBADD += fish/libvfs-fish.la +endif + +if ENABLE_VFS_FTP +SUBDIRS += ftpfs +libmc_vfs_la_LIBADD += ftpfs/libvfs-ftpfs.la +endif + +if ENABLE_VFS_SFS +SUBDIRS += sfs +libmc_vfs_la_LIBADD += sfs/libvfs-sfs.la +endif + +if ENABLE_VFS_SMB +SUBDIRS += smbfs +libmc_vfs_la_LIBADD += smbfs/libvfs-smbfs.la +endif + +if ENABLE_VFS_TAR +SUBDIRS += tar +libmc_vfs_la_LIBADD += tar/libvfs-tar.la +endif + +if ENABLE_VFS_UNDELFS +SUBDIRS += undelfs +libmc_vfs_la_LIBADD += undelfs/libvfs-undelfs.la +endif diff --git a/src/vfs/cpio/Makefile.am b/src/vfs/cpio/Makefile.am new file mode 100644 index 000000000..c6feef56d --- /dev/null +++ b/src/vfs/cpio/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-cpio.la + +libvfs_cpio_la_SOURCES = \ + cpio.c cpio.h diff --git a/lib/vfs/mc-vfs/cpio.c b/src/vfs/cpio/cpio.c similarity index 99% rename from lib/vfs/mc-vfs/cpio.c rename to src/vfs/cpio/cpio.c index c29552b2c..e7d7724b4 100644 --- a/lib/vfs/mc-vfs/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -34,10 +34,12 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "xdirentry.h" -#include "gc.h" /* vfs_rmstamp */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/xdirentry.h" +#include "lib/vfs/gc.h" /* vfs_rmstamp */ + +#include "cpio.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/cpio/cpio.h b/src/vfs/cpio/cpio.h new file mode 100644 index 000000000..ca4c9d195 --- /dev/null +++ b/src/vfs/cpio/cpio.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_CPIO_H +#define MC__VFS_CPIO_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void init_cpiofs(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_CPIO_H */ diff --git a/src/vfs/extfs/Makefile.am b/src/vfs/extfs/Makefile.am new file mode 100644 index 000000000..e86e56d4a --- /dev/null +++ b/src/vfs/extfs/Makefile.am @@ -0,0 +1,10 @@ +SUBDIRS = helpers +DIST_SUBDIRS = helpers + +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = -DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\" + +noinst_LTLIBRARIES = libvfs-extfs.la + +libvfs_extfs_la_SOURCES = \ + extfs.c extfs.h diff --git a/lib/vfs/mc-vfs/extfs.c b/src/vfs/extfs/extfs.c similarity index 99% rename from lib/vfs/mc-vfs/extfs.c rename to src/vfs/extfs/extfs.c index b9ab05227..35efd8ffd 100644 --- a/lib/vfs/mc-vfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -55,9 +55,11 @@ #include "src/main.h" /* shell */ #include "src/execute.h" /* For shell_execute */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "gc.h" /* vfs_rmstamp */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/gc.h" /* vfs_rmstamp */ + +#include "extfs.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/extfs/extfs.h b/src/vfs/extfs/extfs.h new file mode 100644 index 000000000..5aedc88c0 --- /dev/null +++ b/src/vfs/extfs/extfs.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_EXTFS_H +#define MC__VFS_EXTFS_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void init_extfs(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_CPIO_H */ diff --git a/lib/vfs/mc-vfs/extfs/.gitignore b/src/vfs/extfs/helpers/.gitignore similarity index 100% rename from lib/vfs/mc-vfs/extfs/.gitignore rename to src/vfs/extfs/helpers/.gitignore diff --git a/lib/vfs/mc-vfs/extfs/Makefile.am b/src/vfs/extfs/helpers/Makefile.am similarity index 100% rename from lib/vfs/mc-vfs/extfs/Makefile.am rename to src/vfs/extfs/helpers/Makefile.am diff --git a/lib/vfs/mc-vfs/extfs/README b/src/vfs/extfs/helpers/README similarity index 100% rename from lib/vfs/mc-vfs/extfs/README rename to src/vfs/extfs/helpers/README diff --git a/lib/vfs/mc-vfs/extfs/README.extfs b/src/vfs/extfs/helpers/README.extfs similarity index 100% rename from lib/vfs/mc-vfs/extfs/README.extfs rename to src/vfs/extfs/helpers/README.extfs diff --git a/lib/vfs/mc-vfs/extfs/README.it b/src/vfs/extfs/helpers/README.it similarity index 100% rename from lib/vfs/mc-vfs/extfs/README.it rename to src/vfs/extfs/helpers/README.it diff --git a/lib/vfs/mc-vfs/extfs/README.uzip b/src/vfs/extfs/helpers/README.uzip similarity index 100% rename from lib/vfs/mc-vfs/extfs/README.uzip rename to src/vfs/extfs/helpers/README.uzip diff --git a/lib/vfs/mc-vfs/extfs/a+.in b/src/vfs/extfs/helpers/a+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/a+.in rename to src/vfs/extfs/helpers/a+.in diff --git a/lib/vfs/mc-vfs/extfs/apt+.in b/src/vfs/extfs/helpers/apt+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/apt+.in rename to src/vfs/extfs/helpers/apt+.in diff --git a/lib/vfs/mc-vfs/extfs/audio.in b/src/vfs/extfs/helpers/audio.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/audio.in rename to src/vfs/extfs/helpers/audio.in diff --git a/lib/vfs/mc-vfs/extfs/bpp b/src/vfs/extfs/helpers/bpp similarity index 100% rename from lib/vfs/mc-vfs/extfs/bpp rename to src/vfs/extfs/helpers/bpp diff --git a/lib/vfs/mc-vfs/extfs/deb.in b/src/vfs/extfs/helpers/deb.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/deb.in rename to src/vfs/extfs/helpers/deb.in diff --git a/lib/vfs/mc-vfs/extfs/deba.in b/src/vfs/extfs/helpers/deba.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/deba.in rename to src/vfs/extfs/helpers/deba.in diff --git a/lib/vfs/mc-vfs/extfs/debd.in b/src/vfs/extfs/helpers/debd.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/debd.in rename to src/vfs/extfs/helpers/debd.in diff --git a/lib/vfs/mc-vfs/extfs/dpkg+.in b/src/vfs/extfs/helpers/dpkg+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/dpkg+.in rename to src/vfs/extfs/helpers/dpkg+.in diff --git a/lib/vfs/mc-vfs/extfs/hp48+.in b/src/vfs/extfs/helpers/hp48+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/hp48+.in rename to src/vfs/extfs/helpers/hp48+.in diff --git a/lib/vfs/mc-vfs/extfs/iso9660.in b/src/vfs/extfs/helpers/iso9660.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/iso9660.in rename to src/vfs/extfs/helpers/iso9660.in diff --git a/lib/vfs/mc-vfs/extfs/lslR.in b/src/vfs/extfs/helpers/lslR.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/lslR.in rename to src/vfs/extfs/helpers/lslR.in diff --git a/lib/vfs/mc-vfs/extfs/mailfs.in b/src/vfs/extfs/helpers/mailfs.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/mailfs.in rename to src/vfs/extfs/helpers/mailfs.in diff --git a/lib/vfs/mc-vfs/extfs/patchfs.in b/src/vfs/extfs/helpers/patchfs.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/patchfs.in rename to src/vfs/extfs/helpers/patchfs.in diff --git a/lib/vfs/mc-vfs/extfs/rpm b/src/vfs/extfs/helpers/rpm similarity index 100% rename from lib/vfs/mc-vfs/extfs/rpm rename to src/vfs/extfs/helpers/rpm diff --git a/lib/vfs/mc-vfs/extfs/rpms+.in b/src/vfs/extfs/helpers/rpms+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/rpms+.in rename to src/vfs/extfs/helpers/rpms+.in diff --git a/lib/vfs/mc-vfs/extfs/s3+.in b/src/vfs/extfs/helpers/s3+.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/s3+.in rename to src/vfs/extfs/helpers/s3+.in diff --git a/lib/vfs/mc-vfs/extfs/sfs.ini b/src/vfs/extfs/helpers/sfs.ini similarity index 100% rename from lib/vfs/mc-vfs/extfs/sfs.ini rename to src/vfs/extfs/helpers/sfs.ini diff --git a/lib/vfs/mc-vfs/extfs/trpm b/src/vfs/extfs/helpers/trpm similarity index 100% rename from lib/vfs/mc-vfs/extfs/trpm rename to src/vfs/extfs/helpers/trpm diff --git a/lib/vfs/mc-vfs/extfs/u7z b/src/vfs/extfs/helpers/u7z similarity index 100% rename from lib/vfs/mc-vfs/extfs/u7z rename to src/vfs/extfs/helpers/u7z diff --git a/lib/vfs/mc-vfs/extfs/uace.in b/src/vfs/extfs/helpers/uace.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uace.in rename to src/vfs/extfs/helpers/uace.in diff --git a/lib/vfs/mc-vfs/extfs/ualz.in b/src/vfs/extfs/helpers/ualz.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/ualz.in rename to src/vfs/extfs/helpers/ualz.in diff --git a/lib/vfs/mc-vfs/extfs/uar.in b/src/vfs/extfs/helpers/uar.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uar.in rename to src/vfs/extfs/helpers/uar.in diff --git a/lib/vfs/mc-vfs/extfs/uarc.in b/src/vfs/extfs/helpers/uarc.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uarc.in rename to src/vfs/extfs/helpers/uarc.in diff --git a/lib/vfs/mc-vfs/extfs/uarj.in b/src/vfs/extfs/helpers/uarj.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uarj.in rename to src/vfs/extfs/helpers/uarj.in diff --git a/lib/vfs/mc-vfs/extfs/uc1541.in b/src/vfs/extfs/helpers/uc1541.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uc1541.in rename to src/vfs/extfs/helpers/uc1541.in diff --git a/lib/vfs/mc-vfs/extfs/ucab b/src/vfs/extfs/helpers/ucab similarity index 100% rename from lib/vfs/mc-vfs/extfs/ucab rename to src/vfs/extfs/helpers/ucab diff --git a/lib/vfs/mc-vfs/extfs/uha.in b/src/vfs/extfs/helpers/uha.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uha.in rename to src/vfs/extfs/helpers/uha.in diff --git a/lib/vfs/mc-vfs/extfs/ulha.in b/src/vfs/extfs/helpers/ulha.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/ulha.in rename to src/vfs/extfs/helpers/ulha.in diff --git a/lib/vfs/mc-vfs/extfs/urar.in b/src/vfs/extfs/helpers/urar.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/urar.in rename to src/vfs/extfs/helpers/urar.in diff --git a/lib/vfs/mc-vfs/extfs/uzip.in b/src/vfs/extfs/helpers/uzip.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uzip.in rename to src/vfs/extfs/helpers/uzip.in diff --git a/lib/vfs/mc-vfs/extfs/uzoo.in b/src/vfs/extfs/helpers/uzoo.in similarity index 100% rename from lib/vfs/mc-vfs/extfs/uzoo.in rename to src/vfs/extfs/helpers/uzoo.in diff --git a/src/vfs/fish/Makefile.am b/src/vfs/fish/Makefile.am new file mode 100644 index 000000000..5a8035ae8 --- /dev/null +++ b/src/vfs/fish/Makefile.am @@ -0,0 +1,11 @@ +SUBDIRS = helpers +DIST_SUBDIRS = helpers + +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = -DLIBEXECDIR=\""$(libexecdir)/@PACKAGE@/"\" + +noinst_LTLIBRARIES = libvfs-fish.la + +libvfs_fish_la_SOURCES = \ + fish.c fish.h \ + fishdef.h diff --git a/lib/vfs/mc-vfs/fish.c b/src/vfs/fish/fish.c similarity index 99% rename from lib/vfs/mc-vfs/fish.c rename to src/vfs/fish/fish.c index 16c6ffc94..88ceadefe 100644 --- a/lib/vfs/mc-vfs/fish.c +++ b/src/vfs/fish/fish.c @@ -66,11 +66,11 @@ #include "src/filemanager/layout.h" /* print_vfs_message */ #include "src/execute.h" /* pre_exec, post_exec */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "netutil.h" -#include "xdirentry.h" -#include "gc.h" /* vfs_stamp_create */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/netutil.h" +#include "lib/vfs/xdirentry.h" +#include "lib/vfs/gc.h" /* vfs_stamp_create */ #include "fish.h" #include "fishdef.h" diff --git a/lib/vfs/mc-vfs/fish.h b/src/vfs/fish/fish.h similarity index 97% rename from lib/vfs/mc-vfs/fish.h rename to src/vfs/fish/fish.h index d015af76f..1f3611021 100644 --- a/lib/vfs/mc-vfs/fish.h +++ b/src/vfs/fish/fish.h @@ -21,6 +21,8 @@ extern int fish_directory_timeout; /*** declarations of public functions ************************************************************/ +void init_fish(void); + /*** inline functions ****************************************************************************/ #endif diff --git a/lib/vfs/mc-vfs/fishdef.h b/src/vfs/fish/fishdef.h similarity index 100% rename from lib/vfs/mc-vfs/fishdef.h rename to src/vfs/fish/fishdef.h diff --git a/lib/vfs/mc-vfs/fish/Makefile.am b/src/vfs/fish/helpers/Makefile.am similarity index 100% rename from lib/vfs/mc-vfs/fish/Makefile.am rename to src/vfs/fish/helpers/Makefile.am diff --git a/lib/vfs/mc-vfs/fish/README.fish b/src/vfs/fish/helpers/README.fish similarity index 100% rename from lib/vfs/mc-vfs/fish/README.fish rename to src/vfs/fish/helpers/README.fish diff --git a/lib/vfs/mc-vfs/fish/append b/src/vfs/fish/helpers/append similarity index 100% rename from lib/vfs/mc-vfs/fish/append rename to src/vfs/fish/helpers/append diff --git a/lib/vfs/mc-vfs/fish/chmod b/src/vfs/fish/helpers/chmod similarity index 100% rename from lib/vfs/mc-vfs/fish/chmod rename to src/vfs/fish/helpers/chmod diff --git a/lib/vfs/mc-vfs/fish/chown b/src/vfs/fish/helpers/chown similarity index 100% rename from lib/vfs/mc-vfs/fish/chown rename to src/vfs/fish/helpers/chown diff --git a/lib/vfs/mc-vfs/fish/fexists b/src/vfs/fish/helpers/fexists similarity index 100% rename from lib/vfs/mc-vfs/fish/fexists rename to src/vfs/fish/helpers/fexists diff --git a/lib/vfs/mc-vfs/fish/get b/src/vfs/fish/helpers/get similarity index 100% rename from lib/vfs/mc-vfs/fish/get rename to src/vfs/fish/helpers/get diff --git a/lib/vfs/mc-vfs/fish/hardlink b/src/vfs/fish/helpers/hardlink similarity index 100% rename from lib/vfs/mc-vfs/fish/hardlink rename to src/vfs/fish/helpers/hardlink diff --git a/lib/vfs/mc-vfs/fish/info b/src/vfs/fish/helpers/info similarity index 100% rename from lib/vfs/mc-vfs/fish/info rename to src/vfs/fish/helpers/info diff --git a/lib/vfs/mc-vfs/fish/ln b/src/vfs/fish/helpers/ln similarity index 100% rename from lib/vfs/mc-vfs/fish/ln rename to src/vfs/fish/helpers/ln diff --git a/lib/vfs/mc-vfs/fish/ls b/src/vfs/fish/helpers/ls similarity index 100% rename from lib/vfs/mc-vfs/fish/ls rename to src/vfs/fish/helpers/ls diff --git a/lib/vfs/mc-vfs/fish/mkdir b/src/vfs/fish/helpers/mkdir similarity index 100% rename from lib/vfs/mc-vfs/fish/mkdir rename to src/vfs/fish/helpers/mkdir diff --git a/lib/vfs/mc-vfs/fish/mv b/src/vfs/fish/helpers/mv similarity index 100% rename from lib/vfs/mc-vfs/fish/mv rename to src/vfs/fish/helpers/mv diff --git a/lib/vfs/mc-vfs/fish/rmdir b/src/vfs/fish/helpers/rmdir similarity index 100% rename from lib/vfs/mc-vfs/fish/rmdir rename to src/vfs/fish/helpers/rmdir diff --git a/lib/vfs/mc-vfs/fish/send b/src/vfs/fish/helpers/send similarity index 100% rename from lib/vfs/mc-vfs/fish/send rename to src/vfs/fish/helpers/send diff --git a/lib/vfs/mc-vfs/fish/unlink b/src/vfs/fish/helpers/unlink similarity index 100% rename from lib/vfs/mc-vfs/fish/unlink rename to src/vfs/fish/helpers/unlink diff --git a/src/vfs/ftpfs/Makefile.am b/src/vfs/ftpfs/Makefile.am new file mode 100644 index 000000000..1dc0ad17b --- /dev/null +++ b/src/vfs/ftpfs/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-ftpfs.la + +libvfs_ftpfs_la_SOURCES = \ + ftpfs.c ftpfs.h diff --git a/lib/vfs/mc-vfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c similarity index 99% rename from lib/vfs/mc-vfs/ftpfs.c rename to src/vfs/ftpfs/ftpfs.c index 141e01b6a..546005f02 100644 --- a/lib/vfs/mc-vfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -98,11 +98,11 @@ What to do with this? #include "src/history.h" #include "src/setup.h" /* for load_anon_passwd */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "netutil.h" -#include "xdirentry.h" -#include "gc.h" /* vfs_stamp_create */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/netutil.h" +#include "lib/vfs/xdirentry.h" +#include "lib/vfs/gc.h" /* vfs_stamp_create */ #include "ftpfs.h" diff --git a/lib/vfs/mc-vfs/ftpfs.h b/src/vfs/ftpfs/ftpfs.h similarity index 100% rename from lib/vfs/mc-vfs/ftpfs.h rename to src/vfs/ftpfs/ftpfs.h diff --git a/src/vfs/local/Makefile.am b/src/vfs/local/Makefile.am new file mode 100644 index 000000000..0643304ec --- /dev/null +++ b/src/vfs/local/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-local.la + +libvfs_local_la_SOURCES = \ + local.c local.h diff --git a/lib/vfs/mc-vfs/local.c b/src/vfs/local/local.c similarity index 99% rename from lib/vfs/mc-vfs/local.c rename to src/vfs/local/local.c index ec19502b9..19ae85f63 100644 --- a/lib/vfs/mc-vfs/local.c +++ b/src/vfs/local/local.c @@ -14,8 +14,7 @@ #include "lib/global.h" -#include "vfs-impl.h" -#include "utilvfs.h" +#include "lib/vfs/utilvfs.h" #include "local.h" diff --git a/lib/vfs/mc-vfs/local.h b/src/vfs/local/local.h similarity index 97% rename from lib/vfs/mc-vfs/local.h rename to src/vfs/local/local.h index 1002b273d..db2f30920 100644 --- a/lib/vfs/mc-vfs/local.h +++ b/src/vfs/local/local.h @@ -6,7 +6,7 @@ #ifndef MC__VFS_LOCAL_H #define MC__VFS_LOCAL_H -#include "vfs-impl.h" +#include "lib/vfs/vfs.h" /*** typedefs(not structures) and defined constants **********************************************/ diff --git a/src/vfs/plugins_init.c b/src/vfs/plugins_init.c new file mode 100644 index 000000000..78deeeb62 --- /dev/null +++ b/src/vfs/plugins_init.c @@ -0,0 +1,125 @@ +/* + Init VFS plugins. + + Copyright (C) 2011 The Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +/** \file + * \brief This is a template file (here goes brief description). + * \author Author1 + * \author Author2 + * \date 20xx + * + * Detailed description. + */ + +#include + +#include "lib/global.h" + +#include "local/local.h" + +#ifdef ENABLE_VFS_CPIO +#include "cpio/cpio.h" +#endif + +#ifdef ENABLE_VFS_EXTFS +#include "extfs/extfs.h" +#endif + +#ifdef ENABLE_VFS_FISH +#include "fish/fish.h" +#endif + +#ifdef ENABLE_VFS_FTP +#include "ftpfs/ftpfs.h" +#endif + +#ifdef ENABLE_VFS_SFS +#include "sfs/sfs.h" +#endif + +#ifdef ENABLE_VFS_SMB +#include "smbfs/smbfs.h" +#endif + +#ifdef ENABLE_VFS_TAR +#include "tar/tar.h" +#endif + +#ifdef ENABLE_VFS_UNDELFS +#include "undelfs/undelfs.h" +#endif + +#include "plugins_init.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +void +vfs_plugins_init(void) +{ + /* localfs needs to be the first one */ + init_localfs (); + +#ifdef ENABLE_VFS_CPIO + init_cpiofs (); +#endif /* ENABLE_VFS_CPIO */ +#ifdef ENABLE_VFS_TAR + init_tarfs (); +#endif /* ENABLE_VFS_TAR */ +#ifdef ENABLE_VFS_SFS + init_sfs (); +#endif /* ENABLE_VFS_SFS */ +#ifdef ENABLE_VFS_EXTFS + init_extfs (); +#endif /* ENABLE_VFS_EXTFS */ +#ifdef ENABLE_VFS_UNDELFS + init_undelfs (); +#endif /* ENABLE_VFS_UNDELFS */ + +#ifdef ENABLE_VFS_FTP + init_ftpfs (); +#endif /* ENABLE_VFS_FTP */ +#ifdef ENABLE_VFS_FISH + init_fish (); +#endif /* ENABLE_VFS_FISH */ +#ifdef ENABLE_VFS_SMB + init_smbfs (); +#endif /* ENABLE_VFS_SMB */ + +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/plugins_init.h b/src/vfs/plugins_init.h new file mode 100644 index 000000000..5a60bd540 --- /dev/null +++ b/src/vfs/plugins_init.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_PLUINS_INIT_H +#define MC__VFS_PLUINS_INIT_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void vfs_plugins_init(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_PLUINS_INIT_H */ diff --git a/src/vfs/sfs/Makefile.am b/src/vfs/sfs/Makefile.am new file mode 100644 index 000000000..d38dcd282 --- /dev/null +++ b/src/vfs/sfs/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-sfs.la + +libvfs_sfs_la_SOURCES = \ + sfs.c sfs.h diff --git a/lib/vfs/mc-vfs/sfs.c b/src/vfs/sfs/sfs.c similarity index 98% rename from lib/vfs/mc-vfs/sfs.c rename to src/vfs/sfs/sfs.c index 4e745387b..a241a84e0 100644 --- a/lib/vfs/mc-vfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -48,10 +48,12 @@ #include "src/main.h" /* mc_sysconfig_dir */ #include "src/execute.h" /* EXECUTE_AS_SHELL */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "local.h" -#include "gc.h" /* vfs_stamp_create */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "src/vfs/local/local.h" +#include "lib/vfs/gc.h" /* vfs_stamp_create */ + +#include "sfs.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/sfs/sfs.h b/src/vfs/sfs/sfs.h new file mode 100644 index 000000000..e9f524721 --- /dev/null +++ b/src/vfs/sfs/sfs.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_SFS_H +#define MC__VFS_SFS_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void init_sfs(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_SFS_H */ diff --git a/src/vfs/smbfs/Makefile.am b/src/vfs/smbfs/Makefile.am new file mode 100644 index 000000000..70a8a510d --- /dev/null +++ b/src/vfs/smbfs/Makefile.am @@ -0,0 +1,84 @@ +DIST_SUBDIRS = + +SUBDIRS = helpers + +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) -DCONFIGDIR=\""@smbconfigdir@"\" +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-smbfs.la + +libvfs_smbfs_la_SOURCES = \ + smbfs.c smbfs.h + +SAMBA_DIST = \ + Makefile.in \ + aclocal.m4 \ + configure.ac \ + configure \ + internals.doc \ + parsing.doc \ + include/byteorder.h \ + include/charset.h \ + include/client.h \ + include/config.h.in \ + include/includes.h \ + include/kanji.h \ + include/local.h \ + include/nameserv.h \ + include/nterr.h \ + include/proto.h \ + include/smb.h \ + include/stamp-h.in \ + include/trans2.h \ + include/version.h \ + lib/charcnv.c \ + lib/charset.c \ + lib/debug.c \ + lib/interface.c \ + lib/kanji.c \ + lib/md4.c \ + lib/netmask.c \ + lib/slprintf.c \ + lib/system.c \ + lib/time.c \ + lib/username.c \ + lib/util.c \ + lib/util_file.c \ + lib/util_sock.c \ + lib/util_str.c \ + libsmb/clientgen.c \ + libsmb/namequery.c \ + libsmb/nmblib.c \ + libsmb/nterr.c \ + libsmb/pwd_cache.c \ + libsmb/smbdes.c \ + libsmb/smbencrypt.c \ + libsmb/smberr.c \ + param/loadparm.c \ + param/params.c + +dist-hook: + $(mkinstalldirs) $(distdir)/helpers + $(mkinstalldirs) $(distdir)/helpers/include + $(mkinstalldirs) $(distdir)/helpers/lib + $(mkinstalldirs) $(distdir)/helpers/libsmb + $(mkinstalldirs) $(distdir)/helpers/param + for I in $(SAMBA_DIST); do \ + cp -p $(srcdir)/helpers/$$I $(distdir)/helpers/$$I || exit 1; \ + done + +mostlyclean-local: + if test -f helpers/Makefile; then \ + (cd helpers && $(MAKE) mostlyclean) \ + else :; fi + +clean-local: + if test -f helpers/Makefile; then \ + (cd helpers && $(MAKE) clean) \ + else :; fi + +distclean-local: + if test -f helpers/Makefile; then \ + (cd helpers && $(MAKE) distclean) \ + else :; fi + diff --git a/lib/vfs/mc-vfs/samba/Makefile.in b/src/vfs/smbfs/helpers/Makefile.in similarity index 100% rename from lib/vfs/mc-vfs/samba/Makefile.in rename to src/vfs/smbfs/helpers/Makefile.in diff --git a/lib/vfs/mc-vfs/samba/aclocal.m4 b/src/vfs/smbfs/helpers/aclocal.m4 similarity index 100% rename from lib/vfs/mc-vfs/samba/aclocal.m4 rename to src/vfs/smbfs/helpers/aclocal.m4 diff --git a/lib/vfs/mc-vfs/samba/configure.ac b/src/vfs/smbfs/helpers/configure.ac similarity index 100% rename from lib/vfs/mc-vfs/samba/configure.ac rename to src/vfs/smbfs/helpers/configure.ac diff --git a/lib/vfs/mc-vfs/samba/include/byteorder.h b/src/vfs/smbfs/helpers/include/byteorder.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/byteorder.h rename to src/vfs/smbfs/helpers/include/byteorder.h diff --git a/lib/vfs/mc-vfs/samba/include/charset.h b/src/vfs/smbfs/helpers/include/charset.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/charset.h rename to src/vfs/smbfs/helpers/include/charset.h diff --git a/lib/vfs/mc-vfs/samba/include/client.h b/src/vfs/smbfs/helpers/include/client.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/client.h rename to src/vfs/smbfs/helpers/include/client.h diff --git a/lib/vfs/mc-vfs/samba/include/includes.h b/src/vfs/smbfs/helpers/include/includes.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/includes.h rename to src/vfs/smbfs/helpers/include/includes.h diff --git a/lib/vfs/mc-vfs/samba/include/kanji.h b/src/vfs/smbfs/helpers/include/kanji.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/kanji.h rename to src/vfs/smbfs/helpers/include/kanji.h diff --git a/lib/vfs/mc-vfs/samba/include/local.h b/src/vfs/smbfs/helpers/include/local.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/local.h rename to src/vfs/smbfs/helpers/include/local.h diff --git a/lib/vfs/mc-vfs/samba/include/nameserv.h b/src/vfs/smbfs/helpers/include/nameserv.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/nameserv.h rename to src/vfs/smbfs/helpers/include/nameserv.h diff --git a/lib/vfs/mc-vfs/samba/include/nterr.h b/src/vfs/smbfs/helpers/include/nterr.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/nterr.h rename to src/vfs/smbfs/helpers/include/nterr.h diff --git a/lib/vfs/mc-vfs/samba/include/proto.h b/src/vfs/smbfs/helpers/include/proto.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/proto.h rename to src/vfs/smbfs/helpers/include/proto.h diff --git a/lib/vfs/mc-vfs/samba/include/smb.h b/src/vfs/smbfs/helpers/include/smb.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/smb.h rename to src/vfs/smbfs/helpers/include/smb.h diff --git a/lib/vfs/mc-vfs/samba/include/trans2.h b/src/vfs/smbfs/helpers/include/trans2.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/trans2.h rename to src/vfs/smbfs/helpers/include/trans2.h diff --git a/lib/vfs/mc-vfs/samba/include/version.h b/src/vfs/smbfs/helpers/include/version.h similarity index 100% rename from lib/vfs/mc-vfs/samba/include/version.h rename to src/vfs/smbfs/helpers/include/version.h diff --git a/lib/vfs/mc-vfs/samba/internals.doc b/src/vfs/smbfs/helpers/internals.doc similarity index 100% rename from lib/vfs/mc-vfs/samba/internals.doc rename to src/vfs/smbfs/helpers/internals.doc diff --git a/lib/vfs/mc-vfs/samba/lib/charcnv.c b/src/vfs/smbfs/helpers/lib/charcnv.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/charcnv.c rename to src/vfs/smbfs/helpers/lib/charcnv.c diff --git a/lib/vfs/mc-vfs/samba/lib/charset.c b/src/vfs/smbfs/helpers/lib/charset.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/charset.c rename to src/vfs/smbfs/helpers/lib/charset.c diff --git a/lib/vfs/mc-vfs/samba/lib/debug.c b/src/vfs/smbfs/helpers/lib/debug.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/debug.c rename to src/vfs/smbfs/helpers/lib/debug.c diff --git a/lib/vfs/mc-vfs/samba/lib/interface.c b/src/vfs/smbfs/helpers/lib/interface.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/interface.c rename to src/vfs/smbfs/helpers/lib/interface.c diff --git a/lib/vfs/mc-vfs/samba/lib/kanji.c b/src/vfs/smbfs/helpers/lib/kanji.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/kanji.c rename to src/vfs/smbfs/helpers/lib/kanji.c diff --git a/lib/vfs/mc-vfs/samba/lib/md4.c b/src/vfs/smbfs/helpers/lib/md4.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/md4.c rename to src/vfs/smbfs/helpers/lib/md4.c diff --git a/lib/vfs/mc-vfs/samba/lib/netmask.c b/src/vfs/smbfs/helpers/lib/netmask.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/netmask.c rename to src/vfs/smbfs/helpers/lib/netmask.c diff --git a/lib/vfs/mc-vfs/samba/lib/slprintf.c b/src/vfs/smbfs/helpers/lib/slprintf.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/slprintf.c rename to src/vfs/smbfs/helpers/lib/slprintf.c diff --git a/lib/vfs/mc-vfs/samba/lib/system.c b/src/vfs/smbfs/helpers/lib/system.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/system.c rename to src/vfs/smbfs/helpers/lib/system.c diff --git a/lib/vfs/mc-vfs/samba/lib/time.c b/src/vfs/smbfs/helpers/lib/time.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/time.c rename to src/vfs/smbfs/helpers/lib/time.c diff --git a/lib/vfs/mc-vfs/samba/lib/username.c b/src/vfs/smbfs/helpers/lib/username.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/username.c rename to src/vfs/smbfs/helpers/lib/username.c diff --git a/lib/vfs/mc-vfs/samba/lib/util.c b/src/vfs/smbfs/helpers/lib/util.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/util.c rename to src/vfs/smbfs/helpers/lib/util.c diff --git a/lib/vfs/mc-vfs/samba/lib/util_file.c b/src/vfs/smbfs/helpers/lib/util_file.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/util_file.c rename to src/vfs/smbfs/helpers/lib/util_file.c diff --git a/lib/vfs/mc-vfs/samba/lib/util_sock.c b/src/vfs/smbfs/helpers/lib/util_sock.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/util_sock.c rename to src/vfs/smbfs/helpers/lib/util_sock.c diff --git a/lib/vfs/mc-vfs/samba/lib/util_str.c b/src/vfs/smbfs/helpers/lib/util_str.c similarity index 100% rename from lib/vfs/mc-vfs/samba/lib/util_str.c rename to src/vfs/smbfs/helpers/lib/util_str.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/clientgen.c b/src/vfs/smbfs/helpers/libsmb/clientgen.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/clientgen.c rename to src/vfs/smbfs/helpers/libsmb/clientgen.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/namequery.c b/src/vfs/smbfs/helpers/libsmb/namequery.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/namequery.c rename to src/vfs/smbfs/helpers/libsmb/namequery.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/nmblib.c b/src/vfs/smbfs/helpers/libsmb/nmblib.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/nmblib.c rename to src/vfs/smbfs/helpers/libsmb/nmblib.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/nterr.c b/src/vfs/smbfs/helpers/libsmb/nterr.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/nterr.c rename to src/vfs/smbfs/helpers/libsmb/nterr.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/pwd_cache.c b/src/vfs/smbfs/helpers/libsmb/pwd_cache.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/pwd_cache.c rename to src/vfs/smbfs/helpers/libsmb/pwd_cache.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/smbdes.c b/src/vfs/smbfs/helpers/libsmb/smbdes.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/smbdes.c rename to src/vfs/smbfs/helpers/libsmb/smbdes.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/smbencrypt.c b/src/vfs/smbfs/helpers/libsmb/smbencrypt.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/smbencrypt.c rename to src/vfs/smbfs/helpers/libsmb/smbencrypt.c diff --git a/lib/vfs/mc-vfs/samba/libsmb/smberr.c b/src/vfs/smbfs/helpers/libsmb/smberr.c similarity index 100% rename from lib/vfs/mc-vfs/samba/libsmb/smberr.c rename to src/vfs/smbfs/helpers/libsmb/smberr.c diff --git a/lib/vfs/mc-vfs/samba/param/loadparm.c b/src/vfs/smbfs/helpers/param/loadparm.c similarity index 100% rename from lib/vfs/mc-vfs/samba/param/loadparm.c rename to src/vfs/smbfs/helpers/param/loadparm.c diff --git a/lib/vfs/mc-vfs/samba/param/params.c b/src/vfs/smbfs/helpers/param/params.c similarity index 100% rename from lib/vfs/mc-vfs/samba/param/params.c rename to src/vfs/smbfs/helpers/param/params.c diff --git a/lib/vfs/mc-vfs/samba/parsing.doc b/src/vfs/smbfs/helpers/parsing.doc similarity index 100% rename from lib/vfs/mc-vfs/samba/parsing.doc rename to src/vfs/smbfs/helpers/parsing.doc diff --git a/lib/vfs/mc-vfs/smbfs.c b/src/vfs/smbfs/smbfs.c similarity index 99% rename from lib/vfs/mc-vfs/smbfs.c rename to src/vfs/smbfs/smbfs.c index 91ed17404..0ed238445 100644 --- a/lib/vfs/mc-vfs/smbfs.c +++ b/src/vfs/smbfs/smbfs.c @@ -51,18 +51,19 @@ #undef PACKAGE_TARNAME #undef PACKAGE_VERSION -#include "samba/include/config.h" +#include "helpers/include/config.h" /* don't load crap in "samba/include/includes.h" we don't use and which conflicts with definitions in other includes */ #undef HAVE_LIBREADLINE #define NO_CONFIG_H #undef VERSION -#include "samba/include/includes.h" +#include "helpers/include/includes.h" + +#include "lib/vfs/vfs.h" +#include "lib/vfs/netutil.h" +#include "lib/vfs/utilvfs.h" -#include "vfs-impl.h" -#include "netutil.h" -#include "utilvfs.h" #include "smbfs.h" /*** global variables ****************************************************************************/ diff --git a/lib/vfs/mc-vfs/smbfs.h b/src/vfs/smbfs/smbfs.h similarity index 100% rename from lib/vfs/mc-vfs/smbfs.h rename to src/vfs/smbfs/smbfs.h diff --git a/src/vfs/tar/Makefile.am b/src/vfs/tar/Makefile.am new file mode 100644 index 000000000..6a2c9d451 --- /dev/null +++ b/src/vfs/tar/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-tar.la + +libvfs_tar_la_SOURCES = \ + tar.c tar.h diff --git a/lib/vfs/mc-vfs/tar.c b/src/vfs/tar/tar.c similarity index 99% rename from lib/vfs/mc-vfs/tar.c rename to src/vfs/tar/tar.c index 2ca48e41f..31c997ddf 100644 --- a/lib/vfs/mc-vfs/tar.c +++ b/src/vfs/tar/tar.c @@ -44,10 +44,12 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "vfs-impl.h" -#include "utilvfs.h" -#include "xdirentry.h" -#include "gc.h" /* vfs_rmstamp */ +#include "lib/vfs/vfs.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/xdirentry.h" +#include "lib/vfs/gc.h" /* vfs_rmstamp */ + +#include "tar.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/tar/tar.h b/src/vfs/tar/tar.h new file mode 100644 index 000000000..b099f2fca --- /dev/null +++ b/src/vfs/tar/tar.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_TAR_H +#define MC__VFS_TAR_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void init_tarfs(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_TAR_H */ diff --git a/src/vfs/undelfs/Makefile.am b/src/vfs/undelfs/Makefile.am new file mode 100644 index 000000000..83df9c69d --- /dev/null +++ b/src/vfs/undelfs/Makefile.am @@ -0,0 +1,7 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) +AM_CPPFLAGS = + +noinst_LTLIBRARIES = libvfs-undelfs.la + +libvfs_undelfs_la_SOURCES = \ + undelfs.c undelfs.h diff --git a/lib/vfs/mc-vfs/undelfs.c b/src/vfs/undelfs/undelfs.c similarity index 99% rename from lib/vfs/mc-vfs/undelfs.c rename to src/vfs/undelfs/undelfs.c index 9655edf6e..4d8831fb0 100644 --- a/lib/vfs/mc-vfs/undelfs.c +++ b/src/vfs/undelfs/undelfs.c @@ -60,8 +60,10 @@ #include "lib/widget.h" /* message() */ #include "src/filemanager/layout.h" /* print_vfs_message */ -#include "utilvfs.h" -#include "vfs-impl.h" +#include "lib/vfs/utilvfs.h" +#include "lib/vfs/vfs.h" + +#include "undelfs.h" /*** global variables ****************************************************************************/ diff --git a/src/vfs/undelfs/undelfs.h b/src/vfs/undelfs/undelfs.h new file mode 100644 index 000000000..06d32095b --- /dev/null +++ b/src/vfs/undelfs/undelfs.h @@ -0,0 +1,18 @@ +#ifndef MC__VFS_UNDELFS_H +#define MC__VFS_UNDELFS_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void init_undelfs(void); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__VFS_UNDELFS_H */ diff --git a/src/viewer/datasource.c b/src/viewer/datasource.c index 2af8368bc..aa5bec31f 100644 --- a/src/viewer/datasource.c +++ b/src/viewer/datasource.c @@ -57,7 +57,7 @@ #include #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" /* D_NORMAL, D_ERROR */ diff --git a/src/viewer/growbuf.c b/src/viewer/growbuf.c index fb54bc8fc..a98bf93b1 100644 --- a/src/viewer/growbuf.c +++ b/src/viewer/growbuf.c @@ -39,7 +39,7 @@ #include #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" /* D_NORMAL */ diff --git a/src/viewer/hex.c b/src/viewer/hex.c index 0515074e7..74148e5ee 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -44,7 +44,7 @@ #include "lib/global.h" #include "lib/tty/tty.h" #include "lib/skin.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/util.h" #include "lib/widget.h" #include "lib/charsets.h" diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 7cdcbe769..435caa2dd 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -41,7 +41,7 @@ #include #include "lib/global.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" /* save_file_position() */ #include "lib/lock.h" /* unlock_file() */ diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index aed360a02..3cf994837 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -42,7 +42,7 @@ #include "lib/global.h" #include "lib/tty/tty.h" #include "lib/tty/mouse.h" -#include "lib/vfs/mc-vfs/vfs.h" +#include "lib/vfs/vfs.h" #include "lib/strutil.h" #include "lib/util.h" /* load_file_position() */ #include "lib/widget.h" From 6016620f42a22cef1dcbb6414aef1927165c63d1 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 10 Feb 2011 17:02:54 +0200 Subject: [PATCH 05/25] Remove backlinks from lib to src - move global variables(used in lib) to mc_global structure (see lib/global.c) Signed-off-by: Slava Zanko --- lib/Makefile.am | 2 +- lib/charsets.c | 12 ++- lib/charsets.h | 4 +- lib/filehighlight/ini-file-read.c | 6 +- lib/global.c | 127 ++++++++++++++++++++++++++++++ lib/global.h | 116 +++++++++++++++++++++++++++ lib/mcconfig/get.c | 4 +- lib/mcconfig/set.c | 4 +- lib/skin/colors-old.c | 11 +-- lib/skin/colors.c | 4 +- lib/skin/common.c | 10 +-- lib/skin/ini-file.c | 6 +- lib/skin/lines.c | 6 +- lib/tty/color-slang.c | 6 +- lib/tty/color.c | 2 - lib/tty/color.h | 3 - lib/tty/key.c | 13 ++- lib/tty/tty-ncurses.c | 4 +- lib/tty/win.c | 9 +-- lib/util.c | 5 +- lib/vfs/gc.c | 1 - lib/vfs/utilvfs.c | 4 +- lib/vfs/vfs.c | 3 +- lib/widget/dialog-switch.c | 9 +-- lib/widget/dialog.c | 4 +- lib/widget/history.c | 7 +- lib/widget/listbox.c | 3 +- lib/widget/wtools.c | 4 +- src/args.c | 52 +++++------- src/args.h | 4 - src/background.c | 5 +- src/background.h | 2 - src/cons.handler.c | 46 ++++++----- src/consaver/cons.saver.h | 1 - src/diffviewer/ydiff.c | 17 ++-- src/editor/edit.c | 11 ++- src/editor/editcmd.c | 19 +++-- src/editor/editdraw.c | 11 ++- src/editor/editkeys.c | 3 +- src/editor/syntax.c | 8 +- src/execute.c | 48 +++++------ src/filemanager/boxes.c | 34 ++++---- src/filemanager/cmd.c | 29 ++++--- src/filemanager/command.c | 6 +- src/filemanager/complete.c | 4 +- src/filemanager/ext.c | 18 ++--- src/filemanager/file.c | 16 ++-- src/filemanager/layout.c | 78 +++++++++--------- src/filemanager/layout.h | 3 - src/filemanager/midnight.c | 43 +++++----- src/filemanager/option.c | 6 +- src/filemanager/panel.c | 12 +-- src/filemanager/panelize.c | 3 +- src/filemanager/usermenu.c | 8 +- src/help.c | 2 +- src/history.h | 1 - src/main.c | 95 ++++++++-------------- src/main.h | 20 ----- src/selcodepage.c | 4 +- src/setup.c | 88 ++++++++++----------- src/setup.h | 7 +- src/subshell.c | 99 +++++++++++------------ src/subshell.h | 8 -- src/vfs/ftpfs/ftpfs.c | 2 +- src/vfs/sfs/sfs.c | 3 +- src/viewer/actions_cmd.c | 5 +- src/viewer/display.c | 2 +- src/viewer/hex.c | 4 +- src/viewer/lib.c | 6 +- src/viewer/nroff.c | 3 +- src/viewer/plain.c | 3 +- 71 files changed, 654 insertions(+), 574 deletions(-) create mode 100644 lib/global.c diff --git a/lib/Makefile.am b/lib/Makefile.am index 9a99991d7..98cfbb35f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -25,7 +25,7 @@ libmc_la_SOURCES = \ fs.h \ hook.c hook.h \ glibcompat.c glibcompat.h \ - global.h \ + global.c global.h \ keybind.c keybind.h \ lock.c lock.h \ timefmt.c timefmt.h diff --git a/lib/charsets.c b/lib/charsets.c index 781533363..5cbe38faf 100644 --- a/lib/charsets.c +++ b/lib/charsets.c @@ -34,8 +34,6 @@ #include "lib/fileloc.h" #include "lib/charsets.h" -#include "src/main.h" - /*** global variables ****************************************************************************/ GPtrArray *codepages = NULL; @@ -163,7 +161,7 @@ load_codepages_list_from_file (GPtrArray ** list, const char *fname) if (default_codepage != NULL) { - display_codepage = get_codepage_index (default_codepage); + mc_global.display_codepage = get_codepage_index (default_codepage); g_free (default_codepage); } @@ -200,12 +198,12 @@ load_codepages_list (void) char *fname; /* 1: try load /usr/share/mc/mc.charsets */ - fname = g_build_filename (mc_share_data_dir, CHARSETS_LIST, (char *) NULL); + fname = g_build_filename (mc_global.share_data_dir, CHARSETS_LIST, (char *) NULL); load_codepages_list_from_file (&codepages, fname); g_free (fname); /* 2: try load /etc/mc/mc.charsets */ - fname = g_build_filename (mc_sysconfig_dir, CHARSETS_LIST, (char *) NULL); + fname = g_build_filename (mc_global.sysconfig_dir, CHARSETS_LIST, (char *) NULL); load_codepages_list_from_file (&codepages, fname); g_free (fname); @@ -435,7 +433,7 @@ convert_from_utf_to_current (const char *str) if (!str) return '.'; - cp_to = get_codepage_id (source_codepage); + cp_to = get_codepage_id (mc_global.source_codepage); conv = str_crt_conv_to (cp_to); if (conv != INVALID_CONV) @@ -537,7 +535,7 @@ convert_from_8bit_to_utf_c2 (const char input_char) str[0] = (unsigned char) input_char; str[1] = '\0'; - cp_from = get_codepage_id (source_codepage); + cp_from = get_codepage_id (mc_global.source_codepage); conv = str_crt_conv_to (cp_from); if (conv != INVALID_CONV) diff --git a/lib/charsets.h b/lib/charsets.h index bb1a59271..98e2ac779 100644 --- a/lib/charsets.h +++ b/lib/charsets.h @@ -54,14 +54,14 @@ void convert_string (unsigned char *str); /* * Converter from utf to selected codepage * param str, utf char - * return char in needle codepage (by global int source_codepage) + * return char in needle codepage (by global int mc_global.source_codepage) */ unsigned char convert_from_utf_to_current (const char *str); /* * Converter from utf to selected codepage * param input_char, gunichar - * return char in needle codepage (by global int source_codepage) + * return char in needle codepage (by global int mc_global.source_codepage) */ unsigned char convert_from_utf_to_current_c (const int input_char, GIConv conv); diff --git a/lib/filehighlight/ini-file-read.c b/lib/filehighlight/ini-file-read.c index a82eb7e45..fabe97004 100644 --- a/lib/filehighlight/ini-file-read.c +++ b/lib/filehighlight/ini-file-read.c @@ -35,8 +35,6 @@ #include "lib/util.h" /* exist_file() */ #include "lib/filehighlight.h" -#include "src/main.h" - #include "internal.h" /*** global variables ****************************************************************************/ @@ -209,14 +207,14 @@ mc_fhl_init_from_standard_files (mc_fhl_t * fhl) return TRUE; /* ${sysconfdir}/mc/filehighlight.ini */ - name = g_build_filename (mc_sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL); + name = g_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL); ok = mc_fhl_read_ini_file (fhl, name); g_free (name); if (ok) return TRUE; /* ${datadir}/mc/filehighlight.ini */ - name = g_build_filename (mc_share_data_dir, MC_FHL_INI_FILE, (char *) NULL); + name = g_build_filename (mc_global.share_data_dir, MC_FHL_INI_FILE, (char *) NULL); ok = mc_fhl_read_ini_file (fhl, name); g_free (name); return ok; diff --git a/lib/global.c b/lib/global.c new file mode 100644 index 000000000..eb6eedc58 --- /dev/null +++ b/lib/global.c @@ -0,0 +1,127 @@ +/* GLIB - Library of useful routines for C programming + Copyright (C) 2009 + Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2009. + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. + */ + +/** \file glibcompat.c + * \brief Source: compatibility with older versions of glib + * + * Following code was copied from glib to GNU Midnight Commander to + * provide compatibility with older versions of glib. + */ + +#include + +#include "global.h" + + +/* *INDENT-OFF* */ +#ifdef HAVE_SUBSHELL_SUPPORT +# ifdef SUBSHELL_OPTIONAL +# define SUBSHELL_USE FALSE +# else /* SUBSHELL_OPTIONAL */ +# define SUBSHELL_USE TRUE +# endif /* SUBSHELL_OPTIONAL */ +#else /* !HAVE_SUBSHELL_SUPPORT */ +# define SUBSHELL_USE FALSE +#endif /* !HAVE_SUBSHELL_SUPPORT */ +/* *INDENT-ON* */ + +/*** global variables ****************************************************************************/ + +/* *INDENT-OFF* */ +mc_global_t mc_global = { +#ifdef WITH_BACKGROUND + .we_are_background = 0, +#endif /* WITH_BACKGROUND */ + + .message_visible = 1, + .keybar_visible = 1, + .mc_run_mode = MC_RUN_FULL, + +#ifdef HAVE_CHARSET + .source_codepage = -1, + .display_codepage = -1, +#else + .eight_bit_clean = 1, + .full_eight_bits = 0, +#endif /* !HAVE_CHARSET */ + + .utf8_display = 0, + .sysconfig_dir = NULL, + .share_data_dir = NULL, + + .args = + { + .disable_colors = FALSE, + .skin = NULL, + .ugly_line_drawing = FALSE, + .slow_terminal = FALSE + }, + + .widget = + { + .midnight_shutdown = FALSE, + .confirm_history_cleanup = TRUE, + .show_all_if_ambiguous = FALSE + }, + + .tty = + { + .setup_color_string = NULL, + .term_color_string = NULL, + .color_terminal_string = NULL, +#ifndef LINUX_CONS_SAVER_C + .console_flag = '\0', +#endif /* !LINUX_CONS_SAVER_C */ + + .use_subshell = SUBSHELL_USE, + +#ifdef HAVE_SUBSHELL_SUPPORT + .subshell_pty = 0, +#endif /* !HAVE_SUBSHELL_SUPPORT */ + + .winch_flag = FALSE, + .command_line_colors = NULL, + }, + + .vfs = + { + .cd_symlinks = TRUE + } + +}; +/* *INDENT-ON* */ + +#undef SUBSHELL_USE + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ + +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/global.h b/lib/global.h index 18fe4e76c..aafe28715 100644 --- a/lib/global.h +++ b/lib/global.h @@ -145,10 +145,126 @@ /*** enums ***************************************************************************************/ +/* run mode and params */ +typedef enum +{ + MC_RUN_FULL = 0, + MC_RUN_EDITOR, + MC_RUN_VIEWER, + MC_RUN_DIFFVIEWER +} mc_run_mode_t; + /*** structures declarations (and typedefs of structures)*****************************************/ +typedef struct +{ +#ifdef WITH_BACKGROUND + /* If true, this is a background process */ + int we_are_background; +#endif /* WITH_BACKGROUND */ + + /* + * If utf-8 terminal utf8_display = 1 + * Display bits set UTF-8 + */ + int utf8_display; + + /* Set if the nice message (hint) bar is visible */ + int message_visible; + + /* Set if the nice and useful keybar is visible */ + int keybar_visible; + + mc_run_mode_t mc_run_mode; + +#ifdef HAVE_CHARSET + /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */ + int source_codepage; + int display_codepage; +#else + /* If true, allow characters in the range 160-255 */ + int eight_bit_clean; + /* + * If true, also allow characters in the range 128-159. + * This is reported to break on many terminals (xterm, qansi-m). + */ + int full_eight_bits; +#endif /* !HAVE_CHARSET */ + + /* sysconfig_dir: Area for default settings from maintainers of distributuves + default is /etc/mc or may be defined by MC_DATADIR + */ + char *sysconfig_dir; + + /* share_data_dir: Area for default settings from developers */ + char *share_data_dir; + + struct + { + /* Use the specified skin */ + char *skin; + + /* Set to force black and white display at program startup */ + gboolean disable_colors; + + /* If true use +, -, | for line drawing */ + gboolean ugly_line_drawing; + + /* For slow terminals */ + gboolean slow_terminal; + + } args; + + struct + { + /* Used so that widgets know if they are being destroyed or shut down */ + gboolean midnight_shutdown; + + /* Asks for confirmation before clean up of history */ + gboolean confirm_history_cleanup; + + /* Set if you want the possible completions dialog for the first time */ + gboolean show_all_if_ambiguous; + + } widget; + + struct + { + char *setup_color_string; + char *term_color_string; + char *color_terminal_string; + + /* Set if the window has changed it's size */ + gboolean winch_flag; + +#ifndef LINUX_CONS_SAVER_C + /* Used only in mc, not in cons.saver */ + char console_flag; +#endif /* !LINUX_CONS_SAVER_C */ + /* If using a subshell for evaluating commands this is true */ + gboolean use_subshell; +#ifdef HAVE_SUBSHELL_SUPPORT + /* File descriptors of the pseudoterminal used by the subshell */ + int subshell_pty; +#endif /* !HAVE_SUBSHELL_SUPPORT */ + + /* colors specified on the command line: they override any other setting */ + char *command_line_colors; + + } tty; + + struct + { + /* Set when cd symlink following is desirable (bash mode) */ + gboolean cd_symlinks; + } vfs; + +} mc_global_t; + /*** global variables defined in .c file *********************************************************/ +extern mc_global_t mc_global; + /*** declarations of public functions ************************************************************/ void refresh_screen (void *); diff --git a/lib/mcconfig/get.c b/lib/mcconfig/get.c index 0531b4a59..e3ced7cac 100644 --- a/lib/mcconfig/get.c +++ b/lib/mcconfig/get.c @@ -25,8 +25,6 @@ /*** global variables **************************************************/ -extern int utf8_display; - /*** file scope macro definitions **************************************/ /*** file scope type declarations **************************************/ @@ -103,7 +101,7 @@ mc_config_get_string (mc_config_t * mc_config, const gchar * group, if (ret == NULL) ret = g_strdup (def); - if (utf8_display) + if (mc_global.utf8_display) return ret; conv = str_crt_conv_from ("UTF-8"); diff --git a/lib/mcconfig/set.c b/lib/mcconfig/set.c index efce0bc7c..c3ae303df 100644 --- a/lib/mcconfig/set.c +++ b/lib/mcconfig/set.c @@ -25,8 +25,6 @@ /*** global variables **************************************************/ -extern int utf8_display; - /*** file scope macro definitions **************************************/ /*** file scope type declarations **************************************/ @@ -42,7 +40,7 @@ mc_config_normalize_before_save (const gchar * value) GIConv conv; GString *buffer; - if (utf8_display) + if (mc_global.utf8_display) return g_strdup (value); conv = str_crt_conv_to ("UTF-8"); diff --git a/lib/skin/colors-old.c b/lib/skin/colors-old.c index deed2362f..1f294d29e 100644 --- a/lib/skin/colors-old.c +++ b/lib/skin/colors-old.c @@ -35,8 +35,6 @@ #include "lib/tty/color.h" -#include "src/setup.h" - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -160,8 +158,7 @@ mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_str if (key_val == NULL) continue; - if (key_val[1] != NULL - && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key)) + if (key_val[1] != NULL && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key)) { gchar *skin_val; @@ -188,10 +185,10 @@ mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_str void mc_skin_colors_old_configure (mc_skin_t * mc_skin) { - mc_skin_colors_old_configure_one (mc_skin, setup_color_string); - mc_skin_colors_old_configure_one (mc_skin, term_color_string); + mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.setup_color_string); + mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.term_color_string); mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE")); - mc_skin_colors_old_configure_one (mc_skin, command_line_colors); + mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.command_line_colors); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/skin/colors.c b/lib/skin/colors.c index d99353276..bcb168ab7 100644 --- a/lib/skin/colors.c +++ b/lib/skin/colors.c @@ -33,8 +33,6 @@ #include "lib/tty/color.h" -#include "src/args.h" - /*** global variables ****************************************************************************/ int mc_skin_color__cache[MC_SKIN_COLOR_CACHE_COUNT]; @@ -273,7 +271,7 @@ mc_skin_color_check_bw_mode (mc_skin_t * mc_skin) { gchar **groups, **orig_groups; - if (tty_use_colors () && !mc_args__disable_colors) + if (tty_use_colors () && !mc_global.args.disable_colors) return; orig_groups = groups = mc_config_get_groups (mc_skin->config, NULL); diff --git a/lib/skin/common.c b/lib/skin/common.c index ebf85ff8a..148a9634b 100644 --- a/lib/skin/common.c +++ b/lib/skin/common.c @@ -33,8 +33,6 @@ #include "lib/tty/color.h" /* tty_use_256colors(); */ -#include "src/args.h" - /*** global variables ****************************************************************************/ mc_skin_t mc_skin__default; @@ -69,8 +67,8 @@ mc_skin_get_default_name (void) char *tmp_str; /* from command line */ - if (mc_args__skin != NULL) - return g_strdup (mc_args__skin); + if (mc_global.args.skin != NULL) + return g_strdup (mc_global.args.skin); /* from envirovement variable */ tmp_str = getenv ("MC_SKIN"); @@ -146,7 +144,7 @@ mc_skin_init (GError ** error) (void) mc_skin_ini_file_parse (&mc_skin__default); is_good_init = FALSE; } - if ( is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors ) + if (is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors) { if (*error == NULL) *error = g_error_new (MC_ERROR, 0, @@ -187,7 +185,7 @@ mc_skin_deinit (void) gchar * mc_skin_get (const gchar * group, const gchar * key, const gchar * default_value) { - if (mc_args__ugly_line_drawing) + if (mc_global.args.ugly_line_drawing) { return g_strdup (default_value); } diff --git a/lib/skin/ini-file.c b/lib/skin/ini-file.c index 757523379..3ee70ec38 100644 --- a/lib/skin/ini-file.c +++ b/lib/skin/ini-file.c @@ -32,8 +32,6 @@ #include "lib/fileloc.h" #include "lib/util.h" /* exist_file() */ -#include "src/main.h" - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -102,11 +100,11 @@ mc_skin_ini_file_load (mc_skin_t * mc_skin) return TRUE; /* /etc/mc/skins/ */ - if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_sysconfig_dir)) + if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.sysconfig_dir)) return TRUE; /* /usr/share/mc/skins/ */ - return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_share_data_dir); + return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.share_data_dir); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/skin/lines.c b/lib/skin/lines.c index da043ab6b..3debef570 100644 --- a/lib/skin/lines.c +++ b/lib/skin/lines.c @@ -31,8 +31,6 @@ #include "internal.h" #include "lib/tty/tty.h" -#include "src/args.h" - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -98,9 +96,9 @@ mc_skin_lines_load_frm (mc_skin_t * mc_skin, const char *name) void mc_skin_lines_parse_ini_file (mc_skin_t * mc_skin) { - if (mc_args__slow_terminal) + if (mc_global.args.slow_terminal) mc_skin_hardcoded_space_lines (mc_skin); - else if (mc_args__ugly_line_drawing) + else if (mc_global.args.ugly_line_drawing) mc_skin_hardcoded_ugly_lines (mc_skin); /* single lines */ diff --git a/lib/tty/color-slang.c b/lib/tty/color-slang.c index 180d872fe..000252e51 100644 --- a/lib/tty/color-slang.c +++ b/lib/tty/color-slang.c @@ -37,8 +37,6 @@ #include "color.h" /* variables */ #include "color-internal.h" -#include "src/setup.h" /* color_terminal_string */ - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -63,11 +61,11 @@ has_colors (gboolean disable, gboolean force) const char *terminal = getenv ("TERM"); const size_t len = strlen (terminal); - char *cts = color_terminal_string; + char *cts = mc_global.tty.color_terminal_string; char *s; size_t i; - /* check color_terminal_string */ + /* check mc_global.tty.color_terminal_string */ while (*cts != '\0') { while (*cts == ' ' || *cts == '\t') diff --git a/lib/tty/color.c b/lib/tty/color.c index bcb553dba..a31ccfa15 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -44,8 +44,6 @@ /*** global variables ****************************************************************************/ -char *command_line_colors = NULL; - static char *tty_color_defaults__fg = NULL; static char *tty_color_defaults__bg = NULL; static char *tty_color_defaults__attrs = NULL; diff --git a/lib/tty/color.h b/lib/tty/color.h index b7f9b7ddb..ad778eb3d 100644 --- a/lib/tty/color.h +++ b/lib/tty/color.h @@ -29,9 +29,6 @@ /*** global variables defined in .c file *********************************************************/ -/* colors specified on the command line: they override any other setting */ -extern char *command_line_colors; - /*** declarations of public functions ************************************************************/ void tty_init_colors (gboolean disable, gboolean force); diff --git a/lib/tty/key.c b/lib/tty/key.c index 23910149f..fd993d1f5 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -48,10 +48,7 @@ #include "key.h" #include "win.h" /* xterm_flag */ -#include "src/main.h" -#include "src/filemanager/layout.h" /* winch_flag, mc_refresh() */ -#include "src/consaver/cons.saver.h" - +#include "src/filemanager/layout.h" /* mc_refresh() */ #ifdef HAVE_TEXTMODE_X11_SUPPORT #include "x11conn.h" @@ -1959,7 +1956,7 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block) } } - if (!block || winch_flag) + if (!block || mc_global.tty.winch_flag) { time_addr = &time_out; time_out.tv_sec = 0; @@ -1979,7 +1976,7 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block) { if (redo_event) return EV_MOUSE; - if (!block || winch_flag) + if (!block || mc_global.tty.winch_flag) return EV_NONE; vfs_timeout_handler (); } @@ -2106,7 +2103,7 @@ learn_key (void) void numeric_keypad_mode (void) { - if (console_flag || xterm_flag) + if (mc_global.tty.console_flag || xterm_flag) { fputs ("\033>", stdout); fflush (stdout); @@ -2118,7 +2115,7 @@ numeric_keypad_mode (void) void application_keypad_mode (void) { - if (console_flag || xterm_flag) + if (mc_global.tty.console_flag || xterm_flag) { fputs ("\033=", stdout); fflush (stdout); diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 10a7c492b..fca7d5441 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -39,8 +39,6 @@ #include "lib/global.h" #include "lib/strutil.h" /* str_term_form */ -#include "src/main.h" - #ifndef WANT_TERM_H #define WANT_TERM_H #endif @@ -396,7 +394,7 @@ tty_print_anychar (int c) { unsigned char str[6 + 1]; - if (utf8_display || c > 255) + if (mc_global.utf8_display || c > 255) { int res = g_unichar_to_utf8 (c, (char *) str); if (res == 0) diff --git a/lib/tty/win.c b/lib/tty/win.c index 6d0b841f2..329131afa 100644 --- a/lib/tty/win.c +++ b/lib/tty/win.c @@ -36,7 +36,6 @@ #include "lib/util.h" /* is_printable() */ #include "tty.h" /* tty_gotoyx, tty_print_char */ #include "win.h" -#include "src/consaver/cons.saver.h" /* console_flag */ /*** global variables ****************************************************************************/ @@ -44,8 +43,6 @@ /* It is used by function view_other_cmd() */ int xterm_flag = 0; -extern int keybar_visible; - /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -122,8 +119,8 @@ show_rxvt_contents (int starty, unsigned char y1, unsigned char y2) unsigned char *k; int bytes, i, j, cols = 0; - y1 += (keybar_visible != 0); /* i don't knwo why we need this - paul */ - y2 += (keybar_visible != 0); + y1 += (mc_global.keybar_visible != 0); /* i don't knwo why we need this - paul */ + y2 += (mc_global.keybar_visible != 0); while (anything_ready ()) tty_lowlevel_getch (); @@ -174,7 +171,7 @@ look_for_rxvt_extensions (void) } if (rxvt_extensions) - console_flag = 4; + mc_global.tty.console_flag = '\004'; return rxvt_extensions; } diff --git a/lib/util.c b/lib/util.c index 7bd8b46e5..f72d35832 100644 --- a/lib/util.c +++ b/lib/util.c @@ -50,7 +50,6 @@ #include "src/filemanager/filegui.h" #include "src/filemanager/file.h" /* copy_file_file() */ -#include "src/main.h" /* eight_bit_clean */ /*** global variables ****************************************************************************/ @@ -221,10 +220,10 @@ is_printable (int c) by setting the output codepage */ return is_8bit_printable (c); #else - if (!eight_bit_clean) + if (!mc_global.eight_bit_clean) return is_7bit_printable (c); - if (full_eight_bits) + if (mc_global.full_eight_bits) { return is_8bit_printable (c); } diff --git a/lib/vfs/gc.c b/lib/vfs/gc.c index 952c1e268..c412de820 100644 --- a/lib/vfs/gc.c +++ b/lib/vfs/gc.c @@ -45,7 +45,6 @@ #include "lib/global.h" #include "src/filemanager/midnight.h" /* current_panel */ -#include "src/filemanager/layout.h" /* get_current_type(), get_other_type() */ #include "vfs.h" #include "utilvfs.h" diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c index 3d2ba162e..703af429e 100644 --- a/lib/vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -40,8 +40,6 @@ #include "lib/util.h" /* mc_mkstemps() */ #include "lib/widget.h" /* message() */ -#include "src/history.h" - #include "vfs.h" #include "utilvfs.h" @@ -62,6 +60,8 @@ /* Parsing code is used by ftpfs, fish and extfs */ #define MAXCOLS 30 +#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password" + /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index aa02bde5f..90f94bfca 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -58,7 +58,6 @@ #ifdef HAVE_CHARSET #include "lib/charsets.h" #endif -#include "src/setup.h" /* cd_symlinks */ #include "vfs.h" #include "utilvfs.h" @@ -413,7 +412,7 @@ _vfs_get_cwd (void) { struct stat my_stat, my_stat2; /* Check if it is O.K. to use the current_dir */ - if (cd_symlinks + if (mc_global.vfs.cd_symlinks && mc_stat (sys_cwd, &my_stat) == 0 && mc_stat (current_dir, &my_stat2) == 0 && my_stat.st_ino == my_stat2.st_ino && my_stat.st_dev == my_stat2.st_dev) diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c index 49bb5cffa..7f3e1de4e 100644 --- a/lib/widget/dialog-switch.c +++ b/lib/widget/dialog-switch.c @@ -33,7 +33,6 @@ /* TODO: these includes should be removed! */ #include "src/filemanager/layout.h" /* repaint_screen() */ #include "src/filemanager/midnight.h" /* midnight_dlg */ -#include "src/main.h" /* midnight_shutdown */ /*** global variables ****************************************************************************/ @@ -148,7 +147,7 @@ dialog_switch_next (void) { GList *next; - if (midnight_shutdown || mc_current == NULL) + if (mc_global.widget.midnight_shutdown || mc_current == NULL) return; next = g_list_next (mc_current); @@ -165,7 +164,7 @@ dialog_switch_prev (void) { GList *prev; - if (midnight_shutdown || mc_current == NULL) + if (mc_global.widget.midnight_shutdown || mc_current == NULL) return; prev = g_list_previous (mc_current); @@ -187,7 +186,7 @@ dialog_switch_list (void) int i = 0; int rv; - if (midnight_shutdown || mc_current == NULL) + if (mc_global.widget.midnight_shutdown || mc_current == NULL) return; lines = min ((size_t) (LINES * 2 / 3), dlg_num); @@ -240,7 +239,7 @@ dialog_switch_process_pending (void) { destroy_dlg (h); /* return to panels */ - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) { mc_current = g_list_find (mc_dialogs, midnight_dlg); update_panels (UP_OPTIMIZE, UP_KEEPSEL); diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 4181da4c1..f8f383416 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -498,7 +498,7 @@ frontend_run_dlg (Dlg_head * h) event.x = -1; /* close opened editors, viewers, etc */ - if (!h->modal && midnight_shutdown) + if (!h->modal && mc_global.widget.midnight_shutdown) { h->callback (h, NULL, DLG_VALIDATE, 0, NULL); return; @@ -506,7 +506,7 @@ frontend_run_dlg (Dlg_head * h) while (h->state == DLG_ACTIVE) { - if (winch_flag) + if (mc_global.tty.winch_flag) change_screen_size (); if (is_idle ()) diff --git a/lib/widget/history.c b/lib/widget/history.c index b778f54fa..7d24fc970 100644 --- a/lib/widget/history.c +++ b/lib/widget/history.c @@ -49,9 +49,6 @@ #include "lib/util.h" /* list_append_unique */ #include "lib/widget.h" -/* TODO: these includes should be removed! */ -#include "src/setup.h" /* num_history_items_recorded */ - /*** global variables ****************************************************************************/ int num_history_items_recorded = 60; @@ -163,7 +160,7 @@ history_get (const char *input_name) /* create charset conversion handler to convert strings from utf-8 to system codepage */ - if (!utf8_display) + if (!mc_global.utf8_display) conv = str_crt_conv_from ("UTF-8"); buffer = g_string_sized_new (64); @@ -254,7 +251,7 @@ history_put (const char *input_name, GList * h) /* create charset conversion handler to convert strings from system codepage to UTF-8 */ - if (!utf8_display) + if (!mc_global.utf8_display) conv = str_crt_conv_to ("UTF-8"); buffer = g_string_sized_new (64); diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index fa0c23d2b..51602c9e8 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -46,7 +46,6 @@ /* TODO: these includes should be removed! */ #include "src/keybind-defaults.h" /* listbox_map */ -#include "src/setup.h" /* confirm_history_cleanup */ /*** global variables ****************************************************************************/ @@ -269,7 +268,7 @@ listbox_execute_cmd (WListbox * l, unsigned long command) } break; case CK_Clear: - if (l->deletable && confirm_history_cleanup + if (l->deletable && mc_global.widget.confirm_history_cleanup /* TRANSLATORS: no need to translate 'DialogTitle', it's just a context prefix */ && (query_dialog (Q_ ("DialogTitle|History cleanup"), _("Do you want clean this history?"), diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index 9054d7c2f..10a0b7a82 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -386,7 +386,7 @@ message (int flags, const char *title, const char *text, ...) title = _("Error"); #ifdef WITH_BACKGROUND - if (we_are_background) + if (mc_global.we_are_background) { func.f = bg_message; parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p); @@ -416,7 +416,7 @@ input_dialog_help (const char *header, const char *text, const char *help, char *(*f) (const char *, const char *, const char *, const char *, const char *); } func; #ifdef WITH_BACKGROUND - if (we_are_background) + if (mc_global.we_are_background) { func.f = fg_input_dialog_help; return parent_call_string (func.p, 5, diff --git a/src/args.c b/src/args.c index f08256985..15051622c 100644 --- a/src/args.c +++ b/src/args.c @@ -30,19 +30,17 @@ #include "lib/global.h" #include "lib/tty/tty.h" -#include "lib/tty/color.h" /* command_line_colors */ #include "lib/tty/mouse.h" #include "lib/strutil.h" #include "lib/vfs/vfs.h" #include "lib/util.h" /* x_basename() */ #ifdef ENABLE_VFS_SMB -#include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */ +#include "src/vfs/smbfs/smbfs.h" /* smbfs_set_debugf() */ #endif #include "src/main.h" #include "src/textconf.h" -#include "src/subshell.h" /* use_subshell */ #include "src/args.h" @@ -58,15 +56,6 @@ gboolean mc_args__force_xterm = FALSE; gboolean mc_args__nomouse = FALSE; -/* For slow terminals */ -gboolean mc_args__slow_terminal = FALSE; - -/* If true use +, -, | for line drawing */ -gboolean mc_args__ugly_line_drawing = FALSE; - -/* Set to force black and white display at program startup */ -gboolean mc_args__disable_colors = FALSE; - /* Force colors, only used by Slang */ gboolean mc_args__force_colors = FALSE; @@ -76,9 +65,6 @@ gboolean mc_args__nokeymap = FALSE; /* Line to start the editor on */ int mc_args__edit_start_line = 0; -/* Use the specified skin */ -char *mc_args__skin = NULL; - char *mc_args__last_wd_file = NULL; /* when enabled NETCODE, use folowing file as logfile */ @@ -137,7 +123,7 @@ static const GOptionEntry argument_main_table[] = { #ifdef HAVE_SUBSHELL_SUPPORT { "subshell", 'U', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, - &use_subshell, + &mc_global.tty.use_subshell, N_("Enables subshell support (default)"), NULL }, @@ -218,14 +204,14 @@ static const GOptionEntry argument_terminal_table[] = { { "slow", 's', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE, - &mc_args__slow_terminal, + &mc_global.args.slow_terminal, N_("To run on slow terminals"), NULL }, { "stickchars", 'a', ARGS_TERM_OPTIONS, G_OPTION_ARG_NONE, - &mc_args__ugly_line_drawing, + &mc_global.args.ugly_line_drawing, N_("Use stickchars to draw"), NULL }, @@ -261,13 +247,13 @@ static const GOptionEntry argument_terminal_table[] = { GOptionGroup *color_group; #define ARGS_COLOR_OPTIONS 0 -// #define ARGS_COLOR_OPTIONS G_OPTION_FLAG_IN_MAIN +/* #define ARGS_COLOR_OPTIONS G_OPTION_FLAG_IN_MAIN */ static const GOptionEntry argument_color_table[] = { /* *INDENT-OFF* */ /* color options */ { "nocolor", 'b', ARGS_COLOR_OPTIONS, G_OPTION_ARG_NONE, - &mc_args__disable_colors, + &mc_global.args.disable_colors, N_("Requests to run in black and white"), NULL }, @@ -281,14 +267,14 @@ static const GOptionEntry argument_color_table[] = { { "colors", 'C', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING, - &command_line_colors, + &mc_global.tty.command_line_colors, N_("Specifies a color configuration"), "" }, { "skin", 'S', ARGS_COLOR_OPTIONS, G_OPTION_ARG_STRING, - &mc_args__skin, + &mc_global.args.skin, N_("Show mc with specified skin"), "" }, @@ -330,6 +316,7 @@ mc_args_clean_temp_help_strings (void) static GOptionGroup * mc_args_new_color_group (void) { +/* *INDENT-OFF* */ /* FIXME: to preserve translations, lines should be split. */ mc_args__loc__colors_string = g_strdup_printf ("%s\n%s", /* TRANSLATORS: don't translate keywords */ @@ -358,6 +345,7 @@ mc_args_new_color_group (void) "Attributes:\n" " bold, underline, reverse, blink; append more with '+'\n") ); +/* *INDENT-ON* */ return g_option_group_new ("color", mc_args__loc__colors_string, _("Color options"), NULL, NULL); @@ -499,7 +487,7 @@ mc_setup_by_args (int argc, char *argv[]) mc_run_param0 = g_strdup (tmp); } } - mc_run_mode = MC_RUN_EDITOR; + mc_global.mc_run_mode = MC_RUN_EDITOR; } else if (strncmp (base, "mcv", 3) == 0 || strcmp (base, "view") == 0) { @@ -512,7 +500,7 @@ mc_setup_by_args (int argc, char *argv[]) fprintf (stderr, "%s\n", _("No arguments given to the viewer.")); exit (EXIT_FAILURE); } - mc_run_mode = MC_RUN_VIEWER; + mc_global.mc_run_mode = MC_RUN_VIEWER; } #ifdef USE_DIFF_VIEW else if (strncmp (base, "mcd", 3) == 0 || strcmp (base, "diff") == 0) @@ -531,7 +519,7 @@ mc_setup_by_args (int argc, char *argv[]) tmp = (argc > 1) ? argv[2] : NULL; if (tmp != NULL) mc_run_param1 = g_strdup (tmp); - mc_run_mode = MC_RUN_DIFFVIEWER; + mc_global.mc_run_mode = MC_RUN_DIFFVIEWER; } } #endif /* USE_DIFF_VIEW */ @@ -539,7 +527,7 @@ mc_setup_by_args (int argc, char *argv[]) { /* MC is run as mc */ - switch (mc_run_mode) + switch (mc_global.mc_run_mode) { case MC_RUN_EDITOR: case MC_RUN_VIEWER: @@ -560,7 +548,7 @@ mc_setup_by_args (int argc, char *argv[]) if (tmp != NULL) mc_run_param1 = g_strdup (tmp); } - mc_run_mode = MC_RUN_FULL; + mc_global.mc_run_mode = MC_RUN_FULL; break; } } @@ -578,16 +566,16 @@ mc_args_process (int argc, char *argv[]) } if (mc_args__show_datadirs) { - printf ("%s (%s)\n", mc_sysconfig_dir, mc_share_data_dir); + printf ("%s (%s)\n", mc_global.sysconfig_dir, mc_global.share_data_dir); return FALSE; } if (mc_args__force_colors) - mc_args__disable_colors = FALSE; + mc_global.args.disable_colors = FALSE; #ifdef HAVE_SUBSHELL_SUPPORT if (mc_args__nouse_subshell) - use_subshell = 0; + mc_global.tty.use_subshell = FALSE; #endif /* HAVE_SUBSHELL_SUPPORT */ mc_setup_by_args (argc, argv); @@ -622,7 +610,7 @@ parse_mc_e_argument (const gchar * option_name, const gchar * value, gpointer da (void) data; (void) error; - mc_run_mode = MC_RUN_EDITOR; + mc_global.mc_run_mode = MC_RUN_EDITOR; mc_run_param0 = g_strdup (value); return TRUE; @@ -637,7 +625,7 @@ parse_mc_v_argument (const gchar * option_name, const gchar * value, gpointer da (void) data; (void) error; - mc_run_mode = MC_RUN_VIEWER; + mc_global.mc_run_mode = MC_RUN_VIEWER; mc_run_param0 = g_strdup (value); return TRUE; diff --git a/src/args.h b/src/args.h index 4e892b3e9..9e01c3d48 100644 --- a/src/args.h +++ b/src/args.h @@ -13,12 +13,8 @@ extern gboolean mc_args__force_xterm; extern gboolean mc_args__nomouse; -extern gboolean mc_args__slow_terminal; -extern gboolean mc_args__ugly_line_drawing; -extern gboolean mc_args__disable_colors; extern gboolean mc_args__force_colors; extern gboolean mc_args__nokeymap; -extern char *mc_args__skin; extern gboolean mc_args__version; extern int mc_args__edit_start_line; extern char *mc_args__last_wd_file; diff --git a/src/background.c b/src/background.c index 2ace81d64..984a5bfbf 100644 --- a/src/background.c +++ b/src/background.c @@ -56,9 +56,6 @@ #define MAXCALLARGS 4 /* Number of arguments supported */ -/* If true, this is a background process */ -int we_are_background = 0; - /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -475,7 +472,7 @@ do_background (struct FileOpContext *ctx, char *info) parent_fd = comm[1]; from_parent_fd = back_comm[0]; - we_are_background = 1; + mc_global.we_are_background = 1; top_dlg = NULL; /* Make stdin/stdout/stderr point somewhere */ diff --git a/src/background.h b/src/background.h index 26de3ba02..e026d0534 100644 --- a/src/background.h +++ b/src/background.h @@ -37,8 +37,6 @@ struct FileOpContext; extern struct TaskList *task_list; -extern int we_are_background; - /*** declarations of public functions ************************************************************/ int do_background (struct FileOpContext *ctx, char *info); diff --git a/src/cons.handler.c b/src/cons.handler.c index 44bdd6ac3..31d4c9483 100644 --- a/src/cons.handler.c +++ b/src/cons.handler.c @@ -45,8 +45,6 @@ /*** global variables ****************************************************************************/ -signed char console_flag = 0; - #ifdef __linux__ int cons_saver_pid = 1; #endif /* __linux__ */ @@ -90,13 +88,13 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char ssize_t ret; /* Is tty console? */ - if (!console_flag) + if (!mc_global.tty.console_flag) return; /* Paranoid: Is the cons.saver still running? */ if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT)) { cons_saver_pid = 0; - console_flag = 0; + mc_global.tty.console_flag = '\0'; return; } @@ -123,7 +121,7 @@ show_console_contents_linux (int starty, unsigned char begin_line, unsigned char tty_print_char (message); } - /* Read the value of the console_flag */ + /* Read the value of the mc_global.tty.console_flag */ ret = read (pipefd2[0], &message, 1); } @@ -145,7 +143,7 @@ handle_console_linux (unsigned char action) /* Create two pipes for communication */ if (!((pipe (pipefd1) == 0) && ((pipe (pipefd2)) == 0))) { - console_flag = 0; + mc_global.tty.console_flag = '\0'; break; } /* Get the console saver running */ @@ -158,7 +156,7 @@ handle_console_linux (unsigned char action) status = close (pipefd1[0]); status = close (pipefd2[1]); status = close (pipefd2[0]); - console_flag = 0; + mc_global.tty.console_flag = '\0'; } else if (cons_saver_pid > 0) { @@ -167,8 +165,8 @@ handle_console_linux (unsigned char action) status = close (pipefd1[0]); status = close (pipefd2[1]); /* Was the child successful? */ - status = read (pipefd2[0], &console_flag, 1); - if (!console_flag) + status = read (pipefd2[0], &mc_global.tty.console_flag, 1); + if (!mc_global.tty.console_flag) { pid_t ret; status = close (pipefd1[1]); @@ -208,8 +206,8 @@ handle_console_linux (unsigned char action) /* Console is not a tty or execl() failed */ } while (0); - console_flag = 0; - status = write (1, &console_flag, 1); + mc_global.tty.console_flag = '\0'; + status = write (1, &mc_global.tty.console_flag, 1); _exit (3); } /* if (cons_saver_pid ...) */ break; @@ -218,13 +216,13 @@ handle_console_linux (unsigned char action) case CONSOLE_SAVE: case CONSOLE_RESTORE: /* Is tty console? */ - if (!console_flag) + if (!mc_global.tty.console_flag) return; /* Paranoid: Is the cons.saver still running? */ if (cons_saver_pid < 1 || kill (cons_saver_pid, SIGCONT)) { cons_saver_pid = 0; - console_flag = 0; + mc_global.tty.console_flag = '\0'; return; } /* Send command to the console handler */ @@ -232,16 +230,16 @@ handle_console_linux (unsigned char action) if (action != CONSOLE_DONE) { /* Wait the console handler to do its job */ - status = read (pipefd2[0], &console_flag, 1); + status = read (pipefd2[0], &mc_global.tty.console_flag, 1); } - if (action == CONSOLE_DONE || !console_flag) + if (action == CONSOLE_DONE || !mc_global.tty.console_flag) { /* We are done -> Let's clean up */ pid_t ret; close (pipefd1[1]); close (pipefd2[0]); ret = waitpid (cons_saver_pid, &status, 0); - console_flag = 0; + mc_global.tty.console_flag = '\0'; } break; } @@ -258,7 +256,7 @@ handle_console_linux (unsigned char action) static void console_init (void) { - if (console_flag) + if (mc_global.tty.console_flag) return; screen_info.size = sizeof (screen_info); @@ -270,7 +268,7 @@ console_init (void) screen_shot.ysize = screen_info.mv_rsz; screen_shot.buf = g_try_malloc (screen_info.mv_csz * screen_info.mv_rsz * 2); if (screen_shot.buf != NULL) - console_flag = 1; + mc_global.tty.console_flag = '\001'; } /* --------------------------------------------------------------------------------------------- */ @@ -299,7 +297,7 @@ console_restore (void) { int i, last; - if (!console_flag) + if (!mc_global.tty.console_flag) return; cursor_to (0, 0); @@ -323,12 +321,12 @@ console_restore (void) static void console_shutdown (void) { - if (!console_flag) + if (!mc_global.tty.console_flag) return; g_free (screen_shot.buf); - console_flag = 0; + mc_global.tty.console_flag = '\0'; } /* --------------------------------------------------------------------------------------------- */ @@ -340,7 +338,7 @@ console_save (void) scrmap_t map; scrmap_t revmap; - if (!console_flag) + if (!mc_global.tty.console_flag) return; /* screen_info.size is already set in console_init() */ @@ -391,7 +389,7 @@ show_console_contents_freebsd (int starty, unsigned char begin_line, unsigned ch int col, line; char c; - if (!console_flag) + if (!mc_global.tty.console_flag) return; for (line = begin_line; line <= end_line; line++) @@ -450,7 +448,7 @@ show_console_contents (int starty, unsigned char begin_line, unsigned char end_l #elif defined (__FreeBSD__) show_console_contents_freebsd (starty, begin_line, end_line); #else - console_flag = 0; + mc_global.tty.console_flag = '\0'; #endif } diff --git a/src/consaver/cons.saver.h b/src/consaver/cons.saver.h index f2d5fef67..b5ee628a0 100644 --- a/src/consaver/cons.saver.h +++ b/src/consaver/cons.saver.h @@ -31,7 +31,6 @@ enum #ifndef LINUX_CONS_SAVER_C /* Used only in mc, not in cons.saver */ -extern signed char console_flag; extern int cons_saver_pid; #endif /* !LINUX_CONS_SAVER_C */ diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index c02a9c377..8fce0872a 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -38,7 +38,7 @@ #include "lib/tty/color.h" #include "lib/tty/key.h" #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ -#include "lib/vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */ +#include "lib/vfs/vfs.h" /* mc_opendir, mc_readdir, mc_closedir, */ #include "lib/util.h" #include "lib/widget.h" #include "lib/charsets.h" @@ -50,7 +50,6 @@ #include "src/keybind-defaults.h" #include "src/help.h" #include "src/history.h" -#include "src/main.h" /* mc_run_mode, midnight_shutdown */ #include "src/selcodepage.h" #include "ydiff.h" @@ -119,7 +118,7 @@ dview_set_codeset (WDiff * dview) const char *encoding_id = NULL; dview->utf8 = TRUE; - encoding_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage); + encoding_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage); if (encoding_id != NULL) { GIConv conv; @@ -2582,7 +2581,7 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int { tty_setcolor (att[cnt] ? DFF_CHH_COLOR : DFF_CHG_COLOR); #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!dview->utf8) { @@ -2660,7 +2659,7 @@ dview_display_file (const WDiff * dview, int ord, int r, int c, int height, int if (ch_res) { #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!dview->utf8) { @@ -2943,13 +2942,13 @@ dview_ok_to_exit (WDiff * dview) if (!dview->merged) return res; - act = query_dialog (_("Quit"), !midnight_shutdown ? + act = query_dialog (_("Quit"), !mc_global.widget.midnight_shutdown ? _("File was modified. Save with exit?") : _("Midnight Commander is being shut down.\nSave modified file?"), D_NORMAL, 2, _("&Yes"), _("&No")); /* Esc is No */ - if (midnight_shutdown || (act == -1)) + if (mc_global.widget.midnight_shutdown || (act == -1)) act = 1; switch (act) @@ -3235,7 +3234,7 @@ dview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, v case DLG_VALIDATE: dview = (WDiff *) find_widget_type (h, dview_callback); - h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ + h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ if (dview_ok_to_exit (dview)) h->state = DLG_CLOSED; return MSG_HANDLED; @@ -3357,7 +3356,7 @@ dview_diff_cmd (void) int is_dir0 = 0; int is_dir1 = 0; - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) { const WPanel *panel0 = current_panel; const WPanel *panel1 = other_panel; diff --git a/src/editor/edit.c b/src/editor/edit.c index 97008f62f..226151b79 100644 --- a/src/editor/edit.c +++ b/src/editor/edit.c @@ -60,7 +60,6 @@ #include "src/filemanager/cmd.h" /* view_other_cmd() */ #include "src/filemanager/usermenu.h" /* user_menu_cmd() */ -#include "src/main.h" /* source_codepage */ #include "src/setup.h" /* option_tab_spacing */ #include "src/learn.h" /* learn_keys */ #include "src/keybind-defaults.h" @@ -2322,7 +2321,7 @@ edit_set_codeset (WEdit * edit) #ifdef HAVE_CHARSET const char *cp_id; - cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage); + cp_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage); if (cp_id != NULL) { @@ -2937,7 +2936,7 @@ edit_move_forward3 (WEdit * edit, long current, int cols, long upto) int cw = 1; utf_ch = edit_get_utf (edit, p, &cw); - if (utf8_display) + if (mc_global.utf8_display) { if (cw > 1) col -= cw - 1; @@ -2960,7 +2959,7 @@ edit_move_forward3 (WEdit * edit, long current, int cols, long upto) else return p; } - else if ((c < 32 || c == 127) && (orig_c == c || (!utf8_display && !edit->utf8))) + else if ((c < 32 || c == 127) && (orig_c == c || (!mc_global.utf8_display && !edit->utf8))) /* '\r' is shown as ^M, so we must advance 2 characters */ /* Caret notation for control characters */ col += 2; @@ -3499,14 +3498,14 @@ edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion) if (edit->overwrite) { /* remove char only one time, after input first byte, multibyte chars */ - if ((!utf8_display || edit->charpoint == 0) + if ((!mc_global.utf8_display || edit->charpoint == 0) && edit_get_byte (edit, edit->curs1) != '\n') edit_delete (edit, 0); } if (option_cursor_beyond_eol && edit->over_col > 0) edit_insert_over (edit); #ifdef HAVE_CHARSET - if (char_for_insertion > 255 && utf8_display == 0) + if (char_for_insertion > 255 && mc_global.utf8_display == 0) { unsigned char str[6 + 1]; size_t i = 0; diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 13487d96e..5b05e0b58 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -60,7 +60,6 @@ #include "src/filemanager/layout.h" /* clr_scr() */ #include "src/history.h" -#include "src/main.h" /* mc_sysconfig_dir, midnight_shutdown */ #include "src/setup.h" /* option_tab_spacing */ #include "src/help.h" /* interactive_display() */ #include "src/selcodepage.h" @@ -515,11 +514,11 @@ edit_load_syntax_file (WEdit * edit) _("&User"), _("&System Wide")); } - extdir = g_build_filename (mc_sysconfig_dir, "syntax", "Syntax", (char *) NULL); + extdir = g_build_filename (mc_global.sysconfig_dir, "syntax", "Syntax", (char *) NULL); if (!exist_file (extdir)) { g_free (extdir); - extdir = g_build_filename (mc_share_data_dir, "syntax", "Syntax", (char *) NULL); + extdir = g_build_filename (mc_global.share_data_dir, "syntax", "Syntax", (char *) NULL); } if (dir == 0) @@ -550,12 +549,12 @@ edit_load_menu_file (WEdit * edit) _("Which menu file do you want to edit?"), D_NORMAL, geteuid () != 0 ? 2 : 3, _("&Local"), _("&User"), _("&System Wide")); - menufile = concat_dir_and_file (mc_sysconfig_dir, EDIT_GLOBAL_MENU); + menufile = concat_dir_and_file (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU); if (!exist_file (menufile)) { g_free (menufile); - menufile = concat_dir_and_file (mc_share_data_dir, EDIT_GLOBAL_MENU); + menufile = concat_dir_and_file (mc_global.share_data_dir, EDIT_GLOBAL_MENU); } switch (dir) @@ -572,11 +571,11 @@ edit_load_menu_file (WEdit * edit) break; case 2: - buffer = concat_dir_and_file (mc_sysconfig_dir, EDIT_GLOBAL_MENU); + buffer = concat_dir_and_file (mc_global.sysconfig_dir, EDIT_GLOBAL_MENU); if (!exist_file (buffer)) { g_free (buffer); - buffer = concat_dir_and_file (mc_share_data_dir, EDIT_GLOBAL_MENU); + buffer = concat_dir_and_file (mc_global.share_data_dir, EDIT_GLOBAL_MENU); } break; @@ -2486,7 +2485,7 @@ edit_ok_to_exit (WEdit * edit) if (!edit->modified) return TRUE; - if (!midnight_shutdown) + if (!mc_global.widget.midnight_shutdown) { if (!edit_check_newline (edit)) return FALSE; @@ -2512,8 +2511,8 @@ edit_ok_to_exit (WEdit * edit) case 0: /* Yes */ edit_push_markers (edit); edit_set_markers (edit, 0, 0, 0, 0); - if (!edit_save_cmd (edit) || midnight_shutdown) - return (gboolean) midnight_shutdown; + if (!edit_save_cmd (edit) || mc_global.widget.midnight_shutdown) + return mc_global.widget.midnight_shutdown; break; case 1: /* No */ break; diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index 37eb85279..7fbb2942a 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -47,7 +47,6 @@ #include "lib/widget.h" /* buttonbar_redraw() */ #include "lib/charsets.h" -#include "src/main.h" /* source_codepage */ #include "src/setup.h" /* edit_tab_spacing */ #include "edit-impl.h" @@ -151,7 +150,7 @@ status_string (WEdit * edit, char *s, int w) edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, #ifdef HAVE_CHARSET - source_codepage >= 0 ? get_codepage_id (source_codepage) : "" + mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : "" #else "" #endif @@ -169,7 +168,7 @@ status_string (WEdit * edit, char *s, int w) edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte, byte_str, #ifdef HAVE_CHARSET - source_codepage >= 0 ? get_codepage_id (source_codepage) : "" + mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : "" #else "" #endif @@ -502,7 +501,7 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co /* fallthrough */ default: #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!edit->utf8) { @@ -540,8 +539,8 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co } if (!edit->utf8) { - if ((utf8_display && g_unichar_isprint (c)) || - (!utf8_display && is_printable (c))) + if ((mc_global.utf8_display && g_unichar_isprint (c)) || + (!mc_global.utf8_display && is_printable (c))) { p->ch = c; p++; diff --git a/src/editor/editkeys.c b/src/editor/editkeys.c index 9a945473c..bc41dad56 100644 --- a/src/editor/editkeys.c +++ b/src/editor/editkeys.c @@ -51,7 +51,6 @@ #include "editcmd_dialogs.h" #include "src/keybind-defaults.h" /* keybind_lookup_keymap_command() */ -#include "src/main.h" /* display_codepage */ /*** global variables ****************************************************************************/ @@ -95,7 +94,7 @@ edit_translate_key (WEdit * edit, long x_key, int *cmd, int *ch) } /* input from 8-bit locale */ - if (!utf8_display) + if (!mc_global.utf8_display) { /* source in 8-bit codeset */ if (!edit->utf8) diff --git a/src/editor/syntax.c b/src/editor/syntax.c index 5863a48fe..b00827ed7 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -57,8 +57,6 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "src/main.h" /* mc_sysconfig_dir */ - #include "edit-impl.h" #include "edit-widget.h" @@ -859,13 +857,13 @@ open_include_file (const char *filename) return f; g_free (error_file_name); - error_file_name = g_build_filename (mc_sysconfig_dir, "syntax", filename, (char *) NULL); + error_file_name = g_build_filename (mc_global.sysconfig_dir, "syntax", filename, (char *) NULL); f = fopen (error_file_name, "r"); if (f != NULL) return f; g_free (error_file_name); - error_file_name = g_build_filename (mc_share_data_dir, "syntax", filename, (char *) NULL); + error_file_name = g_build_filename (mc_global.share_data_dir, "syntax", filename, (char *) NULL); return fopen (error_file_name, "r"); } @@ -1267,7 +1265,7 @@ edit_read_syntax_file (WEdit * edit, char ***pnames, const char *syntax_file, f = fopen (syntax_file, "r"); if (f == NULL) { - lib_file = g_build_filename (mc_share_data_dir, "syntax", "Syntax", (char *) NULL); + lib_file = g_build_filename (mc_global.share_data_dir, "syntax", "Syntax", (char *) NULL); f = fopen (lib_file, "r"); g_free (lib_file); if (f == NULL) diff --git a/src/execute.c b/src/execute.c index bbdeba803..bbda6de39 100644 --- a/src/execute.c +++ b/src/execute.c @@ -81,7 +81,7 @@ edition_pre_exec (void) clr_scr (); else { - if (!(console_flag || xterm_flag)) + if (!(mc_global.tty.console_flag || xterm_flag)) printf ("\n\n"); } @@ -132,19 +132,19 @@ do_execute (const char *lc_shell, const char *command, int flags) if (!vfs_current_is_local ()) old_vfs_dir = g_strdup (vfs_get_current_dir ()); - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) save_cwds_stat (); pre_exec (); - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_RESTORE); - if (!use_subshell && command && !(flags & EXECUTE_INTERNAL)) + if (!mc_global.tty.use_subshell && command && !(flags & EXECUTE_INTERNAL)) { printf ("%s%s\n", mc_prompt, command); fflush (stdout); } #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell && !(flags & EXECUTE_INTERNAL)) + if (mc_global.tty.use_subshell && !(flags & EXECUTE_INTERNAL)) { do_update_prompt (); @@ -159,7 +159,7 @@ do_execute (const char *lc_shell, const char *command, int flags) { if ((pause_after_run == pause_always || (pause_after_run == pause_on_dumb_terminals && !xterm_flag - && !console_flag)) && quit == 0 + && !mc_global.tty.console_flag)) && quit == 0 #ifdef HAVE_SUBSHELL_SUPPORT && subshell_state != RUNNING_COMMAND #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -172,9 +172,9 @@ do_execute (const char *lc_shell, const char *command, int flags) printf ("\r\n"); fflush (stdout); } - if (console_flag) + if (mc_global.tty.console_flag) { - if (output_lines && keybar_visible) + if (output_lines && mc_global.keybar_visible) { putchar ('\n'); fflush (stdout); @@ -182,7 +182,7 @@ do_execute (const char *lc_shell, const char *command, int flags) } } - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_SAVE); edition_post_exec (); @@ -198,7 +198,7 @@ do_execute (const char *lc_shell, const char *command, int flags) g_free (old_vfs_dir); } - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) { update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); @@ -215,7 +215,7 @@ do_suspend_cmd (void) { pre_exec (); - if (console_flag && !use_subshell) + if (mc_global.tty.console_flag && !mc_global.tty.use_subshell) handle_console (CONSOLE_RESTORE); #ifdef SIGTSTP @@ -234,7 +234,7 @@ do_suspend_cmd (void) } #endif /* SIGTSTP */ - if (console_flag && !use_subshell) + if (mc_global.tty.console_flag && !mc_global.tty.use_subshell) handle_console (CONSOLE_SAVE); edition_post_exec (); @@ -277,7 +277,7 @@ shell_execute (const char *command, int flags) } #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_global.tty.use_subshell) if (subshell_state == INACTIVE) do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); else @@ -324,11 +324,11 @@ toggle_panels (void) tty_reset_screen (); do_exit_ca_mode (); tty_raw_mode (); - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_RESTORE); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_global.tty.use_subshell) { new_dir_p = vfs_current_is_local ()? &new_dir : NULL; invoke_subshell (NULL, VISIBLY, new_dir_p); @@ -347,7 +347,7 @@ toggle_panels (void) get_key_code (0); } - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_SAVE); do_enter_ca_mode (); @@ -366,7 +366,7 @@ toggle_panels (void) quit = 0; #ifdef HAVE_SUBSHELL_SUPPORT /* restart subshell */ - if (use_subshell) + if (mc_global.tty.use_subshell) init_subshell (); #endif /* HAVE_SUBSHELL_SUPPORT */ } @@ -377,19 +377,19 @@ toggle_panels (void) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_global.tty.use_subshell) { load_prompt (0, NULL); if (new_dir) do_possible_cd (new_dir); - if (console_flag && output_lines) + if (mc_global.tty.console_flag && output_lines) show_console_contents (output_start_y, - LINES - keybar_visible - output_lines - - 1, LINES - keybar_visible - 1); + LINES - mc_global.keybar_visible - output_lines - + 1, LINES - mc_global.keybar_visible - 1); } #endif /* HAVE_SUBSHELL_SUPPORT */ - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) { update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_xterm_title_path (); @@ -402,10 +402,10 @@ toggle_panels (void) void suspend_cmd (void) { - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) save_cwds_stat (); do_suspend_cmd (); - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) update_panels (UP_OPTIMIZE, UP_KEEPSEL); do_refresh (); } diff --git a/src/filemanager/boxes.c b/src/filemanager/boxes.c index 6c7a53995..db4cf2e6f 100644 --- a/src/filemanager/boxes.c +++ b/src/filemanager/boxes.c @@ -337,7 +337,7 @@ sel_charset_button (WButton * button, int action) _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) - utf8_display = str_isutf8 (cpname); + mc_global.utf8_display = str_isutf8 (cpname); /* avoid strange bug with label repainting */ g_snprintf (buf, sizeof (buf), "%-27s", cpname); label_set_text (cplabel, buf); @@ -576,7 +576,7 @@ display_box (WPanel * panel, char **userp, char **minip, int *use_msformat, int /* --------------------------------------------------------------------------------------------- */ const panel_field_t * -sort_box (panel_sort_info_t *info) +sort_box (panel_sort_info_t * info) { int dlg_width = 40, dlg_height = 7; @@ -603,9 +603,11 @@ sort_box (panel_sort_info_t *info) /* 2 */ QUICK_CHECKBOX (0, dlg_width, 5, dlg_height, N_("&Reverse"), &info->reverse), /* 3 */ - QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), &info->case_sensitive), + QUICK_CHECKBOX (0, dlg_width, 4, dlg_height, N_("Case sensi&tive"), + &info->case_sensitive), /* 4 */ - QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), &info->exec_first), + QUICK_CHECKBOX (0, dlg_width, 3, dlg_height, N_("Executable &first"), + &info->exec_first), /* 5 */ QUICK_RADIO (4, dlg_width, 3, dlg_height, 0, NULL, &sort_idx), QUICK_END @@ -687,7 +689,7 @@ confirm_box (void) /* 1 */ QUICK_BUTTON (12, 46, 10, 13, N_("&OK"), B_ENTER, NULL), /* TRANSLATORS: no need to translate 'Confirmation', it's just a context prefix */ /* 2 */ QUICK_CHECKBOX (3, 46, 8, 13, N_("Confirmation|&History cleanup"), - &confirm_history_cleanup), + &mc_global.widget.confirm_history_cleanup), /* 3 */ QUICK_CHECKBOX (3, 46, 7, 13, N_("Confirmation|Di&rectory hotlist delete"), &confirm_directory_hotlist_delete), /* 4 */ QUICK_CHECKBOX (3, 46, 6, 13, N_("Confirmation|E&xit"), &confirm_exit), @@ -823,9 +825,9 @@ display_bits_box (void) /* AB:FIXME: test dialog */ display_widgets[0].relative_x = display_bits.xlen * 2 / 3 - cancel_len / 2; display_widgets[1].relative_x = display_bits.xlen / 3 - ok_len / 2; - if (full_eight_bits) + if (mc_global.full_eight_bits) current_mode = 0; - else if (eight_bit_clean) + else if (mc_global.eight_bit_clean) current_mode = 1; else current_mode = 2; @@ -834,12 +836,12 @@ display_bits_box (void) /* AB:FIXME: test dialog */ if (quick_dialog (&display_bits) != B_CANCEL) { - eight_bit_clean = current_mode < 3; - full_eight_bits = current_mode < 2; + mc_global.eight_bit_clean = current_mode < 3; + mc_global.full_eight_bits = current_mode < 2; #ifndef HAVE_SLANG - meta (stdscr, eight_bit_clean); + meta (stdscr, mc_global.eight_bit_clean); #else - SLsmg_Display_Eight_Bit = full_eight_bits ? 128 : 160; + SLsmg_Display_Eight_Bit = mc_global.full_eight_bits ? 128 : 160; #endif use_8th_bit_as_meta = !new_meta; } @@ -852,7 +854,7 @@ void display_bits_box (void) { Dlg_head *dbits_dlg; - new_display_codepage = display_codepage; + new_display_codepage = mc_global.display_codepage; application_keypad_mode (); dbits_dlg = init_disp_bits_box (); @@ -863,17 +865,17 @@ display_bits_box (void) { char *errmsg; - display_codepage = new_display_codepage; - errmsg = init_translation_table (source_codepage, display_codepage); + mc_global.display_codepage = new_display_codepage; + errmsg = init_translation_table (mc_global.source_codepage, mc_global.display_codepage); if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); g_free (errmsg); } #ifdef HAVE_SLANG - tty_display_8bit (display_codepage != 0 && display_codepage != 1); + tty_display_8bit (mc_global.display_codepage != 0 && mc_global.display_codepage != 1); #else - tty_display_8bit (display_codepage != 0); + tty_display_8bit (mc_global.display_codepage != 0); #endif use_8th_bit_as_meta = !(inpcheck->state & C_BOOL); } diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 4027f5079..a58ea5f16 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -60,8 +60,6 @@ #include "lib/widget.h" #include "lib/keybind.h" /* CK_Down, CK_History */ -#include "src/subshell.h" /* use_subshell */ -#include "src/consaver/cons.saver.h" /* console_flag */ #include "src/viewer/mcviewer.h" #include "src/help.h" /* interactive_display() */ #include "src/setup.h" @@ -767,7 +765,7 @@ do_edit_at_line (const char *what, gboolean internal, int start_line) execute_with_vfs_arg (editor, what); } - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) update_panels (UP_OPTIMIZE, UP_KEEPSEL); #ifdef USE_INTERNAL_EDIT @@ -804,7 +802,7 @@ void edit_cmd_new (void) { #if HAVE_CHARSET - source_codepage = default_source_codepage; + mc_global.source_codepage = default_source_codepage; #endif do_edit (NULL); } @@ -1022,7 +1020,7 @@ ext_cmd (void) _("Which extension file you want to edit?"), D_NORMAL, 2, _("&User"), _("&System Wide")); } - extdir = concat_dir_and_file (mc_sysconfig_dir, MC_LIB_EXT); + extdir = concat_dir_and_file (mc_global.sysconfig_dir, MC_LIB_EXT); if (dir == 0) { @@ -1036,7 +1034,7 @@ ext_cmd (void) if (!exist_file (extdir)) { g_free (extdir); - extdir = concat_dir_and_file (mc_share_data_dir, MC_LIB_EXT); + extdir = concat_dir_and_file (mc_global.share_data_dir, MC_LIB_EXT); } do_edit (extdir); } @@ -1058,12 +1056,12 @@ edit_mc_menu_cmd (void) _("Which menu file do you want to edit?"), D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide")); - menufile = concat_dir_and_file (mc_sysconfig_dir, MC_GLOBAL_MENU); + menufile = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU); if (!exist_file (menufile)) { g_free (menufile); - menufile = concat_dir_and_file (mc_share_data_dir, MC_GLOBAL_MENU); + menufile = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU); } switch (dir) @@ -1080,11 +1078,11 @@ edit_mc_menu_cmd (void) break; case 2: - buffer = concat_dir_and_file (mc_sysconfig_dir, MC_GLOBAL_MENU); + buffer = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU); if (!exist_file (buffer)) { g_free (buffer); - buffer = concat_dir_and_file (mc_share_data_dir, MC_GLOBAL_MENU); + buffer = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU); } break; @@ -1116,7 +1114,7 @@ edit_fhl_cmd (void) _("Which highlighting file you want to edit?"), D_NORMAL, 2, _("&User"), _("&System Wide")); } - fhlfile = concat_dir_and_file (mc_sysconfig_dir, MC_FHL_INI_FILE); + fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE); if (dir == 0) { @@ -1130,7 +1128,7 @@ edit_fhl_cmd (void) if (!exist_file (fhlfile)) { g_free (fhlfile); - fhlfile = concat_dir_and_file (mc_sysconfig_dir, MC_FHL_INI_FILE); + fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE); } do_edit (fhlfile); } @@ -1217,7 +1215,7 @@ diff_view_cmd (void) { dview_diff_cmd (); - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) update_panels (UP_OPTIMIZE, UP_KEEPSEL); dialog_switch_process_pending (); @@ -1241,7 +1239,8 @@ view_other_cmd (void) { static int message_flag = TRUE; - if (!xterm_flag && !console_flag && !use_subshell && !output_starts_shell) + if (!xterm_flag && !mc_global.tty.console_flag && !mc_global.tty.use_subshell + && !output_starts_shell) { if (message_flag) message (D_ERROR, MSG_ERROR, @@ -1358,7 +1357,7 @@ get_random_hint (int force) return g_strdup (""); last_sec = tv.tv_sec; - data = load_mc_home_file (mc_share_data_dir, MC_HINT, NULL); + data = load_mc_home_file (mc_global.share_data_dir, MC_HINT, NULL); if (data == NULL) return NULL; diff --git a/src/filemanager/command.c b/src/filemanager/command.c index f05e83778..e37e26f8a 100644 --- a/src/filemanager/command.c +++ b/src/filemanager/command.c @@ -215,7 +215,7 @@ enter (WInput * lc_cmdline) #ifdef HAVE_SUBSHELL_SUPPORT /* Check this early before we clean command line * (will be checked again by shell_execute) */ - if (use_subshell && subshell_state != INACTIVE) + if (mc_global.tty.use_subshell && subshell_state != INACTIVE) { message (D_ERROR, MSG_ERROR, _("The shell is already running a command")); return MSG_NOT_HANDLED; @@ -254,11 +254,11 @@ enter (WInput * lc_cmdline) quit = 0; /* restart subshell */ - if (use_subshell) + if (mc_global.tty.use_subshell) init_subshell (); } - if (use_subshell) + if (mc_global.tty.use_subshell) load_prompt (0, NULL); #endif } diff --git a/src/filemanager/complete.c b/src/filemanager/complete.c index 5d238d7be..9817fc75a 100644 --- a/src/filemanager/complete.c +++ b/src/filemanager/complete.c @@ -46,8 +46,6 @@ #include "lib/util.h" #include "lib/widget.h" -#include "src/setup.h" /* show_all_if_ambiguous */ - /*** global variables ****************************************************************************/ /* Linux declares environ in , so don't repeat it here. */ @@ -1343,7 +1341,7 @@ complete (WInput * in) { engine_flags = DO_INSERTION; - if (show_all_if_ambiguous) + if (mc_global.widget.show_all_if_ambiguous) engine_flags |= DO_QUERY; } diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 0f371ad4c..e63407f9e 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -352,13 +352,13 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st else { shell_execute (cmd, EXECUTE_INTERNAL); - if (console_flag) + if (mc_global.tty.console_flag) { handle_console (CONSOLE_SAVE); - if (output_lines && keybar_visible) + if (output_lines && mc_global.keybar_visible) show_console_contents (output_start_y, - LINES - keybar_visible - - output_lines - 1, LINES - keybar_visible - 1); + LINES - mc_global.keybar_visible - + output_lines - 1, LINES - mc_global.keybar_visible - 1); } } @@ -635,11 +635,11 @@ regex_command (const char *filename, const char *action, int *move_dir) { g_free (extension_file); check_stock_mc_ext: - extension_file = concat_dir_and_file (mc_sysconfig_dir, MC_LIB_EXT); + extension_file = concat_dir_and_file (mc_global.sysconfig_dir, MC_LIB_EXT); if (!exist_file (extension_file)) { g_free (extension_file); - extension_file = concat_dir_and_file (mc_share_data_dir, MC_LIB_EXT); + extension_file = concat_dir_and_file (mc_global.share_data_dir, MC_LIB_EXT); } mc_user_ext = 0; } @@ -663,12 +663,12 @@ regex_command (const char *filename, const char *action, int *move_dir) else { char *title = g_strdup_printf (_(" %s%s file error"), - mc_sysconfig_dir, MC_LIB_EXT); + mc_global.sysconfig_dir, MC_LIB_EXT); message (D_ERROR, title, _("The format of the %smc.ext " "file has changed with version 3.0. It seems that " "the installation failed. Please fetch a fresh " "copy from the Midnight Commander package."), - mc_sysconfig_dir); + mc_global.sysconfig_dir); g_free (title); return 0; } @@ -683,7 +683,7 @@ regex_command (const char *filename, const char *action, int *move_dir) _("The format of the %s%s%s file has " "changed with version 3.0. You may either want to copy " "it from %smc.ext or use that file as an example of how to write it."), - mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE, mc_sysconfig_dir); + mc_config_get_data_path (), PATH_SEP_STR, MC_FILEBIND_FILE, mc_global.sysconfig_dir); g_free (title); } } diff --git a/src/filemanager/file.c b/src/filemanager/file.c index e87eddc25..42e011713 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -66,7 +66,7 @@ #include "lib/widget.h" #include "src/setup.h" -#include "src/background.h" /* we_are_background */ +#include "src/background.h" #include "layout.h" /* rotate_dash() */ @@ -469,13 +469,13 @@ warn_same_file (const char *fmt, const char *a, const char *b) union { void *p; - FileProgressStatus (*f) (enum OperationMode, const char *fmt, - const char *a, const char *b); + FileProgressStatus (*f) (enum OperationMode, const char *fmt, + const char *a, const char *b); } pntr; pntr.f = real_warn_same_file; - if (we_are_background) + if (mc_global.we_are_background) return parent_call (pntr.p, NULL, 3, strlen (fmt), fmt, strlen (a), a, strlen (b), b); #endif return real_warn_same_file (Foreground, fmt, a, b); @@ -1160,7 +1160,7 @@ do_file_error (const char *str) } pntr; pntr.f = real_do_file_error; - if (we_are_background) + if (mc_global.we_are_background) return parent_call (pntr.p, NULL, 1, strlen (str), str); else return real_do_file_error (Foreground, str); @@ -1178,7 +1178,7 @@ query_recursive (FileOpContext * ctx, const char *s) } pntr; pntr.f = real_query_recursive; - if (we_are_background) + if (mc_global.we_are_background) return parent_call (pntr.p, ctx, 1, strlen (s), s); else return real_query_recursive (ctx, Foreground, s); @@ -1198,7 +1198,7 @@ query_replace (FileOpContext * ctx, const char *destname, struct stat *_s_stat, } pntr; pntr.f = file_progress_real_query_replace; - if (we_are_background) + if (mc_global.we_are_background) return parent_call (pntr.p, ctx, 3, strlen (destname), destname, sizeof (struct stat), _s_stat, sizeof (struct stat), _d_stat); else @@ -2639,7 +2639,7 @@ panel_operate (void *source_panel, FileOperation operation, gboolean force_singl #ifdef WITH_BACKGROUND /* Let our parent know we are saying bye bye */ - if (we_are_background) + if (mc_global.we_are_background) { int cur_pid = getpid (); /* Send pid to parent with child context, it is fork and diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 5c1f61949..00c4d6ecf 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -51,16 +51,15 @@ #include "lib/tty/mouse.h" #include "lib/tty/win.h" /* do_enter_ca_mode() */ #include "lib/mcconfig.h" -#include "lib/vfs/vfs.h" /* For vfs_translate_url() */ +#include "lib/vfs/vfs.h" /* For vfs_translate_url() */ #include "lib/strutil.h" #include "lib/widget.h" -#include "src/main.h" #include "src/consaver/cons.saver.h" #include "src/viewer/mcviewer.h" /* The view widget */ #include "src/setup.h" -#include "src/subshell.h" /* For use_subshell and resize_subshell() */ -#include "src/background.h" /* we_are_background */ +#include "src/subshell.h" /* For resize_subshell() */ +#include "src/background.h" #include "command.h" #include "midnight.h" @@ -79,9 +78,6 @@ int nice_rotating_dash = 1; /* Set if the panels are split horizontally */ int horizontal_split = 0; -/* Set if the window has changed it's size */ -int winch_flag = 0; - /* Set if the split is the same */ int equal_split = 1; @@ -97,12 +93,6 @@ int command_prompt = 1; /* Set if the main menu is visible */ int menubar_visible = 1; -/* Set if the nice and useful keybar is visible */ -int keybar_visible = 1; - -/* Set if the nice message (hint) bar is visible */ -int message_visible = 1; - /* Set to show current working dir in xterm window title */ int xterm_title = 1; @@ -187,8 +177,8 @@ static struct /* *INDENT-OFF* */ { N_("Show free sp&ace"), &free_space, NULL}, { N_("&XTerm window title"), &xterm_title, NULL}, - { N_("H&intbar visible"), &message_visible, NULL}, - { N_("&Keybar visible"), &keybar_visible, NULL}, + { N_("H&intbar visible"), &mc_global.message_visible, NULL}, + { N_("&Keybar visible"), &mc_global.keybar_visible, NULL}, { N_("Command &prompt"), &command_prompt, NULL}, { N_("Menu&bar visible"), &menubar_visible, NULL}, { N_("&Equal split"), &equal_split, NULL} @@ -319,7 +309,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d if (old_output_lines != _output_lines) { old_output_lines = _output_lines; - tty_setcolor (console_flag ? COLOR_NORMAL : DISABLED_COLOR); + tty_setcolor (mc_global.tty.console_flag ? COLOR_NORMAL : DISABLED_COLOR); dlg_move (h, 9, 6); tty_print_string (output_lines_label); dlg_move (h, 9, 6 + 3 + output_lines_label_len); @@ -335,7 +325,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d _xterm_title = check_options[1].widget->state & C_BOOL; _free_space = check_options[0].widget->state & C_BOOL; - if (console_flag) + if (mc_global.tty.console_flag) { int minimum; if (_output_lines < 0) @@ -356,7 +346,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d if (old_output_lines != _output_lines) { old_output_lines = _output_lines; - tty_setcolor (console_flag ? COLOR_NORMAL : DISABLED_COLOR); + tty_setcolor (mc_global.tty.console_flag ? COLOR_NORMAL : DISABLED_COLOR); dlg_move (h, 9, 6 + 3 + output_lines_label_len); tty_printf ("%02d", _output_lines); } @@ -503,13 +493,13 @@ init_layout (void) _equal_split = equal_split; _menubar_visible = menubar_visible; _command_prompt = command_prompt; - _keybar_visible = keybar_visible; - _message_visible = message_visible; + _keybar_visible = mc_global.keybar_visible; + _message_visible = mc_global.message_visible; _xterm_title = xterm_title; _free_space = free_space; { - const int disabled = console_flag ? 0 : W_DISABLED; + const int disabled = mc_global.tty.console_flag ? 0 : W_DISABLED; Widget *w; w = (Widget *) groupbox_new (8, 4, 3, first_width, title2); @@ -720,10 +710,10 @@ void mc_refresh (void) { #ifdef WITH_BACKGROUND - if (we_are_background) + if (mc_global.we_are_background) return; #endif /* WITH_BACKGROUND */ - if (winch_flag == 0) + if (mc_global.tty.winch_flag == FALSE) tty_refresh (); else { @@ -741,14 +731,14 @@ setup_panels (void) int start_y; int promptl; /* the prompt len */ - if (console_flag) + if (mc_global.tty.console_flag) { int minimum; if (output_lines < 0) output_lines = 0; height = - LINES - keybar_visible - command_prompt - menubar_visible - - output_lines - message_visible; + LINES - mc_global.keybar_visible - command_prompt - menubar_visible - + output_lines - mc_global.message_visible; minimum = MINHEIGHT * (1 + horizontal_split); if (height < minimum) { @@ -758,7 +748,9 @@ setup_panels (void) } else { - height = LINES - menubar_visible - command_prompt - keybar_visible - message_visible; + height = + LINES - menubar_visible - command_prompt - mc_global.keybar_visible - + mc_global.message_visible; } check_split (); start_y = menubar_visible; @@ -789,9 +781,10 @@ setup_panels (void) if (command_prompt) { - widget_set_size (&cmdline->widget, LINES - 1 - keybar_visible, promptl, 1, COLS - promptl); + widget_set_size (&cmdline->widget, LINES - 1 - mc_global.keybar_visible, promptl, 1, + COLS - promptl); input_set_origin (cmdline, promptl, COLS - promptl); - widget_set_size (&the_prompt->widget, LINES - 1 - keybar_visible, 0, 1, promptl); + widget_set_size (&the_prompt->widget, LINES - 1 - mc_global.keybar_visible, 0, 1, promptl); } else { @@ -800,18 +793,18 @@ setup_panels (void) widget_set_size (&the_prompt->widget, LINES, COLS, 0, 0); } - widget_set_size (&the_bar->widget, LINES - 1, 0, keybar_visible, COLS); - buttonbar_set_visible (the_bar, keybar_visible); + widget_set_size (&the_bar->widget, LINES - 1, 0, mc_global.keybar_visible, COLS); + buttonbar_set_visible (the_bar, mc_global.keybar_visible); /* Output window */ - if (console_flag && output_lines) + if (mc_global.tty.console_flag && output_lines) { - output_start_y = LINES - command_prompt - keybar_visible - output_lines; + output_start_y = LINES - command_prompt - mc_global.keybar_visible - output_lines; show_console_contents (output_start_y, - LINES - output_lines - keybar_visible - 1, - LINES - keybar_visible - 1); + LINES - output_lines - mc_global.keybar_visible - 1, + LINES - mc_global.keybar_visible - 1); } - if (message_visible) + if (mc_global.message_visible) widget_set_size (&the_hint->widget, height + start_y, 0, 1, COLS); else widget_set_size (&the_hint->widget, 0, 0, 0, 0); @@ -828,7 +821,7 @@ sigwinch_handler (int dummy) #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */ low_level_change_screen_size (); #endif - winch_flag = 1; + mc_global.tty.winch_flag = TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -836,7 +829,7 @@ sigwinch_handler (int dummy) void change_screen_size (void) { - winch_flag = 0; + mc_global.tty.winch_flag = FALSE; #if defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 #if defined TIOCGWINSZ @@ -903,10 +896,10 @@ print_vfs_message (const char *msg, ...) g_vsnprintf (str, sizeof (str), msg, ap); va_end (ap); - if (midnight_shutdown) + if (mc_global.widget.midnight_shutdown) return; - if (!message_visible || !the_hint || !the_hint->widget.owner) + if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner) { int col, row; @@ -926,7 +919,7 @@ print_vfs_message (const char *msg, ...) return; } - if (message_visible) + if (mc_global.message_visible) set_hintbar (str); } @@ -985,7 +978,7 @@ void set_display_type (int num, panel_view_mode_t type) { int x = 0, y = 0, cols = 0, lines = 0; - unsigned int the_other = 0; /* Index to the other panel */ + unsigned int the_other = 0; /* Index to the other panel */ const char *file_name = NULL; /* For Quick view */ Widget *new_widget = NULL, *old_widget = NULL; WPanel *the_other_panel = NULL; @@ -1106,6 +1099,7 @@ set_display_type (int num, panel_view_mode_t type) g_free (old_widget); } + /* --------------------------------------------------------------------------------------------- */ void diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h index ad250e510..b0b6f343f 100644 --- a/src/filemanager/layout.h +++ b/src/filemanager/layout.h @@ -18,15 +18,12 @@ /*** global variables defined in .c file *********************************************************/ -extern int winch_flag; extern int equal_split; extern int first_panel_size; extern int output_lines; extern int command_prompt; extern int menubar_visible; -extern int keybar_visible; extern int output_start_y; -extern int message_visible; extern int xterm_title; extern int free_space; diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 8a615f268..5c4323f7f 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -49,7 +49,7 @@ #include "lib/skin.h" #include "lib/util.h" -#include "lib/vfs/vfs.h" /* vfs_translate_url() */ +#include "lib/vfs/vfs.h" /* vfs_translate_url() */ #include "src/args.h" #include "src/subshell.h" @@ -57,7 +57,6 @@ #include "src/learn.h" /* learn_keys() */ #include "src/execute.h" /* suspend_cmd() */ #include "src/keybind-defaults.h" -#include "src/main.h" /* quit */ #include "option.h" /* configure_box() */ #include "tree.h" @@ -81,7 +80,7 @@ #include "src/diffviewer/ydiff.h" #endif -#include "src/consaver/cons.saver.h" /* console_flag */ +#include "src/consaver/cons.saver.h" /* show_console_contents */ #include "midnight.h" @@ -122,8 +121,6 @@ Dlg_head *midnight_dlg = NULL; * Don't restrict the output on the screen manager level, * the translation tables take care of it. */ -#define full_eight_bits (1) -#define eight_bit_clean (1) #endif /* !HAVE_CHARSET */ /*** file scope type declarations ****************************************************************/ @@ -552,7 +549,7 @@ create_panels (void) cmdline = command_new (0, 0, 0); the_prompt = label_new (0, 0, mc_prompt); the_prompt->transparent = 1; - the_bar = buttonbar_new (keybar_visible); + the_bar = buttonbar_new (mc_global.keybar_visible); the_hint = label_new (0, 0, 0); the_hint->transparent = 1; @@ -781,14 +778,24 @@ static void setup_mc (void) { #ifdef HAVE_SLANG +#ifdef HAVE_CHARSET + tty_display_8bit (TRUE); +#else tty_display_8bit (full_eight_bits != 0); +#endif /* HAVE_CHARSET */ +#else + +#ifdef HAVE_CHARSET + tty_display_8bit (TRUE); #else tty_display_8bit (eight_bit_clean != 0); +#endif /* HAVE_CHARSET */ + #endif #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) - add_select_channel (subshell_pty, load_prompt, 0); + if (mc_global.tty.use_subshell) + add_select_channel (mc_global.tty.subshell_pty, load_prompt, 0); #endif /* !HAVE_SUBSHELL_SUPPORT */ tty_setup_sigwinch (sigwinch_handler); @@ -906,7 +913,7 @@ prepend_cwd_on_local (const char *filename) static void mc_maybe_editor_or_viewer (void) { - switch (mc_run_mode) + switch (mc_global.mc_run_mode) { #ifdef USE_INTERNAL_EDIT case MC_RUN_EDITOR: @@ -962,7 +969,7 @@ quit_cmd_internal (int quiet) if (q != 0) { #ifdef HAVE_SUBSHELL_SUPPORT - if (!use_subshell) + if (!mc_global.tty.use_subshell) stop_dialogs (); else if ((q = exit_subshell ())) #endif @@ -1305,10 +1312,10 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void case DLG_DRAW: load_hint (1); /* We handle the special case of the output lines */ - if (console_flag && output_lines) + if (mc_global.tty.console_flag && output_lines) show_console_contents (output_start_y, - LINES - output_lines - keybar_visible - - 1, LINES - keybar_visible - 1); + LINES - output_lines - mc_global.keybar_visible - + 1, LINES - mc_global.keybar_visible - 1); return MSG_HANDLED; case DLG_RESIZE: @@ -1378,7 +1385,7 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void return MSG_HANDLED; } - if ((!alternate_plus_minus || !(console_flag || xterm_flag)) + if ((!alternate_plus_minus || !(mc_global.tty.console_flag || xterm_flag)) && !quote && !current_panel->searching) { if (!only_leading_plus_minus) @@ -1530,7 +1537,7 @@ load_hint (gboolean force) if (the_hint->widget.owner == NULL) return; - if (!message_visible) + if (!mc_global.message_visible) { label_set_text (the_hint, NULL); return; @@ -1608,13 +1615,13 @@ do_nc (void) midnight_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, midnight_colors, midnight_callback, "[main]", NULL, DLG_WANT_IDLE); - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) setup_mc (); else setup_dummy_mc (); /* Check if we were invoked as an editor or file viewer */ - if (mc_run_mode != MC_RUN_FULL) + if (mc_global.mc_run_mode != MC_RUN_FULL) mc_maybe_editor_or_viewer (); else { @@ -1626,7 +1633,7 @@ do_nc (void) } /* Program end */ - midnight_shutdown = 1; + mc_global.widget.midnight_shutdown = TRUE; dialog_switch_shutdown (); done_mc (); destroy_dlg (midnight_dlg); diff --git a/src/filemanager/option.c b/src/filemanager/option.c index 1f5860f96..6bf72ca8c 100644 --- a/src/filemanager/option.c +++ b/src/filemanager/option.c @@ -119,11 +119,11 @@ configure_box (void) QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 11, dlg_height, N_("Sa&fe delete"), &safe_delete), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 10, dlg_height, N_("Cd follows lin&ks"), - &cd_symlinks), + &mc_global.vfs.cd_symlinks), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 9, dlg_height, N_("Rotating d&ash"), &nice_rotating_dash), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 8, dlg_height, N_("Co&mplete: show all"), - &show_all_if_ambiguous), + &mc_global.widget.show_all_if_ambiguous), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 7, dlg_height, N_("Shell &patterns"), &easy_patterns), QUICK_CHECKBOX (dlg_width / 2 + 2, dlg_width, 6, dlg_height, N_("&Drop down menus"), @@ -439,7 +439,7 @@ panel_options_box (void) if ((qd_result == B_ENTER) || (qd_result == B_EXIT)) { mc_config_set_bool (mc_main_config, CONFIG_PANELS_SECTION, - "simple_swap", (gboolean) (simple_swap & C_BOOL)); + "simple_swap", (gboolean) (simple_swap & C_BOOL)); if (!panels_options.fast_reload_msg_shown && panels_options.fast_reload) { diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index c02ee3d0a..08b9ea579 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -53,7 +53,7 @@ #include "src/execute.h" #include "src/selcodepage.h" /* select_charset (), SELECT_CHARSET_NO_TRANSLATE */ #include "src/keybind-defaults.h" /* global_keymap_t */ -#include "src/subshell.h" /* use_subshell */ +#include "src/subshell.h" /* do_subshell_chdir() */ #include "dir.h" #include "boxes.h" @@ -1181,7 +1181,7 @@ static char * panel_save_name (WPanel * panel) { /* If the program is shuting down */ - if ((midnight_shutdown && auto_save_setup) || saving_setup) + if ((mc_global.widget.midnight_shutdown && auto_save_setup) || saving_setup) return g_strdup (panel->panel_name); else return g_strconcat ("Temporal:", panel->panel_name, (char *) NULL); @@ -2264,7 +2264,7 @@ do_enter_on_file_entry (file_entry * fe) } #if HAVE_CHARSET - source_codepage = default_source_codepage; + mc_global.source_codepage = default_source_codepage; #endif return 1; @@ -2591,7 +2591,7 @@ static void subshell_chdir (const char *directory) { #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell && vfs_current_is_local ()) + if (mc_global.tty.use_subshell && vfs_current_is_local ()) do_subshell_chdir (directory, FALSE, TRUE); #endif /* HAVE_SUBSHELL_SUPPORT */ } @@ -3890,14 +3890,14 @@ panel_change_encoding (WPanel * panel) if (panel->codepage == SELECT_CHARSET_NO_TRANSLATE) { /* No translation */ - g_free (init_translation_table (display_codepage, display_codepage)); + g_free (init_translation_table (mc_global.display_codepage, mc_global.display_codepage)); cd_path = remove_encoding_from_path (panel->cwd); do_panel_cd (panel, cd_path, cd_parse_command); g_free (cd_path); return; } - errmsg = init_translation_table (panel->codepage, display_codepage); + errmsg = init_translation_table (panel->codepage, mc_global.display_codepage); if (errmsg != NULL) { message (D_ERROR, MSG_ERROR, "%s", errmsg); diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 4636a1ebb..8d6d441c4 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -43,7 +43,6 @@ #include "lib/widget.h" #include "src/setup.h" /* For profile_bname */ -#include "src/main.h" #include "src/history.h" #include "dir.h" @@ -481,7 +480,7 @@ load_panelize (void) while (*profile_keys) { - if (utf8_display || conv == INVALID_CONV) + if (mc_global.utf8_display || conv == INVALID_CONV) { buffer = g_string_new (*profile_keys); } diff --git a/src/filemanager/usermenu.c b/src/filemanager/usermenu.c index b46956d1b..0e930ff4e 100644 --- a/src/filemanager/usermenu.c +++ b/src/filemanager/usermenu.c @@ -722,7 +722,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote) if (c == '%') return g_strdup ("%"); - if (mc_run_mode == MC_RUN_FULL) + if (mc_global.mc_run_mode == MC_RUN_FULL) { if (g_ascii_islower ((gchar) c)) panel = current_panel; @@ -735,7 +735,7 @@ expand_format (struct WEdit *edit_widget, char c, gboolean do_quote) fname = panel->dir.list[panel->selected].fname; } #ifdef USE_INTERNAL_EDIT - else if (mc_run_mode == MC_RUN_EDITOR) + else if (mc_global.mc_run_mode == MC_RUN_EDITOR) fname = (char *) edit_get_file_name (edit_widget); #endif @@ -906,13 +906,13 @@ user_menu_cmd (struct WEdit *edit_widget, const char *menu_file, int selected_en { g_free (menu); menu = - concat_dir_and_file (mc_sysconfig_dir, + concat_dir_and_file (mc_global.sysconfig_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); if (!exist_file (menu)) { g_free (menu); menu = concat_dir_and_file - (mc_share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); + (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); } } } diff --git a/src/help.c b/src/help.c index e10b8697f..437bf9ef5 100644 --- a/src/help.c +++ b/src/help.c @@ -1047,7 +1047,7 @@ interactive_display (const char *filename, const char *node) if (filename != NULL) g_file_get_contents (filename, &filedata, NULL, NULL); else - filedata = load_mc_home_file (mc_share_data_dir, MC_HELP, &hlpfile); + filedata = load_mc_home_file (mc_global.share_data_dir, MC_HELP, &hlpfile); if (filedata == NULL) message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), diff --git a/src/history.h b/src/history.h index d032942cc..e80115d60 100644 --- a/src/history.h +++ b/src/history.h @@ -37,7 +37,6 @@ #define MC_HISTORY_VIEW_SEARCH_REGEX "mc.view.search.regex" #define MC_HISTORY_FTPFS_ACCOUNT "mc.vfs.ftp.account" -#define MC_HISTORY_VFS_PASSWORD "mc.vfs.password" #define MC_HISTORY_EXT_PARAMETER "mc.ext.parameter" diff --git a/src/main.c b/src/main.c index b54a0a2c6..aa74562f8 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,7 @@ #include "lib/fileloc.h" #include "lib/strutil.h" #include "lib/util.h" -#include "lib/vfs/vfs.h" /* vfs_init(), vfs_shut() */ +#include "lib/vfs/vfs.h" /* vfs_init(), vfs_shut() */ #include "filemanager/midnight.h" /* current_panel */ #include "filemanager/treestore.h" /* tree_store_save */ @@ -70,7 +70,7 @@ #include "selcodepage.h" #endif /* HAVE_CHARSET */ -#include "consaver/cons.saver.h" /* console_flag */ +#include "consaver/cons.saver.h" /* cons_saver_pid */ #include "main.h" @@ -83,54 +83,25 @@ int quit = 0; #ifdef HAVE_CHARSET /* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */ -int source_codepage = -1; int default_source_codepage = -1; -int display_codepage = -1; char *autodetect_codeset = NULL; gboolean is_autodetect_codeset_enabled = FALSE; -#else -/* If true, allow characters in the range 160-255 */ -int eight_bit_clean = 1; -/* - * If true, also allow characters in the range 128-159. - * This is reported to break on many terminals (xterm, qansi-m). - */ -int full_eight_bits = 0; #endif /* !HAVE_CHARSET */ -/* - * If utf-8 terminal utf8_display = 1 - * Display bits set UTF-8 - */ -int utf8_display = 0; - /* If true use the internal viewer */ int use_internal_view = 1; /* If set, use the builtin editor */ int use_internal_edit = 1; -mc_run_mode_t mc_run_mode = MC_RUN_FULL; char *mc_run_param0 = NULL; char *mc_run_param1 = NULL; -/* Used so that widgets know if they are being destroyed or - shut down */ -int midnight_shutdown = 0; - /* The user's shell */ char *shell = NULL; /* The prompt */ const char *mc_prompt = NULL; -/* mc_sysconfig_dir: Area for default settings from maintainers of distributuves - default is /etc/mc or may be defined by MC_DATADIR - */ -char *mc_sysconfig_dir = NULL; - -/* mc_share_data_dir: Area for default settings from developers */ -char *mc_share_data_dir = NULL; - /* Set to TRUE to suppress printing the last directory */ int print_last_revert = FALSE; @@ -162,20 +133,20 @@ check_codeset (void) { const char *_display_codepage; - _display_codepage = get_codepage_id (display_codepage); + _display_codepage = get_codepage_id (mc_global.display_codepage); if (strcmp (_display_codepage, current_system_codepage) != 0) { - display_codepage = get_codepage_index (current_system_codepage); - if (display_codepage == -1) - display_codepage = 0; + mc_global.display_codepage = get_codepage_index (current_system_codepage); + if (mc_global.display_codepage == -1) + mc_global.display_codepage = 0; mc_config_set_string (mc_main_config, "Misc", "display_codepage", cp_display); } } #endif - utf8_display = str_isutf8 (current_system_codepage); + mc_global.utf8_display = str_isutf8 (current_system_codepage); } /* --------------------------------------------------------------------------------------------- */ @@ -208,13 +179,13 @@ OS_Setup (void) mc_libdir = getenv ("MC_DATADIR"); if (mc_libdir != NULL) { - mc_sysconfig_dir = g_strdup (mc_libdir); - mc_share_data_dir = g_strdup (SYSCONFDIR); + mc_global.sysconfig_dir = g_strdup (mc_libdir); + mc_global.share_data_dir = g_strdup (SYSCONFDIR); } else { - mc_sysconfig_dir = g_strdup (SYSCONFDIR); - mc_share_data_dir = g_strdup (DATADIR); + mc_global.sysconfig_dir = g_strdup (SYSCONFDIR); + mc_global.share_data_dir = g_strdup (DATADIR); } } @@ -227,12 +198,12 @@ sigchld_handler_no_subshell (int sig) #ifdef __linux__ int pid, status; - if (!console_flag) + if (!mc_global.tty.console_flag) return; /* COMMENT: if it were true that after the call to handle_console(..INIT) - the value of console_flag never changed, we could simply not install - this handler at all if (!console_flag && !use_subshell). */ + the value of mc_global.tty.console_flag never changed, we could simply not install + this handler at all if (!mc_global.tty.console_flag && !mc_global.tty.use_subshell). */ /* That comment is no longer true. We need to wait() on a sigchld handler (that's at least what the tarfs code expects currently). */ @@ -251,7 +222,7 @@ sigchld_handler_no_subshell (int sig) { /* cons.saver has died - disable console saving */ handle_console (CONSOLE_DONE); - console_flag = 0; + mc_global.tty.console_flag = '\0'; } } /* If we got here, some other child exited; ignore it */ @@ -269,7 +240,7 @@ init_sigchld (void) sigchld_action.sa_handler = #ifdef HAVE_SUBSHELL_SUPPORT - use_subshell ? sigchld_handler : + mc_global.tty.use_subshell ? sigchld_handler : #endif /* HAVE_SUBSHELL_SUPPORT */ sigchld_handler_no_subshell; @@ -288,7 +259,7 @@ init_sigchld (void) * This may happen on QNX Neutrino 6, where SA_RESTART * is defined but not implemented. Fallback to no subshell. */ - use_subshell = 0; + mc_global.tty.use_subshell = FALSE; #endif /* HAVE_SUBSHELL_SUPPORT */ } } @@ -447,7 +418,7 @@ main (int argc, char *argv[]) str_init_strings (NULL); vfs_init (); - vfs_plugins_init(); + vfs_plugins_init (); vfs_setup_work_dir (); if (!mc_args_handle (argc, argv, "mc")) @@ -462,10 +433,10 @@ main (int argc, char *argv[]) #ifdef HAVE_SUBSHELL_SUPPORT /* Don't use subshell when invoked as viewer or editor */ - if (mc_run_mode != MC_RUN_FULL) - use_subshell = 0; + if (mc_global.mc_run_mode != MC_RUN_FULL) + mc_global.tty.use_subshell = FALSE; - if (use_subshell) + if (mc_global.tty.use_subshell) subshell_get_console_attributes (); #endif /* HAVE_SUBSHELL_SUPPORT */ @@ -488,11 +459,11 @@ main (int argc, char *argv[]) /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ - tty_init ((gboolean) mc_args__slow_terminal, (gboolean) mc_args__ugly_line_drawing); + tty_init (mc_global.args.slow_terminal, mc_global.args.ugly_line_drawing); load_setup (); - /* start check display_codepage and source_codepage */ + /* start check mc_global.display_codepage and mc_global.source_codepage */ check_codeset (); /* Removing this from the X code let's us type C-c */ @@ -502,7 +473,7 @@ main (int argc, char *argv[]) macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t)); - tty_init_colors (mc_args__disable_colors, mc_args__force_colors); + tty_init_colors (mc_global.args.disable_colors, mc_args__force_colors); { GError *error2 = NULL; @@ -529,20 +500,20 @@ main (int argc, char *argv[]) #ifdef HAVE_SUBSHELL_SUPPORT /* Done here to ensure that the subshell doesn't */ /* inherit the file descriptors opened below, etc */ - if (use_subshell) + if (mc_global.tty.use_subshell) init_subshell (); #endif /* HAVE_SUBSHELL_SUPPORT */ /* Also done after init_subshell, to save any shell init file messages */ - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_SAVE); if (alternate_plus_minus) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT - if (use_subshell) + if (mc_global.tty.use_subshell) { mc_prompt = strip_ctrl_codes (subshell_prompt); if (mc_prompt == NULL) @@ -553,7 +524,7 @@ main (int argc, char *argv[]) mc_prompt = (geteuid () == 0) ? "# " : "$ "; /* Program main loop */ - if (!midnight_shutdown) + if (!mc_global.widget.midnight_shutdown) do_nc (); /* Save the tree store */ @@ -574,17 +545,17 @@ main (int argc, char *argv[]) done_setup (); - if (console_flag && (quit & SUBSHELL_EXIT) == 0) + if (mc_global.tty.console_flag && (quit & SUBSHELL_EXIT) == 0) handle_console (CONSOLE_RESTORE); if (alternate_plus_minus) numeric_keypad_mode (); signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */ - if (console_flag) + if (mc_global.tty.console_flag) handle_console (CONSOLE_DONE); - if (mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL + if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL && last_wd_string != NULL && !print_last_revert) { int last_wd_fd; @@ -601,8 +572,8 @@ main (int argc, char *argv[]) } g_free (last_wd_string); - g_free (mc_share_data_dir); - g_free (mc_sysconfig_dir); + g_free (mc_global.share_data_dir); + g_free (mc_global.sysconfig_dir); g_free (shell); done_key (); diff --git a/src/main.h b/src/main.h index 42d833a70..d0c219700 100644 --- a/src/main.h +++ b/src/main.h @@ -14,13 +14,6 @@ /*** enums ***************************************************************************************/ /* run mode and params */ -typedef enum -{ - MC_RUN_FULL = 0, - MC_RUN_EDITOR, - MC_RUN_VIEWER, - MC_RUN_DIFFVIEWER -} mc_run_mode_t; enum cd_enum { @@ -49,7 +42,6 @@ struct mc_fhl_struct; /*** global variables defined in .c file *********************************************************/ -extern mc_run_mode_t mc_run_mode; /* * MC_RUN_FULL: dir for left panel * MC_RUN_EDITOR: file to edit @@ -77,26 +69,14 @@ extern int use_internal_view; extern int use_internal_edit; #ifdef HAVE_CHARSET -extern int source_codepage; extern int default_source_codepage; -extern int display_codepage; extern char *autodetect_codeset; extern gboolean is_autodetect_codeset_enabled; -#else -extern int eight_bit_clean; -extern int full_eight_bits; #endif /* !HAVE_CHARSET */ -extern int utf8_display; - -extern int midnight_shutdown; - extern char *shell; extern const char *mc_prompt; -extern char *mc_sysconfig_dir; -extern char *mc_share_data_dir; - /* index to record_macro_buf[], -1 if not recording a macro */ extern int macro_index; diff --git a/src/selcodepage.c b/src/selcodepage.c index ff5fd596e..1f6d1f557 100644 --- a/src/selcodepage.c +++ b/src/selcodepage.c @@ -136,9 +136,9 @@ do_set_codepage (int codepage) char *errmsg; gboolean ret; - source_codepage = codepage; + mc_global.source_codepage = codepage; errmsg = init_translation_table (codepage == SELECT_CHARSET_NO_TRANSLATE ? - display_codepage : source_codepage, display_codepage); + mc_global.display_codepage : mc_global.source_codepage, mc_global.display_codepage); ret = errmsg == NULL; if (!ret) diff --git a/src/setup.c b/src/setup.c index 544165886..23b3a2929 100644 --- a/src/setup.c +++ b/src/setup.c @@ -84,10 +84,6 @@ char *global_profile_name; /* mc.lib */ /* Only used at program boot */ gboolean boot_current_is_left = TRUE; -char *setup_color_string; -char *term_color_string; -char *color_terminal_string; - /* If on, default for "No" in delete operations */ int safe_delete = 0; @@ -104,8 +100,6 @@ int confirm_overwrite = 1; int confirm_execute = 0; /* Asks for confirmation before leaving the program */ int confirm_exit = 1; -/* Asks for confirmation before clean up of history */ -int confirm_history_cleanup = 1; /* If true, at startup the user-menu is invoked */ int auto_menu = 0; @@ -158,12 +152,6 @@ int auto_save_setup = 1; */ int only_leading_plus_minus = 1; -/* Set when cd symlink following is desirable (bash mode) */ -int cd_symlinks = 1; - -/* Set if you want the possible completions dialog for the first time */ -int show_all_if_ambiguous = 0; - /* Automatically fills name with current selected item name on mkdir */ int auto_fill_mkdir_name = 1; @@ -226,8 +214,8 @@ static const struct } layout [] = { { "equal_split", &equal_split }, { "first_panel_size", &first_panel_size }, - { "message_visible", &message_visible }, - { "keybar_visible", &keybar_visible }, + { "message_visible", &mc_global.message_visible }, + { "keybar_visible", &mc_global.keybar_visible }, { "xterm_title", &xterm_title }, { "output_lines", &output_lines }, { "command_prompt", &command_prompt }, @@ -252,15 +240,15 @@ static const struct { "confirm_delete", &confirm_delete }, { "confirm_overwrite", &confirm_overwrite }, { "confirm_execute", &confirm_execute }, - { "confirm_history_cleanup", &confirm_history_cleanup }, + { "confirm_history_cleanup", &mc_global.widget.confirm_history_cleanup }, { "confirm_exit", &confirm_exit }, { "confirm_directory_hotlist_delete", &confirm_directory_hotlist_delete }, { "safe_delete", &safe_delete }, { "mouse_repeat_rate", &mou_auto_repeat }, { "double_click_speed", &double_click_speed }, #ifndef HAVE_CHARSET - { "eight_bit_clean", &eight_bit_clean }, - { "full_eight_bits", &full_eight_bits }, + { "eight_bit_clean", &mc_global.eight_bit_clean }, + { "full_eight_bits", &mc_global.full_eight_bits }, #endif /* !HAVE_CHARSET */ { "use_8th_bit_as_meta", &use_8th_bit_as_meta }, { "confirm_view_dir", &confirm_view_dir }, @@ -271,8 +259,8 @@ static const struct { "wrap_mode", &mcview_global_wrap_mode}, { "old_esc_mode", &old_esc_mode }, { "old_esc_mode_timeout", &old_esc_mode_timeout }, - { "cd_symlinks", &cd_symlinks }, - { "show_all_if_ambiguous", &show_all_if_ambiguous }, + { "cd_symlinks", &mc_global.vfs.cd_symlinks }, + { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous }, { "max_dirt_limit", &mcview_max_dirt_limit }, { "use_file_to_guess_type", &use_file_to_check_type }, { "alternate_plus_minus", &alternate_plus_minus }, @@ -418,9 +406,9 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam g_free (ret); if (subdir != NULL) - ret = g_build_filename (mc_sysconfig_dir, subdir, lc_basename, NULL); + ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL); else - ret = g_build_filename (mc_sysconfig_dir, lc_basename, NULL); + ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL); if (exist_file (ret)) { @@ -430,9 +418,9 @@ load_setup_get_full_config_name (const char *subdir, const char *config_file_nam g_free (ret); if (subdir != NULL) - ret = g_build_filename (mc_share_data_dir, subdir, lc_basename, NULL); + ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL); else - ret = g_build_filename (mc_share_data_dir, lc_basename, NULL); + ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL); g_free (lc_basename); @@ -677,13 +665,13 @@ load_setup_get_keymap_profile_config (gboolean load_from_file) if (!load_from_file) return keymap_config; - /* 1) /usr/share/mc (mc_share_data_dir) */ - fname = g_build_filename (mc_share_data_dir, GLOBAL_KEYMAP_FILE, NULL); + /* 1) /usr/share/mc (mc_global.share_data_dir) */ + fname = g_build_filename (mc_global.share_data_dir, GLOBAL_KEYMAP_FILE, NULL); load_setup_init_config_from_file (&keymap_config, fname); g_free (fname); - /* 2) /etc/mc (mc_sysconfig_dir) */ - fname = g_build_filename (mc_sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); + /* 2) /etc/mc (mc_global.sysconfig_dir) */ + fname = g_build_filename (mc_global.sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL); load_setup_init_config_from_file (&keymap_config, fname); g_free (fname); @@ -769,7 +757,7 @@ save_panel_types (void) { panel_view_mode_t type; - if (mc_run_mode != MC_RUN_FULL) + if (mc_global.mc_run_mode != MC_RUN_FULL) return; type = get_display_type (0); @@ -812,7 +800,7 @@ setup_init (void) profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL); if (!exist_file (profile)) { - inifile = concat_dir_and_file (mc_sysconfig_dir, "mc.ini"); + inifile = concat_dir_and_file (mc_global.sysconfig_dir, "mc.ini"); if (exist_file (inifile)) { g_free (profile); @@ -821,7 +809,7 @@ setup_init (void) else { g_free (inifile); - inifile = concat_dir_and_file (mc_share_data_dir, "mc.ini"); + inifile = concat_dir_and_file (mc_global.share_data_dir, "mc.ini"); if (exist_file (inifile)) { g_free (profile); @@ -855,11 +843,13 @@ load_setup (void) /* mc.lib is common for all users, but has priority lower than ${XDG_CONFIG_HOME}/mc/ini. FIXME: it's only used for keys and treestore now */ - global_profile_name = g_build_filename (mc_sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); + global_profile_name = + g_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); if (!exist_file (global_profile_name)) { g_free (global_profile_name); - global_profile_name = g_build_filename (mc_share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); + global_profile_name = + g_build_filename (mc_global.share_data_dir, MC_GLOBAL_CONFIG_FILE, (char *) NULL); } panels_profile_name = g_build_filename (mc_config_get_cache_path (), MC_PANELS_FILE, NULL); @@ -931,9 +921,12 @@ load_setup (void) #endif /* ENABLE_VFS_FTP */ /* The default color and the terminal dependent color */ - setup_color_string = mc_config_get_string (mc_main_config, "Colors", "base_color", ""); - term_color_string = mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), ""); - color_terminal_string = mc_config_get_string (mc_main_config, "Colors", "color_terminals", ""); + mc_global.tty.setup_color_string = + mc_config_get_string (mc_main_config, "Colors", "base_color", ""); + mc_global.tty.term_color_string = + mc_config_get_string (mc_main_config, "Colors", getenv ("TERM"), ""); + mc_global.tty.color_terminal_string = + mc_config_get_string (mc_main_config, "Colors", "color_terminals", ""); /* Load the directory history */ /* directory_history_load (); */ @@ -945,16 +938,16 @@ load_setup (void) buffer = mc_config_get_string (mc_main_config, "Misc", "display_codepage", ""); if (buffer[0] != '\0') { - display_codepage = get_codepage_index (buffer); - cp_display = get_codepage_id (display_codepage); + mc_global.display_codepage = get_codepage_index (buffer); + cp_display = get_codepage_id (mc_global.display_codepage); } g_free (buffer); buffer = mc_config_get_string (mc_main_config, "Misc", "source_codepage", ""); if (buffer[0] != '\0') { default_source_codepage = get_codepage_index (buffer); - source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */ - cp_source = get_codepage_id (source_codepage); + mc_global.source_codepage = default_source_codepage; /* May be source_codepage doesn't need this */ + cp_source = get_codepage_id (mc_global.source_codepage); } g_free (buffer); } @@ -963,10 +956,10 @@ load_setup (void) if ((autodetect_codeset[0] != '\0') && (strcmp (autodetect_codeset, "off") != 0)) is_autodetect_codeset_enabled = TRUE; - g_free (init_translation_table (source_codepage, display_codepage)); - buffer = (char *) get_codepage_id (display_codepage); + g_free (init_translation_table (mc_global.source_codepage, mc_global.display_codepage)); + buffer = (char *) get_codepage_id (mc_global.display_codepage); if (buffer != NULL) - utf8_display = str_isutf8 (buffer); + mc_global.utf8_display = str_isutf8 (buffer); #endif /* HAVE_CHARSET */ clipboard_store_path = mc_config_get_string (mc_main_config, "Misc", "clipboard_store", ""); @@ -1005,7 +998,7 @@ save_setup (gboolean save_options, gboolean save_panel_options) #ifdef HAVE_CHARSET mc_config_set_string (mc_main_config, "Misc", "display_codepage", - get_codepage_id (display_codepage)); + get_codepage_id (mc_global.display_codepage)); mc_config_set_string (mc_main_config, "Misc", "source_codepage", get_codepage_id (default_source_codepage)); mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset); @@ -1035,9 +1028,9 @@ done_setup (void) g_free (clipboard_paste_path); g_free (profile_name); g_free (global_profile_name); - g_free (color_terminal_string); - g_free (term_color_string); - g_free (setup_color_string); + g_free (mc_global.tty.color_terminal_string); + g_free (mc_global.tty.term_color_string); + g_free (mc_global.tty.setup_color_string); g_free (panels_profile_name); mc_config_deinit (mc_main_config); mc_config_deinit (mc_panels_config); @@ -1327,7 +1320,8 @@ panel_save_setup (struct WPanel *panel, const char *section) size_t i; mc_config_set_int (mc_panels_config, section, "reverse", panel->sort_info.reverse); - mc_config_set_int (mc_panels_config, section, "case_sensitive", panel->sort_info.case_sensitive); + mc_config_set_int (mc_panels_config, section, "case_sensitive", + panel->sort_info.case_sensitive); mc_config_set_int (mc_panels_config, section, "exec_first", panel->sort_info.exec_first); mc_config_set_string (mc_panels_config, section, "sort_order", panel->sort_info.sort_field->id); diff --git a/src/setup.h b/src/setup.h index eace2f7d6..892e62829 100644 --- a/src/setup.h +++ b/src/setup.h @@ -49,7 +49,7 @@ typedef struct gboolean filetype_mode; /* If TRUE then add per file type hilighting */ gboolean permission_mode; /* If TRUE, we use permission hilighting */ qsearch_mode_t qsearch_mode; /* Quick search mode */ - gboolean torben_fj_mode; /* If TRUE, use some usability hacks by Torben */ + gboolean torben_fj_mode; /* If TRUE, use some usability hacks by Torben */ } panels_options_t; /*** global variables defined in .c file *********************************************************/ @@ -57,15 +57,11 @@ typedef struct /* global paremeters */ extern char *profile_name; extern char *global_profile_name; -extern char *setup_color_string; -extern char *term_color_string; -extern char *color_terminal_string; extern int confirm_delete; extern int confirm_directory_hotlist_delete; extern int confirm_execute; extern int confirm_exit; extern int confirm_overwrite; -extern int confirm_history_cleanup; extern int confirm_view_dir; extern int safe_delete; extern int clear_before_exec; @@ -81,7 +77,6 @@ extern int option_tab_spacing; extern int auto_save_setup; extern int only_leading_plus_minus; extern int cd_symlinks; -extern int show_all_if_ambiguous; extern int auto_fill_mkdir_name; extern int output_starts_shell; extern int use_file_to_check_type; diff --git a/src/subshell.c b/src/subshell.c index f753a138a..23b1fe072 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -59,23 +59,11 @@ #include "filemanager/midnight.h" /* current_panel */ -#include "main.h" /* home_dir */ #include "consaver/cons.saver.h" /* handle_console() */ #include "subshell.h" /*** global variables ****************************************************************************/ -/* If using a subshell for evaluating commands this is true */ -int use_subshell = -#ifdef SUBSHELL_OPTIONAL - FALSE; -#else - TRUE; -#endif - -/* File descriptors of the pseudoterminal used by the subshell */ -int subshell_pty = 0; - /* State of the subshell: * INACTIVE: the default state; awaiting a command * ACTIVE: remain in the shell until the user hits `subshell_switch_key' @@ -338,7 +326,7 @@ init_subshell_child (const char *pty_name) /* means that when MC exits, the subshell will get a SIGHUP and */ /* exit too, because there will be no more descriptors pointing */ /* at the master side of the pty and so it will disappear. */ - close (subshell_pty); + close (mc_global.tty.subshell_pty); /* Execute the subshell at last */ @@ -469,9 +457,9 @@ feed_subshell (int how, int fail_on_error) /* Prepare the file-descriptor set and call `select' */ FD_ZERO (&read_set); - FD_SET (subshell_pty, &read_set); + FD_SET (mc_global.tty.subshell_pty, &read_set); FD_SET (subshell_pipe[READ], &read_set); - maxfdp = max (subshell_pty, subshell_pipe[READ]); + maxfdp = max (mc_global.tty.subshell_pty, subshell_pipe[READ]); if (how == VISIBLY) { FD_SET (STDIN_FILENO, &read_set); @@ -490,7 +478,7 @@ feed_subshell (int how, int fail_on_error) exit (EXIT_FAILURE); } - if (FD_ISSET (subshell_pty, &read_set)) + if (FD_ISSET (mc_global.tty.subshell_pty, &read_set)) /* Read from the subshell, write to stdout */ /* This loop improves performance by reducing context switches @@ -498,7 +486,7 @@ feed_subshell (int how, int fail_on_error) randomly, because of an apparent Linux bug. Investigate. */ /* for (i=0; i<5; ++i) * FIXME -- experimental */ { - bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); + bytes = read (mc_global.tty.subshell_pty, pty_buffer, sizeof (pty_buffer)); /* The subshell has died */ if (bytes == -1 && errno == EIO && !subshell_alive) @@ -554,13 +542,13 @@ feed_subshell (int how, int fail_on_error) for (i = 0; i < bytes; ++i) if (pty_buffer[i] == subshell_switch_key) { - write_all (subshell_pty, pty_buffer, i); + write_all (mc_global.tty.subshell_pty, pty_buffer, i); if (subshell_ready) subshell_state = INACTIVE; return TRUE; } - write_all (subshell_pty, pty_buffer, bytes); + write_all (mc_global.tty.subshell_pty, pty_buffer, bytes); if (pty_buffer[bytes - 1] == '\n' || pty_buffer[bytes - 1] == '\r') subshell_ready = FALSE; @@ -770,7 +758,7 @@ pty_open_slave (const char *pty_name) * * Possibly modifies the global variables: * subshell_type, subshell_alive, subshell_stopped, subshell_pid - * use_subshell - Is set to FALSE if we can't run the subshell + * mc_global.tty.use_subshell - Is set to FALSE if we can't run the subshell * quit - Can be set to SUBSHELL_EXIT by the SIGCHLD handler */ @@ -784,11 +772,11 @@ init_subshell (void) switch (check_sid ()) { case 1: - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; case 2: - use_subshell = FALSE; - midnight_shutdown = 1; + mc_global.tty.use_subshell = FALSE; + mc_global.widget.midnight_shutdown = TRUE; return; } @@ -796,7 +784,7 @@ init_subshell (void) /* a raw mode based on it now, before we do anything else with it */ init_raw_mode (); - if (subshell_pty == 0) + if (mc_global.tty.subshell_pty == 0) { /* First time through */ /* Find out what type of shell we have */ @@ -812,7 +800,7 @@ init_subshell (void) subshell_type = FISH; else { - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } @@ -820,11 +808,11 @@ init_subshell (void) /* FIXME: We may need to open a fresh pty each time on SVR4 */ - subshell_pty = pty_open_master (pty_name); - if (subshell_pty == -1) + mc_global.tty.subshell_pty = pty_open_master (pty_name); + if (mc_global.tty.subshell_pty == -1) { fprintf (stderr, "Cannot open master side of pty: %s\r\n", unix_error_string (errno)); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } subshell_pty_slave = pty_open_slave (pty_name); @@ -832,7 +820,7 @@ init_subshell (void) { fprintf (stderr, "Cannot open slave side of pty %s: %s\r\n", pty_name, unix_error_string (errno)); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } @@ -845,7 +833,7 @@ init_subshell (void) if (mkfifo (tcsh_fifo, 0600) == -1) { fprintf (stderr, "mkfifo(%s) failed: %s\r\n", tcsh_fifo, unix_error_string (errno)); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } @@ -856,14 +844,14 @@ init_subshell (void) { fprintf (stderr, _("Cannot open named pipe %s\n"), tcsh_fifo); perror (__FILE__ ": open"); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } } else /* subshell_type is BASH or ZSH */ if (pipe (subshell_pipe)) { perror (__FILE__ ": couldn't create pipe"); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } } @@ -914,7 +902,7 @@ init_subshell (void) break; } - write_all (subshell_pty, precmd, strlen (precmd)); + write_all (mc_global.tty.subshell_pty, precmd, strlen (precmd)); /* Wait until the subshell has started up and processed the command */ @@ -922,11 +910,11 @@ init_subshell (void) tty_enable_interrupt_key (); if (!feed_subshell (QUIETLY, TRUE)) { - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; } tty_disable_interrupt_key (); if (!subshell_alive) - use_subshell = FALSE; /* Subshell died instantly, so don't use it */ + mc_global.tty.use_subshell = FALSE; /* Subshell died instantly, so don't use it */ } /* --------------------------------------------------------------------------------------------- */ @@ -951,16 +939,16 @@ invoke_subshell (const char *command, int how, char **new_dir) /* FIXME: possibly take out this hack; the user can re-play it by hitting C-hyphen a few times! */ if (subshell_ready) - write_all (subshell_pty, " \b", 2); /* Hack to make prompt reappear */ + write_all (mc_global.tty.subshell_pty, " \b", 2); /* Hack to make prompt reappear */ } } else /* MC has passed us a user command */ { if (how == QUIETLY) - write_all (subshell_pty, " ", 1); + write_all (mc_global.tty.subshell_pty, " ", 1); /* FIXME: if command is long (>8KB ?) we go comma */ - write_all (subshell_pty, command, strlen (command)); - write_all (subshell_pty, "\n", 1); + write_all (mc_global.tty.subshell_pty, command, strlen (command)); + write_all (mc_global.tty.subshell_pty, "\n", 1); subshell_state = RUNNING_COMMAND; subshell_ready = FALSE; } @@ -973,7 +961,7 @@ invoke_subshell (const char *command, int how, char **new_dir) g_free (pcwd); /* Restart the subshell if it has died by SIGHUP, SIGQUIT, etc. */ - while (!subshell_alive && quit == 0 && use_subshell) + while (!subshell_alive && quit == 0 && mc_global.tty.use_subshell) init_subshell (); prompt_pos = 0; @@ -993,7 +981,7 @@ read_subshell_prompt (void) fd_set tmp; FD_ZERO (&tmp); - FD_SET (subshell_pty, &tmp); + FD_SET (mc_global.tty.subshell_pty, &tmp); if (subshell_prompt == NULL) { /* First time through */ @@ -1002,7 +990,8 @@ read_subshell_prompt (void) prompt_pos = 0; } - while (subshell_alive && (rc = select (subshell_pty + 1, &tmp, NULL, NULL, &timeleft))) + while (subshell_alive + && (rc = select (mc_global.tty.subshell_pty + 1, &tmp, NULL, NULL, &timeleft))) { /* Check for `select' errors */ if (rc == -1) @@ -1016,7 +1005,7 @@ read_subshell_prompt (void) } } - bytes = read (subshell_pty, pty_buffer, sizeof (pty_buffer)); + bytes = read (mc_global.tty.subshell_pty, pty_buffer, sizeof (pty_buffer)); /* Extract the prompt from the shell output */ @@ -1075,15 +1064,15 @@ resize_tty (int fd) } /* --------------------------------------------------------------------------------------------- */ -/** Resize subshell_pty */ +/** Resize mc_global.tty.subshell_pty */ void resize_subshell (void) { - if (use_subshell == 0) + if (!mc_global.tty.use_subshell) return; - resize_tty (subshell_pty); + resize_tty (mc_global.tty.subshell_pty); } /* --------------------------------------------------------------------------------------------- */ @@ -1228,7 +1217,7 @@ do_subshell_chdir (const char *directory, gboolean update_prompt, gboolean reset /* The initial space keeps this out of the command history (in bash because we set "HISTCONTROL=ignorespace") */ - write_all (subshell_pty, " cd ", 4); + write_all (mc_global.tty.subshell_pty, " cd ", 4); if (*directory) { translate = vfs_translate_path_n (directory); @@ -1237,27 +1226,27 @@ do_subshell_chdir (const char *directory, gboolean update_prompt, gboolean reset temp = subshell_name_quote (translate); if (temp) { - write_all (subshell_pty, temp, strlen (temp)); + write_all (mc_global.tty.subshell_pty, temp, strlen (temp)); g_free (temp); } else { /* Should not happen unless the directory name is so long that we don't have memory to quote it. */ - write_all (subshell_pty, ".", 1); + write_all (mc_global.tty.subshell_pty, ".", 1); } g_free (translate); } else { - write_all (subshell_pty, ".", 1); + write_all (mc_global.tty.subshell_pty, ".", 1); } } else { - write_all (subshell_pty, "/", 1); + write_all (mc_global.tty.subshell_pty, "/", 1); } - write_all (subshell_pty, "\n", 1); + write_all (mc_global.tty.subshell_pty, "\n", 1); subshell_state = RUNNING_COMMAND; feed_subshell (QUIETLY, FALSE); @@ -1308,7 +1297,7 @@ subshell_get_console_attributes (void) if (tcgetattr (STDOUT_FILENO, &shell_mode)) { fprintf (stderr, "Cannot get terminal settings: %s\r\n", unix_error_string (errno)); - use_subshell = FALSE; + mc_global.tty.use_subshell = FALSE; return; } } @@ -1349,7 +1338,7 @@ sigchld_handler (int sig) { /* The subshell has either exited normally or been killed */ subshell_alive = FALSE; - delete_select_channel (subshell_pty); + delete_select_channel (mc_global.tty.subshell_pty); if (WIFEXITED (status) && WEXITSTATUS (status) != FORK_FAILURE) quit |= SUBSHELL_EXIT; /* Exited normally */ } @@ -1367,7 +1356,7 @@ sigchld_handler (int sig) { /* cons.saver has died - disable confole saving */ handle_console (CONSOLE_DONE); - console_flag = 0; + mc_global.tty.console_flag = '\0'; } } diff --git a/src/subshell.h b/src/subshell.h index abfe174f9..f2e2504e9 100644 --- a/src/subshell.h +++ b/src/subshell.h @@ -35,12 +35,6 @@ enum /*** global variables defined in .c file *********************************************************/ -/* If using a subshell for evaluating commands this is true */ -extern int use_subshell; - -/* File descriptor of the pseudoterminal used by the subshell */ -extern int subshell_pty; - extern enum subshell_state_enum subshell_state; /* Holds the latest prompt captured from the subshell */ @@ -60,8 +54,6 @@ void do_subshell_chdir (const char *directory, gboolean update_prompt, gboolean void subshell_get_console_attributes (void); void sigchld_handler (int sig); -#else /* not HAVE_SUBSHELL_SUPPORT */ -#define use_subshell 0 #endif /* HAVE_SUBSHELL_SUPPORT */ /*** inline functions ****************************************************************************/ diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 546005f02..fb8da1672 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -663,7 +663,7 @@ ftpfs_load_no_proxy_list (void) if (mc_file) return; - mc_file = concat_dir_and_file (mc_sysconfig_dir, "mc.no_proxy"); + mc_file = concat_dir_and_file (mc_global.sysconfig_dir, "mc.no_proxy"); if (exist_file (mc_file)) { npf = fopen (mc_file, "r"); diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index a241a84e0..c32a22812 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -45,7 +45,6 @@ #include "lib/util.h" #include "lib/widget.h" /* D_ERROR, D_NORMAL */ -#include "src/main.h" /* mc_sysconfig_dir */ #include "src/execute.h" /* EXECUTE_AS_SHELL */ #include "lib/vfs/vfs.h" @@ -417,7 +416,7 @@ sfs_init (struct vfs_class *me) (void) me; - mc_sfsini = g_build_filename (mc_sysconfig_dir, "sfs.ini", (char *) NULL); + mc_sfsini = g_build_filename (mc_global.sysconfig_dir, "sfs.ini", (char *) NULL); cfg = fopen (mc_sfsini, "r"); if (cfg == NULL) diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 4f8925006..3de327a35 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -66,7 +66,6 @@ #include "src/execute.h" #include "src/help.h" #include "src/keybind-defaults.h" -#include "src/main.h" /* midnight_shutdown */ #include "internal.h" #include "mcviewer.h" @@ -494,7 +493,7 @@ mcview_callback (Widget * w, widget_msg_t msg, int parm) { delete_hook (&select_file_hook, mcview_hook); - if (midnight_shutdown) + if (mc_global.widget.midnight_shutdown) mcview_ok_to_quit (view); } mcview_done (view); @@ -525,7 +524,7 @@ mcview_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, case DLG_VALIDATE: view = (mcview_t *) find_widget_type (h, mcview_callback); - h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ + h->state = DLG_ACTIVE; /* don't stop the dialog before final decision */ if (mcview_ok_to_quit (view)) h->state = DLG_CLOSED; else diff --git a/src/viewer/display.c b/src/viewer/display.c index 7e68b9aea..bf020492d 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -158,7 +158,7 @@ mcview_display_status (mcview_t * view) tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end, buffer, mcview_may_still_grow (view) ? "+" : " ", #ifdef HAVE_CHARSET - source_codepage >= 0 ? get_codepage_id (source_codepage) : "" + mc_global.source_codepage >= 0 ? get_codepage_id (mc_global.source_codepage) : "" #else "" #endif diff --git a/src/viewer/hex.c b/src/viewer/hex.c index 74148e5ee..b5645b488 100644 --- a/src/viewer/hex.c +++ b/src/viewer/hex.c @@ -49,8 +49,6 @@ #include "lib/widget.h" #include "lib/charsets.h" -#include "src/main.h" - #include "internal.h" /*** global variables ****************************************************************************/ @@ -285,7 +283,7 @@ mcview_display_hex (mcview_t * view) #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!view->utf8) { diff --git a/src/viewer/lib.c b/src/viewer/lib.c index 435caa2dd..00be8d021 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -149,7 +149,7 @@ mcview_ok_to_quit (mcview_t * view) if (view->change_list == NULL) return TRUE; - if (!midnight_shutdown) + if (!mc_global.widget.midnight_shutdown) { query_set_sel (2); r = query_dialog (_("Quit"), @@ -169,7 +169,7 @@ mcview_ok_to_quit (mcview_t * view) switch (r) { case 0: /* Yes */ - return mcview_hexedit_save_changes (view) || midnight_shutdown; + return mcview_hexedit_save_changes (view) || mc_global.widget.midnight_shutdown; case 1: /* No */ mcview_hexedit_free_change_list (view); return TRUE; @@ -290,7 +290,7 @@ mcview_set_codeset (mcview_t * view) const char *cp_id = NULL; view->utf8 = TRUE; - cp_id = get_codepage_id (source_codepage >= 0 ? source_codepage : display_codepage); + cp_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage); if (cp_id != NULL) { GIConv conv; diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 60168d159..16167f718 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -42,7 +42,6 @@ #include "lib/skin.h" #include "lib/charsets.h" -#include "src/main.h" /* utf8_display */ #include "src/setup.h" /* option_tab_spacing */ #include "internal.h" @@ -181,7 +180,7 @@ mcview_display_nroff (mcview_t * view) { widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column)); #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!view->utf8) { diff --git a/src/viewer/plain.c b/src/viewer/plain.c index b25b38e2b..346c4e9b4 100644 --- a/src/viewer/plain.c +++ b/src/viewer/plain.c @@ -44,7 +44,6 @@ #include "lib/util.h" /* is_printable() */ #include "lib/charsets.h" -#include "src/main.h" /* utf8_display */ #include "src/setup.h" /* option_tab_spacing */ #include "internal.h" @@ -159,7 +158,7 @@ mcview_display_text (mcview_t * view) { widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column)); #ifdef HAVE_CHARSET - if (utf8_display) + if (mc_global.utf8_display) { if (!view->utf8) c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); From 4005b7924e255d60f5fe43ad6c16a083a7b7145f Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Tue, 15 Feb 2011 16:41:22 +0200 Subject: [PATCH 06/25] Use events to check timestamp of panel directories ...instead of direct access to panels in VGS GC. Inlcudes clean up. Signed-off-by: Andrew Borodin Signed-off-by: Slava Zanko --- lib/event-types.h | 12 ++++++ lib/vfs/gc.c | 59 +++++++-------------------- src/filemanager/midnight.c | 81 +++++++++++++++++++++++++++++++++----- 3 files changed, 99 insertions(+), 53 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index 2eb40113d..1686c11d8 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -1,6 +1,8 @@ #ifndef MC__EVENT_TYPES_H #define MC__EVENT_TYPES_H +#include + /*** typedefs(not structures) and defined constants **********************************************/ /* Event groups for main modules */ @@ -14,6 +16,16 @@ /*** structures declarations (and typedefs of structures)*****************************************/ + +/* MCEVENT_GROUP_CORE:vfs_timestamp */ +struct vfs_class; +typedef struct +{ + struct vfs_class *vclass; + gpointer id; + gboolean ret; +} ev_vfs_stamp_create_t; + /*** global variables defined in .c file *********************************************************/ /*** declarations of public functions ************************************************************/ diff --git a/lib/vfs/gc.c b/lib/vfs/gc.c index c412de820..abb2e4a95 100644 --- a/lib/vfs/gc.c +++ b/lib/vfs/gc.c @@ -33,18 +33,12 @@ #include -#include #include /* For atol() */ -#include -#include -#include #include -#include /* is_digit() */ #include /* gettimeofday() */ #include "lib/global.h" - -#include "src/filemanager/midnight.h" /* current_panel */ +#include "lib/event.h" #include "vfs.h" #include "utilvfs.h" @@ -173,58 +167,35 @@ vfs_stamp_path (const char *path) */ void -vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid) +vfs_stamp_create (struct vfs_class *vclass, vfsid id) { - struct vfs_class *nvfs, *n2vfs, *n3vfs; - vfsid nvfsid, n2vfsid, n3vfsid; + struct vfs_class *nvfs; + vfsid nvfsid; + + ev_vfs_stamp_create_t event_data = { vclass, id, FALSE }; /* There are three directories we have to take care of: current_dir, current_panel->cwd and other_panel->cwd. Athough most of the time either current_dir and current_panel->cwd or current_dir and other_panel->cwd are the same, it's possible that all three are different -- Norbert */ - if (current_panel == NULL) + if (!mc_event_present (MCEVENT_GROUP_CORE, "vfs_timestamp")) return; nvfs = vfs_get_class (vfs_get_current_dir ()); nvfsid = vfs_getid (nvfs, vfs_get_current_dir ()); vfs_rmstamp (nvfs, nvfsid); - if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL) - { - return; - } - - if (get_current_type () == view_listing) - { - n2vfs = vfs_get_class (current_panel->cwd); - n2vfsid = vfs_getid (n2vfs, current_panel->cwd); - if (n2vfs == oldvfs && n2vfsid == oldvfsid) - return; - } - else - { - n2vfs = NULL; - n2vfsid = NULL; - } - - if (get_other_type () == view_listing) - { - n3vfs = vfs_get_class (other_panel->cwd); - n3vfsid = vfs_getid (n3vfs, other_panel->cwd); - if (n3vfs == oldvfs && n3vfsid == oldvfsid) - return; - } - else - { - n3vfs = NULL; - n3vfsid = NULL; - } - - if (!oldvfs || !oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid)) + if (id == NULL || (nvfs == vclass && nvfsid == id)) return; - vfs_addstamp (oldvfs, oldvfsid); + mc_event_raise (MCEVENT_GROUP_CORE, "vfs_timestamp", (gpointer) &event_data); + + if (event_data.ret) + return; + + if (vclass != NULL && vclass->nothingisopen != NULL && vclass->nothingisopen (id) != 0) + vfs_addstamp (vclass, id); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 5c4323f7f..3ae6a9365 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -57,6 +57,8 @@ #include "src/learn.h" /* learn_keys() */ #include "src/execute.h" /* suspend_cmd() */ #include "src/keybind-defaults.h" +#include "lib/keybind.h" +#include "lib/event.h" #include "option.h" /* configure_box() */ #include "tree.h" @@ -66,7 +68,6 @@ #include "hotlist.h" #include "panelize.h" #include "command.h" /* cmdline */ -#include "lib/keybind.h" #include "chmod.h" #include "chown.h" @@ -487,6 +488,66 @@ translated_mc_chdir (char *dir) /* --------------------------------------------------------------------------------------------- */ +#if ENABLE_VFS + +/* event helper */ +static gboolean +check_panel_timestamp (WPanel * panel, panel_view_mode_t mode, struct vfs_class *vclass, vfsid id) +{ + if (mode == view_listing) + { + struct vfs_class *nvfs; + vfsid nvfsid; + nvfs = vfs_get_class (panel->cwd); + if (nvfs != vclass) + return FALSE; + nvfsid = vfs_getid (nvfs, panel->cwd); + if (nvfsid == id) + return TRUE; + } + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +static gboolean +check_current_panel_timestamp (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret = + check_panel_timestamp (current_panel, get_current_type (), event_data->vclass, + event_data->id); + return !event_data->ret; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +static gboolean +check_other_panel_timestamp (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_vfs_stamp_create_t *event_data = (ev_vfs_stamp_create_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret = + check_panel_timestamp (other_panel, get_other_type (), event_data->vclass, event_data->id); + return !event_data->ret; +} +#endif /* ENABLE_VFS */ + +/* --------------------------------------------------------------------------------------------- */ + static void create_panels (void) { @@ -534,16 +595,18 @@ create_panels (void) set_display_type (other_index, other_mode); if (startup_left_mode == view_listing) - { current_panel = left_panel; - } + else if (right_panel != NULL) + current_panel = right_panel; else - { - if (right_panel) - current_panel = right_panel; - else - current_panel = left_panel; - } + current_panel = left_panel; + +#if ENABLE_VFS + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, + NULL); + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, + NULL); +#endif /* ENABLE_VFS */ /* Create the nice widgets */ cmdline = command_new (0, 0, 0); From 746653fda24bb4e9330873d0c8de180b8834a96f Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 10 Feb 2011 15:32:38 +0200 Subject: [PATCH 07/25] Removed mc_main_error_quark() function Signed-off-by: Slava Zanko --- lib/event/event.c | 6 +++--- lib/event/manage.c | 6 +++--- lib/global.h | 3 +-- lib/mcconfig/common.c | 10 +++------- src/main.c | 9 --------- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/event/event.c b/lib/event/event.c index f91967e72..305ed0117 100644 --- a/lib/event/event.c +++ b/lib/event/event.c @@ -53,7 +53,7 @@ mc_event_init (GError ** mcerror) if (mc_event_grouplist != NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 1, + g_error_new (MC_ERROR, 1, _("Event system already initialized"))); return FALSE; } @@ -65,7 +65,7 @@ mc_event_init (GError ** mcerror) if (mc_event_grouplist == NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 2, + g_error_new (MC_ERROR, 2, _("Failed to initialize event system"))); return FALSE; } @@ -81,7 +81,7 @@ mc_event_deinit (GError ** mcerror) if (mc_event_grouplist == NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 1, + g_error_new (MC_ERROR, 1, _("Event system not initialized"))); return FALSE; } diff --git a/lib/event/manage.c b/lib/event/manage.c index f5e9c3f8e..9e9ba628f 100644 --- a/lib/event/manage.c +++ b/lib/event/manage.c @@ -73,7 +73,7 @@ mc_event_add (const gchar * event_group_name, const gchar * event_name, || event_callback == NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 1, + g_error_new (MC_ERROR, 1, _("Check input data! Some of parameters are NULL!"))); return FALSE; } @@ -171,7 +171,7 @@ mc_event_get_event_group_by_name (const gchar * event_group_name, gboolean creat if (event_group == NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 1, + g_error_new (MC_ERROR, 1, _("Unable to create group '%s' for events!"), event_group_name)); return NULL; @@ -196,7 +196,7 @@ mc_event_get_event_by_name (GTree * event_group, const gchar * event_name, gbool if (callbacks == NULL) { g_propagate_error (mcerror, - g_error_new (mc_main_error_quark (), 1, + g_error_new (MC_ERROR, 1, _("Unable to create event '%s'!"), event_name)); return NULL; } diff --git a/lib/global.h b/lib/global.h index aafe28715..f86f0eadf 100644 --- a/lib/global.h +++ b/lib/global.h @@ -141,7 +141,7 @@ #include #endif -#define MC_ERROR mc_main_error_quark () +#define MC_ERROR g_quark_from_static_string (PACKAGE) /*** enums ***************************************************************************************/ @@ -268,7 +268,6 @@ extern mc_global_t mc_global; /*** declarations of public functions ************************************************************/ void refresh_screen (void *); -GQuark mc_main_error_quark (void); /*** inline functions ****************************************************************************/ #endif diff --git a/lib/mcconfig/common.c b/lib/mcconfig/common.c index 893a2ab02..64f4d978c 100644 --- a/lib/mcconfig/common.c +++ b/lib/mcconfig/common.c @@ -26,7 +26,7 @@ #include /* extern int errno */ #include "lib/global.h" -#include "lib/vfs/vfs.h" /* mc_stat */ +#include "lib/vfs/vfs.h" /* mc_stat */ #include "lib/util.h" #include "lib/mcconfig.h" @@ -65,9 +65,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, fd = mc_open (ini_path, O_WRONLY | O_TRUNC | O_SYNC, 0); if (fd == -1) { - g_propagate_error (error, - g_error_new (mc_main_error_quark (), 0, "%s", - unix_error_string (errno))); + g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); g_free (data); return FALSE; } @@ -81,9 +79,7 @@ mc_config_new_or_override_file (mc_config_t * mc_config, const gchar * ini_path, if (cur_written == -1) { mc_util_restore_from_backup_if_possible (ini_path, "~"); - g_propagate_error (error, - g_error_new (mc_main_error_quark (), 0, "%s", - unix_error_string (errno))); + g_propagate_error (error, g_error_new (MC_ERROR, 0, "%s", unix_error_string (errno))); return FALSE; } diff --git a/src/main.c b/src/main.c index aa74562f8..a69607e28 100644 --- a/src/main.c +++ b/src/main.c @@ -268,15 +268,6 @@ init_sigchld (void) /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -/** Define this function for glib-style error handling */ -GQuark -mc_main_error_quark (void) -{ - return g_quark_from_static_string (PACKAGE); -} - -/* --------------------------------------------------------------------------------------------- */ - int do_cd (const char *new_dir, enum cd_enum exact) { From 5a458c702d2fbd7f5d71cc871e0da907d37443a8 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 13:26:59 +0200 Subject: [PATCH 08/25] Use events to show VFS messages. Signed-off-by: Slava Zanko --- lib/event-types.h | 9 ++++++ lib/vfs/direntry.c | 11 ++++---- lib/vfs/vfs.c | 15 ++++++++++ lib/vfs/vfs.h | 2 ++ src/filemanager/layout.c | 42 ++-------------------------- src/filemanager/layout.h | 2 -- src/filemanager/midnight.c | 48 ++++++++++++++++++++++++++++++++ src/vfs/fish/fish.c | 31 ++++++++++----------- src/vfs/ftpfs/ftpfs.c | 57 +++++++++++++++++++------------------- src/vfs/undelfs/undelfs.c | 11 ++++---- 10 files changed, 129 insertions(+), 99 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index 1686c11d8..f4e293d31 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -26,6 +26,15 @@ typedef struct gboolean ret; } ev_vfs_stamp_create_t; + +/* MCEVENT_GROUP_CORE:vfs_print_message */ +typedef struct +{ + const char *msg; + va_list ap; +} ev_vfs_print_message_t; + + /*** global variables defined in .c file *********************************************************/ /*** declarations of public functions ************************************************************/ diff --git a/lib/vfs/direntry.c b/lib/vfs/direntry.c index 4cdabd2e0..aba791d74 100644 --- a/lib/vfs/direntry.c +++ b/lib/vfs/direntry.c @@ -36,6 +36,7 @@ #include #include /* gettimeofday() */ #include /* uintmax_t */ +#include #include "lib/global.h" @@ -45,8 +46,6 @@ #include "lib/widget.h" /* message() */ #endif -#include "src/filemanager/layout.h" /* print_vfs_message */ - #include "vfs.h" #include "utilvfs.h" #include "xdirentry.h" @@ -279,7 +278,7 @@ vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root, if (ent && (!(MEDATA->dir_uptodate) (me, ent->ino))) { #if 1 - print_vfs_message (_("Directory cache expired for %s"), path); + vfs_print_message (_("Directory cache expired for %s"), path); #endif vfs_s_free_entry (me, ent); ent = NULL; @@ -708,11 +707,11 @@ vfs_s_print_stats (const char *fs_name, const char *action, } if (need) - print_vfs_message (i18n_percent_transf_format, fs_name, action, + vfs_print_message (i18n_percent_transf_format, fs_name, action, file_name, (int) ((double) have * 100 / need), (uintmax_t) have, _("bytes transferred")); else - print_vfs_message (i18n_transf_format, fs_name, action, file_name, (uintmax_t) have, + vfs_print_message (i18n_transf_format, fs_name, action, file_name, (uintmax_t) have, _("bytes transferred")); } @@ -1203,7 +1202,7 @@ vfs_s_open (struct vfs_class *me, const char *file, int flags, mode_t mode) { if (MEDATA->linear_start) { - print_vfs_message (_("Starting linear transfer...")); + vfs_print_message (_("Starting linear transfer...")); fh->linear = LS_LINEAR_PREOPEN; } } diff --git a/lib/vfs/vfs.c b/lib/vfs/vfs.c index 90f94bfca..25e44b0b6 100644 --- a/lib/vfs/vfs.c +++ b/lib/vfs/vfs.c @@ -54,6 +54,7 @@ #include "lib/strutil.h" #include "lib/util.h" #include "lib/widget.h" /* message() */ +#include "lib/event.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" @@ -1515,3 +1516,17 @@ vfs_file_is_local (const char *filename) } /* --------------------------------------------------------------------------------------------- */ + +void +vfs_print_message (const char *msg, ...) +{ + ev_vfs_print_message_t event_data; + + va_start (event_data.ap, msg); + event_data.msg = msg; + + mc_event_raise (MCEVENT_GROUP_CORE, "vfs_print_message", (gpointer) & event_data); + va_end (event_data.ap); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h index cfc554e6d..cd6cd974a 100644 --- a/lib/vfs/vfs.h +++ b/lib/vfs/vfs.h @@ -288,5 +288,7 @@ void vfs_release_path (const char *dir); void vfs_fill_names (fill_names_f); +void vfs_print_message (const char *msg, ...) __attribute__ ((format (__printf__, 1, 2))); + /*** inline functions ****************************************************************************/ #endif /* MC_VFS_VFS_H */ diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 00c4d6ecf..d9feb2df9 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -102,6 +102,8 @@ int free_space = 1; /* The starting line for the output of the subprogram */ int output_start_y = 0; +int ok_to_refresh = 1; + /*** file scope macro definitions ****************************************************************/ /* The maximum number of views managed by the set_display_type routine */ @@ -191,7 +193,6 @@ static int output_lines_label_len; static WButton *bleft_widget, *bright_widget; -static int ok_to_refresh = 1; /*** file scope functions ************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -886,45 +887,6 @@ set_hintbar (const char *str) /* --------------------------------------------------------------------------------------------- */ -void -print_vfs_message (const char *msg, ...) -{ - va_list ap; - char str[128]; - - va_start (ap, msg); - g_vsnprintf (str, sizeof (str), msg, ap); - va_end (ap); - - if (mc_global.widget.midnight_shutdown) - return; - - if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner) - { - int col, row; - - if (!nice_rotating_dash || (ok_to_refresh <= 0)) - return; - - /* Preserve current cursor position */ - tty_getyx (&row, &col); - - tty_gotoyx (0, 0); - tty_setcolor (NORMAL_COLOR); - tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT)); - - /* Restore cursor position */ - tty_gotoyx (row, col); - mc_refresh (); - return; - } - - if (mc_global.message_visible) - set_hintbar (str); -} - -/* --------------------------------------------------------------------------------------------- */ - void rotate_dash (void) { diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h index b0b6f343f..0ce2da262 100644 --- a/src/filemanager/layout.h +++ b/src/filemanager/layout.h @@ -66,8 +66,6 @@ void clr_scr (void); void repaint_screen (void); void mc_refresh (void); -void print_vfs_message (const char *msg, ...) __attribute__ ((format (__printf__, 1, 2))); - /*** inline functions ****************************************************************************/ #endif /* MC__LAYOUT_H */ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 3ae6a9365..9b61f53fe 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -86,6 +86,7 @@ #include "midnight.h" /* TODO: merge content of layout.c here */ +extern int ok_to_refresh; /*** global variables ****************************************************************************/ @@ -548,6 +549,51 @@ check_other_panel_timestamp (const gchar * event_group_name, const gchar * event /* --------------------------------------------------------------------------------------------- */ +/* event callback */ +static gboolean +print_vfs_message (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + char str[128]; + ev_vfs_print_message_t *event_data = (ev_vfs_print_message_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + g_vsnprintf (str, sizeof (str), event_data->msg, event_data->ap); + + if (mc_global.widget.midnight_shutdown) + return TRUE; + + if (!mc_global.message_visible || !the_hint || !the_hint->widget.owner) + { + int col, row; + + if (!nice_rotating_dash || (ok_to_refresh <= 0)) + return TRUE; + + /* Preserve current cursor position */ + tty_getyx (&row, &col); + + tty_gotoyx (0, 0); + tty_setcolor (NORMAL_COLOR); + tty_print_string (str_fit_to_term (str, COLS - 1, J_LEFT)); + + /* Restore cursor position */ + tty_gotoyx (row, col); + mc_refresh (); + return TRUE; + } + + if (mc_global.message_visible) + set_hintbar (str); + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + static void create_panels (void) { @@ -608,6 +654,8 @@ create_panels (void) NULL); #endif /* ENABLE_VFS */ + mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL); + /* Create the nice widgets */ cmdline = command_new (0, 0, 0); the_prompt = label_new (0, 0, mc_prompt); diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c index 88ceadefe..50c9600cb 100644 --- a/src/vfs/fish/fish.c +++ b/src/vfs/fish/fish.c @@ -63,7 +63,6 @@ #include "lib/fileloc.h" #include "lib/mcconfig.h" -#include "src/filemanager/layout.h" /* print_vfs_message */ #include "src/execute.h" /* pre_exec, post_exec */ #include "lib/vfs/vfs.h" @@ -260,7 +259,7 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super) { if ((SUP.sockw != -1) || (SUP.sockr != -1)) { - print_vfs_message (_("fish: Disconnecting from %s"), super->name ? super->name : "???"); + vfs_print_message (_("fish: Disconnecting from %s"), super->name ? super->name : "???"); fish_command (me, super, NONE, "#BYE\nexit\n"); close (SUP.sockw); close (SUP.sockr); @@ -509,7 +508,7 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) if (!ftalk) ERRNOR (E_PROTO, -1); - print_vfs_message (_("fish: Sending initial line...")); + vfs_print_message (_("fish: Sending initial line...")); /* * Run `start_fish_server'. If it doesn't exist - no problem, * we'll talk directly to the shell. @@ -520,7 +519,7 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n") != COMPLETE) ERRNOR (E_PROTO, -1); - print_vfs_message (_("fish: Handshaking version...")); + vfs_print_message (_("fish: Handshaking version...")); if (fish_command (me, super, WAIT_REPLY, "#VER 0.0.3\necho '### 000'\n") != COMPLETE) ERRNOR (E_PROTO, -1); @@ -530,13 +529,13 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) "LANG=C LC_ALL=C LC_TIME=C; export LANG LC_ALL LC_TIME;\n" "echo '### 200'\n") != COMPLETE) ERRNOR (E_PROTO, -1); - print_vfs_message (_("fish: Getting host info...")); + vfs_print_message (_("fish: Getting host info...")); if (fish_info (me, super)) SUP.scr_env = fish_set_env (SUP.host_flags); - print_vfs_message (_("fish: Setting up current directory...")); + vfs_print_message (_("fish: Setting up current directory...")); SUP.cwdir = fish_getcwd (me, super); - print_vfs_message (_("fish: Connected, home %s."), SUP.cwdir); + vfs_print_message (_("fish: Connected, home %s."), SUP.cwdir); #if 0 super->name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, "/", (char *) NULL); #endif @@ -643,7 +642,7 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) #endif logfile = MEDATA->logfile; - print_vfs_message (_("fish: Reading directory %s..."), remote_path); + vfs_print_message (_("fish: Reading directory %s..."), remote_path); gettimeofday (&dir->timestamp, NULL); dir->timestamp.tv_sec += fish_directory_timeout; @@ -809,7 +808,7 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) { g_free (SUP.cwdir); SUP.cwdir = g_strdup (remote_path); - print_vfs_message (_("%s: done."), me->name); + vfs_print_message (_("%s: done."), me->name); return 0; } else if (reply_code == ERROR) @@ -822,7 +821,7 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path) } error: - print_vfs_message (_("%s: failure"), me->name); + vfs_print_message (_("%s: failure"), me->name); return -1; } @@ -880,7 +879,7 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo */ quoted_name = strutils_shell_escape (name); - print_vfs_message (_("fish: store %s: sending command..."), quoted_name); + vfs_print_message (_("fish: store %s: sending command..."), quoted_name); /* FIXME: File size is limited to ULONG_MAX */ if (!fh->u.fish.append) @@ -914,7 +913,7 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo { if ((errno == EINTR) && tty_got_interrupt ()) continue; - print_vfs_message (_("fish: Local read failed, sending zeros")); + vfs_print_message (_("fish: Local read failed, sending zeros")); close (h); h = open ("/dev/zero", O_RDONLY); } @@ -933,7 +932,7 @@ fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *lo } tty_disable_interrupt_key (); total += n; - print_vfs_message ("%s: %d/%" PRIuMAX, + vfs_print_message ("%s: %d/%" PRIuMAX, was_error ? _("fish: storing zeros") : _("fish: storing file"), total, (uintmax_t) s.st_size); } @@ -1002,7 +1001,7 @@ fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh) char buffer[8192]; int n; - print_vfs_message (_("Aborting transfer...")); + vfs_print_message (_("Aborting transfer...")); do { n = MIN (8192, fh->u.fish.total - fh->u.fish.got); @@ -1017,9 +1016,9 @@ fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh) while (n != 0); if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) - print_vfs_message (_("Error reported after abort.")); + vfs_print_message (_("Error reported after abort.")); else - print_vfs_message (_("Aborted transfer would be successful.")); + vfs_print_message (_("Aborted transfer would be successful.")); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index fb8da1672..d119021e7 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -94,7 +94,6 @@ What to do with this? #include "lib/tty/tty.h" /* enable/disable interrupt key */ #include "lib/widget.h" /* message() */ -#include "src/filemanager/layout.h" /* print_vfs_message */ #include "src/history.h" #include "src/setup.h" /* for load_anon_passwd */ @@ -508,7 +507,7 @@ ftpfs_free_archive (struct vfs_class *me, struct vfs_s_super *super) { if (SUP.sock != -1) { - print_vfs_message (_("ftpfs: Disconnecting from %s"), SUP.host); + vfs_print_message (_("ftpfs: Disconnecting from %s"), SUP.host); ftpfs_command (me, super, NONE, "QUIT"); close (SUP.sock); } @@ -601,12 +600,12 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char fflush (MEDATA->logfile); } - print_vfs_message (_("ftpfs: sending login name")); + vfs_print_message (_("ftpfs: sending login name")); switch (ftpfs_command (me, super, WAIT_REPLY, "USER %s", name)) { case CONTINUE: - print_vfs_message (_("ftpfs: sending user password")); + vfs_print_message (_("ftpfs: sending user password")); code = ftpfs_command (me, super, WAIT_REPLY, "PASS %s", pass); if (code == CONTINUE) { @@ -617,7 +616,7 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char g_free (p); if (op == NULL) ERRNOR (EPERM, 0); - print_vfs_message (_("ftpfs: sending user account")); + vfs_print_message (_("ftpfs: sending user account")); code = ftpfs_command (me, super, WAIT_REPLY, "ACCT %s", op); g_free (op); } @@ -626,7 +625,7 @@ ftpfs_login_server (struct vfs_class *me, struct vfs_s_super *super, const char /* fall through */ case COMPLETE: - print_vfs_message (_("ftpfs: logged in")); + vfs_print_message (_("ftpfs: logged in")); wipe_password (pass); g_free (name); return 1; @@ -776,7 +775,7 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super) if (!host || !*host) { - print_vfs_message (_("ftpfs: Invalid host name.")); + vfs_print_message (_("ftpfs: Invalid host name.")); ftpfs_errno = EINVAL; g_free (host); return -1; @@ -828,7 +827,7 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super) if (e != 0) { tty_disable_interrupt_key (); - print_vfs_message (_("ftpfs: %s"), gai_strerror (e)); + vfs_print_message (_("ftpfs: %s"), gai_strerror (e)); g_free (host); ftpfs_errno = EINVAL; return -1; @@ -846,14 +845,14 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super) continue; tty_disable_interrupt_key (); - print_vfs_message (_("ftpfs: %s"), unix_error_string (errno)); + vfs_print_message (_("ftpfs: %s"), unix_error_string (errno)); g_free (host); freeaddrinfo (res); ftpfs_errno = errno; return -1; } - print_vfs_message (_("ftpfs: making connection to %s"), host); + vfs_print_message (_("ftpfs: making connection to %s"), host); g_free (host); host = NULL; @@ -865,11 +864,11 @@ ftpfs_open_socket (struct vfs_class *me, struct vfs_s_super *super) if (errno == EINTR && tty_got_interrupt ()) { - print_vfs_message (_("ftpfs: connection interrupted by user")); + vfs_print_message (_("ftpfs: connection interrupted by user")); } else if (res->ai_next == NULL) { - print_vfs_message (_("ftpfs: connection to server failed: %s"), + vfs_print_message (_("ftpfs: connection to server failed: %s"), unix_error_string (errno)); } else @@ -929,7 +928,7 @@ ftpfs_open_archive_int (struct vfs_class *me, struct vfs_s_super *super) tty_enable_interrupt_key (); for (count_down = retry_seconds; count_down; count_down--) { - print_vfs_message (_("Waiting to retry... %d (Control-C to cancel)"), + vfs_print_message (_("Waiting to retry... %d (Control-C to cancel)"), count_down); sleep (1); if (tty_got_interrupt ()) @@ -1265,7 +1264,7 @@ ftpfs_init_data_socket (struct vfs_class *me, struct vfs_s_super *super, ((struct sockaddr_in6 *) data_addr)->sin6_port = 0; break; default: - print_vfs_message (_("ftpfs: invalid address family")); + vfs_print_message (_("ftpfs: invalid address family")); ERRNOR (EINVAL, -1); } @@ -1273,7 +1272,7 @@ ftpfs_init_data_socket (struct vfs_class *me, struct vfs_s_super *super, if (result < 0) { - print_vfs_message (_("ftpfs: could not create socket: %s"), unix_error_string (errno)); + vfs_print_message (_("ftpfs: could not create socket: %s"), unix_error_string (errno)); return -1; } else @@ -1307,7 +1306,7 @@ ftpfs_initconn (struct vfs_class *me, struct vfs_s_super *super) if (ftpfs_setup_passive (me, super, data_sock, &data_addr, &data_addrlen)) return data_sock; - print_vfs_message (_("ftpfs: could not setup passive mode")); + vfs_print_message (_("ftpfs: could not setup passive mode")); SUP.use_passive_connection = 0; close (data_sock); @@ -1407,10 +1406,10 @@ ftpfs_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh) FH_SOCK = -1; SUP.ctl_connection_busy = 0; - print_vfs_message (_("ftpfs: aborting transfer.")); + vfs_print_message (_("ftpfs: aborting transfer.")); if (send (SUP.sock, ipbuf, sizeof (ipbuf), MSG_OOB) != sizeof (ipbuf)) { - print_vfs_message (_("ftpfs: abort error: %s"), unix_error_string (errno)); + vfs_print_message (_("ftpfs: abort error: %s"), unix_error_string (errno)); if (dsock != -1) close (dsock); return; @@ -1418,7 +1417,7 @@ ftpfs_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh) if (ftpfs_command (me, super, NONE, "%cABOR", DM) != COMPLETE) { - print_vfs_message (_("ftpfs: abort failed")); + vfs_print_message (_("ftpfs: abort failed")); if (dsock != -1) close (dsock); return; @@ -1547,7 +1546,7 @@ resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super { if (ftpfs_chdir_internal (bucket, dir->remote_path) != COMPLETE) { - print_vfs_message (_("ftpfs: CWD failed.")); + vfs_print_message (_("ftpfs: CWD failed.")); return; } sock = ftpfs_open_data_connection (bucket, "LIST -lLa", ".", TYPE_ASCII, 0); @@ -1557,7 +1556,7 @@ resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super if (sock == -1) { - print_vfs_message (_("ftpfs: couldn't resolve symlink")); + vfs_print_message (_("ftpfs: couldn't resolve symlink")); return; } @@ -1565,7 +1564,7 @@ resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super if (fp == NULL) { close (sock); - print_vfs_message (_("ftpfs: couldn't resolve symlink")); + vfs_print_message (_("ftpfs: couldn't resolve symlink")); return; } tty_enable_interrupt_key (); @@ -1626,7 +1625,7 @@ resolve_symlink_with_ls_options (struct vfs_class *me, struct vfs_s_super *super static void resolve_symlink (struct vfs_class *me, struct vfs_s_super *super, struct vfs_s_inode *dir) { - print_vfs_message (_("Resolving symlink...")); + vfs_print_message (_("Resolving symlink...")); if (SUP.strict_rfc959_list_cmd) resolve_symlink_without_ls_options (me, super, dir); @@ -1650,7 +1649,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path || (strchr (remote_path, ' ') != NULL); again: - print_vfs_message (_("ftpfs: Reading FTP directory %s... %s%s"), + vfs_print_message (_("ftpfs: Reading FTP directory %s... %s%s"), remote_path, SUP.strict == RFC_STRICT ? _("(strict rfc959)") : "", cd_first ? _("(chdir first)") : ""); @@ -1660,7 +1659,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path if (ftpfs_chdir_internal (me, super, remote_path) != COMPLETE) { ftpfs_errno = ENOENT; - print_vfs_message (_("ftpfs: CWD failed.")); + vfs_print_message (_("ftpfs: CWD failed.")); return -1; } } @@ -1702,7 +1701,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path close (sock); tty_disable_interrupt_key (); ftpfs_get_reply (me, SUP.sock, NULL, 0); - print_vfs_message (_("%s: failure"), me->name); + vfs_print_message (_("%s: failure"), me->name); return -1; } @@ -1749,7 +1748,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path if (SUP.strict == RFC_AUTODETECT) SUP.strict = RFC_DARING; - print_vfs_message (_("%s: done."), me->name); + vfs_print_message (_("%s: done."), me->name); return 0; fallback: @@ -1763,7 +1762,7 @@ ftpfs_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path cd_first = 1; goto again; } - print_vfs_message (_("ftpfs: failed; nowhere to fallback to")); + vfs_print_message (_("ftpfs: failed; nowhere to fallback to")); ERRNOR (EACCES, -1); } @@ -1840,7 +1839,7 @@ ftpfs_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *l w_buf += n_written; n_read -= n_written; } - print_vfs_message ("%s: %" PRIuMAX "/%" PRIuMAX, + vfs_print_message ("%s: %" PRIuMAX "/%" PRIuMAX, _("ftpfs: storing file"), (uintmax_t) n_stored, (uintmax_t) s.st_size); } tty_disable_interrupt_key (); diff --git a/src/vfs/undelfs/undelfs.c b/src/vfs/undelfs/undelfs.c index 4d8831fb0..4778207de 100644 --- a/src/vfs/undelfs/undelfs.c +++ b/src/vfs/undelfs/undelfs.c @@ -59,7 +59,6 @@ #include "lib/global.h" #include "lib/widget.h" /* message() */ -#include "src/filemanager/layout.h" /* print_vfs_message */ #include "lib/vfs/utilvfs.h" #include "lib/vfs/vfs.h" @@ -260,7 +259,7 @@ undelfs_loaddel (void) while (ino) { if ((count++ % 1024) == 0) - print_vfs_message (_("undelfs: loading deleted files information %d inodes"), count); + vfs_print_message (_("undelfs: loading deleted files information %d inodes"), count); if (inode.i_dtime == 0) goto next; @@ -360,13 +359,13 @@ undelfs_opendir (struct vfs_class *me, const char *dirname) message (D_ERROR, undelfserr, _("Cannot open file %s"), ext2_fname); return 0; } - print_vfs_message (_("undelfs: reading inode bitmap...")); + vfs_print_message (_("undelfs: reading inode bitmap...")); if (ext2fs_read_inode_bitmap (fs)) { message (D_ERROR, undelfserr, _("Cannot load inode bitmap from:\n%s"), ext2_fname); goto quit_opendir; } - print_vfs_message (_("undelfs: reading block bitmap...")); + vfs_print_message (_("undelfs: reading block bitmap...")); if (ext2fs_read_block_bitmap (fs)) { message (D_ERROR, undelfserr, _("Cannot load block bitmap from:\n%s"), ext2_fname); @@ -375,10 +374,10 @@ undelfs_opendir (struct vfs_class *me, const char *dirname) /* Now load the deleted information */ if (!undelfs_loaddel ()) goto quit_opendir; - print_vfs_message (_("%s: done."), me->name); + vfs_print_message (_("%s: done."), me->name); return fs; quit_opendir: - print_vfs_message (_("%s: failure"), me->name); + vfs_print_message (_("%s: failure"), me->name); ext2fs_close (fs); fs = NULL; return 0; From e784cf65a5da2ff5300f55e2657a501094ae765c Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 13:58:36 +0200 Subject: [PATCH 09/25] Move src/filemanager/complete.c to lib/widget/input_complete.c Signed-off-by: Slava Zanko --- lib/widget/Makefile.am | 1 + lib/widget/input.c | 2 ++ lib/widget/input.h | 3 --- .../complete.c => lib/widget/input_complete.c | 2 ++ lib/widget/input_complete.h | 18 ++++++++++++++++++ src/filemanager/Makefile.am | 1 - 6 files changed, 23 insertions(+), 4 deletions(-) rename src/filemanager/complete.c => lib/widget/input_complete.c (99%) create mode 100644 lib/widget/input_complete.h diff --git a/lib/widget/Makefile.am b/lib/widget/Makefile.am index ab4742ba6..b68c8cf0e 100644 --- a/lib/widget/Makefile.am +++ b/lib/widget/Makefile.am @@ -12,6 +12,7 @@ libmcwidget_la_SOURCES = \ hline.c hline.h \ history.c history.h \ input.c input.h \ + input_complete.c input_complete.h \ listbox-window.c listbox-window.h \ listbox.c listbox.h \ label.c label.h \ diff --git a/lib/widget/input.c b/lib/widget/input.c index 47f6512d7..bcce66a1c 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -50,6 +50,8 @@ #include "lib/keybind.h" /* global_keymap_t */ #include "lib/widget.h" +#include "input_complete.h" + #include "src/main.h" /* home_dir */ #include "src/filemanager/midnight.h" /* current_panel */ #include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ diff --git a/lib/widget/input.h b/lib/widget/input.h index 979bba40d..702e39da9 100644 --- a/lib/widget/input.h +++ b/lib/widget/input.h @@ -88,9 +88,6 @@ void input_disable_update (WInput * in); void input_clean (WInput * in); void input_free_completions (WInput * in); -/* src/complete.c */ -void complete (WInput * in); - /*** inline functions ****************************************************************************/ #endif /* MC__WIDGET_INPUT_H */ diff --git a/src/filemanager/complete.c b/lib/widget/input_complete.c similarity index 99% rename from src/filemanager/complete.c rename to lib/widget/input_complete.c index 9817fc75a..fe00b6aaa 100644 --- a/src/filemanager/complete.c +++ b/lib/widget/input_complete.c @@ -46,6 +46,8 @@ #include "lib/util.h" #include "lib/widget.h" +#include "input_complete.h" + /*** global variables ****************************************************************************/ /* Linux declares environ in , so don't repeat it here. */ diff --git a/lib/widget/input_complete.h b/lib/widget/input_complete.h new file mode 100644 index 000000000..5198d5df7 --- /dev/null +++ b/lib/widget/input_complete.h @@ -0,0 +1,18 @@ +#ifndef MC__WIDGET_INPUT_COMPLETE_H +#define MC__WIDGET_INPUT_COMPLETE_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +void complete (WInput * in); + +/*** inline functions ****************************************************************************/ + +#endif /* MC__WIDGET_INPUT_COMPLETE_H */ diff --git a/src/filemanager/Makefile.am b/src/filemanager/Makefile.am index 1d9c5c0a1..99703d3dd 100644 --- a/src/filemanager/Makefile.am +++ b/src/filemanager/Makefile.am @@ -8,7 +8,6 @@ libmcfilemanager_la_SOURCES = \ chown.c chown.h \ cmd.c cmd.h \ command.c command.h \ - complete.c \ dir.c dir.h \ ext.c ext.h \ file.c file.h \ From 7dad2df6a845f32cc526c3afa4d55557e9d25d9c Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 14:23:29 +0200 Subject: [PATCH 10/25] Moved initialization of mc_global.share_data_dir and mc_global.sysconf_dir to library Signed-off-by: Slava Zanko --- lib/mcconfig/Makefile.am | 5 +++-- lib/mcconfig/paths.c | 16 ++++++++++++++++ src/Makefile.am | 5 +---- src/main.c | 36 +++++++----------------------------- src/vfs/sfs/sfs.c | 2 +- 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/lib/mcconfig/Makefile.am b/lib/mcconfig/Makefile.am index 5605a076f..296047fd2 100644 --- a/lib/mcconfig/Makefile.am +++ b/lib/mcconfig/Makefile.am @@ -9,5 +9,6 @@ libmcconfig_la_SOURCES = \ libmcconfig_la_CFLAGS = -I$(top_srcdir) \ $(GLIB_CFLAGS) \ - -DDATADIR=\""$(pkgdatadir)/"\" -DLOCALEDIR=\""$(localedir)"\" - + -DDATADIR=\""$(pkgdatadir)/"\" \ + -DLOCALEDIR=\""$(localedir)"\" \ + -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" diff --git a/lib/mcconfig/paths.c b/lib/mcconfig/paths.c index abcf9decc..3fdd3c57e 100644 --- a/lib/mcconfig/paths.c +++ b/lib/mcconfig/paths.c @@ -206,6 +206,8 @@ mc_config_copy (const char *old_name, const char *new_name, GError ** error) void mc_config_init_config_paths (GError ** error) { + const char *mc_datadir; + char *u_config_dir = (char *) g_get_user_config_dir (); char *u_data_dir = (char *) g_get_user_data_dir (); char *u_cache_dir = (char *) g_get_user_cache_dir (); @@ -230,6 +232,17 @@ mc_config_init_config_paths (GError ** error) g_free (u_data_dir); g_free (u_cache_dir); g_free (u_config_dir); + + /* This is the directory, where MC was installed, on Unix this is DATADIR */ + /* and can be overriden by the MC_DATADIR environment variable */ + mc_datadir = g_getenv ("MC_DATADIR"); + if (mc_datadir != NULL) + mc_global.sysconfig_dir = g_strdup (mc_datadir); + else + mc_global.sysconfig_dir = g_strdup (SYSCONFDIR); + + mc_global.share_data_dir = g_strdup (DATADIR); + xdg_vars_initialized = TRUE; } @@ -245,6 +258,9 @@ mc_config_deinit_config_paths (void) g_free (xdg_cache); g_free (xdg_data); + g_free (mc_global.share_data_dir); + g_free (mc_global.sysconfig_dir); + xdg_vars_initialized = FALSE; } diff --git a/src/Makefile.am b/src/Makefile.am index 2e36f2eac..bf36f7d14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,10 +8,7 @@ if USE_DIFF SUBDIRS += diffviewer endif -AM_CPPFLAGS = -DDATADIR=\""$(pkgdatadir)/"\" \ - -DLOCALEDIR=\""$(localedir)"\" \ - -DSYSCONFDIR=\""$(sysconfdir)/@PACKAGE@/"\" - +AM_CPPFLAGS = -DLOCALEDIR=\""$(localedir)"\" if CONS_SAVER SUBDIRS += consaver diff --git a/src/main.c b/src/main.c index a69607e28..ae53f5e78 100644 --- a/src/main.c +++ b/src/main.c @@ -156,7 +156,6 @@ static void OS_Setup (void) { const char *shell_env = getenv ("SHELL"); - const char *mc_libdir; if ((shell_env == NULL) || (shell_env[0] == '\0')) { @@ -173,21 +172,6 @@ OS_Setup (void) g_free (shell); shell = g_strdup ("/bin/sh"); } - - /* This is the directory, where MC was installed, on Unix this is DATADIR */ - /* and can be overriden by the MC_DATADIR environment variable */ - mc_libdir = getenv ("MC_DATADIR"); - if (mc_libdir != NULL) - { - mc_global.sysconfig_dir = g_strdup (mc_libdir); - mc_global.share_data_dir = g_strdup (SYSCONFDIR); - } - else - { - mc_global.sysconfig_dir = g_strdup (SYSCONFDIR); - mc_global.share_data_dir = g_strdup (DATADIR); - } - } /* --------------------------------------------------------------------------------------------- */ @@ -408,6 +392,13 @@ main (int argc, char *argv[]) str_init_strings (NULL); + /* Initialize and create home directories */ + /* do it after the screen library initialization to show the error message */ + mc_config_init_config_paths (&error); + + if (error == NULL && mc_config_deprecated_dir_present ()) + mc_config_migrate_from_old_place (&error); + vfs_init (); vfs_plugins_init (); vfs_setup_work_dir (); @@ -437,17 +428,6 @@ main (int argc, char *argv[]) /* We need this, since ncurses endwin () doesn't restore the signals */ save_stop_handler (); - /* Initialize and create home directories */ - /* do it after the screen library initialization to show the error message */ - mc_config_init_config_paths (&error); - if (error == NULL) - { - if (mc_config_deprecated_dir_present ()) - { - mc_config_migrate_from_old_place (&error); - } - } - /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ tty_init (mc_global.args.slow_terminal, mc_global.args.ugly_line_drawing); @@ -563,8 +543,6 @@ main (int argc, char *argv[]) } g_free (last_wd_string); - g_free (mc_global.share_data_dir); - g_free (mc_global.sysconfig_dir); g_free (shell); done_key (); diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c index c32a22812..401fbfef9 100644 --- a/src/vfs/sfs/sfs.c +++ b/src/vfs/sfs/sfs.c @@ -421,7 +421,7 @@ sfs_init (struct vfs_class *me) if (cfg == NULL) { - fprintf (stderr, _("Warning: file %s not found\n"), mc_sfsini); + fprintf (stderr, _("%s: Warning: file %s not found\n"), "sfs_init()", mc_sfsini); g_free (mc_sfsini); return 0; } From c58365fa64e265bb653271416d911d635417b137 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 11 Feb 2011 17:28:29 +0200 Subject: [PATCH 11/25] Move check_for_default() function from lib/util.c to src/util.c Signed-off-by: Slava Zanko --- lib/util.c | 27 ---------------- lib/util.h | 3 -- src/Makefile.am | 3 +- src/editor/editcmd.c | 1 + src/filemanager/cmd.c | 1 + src/util.c | 72 +++++++++++++++++++++++++++++++++++++++++++ src/util.h | 20 ++++++++++++ 7 files changed, 96 insertions(+), 31 deletions(-) create mode 100644 src/util.c create mode 100644 src/util.h diff --git a/lib/util.c b/lib/util.c index f72d35832..c70e7e201 100644 --- a/lib/util.c +++ b/lib/util.c @@ -48,9 +48,6 @@ #include "lib/strutil.h" #include "lib/util.h" -#include "src/filemanager/filegui.h" -#include "src/filemanager/file.h" /* copy_file_file() */ - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -610,30 +607,6 @@ extension (const char *filename) /* --------------------------------------------------------------------------------------------- */ -int -check_for_default (const char *default_file, const char *file) -{ - if (!exist_file (file)) - { - FileOpContext *ctx; - FileOpTotalContext *tctx; - - if (!exist_file (default_file)) - return -1; - - ctx = file_op_context_new (OP_COPY); - tctx = file_op_total_context_new (); - file_op_context_create_ui (ctx, 0, FALSE); - copy_file_file (tctx, ctx, default_file, file); - file_op_total_context_destroy (tctx); - file_op_context_destroy (ctx); - } - - return 0; -} - -/* --------------------------------------------------------------------------------------------- */ - char * load_mc_home_file (const char *from, const char *filename, char **allocated_filename) { diff --git a/lib/util.h b/lib/util.h index a6aa3a444..ea9dadec5 100644 --- a/lib/util.h +++ b/lib/util.h @@ -122,9 +122,6 @@ void init_uid_gid_cache (void); char *get_group (int); char *get_owner (int); -/* Check if the file exists. If not copy the default */ -int check_for_default (const char *default_file, const char *file); - /* Returns a copy of *s until a \n is found and is below top */ const char *extract_line (const char *s, const char *top); diff --git a/src/Makefile.am b/src/Makefile.am index bf36f7d14..0e10e004e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,7 +69,8 @@ mc_SOURCES = \ main.c main.h \ setup.c setup.h \ subshell.c subshell.h \ - textconf.c textconf.h + textconf.c textconf.h \ + util.c util.h if CHARSET mc_SOURCES += selcodepage.c selcodepage.h diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 5b05e0b58..8fed62155 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -65,6 +65,7 @@ #include "src/selcodepage.h" #include "src/keybind-defaults.h" #include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ +#include "src/util.h" /* check_for_default() */ #include "edit-impl.h" #include "edit-widget.h" diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index a58ea5f16..27df89ac6 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -65,6 +65,7 @@ #include "src/setup.h" #include "src/execute.h" /* toggle_panels() */ #include "src/history.h" +#include "src/util.h" /* check_for_default() */ #ifdef USE_INTERNAL_EDIT #include "src/editor/edit.h" diff --git a/src/util.c b/src/util.c new file mode 100644 index 000000000..14658a138 --- /dev/null +++ b/src/util.c @@ -0,0 +1,72 @@ +/* Various non-library utilities + + Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + + Authors: 2003 Adam Byrtek + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + */ + + +#include + +#include "lib/global.h" +#include "lib/util.h" + +#include "src/filemanager/file.h" +#include "src/filemanager/filegui.h" + +#include "util.h" + +/*** global variables ****************************************************************************/ + +/*** file scope macro definitions ****************************************************************/ + +/*** file scope type declarations ****************************************************************/ + +/*** file scope variables ************************************************************************/ + +/*** file scope functions ************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + +int +check_for_default (const char *default_file, const char *file) +{ + if (!exist_file (file)) + { + FileOpContext *ctx; + FileOpTotalContext *tctx; + + if (!exist_file (default_file)) + return -1; + + ctx = file_op_context_new (OP_COPY); + tctx = file_op_total_context_new (); + file_op_context_create_ui (ctx, 0, FALSE); + copy_file_file (tctx, ctx, default_file, file); + file_op_total_context_destroy (tctx); + file_op_context_destroy (ctx); + } + + return 0; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/util.h b/src/util.h new file mode 100644 index 000000000..a94916196 --- /dev/null +++ b/src/util.h @@ -0,0 +1,20 @@ +#ifndef MC_SRC_UTIL_H +#define MC_SRC_UTIL_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/* Check if the file exists. If not copy the default */ +int check_for_default (const char *default_file, const char *file); + +/*** inline functions ****************************************************************************/ + +#endif /* MC_SRC_UTIL_H */ + From 0f93e313df746bacafb62ffc9fe896148eca242e Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 17:08:44 +0200 Subject: [PATCH 12/25] src/background.c: added some forgotten va_end() calls Signed-off-by: Slava Zanko --- src/background.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/background.c b/src/background.c index 984a5bfbf..df6f6b470 100644 --- a/src/background.c +++ b/src/background.c @@ -527,6 +527,7 @@ parent_call (void *routine, struct FileOpContext *ctx, int argc, ...) if (ctx) ret = read (from_parent_fd, ctx, sizeof (FileOpContext)); + va_end (ap); return i; } @@ -550,8 +551,13 @@ parent_call_string (void *routine, int argc, ...) value = va_arg (ap, void *); if ((write (parent_fd, &len, sizeof (int)) != sizeof (int)) || (write (parent_fd, value, len) != len)) + { + va_end (ap); return NULL; + } } + va_end (ap); + if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int)) return NULL; if (!i) From 3634716374c2adde10e2979c0ad5aad14457bc8f Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 17:19:48 +0200 Subject: [PATCH 13/25] Moved input_map, listbox_map and dialog_map variables to 'lib' subdirectory. Signed-off-by: Slava Zanko --- lib/widget/dialog.c | 3 ++- lib/widget/dialog.h | 3 +++ lib/widget/input.c | 3 ++- lib/widget/input.h | 4 ++++ lib/widget/listbox.c | 9 ++++----- lib/widget/listbox.h | 4 ++++ src/keybind-defaults.c | 1 + src/keybind-defaults.h | 1 + src/setup.c | 4 ++-- 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index f8f383416..bf0a75224 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -42,7 +42,6 @@ #include "src/help.h" /* interactive_display() */ #include "src/filemanager/layout.h" #include "src/execute.h" /* suspend_cmd() */ -#include "src/keybind-defaults.h" /*** global variables ****************************************************************************/ @@ -64,6 +63,8 @@ int fast_refresh = 0; /* left click outside of dialog closes it */ int mouse_close_dialog = 0; +const global_keymap_t *dialog_map; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ diff --git a/lib/widget/dialog.h b/lib/widget/dialog.h index 468be9e68..7aa112aab 100644 --- a/lib/widget/dialog.h +++ b/lib/widget/dialog.h @@ -31,6 +31,7 @@ #include "lib/global.h" #include "lib/hook.h" /* hook_t */ +#include "lib/keybind.h" /* global_keymap_t */ /*** defined constants ***************************************************************************/ @@ -162,6 +163,8 @@ extern hook_t *idle_hook; extern int fast_refresh; extern int mouse_close_dialog; +extern const global_keymap_t *dialog_map; + /*** declarations of public functions ************************************************************/ /* draw box in window */ diff --git a/lib/widget/input.c b/lib/widget/input.c index bcce66a1c..46eb66b9e 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -55,12 +55,13 @@ #include "src/main.h" /* home_dir */ #include "src/filemanager/midnight.h" /* current_panel */ #include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ -#include "src/keybind-defaults.h" /* input_map */ /*** global variables ****************************************************************************/ int quote = 0; +const global_keymap_t *input_map; + /*** file scope macro definitions ****************************************************************/ #define LARGE_HISTORY_BUTTON 1 diff --git a/lib/widget/input.h b/lib/widget/input.h index 702e39da9..25b6c2295 100644 --- a/lib/widget/input.h +++ b/lib/widget/input.h @@ -6,6 +6,8 @@ #ifndef MC__WIDGET_INPUT_H #define MC__WIDGET_INPUT_H +#include "lib/keybind.h" /* global_keymap_t */ + /*** typedefs(not structures) and defined constants **********************************************/ /* For history load-save functions */ @@ -68,6 +70,8 @@ typedef struct extern int quote; +extern const global_keymap_t *input_map; + /*** declarations of public functions ************************************************************/ WInput *input_new (int y, int x, const int *input_colors, diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index 51602c9e8..a2353ba2f 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -44,11 +44,10 @@ #include "lib/keybind.h" /* global_keymap_t */ #include "lib/widget.h" -/* TODO: these includes should be removed! */ -#include "src/keybind-defaults.h" /* listbox_map */ - /*** global variables ****************************************************************************/ +const global_keymap_t *listbox_map; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -122,8 +121,8 @@ listbox_draw (WListbox * l, gboolean focused) const gboolean disabled = (((Widget *) l)->options & W_DISABLED) != 0; const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; int selc = - disabled ? DISABLED_COLOR : focused ? h->color[DLG_COLOR_HOT_FOCUS] : h-> - color[DLG_COLOR_FOCUS]; + disabled ? DISABLED_COLOR : focused ? h-> + color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS]; GList *le; int pos; diff --git a/lib/widget/listbox.h b/lib/widget/listbox.h index 6513ff83f..88424848b 100644 --- a/lib/widget/listbox.h +++ b/lib/widget/listbox.h @@ -6,6 +6,8 @@ #ifndef MC__WIDGET_LISTBOX_H #define MC__WIDGET_LISTBOX_H +#include "lib/keybind.h" /* global_keymap_t */ + /*** typedefs(not structures) and defined constants **********************************************/ /*** enums ***************************************************************************************/ @@ -53,6 +55,8 @@ typedef struct WListbox /*** global variables defined in .c file *********************************************************/ +extern const global_keymap_t *listbox_map; + /*** declarations of public functions ************************************************************/ WListbox *listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback); diff --git a/src/keybind-defaults.c b/src/keybind-defaults.c index b46b87e46..7d3237130 100644 --- a/src/keybind-defaults.c +++ b/src/keybind-defaults.c @@ -57,6 +57,7 @@ const global_keymap_t *input_map = NULL; const global_keymap_t *listbox_map = NULL; const global_keymap_t *tree_map = NULL; const global_keymap_t *help_map = NULL; + #ifdef USE_INTERNAL_EDIT const global_keymap_t *editor_map = NULL; const global_keymap_t *editor_x_map = NULL; diff --git a/src/keybind-defaults.h b/src/keybind-defaults.h index 53b324afb..038b910c8 100644 --- a/src/keybind-defaults.h +++ b/src/keybind-defaults.h @@ -40,6 +40,7 @@ extern const global_keymap_t *input_map; extern const global_keymap_t *listbox_map; extern const global_keymap_t *tree_map; extern const global_keymap_t *help_map; + #ifdef USE_INTERNAL_EDIT extern const global_keymap_t *editor_map; extern const global_keymap_t *editor_x_map; diff --git a/src/setup.c b/src/setup.c index 23b3a2929..2d7dad78a 100644 --- a/src/setup.c +++ b/src/setup.c @@ -35,6 +35,8 @@ #include "lib/mcconfig.h" #include "lib/fileloc.h" #include "lib/timefmt.h" +#include "lib/util.h" +#include "lib/widget.h" #include "lib/vfs/vfs.h" @@ -45,8 +47,6 @@ #include "src/vfs/fish/fish.h" #endif -#include "lib/util.h" -#include "lib/widget.h" #ifdef HAVE_CHARSET #include "lib/charsets.h" #endif From c2dfb82f61040afb2deb77cf1d4d8addb54b69a1 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 16 Feb 2011 18:11:19 +0200 Subject: [PATCH 14/25] Use events for update panels Signed-off-by: Slava Zanko --- lib/widget/dialog-switch.c | 29 ++++++++++++++++++++++++----- lib/widget/dialog-switch.h | 7 +++++++ src/background.c | 1 - src/editor/editcmd.c | 4 ++-- src/filemanager/achown.c | 1 - src/filemanager/chmod.c | 1 - src/filemanager/chown.c | 1 - src/filemanager/find.c | 1 - src/filemanager/hotlist.c | 1 - src/filemanager/layout.c | 19 ------------------- src/filemanager/layout.h | 2 -- src/filemanager/listmode.c | 1 - src/filemanager/midnight.c | 3 --- src/filemanager/panel.c | 22 ++++++++++++++++++++++ src/filemanager/panelize.c | 1 - src/learn.c | 2 +- 16 files changed, 56 insertions(+), 40 deletions(-) diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c index 7f3e1de4e..7f4b4269a 100644 --- a/lib/widget/dialog-switch.c +++ b/lib/widget/dialog-switch.c @@ -28,14 +28,14 @@ #include "lib/global.h" #include "lib/tty/tty.h" /* LINES, COLS */ +#include "lib/tty/color.h" /* tty_set_normal_attrs() */ #include "lib/widget.h" - -/* TODO: these includes should be removed! */ -#include "src/filemanager/layout.h" /* repaint_screen() */ -#include "src/filemanager/midnight.h" /* midnight_dlg */ +#include "lib/event.h" /*** global variables ****************************************************************************/ +Dlg_head *midnight_dlg = NULL; + /*** file scope macro definitions ****************************************************************/ /*** file scope type declarations ****************************************************************/ @@ -242,7 +242,7 @@ dialog_switch_process_pending (void) if (mc_global.mc_run_mode == MC_RUN_FULL) { mc_current = g_list_find (mc_dialogs, midnight_dlg); - update_panels (UP_OPTIMIZE, UP_KEEPSEL); + mc_event_raise (MCEVENT_GROUP_FILEMANAGER, "update_panels", NULL); } } } @@ -279,3 +279,22 @@ dialog_switch_shutdown (void) } /* --------------------------------------------------------------------------------------------- */ + +void +clr_scr (void) +{ + tty_set_normal_attrs (); + tty_fill_region (0, 0, LINES, COLS, ' '); + tty_refresh (); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +repaint_screen (void) +{ + do_refresh (); + tty_refresh (); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/dialog-switch.h b/lib/widget/dialog-switch.h index 1919139c7..5ab5c9edb 100644 --- a/lib/widget/dialog-switch.h +++ b/lib/widget/dialog-switch.h @@ -12,6 +12,8 @@ /*** global variables defined in .c file *********************************************************/ +extern Dlg_head *midnight_dlg; + /*** declarations of public functions ************************************************************/ void dialog_switch_add (struct Dlg_head *h); @@ -26,5 +28,10 @@ int dialog_switch_process_pending (void); void dialog_switch_got_winch (void); void dialog_switch_shutdown (void); +/* Clear screen */ +void clr_scr (void); +void repaint_screen (void); + /*** inline functions ****************************************************************************/ + #endif /* MC__DIALOG_SWITCH_H */ diff --git a/src/background.c b/src/background.c index df6f6b470..1e878f95a 100644 --- a/src/background.c +++ b/src/background.c @@ -47,7 +47,6 @@ #include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */ #include "lib/widget.h" /* message() */ -#include "filemanager/layout.h" /* repaint_screen() */ #include "filemanager/fileopctx.h" /* FileOpContext */ #include "background.h" diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 8fed62155..c1355e9b9 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -57,8 +57,6 @@ #include "lib/widget.h" #include "lib/charsets.h" -#include "src/filemanager/layout.h" /* clr_scr() */ - #include "src/history.h" #include "src/setup.h" /* option_tab_spacing */ #include "src/help.h" /* interactive_display() */ @@ -66,6 +64,8 @@ #include "src/keybind-defaults.h" #include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ #include "src/util.h" /* check_for_default() */ +#include "src/filemanager/layout.h" /* mc_refresh() */ + #include "edit-impl.h" #include "edit-widget.h" diff --git a/src/filemanager/achown.c b/src/filemanager/achown.c index ae014ce9a..d523f7264 100644 --- a/src/filemanager/achown.c +++ b/src/filemanager/achown.c @@ -46,7 +46,6 @@ #include "dir.h" #include "midnight.h" /* current_panel */ #include "chmod.h" -#include "layout.h" /* repaint_screen() */ #include "achown.h" diff --git a/src/filemanager/chmod.c b/src/filemanager/chmod.c index a2c611992..c2cb6c31f 100644 --- a/src/filemanager/chmod.c +++ b/src/filemanager/chmod.c @@ -41,7 +41,6 @@ #include "lib/widget.h" #include "midnight.h" /* current_panel */ -#include "layout.h" /* repaint_screen() */ #include "chmod.h" /*** global variables ****************************************************************************/ diff --git a/src/filemanager/chown.c b/src/filemanager/chown.c index 422450cc4..e5e053945 100644 --- a/src/filemanager/chown.c +++ b/src/filemanager/chown.c @@ -46,7 +46,6 @@ /* Needed for the extern declarations of integer parameters */ #include "chmod.h" #include "midnight.h" /* current_panel */ -#include "layout.h" /* repaint_screen() */ #include "chown.h" diff --git a/src/filemanager/find.c b/src/filemanager/find.c index e5913a321..adc2e436d 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -52,7 +52,6 @@ #include "cmd.h" /* view_file_at_line */ #include "midnight.h" /* current_panel */ #include "boxes.h" -#include "layout.h" /* mc_refresh() */ #include "find.h" diff --git a/src/filemanager/hotlist.c b/src/filemanager/hotlist.c index 72020ceab..fa797343e 100644 --- a/src/filemanager/hotlist.c +++ b/src/filemanager/hotlist.c @@ -56,7 +56,6 @@ #include "src/history.h" #include "midnight.h" /* current_panel */ -#include "layout.h" /* repaint_screen() */ #include "command.h" /* cmdline */ #include "hotlist.h" diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index d9feb2df9..3a597bb9b 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -688,25 +688,6 @@ layout_box (void) /* --------------------------------------------------------------------------------------------- */ -void -clr_scr (void) -{ - tty_set_normal_attrs (); - tty_fill_region (0, 0, LINES, COLS, ' '); - tty_refresh (); -} - -/* --------------------------------------------------------------------------------------------- */ - -void -repaint_screen (void) -{ - do_refresh (); - tty_refresh (); -} - -/* --------------------------------------------------------------------------------------------- */ - void mc_refresh (void) { diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h index 0ce2da262..1d84e68d9 100644 --- a/src/filemanager/layout.h +++ b/src/filemanager/layout.h @@ -62,8 +62,6 @@ void use_dash (gboolean flag); /* Disable/Enable rotate_dash routines */ void rotate_dash (void); /* Clear screen */ -void clr_scr (void); -void repaint_screen (void); void mc_refresh (void); /*** inline functions ****************************************************************************/ diff --git a/src/filemanager/listmode.c b/src/filemanager/listmode.c index 38433a090..38a385686 100644 --- a/src/filemanager/listmode.c +++ b/src/filemanager/listmode.c @@ -46,7 +46,6 @@ #include "dir.h" #include "panel.h" /* Needed for the externs */ #include "file.h" -#include "layout.h" /* repaint_screen() */ #include "listmode.h" /*** global variables ****************************************************************************/ diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 9b61f53fe..4e01d7354 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -113,9 +113,6 @@ WLabel *the_hint; /* The button bar */ WButtonBar *the_bar; -/* The dialog handle for the main program */ -Dlg_head *midnight_dlg = NULL; - /*** file scope macro definitions ****************************************************************/ #ifdef HAVE_CHARSET diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index 08b9ea579..c259d2ef9 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -48,6 +48,7 @@ #ifdef HAVE_CHARSET #include "lib/charsets.h" /* get_codepage_id () */ #endif +#include "lib/event.h" #include "src/setup.h" /* For loading/saving panel options */ #include "src/execute.h" @@ -3409,6 +3410,25 @@ do_try_to_select (WPanel * panel, const char *name) /* --------------------------------------------------------------------------------------------- */ +/* event callback */ +static gboolean +event_update_panels (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + (void) event_group_name; + (void) event_name; + (void) init_data; + (void) data; + + update_panels (UP_RELOAD, UP_KEEPSEL); + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ +/*** public functions ****************************************************************************/ +/* --------------------------------------------------------------------------------------------- */ + void try_to_select (WPanel * panel, const char *name) { @@ -4103,6 +4123,8 @@ panel_init (void) panel_history_next_item_sign = mc_skin_get ("widget-panel", "history-next-item-sign", ">"); panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^"); + mc_event_add (MCEVENT_GROUP_FILEMANAGER, "update_panels", event_update_panels, NULL, NULL); + } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/panelize.c b/src/filemanager/panelize.c index 8d6d441c4..9d2fb969e 100644 --- a/src/filemanager/panelize.c +++ b/src/filemanager/panelize.c @@ -47,7 +47,6 @@ #include "dir.h" #include "midnight.h" /* current_panel */ -#include "layout.h" /* repaint_screen() */ #include "panelize.h" diff --git a/src/learn.c b/src/learn.c index 2bf7ca581..417a170d8 100644 --- a/src/learn.c +++ b/src/learn.c @@ -44,7 +44,7 @@ #include "lib/util.h" /* convert_controls() */ #include "lib/widget.h" -#include "filemanager/layout.h" /* repaint_screen() */ +#include "src/filemanager/layout.h" /* mc_refresh() */ #include "setup.h" #include "learn.h" From 62207c8d4d40a8d8a419294a6911cbe1b65365e0 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 17 Feb 2011 11:24:53 +0200 Subject: [PATCH 15/25] Use events for operate with clipboard (copy/paste to external clipboard, save/load to file) Signed-off-by: Slava Zanko --- lib/event-types.h | 7 ++ lib/widget/input.c | 137 ++++------------------------------------ src/clipboard.c | 120 +++++++++++++++++++++++++++++++++-- src/clipboard.h | 11 +++- src/editor/editcmd.c | 8 +-- src/events_init.c | 7 ++ src/filemanager/panel.c | 49 ++++++++++++++ 7 files changed, 203 insertions(+), 136 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index f4e293d31..dc5af429f 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -34,6 +34,13 @@ typedef struct va_list ap; } ev_vfs_print_message_t; +/* MCEVENT_GROUP_CORE:clipboard_text_from_file */ +typedef struct +{ + char **text; + gboolean ret; +} ev_clipboard_text_from_file_t; + /*** global variables defined in .c file *********************************************************/ diff --git a/lib/widget/input.c b/lib/widget/input.c index 46eb66b9e..1e38dea4c 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -42,19 +42,18 @@ #include "lib/tty/tty.h" #include "lib/tty/mouse.h" #include "lib/tty/key.h" /* XCTRL and ALT macros */ -#include "lib/vfs/vfs.h" #include "lib/fileloc.h" #include "lib/skin.h" #include "lib/strutil.h" #include "lib/util.h" #include "lib/keybind.h" /* global_keymap_t */ #include "lib/widget.h" +#include "lib/event.h" /* mc_event_raise() */ #include "input_complete.h" #include "src/main.h" /* home_dir */ #include "src/filemanager/midnight.h" /* current_panel */ -#include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ /*** global variables ****************************************************************************/ @@ -85,124 +84,6 @@ const global_keymap_t *input_map; static char *kill_buffer = NULL; /*** file scope functions ************************************************************************/ - -static gboolean -save_text_to_clip_file (const char *text) -{ - int file; - char *fname = NULL; - ssize_t ret; - size_t str_len; - - fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); - file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY); - g_free (fname); - - if (file == -1) - return FALSE; - - str_len = strlen (text); - ret = mc_write (file, (char *) text, str_len); - mc_close (file); - return ret == (ssize_t) str_len; -} - -/* --------------------------------------------------------------------------------------------- */ - -static gboolean -load_text_from_clip_file (char **text) -{ - char buf[BUF_LARGE]; - FILE *f; - char *fname = NULL; - gboolean first = TRUE; - - fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); - f = fopen (fname, "r"); - g_free (fname); - - if (f == NULL) - return FALSE; - - *text = NULL; - - while (fgets (buf, sizeof (buf), f)) - { - size_t len; - - len = strlen (buf); - if (len > 0) - { - if (buf[len - 1] == '\n') - buf[len - 1] = '\0'; - - if (first) - { - first = FALSE; - *text = g_strdup (buf); - } - else - { - /* remove \n on EOL */ - char *tmp; - - tmp = g_strconcat (*text, " ", buf, (char *) NULL); - g_free (*text); - *text = tmp; - } - } - } - - fclose (f); - - return (*text != NULL); -} - -/* --------------------------------------------------------------------------------------------- */ - -static gboolean -panel_save_curent_file_to_clip_file (void) -{ - gboolean res = FALSE; - - if (current_panel->marked == 0) - res = save_text_to_clip_file (selection (current_panel)->fname); - else - { - int i; - gboolean first = TRUE; - char *flist = NULL; - - for (i = 0; i < current_panel->count; i++) - if (current_panel->dir.list[i].f.marked != 0) - { /* Skip the unmarked ones */ - if (first) - { - flist = g_strdup (current_panel->dir.list[i].fname); - first = FALSE; - } - else - { - /* Add empty lines after the file */ - char *tmp; - - tmp = - g_strconcat (flist, "\n", current_panel->dir.list[i].fname, (char *) NULL); - g_free (flist); - flist = tmp; - } - } - - if (flist != NULL) - { - res = save_text_to_clip_file (flist); - g_free (flist); - } - } - return res; -} - /* --------------------------------------------------------------------------------------------- */ static void @@ -571,9 +452,9 @@ copy_region (WInput * in, int x_first, int x_last) if (last == first) { /* Copy selected files to clipboard */ - panel_save_curent_file_to_clip_file (); + mc_event_raise (MCEVENT_GROUP_FILEMANAGER, "panel_save_curent_file_to_clip_file", NULL); /* try use external clipboard utility */ - copy_file_to_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", NULL); return; } @@ -584,9 +465,9 @@ copy_region (WInput * in, int x_first, int x_last) kill_buffer = g_strndup (in->buffer + first, last - first); - save_text_to_clip_file (kill_buffer); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", kill_buffer); /* try use external clipboard utility */ - copy_file_to_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", NULL); } /* --------------------------------------------------------------------------------------------- */ @@ -669,11 +550,15 @@ static void ins_from_clip (WInput * in) { char *p = NULL; + ev_clipboard_text_from_file_t event_data; /* try use external clipboard utility */ - paste_to_file_from_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL); - if (load_text_from_clip_file (&p)) + + event_data.text = &p; + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_from_file", &event_data); + if (event_data.ret) { char *pp; diff --git a/src/clipboard.c b/src/clipboard.c index ec4ba7472..3ed3254aa 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -33,6 +33,9 @@ #include "lib/fileloc.h" #include "lib/mcconfig.h" #include "lib/util.h" +#include "lib/event.h" + +#include "lib/vfs/vfs.h" #include "main.h" #include "src/execute.h" @@ -58,15 +61,22 @@ char *clipboard_paste_path = NULL; /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ +/* event callback */ gboolean -copy_file_to_ext_clip (void) +clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) { char *tmp, *cmd; int res = 0; const char *d = getenv ("DISPLAY"); + (void) event_group_name; + (void) event_name; + (void) init_data; + (void) data; + if (d == NULL || clipboard_store_path == NULL || clipboard_store_path[0] == '\0') - return FALSE; + return TRUE; tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL); @@ -81,15 +91,22 @@ copy_file_to_ext_clip (void) /* --------------------------------------------------------------------------------------------- */ +/* event callback */ gboolean -paste_to_file_from_ext_clip (void) +clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) { char *tmp, *cmd; int res = 0; const char *d = getenv ("DISPLAY"); + (void) event_group_name; + (void) event_name; + (void) init_data; + (void) data; + if (d == NULL || clipboard_paste_path == NULL || clipboard_paste_path[0] == '\0') - return FALSE; + return TRUE; tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL); @@ -103,3 +120,98 @@ paste_to_file_from_ext_clip (void) } /* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +gboolean +clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + int file; + char *fname = NULL; + ssize_t ret; + size_t str_len; + const char *text = (const char *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + if (text == NULL) + return FALSE; + + fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); + file = mc_open (fname, O_CREAT | O_WRONLY | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | O_BINARY); + g_free (fname); + + if (file == -1) + return TRUE; + + str_len = strlen (text); + ret = mc_write (file, (char *) text, str_len); + mc_close (file); + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +gboolean +clipboard_text_from_file (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + char buf[BUF_LARGE]; + FILE *f; + char *fname = NULL; + gboolean first = TRUE; + ev_clipboard_text_from_file_t *event_data = (ev_clipboard_text_from_file_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + fname = g_build_filename (mc_config_get_cache_path (), EDIT_CLIP_FILE, NULL); + f = fopen (fname, "r"); + g_free (fname); + + if (f == NULL) + { + event_data->ret = FALSE; + return TRUE; + } + + *(event_data->text) = NULL; + + while (fgets (buf, sizeof (buf), f)) + { + size_t len; + + len = strlen (buf); + if (len > 0) + { + if (buf[len - 1] == '\n') + buf[len - 1] = '\0'; + + if (first) + { + first = FALSE; + *(event_data->text) = g_strdup (buf); + } + else + { + /* remove \n on EOL */ + char *tmp; + + tmp = g_strconcat (*(event_data->text), " ", buf, (char *) NULL); + g_free (*(event_data->text)); + *(event_data->text) = tmp; + } + } + } + + fclose (f); + event_data->ret = (*(event_data->text) != NULL); + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/clipboard.h b/src/clipboard.h index bd2df5381..9b2fc2216 100644 --- a/src/clipboard.h +++ b/src/clipboard.h @@ -18,8 +18,15 @@ extern char *clipboard_paste_path; /*** declarations of public functions ************************************************************/ -gboolean copy_file_to_ext_clip (void); -gboolean paste_to_file_from_ext_clip (void); +gboolean clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); +gboolean clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); + +gboolean clipboard_text_to_file (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); +gboolean clipboard_text_from_file (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); /*** inline functions ****************************************************************************/ diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index c1355e9b9..2eb0154cd 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -56,13 +56,13 @@ #include "lib/vfs/vfs.h" #include "lib/widget.h" #include "lib/charsets.h" +#include "lib/event.h" /* mc_event_raise() */ #include "src/history.h" #include "src/setup.h" /* option_tab_spacing */ #include "src/help.h" /* interactive_display() */ #include "src/selcodepage.h" #include "src/keybind-defaults.h" -#include "src/clipboard.h" /* copy_file_to_ext_clip, paste_to_file_from_ext_clip */ #include "src/util.h" /* check_for_default() */ #include "src/filemanager/layout.h" /* mc_refresh() */ @@ -2602,7 +2602,7 @@ edit_copy_to_X_buf_cmd (WEdit * edit) return 1; } /* try use external clipboard utility */ - copy_file_to_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", NULL); return 0; } @@ -2621,7 +2621,7 @@ edit_cut_to_X_buf_cmd (WEdit * edit) return 1; } /* try use external clipboard utility */ - copy_file_to_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", NULL); edit_block_delete_cmd (edit); edit_mark_cmd (edit, 1); @@ -2635,7 +2635,7 @@ edit_paste_from_X_buf_cmd (WEdit * edit) { gchar *tmp; /* try use external clipboard utility */ - paste_to_file_from_ext_clip (); + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", NULL); tmp = concat_dir_and_file (mc_config_get_cache_path (), EDIT_CLIP_FILE); edit_insert_file (edit, tmp); g_free (tmp); diff --git a/src/events_init.c b/src/events_init.c index cfc4f7459..956870fbd 100644 --- a/src/events_init.c +++ b/src/events_init.c @@ -27,6 +27,8 @@ #include "lib/event.h" +#include "clipboard.h" /* clipboard events */ + #include "events_init.h" /*** global variables ****************************************************************************/ @@ -51,6 +53,11 @@ events_init (GError ** error) /* *INDENT-OFF* */ event_init_t standard_events[] = { + {MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", clipboard_file_to_ext_clip, NULL}, + {MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", clipboard_file_from_ext_clip, NULL}, + {MCEVENT_GROUP_CORE, "clipboard_text_to_file", clipboard_text_to_file, NULL}, + {MCEVENT_GROUP_CORE, "clipboard_text_from_file", clipboard_text_from_file, NULL}, + {NULL, NULL, NULL, NULL} }; /* *INDENT-ON* */ diff --git a/src/filemanager/panel.c b/src/filemanager/panel.c index c259d2ef9..3093fb156 100644 --- a/src/filemanager/panel.c +++ b/src/filemanager/panel.c @@ -3425,6 +3425,53 @@ event_update_panels (const gchar * event_group_name, const gchar * event_name, return TRUE; } +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +static gboolean +panel_save_curent_file_to_clip_file (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + (void) event_group_name; + (void) event_name; + (void) init_data; + (void) data; + + if (current_panel->marked == 0) + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", + (gpointer) selection (current_panel)->fname); + else + { + int i; + gboolean first = TRUE; + char *flist = NULL; + + for (i = 0; i < current_panel->count; i++) + if (current_panel->dir.list[i].f.marked != 0) + { /* Skip the unmarked ones */ + if (first) + { + flist = g_strdup (current_panel->dir.list[i].fname); + first = FALSE; + } + else + { + /* Add empty lines after the file */ + char *tmp; + + tmp = + g_strconcat (flist, "\n", current_panel->dir.list[i].fname, (char *) NULL); + g_free (flist); + flist = tmp; + } + } + + mc_event_raise (MCEVENT_GROUP_CORE, "clipboard_text_to_file", (gpointer) flist); + g_free (flist); + } + return TRUE; +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -4124,6 +4171,8 @@ panel_init (void) panel_history_show_list_sign = mc_skin_get ("widget-panel", "history-show-list-sign", "^"); mc_event_add (MCEVENT_GROUP_FILEMANAGER, "update_panels", event_update_panels, NULL, NULL); + mc_event_add (MCEVENT_GROUP_FILEMANAGER, "panel_save_curent_file_to_clip_file", + panel_save_curent_file_to_clip_file, NULL, NULL); } From 5f8a5e4290d4f90dcff763cb7823a57c80265674 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 17 Feb 2011 14:02:31 +0200 Subject: [PATCH 16/25] Use events for calling help window Signed-off-by: Slava Zanko --- lib/event-types.h | 7 +++++++ lib/widget/dialog.c | 8 ++++++-- lib/widget/menu.c | 21 +++++++++++++-------- src/diffviewer/ydiff.c | 11 ++++++++--- src/editor/editcmd.c | 5 +++-- src/events_init.c | 3 +++ src/filemanager/cmd.c | 10 +++++++--- src/filemanager/tree.c | 8 ++++++-- src/help.c | 33 +++++++++++++++++++++------------ src/help.h | 3 ++- src/viewer/actions_cmd.c | 8 ++++++-- 11 files changed, 82 insertions(+), 35 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index dc5af429f..51b590e13 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -41,6 +41,13 @@ typedef struct gboolean ret; } ev_clipboard_text_from_file_t; +/* MCEVENT_GROUP_CORE:help */ +typedef struct +{ + const char *filename; + const char *node; +} ev_help_t; + /*** global variables defined in .c file *********************************************************/ diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index bf0a75224..1ccee95dc 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -37,6 +37,7 @@ #include "lib/tty/key.h" #include "lib/strutil.h" #include "lib/widget.h" +#include "lib/event.h" /* mc_event_raise() */ /* TODO: these includes should be removed! */ #include "src/help.h" /* interactive_display() */ @@ -266,8 +267,11 @@ dlg_execute_cmd (Dlg_head * h, unsigned long command) break; case CK_Help: - interactive_display (NULL, h->help_ctx); - do_refresh (); + { + ev_help_t event_data = { NULL, h->help_ctx }; + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + do_refresh (); + } break; case CK_Suspend: diff --git a/lib/widget/menu.c b/lib/widget/menu.c index ad513cf72..11f7f986b 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -34,6 +34,7 @@ #include "lib/tty/key.h" /* key macros */ #include "lib/strutil.h" #include "lib/widget.h" +#include "lib/event.h" /* mc_event_raise() */ /* TODO: these includes should be removed! */ #include "src/keybind-defaults.h" /* CK_IgnoreKey */ @@ -422,15 +423,19 @@ menubar_handle_key (WMenuBar * menubar, int key) switch (key) { case KEY_F (1): - if (menubar->is_dropped) - interactive_display (NULL, - ((Menu *) g_list_nth_data (menubar->menu, - menubar->selected))->help_node); - else - interactive_display (NULL, "[Menu Bar]"); - menubar_draw (menubar); - return 1; + { + ev_help_t event_data = { NULL, NULL }; + if (menubar->is_dropped) + event_data.node = + ((Menu *) g_list_nth_data (menubar->menu, menubar->selected))->help_node; + else + event_data.node = "[Menu Bar]"; + + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + menubar_draw (menubar); + return 1; + } case KEY_LEFT: case XCTRL ('b'): menubar_left (menubar); diff --git a/src/diffviewer/ydiff.c b/src/diffviewer/ydiff.c index 8fce0872a..18cb96eae 100644 --- a/src/diffviewer/ydiff.c +++ b/src/diffviewer/ydiff.c @@ -42,13 +42,13 @@ #include "lib/util.h" #include "lib/widget.h" #include "lib/charsets.h" +#include "lib/event.h" /* mc_event_raise() */ #include "src/filemanager/cmd.h" #include "src/filemanager/midnight.h" /* Needed for current_panel and other_panel */ #include "src/filemanager/layout.h" /* Needed for get_current_index and get_other_panel */ #include "src/keybind-defaults.h" -#include "src/help.h" #include "src/history.h" #include "src/selcodepage.h" @@ -118,7 +118,9 @@ dview_set_codeset (WDiff * dview) const char *encoding_id = NULL; dview->utf8 = TRUE; - encoding_id = get_codepage_id (mc_global.source_codepage >= 0 ? mc_global.source_codepage : mc_global.display_codepage); + encoding_id = + get_codepage_id (mc_global.source_codepage >= + 0 ? mc_global.source_codepage : mc_global.display_codepage); if (encoding_id != NULL) { GIConv conv; @@ -2980,7 +2982,10 @@ dview_execute_cmd (WDiff * dview, unsigned long command) switch (command) { case CK_Help: - interactive_display (NULL, "[Diff Viewer]"); + { + ev_help_t event_data = { NULL, "[Diff Viewer]" }; + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + } break; case CK_ShowSymbols: dview->display_symbols ^= 1; diff --git a/src/editor/editcmd.c b/src/editor/editcmd.c index 2eb0154cd..fc027e112 100644 --- a/src/editor/editcmd.c +++ b/src/editor/editcmd.c @@ -60,7 +60,6 @@ #include "src/history.h" #include "src/setup.h" /* option_tab_spacing */ -#include "src/help.h" /* interactive_display() */ #include "src/selcodepage.h" #include "src/keybind-defaults.h" #include "src/util.h" /* check_for_default() */ @@ -1146,7 +1145,9 @@ edit_collect_completions (WEdit * edit, long start, gsize word_len, void edit_help_cmd (WEdit * edit) { - interactive_display (NULL, "[Internal File Editor]"); + ev_help_t event_data = { NULL, "[Internal File Editor]" }; + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + edit->force |= REDRAW_COMPLETELY; } diff --git a/src/events_init.c b/src/events_init.c index 956870fbd..7724640a3 100644 --- a/src/events_init.c +++ b/src/events_init.c @@ -28,6 +28,7 @@ #include "lib/event.h" #include "clipboard.h" /* clipboard events */ +#include "help.h" /* help_interactive_display() */ #include "events_init.h" @@ -58,6 +59,8 @@ events_init (GError ** error) {MCEVENT_GROUP_CORE, "clipboard_text_to_file", clipboard_text_to_file, NULL}, {MCEVENT_GROUP_CORE, "clipboard_text_from_file", clipboard_text_from_file, NULL}, + {MCEVENT_GROUP_CORE, "help", help_interactive_display, NULL}, + {NULL, NULL, NULL, NULL} }; /* *INDENT-ON* */ diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 27df89ac6..8d1f76026 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -59,9 +59,9 @@ #include "lib/util.h" #include "lib/widget.h" #include "lib/keybind.h" /* CK_Down, CK_History */ +#include "lib/event.h" /* mc_event_raise() */ #include "src/viewer/mcviewer.h" -#include "src/help.h" /* interactive_display() */ #include "src/setup.h" #include "src/execute.h" /* toggle_panels() */ #include "src/history.h" @@ -1322,10 +1322,14 @@ edit_symlink_cmd (void) void help_cmd (void) { + ev_help_t event_data = { NULL, NULL }; + if (current_panel->searching) - interactive_display (NULL, "[Quick search]"); + event_data.node = "[Quick search]"; else - interactive_display (NULL, "[main]"); + event_data.node = "[main]"; + + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/filemanager/tree.c b/src/filemanager/tree.c index c639611ec..8d993c4d8 100644 --- a/src/filemanager/tree.c +++ b/src/filemanager/tree.c @@ -50,11 +50,12 @@ #include "lib/strutil.h" #include "lib/util.h" #include "lib/widget.h" +#include "lib/event.h" /* mc_event_raise() */ + #include "src/setup.h" /* confirm_delete, panels_options */ #include "src/keybind-defaults.h" #include "src/history.h" -#include "src/help.h" #include "dir.h" #include "midnight.h" /* the_menubar */ @@ -1022,7 +1023,10 @@ tree_execute_cmd (WTree * tree, unsigned long command) switch (command) { case CK_Help: - interactive_display (NULL, "[Directory Tree]"); + { + ev_help_t event_data = { NULL, "[Directory Tree]" }; + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + } break; case CK_Forget: tree_forget (tree); diff --git a/src/help.c b/src/help.c index 437bf9ef5..9c007ba86 100644 --- a/src/help.c +++ b/src/help.c @@ -60,6 +60,7 @@ #include "lib/fileloc.h" #include "lib/util.h" #include "lib/widget.h" +#include "lib/event-types.h" #include "keybind-defaults.h" #include "keybind-defaults.h" @@ -1028,8 +1029,10 @@ mousedispatch_new (int y, int x, int yl, int xl) /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ -void -interactive_display (const char *filename, const char *node) +/* event callback */ +gboolean +help_interactive_display (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) { const dlg_colors_t help_colors = { HELP_NORMAL_COLOR, /* common text color */ @@ -1043,43 +1046,48 @@ interactive_display (const char *filename, const char *node) Widget *md; char *hlpfile = NULL; char *filedata; + ev_help_t *event_data = (ev_help_t *) data; - if (filename != NULL) - g_file_get_contents (filename, &filedata, NULL, NULL); + (void) event_group_name; + (void) event_name; + (void) init_data; + + if (event_data->filename != NULL) + g_file_get_contents (event_data->filename, &filedata, NULL, NULL); else filedata = load_mc_home_file (mc_global.share_data_dir, MC_HELP, &hlpfile); if (filedata == NULL) message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), - filename ? filename : hlpfile, unix_error_string (errno)); + event_data->filename ? event_data->filename : hlpfile, unix_error_string (errno)); g_free (hlpfile); if (filedata == NULL) - return; + return TRUE; translate_file (filedata); g_free (filedata); if (fdata == NULL) - return; + return TRUE; - if ((node == NULL) || (*node == '\0')) - node = "[main]"; + if ((event_data->node == NULL) || (*event_data->node == '\0')) + event_data->node = "[main]"; - main_node = search_string (fdata, node); + main_node = search_string (fdata, event_data->node); if (main_node == NULL) { - message (D_ERROR, MSG_ERROR, _("Cannot find node %s in help file"), node); + message (D_ERROR, MSG_ERROR, _("Cannot find node %s in help file"), event_data->node); /* Fallback to [main], return if it also cannot be found */ main_node = search_string (fdata, "[main]"); if (main_node == NULL) { interactive_display_finish (); - return; + return TRUE; } } @@ -1123,6 +1131,7 @@ interactive_display (const char *filename, const char *node) run_dlg (whelp); interactive_display_finish (); destroy_dlg (whelp); + return TRUE; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/help.h b/src/help.h index 8374442ba..3db546926 100644 --- a/src/help.h +++ b/src/help.h @@ -50,7 +50,8 @@ /*** declarations of public functions ************************************************************/ -void interactive_display (const char *filename, const char *node); +gboolean help_interactive_display (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); /*** inline functions ****************************************************************************/ #endif /* MC__HELP_H */ diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 3de327a35..b4c5fbccd 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -57,6 +57,7 @@ #include "lib/util.h" #include "lib/widget.h" #include "lib/charsets.h" +#include "lib/event.h" /* mc_event_raise() */ #include "src/filemanager/layout.h" #include "src/filemanager/cmd.h" @@ -64,7 +65,6 @@ #include "src/history.h" #include "src/execute.h" -#include "src/help.h" #include "src/keybind-defaults.h" #include "internal.h" @@ -249,7 +249,11 @@ mcview_execute_cmd (mcview_t * view, unsigned long command) switch (command) { case CK_Help: - interactive_display (NULL, "[Internal File Viewer]"); + { + ev_help_t event_data = { NULL, "[Internal File Viewer]" }; + mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data); + do_refresh (); + } break; case CK_WrapMode: /* Toggle between wrapped and unwrapped view */ From aad40e52fb150942e1e8e41123241ff40b0986f4 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 18 Feb 2011 13:30:15 +0200 Subject: [PATCH 17/25] Moved mc_refresh() to lib/widget Signed-off-by: Slava Zanko --- lib/tty/key.c | 2 +- lib/tty/tty.c | 57 ++++++++++++++++++++- lib/tty/tty.h | 3 ++ lib/widget/dialog-switch.c | 51 +++++++++++++++++++ lib/widget/dialog-switch.h | 1 + lib/widget/dialog.c | 2 +- lib/widget/wtools.c | 19 +++++++ lib/widget/wtools.h | 3 ++ src/filemanager/layout.c | 101 +------------------------------------ src/filemanager/layout.h | 4 -- src/subshell.c | 34 +------------ src/subshell.h | 1 - 12 files changed, 137 insertions(+), 141 deletions(-) diff --git a/lib/tty/key.c b/lib/tty/key.c index fd993d1f5..44d9a55ec 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -48,7 +48,7 @@ #include "key.h" #include "win.h" /* xterm_flag */ -#include "src/filemanager/layout.h" /* mc_refresh() */ +#include "lib/widget.h" /* mc_refresh() */ #ifdef HAVE_TEXTMODE_X11_SUPPORT #include "x11conn.h" diff --git a/lib/tty/tty.c b/lib/tty/tty.c index dc7ca6c7b..4c1d12f30 100644 --- a/lib/tty/tty.c +++ b/lib/tty/tty.c @@ -34,12 +34,16 @@ #include #include +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + #include "lib/global.h" #include "lib/strutil.h" #include "tty.h" #include "tty-internal.h" - +#include "win.h" /*** global variables ****************************************************************************/ @@ -204,3 +208,54 @@ mc_tty_normalize_from_utf8 (const char *str) } /* --------------------------------------------------------------------------------------------- */ + +/** Resize given terminal using TIOCSWINSZ, return ioctl() result */ +int +tty_resize (int fd) +{ +#if defined TIOCSWINSZ + struct winsize tty_size; + + tty_size.ws_row = LINES; + tty_size.ws_col = COLS; + tty_size.ws_xpixel = tty_size.ws_ypixel = 0; + + return ioctl (fd, TIOCSWINSZ, &tty_size); +#else + return 0; +#endif +} + +/* --------------------------------------------------------------------------------------------- */ + +void +tty_low_level_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 */ +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/tty.h b/lib/tty/tty.h index 76090d306..ea2f96885 100644 --- a/lib/tty/tty.h +++ b/lib/tty/tty.h @@ -130,8 +130,11 @@ extern void tty_draw_vline (int y, int x, int ch, int len); extern void tty_draw_box (int y, int x, int rows, int cols, gboolean single); extern void tty_fill_region (int y, int x, int rows, int cols, unsigned char ch); +extern int tty_resize (int fd); extern void tty_refresh (void); extern void tty_setup_sigwinch (void (*handler) (int)); +extern void tty_low_level_change_screen_size (void); + extern int mc_tty_normalize_lines_char (const char *); diff --git a/lib/widget/dialog-switch.c b/lib/widget/dialog-switch.c index 7f4b4269a..6876c848e 100644 --- a/lib/widget/dialog-switch.c +++ b/lib/widget/dialog-switch.c @@ -28,6 +28,7 @@ #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" @@ -91,6 +92,17 @@ dialog_switch_goto (GList * dlg) } } +/* --------------------------------------------------------------------------------------------- */ + +static void +dlg_resize_cb (void *data, void *user_data) +{ + Dlg_head *d = data; + + (void) user_data; + d->callback (d, NULL, DLG_RESIZE, 0, NULL); +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -298,3 +310,42 @@ repaint_screen (void) } /* --------------------------------------------------------------------------------------------- */ + +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_low_level_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); +#endif + + /* Inform all suspending dialogs */ + dialog_switch_got_winch (); + /* Inform all running dialogs */ + g_list_foreach (top_dlg, (GFunc) dlg_resize_cb, NULL); + + /* Now, force the redraw */ + repaint_screen (); + +#endif /* TIOCGWINSZ */ +#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/dialog-switch.h b/lib/widget/dialog-switch.h index 5ab5c9edb..5f1fb7027 100644 --- a/lib/widget/dialog-switch.h +++ b/lib/widget/dialog-switch.h @@ -31,6 +31,7 @@ void dialog_switch_shutdown (void); /* Clear screen */ void clr_scr (void); void repaint_screen (void); +void dialog_change_screen_size (void); /*** inline functions ****************************************************************************/ diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 1ccee95dc..b18001f48 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -512,7 +512,7 @@ frontend_run_dlg (Dlg_head * h) while (h->state == DLG_ACTIVE) { if (mc_global.tty.winch_flag) - change_screen_size (); + dialog_change_screen_size (); if (is_idle ()) { diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index 10a0b7a82..9fb30f692 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -459,3 +459,22 @@ input_expand_dialog (const char *header, const char *text, } /* --------------------------------------------------------------------------------------------- */ + +void +mc_refresh (void) +{ +#ifdef WITH_BACKGROUND + if (mc_global.we_are_background) + return; +#endif /* WITH_BACKGROUND */ + if (mc_global.tty.winch_flag == FALSE) + tty_refresh (); + else + { + /* if winch was caugth, we should do not only redraw screen, but + reposition/resize all */ + dialog_change_screen_size (); + } +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/wtools.h b/lib/widget/wtools.h index 16e4755cc..1cb055e8f 100644 --- a/lib/widget/wtools.h +++ b/lib/widget/wtools.h @@ -47,6 +47,9 @@ struct Dlg_head *create_message (int flags, const char *title, void message (int flags, const char *title, const char *text, ...) __attribute__ ((format (__printf__, 3, 4))); +/* Clear screen */ +void mc_refresh (void); + /*** inline functions ****************************************************************************/ #endif /* MC__WTOOLS_H */ diff --git a/src/filemanager/layout.c b/src/filemanager/layout.c index 3a597bb9b..c1ae4c79a 100644 --- a/src/filemanager/layout.c +++ b/src/filemanager/layout.c @@ -58,7 +58,6 @@ #include "src/consaver/cons.saver.h" #include "src/viewer/mcviewer.h" /* The view widget */ #include "src/setup.h" -#include "src/subshell.h" /* For resize_subshell() */ #include "src/background.h" #include "command.h" @@ -597,46 +596,6 @@ restore_into_right_dir_panel (int idx, Widget * from_widget) return new_widget; } -/* --------------------------------------------------------------------------------------------- */ - -static inline void -low_level_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 - resize_subshell (); -#endif - } -#endif /* TIOCGWINSZ */ -#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ -} - -/* --------------------------------------------------------------------------------------------- */ - -static void -dlg_resize_cb (void *data, void *user_data) -{ - Dlg_head *d = data; - - (void) user_data; - d->callback (d, NULL, DLG_RESIZE, 0, NULL); -} - /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -688,25 +647,6 @@ layout_box (void) /* --------------------------------------------------------------------------------------------- */ -void -mc_refresh (void) -{ -#ifdef WITH_BACKGROUND - if (mc_global.we_are_background) - return; -#endif /* WITH_BACKGROUND */ - if (mc_global.tty.winch_flag == FALSE) - tty_refresh (); - else - { - /* if winch was caugth, we should do not only redraw screen, but - reposition/resize all */ - change_screen_size (); - } -} - -/* --------------------------------------------------------------------------------------------- */ - void setup_panels (void) { @@ -801,50 +741,11 @@ sigwinch_handler (int dummy) { (void) dummy; #if !(defined(USE_NCURSES) || defined(USE_NCURSESW)) /* don't do malloc in a signal handler */ - low_level_change_screen_size (); + tty_low_level_change_screen_size (); #endif mc_global.tty.winch_flag = TRUE; } -/* --------------------------------------------------------------------------------------------- */ - -void -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 - low_level_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); -#endif - - /* Inform all suspending dialogs */ - dialog_switch_got_winch (); - /* Inform all running dialogs */ - g_list_foreach (top_dlg, (GFunc) dlg_resize_cb, NULL); - - /* Now, force the redraw */ - repaint_screen (); -#endif /* TIOCGWINSZ */ -#endif /* defined(HAVE_SLANG) || NCURSES_VERSION_MAJOR >= 4 */ -} - - /* --------------------------------------------------------------------------------------------- */ void diff --git a/src/filemanager/layout.h b/src/filemanager/layout.h index 1d84e68d9..89a1f698e 100644 --- a/src/filemanager/layout.h +++ b/src/filemanager/layout.h @@ -37,7 +37,6 @@ void layout_box (void); void setup_panels (void); void destroy_panels (void); void sigwinch_handler (int dummy); -void change_screen_size (void); void set_display_type (int num, panel_view_mode_t type); void panel_update_cols (Widget * widget, panel_display_t frame_size); void swap_panels (void); @@ -61,9 +60,6 @@ void set_hintbar (const char *str); void use_dash (gboolean flag); /* Disable/Enable rotate_dash routines */ void rotate_dash (void); -/* Clear screen */ -void mc_refresh (void); - /*** inline functions ****************************************************************************/ #endif /* MC__LAYOUT_H */ diff --git a/src/subshell.c b/src/subshell.c index 23b1fe072..b524b7243 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -180,7 +180,6 @@ static gboolean feed_subshell (int how, int fail_on_error); static void synchronize (void); static int pty_open_master (char *pty_name); static int pty_open_slave (const char *pty_name); -static int resize_tty (int fd); /* --------------------------------------------------------------------------------------------- */ /** @@ -250,7 +249,7 @@ init_subshell_child (const char *pty_name) /* Set the pty's size (80x25 by default on Linux) according to the */ /* size of the real terminal as calculated by ncurses, if possible */ - resize_tty (subshell_pty_slave); + tty_resize (subshell_pty_slave); /* Set up the subshell's environment and init file name */ @@ -1046,37 +1045,6 @@ do_update_prompt (void) /* --------------------------------------------------------------------------------------------- */ -/** Resize given terminal using TIOCSWINSZ, return ioctl() result */ -static int -resize_tty (int fd) -{ -#if defined TIOCSWINSZ - struct winsize tty_size; - - tty_size.ws_row = LINES; - tty_size.ws_col = COLS; - tty_size.ws_xpixel = tty_size.ws_ypixel = 0; - - return ioctl (fd, TIOCSWINSZ, &tty_size); -#else - return 0; -#endif -} - -/* --------------------------------------------------------------------------------------------- */ -/** Resize mc_global.tty.subshell_pty */ - -void -resize_subshell (void) -{ - if (!mc_global.tty.use_subshell) - return; - - resize_tty (mc_global.tty.subshell_pty); -} - -/* --------------------------------------------------------------------------------------------- */ - int exit_subshell (void) { diff --git a/src/subshell.h b/src/subshell.h index f2e2504e9..e8afe0b65 100644 --- a/src/subshell.h +++ b/src/subshell.h @@ -48,7 +48,6 @@ void init_subshell (void); int invoke_subshell (const char *command, int how, char **new_dir); int read_subshell_prompt (void); void do_update_prompt (void); -void resize_subshell (void); int exit_subshell (void); void do_subshell_chdir (const char *directory, gboolean update_prompt, gboolean reset_prompt); void subshell_get_console_attributes (void); From a01b8edd7aac448c3916ed9b5374be589d5fc493 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 18 Feb 2011 14:13:44 +0200 Subject: [PATCH 18/25] Use events for suspend mc (by pressing on CTRL+Z) Signed-off-by: Slava Zanko --- lib/widget/dialog.c | 3 +-- src/events_init.c | 2 ++ src/execute.c | 13 +++++++++++-- src/execute.h | 3 ++- src/filemanager/midnight.c | 9 +++------ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index b18001f48..2d280dba7 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -42,7 +42,6 @@ /* TODO: these includes should be removed! */ #include "src/help.h" /* interactive_display() */ #include "src/filemanager/layout.h" -#include "src/execute.h" /* suspend_cmd() */ /*** global variables ****************************************************************************/ @@ -275,7 +274,7 @@ dlg_execute_cmd (Dlg_head * h, unsigned long command) break; case CK_Suspend: - suspend_cmd (); + mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL); refresh_cmd (); break; case CK_Refresh: diff --git a/src/events_init.c b/src/events_init.c index 7724640a3..6b767cca8 100644 --- a/src/events_init.c +++ b/src/events_init.c @@ -29,6 +29,7 @@ #include "clipboard.h" /* clipboard events */ #include "help.h" /* help_interactive_display() */ +#include "execute.h" /* execute_suspend() */ #include "events_init.h" @@ -60,6 +61,7 @@ events_init (GError ** error) {MCEVENT_GROUP_CORE, "clipboard_text_from_file", clipboard_text_from_file, NULL}, {MCEVENT_GROUP_CORE, "help", help_interactive_display, NULL}, + {MCEVENT_GROUP_CORE, "suspend", execute_suspend, NULL}, {NULL, NULL, NULL, NULL} }; diff --git a/src/execute.c b/src/execute.c index bbda6de39..5a11e5f8e 100644 --- a/src/execute.c +++ b/src/execute.c @@ -399,15 +399,24 @@ toggle_panels (void) /* --------------------------------------------------------------------------------------------- */ -void -suspend_cmd (void) +/* event callback */ +gboolean +execute_suspend (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) { + (void) event_group_name; + (void) event_name; + (void) init_data; + (void) data; + if (mc_global.mc_run_mode == MC_RUN_FULL) save_cwds_stat (); do_suspend_cmd (); if (mc_global.mc_run_mode == MC_RUN_FULL) update_panels (UP_OPTIMIZE, UP_KEEPSEL); do_refresh (); + + return TRUE; } /* --------------------------------------------------------------------------------------------- */ diff --git a/src/execute.h b/src/execute.h index 7730b7b91..a626c4403 100644 --- a/src/execute.h +++ b/src/execute.h @@ -40,7 +40,8 @@ void exec_shell (void); void toggle_panels (void); /* Handle toggling panels by Ctrl-Z */ -void suspend_cmd (void); +gboolean execute_suspend (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); /* Execute command on a filename that can be on VFS */ void execute_with_vfs_arg (const char *command, const char *filename); diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index 4e01d7354..bba1107a4 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -55,7 +55,6 @@ #include "src/subshell.h" #include "src/setup.h" /* variables */ #include "src/learn.h" /* learn_keys() */ -#include "src/execute.h" /* suspend_cmd() */ #include "src/keybind-defaults.h" #include "lib/keybind.h" #include "lib/event.h" @@ -645,10 +644,8 @@ create_panels (void) current_panel = left_panel; #if ENABLE_VFS - mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, - NULL); - mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, - NULL); + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_other_panel_timestamp, NULL, NULL); + mc_event_add (MCEVENT_GROUP_CORE, "vfs_timestamp", check_current_panel_timestamp, NULL, NULL); #endif /* ENABLE_VFS */ mc_event_add (MCEVENT_GROUP_CORE, "vfs_print_message", print_vfs_message, NULL, NULL); @@ -1356,7 +1353,7 @@ midnight_execute_cmd (Widget * sender, unsigned long command) ctl_x_cmd (); break; case CK_Suspend: - suspend_cmd (); + mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL); break; case CK_Swap: swap_cmd (); From 66212502928f3630f6cf01e0b86bc4fee6637444 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 18 Feb 2011 14:50:30 +0200 Subject: [PATCH 19/25] Added events for handle parent_call_string() and parent_call() Signed-off-by: Slava Zanko --- lib/event-types.h | 15 +++++ lib/widget/wtools.c | 59 +++++++++++++---- src/background.c | 155 +++++++++++++++++++++++++++++++------------- src/background.h | 7 ++ src/events_init.c | 10 ++- 5 files changed, 185 insertions(+), 61 deletions(-) diff --git a/lib/event-types.h b/lib/event-types.h index 51b590e13..c4c0b6911 100644 --- a/lib/event-types.h +++ b/lib/event-types.h @@ -48,6 +48,21 @@ typedef struct const char *node; } ev_help_t; +/* MCEVENT_GROUP_CORE:background_parent_call */ +/* MCEVENT_GROUP_CORE:background_parent_call_string */ +typedef struct +{ + void *routine; + gpointer *ctx; + int argc; + va_list ap; + union + { + int i; + char *s; + } ret; +} ev_background_parent_call_t; + /*** global variables defined in .c file *********************************************************/ diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index 9fb30f692..150c63642 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -39,9 +39,7 @@ #include "lib/strutil.h" #include "lib/util.h" /* tilde_expand() */ #include "lib/widget.h" - -/* TODO: these includes should be removed! */ -#include "src/background.h" /* parent_call */ +#include "lib/event.h" /* mc_event_raise() */ /*** global variables ****************************************************************************/ @@ -237,6 +235,37 @@ fg_input_dialog_help (const char *header, const char *text, const char *help, return (ret != B_CANCEL) ? my_str : NULL; } +/* --------------------------------------------------------------------------------------------- */ + +static int +wtools_parent_call (void *routine, gpointer ctx, int argc, ...) +{ + ev_background_parent_call_t event_data; + + event_data.routine = routine; + event_data.ctx = ctx; + event_data.argc = argc; + va_start (event_data.ap, argc); + mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call", (gpointer) & event_data); + va_end (event_data.ap); + return event_data.ret.i; +} + +/* --------------------------------------------------------------------------------------------- */ + +static char * +wtools_parent_call_string (void *routine, int argc, ...) +{ + ev_background_parent_call_t event_data; + + event_data.routine = routine; + event_data.argc = argc; + va_start (event_data.ap, argc); + mc_event_raise (MCEVENT_GROUP_CORE, "background_parent_call_string", (gpointer) & event_data); + va_end (event_data.ap); + return event_data.ret.s; +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -372,11 +401,6 @@ message (int flags, const char *title, const char *text, ...) { char *p; va_list ap; - union - { - void *p; - void (*f) (int, int *, char *, const char *); - } func; va_start (ap, text); p = g_strdup_vprintf (text, ap); @@ -388,8 +412,15 @@ message (int flags, const char *title, const char *text, ...) #ifdef WITH_BACKGROUND if (mc_global.we_are_background) { + union + { + void *p; + void (*f) (int, int *, char *, const char *); + } func; func.f = bg_message; - parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, strlen (p), p); + + wtools_parent_call (func.p, NULL, 3, sizeof (flags), &flags, strlen (title), title, + strlen (p), p); } else #endif /* WITH_BACKGROUND */ @@ -419,11 +450,11 @@ input_dialog_help (const char *header, const char *text, const char *help, if (mc_global.we_are_background) { func.f = fg_input_dialog_help; - return parent_call_string (func.p, 5, - strlen (header), header, strlen (text), - text, strlen (help), help, - strlen (history_name), history_name, - strlen (def_text), def_text); + return wtools_parent_call_string (func.p, 5, + strlen (header), header, strlen (text), + text, strlen (help), help, + strlen (history_name), history_name, + strlen (def_text), def_text); } else #endif /* WITH_BACKGROUND */ diff --git a/src/background.c b/src/background.c index 1e878f95a..8b39a4546 100644 --- a/src/background.c +++ b/src/background.c @@ -46,6 +46,7 @@ #include "lib/global.h" #include "lib/tty/key.h" /* add_select_channel(), delete_select_channel() */ #include "lib/widget.h" /* message() */ +#include "lib/event-types.h" #include "filemanager/fileopctx.h" /* FileOpContext */ @@ -407,6 +408,71 @@ parent_call_header (void *routine, int argc, enum ReturnType type, FileOpContext ret = write (parent_fd, ctx, sizeof (FileOpContext)); } +/* --------------------------------------------------------------------------------------------- */ + +static int +parent_va_call (void *routine, gpointer data, int argc, va_list ap) +{ + int i; + ssize_t ret; + struct FileOpContext *ctx = (struct FileOpContext *) data; + + parent_call_header (routine, argc, Return_Integer, ctx); + for (i = 0; i < argc; i++) + { + int len; + void *value; + + len = va_arg (ap, int); + value = va_arg (ap, void *); + ret = write (parent_fd, &len, sizeof (int)); + ret = write (parent_fd, value, len); + } + + ret = read (from_parent_fd, &i, sizeof (int)); + if (ctx) + ret = read (from_parent_fd, ctx, sizeof (FileOpContext)); + + return i; +} + +/* --------------------------------------------------------------------------------------------- */ + +static char * +parent_va_call_string (void *routine, int argc, va_list ap) +{ + char *str; + int i; + + parent_call_header (routine, argc, Return_String, NULL); + for (i = 0; i < argc; i++) + { + int len; + void *value; + + len = va_arg (ap, int); + value = va_arg (ap, void *); + if ((write (parent_fd, &len, sizeof (int)) != sizeof (int)) || + (write (parent_fd, value, len) != len)) + { + return NULL; + } + } + + if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int)) + return NULL; + if (!i) + return NULL; + str = g_malloc (i + 1); + if (read (from_parent_fd, str, i) != i) + { + g_free (str); + return NULL; + } + str[i] = 0; + return str; +} + /* --------------------------------------------------------------------------------------------- */ /*** public functions ****************************************************************************/ /* --------------------------------------------------------------------------------------------- */ @@ -505,29 +571,14 @@ do_background (struct FileOpContext *ctx, char *info) int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...) { + int ret; va_list ap; - int i; - ssize_t ret; va_start (ap, argc); - parent_call_header (routine, argc, Return_Integer, ctx); - for (i = 0; i < argc; i++) - { - int len; - void *value; - - len = va_arg (ap, int); - value = va_arg (ap, void *); - ret = write (parent_fd, &len, sizeof (int)); - ret = write (parent_fd, value, len); - } - - ret = read (from_parent_fd, &i, sizeof (int)); - if (ctx) - ret = read (from_parent_fd, ctx, sizeof (FileOpContext)); - + ret = parent_va_call (routine, (gpointer) ctx, argc, ap); va_end (ap); - return i; + + return ret; } /* --------------------------------------------------------------------------------------------- */ @@ -537,40 +588,52 @@ parent_call_string (void *routine, int argc, ...) { va_list ap; char *str; - int i; va_start (ap, argc); - parent_call_header (routine, argc, Return_String, NULL); - for (i = 0; i < argc; i++) - { - int len; - void *value; - - len = va_arg (ap, int); - value = va_arg (ap, void *); - if ((write (parent_fd, &len, sizeof (int)) != sizeof (int)) || - (write (parent_fd, value, len) != len)) - { - va_end (ap); - return NULL; - } - } + str = parent_va_call_string (routine, argc, ap); va_end (ap); - if (read (from_parent_fd, &i, sizeof (int)) != sizeof (int)) - return NULL; - if (!i) - return NULL; - str = g_malloc (i + 1); - if (read (from_parent_fd, str, i) != i) - { - g_free (str); - return NULL; - } - str[i] = 0; return str; } /* --------------------------------------------------------------------------------------------- */ +/* event callback */ +gboolean +background_parent_call (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_background_parent_call_t *event_data = (ev_background_parent_call_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret.i = + parent_va_call (event_data->routine, event_data->ctx, event_data->argc, event_data->ap); + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + +/* event callback */ +gboolean +background_parent_call_string (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data) +{ + ev_background_parent_call_t *event_data = (ev_background_parent_call_t *) data; + + (void) event_group_name; + (void) event_name; + (void) init_data; + + event_data->ret.s = + parent_va_call_string (event_data->routine, event_data->argc, event_data->ap); + + return TRUE; +} + +/* --------------------------------------------------------------------------------------------- */ + #endif /* WITH_BACKGROUND */ diff --git a/src/background.h b/src/background.h index e026d0534..cf5daac19 100644 --- a/src/background.h +++ b/src/background.h @@ -46,6 +46,13 @@ char *parent_call_string (void *routine, int argc, ...); void unregister_task_running (pid_t pid, int fd); void unregister_task_with_pid (pid_t pid); +gboolean background_parent_call (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); + +gboolean +background_parent_call_string (const gchar * event_group_name, const gchar * event_name, + gpointer init_data, gpointer data); + /*** inline functions ****************************************************************************/ #endif /* !WITH_BACKGROUND */ diff --git a/src/events_init.c b/src/events_init.c index 6b767cca8..23fd026c4 100644 --- a/src/events_init.c +++ b/src/events_init.c @@ -27,9 +27,12 @@ #include "lib/event.h" +#ifdef WITH_BACKGROUND +#include "background.h" /* (background_parent_call), background_parent_call_string() */ +#endif /* WITH_BACKGROUND */ #include "clipboard.h" /* clipboard events */ -#include "help.h" /* help_interactive_display() */ #include "execute.h" /* execute_suspend() */ +#include "help.h" /* help_interactive_display() */ #include "events_init.h" @@ -63,6 +66,11 @@ events_init (GError ** error) {MCEVENT_GROUP_CORE, "help", help_interactive_display, NULL}, {MCEVENT_GROUP_CORE, "suspend", execute_suspend, NULL}, +#ifdef WITH_BACKGROUND + {MCEVENT_GROUP_CORE, "background_parent_call", background_parent_call, NULL}, + {MCEVENT_GROUP_CORE, "background_parent_call_string", background_parent_call_string, NULL}, +#endif /* WITH_BACKGROUND */ + {NULL, NULL, NULL, NULL} }; /* *INDENT-ON* */ From f40887c3c69a496b520386f7cb5293738ad3f538 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 18 Feb 2011 15:11:57 +0200 Subject: [PATCH 20/25] Lib: removed includes to "src" directory Signed-off-by: Slava Zanko --- lib/Makefile.am | 2 +- lib/filehighlight.h | 2 +- lib/global.c | 2 ++ lib/global.h | 4 ++++ lib/util.h | 22 ++++++++++++++++++++++ lib/utilunix.c | 5 +++-- lib/utilunix.h | 25 +++++++++++++++++++++++++ lib/widget/dialog.c | 4 ---- lib/widget/input.c | 3 --- lib/widget/menu.c | 7 +------ src/execute.h | 8 +++----- src/filemanager/dir.h | 23 +---------------------- src/filemanager/midnight.c | 3 --- src/filemanager/midnight.h | 9 +++------ 14 files changed, 66 insertions(+), 53 deletions(-) create mode 100644 lib/utilunix.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 98cfbb35f..bec2d63c5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -13,7 +13,7 @@ SUBLIB_includes = \ widget.h SRC_mc_utils = \ - utilunix.c \ + utilunix.c utilunix.h \ unixcompat.h \ util.c util.h diff --git a/lib/filehighlight.h b/lib/filehighlight.h index 997b5ab1f..44bafc862 100644 --- a/lib/filehighlight.h +++ b/lib/filehighlight.h @@ -4,7 +4,7 @@ #include "lib/mcconfig.h" #include "lib/search.h" -#include "src/filemanager/dir.h" +#include "lib/util.h" /*** typedefs(not structures) and defined constants **********************************************/ diff --git a/lib/global.c b/lib/global.c index eb6eedc58..beb5329ca 100644 --- a/lib/global.c +++ b/lib/global.c @@ -71,6 +71,8 @@ mc_global_t mc_global = { .sysconfig_dir = NULL, .share_data_dir = NULL, + .is_right = FALSE, + .args = { .disable_colors = FALSE, diff --git a/lib/global.h b/lib/global.h index f86f0eadf..c476a9812 100644 --- a/lib/global.h +++ b/lib/global.h @@ -199,6 +199,10 @@ typedef struct /* share_data_dir: Area for default settings from developers */ char *share_data_dir; + /* Ugly hack in order to distinguish between left and right panel in menubar */ + /* Set if the command is being run from the "Right" menu */ + gboolean is_right; /* If the selected menu was the right */ + struct { /* Use the specified skin */ diff --git a/lib/util.h b/lib/util.h index ea9dadec5..95b4af607 100644 --- a/lib/util.h +++ b/lib/util.h @@ -47,6 +47,28 @@ enum compression_type /*** structures declarations (and typedefs of structures)*****************************************/ +/* keys are set only during sorting */ +typedef struct +{ + /* File attributes */ + size_t fnamelen; + char *fname; + struct stat st; + /* key used for comparing names */ + char *sort_key; + /* key used for comparing extensions */ + char *second_sort_key; + + /* Flags */ + struct + { + unsigned int marked:1; /* File marked in pane window */ + unsigned int link_to_dir:1; /* If this is a link, does it point to directory? */ + unsigned int stale_link:1; /* If this is a symlink and points to Charon's land */ + unsigned int dir_size_computed:1; /* Size of directory was computed with dirsizes_cmd */ + } f; +} file_entry; + /*** global variables defined in .c file *********************************************************/ extern struct sigaction startup_handler; diff --git a/lib/utilunix.c b/lib/utilunix.c index b81be0896..354a9b3b7 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -57,11 +57,12 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "src/execute.h" #ifdef HAVE_CHARSET -#include "charsets.h" +#include "lib/charsets.h" #endif +#include "utilunix.h" + /*** global variables ****************************************************************************/ struct sigaction startup_handler; diff --git a/lib/utilunix.h b/lib/utilunix.h new file mode 100644 index 000000000..922d2657a --- /dev/null +++ b/lib/utilunix.h @@ -0,0 +1,25 @@ +/** \file execute.h + * \brief Header: execution routines + */ + +#ifndef MC__UTILUNIX_H +#define MC__UTILUNIX_H + +/*** typedefs(not structures) and defined constants **********************************************/ + +/* flags for shell_execute */ +#define EXECUTE_INTERNAL (1 << 0) +#define EXECUTE_AS_SHELL (1 << 2) +#define EXECUTE_HIDE (1 << 3) + +/*** enums ***************************************************************************************/ + +/*** structures declarations (and typedefs of structures)*****************************************/ + +/*** global variables defined in .c file *********************************************************/ + +/*** declarations of public functions ************************************************************/ + +/*** inline functions ****************************************************************************/ + +#endif /* MC__UTILUNIX_H */ diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 2d280dba7..9fb18e132 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -39,10 +39,6 @@ #include "lib/widget.h" #include "lib/event.h" /* mc_event_raise() */ -/* TODO: these includes should be removed! */ -#include "src/help.h" /* interactive_display() */ -#include "src/filemanager/layout.h" - /*** global variables ****************************************************************************/ /* Color styles for normal and error dialogs */ diff --git a/lib/widget/input.c b/lib/widget/input.c index 1e38dea4c..e7f33b18b 100644 --- a/lib/widget/input.c +++ b/lib/widget/input.c @@ -52,9 +52,6 @@ #include "input_complete.h" -#include "src/main.h" /* home_dir */ -#include "src/filemanager/midnight.h" /* current_panel */ - /*** global variables ****************************************************************************/ int quote = 0; diff --git a/lib/widget/menu.c b/lib/widget/menu.c index 11f7f986b..1595cd18f 100644 --- a/lib/widget/menu.c +++ b/lib/widget/menu.c @@ -36,11 +36,6 @@ #include "lib/widget.h" #include "lib/event.h" /* mc_event_raise() */ -/* TODO: these includes should be removed! */ -#include "src/keybind-defaults.h" /* CK_IgnoreKey */ -#include "src/help.h" -#include "src/filemanager/midnight.h" /* is_right */ - /*** global variables ****************************************************************************/ /*** file scope macro definitions ****************************************************************/ @@ -297,7 +292,7 @@ menubar_execute (WMenuBar * menubar) if ((entry != NULL) && (entry->command != CK_IgnoreKey)) { - is_right = (menubar->selected != 0); + mc_global.is_right = (menubar->selected != 0); menubar_finish (menubar); menubar->widget.owner->callback (menubar->widget.owner, &menubar->widget, DLG_ACTION, entry->command, NULL); diff --git a/src/execute.h b/src/execute.h index a626c4403..0ca97967d 100644 --- a/src/execute.h +++ b/src/execute.h @@ -5,12 +5,9 @@ #ifndef MC__EXECUTE_H #define MC__EXECUTE_H -/*** typedefs(not structures) and defined constants **********************************************/ +#include "lib/utilunix.h" -/* flags for shell_execute */ -#define EXECUTE_INTERNAL (1 << 0) -#define EXECUTE_AS_SHELL (1 << 2) -#define EXECUTE_HIDE (1 << 3) +/*** typedefs(not structures) and defined constants **********************************************/ /*** enums ***************************************************************************************/ @@ -50,4 +47,5 @@ void post_exec (void); void pre_exec (void); /*** inline functions ****************************************************************************/ + #endif /* MC__EXECUTE_H */ diff --git a/src/filemanager/dir.h b/src/filemanager/dir.h index 44a3b89d9..dd135421f 100644 --- a/src/filemanager/dir.h +++ b/src/filemanager/dir.h @@ -8,6 +8,7 @@ #include #include "lib/global.h" +#include "lib/util.h" /*** typedefs(not structures) and defined constants **********************************************/ @@ -20,28 +21,6 @@ typedef int sortfn (const void *, const void *); /*** structures declarations (and typedefs of structures)*****************************************/ -/* keys are set only during sorting */ -typedef struct -{ - /* File attributes */ - size_t fnamelen; - char *fname; - struct stat st; - /* key used for comparing names */ - char *sort_key; - /* key used for comparing extensions */ - char *second_sort_key; - - /* Flags */ - struct - { - unsigned int marked:1; /* File marked in pane window */ - unsigned int link_to_dir:1; /* If this is a link, does it point to directory? */ - unsigned int stale_link:1; /* If this is a symlink and points to Charon's land */ - unsigned int dir_size_computed:1; /* Size of directory was computed with dirsizes_cmd */ - } f; -} file_entry; - typedef struct { file_entry *list; diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index bba1107a4..b4197a473 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -100,9 +100,6 @@ WPanel *right_panel = NULL; /* Pointer to the selected and unselected panel */ WPanel *current_panel = NULL; -/* Set if the command is being run from the "Right" menu */ -int is_right = 0; - /* The Menubar */ WMenuBar *the_menubar = NULL; /* The widget where we draw the prompt */ diff --git a/src/filemanager/midnight.h b/src/filemanager/midnight.h index 891aa6160..4fd86a683 100644 --- a/src/filemanager/midnight.h +++ b/src/filemanager/midnight.h @@ -14,9 +14,9 @@ /*** typedefs(not structures) and defined constants **********************************************/ -#define MENU_PANEL (is_right ? right_panel : left_panel) -#define MENU_PANEL_IDX (is_right ? 1 : 0) -#define SELECTED_IS_PANEL (get_display_type (is_right ? 1 : 0) == view_listing) +#define MENU_PANEL (mc_global.is_right ? right_panel : left_panel) +#define MENU_PANEL_IDX (mc_global.is_right ? 1 : 0) +#define SELECTED_IS_PANEL (get_display_type (mc_global.is_right ? 1 : 0) == view_listing) #define other_panel get_other_panel() @@ -34,9 +34,6 @@ extern WLabel *the_prompt; extern WLabel *the_hint; extern WButtonBar *the_bar; -/* Ugly hack in order to distinguish between left and right panel in menubar */ -extern gboolean is_right; /* If the selected menu was the right */ - extern WPanel *left_panel; extern WPanel *right_panel; extern WPanel *current_panel; From 7df04e95e2a9a60a4d4a4daa1f57aa8ff3713794 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Thu, 24 Feb 2011 17:32:00 +0200 Subject: [PATCH 21/25] Added manual for events (Russian and English). Signed-off-by: Slava Zanko --- lib/event/event-ru.txt | 129 ++++++++++++++++++++++++++++++++++ lib/event/event.txt | 153 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+) create mode 100644 lib/event/event-ru.txt create mode 100644 lib/event/event.txt diff --git a/lib/event/event-ru.txt b/lib/event/event-ru.txt new file mode 100644 index 000000000..0fbbb98a4 --- /dev/null +++ b/lib/event/event-ru.txt @@ -0,0 +1,129 @@ += СОБЫТИЯ = + +В mc используется система событий, основанная на технологии быстрых бинарных деревьев. + +== Вступление == + +Система событий, в первую очередь, призвана отвязать на уровне исходных текстов источник события и обработчик. +Например, в модуле VFS используется функция вывода сообщений, которая определена в исходных текстах (не в lib). +В lib определение этой функции будет затруднительным (потому что функция делает множество вызовов на другие +функции из src). В данном случае можно представить эту функцию как обработчик события, а сам процесс вывода +сообщения от VFS на экран как непосредственно событие. В начале запуска mc функцию вывода сообщений необходимо +зарегистрировать как обработчик события; в последствии при необходимости выдачи сообщений нужно просто вызвать +событие, абсолютно не волнуясь, привязан ли обработчик к событию, а также какая именно функция сейчас является +обработчиком события (вероятна ситуация, при которой позже загрузился плагин и переопределил этот обработчик +событий на себя). + +=== Использование === + +Не везде и не всегда применимы события. Самое трудное порой бывает решить, это должна быть простая функция или это +должно быть событие. Наиболее правильным будет заменить все функции (или части switch(){case:}), используемые при +обработке кейбиндингов. Все кейбиндинги описаны в lib/keybind.h + +Вторым аргументом при выборе решения (обработчик события или функция) должна стать мысль, что функцию в обработчик +события "превратить" легко; обратный процесс (обработчик в функцию) будет значительно сложнее - хотя бы потому, +что на одном событии может "висеть" множество обработчиков, и каждый может зависеть от работы предыдущего. + +Третьим аргументом при выборе в пользу обработчиков событий могут стать плагины (когда появятся). В данном случае +события - это способ дать плагинам доступ к внутренним ресурсам приложения, не "пуская" эти плагины в низкоуровневое +API. Всё, что нужно будет знать "плагинам" - какое событие с какой структурой надо вызвать и как именно вызвать +(#include "lib/event.h"). + +== Структура == + +В общем виде подсистему событий можно представить так: + + + ------------------------------------ } + |Группа1 Группа2 ... ГруппаN| } Группы событий (GTree) + ------------------------------------- } + | | | + /|\ /|\ /|\ + / | \ / | ... ... событиеN } + / | \ / ... } + / | \ ... } События, разбитые на группы + | | событие3 } (GTree для каждой группы) + | событие2 } + событие1 } + | | | | + f1f2...fN } список обработчиков события (GPtrArray на каждое событие) + + +Такая схема позволяет группировать события и выполнять более одного обработчика на одно событие. + +== Требования к обработчикам событий == + +Любой каллбэк должен быть вида: + +gboolean mc_event_callback_func_t (const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer event_data); +где: + event_group: + название группы, в которой было инициировано событие + + event_name: + название события. Вместе с названием группы событий позволяют точно идентифицировать событие. + Эти параметры могут быть полезны в случае если обработчик события привязан сразу к нескольким событиям + и необходимо различать различные события (например, в функции логгирования) + + init_data: + Произвольные данные, предоставляемые обработчикам события. Эти данные указываются при добавлении обработчика + к событию (инициализационные данные). + event_data: + Данные, предоставляемые обработчику событий в момент возникновения события. + +Каллбэк должен вернуть TRUE, чтобы разрешить исполниться всем последующим за ним каллбэкам в данном событии; либо +FALSE если необходимо немедленно прекратить дальнейшую обработку события (оставшиеся каллбэки не вызываются). + +Если для одного и того же события будет привязано множество каллбэков, то порядок из исполнения будет следующим: +"Последним добавился - первым выполнился". Это позволяет в последствии переопределять стандартные обработчики событий +(например, в плагинах). + +=== Передача параметров в обработчики событий. Возврат результатов === + +Из-за унификации обработчиков событий стало невозможным передать определённое количество параметров и +получить результат выполнения. Если передачу одного параметра (или приём одного результата от обработчика события) +можно произвести простым приведением типа на одну переменную при вызове событий, то при передаче нескольких параметров +(или при получении нескольких результатов) такой метод неприменим. + +Для решения этой проблемы можно передавать ранее определённые структуры по универсальному указателю event_data. +Все структуры, используемые в обработчиках событий, должны быть определены в файле lib/event-types.h. + +У данного метода (передача параметров указателем на структуру) есть как достоинства, так и недостатки. + +Достоинства: + * произвольное количество параметров и их типов; + * произвольное количество возвращаемых значений и их типов. + +Недостатки: + * вероятность ошибки: вызов события с неправильной структурой. В данном случае обработчик приведёт указатель к той + структуре, на которую он рассчитан. При этом возможны весёлые глюки с отладкой (особенно если нет сразу segfault); + * необходимость иметь ранее определённые структуры для того, чтобы и обработчик события, и инициатор события могли бы + без проблем "общаться" между собой. + +== Примеры использования == + +=== Логгирование === + +Рассмотрим пример временного каллбэка, который просто логгирует порядок вызова определённых событий (например, +для выявления зацикливаний). + +Сам каллбэк: + +gboolean mc_temp_event_logger (const gchar *event_group, const gchar *event_name, gpointer init_data, gpointer data) +{ + (void) init_data; + (void) data; + + mc_log("Event: %s:%s",event_group,event_name); + return TRUE; +} + +Добавляем его в src/event_init.c в виде записей к инициализационной структуре +перед строчкой "{NULL, NULL, NULL, NULL}": + +{MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_text_to_file", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_text_from_file", mc_temp_event_logger, NULL}, +...(тут любые другие события, которые необходимо мониторить)... + diff --git a/lib/event/event.txt b/lib/event/event.txt new file mode 100644 index 000000000..a3460facd --- /dev/null +++ b/lib/event/event.txt @@ -0,0 +1,153 @@ += EVENTS = + +The subsystem of events used in mc is based on fast binary trees engine. + + +== Introduction == + +Subsystem of events is primarily designed to detach event source and event +handler in source code level. For example, VFS module uses function to show +messages, which is defined in the source code (not in the lib). In the lib, +definition of this function will be difficult (because the function does +a lot of calls of other functions from src). In this case, the transform +of this function to event handler is needed, and the display messages process +can be used as an event. Function as event handler should be registered +at early stage of mc start. Later just call the event, absolutely without +worrying whether the handler is tied to the event, and which function +is an event handler now (in some situation, plugin will load and reassign +this event handler to itself). + + +=== Usage === + +Events are applicable in any case. Sometimes it is hard to decide whether +it should be a common function or it should be an event handler. The replacement +of all functions used in keybindings process to event handler is good choice +(or parts of the 'switch () {case:}' in keybindings handlers). All keybindings +are described in lib/keybind.h. + +The second argument to choose the solution (event handler or function) should be +thought whether that transformation of function to the event handler is easy, +the inverse process (handler to function) would be more difficult because +one event can have multiple handlers and each handler may depend to another. + +A third argument in the choice in favor of the event handlers can be a plug-ins +(in future). In this case events is a way to give access to internal application +resources without providing a low-level API. All plug-ins need is to know what and how +call the event with proper structure type (#include "lib/event.h"). + + +== Structure == + +In general, the subsystem of events can be represented as following: + + ------------------------------------ } + |Group1 Group2 ... GroupN| } Event groups (GTree) + ------------------------------------- } + | | | + /|\ /|\ /|\ + / | \ / | ... ... eventN } + / | \ / ... } + / | \ ... } Events by groups + | | event3 } (GTree for any group) + | event2 } + event1 } + | | | | + f1f2...fN } list of event handlers (GPtrArray for any event) + + +This scheme allows to group events, and perform several handlers for one event. + + +== Requirements for event handlers == + +The following function prototype is event handler: + +gboolean mc_event_callback_func_t ( + const gchar *event_group, + const gchar *event_name, + gpointer init_data, + gpointer event_data +); + +where: + event_group: + name of the group, where event was initiated + + event_name: + event name. event_name ans event_group uniquely identify an event. + These parameters can be useful if event handler is tied to several events + and the distinguish between different events (for example, function of logging) + is required. + + init_data: + Arbitrary data, provided to the event handler. + This data is provided by adding a handler to the event (the initialization data). + + event_data: + Data provided to the handler when the event occurred. + +Handler should return TRUE to allow running all other handlers tied to this event; +or FALSE if it is necessary to stop further processing of event (the remaining +handlers are not called). + +If one event will have multiple handlers, the order of execution is "Last added - first +executed". This allows to override the standard event handlers (eg, in plug-ins). + + +=== Passing parameters to event handlers. Returning rezults == + +Due to the unification of the event handlers, there is no possibility to pass +a certain number of parameters and get the results of execution. Pass of a single +parameter (or get one result of an event handler) can be made as simple type casting +for one variable when event is called. But this way isn't applicable if pass +of several parameters (or get multiple return values) is required. + +To solve this problem, you can pass the previously defined structure as universal +pointer event_data. All structures used in the event handlers should be defined +in the lib/event-types.h. + +This way (the pass parameters as pointer to structure) has advantages and disadvantages. + +Advantages: + * any number of parameters and their types; + * any number of return values and their types. + +Disadvantages: + * probability of error: call the event with the wrong structure. In this case, + the handler will cast pointer to the structure on which it was designed. + At this point funny bugs and very long debugging process (especially if segfault + doesn't occur immediately) are possible; + * in order for an event handler and the initiator of the event to "communicate" + with each other, previously defined structures is needed. + + +== Examples == + +=== Logging === + +Consider the example of a temporary handler which simply logged the order +of certain events (for example, to detect infinite loop). + +Here event handler: + +gboolean +mc_temp_event_logger (const gchar *event_group, const gchar *event_name, + gpointer init_data, gpointer data) +{ + (void) init_data; + (void) data; + + mc_log("Event: %s:%s",event_group,event_name); + return TRUE; +} + +Add the following lines into src/event_init.c before "{NULL, NULL, NULL, NULL}" line +as one record to the initialization structure. + +{MCEVENT_GROUP_CORE, "clipboard_file_to_ext_clip", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_file_from_ext_clip", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_text_to_file", mc_temp_event_logger, NULL}, +{MCEVENT_GROUP_CORE, "clipboard_text_from_file", mc_temp_event_logger, NULL}, + +...(there any other events which you want to monitor)... From 48d1f1f5189370a98e8262c242e8ba259e4afc30 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 4 Mar 2011 16:00:45 +0200 Subject: [PATCH 22/25] configure.ac: Moved GLib initialization to m4.include/ac-glib.m4 Signed-off-by: Slava Zanko --- acinclude.m4 | 2 +- configure.ac | 51 +----------------- .../{ac-g-module-supported.m4 => ac-glib.m4} | 53 +++++++++++++++++++ 3 files changed, 56 insertions(+), 50 deletions(-) rename m4.include/{ac-g-module-supported.m4 => ac-glib.m4} (52%) diff --git a/acinclude.m4 b/acinclude.m4 index 2a800371b..222661877 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -6,7 +6,7 @@ m4_include([m4.include/mc-check-search-type.m4]) m4_include([m4.include/ac-get-fs-info.m4]) m4_include([m4.include/mc-use-termcap.m4]) m4_include([m4.include/mc-with-screen.m4]) -m4_include([m4.include/ac-g-module-supported.m4]) +m4_include([m4.include/ac-glib.m4]) m4_include([m4.include/mc-vfs.m4]) m4_include([m4.include/mc-version.m4]) m4_include([m4.include/mc-tests.m4]) diff --git a/configure.ac b/configure.ac index 24a297ec4..64b39f28b 100644 --- a/configure.ac +++ b/configure.ac @@ -43,22 +43,7 @@ DX_INIT_DOXYGEN(mc,doxygen.cfg,devel) dnl PKG_CHECK_MODULES([CHECK], [check >= 0.9.4]) -dnl -dnl First try glib 2.x. -dnl Keep this check close to the beginning, so that the users -dnl without any glib won't have their time wasted by other checks. -dnl - -AC_ARG_WITH([glib_static], - [ --with-glib-static Link glib statically [[no]]]) - -glib_found=no - -PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.8], [glib_found=yes], [:]) -if test x"$glib_found" = xno; then - AC_MSG_ERROR([glib-2.0 not found or version too old (must be >= 2.8)]) -fi - +AC_CHECK_GLIB AC_HEADER_MAJOR AC_C_CONST @@ -219,43 +204,11 @@ dnl dnl X11 support. dnl Used to read keyboard modifiers when running under X11. AC_PATH_XTRA + dnl dnl Check if the gmodule functionality supported on this system. AC_G_MODULE_SUPPORTED -dnl -dnl Try to find static libraries for glib and gmodule. -dnl -if test x$with_glib_static = xyes; then - new_GLIB_LIBS= - for i in $GLIB_LIBS; do - case x$i in - x-lglib*) - lib=glib ;; - x-lgmodule*) - lib=gmodule ;; - *) - lib= - add="$i" ;; - esac - - if test -n "$lib"; then - lib1=`echo $i | sed 's/^-l//'` - if test -f "$GLIB_LIBDIR/lib${lib1}.a"; then - add="$GLIB_LIBDIR/lib${lib1}.a" - else - if test -f "$GLIB_LIBDIR/lib${lib}.a"; then - add="$GLIB_LIBDIR/lib${lib}.a" - else - AC_MSG_ERROR([Cannot find static $lib]) - fi - fi - fi - new_GLIB_LIBS="$new_GLIB_LIBS $add" - done - GLIB_LIBS="$new_GLIB_LIBS" -fi - dnl dnl Sequent wants getprocessstats dnl diff --git a/m4.include/ac-g-module-supported.m4 b/m4.include/ac-glib.m4 similarity index 52% rename from m4.include/ac-g-module-supported.m4 rename to m4.include/ac-glib.m4 index 359b6cf41..b3079ecc8 100644 --- a/m4.include/ac-g-module-supported.m4 +++ b/m4.include/ac-glib.m4 @@ -42,4 +42,57 @@ AC_DEFUN([AC_G_MODULE_SUPPORTED], [ fi AM_CONDITIONAL([HAVE_GMODULE], [test x"$g_module_supported" != x]) + + dnl + dnl Try to find static libraries for glib and gmodule. + dnl + if test x$with_glib_static = xyes; then + new_GLIB_LIBS= + for i in $GLIB_LIBS; do + case x$i in + x-lglib*) + lib=glib ;; + x-lgmodule*) + lib=gmodule ;; + *) + lib= + add="$i" ;; + esac + + if test -n "$lib"; then + lib1=`echo $i | sed 's/^-l//'` + if test -f "$GLIB_LIBDIR/lib${lib1}.a"; then + add="$GLIB_LIBDIR/lib${lib1}.a" + else + if test -f "$GLIB_LIBDIR/lib${lib}.a"; then + add="$GLIB_LIBDIR/lib${lib}.a" + else + AC_MSG_ERROR([Cannot find static $lib]) + fi + fi + fi + new_GLIB_LIBS="$new_GLIB_LIBS $add" + done + GLIB_LIBS="$new_GLIB_LIBS" + fi + ]) + +AC_DEFUN([AC_CHECK_GLIB], [ + dnl + dnl First try glib 2.x. + dnl Keep this check close to the beginning, so that the users + dnl without any glib won't have their time wasted by other checks. + dnl + + AC_ARG_WITH([glib_static], + AC_HELP_STRING([--with-glib-static],[Link glib statically [[no]]])) + + glib_found=no + PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.8], [glib_found=yes], [:]) + if test x"$glib_found" = xno; then + AC_MSG_ERROR([glib-2.0 not found or version too old (must be >= 2.8)]) + fi + +]) + From c0637dcb274f65ebfd9da6ba14c6e3443ea27442 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 4 Mar 2011 16:33:56 +0200 Subject: [PATCH 23/25] update .gitignore for src/vfs/extfs/helpers/ Signed-off-by: Slava Zanko --- src/vfs/extfs/helpers/.gitignore | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vfs/extfs/helpers/.gitignore b/src/vfs/extfs/helpers/.gitignore index 70fd3c690..e23b9188a 100644 --- a/src/vfs/extfs/helpers/.gitignore +++ b/src/vfs/extfs/helpers/.gitignore @@ -1,18 +1,19 @@ Makefile Makefile.in -a -apt +a+ +apt+ audio deb deba debd -dpkg -hp48 +dpkg+ +hp48+ iso9660 lslR mailfs patchfs -rpms +rpms+ +s3+ ualz uar uarj From 06f99484de42f9a04de5c2433f10d86eca3b94de Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Fri, 4 Mar 2011 18:07:30 +0200 Subject: [PATCH 24/25] Added configure parameter --enable-mclib for build own shared library Signed-off-by: Slava Zanko --- configure.ac | 23 +++++++++++++++++++++++ lib/Makefile.am | 24 +++++++++++++++++++++++- src/Makefile.am | 12 +----------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 64b39f28b..a8bf724ce 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,11 @@ AC_CONFIG_AUX_DIR(config) MC_VERSION AM_INIT_AUTOMAKE(mc, ${VERSION} ) +LIBMC_VERSION="0.0.1" +LIBMC_RELEASE="1" +AC_SUBST(LIBMC_VERSION) +AC_SUBST(LIBMC_RELEASE) + dnl Enable silent rules by default (if yes) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -45,6 +50,24 @@ dnl PKG_CHECK_MODULES([CHECK], [check >= 0.9.4]) AC_CHECK_GLIB +AC_ARG_ENABLE([mclib], + [AS_HELP_STRING([--enable-mclib],[ Compile shared library libmc.so [no]])], + [ + if test "x$enableval" = "xno" ; then + enable_mclib=no + else + if test "x$enable_shared" = "xno" ; then + AC_MSG_WARN([Build of shared library is disabled. Specify --enable-shared first]) + enable_mclib=no + else + enable_mclib=yes + fi + fi + ], + [enable_mclib=no]) + +AM_CONDITIONAL([ENABLE_MCLIB], [test x$enable_mclib = xyes]) + AC_HEADER_MAJOR AC_C_CONST AC_SYS_LARGEFILE diff --git a/lib/Makefile.am b/lib/Makefile.am index bec2d63c5..f57334b2c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,6 +1,17 @@ SUBDIRS = event filehighlight mcconfig search skin tty vfs strutil widget -noinst_LTLIBRARIES = libmc.la +if ENABLE_MCLIB + LIB_VERSION=`echo $(LIBMC_VERSION) | \ + tr '.' ' '| \ + while read v1 v2 v3; do echo $$v2':'$$v3':'$$v1; done` + + libmc_la_LDFLAGS=-no-undefined -version-info $(LIB_VERSION) -release $(LIBMC_RELEASE) + + lib_LTLIBRARIES = libmc.la +else + noinst_LTLIBRARIES = libmc.la +endif + SUBLIB_includes = \ event.h event-types.h \ @@ -50,3 +61,14 @@ libmc_la_LIBADD = \ tty/libmctty.la \ vfs/libmcvfs.la \ widget/libmcwidget.la + +libmc_la_LIBADD += $(MCLIBS) $(SLANGLIB) + +if HAVE_GMODULE + libmc_la_LIBADD += $(GMODULE_LIBS) +else + libmc_la_LIBADD += $(GLIB_LIBS) +endif + +libmc_la_LIBADD += $(PCRE_LIBS) $(LIBICONV) $(INTLLIBS) + diff --git a/src/Makefile.am b/src/Makefile.am index 0e10e004e..d5ec6b00e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,23 +35,13 @@ mc_LDADD = \ viewer/libmcviewer.la \ filemanager/libmcfilemanager.la \ $(DIFFLIB) $(EDITLIB) \ - ../lib/libmc.la + $(top_builddir)/lib/libmc.la if ENABLE_VFS_SMB # this is a hack for linking with own samba library in simple way mc_LDADD += vfs/smbfs/helpers/libsamba.a endif -mc_LDADD += $(MCLIBS) $(SLANGLIB) - -if HAVE_GMODULE -mc_LDADD += $(GMODULE_LIBS) -else -mc_LDADD += $(GLIB_LIBS) -endif - -mc_LDADD += $(PCRE_LIBS) $(LIBICONV) $(INTLLIBS) - SRC_mc_conssaver = \ cons.handler.c consaver/cons.saver.h From 994254917c05d2d36192118c723ccef634b0cfb0 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Wed, 9 Mar 2011 11:33:46 +0200 Subject: [PATCH 25/25] Added test for checking if library is independ to $(topsrcdir)/src Signed-off-by: Slava Zanko --- configure.ac | 8 +++++ lib/Makefile.am | 6 +++- lib/tests/Makefile.am | 10 ++++++ lib/tests/library_independ.c | 59 ++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 lib/tests/Makefile.am create mode 100644 lib/tests/library_independ.c diff --git a/configure.ac b/configure.ac index a8bf724ce..34b227401 100644 --- a/configure.ac +++ b/configure.ac @@ -602,6 +602,14 @@ intl/Makefile po/Makefile.in ]) +if test x$enable_tests != xno; then + AC_CONFIG_FILES([ +lib/tests/Makefile +]) + +fi + + AC_OUTPUT echo " diff --git a/lib/Makefile.am b/lib/Makefile.am index f57334b2c..d0f816b6f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,8 @@ -SUBDIRS = event filehighlight mcconfig search skin tty vfs strutil widget +SUBDIRS = event filehighlight mcconfig search skin tty vfs strutil widget . + +if HAVE_TESTS + SUBDIRS += tests +endif if ENABLE_MCLIB LIB_VERSION=`echo $(LIBMC_VERSION) | \ diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am new file mode 100644 index 000000000..cd64c9996 --- /dev/null +++ b/lib/tests/Makefile.am @@ -0,0 +1,10 @@ +AM_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir) @CHECK_CFLAGS@ +LIBS=@CHECK_LIBS@ $(top_builddir)/lib/libmc.la + +TESTS = \ + library_independ + +check_PROGRAMS = $(TESTS) + +library_independ_SOURCES = \ + library_independ.c diff --git a/lib/tests/library_independ.c b/lib/tests/library_independ.c new file mode 100644 index 000000000..6f249179f --- /dev/null +++ b/lib/tests/library_independ.c @@ -0,0 +1,59 @@ +/* libmc - check if library is independ to $(topsrc)/src directory + + Copyright (C) 2011 Free Software Foundation, Inc. + + Written by: + Slava Zanko , 2011 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License + as published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#define TEST_SUITE_NAME "lib/library_independ" + +#include + +#include "lib/global.h" + +/* --------------------------------------------------------------------------------------------- */ + +START_TEST (test_library_independ) +{ +} +END_TEST + +/* --------------------------------------------------------------------------------------------- */ + +int +main (void) +{ + int number_failed; + + Suite *s = suite_create (TEST_SUITE_NAME); + TCase *tc_core = tcase_create ("Core"); + SRunner *sr; + + /* Add new tests here: *************** */ + tcase_add_test (tc_core, test_library_independ); + /* *********************************** */ + + suite_add_tcase (s, tc_core); + sr = srunner_create (s); + srunner_run_all (sr, CK_NORMAL); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + return (number_failed == 0) ? 0 : 1; +} + +/* --------------------------------------------------------------------------------------------- */