gattrib
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gattrib -- gEDA component and net attribute manipulation using spreadsheet. 00003 * Copyright (C) 2003-2010 Stuart D. Brorson. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00102 #include <config.h> 00103 #include <version.h> 00104 00105 #ifdef HAVE_UNISTD_H 00106 #include <unistd.h> 00107 #endif 00108 00109 /*------------------------------------------------------------------*/ 00110 /* Includes originally from testgtksheet -- stuff needed to deal with 00111 * spreadsheet widget. 00112 *------------------------------------------------------------------*/ 00113 #include <stdio.h> 00114 #include <stdlib.h> 00115 #include <gtk/gtk.h> 00116 #include <gdk/gdk.h> 00117 #include <gdk/gdkkeysyms.h> 00118 00119 #include <glib.h> 00120 #include <glib-object.h> 00121 00122 #ifdef HAVE_STRING_H 00123 #include <string.h> 00124 #endif 00125 00126 /*------------------------------------------------------------------*/ 00127 /* Gattrib specific includes -- stuff dealing with gattrib data structs. 00128 *------------------------------------------------------------------*/ 00129 #include <libgeda/libgeda.h> /* geda library fcns */ 00130 #include "../include/struct.h" /* typdef and struct declarations */ 00131 #include "../include/prototype.h" /* function prototypes */ 00132 #include "../include/globals.h" 00133 00134 #ifdef HAVE_LIBDMALLOC 00135 #include <dmalloc.h> 00136 #endif 00137 00138 /*------------------------------------------------------------------*/ 00149 gboolean gattrib_really_quit(void) 00150 { 00151 if (sheet_head->CHANGED == TRUE) { 00152 x_dialog_unsaved_data(); 00153 } else { 00154 gattrib_quit(0); 00155 } 00156 return TRUE; 00157 } 00158 00159 /*------------------------------------------------------------------*/ 00168 gint gattrib_quit(gint return_code) 00169 { 00170 /* s_clib_cache_free(); */ 00171 s_clib_free(); 00172 s_slib_free(); 00173 /* s_rename_destroy_all(); */ 00174 #ifdef DEBUG 00175 fflush(stderr); 00176 fflush(stdout); 00177 printf("In gattrib_quit, calling gtk_main_quit()\n"); 00178 #endif 00179 gtk_main_quit(); 00180 exit(return_code); 00181 } 00182 00183 /*------------------------------------------------------------------*/ 00205 void gattrib_main(void *closure, int argc, char *argv[]) 00206 { 00207 /* TOPLEVEL *pr_current is a global */ 00208 /* SHEET_DATA *sheet_head is a global */ 00209 /* GtkWidget *main_window is a global */ 00210 00211 int argv_index; 00212 00213 #ifdef HAVE_GTHREAD 00214 /* Gattrib isn't threaded, but some of GTK's file chooser 00215 * backends uses threading so we need to call g_thread_init(). 00216 * GLib requires threading be initialised before any other GLib 00217 * functions are called. Do it now if its not already setup. */ 00218 if (!g_thread_supported ()) 00219 g_thread_init (NULL); 00220 #endif 00221 00222 /* Initialize gEDA stuff */ 00223 libgeda_init(); 00224 00225 /* Note that argv_index holds index to first non-flag command line option 00226 * (that is, to the first file name) */ 00227 argv_index = parse_commandline(argc, argv); 00228 00229 /* ---------- create log file right away ---------- */ 00230 /* ---------- even if logging is enabled ---------- */ 00231 s_log_init ("gattrib"); 00232 00233 s_log_message 00234 ("gEDA/gattrib version %s%s.%s\n", PREPEND_VERSION_STRING, 00235 PACKAGE_DOTTED_VERSION, PACKAGE_DATE_VERSION); 00236 s_log_message 00237 ("gEDA/gattrib comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\n"); 00238 s_log_message 00239 ("This is free software, and you are welcome to redistribute it under certain\n"); 00240 s_log_message 00241 ("conditions; please see the COPYING file for more details.\n\n"); 00242 00243 /* ------ register guile (scheme) functions. Necessary to parse RC file. ------ */ 00244 g_register_funcs(); 00245 00246 /* ---------- Start creation of new project: (TOPLEVEL *pr_current) ---------- */ 00247 pr_current = s_toplevel_new(); 00248 00249 /* ----- Read in RC files. ----- */ 00250 g_rc_parse (pr_current, argv[0], "gattribrc", NULL); 00251 00252 i_vars_set(pr_current); 00253 00254 gtk_init(&argc, &argv); 00255 00256 x_window_init(); 00257 00258 /* ---------- Initialize SHEET_DATA data structure ---------- */ 00259 sheet_head = s_sheet_data_new(); /* sheet_head was declared in globals.h */ 00260 00261 GSList *file_list = NULL; 00262 if (argv_index >= argc) { 00263 /* No files specified on the command line, pop up the File open dialog. */ 00264 file_list = x_fileselect_open(); 00265 if(file_list == NULL) 00266 exit(0); 00267 } else { 00268 /* Construct the list of filenames from the command line. 00269 * argv_index holds the position of the first filename */ 00270 while (argv_index < argc) { 00271 gchar *filename = f_normalize_filename(argv[argv_index], NULL); 00272 if (filename != NULL) { 00273 file_list = g_slist_append(file_list, filename); 00274 } else { 00275 fprintf(stderr, "Couldn't find file [%s]\n", argv[argv_index]); 00276 exit(1); 00277 } 00278 argv_index++; 00279 } 00280 } 00281 00282 /* Load the files */ 00283 if(x_fileselect_load_files(file_list) == FALSE) { 00284 /* just exit the program */ 00285 exit(1); 00286 } 00287 00288 g_slist_foreach(file_list, (GFunc)g_free, NULL); 00289 g_slist_free(file_list); 00290 00291 gtk_main(); 00292 exit(0); 00293 } 00294 00295 /*------------------------------------------------------------------*/ 00306 int main(int argc, char *argv[]) 00307 { 00308 /* disable the deprecated warnings in guile 1.6.3 */ 00309 /* Eventually the warnings will need to be fixed */ 00310 if(getenv("GUILE_WARN_DEPRECATED")==NULL) 00311 putenv("GUILE_WARN_DEPRECATED=no"); 00312 00313 /* Initialize the Guile Scheme interpreter. This function does not 00314 * return but calls exit(0) on completion. 00315 */ 00316 scm_boot_guile( argc, argv, gattrib_main, NULL); 00317 00318 exit(0); /* This is not real exit point. Real exit is in gattrib_quit. */ 00319 }