2 * IR toolkit for tcl/tk
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.28 1995-05-23 15:34:48 adam
8 * Many new settings, userInformationField, smallSetUpperBound, etc.
9 * A number of settings are inherited when ir-set is executed.
10 * This version is incompatible with the graphical test client (client.tcl).
12 * Revision 1.27 1995/05/11 15:34:47 adam
13 * Scan request changed a bit. This version works with RLG.
15 * Revision 1.26 1995/04/18 16:11:51 adam
16 * First version of graphical Scan. Some work on query-by-form.
18 * Revision 1.25 1995/04/17 09:37:17 adam
19 * Further development of scan.
21 * Revision 1.24 1995/04/11 14:16:42 adam
22 * Further work on scan. Response works. Entries aren't saved yet.
24 * Revision 1.23 1995/04/10 10:50:27 adam
25 * Result-set name defaults to suffix of ir-set name.
26 * Started working on scan. Not finished at this point.
28 * Revision 1.22 1995/03/31 10:43:03 adam
29 * More robust when getting bad MARC records.
31 * Revision 1.21 1995/03/31 08:56:37 adam
32 * New button "Search".
34 * Revision 1.20 1995/03/29 16:07:09 adam
35 * Bug fix: Didn't use setName in present request.
37 * Revision 1.19 1995/03/28 12:45:23 adam
38 * New ir method failback: called on disconnect/protocol error.
39 * New ir set/get method: protocol: SR / Z3950.
40 * Simple popup and disconnect when failback is invoked.
42 * Revision 1.18 1995/03/21 15:50:12 adam
45 * Revision 1.17 1995/03/21 13:41:03 adam
46 * Comstack cs_create not used too often. Non-blocking connect.
48 * Revision 1.16 1995/03/21 08:26:06 adam
49 * New method, setName, to specify the result set name (other than Default).
50 * New method, responseStatus, which returns diagnostic info, if any, after
51 * present response / search response.
53 * Revision 1.15 1995/03/20 15:24:07 adam
54 * Diagnostic records saved on searchResponse.
56 * Revision 1.14 1995/03/20 08:53:22 adam
57 * Event loop in tclmain.c rewritten. New method searchStatus.
59 * Revision 1.13 1995/03/17 18:26:17 adam
60 * Non-blocking i/o used now. Database names popup as cascade items.
62 * Revision 1.12 1995/03/17 15:45:00 adam
63 * Improved target/database setup.
65 * Revision 1.11 1995/03/16 17:54:03 adam
66 * Minor changes really.
68 * Revision 1.10 1995/03/15 16:14:50 adam
69 * Blocking arg in cs_create changed.
71 * Revision 1.9 1995/03/15 13:59:24 adam
74 * Revision 1.8 1995/03/15 08:25:16 adam
75 * New method presentStatus to check for error on present. Misc. cleanup
76 * of IRRecordList manipulations. Full MARC record presentation in
79 * Revision 1.7 1995/03/14 17:32:29 adam
80 * Presentation of full Marc record in popup window.
82 * Revision 1.6 1995/03/12 19:31:55 adam
83 * Pattern matching implemented when retrieving MARC records. More
84 * diagnostic functions.
86 * Revision 1.5 1995/03/10 18:00:15 adam
87 * Actual presentation in line-by-line format. RPN query support.
89 * Revision 1.4 1995/03/09 16:15:08 adam
90 * First presentRequest attempts. Hot-target list.
106 int (*method) (void *obj, Tcl_Interp *interp, int argc, char **argv);
110 static int do_disconnect (void *obj,Tcl_Interp *interp, int argc, char **argv);
112 static IRRecordList *new_IR_record (IRSetObj *setobj, int no, int which)
116 for (rl = setobj->record_list; rl; rl = rl->next)
122 case Z_NamePlusRecord_databaseRecord:
123 iso2709_rm (rl->u.marc.rec);
125 case Z_NamePlusRecord_surrogateDiagnostic:
126 free (rl->u.diag.addinfo);
127 rl->u.diag.addinfo = NULL;
135 rl = malloc (sizeof(*rl));
137 rl->next = setobj->record_list;
139 setobj->record_list = rl;
145 static IRRecordList *find_IR_record (IRSetObj *setobj, int no)
149 for (rl = setobj->record_list; rl; rl = rl->next)
156 * getsetint: Set/get integer value
158 static int get_set_int (int *val, Tcl_Interp *interp, int argc, char **argv)
164 if (Tcl_GetInt (interp, argv[2], val)==TCL_ERROR)
167 sprintf (buf, "%d", *val);
168 Tcl_AppendResult (interp, buf, NULL);
173 * mk_nonSurrogateDiagnostics: Make Tcl result with diagnostic info
175 static int mk_nonSurrogateDiagnostics (Tcl_Interp *interp,
182 Tcl_AppendElement (interp, "NSD");
183 sprintf (buf, "%d", condition);
184 Tcl_AppendElement (interp, buf);
185 cp = diagbib1_str (condition);
187 Tcl_AppendElement (interp, (char*) cp);
189 Tcl_AppendElement (interp, "");
191 Tcl_AppendElement (interp, (char*) addinfo);
193 Tcl_AppendElement (interp, "");
198 * get_parent_info: Returns information about parent object.
200 static int get_parent_info (Tcl_Interp *interp, const char *name,
201 Tcl_CmdInfo *parent_info,
204 char parent_name[128];
205 const char *csep = strrchr (name, '.');
210 interp->result = "missing .";
218 memcpy (parent_name, name, pos);
219 parent_name[pos] = '\0';
220 if (!Tcl_GetCommandInfo (interp, parent_name, parent_info))
222 interp->result = "No parent";
229 * ir_method: Search for method in table and invoke method handler
231 int ir_method (void *obj, Tcl_Interp *interp, int argc, char **argv,
232 IRMethod *tab, int sigerr)
235 for (t = tab; t->name; t++)
236 if (!strcmp (t->name, argv[1]))
237 return (*t->method)(obj, interp, argc, argv);
240 Tcl_AppendResult (interp, "Bad method. Possible values:", NULL);
241 for (t = tab; t->name; t++)
242 Tcl_AppendResult (interp, " ", t->name, NULL);
247 * ir_method_r: Get status for all readable elements
249 int ir_method_r (void *obj, Tcl_Interp *interp, int argc, char **argv,
257 for (; tab->name; tab++)
260 argv_n[1] = tab->name;
261 Tcl_AppendResult (interp, "{", NULL);
262 (*tab->method)(obj, interp, argc_n, argv_n);
263 Tcl_AppendResult (interp, "} ", NULL);
269 * ir_asc2bitmask: Ascii to ODR bitmask conversion
271 int ir_asc2bitmask (const char *asc, Odr_bitmask *ob)
273 const char *cp = asc + strlen(asc);
280 ODR_MASK_SET (ob, bitno);
287 * ir_strdup: Duplicate string
289 int ir_strdup (Tcl_Interp *interp, char** p, const char *s)
291 *p = malloc (strlen(s)+1);
294 interp->result = "strdup fail";
302 * ir_malloc: Malloc function
304 void *ir_malloc (Tcl_Interp *interp, size_t size)
306 static char buf[128];
307 void *p = malloc (size);
311 sprintf (buf, "Malloc fail. %ld bytes requested", (long) size);
312 interp->result = buf;
318 /* ------------------------------------------------------- */
321 * do_init_request: init method on IR object
323 static int do_init_request (void *obj, Tcl_Interp *interp,
324 int argc, char **argv)
326 Z_APDU apdu, *apdup = &apdu;
333 interp->result = "not connected";
337 req.options = &p->options;
338 req.protocolVersion = &p->protocolVersion;
339 req.preferredMessageSize = &p->preferredMessageSize;
340 req.maximumRecordSize = &p->maximumRecordSize;
342 req.idAuthentication = p->idAuthentication;
343 req.implementationId = p->implementationId;
344 req.implementationName = p->implementationName;
345 req.implementationVersion = "0.1";
346 req.userInformationField = 0;
348 apdu.u.initRequest = &req;
349 apdu.which = Z_APDU_initRequest;
351 if (!z_APDU (p->odr_out, &apdup, 0))
353 Tcl_AppendResult (interp, odr_errlist [odr_geterror (p->odr_out)],
355 odr_reset (p->odr_out);
358 p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
359 if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
361 interp->result = "cs_put failed in init";
362 do_disconnect (p, NULL, 0, NULL);
367 ir_select_add_write (cs_fileno(p->cs_link), p);
368 printf("Sent part of initializeRequest (%d bytes).\n", p->slen);
371 printf("Sent whole initializeRequest (%d bytes).\n", p->slen);
376 * do_protocolVersion: Set protocol Version
378 static int do_protocolVersion (void *obj, Tcl_Interp *interp,
379 int argc, char **argv)
382 ir_asc2bitmask (argv[2], &((IRObj *) obj)->protocolVersion);
387 * do_options: Set options
389 static int do_options (void *obj, Tcl_Interp *interp,
390 int argc, char **argv)
393 ir_asc2bitmask (argv[2], &((IRObj *) obj)->options);
398 * do_preferredMessageSize: Set/get preferred message size
400 static int do_preferredMessageSize (void *obj, Tcl_Interp *interp,
401 int argc, char **argv)
404 return get_set_int (&p->preferredMessageSize, interp, argc, argv);
408 * do_maximumRecordSize: Set/get maximum record size
410 static int do_maximumRecordSize (void *obj, Tcl_Interp *interp,
411 int argc, char **argv)
414 return get_set_int (&p->maximumRecordSize, interp, argc, argv);
418 * do_initResult: Get init result
420 static int do_initResult (void *o, Tcl_Interp *interp,
421 int argc, char **argv)
425 return get_set_int (&obj->initResult, interp, argc, argv);
430 * do_implementationName: Set/get Implementation Name.
432 static int do_implementationName (void *obj, Tcl_Interp *interp,
433 int argc, char **argv)
439 free (((IRObj*)obj)->implementationName);
440 if (ir_strdup (interp, &p->implementationName, argv[2])
444 Tcl_AppendResult (interp, p->implementationName,
450 * do_implementationId: Set/get Implementation Id.
452 static int do_implementationId (void *obj, Tcl_Interp *interp,
453 int argc, char **argv)
457 free (((IRObj*)obj)->implementationId);
458 if (ir_strdup (interp, &((IRObj*) obj)->implementationId, argv[2])
462 Tcl_AppendResult (interp, ((IRObj*)obj)->implementationId,
468 * do_targetImplementationName: Get Implementation Name of target.
470 static int do_targetImplementationName (void *obj, Tcl_Interp *interp,
471 int argc, char **argv)
475 Tcl_AppendResult (interp, p->targetImplementationName,
481 * do_targetImplementationId: Get Implementation Id of target
483 static int do_targetImplementationId (void *obj, Tcl_Interp *interp,
484 int argc, char **argv)
486 Tcl_AppendResult (interp, ((IRObj*)obj)->targetImplementationId,
492 * do_targetImplementationVersion: Get Implementation Version of target
494 static int do_targetImplementationVersion (void *obj, Tcl_Interp *interp,
495 int argc, char **argv)
497 Tcl_AppendResult (interp, ((IRObj*)obj)->targetImplementationVersion,
503 * do_idAuthentication: Set/get id Authentication
505 static int do_idAuthentication (void *obj, Tcl_Interp *interp,
506 int argc, char **argv)
510 free (((IRObj*)obj)->idAuthentication);
511 if (ir_strdup (interp, &((IRObj*) obj)->idAuthentication, argv[2])
515 Tcl_AppendResult (interp, ((IRObj*)obj)->idAuthentication,
521 * do_connect: connect method on IR object
523 static int do_connect (void *obj, Tcl_Interp *interp,
524 int argc, char **argv)
529 int protocol_type = CS_Z3950;
535 interp->result = "already connected";
538 if (!strcmp (p->protocol_type, "Z3950"))
539 protocol_type = CS_Z3950;
540 else if (!strcmp (p->protocol_type, "SR"))
541 protocol_type = CS_SR;
544 interp->result = "bad protocol type";
547 if (!strcmp (p->cs_type, "tcpip"))
549 p->cs_link = cs_create (tcpip_type, CS_BLOCK, protocol_type);
550 addr = tcpip_strtoaddr (argv[2]);
553 interp->result = "tcpip_strtoaddr fail";
556 printf ("tcp/ip connect %s\n", argv[2]);
559 else if (!strcmp (p->cs_type, "mosi"))
561 p->cs_link = cs_create (mosi_type, CS_BLOCK, protocol_type);
562 addr = mosi_strtoaddr (argv[2]);
565 interp->result = "mosi_strtoaddr fail";
568 printf ("mosi connect %s\n", argv[2]);
573 interp->result = "unknown comstack type";
576 if (ir_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR)
578 if ((r=cs_connect (p->cs_link, addr)) < 0)
580 interp->result = "cs_connect fail";
581 do_disconnect (p, NULL, 0, NULL);
584 ir_select_add (cs_fileno (p->cs_link), p);
587 ir_select_add_write (cs_fileno (p->cs_link), p);
594 Tcl_Eval (p->interp, p->callback);
598 Tcl_AppendElement (interp, p->hostname);
603 * do_disconnect: disconnect method on IR object
605 static int do_disconnect (void *obj, Tcl_Interp *interp,
606 int argc, char **argv)
614 ir_select_remove_write (cs_fileno (p->cs_link), p);
615 ir_select_remove (cs_fileno (p->cs_link), p);
618 cs_close (p->cs_link);
621 assert (!p->cs_link);
626 * do_comstack: Set/get comstack method on IR object
628 static int do_comstack (void *o, Tcl_Interp *interp,
629 int argc, char **argv)
636 if (ir_strdup (interp, &obj->cs_type, argv[2]) == TCL_ERROR)
639 Tcl_AppendElement (interp, obj->cs_type);
644 * do_protocol: Set/get protocol method on IR object
646 static int do_protocol (void *o, Tcl_Interp *interp,
647 int argc, char **argv)
653 free (obj->protocol_type);
654 if (ir_strdup (interp, &obj->protocol_type, argv[2]) == TCL_ERROR)
657 Tcl_AppendElement (interp, obj->protocol_type);
662 * do_callback: add callback
664 static int do_callback (void *obj, Tcl_Interp *interp,
665 int argc, char **argv)
672 if (ir_strdup (interp, &p->callback, argv[2]) == TCL_ERROR)
680 * do_failback: add error handle callback
682 static int do_failback (void *obj, Tcl_Interp *interp,
683 int argc, char **argv)
690 if (ir_strdup (interp, &p->failback, argv[2]) == TCL_ERROR)
698 * do_databaseNames: specify database names
700 static int do_databaseNames (void *obj, Tcl_Interp *interp,
701 int argc, char **argv)
708 for (i=0; i<p->num_databaseNames; i++)
709 Tcl_AppendElement (interp, p->databaseNames[i]);
712 if (p->databaseNames)
714 for (i=0; i<p->num_databaseNames; i++)
715 free (p->databaseNames[i]);
716 free (p->databaseNames);
718 p->num_databaseNames = argc - 2;
719 if (!(p->databaseNames = ir_malloc (interp,
720 sizeof(*p->databaseNames) * p->num_databaseNames)))
722 for (i=0; i<p->num_databaseNames; i++)
724 if (ir_strdup (interp, &p->databaseNames[i], argv[2+i])
732 * do_replaceIndicator: Set/get replace Set indicator
734 static int do_replaceIndicator (void *obj, Tcl_Interp *interp,
735 int argc, char **argv)
739 return get_set_int (&p->replaceIndicator, interp, argc, argv);
743 * do_queryType: Set/Get query method
745 static int do_queryType (void *obj, Tcl_Interp *interp,
746 int argc, char **argv)
753 if (ir_strdup (interp, &p->queryType, argv[2]) == TCL_ERROR)
756 Tcl_AppendResult (interp, p->queryType, NULL);
761 * do_userInformationField: Get User information field
763 static int do_userInformationField (void *obj, Tcl_Interp *interp,
764 int argc, char **argv)
768 Tcl_AppendResult (interp, p->userInformationField, NULL);
773 * do_smallSetUpperBound: Set/get small set upper bound
775 static int do_smallSetUpperBound (void *o, Tcl_Interp *interp,
776 int argc, char **argv)
780 return get_set_int (&obj->smallSetUpperBound, interp, argc, argv);
784 * do_largeSetLowerBound: Set/get large set lower bound
786 static int do_largeSetLowerBound (void *o, Tcl_Interp *interp,
787 int argc, char **argv)
791 return get_set_int (&obj->largeSetLowerBound, interp, argc, argv);
795 * do_mediumSetPresentNumber: Set/get large set lower bound
797 static int do_mediumSetPresentNumber (void *o, Tcl_Interp *interp,
798 int argc, char **argv)
802 return get_set_int (&obj->mediumSetPresentNumber, interp, argc, argv);
806 static IRMethod ir_method_tab[] = {
807 { 1, "comstack", do_comstack },
808 { 1, "protocol", do_protocol },
809 { 0, "failback", do_failback },
811 { 1, "connect", do_connect },
812 { 0, "protocolVersion", do_protocolVersion },
813 { 1, "preferredMessageSize", do_preferredMessageSize },
814 { 1, "maximumRecordSize", do_maximumRecordSize },
815 { 1, "implementationName", do_implementationName },
816 { 1, "implementationId", do_implementationId },
817 { 0, "targetImplementationName", do_targetImplementationName },
818 { 0, "targetImplementationId", do_targetImplementationId },
819 { 0, "targetImplementationVersion", do_targetImplementationVersion },
820 { 0, "userInformationField", do_userInformationField },
821 { 1, "idAuthentication", do_idAuthentication },
822 { 0, "options", do_options },
823 { 0, "init", do_init_request },
824 { 0, "initResult", do_initResult },
825 { 0, "disconnect", do_disconnect },
826 { 0, "callback", do_callback },
830 static IRMethod ir_set_c_method_tab[] = {
831 { 0, "databaseNames", do_databaseNames},
832 { 0, "replaceIndicator", do_replaceIndicator},
833 { 0, "queryType", do_queryType },
834 { 0, "smallSetUpperBound", do_smallSetUpperBound},
835 { 0, "largeSetLowerBound", do_largeSetLowerBound},
836 { 0, "mediumSetPresentNumber", do_mediumSetPresentNumber},
841 * ir_obj_method: IR Object methods
843 static int ir_obj_method (ClientData clientData, Tcl_Interp *interp,
844 int argc, char **argv)
847 return ir_method_r (clientData, interp, argc, argv, ir_method_tab);
848 if (ir_method (clientData, interp, argc, argv,
849 ir_method_tab, 1) == TCL_OK)
851 return ir_method (&((IRObj*) clientData)->set_inher, interp,
852 argc, argv, ir_set_c_method_tab, 0);
856 * ir_obj_delete: IR Object disposal
858 static void ir_obj_delete (ClientData clientData)
860 free ( (void*) clientData);
863 static int ir_reset_inher (Tcl_Interp *interp, IRSetCObj *o)
865 o->smallSetUpperBound = 0;
866 o->largeSetLowerBound = 2;
867 o->mediumSetPresentNumber = 0;
868 o->replaceIndicator = 1;
870 obj->databaseNames = NULL;
871 obj->num_databaseNames = 0;
873 o->num_databaseNames = 1;
874 if (!(o->databaseNames =
875 ir_malloc (interp, sizeof(*o->databaseNames))))
877 if (ir_strdup (interp, &o->databaseNames[0], "Default")
881 if (ir_strdup (interp, &o->queryType, "rpn") == TCL_ERROR)
887 * ir_obj_mk: IR Object creation
889 static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp,
890 int argc, char **argv)
897 interp->result = "wrong # args";
900 if (!(obj = ir_malloc (interp, sizeof(*obj))))
902 if (ir_strdup (interp, &obj->cs_type, "tcpip") == TCL_ERROR)
904 if (ir_strdup (interp, &obj->protocol_type, "Z3950") == TCL_ERROR)
907 obj->bib1.proto = PROTO_Z3950;
908 obj->bib1.class = CLASS_ATTSET;
909 obj->bib1.value = VAL_BIB1;
911 obj->maximumRecordSize = 32768;
912 obj->preferredMessageSize = 4096;
913 obj->connectFlag = 0;
915 obj->idAuthentication = NULL;
917 if (ir_strdup (interp, &obj->implementationName, "TCL/TK on YAZ")
921 if (ir_strdup (interp, &obj->implementationId, "TCL/TK/YAZ")
925 obj->targetImplementationName = NULL;
926 obj->targetImplementationId = NULL;
927 obj->targetImplementationVersion = NULL;
928 obj->userInformationField = NULL;
930 obj->hostname = NULL;
932 obj->bibset = ccl_qual_mk ();
933 if ((inf = fopen ("default.bib", "r")))
935 ccl_qual_file (obj->bibset, inf);
938 ODR_MASK_ZERO (&obj->protocolVersion);
939 ODR_MASK_SET (&obj->protocolVersion, 0);
940 ODR_MASK_SET (&obj->protocolVersion, 1);
942 ODR_MASK_ZERO (&obj->options);
943 ODR_MASK_SET (&obj->options, 0);
945 obj->odr_in = odr_createmem (ODR_DECODE);
946 obj->odr_out = odr_createmem (ODR_ENCODE);
947 obj->odr_pr = odr_createmem (ODR_PRINT);
949 obj->len_out = 10000;
950 if (!(obj->buf_out = ir_malloc (interp, obj->len_out)))
952 odr_setbuf (obj->odr_out, obj->buf_out, obj->len_out, 0);
957 obj->callback = NULL;
958 obj->failback = NULL;
960 if (ir_reset_inher (interp, &obj->set_inher) == TCL_ERROR)
962 Tcl_CreateCommand (interp, argv[1], ir_obj_method,
963 (ClientData) obj, ir_obj_delete);
967 /* ------------------------------------------------------- */
969 * do_search: Do search request
971 static int do_search (void *o, Tcl_Interp *interp,
972 int argc, char **argv)
976 Z_APDU apdu, *apdup = &apdu;
979 IRObj *p = obj->parent;
985 interp->result = "wrong # args";
988 if (!p->set_inher.num_databaseNames)
990 interp->result = "no databaseNames";
995 interp->result = "not connected";
998 apdu.which = Z_APDU_searchRequest;
999 apdu.u.searchRequest = &req;
1001 req.referenceId = 0;
1002 req.smallSetUpperBound = &p->set_inher.smallSetUpperBound;
1003 req.largeSetLowerBound = &p->set_inher.largeSetLowerBound;
1004 req.mediumSetPresentNumber = &p->set_inher.mediumSetPresentNumber;
1005 req.replaceIndicator = &p->set_inher.replaceIndicator;
1006 req.resultSetName = obj->setName ? obj->setName : "Default";
1007 req.num_databaseNames = p->set_inher.num_databaseNames;
1008 req.databaseNames = p->set_inher.databaseNames;
1010 for (r=0; r < p->set_inher.num_databaseNames; r++)
1012 printf (" %s", p->set_inher.databaseNames[r]);
1014 req.smallSetElementSetNames = 0;
1015 req.mediumSetElementSetNames = 0;
1016 req.preferredRecordSyntax = 0;
1019 if (!strcmp (p->set_inher.queryType, "rpn"))
1023 struct ccl_rpn_node *rpn;
1024 Z_RPNQuery *RPNquery;
1026 rpn = ccl_find_str(p->bibset, argv[2], &error, &pos);
1029 Tcl_AppendResult (interp, "CCL error: ", ccl_err_msg(error),NULL);
1032 ccl_pr_tree (rpn, stderr);
1033 fprintf (stderr, "\n");
1034 query.which = Z_Query_type_1;
1035 assert((RPNquery = ccl_rpn_query(rpn)));
1036 RPNquery->attributeSetId = oid_getoidbyent (&p->bib1);
1037 query.u.type_1 = RPNquery;
1040 else if (!strcmp (p->set_inher.queryType, "ccl"))
1042 query.which = Z_Query_type_2;
1043 query.u.type_2 = &ccl_query;
1044 ccl_query.buf = (unsigned char *) argv[2];
1045 ccl_query.len = strlen (argv[2]);
1050 interp->result = "unknown query method";
1053 if (!z_APDU (p->odr_out, &apdup, 0))
1055 interp->result = odr_errlist [odr_geterror (p->odr_out)];
1056 odr_reset (p->odr_out);
1059 p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
1060 if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
1062 interp->result = "cs_put failed in search";
1067 ir_select_add_write (cs_fileno(p->cs_link), p);
1068 printf("Sent part of searchRequest (%d bytes).\n", p->slen);
1072 printf ("Whole search request\n");
1078 * do_resultCount: Get number of hits
1080 static int do_resultCount (void *o, Tcl_Interp *interp,
1081 int argc, char **argv)
1085 return get_set_int (&obj->resultCount, interp, argc, argv);
1089 * do_searchStatus: Get search status (after search response)
1091 static int do_searchStatus (void *o, Tcl_Interp *interp,
1092 int argc, char **argv)
1096 return get_set_int (&obj->searchStatus, interp, argc, argv);
1100 * do_setName: Set result Set name
1102 static int do_setName (void *o, Tcl_Interp *interp,
1103 int argc, char **argv)
1109 free (obj->setName);
1110 if (ir_strdup (interp, &obj->setName, argv[2])
1114 Tcl_AppendElement (interp, obj->setName);
1119 * do_numberOfRecordsReturned: Get number of records returned
1121 static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
1122 int argc, char **argv)
1126 return get_set_int (&obj->numberOfRecordsReturned, interp, argc, argv);
1129 static int get_marc_fields(Tcl_Interp *interp, Iso2709Rec rec,
1130 int argc, char **argv)
1137 a = iso2709_a_mk (rec);
1138 while (iso2709_a_search (a, argv[4], argv[5], argv[6]))
1140 if (!(iso2709_a_info_field (a, NULL, NULL, NULL, &data)))
1142 Tcl_AppendElement (interp, data);
1150 static int get_marc_lines(Tcl_Interp *interp, Iso2709Rec rec,
1151 int argc, char **argv)
1162 a = iso2709_a_mk (rec);
1163 while (iso2709_a_search (a, argv[4], argv[5], argv[6]))
1165 if (!(iso2709_a_info_field (a, &tag, &indicator, &identifier, &data)))
1167 if (strcmp (tag, ptag))
1170 Tcl_AppendResult (interp, "}} ", NULL);
1172 Tcl_AppendResult (interp, "{", tag, " {} {", NULL);
1174 Tcl_AppendResult (interp, "{", tag, " {", indicator,
1179 Tcl_AppendResult (interp, "{{}", NULL);
1181 Tcl_AppendResult (interp, "{", identifier, NULL);
1182 Tcl_AppendElement (interp, data);
1183 Tcl_AppendResult (interp, "} ", NULL);
1187 Tcl_AppendResult (interp, "}} ", NULL);
1193 * do_recordType: Return record type (if any) at position.
1195 static int do_recordType (void *o, Tcl_Interp *interp, int argc, char **argv)
1203 sprintf (interp->result, "wrong # args");
1206 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
1208 rl = find_IR_record (obj, offset);
1213 case Z_NamePlusRecord_databaseRecord:
1214 interp->result = "databaseRecord";
1216 case Z_NamePlusRecord_surrogateDiagnostic:
1217 interp->result = "surrogateDiagnostic";
1224 * do_recordDiag: Return diagnostic record info
1226 static int do_recordDiag (void *o, Tcl_Interp *interp, int argc, char **argv)
1235 sprintf (interp->result, "wrong # args");
1238 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
1240 rl = find_IR_record (obj, offset);
1243 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
1246 if (rl->which != Z_NamePlusRecord_surrogateDiagnostic)
1248 Tcl_AppendResult (interp, "No Diagnostic record at #", argv[2], NULL);
1251 sprintf (buf, "%d", rl->u.diag.condition);
1252 Tcl_AppendResult (interp, buf, " {",
1253 (rl->u.diag.addinfo ? rl->u.diag.addinfo : ""),
1259 * do_recordMarc: Get ISO2709 Record lines/fields
1261 static int do_recordMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
1269 sprintf (interp->result, "wrong # args");
1272 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
1274 rl = find_IR_record (obj, offset);
1277 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
1280 if (rl->which != Z_NamePlusRecord_databaseRecord)
1282 Tcl_AppendResult (interp, "No MARC record at #", argv[2], NULL);
1285 if (!strcmp (argv[3], "field"))
1286 return get_marc_fields (interp, rl->u.marc.rec, argc, argv);
1287 else if (!strcmp (argv[3], "line"))
1288 return get_marc_lines (interp, rl->u.marc.rec, argc, argv);
1291 Tcl_AppendResult (interp, "field/line expected", NULL);
1298 * do_responseStatus: Return response status (present or search)
1300 static int do_responseStatus (void *o, Tcl_Interp *interp,
1301 int argc, char **argv)
1305 if (!obj->recordFlag)
1307 Tcl_AppendElement (interp, "OK");
1312 case Z_Records_DBOSD:
1313 Tcl_AppendElement (interp, "DBOSD");
1316 return mk_nonSurrogateDiagnostics (interp, obj->condition,
1323 * do_present: Perform Present Request
1326 static int do_present (void *o, Tcl_Interp *interp,
1327 int argc, char **argv)
1330 IRObj *p = obj->parent;
1331 Z_APDU apdu, *apdup = &apdu;
1332 Z_PresentRequest req;
1339 if (Tcl_GetInt (interp, argv[2], &start) == TCL_ERROR)
1346 if (Tcl_GetInt (interp, argv[3], &number) == TCL_ERROR)
1353 interp->result = "not connected";
1357 obj->number = number;
1359 apdu.which = Z_APDU_presentRequest;
1360 apdu.u.presentRequest = &req;
1361 req.referenceId = 0;
1362 /* sprintf(setstring, "%d", setnumber); */
1364 req.resultSetId = obj->setName ? obj->setName : "Default";
1366 req.resultSetStartPoint = &start;
1367 req.numberOfRecordsRequested = &number;
1368 req.elementSetNames = 0;
1369 req.preferredRecordSyntax = 0;
1371 if (!z_APDU (p->odr_out, &apdup, 0))
1373 interp->result = odr_errlist [odr_geterror (p->odr_out)];
1374 odr_reset (p->odr_out);
1377 p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
1378 if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
1380 interp->result = "cs_put failed in present";
1385 ir_select_add_write (cs_fileno(p->cs_link), p);
1386 printf ("Part of present request, start=%d, num=%d (%d bytes)\n",
1387 start, number, p->slen);
1391 printf ("Whole present request, start=%d, num=%d (%d bytes)\n",
1392 start, number, p->slen);
1398 * do_loadFile: Load result set from file
1401 static int do_loadFile (void *o, Tcl_Interp *interp,
1402 int argc, char **argv)
1404 IRSetObj *setobj = o;
1411 interp->result = "wrong # args";
1414 inf = fopen (argv[2], "r");
1417 Tcl_AppendResult (interp, "Cannot open ", argv[2], NULL);
1420 while ((buf = iso2709_read (inf)))
1425 rec = iso2709_cvt (buf);
1428 rl = new_IR_record (setobj, no, Z_NamePlusRecord_databaseRecord);
1429 rl->u.marc.rec = rec;
1432 setobj->numberOfRecordsReturned = no-1;
1438 * ir_set_obj_method: IR Set Object methods
1440 static int ir_set_obj_method (ClientData clientData, Tcl_Interp *interp,
1441 int argc, char **argv)
1443 static IRMethod tab[] = {
1444 { 0, "search", do_search },
1445 { 0, "searchStatus", do_searchStatus },
1446 { 0, "setName", do_setName },
1447 { 0, "resultCount", do_resultCount },
1448 { 0, "numberOfRecordsReturned", do_numberOfRecordsReturned },
1449 { 0, "present", do_present },
1450 { 0, "recordType", do_recordType },
1451 { 0, "recordMarc", do_recordMarc },
1452 { 0, "recordDiag", do_recordDiag },
1453 { 0, "responseStatus", do_responseStatus },
1454 { 0, "loadFile", do_loadFile },
1460 interp->result = "wrong # args";
1463 if (ir_method (clientData, interp, argc, argv, tab, 1) == TCL_OK)
1465 return ir_method (&((IRSetObj *)clientData)->set_inher, interp, argc,
1466 argv, ir_set_c_method_tab, 0);
1470 * ir_set_obj_delete: IR Set Object disposal
1472 static void ir_set_obj_delete (ClientData clientData)
1474 free ( (void*) clientData);
1478 * ir_set_obj_mk: IR Set Object creation
1480 static int ir_set_obj_mk (ClientData clientData, Tcl_Interp *interp,
1481 int argc, char **argv)
1485 if (argc < 2 || argc > 3)
1487 interp->result = "wrong # args";
1492 Tcl_CmdInfo parent_info;
1497 if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
1499 interp->result = "No parent";
1502 if (!(obj = ir_malloc (interp, sizeof(*obj))))
1504 obj->parent = (IRObj *) parent_info.clientData;
1506 dst = &obj->set_inher;
1507 src = &obj->parent->set_inher;
1509 dst->num_databaseNames = src->num_databaseNames;
1510 if (!(dst->databaseNames =
1511 ir_malloc (interp, sizeof (*dst->databaseNames)
1512 * dst->num_databaseNames)))
1514 for (i = 0; i < dst->num_databaseNames; i++)
1516 printf ("database %i %s\n", i, src->databaseNames[i]);
1517 if (ir_strdup (interp, &dst->databaseNames[i],
1518 src->databaseNames[i]) == TCL_ERROR)
1521 if (ir_strdup (interp, &dst->queryType, src->queryType)
1525 dst->smallSetUpperBound = src->smallSetUpperBound;
1526 dst->largeSetLowerBound = src->largeSetLowerBound;
1527 dst->mediumSetPresentNumber = src->mediumSetPresentNumber;
1528 printf ("ssu lsl msp %d %d %d\n", dst->smallSetUpperBound,
1529 dst->largeSetLowerBound, dst->mediumSetPresentNumber);
1533 if (ir_strdup (interp, &obj->setName, argv[2]) == TCL_ERROR)
1535 obj->record_list = NULL;
1536 obj->addinfo = NULL;
1537 Tcl_CreateCommand (interp, argv[1], ir_set_obj_method,
1538 (ClientData) obj, ir_set_obj_delete);
1542 /* ------------------------------------------------------- */
1545 * do_scan: Perform scan
1547 static int do_scan (void *o, Tcl_Interp *interp, int argc, char **argv)
1550 Z_APDU apdu, *apdup = &apdu;
1552 IRObj *p = obj->parent;
1554 struct ccl_rpn_node *rpn;
1559 interp->result = "wrong # args";
1562 if (!p->set_inher.num_databaseNames)
1564 interp->result = "no databaseNames";
1569 interp->result = "not connected";
1572 apdu.which = Z_APDU_scanRequest;
1573 apdu.u.scanRequest = &req;
1574 req.referenceId = NULL;
1575 req.num_databaseNames = p->set_inher.num_databaseNames;
1576 req.databaseNames = p->set_inher.databaseNames;
1577 req.attributeSet = oid_getoidbyent (&p->bib1);
1580 if (!(req.termListAndStartPoint =
1581 ir_malloc (interp, sizeof(*req.termListAndStartPoint))))
1583 req.termListAndStartPoint->num_attributes = 0;
1584 req.termListAndStartPoint->attributeList = NULL;
1585 if (!(req.termListAndStartPoint->term = ir_malloc (interp,
1588 req.termListAndStartPoint->term->which = Z_Term_general;
1589 if (!(req.termListAndStartPoint->term->u.general =
1590 ir_malloc (interp, sizeof(*req.termListAndStartPoint->
1593 if (ir_strdup (interp, &req.termListAndStartPoint->term->u.general->buf,
1594 argv[2]) == TCL_ERROR)
1596 req.termListAndStartPoint->term->u.general->len =
1597 req.termListAndStartPoint->term->u.general->size = strlen(argv[2]);
1599 rpn = ccl_find_str(p->bibset, argv[2], &r, &pos);
1602 Tcl_AppendResult (interp, "CCL error: ", ccl_err_msg (r), NULL);
1605 ccl_pr_tree (rpn, stderr);
1606 fprintf (stderr, "\n");
1607 if (!(req.termListAndStartPoint = ccl_scan_query (rpn)))
1610 req.stepSize = &obj->stepSize;
1611 req.numberOfTermsRequested = &obj->numberOfTermsRequested;
1612 req.preferredPositionInResponse = &obj->preferredPositionInResponse;
1613 printf ("stepSize=%d\n", *req.stepSize);
1614 printf ("numberOfTermsRequested=%d\n", *req.numberOfTermsRequested);
1615 printf ("preferredPositionInResponse=%d\n",
1616 *req.preferredPositionInResponse);
1618 if (!z_APDU (p->odr_out, &apdup, 0))
1620 interp->result = odr_errlist [odr_geterror (p->odr_out)];
1621 odr_reset (p->odr_out);
1624 p->sbuf = odr_getbuf (p->odr_out, &p->slen, NULL);
1625 if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
1627 interp->result = "cs_put failed in scan";
1632 ir_select_add_write (cs_fileno(p->cs_link), p);
1633 printf("Sent part of scanRequest (%d bytes).\n", p->slen);
1637 printf ("Whole scan request\n");
1643 * do_stepSize: Set/get replace Step Size
1645 static int do_stepSize (void *obj, Tcl_Interp *interp,
1646 int argc, char **argv)
1649 return get_set_int (&p->stepSize, interp, argc, argv);
1653 * do_numberOfTermsRequested: Set/get Number of Terms requested
1655 static int do_numberOfTermsRequested (void *obj, Tcl_Interp *interp,
1656 int argc, char **argv)
1659 return get_set_int (&p->numberOfTermsRequested, interp, argc, argv);
1664 * do_preferredPositionInResponse: Set/get preferred Position
1666 static int do_preferredPositionInResponse (void *obj, Tcl_Interp *interp,
1667 int argc, char **argv)
1670 return get_set_int (&p->preferredPositionInResponse, interp, argc, argv);
1674 * do_scanStatus: Get scan status
1676 static int do_scanStatus (void *obj, Tcl_Interp *interp,
1677 int argc, char **argv)
1680 return get_set_int (&p->scanStatus, interp, argc, argv);
1684 * do_numberOfEntriesReturned: Get number of Entries returned
1686 static int do_numberOfEntriesReturned (void *obj, Tcl_Interp *interp,
1687 int argc, char **argv)
1690 return get_set_int (&p->numberOfEntriesReturned, interp, argc, argv);
1694 * do_positionOfTerm: Get position of Term
1696 static int do_positionOfTerm (void *obj, Tcl_Interp *interp,
1697 int argc, char **argv)
1700 return get_set_int (&p->positionOfTerm, interp, argc, argv);
1704 * do_scanLine: get Scan Line (surrogate or normal) after response
1706 static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv)
1714 interp->result = "wrong # args";
1717 if (Tcl_GetInt (interp, argv[2], &i) == TCL_ERROR)
1719 if (!p->entries_flag || p->which != Z_ListEntries_entries || !p->entries
1720 || i >= p->num_entries || i < 0)
1722 switch (p->entries[i].which)
1724 case Z_Entry_termInfo:
1725 Tcl_AppendElement (interp, "T");
1726 if (p->entries[i].u.term.buf)
1727 Tcl_AppendElement (interp, p->entries[i].u.term.buf);
1729 Tcl_AppendElement (interp, "");
1730 sprintf (numstr, "%d", p->entries[i].u.term.globalOccurrences);
1731 Tcl_AppendElement (interp, numstr);
1733 case Z_Entry_surrogateDiagnostic:
1735 mk_nonSurrogateDiagnostics (interp, p->entries[i].u.diag.condition,
1736 p->entries[i].u.diag.addinfo);
1743 * ir_scan_obj_method: IR Scan Object methods
1745 static int ir_scan_obj_method (ClientData clientData, Tcl_Interp *interp,
1746 int argc, char **argv)
1748 static IRMethod tab[] = {
1749 { 0, "scan", do_scan },
1750 { 0, "stepSize", do_stepSize },
1751 { 0, "numberOfTermsRequested", do_numberOfTermsRequested },
1752 { 0, "preferredPositionInResponse", do_preferredPositionInResponse },
1753 { 0, "scanStatus", do_scanStatus },
1754 { 0, "numberOfEntriesReturned", do_numberOfEntriesReturned },
1755 { 0, "positionOfTerm", do_positionOfTerm },
1756 { 0, "scanLine", do_scanLine },
1762 interp->result = "wrong # args";
1765 return ir_method (clientData, interp, argc, argv, tab, 0);
1769 * ir_scan_obj_delete: IR Scan Object disposal
1771 static void ir_scan_obj_delete (ClientData clientData)
1773 free ( (void*) clientData);
1777 * ir_scan_obj_mk: IR Scan Object creation
1779 static int ir_scan_obj_mk (ClientData clientData, Tcl_Interp *interp,
1780 int argc, char **argv)
1782 Tcl_CmdInfo parent_info;
1787 interp->result = "wrong # args";
1790 if (get_parent_info (interp, argv[1], &parent_info, NULL) == TCL_ERROR)
1792 if (!(obj = ir_malloc (interp, sizeof(*obj))))
1796 obj->numberOfTermsRequested = 20;
1797 obj->preferredPositionInResponse = 1;
1799 obj->entries = NULL;
1800 obj->nonSurrogateDiagnostics = NULL;
1802 obj->parent = (IRObj *) parent_info.clientData;
1803 Tcl_CreateCommand (interp, argv[1], ir_scan_obj_method,
1804 (ClientData) obj, ir_scan_obj_delete);
1808 /* ------------------------------------------------------- */
1810 static void ir_initResponse (void *obj, Z_InitResponse *initrs)
1814 p->initResult = *initrs->result ? 1 : 0;
1815 if (!*initrs->result)
1816 printf("Connection rejected by target.\n");
1818 printf("Connection accepted by target.\n");
1820 free (p->targetImplementationId);
1821 ir_strdup (p->interp, &p->targetImplementationId,
1822 initrs->implementationId);
1823 free (p->targetImplementationName);
1824 ir_strdup (p->interp, &p->targetImplementationName,
1825 initrs->implementationName);
1826 free (p->targetImplementationVersion);
1827 ir_strdup (p->interp, &p->targetImplementationVersion,
1828 initrs->implementationVersion);
1830 p->maximumRecordSize = *initrs->maximumRecordSize;
1831 p->preferredMessageSize = *initrs->preferredMessageSize;
1833 free (p->userInformationField);
1834 p->userInformationField = NULL;
1835 if (initrs->userInformationField)
1839 if (initrs->userInformationField->which == ODR_EXTERNAL_octet &&
1840 (p->userInformationField =
1842 initrs->userInformationField->u.octet_aligned->len)
1845 memcpy (p->userInformationField,
1846 initrs->userInformationField->u.octet_aligned->buf,
1848 (p->userInformationField)[len] = '\0';
1853 static void ir_handleRecords (void *o, Z_Records *zrs)
1856 IRSetObj *setobj = p->set_child;
1858 setobj->which = zrs->which;
1859 setobj->recordFlag = 1;
1860 if (zrs->which == Z_Records_NSD)
1862 const char *addinfo;
1864 setobj->numberOfRecordsReturned = 0;
1865 setobj->condition = *zrs->u.nonSurrogateDiagnostic->condition;
1866 free (setobj->addinfo);
1867 setobj->addinfo = NULL;
1868 addinfo = zrs->u.nonSurrogateDiagnostic->addinfo;
1869 if (addinfo && (setobj->addinfo = malloc (strlen(addinfo) + 1)))
1870 strcpy (setobj->addinfo, addinfo);
1871 printf ("Diagnostic response. %s (%d): %s\n",
1872 diagbib1_str (setobj->condition),
1874 setobj->addinfo ? setobj->addinfo : "");
1881 setobj->numberOfRecordsReturned =
1882 zrs->u.databaseOrSurDiagnostics->num_records;
1883 printf ("Got %d records\n", setobj->numberOfRecordsReturned);
1884 for (offset = 0; offset<setobj->numberOfRecordsReturned; offset++)
1886 rl = new_IR_record (setobj, setobj->start + offset,
1887 zrs->u.databaseOrSurDiagnostics->
1888 records[offset]->which);
1889 if (rl->which == Z_NamePlusRecord_surrogateDiagnostic)
1893 diagrec = zrs->u.databaseOrSurDiagnostics->
1894 records[offset]->u.surrogateDiagnostic;
1896 rl->u.diag.condition = *diagrec->condition;
1897 if (diagrec->addinfo && (rl->u.diag.addinfo =
1898 malloc (strlen (diagrec->addinfo)+1)))
1899 strcpy (rl->u.diag.addinfo, diagrec->addinfo);
1903 Z_DatabaseRecord *zr;
1906 zr = zrs->u.databaseOrSurDiagnostics->records[offset]
1908 oe = (Odr_external*) zr;
1909 if (oe->which == ODR_EXTERNAL_octet
1910 && zr->u.octet_aligned->len)
1912 const char *buf = (char*) zr->u.octet_aligned->buf;
1913 rl->u.marc.rec = iso2709_cvt (buf);
1916 rl->u.marc.rec = NULL;
1922 static void ir_searchResponse (void *o, Z_SearchResponse *searchrs)
1925 IRSetObj *setobj = p->set_child;
1926 Z_Records *zrs = searchrs->records;
1930 setobj->searchStatus = searchrs->searchStatus ? 1 : 0;
1931 setobj->resultCount = *searchrs->resultCount;
1932 printf ("Search response %d, %d hits\n",
1933 setobj->searchStatus, setobj->resultCount);
1935 ir_handleRecords (o, zrs);
1937 setobj->recordFlag = 0;
1940 printf ("Search response, no object!\n");
1944 static void ir_presentResponse (void *o, Z_PresentResponse *presrs)
1947 IRSetObj *setobj = p->set_child;
1948 Z_Records *zrs = presrs->records;
1950 printf ("Received presentResponse\n");
1952 ir_handleRecords (o, zrs);
1955 setobj->recordFlag = 0;
1956 printf ("No records!\n");
1960 static void ir_scanResponse (void *o, Z_ScanResponse *scanrs)
1963 IRScanObj *scanobj = p->scan_child;
1965 printf ("Received scanResponse\n");
1967 scanobj->scanStatus = *scanrs->scanStatus;
1968 printf ("scanStatus=%d\n", scanobj->scanStatus);
1970 if (scanrs->stepSize)
1971 scanobj->stepSize = *scanrs->stepSize;
1972 printf ("stepSize=%d\n", scanobj->stepSize);
1974 scanobj->numberOfEntriesReturned = *scanrs->numberOfEntriesReturned;
1975 printf ("numberOfEntriesReturned=%d\n", scanobj->numberOfEntriesReturned);
1977 if (scanrs->positionOfTerm)
1978 scanobj->positionOfTerm = *scanrs->positionOfTerm;
1980 scanobj->positionOfTerm = -1;
1981 printf ("positionOfTerm=%d\n", scanobj->positionOfTerm);
1983 free (scanobj->entries);
1984 scanobj->entries = NULL;
1985 free (scanobj->nonSurrogateDiagnostics);
1986 scanobj->nonSurrogateDiagnostics = NULL;
1988 if (scanrs->entries)
1993 scanobj->entries_flag = 1;
1994 scanobj->which = scanrs->entries->which;
1995 switch (scanobj->which)
1997 case Z_ListEntries_entries:
1998 scanobj->num_entries = scanrs->entries->u.entries->num_entries;
1999 scanobj->entries = malloc (scanobj->num_entries *
2000 sizeof(*scanobj->entries));
2001 for (i=0; i<scanobj->num_entries; i++)
2003 ze = scanrs->entries->u.entries->entries[i];
2004 scanobj->entries[i].which = ze->which;
2007 case Z_Entry_termInfo:
2008 if (ze->u.termInfo->term->which == Z_Term_general)
2010 int l = ze->u.termInfo->term->u.general->len;
2011 scanobj->entries[i].u.term.buf = malloc (1+l);
2012 memcpy (scanobj->entries[i].u.term.buf,
2013 ze->u.termInfo->term->u.general->buf,
2015 scanobj->entries[i].u.term.buf[l] = '\0';
2018 scanobj->entries[i].u.term.buf = NULL;
2019 if (ze->u.termInfo->globalOccurrences)
2020 scanobj->entries[i].u.term.globalOccurrences =
2021 *ze->u.termInfo->globalOccurrences;
2023 scanobj->entries[i].u.term.globalOccurrences = 0;
2025 case Z_Entry_surrogateDiagnostic:
2026 scanobj->entries[i].u.diag.addinfo =
2027 malloc (1+strlen(ze->u.surrogateDiagnostic->
2029 strcpy (scanobj->entries[i].u.diag.addinfo,
2030 ze->u.surrogateDiagnostic->addinfo);
2031 scanobj->entries[i].u.diag.condition =
2032 *ze->u.surrogateDiagnostic->condition;
2037 case Z_ListEntries_nonSurrogateDiagnostics:
2038 scanobj->num_diagRecs = scanrs->entries->
2039 u.nonSurrogateDiagnostics->num_diagRecs;
2040 scanobj->nonSurrogateDiagnostics = malloc (scanobj->num_diagRecs *
2041 sizeof(*scanobj->nonSurrogateDiagnostics));
2046 scanobj->entries_flag = 0;
2050 * ir_select_read: handle incoming packages
2052 void ir_select_read (ClientData clientData)
2054 IRObj *p = clientData;
2060 r = cs_rcvconnect (p->cs_link);
2064 ir_select_remove_write (cs_fileno (p->cs_link), p);
2067 printf ("cs_rcvconnect error\n");
2069 Tcl_Eval (p->interp, p->failback);
2070 do_disconnect (p, NULL, 0, NULL);
2074 Tcl_Eval (p->interp, p->callback);
2079 if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) <= 0)
2081 printf ("cs_get failed\n");
2082 ir_select_remove (cs_fileno (p->cs_link), p);
2084 Tcl_Eval (p->interp, p->failback);
2085 do_disconnect (p, NULL, 0, NULL);
2090 odr_setbuf (p->odr_in, p->buf_in, r, 0);
2091 printf ("cs_get ok, got %d\n", r);
2092 if (!z_APDU (p->odr_in, &apdu, 0))
2094 printf ("%s\n", odr_errlist [odr_geterror (p->odr_in)]);
2096 Tcl_Eval (p->interp, p->failback);
2097 do_disconnect (p, NULL, 0, NULL);
2102 case Z_APDU_initResponse:
2103 ir_initResponse (p, apdu->u.initResponse);
2105 case Z_APDU_searchResponse:
2106 ir_searchResponse (p, apdu->u.searchResponse);
2108 case Z_APDU_presentResponse:
2109 ir_presentResponse (p, apdu->u.presentResponse);
2111 case Z_APDU_scanResponse:
2112 ir_scanResponse (p, apdu->u.scanResponse);
2115 printf("Received unknown APDU type (%d).\n",
2118 Tcl_Eval (p->interp, p->failback);
2119 do_disconnect (p, NULL, 0, NULL);
2122 Tcl_Eval (p->interp, p->callback);
2123 } while (cs_more (p->cs_link));
2127 * ir_select_write: handle outgoing packages - not yet written.
2129 void ir_select_write (ClientData clientData)
2131 IRObj *p = clientData;
2134 printf ("In write handler.....\n");
2137 r = cs_rcvconnect (p->cs_link);
2143 printf ("cs_rcvconnect error\n");
2144 ir_select_remove_write (cs_fileno (p->cs_link), p);
2146 Tcl_Eval (p->interp, p->failback);
2147 do_disconnect (p, NULL, 0, NULL);
2150 ir_select_remove_write (cs_fileno (p->cs_link), p);
2152 Tcl_Eval (p->interp, p->callback);
2155 if ((r=cs_put (p->cs_link, p->sbuf, p->slen)) < 0)
2157 printf ("select write fail\n");
2159 Tcl_Eval (p->interp, p->failback);
2160 do_disconnect (p, NULL, 0, NULL);
2162 else if (r == 0) /* remove select bit */
2164 ir_select_remove_write (cs_fileno (p->cs_link), p);
2168 /* ------------------------------------------------------- */
2171 * ir_tcl_init: Registration of TCL commands.
2173 int ir_tcl_init (Tcl_Interp *interp)
2175 Tcl_CreateCommand (interp, "ir", ir_obj_mk, (ClientData) NULL,
2176 (Tcl_CmdDeleteProc *) NULL);
2177 Tcl_CreateCommand (interp, "ir-set", ir_set_obj_mk,
2178 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
2179 Tcl_CreateCommand (interp, "ir-scan", ir_scan_obj_mk,
2180 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);