libgeda: Remove some exit() calls and assertions.
[geda-gaf/peter-b.git] / libgeda / src / scheme_toplevel.c
blob77745229c74b0cf7f407007f6e7da3167b47626b
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library - Scheme API
3 * Copyright (C) 2010 Peter Brett <peter@peter-b.co.uk>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 /*!
21 * \file scheme_toplevel.c
22 * \brief Scheme API procedures for working with the TOPLEVEL.
25 #include <config.h>
27 #include "libgeda_priv.h"
28 #include "libgedaguile_priv.h"
30 SCM scheme_toplevel_fluid = SCM_UNDEFINED;
32 /*!
33 * \brief Set the #TOPLEVEL fluid in the current dynamic context.
34 * \par Function Description
35 * This function must be used inside a pair of calls to
36 * scm_dynwind_begin() and scm_dynwind_end(). During the dynwind
37 * context, the #TOPLEVEL fluid is set to \a toplevel.
39 * \note This is a part of the public C interface to the Scheme API.
41 void
42 edascm_dynwind_toplevel (TOPLEVEL *toplevel)
44 SCM s_toplevel = edascm_from_toplevel (toplevel);
46 scm_dynwind_fluid (scheme_toplevel_fluid, s_toplevel);
49 /*!
50 * \brief Get the value of the #TOPLEVEL fluid.
51 * \par Function Description
52 * Return the value of the #TOPLEVEL fluid in the current dynamic
53 * context.
55 SCM_DEFINE (edascm_current_toplevel, "%current-toplevel", 0, 0, 0,
56 (),
57 "Get the TOPLEVEL for the current dynamic context.")
59 return scm_fluid_ref (scheme_toplevel_fluid);
62 /*!
63 * \brief Get the value of the #TOPLEVEL fluid.
64 * \par Function Description
65 * Return the value of the #TOPLEVEL fluid in the current dynamic
66 * context.
68 * \note This is a part of the public C interface to the Scheme API.
70 TOPLEVEL *
71 edascm_c_current_toplevel ()
73 SCM s_toplevel = edascm_current_toplevel ();
75 EDASCM_ASSERT_SMOB_VALID(s_toplevel);
77 return (TOPLEVEL *) SCM_SMOB_DATA (s_toplevel);
80 /*!
81 * \brief Set the current #TOPLEVEL temporarily.
82 * \par Function Description
83 * Set the #TOPLEVEL fluid to \a toplevel and call \a thunk.
85 SCM_DEFINE (edascm_with_toplevel, "%with-toplevel", 2, 0, 0,
86 (SCM toplevel, SCM thunk),
87 "Call `thunk', setting the TOPLEVEL fluid to `toplevel'.")
89 return scm_with_fluid (scheme_toplevel_fluid, toplevel, thunk);
92 /*!
93 * \brief Set the current #TOPLEVEL temporarily.
94 * \par Function Description
95 * Set the #TOPLEVEL fluid to \a toplevel and call \a func with \a
96 * user_data.
98 SCM
99 edascm_c_with_toplevel (TOPLEVEL *toplevel, SCM (*func)(void *),
100 void *user_data)
102 SCM s_toplevel = edascm_from_toplevel (toplevel);
103 return scm_c_with_fluid (scheme_toplevel_fluid, s_toplevel, func, user_data);
107 * \brief Create the (geda core toplevel) Scheme module
108 * \par Function Description
109 * Defines procedures in the (geda core toplevel) module. The module
110 * can be accessed using (use-modules (geda core toplevel)).
112 static void
113 init_module_geda_core_toplevel ()
115 /* Register the functions */
116 #include "scheme_toplevel.x"
118 /* Add them to the module's public definitions. */
119 scm_c_export (s_edascm_with_toplevel, s_edascm_current_toplevel, NULL);
123 * \brief Initialise the TOPLEVEL manipulation procedures.
124 * \par Function Description
125 * Registers some Scheme procedures for working with #TOPLEVEL smobs
126 * and creates the #TOPLEVEL fluid. Should only be called by
127 * scheme_api_init().
129 void
130 edascm_init_toplevel ()
132 scheme_toplevel_fluid = scm_permanent_object (scm_make_fluid ());
134 /* Define the (geda core toplevel) module */
135 scm_c_define_module ("geda core toplevel",
136 init_module_geda_core_toplevel,
137 NULL);