From 50fbdc0bbd17afe2fd8f128330dc313700593d78 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 30 Jan 2014 11:47:41 +0100 Subject: [PATCH] zoomsh: sortby command --- zoom/zoomsh.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index daa6cc7..35b14a0 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -31,6 +31,8 @@ #include struct zoom_sh { + WRBUF strategy; + WRBUF criteria; ZOOM_options options; struct zoom_db *list; }; @@ -511,6 +513,21 @@ static int cmd_search(struct zoom_sh *sh, const char **args) ZOOM_query_destroy(s); return 1; } + if (sh->strategy && wrbuf_len(sh->strategy) && wrbuf_len(sh->criteria)) + { + int r = ZOOM_query_sortby2(s, wrbuf_cstr(sh->strategy), + wrbuf_cstr(sh->criteria)); + if (r) + { + if (r == -1) + printf("Bad sortby strategy: %s\n", wrbuf_cstr(sh->strategy)); + else + printf("Bad sortby criteria: %s\n", wrbuf_cstr(sh->criteria)); + ZOOM_query_destroy(s); + return 1; + } + printf("sortby added\n"); + } for (db = sh->list; db; db = db->next) { if (db->con) @@ -647,6 +664,26 @@ static int cmd_scan(struct zoom_sh *sh, const char **args) return ret; } +static int cmd_sortby(struct zoom_sh *sh, const char **args) +{ + WRBUF strategy; + const char *criteria; + if (!(strategy = next_token_new_wrbuf(args))) + { + printf("missing argument argument: strategy and criteria\n"); + return 1; + } + criteria = *args; + while (*criteria == ' ') + criteria++; + wrbuf_destroy(sh->strategy); + sh->strategy = strategy; + + wrbuf_rewind(sh->criteria); + wrbuf_puts(sh->criteria, criteria); + return 0; +} + static int cmd_sort(struct zoom_sh *sh, const char **args) { const char *sort_spec = *args; @@ -667,6 +704,7 @@ static int cmd_help(struct zoom_sh *sh, const char **args) { printf("connect \n"); printf("search \n"); + printf("sortby \n"); printf("show [ [ [\n"); @@ -777,6 +815,8 @@ static int cmd_parse(struct zoom_sh *sh, const char **buf) ret = cmd_connect(sh, buf); else if (is_command("search", cmd_str, cmd_len)) ret = cmd_search(sh, buf); + else if (is_command("sortby", cmd_str, cmd_len)) + ret = cmd_sortby(sh, buf); else if (is_command("facets", cmd_str, cmd_len)) ret = cmd_facets(sh, buf); else if (is_command("find", cmd_str, cmd_len)) @@ -869,6 +909,8 @@ static int zoomsh(int argc, char **argv) sh.list = 0; sh.options = ZOOM_options_create(); + sh.strategy = 0; + sh.criteria = wrbuf_alloc(); while (res == 0) { @@ -909,6 +951,8 @@ static int zoomsh(int argc, char **argv) db = n; } ZOOM_options_destroy(sh.options); + wrbuf_destroy(sh.strategy); + wrbuf_destroy(sh.criteria); if (res == -1) /* quit .. which is not an error */ res = 0; return res; -- 1.7.10.4