From: Sebastian Harl Date: Sun, 15 Dec 2013 08:49:10 +0000 (+0100) Subject: sysdb: Use a string buffer and simple (stupid) ';' EO-query checks. X-Git-Tag: sysdb-0.1.0~300^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f13d94b40055d56dd5d546ab6e36eb655b26420c;p=sysdb.git sysdb: Use a string buffer and simple (stupid) ';' EO-query checks. Use a different prompt (similar to psql) when inside a query. --- diff --git a/src/client/sysdb.c b/src/client/sysdb.c index ada0ec3..ecadb4c 100644 --- a/src/client/sysdb.c +++ b/src/client/sysdb.c @@ -171,6 +171,8 @@ main(int argc, char **argv) const char *homedir; char hist_file[1024] = ""; + sdb_strbuf_t *buf; + while (42) { int opt = getopt(argc, argv, "H:U:hV"); @@ -236,20 +238,30 @@ main(int argc, char **argv) } } + buf = sdb_strbuf_create(1024); + while (42) { - char *line = readline("sysdb> "); + const char *prompt = "sysdb=> "; + const char *query; + char *input; + + if (sdb_strbuf_len(buf)) + prompt = "sysdb-> "; + + input = readline(prompt); - if (! line) + if (! input) break; - if (*line == '\0') { - free(line); - continue; - } - if (*line != ' ') - add_history(line); + sdb_strbuf_append(buf, input); + free(input); + + query = sdb_strbuf_string(buf); + if (! strchr(query, (int)';')) + continue; - free(line); + /* XXX */ + sdb_strbuf_clear(buf); } if (hist_file[0] != '\0') {