- int pos = i + start;
- Z3950_record rec = Z3950_resultset_record (r, pos);
- const char *db = Z3950_record_get (rec, "database", 0);
- int len;
- const char *render = Z3950_record_get (rec, "render", &len);
- const char *syntax = Z3950_record_get (rec, "syntax", 0);
- /* if rec is non-null, we got a record for display */
- if (rec)
- {
- printf ("%d %s %s\n", pos+1, (db ? db : "unknown"), syntax);
- if (render)
- fwrite (render, 1, len, stdout);
- putchar ('\n');
- }
+ int pos = i + start;
+ ZOOM_record rec = ZOOM_resultset_record(r, pos);
+ const char *db = ZOOM_record_get(rec, "database", 0);
+
+ if (ZOOM_record_error(rec, 0, 0, 0))
+ {
+ const char *msg;
+ const char *addinfo;
+ const char *diagset;
+ int error = ZOOM_record_error(rec, &msg, &addinfo, &diagset);
+
+ printf("%d %s: %s (%s:%d) %s\n", pos, (db ? db : "unknown"),
+ msg, diagset, error, addinfo ? addinfo : "none");
+ }
+ else
+ {
+ int len, opac_len;
+ const char *render = ZOOM_record_get(rec, type, &len);
+ const char *opac_render = ZOOM_record_get(rec, "opac", &opac_len);
+ const char *syntax = ZOOM_record_get(rec, "syntax", 0);
+ const char *schema = ZOOM_record_get(rec, "schema", 0);
+ /* if rec is non-null, we got a record for display */
+ if (rec)
+ {
+ printf("%d database=%s syntax=%s schema=%s\n",
+ pos, (db ? db : "unknown"), syntax,
+ schema ? schema : "unknown");
+ if (render)
+ {
+ if (fwrite(render, 1, len, stdout) != (size_t) len)
+ {
+ printf("write to stdout failed\n");
+ }
+ }
+ printf("\n");
+ if (opac_render)
+ {
+ if (fwrite(opac_render, 1, opac_len, stdout) != (size_t)
+ opac_len)
+ printf("write to stdout failed\n");
+ }
+ }
+ }
+ }
+}
+
+static void cmd_show(ZOOM_connection *c, ZOOM_resultset *r,
+ ZOOM_options options,
+ const char **args)
+{
+ int i;
+ char start_str[10], count_str[10], render_str[60];
+ const char *type = "render";
+
+ 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)) <= 0)
+ strcpy(count_str, "1");
+ ZOOM_options_set(options, "count", count_str);
+
+ if (next_token_copy(args, render_str, sizeof(render_str)) >= 0)
+ type = render_str;
+
+ for (i = 0; i<MAX_CON; i++)
+ ZOOM_resultset_records(r[i], 0, atoi(start_str), atoi(count_str));
+ while (ZOOM_event(MAX_CON, c))
+ ;
+
+ for (i = 0; i<MAX_CON; i++)
+ {
+ int error;
+ const char *errmsg, *addinfo, *dset;
+ /* display errors if any */
+ if (!c[i])
+ continue;
+ if ((error = ZOOM_connection_error_x(c[i], &errmsg, &addinfo, &dset)))
+ printf("%s error: %s (%s:%d) %s\n",
+ ZOOM_connection_option_get(c[i], "host"), errmsg,
+ dset, error, addinfo);
+ else if (r[i])
+ {
+ /* OK, no major errors. Display records... */
+ int start = ZOOM_options_get_int(options, "start", 0);
+ int count = ZOOM_options_get_int(options, "count", 0);
+ display_records(c[i], r[i], start, count, type);
+ }