* (c) Index Data 1995
*
* $Log: ir-tcl.c,v $
- * Revision 1.4 1995-03-09 16:15:08 adam
+ * Revision 1.5 1995-03-10 18:00:15 adam
+ * Actual presentation in line-by-line format. RPN query support.
+ *
+ * Revision 1.4 1995/03/09 16:15:08 adam
* First presentRequest attempts. Hot-target list.
*
*/
#include <sys/time.h>
#include <assert.h>
+#include <yaz-ccl.h>
+#include <iso2709p.h>
#include <comstack.h>
#include <tcpip.h>
#include <xmosi.h>
int replaceIndicator;
char **databaseNames;
int num_databaseNames;
+ char *query_method;
+
+ CCL_bibset bibset;
struct IRSetObj_ *child;
} IRObj;
+typedef struct IRRecordList_ {
+ int status;
+ Iso2709Rec rec;
+ int no;
+ struct IRRecordList_ *next;
+} IRRecordList;
+
typedef struct IRSetObj_ {
IRObj *parent;
int resultCount;
+ int start;
+ int number;
+ int numberOfRecordsReturned;
+ Z_Records *z_records;
+ IRRecordList *record_list;
} IRSetObj;
typedef struct {
return TCL_OK;
}
+/*
+ * do_query: Set/Get query mothod
+ */
+static int do_query (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRObj *p = obj;
+ if (argc == 3)
+ {
+ free (p->query_method);
+ if (ir_strdup (interp, &p->query_method, argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendResult (interp, p->query_method, NULL);
+ return TCL_OK;
+}
+
/*
* ir_obj_method: IR Object methods
*/
int argc, char **argv)
{
static IRMethod tab[] = {
- { "comstack", do_comstack },
- { "connect", do_connect },
- { "protocolVersion", do_protocolVersion },
- { "options", do_options },
- { "preferredMessageSize", do_preferredMessageSize },
- { "maximumMessageSize", do_maximumMessageSize },
- { "implementationName", do_implementationName },
- { "implementationId", do_implementationId },
- { "idAuthentication", do_idAuthentication },
- { "init", do_init_request },
- { "disconnect", do_disconnect },
- { "callback", do_callback },
- { "databaseNames", do_databaseNames},
+ { "comstack", do_comstack },
+ { "connect", do_connect },
+ { "protocolVersion", do_protocolVersion },
+ { "options", do_options },
+ { "preferredMessageSize", do_preferredMessageSize },
+ { "maximumMessageSize", do_maximumMessageSize },
+ { "implementationName", do_implementationName },
+ { "implementationId", do_implementationId },
+ { "idAuthentication", do_idAuthentication },
+ { "init", do_init_request },
+ { "disconnect", do_disconnect },
+ { "callback", do_callback },
+ { "databaseNames", do_databaseNames},
+ { "query", do_query },
{ NULL, NULL}
};
if (argc < 2)
int argc, char **argv)
{
IRObj *obj;
+ FILE *inf;
if (argc != 2)
{
}
obj->cs_link = cs_create (tcpip_type);
- obj->maximumMessageSize = 9000;
+ obj->maximumMessageSize = 32768;
obj->preferredMessageSize = 4096;
obj->idAuthentication = NULL;
obj->replaceIndicator = 1;
obj->databaseNames = NULL;
obj->num_databaseNames = 0;
-
+ if (ir_strdup (interp, &obj->query_method, "rpn") == TCL_ERROR)
+ return TCL_ERROR;
+ obj->bibset = ccl_qual_mk ();
+ if ((inf = fopen ("default.bib", "r")))
+ {
+ ccl_qual_file (obj->bibset, inf);
+ fclose (inf);
+ }
ODR_MASK_ZERO (&obj->protocolVersion);
ODR_MASK_SET (&obj->protocolVersion, 0);
ODR_MASK_SET (&obj->protocolVersion, 1);
obj->buf_in = NULL;
obj->callback = NULL;
-
Tcl_CreateCommand (interp, argv[1], ir_obj_method,
(ClientData) obj, ir_obj_delete);
return TCL_OK;
req.preferredRecordSyntax = 0;
req.query = &query;
- query.which = Z_Query_type_2;
- query.u.type_2 = &ccl_query;
- ccl_query.buf = argv[2];
- ccl_query.len = strlen (argv[2]);
+ if (!strcmp (p->query_method, "rpn"))
+ {
+ int error;
+ int pos;
+ struct ccl_rpn_node *rpn;
+ Z_RPNQuery *RPNquery;
+ rpn = ccl_find_str(p->bibset, argv[2], &error, &pos);
+ if (error)
+ {
+ Tcl_AppendResult (interp, "CCL error: ", ccl_err_msg(error),NULL);
+ return TCL_ERROR;
+ }
+ query.which = Z_Query_type_1;
+ assert((RPNquery = ccl_rpn_query(rpn)));
+ RPNquery->attributeSetId = bib1;
+ query.u.type_1 = RPNquery;
+ }
+ else if (!strcmp (p->query_method, "ccl"))
+ {
+ query.which = Z_Query_type_2;
+ query.u.type_2 = &ccl_query;
+ ccl_query.buf = argv[2];
+ ccl_query.len = strlen (argv[2]);
+ }
+ else
+ {
+ interp->result = "unknown query method";
+ return TCL_ERROR;
+ }
if (!z_APDU (p->odr_out, &apdup, 0))
{
interp->result = odr_errlist [odr_geterror (p->odr_out)];
interp->result = "cs_put failed in init";
return TCL_ERROR;
}
+ printf ("Search request\n");
return TCL_OK;
}
/*
- * do_query: Set query for a Set Object
+ * do_resultCount: Get number of hits
*/
-static int do_query (void *obj, Tcl_Interp *interp,
+static int do_resultCount (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
+ IRSetObj *obj = o;
+
+ sprintf (interp->result, "%d", obj->resultCount);
return TCL_OK;
}
/*
- * do_resultCount: Get number of hits
+ * do_numberOfRecordsReturned: Get number of records returned
*/
-static int do_resultCount (void *o, Tcl_Interp *interp,
+static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
IRSetObj *obj = o;
- sprintf (interp->result, "%d", obj->resultCount);
+ sprintf (interp->result, "%d", obj->numberOfRecordsReturned);
return TCL_OK;
}
+static int get_marc_record(Tcl_Interp *interp, Iso2709Rec rec,
+ int argc, char **argv)
+{
+ struct iso2709_dir *dir;
+ struct iso2709_field *field;
+
+ for (dir = rec->directory; dir; dir = dir->next)
+ {
+ if (strcmp (dir->tag, argv[3]))
+ continue;
+ for (field = dir->fields; field; field = field->next)
+ {
+ if (argc > 4 && strcmp (field->identifier, argv[4]))
+ continue;
+ Tcl_AppendElement (interp, field->data);
+ }
+ }
+ return TCL_OK;
+}
/*
- * do_present: Perform present Request
+ * do_getRecord: Get an ISO2709 Record
+ */
+static int do_getRecord (void *o, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRSetObj *obj = o;
+ int offset;
+ IRRecordList *rl;
+
+ if (argc < 3)
+ {
+ sprintf (interp->result, "wrong # args");
+ return TCL_ERROR;
+ }
+ if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
+ return TCL_ERROR;
+ for (rl = obj->record_list; rl; rl = rl->next)
+ {
+ if (rl->no == offset)
+ break;
+ }
+ if (!rl)
+ {
+ Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
+ return TCL_ERROR;
+ }
+ if (!rl->rec)
+ {
+ Tcl_AppendResult (interp, "Not a MARC record at #", argv[2], NULL);
+ return TCL_ERROR;
+ }
+ return get_marc_record (interp, rl->rec, argc, argv);
+}
+
+/*
+ * do_present: Perform Present Request
*/
static int do_present (void *o, Tcl_Interp *interp,
}
else
number = 10;
+ obj->start = start;
+ obj->number = number;
+
apdup = &apdu;
apdu.which = Z_APDU_presentRequest;
apdu.u.presentRequest = &req;
interp->result = "cs_put failed in init";
return TCL_ERROR;
}
- printf ("Present request\n");
+ printf ("Present request, start=%d, num=%d\n", start, number);
return TCL_OK;
}
int argc, char **argv)
{
static IRMethod tab[] = {
- { "query", do_query },
- { "search", do_search },
- { "resultCount", do_resultCount },
- { "present", do_present },
+ { "search", do_search },
+ { "resultCount", do_resultCount },
+ { "numberOfRecordsReturned", do_numberOfRecordsReturned },
+ { "present", do_present },
+ { "getRecord", do_getRecord },
{ NULL, NULL}
};
interp->result = "malloc fail";
return TCL_ERROR;
}
+ obj->z_records = NULL;
+ obj->record_list = NULL;
obj->parent = (IRObj *) parent_info.clientData;
Tcl_CreateCommand (interp, argv[1], ir_set_obj_method,
(ClientData) obj, ir_set_obj_delete);
static void ir_presentResponse (void *o, Z_PresentResponse *presrs)
{
IRObj *p = o;
- IRSetObj *obj = p->child;
-
- printf("Received presentResponse.\n");
- if (presrs->records)
- printf ("Got records\n");
+ IRSetObj *setobj = p->child;
+ Z_Records *zrs = presrs->records;
+ setobj->z_records = presrs->records;
+
+ printf ("Received presentResponse\n");
+ if (zrs)
+ {
+ if (zrs->which == Z_Records_NSD)
+ {
+ setobj->numberOfRecordsReturned = 0;
+ printf ("They are diagnostic!!!\n");
+ /*
+ char buf[16];
+ sprintf (buf, "%d", *zrs->u.nonSurrogateDiagnostic->condition);
+ Tcl_AppendResult (interp, "Diagnostic message: ", buf,
+ " : ",
+ zrs->u.nonSurrogateDiagnostic->addinfo, NULL);
+ return TCL_ERROR;
+ */
+ return;
+ }
+ else
+ {
+ int offset;
+ IRRecordList *rl;
+
+ setobj->numberOfRecordsReturned =
+ zrs->u.databaseOrSurDiagnostics->num_records;
+ printf ("Got %d records\n", setobj->numberOfRecordsReturned);
+ for (offset = 0; offset<setobj->numberOfRecordsReturned; offset++)
+ {
+ int no = setobj->start + offset;
+
+ for (rl = setobj->record_list; rl; rl = rl->next)
+ {
+ if (no == rl->no)
+ {
+ if (rl->rec)
+ iso2709_rm (rl->rec);
+ break;
+ }
+ }
+ if (!rl)
+ {
+ rl = malloc (sizeof(*rl));
+ assert (rl);
+ rl->next = setobj->record_list;
+ rl->no = no;
+ rl->status = 0;
+ setobj->record_list = rl;
+ }
+ if (zrs->u.databaseOrSurDiagnostics->records[offset]->which ==
+ Z_NamePlusRecord_surrogateDiagnostic)
+ {
+ rl->status = -1;
+ rl->rec = NULL;
+ }
+ else
+ {
+ Z_DatabaseRecord *zr;
+ Odr_external *oe;
+
+ rl->status = 0;
+ zr = zrs->u.databaseOrSurDiagnostics->records[offset]
+ ->u.databaseRecord;
+ oe = (Odr_external*) zr;
+ if (oe->which == ODR_EXTERNAL_octet
+ && zr->u.octet_aligned->len)
+ {
+ const char *buf = (char*) zr->u.octet_aligned->buf;
+ rl->rec = iso2709_cvt (buf);
+ }
+ }
+ }
+ }
+ }
else
- printf("No records\n");
+ {
+ printf ("No records!\n");
+ }
}
void ir_select_proc (ClientData clientData)