2 * IR toolkit for tcl/tk
3 * (c) Index Data 1995-1999
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.112 1999-03-22 06:51:34 adam
11 * Revision 1.111 1999/02/11 11:30:09 adam
14 * Revision 1.110 1998/10/20 15:15:31 adam
15 * Changed scan response handler.
17 * Revision 1.109 1998/10/13 21:23:26 adam
18 * Fixed searchStatus method.
20 * Revision 1.108 1998/10/12 11:48:08 adam
21 * Removed printf call.
23 * Revision 1.107 1998/06/10 13:00:46 adam
24 * Added ir-version command.
26 * Revision 1.106 1998/05/20 12:25:35 adam
27 * Fixed bug that occurred in rare cases when encoding of incoming
30 * Revision 1.105 1998/04/02 14:31:08 adam
31 * This version works with compiled ASN.1 code.
33 * Revision 1.104 1998/02/27 14:26:07 adam
34 * Changed client so that it still works if target sets numberOfRecords
35 * in response to an illegal value.
37 * Revision 1.103 1997/11/19 11:22:10 adam
38 * Object identifiers can be accessed in GRS-1 records.
40 * Revision 1.102 1997/09/17 12:22:40 adam
41 * Changed to use YAZ version 1.4. The new comstack utility, cs_straddr,
44 * Revision 1.101 1997/09/09 10:19:53 adam
45 * New MSV5.0 port with fewer warnings.
47 * Revision 1.100 1997/05/01 15:04:05 adam
48 * Added ir-log command.
50 * Revision 1.99 1997/04/30 07:24:47 adam
51 * Spell fix of an error message.
53 * Revision 1.98 1997/04/13 18:57:20 adam
54 * Better error reporting and aligned with Tcl/Tk style.
55 * Rework of notifier code with Tcl_File handles.
57 * Revision 1.97 1996/11/14 17:11:07 adam
58 * Added Explain documentaion.
60 * Revision 1.96 1996/10/08 13:02:50 adam
61 * When dealing with records, odr_choice_enable_bias function is used to
62 * prevent decoding of externals.
64 * Revision 1.95 1996/09/13 10:51:49 adam
65 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
67 * Revision 1.94 1996/08/21 13:32:53 adam
68 * Implemented saveFile method and extended loadFile method to work with it.
70 * Revision 1.93 1996/08/16 15:07:45 adam
71 * First work on Explain.
73 * Revision 1.92 1996/08/09 15:33:07 adam
74 * Modified the code to use tk4.1/tcl7.5 patch level 1. The time-driven
75 * polling is no longer activated on Windows since asynchrounous I/O works
78 * Revision 1.91 1996/07/03 13:31:11 adam
79 * The xmalloc/xfree functions from YAZ are used to manage memory.
81 * Revision 1.90 1996/06/27 14:21:00 adam
82 * Yet another Windows port.
84 * Revision 1.89 1996/06/11 15:27:15 adam
85 * Event type set to connect a little earlier in the do_connect function.
87 * Revision 1.88 1996/06/03 09:04:22 adam
88 * Changed a few logf calls.
90 * Revision 1.87 1996/05/29 06:37:51 adam
91 * Function ir_tcl_get_grs_r enhanced so that specific elements can be
94 * Revision 1.86 1996/03/20 13:54:04 adam
95 * The Tcl_File structure is only manipulated in the Tk-event interface
98 * Revision 1.85 1996/03/15 11:15:48 adam
99 * Modified to use new prototypes for p_query_rpn and p_query_scan.
101 * Revision 1.84 1996/03/07 12:42:49 adam
102 * Better logging when callback is invoked.
104 * Revision 1.83 1996/03/05 09:21:09 adam
105 * Bug fix: memory used by GRS records wasn't freed.
106 * Rewrote some of the error handling code - the connection is always
107 * closed before failback is called.
108 * If failback is defined the send APDU methods (init, search, ...) will
109 * return OK but invoke failback (as is the case if the write operation
111 * Bug fix: ref_count in assoc object could grow if fraction of PDU was
114 * Revision 1.82 1996/02/29 15:30:21 adam
115 * Export of IrTcl functionality to extensions.
117 * Revision 1.81 1996/02/26 18:38:32 adam
118 * Work on export of set methods.
120 * Revision 1.80 1996/02/23 17:31:39 adam
121 * More functions made available to the wais tcl extension.
123 * Revision 1.79 1996/02/23 13:41:38 adam
124 * Work on public access to simple ir class system.
126 * Revision 1.78 1996/02/21 10:16:08 adam
127 * Simplified select handling. Only one function ir_tcl_select_set has
128 * to be externally defined.
130 * Revision 1.77 1996/02/20 17:52:58 adam
131 * Uses the YAZ oid system to name record syntax object identifiers.
133 * Revision 1.76 1996/02/20 16:09:51 adam
134 * Bug fix: didn't set element set names stamp correctly on result
135 * set records when element set names were set to the empty string.
137 * Revision 1.75 1996/02/19 15:41:53 adam
138 * Better log messages.
139 * Minor improvement of connect method.
141 * Revision 1.74 1996/02/05 17:58:03 adam
142 * Ported ir-tcl to use the beta releases of tcl7.5/tk4.1.
144 * Revision 1.73 1996/01/29 11:35:19 adam
145 * Bug fix: cs_type member renamed to comstackType to avoid conflict with
146 * cs_type macro defined by YAZ.
148 * Revision 1.72 1996/01/19 17:45:34 quinn
149 * Added debugging output
151 * Revision 1.71 1996/01/19 16:22:38 adam
152 * New method: apduDump - returns information about last incoming APDU.
154 * Revision 1.70 1996/01/10 09:18:34 adam
155 * PDU specific callbacks implemented: initRespnse, searchResponse,
156 * presentResponse and scanResponse.
157 * Bug fix in the command line shell (tclmain.c) - discovered on OSF/1.
159 * Revision 1.69 1996/01/04 16:12:12 adam
160 * Setting PDUType renamed to eventType.
162 * Revision 1.68 1996/01/04 11:05:22 adam
163 * New setting: PDUType - returns type of last PDU returned from the target.
164 * Fixed a bug in configure/Makefile.
166 * Revision 1.67 1996/01/03 09:00:51 adam
167 * Updated to use new version of Yaz (names changed to avoid C++ conflict).
169 * Revision 1.66 1995/11/28 17:26:39 adam
170 * Removed Carriage return from ir-tcl.c!
171 * Removed misc. debug logs.
173 * Revision 1.65 1995/11/28 13:53:00 quinn
176 * Revision 1.64 1995/11/13 15:39:18 adam
177 * Bug fix: {small,medium}SetElementSetNames weren't set correctly.
178 * Bug fix: idAuthentication weren't set correctly.
180 * Revision 1.63 1995/11/13 09:55:39 adam
181 * Multiple records at a position in a result-set with differnt
184 * Revision 1.62 1995/10/18 17:20:33 adam
185 * Work on target setup in client.tcl.
187 * Revision 1.61 1995/10/18 16:42:42 adam
188 * New settings: smallSetElementSetNames and mediumSetElementSetNames.
190 * Revision 1.60 1995/10/18 15:43:31 adam
191 * In search: mediumSetElementSetNames and smallSetElementSetNames are
192 * set to elementSetNames.
194 * Revision 1.59 1995/10/17 12:18:58 adam
195 * Bug fix: when target connection closed, the connection was not
196 * properly reestablished.
198 * Revision 1.58 1995/10/16 17:00:55 adam
199 * New setting: elementSetNames.
200 * Various client improvements. Medium presentation format looks better.
202 * Revision 1.57 1995/09/21 13:11:51 adam
203 * Support of dynamic loading.
204 * Test script uses load command if necessary.
206 * Revision 1.56 1995/08/29 15:30:14 adam
207 * Work on GRS records.
209 * Revision 1.55 1995/08/28 09:43:25 adam
210 * Minor changes. configure only searches for yaz beta 3 and versions after
213 * Revision 1.54 1995/08/24 12:25:16 adam
214 * Modified to work with yaz 1.0b3.
216 * Revision 1.53 1995/08/04 12:49:26 adam
217 * Bug fix: reading uninitialized variable p.
219 * Revision 1.52 1995/08/04 11:32:38 adam
220 * More work on output queue. Memory related routines moved
223 * Revision 1.51 1995/08/03 13:22:54 adam
226 * Revision 1.50 1995/07/20 08:09:49 adam
227 * client.tcl: Targets removed from hotTargets list when targets
228 * are removed/modified.
229 * ir-tcl.c: More work on triggerResourceControl.
231 * Revision 1.49 1995/06/30 12:39:21 adam
232 * Bug fix: loadFile didn't set record type.
233 * The MARC routines are a little less strict in the interpretation.
234 * Script display.tcl replaces the old marc.tcl.
235 * New interactive script: shell.tcl.
237 * Revision 1.48 1995/06/27 19:03:50 adam
238 * Bug fix in do_present in ir-tcl.c: p->set_child member weren't set.
239 * nextResultSetPosition used instead of setOffset.
241 * Revision 1.47 1995/06/25 10:25:04 adam
242 * Working on triggerResourceControl. Description of compile/install
243 * procedure moved to ir-tcl.sgml.
245 * Revision 1.46 1995/06/22 13:15:06 adam
246 * Feature: SUTRS. Setting getSutrs implemented.
247 * Work on display formats.
248 * Preferred record syntax can be set by the user.
250 * Revision 1.45 1995/06/20 08:07:30 adam
251 * New setting: failInfo.
252 * Working on better cancel mechanism.
254 * Revision 1.44 1995/06/19 17:01:20 adam
257 * Revision 1.43 1995/06/19 13:06:08 adam
258 * New define: IR_TCL_VERSION.
260 * Revision 1.42 1995/06/19 08:08:52 adam
261 * client.tcl: hotTargets now contain both database and target name.
262 * ir-tcl.c: setting protocol edited. Errors in callbacks are logged
263 * by logf(LOG_WARN, ...) calls.
265 * Revision 1.41 1995/06/16 12:28:16 adam
266 * Implemented preferredRecordSyntax.
267 * Minor changes in diagnostic handling.
268 * Record list deleted when connection closes.
270 * Revision 1.40 1995/06/14 13:37:18 adam
271 * Setting recordType implemented.
272 * Setting implementationVersion implemented.
273 * Settings implementationId / implementationName edited.
275 * Revision 1.39 1995/06/08 10:26:32 adam
276 * Bug fix in ir_strdup.
278 * Revision 1.38 1995/06/01 16:36:47 adam
279 * About buttons. Minor bug fixes.
281 * Revision 1.37 1995/06/01 07:31:20 adam
282 * Rename of many typedefs -> IrTcl_...
284 * Revision 1.36 1995/05/31 13:09:59 adam
285 * Client searches/presents may be interrupted.
286 * New moving book-logo.
288 * Revision 1.35 1995/05/31 08:36:33 adam
289 * Bug fix in client.tcl: didn't save options on clientrc.tcl.
290 * New method: referenceId. More work on scan.
292 * Revision 1.34 1995/05/29 10:33:42 adam
293 * README and rename of startup script.
295 * Revision 1.33 1995/05/29 09:15:11 quinn
296 * Changed CS_SR to PROTO_SR, etc.
298 * Revision 1.32 1995/05/29 08:44:16 adam
299 * Work on delete of objects.
301 * Revision 1.31 1995/05/26 11:44:10 adam
302 * Bugs fixed. More work on MARC utilities and queries. Test
303 * client is up-to-date again.
305 * Revision 1.30 1995/05/26 08:54:11 adam
306 * New MARC utilities. Uses prefix query.
308 * Revision 1.29 1995/05/24 14:10:22 adam
309 * Work on idAuthentication, protocolVersion and options.
311 * Revision 1.28 1995/05/23 15:34:48 adam
312 * Many new settings, userInformationField, smallSetUpperBound, etc.
313 * A number of settings are inherited when ir-set is executed.
314 * This version is incompatible with the graphical test client (client.tcl).
316 * Revision 1.27 1995/05/11 15:34:47 adam
317 * Scan request changed a bit. This version works with RLG.
319 * Revision 1.26 1995/04/18 16:11:51 adam
320 * First version of graphical Scan. Some work on query-by-form.
322 * Revision 1.25 1995/04/17 09:37:17 adam
323 * Further development of scan.
325 * Revision 1.24 1995/04/11 14:16:42 adam
326 * Further work on scan. Response works. Entries aren't saved yet.
328 * Revision 1.23 1995/04/10 10:50:27 adam
329 * Result-set name defaults to suffix of ir-set name.
330 * Started working on scan. Not finished at this point.
332 * Revision 1.22 1995/03/31 10:43:03 adam
333 * More robust when getting bad MARC records.
335 * Revision 1.21 1995/03/31 08:56:37 adam
336 * New button "Search".
338 * Revision 1.20 1995/03/29 16:07:09 adam
339 * Bug fix: Didn't use setName in present request.
341 * Revision 1.19 1995/03/28 12:45:23 adam
342 * New ir method failback: called on disconnect/protocol error.
343 * New ir set/get method: protocol: SR / Z3950.
344 * Simple popup and disconnect when failback is invoked.
346 * Revision 1.18 1995/03/21 15:50:12 adam
349 * Revision 1.17 1995/03/21 13:41:03 adam
350 * Comstack cs_create not used too often. Non-blocking connect.
352 * Revision 1.16 1995/03/21 08:26:06 adam
353 * New method, setName, to specify the result set name (other than Default).
354 * New method, responseStatus, which returns diagnostic info, if any, after
355 * present response / search response.
357 * Revision 1.15 1995/03/20 15:24:07 adam
358 * Diagnostic records saved on searchResponse.
360 * Revision 1.14 1995/03/20 08:53:22 adam
361 * Event loop in tclmain.c rewritten. New method searchStatus.
363 * Revision 1.13 1995/03/17 18:26:17 adam
364 * Non-blocking i/o used now. Database names popup as cascade items.
366 * Revision 1.12 1995/03/17 15:45:00 adam
367 * Improved target/database setup.
369 * Revision 1.11 1995/03/16 17:54:03 adam
370 * Minor changes really.
372 * Revision 1.10 1995/03/15 16:14:50 adam
373 * Blocking arg in cs_create changed.
375 * Revision 1.9 1995/03/15 13:59:24 adam
378 * Revision 1.8 1995/03/15 08:25:16 adam
379 * New method presentStatus to check for error on present. Misc. cleanup
380 * of IrTcl_RecordList manipulations. Full MARC record presentation in
383 * Revision 1.7 1995/03/14 17:32:29 adam
384 * Presentation of full Marc record in popup window.
386 * Revision 1.6 1995/03/12 19:31:55 adam
387 * Pattern matching implemented when retrieving MARC records. More
388 * diagnostic functions.
390 * Revision 1.5 1995/03/10 18:00:15 adam
391 * Actual presentation in line-by-line format. RPN query support.
393 * Revision 1.4 1995/03/09 16:15:08 adam
394 * First presentRequest attempts. Hot-target list.
412 #if defined(__WIN32__)
413 # define WIN32_LEAN_AND_MEAN
414 # include <windows.h>
415 # undef WIN32_LEAN_AND_MEAN
418 * VC++ has an alternate entry point called DllMain, so we need to rename
422 # if defined(_MSC_VER)
423 # define EXPORT(a,b) __declspec(dllexport) a b
424 # define DllEntryPoint DllMain
426 # if defined(__BORLANDC__)
427 # define EXPORT(a,b) a _export b
429 # define EXPORT(a,b) a b
433 # define EXPORT(a,b) a b
436 static char *wrongArgs = "wrong # args: should be \"";
438 static int ir_tcl_error_exec (Tcl_Interp *interp, int argc, char **argv)
441 Tcl_AppendResult (interp, " while executing ", NULL);
442 for (i = 0; i<argc; i++)
443 Tcl_AppendResult (interp, (i ? " " : "\""), argv[i], NULL);
444 Tcl_AppendResult (interp, "\"", NULL);
449 static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num);
451 static void ir_select_notify (ClientData clientData, int r, int w, int e);
453 void ir_select_add (int fd, void *obj)
455 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
458 void ir_select_add_write (int fd, void *obj)
460 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 1, 0);
463 void ir_select_remove (int fd, void *obj)
465 ir_tcl_select_set (NULL, fd, obj, 0, 0, 0);
468 void ir_select_remove_write (int fd, void *obj)
470 ir_tcl_select_set (ir_select_notify, fd, obj, 1, 0, 0);
473 static void delete_IR_record (IrTcl_RecordList *rl)
477 case Z_NamePlusRecord_databaseRecord:
478 switch (rl->u.dbrec.type)
481 ir_tcl_grs_del (&rl->u.dbrec.u.grs1);
486 xfree (rl->u.dbrec.buf);
487 rl->u.dbrec.buf = NULL;
489 case Z_NamePlusRecord_surrogateDiagnostic:
490 ir_deleteDiags (&rl->u.surrogateDiagnostics.list,
491 &rl->u.surrogateDiagnostics.num);
494 xfree (rl->elements);
497 static void purge_IR_records (IrTcl_SetObj *setobj)
499 IrTcl_RecordList *rl;
500 while ((rl = setobj->record_list))
502 setobj->record_list = rl->next;
503 delete_IR_record (rl);
508 static IrTcl_RecordList *new_IR_record (IrTcl_SetObj *setobj,
510 const char *elements)
512 IrTcl_RecordList *rl;
514 if (elements && !*elements)
516 for (rl = setobj->record_list; rl; rl = rl->next)
518 if (no == rl->no && (!rl->elements || !elements ||
519 !strcmp(elements, rl->elements)))
521 delete_IR_record (rl);
527 rl = ir_tcl_malloc (sizeof(*rl));
528 rl->next = setobj->record_list;
530 setobj->record_list = rl;
533 ir_tcl_strdup (NULL, &rl->elements, elements);
540 int ir_tcl_eval (Tcl_Interp *interp, const char *command)
542 char *tmp = ir_tcl_malloc (strlen(command)+1);
545 logf (LOG_DEBUG, "Invoking %.23s ...", command);
546 strcpy (tmp, command);
547 r = Tcl_Eval (interp, tmp);
550 const char *errorInfo = Tcl_GetVar (interp, "errorInfo", 0);
551 logf (LOG_WARN, "Tcl error in line %d: %s\n%s", interp->errorLine,
552 interp->result, errorInfo ? errorInfo : "<null>");
554 Tcl_FreeResult (interp);
560 * IrTcl_getRecordSyntaxStr: Return record syntax name of object id
562 static char *IrTcl_getRecordSyntaxStr (enum oid_value value)
565 struct oident ent, *entp;
567 ent.proto = PROTO_Z3950;
568 ent.oclass = CLASS_RECSYN;
571 o = oid_getoidbyent (&ent);
572 entp = oid_getentbyoid (o);
580 * IrTcl_getRecordSyntaxVal: Return record syntax value of string
582 static enum oid_value IrTcl_getRecordSyntaxVal (const char *name)
584 return oid_getvalbyname (name);
587 static IrTcl_RecordList *find_IR_record (IrTcl_SetObj *setobj, int no)
589 IrTcl_RecordList *rl;
591 for (rl = setobj->record_list; rl; rl = rl->next)
593 (!setobj->recordElements || !rl->elements ||
594 !strcmp (setobj->recordElements, rl->elements)))
599 static void delete_IR_records (IrTcl_SetObj *setobj)
601 IrTcl_RecordList *rl, *rl1;
603 for (rl = setobj->record_list; rl; rl = rl1)
605 delete_IR_record (rl);
609 setobj->record_list = NULL;
613 * ir_tcl_get_set_int: Set/get integer value
615 int ir_tcl_get_set_int (int *val, Tcl_Interp *interp, int argc, char **argv)
621 if (Tcl_GetInt (interp, argv[2], val)==TCL_ERROR)
624 sprintf (buf, "%d", *val);
625 Tcl_AppendResult (interp, buf, NULL);
631 * ir_tcl_method_error
633 int ir_tcl_method_error (Tcl_Interp *interp, int argc, char **argv,
636 IrTcl_Methods *tab_i = tab;
639 Tcl_AppendResult (interp, "bad method: \"", *argv, " ", argv[1],
640 "\"\nmethod should be of:", NULL);
641 for (tab_i = tab; tab_i->tab; tab_i++)
642 for (t = tab_i->tab; t->name; t++)
643 Tcl_AppendResult (interp, " ", t->name, NULL);
648 * ir_tcl_method: Search for method in table and invoke method handler
650 int ir_tcl_method (Tcl_Interp *interp, int argc, char **argv,
651 IrTcl_Methods *tab, int *ret)
653 IrTcl_Methods *tab_i = tab;
656 for (tab_i = tab; tab_i->tab; tab_i++)
657 for (t = tab_i->tab; t->name; t++)
660 if ((*t->method)(tab_i->obj, interp, argc, argv) == TCL_ERROR)
664 if (!strcmp (t->name, argv[1]))
666 *ret = (*t->method)(tab_i->obj, interp, argc, argv);
677 * ir_tcl_named_bits: get/set named bits
679 int ir_tcl_named_bits (struct ir_named_entry *tab, Odr_bitmask *ob,
680 Tcl_Interp *interp, int argc, char **argv)
682 struct ir_named_entry *ti;
687 for (no = 0; no < argc; no++)
690 for (ti = tab; ti->name; ti++)
691 if (!strcmp(argv[no], "@all") || !strcmp (argv[no], ti->name))
693 ODR_MASK_SET (ob, ti->pos);
698 Tcl_AppendResult (interp, "bad bit mask ", argv[no], NULL);
699 return ir_tcl_error_exec (interp, argc, argv);
704 for (ti = tab; ti->name; ti++)
705 if (ODR_MASK_GET (ob, ti->pos))
706 Tcl_AppendElement (interp, ti->name);
710 static void set_referenceId (ODR o, Z_ReferenceId **dst, const char *src)
716 *dst = odr_malloc (o, sizeof(**dst));
717 (*dst)->size = (*dst)->len = strlen(src);
718 (*dst)->buf = odr_malloc (o, (*dst)->len);
719 memcpy ((*dst)->buf, src, (*dst)->len);
723 static void get_referenceId (char **dst, Z_ReferenceId *src)
731 *dst = ir_tcl_malloc (src->len+1);
732 memcpy (*dst, src->buf, src->len);
733 (*dst)[src->len] = '\0';
736 /* ------------------------------------------------------- */
739 * do_init_request: init method on IR object
741 static int do_init_request (void *obj, Tcl_Interp *interp,
742 int argc, char **argv)
750 logf (LOG_DEBUG, "init %s", *argv);
753 Tcl_AppendResult (interp, "not connected", NULL);
754 return ir_tcl_error_exec (interp, argc, argv);
756 apdu = zget_APDU (p->odr_out, Z_APDU_initRequest);
757 req = apdu->u.initRequest;
759 set_referenceId (p->odr_out, &req->referenceId, p->set_inher.referenceId);
760 req->options = &p->options;
761 req->protocolVersion = &p->protocolVersion;
762 req->preferredMessageSize = &p->preferredMessageSize;
763 req->maximumRecordSize = &p->maximumRecordSize;
765 if (p->idAuthenticationGroupId)
767 Z_IdPass *pass = odr_malloc (p->odr_out, sizeof(*pass));
768 Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
770 logf (LOG_DEBUG, "using pass authentication");
772 auth->which = Z_IdAuthentication_idPass;
773 auth->u.idPass = pass;
774 if (p->idAuthenticationGroupId && *p->idAuthenticationGroupId)
775 pass->groupId = p->idAuthenticationGroupId;
777 pass->groupId = NULL;
778 if (p->idAuthenticationUserId && *p->idAuthenticationUserId)
779 pass->userId = p->idAuthenticationUserId;
782 if (p->idAuthenticationPassword && *p->idAuthenticationPassword)
783 pass->password = p->idAuthenticationPassword;
785 pass->password = NULL;
786 req->idAuthentication = auth;
788 else if (!p->idAuthenticationOpen || !*p->idAuthenticationOpen)
789 req->idAuthentication = NULL;
792 Z_IdAuthentication *auth = odr_malloc (p->odr_out, sizeof(*auth));
794 logf (LOG_DEBUG, "using open authentication");
795 auth->which = Z_IdAuthentication_open;
796 auth->u.open = p->idAuthenticationOpen;
797 req->idAuthentication = auth;
799 req->implementationId = p->implementationId;
800 req->implementationName = p->implementationName;
801 req->implementationVersion = p->implementationVersion;
802 req->userInformationField = 0;
804 return ir_tcl_send_APDU (interp, p, apdu, "init", *argv);
808 * do_protocolVersion: Set protocol Version
810 static int do_protocolVersion (void *obj, Tcl_Interp *interp,
811 int argc, char **argv)
819 ODR_MASK_ZERO (&p->protocolVersion);
820 ODR_MASK_SET (&p->protocolVersion, 0);
821 ODR_MASK_SET (&p->protocolVersion, 1);
826 if (Tcl_GetInt (interp, argv[2], &version)==TCL_ERROR)
828 ODR_MASK_ZERO (&p->protocolVersion);
829 for (i = 0; i<version; i++)
830 ODR_MASK_SET (&p->protocolVersion, i);
832 for (i = 4; --i >= 0; )
833 if (ODR_MASK_GET (&p->protocolVersion, i))
835 sprintf (buf, "%d", i+1);
836 interp->result = buf;
841 * do_options: Set options
843 static int do_options (void *obj, Tcl_Interp *interp,
844 int argc, char **argv)
846 static struct ir_named_entry options_tab[] = {
850 { "resourceReport", 3 },
851 { "triggerResourceCtrl", 4},
852 { "resourceCtrl", 5},
856 { "extendedServices", 10},
857 { "level-1Segmentation", 11},
858 { "level-2Segmentation", 12},
859 { "concurrentOperations", 13},
860 { "namedResultSets", 14},
867 ODR_MASK_ZERO (&p->options);
868 ODR_MASK_SET (&p->options, 0);
869 ODR_MASK_SET (&p->options, 1);
870 ODR_MASK_SET (&p->options, 4);
871 ODR_MASK_SET (&p->options, 7);
872 ODR_MASK_SET (&p->options, 14);
875 return ir_tcl_named_bits (options_tab, &p->options, interp, argc-2, argv+2);
879 * do_apduInfo: Get APDU information
881 static int do_apduInfo (void *obj, Tcl_Interp *interp, int argc, char **argv)
889 sprintf (buf, "%d", p->apduLen);
890 Tcl_AppendElement (interp, buf);
891 sprintf (buf, "%d", p->apduOffset);
892 Tcl_AppendElement (interp, buf);
895 Tcl_AppendElement (interp, "");
898 apduf = fopen ("apdu.tmp", "w");
901 Tcl_AppendElement (interp, "");
904 odr_dumpBER (apduf, p->buf_in, p->apduLen);
906 if (!(apduf = fopen ("apdu.tmp", "r")))
907 Tcl_AppendElement (interp, "");
912 Tcl_AppendResult (interp, " {", NULL);
913 while ((c = getc (apduf)) != EOF)
917 Tcl_AppendResult (interp, buf, NULL);
920 Tcl_AppendResult (interp, "}", NULL);
927 * do_failInfo: Get fail information
929 static int do_failInfo (void *obj, Tcl_Interp *interp, int argc, char **argv)
939 sprintf (buf, "%d", p->failInfo);
945 case IR_TCL_FAIL_CONNECT:
946 cp = "connect failed";
948 case IR_TCL_FAIL_READ:
949 cp = "connection closed";
951 case IR_TCL_FAIL_WRITE:
952 cp = "connection closed";
954 case IR_TCL_FAIL_IN_APDU:
955 cp = "failed to decode incoming APDU";
957 case IR_TCL_FAIL_UNKNOWN_APDU:
963 Tcl_AppendElement (interp, buf);
964 Tcl_AppendElement (interp, cp);
969 * do_preferredMessageSize: Set/get preferred message size
971 static int do_preferredMessageSize (void *obj, Tcl_Interp *interp,
972 int argc, char **argv)
978 p->preferredMessageSize = 30000;
981 return ir_tcl_get_set_int (&p->preferredMessageSize, interp, argc, argv);
985 * do_maximumRecordSize: Set/get maximum record size
987 static int do_maximumRecordSize (void *obj, Tcl_Interp *interp,
988 int argc, char **argv)
994 p->maximumRecordSize = 30000;
997 return ir_tcl_get_set_int (&p->maximumRecordSize, interp, argc, argv);
1001 * do_initResult: Get init result
1003 static int do_initResult (void *obj, Tcl_Interp *interp,
1004 int argc, char **argv)
1010 return ir_tcl_get_set_int (&p->initResult, interp, argc, argv);
1015 * do_implementationName: Set/get Implementation Name.
1017 static int do_implementationName (void *obj, Tcl_Interp *interp,
1018 int argc, char **argv)
1023 return ir_tcl_strdup (interp, &p->implementationName,
1024 "Index Data/IrTcl on YAZ");
1025 else if (argc == -1)
1026 return ir_tcl_strdel (interp, &p->implementationName);
1029 xfree (p->implementationName);
1030 if (ir_tcl_strdup (interp, &p->implementationName, argv[2])
1034 Tcl_AppendResult (interp, p->implementationName, (char*) NULL);
1039 * do_implementationId: Get Implementation Id.
1041 static int do_implementationId (void *obj, Tcl_Interp *interp,
1042 int argc, char **argv)
1047 return ir_tcl_strdup (interp, &p->implementationId, "YAZ (id=81)");
1048 else if (argc == -1)
1049 return ir_tcl_strdel (interp, &p->implementationId);
1050 Tcl_AppendResult (interp, p->implementationId, (char*) NULL);
1055 * do_implementationVersion: get Implementation Version.
1057 static int do_implementationVersion (void *obj, Tcl_Interp *interp,
1058 int argc, char **argv)
1063 return ir_tcl_strdup (interp, &p->implementationVersion,
1065 #ifdef IR_TCL_VERSION
1066 " / Irtcl: " IR_TCL_VERSION
1069 else if (argc == -1)
1070 return ir_tcl_strdel (interp, &p->implementationVersion);
1071 Tcl_AppendResult (interp, p->implementationVersion, (char*) NULL);
1076 * do_targetImplementationName: Get Implementation Name of target.
1078 static int do_targetImplementationName (void *obj, Tcl_Interp *interp,
1079 int argc, char **argv)
1085 p->targetImplementationName = NULL;
1088 else if (argc == -1)
1089 return ir_tcl_strdel (interp, &p->targetImplementationName);
1090 Tcl_AppendResult (interp, p->targetImplementationName, (char*) NULL);
1095 * do_targetImplementationId: Get Implementation Id of target
1097 static int do_targetImplementationId (void *obj, Tcl_Interp *interp,
1098 int argc, char **argv)
1104 p->targetImplementationId = NULL;
1107 else if (argc == -1)
1108 return ir_tcl_strdel (interp, &p->targetImplementationId);
1109 Tcl_AppendResult (interp, p->targetImplementationId, (char*) NULL);
1114 * do_targetImplementationVersion: Get Implementation Version of target
1116 static int do_targetImplementationVersion (void *obj, Tcl_Interp *interp,
1117 int argc, char **argv)
1123 p->targetImplementationVersion = NULL;
1126 else if (argc == -1)
1127 return ir_tcl_strdel (interp, &p->targetImplementationVersion);
1128 Tcl_AppendResult (interp, p->targetImplementationVersion, (char*) NULL);
1133 * do_idAuthentication: Set/get id Authentication
1135 static int do_idAuthentication (void *obj, Tcl_Interp *interp,
1136 int argc, char **argv)
1140 if (argc >= 3 || argc == -1)
1142 xfree (p->idAuthenticationOpen);
1143 xfree (p->idAuthenticationGroupId);
1144 xfree (p->idAuthenticationUserId);
1145 xfree (p->idAuthenticationPassword);
1147 if (argc >= 3 || argc <= 0)
1149 p->idAuthenticationOpen = NULL;
1150 p->idAuthenticationGroupId = NULL;
1151 p->idAuthenticationUserId = NULL;
1152 p->idAuthenticationPassword = NULL;
1161 ir_tcl_strdup (interp, &p->idAuthenticationOpen, argv[2])
1168 ir_tcl_strdup (interp, &p->idAuthenticationGroupId, argv[2])
1172 ir_tcl_strdup (interp, &p->idAuthenticationUserId, argv[3])
1176 ir_tcl_strdup (interp, &p->idAuthenticationPassword, argv[4])
1181 if (p->idAuthenticationOpen)
1182 Tcl_AppendElement (interp, p->idAuthenticationOpen);
1183 else if (p->idAuthenticationGroupId)
1185 Tcl_AppendElement (interp, p->idAuthenticationGroupId);
1186 Tcl_AppendElement (interp, p->idAuthenticationUserId);
1187 Tcl_AppendElement (interp, p->idAuthenticationPassword);
1193 * do_connect: connect method on IR object
1195 static int do_connect (void *obj, Tcl_Interp *interp,
1196 int argc, char **argv)
1206 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
1207 " ?hostname?\"", NULL);
1212 Tcl_AppendResult (interp, p->hostname, NULL);
1216 logf (LOG_DEBUG, "connect %s %s", *argv, argv[2]);
1219 Tcl_AppendResult (interp, "already connected", NULL);
1220 return ir_tcl_error_exec (interp, argc, argv);
1222 if (!strcmp (p->comstackType, "tcpip"))
1224 p->cs_link = cs_create (tcpip_type, CS_BLOCK, p->protocol_type);
1225 logf (LOG_DEBUG, "tcp/ip connect %s", argv[2]);
1227 else if (!strcmp (p->comstackType, "mosi"))
1230 p->cs_link = cs_create (mosi_type, CS_BLOCK, p->protocol_type);
1231 logf (LOG_DEBUG, "mosi connect %s", argv[2]);
1233 Tcl_AppendResult (interp, "mosi not supported", NULL);
1234 return ir_tcl_error_exec (interp, argc, argv);
1239 Tcl_AppendResult (interp, "bad comstack type ",
1240 p->comstackType, NULL);
1241 return ir_tcl_error_exec (interp, argc, argv);
1243 if (ir_tcl_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR)
1245 p->eventType = "connect";
1246 addr = cs_straddr (p->cs_link, argv[2]);
1249 ir_tcl_disconnect (p);
1250 Tcl_AppendResult (interp, "cs_straddr fail", NULL);
1251 return ir_tcl_error_exec (interp, argc, argv);
1253 if ((r=cs_connect (p->cs_link, addr)) < 0)
1255 ir_tcl_disconnect (p);
1256 Tcl_AppendResult (interp, "connect fail", NULL);
1257 return ir_tcl_error_exec (interp, argc, argv);
1259 ir_select_add (cs_fileno (p->cs_link), p);
1262 logf (LOG_DEBUG, "connect pending fd=%d", cs_fileno(p->cs_link));
1263 ir_select_add_write (cs_fileno (p->cs_link), p);
1264 p->state = IR_TCL_R_Connecting;
1268 logf (LOG_DEBUG, "connect ok fd=%d", cs_fileno(p->cs_link));
1269 p->state = IR_TCL_R_Idle;
1271 ir_tcl_eval (p->interp, p->callback);
1278 * ir_tcl_disconnect: close connection
1280 void ir_tcl_disconnect (IrTcl_Obj *p)
1284 logf(LOG_DEBUG, "Closing connection to %s", p->hostname);
1285 xfree (p->hostname);
1287 assert (p->cs_link);
1288 ir_select_remove (cs_fileno (p->cs_link), p);
1290 odr_reset (p->odr_in);
1292 #if TCL_MAJOR_VERSION == 8
1293 cs_fileno(p->cs_link) = -1;
1295 cs_close (p->cs_link);
1298 ODR_MASK_ZERO (&p->options);
1299 ODR_MASK_SET (&p->options, 0);
1300 ODR_MASK_SET (&p->options, 1);
1301 ODR_MASK_SET (&p->options, 4);
1302 ODR_MASK_SET (&p->options, 7);
1303 ODR_MASK_SET (&p->options, 14);
1305 ODR_MASK_ZERO (&p->protocolVersion);
1306 ODR_MASK_SET (&p->protocolVersion, 0);
1307 ODR_MASK_SET (&p->protocolVersion, 1);
1310 assert (!p->cs_link);
1314 * do_disconnect: disconnect method on IR object
1316 static int do_disconnect (void *obj, Tcl_Interp *interp,
1317 int argc, char **argv)
1323 p->state = IR_TCL_R_Idle;
1324 p->eventType = NULL;
1329 ir_tcl_disconnect (p);
1334 * do_comstack: Set/get comstack method on IR object
1336 static int do_comstack (void *o, Tcl_Interp *interp,
1337 int argc, char **argv)
1342 return ir_tcl_strdup (interp, &obj->comstackType, "tcpip");
1343 else if (argc == -1)
1344 return ir_tcl_strdel (interp, &obj->comstackType);
1347 xfree (obj->comstackType);
1348 if (ir_tcl_strdup (interp, &obj->comstackType, argv[2]) == TCL_ERROR)
1351 Tcl_AppendElement (interp, obj->comstackType);
1356 * do_logLevel: Set log level
1358 static int do_logLevel (void *o, Tcl_Interp *interp,
1359 int argc, char **argv)
1364 log_init (log_mask_str (argv[2]), "", NULL);
1366 log_init (log_mask_str (argv[2]), argv[3], NULL);
1368 log_init (log_mask_str (argv[2]), argv[3], argv[4]);
1374 * do_eventType: Return type of last event
1376 static int do_eventType (void *obj, Tcl_Interp *interp,
1377 int argc, char **argv)
1383 p->eventType = NULL;
1386 Tcl_AppendElement (interp, p->eventType ? p->eventType : "");
1392 * do_callback: add callback
1394 static int do_callback (void *obj, Tcl_Interp *interp,
1395 int argc, char **argv)
1404 else if (argc == -1)
1405 return ir_tcl_strdel (interp, &p->callback);
1408 xfree (p->callback);
1411 if (ir_tcl_strdup (interp, &p->callback, argv[2]) == TCL_ERROR)
1421 * do_failback: add error handle callback
1423 static int do_failback (void *obj, Tcl_Interp *interp,
1424 int argc, char **argv)
1433 else if (argc == -1)
1434 return ir_tcl_strdel (interp, &p->failback);
1437 xfree (p->failback);
1440 if (ir_tcl_strdup (interp, &p->failback, argv[2]) == TCL_ERROR)
1450 * do_initResponse: add init response handler
1452 static int do_initResponse (void *obj, Tcl_Interp *interp,
1453 int argc, char **argv)
1459 p->initResponse = NULL;
1462 else if (argc == -1)
1463 return ir_tcl_strdel (interp, &p->initResponse);
1466 xfree (p->initResponse);
1469 if (ir_tcl_strdup (interp, &p->initResponse, argv[2]) == TCL_ERROR)
1473 p->initResponse = NULL;
1478 * do_protocol: Set/get protocol method on IR object
1480 static int do_protocol (void *o, Tcl_Interp *interp, int argc, char **argv)
1486 p->protocol_type = PROTO_Z3950;
1491 if (!strcmp (argv[2], "Z39"))
1492 p->protocol_type = PROTO_Z3950;
1493 else if (!strcmp (argv[2], "SR"))
1494 p->protocol_type = PROTO_SR;
1497 Tcl_AppendResult (interp, "bad protocol ", argv[2], NULL);
1498 return ir_tcl_error_exec (interp, argc, argv);
1502 switch (p->protocol_type)
1505 Tcl_AppendElement (interp, "Z39");
1508 Tcl_AppendElement (interp, "SR");
1515 * do_triggerResourceControl:
1517 static int do_triggerResourceControl (void *obj, Tcl_Interp *interp,
1518 int argc, char **argv)
1522 Z_TriggerResourceControlRequest *req;
1523 bool_t is_false = 0;
1529 Tcl_AppendResult (interp, "not connected", NULL);
1530 return ir_tcl_error_exec (interp, argc, argv);
1532 apdu = zget_APDU (p->odr_out, Z_APDU_triggerResourceControlRequest);
1533 req = apdu->u.triggerResourceControlRequest;
1534 *req->requestedAction = Z_TriggerResourceCtrl_cancel;
1535 req->resultSetWanted = &is_false;
1537 return ir_tcl_send_APDU (interp, p, apdu, "triggerResourceControl",
1542 * do_databaseNames: specify database names
1544 static int do_databaseNames (void *obj, Tcl_Interp *interp,
1545 int argc, char **argv)
1548 IrTcl_SetCObj *p = obj;
1552 for (i=0; i<p->num_databaseNames; i++)
1553 xfree (p->databaseNames[i]);
1554 xfree (p->databaseNames);
1558 p->num_databaseNames = 0;
1559 p->databaseNames = NULL;
1564 for (i=0; i<p->num_databaseNames; i++)
1565 Tcl_AppendElement (interp, p->databaseNames[i]);
1568 if (p->databaseNames)
1570 for (i=0; i<p->num_databaseNames; i++)
1571 xfree (p->databaseNames[i]);
1572 xfree (p->databaseNames);
1574 p->num_databaseNames = argc - 2;
1576 ir_tcl_malloc (sizeof(*p->databaseNames) * (1+p->num_databaseNames));
1577 for (i=0; i<p->num_databaseNames; i++)
1579 if (ir_tcl_strdup (interp, &p->databaseNames[i], argv[2+i])
1583 p->databaseNames[i] = NULL;
1588 * do_replaceIndicator: Set/get replace Set indicator
1590 static int do_replaceIndicator (void *obj, Tcl_Interp *interp,
1591 int argc, char **argv)
1593 IrTcl_SetCObj *p = obj;
1597 p->replaceIndicator = 1;
1600 return ir_tcl_get_set_int (&p->replaceIndicator, interp, argc, argv);
1604 * do_queryType: Set/Get query method
1606 static int do_queryType (void *obj, Tcl_Interp *interp,
1607 int argc, char **argv)
1609 IrTcl_SetCObj *p = obj;
1612 return ir_tcl_strdup (interp, &p->queryType, "rpn");
1613 else if (argc == -1)
1614 return ir_tcl_strdel (interp, &p->queryType);
1617 xfree (p->queryType);
1618 if (ir_tcl_strdup (interp, &p->queryType, argv[2]) == TCL_ERROR)
1621 Tcl_AppendResult (interp, p->queryType, NULL);
1626 * do_userInformationField: Get User information field
1628 static int do_userInformationField (void *obj, Tcl_Interp *interp,
1629 int argc, char **argv)
1635 p->userInformationField = NULL;
1638 else if (argc == -1)
1639 return ir_tcl_strdel (interp, &p->userInformationField);
1640 Tcl_AppendResult (interp, p->userInformationField, NULL);
1645 * do_smallSetUpperBound: Set/get small set upper bound
1647 static int do_smallSetUpperBound (void *o, Tcl_Interp *interp,
1648 int argc, char **argv)
1650 IrTcl_SetCObj *p = o;
1654 p->smallSetUpperBound = 0;
1657 return ir_tcl_get_set_int (&p->smallSetUpperBound, interp, argc, argv);
1661 * do_largeSetLowerBound: Set/get large set lower bound
1663 static int do_largeSetLowerBound (void *o, Tcl_Interp *interp,
1664 int argc, char **argv)
1666 IrTcl_SetCObj *p = o;
1670 p->largeSetLowerBound = 2;
1673 return ir_tcl_get_set_int (&p->largeSetLowerBound, interp, argc, argv);
1677 * do_mediumSetPresentNumber: Set/get large set lower bound
1679 static int do_mediumSetPresentNumber (void *o, Tcl_Interp *interp,
1680 int argc, char **argv)
1682 IrTcl_SetCObj *p = o;
1686 p->mediumSetPresentNumber = 0;
1689 return ir_tcl_get_set_int (&p->mediumSetPresentNumber, interp, argc, argv);
1693 * do_referenceId: Set/Get referenceId
1695 static int do_referenceId (void *obj, Tcl_Interp *interp,
1696 int argc, char **argv)
1698 IrTcl_SetCObj *p = obj;
1702 p->referenceId = NULL;
1705 else if (argc == -1)
1706 return ir_tcl_strdel (interp, &p->referenceId);
1709 xfree (p->referenceId);
1710 if (ir_tcl_strdup (interp, &p->referenceId, argv[2]) == TCL_ERROR)
1713 Tcl_AppendResult (interp, p->referenceId, NULL);
1718 * do_preferredRecordSyntax: Set/get preferred record syntax
1720 static int do_preferredRecordSyntax (void *obj, Tcl_Interp *interp,
1721 int argc, char **argv)
1723 IrTcl_SetCObj *p = obj;
1727 p->preferredRecordSyntax = NULL;
1730 else if (argc == -1)
1732 xfree (p->preferredRecordSyntax);
1733 p->preferredRecordSyntax = NULL;
1738 xfree (p->preferredRecordSyntax);
1739 p->preferredRecordSyntax = NULL;
1740 if (argv[2][0] && (p->preferredRecordSyntax =
1741 ir_tcl_malloc (sizeof(*p->preferredRecordSyntax))))
1742 *p->preferredRecordSyntax = IrTcl_getRecordSyntaxVal (argv[2]);
1747 (interp,!p->preferredRecordSyntax ? "" :
1748 IrTcl_getRecordSyntaxStr(*p->preferredRecordSyntax));
1755 * do_elementSetNames: Set/Get element Set Names
1757 static int do_elementSetNames (void *obj, Tcl_Interp *interp,
1758 int argc, char **argv)
1760 IrTcl_SetCObj *p = obj;
1764 p->elementSetNames = NULL;
1767 else if (argc == -1)
1768 return ir_tcl_strdel (interp, &p->elementSetNames);
1771 xfree (p->elementSetNames);
1772 if (ir_tcl_strdup (interp, &p->elementSetNames, argv[2]) == TCL_ERROR)
1775 Tcl_AppendResult (interp, p->elementSetNames, NULL);
1780 * do_smallSetElementSetNames: Set/Get small Set Element Set Names
1782 static int do_smallSetElementSetNames (void *obj, Tcl_Interp *interp,
1783 int argc, char **argv)
1785 IrTcl_SetCObj *p = obj;
1789 p->smallSetElementSetNames = NULL;
1792 else if (argc == -1)
1793 return ir_tcl_strdel (interp, &p->smallSetElementSetNames);
1796 xfree (p->smallSetElementSetNames);
1797 if (ir_tcl_strdup (interp, &p->smallSetElementSetNames,
1798 argv[2]) == TCL_ERROR)
1801 Tcl_AppendResult (interp, p->smallSetElementSetNames, NULL);
1806 * do_mediumSetElementSetNames: Set/Get medium Set Element Set Names
1808 static int do_mediumSetElementSetNames (void *obj, Tcl_Interp *interp,
1809 int argc, char **argv)
1811 IrTcl_SetCObj *p = obj;
1815 p->mediumSetElementSetNames = NULL;
1818 else if (argc == -1)
1819 return ir_tcl_strdel (interp, &p->mediumSetElementSetNames);
1822 xfree (p->mediumSetElementSetNames);
1823 if (ir_tcl_strdup (interp, &p->mediumSetElementSetNames,
1824 argv[2]) == TCL_ERROR)
1827 Tcl_AppendResult (interp, p->mediumSetElementSetNames, NULL);
1831 static IrTcl_Method ir_method_tab[] = {
1832 { "comstack", do_comstack, NULL },
1833 { "protocol", do_protocol, NULL },
1834 { "failback", do_failback, NULL },
1835 { "failInfo", do_failInfo, NULL },
1836 { "apduInfo", do_apduInfo, NULL },
1837 { "logLevel", do_logLevel, NULL },
1839 { "eventType", do_eventType, NULL },
1840 { "connect", do_connect, NULL },
1841 { "protocolVersion", do_protocolVersion, NULL },
1842 { "preferredMessageSize", do_preferredMessageSize, NULL },
1843 { "maximumRecordSize", do_maximumRecordSize, NULL },
1844 { "implementationName", do_implementationName, NULL },
1845 { "implementationId", do_implementationId, NULL },
1846 { "implementationVersion", do_implementationVersion, NULL },
1847 { "targetImplementationName", do_targetImplementationName, NULL },
1848 { "targetImplementationId", do_targetImplementationId, NULL },
1849 { "targetImplementationVersion", do_targetImplementationVersion, NULL},
1850 { "userInformationField", do_userInformationField, NULL},
1851 { "idAuthentication", do_idAuthentication, NULL},
1852 { "options", do_options, NULL},
1853 { "init", do_init_request, NULL},
1854 { "initResult", do_initResult, NULL},
1855 { "disconnect", do_disconnect, NULL},
1856 { "callback", do_callback, NULL},
1857 { "initResponse", do_initResponse, NULL},
1858 { "triggerResourceControl", do_triggerResourceControl, NULL},
1859 { "initResponse", do_initResponse, NULL},
1863 static IrTcl_Method ir_set_c_method_tab[] = {
1864 { "databaseNames", do_databaseNames, NULL},
1865 { "replaceIndicator", do_replaceIndicator, NULL},
1866 { "queryType", do_queryType, NULL},
1867 { "preferredRecordSyntax", do_preferredRecordSyntax, NULL},
1868 { "smallSetUpperBound", do_smallSetUpperBound, NULL},
1869 { "largeSetLowerBound", do_largeSetLowerBound, NULL},
1870 { "mediumSetPresentNumber", do_mediumSetPresentNumber, NULL},
1871 { "referenceId", do_referenceId, NULL},
1872 { "elementSetNames", do_elementSetNames, NULL},
1873 { "smallSetElementSetNames", do_smallSetElementSetNames, NULL},
1874 { "mediumSetElementSetNames", do_mediumSetElementSetNames, NULL},
1879 * ir_obj_method: IR Object methods
1881 static int ir_obj_method (ClientData clientData, Tcl_Interp *interp,
1882 int argc, char **argv)
1884 IrTcl_Methods tab[3];
1885 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
1890 Tcl_AppendResult (interp, wrongArgs, *argv, "method args...\"", NULL);
1894 tab[0].tab = ir_method_tab;
1896 tab[1].tab = ir_set_c_method_tab;
1897 tab[1].obj = &p->set_inher;
1900 if (ir_tcl_method (interp, argc, argv, tab, &r) == TCL_ERROR)
1901 return ir_tcl_method_error (interp, argc, argv, tab);
1906 * ir_obj_delete: IR Object disposal
1908 static void ir_obj_delete (ClientData clientData)
1910 IrTcl_Obj *obj = (IrTcl_Obj *) clientData;
1911 IrTcl_Methods tab[3];
1914 if (obj->ref_count > 0)
1916 assert (obj->ref_count == 0);
1918 logf (LOG_DEBUG, "ir object delete");
1919 tab[0].tab = ir_method_tab;
1921 tab[1].tab = ir_set_c_method_tab;
1922 tab[1].obj = &obj->set_inher;
1925 ir_tcl_method (NULL, -1, NULL, tab, NULL);
1928 odr_destroy (obj->odr_in);
1929 odr_destroy (obj->odr_out);
1930 odr_destroy (obj->odr_pr);
1935 * ir_obj_init: IR Object initialization
1937 int ir_obj_init (ClientData clientData, Tcl_Interp *interp,
1938 int argc, char **argv, ClientData *subData,
1939 ClientData parentData)
1941 IrTcl_Methods tab[3];
1949 Tcl_AppendResult (interp, wrongArgs, *argv, " objName\"", NULL);
1952 obj = ir_tcl_malloc (sizeof(*obj));
1955 obj->bibset = ccl_qual_mk ();
1956 if ((inf = fopen ("default.bib", "r")))
1958 ccl_qual_file (obj->bibset, inf);
1963 logf (LOG_DEBUG, "ir object create %s", argv[1]);
1964 obj->odr_in = odr_createmem (ODR_DECODE);
1965 odr_choice_enable_bias (obj->odr_in, 0);
1966 obj->odr_out = odr_createmem (ODR_ENCODE);
1967 obj->odr_pr = odr_createmem (ODR_PRINT);
1968 obj->state = IR_TCL_R_Idle;
1969 obj->interp = interp;
1973 obj->request_queue = NULL;
1975 tab[0].tab = ir_method_tab;
1977 tab[1].tab = ir_set_c_method_tab;
1978 tab[1].obj = &obj->set_inher;
1981 if (ir_tcl_method (interp, 0, NULL, tab, NULL) == TCL_ERROR)
1983 Tcl_AppendResult (interp, "Failed to initialize ", argv[1], NULL);
1986 *subData = (ClientData) obj;
1992 * ir_obj_mk: IR Object creation
1994 static int ir_obj_mk (ClientData clientData, Tcl_Interp *interp,
1995 int argc, char **argv)
1998 int r = ir_obj_init (clientData, interp, argc, argv, &subData, 0);
2002 Tcl_CreateCommand (interp, argv[1], ir_obj_method,
2003 subData, ir_obj_delete);
2007 IrTcl_Class ir_obj_class = {
2015 /* ------------------------------------------------------- */
2017 * do_search: Do search request
2019 static int do_search (void *o, Tcl_Interp *interp, int argc, char **argv)
2021 Z_SearchRequest *req;
2025 IrTcl_SetObj *obj = o;
2036 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1], "query\"",
2040 logf (LOG_DEBUG, "search %s %s", *argv, argv[2]);
2041 if (!obj->set_inher.num_databaseNames)
2043 Tcl_AppendResult (interp, "no databaseNames", NULL);
2044 return ir_tcl_error_exec (interp, argc, argv);
2048 Tcl_AppendResult (interp, "not connected", NULL);
2049 return ir_tcl_error_exec (interp, argc, argv);
2051 apdu = zget_APDU (p->odr_out, Z_APDU_searchRequest);
2052 req = apdu->u.searchRequest;
2056 set_referenceId (p->odr_out, &req->referenceId,
2057 obj->set_inher.referenceId);
2059 req->smallSetUpperBound = &obj->set_inher.smallSetUpperBound;
2060 req->largeSetLowerBound = &obj->set_inher.largeSetLowerBound;
2061 req->mediumSetPresentNumber = &obj->set_inher.mediumSetPresentNumber;
2062 req->replaceIndicator = &obj->set_inher.replaceIndicator;
2063 req->resultSetName = obj->setName ? obj->setName : "default";
2064 logf (LOG_DEBUG, "Search, resultSetName %s", req->resultSetName);
2065 req->num_databaseNames = obj->set_inher.num_databaseNames;
2066 req->databaseNames = obj->set_inher.databaseNames;
2067 for (r=0; r < obj->set_inher.num_databaseNames; r++)
2068 logf (LOG_DEBUG, " Database %s", obj->set_inher.databaseNames[r]);
2069 if (obj->set_inher.preferredRecordSyntax)
2071 struct oident ident;
2073 ident.proto = p->protocol_type;
2074 ident.oclass = CLASS_RECSYN;
2075 ident.value = *obj->set_inher.preferredRecordSyntax;
2076 logf (LOG_DEBUG, "Preferred record syntax is %d", ident.value);
2077 req->preferredRecordSyntax = odr_oiddup (p->odr_out,
2078 oid_getoidbyent (&ident));
2081 req->preferredRecordSyntax = 0;
2083 if (obj->set_inher.smallSetElementSetNames &&
2084 *obj->set_inher.smallSetElementSetNames)
2086 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2088 esn->which = Z_ElementSetNames_generic;
2089 esn->u.generic = obj->set_inher.smallSetElementSetNames;
2090 req->smallSetElementSetNames = esn;
2093 req->smallSetElementSetNames = NULL;
2095 if (obj->set_inher.mediumSetElementSetNames &&
2096 *obj->set_inher.mediumSetElementSetNames)
2098 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2100 esn->which = Z_ElementSetNames_generic;
2101 esn->u.generic = obj->set_inher.mediumSetElementSetNames;
2102 req->mediumSetElementSetNames = esn;
2105 req->mediumSetElementSetNames = NULL;
2107 req->query = &query;
2109 logf (LOG_DEBUG, "queryType %s", obj->set_inher.queryType);
2110 if (!strcmp (obj->set_inher.queryType, "rpn"))
2112 Z_RPNQuery *RPNquery;
2114 RPNquery = p_query_rpn (p->odr_out, p->protocol_type, argv[2]);
2117 Tcl_AppendResult (interp, "query syntax error", NULL);
2118 return ir_tcl_error_exec (interp, argc, argv);
2120 query.which = Z_Query_type_1;
2121 query.u.type_1 = RPNquery;
2124 else if (!strcmp (obj->set_inher.queryType, "cclrpn"))
2128 struct ccl_rpn_node *rpn;
2129 Z_RPNQuery *RPNquery;
2132 bib1.proto = p->protocol_type;
2133 bib1.oclass = CLASS_ATTSET;
2134 bib1.value = VAL_BIB1;
2136 rpn = ccl_find_str(p->bibset, argv[2], &error, &pos);
2139 Tcl_AppendResult (interp, "ccl syntax error ", ccl_err_msg(error),
2141 return ir_tcl_error_exec (interp, argc, argv);
2144 ccl_pr_tree (rpn, stderr);
2145 fprintf (stderr, "\n");
2147 assert((RPNquery = ccl_rpn_query(rpn)));
2148 RPNquery->attributeSetId = oid_getoidbyent (&bib1);
2149 query.which = Z_Query_type_1;
2150 query.u.type_1 = RPNquery;
2153 else if (!strcmp (obj->set_inher.queryType, "ccl"))
2155 query.which = Z_Query_type_2;
2156 query.u.type_2 = &ccl_query;
2157 ccl_query.buf = (unsigned char *) argv[2];
2158 ccl_query.len = strlen (argv[2]);
2162 Tcl_AppendResult (interp, "invalid query method ",
2163 obj->set_inher.queryType, NULL);
2164 return ir_tcl_error_exec (interp, argc, argv);
2166 return ir_tcl_send_APDU (interp, p, apdu, "search", *argv);
2170 * do_searchResponse: add search response handler
2172 static int do_searchResponse (void *o, Tcl_Interp *interp,
2173 int argc, char **argv)
2175 IrTcl_SetObj *obj = o;
2179 obj->searchResponse = NULL;
2182 else if (argc == -1)
2183 return ir_tcl_strdel (interp, &obj->searchResponse);
2186 xfree (obj->searchResponse);
2189 if (ir_tcl_strdup (interp, &obj->searchResponse, argv[2])
2194 obj->searchResponse = NULL;
2200 * do_presentResponse: add present response handler
2202 static int do_presentResponse (void *o, Tcl_Interp *interp,
2203 int argc, char **argv)
2205 IrTcl_SetObj *obj = o;
2209 obj->presentResponse = NULL;
2212 else if (argc == -1)
2213 return ir_tcl_strdel (interp, &obj->presentResponse);
2216 xfree (obj->presentResponse);
2219 if (ir_tcl_strdup (interp, &obj->presentResponse, argv[2])
2224 obj->presentResponse = NULL;
2230 * do_sortResponse: add sort response handler
2232 static int do_sortResponse (void *o, Tcl_Interp *interp,
2233 int argc, char **argv)
2235 IrTcl_SetObj *obj = o;
2239 obj->sortResponse = NULL;
2242 else if (argc == -1)
2243 return ir_tcl_strdel (interp, &obj->sortResponse);
2246 xfree (obj->sortResponse);
2249 if (ir_tcl_strdup (interp, &obj->sortResponse, argv[2])
2254 obj->sortResponse = NULL;
2260 * do_resultCount: Get number of hits
2262 static int do_resultCount (void *o, Tcl_Interp *interp,
2263 int argc, char **argv)
2265 IrTcl_SetObj *obj = o;
2269 obj->resultCount = 0;
2272 return ir_tcl_get_set_int (&obj->resultCount, interp, argc, argv);
2276 * do_searchStatus: Get search status (after search response)
2278 static int do_searchStatus (void *o, Tcl_Interp *interp,
2279 int argc, char **argv)
2281 IrTcl_SetObj *obj = o;
2285 return ir_tcl_get_set_int (&obj->searchStatus, interp, argc, argv);
2289 * do_presentStatus: Get search status (after search/present response)
2291 static int do_presentStatus (void *o, Tcl_Interp *interp,
2292 int argc, char **argv)
2294 IrTcl_SetObj *obj = o;
2298 return ir_tcl_get_set_int (&obj->presentStatus, interp, argc, argv);
2302 * do_sortStatus: Get sort status (after sort response)
2304 static int do_sortStatus (void *o, Tcl_Interp *interp,
2305 int argc, char **argv)
2307 IrTcl_SetObj *obj = o;
2312 obj->sortStatus = Z_SortStatus_failure;
2315 switch (obj->sortStatus)
2317 case Z_SortStatus_success:
2318 res = "success"; break;
2319 case Z_SortStatus_partial_1:
2320 res = "partial"; break;
2321 case Z_SortStatus_failure:
2322 res = "failure"; break;
2324 res = "unknown"; break;
2326 Tcl_AppendElement (interp, res);
2331 * do_nextResultSetPosition: Get next result set position
2332 * (after search/present response)
2334 static int do_nextResultSetPosition (void *o, Tcl_Interp *interp,
2335 int argc, char **argv)
2337 IrTcl_SetObj *obj = o;
2341 obj->nextResultSetPosition = 0;
2344 return ir_tcl_get_set_int (&obj->nextResultSetPosition, interp,
2349 * do_setName: Set result Set name
2351 static int do_setName (void *o, Tcl_Interp *interp,
2352 int argc, char **argv)
2354 IrTcl_SetObj *obj = o;
2357 return ir_tcl_strdup (interp, &obj->setName, "Default");
2358 else if (argc == -1)
2359 return ir_tcl_strdel (interp, &obj->setName);
2362 xfree (obj->setName);
2363 if (ir_tcl_strdup (interp, &obj->setName, argv[2])
2367 Tcl_AppendElement (interp, obj->setName);
2372 * do_numberOfRecordsReturned: Get number of records returned
2374 static int do_numberOfRecordsReturned (void *o, Tcl_Interp *interp,
2375 int argc, char **argv)
2377 IrTcl_SetObj *obj = o;
2381 obj->numberOfRecordsReturned = 0;
2384 return ir_tcl_get_set_int (&obj->numberOfRecordsReturned, interp,
2389 * do_type: Return type (if any) at position.
2391 static int do_type (void *o, Tcl_Interp *interp, int argc, char **argv)
2393 IrTcl_SetObj *obj = o;
2395 IrTcl_RecordList *rl;
2399 obj->record_list = NULL;
2402 else if (argc == -1)
2404 delete_IR_records (obj);
2409 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2410 " position\"", NULL);
2413 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2415 rl = find_IR_record (obj, offset);
2418 logf (LOG_DEBUG, "%s %s %s: no record", argv[0], argv[1], argv[2]);
2423 case Z_NamePlusRecord_databaseRecord:
2424 interp->result = "DB";
2426 case Z_NamePlusRecord_surrogateDiagnostic:
2427 interp->result = "SD";
2435 * do_recordType: Return record type (if any) at position.
2437 static int do_recordType (void *o, Tcl_Interp *interp, int argc, char **argv)
2439 IrTcl_SetObj *obj = o;
2441 IrTcl_RecordList *rl;
2447 else if (argc == -1)
2453 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2454 " position\"", NULL);
2457 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2459 rl = find_IR_record (obj, offset);
2462 logf (LOG_DEBUG, "%s %s %s: no record", argv[0], argv[1], argv[2]);
2465 if (rl->which != Z_NamePlusRecord_databaseRecord)
2467 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2470 Tcl_AppendElement (interp, (char*)
2471 IrTcl_getRecordSyntaxStr (rl->u.dbrec.type));
2476 * set record elements (for record extraction)
2478 static int do_recordElements (void *o, Tcl_Interp *interp,
2479 int argc, char **argv)
2481 IrTcl_SetObj *obj = o;
2485 obj->recordElements = NULL;
2488 else if (argc == -1)
2489 return ir_tcl_strdel (NULL, &obj->recordElements);
2492 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2493 " ?position?\"", NULL);
2498 xfree (obj->recordElements);
2499 return ir_tcl_strdup (NULL, &obj->recordElements,
2500 (*argv[2] ? argv[2] : NULL));
2502 Tcl_AppendResult (interp, obj->recordElements, NULL);
2509 static int ir_diagResult (Tcl_Interp *interp, IrTcl_Diagnostic *list, int num)
2515 for (i = 0; i<num; i++)
2517 sprintf (buf, "%d", list[i].condition);
2518 Tcl_AppendElement (interp, buf);
2519 cp = diagbib1_str (list[i].condition);
2521 Tcl_AppendElement (interp, (char*) cp);
2523 Tcl_AppendElement (interp, "");
2524 if (list[i].addinfo)
2525 Tcl_AppendElement (interp, (char*) list[i].addinfo);
2527 Tcl_AppendElement (interp, "");
2533 * do_diag: Return diagnostic record info
2535 static int do_diag (void *o, Tcl_Interp *interp, int argc, char **argv)
2537 IrTcl_SetObj *obj = o;
2539 IrTcl_RecordList *rl;
2545 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2546 " position\"", NULL);
2549 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2551 rl = find_IR_record (obj, offset);
2554 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2557 if (rl->which != Z_NamePlusRecord_surrogateDiagnostic)
2559 Tcl_AppendResult (interp, "No Diagnostic record at #", argv[2], NULL);
2562 return ir_diagResult (interp, rl->u.surrogateDiagnostics.list,
2563 rl->u.surrogateDiagnostics.num);
2567 * do_getMarc: Get ISO2709 Record lines/fields
2569 static int do_getMarc (void *o, Tcl_Interp *interp, int argc, char **argv)
2571 IrTcl_SetObj *obj = o;
2573 IrTcl_RecordList *rl;
2579 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2580 " position line|field tag ind field\"", NULL);
2583 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2585 rl = find_IR_record (obj, offset);
2588 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2591 if (rl->which != Z_NamePlusRecord_databaseRecord)
2593 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2596 return ir_tcl_get_marc (interp, rl->u.dbrec.buf, argc, argv);
2600 * do_getSutrs: Get SUTRS Record
2602 static int do_getSutrs (void *o, Tcl_Interp *interp, int argc, char **argv)
2604 IrTcl_SetObj *obj = o;
2606 IrTcl_RecordList *rl;
2612 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2613 " position\"", NULL);
2616 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2618 rl = find_IR_record (obj, offset);
2621 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2624 if (rl->which != Z_NamePlusRecord_databaseRecord)
2626 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2629 if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_SUTRS)
2631 Tcl_AppendElement (interp, rl->u.dbrec.buf);
2637 * do_getGrs: Get a GRS-1 Record
2639 static int do_getGrs (void *o, Tcl_Interp *interp, int argc, char **argv)
2641 IrTcl_SetObj *obj = o;
2643 IrTcl_RecordList *rl;
2649 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2650 " position ?(set,tag) (set,tag) ...?\"", NULL);
2653 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2655 rl = find_IR_record (obj, offset);
2658 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2661 if (rl->which != Z_NamePlusRecord_databaseRecord)
2663 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2666 if (rl->u.dbrec.type != VAL_GRS1)
2668 return ir_tcl_get_grs (interp, rl->u.dbrec.u.grs1, argc, argv);
2673 * do_getExplain: Get an Explain Record
2675 static int do_getExplain (void *o, Tcl_Interp *interp, int argc, char **argv)
2677 IrTcl_SetObj *obj = o;
2678 IrTcl_Obj *p = obj->parent;
2680 Z_ext_typeent *etype;
2682 IrTcl_RecordList *rl;
2688 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2689 " position ?mask? ...\"", NULL);
2692 if (Tcl_GetInt (interp, argv[2], &offset)==TCL_ERROR)
2694 rl = find_IR_record (obj, offset);
2697 Tcl_AppendResult (interp, "No record at #", argv[2], NULL);
2700 if (rl->which != Z_NamePlusRecord_databaseRecord)
2702 Tcl_AppendResult (interp, "No DB record at #", argv[2], NULL);
2705 if (!rl->u.dbrec.buf || rl->u.dbrec.type != VAL_EXPLAIN)
2708 if (!(etype = z_ext_getentbyref (VAL_EXPLAIN)))
2710 assert (rl->u.dbrec.buf);
2711 odr_setbuf (p->odr_in, rl->u.dbrec.buf, rl->u.dbrec.size, 0);
2712 if (!(*etype->fun)(p->odr_in, (char **) &rr, 0))
2715 if (etype->what != Z_External_explainRecord)
2718 return ir_tcl_get_explain (interp, rr, argc, argv);
2722 * do_responseStatus: Return response status (present or search)
2724 static int do_responseStatus (void *o, Tcl_Interp *interp,
2725 int argc, char **argv)
2727 IrTcl_SetObj *obj = o;
2731 obj->recordFlag = 0;
2732 obj->nonSurrogateDiagnosticNum = 0;
2733 obj->nonSurrogateDiagnosticList = NULL;
2736 else if (argc == -1)
2738 ir_deleteDiags (&obj->nonSurrogateDiagnosticList,
2739 &obj->nonSurrogateDiagnosticNum);
2742 if (!obj->recordFlag)
2744 Tcl_AppendElement (interp, "OK");
2749 case Z_Records_DBOSD:
2750 Tcl_AppendElement (interp, "DBOSD");
2753 Tcl_AppendElement (interp, "NSD");
2754 return ir_diagResult (interp, obj->nonSurrogateDiagnosticList,
2755 obj->nonSurrogateDiagnosticNum);
2761 * do_present: Perform Present Request
2764 static int do_present (void *o, Tcl_Interp *interp, int argc, char **argv)
2766 IrTcl_SetObj *obj = o;
2769 Z_PresentRequest *req;
2777 if (Tcl_GetInt (interp, argv[2], &start) == TCL_ERROR)
2784 if (Tcl_GetInt (interp, argv[3], &number) == TCL_ERROR)
2789 logf (LOG_DEBUG, "present %s %d %d", *argv, start, number);
2793 Tcl_AppendResult (interp, "not connected", NULL);
2794 return ir_tcl_error_exec (interp, argc, argv);
2797 obj->number = number;
2799 apdu = zget_APDU (p->odr_out, Z_APDU_presentRequest);
2800 req = apdu->u.presentRequest;
2802 set_referenceId (p->odr_out, &req->referenceId,
2803 obj->set_inher.referenceId);
2805 req->resultSetId = obj->setName ? obj->setName : "Default";
2807 req->resultSetStartPoint = &start;
2808 req->numberOfRecordsRequested = &number;
2809 if (obj->set_inher.preferredRecordSyntax)
2811 struct oident ident;
2813 ident.proto = p->protocol_type;
2814 ident.oclass = CLASS_RECSYN;
2815 ident.value = *obj->set_inher.preferredRecordSyntax;
2816 logf (LOG_DEBUG, "Preferred record syntax is %d", ident.value);
2817 req->preferredRecordSyntax = odr_oiddup (p->odr_out,
2818 oid_getoidbyent (&ident));
2821 req->preferredRecordSyntax = 0;
2823 if (obj->set_inher.elementSetNames && *obj->set_inher.elementSetNames)
2825 Z_ElementSetNames *esn = odr_malloc (p->odr_out, sizeof(*esn));
2826 Z_RecordComposition *compo = odr_malloc (p->odr_out, sizeof(*compo));
2828 esn->which = Z_ElementSetNames_generic;
2829 esn->u.generic = obj->set_inher.elementSetNames;
2831 req->recordComposition = compo;
2832 compo->which = Z_RecordComp_simple;
2833 compo->u.simple = esn;
2836 req->recordComposition = NULL;
2837 return ir_tcl_send_APDU (interp, p, apdu, "present", *argv);
2840 #define IR_TCL_RECORD_ENCODING_ISO2709 1
2841 #define IR_TCL_RECORD_ENCODING_RAW 2
2847 } IrTcl_FileRecordHead;
2850 * do_loadFile: Load result set from file
2852 static int do_loadFile (void *o, Tcl_Interp *interp,
2853 int argc, char **argv)
2855 IrTcl_SetObj *setobj = o;
2867 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2868 " filename ?start? ?number?\"", NULL);
2872 start = atoi (argv[3]);
2874 number = atoi (argv[4]);
2877 inf = fopen (argv[2], "r");
2880 Tcl_AppendResult (interp, "Cannot open ", argv[2], NULL);
2881 return ir_tcl_error_exec (interp, argc, argv);
2883 while (offset < (start+number))
2885 IrTcl_FileRecordHead head;
2886 IrTcl_RecordList *rl;
2888 if (fread (&head, sizeof(head), 1, inf) < 1)
2890 rl = new_IR_record (setobj, offset,
2891 Z_NamePlusRecord_databaseRecord,
2892 (argc > 5) ? argv[5] : NULL);
2893 rl->u.dbrec.type = head.syntax;
2894 if (head.encoding == IR_TCL_RECORD_ENCODING_ISO2709)
2896 if (!(buf = ir_tcl_fread_marc (inf, &size)))
2898 rl->u.dbrec.buf = buf;
2899 rl->u.dbrec.size = size;
2900 if (size != head.size)
2903 Tcl_AppendResult (interp, "bad ISO2709 encoding", NULL);
2904 return ir_tcl_error_exec (interp, argc, argv);
2907 else if (head.encoding == IR_TCL_RECORD_ENCODING_RAW)
2909 rl->u.dbrec.size = head.size;
2910 rl->u.dbrec.buf = ir_tcl_malloc (head.size + 1);
2911 if (fread (rl->u.dbrec.buf, rl->u.dbrec.size, 1, inf) < 1)
2914 Tcl_AppendResult (interp, "bad raw encoding", NULL);
2915 return ir_tcl_error_exec (interp, argc, argv);
2917 rl->u.dbrec.buf[rl->u.dbrec.size] = '\0';
2921 rl->u.dbrec.buf = NULL;
2922 rl->u.dbrec.size = 0;
2924 Tcl_AppendResult (interp, "bad encoding", NULL);
2925 return ir_tcl_error_exec (interp, argc, argv);
2929 setobj->numberOfRecordsReturned = offset - start;
2935 * do_saveFile: Save result set on file
2937 static int do_saveFile (void *o, Tcl_Interp *interp,
2938 int argc, char **argv)
2940 IrTcl_SetObj *setobj = o;
2945 IrTcl_RecordList *rl;
2951 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
2952 " filename ?start? ?number?\"", NULL);
2956 start = atoi (argv[3]);
2958 number = atoi (argv[4]);
2961 outf = fopen (argv[2], "w");
2964 Tcl_AppendResult (interp, "cannot open file", NULL);
2965 return ir_tcl_error_exec (interp, argc, argv);
2967 while (offset < (start+number) && (rl = find_IR_record (setobj, offset)))
2969 if (rl->which == Z_NamePlusRecord_databaseRecord &&
2970 rl->u.dbrec.buf && rl->u.dbrec.size)
2972 IrTcl_FileRecordHead head;
2974 head.encoding = IR_TCL_RECORD_ENCODING_RAW;
2975 head.syntax = rl->u.dbrec.type;
2976 head.size = rl->u.dbrec.size;
2977 if (fwrite (&head, sizeof(head), 1, outf) < 1)
2979 Tcl_AppendResult (interp, "cannot write", NULL);
2980 return ir_tcl_error_exec (interp, argc, argv);
2982 if (fwrite (rl->u.dbrec.buf, rl->u.dbrec.size, 1, outf) < 1)
2984 Tcl_AppendResult (interp, "cannot write", NULL);
2985 return ir_tcl_error_exec (interp, argc, argv);
2992 Tcl_AppendResult (interp, "cannot write ", NULL);
2993 return ir_tcl_error_exec (interp, argc, argv);
2999 /* ------------------------------------------------------- */
3001 * do_sort: Do sort request
3003 static int do_sort (void *o, Tcl_Interp *interp, int argc, char **argv)
3007 IrTcl_SetObj *obj = o;
3009 char sort_string[64], sort_flags[64];
3012 Z_SortKeySpecList *sksl;
3023 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1], "query\"",
3027 logf (LOG_DEBUG, "sort %s %s", *argv, argv[2]);
3030 Tcl_AppendResult (interp, "not connected", NULL);
3031 return ir_tcl_error_exec (interp, argc, argv);
3033 apdu = zget_APDU (p->odr_out, Z_APDU_sortRequest);
3034 sksl = (Z_SortKeySpecList *) odr_malloc (p->odr_out, sizeof(*sksl));
3035 req = apdu->u.sortRequest;
3037 set_referenceId (p->odr_out, &req->referenceId,
3038 obj->set_inher.referenceId);
3041 req->num_inputResultSetNames = 1;
3042 req->inputResultSetNames = (Z_InternationalString **)
3043 odr_malloc (out, sizeof(*req->inputResultSetNames));
3044 req->inputResultSetNames[0] = obj->setName;
3046 req->inputResultSetNames =
3047 (Z_StringList *)odr_malloc (p->odr_out,
3048 sizeof(*req->inputResultSetNames));
3049 req->inputResultSetNames->num_strings = 1;
3050 req->inputResultSetNames->strings =
3051 (char **)odr_malloc (p->odr_out,
3052 sizeof(*req->inputResultSetNames->strings));
3053 req->inputResultSetNames->strings[0] = obj->setName;
3056 req->sortedResultSetName = (char *) obj->setName;
3059 req->sortSequence = sksl;
3060 sksl->num_specs = 0;
3061 sksl->specs = (Z_SortKeySpec **)
3062 odr_malloc (p->odr_out, sizeof(sksl->specs) * 20);
3064 bib1.proto = PROTO_Z3950;
3065 bib1.oclass = CLASS_ATTSET;
3066 bib1.value = VAL_BIB1;
3068 while ((sscanf (arg, "%63s %63s%n", sort_string, sort_flags, &off)) == 2
3072 char *sort_string_sep;
3073 Z_SortKeySpec *sks = (Z_SortKeySpec *)
3074 odr_malloc (p->odr_out, sizeof(*sks));
3075 Z_SortKey *sk = (Z_SortKey *)
3076 odr_malloc (p->odr_out, sizeof(*sk));
3079 sksl->specs[sksl->num_specs++] = sks;
3080 sks->sortElement = (Z_SortElement *)
3081 odr_malloc (p->odr_out, sizeof(*sks->sortElement));
3082 sks->sortElement->which = Z_SortElement_generic;
3083 sks->sortElement->u.generic = sk;
3085 if ((sort_string_sep = strchr (sort_string, '=')))
3087 Z_AttributeElement *el = (Z_AttributeElement *)
3088 odr_malloc (p->odr_out, sizeof(*el));
3089 sk->which = Z_SortKey_sortAttributes;
3090 sk->u.sortAttributes =
3091 (Z_SortAttributes *)
3092 odr_malloc (p->odr_out, sizeof(*sk->u.sortAttributes));
3093 sk->u.sortAttributes->id = oid_ent_to_oid(&bib1, oid);
3094 sk->u.sortAttributes->list =
3096 odr_malloc (p->odr_out, sizeof(*sk->u.sortAttributes->list));
3097 sk->u.sortAttributes->list->num_attributes = 1;
3098 sk->u.sortAttributes->list->attributes =
3099 (Z_AttributeElement **)odr_malloc (p->odr_out,
3100 sizeof(*sk->u.sortAttributes->list->attributes));
3101 sk->u.sortAttributes->list->attributes[0] = el;
3102 el->attributeSet = 0;
3103 el->attributeType = (int *)
3104 odr_malloc (p->odr_out, sizeof(*el->attributeType));
3105 *el->attributeType = atoi (sort_string);
3106 el->which = Z_AttributeValue_numeric;
3107 el->value.numeric = (int *)
3108 odr_malloc (p->odr_out, sizeof(*el->value.numeric));
3109 *el->value.numeric = atoi (sort_string_sep + 1);
3113 sk->which = Z_SortKey_sortField;
3114 sk->u.sortField = (char *)odr_malloc (p->odr_out, strlen(sort_string)+1);
3115 strcpy (sk->u.sortField, sort_string);
3117 sks->sortRelation = (int *)
3118 odr_malloc (p->odr_out, sizeof(*sks->sortRelation));
3119 *sks->sortRelation = Z_SortRelation_ascending;
3120 sks->caseSensitivity = (int *)
3121 odr_malloc (p->odr_out, sizeof(*sks->caseSensitivity));
3122 *sks->caseSensitivity = Z_SortCase_caseSensitive;
3125 sks->which = Z_SortKeySpec_null;
3126 sks->u.null = odr_nullval ();
3128 sks->missingValueAction = NULL;
3131 for (i = 0; sort_flags[i]; i++)
3133 switch (sort_flags[i])
3138 *sks->sortRelation = Z_SortRelation_descending;
3143 *sks->sortRelation = Z_SortRelation_ascending;
3147 *sks->caseSensitivity = Z_SortCase_caseInsensitive;
3151 *sks->caseSensitivity = Z_SortCase_caseSensitive;
3156 if (!sksl->num_specs)
3158 printf ("Missing sort specifications\n");
3161 return ir_tcl_send_APDU (interp, p, apdu, "sort", *argv);
3164 static IrTcl_Method ir_set_method_tab[] = {
3165 { "search", do_search, NULL},
3166 { "searchResponse", do_searchResponse, NULL},
3167 { "presentResponse", do_presentResponse, NULL},
3168 { "searchStatus", do_searchStatus, NULL},
3169 { "presentStatus", do_presentStatus, NULL},
3170 { "nextResultSetPosition", do_nextResultSetPosition, NULL},
3171 { "setName", do_setName, NULL},
3172 { "resultCount", do_resultCount, NULL},
3173 { "numberOfRecordsReturned", do_numberOfRecordsReturned, NULL},
3174 { "present", do_present, NULL},
3175 { "type", do_type, NULL},
3176 { "getMarc", do_getMarc, NULL},
3177 { "getSutrs", do_getSutrs, NULL},
3178 { "getGrs", do_getGrs, NULL},
3179 { "getExplain", do_getExplain, NULL},
3180 { "recordType", do_recordType, NULL},
3181 { "recordElements", do_recordElements, NULL},
3182 { "diag", do_diag, NULL},
3183 { "responseStatus", do_responseStatus, NULL},
3184 { "loadFile", do_loadFile, NULL},
3185 { "saveFile", do_saveFile, NULL},
3186 { "sort", do_sort, NULL },
3187 { "sortResponse", do_sortResponse, NULL},
3188 { "sortStatus", do_sortStatus, NULL},
3193 * ir_set_obj_method: IR Set Object methods
3195 static int ir_set_obj_method (ClientData clientData, Tcl_Interp *interp,
3196 int argc, char **argv)
3198 IrTcl_Methods tabs[3];
3199 IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
3204 Tcl_AppendResult (interp, wrongArgs, *argv, " method args...\"", NULL);
3207 tabs[0].tab = ir_set_method_tab;
3209 tabs[1].tab = ir_set_c_method_tab;
3210 tabs[1].obj = &p->set_inher;
3213 if (ir_tcl_method (interp, argc, argv, tabs, &r) == TCL_ERROR)
3214 return ir_tcl_method_error (interp, argc, argv, tabs);
3219 * ir_set_obj_delete: IR Set Object disposal
3221 static void ir_set_obj_delete (ClientData clientData)
3223 IrTcl_Methods tabs[3];
3224 IrTcl_SetObj *p = (IrTcl_SetObj *) clientData;
3226 logf (LOG_DEBUG, "ir set delete");
3228 tabs[0].tab = ir_set_method_tab;
3230 tabs[1].tab = ir_set_c_method_tab;
3231 tabs[1].obj = &p->set_inher;
3234 ir_tcl_method (NULL, -1, NULL, tabs, NULL);
3240 * ir_set_obj_init: IR Set Object initialization
3242 static int ir_set_obj_init (ClientData clientData, Tcl_Interp *interp,
3243 int argc, char **argv, ClientData *subData,
3244 ClientData parentData)
3246 IrTcl_Methods tabs[3];
3249 if (argc < 2 || argc > 3)
3251 Tcl_AppendResult (interp, wrongArgs, *argv,
3252 " objSetName ?objParent?\"", NULL);
3255 obj = ir_tcl_malloc (sizeof(*obj));
3256 logf (LOG_DEBUG, "ir set create %s", argv[1]);
3263 obj->parent = (IrTcl_Obj *) parentData;
3265 dst = &obj->set_inher;
3266 src = &obj->parent->set_inher;
3268 if ((dst->num_databaseNames = src->num_databaseNames))
3270 dst->databaseNames =
3271 ir_tcl_malloc (sizeof (*dst->databaseNames)
3272 * (1+dst->num_databaseNames));
3273 for (i = 0; i < dst->num_databaseNames; i++)
3274 if (ir_tcl_strdup (interp, &dst->databaseNames[i],
3275 src->databaseNames[i]) == TCL_ERROR)
3277 dst->databaseNames[i] = NULL;
3280 dst->databaseNames = NULL;
3281 if (ir_tcl_strdup (interp, &dst->queryType, src->queryType)
3285 if (ir_tcl_strdup (interp, &dst->referenceId, src->referenceId)
3289 if (ir_tcl_strdup (interp, &dst->elementSetNames, src->elementSetNames)
3293 if (ir_tcl_strdup (interp, &dst->smallSetElementSetNames,
3294 src->smallSetElementSetNames)
3298 if (ir_tcl_strdup (interp, &dst->mediumSetElementSetNames,
3299 src->mediumSetElementSetNames)
3303 if (src->preferredRecordSyntax &&
3304 (dst->preferredRecordSyntax
3305 = ir_tcl_malloc (sizeof(*dst->preferredRecordSyntax))))
3306 *dst->preferredRecordSyntax = *src->preferredRecordSyntax;
3308 dst->preferredRecordSyntax = NULL;
3309 dst->replaceIndicator = src->replaceIndicator;
3310 dst->smallSetUpperBound = src->smallSetUpperBound;
3311 dst->largeSetLowerBound = src->largeSetLowerBound;
3312 dst->mediumSetPresentNumber = src->mediumSetPresentNumber;
3317 tabs[0].tab = ir_set_method_tab;
3321 if (ir_tcl_method (interp, 0, NULL, tabs, NULL) == TCL_ERROR)
3324 *subData = (ClientData) obj;
3329 * ir_set_obj_mk: IR Set Object creation
3331 static int ir_set_obj_mk (ClientData clientData, Tcl_Interp *interp,
3332 int argc, char **argv)
3335 ClientData parentData = 0;
3340 Tcl_CmdInfo parent_info;
3341 if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
3343 Tcl_AppendResult (interp, "no object parent", NULL);
3344 return ir_tcl_error_exec (interp, argc, argv);
3346 parentData = parent_info.clientData;
3348 r = ir_set_obj_init (clientData, interp, argc, argv, &subData, parentData);
3351 Tcl_CreateCommand (interp, argv[1], ir_set_obj_method,
3352 subData, ir_set_obj_delete);
3356 IrTcl_Class ir_set_obj_class = {
3363 /* ------------------------------------------------------- */
3366 * do_scan: Perform scan
3368 static int do_scan (void *o, Tcl_Interp *interp, int argc, char **argv)
3372 IrTcl_ScanObj *obj = o;
3373 IrTcl_Obj *p = obj->parent;
3376 struct ccl_rpn_node *rpn;
3384 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
3385 " scanQuery\"", NULL);
3388 logf (LOG_DEBUG, "scan %s %s", *argv, argv[2]);
3389 if (!p->set_inher.num_databaseNames)
3391 Tcl_AppendResult (interp, "no databaseNames", NULL);
3392 return ir_tcl_error_exec (interp, argc, argv);
3396 Tcl_AppendResult (interp, "not connected", NULL);
3397 return ir_tcl_error_exec (interp, argc, argv);
3400 apdu = zget_APDU (p->odr_out, Z_APDU_scanRequest);
3401 req = apdu->u.scanRequest;
3403 set_referenceId (p->odr_out, &req->referenceId, p->set_inher.referenceId);
3404 req->num_databaseNames = p->set_inher.num_databaseNames;
3405 req->databaseNames = p->set_inher.databaseNames;
3408 if (!(req->termListAndStartPoint =
3409 p_query_scan (p->odr_out, p->protocol_type,
3410 &req->attributeSet, argv[2])))
3412 Tcl_AppendResult (interp, "query syntax error", NULL);
3413 return ir_tcl_error_exec (interp, argc, argv);
3416 rpn = ccl_find_str(p->bibset, argv[2], &r, &pos);
3419 Tcl_AppendResult (interp, "ccl syntax error ", ccl_err_msg(r), NULL);
3420 return ir_tcl_error_exec (interp, argc, argv);
3422 bib1.proto = p->protocol_type;
3423 bib1.oclass = CLASS_ATTSET;
3424 bib1.value = VAL_BIB1;
3426 req->attributeSet = oid_getoidbyent (&bib1);
3427 if (!(req->termListAndStartPoint = ccl_scan_query (rpn)))
3430 req->stepSize = &obj->stepSize;
3431 req->numberOfTermsRequested = &obj->numberOfTermsRequested;
3432 req->preferredPositionInResponse = &obj->preferredPositionInResponse;
3433 logf (LOG_DEBUG, "stepSize=%d", *req->stepSize);
3434 logf (LOG_DEBUG, "numberOfTermsRequested=%d",
3435 *req->numberOfTermsRequested);
3436 logf (LOG_DEBUG, "preferredPositionInResponse=%d",
3437 *req->preferredPositionInResponse);
3439 return ir_tcl_send_APDU (interp, p, apdu, "scan", *argv);
3443 * do_scanResponse: add scan response handler
3445 static int do_scanResponse (void *o, Tcl_Interp *interp,
3446 int argc, char **argv)
3448 IrTcl_ScanObj *obj = o;
3452 obj->scanResponse = NULL;
3455 else if (argc == -1)
3456 return ir_tcl_strdel (interp, &obj->scanResponse);
3459 xfree (obj->scanResponse);
3462 if (ir_tcl_strdup (interp, &obj->scanResponse, argv[2])
3467 obj->scanResponse = NULL;
3473 * do_stepSize: Set/get replace Step Size
3475 static int do_stepSize (void *obj, Tcl_Interp *interp,
3476 int argc, char **argv)
3478 IrTcl_ScanObj *p = obj;
3484 return ir_tcl_get_set_int (&p->stepSize, interp, argc, argv);
3488 * do_numberOfTermsRequested: Set/get Number of Terms requested
3490 static int do_numberOfTermsRequested (void *obj, Tcl_Interp *interp,
3491 int argc, char **argv)
3493 IrTcl_ScanObj *p = obj;
3497 p->numberOfTermsRequested = 20;
3500 return ir_tcl_get_set_int (&p->numberOfTermsRequested, interp, argc, argv);
3505 * do_preferredPositionInResponse: Set/get preferred Position
3507 static int do_preferredPositionInResponse (void *obj, Tcl_Interp *interp,
3508 int argc, char **argv)
3510 IrTcl_ScanObj *p = obj;
3514 p->preferredPositionInResponse = 1;
3517 return ir_tcl_get_set_int (&p->preferredPositionInResponse, interp,
3522 * do_scanStatus: Get scan status
3524 static int do_scanStatus (void *obj, Tcl_Interp *interp,
3525 int argc, char **argv)
3527 IrTcl_ScanObj *p = obj;
3531 return ir_tcl_get_set_int (&p->scanStatus, interp, argc, argv);
3535 * do_numberOfEntriesReturned: Get number of Entries returned
3537 static int do_numberOfEntriesReturned (void *obj, Tcl_Interp *interp,
3538 int argc, char **argv)
3540 IrTcl_ScanObj *p = obj;
3544 return ir_tcl_get_set_int (&p->numberOfEntriesReturned, interp,
3549 * do_positionOfTerm: Get position of Term
3551 static int do_positionOfTerm (void *obj, Tcl_Interp *interp,
3552 int argc, char **argv)
3554 IrTcl_ScanObj *p = obj;
3558 return ir_tcl_get_set_int (&p->positionOfTerm, interp, argc, argv);
3562 * do_scanLine: get Scan Line (surrogate or normal) after response
3564 static int do_scanLine (void *obj, Tcl_Interp *interp, int argc, char **argv)
3566 IrTcl_ScanObj *p = obj;
3572 p->entries_flag = 0;
3574 p->nonSurrogateDiagnosticNum = 0;
3575 p->nonSurrogateDiagnosticList = 0;
3578 else if (argc == -1)
3580 p->entries_flag = 0;
3581 /* release entries */
3584 ir_deleteDiags (&p->nonSurrogateDiagnosticList,
3585 &p->nonSurrogateDiagnosticNum);
3590 Tcl_AppendResult (interp, wrongArgs, *argv, " ", argv[1],
3591 " position\"", NULL);
3594 if (Tcl_GetInt (interp, argv[2], &i) == TCL_ERROR)
3596 if (!p->entries_flag || !p->entries || i >= p->num_entries || i < 0)
3598 switch (p->entries[i].which)
3600 case Z_Entry_termInfo:
3601 Tcl_AppendElement (interp, "T");
3602 if (p->entries[i].u.term.buf)
3603 Tcl_AppendElement (interp, p->entries[i].u.term.buf);
3605 Tcl_AppendElement (interp, "");
3606 sprintf (numstr, "%d", p->entries[i].u.term.globalOccurrences);
3607 Tcl_AppendElement (interp, numstr);
3609 case Z_Entry_surrogateDiagnostic:
3610 Tcl_AppendElement (interp, "SD");
3611 return ir_diagResult (interp, p->entries[i].u.diag.list,
3612 p->entries[i].u.diag.num);
3618 static IrTcl_Method ir_scan_method_tab[] = {
3619 { "scan", do_scan, NULL},
3620 { "scanResponse", do_scanResponse, NULL},
3621 { "stepSize", do_stepSize, NULL},
3622 { "numberOfTermsRequested", do_numberOfTermsRequested, NULL},
3623 { "preferredPositionInResponse", do_preferredPositionInResponse, NULL},
3624 { "scanStatus", do_scanStatus, NULL},
3625 { "numberOfEntriesReturned", do_numberOfEntriesReturned, NULL},
3626 { "positionOfTerm", do_positionOfTerm, NULL},
3627 { "scanLine", do_scanLine, NULL},
3632 * ir_scan_obj_method: IR Scan Object methods
3634 static int ir_scan_obj_method (ClientData clientData, Tcl_Interp *interp,
3635 int argc, char **argv)
3637 IrTcl_Methods tabs[2];
3642 Tcl_AppendResult (interp, wrongArgs, *argv, " method args...\"", NULL);
3645 tabs[0].tab = ir_scan_method_tab;
3646 tabs[0].obj = clientData;
3649 if (ir_tcl_method (interp, argc, argv, tabs, &r) == TCL_ERROR)
3650 return ir_tcl_method_error (interp, argc, argv, tabs);
3655 * ir_scan_obj_delete: IR Scan Object disposal
3657 static void ir_scan_obj_delete (ClientData clientData)
3659 IrTcl_Methods tabs[2];
3660 IrTcl_ScanObj *obj = (IrTcl_ScanObj *) clientData;
3662 tabs[0].tab = ir_scan_method_tab;
3666 ir_tcl_method (NULL, -1, NULL, tabs, NULL);
3671 * ir_scan_obj_mk: IR Scan Object creation
3673 static int ir_scan_obj_mk (ClientData clientData, Tcl_Interp *interp,
3674 int argc, char **argv)
3676 Tcl_CmdInfo parent_info;
3678 IrTcl_Methods tabs[2];
3682 Tcl_AppendResult (interp, wrongArgs, *argv,
3683 "objScanName objParentName\"", NULL);
3686 logf (LOG_DEBUG, "ir scan create %s", argv[1]);
3687 if (!Tcl_GetCommandInfo (interp, argv[2], &parent_info))
3689 Tcl_AppendResult (interp, "no object parent", NULL);
3690 return ir_tcl_error_exec (interp, argc, argv);
3692 obj = ir_tcl_malloc (sizeof(*obj));
3693 obj->parent = (IrTcl_Obj *) parent_info.clientData;
3695 tabs[0].tab = ir_scan_method_tab;
3699 if (ir_tcl_method (interp, 0, NULL, tabs, NULL) == TCL_ERROR)
3701 Tcl_CreateCommand (interp, argv[1], ir_scan_obj_method,
3702 (ClientData) obj, ir_scan_obj_delete);
3706 /* ------------------------------------------------------- */
3709 * ir_log_init_proc: set yaz log level
3711 static int ir_log_init_proc (ClientData clientData, Tcl_Interp *interp,
3712 int argc, char **argv)
3714 if (argc <= 1 || argc > 4)
3716 Tcl_AppendResult (interp, wrongArgs, *argv,
3717 " ?level ?prefix ?filename\"", NULL);
3721 log_init (log_mask_str (argv[1]), "", NULL);
3723 log_init (log_mask_str (argv[1]), argv[2], NULL);
3725 log_init (log_mask_str (argv[1]), argv[2], argv[3]);
3730 * ir_log_proc: log yaz message
3732 static int ir_log_proc (ClientData clientData, Tcl_Interp *interp,
3733 int argc, char **argv)
3738 Tcl_AppendResult (interp, wrongArgs, *argv,
3739 " level string\"", NULL);
3742 mask = log_mask_str_x (argv[1], 0);
3743 logf (LOG_DEBUG, "%s", argv[2]);
3749 * ir_version: log ir version
3751 static int ir_version (ClientData clientData, Tcl_Interp *interp,
3752 int argc, char **argv)
3754 Tcl_AppendElement (interp, IR_TCL_VERSION);
3755 Tcl_AppendElement (interp, YAZ_VERSION);
3760 /* ------------------------------------------------------- */
3761 static void ir_initResponse (void *obj, Z_InitResponse *initrs)
3765 p->initResult = *initrs->result ? 1 : 0;
3766 if (!*initrs->result)
3767 logf (LOG_DEBUG, "Connection rejected by target");
3769 logf (LOG_DEBUG, "Connection accepted by target");
3771 get_referenceId (&p->set_inher.referenceId, initrs->referenceId);
3773 xfree (p->targetImplementationId);
3774 ir_tcl_strdup (p->interp, &p->targetImplementationId,
3775 initrs->implementationId);
3776 xfree (p->targetImplementationName);
3777 ir_tcl_strdup (p->interp, &p->targetImplementationName,
3778 initrs->implementationName);
3779 xfree (p->targetImplementationVersion);
3780 ir_tcl_strdup (p->interp, &p->targetImplementationVersion,
3781 initrs->implementationVersion);
3783 p->maximumRecordSize = *initrs->maximumRecordSize;
3784 p->preferredMessageSize = *initrs->preferredMessageSize;
3786 memcpy (&p->options, initrs->options, sizeof(initrs->options));
3787 memcpy (&p->protocolVersion, initrs->protocolVersion,
3788 sizeof(initrs->protocolVersion));
3789 xfree (p->userInformationField);
3790 p->userInformationField = NULL;
3791 if (initrs->userInformationField)
3795 if (initrs->userInformationField->which == ODR_EXTERNAL_octet &&
3796 (p->userInformationField =
3797 ir_tcl_malloc ((len =
3798 initrs->userInformationField->
3799 u.octet_aligned->len) +1)))
3801 memcpy (p->userInformationField,
3802 initrs->userInformationField->u.octet_aligned->buf,
3804 (p->userInformationField)[len] = '\0';
3809 static void ir_deleteDiags (IrTcl_Diagnostic **dst_list, int *dst_num)
3812 for (i = 0; i<*dst_num; i++)
3813 xfree (dst_list[i]->addinfo);
3819 static void ir_handleDiags (IrTcl_Diagnostic **dst_list, int *dst_num,
3820 Z_DiagRec **list, int num)
3823 char *addinfo = NULL;
3826 *dst_list = ir_tcl_malloc (sizeof(**dst_list) * num);
3827 for (i = 0; i<num; i++)
3830 switch (list[i]->which)
3832 case Z_DiagRec_defaultFormat:
3833 (*dst_list)[i].condition = *list[i]->u.defaultFormat->condition;
3835 switch (list[i]->u.defaultFormat->which)
3837 case Z_DefaultDiagFormat_v2Addinfo:
3838 addinfo = list[i]->u.defaultFormat->u.v2Addinfo;
3840 case Z_DefaultDiagFormat_v3Addinfo:
3841 addinfo = list[i]->u.defaultFormat->u.v3Addinfo;
3845 addinfo = list[i]->u.defaultFormat->addinfo;
3848 ((*dst_list)[i].addinfo = ir_tcl_malloc (strlen(addinfo)+1)))
3849 strcpy ((*dst_list)[i].addinfo, addinfo);
3850 cp = diagbib1_str ((*dst_list)[i].condition);
3851 logf (LOG_DEBUG, "Diag %d %s %s", (*dst_list)[i].condition,
3852 cp ? cp : "", addinfo ? addinfo : "");
3855 (*dst_list)[i].addinfo = NULL;
3856 (*dst_list)[i].condition = 0;
3861 static void ir_handleDBRecord (IrTcl_Obj *p, IrTcl_RecordList *rl,
3864 struct oident *ident;
3865 Z_ext_typeent *etype;
3867 logf (LOG_DEBUG, "handleDBRecord size=%d", oe->u.octet_aligned->len);
3868 rl->u.dbrec.size = oe->u.octet_aligned->len;
3869 rl->u.dbrec.buf = NULL;
3871 if ((ident = oid_getentbyoid (oe->direct_reference)))
3872 rl->u.dbrec.type = ident->value;
3874 rl->u.dbrec.type = VAL_USMARC;
3876 if (ident && (oe->which == Z_External_single ||
3877 oe->which == Z_External_octet)
3878 && (etype = z_ext_getentbyref (ident->value)))
3882 odr_setbuf (p->odr_in, (char*) oe->u.octet_aligned->buf,
3883 oe->u.octet_aligned->len, 0);
3884 if (!(*etype->fun)(p->odr_in, (char **) &rr, 0))
3886 rl->u.dbrec.type = VAL_NONE;
3889 switch (etype->what)
3891 case Z_External_sutrs:
3892 logf (LOG_DEBUG, "Z_External_sutrs");
3894 if ((rl->u.dbrec.buf = ir_tcl_malloc (oe->u.sutrs->len+1)))
3896 memcpy (rl->u.dbrec.buf, oe->u.sutrs->buf,
3898 rl->u.dbrec.buf[oe->u.sutrs->len] = '\0';
3900 rl->u.dbrec.size = oe->u.sutrs->len;
3902 case Z_External_grs1:
3903 logf (LOG_DEBUG, "Z_External_grs1");
3905 ir_tcl_grs_mk (oe->u.grs1, &rl->u.dbrec.u.grs1);
3907 case Z_External_explainRecord:
3908 logf (LOG_DEBUG, "Z_External_explainRecord");
3909 if ((rl->u.dbrec.buf = ir_tcl_malloc (rl->u.dbrec.size)))
3911 memcpy (rl->u.dbrec.buf, oe->u.octet_aligned->buf,
3919 if (oe->which == Z_External_octet && rl->u.dbrec.size > 0)
3921 char *buf = (char*) oe->u.octet_aligned->buf;
3922 if ((rl->u.dbrec.buf = ir_tcl_malloc (rl->u.dbrec.size)))
3923 memcpy (rl->u.dbrec.buf, buf, rl->u.dbrec.size);
3925 else if (rl->u.dbrec.type == VAL_SUTRS &&
3926 oe->which == Z_External_sutrs)
3928 if ((rl->u.dbrec.buf = ir_tcl_malloc (oe->u.sutrs->len+1)))
3930 memcpy (rl->u.dbrec.buf, oe->u.sutrs->buf,
3932 rl->u.dbrec.buf[oe->u.sutrs->len] = '\0';
3934 rl->u.dbrec.size = oe->u.sutrs->len;
3936 else if (rl->u.dbrec.type == VAL_GRS1 &&
3937 oe->which == Z_External_grs1)
3939 ir_tcl_grs_mk (oe->u.grs1, &rl->u.dbrec.u.grs1);
3944 static void ir_handleZRecords (void *o, Z_Records *zrs, IrTcl_SetObj *setobj,
3945 const char *elements)
3950 IrTcl_RecordList *rl;
3952 setobj->which = zrs->which;
3953 setobj->recordFlag = 1;
3955 ir_deleteDiags (&setobj->nonSurrogateDiagnosticList,
3956 &setobj->nonSurrogateDiagnosticNum);
3957 if (zrs->which == Z_Records_DBOSD)
3959 int num_rec = zrs->u.databaseOrSurDiagnostics->num_records;
3961 if (num_rec != setobj->numberOfRecordsReturned)
3963 logf (LOG_WARN, "numberOfRecordsReturned=%d but num records=%d",
3964 setobj->numberOfRecordsReturned, num_rec);
3965 setobj->numberOfRecordsReturned = num_rec;
3968 for (offset = 0; offset < num_rec; offset++)
3970 Z_NamePlusRecord *znpr = zrs->u.databaseOrSurDiagnostics->
3973 rl = new_IR_record (setobj, setobj->start + offset, znpr->which,
3975 if (rl->which == Z_NamePlusRecord_surrogateDiagnostic)
3976 ir_handleDiags (&rl->u.surrogateDiagnostics.list,
3977 &rl->u.surrogateDiagnostics.num,
3978 &znpr->u.surrogateDiagnostic,
3981 ir_handleDBRecord (p, rl,
3982 (Z_External*) (znpr->u.databaseRecord));
3985 else if (zrs->which == Z_Records_multipleNSD)
3987 logf (LOG_DEBUG, "multipleNonSurrogateDiagnostic %d",
3988 zrs->u.multipleNonSurDiagnostics->num_diagRecs);
3989 setobj->numberOfRecordsReturned = 0;
3990 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
3991 &setobj->nonSurrogateDiagnosticNum,
3992 zrs->u.multipleNonSurDiagnostics->diagRecs,
3993 zrs->u.multipleNonSurDiagnostics->num_diagRecs);
3998 Z_DiagRec dr, *dr_p = &dr;
3999 dr.which = Z_DiagRec_defaultFormat;
4000 dr.u.defaultFormat = zrs->u.nonSurrogateDiagnostic;
4002 Z_DiagRec *dr_p = zrs->u.nonSurrogateDiagnostic;
4004 logf (LOG_DEBUG, "NonSurrogateDiagnostic");
4006 setobj->numberOfRecordsReturned = 0;
4007 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4008 &setobj->nonSurrogateDiagnosticNum,
4013 static void ir_searchResponse (void *o, Z_SearchResponse *searchrs,
4014 IrTcl_SetObj *setobj)
4016 Z_Records *zrs = searchrs->records;
4018 logf (LOG_DEBUG, "Received search response");
4021 logf (LOG_DEBUG, "Search response, no object!");
4024 setobj->searchStatus = *searchrs->searchStatus;
4025 get_referenceId (&setobj->set_inher.referenceId, searchrs->referenceId);
4026 setobj->resultCount = *searchrs->resultCount;
4027 if (searchrs->presentStatus)
4028 setobj->presentStatus = *searchrs->presentStatus;
4030 setobj->presentStatus = Z_RES_NONE;
4031 if (searchrs->nextResultSetPosition)
4032 setobj->nextResultSetPosition = *searchrs->nextResultSetPosition;
4034 logf (LOG_DEBUG, "status %d hits %d",
4035 setobj->searchStatus, setobj->resultCount);
4039 if (setobj->resultCount <= setobj->set_inher.smallSetUpperBound)
4040 es = setobj->set_inher.smallSetElementSetNames;
4042 es = setobj->set_inher.mediumSetElementSetNames;
4043 setobj->numberOfRecordsReturned = *searchrs->numberOfRecordsReturned;
4044 ir_handleZRecords (o, zrs, setobj, es);
4048 setobj->numberOfRecordsReturned = 0;
4049 setobj->recordFlag = 0;
4054 static void ir_presentResponse (void *o, Z_PresentResponse *presrs,
4055 IrTcl_SetObj *setobj)
4057 Z_Records *zrs = presrs->records;
4059 logf (LOG_DEBUG, "Received present response");
4062 logf (LOG_DEBUG, "Present response, no object!");
4065 setobj->presentStatus = *presrs->presentStatus;
4066 get_referenceId (&setobj->set_inher.referenceId, presrs->referenceId);
4067 setobj->nextResultSetPosition = *presrs->nextResultSetPosition;
4070 setobj->numberOfRecordsReturned = *presrs->numberOfRecordsReturned;
4071 ir_handleZRecords (o, zrs, setobj, setobj->set_inher.elementSetNames);
4075 setobj->numberOfRecordsReturned = 0;
4076 setobj->recordFlag = 0;
4077 logf (LOG_DEBUG, "No records!");
4081 static void ir_scanResponse (void *o, Z_ScanResponse *scanrs,
4082 IrTcl_ScanObj *scanobj)
4086 logf (LOG_DEBUG, "Received scanResponse");
4088 get_referenceId (&p->set_inher.referenceId, scanrs->referenceId);
4089 scanobj->scanStatus = *scanrs->scanStatus;
4090 logf (LOG_DEBUG, "scanStatus=%d", scanobj->scanStatus);
4092 if (scanrs->stepSize)
4093 scanobj->stepSize = *scanrs->stepSize;
4094 logf (LOG_DEBUG, "stepSize=%d", scanobj->stepSize);
4096 scanobj->numberOfEntriesReturned = *scanrs->numberOfEntriesReturned;
4097 logf (LOG_DEBUG, "numberOfEntriesReturned=%d",
4098 scanobj->numberOfEntriesReturned);
4100 if (scanrs->positionOfTerm)
4101 scanobj->positionOfTerm = *scanrs->positionOfTerm;
4103 scanobj->positionOfTerm = -1;
4104 logf (LOG_DEBUG, "positionOfTerm=%d", scanobj->positionOfTerm);
4106 xfree (scanobj->entries);
4107 scanobj->entries = NULL;
4108 scanobj->num_entries = 0;
4109 scanobj->entries_flag = 0;
4111 ir_deleteDiags (&scanobj->nonSurrogateDiagnosticList,
4112 &scanobj->nonSurrogateDiagnosticNum);
4113 if (scanrs->entries)
4118 scanobj->entries_flag = 1;
4119 if (scanrs->entries)
4121 scanobj->num_entries = scanrs->entries->num_entries;
4122 scanobj->entries = ir_tcl_malloc (scanobj->num_entries *
4123 sizeof(*scanobj->entries));
4124 ze = scanrs->entries->entries;
4126 for (i=0; i<scanobj->num_entries; i++, ze++)
4128 scanobj->entries[i].which = (*ze)->which;
4129 switch ((*ze)->which)
4131 case Z_Entry_termInfo:
4132 if ((*ze)->u.termInfo->term->which == Z_Term_general)
4134 int l = (*ze)->u.termInfo->term->u.general->len;
4135 scanobj->entries[i].u.term.buf = ir_tcl_malloc (1+l);
4136 memcpy (scanobj->entries[i].u.term.buf,
4137 (*ze)->u.termInfo->term->u.general->buf,
4139 scanobj->entries[i].u.term.buf[l] = '\0';
4142 scanobj->entries[i].u.term.buf = NULL;
4143 if ((*ze)->u.termInfo->globalOccurrences)
4144 scanobj->entries[i].u.term.globalOccurrences =
4145 *(*ze)->u.termInfo->globalOccurrences;
4147 scanobj->entries[i].u.term.globalOccurrences = 0;
4149 case Z_Entry_surrogateDiagnostic:
4150 ir_handleDiags (&scanobj->entries[i].u.diag.list,
4151 &scanobj->entries[i].u.diag.num,
4152 &(*ze)->u.surrogateDiagnostic,
4157 if (scanrs->entries->nonsurrogateDiagnostics)
4158 ir_handleDiags (&scanobj->nonSurrogateDiagnosticList,
4159 &scanobj->nonSurrogateDiagnosticNum,
4160 scanrs->entries->nonsurrogateDiagnostics,
4161 scanrs->entries->num_nonsurrogateDiagnostics);
4166 static void ir_sortResponse (void *o, Z_SortResponse *sortrs,
4167 IrTcl_SetObj *setobj)
4171 logf (LOG_DEBUG, "Received sortResponse");
4176 purge_IR_records (setobj);
4178 get_referenceId (&p->set_inher.referenceId, sortrs->referenceId);
4180 setobj->sortStatus = *sortrs->sortStatus;
4182 ir_deleteDiags (&setobj->nonSurrogateDiagnosticList,
4183 &setobj->nonSurrogateDiagnosticNum);
4185 if (sortrs->diagnostics)
4186 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4187 &setobj->nonSurrogateDiagnosticNum,
4188 sortrs->diagnostics,
4189 sortrs->num_diagnostics);
4191 if (sortrs->diagnostics)
4192 ir_handleDiags (&setobj->nonSurrogateDiagnosticList,
4193 &setobj->nonSurrogateDiagnosticNum,
4194 sortrs->diagnostics->diagRecs,
4195 sortrs->diagnostics->num_diagRecs);
4200 * ir_select_read: handle incoming packages
4202 static void ir_select_read (ClientData clientData)
4204 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
4209 Tcl_CmdInfo cmd_info;
4210 const char *apdu_call;
4212 logf(LOG_DEBUG, "Read handler fd=%d", cs_fileno(p->cs_link));
4213 if (p->state == IR_TCL_R_Connecting)
4215 logf(LOG_DEBUG, "read: connect");
4216 r = cs_rcvconnect (p->cs_link);
4219 logf (LOG_WARN, "cs_rcvconnect returned 1");
4222 p->state = IR_TCL_R_Idle;
4224 ir_select_remove_write (cs_fileno (p->cs_link), p);
4227 logf (LOG_DEBUG, "cs_rcvconnect error");
4228 ir_tcl_disconnect (p);
4231 p->failInfo = IR_TCL_FAIL_CONNECT;
4232 ir_tcl_eval (p->interp, p->failback);
4234 ir_obj_delete ((ClientData) p);
4238 ir_tcl_eval (p->interp, p->callback);
4239 if (p->ref_count == 2 && p->cs_link && p->request_queue
4240 && p->state == IR_TCL_R_Idle)
4241 ir_tcl_send_q (p, p->request_queue, "x");
4242 ir_obj_delete ((ClientData) p);
4247 p->state = IR_TCL_R_Reading;
4249 /* read incoming APDU */
4250 if ((r=cs_get (p->cs_link, &p->buf_in, &p->len_in)) == 1)
4252 logf(LOG_DEBUG, "PDU Fraction read");
4255 /* signal one more use of ir object - callbacks must not
4256 release the ir memory (p pointer) */
4260 logf (LOG_DEBUG, "cs_get failed, code %d", r);
4261 ir_tcl_disconnect (p);
4264 p->failInfo = IR_TCL_FAIL_READ;
4265 ir_tcl_eval (p->interp, p->failback);
4267 /* release ir object now if callback deleted it */
4268 ir_obj_delete ((ClientData) p);
4271 /* got complete APDU. Now decode */
4274 odr_setbuf (p->odr_in, p->buf_in, r, 0);
4275 logf (LOG_DEBUG, "cs_get ok, total size %d", r);
4276 if (!z_APDU (p->odr_in, &apdu, 0))
4278 logf (LOG_DEBUG, "cs_get failed: %s",
4279 odr_errmsg (odr_geterror (p->odr_in)));
4280 ir_tcl_disconnect (p);
4283 p->failInfo = IR_TCL_FAIL_IN_APDU;
4284 p->apduOffset = odr_offset (p->odr_in);
4285 ir_tcl_eval (p->interp, p->failback);
4287 /* release ir object now if failback deleted it */
4288 ir_obj_delete ((ClientData) p);
4291 /* handle APDU and invoke callback */
4292 rq = p->request_queue;
4295 logf (LOG_FATAL, "Internal error. No queue entry");
4298 object_name = rq->object_name;
4299 logf (LOG_DEBUG, "Object %s", object_name);
4301 if (Tcl_GetCommandInfo (p->interp, object_name, &cmd_info))
4305 case Z_APDU_initResponse:
4306 p->eventType = "init";
4307 ir_initResponse (p, apdu->u.initResponse);
4308 apdu_call = p->initResponse;
4310 case Z_APDU_searchResponse:
4311 p->eventType = "search";
4312 ir_searchResponse (p, apdu->u.searchResponse,
4313 (IrTcl_SetObj *) cmd_info.clientData);
4314 apdu_call = ((IrTcl_SetObj *)
4315 cmd_info.clientData)->searchResponse;
4317 case Z_APDU_presentResponse:
4318 p->eventType = "present";
4319 ir_presentResponse (p, apdu->u.presentResponse,
4320 (IrTcl_SetObj *) cmd_info.clientData);
4321 apdu_call = ((IrTcl_SetObj *)
4322 cmd_info.clientData)->presentResponse;
4324 case Z_APDU_scanResponse:
4325 p->eventType = "scan";
4326 ir_scanResponse (p, apdu->u.scanResponse,
4327 (IrTcl_ScanObj *) cmd_info.clientData);
4328 apdu_call = ((IrTcl_ScanObj *)
4329 cmd_info.clientData)->scanResponse;
4331 case Z_APDU_sortResponse:
4332 p->eventType = "sort";
4333 ir_sortResponse (p, apdu->u.sortResponse,
4334 (IrTcl_SetObj *) cmd_info.clientData);
4335 apdu_call = ((IrTcl_SetObj *)
4336 cmd_info.clientData)->sortResponse;
4339 logf (LOG_WARN, "Received unknown APDU type (%d)",
4341 ir_tcl_disconnect (p);
4344 p->failInfo = IR_TCL_FAIL_UNKNOWN_APDU;
4345 ir_tcl_eval (p->interp, p->failback);
4350 p->request_queue = rq->next;
4351 p->state = IR_TCL_R_Idle;
4354 ir_tcl_eval (p->interp, apdu_call);
4355 else if (rq->callback)
4356 ir_tcl_eval (p->interp, rq->callback);
4357 xfree (rq->buf_out);
4358 xfree (rq->callback);
4359 xfree (rq->object_name);
4361 odr_reset (p->odr_in);
4362 if (p->ref_count == 1)
4364 ir_obj_delete ((ClientData) p);
4367 ir_obj_delete ((ClientData) p);
4368 } while (p->cs_link && cs_more (p->cs_link));
4369 if (p->cs_link && p->request_queue && p->state == IR_TCL_R_Idle)
4370 ir_tcl_send_q (p, p->request_queue, "x");
4374 * ir_select_write: handle outgoing packages - not yet written.
4376 static int ir_select_write (ClientData clientData)
4378 IrTcl_Obj *p = (IrTcl_Obj *) clientData;
4382 logf (LOG_DEBUG, "Write handler fd=%d", cs_fileno(p->cs_link));
4383 if (p->state == IR_TCL_R_Connecting)
4385 logf(LOG_DEBUG, "write: connect");
4386 r = cs_rcvconnect (p->cs_link);
4389 logf (LOG_DEBUG, "cs_rcvconnect returned 1");
4392 p->state = IR_TCL_R_Idle;
4394 ir_select_remove_write (cs_fileno (p->cs_link), p);
4397 logf (LOG_DEBUG, "cs_rcvconnect error");
4398 ir_tcl_disconnect (p);
4401 p->failInfo = IR_TCL_FAIL_CONNECT;
4402 ir_tcl_eval (p->interp, p->failback);
4404 ir_obj_delete ((ClientData) p);
4408 ir_tcl_eval (p->interp, p->callback);
4409 ir_obj_delete ((ClientData) p);
4412 rq = p->request_queue;
4413 if (!rq || !rq->buf_out)
4416 if ((r=cs_put (p->cs_link, rq->buf_out, rq->len_out)) < 0)
4418 logf (LOG_DEBUG, "cs_put write fail");
4420 xfree (rq->buf_out);
4422 ir_tcl_disconnect (p);
4425 p->failInfo = IR_TCL_FAIL_WRITE;
4426 ir_tcl_eval (p->interp, p->failback);
4428 ir_obj_delete ((ClientData) p);
4430 else if (r == 0) /* remove select bit */
4432 logf (LOG_DEBUG, "Write completed");
4433 p->state = IR_TCL_R_Waiting;
4434 ir_select_remove_write (cs_fileno (p->cs_link), p);
4435 xfree (rq->buf_out);
4441 static void ir_select_notify (ClientData clientData, int r, int w, int e)
4445 if (!ir_select_write (clientData) && r)
4446 ir_select_read (clientData);
4450 ir_select_read (clientData);
4454 /*----------------------------------------------------------- */
4458 * This wrapper function is used by Windows to invoke the
4459 * initialization code for the DLL. If we are compiling
4460 * with Visual C++, this routine will be renamed to DllMain.
4472 DllEntryPoint(hInst, reason, reserved)
4473 HINSTANCE hInst; /* Library instance handle. */
4474 DWORD reason; /* Reason this function is being called. */
4475 LPVOID reserved; /* Not used. */
4481 /* ------------------------------------------------------- */
4483 * Irtcl_init: Registration of TCL commands.
4485 EXPORT (int,Irtcl_Init) (Tcl_Interp *interp)
4487 Tcl_CreateCommand (interp, "ir", ir_obj_mk, (ClientData) NULL,
4488 (Tcl_CmdDeleteProc *) NULL);
4489 Tcl_CreateCommand (interp, "ir-set", ir_set_obj_mk,
4490 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4491 Tcl_CreateCommand (interp, "ir-scan", ir_scan_obj_mk,
4492 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4493 Tcl_CreateCommand (interp, "ir-log-init", ir_log_init_proc,
4494 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4495 Tcl_CreateCommand (interp, "ir-log", ir_log_proc,
4496 (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
4497 Tcl_CreateCommand (interp, "ir-version", ir_version, (ClientData) NULL,
4498 (Tcl_CmdDeleteProc *) NULL);