+
+static int cmd_begin_trans( char *args[], WRBUF outbuff)
+{
+ int rw=0;
+ if (args[1] && ( (args[1][0]=='1') || (args[1][0]=='w') ))
+ rw=1;
+ return zebra_begin_trans(zh,rw);
+}
+
+static int cmd_end_trans( char *args[], WRBUF outbuff)
+{
+ return zebra_end_trans(zh);
+}
+/*************************************
+ * Inserting and deleting
+ */
+
+static int cmd_record_insert( char *args[], WRBUF outbuff)
+{
+ SYSNO sysno=0;
+ int rc;
+ char *rec=restargs(args,1);
+
+ rc = zebra_insert_record(zh,
+ 0, /* record type */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ rec,
+ strlen(rec),
+ 0);
+ if (0==rc)
+ {
+ wrbuf_printf(outbuff,"ok sysno=%d\n",sysno);
+ }
+ return rc;
+}
+
+
+static int cmd_exchange_record( char *args[], WRBUF outbuff)
+{
+ char *id = args[1];
+ char *action = args[2];
+ int rc;
+ char *rec=restargs(args,3);
+ if (!(id && action && args[4] ))
+ {
+ wrbuf_puts(outbuff,"Missing arguments!\n");
+ onecommand("help exchange_record", outbuff, "");
+ return -90;
+ }
+ rc=zebra_admin_exchange_record(zh, rec, strlen(rec),
+ id, strlen(id), atoi(action));
+ return rc;
+}
+
+/**********************************
+ * Searching and retrieving
+ */
+
+static int cmd_search_pqf(char *args[], WRBUF outbuff)
+{
+ zint hits = 0;
+ char *set = args[1];
+ char *qry = restargs(args,2);
+ int rc;
+ rc = zebra_search_PQF(zh, qry, set, &hits);
+ if (0==rc)
+ wrbuf_printf(outbuff, ZINT_FORMAT " hits found\n", hits);
+ return rc;
+}
+
+static int cmd_find( char *args[], WRBUF outbuff)
+{
+ char *setname=DEFAULTRESULTSET;
+ int rc;
+ zint hits = 0;
+ WRBUF qry = wrbuf_alloc();
+ if (0==strstr(args[0],"@attr"))
+ wrbuf_puts(qry, "@attr 1=/ ");
+ wrbuf_puts(qry,restargs(args,1));
+ if (!zh)
+ onecommand("quickstart", outbuff, "");
+ wrbuf_printf(outbuff, "find %s\n",wrbuf_buf(qry));
+ rc = zebra_search_PQF(zh, wrbuf_buf(qry), setname, &hits);
+ if (0==rc)
+ {
+ wrbuf_printf(outbuff, ZINT_FORMAT " hits found\n", hits);
+ nextrecno = 1;
+ }
+ wrbuf_free(qry, 1);
+ return rc;
+}
+
+static int cmd_show( char *args[], WRBUF outbuff)
+{
+ int start=defargint(args[1], nextrecno);
+ int nrecs=defargint(args[2],1);
+ char *setname=defarg(args[3],DEFAULTRESULTSET);
+ int rc=0;
+ ZebraRetrievalRecord *recs;
+ ODR odr;
+ Z_RecordComposition *pcomp=0;
+ int i;
+ oid_value format;
+
+ odr=odr_createmem(ODR_ENCODE);
+ recs= odr_malloc(odr,sizeof(ZebraRetrievalRecord)*nrecs);
+ rc =z_RecordComposition(odr, &pcomp, 0,"recordComposition");
+ format=oid_getvalbyname ("xml"); /*FIXME - let the user specify*/
+ for (i=0;i<nrecs;i++)
+ recs[i].position=start+i;
+
+ rc = zebra_records_retrieve (zh, odr, setname,
+ pcomp, format, nrecs,recs);
+ if (0==rc)
+ {
+ for (i=0;i<nrecs;i++)
+ {
+ printf("Err %d: %d\n",i,recs[i].errCode);
+ if (recs[i].buf)
+ {
+ wrbuf_printf(outbuff,"Record %d\n", recs[i].position);
+ wrbuf_write(outbuff, recs[i].buf, recs[i].len);
+ wrbuf_puts(outbuff, "\n");
+ } else
+ wrbuf_printf(outbuff,"NO Record %d\n", recs[i].position);
+ }
+ nextrecno=start+nrecs;
+ }
+ odr_destroy(odr);
+ return rc;
+} /* cmd_show */
+
+static int cmd_sort( char *args[], WRBUF outbuff)
+{
+ int rc=0;
+ ODR odr;
+ int sortstatus=0;
+ Z_SortKeySpecList *spec=0;
+ const char * inpsets[]={ DEFAULTRESULTSET, 0};
+ /* FIXME - allow the user to specify result sets in/out */
+
+ odr=odr_createmem(ODR_ENCODE);
+ spec=yaz_sort_spec (odr, restargs(args,1));
+ if (!spec)
+ rc=1;
+ if (!rc)
+ rc=zebra_sort(zh, odr,
+ 1, inpsets,
+ DEFAULTRESULTSET,
+ spec,
+ &sortstatus);
+ if (!rc)
+ wrbuf_printf(outbuff, "sort returned status %d\n",sortstatus);
+
+ odr_destroy(odr);
+ return rc;
+} /* cmd_sort */
+/*
+ *
+ * int bend_sort (void *handle, bend_sort_rr *rr)
+ * {
+ * ZebraHandle zh = (ZebraHandle) handle;
+ *
+ * zebra_sort (zh, rr->stream,
+ * rr->num_input_setnames, (const char **)
+ * rr->input_setnames,
+ * rr->output_setname,
+ * rr->sort_sequence,
+ * &rr->sort_status);
+ * zebra_result (zh, &rr->errcode,
+ * &rr->errstring);
+ * return 0;
+ * }
+ *
+ */
+
+/**************************************)