gsch2pcb: Make --m4-file and -m4-pcbdir arguments work again.
[geda-gaf/peter-b.git] / utils / gschlas / gschlas.c
blobeb6ac4c9e700dbfef63bcaae7e66f04d1c0900d9
1 /* gEDA - GPL Electronic Design Automation
2 * gschlas - gEDA Load and Save
3 * Copyright (C) 2002-2010 Ales Hvezda
4 * Copyright (C) 2002-2010 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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <config.h>
23 #include <stdio.h>
24 #include <sys/stat.h>
25 #ifdef HAVE_STRING_H
26 #include <string.h>
27 #endif
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
32 #include <libgeda/libgeda.h>
34 #include "../include/globals.h"
35 #include "../include/prototype.h"
37 #ifdef HAVE_LIBDMALLOC
38 #include <dmalloc.h>
39 #endif
41 void
42 gschlas_quit(void)
45 s_clib_free();
46 s_slib_free();
50 void
51 main_prog(void *closure, int argc, char *argv[])
53 int i;
54 int argv_index;
55 char *cwd;
57 TOPLEVEL *pr_current;
59 argv_index = parse_commandline(argc, argv);
60 cwd = g_get_current_dir();
62 libgeda_init();
64 /* create log file right away */
65 /* even if logging is enabled */
66 s_log_init ("gschlas");
68 logging_dest=STDOUT_TTY;
70 #if defined(__MINGW32__) && defined(DEBUG)
71 fprintf(stderr, "This is the MINGW32 port.\n");
72 #endif
74 logging_dest=-1; /* don't output to the screen for now */
76 /* register guile (scheme) functions */
77 g_register_funcs();
79 pr_current = s_toplevel_new ();
80 g_rc_parse (pr_current, argv[0], "gschlasrc", rc_filename);
81 i_vars_set(pr_current);
83 i = argv_index;
84 while (argv[i] != NULL) {
86 gchar *filename;
87 GError *err = NULL;
89 if (g_path_is_absolute(argv[i]))
91 /* Path is already absolute so no need to do any concat of cwd */
92 filename = g_strdup (argv[i]);
93 } else {
94 filename = g_build_filename (cwd, argv[i], NULL);
97 s_page_goto (pr_current, s_page_new (pr_current, filename));
99 if (!f_open (pr_current, pr_current->page_current,
100 pr_current->page_current->page_filename, &err)) {
101 /* Not being able to load a file is apparently a fatal error */
102 logging_dest = STDOUT_TTY;
103 g_warning ("%s\n", err->message);
104 g_error_free (err);
105 exit(2);
106 } else {
107 g_message ("Loaded file [%s]\n", filename);
110 i++;
111 g_free (filename);
114 if (argv[argv_index] == NULL) {
115 fprintf(stderr, "\nERROR! You must specify at least one filename\n\n");
116 usage(argv[0]);
119 g_free(cwd);
121 logging_dest=STDOUT_TTY;
123 #if DEBUG
124 s_page_print_all(pr_current);
125 #endif
127 if (!quiet_mode) s_log_message("\n");
129 if (embed_mode) {
130 s_util_embed(pr_current, TRUE);
133 if (unembed_mode) {
134 s_util_embed(pr_current, FALSE);
137 /* save all the opened files */
138 s_page_save_all(pr_current);
140 s_page_delete_list (pr_current);
141 gschlas_quit();
143 exit(0);
146 int
147 main (int argc, char *argv[])
149 /* disable the deprecated warnings in guile 1.6.3 */
150 /* Eventually the warnings will need to be fixed */
151 if(getenv("GUILE_WARN_DEPRECATED")==NULL)
152 putenv("GUILE_WARN_DEPRECATED=no");
154 scm_boot_guile (argc, argv, main_prog, NULL);
155 return 0;