libgeda: Remove some exit() calls and assertions.
[geda-gaf/peter-b.git] / libgeda / src / s_toplevel.c
blob940310a97dc4a45010bc3bd9af0efa6e0824baf6
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda
4 * Copyright (C) 1998-2010 Ales Hvezda
5 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <config.h>
23 #include <stdio.h>
24 #ifdef HAVE_STRING_H
25 #include <string.h>
26 #endif
27 #ifdef HAVE_STDLIB_H
28 #include <stdlib.h>
29 #endif
31 #include "libgeda_priv.h"
33 #ifdef HAVE_LIBDMALLOC
34 #include <dmalloc.h>
35 #endif
37 /*! \todo Finish function documentation!!!
38 * \brief
39 * \par Function Description
42 TOPLEVEL *s_toplevel_new (void)
44 TOPLEVEL *toplevel;
46 toplevel = (TOPLEVEL*)g_new (TOPLEVEL, 1);
48 toplevel->RC_list = NULL;
50 toplevel->untitled_name = NULL;
51 toplevel->bitmap_directory = NULL;
53 toplevel->init_left = 0;
54 toplevel->init_top = 0;
55 /* init_right and _bottom are set before this function is called */
57 toplevel->width = 1;
58 toplevel->height = 1;
60 toplevel->override_color = -1;
62 toplevel->pages = geda_list_new();
63 toplevel->page_current = NULL;
65 toplevel->show_hidden_text = 0;
67 toplevel->major_changed_refdes = NULL;
69 /* BLOCK SET IN GSCHEM, BUT USED IN LIBGEDA - NEEDS A RETHINK */
70 toplevel->background_color = 0;
71 toplevel->override_net_color = -1;
72 toplevel->override_bus_color = -1;
73 toplevel->override_pin_color = -1;
74 toplevel->pin_style = 0;
75 toplevel->net_style = 0;
76 toplevel->bus_style = 0;
77 toplevel->line_style = 0;
78 /* END BLOCK - ALTHOUGH THERE ARE MORE CASES! */
80 toplevel->object_clipping = 0;
82 toplevel->print_orientation = 0;
84 toplevel->image_color = FALSE;
86 toplevel->print_color = FALSE;
88 toplevel->print_color_background = 0;
90 toplevel->setpagedevice_orientation = FALSE;
92 toplevel->setpagedevice_pagesize = FALSE;
94 toplevel->postscript_prolog = NULL;
96 toplevel->net_consolidate = FALSE;
98 /* The following is an attempt at getting (deterministic) defaults */
99 /* for the following variables */
100 toplevel->attribute_promotion = FALSE;
101 toplevel->promote_invisible = FALSE;
102 toplevel->keep_invisible = FALSE;
104 toplevel->print_output_type = 0;
106 toplevel->print_output_capstyle = BUTT_CAP;
108 toplevel->paper_width = 0;
109 toplevel->paper_height = 0;
111 toplevel->bus_ripper_symname = NULL;
113 toplevel->force_boundingbox = FALSE;
115 toplevel->always_promote_attributes = NULL;
117 toplevel->net_naming_priority = 0;
118 toplevel->hierarchy_traversal = 0;
119 toplevel->hierarchy_uref_mangle = 0;
120 toplevel->hierarchy_netname_mangle = 0;
121 toplevel->hierarchy_netattrib_mangle = 0;
122 toplevel->hierarchy_uref_separator = NULL;
123 toplevel->hierarchy_netname_separator = NULL;
124 toplevel->hierarchy_netattrib_separator = NULL;
125 toplevel->hierarchy_netattrib_order = 0;
126 toplevel->hierarchy_netname_order = 0;
127 toplevel->hierarchy_uref_order = 0;
128 toplevel->unnamed_netname = NULL;
129 toplevel->unnamed_busname = NULL;
131 toplevel->rendered_text_bounds_func = NULL;
132 toplevel->rendered_text_bounds_data = NULL;
134 toplevel->change_notify_funcs = NULL;
136 toplevel->load_newer_backup_func = NULL;
137 toplevel->load_newer_backup_data = NULL;
139 /* Auto-save interval */
140 toplevel->auto_save_interval = 0;
141 toplevel->auto_save_timeout = 0;
143 toplevel->weak_refs = NULL;
144 return toplevel;
147 /*! \todo Finish function documentation!!!
148 * \brief
149 * \par Function Description
152 void s_toplevel_delete (TOPLEVEL *toplevel)
154 GList *iter;
156 if (toplevel->auto_save_timeout != 0) {
157 /* Assume this works */
158 g_source_remove (toplevel->auto_save_timeout);
161 g_free (toplevel->untitled_name);
162 g_free (toplevel->bitmap_directory);
163 g_free (toplevel->bus_ripper_symname);
165 /* free all fonts */
166 /* if you close a window, then you free the font set... */
167 /* this is probably a bad idea... */
168 /* The font set can ONLY be freed when exiting!!! */
169 /* o_text_freeallfonts (toplevel); */
171 /* delete all pages */
172 s_page_delete_list (toplevel);
174 /* Delete the page list */
175 g_object_unref(toplevel->pages);
177 /* Remove all change notification handlers */
178 for (iter = toplevel->change_notify_funcs;
179 iter != NULL; iter = g_list_next (iter)) {
180 g_free (iter->data);
182 g_list_free (toplevel->change_notify_funcs);
184 s_weakref_notify (toplevel, toplevel->weak_refs);
186 g_free (toplevel);
190 /*! \brief Add a weak reference watcher to an TOPLEVEL.
191 * \par Function Description
192 * Adds the weak reference callback \a notify_func to \a toplevel. When
193 * \a toplevel is destroyed, \a notify_func will be called with two
194 * arguments: the \a toplevel, and the \a user_data.
196 * \sa s_toplevel_weak_unref
198 * \param [in,out] toplevel Toplevel to weak-reference.
199 * \param [in] notify_func Weak reference notify function.
200 * \param [in] user_data Data to be passed to \a notify_func.
202 void
203 s_toplevel_weak_ref (TOPLEVEL *toplevel,
204 void (*notify_func)(void *, void *),
205 void *user_data)
207 g_return_if_fail (toplevel != NULL);
208 toplevel->weak_refs = s_weakref_add (toplevel->weak_refs,
209 notify_func, user_data);
212 /*! \brief Remove a weak reference watcher from an TOPLEVEL.
213 * \par Function Description
214 * Removes the weak reference callback \a notify_func from \a toplevel.
216 * \sa s_toplevel_weak_ref()
218 * \param [in,out] toplevel Toplevel to weak-reference.
219 * \param [in] notify_func Notify function to search for.
220 * \param [in] user_data Data to to search for.
222 void
223 s_toplevel_weak_unref (TOPLEVEL *toplevel,
224 void (*notify_func)(void *, void *),
225 void *user_data)
227 g_return_if_fail (toplevel != NULL);
228 toplevel->weak_refs = s_weakref_remove (toplevel->weak_refs,
229 notify_func, user_data);
232 /*! \brief Add a weak pointer to an TOPLEVEL.
233 * \par Function Description
234 * Adds the weak pointer at \a weak_pointer_loc to \a toplevel. The
235 * value of \a weak_pointer_loc will be set to NULL when \a toplevel is
236 * destroyed.
238 * \sa s_toplevel_remove_weak_ptr
240 * \param [in,out] toplevel Toplevel to weak-reference.
241 * \param [in] weak_pointer_loc Memory address of a pointer.
243 void
244 s_toplevel_add_weak_ptr (TOPLEVEL *toplevel,
245 void *weak_pointer_loc)
247 g_return_if_fail (toplevel != NULL);
248 toplevel->weak_refs = s_weakref_add_ptr (toplevel->weak_refs,
249 weak_pointer_loc);
252 /*! \brief Remove a weak pointer from an TOPLEVEL.
253 * \par Function Description
254 * Removes the weak pointer at \a weak_pointer_loc from \a toplevel.
256 * \sa s_toplevel_add_weak_ptr()
258 * \param [in,out] toplevel Toplevel to weak-reference.
259 * \param [in] weak_pointer_loc Memory address of a pointer.
261 void
262 s_toplevel_remove_weak_ptr (TOPLEVEL *toplevel,
263 void *weak_pointer_loc)
265 g_return_if_fail (toplevel != NULL);
266 toplevel->weak_refs = s_weakref_remove_ptr (toplevel->weak_refs,
267 weak_pointer_loc);