Updated doc/NEWS file
[midnight-commander.git] / lib / hook.c
blob8e61ad0337eecbd19c0ed2300cba299265f20c6a
1 /*
2 Hooks.
4 Slavaz: Warning! this file is deprecated and should be replaced
5 by mcevents functional.
7 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
8 2004, 2005, 2007, 2009, 2010, 2011
9 The Free Software Foundation, Inc.
11 Written by:
12 Miguel de Icaza, 1994, 1995, 1996
13 Janne Kukonlehto, 1994, 1995, 1996
14 Dugan Porter, 1994, 1995, 1996
15 Jakub Jelinek, 1994, 1995, 1996
16 Mauricio Plaza, 1994, 1995, 1996
18 The file_date routine is mostly from GNU's fileutils package,
19 written by Richard Stallman and David MacKenzie.
21 This file is part of the Midnight Commander.
23 The Midnight Commander is free software: you can redistribute it
24 and/or modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation, either version 3 of the License,
26 or (at your option) any later version.
28 The Midnight Commander is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program. If not, see <http://www.gnu.org/licenses/>.
37 /** \file
38 * \brief Source: hooks
41 #include <config.h>
43 #include "lib/global.h"
44 #include "lib/hook.h"
46 /*** global variables ****************************************************************************/
48 /*** file scope macro definitions ****************************************************************/
50 /*** file scope type declarations ****************************************************************/
52 /*** file scope variables ************************************************************************/
54 /*** file scope functions ************************************************************************/
56 /* --------------------------------------------------------------------------------------------- */
57 /*** public functions ****************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
60 void
61 add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data)
63 hook_t *new_hook = g_new (hook_t, 1);
65 new_hook->hook_fn = hook_fn;
66 new_hook->next = *hook_list;
67 new_hook->hook_data = data;
69 *hook_list = new_hook;
72 /* --------------------------------------------------------------------------------------------- */
74 void
75 execute_hooks (hook_t * hook_list)
77 hook_t *new_hook = NULL;
78 hook_t *p;
80 /* We copy the hook list first so tahat we let the hook
81 * function call delete_hook
84 while (hook_list != NULL)
86 add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
87 hook_list = hook_list->next;
89 p = new_hook;
91 while (new_hook != NULL)
93 new_hook->hook_fn (new_hook->hook_data);
94 new_hook = new_hook->next;
97 for (hook_list = p; hook_list != NULL;)
99 p = hook_list;
100 hook_list = hook_list->next;
101 g_free (p);
105 /* --------------------------------------------------------------------------------------------- */
107 void
108 delete_hook (hook_t ** hook_list, void (*hook_fn) (void *))
110 hook_t *new_list = NULL;
111 hook_t *current, *next;
113 for (current = *hook_list; current != NULL; current = next)
115 next = current->next;
116 if (current->hook_fn == hook_fn)
117 g_free (current);
118 else
119 add_hook (&new_list, current->hook_fn, current->hook_data);
121 *hook_list = new_list;
124 /* --------------------------------------------------------------------------------------------- */
126 gboolean
127 hook_present (hook_t * hook_list, void (*hook_fn) (void *))
129 hook_t *p;
131 for (p = hook_list; p != NULL; p = p->next)
132 if (p->hook_fn == hook_fn)
133 return TRUE;
134 return FALSE;
137 /* --------------------------------------------------------------------------------------------- */