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. */
26 * \brief Source: hooks
31 #include "lib/global.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 /* --------------------------------------------------------------------------------------------- */
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 /* --------------------------------------------------------------------------------------------- */
63 execute_hooks (hook_t
* hook_list
)
65 hook_t
*new_hook
= NULL
;
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
;
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
;)
88 hook_list
= hook_list
->next
;
93 /* --------------------------------------------------------------------------------------------- */
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
)
107 add_hook (&new_list
, current
->hook_fn
, current
->hook_data
);
109 *hook_list
= new_list
;
112 /* --------------------------------------------------------------------------------------------- */
115 hook_present (hook_t
* hook_list
, void (*hook_fn
) (void *))
119 for (p
= hook_list
; p
!= NULL
; p
= p
->next
)
120 if (p
->hook_fn
== hook_fn
)
125 /* --------------------------------------------------------------------------------------------- */