Implementation of getting last editing/viewing position of file.
[midnight-commander.git] / lib / hook.c
blob6a921db5cd3f4ec21d96b4d40a2cbed8c497d8f2
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 This file is part of the Midnight Commander.
20 The Midnight Commander is free software: you can redistribute it
21 and/or modify it under the terms of the GNU General Public License as
22 published by the Free Software Foundation, either version 3 of the License,
23 or (at your option) any later version.
25 The Midnight Commander is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
30 You should have received a copy of the GNU General Public License
31 along with this program. If not, see <http://www.gnu.org/licenses/>.
34 /** \file
35 * \brief Source: hooks
38 #include <config.h>
40 #include "lib/global.h"
41 #include "lib/hook.h"
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** file scope variables ************************************************************************/
51 /*** file scope functions ************************************************************************/
53 /* --------------------------------------------------------------------------------------------- */
54 /*** public functions ****************************************************************************/
55 /* --------------------------------------------------------------------------------------------- */
57 void
58 add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data)
60 hook_t *new_hook = g_new (hook_t, 1);
62 new_hook->hook_fn = hook_fn;
63 new_hook->next = *hook_list;
64 new_hook->hook_data = data;
66 *hook_list = new_hook;
69 /* --------------------------------------------------------------------------------------------- */
71 void
72 execute_hooks (hook_t * hook_list)
74 hook_t *new_hook = NULL;
75 hook_t *p;
77 /* We copy the hook list first so tahat we let the hook
78 * function call delete_hook
81 while (hook_list != NULL)
83 add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
84 hook_list = hook_list->next;
86 p = new_hook;
88 while (new_hook != NULL)
90 new_hook->hook_fn (new_hook->hook_data);
91 new_hook = new_hook->next;
94 for (hook_list = p; hook_list != NULL;)
96 p = hook_list;
97 hook_list = hook_list->next;
98 g_free (p);
102 /* --------------------------------------------------------------------------------------------- */
104 void
105 delete_hook (hook_t ** hook_list, void (*hook_fn) (void *))
107 hook_t *new_list = NULL;
108 hook_t *current, *next;
110 for (current = *hook_list; current != NULL; current = next)
112 next = current->next;
113 if (current->hook_fn == hook_fn)
114 g_free (current);
115 else
116 add_hook (&new_list, current->hook_fn, current->hook_data);
118 *hook_list = new_list;
121 /* --------------------------------------------------------------------------------------------- */
123 gboolean
124 hook_present (hook_t * hook_list, void (*hook_fn) (void *))
126 hook_t *p;
128 for (p = hook_list; p != NULL; p = p->next)
129 if (p->hook_fn == hook_fn)
130 return TRUE;
131 return FALSE;
134 /* --------------------------------------------------------------------------------------------- */