X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=ir-tcl.c;h=8355899bd16cb3502fe2e155fee8603b91a9bf46;hb=1b8061ca3570938335e6b538bfc514504abec092;hp=3c6de3b88fcf790697772285f6a7c5cd8909bd6a;hpb=2563fe310b913cb85d82c641f81361214e24384c;p=ir-tcl-moved-to-github.git diff --git a/ir-tcl.c b/ir-tcl.c index 3c6de3b..8355899 100644 --- a/ir-tcl.c +++ b/ir-tcl.c @@ -5,7 +5,21 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ir-tcl.c,v $ - * Revision 1.73 1996-01-29 11:35:19 adam + * Revision 1.77 1996-02-20 17:52:58 adam + * Uses the YAZ oid system to name record syntax object identifiers. + * + * Revision 1.76 1996/02/20 16:09:51 adam + * Bug fix: didn't set element set names stamp correctly on result + * set records when element set names were set to the empty string. + * + * Revision 1.75 1996/02/19 15:41:53 adam + * Better log messages. + * Minor improvement of connect method. + * + * Revision 1.74 1996/02/05 17:58:03 adam + * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1. + * + * Revision 1.73 1996/01/29 11:35:19 adam * Bug fix: cs_type member renamed to comstackType to avoid conflict with * cs_type macro defined by YAZ. * @@ -262,11 +276,7 @@ #include #include #include -#ifdef WINDOWS #include -#else -#include -#endif #include #define CS_BLOCK 0 @@ -294,6 +304,8 @@ static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, { IrTcl_RecordList *rl; + if (elements && !*elements) + elements = NULL; for (rl = setobj->record_list; rl; rl = rl->next) { if (no == rl->no && (!rl->elements || !elements || @@ -326,30 +338,6 @@ static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj, return rl; } -static struct { - enum oid_value value; - const char *name; -} IrTcl_recordSyntaxTab[] = { -{ VAL_UNIMARC, "UNIMARC" }, -{ VAL_INTERMARC, "INTERMARC" }, -{ VAL_CCF, "CCF" }, -{ VAL_USMARC, "USMARC" }, -{ VAL_UKMARC, "UKMARC" }, -{ VAL_NORMARC, "NORMARC" }, -{ VAL_LIBRISMARC, "LIBRISMARC" }, -{ VAL_DANMARC, "DANMARC" }, -{ VAL_FINMARC, "FINMARC" }, -{ VAL_MAB, "MAB" }, -{ VAL_CANMARC, "CANMARC" }, -{ VAL_SBN, "SBN" }, -{ VAL_PICAMARC, "PICAMARC" }, -{ VAL_AUSMARC, "AUSMARC" }, -{ VAL_IBERMARC, "IBERMARC" }, -{ VAL_SUTRS, "SUTRS" }, -{ VAL_GRS1, "GRS1" }, -{ 0, NULL } -}; - /* * IrTcl_eval */ @@ -371,13 +359,21 @@ int IrTcl_eval (Tcl_Interp *interp, const char *command) /* * IrTcl_getRecordSyntaxStr: Return record syntax name of object id */ -static const char *IrTcl_getRecordSyntaxStr (enum oid_value value) +static char *IrTcl_getRecordSyntaxStr (enum oid_value value) { - int i; - for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) - if (IrTcl_recordSyntaxTab[i].value == value) - return IrTcl_recordSyntaxTab[i].name; - return "USMARC"; + int *o; + struct oident ent, *entp; + + ent.proto = PROTO_Z3950; + ent.oclass = CLASS_RECSYN; + ent.value = value; + + o = oid_getoidbyent (&ent); + entp = oid_getentbyoid (o); + + if (!entp) + return ""; + return entp->desc; } /* @@ -385,11 +381,7 @@ static const char *IrTcl_getRecordSyntaxStr (enum oid_value value) */ static enum oid_value IrTcl_getRecordSyntaxVal (const char *name) { - int i; - for (i = 0; IrTcl_recordSyntaxTab[i].name; i++) - if (!strcmp (IrTcl_recordSyntaxTab[i].name, name)) - return IrTcl_recordSyntaxTab[i].value; - return 0; + return oid_getvalbyname (name); } static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no) @@ -1023,8 +1015,6 @@ static int do_connect (void *obj, Tcl_Interp *interp, interp->result = "already connected"; return TCL_ERROR; } - if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR) - return TCL_ERROR; if (!strcmp (p->comstackType, "tcpip")) { p->cs_link = cs_create (tcpip_type, CS_BLOCK, p->protocol_type); @@ -1058,18 +1048,36 @@ static int do_connect (void *obj, Tcl_Interp *interp, p->comstackType, NULL); return TCL_ERROR; } + if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR) + return TCL_ERROR; +#if IRTCL_GENERIC_FILES +#ifdef WINDOWS + p->csFile = Tcl_GetFile (cs_fileno(p->cs_link), TCL_WIN_SOCKET); +#else + p->csFile = Tcl_GetFile (cs_fileno(p->cs_link), TCL_UNIX_FD); +#endif +#endif if ((r=cs_connect (p->cs_link, addr)) < 0) { interp->result = "connect fail"; do_disconnect (p, NULL, 2, NULL); return TCL_ERROR; } - logf(LOG_DEBUG, "cs_connect() returned %d", r); + logf(LOG_DEBUG, "cs_connect() returned %d fd=%d", r, + cs_fileno(p->cs_link)); p->eventType = "connect"; +#if IRTCL_GENERIC_FILES + ir_select_add (p->csFile, p); +#else ir_select_add (cs_fileno (p->cs_link), p); +#endif if (r == 1) { +#if IRTCL_GENERIC_FILES + ir_select_add_write (p->csFile, p); +#else ir_select_add_write (cs_fileno (p->cs_link), p); +#endif p->state = IR_TCL_R_Connecting; } else @@ -1098,21 +1106,33 @@ static int do_disconnect (void *obj, Tcl_Interp *interp, p->eventType = NULL; p->hostname = NULL; p->cs_link = NULL; +#if IRTCL_GENERIC_FILES + p->csFile = 0; +#endif return TCL_OK; } if (p->hostname) { + logf(LOG_DEBUG, "Closing connection to %s", p->hostname); free (p->hostname); p->hostname = NULL; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); + ir_select_remove (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); ir_select_remove (cs_fileno (p->cs_link), p); +#endif odr_reset (p->odr_in); assert (p->cs_link); - logf(LOG_DEBUG, "Closing connection"); cs_close (p->cs_link); p->cs_link = NULL; +#if IRTCL_GENERIC_FILES + Tcl_FreeFile (p->csFile); + p->csFile = NULL; +#endif ODR_MASK_ZERO (&p->options); ODR_MASK_SET (&p->options, 0); @@ -1540,6 +1560,11 @@ static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp, ir_tcl_malloc (sizeof(*p->preferredRecordSyntax)))) *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]); } + else if (argc == 2) + { + Tcl_AppendElement (interp, IrTcl_getRecordSyntaxStr + (*p->preferredRecordSyntax)); + } return TCL_OK; } @@ -1746,7 +1771,7 @@ static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp, } #endif - logf (LOG_DEBUG, "ir object create"); + logf (LOG_DEBUG, "ir object create %s", argv[1]); obj->odr_in = odr_createmem (ODR_DECODE); obj->odr_out = odr_createmem (ODR_ENCODE); obj->odr_pr = odr_createmem (ODR_PRINT); @@ -1990,7 +2015,10 @@ static int do_resultCount (void *o, Tcl_Interp *interp, IrTcl_SetObj *obj = o; if (argc <= 0) + { + obj->resultCount = 0; return TCL_OK; + } return get_set_int (&obj->resultCount, interp, argc, argv); } @@ -3349,7 +3377,7 @@ void ir_select_read (ClientData clientData) Tcl_CmdInfo cmd_info; const char *apdu_call; - logf(LOG_DEBUG, "Read handler"); + logf(LOG_DEBUG, "Read handler fd=%d", cs_fileno(p->cs_link)); if (p->state == IR_TCL_R_Connecting) { logf(LOG_DEBUG, "Connect handler"); @@ -3360,7 +3388,11 @@ void ir_select_read (ClientData clientData) return; } p->state = IR_TCL_R_Idle; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (r < 0) { logf (LOG_DEBUG, "cs_rcvconnect error"); @@ -3390,7 +3422,11 @@ void ir_select_read (ClientData clientData) if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) <= 0) { logf (LOG_DEBUG, "cs_get failed, code %d", r); +#if IRTCL_GENERIC_FILES + ir_select_remove (p->csFile, p); +#else ir_select_remove (cs_fileno (p->cs_link), p); +#endif do_disconnect (p, NULL, 2, NULL); if (p->failback) { @@ -3511,7 +3547,7 @@ void ir_select_write (ClientData clientData) int r; IrTcl_Request *rq; - logf (LOG_DEBUG, "Write handler"); + logf (LOG_DEBUG, "Write handler fd=%d", cs_fileno(p->cs_link)); if (p->state == IR_TCL_R_Connecting) { logf(LOG_DEBUG, "Connect handler"); @@ -3522,7 +3558,11 @@ void ir_select_write (ClientData clientData) if (r < 0) { logf (LOG_DEBUG, "cs_rcvconnect error"); +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (p->failback) { p->failInfo = IR_TCL_FAIL_CONNECT; @@ -3531,7 +3571,11 @@ void ir_select_write (ClientData clientData) do_disconnect (p, NULL, 2, NULL); return; } +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif if (p->callback) IrTcl_eval (p->interp, p->callback); return; @@ -3556,7 +3600,11 @@ void ir_select_write (ClientData clientData) { logf(LOG_DEBUG, "Write completed"); p->state = IR_TCL_R_Waiting; +#if IRTCL_GENERIC_FILES + ir_select_remove_write (p->csFile, p); +#else ir_select_remove_write (cs_fileno (p->cs_link), p); +#endif free (rq->buf_out); rq->buf_out = NULL; }