X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=ad829489bffcab461aa02459a548879f6064ad22;hp=2f3897faf66ccff0481639099185ac8f5de4817b;hb=16ee7ff60aee87829916837bcb2a200ce72870d9;hpb=69bcd68523a9a8da083faef16887100369152673 diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 2f3897f..ad82948 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,16 +1,20 @@ /* - * $Id: zoomsh.c,v 1.1 2001-10-23 21:00:20 adam Exp $ + * Copyright (C) 1995-2005, Index Data ApS + * See the file LICENSE for details. * - * ZOOM-C Shell + * $Id: zoomsh.c,v 1.41 2006-04-24 10:30:44 adam Exp $ */ +/** \file zoomsh.c + \brief ZOOM C command line tool (shell) +*/ + #include #include #include #include -#define HAVE_READLINE_READLINE_H 1 -#define HAVE_READLINE_HISTORY_H 1 +#include #if HAVE_READLINE_READLINE_H #include @@ -21,7 +25,10 @@ #include +#include +#include #include +#include #define MAX_CON 100 @@ -30,28 +37,45 @@ 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++; + 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) { const char *start; int len = next_token (cpp, &start); - if (!len) + if (len < 0) { - *buf_out = 0; - return 0; + *buf_out = 0; + return len; } if (len >= buf_max) - len = buf_max-1; + len = buf_max-1; memcpy (buf_out, start, len); buf_out[len] = '\0'; return len; @@ -61,182 +85,356 @@ 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; + return 0; if (memcmp (cmd_str, this_str, cmd_len)) - return 0; + return 0; return 1; } -static void cmd_set (Z3950_connection *c, Z3950_resultset *r, - Z3950_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]; - if (!next_token_copy (args, key, sizeof(key))) + if (next_token_copy (args, key, sizeof(key)) < 0) { - printf ("missing argument for set\n"); - return ; + printf ("missing argument for set\n"); + return ; } - if (!next_token_copy (args, val, sizeof(val))) + if (next_token_copy (args, val, sizeof(val)) < 0) + ZOOM_options_set(options, key, 0); + else + ZOOM_options_set(options, key, val); +} + +static void cmd_get (ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + char key[40]; + if (next_token_copy (args, key, sizeof(key)) < 0) { - const char *val = Z3950_options_get(options, key); - printf ("%s = %s\n", key, val ? val : ""); + printf ("missing argument for get\n"); } else - Z3950_options_set(options, key, val); + { + const char *val = ZOOM_options_get(options, key); + printf ("%s = %s\n", key, val ? val : ""); + } +} + +static void cmd_rget(ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + char key[40]; + if (next_token_copy (args, key, sizeof(key)) < 0) + { + printf ("missing argument for get\n"); + } + else + { + int i; + for (i = 0; i"); + } + } } -static void cmd_close (Z3950_connection *c, Z3950_resultset *r, - Z3950_options options, - const char **args) +static void cmd_close (ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) { char host[60]; int i; next_token_copy (args, host, sizeof(host)); for (i = 0; i= 0) + ZOOM_options_set (options, "start", start_str); - if (next_token_copy (args, count_str, sizeof(count_str))) - Z3950_options_set (options, "count", count_str); + if (next_token_copy (args, count_str, sizeof(count_str)) >= 0) + ZOOM_options_set (options, "count", count_str); for (i = 0; i\n"); printf ("search \n"); printf ("show [ []\n"); + printf ("scan \n"); printf ("quit\n"); printf ("close \n"); - printf ("set