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
37 #ifdef HAVE_LIBDMALLOC
41 /*! \todo Finish function documentation!!!
43 * \par Function Description
46 SCM
g_funcs_print(SCM filename
)
48 SCM_ASSERT (scm_is_string (filename
), filename
,
49 SCM_ARG1
, "gschem-print");
51 if (output_filename
) {
52 if (f_print_file (global_window_current
->toplevel
, output_filename
))
59 filename_chars
= scm_to_locale_string(filename
);
60 scm_dynwind_free(filename_chars
);
62 if (f_print_file(global_window_current
->toplevel
, filename_chars
)) {
72 /*! \todo Finish function documentation!!!
74 * \par Function Description
77 SCM
g_funcs_postscript(SCM filename
)
79 SCM_ASSERT (scm_is_string (filename
), filename
,
80 SCM_ARG1
, "gschem-postscript");
82 if (output_filename
) {
83 if (f_print_file (global_window_current
->toplevel
, output_filename
))
90 filename_chars
= scm_to_locale_string(filename
);
91 scm_dynwind_free(filename_chars
);
93 if (f_print_file(global_window_current
->toplevel
, filename_chars
)) {
103 /*! \todo Finish function documentation!!!
105 * \par Function Description
108 SCM
g_funcs_image(SCM filename
)
110 SCM_ASSERT (scm_is_string (filename
), filename
,
111 SCM_ARG1
, "gschem-image");
113 if (output_filename
) {
114 x_image_lowlevel (global_window_current
, output_filename
,
115 global_window_current
->image_width
,
116 global_window_current
->image_height
,
119 char *filename_chars
;
121 scm_dynwind_begin(0);
122 filename_chars
= scm_to_locale_string(filename
);
123 scm_dynwind_free(filename_chars
);
125 x_image_lowlevel(global_window_current
, filename_chars
,
126 global_window_current
->image_width
,
127 global_window_current
->image_height
,
136 /*! \todo Finish function documentation!!!
138 * \par Function Description
141 SCM
g_funcs_exit(void)
146 /*! \todo Finish function documentation!!!
148 * \par Function Description
151 SCM
g_funcs_log(SCM msg
)
155 SCM_ASSERT (scm_is_string (msg
), msg
,
156 SCM_ARG1
, "gschem-log");
158 scm_dynwind_begin(0);
159 msg_chars
= scm_to_locale_string(msg
);
160 scm_dynwind_free(msg_chars
);
162 s_log_message("%s", msg_chars
);
168 /*! \todo Finish function documentation!!!
170 * \par Function Description
173 SCM
g_funcs_msg(SCM msg
)
177 SCM_ASSERT (scm_is_string (msg
), msg
,
178 SCM_ARG1
, "gschem-msg");
180 scm_dynwind_begin(0);
181 msg_chars
= scm_to_locale_string(msg
);
182 scm_dynwind_free(msg_chars
);
184 generic_msg_dialog(msg_chars
);
190 /*! \todo Finish function documentation!!!
192 * \par Function Description
195 SCM
g_funcs_confirm(SCM msg
)
200 SCM_ASSERT (scm_is_string (msg
), msg
,
201 SCM_ARG1
, "gschem-msg");
203 scm_dynwind_begin(0);
204 msg_chars
= scm_to_locale_string(msg
);
205 scm_dynwind_free(msg_chars
);
207 r
= generic_confirm_dialog(msg_chars
);
217 /*! \todo Finish function documentation!!!
219 * \par Function Description
222 SCM
g_funcs_filesel(SCM msg
, SCM templ
, SCM flags
)
224 char *msg_chars
, *templ_chars
;
229 SCM_ASSERT (scm_is_string (msg
), msg
,
230 SCM_ARG1
, "gschem-filesel");
232 SCM_ASSERT (scm_is_string (templ
), templ
,
233 SCM_ARG2
, "gschem-filesel");
235 /*! \bug FIXME -- figure out the magic SCM_ASSERT for the flags */
237 /*! \bug FIXME -- how to deal with conflicting flags?
238 * Should I throw a scheme error? Just deal in the c code?
240 for (c_flags
= 0; scm_pair_p (flags
) == SCM_BOOL_T
; flags
= SCM_CDR (flags
)) {
241 SCM f
= SCM_CAR (flags
);
244 scm_dynwind_begin(0);
245 f_chars
= scm_to_locale_string(f
);
246 scm_dynwind_free(f_chars
);
248 if (strcmp(f_chars
, "may_exist") == 0) {
249 c_flags
|= FSB_MAY_EXIST
;
250 } else if (strcmp(f_chars
, "must_exist") == 0) {
251 c_flags
|= FSB_MUST_EXIST
;
252 } else if (strcmp(f_chars
, "must_not_exist") == 0) {
253 c_flags
|= FSB_SHOULD_NOT_EXIST
;
254 } else if (strcmp(f_chars
, "save") == 0) {
256 } else if (strcmp(f_chars
, "open") == 0) {
259 scm_wrong_type_arg ("gschem-filesel", 1, f
);
265 scm_dynwind_begin(0);
266 msg_chars
= scm_to_locale_string(msg
);
267 templ_chars
= scm_to_locale_string(templ
);
268 scm_dynwind_free(msg_chars
);
269 scm_dynwind_free(templ_chars
);
271 r
= generic_filesel_dialog(msg_chars
, templ_chars
, c_flags
);
275 v
= r
? scm_from_locale_string(r
) : SCM_BOOL_F
;
281 /*! \todo Finish function documentation!!!
283 * \par Function Description
286 SCM
g_funcs_use_rc_values(void)
288 i_vars_freestrings(global_window_current
);
289 i_vars_set(global_window_current
);
293 /*! \todo Finish function documentation!!!
295 * \par Function Description
299 * Gets names from all objects of current page which selected-flags are true.
301 /* all of the declaration part is copied from some other c-code of
303 * I don't really know, whether this all are necessary or not, but
306 hash_table_2_list (gpointer key
,
310 SCM
*plist
= (SCM
*)user_data
;
314 value_scm
= scm_from_locale_string((char const *) value
);
316 value_scm
= SCM_BOOL_F
;
318 *plist
= scm_cons(value_scm
, *plist
);
321 /*! \todo Finish function documentation!!!
323 * \par Function Description
326 SCM
get_selected_component_attributes(GSCHEM_TOPLEVEL
*w_current
)
332 /* build a hash table */
333 ht
= g_hash_table_new (g_str_hash
, g_str_equal
);
334 for (obj
= w_current
->toplevel
->page_current
->object_head
; obj
!= NULL
;
336 if (obj
->selected
&& obj
->type
== OBJ_TEXT
) {
337 const gchar
*str
= o_text_get_string(obj
);
338 if (str
== NULL
) continue;
339 /* add text string in the hash table */
340 g_hash_table_insert (ht
, (gchar
*) str
, (gchar
*) str
);
343 /* now create a scheme list of the entries in the hash table */
344 g_hash_table_foreach (ht
, hash_table_2_list
, &list
);
345 /* and get ride of the hast table */
346 g_hash_table_destroy (ht
);
351 /*! \todo Finish function documentation!!!
352 * \brief Get selected filename of current schematic.
353 * \par Function Description
354 * This function gets the whole filename of the current schematic.
355 * Specifically, the <B>page_filename</B> of the current page.
357 * \param [in] w_current The GSCHEM_TOPLEVEL object to get filename from.
358 * \return whole filename of current schematic.
360 SCM
get_selected_filename(GSCHEM_TOPLEVEL
*w_current
)
364 exit_if_null(w_current
);
366 return_value
= scm_from_locale_string(w_current
->toplevel
->page_current
->page_filename
);
368 return(return_value
);
371 /*! \brief Use gschemdoc to open a browser to a specific wiki page
373 * \param [in] wikiname the name of the wiki page
375 * \par Function Description
376 * Invokes gschemdoc with its -w switch to open a browser to the wiki
377 * page specified by wikiname. If wikiname is empty or not a string,
378 * will browse to the main wiki page.
380 SCM
g_funcs_browse_wiki(SCM wikiname
)
385 /* Extract wiki name string from Scheme value structure.
386 * If not a string, use the empty string */
387 if (scm_is_string (wikiname
)) {
388 /* XXX No need or opportunity to free(3) this due to the exec below. */
389 wikistr
= scm_to_locale_string(wikiname
);
399 /* Fork failed. Still in parent process, so can use the log
401 s_log_message(_("Could not fork\n"));
403 } else if (pid
> 0) {
404 /* Parent process, we're finished here */
408 /* begin daughter process stuff */
410 /* assume gschemdoc is part of path */
411 char *gschemdoc
= "gschemdoc";
412 char *wikiarg
= "-w";
414 execlp(gschemdoc
, gschemdoc
, wikiarg
, wikistr
, NULL
);
416 /* if we return, then nothing happened */
417 fprintf(stderr
, _("Could not invoke %s\n"), gschemdoc
);
420 /* end daughter process stuff */
422 #else /* __MINGW32__ */
423 s_log_message(_("Documentation commands not supported under MinGW.\n"));
425 #endif /* __MINGW32__ */
428 SCM
g_funcs_get_coords(SCM prompt
, SCM continuation
)
430 GtkComboBox
*promptbox
;
436 SCM_ASSERT(scm_is_string(prompt
), prompt
,
437 SCM_ARG1
, "gschem-get-coord");
438 SCM_ASSERT(scm_is_true(scm_procedure_p(continuation
)), continuation
,
439 SCM_ARG2
, "gschem-get-coord");
441 scm_gc_protect_object(continuation
);
446 promptbox
= GTK_COMBO_BOX(global_window_current
->scm_prompts
);
447 model
= GTK_LIST_STORE(gtk_combo_box_get_model(promptbox
));
449 prompt_c
= scm_to_locale_string(prompt
);
450 gtk_list_store_append(model
, &iter
);
451 gtk_list_store_set(model
, &iter
,
452 SCM_PROMPT_MESSAGE
, prompt_c
,
453 SCM_PROMPT_CONTINUATION
, t
,