1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
32 #include <libgeda/libgeda.h>
34 #include "../include/globals.h"
35 #include "../include/i_vars.h"
36 #include "../include/prototype.h"
38 #ifdef HAVE_LIBDMALLOC
47 /* libstroke prototype */
48 void stroke_init(void);
52 gschem_atexit_func func
;
54 } gschem_atexit_struct
;
56 static GList
*exit_functions
= NULL
;
58 /*! \brief Register a function to be called on program exit
60 * \par Function Description
61 * This function registers a function to be called on
62 * program exit. Multiple functions will be executed in
63 * the order they are registered.
65 * \param [in] func a pointer to the function to be registered
66 * \param [in] data an arbitrary argument provided to the function
69 void gschem_atexit(gschem_atexit_func func
, gpointer data
)
71 gschem_atexit_struct
*p
;
73 p
= g_new(gschem_atexit_struct
, 1);
76 exit_functions
= g_list_append(exit_functions
, p
);
79 /*! \brief Cleanup gSchem on exit.
80 * \par Function Description
81 * This function cleans up all memory objects allocated during the
84 void gschem_quit(void)
87 gschem_atexit_struct
*p
;
89 /* Call all registered functions in order */
90 list
= exit_functions
;
92 p
= (gschem_atexit_struct
*) list
->data
;
95 list
= g_list_next(list
);
97 g_list_free(exit_functions
);
102 /* o_text_freeallfonts();*/
106 s_color_destroy_all();
108 /* s_stroke_free(); no longer needed */
112 /* x_window_free_head(); can't do this since it causes a
113 * condition in which window_head->... is still being refered
116 /* enable this to get more memory usage from glib */
117 /* You also have to enable something in glib I think */
118 /* g_mem_profile();*/
124 /*! \brief Main Scheme(GUILE) program function.
125 * \par Function Description
126 * This function is the main program called from scm_boot_guile.
127 * It handles initializing all libraries and gSchem variables
128 * and passes control to the gtk main loop.
130 void main_prog(void *closure
, int argc
, char *argv
[])
134 TOPLEVEL
*w_current
= NULL
;
135 char *input_str
= NULL
;
138 char *geda_data
= NULL
;
143 /* Gschem isn't threaded, but some of GTK's file chooser
144 * backends uses threading so we need to call g_thread_init().
145 * GLib requires threading be initialised before any other GLib
146 * functions are called. Do it now if its not already setup. */
147 if (!g_thread_supported ()) g_thread_init (NULL
);
151 /* this should be equivalent to setlocale (LC_ALL, "") */
154 /* This must be the same for all locales */
155 setlocale(LC_NUMERIC
, "POSIX");
157 /* Disable gtk's ability to set the locale. */
158 /* If gtk is allowed to set the locale, then it will override the */
159 /* setlocale for LC_NUMERIC (which is important for proper PS output. */
160 /* This may look funny here, given we make a call to gtk_set_locale() */
161 /* above. I don't know yet, if this is really the right thing to do. */
162 gtk_disable_setlocale();
166 gtk_init(&argc
, &argv
);
167 visual
= gdk_visual_get_system();
169 argv_index
= parse_commandline(argc
, argv
);
170 cwd
= getcwd(NULL
, 1024);
172 u_basic_strip_trailing(cwd
, G_DIR_SEPARATOR
);
177 /*! \todo Probably the file name shuold be defined elsewhere */
178 /* create log file right away even if logging is enabled */
179 filename
= g_build_path (G_DIR_SEPARATOR_S
,
183 s_log_init (filename
);
187 stroke_init(); /* libstroke function */
188 /* s_stroke_init(); no longer needed libgeda function */
192 _("gEDA/gschem version %s%s.%s\n"), PREPEND_VERSION_STRING
,
193 DOTTED_VERSION
, DATE_VERSION
);
195 _("gEDA/gschem comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n"));
197 _("This is free software, and you are welcome to redistribute it under certain\n"));
199 _("conditions; please see the COPYING file for more details.\n\n"));
203 _("gEDA/gschem version %s%s.%s\n"), PREPEND_VERSION_STRING
,
204 DOTTED_VERSION
, DATE_VERSION
);
206 _("gEDA/gschem comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n"));
208 _("This is free software, and you are welcome to redistribute it under certain\n"));
210 _("conditions; please see the COPYING file for more details.\n\n"));
214 fprintf(stderr
, _("This is the MINGW32 port.\n"));
218 fprintf(stderr
, _("Current locale settings: %s\n"), setlocale(LC_ALL
, NULL
));
221 /* init global buffers */
224 /* register guile (scheme) functions */
229 geda_data
= getenv("GEDADATA");
230 if (geda_data
== NULL
) {
231 fprintf(stderr
, _("You must set the GEDADATA environment variable!\n"));
235 /* Allocate w_current. */
236 w_current
= s_toplevel_new ();
237 global_window_current
= w_current
;
239 /* Now read in RC files. */
241 g_rc_parse(w_current
, "gschemrc", rc_filename
);
243 input_str
= g_strdup_printf("%s%cgschem.scm", default_scheme_directory
,
245 if (g_read_file(input_str
) != -1) {
246 s_log_message(_("Read init scm file [%s]\n"), input_str
);
248 /*! \todo These two messages are the same. Should be
250 s_log_message(_("Failed to read init scm file [%s]\n"),
253 _("Failed to read init scm file [%s]\n"), input_str
);
257 /* Load recent files list. This must be done
258 * before calling x_window_setup(). */
260 gschem_atexit(recent_files_save
, NULL
);
262 /* At end, complete set up of window. */
263 colormap
= gdk_colormap_get_system ();
264 x_window_setup_colors();
265 x_window_setup (w_current
);
267 /* Repaint the background in-case we have to throw up a "restore backup?"
268 * dialog box. Disable grid drawing as there is no page loaded, hence no
269 * scale factor to draw the grid at. (gschem will segfault otherwise.)
271 save_grid
= w_current
->grid
;
272 w_current
->grid
= FALSE
;
273 x_repaint_background (w_current
);
274 w_current
->grid
= save_grid
;
277 while (argv
[i
] != NULL
) {
280 if (argv
[i
][1] == ':' && (argv
[i
][2] == G_DIR_SEPARATOR
||
281 argv
[i
][2] == OTHER_PATH_SEPARATER_CHAR
))
283 if (argv
[i
][0] == G_DIR_SEPARATOR
)
286 /* Path is already absolute so no need to do any concat of cwd */
287 filename
= g_strdup (argv
[i
]);
289 filename
= g_strconcat (cwd
, G_DIR_SEPARATOR_S
, argv
[i
], NULL
);
296 * SDB notes: at this point the filename might be unnormalized, like
297 * /path/to/foo/../bar/baz.sch. Bad filenames will be normalized in
298 * f_open (called by x_window_open_page). This works for Linux and MINGW32.
300 x_window_open_page(w_current
, filename
);
302 /* Go to the next argument */
306 free(cwd
); /* allocated from getcwd, should be regular free */
308 /* If no page has been loaded (wasn't specified in the command line.) */
309 /* Then create an untitled page */
311 x_window_open_untitled_page( w_current
);
314 /* Update the window to show the current page */
315 x_window_set_current_page( w_current
, w_current
->page_current
);
319 scm_c_eval_string ("(display \"hello guile\n\")");
322 if (w_current
->scheme_directory
== NULL
) {
323 fprintf(stderr
, _("Scheme directory NOT set!\n"));
328 /* Execute a script if it exists */
329 if (script_filename
) {
330 s_log_message(_("Executing guile script [%s]\n"),
332 g_read_file(script_filename
);
335 /* open up log window on startup */
336 if (w_current
->log_window
== MAP_ON_STARTUP
) {
340 /* if there were any symbols which had major changes, put up an error */
342 major_changed_dialog(w_current
);
344 /* enter main loop */
348 /*! \brief Main executable entrance point.
349 * \par Function Description
350 * This is the main function for gSchem. It sets up the Scheme(GUILE)
351 * environment and passes control to via scm_boot_guile to
352 * the #main_prog function.
354 int main (int argc
, char *argv
[])
358 setlocale(LC_ALL
, "");
359 setlocale(LC_NUMERIC
, "POSIX");
360 bindtextdomain(PACKAGE
, LOCALEDIR
);
362 bind_textdomain_codeset(PACKAGE
, "UTF-8");
365 /* disable the deprecated warnings in guile 1.6.3 */
366 /* Eventually the warnings will need to be fixed */
367 if(getenv("GUILE_WARN_DEPRECATED") == NULL
)
368 putenv("GUILE_WARN_DEPRECATED=no");
370 scm_boot_guile (argc
, argv
, main_prog
, 0);