Bumped versions to 1.1.2/20070818/30:2:0 for the next development snapshot
[geda-gaf/whiteaudio.git] / gschem / src / g_funcs.c
blob231d2f8b4a1b2e868a096fde6f6f927294643e89
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
20 #include <config.h>
22 #include <stdio.h>
23 #include <sys/stat.h>
24 #include <ctype.h>
25 #ifdef HAVE_STRING_H
26 #include <string.h>
27 #endif
28 #ifdef HAVE_STDLIB_H
29 #include <stdlib.h>
30 #endif
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
35 #include <libgeda/libgeda.h>
37 #include "../include/globals.h"
38 #include "../include/prototype.h"
39 #include "../include/x_dialog.h"
41 #ifdef HAVE_LIBDMALLOC
42 #include <dmalloc.h>
43 #endif
45 /*! \todo Finish function documentation!!!
46 * \brief
47 * \par Function Description
50 SCM g_funcs_print(SCM filename)
52 SCM_ASSERT (scm_is_string (filename), filename,
53 SCM_ARG1, "gschem-print");
55 if (output_filename) {
56 if (f_print_file (global_window_current, output_filename))
57 return SCM_BOOL_F;
58 } else {
59 if (f_print_file (global_window_current, SCM_STRING_CHARS (filename)))
60 return SCM_BOOL_F;
63 return SCM_BOOL_T;
66 /*! \todo Finish function documentation!!!
67 * \brief
68 * \par Function Description
71 SCM g_funcs_postscript(SCM filename)
73 SCM_ASSERT (scm_is_string (filename), filename,
74 SCM_ARG1, "gschem-postscript");
76 if (output_filename) {
77 if (f_print_file (global_window_current, output_filename))
78 return SCM_BOOL_F;
79 } else {
80 if (f_print_file (global_window_current, SCM_STRING_CHARS (filename)))
81 return SCM_BOOL_F;
84 return SCM_BOOL_T;
87 /*! \todo Finish function documentation!!!
88 * \brief
89 * \par Function Description
92 SCM g_funcs_image(SCM filename)
94 SCM_ASSERT (scm_is_string (filename), filename,
95 SCM_ARG1, "gschem-image");
97 if (output_filename) {
98 x_image_lowlevel (global_window_current, output_filename,
99 global_window_current->image_width,
100 global_window_current->image_height,
101 "png");
102 } else {
103 x_image_lowlevel (global_window_current, SCM_STRING_CHARS (filename),
104 global_window_current->image_width,
105 global_window_current->image_height,
106 "png");
109 return SCM_BOOL_T;
112 /*! \todo Finish function documentation!!!
113 * \brief
114 * \par Function Description
117 SCM g_funcs_exit(void)
119 exit(0);
122 /*! \todo Finish function documentation!!!
123 * \brief
124 * \par Function Description
127 SCM g_funcs_log(SCM msg)
130 SCM_ASSERT (scm_is_string (msg), msg,
131 SCM_ARG1, "gschem-log");
133 s_log_message (SCM_STRING_CHARS (msg));
135 return SCM_BOOL_T;
138 /*! \todo Finish function documentation!!!
139 * \brief
140 * \par Function Description
143 SCM g_funcs_msg(SCM msg)
146 SCM_ASSERT (scm_is_string (msg), msg,
147 SCM_ARG1, "gschem-msg");
149 generic_msg_dialog (SCM_STRING_CHARS (msg));
151 return SCM_BOOL_T;
154 /*! \todo Finish function documentation!!!
155 * \brief
156 * \par Function Description
159 SCM g_funcs_confirm(SCM msg)
161 int r;
163 SCM_ASSERT (scm_is_string (msg), msg,
164 SCM_ARG1, "gschem-msg");
166 r = generic_confirm_dialog (SCM_STRING_CHARS (msg));
168 if (r)
169 return SCM_BOOL_T;
170 else
171 return SCM_BOOL_F;
174 /*! \todo Finish function documentation!!!
175 * \brief
176 * \par Function Description
179 SCM g_funcs_filesel(SCM msg, SCM templ, SCM flags)
181 int c_flags;
182 char * r;
183 SCM v;
185 SCM_ASSERT (scm_is_string (msg), msg,
186 SCM_ARG1, "gschem-filesel");
188 SCM_ASSERT (scm_is_string (templ), templ,
189 SCM_ARG1, "gschem-filesel");
191 /*! \bug FIXME -- figure out the magic SCM_ASSERT for the flags */
193 /*! \bug FIXME -- how to deal with conflicting flags?
194 * Should I throw a scheme error? Just deal in the c code?
196 for (c_flags = 0; scm_pair_p (flags) == SCM_BOOL_T; flags = SCM_CDR (flags)) {
197 SCM f = SCM_CAR (flags);
198 if (strcmp (SCM_STRING_CHARS (f), "may_exist") == 0) {
199 c_flags |= FSB_MAY_EXIST;
201 } else if (strcmp (SCM_STRING_CHARS (f), "must_exist") == 0) {
202 c_flags |= FSB_MUST_EXIST;
204 } else if (strcmp (SCM_STRING_CHARS (f), "must_not_exist") == 0) {
205 c_flags |= FSB_SHOULD_NOT_EXIST;
207 } else if (strcmp (SCM_STRING_CHARS (f), "save") == 0) {
208 c_flags |= FSB_SAVE;
210 } else if (strcmp (SCM_STRING_CHARS (f), "open") == 0) {
211 c_flags |= FSB_LOAD;
213 } else {
214 scm_wrong_type_arg ("gschem-filesel", 1, f);
218 r = generic_filesel_dialog (SCM_STRING_CHARS (msg),
219 SCM_STRING_CHARS (templ),
220 c_flags
223 v = scm_makfrom0str (r);
224 g_free (r);
226 return v;
229 /*! \todo Finish function documentation!!!
230 * \brief
231 * \par Function Description
234 SCM g_funcs_use_rc_values(void)
236 i_vars_set(global_window_current);
237 return SCM_BOOL_T;
240 /*! \todo Finish function documentation!!!
241 * \brief
242 * \par Function Description
246 * Gets names from all objects of current page which selected-flags are true.
248 /* all of the declaration part is copied from some other c-code of
249 * gEDA gschem.
250 * I don't really know, whether this all are necessary or not, but
251 * it works :-). */
252 static void
253 hash_table_2_list (gpointer key,
254 gpointer value,
255 gpointer user_data)
257 SCM *plist = (SCM*)user_data;
258 *plist = scm_cons (scm_makfrom0str ((char*)value), *plist);
261 /*! \todo Finish function documentation!!!
262 * \brief
263 * \par Function Description
266 SCM get_selected_component_attributes(TOPLEVEL *toplevel)
268 SCM list = SCM_EOL;
269 OBJECT *obj;
270 GHashTable *ht;
272 /* build a hash table */
273 ht = g_hash_table_new (g_str_hash, g_str_equal);
274 for (obj = toplevel->page_current->object_head; obj != NULL;
275 obj = obj->next) {
276 if (obj->selected &&
277 obj->type == OBJ_TEXT &&
278 obj->text->string != NULL) {
279 /* add text string in the hash table */
280 g_hash_table_insert (ht,
281 obj->text->string,
282 obj->text->string);
285 /* now create a scheme list of the entries in the hash table */
286 g_hash_table_foreach (ht, hash_table_2_list, &list);
287 /* and get ride of the hast table */
288 g_hash_table_destroy (ht);
290 return list;
293 /*! \todo Finish function documentation!!!
294 * \brief Get selected filename of current schematic.
295 * \par Function Description
296 * This function gets the whole filename of the current schematic.
297 * Specifically, the <B>page_filename</B> of the current page.
299 * \param [in] w_current The TOPLEVEL object to get filename from.
300 * \return whole filename of current schematic.
302 SCM get_selected_filename(TOPLEVEL *w_current)
304 SCM return_value;
306 exit_if_null(w_current);
308 return_value = scm_take0str (w_current->page_current->page_filename);
310 return(return_value);
313 /*! \brief Use gschemdoc to open a browser to a specific wiki page
315 * \param [in] wikiname the name of the wiki page
317 * \par Function Description
318 * Invokes gschemdoc with its -w switch to open a browser to the wiki
319 * page specified by wikiname. If wikiname is empty or not a string,
320 * will browse to the main wiki page.
322 SCM g_funcs_browse_wiki(SCM wikiname)
324 char *wikistr;
325 int pid;
327 /* Extract wiki name string from Scheme value structure.
328 * If not a string, use the empty string */
329 if (scm_is_string (wikiname)) {
330 wikistr = SCM_STRING_CHARS(wikiname);
331 } else {
332 wikistr = "";
335 #ifndef __MINGW32__
337 pid = fork();
339 if (pid < 0) {
340 /* Fork failed. Still in parent process, so can use the log
341 * window */
342 s_log_message(_("Could not fork\n"));
343 return SCM_BOOL_F;
344 } else if (pid > 0) {
345 /* Parent process, we're finished here */
346 return SCM_BOOL_T;
349 /* begin daughter process stuff */
351 /* assume gschemdoc is part of path */
352 char *gschemdoc = "gschemdoc";
353 char *wikiarg = "-w";
355 execlp(gschemdoc, gschemdoc, wikiarg, wikistr, NULL);
357 /* if we return, then nothing happened */
358 fprintf(stderr, _("Could not invoke %s\n"), gschemdoc);
359 _exit(0);
361 /* end daughter process stuff */
363 #else /* __MINGW32__ */
364 s_log_message(_("Documentation commands not supported under MinGW.\n"));
365 return SCM_BOOL_F;
366 #endif /* __MINGW32__ */