4 Slavaz: Warning! this file is deprecated and should be replaced
5 by mcevents functional.
7 Copyright (C) 1994-2017
8 Free Software Foundation, Inc.
11 Miguel de Icaza, 1994, 1995, 1996
12 Janne Kukonlehto, 1994, 1995, 1996
13 Dugan Porter, 1994, 1995, 1996
14 Jakub Jelinek, 1994, 1995, 1996
15 Mauricio Plaza, 1994, 1995, 1996
17 This file is part of the Midnight Commander.
19 The Midnight Commander is free software: you can redistribute it
20 and/or modify it under the terms of the GNU General Public License as
21 published by the Free Software Foundation, either version 3 of the License,
22 or (at your option) any later version.
24 The Midnight Commander is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
29 You should have received a copy of the GNU General Public License
30 along with this program. If not, see <http://www.gnu.org/licenses/>.
34 * \brief Source: hooks
39 #include "lib/global.h"
42 /*** global variables ****************************************************************************/
44 /*** file scope macro definitions ****************************************************************/
46 /*** file scope type declarations ****************************************************************/
48 /*** file scope variables ************************************************************************/
50 /*** file scope functions ************************************************************************/
52 /* --------------------------------------------------------------------------------------------- */
53 /*** public functions ****************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
57 add_hook (hook_t
** hook_list
, void (*hook_fn
) (void *), void *data
)
59 hook_t
*new_hook
= g_new (hook_t
, 1);
61 new_hook
->hook_fn
= hook_fn
;
62 new_hook
->next
= *hook_list
;
63 new_hook
->hook_data
= data
;
65 *hook_list
= new_hook
;
68 /* --------------------------------------------------------------------------------------------- */
71 execute_hooks (hook_t
* hook_list
)
73 hook_t
*new_hook
= NULL
;
76 /* We copy the hook list first so tahat we let the hook
77 * function call delete_hook
80 while (hook_list
!= NULL
)
82 add_hook (&new_hook
, hook_list
->hook_fn
, hook_list
->hook_data
);
83 hook_list
= hook_list
->next
;
87 while (new_hook
!= NULL
)
89 new_hook
->hook_fn (new_hook
->hook_data
);
90 new_hook
= new_hook
->next
;
93 for (hook_list
= p
; hook_list
!= NULL
;)
96 hook_list
= hook_list
->next
;
101 /* --------------------------------------------------------------------------------------------- */
104 delete_hook (hook_t
** hook_list
, void (*hook_fn
) (void *))
106 hook_t
*new_list
= NULL
;
107 hook_t
*current
, *next
;
109 for (current
= *hook_list
; current
!= NULL
; current
= next
)
111 next
= current
->next
;
112 if (current
->hook_fn
== hook_fn
)
115 add_hook (&new_list
, current
->hook_fn
, current
->hook_data
);
117 *hook_list
= new_list
;
120 /* --------------------------------------------------------------------------------------------- */
123 hook_present (hook_t
* hook_list
, void (*hook_fn
) (void *))
127 for (p
= hook_list
; p
!= NULL
; p
= p
->next
)
128 if (p
->hook_fn
== hook_fn
)
133 /* --------------------------------------------------------------------------------------------- */