(copy_file_file_display_progress): remove dead code.
[midnight-commander.git] / lib / hook.c
blob68b2245311c11d395b8a8e5fd078b52767e2cbd3
1 /*
2 Hooks.
4 Slavaz: Warning! this file is deprecated and should be replaced
5 by mcevents functional.
7 Copyright (C) 1994-2024
8 Free Software Foundation, Inc.
10 Written by:
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/>.
33 /** \file
34 * \brief Source: hooks
37 #include <config.h>
39 #include "lib/global.h"
40 #include "lib/hook.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 /* --------------------------------------------------------------------------------------------- */
56 void
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 /* --------------------------------------------------------------------------------------------- */
70 void
71 execute_hooks (hook_t *hook_list)
73 hook_t *new_hook = NULL;
74 hook_t *p;
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;
85 p = new_hook;
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;)
95 p = hook_list;
96 hook_list = hook_list->next;
97 g_free (p);
101 /* --------------------------------------------------------------------------------------------- */
103 void
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)
113 g_free (current);
114 else
115 add_hook (&new_list, current->hook_fn, current->hook_data);
117 *hook_list = new_list;
120 /* --------------------------------------------------------------------------------------------- */
122 gboolean
123 hook_present (hook_t *hook_list, void (*hook_fn) (void *))
125 hook_t *p;
127 for (p = hook_list; p != NULL; p = p->next)
128 if (p->hook_fn == hook_fn)
129 return TRUE;
130 return FALSE;
133 /* --------------------------------------------------------------------------------------------- */