X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=5f64c040da815a9d442ad3ea77669a1119f0ef5d;hp=9f9d0e4e149c6a7750a2be8bddcf59e47a55358a;hb=c12f2351ad72e5e4788f30684de0d98e5bc0dc1e;hpb=bc66c2a11aa31c16f46c49100e99dc9b7e940faf diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 9f9d0e4..5f64c04 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* - * $Id: zoomsh.c,v 1.2 2001-10-24 12:24:43 adam Exp $ + * $Id: zoomsh.c,v 1.21 2003-07-09 23:00:21 mike Exp $ * * ZOOM-C Shell */ @@ -18,7 +18,10 @@ #include +#include +#include #include +#include #define MAX_CON 100 @@ -28,24 +31,41 @@ static int next_token (const char **cpp, const char **t_start) const char *cp = *cpp; while (*cp == ' ') cp++; - *t_start = cp; - while (*cp && *cp != ' ' && *cp != '\r' && *cp != '\n') + 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; + return len; } if (len >= buf_max) len = buf_max-1; @@ -64,28 +84,41 @@ static int is_command (const char *cmd_str, const char *this_str, int this_len) return 1; } -static void cmd_set (Z3950_connection *c, Z3950_resultset *r, - Z3950_options options, +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 ; } - 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_close (Z3950_connection *c, Z3950_resultset *r, - Z3950_options options, +static void cmd_close (ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, const char **args) { char host[60]; @@ -96,144 +129,273 @@ static void cmd_close (Z3950_connection *c, Z3950_resultset *r, const char *h; if (!c[i]) continue; - if ((h = Z3950_connection_host(c[i])) && !strcmp (h, host)) + if ((h = ZOOM_connection_option_get(c[i], "host")) + && !strcmp (h, host)) { - Z3950_connection_destroy (c[i]); + ZOOM_connection_destroy (c[i]); c[i] = 0; } else if (*host == '\0') { - Z3950_connection_destroy (c[i]); + ZOOM_connection_destroy (c[i]); c[i] = 0; } } } -static void display_records (Z3950_connection c, - Z3950_resultset r, +static const char *oid_name_to_dotstring(const char *name) { + struct oident ent; + int oid[OID_SIZE]; + static char oidbuf[100]; /* ### bad interface */ + int i; + + /* Translate syntax to oid_val */ + oid_value value = oid_getvalbyname(name); + + /* Build it into an oident */ + ent.proto = PROTO_Z3950; + ent.oclass = CLASS_RECSYN; + ent.value = value; + + /* Translate to an array of int */ + (void) oid_ent_to_oid(&ent, oid); + + /* Write the array of int into a dotted string (phew!) */ + oidbuf[0] = '\0'; + for (i = 0; oid[i] != -1; i++) { + char tmpbuf[20]; + sprintf(tmpbuf, "%d", oid[i]); + if (i > 0) strcat(oidbuf, "."); + strcat(oidbuf, tmpbuf); + } + + return oidbuf; +} + +static void display_records (ZOOM_connection c, + ZOOM_resultset r, int start, int count) { int i; 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