Code

sysdb: Use a string buffer and simple (stupid) ';' EO-query checks.
authorSebastian Harl <sh@tokkee.org>
Sun, 15 Dec 2013 08:49:10 +0000 (09:49 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 15 Dec 2013 08:49:10 +0000 (09:49 +0100)
Use a different prompt (similar to psql) when inside a query.

src/client/sysdb.c

index ada0ec3ae30f5dba633265eee73a2db937118a3c..ecadb4c18462cd94e61cfe116561269efe7622c0 100644 (file)
@@ -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') {