Added '-e' option

This commit is contained in:
vvaltman 2014-10-02 22:54:06 +04:00
parent 59abeaa188
commit ecdec4620d
2 changed files with 22 additions and 1 deletions

16
loop.c
View File

@ -91,6 +91,8 @@ static int delete_stdin_event;
extern volatile int sigterm_cnt; extern volatile int sigterm_cnt;
extern char *start_command;
static void stdin_read_callback_all (int arg, short what, struct event *self) { static void stdin_read_callback_all (int arg, short what, struct event *self) {
if (!readline_disabled) { if (!readline_disabled) {
if (((long)arg) & 1) { if (((long)arg) & 1) {
@ -852,6 +854,20 @@ int loop (void) {
lua_diff_end (); lua_diff_end ();
#endif #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); /*tgl_do_get_dialog_list (get_dialogs_callback, 0);
if (wait_dialog_list) { if (wait_dialog_list) {

7
main.c
View File

@ -111,6 +111,7 @@ int readline_disabled;
int disable_output; int disable_output;
int reset_authorization; int reset_authorization;
int port; int port;
char *start_command;
void set_default_username (const char *s) { void set_default_username (const char *s) {
if (default_username) { if (default_username) {
@ -436,6 +437,7 @@ void usage (void) {
printf (" -D disable output\n"); printf (" -D disable output\n");
printf (" -P <port> port to listen for input commands\n"); printf (" -P <port> port to listen for input commands\n");
printf (" -S <socket-name> unix socket to create\n"); printf (" -S <socket-name> unix socket to create\n");
printf (" -e <commands> make commands end exit\n");
exit (1); exit (1);
} }
@ -538,7 +540,7 @@ char *unix_socket;
void args_parse (int argc, char **argv) { void args_parse (int argc, char **argv) {
int opt = 0; 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 #ifdef HAVE_LIBCONFIG
"c:p:" "c:p:"
#else #else
@ -627,6 +629,9 @@ void args_parse (int argc, char **argv) {
case 'S': case 'S':
unix_socket = optarg; unix_socket = optarg;
break; break;
case 'e':
start_command = optarg;
break;
case 'h': case 'h':
default: default:
usage (); usage ();