1 /* gEDA - GPL Electronic Design Automation
2 * gnetlist - gEDA Netlist
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 #include <libgeda/libgeda.h>
39 #include "../include/globals.h"
40 #include "../include/prototype.h"
41 #include "../include/gettext.h"
43 #ifdef HAVE_LIBDMALLOC
47 #define OPTIONS "c:g:hil:L:m:o:O:qvV"
49 #ifndef OPTARG_IN_UNISTD
55 /* Added by SDB 3.3.2006. */
56 #ifdef HAVE_GETOPT_LONG
57 struct option long_options
[] =
60 {"list-backends", 0, &list_backends
, TRUE
},
61 {"verbose", 0, 0, 'v'},
62 {"version", 0, 0, 'V'},
72 "Usage: %s [OPTION ...] [-g BACKEND] [--] FILE ...\n"
74 "Generate a netlist from one or more gEDA schematic FILEs.\n"
78 " -v, --verbose Verbose mode.\n"
79 " -o FILE Filename for netlist data output.\n"
80 " -L DIR Add DIR to Scheme search path.\n"
81 " -g BACKEND Specify netlist backend to use.\n"
82 " -O STRING Pass an option string to backend.\n"
83 " -l FILE Load Scheme file before loading backend.\n"
84 " -m FILE Load Scheme file after loading backend.\n"
85 " -c EXPR Evaluate Scheme expression at startup.\n"
86 " -i Enter interactive Scheme REPL after loading.\n"
87 " --list-backends Print a list of available netlist backends.\n"
88 " -h, --help Help; this message.\n"
89 " -V, --version Show version information.\n"
90 " -- Treat all remaining arguments as filenames.\n"
92 "Report bugs at <https://bugs.launchpad.net/geda>\n"
93 "gEDA/gaf homepage: <http://www.geda-project.org/>\n"),
98 /*! \brief Print version info and exit.
99 * \par Function Description
100 * Print gEDA version, and copyright/warranty notices, and exit with
108 "Copyright (C) 1998-2012 gEDA developers\n"
109 "This is free software, and you are welcome to redistribute it under\n"
110 "certain conditions. For details, see the file `COPYING', which is\n"
111 "included in the gEDA distribution.\n"
112 "There is NO WARRANTY, to the extent permitted by law.\n"),
113 PACKAGE_DOTTED_VERSION
, PACKAGE_GIT_COMMIT
);
117 /* from guile (libguile/gh_init.c) */
119 catch_handler (void *data
, SCM tag
, SCM throw_args
)
121 fprintf (stderr
, _("\nJust got an error; tag is\n "));
122 scm_display (tag
, scm_current_output_port ());
123 scm_newline (scm_current_output_port ());
124 scm_newline (scm_current_output_port ());
130 parse_commandline (int argc
, char *argv
[])
133 SCM sym_begin
= scm_from_utf8_symbol ("begin");
134 SCM sym_cons
= scm_from_utf8_symbol ("cons");
135 SCM sym_load
= scm_from_utf8_symbol ("load");
136 SCM sym_set_x
= scm_from_utf8_symbol ("set!");
137 SCM sym_load_path
= scm_from_utf8_symbol ("%load-path");
139 #ifdef HAVE_GETOPT_LONG
140 /* int option_index = 0; */
142 while ((ch
= getopt_long(argc
, argv
, OPTIONS
, long_options
, NULL
/* &option_index */)) != -1) {
144 while ((ch
= getopt(argc
, argv
, OPTIONS
)) != -1) {
149 /* This is a long-form-only flag option, and has already been
150 * dealt with by getopt_long(). */
158 interactive_mode
= TRUE
;
166 /* Argument is a directory to add to the Scheme load path.
167 * Add the necessary expression to be evaluated before rc file
170 scm_cons (scm_list_3 (sym_set_x
,
172 scm_list_3 (sym_cons
,
173 scm_from_locale_string (optarg
),
179 guile_proc
= g_strdup(optarg
);
183 /* Argument is filename of a Scheme script to be run before
184 * loading gnetlist backend. */
186 scm_cons (scm_list_2 (sym_load
, scm_from_locale_string (optarg
)),
191 /* Argument is filename of a Scheme script to be run after
192 * loading gnetlist backend. */
194 scm_cons (scm_list_2 (sym_load
, scm_from_locale_string (optarg
)),
199 g_free(output_filename
);
200 output_filename
= g_strdup(optarg
);
204 backend_params
= g_slist_append(backend_params
, optarg
);
208 scm_internal_stack_catch (SCM_BOOL_T
,
209 (scm_t_catch_body
) scm_c_eval_string
,
211 (scm_t_catch_handler
) catch_handler
,
224 #ifndef HAVE_GETOPT_LONG
225 if ((optopt
!= ':') && (strchr (GETOPT_OPTIONS
, optopt
) != NULL
)) {
227 _("ERROR: -%c option requires an argument.\n\n"),
229 } else if (isprint (optopt
)) {
230 fprintf (stderr
, _("ERROR: Unknown option -%c.\n\n"), optopt
);
232 fprintf (stderr
, _("ERROR: Unknown option character `\\x%x'.\n\n"),
236 fprintf (stderr
, _("\nRun `%s --help' for more information.\n"), argv
[0]);
241 g_assert_not_reached ();
246 verbose_mode
= FALSE
;
249 /* Make sure Scheme expressions can be passed straight to eval */
250 pre_rc_list
= scm_cons (sym_begin
,
251 scm_reverse_x (pre_rc_list
, SCM_UNDEFINED
));
252 scm_gc_protect_object (pre_rc_list
);
253 pre_backend_list
= scm_cons (sym_begin
,
254 scm_reverse_x (pre_backend_list
, SCM_UNDEFINED
));
255 scm_gc_protect_object (pre_backend_list
);
256 post_backend_list
= scm_cons (sym_begin
,
257 scm_reverse_x (post_backend_list
, SCM_UNDEFINED
));
258 scm_gc_protect_object (post_backend_list
);