gschem

g_hook.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2011 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 #include <missing.h>
00022 
00023 #include <stdio.h>
00024 #ifdef HAVE_STRING_H
00025 #include <string.h>
00026 #endif
00027 #include <math.h>
00028 
00029 #include "gschem.h"
00030 
00031 #ifdef HAVE_LIBDMALLOC
00032 #include <dmalloc.h>
00033 #endif
00034 
00035 SCM_SYMBOL (at_sym, "@");
00036 SCM_SYMBOL (gschem_sym, "gschem");
00037 SCM_SYMBOL (core_sym, "core");
00038 SCM_SYMBOL (hook_sym, "hook");
00039 SCM_SYMBOL (run_hook_sym, "run-hook");
00040 SCM_SYMBOL (list_sym, "list");
00041 
00050 static SCM
00051 g_get_hook_by_name (const char *name)
00052 {
00053   SCM exp = scm_list_3 (at_sym,
00054                         scm_list_3 (gschem_sym, core_sym, hook_sym),
00055                         scm_from_utf8_symbol (name));
00056   return g_scm_eval_protected (exp, SCM_UNDEFINED);
00057 }
00058 
00069 void
00070 g_run_hook_object_list (GSCHEM_TOPLEVEL *w_current, const char *name,
00071                         GList *obj_lst)
00072 {
00073   SCM lst = SCM_EOL;
00074   GList *iter;
00075 
00076   scm_dynwind_begin (0);
00077   g_dynwind_window (w_current);
00078 
00079   for (iter = obj_lst; iter != NULL; iter = g_list_next (iter)) {
00080     lst = scm_cons (edascm_from_object ((OBJECT *) iter->data), lst);
00081   }
00082   SCM expr = scm_list_3 (run_hook_sym,
00083                          g_get_hook_by_name (name),
00084                          scm_cons (list_sym,
00085                                    scm_reverse_x (lst, SCM_EOL)));
00086 
00087   g_scm_eval_protected (expr, scm_interaction_environment ());
00088   scm_dynwind_end ();
00089   scm_remember_upto_here_1 (expr);
00090 }
00091 
00102 void
00103 g_run_hook_object (GSCHEM_TOPLEVEL *w_current, const char *name, OBJECT *obj)
00104 {
00105   scm_dynwind_begin (0);
00106   g_dynwind_window (w_current);
00107 
00108   SCM expr = scm_list_3 (run_hook_sym,
00109                          g_get_hook_by_name (name),
00110                          scm_list_2 (list_sym, edascm_from_object (obj)));
00111 
00112   g_scm_eval_protected (expr, scm_interaction_environment ());
00113   scm_dynwind_end ();
00114   scm_remember_upto_here_1 (expr);
00115 }
00116 
00125 void
00126 g_run_hook_page (GSCHEM_TOPLEVEL *w_current, const char *name, PAGE *page)
00127 {
00128   scm_dynwind_begin (0);
00129   g_dynwind_window (w_current);
00130 
00131   SCM expr = scm_list_3 (run_hook_sym,
00132                          g_get_hook_by_name (name),
00133                          edascm_from_page (page));
00134 
00135   g_scm_eval_protected (expr, scm_interaction_environment ());
00136   scm_dynwind_end ();
00137   scm_remember_upto_here_1 (expr);
00138 }
00139 
00147 static void
00148 init_module_gschem_core_hook ()
00149 {
00150 
00151 #include "g_hook.x"
00152 
00153 #define DEFINE_HOOK(name) \
00154   do { \
00155     scm_c_define (name, scm_make_hook (scm_from_int (1)));      \
00156     scm_c_export (name, NULL); \
00157   } while (0)
00158 
00159   DEFINE_HOOK ("%add-objects-hook");
00160   DEFINE_HOOK ("%remove-objects-hook");
00161   DEFINE_HOOK ("%move-objects-hook");
00162   DEFINE_HOOK ("%mirror-objects-hook");
00163   DEFINE_HOOK ("%rotate-objects-hook");
00164   DEFINE_HOOK ("%paste-objects-hook");
00165   DEFINE_HOOK ("%attach-attribs-hook");
00166   DEFINE_HOOK ("%detach-attribs-hook");
00167   DEFINE_HOOK ("%select-objects-hook");
00168   DEFINE_HOOK ("%deselect-objects-hook");
00169   DEFINE_HOOK ("%new-page-hook");
00170 }
00171 
00179 void
00180 g_init_hook ()
00181 {
00182   /* Define the (gschem core hook) module */
00183   scm_c_define_module ("gschem core hook",
00184                        init_module_gschem_core_hook,
00185                        NULL);
00186 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines