X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=9115bf3afc6bd9932ec331f85832b22bff9e4f65;hp=24746d26a5c033c9f5c7ce5d45ec83897b91ecd3;hb=37fbd309fef590f0cc0e3bc955161bcb8e37e99e;hpb=13671e7cc0f3dd4e4b02f94d64a50778c5696ba6 diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 24746d2..9115bf3 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,13 +1,19 @@ -/* - * $Id: zoomsh.c,v 1.7 2001-11-18 21:14:23 adam Exp $ - * - * ZOOM-C Shell +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2011 Index Data + * See the file LICENSE for details. */ +/** \file zoomsh.c + \brief ZOOM C command line tool (shell) +*/ +#if HAVE_CONFIG_H +#include +#endif #include #include #include -#include +#include +#include #if HAVE_READLINE_READLINE_H #include @@ -16,382 +22,763 @@ #include #endif -#include - +#include #include #define MAX_CON 100 -static int next_token (const char **cpp, const char **t_start) +static void process_events(ZOOM_connection *c) +{ + int i; + + yaz_log(YLOG_DEBUG, "process_events"); + while ((i = ZOOM_event(MAX_CON, c)) != 0) + { + int peek = ZOOM_connection_peek_event(c[i-1]); + int event = ZOOM_connection_last_event(c[i-1]); + yaz_log(YLOG_DEBUG, "no = %d peek = %d event = %d %s", i-1, + peek, + event, + ZOOM_get_event_str(event)); + } +} + +static int next_token(const char **cpp, const char **t_start) { int len = 0; const char *cp = *cpp; while (*cp == ' ') - cp++; - *t_start = cp; - while (*cp && *cp != ' ' && *cp != '\r' && *cp != '\n') + cp++; + if (*cp == '"') { - cp++; - len++; + cp++; + *t_start = cp; + while (*cp && *cp != '"') + { + cp++; + len++; + } + if (*cp) + cp++; + } + else + { + *t_start = cp; + while (*cp && *cp != ' ' && *cp != '\r' && *cp != '\n') + { + cp++; + len++; + } + if (len == 0) + len = -1; } *cpp = cp; - return len; + return len; /* return -1 if no token was read .. */ } -static int next_token_copy (const char **cpp, char *buf_out, int buf_max) +static WRBUF next_token_new_wrbuf(const char **cpp) { + WRBUF w = 0; const char *start; - int len = next_token (cpp, &start); - if (!len) - { - *buf_out = 0; - return 0; - } - if (len >= buf_max) - len = buf_max-1; - memcpy (buf_out, start, len); - buf_out[len] = '\0'; - return len; + int len = next_token(cpp, &start); + if (len < 0) + return 0; + w = wrbuf_alloc(); + if (len > 0) + wrbuf_write(w, start, len); + return w; } -static int is_command (const char *cmd_str, const char *this_str, int this_len) +static int is_command(const char *cmd_str, const char *this_str, int this_len) { int cmd_len = strlen(cmd_str); if (cmd_len != this_len) - return 0; - if (memcmp (cmd_str, this_str, cmd_len)) - return 0; + return 0; + if (memcmp(cmd_str, this_str, cmd_len)) + return 0; return 1; } -static void cmd_set (ZOOM_connection *c, ZOOM_resultset *r, - ZOOM_options options, - const char **args) +static void cmd_set(ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) { - char key[40], val[80]; + WRBUF key, val; - if (!next_token_copy (args, key, sizeof(key))) + if (!(key = next_token_new_wrbuf(args))) + { + printf("missing argument for set\n"); + return ; + } + if ((val = next_token_new_wrbuf(args))) { - printf ("missing argument for set\n"); - return ; + ZOOM_options_set(options, wrbuf_cstr(key), wrbuf_cstr(val)); + wrbuf_destroy(val); } - if (!next_token_copy (args, val, sizeof(val))) + else + ZOOM_options_set(options, wrbuf_cstr(key), 0); + wrbuf_destroy(key); +} + +static void cmd_get(ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + WRBUF key; + if (!(key = next_token_new_wrbuf(args))) + { + printf("missing argument for get\n"); + } + else + { + const char *val = ZOOM_options_get(options, wrbuf_cstr(key)); + printf("%s = %s\n", wrbuf_cstr(key), val ? val : ""); + wrbuf_destroy(key); + } +} + +static void cmd_rget(ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + WRBUF key; + if (!(key = next_token_new_wrbuf(args))) { - const char *val = ZOOM_options_get(options, key); - printf ("%s = %s\n", key, val ? val : ""); + printf("missing argument for get\n"); } else - ZOOM_options_set(options, key, val); + { + int i; + for (i = 0; i"); + } + wrbuf_destroy(key); + } } -static void cmd_close (ZOOM_connection *c, ZOOM_resultset *r, - ZOOM_options options, - const char **args) +static void cmd_close(ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) { - char host[60]; + WRBUF host; int i; - next_token_copy (args, host, sizeof(host)); + host = next_token_new_wrbuf(args); for (i = 0; i\n"); - printf ("search \n"); - printf ("show [ []\n"); - printf ("quit\n"); - printf ("close \n"); - printf ("set