2 * gEDA/gaf command-line utility
3 * Copyright (C) 2012 Peter Brett <peter@peter-b.co.uk>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 /* Gettext translation */
32 #include <libgeda/libgeda.h>
33 #include <libgeda/libgedaguile.h>
35 #define shell_short_options "s:c:L:l:h"
37 static struct option shell_long_options
[] =
39 {"help", 0, NULL
, 'h'},
46 printf (_("Usage: gaf shell [OPTION ...]\n"
48 "Shell for interactive processing of gEDA data using Scheme.\n"
50 " -s FILE load Scheme source code from FILE, and exit\n"
51 " -c EXPR evaluate Scheme expression EXPR, and exit\n"
52 " -- stop scanning arguments; run interactively\n"
54 "The above switches stop argument processing, and pass all\n"
55 "remaining arguments as the value of (command-line).\n"
57 " -L DIRECTORY add DIRECTORY to the front of the Scheme load path\n"
58 " -l FILE load Scheme source code from FILE\n"
59 " -h, --help display usage information and exit\n"
61 "Please report bugs to %s.\n"),
66 /* Some symbols we need */
67 SCM_SYMBOL (sym_begin
, "begin");
68 SCM_SYMBOL (sym_use_modules
, "use-modules");
69 SCM_SYMBOL (sym_ice_9
, "ice-9");
70 SCM_SYMBOL (sym_readline
, "readline");
71 SCM_SYMBOL (sym_activate_readline
, "activate-readline");
74 cmd_shell_impl (void *data
, int argc
, char **argv
)
76 int c
, interactive
= 1;
81 /* Parse command-line arguments */
82 while ((c
= getopt_long (argc
, argv
, shell_short_options
,
83 shell_long_options
, NULL
)) != -1) {
86 /* This is a long-form-only flag option, and has already been
87 * dealt with by getopt_long(). */
92 /* Intentionally falls through */
95 /* Do nothing, scm_shell() will deal with these. */
101 /* getopt_long already printed an error message */
102 fprintf (stderr
, _("\nRun `gaf shell --help' for more information.\n"));
106 g_assert_not_reached ();
111 scm_dynwind_begin (0);
112 toplevel
= s_toplevel_new ();
113 edascm_dynwind_toplevel (toplevel
);
115 /* Interactive, so enable readline support and print an abbreviated
116 * version message. */
118 fprintf (stderr
, "gEDA %s (g%.7s)\n", PACKAGE_DOTTED_VERSION
, PACKAGE_GIT_COMMIT
);
119 /* readline is not supported for MinGW builds yet */
121 SCM expr
= scm_list_3 (sym_begin
,
122 scm_list_2 (sym_use_modules
,
123 scm_list_2 (sym_ice_9
, sym_readline
)),
124 scm_list_1 (sym_activate_readline
));
126 scm_eval_x (expr
, scm_current_module ());
127 #endif /* __MINGW32__ */
130 /* Now load rc files, if necessary */
131 if (getenv ("GAF_INHIBIT_RCFILES") == NULL
) {
132 g_rc_parse (toplevel
, "gaf shell", NULL
, NULL
);
134 i_vars_libgeda_set (toplevel
); /* Ugh */
136 scm_shell (argc
, argv
); /* Doesn't return */
142 cmd_shell (int argc
, char **argv
)
144 scm_boot_guile (argc
, argv
, cmd_shell_impl
, NULL
); /* Doesn't return */