utils

gschlas.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschlas - gEDA Load and Save
00003  * Copyright (C) 2002-2010 Ales Hvezda
00004  * Copyright (C) 2002-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,
00019  * MA 02111-1301 USA.
00020  */
00021 
00022 #include <config.h>
00023 
00024 #include <stdio.h>
00025 #include <sys/stat.h>
00026 #ifdef HAVE_STRING_H
00027 #include <string.h>
00028 #endif
00029 #ifdef HAVE_UNISTD_H
00030 #include <unistd.h>
00031 #endif
00032 
00033 #include <libgeda/libgeda.h>
00034 
00035 #include "../include/globals.h"
00036 #include "../include/prototype.h"
00037 
00038 #ifdef HAVE_LIBDMALLOC
00039 #include <dmalloc.h>
00040 #endif
00041 
00042 void
00043 gschlas_quit(void)
00044 {
00045   
00046   s_clib_free();
00047   s_slib_free();
00048 
00049 }
00050 
00051 void 
00052 main_prog(void *closure, int argc, char *argv[])
00053 {
00054   int i;
00055   int argv_index;
00056   char *cwd;
00057   
00058   TOPLEVEL *pr_current;
00059 
00060   argv_index = parse_commandline(argc, argv);
00061   cwd = g_get_current_dir();
00062 
00063   libgeda_init();
00064 
00065   /* create log file right away */
00066   /* even if logging is enabled */
00067   s_log_init ("gschlas");
00068     
00069   logging_dest=STDOUT_TTY;
00070 
00071 #if defined(__MINGW32__) && defined(DEBUG)
00072   fprintf(stderr, "This is the MINGW32 port.\n");
00073 #endif  
00074 
00075   logging_dest=-1; /* don't output to the screen for now */
00076   
00077   /* register guile (scheme) functions */
00078   g_register_funcs();
00079 
00080   pr_current = s_toplevel_new ();
00081   g_rc_parse (pr_current, argv[0], "gschlasrc", rc_filename);
00082   i_vars_set(pr_current);
00083   
00084   i = argv_index;
00085   while (argv[i] != NULL) {
00086 
00087     gchar *filename;
00088     GError *err = NULL;
00089 
00090     if (g_path_is_absolute(argv[i]))
00091     {
00092       /* Path is already absolute so no need to do any concat of cwd */
00093       filename = g_strdup (argv[i]);
00094     } else {
00095       filename = g_build_filename (cwd, argv[i], NULL);
00096     }
00097 
00098     s_page_goto (pr_current, s_page_new (pr_current, filename));
00099 
00100     if (!f_open (pr_current, pr_current->page_current,
00101                  pr_current->page_current->page_filename, &err)) {
00102       /* Not being able to load a file is apparently a fatal error */
00103       logging_dest = STDOUT_TTY;
00104       g_warning ("%s\n", err->message);
00105       g_error_free (err);
00106       exit(2);
00107     } else {
00108       g_message ("Loaded file [%s]\n", filename);
00109     }
00110 
00111     i++;
00112     g_free (filename);
00113   }
00114 
00115   if (argv[argv_index] == NULL) {
00116     fprintf(stderr, "\nERROR! You must specify at least one filename\n\n");
00117     usage(argv[0]);
00118   }
00119 
00120   g_free(cwd);
00121 
00122   logging_dest=STDOUT_TTY;
00123 
00124 #if DEBUG 
00125   s_page_print_all(pr_current);
00126 #endif
00127   
00128   if (!quiet_mode) s_log_message("\n");
00129 
00130   if (embed_mode) {
00131     s_util_embed(pr_current, TRUE);
00132   }
00133 
00134   if (unembed_mode) {
00135     s_util_embed(pr_current, FALSE);
00136   } 
00137 
00138   /* save all the opened files */
00139   s_page_save_all(pr_current);
00140 
00141   s_page_delete_list (pr_current);
00142   gschlas_quit();
00143 
00144   exit(0);
00145 }
00146 
00147 int 
00148 main (int argc, char *argv[])
00149 {
00150   /* disable the deprecated warnings in guile 1.6.3 */
00151   /* Eventually the warnings will need to be fixed */
00152   if(getenv("GUILE_WARN_DEPRECATED")==NULL)
00153     putenv("GUILE_WARN_DEPRECATED=no");
00154 
00155   scm_boot_guile (argc, argv, main_prog, NULL);
00156   return 0;
00157 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines