mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 12:32:40 +03:00
Moved hooks from lib/util.[ch] to new files lib/hook.[ch]
... and renamed Hook to hook_t. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
c2754de8aa
commit
79133154b0
@ -21,6 +21,7 @@ libmc_la_SOURCES = \
|
||||
$(SRC_mc_utils) \
|
||||
fileloc.h \
|
||||
fs.h \
|
||||
hook.c hook.h \
|
||||
glibcompat.c glibcompat.h \
|
||||
global.h \
|
||||
lock.c lock.h \
|
||||
|
125
lib/hook.c
Normal file
125
lib/hook.c
Normal file
@ -0,0 +1,125 @@
|
||||
/* Hooks
|
||||
Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
|
||||
2004, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
|
||||
Written 1994, 1995, 1996 by:
|
||||
Miguel de Icaza, Janne Kukonlehto, Dugan Porter,
|
||||
Jakub Jelinek, Mauricio Plaza.
|
||||
|
||||
The file_date routine is mostly from GNU's fileutils package,
|
||||
written by Richard Stallman and David MacKenzie.
|
||||
|
||||
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. */
|
||||
|
||||
/** \file
|
||||
* \brief Source: hooks
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/hook.h"
|
||||
|
||||
/*** global variables ****************************************************************************/
|
||||
|
||||
/*** file scope macro definitions ****************************************************************/
|
||||
|
||||
/*** file scope type declarations ****************************************************************/
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data)
|
||||
{
|
||||
hook_t *new_hook = g_new (hook_t, 1);
|
||||
|
||||
new_hook->hook_fn = hook_fn;
|
||||
new_hook->next = *hook_list;
|
||||
new_hook->hook_data = data;
|
||||
|
||||
*hook_list = new_hook;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
execute_hooks (hook_t * hook_list)
|
||||
{
|
||||
hook_t *new_hook = NULL;
|
||||
hook_t *p;
|
||||
|
||||
/* We copy the hook list first so tahat we let the hook
|
||||
* function call delete_hook
|
||||
*/
|
||||
|
||||
while (hook_list != NULL)
|
||||
{
|
||||
add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
|
||||
hook_list = hook_list->next;
|
||||
}
|
||||
p = new_hook;
|
||||
|
||||
while (new_hook != NULL)
|
||||
{
|
||||
new_hook->hook_fn (new_hook->hook_data);
|
||||
new_hook = new_hook->next;
|
||||
}
|
||||
|
||||
for (hook_list = p; hook_list != NULL;)
|
||||
{
|
||||
p = hook_list;
|
||||
hook_list = hook_list->next;
|
||||
g_free (p);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
delete_hook (hook_t ** hook_list, void (*hook_fn) (void *))
|
||||
{
|
||||
hook_t *new_list = NULL;
|
||||
hook_t *current, *next;
|
||||
|
||||
for (current = *hook_list; current != NULL; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
if (current->hook_fn == hook_fn)
|
||||
g_free (current);
|
||||
else
|
||||
add_hook (&new_list, current->hook_fn, current->hook_data);
|
||||
}
|
||||
*hook_list = new_list;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
gboolean
|
||||
hook_present (hook_t * hook_list, void (*hook_fn) (void *))
|
||||
{
|
||||
hook_t *p;
|
||||
|
||||
for (p = hook_list; p != NULL; p = p->next)
|
||||
if (p->hook_fn == hook_fn)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
34
lib/hook.h
Normal file
34
lib/hook.h
Normal file
@ -0,0 +1,34 @@
|
||||
/** \file util.h
|
||||
* \brief Header: hooks
|
||||
*/
|
||||
|
||||
#ifndef MC_HOOK_H
|
||||
#define MC_HOOK_H
|
||||
|
||||
#include "lib/global.h"
|
||||
|
||||
/*** typedefs(not structures) and defined constants **********************************************/
|
||||
|
||||
/*** enums ***************************************************************************************/
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct hook_t
|
||||
{
|
||||
void (*hook_fn) (void *);
|
||||
void *hook_data;
|
||||
struct hook_t *next;
|
||||
} hook_t;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
/*** declarations of public functions ************************************************************/
|
||||
|
||||
void add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data);
|
||||
void execute_hooks (hook_t * hook_list);
|
||||
void delete_hook (hook_t ** hook_list, void (*hook_fn) (void *));
|
||||
gboolean hook_present (hook_t * hook_list, void (*hook_fn) (void *));
|
||||
|
||||
/*** inline functions **************************************************/
|
||||
|
||||
#endif /* MC_HOOK_H */
|
81
lib/util.c
81
lib/util.c
@ -1177,87 +1177,6 @@ decompress_extension (int type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/* Hooks */
|
||||
|
||||
void
|
||||
add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data)
|
||||
{
|
||||
Hook *new_hook = g_new (Hook, 1);
|
||||
|
||||
new_hook->hook_fn = hook_fn;
|
||||
new_hook->next = *hook_list;
|
||||
new_hook->hook_data = data;
|
||||
|
||||
*hook_list = new_hook;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
execute_hooks (Hook * hook_list)
|
||||
{
|
||||
Hook *new_hook = 0;
|
||||
Hook *p;
|
||||
|
||||
/* We copy the hook list first so tahat we let the hook
|
||||
* function call delete_hook
|
||||
*/
|
||||
|
||||
while (hook_list)
|
||||
{
|
||||
add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
|
||||
hook_list = hook_list->next;
|
||||
}
|
||||
p = new_hook;
|
||||
|
||||
while (new_hook)
|
||||
{
|
||||
(*new_hook->hook_fn) (new_hook->hook_data);
|
||||
new_hook = new_hook->next;
|
||||
}
|
||||
|
||||
for (hook_list = p; hook_list;)
|
||||
{
|
||||
p = hook_list;
|
||||
hook_list = hook_list->next;
|
||||
g_free (p);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
delete_hook (Hook ** hook_list, void (*hook_fn) (void *))
|
||||
{
|
||||
Hook *current, *new_list, *next;
|
||||
|
||||
new_list = 0;
|
||||
|
||||
for (current = *hook_list; current; current = next)
|
||||
{
|
||||
next = current->next;
|
||||
if (current->hook_fn == hook_fn)
|
||||
g_free (current);
|
||||
else
|
||||
add_hook (&new_list, current->hook_fn, current->hook_data);
|
||||
}
|
||||
*hook_list = new_list;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
hook_present (Hook * hook_list, void (*hook_fn) (void *))
|
||||
{
|
||||
Hook *p;
|
||||
|
||||
for (p = hook_list; p; p = p->next)
|
||||
if (p->hook_fn == hook_fn)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
|
15
lib/util.h
15
lib/util.h
@ -100,13 +100,6 @@ enum compression_type
|
||||
|
||||
/*** structures declarations (and typedefs of structures)*****************************************/
|
||||
|
||||
typedef struct hook
|
||||
{
|
||||
void (*hook_fn) (void *);
|
||||
void *hook_data;
|
||||
struct hook *next;
|
||||
} Hook;
|
||||
|
||||
/*** global variables defined in .c file *********************************************************/
|
||||
|
||||
extern char *user_recent_timeformat; /* time format string for recent dates */
|
||||
@ -256,14 +249,6 @@ char *mc_realpath (const char *path, char *resolved_path);
|
||||
enum compression_type get_compression_type (int fd, const char *);
|
||||
const char *decompress_extension (int type);
|
||||
|
||||
/* Hook functions */
|
||||
|
||||
|
||||
void add_hook (Hook ** hook_list, void (*hook_fn) (void *), void *data);
|
||||
void execute_hooks (Hook * hook_list);
|
||||
void delete_hook (Hook ** hook_list, void (*hook_fn) (void *));
|
||||
int hook_present (Hook * hook_list, void (*hook_fn) (void *));
|
||||
|
||||
GList *list_append_unique (GList * list, char *text);
|
||||
|
||||
/* Position saving and restoring */
|
||||
|
@ -57,7 +57,7 @@ dlg_colors_t alarm_colors;
|
||||
GList *top_dlg = NULL;
|
||||
|
||||
/* A hook list for idle events */
|
||||
Hook *idle_hook = NULL;
|
||||
hook_t *idle_hook = NULL;
|
||||
|
||||
/* left click outside of dialog closes it */
|
||||
int mouse_close_dialog = 0;
|
||||
|
@ -31,7 +31,7 @@
|
||||
|
||||
#include "lib/global.h"
|
||||
#include "lib/tty/mouse.h"
|
||||
#include "lib/util.h" /* Hook */
|
||||
#include "lib/hook.h" /* hook_t */
|
||||
|
||||
/* Common return values */
|
||||
#define B_EXIT 0
|
||||
@ -266,7 +266,7 @@ void common_dialog_repaint (Dlg_head *h);
|
||||
extern GList *top_dlg;
|
||||
|
||||
/* A hook list for idle events */
|
||||
extern Hook *idle_hook;
|
||||
extern hook_t *idle_hook;
|
||||
|
||||
static inline cb_ret_t
|
||||
send_message (Widget * w, widget_msg_t msg, int parm)
|
||||
|
@ -138,7 +138,7 @@ void try_to_select (WPanel *panel, const char *name);
|
||||
void unmark_files (WPanel *panel);
|
||||
void select_item (WPanel *panel);
|
||||
|
||||
extern Hook *select_file_hook;
|
||||
extern hook_t *select_file_hook;
|
||||
|
||||
void recalculate_panel_summary (WPanel *panel);
|
||||
void file_mark (WPanel *panel, int idx, int val);
|
||||
|
@ -106,7 +106,7 @@ int show_mini_info = 1;
|
||||
int torben_fj_mode = 0;
|
||||
|
||||
/* The hook list for the select file function */
|
||||
Hook *select_file_hook = 0;
|
||||
hook_t *select_file_hook = NULL;
|
||||
|
||||
static cb_ret_t panel_callback (Widget *, widget_msg_t msg, int parm);
|
||||
static int panel_event (Gpm_Event * event, void *);
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "lib/mcconfig.h"
|
||||
#include "lib/vfs/mc-vfs/vfs.h"
|
||||
#include "lib/fileloc.h"
|
||||
#include "lib/hook.h"
|
||||
|
||||
#include "treestore.h"
|
||||
#include "setup.h"
|
||||
@ -61,6 +62,8 @@ static struct TreeStore ts;
|
||||
|
||||
static tree_entry *tree_store_add_entry (const char *name);
|
||||
|
||||
static hook_t *remove_entry_hooks;
|
||||
|
||||
static void
|
||||
tree_store_dirty (int state)
|
||||
{
|
||||
@ -527,8 +530,6 @@ tree_store_add_entry (const char *name)
|
||||
return new;
|
||||
}
|
||||
|
||||
static Hook *remove_entry_hooks;
|
||||
|
||||
void
|
||||
tree_store_add_entry_remove_hook (tree_store_remove_fn callback, void *data)
|
||||
{
|
||||
@ -544,10 +545,10 @@ tree_store_remove_entry_remove_hook (tree_store_remove_fn callback)
|
||||
static void
|
||||
tree_store_notify_remove (tree_entry * entry)
|
||||
{
|
||||
Hook *p = remove_entry_hooks;
|
||||
hook_t *p = remove_entry_hooks;
|
||||
tree_store_remove_fn r;
|
||||
|
||||
while (p)
|
||||
while (p != NULL)
|
||||
{
|
||||
r = (tree_store_remove_fn) p->hook_fn;
|
||||
r (entry, p->hook_data);
|
||||
|
Loading…
Reference in New Issue
Block a user