[seed] Add -e option to repl.
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [seed] Add -e option to repl.
- Date: Fri, 22 Jan 2010 01:36:56 +0000 (UTC)
commit f7c089d060eb030a6af4dcaa370e5c6c649db5ef
Author: Matt Arsenault <arsenm2 rpi edu>
Date: Sun Jan 17 01:46:34 2010 -0500
Add -e option to repl.
src/args.c | 6 +++++-
src/main.c | 50 +++++++++++++++++++++++++++++++++++++++++++-------
2 files changed, 48 insertions(+), 8 deletions(-)
---
diff --git a/src/args.c b/src/args.c
index 9b9a488..5519c21 100644
--- a/src/args.c
+++ b/src/args.c
@@ -26,13 +26,17 @@
#include "config.h"
extern gboolean seed_interpreter_arg_print_version;
+extern gchar *seed_interpreter_arg_exec_string;
static GOptionEntry seed_args[] = {
{"version", 0, 0, G_OPTION_ARG_NONE, &seed_interpreter_arg_print_version,
"Print interpreter version", 0},
+ {"execute", 'e', 0, G_OPTION_ARG_STRING, &seed_interpreter_arg_exec_string,
+ "program passed in as string", "expression"},
{NULL,},
};
+
static GOptionGroup *
seed_interpreter_get_option_group (void)
{
@@ -62,7 +66,7 @@ seed_interpreter_parse_args (int *argc, char ***argv)
interpreter_group = seed_interpreter_get_option_group ();
g_option_context_set_main_group (option_context, interpreter_group);
- g_option_context_add_group (option_context, seed_get_option_group());
+ g_option_context_add_group (option_context, seed_get_option_group ());
if (!g_option_context_parse (option_context, argc, argv, &error))
{
diff --git a/src/main.c b/src/main.c
index 774b74a..f603560 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,6 +29,7 @@
SeedEngine *eng;
gboolean seed_interpreter_arg_print_version;
+gchar *seed_interpreter_arg_exec_string;
gboolean seed_interpreter_parse_args (int *argc, char ***argv);
@@ -101,25 +102,60 @@ seed_exec (gchar * filename)
g_free (script);
}
+static void
+seed_exec_str ()
+{
+ SeedException e = NULL;
+ SeedValue val;
+ gchar *val_str;
+
+ val =
+ seed_simple_evaluate (eng->context, seed_interpreter_arg_exec_string, &e);
+
+ if (e)
+ {
+ g_critical ("%s", seed_exception_to_string (eng->context, e));
+ exit (EXIT_FAILURE);
+ }
+ else
+ {
+ val_str = seed_value_to_string (eng->context, val, &e);
+ if (e)
+ {
+ g_critical ("%s", seed_exception_to_string (eng->context, e));
+ exit (EXIT_FAILURE);
+ }
+
+ g_print ("%s\n", val_str);
+ g_free (seed_interpreter_arg_exec_string);
+ g_free (val_str);
+
+ exit (EXIT_SUCCESS);
+ }
+
+}
+
gint
main (gint argc, gchar ** argv)
{
g_set_prgname ("seed");
- g_thread_init (0);
-
- seed_interpreter_parse_args(&argc, &argv);
-
+ g_thread_init (NULL);
+
+ seed_interpreter_parse_args (&argc, &argv);
+
if (seed_interpreter_arg_print_version)
{
- g_print("%s\n", "Seed " VERSION);
- exit(EXIT_SUCCESS);
+ g_print ("%s\n", "Seed " VERSION);
+ exit (EXIT_SUCCESS);
}
eng = seed_init (&argc, &argv);
seed_engine_set_search_path (eng, DEFAULT_PATH);
- if (argc == 1)
+ if (seed_interpreter_arg_exec_string)
+ seed_exec_str ();
+ else if (argc == 1)
seed_repl ();
else
seed_exec (argv[1]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]