missing NULL terminator in set_config_x
[geda-gaf.git] / utils / gschlas / gschlas.c
blob05c0ede466e53b53d4dd6f4b79f4f6bc835a746f
1 /* gEDA - GPL Electronic Design Automation
2 * gschlas - gEDA Load and Save
3 * Copyright (C) 2002-2010 Ales Hvezda
4 * Copyright (C) 2002-2020 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., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02111-1301 USA.
22 #include <config.h>
23 #include <version.h>
26 #include <stdio.h>
27 #include <sys/stat.h>
28 #ifdef HAVE_STRING_H
29 #include <string.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"
40 void
41 gschlas_quit(void)
44 s_clib_free();
45 s_slib_free();
49 /*! \brief The "real" main for gschlas.
51 * This is the main program body for gschlas. A pointer to this
52 * function is passed to scm_boot_guile() at startup.
54 * This function:
55 * - initialises libgeda;
56 * - parses the command line;
57 * - starts logging;
58 * - registers the Scheme functions with Guile;
59 * - parses the RC files;
61 * \param closure
62 * \param argc Number of command line arguments
63 * \param argv Command line arguments
65 void
66 main_prog(void *closure, int argc, char *argv[])
68 int i;
69 int argv_index;
70 char *cwd;
72 TOPLEVEL *pr_current;
74 argv_index = parse_commandline(argc, argv);
75 cwd = g_get_current_dir();
77 libgeda_init();
79 /* create log file right away */
80 /* even if logging is enabled */
81 s_log_init ("gschlas");
83 #if defined(__MINGW32__) && defined(DEBUG)
84 fprintf(stderr, "This is the MINGW32 port.\n");
85 #endif
87 s_log_message
88 ("gEDA/gschlas version %s%s.%s\ngEDA/gschlas comes with ABSOLUTELY NO WARRANTY; see COPYING for more details.\nThis is free software, and you are welcome to redistribute it under certain\nconditions; please see the COPYING file for more details.\n\n",
89 PREPEND_VERSION_STRING, PACKAGE_DOTTED_VERSION,
90 PACKAGE_DATE_VERSION);
92 /* register guile (scheme) functions */
93 g_register_funcs();
95 pr_current = s_toplevel_new ();
96 g_rc_parse (pr_current, argv[0], "gschlasrc", NULL);
97 i_vars_set(pr_current);
99 i = argv_index;
100 while (argv[i] != NULL) {
102 gchar *filename;
103 GError *err = NULL;
105 if (g_path_is_absolute(argv[i]))
107 /* Path is already absolute so no need to do any concat of cwd */
108 filename = g_strdup (argv[i]);
109 } else {
110 filename = g_build_filename (cwd, argv[i], NULL);
113 s_page_goto (pr_current, s_page_new (pr_current, filename));
115 if (!f_open (pr_current, pr_current->page_current,
116 pr_current->page_current->page_filename, &err)) {
117 /* Not being able to load a file is apparently a fatal error */
118 g_warning ("%s\n", err->message);
119 g_error_free (err);
120 exit(2);
121 } else {
122 g_message ("Loaded file [%s]\n", filename);
125 i++;
126 g_free (filename);
129 if (argv[argv_index] == NULL) {
130 fprintf(stderr, "\nERROR! You must specify at least one filename\n\n");
131 usage(argv[0]);
134 g_free(cwd);
135 #if DEBUG
136 s_page_print_all(pr_current);
137 #endif
139 if (!quiet_mode) s_log_message("\n");
141 if (embed_mode) {
142 s_util_embed(pr_current, TRUE);
145 if (unembed_mode) {
146 s_util_embed(pr_current, FALSE);
149 /* save all the opened files */
150 s_page_save_all(pr_current);
152 s_page_delete_list (pr_current);
153 gschlas_quit();
155 exit(0);
158 /*! \brief Entry point to gschlas
160 * This is just a wrapper which invokes the guile stuff, and
161 * points to the real main program main_prog().
163 * \param argc Number of command line arguments
164 * \param argv Command line arguments
167 main (int argc, char *argv[])
169 scm_boot_guile (argc, argv, main_prog, NULL);
170 return 0;