summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 61fb775)
raw | patch | inline | side by side (parent: 61fb775)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 11 Dec 2014 22:42:14 +0000 (23:42 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 11 Dec 2014 22:42:14 +0000 (23:42 +0100) |
src/tools/sysdb/command.c | patch | blob | history | |
src/tools/sysdb/input.c | patch | blob | history | |
src/tools/sysdb/input.h | patch | blob | history | |
src/tools/sysdb/scanner.l | patch | blob | history |
index 3126c7bc9d42ec7a73ad439eade0f29804748d9f..6c3114d8e692274d8223c7601c3082d5174b5fe2 100644 (file)
sdb_strbuf_skip(input->input, 0, input->query_len);
input->tokenizer_pos -= input->query_len;
input->query_len = 0;
+ input->have_input = 0;
} /* clear_query */
/*
index a88b2266147de67a659cd383e802a0a61701f7ce..898464af0b550118aa0367337a4e4b85460930c6 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
return;
}
- if (sdb_client_eof(sysdb_input->client))
- sdb_input_reconnect();
-
sdb_strbuf_append(sysdb_input->input, "%s\n", line);
free(line);
return (ssize_t)(sdb_strbuf_len(sysdb_input->input) - len);
}
- if (sysdb_input->query_len)
+ if (sysdb_input->have_input)
prompt = "sysdb-> ";
if (sdb_client_eof(sysdb_input->client))
prompt = "!-> ";
int
sdb_input_exec_query(void)
{
- char *query = sdb_command_exec(sysdb_input);
+ char *query = NULL;
HIST_ENTRY *hist;
const char *prev = NULL;
+ if (! sysdb_input->have_input) {
+ /* empty line */
+ if (sdb_client_eof(sysdb_input->client))
+ sdb_input_reconnect();
+ return 0;
+ }
+
+ query = sdb_command_exec(sysdb_input);
if (! query)
return -1;
index 0aeabf8b7b653197f98ffa0678d13b769e0c21e2..b8501f472383cd454608c19aebcab8688e784c60 100644 (file)
--- a/src/tools/sysdb/input.h
+++ b/src/tools/sysdb/input.h
size_t tokenizer_pos;
size_t query_len;
+ /* indicates that we've had non-empty input */
+ bool have_input;
+
bool interactive;
bool eof;
} sdb_input_t;
-#define SDB_INPUT_INIT { NULL, NULL, NULL, 0, 0, 1, 0 }
+#define SDB_INPUT_INIT { NULL, NULL, NULL, 0, 0, 0, 1, 0 }
/*
* sysdb_input:
index 1404690a1256354f078ab87f863e516d57ff270e..16defa61859085dc20dad932c8f812986af494e3 100644 (file)
#define APPEND() \
do { \
+ if (! isspace((int)yytext[0])) \
+ sysdb_input->have_input = 1; \
sysdb_input->query_len += strlen(yytext); \
} while (0)
%x CSC
-newline ([\n\r]+)
+newline (\n|\r\n)
simple_comment ("--"[^\n\r]*)
/*
* The following rules are specific to the command line tool.
*/
+";\n" { APPEND(); sdb_input_exec_query(); }
";" { APPEND(); sdb_input_exec_query(); }
+{newline} {
+ APPEND();
+ if (! sysdb_input->have_input)
+ /* give the input module a chance to do stuff on empty lines */
+ sdb_input_exec_query();
+ }
+
. { APPEND(); }
-{newline} { APPEND(); }
%%