root/lib/hook.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. add_hook
  2. execute_hooks
  3. delete_hook
  4. hook_present

   1 /*
   2    Hooks.
   3 
   4    Slavaz: Warning! this file is deprecated and should be replaced
   5    by mcevents functional.
   6 
   7    Copyright (C) 1994-2019
   8    Free Software Foundation, Inc.
   9 
  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
  16 
  17    This file is part of the Midnight Commander.
  18 
  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.
  23 
  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.
  28 
  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/>.
  31  */
  32 
  33 /** \file
  34  *  \brief Source: hooks
  35  */
  36 
  37 #include <config.h>
  38 
  39 #include "lib/global.h"
  40 #include "lib/hook.h"
  41 
  42 /*** global variables ****************************************************************************/
  43 
  44 /*** file scope macro definitions ****************************************************************/
  45 
  46 /*** file scope type declarations ****************************************************************/
  47 
  48 /*** file scope variables ************************************************************************/
  49 
  50 /*** file scope functions ************************************************************************/
  51 
  52 /* --------------------------------------------------------------------------------------------- */
  53 /*** public functions ****************************************************************************/
  54 /* --------------------------------------------------------------------------------------------- */
  55 
  56 void
  57 add_hook (hook_t ** hook_list, void (*hook_fn) (void *), void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     hook_t *new_hook = g_new (hook_t, 1);
  60 
  61     new_hook->hook_fn = hook_fn;
  62     new_hook->next = *hook_list;
  63     new_hook->hook_data = data;
  64 
  65     *hook_list = new_hook;
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 void
  71 execute_hooks (hook_t * hook_list)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     hook_t *new_hook = NULL;
  74     hook_t *p;
  75 
  76     /* We copy the hook list first so tahat we let the hook
  77      * function call delete_hook
  78      */
  79 
  80     while (hook_list != NULL)
  81     {
  82         add_hook (&new_hook, hook_list->hook_fn, hook_list->hook_data);
  83         hook_list = hook_list->next;
  84     }
  85     p = new_hook;
  86 
  87     while (new_hook != NULL)
  88     {
  89         new_hook->hook_fn (new_hook->hook_data);
  90         new_hook = new_hook->next;
  91     }
  92 
  93     for (hook_list = p; hook_list != NULL;)
  94     {
  95         p = hook_list;
  96         hook_list = hook_list->next;
  97         g_free (p);
  98     }
  99 }
 100 
 101 /* --------------------------------------------------------------------------------------------- */
 102 
 103 void
 104 delete_hook (hook_t ** hook_list, void (*hook_fn) (void *))
     /* [previous][next][first][last][top][bottom][index][help]  */
 105 {
 106     hook_t *new_list = NULL;
 107     hook_t *current, *next;
 108 
 109     for (current = *hook_list; current != NULL; current = next)
 110     {
 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);
 116     }
 117     *hook_list = new_list;
 118 }
 119 
 120 /* --------------------------------------------------------------------------------------------- */
 121 
 122 gboolean
 123 hook_present (hook_t * hook_list, void (*hook_fn) (void *))
     /* [previous][next][first][last][top][bottom][index][help]  */
 124 {
 125     hook_t *p;
 126 
 127     for (p = hook_list; p != NULL; p = p->next)
 128         if (p->hook_fn == hook_fn)
 129             return TRUE;
 130     return FALSE;
 131 }
 132 
 133 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */