gschem
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gschem - gEDA Schematic Capture 00003 * Copyright (C) 1998-2010 Ales Hvezda 00004 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details) 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 #include <config.h> 00021 #include <missing.h> 00022 00023 #include <stdio.h> 00024 #include <sys/stat.h> 00025 #include <ctype.h> 00026 #ifdef HAVE_STRING_H 00027 #include <string.h> 00028 #endif 00029 #ifdef HAVE_STDLIB_H 00030 #include <stdlib.h> 00031 #endif 00032 #ifdef HAVE_UNISTD_H 00033 #include <unistd.h> 00034 #endif 00035 00036 #include "gschem.h" 00037 00038 #ifdef HAVE_LIBDMALLOC 00039 #include <dmalloc.h> 00040 #endif 00041 00047 SCM g_funcs_print(SCM scm_filename) 00048 { 00049 char *filename; 00050 TOPLEVEL *toplevel = edascm_c_current_toplevel (); 00051 00052 SCM_ASSERT (scm_is_string (scm_filename), scm_filename, 00053 SCM_ARG1, "gschem-print"); 00054 00055 if (output_filename) { 00056 if (f_print_file (toplevel, toplevel->page_current, 00057 output_filename)) 00058 return SCM_BOOL_F; 00059 } else { 00060 filename = scm_to_utf8_string(scm_filename); 00061 if (f_print_file (toplevel, toplevel->page_current, filename)) { 00062 free(filename); 00063 return SCM_BOOL_F; 00064 } 00065 free(filename); 00066 } 00067 00068 return SCM_BOOL_T; 00069 } 00070 00076 SCM g_funcs_postscript(SCM scm_filename) 00077 { 00078 char *filename; 00079 TOPLEVEL *toplevel = edascm_c_current_toplevel (); 00080 00081 SCM_ASSERT (scm_is_string (scm_filename), scm_filename, 00082 SCM_ARG1, "gschem-postscript"); 00083 00084 if (output_filename) { 00085 if (f_print_file (toplevel, toplevel->page_current, 00086 output_filename)) 00087 return SCM_BOOL_F; 00088 } else { 00089 filename = scm_to_utf8_string(scm_filename); 00090 if (f_print_file (toplevel, toplevel->page_current, filename)) { 00091 free(filename); 00092 return SCM_BOOL_F; 00093 } 00094 free(filename); 00095 } 00096 00097 return SCM_BOOL_T; 00098 } 00099 00105 SCM g_funcs_image(SCM scm_filename) 00106 { 00107 char *filename; 00108 00109 SCM_ASSERT (scm_is_string (scm_filename), scm_filename, 00110 SCM_ARG1, "gschem-image"); 00111 00112 GSCHEM_TOPLEVEL *w_current = g_current_window (); 00113 00114 if (output_filename) { 00115 x_image_lowlevel (w_current, output_filename, 00116 w_current->image_width, 00117 w_current->image_height, 00118 g_strdup("png")); 00119 } else { 00120 filename = scm_to_utf8_string (scm_filename); 00121 x_image_lowlevel (w_current, filename, 00122 w_current->image_width, 00123 w_current->image_height, 00124 g_strdup("png")); 00125 free(filename); 00126 } 00127 00128 return SCM_BOOL_T; 00129 } 00130 00136 SCM g_funcs_exit(void) 00137 { 00138 exit(0); 00139 } 00140 00146 SCM g_funcs_log(SCM scm_msg) 00147 { 00148 char *msg; 00149 00150 SCM_ASSERT (scm_is_string (scm_msg), scm_msg, 00151 SCM_ARG1, "gschem-log"); 00152 00153 msg = scm_to_utf8_string (scm_msg); 00154 s_log_message ("%s", msg); 00155 free(msg); 00156 00157 return SCM_BOOL_T; 00158 } 00159 00165 SCM g_funcs_msg(SCM scm_msg) 00166 { 00167 char *msg; 00168 00169 SCM_ASSERT (scm_is_string (scm_msg), scm_msg, 00170 SCM_ARG1, "gschem-msg"); 00171 00172 msg = scm_to_utf8_string (scm_msg); 00173 generic_msg_dialog (msg); 00174 free(msg); 00175 00176 return SCM_BOOL_T; 00177 } 00178 00184 SCM g_funcs_confirm(SCM scm_msg) 00185 { 00186 int r; 00187 char *msg; 00188 00189 SCM_ASSERT (scm_is_string (scm_msg), scm_msg, 00190 SCM_ARG1, "gschem-msg"); 00191 00192 msg = scm_to_utf8_string (scm_msg); 00193 r = generic_confirm_dialog (msg); 00194 free(msg); 00195 00196 if (r) 00197 return SCM_BOOL_T; 00198 else 00199 return SCM_BOOL_F; 00200 } 00201 00207 SCM g_funcs_filesel(SCM scm_msg, SCM scm_templ, SCM scm_flags) 00208 { 00209 int c_flags; 00210 char *r, *msg, *templ; 00211 SCM v; 00212 00213 SCM_ASSERT (scm_is_string (scm_msg), scm_msg, 00214 SCM_ARG1, "gschem-filesel"); 00215 00216 SCM_ASSERT (scm_is_string (scm_templ), scm_templ, 00217 SCM_ARG2, "gschem-filesel"); 00218 00224 for (c_flags = 0; scm_is_pair (scm_flags); scm_flags = SCM_CDR (scm_flags)) { 00225 char *flag; 00226 SCM scm_flag = SCM_CAR (scm_flags); 00227 00228 flag = scm_to_utf8_string (scm_flag); 00229 if (strcmp (flag, "may_exist") == 0) { 00230 c_flags |= FSB_MAY_EXIST; 00231 00232 } else if (strcmp (flag, "must_exist") == 0) { 00233 c_flags |= FSB_MUST_EXIST; 00234 00235 } else if (strcmp (flag, "must_not_exist") == 0) { 00236 c_flags |= FSB_SHOULD_NOT_EXIST; 00237 00238 } else if (strcmp (flag, "save") == 0) { 00239 c_flags |= FSB_SAVE; 00240 00241 } else if (strcmp (flag, "open") == 0) { 00242 c_flags |= FSB_LOAD; 00243 00244 } else { 00245 free(flag); 00246 scm_wrong_type_arg ("gschem-filesel", SCM_ARG3, scm_flag); 00247 } 00248 free(flag); 00249 } 00250 00251 scm_dynwind_begin (0); 00252 msg = scm_to_utf8_string (scm_msg); 00253 scm_dynwind_free (msg); 00254 templ = scm_to_utf8_string (scm_templ); 00255 scm_dynwind_free (templ); 00256 00257 r = generic_filesel_dialog (msg, templ, c_flags); 00258 scm_dynwind_unwind_handler (g_free, r, SCM_F_WIND_EXPLICITLY); 00259 00260 v = scm_from_utf8_string (r); 00261 00262 scm_dynwind_end(); 00263 return v; 00264 } 00265 00271 SCM g_funcs_use_rc_values(void) 00272 { 00273 i_vars_set(g_current_window ()); 00274 return SCM_BOOL_T; 00275 }