From ecdec4620ddc97f779e0be37c6caf33688688d1b Mon Sep 17 00:00:00 2001 From: vvaltman Date: Thu, 2 Oct 2014 22:54:06 +0400 Subject: [PATCH] Added '-e' option --- loop.c | 16 ++++++++++++++++ main.c | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/loop.c b/loop.c index cab2815..ee45225 100644 --- a/loop.c +++ b/loop.c @@ -91,6 +91,8 @@ static int delete_stdin_event; extern volatile int sigterm_cnt; +extern char *start_command; + static void stdin_read_callback_all (int arg, short what, struct event *self) { if (!readline_disabled) { if (((long)arg) & 1) { @@ -852,6 +854,20 @@ int loop (void) { lua_diff_end (); #endif + if (start_command) { + safe_quit = 1; + while (*start_command) { + char *start = start_command; + while (*start_command && *start_command != '\n') { + start_command ++; + } + if (*start_command) { + *start_command = 0; + start_command ++; + } + interpreter_ex (start, 0); + } + } /*tgl_do_get_dialog_list (get_dialogs_callback, 0); if (wait_dialog_list) { diff --git a/main.c b/main.c index d298d27..bac19f6 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,7 @@ int readline_disabled; int disable_output; int reset_authorization; int port; +char *start_command; void set_default_username (const char *s) { if (default_username) { @@ -436,6 +437,7 @@ void usage (void) { printf (" -D disable output\n"); printf (" -P port to listen for input commands\n"); printf (" -S unix socket to create\n"); + printf (" -e make commands end exit\n"); exit (1); } @@ -538,7 +540,7 @@ char *unix_socket; void args_parse (int argc, char **argv) { int opt = 0; - while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:qP:S:" + while ((opt = getopt (argc, argv, "u:hk:vNl:fEwWCRdL:DU:G:qP:S:e:" #ifdef HAVE_LIBCONFIG "c:p:" #else @@ -627,6 +629,9 @@ void args_parse (int argc, char **argv) { case 'S': unix_socket = optarg; break; + case 'e': + start_command = optarg; + break; case 'h': default: usage ();