diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-01-23 22:24:12 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-01-23 22:24:12 +0100 |
commit | 6de8c47c288a6cec1bfd14926f4674f1bc8f0e8c (patch) | |
tree | cf8e251c4783c59264a4f928247acbae0008d2e6 | |
parent | a390fdca3ce4978e4a5a8984c6a45211b9bfd3c4 (diff) | |
download | sciteco-6de8c47c288a6cec1bfd14926f4674f1bc8f0e8c.tar.gz |
added --eval commandline option allowing code to be executed on the commandline
useful, e.g. in Makefiles
-rw-r--r-- | src/main.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 1a3205d..d1a3c84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,7 @@ namespace Flags { gint64 ed = 0; } +static gchar *eval_macro = NULL; static gchar *mung_file = NULL; sig_atomic_t sigint_occurred = FALSE; @@ -126,8 +127,10 @@ static inline void process_options(int &argc, char **&argv) { static const GOptionEntry option_entries[] = { + {"eval", 'e', 0, G_OPTION_ARG_STRING, &eval_macro, + "Evaluate macro", "macro"}, {"mung", 'm', 0, G_OPTION_ARG_FILENAME, &mung_file, - "Mung file instead of " INI_FILE, "filename"}, + "Mung file instead of " INI_FILE, "file"}, {NULL} }; @@ -203,6 +206,18 @@ main(int argc, char **argv) interface.ssm(SCI_APPENDTEXT, 1, (sptr_t)"\n"); } + /* + * Execute macro or mung file + */ + if (eval_macro) { + try { + Execute::macro(eval_macro, false); + } catch (...) { + exit(EXIT_FAILURE); + } + exit(EXIT_SUCCESS); + } + if (g_file_test(mung_file, G_FILE_TEST_IS_REGULAR)) { if (!Execute::file(mung_file, false)) exit(EXIT_FAILURE); @@ -215,6 +230,9 @@ main(int argc, char **argv) } g_free(mung_file); + /* + * If munged file didn't quit, switch into interactive mode + */ Goto::table = &cmdline_goto_table; interface.ssm(SCI_EMPTYUNDOBUFFER); undo.enabled = true; |