Some WIDGET-related stuff moved to lib/widget directory
[midnight-commander/osp/vavradav.git] / lib / hook.c
blobfd5797dfa651689230b12538b819521c6abe4fcd
1 /* Hooks
2 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
4 Written 1994, 1995, 1996 by:
5 Miguel de Icaza, Janne Kukonlehto, Dugan Porter,
6 Jakub Jelinek, Mauricio Plaza.
8 The file_date routine is mostly from GNU's fileutils package,
9 written by Richard Stallman and David MacKenzie.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
25 /** \file
26 * \brief Source: hooks
29 #include <config.h>
31 #include "lib/global.h"
32 #include "lib/hook.h"
34 /*** global variables ****************************************************************************/
36 /*** file scope macro definitions ****************************************************************/
38 /*** file scope type declarations ****************************************************************/
40 /*** file scope variables ************************************************************************/
42 /*** file scope functions ************************************************************************/
44 /* --------------------------------------------------------------------------------------------- */
45 /*** public functions ****************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
48 void
49 add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data)
51 hook_t *new_hook = g_new (hook_t, 1);
53 new_hook->hook_fn = hook_fn;
54 new_hook->next = *hook_list;
55 new_hook->hook_data = data;
57 *hook_list = new_hook;
60 /* --------------------------------------------------------------------------------------------- */
62 void
63 execute_hooks (hook_t * hook_list)
65 hook_t *new_hook = NULL;
66 hook_t *p;
68 /* We copy the hook list first so tahat we let the hook
69 * function call delete_hook
72 while (hook_list != NULL)
74 add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
75 hook_list = hook_list->next;
77 p = new_hook;
79 while (new_hook != NULL)
81 new_hook->hook_fn (new_hook->hook_data);
82 new_hook = new_hook->next;
85 for (hook_list = p; hook_list != NULL;)
87 p = hook_list;
88 hook_list = hook_list->next;
89 g_free (p);
93 /* --------------------------------------------------------------------------------------------- */
95 void
96 delete_hook (hook_t ** hook_list, void (*hook_fn) (void *))
98 hook_t *new_list = NULL;
99 hook_t *current, *next;
101 for (current = *hook_list; current != NULL; current = next)
103 next = current->next;
104 if (current->hook_fn == hook_fn)
105 g_free (current);
106 else
107 add_hook (&new_list, current->hook_fn, current->hook_data);
109 *hook_list = new_list;
112 /* --------------------------------------------------------------------------------------------- */
114 gboolean
115 hook_present (hook_t * hook_list, void (*hook_fn) (void *))
117 hook_t *p;
119 for (p = hook_list; p != NULL; p = p->next)
120 if (p->hook_fn == hook_fn)
121 return TRUE;
122 return FALSE;
125 /* --------------------------------------------------------------------------------------------- */