X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzoomsh.c;h=5f64c040da815a9d442ad3ea77669a1119f0ef5d;hp=37b487b94a5d7f734b199b7c9534c7f811f23942;hb=c12f2351ad72e5e4788f30684de0d98e5bc0dc1e;hpb=ba8d526ec24077c455979314147aaff20746a8ca diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 37b487b..5f64c04 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* - * $Id: zoomsh.c,v 1.18 2003-03-03 19:57:36 adam Exp $ + * $Id: zoomsh.c,v 1.21 2003-07-09 23:00:21 mike Exp $ * * ZOOM-C Shell */ @@ -21,6 +21,7 @@ #include #include #include +#include #define MAX_CON 100 @@ -30,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; @@ -72,12 +90,12 @@ static void cmd_set (ZOOM_connection *c, ZOOM_resultset *r, { 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); @@ -88,7 +106,7 @@ static void cmd_get (ZOOM_connection *c, ZOOM_resultset *r, const char **args) { char key[40]; - if (!next_token_copy (args, key, sizeof(key))) + if (next_token_copy (args, key, sizeof(key)) < 0) { printf ("missing argument for get\n"); } @@ -125,6 +143,35 @@ static void cmd_close (ZOOM_connection *c, ZOOM_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) @@ -141,7 +188,9 @@ static void display_records (ZOOM_connection c, /* if rec is non-null, we got a record for display */ if (rec) { - printf ("%d %s %s\n", pos+1, (db ? db : "unknown"), syntax); + const char *syntax_oid = oid_name_to_dotstring(syntax); + printf ("%d %s %s (%s)\n", + pos+1, (db ? db : "unknown"), syntax, syntax_oid); if (render) fwrite (render, 1, len, stdout); printf ("\n"); @@ -156,10 +205,10 @@ static void cmd_show (ZOOM_connection *c, ZOOM_resultset *r, int i; char start_str[10], count_str[10]; - if (next_token_copy (args, start_str, sizeof(start_str))) + if (next_token_copy (args, start_str, sizeof(start_str)) >= 0) ZOOM_options_set (options, "start", start_str); - if (next_token_copy (args, count_str, sizeof(count_str))) + if (next_token_copy (args, count_str, sizeof(count_str)) >= 0) ZOOM_options_set (options, "count", count_str); for (i = 0; i