2011-10-15 14:56:47 +04:00
|
|
|
/*
|
|
|
|
Hooks.
|
|
|
|
|
|
|
|
Slavaz: Warning! this file is deprecated and should be replaced
|
2012-07-06 14:56:29 +04:00
|
|
|
by mcevents functional.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
2015-01-07 10:06:55 +03:00
|
|
|
Copyright (C) 1994-2015
|
2014-02-12 10:33:10 +04:00
|
|
|
Free Software Foundation, Inc.
|
2011-10-15 14:56:47 +04:00
|
|
|
|
|
|
|
Written by:
|
|
|
|
Miguel de Icaza, 1994, 1995, 1996
|
|
|
|
Janne Kukonlehto, 1994, 1995, 1996
|
|
|
|
Dugan Porter, 1994, 1995, 1996
|
|
|
|
Jakub Jelinek, 1994, 1995, 1996
|
|
|
|
Mauricio Plaza, 1994, 1995, 1996
|
2010-11-09 11:08:20 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
This file is part of the Midnight Commander.
|
2010-11-09 11:08:20 +03:00
|
|
|
|
2011-10-15 14:56:47 +04:00
|
|
|
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 3 of the License,
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
The Midnight Commander is distributed in the hope that it will be useful,
|
2010-11-09 11:08:20 +03:00
|
|
|
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
|
2011-10-15 14:56:47 +04:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-11-09 11:08:20 +03:00
|
|
|
|
|
|
|
/** \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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|