/*
* IR toolkit for tcl/tk
- * (c) Index Data 1995-1996
+ * (c) Index Data 1995-1997
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.100 1997-05-01 15:04:05 adam
+ * Revision 1.103 1997-11-19 11:22:10 adam
+ * Object identifiers can be accessed in GRS-1 records.
+ *
+ * Revision 1.102 1997/09/17 12:22:40 adam
+ * Changed to use YAZ version 1.4. The new comstack utility, cs_straddr,
+ * is used.
+ *
+ * Revision 1.101 1997/09/09 10:19:53 adam
+ * New MSV5.0 port with fewer warnings.
+ *
+ * Revision 1.100 1997/05/01 15:04:05 adam
* Added ir-log command.
*
* Revision 1.99 1997/04/30 07:24:47 adam
r = Tcl_Eval (interp, tmp);
if (r == TCL_ERROR)
{
- logf (LOG_WARN, "Tcl error in line %d: %s", interp->errorLine,
- interp->result);
+ const char *errorInfo = Tcl_GetVar (interp, "errorInfo", 0);
+ logf (LOG_WARN, "Tcl error in line %d: %s\n%s", interp->errorLine,
+ interp->result, errorInfo ? errorInfo : "<null>");
}
Tcl_FreeResult (interp);
xfree (tmp);
if (!strcmp (p->comstackType, "tcpip"))
{
p->cs_link = cs_create (tcpip_type, CS_BLOCK, p->protocol_type);
- addr = tcpip_strtoaddr (argv[2]);
- if (!addr)
- {
- Tcl_AppendResult (interp, "tcpip_strtoaddr fail", NULL);
- return ir_tcl_error_exec (interp, argc, argv);
- }
logf (LOG_DEBUG, "tcp/ip connect %s", argv[2]);
}
else if (!strcmp (p->comstackType, "mosi"))
{
#if MOSI
p->cs_link = cs_create (mosi_type, CS_BLOCK, p->protocol_type);
- addr = mosi_strtoaddr (argv[2]);
- if (!addr)
- {
- Tcl_AppendResult (interp, "mosi_strtoaddr fail", NULL);
- return ir_tcl_error_exec (interp, argc, argv);
- }
logf (LOG_DEBUG, "mosi connect %s", argv[2]);
#else
Tcl_AppendResult (interp, "mosi not supported", NULL);
if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR)
return TCL_ERROR;
p->eventType = "connect";
+ addr = cs_straddr (p->cs_link, argv[2]);
+ if (!addr)
+ {
+ ir_tcl_disconnect (p);
+ Tcl_AppendResult (interp, "cs_straddr fail", NULL);
+ return ir_tcl_error_exec (interp, argc, argv);
+ }
if ((r=cs_connect (p->cs_link, addr)) < 0)
{
ir_tcl_disconnect (p);
odr_reset (p->odr_in);
+#if TCL_MAJOR_VERSION == 8
+ cs_fileno(p->cs_link) = -1;
+#endif
cs_close (p->cs_link);
p->cs_link = NULL;
int argc, char **argv)
{
IrTcl_Methods tab[3];
- IrTcl_Obj *p = clientData;
+ IrTcl_Obj *p = (IrTcl_Obj *) clientData;
int r;
if (argc < 2)
*/
static void ir_obj_delete (ClientData clientData)
{
- IrTcl_Obj *obj = clientData;
+ IrTcl_Obj *obj = (IrTcl_Obj *) clientData;
IrTcl_Methods tab[3];
--(obj->ref_count);
Tcl_AppendResult (interp, "Failed to initialize ", argv[1], NULL);
return TCL_ERROR;
}
- *subData = obj;
+ *subData = (ClientData) obj;
return TCL_OK;
}
Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
return TCL_ERROR;
}
- if (rl->u.dbrec.type != VAL_SUTRS)
+ if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_SUTRS)
return TCL_OK;
Tcl_AppendElement (interp, rl->u.dbrec.buf);
return TCL_OK;
Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
return TCL_ERROR;
}
- if (rl->u.dbrec.type != VAL_EXPLAIN)
+ if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_EXPLAIN)
return TCL_OK;
if (!(etype = z_ext_getentbyref (VAL_EXPLAIN)))
return TCL_OK;
-
+ assert (rl->u.dbrec.buf);
odr_setbuf (p->odr_in, rl->u.dbrec.buf, rl->u.dbrec.size, 0);
if (!(*etype->fun)(p->odr_in, &rr, 0))
return TCL_OK;
typedef struct {
int encoding;
int syntax;
- int size;
+ size_t size;
} IrTcl_FileRecordHead;
/*
int argc, char **argv)
{
IrTcl_Methods tabs[3];
- IrTcl_SetObj *p = clientData;
+ IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
int r;
if (argc < 2)
static void ir_set_obj_delete (ClientData clientData)
{
IrTcl_Methods tabs[3];
- IrTcl_SetObj *p = clientData;
+ IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
logf (LOG_DEBUG, "ir set delete");
if (ir_tcl_method (interp, 0, NULL, tabs, NULL) == TCL_ERROR)
return TCL_ERROR;
- *subData = obj;
+ *subData = (ClientData) obj;
return TCL_OK;
}
static void ir_scan_obj_delete (ClientData clientData)
{
IrTcl_Methods tabs[2];
- IrTcl_ScanObj *obj = clientData;
+ IrTcl_ScanObj *obj = (IrTcl_ScanObj *) clientData;
tabs[0].tab = ir_scan_method_tab;
tabs[0].obj = obj;
return TCL_OK;
}
mask = log_mask_str_x (argv[1], 0);
- logf (mask, "%s", argv[1], mask, argv[2]);
+ logf (LOG_DEBUG, "%s", argv[2]);
return TCL_OK;
}
&setobj->nonSurrogateDiagnosticNum);
if (zrs->which == Z_Records_DBOSD)
{
- setobj->numberOfRecordsReturned =
- zrs->u.databaseOrSurDiagnostics->num_records;
- logf (LOG_DEBUG, "Got %d records", setobj->numberOfRecordsReturned);
- for (offset = 0; offset < setobj->numberOfRecordsReturned; offset++)
+ int num_rec = setobj->numberOfRecordsReturned;
+
+ if (num_rec > zrs->u.databaseOrSurDiagnostics->num_records)
+ num_rec = zrs->u.databaseOrSurDiagnostics->num_records;
+ logf (LOG_DEBUG, "Got %d records", num_rec);
+ for (offset = 0; offset < num_rec; offset++)
{
Z_NamePlusRecord *znpr = zrs->u.databaseOrSurDiagnostics->
records[offset];
es = setobj->set_inher.smallSetElementSetNames;
else
es = setobj->set_inher.mediumSetElementSetNames;
+ setobj->numberOfRecordsReturned = *searchrs->numberOfRecordsReturned;
ir_handleZRecords (o, zrs, setobj, es);
}
else
+ {
+ setobj->numberOfRecordsReturned = 0;
setobj->recordFlag = 0;
+ }
}
get_referenceId (&setobj->set_inher.referenceId, presrs->referenceId);
setobj->nextResultSetPosition = *presrs->nextResultSetPosition;
if (zrs)
+ {
+ setobj->numberOfRecordsReturned = *presrs->numberOfRecordsReturned;
ir_handleZRecords (o, zrs, setobj, setobj->set_inher.elementSetNames);
+ }
else
{
+ setobj->numberOfRecordsReturned = 0;
setobj->recordFlag = 0;
logf (LOG_DEBUG, "No records!");
}
*/
static void ir_select_read (ClientData clientData)
{
- IrTcl_Obj *p = clientData;
+ IrTcl_Obj *p = (IrTcl_Obj *) clientData;
Z_APDU *apdu;
int r;
IrTcl_Request *rq;
p->failInfo = IR_TCL_FAIL_CONNECT;
ir_tcl_eval (p->interp, p->failback);
}
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return;
}
if (p->callback)
if (p->ref_count == 2 && p->cs_link && p->request_queue
&& p->state == IR_TCL_R_Idle)
ir_tcl_send_q (p, p->request_queue, "x");
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return;
}
do
if (r <= 0)
{
logf (LOG_DEBUG, "cs_get failed, code %d", r);
- ir_select_remove (cs_fileno (p->cs_link), p);
ir_tcl_disconnect (p);
if (p->failback)
{
ir_tcl_eval (p->interp, p->failback);
}
/* release ir object now if callback deleted it */
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return;
}
/* got complete APDU. Now decode */
ir_tcl_eval (p->interp, p->failback);
}
/* release ir object now if failback deleted it */
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return;
}
/* handle APDU and invoke callback */
odr_reset (p->odr_in);
if (p->ref_count == 1)
{
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return;
}
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
} while (p->cs_link && cs_more (p->cs_link));
if (p->cs_link && p->request_queue && p->state == IR_TCL_R_Idle)
ir_tcl_send_q (p, p->request_queue, "x");
*/
static int ir_select_write (ClientData clientData)
{
- IrTcl_Obj *p = clientData;
+ IrTcl_Obj *p = (IrTcl_Obj *) clientData;
int r;
IrTcl_Request *rq;
p->failInfo = IR_TCL_FAIL_CONNECT;
ir_tcl_eval (p->interp, p->failback);
}
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return 2;
}
if (p->callback)
ir_tcl_eval (p->interp, p->callback);
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
return 2;
}
rq = p->request_queue;
p->failInfo = IR_TCL_FAIL_WRITE;
ir_tcl_eval (p->interp, p->failback);
}
- ir_obj_delete (p);
+ ir_obj_delete ((ClientData) p);
}
else if (r == 0) /* remove select bit */
{
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
Tcl_CreateCommand (interp, "ir-log", ir_log_proc,
(ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
+ nmem_init ();
return TCL_OK;
}