X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=111f629a9d1bdd3a8576ca997af7a4dab07846a6;hp=24746d26a5c033c9f5c7ce5d45ec83897b91ecd3;hb=ba401b06433f6cebf02ec74bc64922293c39133f;hpb=13671e7cc0f3dd4e4b02f94d64a50778c5696ba6 diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 24746d2..111f629 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,14 +1,19 @@ /* - * $Id: zoomsh.c,v 1.7 2001-11-18 21:14:23 adam Exp $ + * Copyright (C) 1995-2005, Index Data ApS + * See the file LICENSE for details. * - * ZOOM-C Shell + * $Id: zoomsh.c,v 1.37 2005-06-25 15:46:08 adam Exp $ */ +/* ZOOM-C Shell */ + #include #include #include #include +#include + #if HAVE_READLINE_READLINE_H #include #endif @@ -18,7 +23,10 @@ #include +#include +#include #include +#include #define MAX_CON 100 @@ -27,28 +35,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 != '\r' && *cp != '\n') + cp++; + if (*cp == '"') + { + cp++; + *t_start = cp; + while (*cp && *cp != '"') + { + cp++; + len++; + } + if (*cp) + cp++; + } + else { - cp++; - len++; + *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; @@ -58,184 +83,332 @@ 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 (ZOOM_connection *c, ZOOM_resultset *r, - ZOOM_options options, - const char **args) + 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 = 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); + { + const char *val = ZOOM_options_get(options, key); + printf ("%s = %s\n", key, val ? val : ""); + } } static void cmd_close (ZOOM_connection *c, ZOOM_resultset *r, - ZOOM_options options, - const char **args) + 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))) - ZOOM_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