[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gEDA-dev: [PATCH] Implement gschem_atexit()
gschem_atexit() registers a function to be called
just before gschem exits.
---
gschem/include/prototype.h | 2 ++
gschem/src/gschem.c | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
index 617a53e..f79c4ef 100644
--- a/gschem/include/prototype.h
+++ b/gschem/include/prototype.h
@@ -287,6 +287,8 @@ SCM g_rc_select_slack_pixels(SCM pixels);
void g_register_funcs(void);
/* globals.c */
/* gschem.c */
+typedef void (*gschem_atexit_func)(gpointer data);
+void gschem_atexit(gschem_atexit_func func, gpointer data);
void gschem_quit(void);
void main_prog(void *closure, int argc, char *argv[]);
int main(int argc, char *argv[]);
diff --git a/gschem/src/gschem.c b/gschem/src/gschem.c
index 11ec448..c9c8dbb 100644
--- a/gschem/src/gschem.c
+++ b/gschem/src/gschem.c
@@ -45,6 +45,34 @@
void stroke_init(void);
#endif
+typedef struct {
+ gschem_atexit_func func;
+ gpointer arg;
+} gschem_atexit_struct;
+
+static GList *exit_functions = NULL;
+
+/*! \brief Register a function to be called on program exit
+ *
+ * \par Function Description
+ * This function registers a function to be called on
+ * program exit. Multiple functions will be executed in
+ * the order they are registered.
+ *
+ * \param [in] func a pointer to the function to be registered
+ * \param [in] data an arbitrary argument provided to the function
+ * when it is called
+ */
+void gschem_atexit(gschem_atexit_func func, gpointer data)
+{
+ gschem_atexit_struct *p;
+
+ p = g_new(gschem_atexit_struct, 1);
+ p->func = func;
+ p->arg = data;
+ exit_functions = g_list_append(exit_functions, p);
+}
+
/*! \brief Cleanup gSchem on exit.
* \par Function Description
* This function cleans up all memory objects allocated during the
@@ -52,6 +80,19 @@ void stroke_init(void);
*/
void gschem_quit(void)
{
+ GList *list;
+ gschem_atexit_struct *p;
+
+ /* Call all registered functions in order */
+ list = exit_functions;
+ while(list != NULL) {
+ p = (gschem_atexit_struct *) list->data;
+ p->func(p->arg);
+ g_free(p);
+ list = g_list_next(list);
+ }
+ g_list_free(exit_functions);
+
s_clib_free();
s_slib_free();
s_menu_free();
--
1.5.2.1
_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev