* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.36 1995-05-31 13:09:59 adam
+ * Revision 1.37 1995-06-01 07:31:20 adam
+ * Rename of many typedefs -> IrTcl_...
+ *
+ * Revision 1.36 1995/05/31 13:09:59 adam
* Client searches/presents may be interrupted.
* New moving book-logo.
*
*
* Revision 1.8 1995/03/15 08:25:16 adam
* New method presentStatus to check for error on present. Misc. cleanup
- * of IRRecordList manipulations. Full MARC record presentation in
+ * of IrTcl_RecordList manipulations. Full MARC record presentation in
* search.tcl.
*
* Revision 1.7 1995/03/14 17:32:29 adam
int type;
char *name;
int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
-} IRMethod;
+} IrTcl_Method;
typedef struct {
void *obj;
- IRMethod *tab;
-} IRMethods;
+ IrTcl_Method *tab;
+} IrTcl_Methods;
-static int do_disconnect (void *obj,Tcl_Interp *interp, int argc, char **argv);
+static int do_disconnect (void *obj, Tcl_Interp *interp,
+ int argc, char **argv);
-static IRRecordList *new_IR_record (IRSetObj *setobj, int no, int which)
+static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj,
+ int no, int which)
{
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
for (rl = setobj->record_list; rl; rl = rl->next)
{
return rl;
}
-static IRRecordList *find_IR_record (IRSetObj *setobj, int no)
+static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no)
{
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
for (rl = setobj->record_list; rl; rl = rl->next)
if (no == rl->no)
return NULL;
}
-static void delete_IR_records (IRSetObj *setobj)
+static void delete_IR_records (IrTcl_SetObj *setobj)
{
- IRRecordList *rl, *rl1;
+ IrTcl_RecordList *rl, *rl1;
for (rl = setobj->record_list; rl; rl = rl1)
{
* mk_nonSurrogateDiagnostics: Make Tcl result with diagnostic info
*/
static int mk_nonSurrogateDiagnostics (Tcl_Interp *interp,
- int condition,
- const char *addinfo)
+ int condition, const char *addinfo)
{
char buf[20];
const char *cp;
/*
* ir_method: Search for method in table and invoke method handler
*/
-int ir_method (Tcl_Interp *interp, int argc, char **argv, IRMethods *tab)
+int ir_method (Tcl_Interp *interp, int argc, char **argv, IrTcl_Methods *tab)
{
- IRMethods *tab_i = tab;
- IRMethod *t;
+ IrTcl_Methods *tab_i = tab;
+ IrTcl_Method *t;
for (tab_i = tab; tab_i->tab; tab_i++)
for (t = tab_i->tab; t->name; t++)
* ir_method_r: Get status for all readable elements
*/
int ir_method_r (void *obj, Tcl_Interp *interp, int argc, char **argv,
- IRMethod *tab)
+ IrTcl_Method *tab)
{
char *argv_n[3];
int argc_n;
memcpy ((*dst)->buf, src, (*dst)->len);
}
}
+
+static void get_referenceId (char **dst, Z_ReferenceId *src)
+{
+ free (*dst);
+ if (!src)
+ {
+ *dst = NULL;
+ return;
+ }
+ *dst = malloc (src->len+1);
+ memcpy (*dst, src->buf, src->len);
+ (*dst)[src->len] = '\0';
+}
+
/* ------------------------------------------------------- */
/*
* do_init_request: init method on IR object
*/
static int do_init_request (void *obj, Tcl_Interp *interp,
- int argc, char **argv)
+ int argc, char **argv)
{
Z_APDU apdu, *apdup = &apdu;
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
Z_InitRequest req;
int r;
{ "4", 3 },
{ NULL,0}
};
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc <= 0)
{
{ "namedResultSets", 14},
{ NULL, 0}
};
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc <= 0)
{
static int do_preferredMessageSize (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc <= 0)
{
* do_maximumRecordSize: Set/get maximum record size
*/
static int do_maximumRecordSize (void *obj, Tcl_Interp *interp,
- int argc, char **argv)
+ int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc <= 0)
{
static int do_initResult (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc <= 0)
return TCL_OK;
static int do_implementationName (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
return ir_strdup (interp, &p->implementationName, "TCL/TK on YAZ");
static int do_implementationId (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
return ir_strdup (interp, &p->implementationId, "81");
* do_targetImplementationName: Get Implementation Name of target.
*/
static int do_targetImplementationName (void *obj, Tcl_Interp *interp,
- int argc, char **argv)
+ int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_targetImplementationId (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_targetImplementationVersion (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_idAuthentication (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc >= 3 || argc == -1)
{
int argc, char **argv)
{
void *addr;
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
int r;
int protocol_type = PROTO_Z3950;
static int do_disconnect (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_comstack (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *obj = o;
+ IrTcl_Obj *obj = o;
if (argc == 0)
return ir_strdup (interp, &obj->cs_type, "tcpip");
static int do_protocol (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *obj = o;
+ IrTcl_Obj *obj = o;
if (argc == 0)
return ir_strdup (interp, &obj->protocol_type, "Z3950");
static int do_callback (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_failback (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
int argc, char **argv)
{
int i;
- IRSetCObj *p = obj;
+ IrTcl_SetCObj *p = obj;
if (argc == -1)
{
static int do_replaceIndicator (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = obj;
+ IrTcl_SetCObj *p = obj;
if (argc <= 0)
{
static int do_queryType (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = obj;
+ IrTcl_SetCObj *p = obj;
if (argc == 0)
return ir_strdup (interp, &p->queryType, "rpn");
static int do_userInformationField (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
if (argc == 0)
{
static int do_smallSetUpperBound (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = o;
+ IrTcl_SetCObj *p = o;
if (argc <= 0)
{
static int do_largeSetLowerBound (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = o;
+ IrTcl_SetCObj *p = o;
if (argc <= 0)
{
static int do_mediumSetPresentNumber (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = o;
+ IrTcl_SetCObj *p = o;
if (argc <= 0)
{
static int do_referenceId (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetCObj *p = obj;
+ IrTcl_SetCObj *p = obj;
if (argc == 0)
p->referenceId = NULL;
return TCL_OK;
}
-static IRMethod ir_method_tab[] = {
+static IrTcl_Method ir_method_tab[] = {
{ 1, "comstack", do_comstack },
{ 1, "protocol", do_protocol },
{ 0, "failback", do_failback },
{ 0, NULL, NULL}
};
-static IRMethod ir_set_c_method_tab[] = {
+static IrTcl_Method ir_set_c_method_tab[] = {
{ 0, "databaseNames", do_databaseNames},
{ 0, "replaceIndicator", do_replaceIndicator},
{ 0, "queryType", do_queryType },
* ir_obj_method: IR Object methods
*/
static int ir_obj_method (ClientData clientData, Tcl_Interp *interp,
-int argc, char **argv)
+ int argc, char **argv)
{
- IRMethods tab[3];
- IRObj *p = clientData;
+ IrTcl_Methods tab[3];
+ IrTcl_Obj *p = clientData;
if (argc < 2)
return ir_method_r (clientData, interp, argc, argv, ir_method_tab);
*/
static void ir_obj_delete (ClientData clientData)
{
- IRObj *obj = clientData;
- IRMethods tab[3];
+ IrTcl_Obj *obj = clientData;
+ IrTcl_Methods tab[3];
--(obj->ref_count);
if (obj->ref_count > 0)
* ir_obj_mk: IR Object creation
*/
static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp,
- int argc, char **argv)
+ int argc, char **argv)
{
- IRMethods tab[3];
- IRObj *obj;
+ IrTcl_Methods tab[3];
+ IrTcl_Obj *obj;
#if CCL2RPN
FILE *inf;
#endif
Z_Query query;
Z_APDU apdu, *apdup = &apdu;
Odr_oct ccl_query;
- IRSetObj *obj = o;
- IRObj *p = obj->parent;
+ IrTcl_SetObj *obj = o;
+ IrTcl_Obj *p = obj->parent;
int r;
oident bib1;
rpn = ccl_find_str(p->bibset, argv[2], &error, &pos);
if (error)
{
- Tcl_AppendResult (interp, "CCL error: ", ccl_err_msg(error),NULL);
+ Tcl_AppendResult (interp, "CCL error: ",
+ ccl_err_msg(error), NULL);
return TCL_ERROR;
}
ccl_pr_tree (rpn, stderr);
static int do_resultCount (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc <= 0)
return TCL_OK;
static int do_searchStatus (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc <= 0)
return TCL_OK;
static int do_presentStatus (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc <= 0)
return TCL_OK;
static int do_nextResultSetPosition (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc <= 0)
return TCL_OK;
static int do_setName (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc == 0)
return ir_strdup (interp, &obj->setName, "Default");
static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc < 0)
return TCL_OK;
*/
static int do_recordType (void *o, Tcl_Interp *interp, int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
int offset;
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
if (argc == 0)
{
*/
static int do_recordDiag (void *o, Tcl_Interp *interp, int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
int offset;
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
char buf[20];
if (argc <= 0)
*/
static int do_getMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
int offset;
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
if (argc <= 0)
return TCL_OK;
static int do_responseStatus (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
+ IrTcl_SetObj *obj = o;
if (argc == 0)
{
static int do_present (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *obj = o;
- IRObj *p = obj->parent;
+ IrTcl_SetObj *obj = o;
+ IrTcl_Obj *p = obj->parent;
Z_APDU apdu, *apdup = &apdu;
Z_PresentRequest req;
int start;
static int do_loadFile (void *o, Tcl_Interp *interp,
int argc, char **argv)
{
- IRSetObj *setobj = o;
+ IrTcl_SetObj *setobj = o;
FILE *inf;
size_t size;
int no = 1;
}
while ((buf = ir_tcl_fread_marc (inf, &size)))
{
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
rl = new_IR_record (setobj, no, Z_NamePlusRecord_databaseRecord);
rl->u.dbrec.buf = buf;
return TCL_OK;
}
-static IRMethod ir_set_method_tab[] = {
+static IrTcl_Method ir_set_method_tab[] = {
{ 0, "search", do_search },
{ 0, "searchStatus", do_searchStatus },
{ 0, "presentStatus", do_presentStatus },
static int ir_set_obj_method (ClientData clientData, Tcl_Interp *interp,
int argc, char **argv)
{
- IRMethods tabs[3];
- IRSetObj *p = clientData;
+ IrTcl_Methods tabs[3];
+ IrTcl_SetObj *p = clientData;
if (argc < 2)
{
*/
static void ir_set_obj_delete (ClientData clientData)
{
- IRMethods tabs[3];
- IRSetObj *p = clientData;
+ IrTcl_Methods tabs[3];
+ IrTcl_SetObj *p = clientData;
tabs[0].tab = ir_set_method_tab;
tabs[0].obj = p;
static int ir_set_obj_mk (ClientData clientData, Tcl_Interp *interp,
int argc, char **argv)
{
- IRMethods tabs[3];
- IRSetObj *obj;
+ IrTcl_Methods tabs[3];
+ IrTcl_SetObj *obj;
if (argc < 2 || argc > 3)
{
{
Tcl_CmdInfo parent_info;
int i;
- IRSetCObj *dst;
- IRSetCObj *src;
+ IrTcl_SetCObj *dst;
+ IrTcl_SetCObj *src;
if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
{
interp->result = "No parent";
return TCL_ERROR;
}
- obj->parent = (IRObj *) parent_info.clientData;
+ obj->parent = (IrTcl_Obj *) parent_info.clientData;
dst = &obj->set_inher;
src = &obj->parent->set_inher;
{
Z_ScanRequest req;
Z_APDU apdu, *apdup = &apdu;
- IRScanObj *obj = o;
- IRObj *p = obj->parent;
+ IrTcl_ScanObj *obj = o;
+ IrTcl_Obj *p = obj->parent;
int r;
oident bib1;
#if CCL2RPN
static int do_stepSize (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
{
p->stepSize = 0;
static int do_numberOfTermsRequested (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
{
static int do_preferredPositionInResponse (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
{
static int do_scanStatus (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
return TCL_OK;
static int do_numberOfEntriesReturned (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
return TCL_OK;
static int do_positionOfTerm (void *obj, Tcl_Interp *interp,
int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
if (argc <= 0)
return TCL_OK;
*/
static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv)
{
- IRScanObj *p = obj;
+ IrTcl_ScanObj *p = obj;
int i;
char numstr[20];
return TCL_OK;
}
-static IRMethod ir_scan_method_tab[] = {
+static IrTcl_Method ir_scan_method_tab[] = {
{ 0, "scan", do_scan },
{ 0, "stepSize", do_stepSize },
{ 0, "numberOfTermsRequested", do_numberOfTermsRequested },
static int ir_scan_obj_method (ClientData clientData, Tcl_Interp *interp,
int argc, char **argv)
{
- IRMethods tabs[2];
+ IrTcl_Methods tabs[2];
if (argc < 2)
{
*/
static void ir_scan_obj_delete (ClientData clientData)
{
- IRMethods tabs[2];
- IRScanObj *obj = clientData;
+ IrTcl_Methods tabs[2];
+ IrTcl_ScanObj *obj = clientData;
tabs[0].tab = ir_scan_method_tab;
tabs[0].obj = obj;
int argc, char **argv)
{
Tcl_CmdInfo parent_info;
- IRScanObj *obj;
- IRMethods tabs[2];
+ IrTcl_ScanObj *obj;
+ IrTcl_Methods tabs[2];
if (argc != 3)
{
if (!(obj = ir_malloc (interp, sizeof(*obj))))
return TCL_ERROR;
- obj->parent = (IRObj *) parent_info.clientData;
+ obj->parent = (IrTcl_Obj *) parent_info.clientData;
tabs[0].tab = ir_scan_method_tab;
tabs[0].obj = obj;
static void ir_initResponse (void *obj, Z_InitResponse *initrs)
{
- IRObj *p = obj;
+ IrTcl_Obj *p = obj;
p->initResult = *initrs->result ? 1 : 0;
if (!*initrs->result)
else
logf (LOG_DEBUG, "Connection accepted by target");
+ get_referenceId (&p->set_inher.referenceId, initrs->referenceId);
+
free (p->targetImplementationId);
ir_strdup (p->interp, &p->targetImplementationId,
initrs->implementationId);
static void ir_handleRecords (void *o, Z_Records *zrs)
{
- IRObj *p = o;
- IRSetObj *setobj = p->set_child;
+ IrTcl_Obj *p = o;
+ IrTcl_SetObj *setobj = p->set_child;
setobj->which = zrs->which;
setobj->recordFlag = 1;
else
{
int offset;
- IRRecordList *rl;
+ IrTcl_RecordList *rl;
setobj->numberOfRecordsReturned =
zrs->u.databaseOrSurDiagnostics->num_records;
static void ir_searchResponse (void *o, Z_SearchResponse *searchrs)
{
- IRObj *p = o;
- IRSetObj *setobj = p->set_child;
+ IrTcl_Obj *p = o;
+ IrTcl_SetObj *setobj = p->set_child;
Z_Records *zrs = searchrs->records;
- if (setobj)
+ logf (LOG_DEBUG, "Received search response");
+ if (!setobj)
{
- setobj->searchStatus = searchrs->searchStatus ? 1 : 0;
- setobj->resultCount = *searchrs->resultCount;
- if (searchrs->presentStatus)
- setobj->presentStatus = *searchrs->presentStatus;
- if (searchrs->nextResultSetPosition)
- setobj->nextResultSetPosition = *searchrs->nextResultSetPosition;
-
- logf (LOG_DEBUG, "Search response %d, %d hits",
- setobj->searchStatus, setobj->resultCount);
- if (zrs)
- ir_handleRecords (o, zrs);
- else
- setobj->recordFlag = 0;
- }
- else
logf (LOG_DEBUG, "Search response, no object!");
+ return;
+ }
+ setobj->searchStatus = searchrs->searchStatus ? 1 : 0;
+ get_referenceId (&setobj->set_inher.referenceId, searchrs->referenceId);
+ setobj->resultCount = *searchrs->resultCount;
+ if (searchrs->presentStatus)
+ setobj->presentStatus = *searchrs->presentStatus;
+ if (searchrs->nextResultSetPosition)
+ setobj->nextResultSetPosition = *searchrs->nextResultSetPosition;
+
+ logf (LOG_DEBUG, "Search response %d, %d hits",
+ setobj->searchStatus, setobj->resultCount);
+ if (zrs)
+ ir_handleRecords (o, zrs);
+ else
+ setobj->recordFlag = 0;
}
static void ir_presentResponse (void *o, Z_PresentResponse *presrs)
{
- IRObj *p = o;
- IRSetObj *setobj = p->set_child;
+ IrTcl_Obj *p = o;
+ IrTcl_SetObj *setobj = p->set_child;
Z_Records *zrs = presrs->records;
- logf (LOG_DEBUG, "Received presentResponse");
+ logf (LOG_DEBUG, "Received present response");
+ if (!setobj)
+ {
+ logf (LOG_DEBUG, "Present response, no object!");
+ return;
+ }
setobj->presentStatus = *presrs->presentStatus;
+ get_referenceId (&setobj->set_inher.referenceId, presrs->referenceId);
setobj->nextResultSetPosition = *presrs->nextResultSetPosition;
if (zrs)
ir_handleRecords (o, zrs);
static void ir_scanResponse (void *o, Z_ScanResponse *scanrs)
{
- IRObj *p = o;
- IRScanObj *scanobj = p->scan_child;
+ IrTcl_Obj *p = o;
+ IrTcl_ScanObj *scanobj = p->scan_child;
logf (LOG_DEBUG, "Received scanResponse");
+ get_referenceId (&p->set_inher.referenceId, scanrs->referenceId);
scanobj->scanStatus = *scanrs->scanStatus;
logf (LOG_DEBUG, "scanStatus=%d", scanobj->scanStatus);
*/
void ir_select_read (ClientData clientData)
{
- IRObj *p = clientData;
+ IrTcl_Obj *p = clientData;
Z_APDU *apdu;
int r;
Tcl_Eval (p->interp, p->failback);
do_disconnect (p, NULL, 2, NULL);
- /* relase ir object now if callback deleted it */
+ /* release ir object now if callback deleted it */
ir_obj_delete (p);
return;
}
*/
void ir_select_write (ClientData clientData)
{
- IRObj *p = clientData;
+ IrTcl_Obj *p = clientData;
int r;
logf (LOG_DEBUG, "In write handler");